:root {
  --bg: #f6f1e8;
  --surface: #fffdf8;
  --surface-2: #f0e9dc;
  --ink: #1f2a24;
  --muted: #66706a;
  --line: #e2d9c8;
  --brand: #2f5d46;
  --brand-ink: #ffffff;
  --fresh: #2f7a52;
  --fresh-bg: #e3f1e7;
  --slow: #7a4a8c;
  --slow-bg: #f1e6f4;
  --mid: #2f6a8c;
  --mid-bg: #e2eef5;
  --ultra: #c2412d;
  --ultra-bg: #fde6df;
  --hollie: #b4457a;
  --hollie-bg: #fbe7f0;
  --warn: #9a5b00;
  --warn-bg: #fff2d6;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 14px rgba(40, 30, 10, .06);
  --radius: 16px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714;
    --surface: #1a211d;
    --surface-2: #222b26;
    --ink: #ecefe9;
    --muted: #9ba69f;
    --line: #2e3832;
    --brand: #5fae85;
    --brand-ink: #0d1510;
    --fresh: #6cc495;
    --fresh-bg: #1c3327;
    --slow: #c89ad8;
    --slow-bg: #2f2236;
    --mid: #7ab7da;
    --mid-bg: #1b2d38;
    --ultra: #ff8a73;
    --ultra-bg: #3b1f1a;
    --hollie: #f08bb9;
    --hollie-bg: #3a1f2c;
    --warn: #f2c26b;
    --warn-bg: #352a14;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
body.sheet-open { overflow: hidden; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.1rem; }
p { margin: .4rem 0; }
button { font: inherit; color: inherit; }
svg { width: 1em; height: 1em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.15em; flex: none; }
.muted { color: var(--muted); }
.small, small { font-size: .82rem; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── Header ─────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 0; }
.brand > div { min-width: 0; }
.brand h1 { font-size: 1.35rem; }
.week-label { margin: 0; font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.week-line { display: flex; align-items: center; gap: 6px; margin: 0; min-width: 0; }
.sync-pill {
  flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px 1px 6px;
  border: 0; border-radius: 999px; font-size: .72rem; font-weight: 600; cursor: pointer;
  background: var(--surface-2); color: var(--muted);
}
.sync-pill::before, .sync-dot { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; flex: none; }
.sync-pill[data-state="synced"], .sync-status[data-state="synced"] { color: var(--fresh); }
.sync-pill[data-state="local"] { color: var(--hollie); background: var(--hollie-bg); }
.sync-pill[data-state="offline"], .sync-pill[data-state="syncing"] { color: var(--muted); }
.sync-pill[data-state="bad-passcode"], .sync-pill[data-state="error"], .sync-pill[data-state="not-configured"],
.sync-status[data-state="bad-passcode"], .sync-status[data-state="error"], .sync-status[data-state="not-configured"] { color: var(--warn); }
.sync-status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; font-size: .9rem; }
.sync-status b { color: inherit; }
.join-form { display: flex; gap: 8px; }
.join-form input { flex: 1; min-width: 0; min-height: 44px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; }
.week-nav { display: flex; align-items: center; gap: 4px; flex: none; }
@media (max-width: 819px) {
  .app-header { flex-wrap: nowrap; }
  .brand img { width: 28px; height: 28px; }
  .brand h1 { font-size: 1.15rem; }
  .week-nav .btn-icon { min-width: 36px; min-height: 36px; padding: 6px; }
  .week-nav .btn.small { padding: 4px 8px; font-size: .78rem; }
}

.tabs { display: flex; }
.tabs button { border: 0; background: none; cursor: pointer; }
.tabs-top { display: none; }
.tabs-bottom {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  justify-content: space-around;
}
.tabs-bottom button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .75rem; padding: 6px 0; border-radius: 12px; color: var(--muted);
}
.tabs-bottom button span { font-size: 1.3rem; line-height: 1; }
.tabs-bottom button[aria-current="page"] { color: var(--brand); background: var(--surface-2); font-weight: 600; }

@media (min-width: 820px) {
  body { padding-bottom: 32px; }
  .tabs-bottom { display: none; }
  .tabs-top { display: flex; gap: 4px; order: 3; width: 100%; }
  .tabs-top button { padding: 8px 14px; border-radius: 999px; color: var(--muted); font-weight: 500; }
  .tabs-top button[aria-current="page"] { background: var(--ink); color: var(--bg); }
}

/* ── Buttons & controls ─────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink); cursor: pointer;
  font-weight: 500; text-decoration: none;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--ultra); border-color: currentColor; background: transparent; }
.btn-icon { min-width: 40px; padding: 8px; }
.btn-icon.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font-weight: 600; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 2px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative; width: 44px; height: 26px; border-radius: 999px; flex: none;
  background: var(--line); transition: background .2s ease;
}
.switch .thumb {
  position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s ease;
}
.switch input:checked + .track { background: var(--hollie); }
.switch input:checked + .track .thumb { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 3px solid color-mix(in srgb, var(--hollie) 50%, transparent); outline-offset: 2px; }
.switch.small { font-size: .9rem; gap: 8px; }
.switch.small .track { width: 38px; height: 22px; }
.switch.small .thumb { width: 16px; height: 16px; }
.switch.small input:checked + .track .thumb { transform: translateX(16px); }

.search {
  width: 100%; min-height: 44px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink);
  font: inherit;
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: .88rem; white-space: nowrap;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ── Layout ─────────────────────────────────────────── */
.app { max-width: 1280px; margin: 0 auto; padding: 14px 16px 24px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-bottom: 14px; }
.toolbar .btn-primary { min-height: 46px; padding: 10px 18px; font-size: 1rem; }
.toolbar .btn-primary small { opacity: .8; font-weight: 400; }

.move-banner, .import-banner {
  margin: 0 0 12px; padding: 10px 14px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: .95rem;
}
.import-banner { margin: 12px 16px; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: space-between; }
.import-banner .btn-ghost { color: var(--bg); border-color: color-mix(in srgb, var(--bg) 40%, transparent); }

/* ── Board ──────────────────────────────────────────── */
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .board { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .board { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1240px) { .board { grid-template-columns: repeat(4, 1fr); } }

.day {
  --accent: var(--fresh); --accent-bg: var(--fresh-bg);
  position: relative; display: flex; flex-direction: column; gap: 8px;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  border-top: 4px solid var(--accent);
  transition: transform .15s ease, box-shadow .15s ease, outline-color .15s ease;
  outline: 2px solid transparent; outline-offset: 2px;
}
.rule-slow { --accent: var(--slow); --accent-bg: var(--slow-bg); }
.rule-midweek { --accent: var(--mid); --accent-bg: var(--mid-bg); }
.rule-ultra { --accent: var(--ultra); --accent-bg: var(--ultra-bg); }
.day.rule-slow { background: linear-gradient(180deg, var(--slow-bg), var(--surface) 70px); }
.day.rule-ultra { background: linear-gradient(180deg, var(--ultra-bg), var(--surface) 70px); }
.day.is-today { outline-color: var(--accent); }
.day.is-hollie { box-shadow: var(--shadow), inset 3px 0 0 var(--hollie); }
.day.is-source { outline: 3px dashed var(--ink); }
.board.is-moving .day.is-target { cursor: pointer; animation: wiggle .6s ease; }
.board.is-moving .day.is-target:hover { outline: 3px solid var(--accent); }
.day.is-dragging { opacity: .45; }
.day.is-over { outline: 3px solid var(--accent); transform: scale(1.01); }
@keyframes wiggle { 30% { transform: rotate(-.6deg); } 60% { transform: rotate(.6deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.day-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.day-name { display: flex; flex-direction: column; }
.dow { font-family: var(--serif); font-size: 1.2rem; font-weight: 700; }
.date { font-size: .8rem; color: var(--muted); }
.day.is-today .date { color: var(--accent); font-weight: 600; }
.badge {
  flex: none; padding: 4px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700;
  background: var(--accent-bg); color: var(--accent); letter-spacing: .01em; text-align: right;
}
.badge-ultra { background: var(--ultra); color: #fff; }
.badge-slow { background: var(--slow); color: #fff; }
@media (prefers-color-scheme: dark) { .badge-ultra, .badge-slow { color: #140c0a; } }
.day-hint { margin: 0; font-size: .8rem; color: var(--muted); }

.meal, .recipe-row {
  display: flex; flex-direction: column; gap: 3px; width: 100%; text-align: left;
  padding: 10px 12px; border-radius: 12px; border: 1px solid transparent;
  background: var(--surface-2); cursor: pointer;
}
.meal:hover, .recipe-row:hover { border-color: var(--line); }
.cuisine { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--accent, var(--muted)); font-weight: 700; }
.meal-name { font-family: var(--serif); font-size: 1.08rem; font-weight: 600; line-height: 1.25; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: .82rem; color: var(--muted); }
.meta.big { font-size: .9rem; }
.dot { margin: 0 2px; }

.warn { margin: 0; padding: 6px 10px; border-radius: 10px; background: var(--warn-bg); color: var(--warn); font-size: .85rem; font-weight: 500; }
.warn-inline { color: var(--warn); }
.leftover { margin: 0; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: .85rem; }
.hollie-plate { margin: 0; padding: 6px 10px; border-radius: 10px; background: var(--hollie-bg); color: var(--hollie); font-size: .88rem; }
.hollie-plate b { color: inherit; }

.day-actions { display: flex; align-items: center; gap: 6px; margin-top: auto; padding-top: 4px; }
.day-actions .btn { min-height: 36px; padding: 6px 10px; font-size: .88rem; }
.day-actions .btn-icon { margin-left: auto; }
.grip { color: var(--muted); cursor: grab; padding: 4px; font-size: 1.2rem; display: inline-flex; }
.empty {
  padding: 22px 12px; border: 2px dashed var(--line); border-radius: 12px; background: none;
  color: var(--muted); cursor: pointer; font-weight: 600;
}
.empty:hover { border-color: var(--accent); color: var(--accent); }
.foot-hint { color: var(--muted); font-size: .82rem; text-align: center; margin-top: 16px; }

/* ── Shopping ───────────────────────────────────────── */
.shop-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 10px; margin-bottom: 12px; }
.shop-head p { margin: 2px 0 0; font-size: .88rem; }
.shop-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.add-extra { display: flex; gap: 8px; margin-bottom: 14px; }
.add-extra input { flex: 1; min-width: 0; min-height: 44px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; }
.aisles { columns: 1; column-gap: 14px; }
@media (min-width: 820px) { .aisles { columns: 2; } }
@media (min-width: 1180px) { .aisles { columns: 3; } }
.aisle, .staples {
  break-inside: avoid; margin: 0 0 14px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.aisle h3 { display: flex; align-items: center; gap: 8px; font-size: 1rem; margin-bottom: 6px; }
.count { margin-left: auto; font-family: var(--sans); font-size: .78rem; color: var(--muted); font-weight: 500; }
.aisle ul, .staples ul { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item label { flex: 1; display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; cursor: pointer; }
.item input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--brand); flex: none; }
.item-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; }
.amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.note { color: var(--muted); font-size: .82rem; }
.days { width: 100%; font-size: .74rem; color: var(--muted); }
.item.ticked .item-text { opacity: .45; text-decoration: line-through; }
.hollie-item .nm { color: var(--hollie); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: .7rem; font-weight: 700; }
.tag-hollie { background: var(--hollie-bg); color: var(--hollie); }
.staples summary { cursor: pointer; font-weight: 600; padding: 2px 0; }
.staples ul { margin-top: 8px; }
.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); }

/* ── Library ────────────────────────────────────────── */
.lib-head { display: grid; gap: 10px; margin-bottom: 14px; }
.recipe-grid, .picker-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
@media (min-width: 640px) { .recipe-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .recipe-grid { grid-template-columns: repeat(3, 1fr); } }
.recipe-grid .recipe-row { height: 100%; background: var(--surface); border-color: var(--line); padding: 14px; }
.recipe-row.current { outline: 2px solid var(--accent, var(--brand)); }
.pill { padding: 1px 7px; border-radius: 999px; font-size: .7rem; font-weight: 700; }
.pill-fresh { background: var(--fresh-bg); color: var(--fresh); }
.pill-slow { background: var(--slow-bg); color: var(--slow); }
.pill-midweek { background: var(--mid-bg); color: var(--mid); }
.pill-ultra { background: var(--ultra-bg); color: var(--ultra); }

/* ── Sheet (bottom sheet on mobile, dialog on desktop) ─ */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 12, .45); animation: fade .2s ease; }
.sheet-panel {
  position: relative; width: 100%; max-width: 760px; max-height: 92vh; max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.2);
  animation: up .22s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 820px) {
  .sheet { align-items: center; padding: 24px; }
  .sheet-panel { border-radius: 22px; max-height: 88vh; }
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.sheet-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 18px 18px 12px; border-bottom: 1px solid var(--line);
}
.sheet-head.rule-fresh, .sheet-head.rule-slow, .sheet-head.rule-midweek, .sheet-head.rule-ultra { border-top: 5px solid var(--accent); border-radius: 22px 22px 0 0; }
.sheet-head h2 { font-size: 1.3rem; }
.eyebrow { margin: 0 0 4px; font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent, var(--muted)); font-weight: 700; }
.sheet-body { overflow-y: auto; padding: 14px 18px calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 12px; align-content: start; overscroll-behavior: contain; }
.blurb { font-size: 1.02rem; margin: 0; }
.side-note { padding: 10px 12px; border-radius: 12px; background: var(--warn-bg); font-size: .9rem; }
.hollie-card { padding: 12px 14px; border-radius: 14px; background: var(--hollie-bg); border: 1px solid color-mix(in srgb, var(--hollie) 30%, transparent); }
.hollie-card h3 { color: var(--hollie); font-size: 1rem; margin-bottom: 4px; }
.hollie-card p { margin: 4px 0; font-size: .92rem; }
.recipe-cols { display: grid; gap: 16px; }
@media (min-width: 640px) { .recipe-cols { grid-template-columns: 1fr 1.4fr; } }
.recipe-cols h3 { margin-bottom: 8px; }
.ing { list-style: none; margin: 0; padding: 0; font-size: .93rem; }
.ing li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.ing .amt { display: inline-block; min-width: 4.6em; }
.ing .staple { color: var(--muted); }
.ing .reduced .amt { color: var(--hollie); }
.ing .hollie-ing { color: var(--hollie); }
.method { margin: 0; padding-left: 1.3em; display: grid; gap: 10px; font-size: .95rem; }
.method li::marker { font-weight: 700; color: var(--accent, var(--brand)); }
.sheet-actions, .day-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.day-btn { min-width: 64px; }
.day-btn.fits { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.picker-tools { display: grid; gap: 8px; }
.surprise-one { justify-self: start; }
.settings section { display: grid; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.settings section:last-of-type { border-bottom: 0; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper output { min-width: 2ch; text-align: center; font-size: 1.4rem; font-weight: 700; font-family: var(--serif); }

/* ── Toast ──────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: .92rem; box-shadow: var(--shadow);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 820px) { .toast { bottom: 28px; } }

@media print {
  .app-header, .tabs-bottom, .toolbar, .day-actions, .add-extra, .shop-actions, .foot-hint { display: none !important; }
  body { padding: 0; background: #fff; }
  .aisle, .day { box-shadow: none; break-inside: avoid; }
}
