/* eats: a ledger, not a dashboard. Paper, ink, and one colour per macro. */
:root {
  --paper: #F4F1EA;
  --paper-2: #FBFAF6;
  --ink: #1B1A17;
  --ink-2: #3A3732;
  --muted: #5E594F;
  --hair: #DDD7CB;
  --hair-2: #D2CBBD;
  --track: #E4DED2;
  --red: #B5391F;

  --protein: #C2412A; --protein-track: #EFD6CC;
  --carbs: #B87A0E;   --carbs-track: #F0E2C4;
  --fiber: #4E7A31;   --fiber-track: #DCE5D0;
  --fat: #2F5F94;     --fat-track: #D3DDEA;

  --m-breakfast: #1B1A17; --m-lunch: #4A463F; --m-dinner: #7A746A; --m-snack: #A8A195;

  --mono: 'Geist Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0; min-height: 100dvh;
  font-family: 'Geist', system-ui, sans-serif; color: var(--ink); background: var(--paper);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }

.page {
  max-width: 480px; margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 20px 170px;
  display: flex; flex-direction: column; gap: 18px;
}
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 16px 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.label { font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.sq { display: inline-block; width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.sq.ink { background: var(--ink); }
.protein .sq { background: var(--protein); } .carbs .sq { background: var(--carbs); }
.fiber .sq { background: var(--fiber); }     .fat .sq { background: var(--fat); }
.m-breakfast { background: var(--m-breakfast); } .m-lunch { background: var(--m-lunch); }
.m-dinner { background: var(--m-dinner); }       .m-snack { background: var(--m-snack); }

/* ---- Top bar ------------------------------------------------------------ */

.topbar { display: flex; align-items: center; justify-content: space-between; margin: 0 -8px; }
.daynav { display: flex; align-items: center; font-size: 13px; color: var(--muted); }
.daynav a { width: 36px; height: 44px; display: flex; align-items: center; justify-content: center; }
.who { display: flex; align-items: center; margin: 0; }
.who button {
  height: 44px; padding: 0 8px; border: none; background: none; font-size: 15px; font-weight: 500; color: var(--muted);
}
.who button[aria-pressed="true"] {
  color: var(--ink); font-weight: 600;
  text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 6px;
}
.gear { width: 40px; height: 44px; display: flex; align-items: center; justify-content: center; color: var(--muted); }

/* ---- Kcal --------------------------------------------------------------- */

.kcal { display: flex; flex-direction: column; gap: 8px; }
.kcal-top { display: flex; align-items: flex-end; justify-content: space-between; }
.kcal-num { display: flex; align-items: baseline; gap: 8px; margin-top: 4px; }
.kcal-num .big { font-size: 84px; font-weight: 300; line-height: 0.95; letter-spacing: -0.045em; font-variant-numeric: tabular-nums; }
.kcal-num .unit { font-size: 20px; color: var(--muted); }
.pct { font-size: 22px; font-weight: 500; padding-bottom: 6px; }
.kbar { height: 12px; margin-top: 6px; background: var(--track); border-radius: 3px; display: flex; overflow: hidden; }
.kbar .seg { height: 100%; border-right: 2px solid var(--paper); animation: grow 800ms cubic-bezier(.3, 1.1, .5, 1) both; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 11.5px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend .sq { width: 8px; height: 8px; }
.legend .push { margin-left: auto; }
@keyframes grow { from { width: 0; } }

/* ---- Macros ------------------------------------------------------------- */

.macros {
  display: flex; flex-direction: column; width: 100%; padding: 6px 0 0; margin: 0;
  border: none; border-top: 1px solid var(--ink); background: none; text-align: left;
}
.mrow {
  display: grid; grid-template-columns: 76px minmax(0, 1fr) 96px; align-items: center; column-gap: 12px;
  min-height: 42px; border-bottom: 1px solid var(--hair);
}
.mname { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.mtrack { height: 8px; border-radius: 4px; overflow: hidden; }
.mfill { display: block; height: 100%; border-radius: 4px; animation: grow 800ms cubic-bezier(.3, 1.1, .5, 1) both; }
.protein .mtrack { background: var(--protein-track); } .protein .mfill { background: var(--protein); }
.carbs .mtrack { background: var(--carbs-track); }     .carbs .mfill { background: var(--carbs); }
.fiber .mtrack { background: var(--fiber-track); }     .fiber .mfill { background: var(--fiber); }
.fat .mtrack { background: var(--fat-track); }         .fat .mfill { background: var(--fat); }
.mval { text-align: right; font-size: 13px; color: var(--ink-2); }
.mval.over { color: var(--red); }
:root:not([data-mode="left"]) .v-left, [data-mode="left"] .v-eaten { display: none; }

/* ---- Meals -------------------------------------------------------------- */

.meals { display: flex; flex-direction: column; gap: 14px; margin-top: 4px; }
.meal-head { display: flex; align-items: center; gap: 10px; padding: 10px 0 2px; border-top: 1px solid var(--ink); }
.meal-head h2 { flex-grow: 1; font-size: 15px; font-weight: 600; }
.meal-head .mono { font-size: 14px; font-weight: 500; }
.meal-head .sq { width: 8px; height: 8px; }

.swipe { position: relative; overflow: hidden; border-bottom: 1px solid var(--hair); }
.swipe-action { position: absolute; inset: 0; margin: 0; display: flex; justify-content: flex-end; background: var(--red); }
.swipe-action button { border: none; background: none; color: #FFF; font-size: 14px; font-weight: 600; padding: 0 20px; }
.entry {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 52px;
  background: var(--paper); text-decoration: none; touch-action: pan-y;
}
.entry.settling { transition: transform 220ms cubic-bezier(.2, .9, .3, 1); }
.entry-main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.entry-name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-amt { font-size: 13px; color: var(--muted); }
.entry .mono { font-size: 14px; }
.swipe.gone { animation: collapse 260ms ease forwards; }
@keyframes collapse { to { height: 0; opacity: 0; border-width: 0; } }
.empty { display: flex; align-items: center; min-height: 44px; font-size: 14px; color: var(--muted); text-decoration: none; }
.empty u { color: var(--ink); text-underline-offset: 3px; margin-left: 4px; }

/* ---- Dock --------------------------------------------------------------- */

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 12px 16px max(18px, env(safe-area-inset-bottom));
  background: var(--paper); border-top: 1px solid var(--hair);
  display: flex; flex-direction: column; gap: 10px;
}
.dock > * { width: 100%; max-width: 448px; margin: 0 auto; }
.again { display: flex; align-items: center; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.again::-webkit-scrollbar { display: none; }
.again form { margin: 0; flex-shrink: 0; }
.chip-again {
  height: 36px; padding: 0 12px; border: 1px solid var(--hair-2); border-radius: 999px;
  background: var(--paper-2); font-size: 13px; white-space: nowrap;
}
.chip-again:active, .btn:active, .step:active, .chip:active, .logbar:active { transform: scale(.97); }
.logbar {
  display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px;
  background: var(--ink); color: var(--paper); border-radius: 14px; font-size: 16px; text-decoration: none;
}

.toast {
  position: fixed; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 10;
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: var(--paper); border-radius: 12px; padding: 10px 16px; font-size: 14px; white-space: nowrap;
  animation: toast-in 240ms ease;
}
.toast[hidden] { display: none; }
.toast button { border: none; background: none; padding: 4px 0; color: var(--paper); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -10px); } }

/* ---- Sub screens -------------------------------------------------------- */

.subhead { display: flex; align-items: center; margin: 0 -10px -8px; }
.back { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; color: var(--ink); }

.searchbar { display: flex; align-items: center; gap: 8px; margin: 6px -4px 0; }
.search {
  flex-grow: 1; display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 14px;
  background: var(--paper-2); border: 1px solid var(--ink); border-radius: 14px; color: var(--muted);
}
.search input { flex-grow: 1; min-width: 0; border: none; outline: none; background: none; color: var(--ink); font-size: 16px; height: auto; padding: 0; }
.cancel { padding: 0 6px; min-height: 44px; display: flex; align-items: center; font-size: 15px; color: var(--muted); text-decoration: none; }
#results { display: flex; flex-direction: column; margin-top: -8px; }
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; min-height: 58px; border-top: 1px solid var(--hair); text-decoration: none; }
.item-main { flex-grow: 1; display: flex; flex-direction: column; gap: 2px; font-size: 15px; }
.tag { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.tag.boxed { border: 1px solid var(--hair); border-radius: 6px; padding: 3px 6px; }
.links { border-top: 1px solid var(--hair); padding-top: 14px; display: flex; gap: 18px; font-size: 14px; }
.links a { min-height: 44px; text-underline-offset: 3px; }

.card {
  background: var(--paper-2); border: 1px solid var(--hair); border-radius: 16px; padding: 16px;
  display: flex; flex-direction: column; gap: 16px; margin: 0 -4px;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-head .title { font-size: 18px; font-weight: 600; }

.stepper { display: flex; align-items: center; gap: 12px; }
.step { width: 52px; height: 52px; flex-shrink: 0; border: 1px solid var(--hair); border-radius: 12px; background: var(--paper); font-size: 24px; }
.amount { flex-grow: 1; display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.amount input {
  width: 110px; border: none; outline: none; background: none; padding: 0; height: auto; text-align: right;
  font-size: 48px; font-weight: 300; letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
}
.unit-label { font-size: 16px; color: var(--muted); min-width: 60px; }
.chips { display: flex; gap: 8px; justify-content: center; }
.chips[hidden] { display: none; }
.chip { width: 48px; height: 40px; border: 1px solid var(--hair); border-radius: 10px; background: var(--paper); font-family: var(--mono); font-size: 14px; }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.preview { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 10px 0; border-top: 1px solid var(--hair); border-bottom: 1px solid var(--hair); }
.preview div { display: flex; flex-direction: column; gap: 3px; }
.preview b { font-size: 16px; font-weight: 500; }
.preview span { display: flex; align-items: center; gap: 4px; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.preview .sq { width: 6px; height: 6px; }

.tabs { display: flex; gap: 18px; flex-wrap: wrap; }
.tabs label { position: relative; }
.tabs input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tabs span { display: flex; align-items: center; height: 36px; font-size: 14px; color: var(--muted); cursor: pointer; }
.tabs input:checked + span { color: var(--ink); font-weight: 600; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 8px; }
.tabs input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }

.btn {
  display: flex; align-items: center; justify-content: center; height: 54px; width: 100%;
  border: none; border-radius: 14px; background: var(--ink); color: var(--paper); font-size: 16px; font-weight: 500; text-decoration: none;
}
.btn.ghost { background: none; color: var(--muted); height: 48px; }
.btn.danger { color: var(--red); }

/* ---- Forms -------------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: 14px; }
fieldset { border: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
legend { padding: 0; margin-bottom: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
input {
  width: 100%; height: 48px; padding: 0 12px; border: 1px solid var(--hair-2); border-radius: 12px;
  background: var(--paper); font-size: 16px; outline: none; /* 16px stops iOS zooming on focus */
}
input:focus { border-color: var(--ink); }
input[aria-invalid="true"] { border-color: var(--red); }
.error { color: var(--red); font-size: 13px; }
.note { padding: 10px 14px; border: 1px solid var(--hair); border-radius: 12px; font-size: 14px; color: var(--ink-2); }
.note.error { border-color: var(--red); }

.login { margin: 28vh 0 0; display: flex; flex-direction: column; gap: 12px; }
.login .btn { margin-top: 4px; }

/* ---- Motion ------------------------------------------------------------ */

/* Bars grow in when first shown, then slide to new values when a page is
   morphed in place (switching people, logging, undo). */
.mfill, .kbar .seg { transition: width 500ms cubic-bezier(.3, 1.1, .5, 1); }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---- Recipes ------------------------------------------------------------ */

.ingredients { display: flex; flex-direction: column; gap: 8px; }
.ing {
  display: grid; grid-template-columns: minmax(0, 1fr) 84px 36px; align-items: center; gap: 8px;
  min-height: 56px; border-bottom: 1px solid var(--hair);
}
#ingredients { display: flex; flex-direction: column; border-top: 1px solid var(--ink); }
.ing-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ing-name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ing-meta { font-size: 12px; color: var(--muted); font-family: var(--mono); letter-spacing: 0.02em; }
.ing-meta em { font-style: normal; }
.ing-meta .warn { color: var(--red); }
.ing-meta .ok { color: var(--fiber); }
.ing-g { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.ing-g input { height: 40px; padding: 0 8px; text-align: right; font-family: var(--mono); font-size: 15px; }
.ing-remove { width: 36px; height: 40px; border: none; background: none; color: var(--muted); display: flex; align-items: center; justify-content: center; }
.search.light { background: var(--paper-2); border: 1px solid var(--hair-2); color: var(--muted); height: 48px; }
.search.light input { color: var(--ink); }
.search.light input::placeholder { color: var(--muted); opacity: 1; }
#ing-results { display: flex; flex-direction: column; }
.ing-pick {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px;
  border: none; border-bottom: 1px solid var(--hair); background: none; text-align: left; font-size: 15px;
}
.card.per { gap: 10px; margin: 0; }
.btn.secondary { background: none; color: var(--ink); border: 1px solid var(--ink); height: 46px; width: auto; padding: 0 18px; align-self: flex-start; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 14px; font-size: 15px; line-height: 1.45; }
.steps li { display: flex; flex-direction: column; gap: 10px; }
.paste {
  width: 100%; border: 1px solid var(--hair-2); border-radius: 12px; background: var(--paper-2); padding: 12px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5; resize: vertical; outline: none;
}
.paste:focus { border-color: var(--ink); }
.links { flex-wrap: wrap; row-gap: 4px; }
