:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --border: #e2ddd3;
  --text: #1f2421;
  --muted: #6b716c;
  --accent: #2f7d4f;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1e8;
  --ok: #2f7d4f;
  --ok-soft: #e3f1e8;
  --warn: #a55b00;
  --warn-soft: #fbeedb;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --idle: #8a8f8b;
  --idle-soft: #ecebe7;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 14px;
  --tabbar: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141715; --surface: #1d211f; --surface-2: #252a27; --border: #323833;
    --text: #e8ebe8; --muted: #9aa29c; --accent: #5cc08a; --accent-ink: #0d1a12;
    --accent-soft: #1f3a2a; --ok: #5cc08a; --ok-soft: #1f3a2a; --warn: #e8a54b; --warn-soft: #3a2c17;
    --bad: #f07b72; --bad-soft: #3d2120; --idle: #8a918c; --idle-soft: #2a2f2c;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141715; --surface: #1d211f; --surface-2: #252a27; --border: #323833;
  --text: #e8ebe8; --muted: #9aa29c; --accent: #5cc08a; --accent-ink: #0d1a12;
  --accent-soft: #1f3a2a; --ok: #5cc08a; --ok-soft: #1f3a2a; --warn: #e8a54b; --warn-soft: #3a2c17;
  --bad: #f07b72; --bad-soft: #3d2120; --idle: #8a918c; --idle-soft: #2a2f2c;
  --shadow: 0 1px 2px rgba(0,0,0,.4); 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 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ic { display: contents; }
.ic > svg { width: 22px; height: 22px; flex: none; }

/* ---------- layout */
#app { max-width: 760px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--tabbar) + var(--safe-bottom) + 24px); }
.topbar {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 10px; display: flex; align-items: center; gap: 10px;
}
.topbar h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: 4px 16px 16px; }
.section { margin-top: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 2px 8px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 14px; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list > .item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 52px; border-top: 1px solid var(--border); }
.list > .item:first-child { border-top: 0; }
.list > .item.tap { cursor: pointer; }
.list > .item.tap:active { background: var(--surface-2); }
.item .title { font-weight: 560; }
.item .sub { font-size: .85rem; color: var(--muted); }
.empty { padding: 22px 16px; text-align: center; color: var(--muted); }

/* ---------- tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border); padding-bottom: var(--safe-bottom);
}
.tabbar nav { max-width: 760px; margin: 0 auto; display: grid; grid-template-columns: repeat(6, 1fr); height: var(--tabbar); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .68rem; font-weight: 560; border: 0; background: none; padding: 0; }
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }
.tab.scan span.bubble { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: var(--shadow); margin-top: -6px; }
.tab .badge { position: absolute; transform: translate(12px, -10px); background: var(--bad); color: #fff; border-radius: 9px;
  font-size: .65rem; min-width: 18px; height: 18px; line-height: 18px; text-align: center; padding: 0 5px; }
.tab .icon-wrap { position: relative; display: grid; place-items: center; }

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .88rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 0; background: transparent; cursor: pointer; color: var(--text); flex: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

.field { display: block; }
.field > span { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin: 0 2px 5px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); outline: none; font-size: 16px;
}
textarea.input { min-height: 110px; resize: vertical; line-height: 1.4; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.search { position: relative; }
.search .input { padding-left: 38px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.check { display: flex; gap: 10px; align-items: center; min-height: 40px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 7px 13px; font-size: .88rem; font-weight: 560; cursor: pointer; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 8px 6px; border-radius: 9px; font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 9px; font-size: .75rem; font-weight: 650; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.idle { background: var(--idle-soft); color: var(--idle); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--idle); }
.dot.have, .dot.staple { background: var(--ok); }
.dot.short { background: var(--warn); }
.dot.missing { background: var(--bad); }
.dot.unlinked { background: transparent; border: 2px dashed var(--idle); }

.stars { display: inline-flex; gap: 2px; }
.stars button { border: 0; background: none; padding: 4px 2px; cursor: pointer; color: var(--border); font-size: 1.5rem; line-height: 1; }
.stars button.on { color: #e0a100; }
.stars.static span { color: #e0a100; font-size: .85rem; letter-spacing: -1px; }

.fab {
  position: fixed; right: max(16px, calc(50vw - 380px + 16px)); bottom: calc(var(--tabbar) + var(--safe-bottom) + 16px); z-index: 15;
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 6px 20px rgba(0,0,0,.2); display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- recipes */
.recipe-card { display: flex; gap: 12px; padding: 10px; align-items: center; }
.thumb { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; flex: none; background: var(--surface-2);
  display: grid; place-items: center; font-weight: 700; font-size: 1.4rem; color: var(--muted); }
.hero { width: 100%; max-height: 260px; object-fit: cover; border-radius: var(--radius); display: block; }
.ing { display: flex; gap: 12px; align-items: flex-start; padding: 11px 14px; border-top: 1px solid var(--border); cursor: pointer; }
.ing:first-child { border-top: 0; }
.ing .dot { margin-top: 7px; }
.steps { padding-left: 0; list-style: none; margin: 0; counter-reset: s; }
.steps li { position: relative; padding: 10px 0 10px 40px; border-top: 1px solid var(--border); }
.steps li:first-child { border-top: 0; }
.steps li::before { counter-increment: s; content: counter(s); position: absolute; left: 0; top: 10px; width: 28px; height: 28px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; font-size: .85rem; }
.steps li.head { padding-left: 0; font-weight: 700; }
.steps li.head::before { display: none; counter-reset: s; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.stepper button { width: 40px; height: 40px; border: 0; background: none; font-size: 1.2rem; cursor: pointer; }
.stepper span { min-width: 64px; text-align: center; font-weight: 600; }

/* ---------- plan */
.day { margin-top: 14px; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 2px 6px; }
.day-head .today { color: var(--accent); }
.meal { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-top: 1px solid var(--border); }
.meal:first-child { border-top: 0; }
.meal .slot { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.meal.cooked .title { text-decoration: line-through; color: var(--muted); }

/* ---------- shopping */
.shop-item { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--border); min-height: 56px; }
.shop-item:first-child { border-top: 0; }
.shop-item .box { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--border); background: var(--surface); flex: none; cursor: pointer; display: grid; place-items: center; }
.shop-item.checked .box { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.shop-item.checked .title { text-decoration: line-through; color: var(--muted); }
.aisle-head { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--muted); margin: 18px 4px 6px; }

/* ---------- pantry */
.qty { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.qty.zero { color: var(--bad); }
.qty.low { color: var(--warn); }
.mini { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-size: 1.2rem; line-height: 1; cursor: pointer; flex: none; }
.bignum { font-size: 2rem; font-weight: 750; letter-spacing: -.02em; }

/* ---------- sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; opacity: 0; transition: opacity .18s; }
.scrim.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 640px; margin: 0 auto;
  background: var(--bg); border-radius: 20px 20px 0 0; max-height: 92vh; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .22s cubic-bezier(.2,.8,.2,1); box-shadow: 0 -8px 30px rgba(0,0,0,.2);
}
.sheet.show { transform: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 10px 8px 18px; }
.sheet-head h2 { flex: 1; font-size: 1.1rem; }
.sheet-body { overflow-y: auto; padding: 4px 18px calc(18px + var(--safe-bottom)); -webkit-overflow-scrolling: touch; }
@media (min-width: 700px) { .sheet { bottom: auto; top: 50%; border-radius: 20px; transform: translateY(-40%) scale(.98); opacity: 0; }
  .sheet.show { transform: translateY(-50%); opacity: 1; } }

/* ---------- toast */
.toasts { position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top, 0px) + 10px); z-index: 60; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow);
  display: flex; gap: 12px; align-items: center; max-width: 520px; font-size: .92rem; animation: pop .18s ease-out; }
.toast.error { background: var(--bad); color: #fff; }
.toast button { background: none; border: 0; color: inherit; font-weight: 750; text-decoration: underline; cursor: pointer; padding: 4px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- scanner */
.scanner { position: fixed; inset: 0; z-index: 30; background: #000; color: #fff; display: flex; flex-direction: column; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; left: 8%; right: 8%; top: 32%; height: 22%; border: 3px solid rgba(255,255,255,.9); border-radius: 16px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; }
.scanner .frame.hit { border-color: #5cc08a; }
.scanner .frame::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: rgba(255,80,80,.8); }
.scanner .top, .scanner .bottom { position: relative; z-index: 2; padding: 14px 16px; }
.scanner .top { padding-top: calc(env(safe-area-inset-top, 0px) + 12px); display: flex; gap: 8px; align-items: center; }
.scanner .bottom { margin-top: auto; padding-bottom: calc(var(--safe-bottom) + 16px); background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.scanner .icon-btn { color: #fff; background: rgba(0,0,0,.35); }
.scanner .seg { background: rgba(0,0,0,.45); }
.scanner .seg button { color: #ddd; }
.scanner .seg button.on { background: #fff; color: #111; }
.scanner .hint { text-align: center; font-size: .9rem; opacity: .9; margin: 8px 0; text-shadow: 0 1px 3px #000; }
.scanner .input { background: rgba(255,255,255,.95); color: #111; }
.scanner .check { color: #fff; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; margin-bottom: 14px; }
.logo svg { width: 32px; height: 32px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
pre { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; overflow-x: auto; white-space: pre; }
.token { word-break: break-all; background: var(--surface-2); padding: 10px; border-radius: 10px; font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
