:root {
  --bg: #EEF2EA;
  --surface: #FFFFFF;
  --surface-2: #F6F9F4;
  --ink: #1F3B2D;
  --ink-2: #557263;
  --line: #D6E0D3;
  --radish: #D33A60;
  --radish-ink: #FFFFFF;
  --radish-soft: #FBE4EA;
  --mustard: #B87F0A;
  --mustard-soft: #FBF0D4;
  --leaf: #2F7D4B;
  --leaf-soft: #E0EFE3;
  --plate: #F2F6EF;
  --shadow: 0 1px 0 rgba(31, 59, 45, .06), 0 8px 24px -14px rgba(31, 59, 45, .35);
  --display: 'Bricolage Grotesque', 'Avenir Next', system-ui, sans-serif;
  --text: 'Atkinson Hyperlegible Next', 'Atkinson Hyperlegible', system-ui, -apple-system, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101B15; --surface: #182820; --surface-2: #1D2F25; --ink: #E5EFE7; --ink-2: #9FB6A8; --line: #2B4034;
    --radish: #F06A8B; --radish-ink: #22050D; --radish-soft: #3B1E28; --mustard: #E8B84A; --mustard-soft: #372D14;
    --leaf: #6CC48D; --leaf-soft: #1E3A28; --plate: #21352A; --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 30px -16px rgba(0,0,0,.8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101B15; --surface: #182820; --surface-2: #1D2F25; --ink: #E5EFE7; --ink-2: #9FB6A8; --line: #2B4034;
  --radish: #F06A8B; --radish-ink: #22050D; --radish-soft: #3B1E28; --mustard: #E8B84A; --mustard-soft: #372D14;
  --leaf: #6CC48D; --leaf-soft: #1E3A28; --plate: #21352A; --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 30px -16px rgba(0,0,0,.8);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.5 var(--text); -webkit-font-smoothing: antialiased;
  padding-bottom: calc(84px + var(--safe-b));
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--radish); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); line-height: 1.1; margin: 0; letter-spacing: -.01em; }

#app { max-width: 760px; margin: 0 auto; padding: 0 16px; }

/* ---------- Boot / login */
.boot { min-height: 80vh; display: grid; place-items: center; }
.boot-plate { font-size: 56px; animation: spin 1.6s ease-in-out infinite; }
@keyframes spin { 50% { transform: rotate(18deg) scale(1.06); } }
.login { min-height: 85vh; display: grid; place-content: center; gap: 18px; text-align: center; max-width: 360px; margin: 0 auto; }
.login h1 { font-size: 44px; }
.login p { color: var(--ink-2); margin: 0; }

/* ---------- Header */
.top { padding: calc(env(safe-area-inset-top, 0px) + 18px) 0 12px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.top h1 { font-size: clamp(30px, 8vw, 40px); font-weight: 800; }
.top .sub { color: var(--ink-2); font-size: 15px; margin-top: 4px; }
.week-nav { display: flex; gap: 6px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: inline-grid; place-items: center; font-size: 18px; flex: none;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.ghost { border-color: transparent; background: transparent; }

/* ---------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--radish); border-color: var(--radish); color: var(--radish-ink); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 15px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn .spinner { width: 18px; height: 18px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Balance strip */
.balance { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 10px; margin: 0 -16px; scrollbar-width: none; }
.balance::-webkit-scrollbar { display: none; }
.gauge {
  flex: none; display: flex; align-items: center; gap: 6px; padding: 6px 12px 6px 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 14px; white-space: nowrap;
}
.gauge b { font-family: var(--display); font-size: 15px; }
.gauge.ok { background: var(--leaf-soft); border-color: transparent; }
.gauge.low, .gauge.high { background: var(--mustard-soft); border-color: transparent; }
.gauge .st { font-size: 12px; color: var(--ink-2); }

/* ---------- Week */
.days { display: grid; gap: 14px; margin-top: 6px; }
.day { background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); padding: 14px 14px 6px; scroll-margin-top: 12px; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 4px 6px; }
.day-name { font-family: var(--display); font-weight: 800; font-size: 22px; }
.day-date { color: var(--ink-2); font-size: 14px; }
.day.today { outline: 2.5px solid var(--radish); }
.today-pill { background: var(--radish); color: var(--radish-ink); font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 8px; vertical-align: 3px; }
.day.past { opacity: .62; }

.meal { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px dashed var(--line); }
.meal:first-of-type { border-top: 0; }
.meal-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 0; text-align: left; }
.plate {
  width: 54px; height: 54px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 28px;
  background: var(--plate); box-shadow: inset 0 0 0 5px var(--surface), inset 0 0 0 6px var(--line);
}
.meal-text { min-width: 0; }
.slot { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.meal-name { font-weight: 700; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; font-size: 13px; color: var(--ink-2); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 1px; }
.meal.muted .meal-name { font-weight: 600; color: var(--ink-2); }
.meal.muted .plate { filter: grayscale(.6); opacity: .8; }
.meal .lock { font-size: 13px; }
.swap-btn { font-size: 20px; }

.empty { text-align: center; padding: 48px 12px; display: grid; gap: 16px; justify-items: center; }
.empty .big { font-size: 64px; }
.empty h2 { font-size: 28px; }
.empty p { color: var(--ink-2); max-width: 34ch; margin: 0; }

.gen-bar { display: flex; gap: 10px; margin: 18px 0 8px; }
.gen-bar .btn { flex: 1; }

/* ---------- Chips / filters */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 8px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px;
  font-size: 15px; font-weight: 600; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; }

/* ---------- Lists (recipes, shopping) */
.search {
  width: 100%; min-height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  padding: 0 16px; margin: 4px 0 10px;
}
.list { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); overflow: hidden; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.list-item:first-child { border-top: 0; }
.list-item .plate { width: 46px; height: 46px; font-size: 24px; }
.grow { flex: 1; min-width: 0; }
.count-line { color: var(--ink-2); font-size: 14px; margin: 6px 4px 10px; }

.aisle { margin-top: 18px; }
.aisle h3 { font-size: 18px; margin: 0 4px 8px; display: flex; align-items: center; gap: 8px; }
.aisle h3 small { font-family: var(--text); font-weight: 400; color: var(--ink-2); font-size: 14px; }
.check-item { display: flex; align-items: flex-start; gap: 14px; padding: 13px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.check-item:first-child { border-top: 0; }
.check-item input { appearance: none; width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--ink-2); flex: none; margin: 0; display: grid; place-items: center; transition: background .15s; }
.check-item input:checked { background: var(--leaf); border-color: var(--leaf); }
.check-item input:checked::after { content: ''; width: 7px; height: 13px; border: solid #fff; border-width: 0 3px 3px 0; transform: translateY(-2px) rotate(45deg); }
.check-item .name { font-weight: 600; line-height: 1.3; }
.check-item .qty { margin-left: auto; font-family: var(--display); font-weight: 700; white-space: nowrap; padding-left: 8px; }
.check-item .for { display: block; font-size: 13px; color: var(--ink-2); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.check-item .grow { min-width: 0; }
.check-item.done .name, .check-item.done .qty { text-decoration: line-through; color: var(--ink-2); opacity: .7; }
.check-item .del { margin-left: auto; }
.progress { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 2px 0 6px; }
.progress span { display: block; height: 100%; background: var(--leaf); border-radius: 999px; transition: width .3s; }
.add-row { display: flex; gap: 8px; margin: 12px 0 4px; }
.add-row input { flex: 1; min-height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; }
details.pantry > summary { list-style: none; cursor: pointer; }
details.pantry > summary::-webkit-details-marker { display: none; }
details.pantry > summary h3::after { content: '＋'; margin-left: auto; font-size: 16px; color: var(--ink-2); }
details.pantry[open] > summary h3::after { content: '－'; }
.pantry-note { color: var(--ink-2); font-size: 14px; margin: -4px 4px 8px; }

/* ---------- Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-b));
}
.tabs a {
  flex: 1; max-width: 160px; display: grid; justify-items: center; gap: 1px; padding: 6px 0; text-decoration: none;
  font-size: 12px; font-weight: 700; color: var(--ink-2); border-radius: 14px; position: relative;
}
.tab-ico { font-size: 22px; line-height: 1.2; filter: grayscale(1); opacity: .7; }
.tabs a[aria-current="page"] { color: var(--ink); }
.tabs a[aria-current="page"] .tab-ico { filter: none; opacity: 1; }
.tabs a[aria-current="page"]::before { content: ''; position: absolute; top: -7px; width: 28px; height: 3px; border-radius: 3px; background: var(--radish); }
.tab-badge { position: absolute; top: 2px; left: 50%; margin-left: 8px; background: var(--radish); color: var(--radish-ink); font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }

/* ---------- Sheets */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 25, 17, .45); z-index: 40; animation: fade .2s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 26px 26px 0 0; padding: 8px 16px calc(24px + var(--safe-b));
  max-width: 760px; margin: 0 auto; animation: up .26s cubic-bezier(.2, .9, .3, 1.1);
}
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.sheet-head h2 { font-size: 26px; flex: 1; }
.sheet-head .plate { width: 64px; height: 64px; font-size: 34px; background: var(--surface); box-shadow: inset 0 0 0 5px var(--bg), inset 0 0 0 6px var(--line); }
.sheet section { margin-top: 18px; }
.sheet h3 { font-size: 19px; margin-bottom: 8px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.card { background: var(--surface); border-radius: 18px; padding: 14px 16px; box-shadow: var(--shadow); }
.ing { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.ing:first-child { border-top: 0; }
.ing .q { font-weight: 700; white-space: nowrap; }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; display: grid; gap: 10px; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 32px 1fr; gap: 10px; background: var(--surface); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); cursor: pointer; }
.steps li::before { content: counter(s); font-family: var(--display); font-weight: 800; font-size: 20px; color: var(--radish); }
.steps li.done { opacity: .5; }
.steps li.done::before { content: '✓'; color: var(--leaf); }
.note { background: var(--leaf-soft); border-radius: 16px; padding: 12px 14px; display: flex; gap: 10px; }
.stepper { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.stepper button { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--surface-2); font-size: 20px; font-weight: 700; }
.stepper b { min-width: 74px; text-align: center; font-size: 15px; }
.menu { display: grid; gap: 8px; }
.menu .btn { justify-content: flex-start; }
.alt-list .list-item { min-height: 66px; }

textarea, .field input, .field select { width: 100%; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); padding: 12px 14px; }
textarea { min-height: 120px; resize: vertical; }
.field { display: grid; gap: 6px; margin-top: 14px; }
.field label, .field .lbl { font-weight: 700; }
.help { color: var(--ink-2); font-size: 14px; margin: 0; }

/* ---------- Settings */
.set-group { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); margin-top: 16px; }
.set-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; padding: 14px 16px; border-top: 1px solid var(--line); }
.set-row .grow { min-width: 180px; }
.set-row:first-child { border-top: 0; }
.set-row .grow b { display: block; }
.set-row .grow span { color: var(--ink-2); font-size: 14px; }
.switch { appearance: none; width: 52px; height: 32px; border-radius: 16px; background: var(--line); position: relative; flex: none; margin: 0; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch:checked { background: var(--leaf); }
.switch:checked::after { transform: translateX(20px); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.slot-grid { display: grid; grid-template-columns: auto repeat(7, 1fr); gap: 6px; align-items: center; padding: 14px 16px; font-size: 13px; }
.slot-grid .h { text-align: center; font-weight: 700; color: var(--ink-2); }
.slot-grid button { aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--line); background: var(--leaf-soft); font-size: 15px; }
.slot-grid button[aria-pressed="false"] { background: var(--surface-2); opacity: .55; }
.excl { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 14px; }
.excl .tag button { border: 0; background: none; padding: 0 0 0 2px; font-size: 16px; line-height: 1; }
.prose { padding: 16px; }
.prose h3 { font-size: 18px; margin: 16px 0 6px; }
.prose h3:first-child { margin-top: 0; }
.prose p, .prose li { color: var(--ink); margin: 0 0 8px; }
.prose ul { padding-left: 20px; margin: 0 0 8px; }
.disclaimer { font-size: 14px; color: var(--ink-2); background: var(--mustard-soft); border-radius: 14px; padding: 12px 14px; margin-top: 12px; }
.section-title { font-size: 22px; margin: 28px 4px 0; }
.suggest { position: relative; }
.suggest-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 5; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); max-height: 240px; overflow-y: auto; }
.suggest-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 14px; border-top: 1px solid var(--line); }

/* ---------- Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 600; box-shadow: var(--shadow);
  width: max-content; max-width: calc(100vw - 32px); display: flex; gap: 16px; align-items: center; justify-content: space-between; animation: up .2s ease;
}
#toast button { background: none; border: 0; color: var(--radish); font-weight: 800; }

@media (min-width: 900px) {
  #app { max-width: 1080px; }
  .days { grid-template-columns: 1fr 1fr; }
  .top h1 { font-size: 44px; }
}
@media print {
  .tabs, .top .week-nav, .gen-bar, .add-row, .icon-btn { display: none !important; }
  body { background: #fff; padding: 0; }
}
