/* Recipe Manager app styles: "The Well-Used Cookbook". Tokens live in tokens.css. */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font-ui); background: var(--bg); color: var(--text-primary); line-height: 1.6;
       -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; line-height: 1.2; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
::selection { background: var(--accent-subtle); color: var(--text-primary); }
input, textarea, select, button { font-family: inherit; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Masthead ── */
.masthead { background: var(--nav-bg); border-bottom: 3px double var(--rule); padding: 0 2rem;
            position: sticky; top: 0; z-index: 100; }
.masthead-inner { max-width: 1100px; margin: 0 auto; height: 64px; display: flex; align-items: center; gap: 1.5rem; }
.brand { font-family: var(--font-display); font-size: 1.625rem; font-weight: 700; color: var(--text-primary);
         letter-spacing: -0.01em; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand:hover { color: var(--text-primary); }
.nav-logo { height: 32px; max-width: 120px; object-fit: contain; }
.nav-links { display: flex; align-items: center; gap: 0.25rem; flex: 1; min-width: 0; }
.nav-links > a, .menu > summary { color: var(--text-secondary); font-size: var(--fs-sm); font-weight: 600;
        padding: 0.45rem 0.7rem; border-radius: var(--radius); cursor: pointer; list-style: none;
        display: inline-flex; align-items: center; gap: 0.3rem; user-select: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: ""; width: 0.4em; height: 0.4em; border-right: 1.5px solid currentColor;
        border-bottom: 1.5px solid currentColor; transform: translateY(-0.12em) rotate(45deg); }
.nav-links > a:hover, .menu > summary:hover, .menu[open] > summary { color: var(--text-primary); background: var(--border-light); }
.nav-links > a.active, .menu.active > summary { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); border-radius: var(--radius) var(--radius) 0 0; }
.menu { position: relative; }
.menu-panel { position: absolute; top: calc(100% + 6px); left: 0; min-width: 210px; background: var(--surface);
        border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
        padding: 0.35rem; z-index: 120; }
.menu-panel.right { left: auto; right: 0; }
.menu-panel a { display: block; padding: 0.5rem 0.75rem; border-radius: var(--radius); color: var(--text-primary);
        font-size: var(--fs-sm); font-weight: 500; }
.menu-panel a:hover { background: var(--accent-subtle); color: var(--accent); }
.menu-panel .menu-label { padding: 0.4rem 0.75rem 0.15rem; font-size: var(--fs-2xs); font-weight: 700;
        text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-tertiary); }
.menu-panel hr { border: none; border-top: 1px solid var(--border-light); margin: 0.3rem 0; }
.nav-right { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.nav-add > summary { background: var(--accent-solid); color: #fff; padding: 0.45rem 0.85rem; }
.nav-add > summary:hover, .nav-add[open] > summary { background: var(--accent-solid-hover); color: #fff; }
.theme-toggle { background: none; border: 1px solid var(--border); color: var(--text-secondary);
        width: 36px; height: 36px; border-radius: var(--radius); cursor: pointer; display: flex;
        align-items: center; justify-content: center; font-size: var(--fs-base); }
.icon-sun { display: none; } [data-theme="dark"] .icon-sun { display: block; } [data-theme="dark"] .icon-moon { display: none; }
.theme-toggle:hover { background: var(--border-light); color: var(--text-primary); }
.hamburger { display: none; background: none; border: 1px solid var(--border); color: var(--text-primary);
        width: 40px; height: 40px; border-radius: var(--radius); cursor: pointer; align-items: center;
        justify-content: center; margin-left: auto; }
.hamburger span, .hamburger span::before, .hamburger span::after { display: block; width: 18px; height: 2px;
        background: currentColor; content: ""; position: relative; }
.hamburger span::before { position: absolute; top: -6px; } .hamburger span::after { position: absolute; top: 6px; }

/* ── Layout ── */
.container { max-width: 1100px; margin: 0 auto; padding: 2.25rem 1.5rem 4rem; }
.flash { padding: 0.7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: var(--fs-sm);
         font-weight: 500; border: 1px solid transparent; animation: flash-in 0.3s var(--ease-out); }
.flash.success { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.flash.error { background: var(--error-bg); color: var(--error); border-color: var(--error-border); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ── Card stock ── */
.card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
        padding: 1.5rem; margin-bottom: 1.25rem; border: 1px solid var(--border); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; padding: 0.5rem 1rem;
       border-radius: var(--radius); border: 1px solid transparent; cursor: pointer; font-size: var(--fs-sm);
       font-weight: 600; line-height: 1.4; text-decoration: none;
       transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent-solid); color: #fff; border-color: var(--accent-solid); }
.btn-primary:hover { background: var(--accent-solid-hover); border-color: var(--accent-solid-hover); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--border-light); color: var(--text-primary); }
.btn-danger { background: var(--surface); color: var(--error); border-color: var(--error-border); }
.btn-danger:hover { background: var(--error-bg); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: var(--fs-xs); }
.btn[disabled], .btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; }

/* ── Forms ── */
input, textarea, select { width: 100%; padding: 0.55rem 0.75rem; border: 1px solid var(--border);
        border-radius: var(--radius); font-size: var(--fs-base); background: var(--input-bg);
        color: var(--text-primary); transition: border-color 0.15s, box-shadow 0.15s; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
input::placeholder, textarea::placeholder { color: var(--text-tertiary); }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent-solid); }
textarea { min-height: 100px; resize: vertical; }
label { display: block; font-weight: 600; margin-bottom: 0.3rem; margin-top: 1rem; font-size: var(--fs-xs);
        color: var(--text-primary); }
.form-group:first-child label { margin-top: 0; }
.form-hint { font-size: var(--fs-xs); color: var(--text-tertiary); margin-top: 0.2rem; }

/* ── Recipe shelf ── */
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1.5rem; }
.recipe-grid > * { min-width: 0; }
.recipe-card { cursor: pointer; overflow: hidden; padding: 0; transition: box-shadow 0.2s, transform 0.2s; }
@media (hover: hover) { .recipe-card:hover { box-shadow: var(--shadow-md); transform: translateY(-3px); } }
.recipe-card-img, .recipe-card-placeholder { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; display: block; }
.recipe-card-placeholder { display: flex; align-items: center; justify-content: center; font-family: var(--font-display);
        font-weight: 700; font-style: italic; background: var(--tint-1); color: var(--tint-1-ink); }
.recipe-card-placeholder::before { content: attr(data-mono); font-size: 4.5rem; line-height: 1; }
.recipe-card-placeholder.tint-2 { background: var(--tint-2); color: var(--tint-2-ink); }
.recipe-card-placeholder.tint-3 { background: var(--tint-3); color: var(--tint-3-ink); }
.recipe-card-placeholder.tint-4 { background: var(--tint-4); color: var(--tint-4-ink); }
.recipe-card-body { padding: 0.9rem 1.15rem 1.15rem; }
.recipe-card-body h3 { font-size: 1.3rem; margin-bottom: 0.25rem; color: var(--text-primary); line-height: 1.2;
        display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.recipe-meta { color: var(--text-tertiary); font-size: var(--fs-xs); display: flex; gap: 0.75rem; flex-wrap: wrap;
        row-gap: 0.15rem; font-variant-numeric: tabular-nums; }

/* ── Tags (small-caps text, not pills), badges, chips ── */
.tag { display: inline-block; font-size: var(--fs-xs); font-weight: 600; color: var(--accent); overflow-wrap: anywhere; background: none; padding: 0; }
.card-tags, .recipe-tags { display: flex; flex-wrap: wrap; gap: 0.1rem 0.75rem; }
.badge { display: inline-block; padding: 0.1rem 0.45rem; border-radius: var(--radius); font-size: var(--fs-2xs); font-weight: 600; }
.badge-accent { background: var(--accent-subtle); color: var(--accent); }
.badge-muted { background: var(--border-light); color: var(--text-tertiary); }
.filter-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.25rem; }
.chip { padding: 0.3rem 0.8rem; border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: 600;
        border: 1px solid var(--border); color: var(--text-secondary); background: var(--surface);
        transition: background-color 0.15s, border-color 0.15s, color 0.15s; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent-solid); color: #fff; border-color: var(--accent-solid); }
.chip.active:hover { background: var(--accent-solid-hover); color: #fff; }

/* ── Search, headers ── */
.search-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.search-bar input { flex: 1; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 1.25rem;
        flex-wrap: wrap; gap: 0.75rem; padding-bottom: 0.6rem; border-bottom: 1px solid var(--rule); }
.page-header h1, .page-header h2 { font-size: clamp(1.75rem, 4vw, 2.4rem); letter-spacing: -0.01em; text-wrap: balance; overflow-wrap: anywhere; }
.page-header > * { min-width: 0; }
.actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }

/* ── The recipe page: a two-column spread on ruled stock ── */
.detail-hero { width: 100%; aspect-ratio: 16 / 9; max-height: 420px; object-fit: cover; border-radius: var(--radius-lg);
        margin-bottom: 1.5rem; box-shadow: var(--shadow); }
.detail-meta { display: flex; gap: 2.25rem; flex-wrap: wrap; margin: 1.25rem 0; padding: 0.9rem 0;
        border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.meta-label { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-tertiary); font-weight: 700; }
.meta-value { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 700; line-height: 1.2;
        font-variant-numeric: tabular-nums; }
.detail-section { margin-top: 1.9rem; overflow-wrap: anywhere; }
.detail-section h3 { font-size: var(--fs-lg); margin-bottom: 0.6rem; text-wrap: balance; }
.ingredient-list, .instruction-list { list-style: none; padding: 0; max-width: 68ch; font-family: var(--font-display); }
.ingredient-list li { padding: 0.5rem 0 0.5rem 1.1rem; border-bottom: 1px solid var(--rule); font-size: var(--fs-reading);
        line-height: 1.45; position: relative; overflow-wrap: anywhere; }
.ingredient-list li::before { content: ""; position: absolute; left: 0; top: 1.05em; width: 0.55rem; height: 2px; background: var(--accent); }
.instruction-list { counter-reset: step; }
.instruction-list li { padding: 0.75rem 0; border-bottom: 1px solid var(--rule); display: flex; gap: 0.9rem;
        align-items: baseline; font-size: var(--fs-reading); line-height: 1.5; overflow-wrap: anywhere; }
.instruction-list li::before { counter-increment: step; content: counter(step); color: var(--accent); font-style: italic;
        font-weight: 700; font-size: 1.6rem; line-height: 1; min-width: 1.6rem; text-align: right; }
.ingredient-list li.list-section, .instruction-list li.list-section { list-style: none; border-bottom: none;
        padding: 1.1rem 0 0.2rem; font-size: var(--fs-sm); font-weight: 700; font-style: italic; color: var(--accent); display: block; }
.ingredient-list li.list-section::before, .instruction-list li.list-section::before { content: none; }
.instruction-list li.list-section { counter-reset: step; }
@media (min-width: 900px) {
    .recipe-spread { display: grid; grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.4fr); gap: 3rem; align-items: start; }
    .recipe-spread .detail-section { margin-top: 1.5rem; }
    .recipe-spread .spread-side { position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow-y: auto; }
}

/* ── Empty states, auth, tables, stats ── */
.empty-state { text-align: center; padding: 3rem 2rem; }
.empty-state p { font-family: var(--font-display); font-size: var(--fs-lg); color: var(--text-secondary); margin-bottom: 1.25rem; text-wrap: balance; }
.auth-wrapper { max-width: 400px; margin: 4rem auto; }
.auth-wrapper h1, .auth-wrapper h2 { text-align: center; margin-bottom: 0.25rem; font-size: 2rem; }
.auth-wrapper .auth-subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 1.5rem; font-size: var(--fs-sm); text-wrap: pretty; }
.auth-footer { text-align: center; margin-top: 1.25rem; color: var(--text-tertiary); font-size: var(--fs-xs); }
.table { width: 100%; border-collapse: collapse; }
.table th { padding: 0.5rem; font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.06em;
        color: var(--text-tertiary); font-weight: 700; text-align: left; border-bottom: 1px solid var(--border); }
.table td { padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border-light); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: none; }
.stat { text-align: center; padding: 1.25rem; }
.stat-value { font-family: var(--font-display); font-size: 2.25rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: var(--fs-2xs); color: var(--text-tertiary); margin-top: 0.35rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.divider { border: none; border-top: 1px solid var(--rule); margin: 1.25rem 0; }
.card p { text-wrap: pretty; overflow-wrap: anywhere; }

/* ── Touch: 44px targets on coarse pointers ── */
@media (pointer: coarse) {
    .btn, .chip, .theme-toggle, .hamburger, .nav-links > a, .menu > summary, .menu-panel a { min-height: 44px; }
    .theme-toggle, .hamburger { min-width: 44px; }
    .btn-sm { padding: 0.4rem 0.8rem; }
    .chip { display: inline-flex; align-items: center; padding: 0.4rem 0.95rem; }
    .menu-panel a { display: flex; align-items: center; }
}
@media (prefers-reduced-motion: reduce) {
    .flash { animation: none; } .btn:active { transform: none; } .recipe-card:hover { transform: none !important; }
}

/* ── Mobile ── */
@media (max-width: 860px) {
    .masthead { padding: 0 1rem; }
    .masthead-inner { height: 56px; gap: 0.75rem; }
    .hamburger { display: inline-flex; }
    .nav-links { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--nav-bg);
            flex-direction: column; align-items: stretch; padding: 0.5rem 1rem 1rem; gap: 0.15rem;
            border-bottom: 3px double var(--rule); box-shadow: var(--shadow-md); max-height: calc(100vh - 56px); overflow-y: auto; }
    .nav-links.open { display: flex; }
    .nav-links > a, .menu > summary { padding: 0.7rem 0.75rem; }
    .menu-panel { position: static; box-shadow: none; border: none; border-radius: 0;
            margin: 0 0 0.25rem 0.75rem; background: transparent; }
    .nav-right { margin-left: 0; padding-top: 0.5rem; border-top: 1px solid var(--border-light); flex-wrap: wrap; }
    .nav-right .menu { flex: 1 1 100%; }
    .container { padding: 1.5rem 1rem 3rem; }
    .recipe-grid { grid-template-columns: 1fr 1fr; gap: 1rem; }
    .recipe-card-body { padding: 0.75rem 0.85rem 0.9rem; }
    .recipe-card-body h3 { font-size: 1.1rem; }
    .page-header { align-items: flex-start; }
}
@media (max-width: 480px) {
    .recipe-grid { grid-template-columns: 1fr 1fr; gap: 0.75rem; }
    .recipe-card-placeholder::before { font-size: 2.75rem; }
    .recipe-card-body h3 { font-size: 1rem; }
}
@media (max-width: 340px) { .recipe-grid { grid-template-columns: 1fr; } }

/* ── Thumb-reach tab bar (phones): the four things you do in the kitchen ── */
.tabbar { display: none; }
@media (max-width: 860px) {
    body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
    .tabbar { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
            background: var(--nav-bg); border-top: 3px double var(--rule); padding: 0.3rem 0.25rem calc(0.3rem + env(safe-area-inset-bottom)); }
    .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.15rem; min-height: 52px;
            border-radius: var(--radius); color: var(--text-secondary); font-size: var(--fs-2xs); font-weight: 600; }
    .tabbar a:hover { color: var(--text-primary); }
    .tabbar a.active { color: var(--accent); background: var(--accent-subtle); }
}
@media (pointer: coarse) { .back-link { min-height: 44px; } }

/* ── Undo flash, offline notice, install hint, shortcuts dialog ── */
.flash-undo { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.flash-undo form { margin: 0; }
.menu-panel .menu-item { display: block; width: 100%; text-align: left; padding: 0.5rem 0.75rem; border: none; background: none; cursor: pointer;
        border-radius: var(--radius); font-size: var(--fs-sm); font-weight: 500; color: var(--text-primary); }
.menu-panel .menu-item:hover { background: var(--accent-subtle); color: var(--accent); }
.offline-notice { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 200;
        background: var(--text-primary); color: var(--bg); padding: 0.55rem 1rem; border-radius: var(--radius-pill); font-size: var(--fs-sm);
        font-weight: 600; box-shadow: var(--shadow-md); max-width: calc(100vw - 2rem); text-align: center; }
[hidden] { display: none !important; }
.install-hint { position: fixed; left: 0.75rem; right: 0.75rem; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 95; display: flex; align-items: center;
        gap: 0.5rem; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
        box-shadow: var(--shadow-md); padding: 0.75rem 0.9rem; }
.install-hint p { flex: 1 1 200px; font-size: var(--fs-sm); margin: 0; }
.shortcuts-dialog { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text-primary);
        padding: 1.5rem; width: min(420px, calc(100vw - 2rem)); box-shadow: var(--shadow-md); }
.shortcuts-dialog::backdrop { background: rgba(20, 24, 29, 0.55); }
.shortcuts-dialog h2 { font-size: var(--fs-lg); margin-bottom: 0.75rem; }
.shortcut-list > div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0; border-bottom: 1px solid var(--rule); font-size: var(--fs-sm); }
.shortcut-list dt { white-space: nowrap; } .shortcut-list dd { margin: 0; color: var(--text-secondary); text-align: right; }
kbd { font-family: var(--font-ui); font-size: var(--fs-xs); font-weight: 600; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: var(--radius);
      padding: 0.05rem 0.4rem; background: var(--bg); }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 1rem; }

/* ── Print: the recipe only, no chrome ── */
@media print {
    body { background: #fff; color: #000; padding: 0; }
    .masthead, .tabbar, .install-hint, .offline-notice, .flash, .back-link, .recipe-actions, .scale-group, .theme-toggle, .filters-toggle { display: none !important; }
    .container { max-width: none; padding: 0; }
    .detail-hero { max-height: 220px; box-shadow: none; }
    .recipe-spread { display: block !important; }
    .recipe-spread .spread-side { position: static; max-height: none; overflow: visible; }
    .ingredient-list li, .instruction-list li { break-inside: avoid; border-bottom-color: #ccc; }
    .detail-section { break-inside: auto; }
    a { color: inherit; text-decoration: none; }
}

.header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
[id] { scroll-margin-top: 84px; }

/* ── "How do you want to add it?" switcher + two-line menu items ── */
.add-switcher { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.add-switcher a { display: flex; align-items: center; gap: 0.75rem; padding: 0.85rem 1rem; background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius-lg); color: var(--text-primary); min-height: 64px; }
.add-switcher a:hover { border-color: var(--accent); }
.add-switcher a.active { border-color: var(--accent); background: var(--accent-subtle); box-shadow: inset 0 0 0 1px var(--accent); }
.add-switcher .ico { width: 24px; height: 24px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.add-switcher span { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.add-switcher strong { font-size: var(--fs-sm); }
.add-switcher small { font-size: var(--fs-xs); color: var(--text-secondary); }
@media (max-width: 720px) { .add-switcher { grid-template-columns: 1fr; gap: 0.5rem; } .add-switcher a { min-height: 56px; } }
.menu-panel a .menu-title { display: block; font-weight: 600; }
.menu-panel a .menu-desc { display: block; font-size: var(--fs-xs); color: var(--text-secondary); font-weight: 400; margin-top: 0.1rem; }
.new-menu .menu-panel { min-width: 260px; }
