: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;
  /* urgency colour of whatever is being drawn; fresh unless a .lvl- class says otherwise */
  --tone: var(--leaf);
  --on-tone: #fff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1A16;
    --surface: #18261F;
    --ink: #E6EFEA;
    --muted: #9BADA4;
    --line: #2A3B33;
    --leaf: #2C9A5B;
    --chilli: #DE4A33;
    --aubergine: #8A5479;
  }
}
.lvl-fresh { --tone: var(--leaf); --on-tone: #fff; }
.lvl-soon { --tone: var(--turmeric); --on-tone: var(--on-turmeric); }
.lvl-now { --tone: var(--chilli); --on-tone: #fff; }
.lvl-overdue { --tone: var(--aubergine); --on-tone: #fff; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overscroll-behavior-y: none; }
body {
  margin: 0 auto;
  max-width: 560px;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 calc(104px + 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; user-select: none; -webkit-user-select: none;
}
: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); }
#meter { display: flex; gap: 3px; height: 10px; margin-top: 12px; }
#meter span { min-width: 10px; border-radius: 5px; background: var(--tone); }
#filters { display: flex; gap: 8px; overflow-x: auto; margin: 14px calc(-1 * var(--pad)) 0; padding: 0 var(--pad) 4px; scrollbar-width: none; }
#filters::-webkit-scrollbar { display: 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 { margin-top: 22px; }
section h2 { display: flex; align-items: center; gap: 8px; padding: 0 var(--pad) 8px; font-size: 15px; font-weight: 800; }
section h2::before { content: ''; width: 10px; height: 10px; border-radius: 5px; background: var(--tone); }
section ul { background: var(--surface); border-block: 1px solid var(--line); }
section li { position: relative; overflow: hidden; touch-action: pan-y; }
section li + li { border-top: 1px solid var(--line); }
.slide { display: flex; align-items: center; background: var(--surface); translate: var(--dx, 0) 0; }
li:not(.dragging) > .slide { transition: translate 0.2s ease-out; }

/* what a swipe uncovers */
li.dragging { background: var(--leaf); }
li.dragging[data-swipe="binned"] { background: var(--chilli); }
li.dragging::before {
  content: 'Eaten'; position: absolute; inset: 0 auto 0 20px; display: grid; align-content: center;
  color: #fff; font-weight: 800; opacity: 0.6; scale: 0.9; transition: opacity 0.12s, scale 0.12s;
}
li.dragging[data-swipe="binned"]::before { content: 'Binned'; inset: 0 20px 0 auto; }
li.dragging.armed::before { opacity: 1; scale: 1.1; }

.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.word b { font-size: 17px; letter-spacing: -0.02em; }
.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: 68px; height: 84px; display: grid; place-content: center; justify-items: center; gap: 4px; border-radius: var(--radius); }
.amount i { display: block; width: 26px; height: 7px; 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); }
.amount small { margin-top: 2px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.hint { margin: 18px var(--pad) 0; color: var(--muted); font-size: 14px; max-width: 40ch; }

/* ---------- nothing added yet ---------- */
.empty { margin: 28px var(--pad) 0; }
.empty h2 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.empty h2 + p { margin-top: 6px; color: var(--muted); max-width: 34ch; }
.guide { margin: 22px calc(-1 * var(--pad)) 0; background: var(--surface); border-block: 1px solid var(--line); }
.guide li { display: flex; align-items: center; gap: 14px; padding: 10px var(--pad); }
.guide li + li { border-top: 1px solid var(--line); }
.guide .tile { width: 52px; height: 52px; border-radius: 12px; }
.guide .tile b { font-size: 24px; }
.guide .tile small { font-size: 11px; }
.guide .where { white-space: normal; }
.empty .label { margin-top: 24px; }

/* ---------- bottom bar and buttons ---------- */
.bar {
  position: fixed; bottom: 0; left: 50%; translate: -50% 0; width: 100%; max-width: 560px;
  display: flex; gap: 10px; padding: 20px var(--pad) calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 38%);
}
.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; }
.sub { margin: -8px 0 16px; color: var(--muted); }

.field { display: grid; gap: 6px; }
.field span, .label { font-size: 14px; color: var(--muted); }
.label { margin: 18px 0 8px; }
.field input, #add-date {
  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, #add-date:focus { outline: none; border-color: var(--ink); }
#add-date { margin-top: 8px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.pair input { min-width: 0; padding: 0 10px; font-size: 16px; }
.name-field { margin-top: 12px; }
.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 small { color: var(--muted); font-size: 15px; }
.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: 60px; padding: 6px; border-radius: var(--radius);
  border: 1.5px solid var(--line); background: var(--surface); font-size: 15px; line-height: 1.2;
}
.comps small { display: block; margin-top: 3px; font-size: 12px; font-weight: 500; color: var(--muted); }
.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; }
.comps button[aria-pressed="true"] small { color: inherit; opacity: 0.75; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg.small button { min-height: 44px; padding: 2px; font-size: 14px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#login-form { display: grid; }
#login-show { justify-self: start; min-height: 44px; margin-top: 10px; font-weight: 500; }
#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)); }

/* ---------- motion: only in answer to a touch ---------- */
/* Taps must reach the page while rows are still gliding to their new place. */
::view-transition { pointer-events: none; }
@media (prefers-reduced-motion: no-preference) {
  button { transition: scale 0.1s; }
  button:active { scale: 0.96; }
  .amount i { transition: background 0.15s; }
  .sheet[open] { animation: rise 0.18s ease-out; }
  #add[open], #login[open] { animation-name: drop; }
  #toast:not([hidden]) { animation: toast 0.2s ease-out; }
  ::view-transition-group(*) { animation-duration: 0.22s; }
  @keyframes rise { from { translate: 0 24px; opacity: 0; } }
  @keyframes drop { from { translate: 0 -24px; opacity: 0; } }
  @keyframes toast { from { translate: -50% 12px; opacity: 0; } }
}
