:root {
  --bg: #fbf6ef;
  --surface: #ffffff;
  --surface-2: #f4ece1;
  --text: #2b2118;
  --muted: #74675b;
  --line: #e7dccd;
  --brand: #b4532a;
  --brand-ink: #ffffff;
  --brand-soft: #f6e1d3;
  --accent: #e9a23b;
  --ok: #2f7d4f;
  --ok-soft: #e1f1e6;
  --warn: #a35a00;
  --warn-soft: #fdf0d9;
  --danger: #b3261e;
  --est: #6b5ea8;
  --est-soft: #ebe8f7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.08), 0 2px 8px rgba(60, 40, 20, 0.06);
  --tabbar-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1612;
    --surface: #26201a;
    --surface-2: #30281f;
    --text: #f3ebe1;
    --muted: #b4a796;
    --line: #3d3328;
    --brand: #e07a4c;
    --brand-ink: #1b1612;
    --brand-soft: #4a2d1f;
    --accent: #f0b453;
    --ok: #7ccf98;
    --ok-soft: #1f3a2a;
    --warn: #f0b453;
    --warn-soft: #3d2f15;
    --danger: #ff8a80;
    --est: #b3a7f0;
    --est-soft: #2e2945;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
}
body.sheet-open { overflow: hidden; }
a { color: var(--brand); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0.4rem 0 0.6rem; }
h2 { font-size: 1.15rem; margin: 1.4rem 0 0.4rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.3rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0.4rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.mt { margin-top: 0.8rem; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grow { flex: 1 1 0; min-width: 0; }
.col { display: flex; flex-direction: column; gap: 4px; }
[hidden] { display: none !important; }

/* App bar and tabs */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 1.3rem; color: var(--brand); text-decoration: none; letter-spacing: 0.02em; }
.gear { width: 40px; height: 40px; display: grid; place-items: center; color: var(--muted); }
.gear svg { width: 24px; height: 24px; fill: currentColor; }
.view { max-width: 680px; margin: 0 auto; padding: 8px 16px 24px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 0.75rem; font-weight: 600; }
.tabbar svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar a.active { color: var(--brand); }
.count-badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); font-size: 0.7rem; display: grid; place-items: center; }
.banner { background: var(--warn-soft); color: var(--warn); font-size: 0.85rem; padding: 8px 16px; text-align: center; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--danger); }
.btn.danger:not(.ghost) { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.6; }
.link { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; text-decoration: underline; cursor: pointer; }
.icon { width: 40px; height: 40px; flex: none; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 1rem; cursor: pointer; }
.round { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.round.sm { width: 32px; height: 32px; font-size: 1.1rem; }
label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin: 10px 0 0; }
.field {
  display: block; width: 100%; margin-top: 4px;
  min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 16px;
}
.field.small { font-size: 16px; min-height: 40px; padding: 8px 10px; }
.field.tiny { width: 64px; display: inline-block; margin: 0; min-height: 36px; padding: 6px 8px; }
textarea.field { resize: vertical; }
.field:focus, .btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--text); font-size: 0.95rem; min-height: 40px; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }

/* Chips and tags */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-left: -16px; margin-right: -16px; padding: 0 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 36px; padding: 6px 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 0.9rem; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chip.mini { min-height: 30px; padding: 3px 10px; font-size: 0.8rem; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 0.75rem; padding: 2px 8px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.variant { font-size: 0.75em; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); vertical-align: middle; }

/* Search and recipe cards */
.search-wrap { position: sticky; top: 57px; z-index: 10; background: var(--bg); padding: 6px 0 2px; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); fill: var(--muted); }
.search input { width: 100%; min-height: 48px; padding: 10px 44px 10px 40px; border-radius: 24px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 16px; }
.search input::-webkit-search-cancel-button { display: none; }
.search .clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.hint { font-size: 0.8rem; color: var(--muted); margin: 4px 2px; }
.count { margin: 6px 2px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 12px 14px; margin: 10px 0; }
.recipe-card { display: flex; gap: 12px; padding: 10px; margin: 8px 0; color: inherit; text-decoration: none; }
.thumb { width: 76px; height: 76px; flex: none; border-radius: 10px; object-fit: cover; }
.ph { display: grid; place-items: center; background: hsl(var(--h) 55% 82%); color: hsl(var(--h) 45% 30%); font-weight: 800; font-size: 1.8rem; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .ph { background: hsl(var(--h) 30% 28%); color: hsl(var(--h) 60% 80%); } }
.rc-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.rc-title { font-weight: 700; font-size: 1.05rem; }
.match { color: var(--ok); }
.match .miss { color: var(--muted); }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }

/* Recipe page */
.topbar { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.back { text-decoration: none; font-weight: 600; }
.hero-img { width: calc(100% + 32px); margin: 4px -16px 8px; height: 190px; object-fit: cover; display: block; }
.hero-img.ph { display: grid; height: 96px; font-size: 3rem; }
@media (min-width: 700px) { .hero-img { width: 100%; margin: 4px 0 8px; border-radius: var(--radius); } }
.lead { color: var(--muted); }
.meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.92rem; margin: 6px 0; }
.serves { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0; font-weight: 600; }
.serves b { min-width: 24px; text-align: center; font-size: 1.2rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.actions .btn.primary { flex: 1; }
.versions { margin: 6px 0; }
.ings { list-style: none; margin: 0; padding: 0; }
.ing { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 8px 4px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.ing .amt { flex: none; width: 74px; font-weight: 700; color: var(--brand); }
.ing .nm { flex: 1; min-width: 0; }
.ing .note { color: var(--muted); }
.ing .swapped { display: block; font-size: 0.8rem; color: var(--est); }
.ing .chev { color: var(--muted); font-size: 1.3rem; }
.warn { color: var(--warn); }
.steps { padding-left: 1.4rem; }
.steps li { padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.steps li.done { color: var(--muted); text-decoration: line-through; }
.draftbar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 25;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: flex-end;
  padding: 10px 16px; background: var(--est-soft); border-top: 1px solid var(--line); font-size: 0.9rem;
}
.draftbar span { flex: 1 1 100%; font-weight: 600; }

/* Sheets */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(20, 12, 5, 0); transition: background 0.2s; display: flex; align-items: flex-end; justify-content: center; }
.sheet.open { background: rgba(20, 12, 5, 0.45); }
.sheet-panel { position: relative; width: 100%; max-width: 680px; max-height: 88vh; background: var(--bg); border-radius: 18px 18px 0 0; transform: translateY(100%); transition: transform 0.2s ease-out; display: flex; flex-direction: column; }
.sheet.open .sheet-panel { transform: none; }
#sheet-body { overflow-y: auto; padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
#sheet-body h2 { margin-top: 0; padding-right: 40px; }
.sheet-close { position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--text); font-size: 1.4rem; cursor: pointer; z-index: 2; }
.menu { display: flex; flex-direction: column; }
.menu button { min-height: 52px; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); font: inherit; padding: 0 4px; cursor: pointer; }
.menu button.danger { color: var(--danger); }
.alert { background: var(--warn-soft); color: var(--warn); padding: 8px 12px; border-radius: 10px; font-size: 0.9rem; }
.alert.soft { background: var(--surface-2); color: var(--text); }
.subs { list-style: none; padding: 0; margin: 0; }
.subs li { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.prices { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.price-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.price-row.cheapest { border-color: var(--ok); box-shadow: inset 0 0 0 1px var(--ok); }
.price-row.warned { opacity: 0.75; }
.pr-price { text-align: right; }
.pr-price b { font-size: 1.1rem; }
.pr-foot { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.pr-foot .need { margin-left: auto; font-weight: 600; }
.warn-text { flex-basis: 100%; color: var(--warn); }
.badge { font-size: 0.72rem; font-weight: 700; padding: 1px 7px; border-radius: 8px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.you { background: var(--brand-soft); color: var(--brand); }
.badge.est { background: var(--est-soft); color: var(--est); }
.badge.best { background: var(--ok); color: #fff; }
.history { list-style: none; padding: 0; }
.history li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.pick { list-style: none; padding: 0; margin: 8px 0; }
.pick li { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.pick li .check { flex: 1; }

/* Editor */
.editor h2 { margin-top: 1.6rem; }
.ing-row { padding: 10px; margin: 8px 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); display: flex; flex-direction: column; gap: 6px; }
.ing-row .field { margin-top: 0; }
.ing-row .qty { width: 72px; flex: none; }
.ing-row .unit { width: 92px; flex: none; padding-left: 6px; padding-right: 2px; }
.step-row { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; }
.step-row .num { width: 22px; flex: none; padding-top: 12px; font-weight: 700; color: var(--brand); }
.step-row .field { margin-top: 0; }
.photo-edit { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.photo-edit img { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; }
.photo-edit label { margin: 0; color: var(--text); }
.savebar { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); display: flex; gap: 8px; padding: 12px 0; background: var(--bg); margin-top: 16px; border-top: 1px solid var(--line); }

/* Add page */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.seg button { min-height: 40px; border: 0; border-radius: 9px; background: none; color: var(--muted); font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.add-body { margin-top: 12px; }
.busy { display: flex; gap: 10px; align-items: center; margin-top: 14px; color: var(--muted); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: spin 0.8s linear infinite; margin: 0 auto; }
.busy .spinner { margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Shopping list */
.recipes-sum { display: flex; width: 100%; align-items: baseline; justify-content: space-between; gap: 12px; padding: 0; border: 0; background: none; color: var(--text); font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
.recipes-sum .link { flex: none; }
.list-recipes { list-style: none; padding: 0; margin: 6px 0 0; }
.list-recipes li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.list-recipes li a { flex: 1; min-width: 0; font-weight: 600; text-decoration: none; }
.mini-step { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.add-item { display: flex; gap: 8px; margin: 10px 0; }
.add-item .field { margin: 0; }
.totals .big-total { font-size: 1.15rem; margin: 6px 0 2px; }
.totals .big-total b { color: var(--ok); }
.tot { margin-top: 8px; }
.tot-row { padding: 8px 0; border-top: 1px solid var(--line); }
.tot-main { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; }
.tot-main b { white-space: nowrap; }
.tot-row.best .tot-main { color: var(--ok); }
.tot-sub { margin: 14px 0 2px; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.list-tools { margin: 10px 2px 0; }
.aisle h3 { margin-top: 1.2rem; }
.line { display: flex; align-items: stretch; gap: 8px; border-bottom: 1px solid var(--line); }
.tick { flex: none; width: 34px; height: 34px; margin: 10px 0; border-radius: 9px; border: 2px solid var(--muted); background: var(--surface); color: #fff; font-weight: 800; font-size: 1.1rem; cursor: pointer; }
.line.ticked .tick { background: var(--ok); border-color: var(--ok); }
.line.ticked .ln, .line.ticked .la { text-decoration: line-through; color: var(--muted); }
.line-main { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 8px 0; border: 0; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.ln { font-weight: 600; }
.la { font-size: 0.9rem; }
.lp { color: var(--ok); }
.havebtn { flex: none; align-self: center; min-height: 34px; padding: 4px 10px; border-radius: 17px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font: inherit; font-size: 0.8rem; cursor: pointer; }
.line.have { opacity: 0.75; }
.line.have .line-main { padding-left: 4px; }
.h3btn { display: block; width: 100%; margin-top: 1.2rem; padding: 8px 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: 0.95rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; text-align: left; cursor: pointer; }

/* Shops */
.shop.unused { opacity: 0.6; }
.shop .small { margin-top: 3px; }
.howto { padding-left: 1.2rem; }
.howto li { margin: 6px 0; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); z-index: 60; transform: translate(-50%, 20px); max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 0.9rem; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Accounts */
.auth { max-width: 420px; margin: 0 auto; padding: 8px 0 24px; }
.auth-logo { font-size: 2.2rem; font-weight: 800; color: var(--brand); margin: 12px 0 4px; }
.auth h1 { margin-top: 4px; }
.auth form label { display: block; font-weight: 600; margin-bottom: 10px; }
.auth form .field { margin-top: 4px; }
.error { color: var(--warn); font-weight: 600; }
.center { text-align: center; }
.banner a { color: inherit; font-weight: 700; }
.note { padding: 4px 2px 8px; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1.1rem; line-height: 1.55; margin: 12px 0; padding: 16px; border-radius: var(--radius); background: var(--warn-soft); }
.admin-list { list-style: none; padding: 0; margin: 6px 0 12px; }
.admin-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.admin-list li.col { flex-direction: column; align-items: stretch; }
.note-preview { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); max-height: 6.5em; overflow: hidden; }
.note-form label { display: block; margin-top: 8px; font-weight: 600; }
.note-form textarea { min-height: 120px; resize: vertical; }
.note-form .btn { margin-top: 8px; }
