:root {
  color-scheme: light dark;
  /* cool fridge-liner neutrals, produce colours for urgency */
  --bg: #EDF2EF;
  --surface: #FFFFFF;
  --ink: #14211C;
  --muted: #586860;
  --line: #D5DED9;
  --leaf: #1F7A45;
  --turmeric: #F0B429;
  --chilli: #C9301C;
  --aubergine: #5B3350;
  --on-turmeric: #2A1F00;
  --radius: 14px;
  --pad: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1A16;
    --surface: #18261F;
    --ink: #E6EFEA;
    --muted: #9BADA4;
    --line: #2A3B33;
    --leaf: #2C9A5B;
    --chilli: #DE4A33;
    --aubergine: #8A5479;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0 auto;
  max-width: 560px;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 calc(96px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--ink);
  font: 500 16px/1.4 'Be Vietnam Pro', system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button, input { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* ---------- header ---------- */
.top { padding: 20px var(--pad) 4px; }
h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; }
#status { color: var(--muted); font-size: 15px; min-height: 21px; }
#status.offline { color: var(--ink); }
#filters { display: flex; gap: 8px; overflow-x: auto; margin: 14px calc(-1 * var(--pad)) 0; padding: 0 var(--pad) 4px; scrollbar-width: none; }
#filters button { flex: none; min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1.5px solid var(--line); font-size: 15px; white-space: nowrap; }
#filters button span { color: var(--muted); }
#filters button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
#filters button[aria-pressed="true"] span { color: inherit; }

/* ---------- the eat-first list ---------- */
section { --tone: var(--leaf); --on-tone: #fff; margin-top: 22px; }
section.lvl-soon { --tone: var(--turmeric); --on-tone: var(--on-turmeric); }
section.lvl-now { --tone: var(--chilli); }
section.lvl-overdue { --tone: var(--aubergine); }
section h2 { padding: 0 var(--pad) 8px; font-size: 15px; font-weight: 800; }
section ul { background: var(--surface); border-block: 1px solid var(--line); }
section li { display: flex; align-items: center; }
section li + li { border-top: 1px solid var(--line); }

.main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; padding: 10px 0 10px var(--pad); text-align: left; }
.tile {
  flex: none; width: 64px; height: 64px; border-radius: var(--radius);
  display: grid; place-content: center; text-align: center;
  background: var(--tone); color: var(--on-tone);
}
.tile b { font-size: 30px; font-weight: 800; line-height: 1; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.tile small { font-size: 12px; line-height: 1.3; }
.what { min-width: 0; display: grid; gap: 2px; }
.name { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wet { font-size: 13px; }
.where { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.freeze { flex: none; min-height: 40px; padding: 0 12px; border-radius: 20px; border: 1.5px solid var(--ink); font-size: 14px; font-weight: 800; }
.amount { flex: none; width: 60px; height: 84px; display: grid; place-content: center; gap: 4px; }
.amount i { display: block; width: 26px; height: 8px; border-radius: 4px; background: var(--ink); }
.amount[data-amount="2"] i:nth-child(1),
.amount[data-amount="1"] i:nth-child(-n+2) { background: none; box-shadow: inset 0 0 0 1.5px var(--line); }

.empty { margin: 56px var(--pad); display: grid; gap: 8px; }
.empty p:first-child { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.empty p + p { color: var(--muted); max-width: 30ch; }

/* ---------- bottom bar and buttons ---------- */
.bar {
  position: fixed; bottom: 0; left: 50%; translate: -50% 0; width: 100%; max-width: 560px;
  display: flex; gap: 10px; padding: 12px var(--pad) calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.bar .primary { flex: 1; }
.primary, .danger, .quiet { min-height: 56px; padding: 0 20px; border-radius: 28px; font-weight: 800; }
.primary { background: var(--ink); color: var(--bg); font-size: 18px; }
.danger { background: var(--chilli); color: #fff; font-size: 18px; }
.quiet { border: 1.5px solid var(--line); background: var(--surface); }
.sheet-head .quiet { min-height: 44px; }
.wide { width: 100%; margin-top: 20px; font-weight: 500; color: var(--muted); }

/* ---------- sheets ---------- */
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0; overflow-y: auto;
  padding: 18px var(--pad) calc(20px + env(safe-area-inset-bottom));
  border: 0; border-radius: 22px 22px 0 0; background: var(--bg); color: var(--ink);
}
/* The keyboard would cover a bottom sheet's input, so sheets you type in first hang from the top. */
#add, #login { margin: 0 auto auto; border-radius: 0 0 22px 22px; padding-top: calc(18px + env(safe-area-inset-top)); }
/* Opening a sheet focuses the sheet itself, not its first button. */
.sheet:focus-visible { outline: none; }
.sheet::backdrop { background: rgb(8 16 12 / 0.55); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-head h2 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.field { display: grid; gap: 6px; }
.field span, .label { font-size: 14px; color: var(--muted); }
.label { margin: 18px 0 8px; }
.field input {
  width: 100%; min-height: 54px; padding: 0 14px; border-radius: var(--radius);
  border: 1.5px solid var(--line); background: var(--surface); font-size: 18px;
}
.field input:focus { outline: none; border-color: var(--ink); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.note { margin-top: 14px; color: var(--muted); font-size: 15px; min-height: 21px; }

.picks { display: grid; margin-top: 8px; }
.picks button { min-height: 50px; padding: 0 6px; text-align: left; font-size: 18px; border-bottom: 1px solid var(--line); }
.picks.recent { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.picks.recent button { min-height: 44px; padding: 0 14px; border: 1.5px solid var(--line); border-radius: 22px; background: var(--surface); font-size: 16px; }

.comps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.comps button, .seg button {
  min-height: 56px; padding: 4px 6px; border-radius: var(--radius);
  border: 1.5px solid var(--line); background: var(--surface); font-size: 15px; line-height: 1.2;
}
.comps button.suggested { border-color: var(--ink); border-width: 2.5px; font-weight: 800; }
.comps button[aria-pressed="true"], .seg button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); font-weight: 800; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#login-form { display: grid; }
#add-days { display: grid; gap: 12px; margin-top: 16px; }

/* ---------- waste ---------- */
.headline { margin: 22px 0 6px; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.headline b { color: var(--chilli); }
#stats h3 { margin: 26px 0 10px; font-size: 15px; font-weight: 800; }
.bars { display: grid; gap: 12px; }
.bars li { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; }
.bar-count { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.bar-track { grid-column: 1 / -1; height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.bar-track span { display: block; height: 100%; border-radius: 5px; background: var(--chilli); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; translate: -50% 0; bottom: calc(92px + env(safe-area-inset-bottom));
  width: calc(100% - 2 * var(--pad)); max-width: 528px; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; padding: 6px 8px 6px 18px; border-radius: var(--radius);
  background: var(--ink); color: var(--bg);
}
#toast button { min-height: 44px; padding: 0 16px; border-radius: 22px; border: 1.5px solid currentColor; font-weight: 800; }
dialog #toast { bottom: calc(16px + env(safe-area-inset-bottom)); }

@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: rise 0.18s ease-out; }
  #add[open], #login[open] { animation-name: drop; }
  @keyframes rise { from { translate: 0 24px; opacity: 0; } }
  @keyframes drop { from { translate: 0 -24px; opacity: 0; } }
}
