/* ===========================
   Color System — Design Tokens
   =========================== */

:root {
    /* Themed tokens (light mode defaults) */
    --color-bg: #faf8f5;
    --color-surface: #ffffff;
    --color-surface-alt: #f0ece6;
    --color-text: #3d3d3d;
    --color-text-muted: #999999;
    --color-accent: #9a7b5b;
    --color-accent-hover: #7a5f43;
    --color-accent-bg: #f5f0ea;
    --color-border: #e0d6c8;
    --color-shadow: rgba(0, 0, 0, 0.06);
    --color-accent-focus: rgba(154, 123, 91, 0.12);
    --color-success: #3a7d3a;
    --color-error: #c44444;

    /* Fixed tokens (same in both modes) */
    --color-macro-calories: #4A9DE5;
    --color-macro-protein: #E06055;
    --color-macro-fat: #E5A83E;
    --color-macro-carbs: #5BB85B;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #1c1a17;
        --color-surface: #2a2725;
        --color-surface-alt: #332f2b;
        --color-text: #e8e4df;
        --color-text-muted: #888888;
        --color-accent: #c4a882;
        --color-accent-hover: #d4bc9a;
        --color-accent-bg: #3b3632;
        --color-border: #4a4540;
        --color-shadow: rgba(0, 0, 0, 0.4);
        --color-accent-focus: rgba(196, 168, 130, 0.15);
        --color-success: #6abf6a;
        --color-error: #e06060;
    }
}

/* Manual theme overrides — specificity 0,1,1 beats :root (0,1,0) in media query */
html[data-theme="light"] {
    --color-bg: #faf8f5;
    --color-surface: #ffffff;
    --color-surface-alt: #f0ece6;
    --color-text: #3d3d3d;
    --color-text-muted: #999999;
    --color-accent: #9a7b5b;
    --color-accent-hover: #7a5f43;
    --color-accent-bg: #f5f0ea;
    --color-border: #e0d6c8;
    --color-shadow: rgba(0, 0, 0, 0.06);
    --color-accent-focus: rgba(154, 123, 91, 0.12);
    --color-success: #3a7d3a;
    --color-error: #c44444;
    color-scheme: light;
}
html[data-theme="dark"] {
    --color-bg: #1c1a17;
    --color-surface: #2a2725;
    --color-surface-alt: #332f2b;
    --color-text: #e8e4df;
    --color-text-muted: #888888;
    --color-accent: #c4a882;
    --color-accent-hover: #d4bc9a;
    --color-accent-bg: #3b3632;
    --color-border: #4a4540;
    --color-shadow: rgba(0, 0, 0, 0.4);
    --color-accent-focus: rgba(196, 168, 130, 0.15);
    --color-success: #6abf6a;
    --color-error: #e06060;
    color-scheme: dark;
}

/* ===========================
   Our Recipes — Shared Styles
   =========================== */

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    padding: 1rem;
    -webkit-text-size-adjust: 100%;
}

.recipe, .index {
    max-width: 640px;
    margin: 0 auto;
}

h1 { font-size: 1.5rem; margin-bottom: 0.4rem; color: var(--color-text); }
h2 { font-size: 1.05rem; margin-bottom: 0.5rem; color: var(--color-text-muted); letter-spacing: 0.02em; text-transform: uppercase; font-weight: 600; }

ul { padding-left: 1.25rem; }
li { margin-bottom: 0.3rem; }

/* ===========================
   Cards
   =========================== */

.card {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 0.65rem;
    box-shadow: 0 1px 3px var(--color-shadow), 0 1px 2px var(--color-shadow);
}

.header-card {
    text-align: center;
    padding: 1rem 1.25rem 0.75rem;
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: none;
    border-bottom: none;
}
.index .header-card {
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    margin-bottom: 0.65rem;
}
.header-card .subtitle {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-top: 0.4rem;
    font-style: italic;
}
.header-card .source-link {
    font-size: 0.75rem;
    margin-top: 0.2rem;
    color: var(--color-text-muted);
}
.header-card .source-link a {
    color: var(--color-text-muted);
    text-decoration: none;
    transition: color 0.15s ease;
}
.header-card .source-link a:hover { color: var(--color-accent); }

/* Recipe — Hero photo */

.recipe-hero {
    width: 100%;
    max-height: 300px;
    object-fit: cover;
    border-radius: 8px;
    margin: 0.75rem 0 0.5rem;
}

/* ===========================
   Search
   =========================== */

.search-wrapper {
    position: relative;
    margin-top: 1rem;
}
.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--color-text-muted);
    pointer-events: none;
}
#search-input {
    width: 100%;
    padding: 0.65rem 2.25rem 0.65rem 2.25rem;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-bg);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-appearance: none;
    min-height: 44px;
}
#search-input::placeholder { color: var(--color-text-muted); }
#search-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-focus);
}
.search-clear {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    font-size: 1.25rem;
    line-height: 1;
    padding: 0.25rem;
    border-radius: 50%;
    display: none;
    min-width: 28px;
    min-height: 28px;
    align-items: center;
    justify-content: center;
}
.search-clear.visible { display: flex; }
.search-clear:hover { color: var(--color-text); background: var(--color-surface-alt); }

/* ===========================
   Time filter slider
   =========================== */

.time-filter {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.75rem;
    margin-bottom: 0.25rem;
    padding: 0 0.25rem;
}
.time-filter-label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}
.time-filter-slider {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--color-border);
    outline: none;
    cursor: pointer;
}
.time-filter-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--color-surface);
    border: 2px solid var(--color-accent);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.time-filter-slider::-webkit-slider-thumb:hover {
    border-color: var(--color-accent-hover);
    box-shadow: 0 0 0 4px var(--color-accent-focus);
}
.time-filter-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--color-surface);
    border: 2px solid var(--color-accent);
    cursor: pointer;
}
.time-filter-slider::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: var(--color-border);
}
.time-filter-value {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    min-width: 2.5rem;
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

#search-results { display: none; }
#no-results {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.95rem;
    padding: 2rem 1rem;
    display: none;
}

/* ===========================
   Back link
   =========================== */

.back-link {
    display: block;
    text-align: center;
    padding: 0.75rem;
    font-size: 0.9rem;
    color: var(--color-accent);
    text-decoration: none;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
.back-link:active { opacity: 0.6; }

/* ===========================
   Print button
   =========================== */

.nav-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
}
.nav-bar .back-link {
    padding: 0;
    font-size: 0.9rem;
}
.print-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.35rem;
    border-radius: 8px;
    color: var(--color-accent);
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    transition: color 0.15s ease, background 0.15s ease;
}
.print-btn:hover { color: var(--color-accent-hover); background: var(--color-surface-alt); }
.print-btn:active { opacity: 0.6; }
.print-btn svg { display: block; width: 18px; height: 18px; }

.nav-bar-actions { display: flex; align-items: center; gap: 0.25rem; }

.shopping-list-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.35rem;
    border-radius: 8px;
    color: var(--color-accent);
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    transition: color 0.15s ease, background 0.15s ease;
}
.shopping-list-btn:hover { color: var(--color-accent-hover); background: var(--color-surface-alt); }
.shopping-list-btn:active { opacity: 0.6; }
.shopping-list-btn svg { display: block; width: 18px; height: 18px; }
.shopping-list-btn.active { color: #fff; background: var(--color-accent); }

.shopping-list-count-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 0.4rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--color-accent);
    background: var(--color-accent-bg);
    text-decoration: none;
    transition: color 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
.shopping-list-count-link:hover { color: var(--color-accent-hover); background: var(--color-border); }

/* ===========================
   Recipe — Section navigation
   =========================== */

.recipe-nav {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--color-border);
    border-radius: 0 0 12px 12px;
    box-shadow: 0 1px 3px var(--color-shadow), 0 1px 2px var(--color-shadow);
    margin-bottom: 0.65rem;
    position: sticky;
    top: 0;
    z-index: 10;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
@media (prefers-color-scheme: dark) {
    .recipe-nav {
        background: rgba(42, 39, 37, 0.85);
    }
}
html[data-theme="dark"] .recipe-nav { background: rgba(42, 39, 37, 0.85); }
html[data-theme="light"] .recipe-nav { background: rgba(255, 255, 255, 0.75); }
.recipe-nav::-webkit-scrollbar { display: none; }
.recipe-nav-pill {
    flex-shrink: 0;
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-decoration: none;
    background: var(--color-surface-alt);
    transition: color 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    min-height: 32px;
    display: flex;
    align-items: center;
}
.recipe-nav-pill:hover { color: var(--color-text-muted); background: var(--color-border); }
.recipe-nav-pill.active {
    color: var(--color-accent-hover);
    background: var(--color-accent-bg);
}

/* ===========================
   Recipe — Overview (no heading)
   =========================== */

.meta-list {
    list-style: none;
    padding-left: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
}
.meta-list li {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-alt);
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.3;
    flex: 1 0 4.5rem;
    max-width: 9rem;
}
.meta-list li strong {
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 0.1rem;
}

/* ===========================
   Recipe — Ingredients
   =========================== */

.ingredient-list { list-style: none; padding-left: 0; }
.ingredient-list li {
    padding: 0.45rem 0.65rem;
    border-radius: 6px;
}
.ingredient-list li:nth-child(odd) {
    background: var(--color-bg);
}
.ingredient-grams { color: var(--color-text-muted); font-size: 0.8em; }

/* Ingredients — Header row with stepper */

.ingredients-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.ingredients-header h2 { margin-bottom: 0; }

.servings-stepper {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.stepper-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1.5px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-accent);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    user-select: none;
    line-height: 1;
    padding: 0;
}
.stepper-btn:hover { border-color: var(--color-accent); background: var(--color-accent-bg); }
.stepper-btn:active { background: var(--color-accent-bg); }
.stepper-btn:disabled {
    color: var(--color-border);
    border-color: var(--color-border);
    background: var(--color-bg);
    cursor: default;
}
.stepper-value {
    min-width: 1.5rem;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}
.stepper-original {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    font-style: italic;
    margin-right: 0.15rem;
}
.scale-print-note {
    display: none;
    text-align: center;
    font-size: 0.78rem;
    color: var(--color-accent-hover);
    font-style: italic;
    padding: 0.25rem 0;
}

/* Ingredients — Substitutions */

.ingredient-list li[data-subs] {
    cursor: pointer;
    position: relative;
    padding-right: 2rem;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
.ingredient-list li[data-subs]::after {
    content: "";
    position: absolute;
    right: 0.65rem;
    top: 0.45rem;
    width: 16px;
    height: 16px;
    background-color: var(--color-text-muted);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='2' stroke='%23000'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M7.5 21 3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5'/%3E%3C/svg%3E") center/contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='2' stroke='%23000'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M7.5 21 3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5'/%3E%3C/svg%3E") center/contain no-repeat;
    opacity: 0.7;
    transform: rotate(0deg);
    transition: opacity 0.15s ease, transform 0.25s ease;
}
.ingredient-list li[data-subs]:hover::after { opacity: 1; }
.ingredient-list li[data-subs].open {
    background: var(--color-accent-bg);
}
.ingredient-list li[data-subs].open::after {
    opacity: 1;
    transform: rotate(90deg);
    background-color: var(--color-accent);
}
.sub-list {
    list-style: none;
    padding: 0 0 0 0.75rem;
    margin-top: 0;
    border-top: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease, padding 0.25s ease, margin-top 0.25s ease;
}
.ingredient-list li[data-subs].open .sub-list {
    max-height: 200px;
    padding: 0.5rem 0 0.25rem 0.75rem;
    margin-top: 0.4rem;
    border-top: 1px solid var(--color-border);
}
.sub-list li {
    padding: 0.3rem 0;
    margin-bottom: 0;
    background: none !important;
}
.sub-name {
    font-size: 0.85rem;
    color: var(--color-text);
}
.sub-note {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    font-style: italic;
    display: block;
}

/* ===========================
   Recipe — Steps (cooking-optimized)
   =========================== */

.steps-card { padding: 1.25rem 1.25rem 0.75rem; }
.steps-card ol {
    list-style: none;
    padding-left: 0;
    counter-reset: step-counter;
}
.steps-card li {
    counter-increment: step-counter;
    font-size: 1.05rem;
    line-height: 1.7;
    margin-bottom: 1.25rem;
    padding: 0.75rem 0.75rem 0.75rem 3.25rem;
    background: var(--color-bg);
    border-left: 3px solid var(--color-border);
    border-radius: 0 8px 8px 0;
    position: relative;
}
.steps-card li::before {
    content: counter(step-counter);
    position: absolute;
    left: 0.75rem;
    top: 0.65rem;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--color-accent);
    width: 1.8rem;
    text-align: center;
}

/* Step tracking — tap to mark current step */
.steps-card li.step-active {
    border-left-color: var(--color-accent);
    background: var(--color-accent-bg);
}
.steps-card li.step-active::before {
    color: var(--color-accent-hover);
}
.steps-card li.step-done {
    opacity: 0.4;
}
.steps-card li {
    transition: opacity 0.15s ease, background 0.15s ease, border-left-color 0.15s ease;
}

/* ===========================
   Recipe — Tips
   =========================== */

.tips-card { background: var(--color-accent-bg); border: 1px solid var(--color-border); }
.tips-list { padding-left: 1.25rem; }
.tips-list li {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-bottom: 0.4rem;
    line-height: 1.55;
}

/* ===========================
   Recipe — Nutrition
   =========================== */

.nutrition-list {
    list-style: none;
    padding-left: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
}
.nutrition-list li {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    background: var(--color-surface-alt);
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.3;
    flex: 1 0 6rem;
    max-width: 9rem;
}
.nutrition-list li strong {
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 0.1rem;
}
.nutrition-list li[data-macro="calories"] { order: 0; border-bottom: 3px solid var(--color-macro-calories); }
.nutrition-list li[data-macro="protein"]  { order: 1; border-bottom: 3px solid var(--color-macro-protein); }
.nutrition-list li[data-macro="fat"]      { order: 2; border-bottom: 3px solid var(--color-macro-fat); }
.nutrition-list li[data-macro="carbs"]    { order: 3; border-bottom: 3px solid var(--color-macro-carbs); }
.nutrition-list::before {
    content: "";
    flex-basis: 100%;
    order: 4;
    height: 0;
}
.nutrition-list li:not([data-macro]) { order: 5; }
.nutrition-source { font-size: 0.78rem; color: var(--color-text-muted); font-style: italic; margin-top: 0.65rem; text-align: center; }

/* ===========================
   Recipe — Weight estimates
   =========================== */

.weight-card {
    background: #eef3f9;
    border: 1px solid #d6e0ed;
}
@media (prefers-color-scheme: dark) {
    .weight-card {
        background: #1e2a36;
        border-color: #2d3d4d;
    }
}
html[data-theme="dark"] .weight-card { background: #1e2a36; border-color: #2d3d4d; }
html[data-theme="light"] .weight-card { background: #eef3f9; border-color: #d6e0ed; }
.weight-list {
    list-style: none;
    padding-left: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
}
.weight-list li {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.3;
    flex: 1 0 6rem;
    max-width: 9rem;
}
@media (prefers-color-scheme: dark) {
    .weight-list li {
        background: rgba(255, 255, 255, 0.08);
    }
}
html[data-theme="dark"] .weight-list li { background: rgba(255, 255, 255, 0.08); }
html[data-theme="light"] .weight-list li { background: rgba(255, 255, 255, 0.7); }
.weight-list li strong {
    font-size: 0.62rem;
    font-weight: 500;
    color: #7a8ea0;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 0.1rem;
}
.weight-card .method {
    font-size: 0.78rem;
    color: #8899aa;
    margin-top: 0.65rem;
    text-align: center;
    font-style: italic;
}

/* ===========================
   Recipe — Attribution
   =========================== */

.recipe-attribution {
    text-align: center;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    padding: 0.25rem 0 0.5rem;
}
.recipe-attribution a { color: var(--color-text-muted); text-decoration: underline; text-decoration-color: var(--color-border); }
.contributor { color: var(--color-text-muted); }

/* ===========================
   Index — Category sections
   =========================== */

.category-section { margin-bottom: 0.75rem; }
.category-section summary {
    display: flex;
    align-items: center;
    padding: 0.6rem 1rem;
    cursor: pointer;
    list-style: none;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    user-select: none;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.5rem;
}
.category-section summary::-webkit-details-marker { display: none; }
.category-section summary::before {
    content: "\25B8";
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-right: 0.5rem;
    transition: transform 0.15s ease;
    display: inline-block;
}
.category-section details[open] > summary::before {
    transform: rotate(90deg);
}
.category-section summary:active { opacity: 0.8; }
.category-emoji { font-size: 1rem; margin-right: 0.4rem; }
.category-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.category-count {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-left: auto;
    padding-left: 0.5rem;
}
.category-recipes { padding-top: 0.25rem; }

/* ===========================
   Index — Section labels
   =========================== */

.section-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    font-weight: 600;
    margin-bottom: 0.5rem;
    padding-left: 0.15rem;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0.4rem;
}

/* ===========================
   Index — Recipe cards
   =========================== */

.recipe-card {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
    background: var(--color-surface);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 0.5rem;
    box-shadow: 0 1px 3px var(--color-shadow), 0 1px 2px var(--color-shadow);
    transition: box-shadow 0.15s ease;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    min-height: 44px;
}
.recipe-card:hover {
    box-shadow: 0 2px 8px var(--color-shadow);
}
.recipe-card:active { opacity: 0.85; }
.recipe-card-content { flex: 1; }
.recipe-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
}
.recipe-card-title .fav { font-size: 0.85rem; margin-right: 0.2rem; }
.recipe-card-desc {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    font-style: italic;
    margin-top: 0.15rem;
}
.recipe-card-meta {
    display: flex;
    align-items: baseline;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    margin-top: 0.3rem;
}
.recipe-card-meta span { margin-right: 0.75rem; }
.recipe-card-meta-left span { margin-right: 0.75rem; }
.recipe-card-meta-left span:last-child { margin-right: 0; }
.card-contributor {
    color: var(--color-text-muted);
    font-size: 0.82rem;
    white-space: nowrap;
    margin-left: auto;
    margin-right: 0;
}
.recipe-card-chevron {
    color: var(--color-text-muted);
    font-size: 1.2rem;
    margin-left: 0.75rem;
    flex-shrink: 0;
}

/* Index — Recipe card photo thumbnails */

.recipe-card-photo {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
    margin-right: 1rem;
}

/* ===========================
   Index — Per-card cart toggle (shopping list)
   =========================== */

.card-cart-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    margin-left: 0.35rem;
    margin-top: -6px;
    margin-bottom: -6px;
    border: none;
    border-radius: 6px;
    background: none;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
/* Push cart button right when no contributor precedes it */
.recipe-card-meta-left + .card-cart-btn { margin-left: auto; }
.card-cart-btn:hover { color: var(--color-accent); background: var(--color-surface-alt); }
.card-cart-btn:active { opacity: 0.6; }
.card-cart-btn.active { color: #fff; background: var(--color-accent); }
.card-cart-btn svg { width: 16px; height: 16px; }

/* Upload button (top-left) */

.upload-toggle {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    color: var(--color-text-muted);
    text-decoration: none;
    border: 1px solid var(--color-border);
    border-radius: 50%;
    transition: color 0.15s ease, border-color 0.15s ease;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
.upload-toggle:hover { color: var(--color-text); border-color: var(--color-accent); }

/* Inline shopping link (header card) */

.shopping-link {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    display: none;
    align-items: center;
    gap: 0.25rem;
    text-decoration: none;
    padding: 0 0.6rem;
    height: 36px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    color: var(--color-accent);
    font-size: 0.82rem;
    font-weight: 600;
    transition: border-color 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
.shopping-link.visible { display: flex; }
.shopping-link:hover { border-color: var(--color-accent); background: var(--color-accent-bg); }
.shopping-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.shopping-link-count { font-variant-numeric: tabular-nums; }

/* ===========================
   Shopping list page
   =========================== */

.shopping-list {
    max-width: 640px;
    margin: 0 auto;
}
.shopping-list .header-card {
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    margin-bottom: 0.65rem;
}
.shopping-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.25rem;
    margin-bottom: 0.75rem;
}
.shopping-action-link {
    font-size: 0.9rem;
    color: var(--color-accent);
    text-decoration: none;
}
.shopping-action-link:active { opacity: 0.6; }
.shopping-action-btn {
    font-size: 0.82rem;
    font-family: inherit;
    color: var(--color-accent);
    background: none;
    border: 1px solid var(--color-accent);
    border-radius: 8px;
    padding: 0.35rem 0.75rem;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.shopping-action-btn:hover { color: var(--color-accent-hover); border-color: var(--color-accent-hover); background: var(--color-accent-bg); }

/* Recipe tag pills */
.shopping-recipe-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0 0.25rem;
    margin-bottom: 0.75rem;
}
.shopping-recipe-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 500;
    background: var(--color-accent-bg);
    border-radius: 999px;
    padding: 0.4rem 0.5rem 0.4rem 0.85rem;
}
.shopping-recipe-tag-link {
    color: var(--color-accent);
    text-decoration: none;
}
.shopping-recipe-tag-link:hover { text-decoration: underline; }
.shopping-recipe-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--color-surface-alt);
    color: var(--color-text-muted);
    font-size: 1.1rem;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
.shopping-recipe-remove:hover { color: var(--color-error); background: var(--color-border); }

/* Store sections */
.shopping-section {
    background: var(--color-surface);
    border-radius: 12px;
    margin-bottom: 0.5rem;
    box-shadow: 0 1px 3px var(--color-shadow), 0 1px 2px var(--color-shadow);
    overflow: hidden;
    transition: opacity 0.2s ease;
}
.section-completed { opacity: 0.6; }
.shopping-section-header {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.88rem;
    color: var(--color-text);
    text-align: left;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    gap: 0.4rem;
}
.shopping-section-header:hover { background: var(--color-bg); }
.shopping-section-icon { font-size: 1rem; }
.shopping-section-name {
    font-weight: 600;
    flex: 1;
}
.shopping-section-check-all {
    font-family: inherit;
    font-size: 0.7rem;
    color: var(--color-accent);
    font-weight: 500;
    padding: 0.15rem 0.5rem;
    border: none;
    border-radius: 4px;
    background: none;
    cursor: pointer;
}
.shopping-section-check-all:hover {
    background: var(--color-accent-bg);
}
.shopping-section-count {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}
.shopping-section-chevron {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* Item list */
.shopping-section-list {
    list-style: none;
    padding: 0 1rem 0.5rem;
    margin: 0;
}
.shopping-item {
    border-top: 1px solid var(--color-surface-alt);
}
.shopping-item:first-child { border-top: none; }
.shopping-item-label {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.45rem 0;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
.shopping-checkbox {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin-top: 0.1rem;
    accent-color: var(--color-accent);
    cursor: pointer;
}
.shopping-item-detail {
    flex: 1;
    min-width: 0;
}
.shopping-item-text {
    font-size: 0.95rem;
    color: var(--color-text);
    line-height: 1.4;
}
.shopping-item.checked .shopping-item-text {
    text-decoration: line-through;
    color: var(--color-text-muted);
}
.shopping-item-sources {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    font-style: italic;
    line-height: 1.3;
}

/* Empty state */
.shopping-empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}
.shopping-empty-state p {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}
.shopping-empty-link {
    font-size: 0.9rem;
    color: var(--color-accent);
    text-decoration: none;
}
.shopping-empty-link:hover { text-decoration: underline; }

/* ===========================
   Status feedback (shared)
   =========================== */

.status-success {
    background: #f0f9f0;
    color: var(--color-success);
    border: 1px solid #c8e6c8;
}
.status-error {
    background: #fdf0f0;
    color: var(--color-error);
    border: 1px solid #f0c8c8;
}
.status-processing {
    background: var(--color-surface-alt);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}
@media (prefers-color-scheme: dark) {
    .status-success {
        background: #1a2e1a;
        border-color: #2d4a2d;
    }
    .status-error {
        background: #2e1a1a;
        border-color: #4a2d2d;
    }
}
html[data-theme="dark"] .status-success { background: #1a2e1a; border-color: #2d4a2d; }
html[data-theme="dark"] .status-error { background: #2e1a1a; border-color: #4a2d2d; }
html[data-theme="light"] .status-success { background: #f0f9f0; border-color: #c8e6c8; }
html[data-theme="light"] .status-error { background: #fdf0f0; border-color: #f0c8c8; }

/* ===========================
   Responsive — iPad / larger phones
   =========================== */

@media (min-width: 768px) {
    body { padding: 2rem; }
    .recipe, .index, .shopping-list { max-width: 720px; }
    .card { padding: 1.5rem; margin-bottom: 0.85rem; }
    .header-card { padding: 1.25rem 1.5rem 0.85rem; margin-bottom: 0; }
    h1 { font-size: 1.75rem; }
    .steps-card li {
        font-size: 1.1rem;
        line-height: 1.75;
        padding: 1rem 1rem 1rem 3.5rem;
        margin-bottom: 1.5rem;
    }
    .steps-card li::before { font-size: 1.3rem; top: 0.9rem; }
    .ingredient-list li { padding: 0.5rem 0.75rem; }
    .recipe-nav { padding: 0.6rem 1rem; gap: 0.5rem; }
    .recipe-nav-pill { font-size: 0.82rem; padding: 0.35rem 0.85rem; }
    .print-btn svg { width: 20px; height: 20px; }
    .shopping-list-btn svg { width: 20px; height: 20px; }
    .card-cart-btn svg { width: 18px; height: 18px; }
    .recipe-card { padding: 1.25rem 1.5rem; }
    .recipe-card-title { font-size: 1.1rem; }
    .recipe-card-desc { font-size: 0.88rem; }
    .recipe-card-meta { font-size: 0.82rem; }
    .category-name { font-size: 0.9rem; }
    #search-input { font-size: 1rem; padding: 0.75rem 2.5rem; }
    .stepper-btn { width: 32px; height: 32px; font-size: 1rem; }
    .stepper-value { font-size: 1rem; }
    .time-filter-slider::-webkit-slider-thumb { width: 22px; height: 22px; }
    .recipe-hero { max-height: 360px; }
    .recipe-card-photo { width: 88px; height: 88px; }
}

/* ===========================
   Responsive — Small phones
   =========================== */

@media (max-width: 375px) {
    .steps-card li {
        font-size: 1rem;
        padding: 0.6rem 0.6rem 0.6rem 2.75rem;
    }
    .steps-card li::before { font-size: 1.1rem; left: 0.5rem; }
}

/* ===========================
   Reduced motion
   =========================== */

@media (prefers-reduced-motion: reduce) {
    .sub-list { transition: none; }
    .ingredient-list li[data-subs]::after { transition: none; }
    .recipe-nav { scroll-behavior: auto; }
    .stepper-btn { transition: none; }
    .header-card .source-link a { transition: none; }
    .time-filter-slider::-webkit-slider-thumb { transition: none; }
    .card-cart-btn { transition: none; }
    .upload-toggle { transition: none; }
    .shopping-link { transition: none; }
    .shopping-recipe-remove { transition: none; }
    .shopping-list-btn { transition: none; }
    .shopping-list-count-link { transition: none; }
    .shopping-section { transition: none; }
    .shopping-action-btn { transition: none; }
    .shopping-section-header { transition: none; }
    .steps-card li { transition: none; }
    .theme-toggle { transition: none; }
}

/* ===========================
   Page footer (theme toggle row)
   =========================== */

.page-footer {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0.25rem 0;
}
.page-footer > :first-child { justify-self: start; }
.page-footer > :last-child { justify-self: end; }

/* Override default back-link centering when inside footer */
.page-footer .back-link {
    display: inline;
    text-align: left;
    padding: 0;
}

.footer-contributor {
    justify-self: center;
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

/* Non-recipe pages: just the toggle, right-aligned */
.page-footer-end {
    display: flex;
    justify-content: flex-end;
    padding: 0.25rem 0;
}

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.35rem;
    border-radius: 8px;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
.theme-toggle:hover { color: var(--color-text); }
.theme-toggle svg { display: block; }

/* ===========================
   Print — force light mode
   =========================== */

@media print {
    @page { size: portrait; margin: 0.5in; }

    :root,
    html[data-theme="dark"],
    html[data-theme="light"] {
        --color-bg: #faf8f5;
        --color-surface: #ffffff;
        --color-surface-alt: #f0ece6;
        --color-text: #3d3d3d;
        --color-text-muted: #999999;
        --color-accent: #9a7b5b;
        --color-accent-hover: #7a5f43;
        --color-accent-bg: #f5f0ea;
        --color-border: #e0d6c8;
        --color-shadow: rgba(0, 0, 0, 0.06);
        --color-accent-focus: rgba(154, 123, 91, 0.12);
        --color-success: #3a7d3a;
        --color-error: #c44444;
        color-scheme: light;
    }

    body { background: #fff; padding: 0; margin: 0; color: #000; }

    /* Kill dynamic scroll padding that creates blank trailing pages */
    .recipe { max-width: 100% !important; padding-bottom: 0 !important; margin: 0; }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
        border-radius: 0;
        padding: 0.5rem 0.75rem;
        margin-bottom: 0.3rem;
    }

    /* Let cards flow across pages instead of forcing page breaks */
    .steps-card, #ingredients, #nutrition, #weight { break-inside: auto; }
    .header-card, #overview { break-inside: avoid; }

    h1 { font-size: 1.3rem; margin: 0.2rem 0; }
    h2 { font-size: 0.95rem; margin: 0.2rem 0 0.3rem; }
    .header-card { padding: 0.4rem 0.75rem; margin-bottom: 0; }
    .header-card .subtitle { color: #555; font-size: 0.8rem; margin-top: 0.15rem; }
    .header-card .source-link { font-size: 0.65rem; margin-top: 0.1rem; color: var(--color-text-muted); }
    .header-card .source-link a { color: var(--color-text-muted); }

    /* Overview stat blocks — compact for print */
    .meta-list { gap: 0.3rem; }
    .meta-list li {
        font-size: 0.8rem;
        padding: 0.25rem 0.5rem;
        background: #f5f5f5;
        flex: 1 0 4rem;
        max-width: 7rem;
    }
    .meta-list li strong { font-size: 0.55rem; }

    /* Ingredients */
    .ingredient-list li { padding: 0.15rem 0.4rem; font-size: 0.8rem; }
    .ingredient-list li:nth-child(odd) { background: #f5f5f5; }
    .ingredient-list li[data-subs]::after { display: none; }
    .ingredient-grams { font-size: 0.7rem; }

    /* Substitutions — show in print with indentation */
    .sub-list {
        display: block !important;
        max-height: none !important;
        opacity: 1 !important;
        list-style: none;
        padding: 0.15rem 0 0.15rem 1.8rem;
        margin: 0.15rem 0 0;
        border-left: none;
    }
    .sub-list li {
        font-size: 0.55rem;
        color: #666;
        padding: 0.05rem 0;
        background: none !important;
    }
    .sub-list li::before {
        content: "↳ ";
        color: #999;
    }
    .sub-list .sub-name { font-weight: 500; color: #333; font-size: 0.55rem; }
    .sub-list .sub-note { font-style: italic; color: #aaa; font-size: 0.5rem; }
    .sub-list .sub-note::before { content: " \2014 "; }

    /* Steps */
    .steps-card li {
        font-size: 0.8rem;
        line-height: 1.45;
        margin-bottom: 0.3rem;
        padding: 0.25rem 0.4rem 0.25rem 2.2rem;
        background: none;
        border-left-color: #999;
    }
    .steps-card li::before { color: #666; font-size: 0.85rem; left: 0.5rem; top: 0.2rem; }
    .steps-card li.step-active,
    .steps-card li.step-done { opacity: 1; background: none; border-left-color: #999; }
    .steps-card li.step-active::before { color: #666; }

    /* Nutrition stat blocks — compact for print */
    .nutrition-list { gap: 0.25rem; }
    .nutrition-list li {
        font-size: 0.75rem;
        padding: 0.2rem 0.4rem;
        background: #f5f5f5;
        flex: 1 0 3.5rem;
        max-width: 6rem;
        border-bottom: none;
    }
    .nutrition-list li strong { font-size: 0.5rem; }
    .nutrition-list li[data-macro] { border-bottom: 2px solid #999; }
    .nutrition-source { font-size: 0.65rem; }

    /* Weight stat blocks — compact for print */
    .weight-card { background: #f5f5f5; border: 1px solid #ccc; }
    .weight-list { gap: 0.25rem; }
    .weight-list li {
        font-size: 0.75rem;
        padding: 0.2rem 0.4rem;
        background: rgba(255, 255, 255, 0.7);
        flex: 1 0 4rem;
        max-width: 7rem;
    }
    .weight-list li strong { font-size: 0.5rem; }
    .weight-card .method { font-size: 0.65rem; }
    .tips-card { background: #fafafa; border: 1px solid #ddd; }

    /* Hide non-print elements */
    .back-link { display: none; }
    .print-btn { display: none; }
    .recipe-nav { display: none; }
    .servings-stepper { display: none; }
    .scale-print-note.visible { display: block; }
    .nav-bar { display: none; }
    .recipe-attribution { display: none; }
    .page-footer { display: none; }
    .theme-toggle { display: none; }

    /* Index page */
    .category-section summary { border-bottom-color: #ccc; }
    .category-section summary::before { content: ""; margin: 0; }
    .recipe-card { box-shadow: none; border: 1px solid #ddd; }
    .recipe-card-chevron { display: none; }
    .card-cart-btn { display: none; }
    .search-wrapper { display: none; }
    .time-filter { display: none; }
    #search-results { display: none; }
    #no-results { display: none; }
    .upload-toggle { display: none; }
    .shopping-link { display: none !important; }
    .shopping-list-btn { display: none; }
    .shopping-list-count-link { display: none !important; }

    /* Recipe hero photo — hide in print */
    .recipe-hero { display: none; }

    /* Index photo thumbnails — hide in print */
    .recipe-card-photo { display: none; }

    /* Shopping list page — minimal plain list, hide checked items */
    .shopping-list { max-width: 100% !important; }
    .shopping-list .header-card {
        box-shadow: none; border: none; padding: 0.2rem 0; margin-bottom: 0;
    }
    .shopping-list .header-card h1 { font-size: 1rem; margin: 0; }
    .shopping-list .header-card .subtitle { font-size: 0.75rem; margin-top: 0.1rem; }
    .shopping-actions { display: none; }
    .shopping-recipe-list { display: none; }
    #shopping-list-content {
        column-count: 2; column-gap: 1.5rem;
    }
    .shopping-item.checked { display: none; }
    .section-completed { display: none; }
    .shopping-section {
        box-shadow: none; border: none; border-radius: 0;
        padding: 0; margin-bottom: 0.3rem;
        break-inside: avoid;
    }
    .shopping-section-header {
        padding: 0 0 0.15rem; border-bottom: 1px solid #ccc;
        margin-bottom: 0.15rem;
    }
    .shopping-section-chevron { display: none; }
    .shopping-section-check-all { display: none; }
    .shopping-section-count { display: none; }
    .shopping-section-list { padding: 0; }
    .shopping-item {
        padding: 0.1rem 0; border: none;
    }
    .shopping-checkbox { display: none; }
    .shopping-item-label { padding: 0; }
    .shopping-item-text { font-size: 0.8rem; }
    .shopping-item-sources { font-size: 0.65rem; }
}
