/* ===========================
   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: #3d3d3d;
    background: #faf8f5;
    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: #2c2c2c; }
h2 { font-size: 1.05rem; margin-bottom: 0.5rem; color: #5a5a5a; letter-spacing: 0.02em; text-transform: uppercase; font-weight: 600; }

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

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

.card {
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 0.65rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
}

.header-card {
    text-align: center;
    padding: 1.5rem 1.25rem 1rem;
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: none;
    border-bottom: none;
}
.header-card .subtitle {
    font-size: 0.9rem;
    color: #888;
    margin-top: 0.4rem;
    font-style: italic;
}

/* ===========================
   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: #bbb;
    pointer-events: none;
}
#search-input {
    width: 100%;
    padding: 0.65rem 2.25rem 0.65rem 2.25rem;
    border: 1px solid #e0d6c8;
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: inherit;
    color: #3d3d3d;
    background: #faf8f5;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-appearance: none;
    min-height: 44px;
}
#search-input::placeholder { color: #c4b8a8; }
#search-input:focus {
    border-color: #c4a882;
    box-shadow: 0 0 0 3px rgba(196, 168, 130, 0.12);
}
.search-clear {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #bbb;
    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: #888; background: #f0ece6; }

#search-results { display: none; }
#no-results {
    text-align: center;
    color: #aaa;
    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: #9a7b5b;
    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: #9a7b5b;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    transition: color 0.15s ease, background 0.15s ease;
}
.print-btn:hover { color: #7a5f43; background: #f5f3f0; }
.print-btn:active { opacity: 0.6; }
.print-btn svg { display: block; width: 18px; height: 18px; }

/* ===========================
   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 #e8e4df;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
    margin-bottom: 0.65rem;
    position: sticky;
    top: 0;
    z-index: 10;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.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: #aaa;
    text-decoration: none;
    background: #f5f3f0;
    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: #888; background: #eeebe6; }
.recipe-nav-pill.active {
    color: #7a5f43;
    background: #f0e8d8;
}

/* ===========================
   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;
    background: #f7f5f2;
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    color: #3d3d3d;
    line-height: 1.3;
    flex: 1 0 4.5rem;
    max-width: 9rem;
}
.meta-list li strong {
    font-size: 0.62rem;
    font-weight: 500;
    color: #999;
    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: #faf8f5;
}
.ingredient-grams { color: #bbb; font-size: 0.8em; }

/* 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: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='2' stroke='%23b0a090'%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: #f5f0ea;
}
.ingredient-list li[data-subs].open::after {
    opacity: 1;
    transform: rotate(90deg);
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='2' stroke='%23c4a882'%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;
}
.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 #e0d8cd;
}
.sub-list li {
    padding: 0.3rem 0;
    margin-bottom: 0;
    background: none !important;
}
.sub-name {
    font-size: 0.85rem;
    color: #555;
}
.sub-note {
    font-size: 0.78rem;
    color: #aaa;
    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: #fdfcfa;
    border-left: 3px solid #e0d6c8;
    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: #c4a882;
    width: 1.8rem;
    text-align: center;
}

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

.tips-card { background: #fefcf6; border: 1px solid #f0e8d8; }
.tips-list { padding-left: 1.25rem; }
.tips-list li {
    font-size: 0.9rem;
    color: #666;
    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: #f7f5f2;
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    color: #3d3d3d;
    line-height: 1.3;
    flex: 1 0 6rem;
    max-width: 9rem;
}
.nutrition-list li strong {
    font-size: 0.62rem;
    font-weight: 500;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 0.1rem;
}
.nutrition-list li[data-macro="calories"] { order: 0; border-bottom: 3px solid #4A9DE5; }
.nutrition-list li[data-macro="protein"]  { order: 1; border-bottom: 3px solid #E06055; }
.nutrition-list li[data-macro="fat"]      { order: 2; border-bottom: 3px solid #E5A83E; }
.nutrition-list li[data-macro="carbs"]    { order: 3; border-bottom: 3px solid #5BB85B; }
.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: #aaa; font-style: italic; margin-top: 0.65rem; text-align: center; }

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

.weight-card {
    background: #eef3f9;
    border: 1px solid #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: #3d3d3d;
    line-height: 1.3;
    flex: 1 0 6rem;
    max-width: 9rem;
}
.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 — Source footer
   =========================== */

.source-footer {
    text-align: center;
    font-size: 0.8rem;
    color: #bbb;
    padding: 0.25rem 0 0.5rem;
}
.source-footer a { color: #bbb; text-decoration: underline; text-decoration-color: #ddd; }

/* ===========================
   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 #e8e4df;
    margin-bottom: 0.5rem;
}
.category-section summary::-webkit-details-marker { display: none; }
.category-section summary::before {
    content: "▸";
    font-size: 0.75rem;
    color: #ccc;
    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: #999;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.category-count {
    font-size: 0.75rem;
    color: #ccc;
    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: #aaa;
    font-weight: 600;
    margin-bottom: 0.5rem;
    padding-left: 0.15rem;
    border-bottom: 1px solid #e8e4df;
    padding-bottom: 0.4rem;
}

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

.recipe-card {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
    background: #fff;
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
    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 rgba(0,0,0,0.08);
}
.recipe-card:active { opacity: 0.85; }
.recipe-card-content { flex: 1; }
.recipe-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: #2c2c2c;
}
.recipe-card-title .fav { font-size: 0.85rem; margin-right: 0.2rem; }
.recipe-card-desc {
    font-size: 0.82rem;
    color: #999;
    font-style: italic;
    margin-top: 0.15rem;
}
.recipe-card-meta {
    font-size: 0.78rem;
    color: #bbb;
    margin-top: 0.3rem;
}
.recipe-card-meta span { margin-right: 0.75rem; }
.recipe-card-chevron {
    color: #ccc;
    font-size: 1.2rem;
    margin-left: 0.75rem;
    flex-shrink: 0;
}

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

@media (min-width: 768px) {
    body { padding: 2rem; }
    .recipe, .index { max-width: 720px; }
    .card { padding: 1.5rem; margin-bottom: 0.85rem; }
    .header-card { padding: 2rem 1.5rem 1.25rem; 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; }
    .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; }
}

/* ===========================
   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; }
}

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

@media print {
    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; }

    /* 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: " — "; }

    /* 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; }

    /* 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; }
    .nav-bar { display: none; }
    .source-footer { 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; }
    .search-wrapper { display: none; }
    #search-results { display: none; }
    #no-results { display: none; }
}
