:root {
  --bg: #f6f7f5; --surface: #fff; --text: #1c2321; --muted: #5d6b67; --border: #dde3e0;
  --accent: #0f766e; --accent-ink: #fff; --accent-soft: #e0f2ef; --warn: #b45309; --warn-soft: #fef3c7;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615; --surface: #1a2120; --text: #e7ecea; --muted: #9aa8a4; --border: #2c3634;
    --accent: #2dd4bf; --accent-ink: #062b27; --accent-soft: #123430; --warn: #fbbf24; --warn-soft: #3a2d0f;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
header { padding: calc(16px + env(safe-area-inset-top)) 16px 8px; max-width: 720px; margin: auto; }
h1 { margin: 0; font-size: 1.4rem; }
h3 { margin: 0 0 8px; font-size: 1.05rem; }
.muted { color: var(--muted); }
#status { margin: 4px 0 0; font-size: .9rem; }

nav { display: flex; gap: 4px; max-width: 720px; margin: 8px auto 0; padding: 0 16px; position: sticky; top: 0; background: var(--bg); z-index: 1; }
nav button { flex: 1; border: 0; background: none; color: var(--muted); padding: 10px 4px; font: inherit; font-weight: 600; border-bottom: 3px solid transparent; cursor: pointer; }
nav button[aria-selected="true"] { color: var(--accent); border-color: var(--accent); }

main { max-width: 720px; margin: auto; padding: 16px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.row input { flex: 1; min-width: 0; }
input, textarea, button, .file {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
textarea { width: 100%; resize: vertical; }
button, .file { cursor: pointer; font-weight: 600; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: .6; cursor: progress; }
input[type=range] { width: 100%; padding: 0; accent-color: var(--accent); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin: 16px 0; }
.card p { margin: 4px 0 8px; }

#items { list-style: none; padding: 0; margin: 8px 0; }
#items li { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; margin-bottom: 6px; }
#items li input { flex: 1; border: 0; padding: 6px 0; background: none; }
#items li button { border: 0; background: none; color: var(--muted); padding: 6px; font-size: 1.1rem; }

.group h2 { font-size: 1rem; margin: 20px 0 8px; }
.deal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; }
.deal-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.price { font-size: 1.35rem; font-weight: 700; color: var(--accent); }
.price s { font-size: .85rem; color: var(--muted); font-weight: 400; margin-inline-start: 6px; }
.chain { font-weight: 600; }
.product { margin-top: 2px; }
.desc { font-size: .9rem; }
.meta { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: .9rem; }
.until { background: var(--accent-soft); border-radius: 6px; padding: 1px 8px; }
.until.soon { background: var(--warn-soft); color: var(--warn); }
.badge { white-space: nowrap; display: inline-block; font-size: .75rem; border: 1px solid var(--border); border-radius: 6px; padding: 0 6px; margin-inline-start: 6px; color: var(--muted); }
.empty { text-align: center; padding: 32px 8px; }
#chains label { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
details { margin-top: 16px; font-size: .9rem; color: var(--muted); }

.small { font-size: .85rem; margin: 2px 0 0; }
.toggle { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; }
.toggle input { margin-top: 5px; accent-color: var(--accent); }
.desc a { color: var(--accent); }
#toast {
  position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); left: 16px; right: 16px; max-width: 520px; margin: auto;
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; z-index: 5; box-shadow: 0 4px 16px rgb(0 0 0 / .2);
}

body.logged-out header, body.logged-out nav, body.logged-out main { display: none; }
body:not(.logged-out) #login { display: none; }
#login { max-width: 420px; margin: 0 auto; padding: calc(32px + env(safe-area-inset-top)) 16px; }
#login h1 { margin-bottom: 4px; }
label { display: block; margin: 8px 0; }
[hidden] { display: none !important; }
label > input:not([type=checkbox]):not([type=range]):not([type=file]) { display: block; width: 100%; margin-top: 4px; }
form > button { margin-top: 8px; }
.error { color: #b91c1c; }
@media (prefers-color-scheme: dark) { .error { color: #fca5a5; } }
#family { list-style: none; padding: 0; margin: 8px 0; }
#family li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
#family li .who { flex: 1; min-width: 0; }
#family li .acts { display: flex; gap: 6px; }
#family li button { padding: 6px 10px; font-size: .9rem; }

.food { font-size: 1.5rem; line-height: 1; width: 2rem; text-align: center; flex: none; }
.hero { text-align: center; margin: 0 0 8px; }
.hero svg { width: 100%; max-width: 260px; height: auto; display: block; margin: 0 auto; }
.hero p { margin: 0; font-weight: 600; color: var(--muted); }
.h-shadow { fill: var(--border); }
.h-bag { fill: var(--accent); }
.h-handle { fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round; }
.h-milk { fill: #e8f1fb; stroke: #7aa7d6; stroke-width: 2; }
.h-milk-top { fill: #7aa7d6; }
.h-apple { fill: #e5484d; }
.h-stem { fill: none; stroke: #2f855a; stroke-width: 3; stroke-linecap: round; }
.h-baguette { fill: #d9a35b; }
.h-tag { fill: #fbbf24; }
.h-hole { fill: var(--bg); }
.h-pct { font: 700 22px system-ui, sans-serif; fill: #7c2d12; }
.h-spark { fill: #fbbf24; }

#report { margin-top: 16px; }
#report summary { font-weight: 600; cursor: pointer; color: var(--text); }
#report h4 { margin: 12px 0 4px; font-size: .95rem; }
#report p { margin: 6px 0; }
.report-list { margin: 0; padding-inline-start: 18px; }
.report-list li { margin: 4px 0; }
.warn { color: var(--warn); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#gear {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 8px 12px; border-radius: 999px; font-size: .95rem; color: var(--muted);
}
#gear svg { width: 20px; height: 20px; fill: currentColor; transition: transform .3s; }
#gear:hover svg { transform: rotate(45deg); }
#gear[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
@media (max-width: 360px) { #gear span { display: none; } }

.count { display: inline-block; min-width: 1.4em; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .75rem; line-height: 1.4em; }
#homeList { list-style: none; padding: 0; margin: 8px 0; }
.homeitem { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; margin-bottom: 6px; }
.homeitem .check { flex: none; width: 30px; height: 30px; padding: 0; border-radius: 50%; border: 2px solid var(--accent); background: none; color: var(--accent-ink); font-size: 1rem; }
.homeitem.done .check { background: var(--accent); }
.hbody { flex: 1; display: flex; align-items: center; gap: 8px; cursor: pointer; min-width: 0; }
.htext { display: flex; flex-direction: column; min-width: 0; font-size: 1.05rem; }
.htext small { font-size: .8rem; }
.homeitem.done .htext > span:first-child { text-decoration: line-through; color: var(--muted); }
.homeitem.done .food { opacity: .5; }
.onsale { color: var(--warn); font-weight: 600; }
.mini { flex: none; border: 0; background: none; padding: 6px; font-size: 1rem; color: var(--muted); }
nav button { font-size: .95rem; line-height: 1.25; }
#family li .acts { flex-wrap: wrap; }

.voice-row { margin-top: 0; }
.voice-row button { padding: 8px 12px; }
button.live { background: #dc2626; border-color: #dc2626; color: #fff; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .75; } }
.mini.play { font-size: 1.1rem; color: var(--accent); }
