:root {
    --bg: #fdf8f2;
    --surface: #fffdf9;
    --surface-strong: #fff7ed;
    --text: #2c1810;
    --muted: #6a5247;
    --accent: #c8602a;
    --accent-soft: #f1d7c5;
    --border: #ead9ca;
    --shadow: 0 14px 38px rgba(72, 42, 24, 0.08);
    --full: #3c7a3e;
    --stub: #8d857f;
}

html.dark body,
body.dark {
    --bg: #1a1412;
    --surface: #231e1b;
    --surface-strong: #2c2520;
    --text: #f0e8e0;
    --muted: #a89888;
    --accent: #e07840;
    --accent-soft: #3d2a1e;
    --border: #3d3028;
    --shadow: 0 14px 38px rgba(0, 0, 0, 0.4);
    --full: #5aaa5c;
    --stub: #9a9490;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Georgia, "Times New Roman", serif;
    line-height: 1.6;
}

body.print-view {
    background: #fff;
}

.page-shell {
    width: min(1120px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2.5rem 0 4rem;
}

.site-header,
.controls-panel,
.recipe-article {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
}

.site-header {
    position: relative;
    padding: 2.25rem;
    margin-bottom: 1.5rem;
}

.eyebrow {
    margin: 0 0 0.4rem;
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

h1, h2, h3 {
    color: var(--text);
    line-height: 1.2;
}

.site-header h1,
.recipe-article h1 {
    margin: 0;
    font-size: clamp(2.1rem, 4vw, 3.4rem);
}

.subtitle,
.stats-line,
.source-line,
.source-attribution,
.source-url-print,
.stub-note p,
.back-link,
.form-hint {
    color: var(--muted);
}

.header-actions {
    margin-top: 1rem;
}

.controls-panel {
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.search-label {
    display: block;
    margin-bottom: 0.6rem;
    font-weight: 700;
}

.search-input {
    width: 100%;
    padding: 0.95rem 1rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    font: inherit;
    color: var(--text);
    background: var(--surface-strong);
    margin-bottom: 1rem;
}

.search-input:focus {
    outline: 2px solid rgba(200, 96, 42, 0.18);
    border-color: var(--accent);
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.filter-chip,
.status-badge,
.category-badge,
.print-button,
.source-link-button,
.theme-toggle,
.add-recipe-btn,
.ghost-button,
.panel-close {
    border-radius: 999px;
}

.filter-chip {
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    padding: 0.55rem 0.95rem;
    font: inherit;
    cursor: pointer;
}

.filter-chip.active,
.filter-chip:hover,
.print-button,
.source-link-button {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.theme-toggle {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    background: var(--accent-soft);
    border: 1px solid var(--border);
    width: 2.4rem;
    height: 2.4rem;
    font-size: 1.15rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.theme-toggle:hover {
    background: var(--accent);
    color: #fff;
}

.add-recipe-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.5rem 1.1rem;
    font-size: 0.9rem;
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    transition: opacity 0.15s;
}

.add-recipe-btn:hover {
    opacity: 0.85;
}

.add-recipe-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.ghost-button,
.panel-close {
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.ghost-button {
    padding: 0.5rem 1rem;
}

.panel-close {
    width: 2.2rem;
    height: 2.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.add-recipe-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem 2rem;
    margin-bottom: 1.5rem;
    display: none;
}

.add-recipe-panel.open {
    display: block;
}

.panel-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.panel-topline h2 {
    margin: 0;
}

.add-recipe-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.add-recipe-form .full {
    grid-column: 1 / -1;
}

.add-recipe-form label {
    display: block;
    font-weight: 700;
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: var(--muted);
}

.add-recipe-form input,
.add-recipe-form textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
}

.add-recipe-form textarea {
    min-height: 180px;
    resize: vertical;
    font-family: monospace;
}

.add-recipe-form input:focus,
.add-recipe-form textarea:focus {
    outline: 2px solid var(--accent);
    border-color: var(--accent);
}

.form-hint {
    margin: 0.35rem 0 0;
    font-size: 0.85rem;
}

.form-status {
    padding: 0.85rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
}

.form-status.success {
    color: var(--full);
    background: rgba(60, 122, 62, 0.12);
    border-color: rgba(60, 122, 62, 0.3);
}

.form-status.error {
    color: #b34231;
    background: rgba(179, 66, 49, 0.12);
    border-color: rgba(179, 66, 49, 0.3);
}

.form-status a {
    color: inherit;
    font-weight: 700;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.recipe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}

.recipe-card {
    display: block;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: inherit;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.recipe-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 18px 38px rgba(72, 42, 24, 0.14);
}

.recipe-card[hidden] {
    display: none;
}

.card-topline,
.tag-row,
.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    align-items: center;
}

.card-topline {
    justify-content: space-between;
}

.recipe-card h2 {
    margin: 1rem 0 0.65rem;
    font-size: 1.3rem;
}

.status-badge,
.category-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.28rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 700;
}

.status-badge.full {
    background: rgba(60, 122, 62, 0.14);
    color: var(--full);
}

.status-badge.stub {
    background: rgba(141, 133, 127, 0.15);
    color: var(--stub);
}

.category-badge {
    background: var(--accent-soft);
    color: var(--accent);
}

.recipe-shell {
    width: min(880px, calc(100% - 2rem));
}

.page-actions {
    justify-content: space-between;
    margin-bottom: 1rem;
}

.back-link,
.print-button,
.source-link-button {
    text-decoration: none;
    font-weight: 700;
}

.recipe-article {
    padding: 2rem;
}

.recipe-body h2,
.recipe-body h3 {
    margin-top: 1.8rem;
}

.recipe-body ul,
.recipe-body ol {
    padding-left: 1.5rem;
}

.recipe-body li + li {
    margin-top: 0.25rem;
}

.stub-article {
    text-align: left;
}

.stub-note {
    margin-top: 1.5rem;
    padding: 1.25rem;
    border-radius: 18px;
    background: var(--surface-strong);
    border: 1px solid var(--border);
}

.source-notice {
    font-size: 1.05rem;
}

.source-url-print {
    display: none;
}

@media (max-width: 720px) {
    .page-shell {
        width: min(100% - 1rem, 1120px);
        padding-top: 1rem;
    }

    .site-header,
    .controls-panel,
    .recipe-article,
    .recipe-card {
        border-radius: 18px;
    }

    .add-recipe-form {
        grid-template-columns: 1fr;
    }

    .form-actions,
    .page-actions {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media print {
    @page {
        margin: 0.6in;
    }

    body,
    body.print-view,
    .page-shell,
    .recipe-shell,
    .recipe-article {
        background: #fff;
        color: #000;
        box-shadow: none;
    }

    body {
        font-size: 11pt;
    }

    .page-shell,
    .recipe-shell {
        width: 100%;
        margin: 0;
        padding: 0;
    }

    .site-header,
    .controls-panel,
    .page-actions,
    .no-print,
    .print-button,
    .back-link {
        display: none !important;
    }

    .recipe-article {
        border: 0;
        border-radius: 0;
        padding: 0;
    }

    h1 {
        font-size: 22pt;
        margin-bottom: 0.3in;
    }

    h2, h3 {
        page-break-after: avoid;
    }

    p, li {
        orphans: 3;
        widows: 3;
    }

    ul, ol {
        page-break-inside: avoid;
    }

    .source-link-button {
        display: none;
    }

    .source-url-print {
        display: block;
        margin-top: 1rem;
        font-size: 10pt;
    }
}

/* ── Delete recipe (local only) ─────────────────────────── */
.delete-zone {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    margin-top: 2.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
.delete-btn {
    background: #c0392b;
    border: 2px solid #a93226;
    color: #fff;
    border-radius: 8px;
    padding: 0.55rem 1.2rem;
    font-size: 0.92rem;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(192,57,43,0.35);
    transition: background 0.15s, transform 0.1s;
}
.delete-btn:hover {
    background: #a93226;
    transform: scale(1.03);
}
.delete-confirm {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
    color: var(--muted);
}
.delete-confirm-yes {
    background: #c0392b;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.35rem 0.85rem;
    font-family: inherit;
    cursor: pointer;
    font-size: 0.85rem;
}
.delete-confirm-no {
    background: var(--accent-soft);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem 0.85rem;
    font-family: inherit;
    cursor: pointer;
    font-size: 0.85rem;
}

.theme-toggle { position: absolute; top: 1.25rem; right: 1.25rem; background: var(--accent-soft); border: 1px solid var(--border); border-radius: 20px; padding: 0.35rem 0.9rem; font-size: 0.82rem; font-family: inherit; font-weight: bold; letter-spacing: 0.05em; text-transform: uppercase; cursor: pointer; color: var(--muted); transition: background 0.2s, color 0.2s; }

/* ── Split filter groups ─────────────────────────────────── */
.filter-section {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 1rem;
}
.filter-group {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}
.filter-group-label {
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    min-width: 5rem;
    flex-shrink: 0;
}
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

/* ── Edit button & modal ─────────────────────────────────────── */
.edit-btn {
    background: var(--accent, #2980b9);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.edit-btn:hover { background: var(--accent-hover, #1a6497); }

.edit-modal[hidden] { display: none !important; }
.edit-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.edit-modal-inner {
    background: var(--surface, #fff);
    border-radius: 16px;
    width: 100%;
    max-width: 760px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    overflow: hidden;
}
.edit-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border, #e0e0e0);
}
.edit-modal-header h2 { margin: 0; font-size: 1.1rem; }
.edit-hint {
    padding: 8px 20px 4px;
    font-size: 0.82rem;
    color: var(--text-muted, #888);
    margin: 0;
}
.edit-textarea {
    flex: 1;
    margin: 8px 20px;
    padding: 12px;
    font-family: ui-monospace, monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    border: 1px solid var(--border, #ddd);
    border-radius: 8px;
    resize: none;
    min-height: 320px;
    background: var(--code-bg, #f8f8f8);
    color: var(--text, #222);
}
.edit-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px 16px;
    border-top: 1px solid var(--border, #e0e0e0);
}
.edit-save-btn {
    background: #27ae60;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 9px 20px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.95rem;
}
.edit-save-btn:hover { background: #219a52; }
.edit-save-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.edit-close-btn {
    background: transparent;
    border: 1px solid var(--border, #ccc);
    border-radius: 8px;
    padding: 8px 16px;
    cursor: pointer;
    color: var(--text, #444);
    font-size: 0.9rem;
}
.edit-close-btn:hover { background: var(--border, #eee); }
.edit-status { font-size: 0.88rem; color: var(--text-muted, #888); margin-left: 4px; }

/* ── Recipe source credit (full recipes) ─────────────────────── */
.recipe-source-credit {
    margin-top: 24px;
    padding: 10px 16px;
    border-top: 1px solid var(--border, #e0e0e0);
    font-size: 0.85rem;
    color: var(--text-muted, #888);
}
.recipe-source-credit .source-label { font-weight: 600; margin-right: 6px; }
.recipe-source-credit a { color: var(--accent, #2980b9); }
