:root {
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #1e2622;
  --muted: #6b7370;
  --line: #e7e1d6;
  --soft: #f1ede4;
  --primary: #2f6b4f;
  --primary-ink: #ffffff;
  --primary-soft: #e3efe8;
  --amber: #b86e12;
  --amber-soft: #fbefdc;
  --good: #2f7d4f;
  --bad: #b53a2e;
  --heart: #d4465c;
  --shadow: 0 1px 2px rgba(30, 38, 34, 0.06), 0 2px 8px rgba(30, 38, 34, 0.04);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714;
    --card: #1b221e;
    --ink: #e9eee9;
    --muted: #9aa49e;
    --line: #2b342f;
    --soft: #232b26;
    --primary: #6fbf94;
    --primary-ink: #0f1712;
    --primary-soft: #1f3329;
    --amber: #f0b45d;
    --amber-soft: #352915;
    --good: #74c995;
    --bad: #f08a7c;
    --heart: #f27b8d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
:root {
  /* side gutters clear the rounded corners / Dynamic Island in landscape */
  --gutter-l: max(16px, env(safe-area-inset-left));
  --gutter-r: max(16px, env(safe-area-inset-right));
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button {
  cursor: pointer; background: none; border: 0; padding: 0; text-align: inherit;
  touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
h2, h3, h4 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 0 6px; }
p { margin: 8px 0; }

.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.pad { padding: 0 2px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; gap: 12px; }
.gap { gap: 8px; }
.right { text-align: right; }
.eyebrow { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.big { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.big .of { font-size: 1.1rem; color: var(--muted); font-weight: 600; }
.mid { font-size: 1.15rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.loading { padding: 40vh 16px 0; text-align: center; color: var(--muted); }

/* ---------- header ---------- */
.top {
  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) + 8px) var(--gutter-r) 8px var(--gutter-l);
  border-bottom: 1px solid var(--line);
}
.weeknav { display: flex; align-items: center; justify-content: space-between; max-width: 640px; margin: 0 auto; }
.wk { text-align: center; }
.wk-dates { font-weight: 700; font-size: 1.1rem; }
.icon {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 1.5rem; line-height: 1; color: var(--ink);
}
.icon.sm { width: 44px; height: 44px; font-size: 1.3rem; color: var(--muted); flex: none; margin-right: -8px; }
@media (hover: hover) {
  .icon:hover { background: var(--soft); }
  .pick:hover { background: var(--soft); }
}
.jump { display: block; margin: 0 auto; font-size: 0.8rem; color: var(--primary); font-weight: 600; padding: 2px 8px; }
.steps { display: flex; justify-content: center; align-items: center; gap: 2px; margin-top: 6px; }
.step { font-size: 0.82rem; font-weight: 600; padding: 7px 11px; border-radius: 99px; color: var(--muted); }
.step.done { color: var(--good); }
.step.now { background: var(--primary); color: var(--primary-ink); }
.step.here:not(.now) { box-shadow: inset 0 0 0 1.5px var(--primary); color: var(--primary); }
.chev { color: var(--line); font-weight: 700; }

/* ---------- layout ---------- */
main {
  max-width: 640px; margin: 0 auto;
  padding: 14px var(--gutter-r) calc(100px + env(safe-area-inset-bottom)) var(--gutter-l);
}
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 14px 16px; margin-bottom: 12px;
}
.card.empty { text-align: center; padding: 28px 20px; }
.login { max-width: 360px; margin: 18vh auto 0; display: grid; gap: 12px; justify-items: center; }
.login img { border-radius: 18px; }
.login input, .login .btn { width: 100%; }
.login input { min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
.card.hero h2 { font-size: 1.5rem; margin-bottom: 4px; }
.card.hero p { color: var(--muted); }
.actions { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  background: var(--soft); color: var(--ink); font-weight: 600; text-align: center;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: transparent; color: var(--bad); }
.btn.done { background: var(--primary-soft); color: var(--good); }
.btn.big { min-height: 52px; font-size: 1.02rem; }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 0.88rem; border-radius: 10px; flex: none; }
.btn.block { width: 100%; margin-top: 10px; }
.link { color: var(--primary); font-weight: 600; font-size: 0.9rem; padding: 12px 0; min-height: 44px; }
.fav { width: 44px; height: 44px; flex: none; border-radius: 50%; font-size: 1.35rem; color: var(--muted); display: grid; place-items: center; margin: -2px -6px; }
.fav.on { color: var(--heart); }
.heart { color: var(--heart); }

.pill { display: inline-block; font-size: 0.74rem; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.today { background: var(--primary); color: var(--primary-ink); }

.meter { height: 10px; background: var(--soft); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.meter span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width 0.3s; }
.meter.over span { background: var(--bad); }

/* ---------- plan ---------- */
.day.soccer { border-left: 4px solid var(--amber); }
.day-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.meal { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.day-h + .meal { border-top: 0; }
.card > .meal:first-child { border-top: 0; }
.slot { width: 68px; flex: none; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.meal-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mname { font-weight: 600; }
.meal.breakfast .mname, .meal.lunch .mname, .meal.dlunch .mname, .mname.soft { font-weight: 500; }
.meta { font-size: 0.8rem; color: var(--muted); }

/* ---------- shop ---------- */
.list h3 { margin-bottom: 4px; }
.item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.list h3 + .item, .list h4 + .item { border-top: 0; }
.chk {
  position: relative; width: 30px; height: 30px; flex: none; border-radius: 50%;
  border: 2px solid var(--line); color: transparent; font-weight: 800; font-size: 0.9rem;
  display: grid; place-items: center;
}
.chk::after { content: ''; position: absolute; inset: -8px; } /* 46px touch area */
.item { min-height: 52px; }
.chk.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.iname { flex: 1; min-width: 0; display: flex; flex-direction: column; font-weight: 500; }
.iname small { color: var(--muted); font-size: 0.78rem; font-weight: 400; }
.price { font-variant-numeric: tabular-nums; font-size: 0.9rem; color: var(--muted); padding: 6px 4px; flex: none; }
button.price { min-height: 44px; min-width: 56px; padding: 6px 0 6px 10px; text-align: right; margin-right: -2px; }
button.price { text-decoration: underline dotted; text-underline-offset: 3px; }
.item.done .iname { text-decoration: line-through; color: var(--muted); }
.item.skip { opacity: 0.5; }
.item.skip .iname { text-decoration: line-through; }
.toggle { flex: none; font-size: 0.85rem; font-weight: 600; padding: 9px 14px; border-radius: 99px; background: var(--soft); color: var(--muted); min-height: 40px; }
.toggle.on { background: var(--amber-soft); color: var(--amber); }
.total { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }

/* ---------- cook ---------- */
.chips {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain;
  /* bleed to the screen edge so the row scrolls under the gutter */
  margin: 0 calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter-l)); padding: 2px var(--gutter-r) 10px var(--gutter-l);
  scroll-padding-inline: var(--gutter-l);
}
.chips.wrap { margin: 0; padding: 2px 0 10px; }
/* Cook tab: all seven days fit across even the narrowest iPhone, no sideways scrolling */
.chips.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; margin: 0; padding: 2px 0 10px; overflow: visible; }
.chips.week .chip { min-width: 0; padding: 10px 0; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  position: relative; flex: none; min-width: 52px; min-height: 44px; padding: 10px 12px;
  border-radius: 12px; background: var(--card); border: 1px solid var(--line);
  font-weight: 600; font-size: 0.9rem; text-align: center;
}
.chip.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.chip.today:not(.on) { border-color: var(--primary); color: var(--primary); }
.chip .dot { position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.chip.on .dot { background: var(--primary-ink); }
.chip .ball { position: absolute; bottom: -6px; right: -4px; font-size: 0.7rem; }
.day-title { display: flex; align-items: baseline; gap: 10px; margin: 8px 2px 12px; }
.mc-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.mc-h h3 { font-size: 1.15rem; margin: 2px 0; }
.mealcard.cooked { border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
.mealcard.breakfast h3, .mealcard.lunch h3, .mealcard.dlunch h3 { font-size: 1rem; }
.recipe { display: grid; gap: 4px; }
@media (min-width: 560px) { .recipe { grid-template-columns: 1fr 1.4fr; gap: 20px; } }
.ing, .steps-list { margin: 0; padding-left: 20px; }
.ing li, .steps-list li { margin: 4px 0; }
.steps-list li::marker { color: var(--primary); font-weight: 700; }
.tip { background: var(--amber-soft); color: var(--ink); padding: 8px 12px; border-radius: 10px; font-size: 0.88rem; }
.note-card p { margin: 4px 0 0; }

.fb { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); display: grid; gap: 10px; }
.fb-q { font-weight: 600; }
.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 44px; border-radius: 9px; font-weight: 600; font-size: 0.88rem; text-align: center; color: var(--muted); padding: 6px 4px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.seg.mini { flex: none; }
.seg.mini button { min-height: 40px; min-width: 44px; padding: 4px 10px; flex: none; }
.seg.wide { margin-bottom: 12px; }
.kid span { font-size: 0.92rem; }
input.note, .search, .field input, .field select, input.num {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); font-size: 16px;
}
.search { margin-bottom: 10px; }

/* ---------- review ---------- */
.delta { font-weight: 700; font-size: 1.05rem; margin: 6px 0 0; }
.rev-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.rev-row:first-of-type { border-top: 0; }
.rev-row.faded .rname { color: var(--muted); }
.rname { flex: 1; min-width: 0; min-height: 44px; display: flex; align-items: center; font-size: 0.92rem; }
.rname b { flex: none; width: 38px; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; }

/* ---------- history / settings ---------- */
.hist { display: block; width: 100%; padding: 10px 0; border-top: 1px solid var(--line); }
.hist:first-child { border-top: 0; }
.hbar { position: relative; height: 8px; background: var(--soft); border-radius: 99px; margin: 6px 0; }
.hbar span { position: absolute; inset: 0 auto 0 0; background: var(--primary); border-radius: 99px; }
.hbar span.over { background: var(--bad); }
.hbar i { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: 0.5; }
.prefix { color: var(--muted); font-weight: 600; }
input.num { max-width: 140px; }
.rules { padding-left: 18px; margin: 6px 0 0; }
.rules li { margin: 4px 0; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 4px var(--gutter-r) max(6px, env(safe-area-inset-bottom)) var(--gutter-l);
}
.tabbar button { flex: 1; max-width: 120px; min-height: 50px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 0.72rem; font-weight: 600; color: var(--muted); text-align: center; }
.tabbar .ti { font-size: 1.3rem; filter: grayscale(1); opacity: 0.7; }
.tabbar button.on { color: var(--primary); }
.tabbar button.on .ti { filter: none; opacity: 1; }

/* ---------- sheets ---------- */
/* --kb is the on-screen keyboard height (set from visualViewport) so sheets ride above it */
.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(10, 14, 12, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: var(--kb, 0px); overscroll-behavior: contain;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 88vh; max-height: calc(88dvh - var(--kb, 0px)); overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 16px var(--gutter-r) calc(20px + env(safe-area-inset-bottom)) var(--gutter-l);
  animation: up 0.18s ease-out;
}
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.sheet-h h3 { font-size: 1.15rem; }
.field { display: grid; gap: 6px; margin: 12px 0; font-weight: 600; font-size: 0.9rem; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; margin: 4px 0; font-size: 16px; cursor: pointer; }
.check input { width: 24px; height: 24px; flex: none; margin: 0; accent-color: var(--primary); }
.picks { display: grid; gap: 2px; }
.pick { display: flex; flex-direction: column; padding: 12px 8px; min-height: 56px; border-radius: 10px; }
.pick.cur { background: var(--primary-soft); }

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

/* Put-it-on-the-plan panel in the recipe sheet */
.place { background: var(--soft); border-radius: 14px; padding: 12px; margin: 10px 0 4px; }
.place .eyebrow { margin: 4px 0 6px; }
.place .row.between { align-items: center; }
.place .btn.block { margin-top: 6px; }
.chip:disabled { opacity: 0.35; }
.warn { color: var(--amber); }
