:root {
    color-scheme: light dark;
    --bg: #FAF6EF;
    --bg-elev: #FFFFFF;
    --fg: #2B2420;
    --fg-muted: #7A6F63;
    --border: #E7DFD3;
    --accent: #C1592C;
    --accent-soft: #F3E0D3;
    --accent-ink: #9C4620;
    --accent-fg: #FFF8F2;
    --danger: #A23B2E;
    --font-serif: 'Instrument Serif', Georgia, 'Times New Roman', serif;
    --font-sans: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius-lg: 20px;
    --radius-md: 14px;
    --tabbar-h: 78px;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #201C18;
        --bg-elev: #2A2521;
        --fg: #F3ECE3;
        --fg-muted: #B3A796;
        --border: #3B342C;
        --accent: #E2793F;
        --accent-soft: #4A2E1E;
        --accent-ink: #F0B98C;
        --accent-fg: #241505;
        --danger: #E08376;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: var(--font-sans);
    color: var(--fg);
    background: var(--bg);
    -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; }

.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 20px 18px calc(3rem + env(safe-area-inset-bottom));
    position: relative;
}
body.has-nav .container {
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

/* ---------- shared bits ---------- */
.eyebrow {
    font-size: 12px; font-weight: 800; letter-spacing: 1.1px; text-transform: uppercase;
    color: var(--fg-muted); margin: 22px 0 10px;
}
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
    display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft);
    color: var(--accent-ink); border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700;
}
.card {
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 18px; box-shadow: 0 10px 24px -20px rgba(20, 15, 10, .35);
}
.error { color: var(--danger); font-weight: 700; }
.flash { background: var(--accent-soft); color: var(--accent-ink); padding: 10px 14px; border-radius: var(--radius-md); font-weight: 600; }
.empty-state { color: var(--fg-muted); line-height: 1.5; }

.iconbtn {
    width: 40px; height: 40px; border-radius: 50%; background: var(--bg-elev); border: 1px solid var(--border);
    display: inline-flex; align-items: center; justify-content: center; color: var(--fg); flex-shrink: 0;
}
.iconbtn-sm { width: 36px; height: 36px; }
.iconbtn-ghost { background: transparent; border-color: transparent; color: var(--fg-muted); }

/* ---------- bottom tab bar ---------- */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-around;
    height: var(--tabbar-h); padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-elev); border-top: 1px solid var(--border);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--fg-muted); font-size: 11px; font-weight: 700; }
.tab.active { color: var(--accent-ink); }

/* ---------- recipe list ---------- */
.list-header { margin-bottom: 18px; }
.greeting { font-family: var(--font-serif); font-size: 28px; margin: 0 0 4px; }
.subgreeting { font-size: 14px; color: var(--fg-muted); margin: 0; }
.import-link {
    display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 13px;
    font-weight: 700; color: var(--accent-ink);
}
.import-hint { color: var(--fg-muted); font-size: 14px; line-height: 1.5; margin-bottom: 4px; }
.prompt-box { background: var(--accent-soft); border-radius: var(--radius-lg); padding: 14px; margin-bottom: 4px; }
.prompt-box-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.prompt-text {
    white-space: pre-wrap; font-size: 13px; line-height: 1.55; color: var(--fg); background: var(--bg-elev);
    border-radius: var(--radius-md); padding: 12px; margin: 0; font-family: var(--font-sans); border: 1px solid var(--border);
}
.btn-copy {
    height: 32px; padding: 0 12px; border-radius: 999px; border: none; background: var(--accent);
    color: var(--accent-fg); font-size: 12.5px; font-weight: 800; flex-shrink: 0;
}

.recipe-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.recipe-card a, .recipe-card {
    display: flex; align-items: center; gap: 14px; background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 12px 14px; box-shadow: 0 10px 24px -20px rgba(20, 15, 10, .35);
}
.tile {
    width: 52px; height: 52px; border-radius: 16px; flex-shrink: 0; display: flex; align-items: center;
    justify-content: center; background: var(--accent-soft); color: var(--accent-ink);
}
.recipe-card:nth-of-type(4n+2) .tile { background: #E7EADC; color: #5F7A52; }
.recipe-card:nth-of-type(4n+3) .tile { background: #F1E6C8; color: #8A6B22; }
.recipe-card:nth-of-type(4n+4) .tile { background: #EFE1E4; color: #8C4B57; }
@media (prefers-color-scheme: dark) {
    .recipe-card:nth-of-type(4n+2) .tile { background: #2E3327; color: #A8C398; }
    .recipe-card:nth-of-type(4n+3) .tile { background: #362E1B; color: #E0BE6D; }
    .recipe-card:nth-of-type(4n+4) .tile { background: #35262A; color: #DA9BAB; }
}
.card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.card-title { font-family: var(--font-serif); font-size: 18px; line-height: 1.15; }
.chev { color: var(--border); flex-shrink: 0; }

.fab {
    position: fixed; right: 20px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
    width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-fg);
    display: flex; align-items: center; justify-content: center; box-shadow: 0 14px 26px -10px rgba(0,0,0,.45); z-index: 15;
}

/* ---------- recipe detail ---------- */
.detail-topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.detail-topbar form { display: inline-flex; }
.iconbtn-group { display: flex; gap: 8px; }
.detail-title { font-family: var(--font-serif); font-size: 30px; line-height: 1.1; margin: 12px 0 12px; }
.detail-pills { margin-bottom: 8px; }
.form-title { font-family: var(--font-serif); font-size: 20px; margin: 0; }

.ingredients { list-style: none; margin: 0; padding: 0; }
.ingredients li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 15.5px; }
.ingredients li:last-child { border-bottom: none; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-ink); flex-shrink: 0; }

.steps { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.steps li { display: flex; gap: 14px; align-items: flex-start; }
.step-num {
    width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink);
    font-weight: 800; font-size: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.step-body { display: flex; flex-direction: column; gap: 6px; }
.step-text { font-size: 15.5px; line-height: 1.5; }
.step-note {
    display: inline-flex; align-self: flex-start; background: var(--accent-soft); color: var(--accent-ink);
    font-weight: 800; font-size: 12.5px; letter-spacing: .3px; padding: 4px 10px; border-radius: 999px;
}

.cta-spacer { height: 8px; }
.cta-bar {
    position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 14px 0 14px; background: linear-gradient(180deg, transparent 0%, var(--bg) 45%);
}
.btn-cook, .btn-save, .btn-primary {
    width: 100%; height: 54px; border: none; border-radius: var(--radius-md); color: var(--accent-fg);
    background: var(--accent); font-size: 16px; font-weight: 800; font-family: var(--font-sans);
    display: flex; align-items: center; justify-content: center; gap: 8px;
    box-shadow: 0 16px 28px -12px rgba(0,0,0,.4);
}
.btn-secondary {
    width: 100%; height: 50px; border-radius: var(--radius-md); border: 1.5px solid var(--border);
    background: var(--bg-elev); color: var(--fg); font-size: 15px; font-weight: 700;
}
.full-width { width: 100%; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field label { display: block; font-size: 12px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; color: var(--fg-muted); margin-bottom: 6px; }
.field input, .field select, .row input, .row textarea {
    width: 100%; min-height: 48px; border-radius: var(--radius-md); border: 1.5px solid var(--border);
    background: var(--bg-elev); padding: 0 14px; font-size: 16px; color: var(--fg);
}
.field select { min-height: 48px; }
.row textarea { padding: 12px 14px; min-height: 56px; resize: vertical; line-height: 1.4; }
.row2 { display: flex; gap: 12px; }
.row2 .field { flex: 1; }

.row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.ingredient-row input:nth-child(1) { flex: 0 0 62px; }
.ingredient-row input:nth-child(2) { flex: 0 0 70px; }
.ingredient-row input:nth-child(3) { flex: 1; }
.step-row { align-items: flex-start; }
.step-fields { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.row .step-note-input { min-height: 40px; font-size: 14px; color: var(--accent-ink); }
.removebtn {
    width: 40px; height: 40px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--bg-elev);
    color: var(--fg-muted); display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.addbtn {
    width: 100%; height: 48px; border-radius: var(--radius-md); border: 1.5px dashed var(--border); background: transparent;
    color: var(--accent-ink); font-weight: 700; font-size: 14.5px; display: flex; align-items: center; justify-content: center;
    gap: 8px; margin-top: 2px; margin-bottom: 4px;
}

/* ---------- login ---------- */
.login-screen {
    min-height: calc(100vh - 40px); display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 24px; position: relative;
}
.login-glow {
    position: absolute; top: -60px; right: -80px; width: 260px; height: 260px; border-radius: 50%;
    background: var(--accent-soft); opacity: .5; z-index: -1;
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.icon-tile {
    width: 56px; height: 56px; border-radius: 18px; background: var(--accent); display: flex; align-items: center;
    justify-content: center; box-shadow: 0 8px 20px -8px rgba(0,0,0,.35);
}
.icon-tile span { font-family: var(--font-serif); font-style: italic; font-size: 30px; color: var(--accent-fg); }
.login-tagline { font-size: 13px; color: var(--fg-muted); margin: 0; }
.login-card { width: 100%; max-width: 340px; }
.login-hint { font-size: 12.5px; color: var(--fg-muted); }

/* ---------- account ---------- */
.account-card { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.account-row { display: flex; justify-content: space-between; font-size: 15px; }
.account-label { color: var(--fg-muted); }
.account-value { font-weight: 700; }
.account-link {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; font-weight: 700;
}
.user-card { align-items: center; }
.user-tile { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- cook mode ---------- */
.cook-mode { padding-bottom: 20px; }
.cook-topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.wakelock-status {
    display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent-ink);
    border-radius: 999px; padding: 6px 12px; font-size: 12px; font-weight: 700;
}
.wakelock-status:empty { display: none; }
.cook-progress { border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 6px; }
.cook-recipe-name { font-family: var(--font-serif); font-size: 19px; color: var(--fg-muted); margin: 0 0 12px; }
.bar-track { height: 10px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; margin-bottom: 8px; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width .25s ease; width: 0%; }
.progress-label { font-size: 14px; font-weight: 800; margin: 0; }

.cook-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.cook-list.steps { counter-reset: none; }
.task-row { display: flex; align-items: flex-start; gap: 14px; padding: 14px 2px; border-bottom: 1px solid var(--border); cursor: pointer; }
.cook-list li:last-child .task-row { border-bottom: none; }
.box {
    width: 28px; height: 28px; border-radius: 10px; border: 2px solid var(--border); flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; margin-top: 1px; position: relative;
}
.box input.cook-check { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.check-icon { display: none; }
.task-text { font-size: 19px; font-weight: 600; line-height: 1.35; }
.task-text-step { font-size: 20px; }
.task-col { display: flex; flex-direction: column; gap: 6px; }
.cook-list li.done .box { background: var(--accent); border-color: var(--accent); }
.cook-list li.done .check-icon { display: block; }
.cook-list li.done .task-text { text-decoration: line-through; opacity: .45; }
.cook-list li.done .step-note { opacity: .45; }
