/* =========================================================
   Tally — styles
   Tokens first; light is default, dark via system or override.
   ========================================================= */

:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f2efe8;
  --surface-3: #e9e5db;
  --ink: #1c1b18;
  --ink-2: #57544c;
  --ink-3: #8a867c;
  --line: #e7e2d7;
  --line-strong: #d6d0c3;
  --accent: #17845a;
  --accent-hover: #126e4a;
  --accent-ink: #ffffff;
  --accent-soft: #e2f2e9;
  --accent-soft-ink: #0f5c3e;
  --warn: #c2410c;
  --warn-soft: #fdece0;
  --danger: #c9342a;
  --danger-soft: #fbe7e5;
  --track: #ece8de;
  --bar: #c9d9cf;
  --shadow-sm: 0 1px 2px rgb(28 27 24 / .06);
  --shadow: 0 1px 2px rgb(28 27 24 / .05), 0 8px 24px -8px rgb(28 27 24 / .12);
  --shadow-lg: 0 24px 64px -16px rgb(28 27 24 / .28);
  --scrim: rgb(28 27 24 / .38);

  --radius: 20px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --gutter: 16px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.4, .64, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111210;
    --surface: #1a1b19;
    --surface-2: #222321;
    --surface-3: #2b2c29;
    --ink: #f0eee8;
    --ink-2: #b6b2a8;
    --ink-3: #7e7b73;
    --line: #2b2c29;
    --line-strong: #3a3b37;
    --accent: #3cc68a;
    --accent-hover: #58d39e;
    --accent-ink: #08170f;
    --accent-soft: #17301f;
    --accent-soft-ink: #8fe3bd;
    --warn: #fb923c;
    --warn-soft: #3a2415;
    --danger: #f2675e;
    --danger-soft: #3a1d1a;
    --track: #2a2b28;
    --bar: #2f4a3b;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px -8px rgb(0 0 0 / .5);
    --shadow-lg: 0 24px 64px -16px rgb(0 0 0 / .7);
    --scrim: rgb(0 0 0 / .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111210;
  --surface: #1a1b19;
  --surface-2: #222321;
  --surface-3: #2b2c29;
  --ink: #f0eee8;
  --ink-2: #b6b2a8;
  --ink-3: #7e7b73;
  --line: #2b2c29;
  --line-strong: #3a3b37;
  --accent: #3cc68a;
  --accent-hover: #58d39e;
  --accent-ink: #08170f;
  --accent-soft: #17301f;
  --accent-soft-ink: #8fe3bd;
  --warn: #fb923c;
  --warn-soft: #3a2415;
  --danger: #f2675e;
  --danger-soft: #3a1d1a;
  --track: #2a2b28;
  --bar: #2f4a3b;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px -8px rgb(0 0 0 / .5);
  --shadow-lg: 0 24px 64px -16px rgb(0 0 0 / .7);
  --scrim: rgb(0 0 0 / .6);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
/* Guard against any sideways scroll on phones (iOS Safari is unforgiving). */
html, body { overflow-x: hidden; max-width: 100%; }
body { position: relative; }
.app { overflow-x: clip; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }
code { font: 500 .9em/1 ui-monospace, "Cascadia Code", Menlo, monospace; background: var(--surface-2); padding: 2px 5px; border-radius: 5px; }
small { font-size: .72em; color: var(--ink-3); font-weight: 500; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: 8px; top: -40px; z-index: 50; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { top: 8px; }

/* ---------- layout ---------- */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}
@media (min-width: 560px) {
  .app { padding-top: 24px; gap: 16px; }
  .panel { padding: 24px; }
}

/* ---------- top bar ---------- */
/* Grid/flex children default to min-width:auto, which lets long names push past the edge. */
.log, .entries, .recipes, .stack, .meal-group, .stats { grid-template-columns: minmax(0, 1fr); min-width: 0; }
.recipe, .entry, .search { min-width: 0; }
.select { flex: none; }
.topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; margin-bottom: 8px; }
.brand { justify-self: start; }
.topbar__end { justify-self: end; display: flex; align-items: center; gap: 4px; }
.daynav { display: flex; align-items: center; gap: 2px; }
.daynav__label { font-size: 16px; font-weight: 650; letter-spacing: -.01em; min-width: 9.5ch; text-align: center; white-space: nowrap; }

/* ---------- buttons ---------- */
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center;
  border: 0; background: transparent; border-radius: 999px; color: var(--ink-2);
  transition: background .15s, color .15s, transform .15s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { transform: scale(.92); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }
.icon-btn svg, .btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn--filled { background: var(--surface-2); color: var(--ink); }
.icon-btn--filled:hover { background: var(--surface-3); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: 14.5px; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .15s var(--ease), box-shadow .15s;
}
.btn:active { transform: scale(.97); }
.btn--sm { height: 34px; padding: 0 12px; font-size: 13.5px; gap: 6px; }
.btn--sm svg { width: 16px; height: 16px; }
.btn--block { width: 100%; }
.btn--primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 0 rgb(255 255 255 / .15) inset, 0 4px 12px -4px color-mix(in srgb, var(--accent) 60%, transparent); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--primary:disabled { opacity: .45; pointer-events: none; }
.btn--ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn--danger-ghost:hover { background: var(--danger-soft); }
.link-btn { border: 0; background: none; padding: 0; color: inherit; font: inherit; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.link-btn:hover { text-decoration-color: currentColor; }
.chip {
  height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); font-size: 13px; font-weight: 600; color: var(--ink-2);
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { background: var(--surface-2); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-soft-ink); border-color: transparent; }
#go-today { background: var(--accent-soft); color: var(--accent-soft-ink); border-color: transparent; }

/* ---------- summary: ring + stats ---------- */
.summary { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: center; padding: 8px 0 4px; }
.ring { position: relative; width: 156px; aspect-ratio: 1; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 14; stroke-linecap: round; }
.ring__track { stroke: var(--track); }
.ring__fill { stroke: var(--accent); transition: stroke-dashoffset .7s var(--ease), stroke .3s; }
.ring__over { stroke: var(--warn); transition: stroke-dashoffset .7s var(--ease), opacity .3s; opacity: 0; }
.ring.is-over .ring__over { opacity: 1; }
.ring__center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring__value { font-size: 36px; font-weight: 750; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.ring__caption { margin-top: 4px; font-size: 12.5px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.ring.is-over .ring__caption { color: var(--warn); }
.ring__pop {
  position: absolute; left: 50%; top: 18%; translate: -50% 0; pointer-events: none;
  font-weight: 700; font-size: 14px; color: var(--accent-soft-ink); background: var(--accent-soft);
  padding: 3px 9px; border-radius: 999px; opacity: 0;
}
.ring__pop.is-anim { animation: pop-up 1.1s var(--ease) forwards; }
.ring__pop.is-neg { color: var(--ink-2); background: var(--surface-2); }
@keyframes pop-up {
  0% { opacity: 0; transform: translateY(10px) scale(.8); }
  20% { opacity: 1; transform: translateY(0) scale(1); }
  70% { opacity: 1; transform: translateY(-6px); }
  100% { opacity: 0; transform: translateY(-16px); }
}

.stats { margin: 0; display: grid; gap: 12px; }
.stat { display: grid; gap: 1px; }
.stat dt { font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.stat dd { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .link-btn { font-weight: 700; }

@media (max-width: 380px) {
  .ring { width: 132px; }
  .ring__value { font-size: 30px; }
  .summary { gap: 14px; }
  .stat dd { font-size: 18px; }
}
@media (min-width: 560px) {
  .ring { width: 184px; }
  .ring__value { font-size: 44px; }
  .summary { gap: 36px; padding: 8px 8px 4px; }
  .stats { grid-template-columns: repeat(3, auto); justify-content: start; gap: 28px; }
  .stat dd { font-size: 22px; }
}

/* ---------- week strip ---------- */
.panel { overflow: hidden; min-width: 0; }
.week-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 18px; }
.week-head__title { font-size: 12px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.week-head__link { font-size: 13px; font-weight: 600; color: var(--accent-soft-ink); }
.week { margin: 10px 0 4px; overflow: hidden; }
.week__plot { position: relative; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; height: 112px; padding-top: 22px; }
.week__plot--dense { gap: 2px; height: 128px; }
.week__plot--dense .day__bar { width: 100%; border-radius: 3px 3px 1px 1px; }
.week__plot--dense .day__label { font-size: 10px; }
.week__plot--dense .day__track { border-radius: 3px; }
.week__goal {
  position: absolute; left: 0; right: 0; height: 0; border-top: 1.5px dashed var(--line-strong);
  pointer-events: none; z-index: 1;
}
.week__legend { position: absolute; top: 0; right: 0; display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; color: var(--ink-3); pointer-events: none; }
.week__legend i { width: 16px; border-top: 1.5px dashed var(--line-strong); }
.day {
  position: relative; display: grid; grid-template-rows: 1fr auto; gap: 4px; align-items: end;
  border: 0; background: none; padding: 0; border-radius: 10px; color: var(--ink-3);
}
.day__track { position: relative; height: 100%; display: flex; align-items: flex-end; justify-content: center; border-radius: 8px; transition: background .15s; }
.day:hover .day__track { background: var(--surface-2); }
.day__bar {
  width: min(28px, 70%); min-height: 3px; border-radius: 4px 4px 2px 2px; background: var(--bar);
  transition: height .6s var(--ease), background .2s;
}
.day.is-over .day__bar { background: color-mix(in srgb, var(--warn) 45%, var(--surface)); }
.day.is-selected .day__bar { background: var(--accent); }
.day.is-selected.is-over .day__bar { background: var(--warn); }
.day.is-empty .day__bar { background: var(--track); }
.day__label { display: grid; font-size: 11.5px; font-weight: 600; text-align: center; line-height: 1.2; min-height: 2.4em; }
.day__dow { font-size: .9em; font-weight: 500; }
.day__num { font-weight: 700; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.day.is-selected .day__label, .day.is-selected .day__num { color: var(--ink); }
.day.is-today .day__num { color: var(--accent); }
.day.is-future { pointer-events: none; }
.day.is-future .day__bar { background: transparent; }
.day.is-future .day__num { opacity: .45; }
.day__tip {
  position: absolute; bottom: calc(100% - 6px); left: 50%; translate: -50% 0; z-index: 3;
  background: var(--ink); color: var(--bg); padding: 6px 9px; border-radius: 8px;
  font-size: 12px; font-weight: 600; white-space: nowrap; pointer-events: none;
  opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s;
  font-variant-numeric: tabular-nums;
}
.day__tip em { font-style: normal; color: color-mix(in srgb, var(--bg) 65%, transparent); font-weight: 500; }
.day:hover .day__tip, .day:focus-visible .day__tip { opacity: 1; transform: none; }
.day.tip-l .day__tip { left: 0; translate: 0 0; }
.day.tip-r .day__tip { left: auto; right: 0; translate: 0 0; }
.day__tip { visibility: hidden; }
.day:hover .day__tip, .day:focus-visible .day__tip { visibility: visible; }

/* ---------- log ---------- */
.log-head, .recipes-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.log-head { margin: 16px 0 6px; padding-top: 16px; border-top: 1px solid var(--line); }
.section-title { font-size: 17px; font-weight: 700; letter-spacing: -.015em; }
.subtle { color: var(--ink-3); font-size: 13.5px; }
.hint { color: var(--ink-3); font-size: 12.5px; line-height: 1.5; }
.hint--gesture { margin-top: 10px; text-align: center; }
@media (hover: hover) and (pointer: fine) { .hint--gesture { display: none; } }

.log { display: grid; }
.meal-group + .meal-group { margin-top: 6px; }
.meal-group__head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 4px 4px; font-size: 12px; font-weight: 650; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .06em;
}
.meal-group__head span:last-child { font-variant-numeric: tabular-nums; }
.entries { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }

.entry { position: relative; border-radius: var(--radius-sm); overflow: hidden; }
.entry.is-collapsing { transition: height .25s var(--ease), opacity .25s, margin .25s; }
.entry__bg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; background: var(--danger); color: #fff; font-weight: 600; font-size: 13.5px;
  opacity: 0; transition: opacity .15s;
}
.entry__bg svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.entry__bg span { display: flex; align-items: center; gap: 6px; }
.entry.is-dragging .entry__bg { opacity: 1; }
.entry__fg {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 8px 8px 8px 14px; background: var(--surface-2);
  border-radius: var(--radius-sm); touch-action: pan-y; user-select: none; -webkit-user-select: none;
  transition: transform .3s var(--ease), box-shadow .2s, background .2s;
  cursor: pointer;
}
.entry__fg:hover { background: var(--surface-3); }
.entry.is-held .entry__fg { box-shadow: var(--shadow); transform: scale(.985); background: var(--surface); }
.entry.is-dragging .entry__fg { transition: none; box-shadow: var(--shadow); background: var(--surface); }
.entry.is-new .entry__fg { animation: entry-in .5s var(--ease-spring); }
.entry.is-new .entry__fg::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  box-shadow: 0 0 0 2px var(--accent) inset; animation: flash 1.2s ease-out forwards;
}
@keyframes entry-in { from { opacity: 0; transform: translateY(-8px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }
.entry__open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px;
  border: 0; background: none; padding: 0; text-align: left; color: inherit; cursor: inherit;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
}
.entry__main { flex: 1; min-width: 0; display: grid; }
.entry__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry__meta { font-size: 12.5px; color: var(--ink-3); }
.entry__kcal { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entry__kcal small { margin-left: 2px; }
.entry__del { color: var(--ink-3); opacity: 0; }
.entry__fg:hover .entry__del, .entry__del:focus-visible { opacity: 1; }
.entry__del:hover { color: var(--danger); background: var(--danger-soft); }
@media (hover: none) { .entry__del { display: none; } .entry__del:focus-visible { display: inline-grid; } }

.empty {
  display: grid; justify-items: center; gap: 6px; text-align: center;
  padding: 24px 16px; border: 1.5px dashed var(--line-strong); border-radius: var(--radius-sm); color: var(--ink-3);
}
.empty svg { width: 36px; height: 36px; fill: none; stroke: var(--ink-3); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 4px; }
.empty strong { color: var(--ink); font-size: 15px; }
.empty p { font-size: 13.5px; max-width: 34ch; }
.empty .btn { margin-top: 8px; }

.entry--burn .entry__kcal { color: var(--accent-soft-ink); }

/* ---------- recipes ---------- */
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 999px; margin-bottom: 18px; }
.tabs [role="tab"] {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px;
  border: 0; background: none; border-radius: 999px; font-weight: 650; font-size: 14px; color: var(--ink-2);
  transition: background .15s, color .15s, box-shadow .15s;
}
.tabs [role="tab"]:hover { color: var(--ink); }
.tabs [role="tab"] svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs [aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.recipes-head { margin-bottom: 14px; }
.meal-picker { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0; margin: 0 0 12px; }
.meal-picker::-webkit-scrollbar { display: none; }
.meal-picker--compact { margin-bottom: 0; flex-wrap: wrap; }
.meal-opt {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px;
  border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 13.5px; font-weight: 600; color: var(--ink-2); transition: all .15s;
}
.meal-opt:hover { color: var(--ink); background: var(--surface-2); }
.meal-opt[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.meal-picker__lead { flex: none; align-self: center; font-size: 13px; font-weight: 600; color: var(--ink-3); padding-right: 2px; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.search {
  flex: 1; position: relative; display: flex; align-items: center;
  background: var(--surface-2); border-radius: 999px; border: 1px solid transparent; transition: border-color .15s, background .15s;
}
.search:focus-within { border-color: var(--accent); background: var(--surface); }
.search > svg { position: absolute; left: 13px; width: 18px; height: 18px; fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round; }
.search input { width: 100%; height: 40px; border: 0; background: none; padding: 0 36px 0 40px; outline: none; }
.search input::-webkit-search-cancel-button { display: none; }
.search kbd { position: absolute; right: 12px; font: 600 11px/1 var(--font); color: var(--ink-3); border: 1px solid var(--line-strong); border-radius: 5px; padding: 3px 6px; }
.search:focus-within kbd { display: none; }
@media (hover: none) { .search kbd { display: none; } }
.select select {
  height: 40px; border-radius: 999px; border: 1px solid var(--line-strong); background-color: var(--surface);
  padding: 0 32px 0 14px; font-size: 14px; font-weight: 600; color: var(--ink-2); appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a867c' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}

.recipes { list-style: none; margin: 0; padding: 0; display: grid; }
.recipe {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px 12px 4px;
  border-top: 1px solid var(--line);
}
.recipe:first-child { border-top: 0; }
.recipe.is-new { animation: entry-in .45s var(--ease-spring); }
.recipe.is-new .recipe__name::after { content: "New"; margin-left: 8px; font-size: 11px; font-weight: 700; color: var(--accent-soft-ink); background: var(--accent-soft); padding: 2px 7px; border-radius: 999px; vertical-align: 2px; }
.recipe__main { flex: 1; min-width: 0; border: 0; background: none; padding: 4px 6px; margin: -4px -6px; text-align: left; border-radius: 8px; }
.recipe__main:hover .recipe__name { text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.recipe__name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipe__notes {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 13px; color: var(--ink-3); white-space: pre-line; margin-top: 1px;
}
.recipe__kcal { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.recipe__kcal small { display: block; margin-top: -2px; }
mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

.add-btn {
  position: relative; flex: none; width: 44px; height: 44px; border-radius: 999px; border: 0;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-soft-ink);
  transition: background .15s, color .15s, transform .2s var(--ease-spring);
}
.add-btn:hover { background: var(--accent); color: var(--accent-ink); }
.add-btn:active { transform: scale(.88); }
.add-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform .3s var(--ease-spring), opacity .2s; }
.add-btn .i-check { position: absolute; opacity: 0; transform: scale(.4) rotate(-30deg); }
.add-btn.is-done { background: var(--accent); color: var(--accent-ink); }
.add-btn.is-done .i-plus { opacity: 0; transform: scale(.4) rotate(90deg); }
.add-btn.is-done .i-check { opacity: 1; transform: none; }
.add-btn.is-done::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; border: 2px solid var(--accent);
  animation: ripple .6s ease-out forwards;
}
@keyframes ripple { from { transform: scale(1); opacity: .8; } to { transform: scale(1.6); opacity: 0; } }

.no-results { padding: 24px 8px; text-align: center; color: var(--ink-3); }

.foot { text-align: center; font-size: 12.5px; color: var(--ink-3); padding: 4px 0 8px; }

/* ---------- dialogs (bottom sheet on mobile, centered on desktop) ---------- */
dialog.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--ink);
  width: 100%; max-width: 100%; max-height: 92dvh; margin: auto auto 0;
  border-radius: 24px 24px 0 0; box-shadow: var(--shadow-lg);
  overscroll-behavior: contain;
}
dialog.sheet::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
dialog.sheet[open] { animation: sheet-up .32s var(--ease); }
dialog.sheet[open]::backdrop { animation: fade .25s ease; }
dialog.sheet.is-closing { animation: sheet-down .2s ease-in forwards; }
dialog.sheet.is-closing::backdrop { animation: fade .2s ease reverse forwards; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sheet-down { to { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (min-width: 640px) {
  dialog.sheet { width: min(460px, calc(100% - 32px)); margin: auto; border-radius: 24px; max-height: 86dvh; }
  dialog.sheet--wide { width: min(640px, calc(100% - 32px)); }
}
.sheet__inner { display: grid; gap: 16px; padding: 20px var(--gutter) calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .sheet__inner { padding: 22px 24px 20px; } }
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin: -6px -8px -4px 0; }
.sheet__head h2:focus { outline: none; }
.toast__action { flex: none; }
.sheet__head h2 { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.sheet__inner::before {
  content: ""; width: 36px; height: 4px; border-radius: 4px; background: var(--line-strong);
  justify-self: center; margin: -8px 0 -6px;
}
@media (min-width: 640px) { .sheet__inner::before { display: none; } }
.sheet__foot { display: flex; align-items: center; gap: 8px; padding: 10px 0 2px; position: sticky; bottom: 0; z-index: 2; background: var(--surface); box-shadow: 0 -12px 12px -12px rgb(0 0 0 / .18); }
.spacer { flex: 1; }

.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field input[type="text"], .field textarea, .input-suffix {
  width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius-sm);
  padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
.field input[type="text"]:focus, .field textarea:focus, .input-suffix:focus-within {
  border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.field input.is-invalid, .field textarea.is-invalid { border-color: var(--danger); }
.input-suffix { display: flex; align-items: center; gap: 8px; padding: 0 12px; }
.input-suffix input { flex: 1; min-width: 0; height: 42px; border: 0; background: none; outline: none; font-variant-numeric: tabular-nums; font-weight: 600; }
.input-suffix span { color: var(--ink-3); font-weight: 600; font-size: 13.5px; }
.input-suffix--lg input { height: 60px; font-size: 30px; font-weight: 700; letter-spacing: -.03em; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.stack { display: grid; gap: 8px; margin-top: 4px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
input[type="number"] { -moz-appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); padding: 3px; border-radius: 999px; gap: 2px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: grid; place-items: center; height: 34px; padding: 0 10px; border-radius: 999px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); text-align: center; transition: background .15s, color .15s, box-shadow .15s; }
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

.stepper { display: flex; align-items: center; gap: 16px; }
.stepper output { min-width: 3ch; text-align: center; font-size: 28px; font-weight: 750; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.entry-total { color: var(--ink-3); font-size: 14px; font-variant-numeric: tabular-nums; }

/* ---------- recipe entry grid ---------- */
.grid { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.grid__head, .grid-row { display: grid; grid-template-columns: 1fr 108px 40px; }
.grid__head { background: var(--surface-2); font-size: 12px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.grid__head > span { padding: 8px 12px; }
.grid__head > span + span { border-left: 1px solid var(--line); }
.grid-row { border-top: 1px solid var(--line); }
.grid-row.is-new { animation: entry-in .3s var(--ease); }
.grid-row > * + * { border-left: 1px solid var(--line); }
.grid-row textarea, .grid-row input {
  width: 100%; border: 0; background: transparent; outline: none; padding: 11px 12px; resize: none;
  min-height: 44px; line-height: 1.45; display: block; overflow: hidden;
}
.grid-row input { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.grid-row textarea:focus, .grid-row input:focus { background: color-mix(in srgb, var(--accent) 7%, var(--surface)); box-shadow: inset 0 0 0 2px var(--accent); }
.grid-row.is-invalid input, .grid-row .is-invalid { background: var(--danger-soft); }
.grid-row__rm { display: grid; place-items: start center; padding-top: 6px; }
.grid-row__rm .icon-btn { width: 32px; height: 32px; color: var(--ink-3); }
.grid-row__rm .icon-btn:hover { color: var(--danger); background: var(--danger-soft); }
.grid-row__rm svg { width: 16px; height: 16px; }
#grid-body { max-height: 46dvh; overflow-y: auto; }
.grid__actions { display: flex; align-items: center; justify-content: space-between; margin-top: -6px; }
.grid__total { font-size: 13.5px; font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }
@media (max-width: 420px) { .grid__head, .grid-row { grid-template-columns: 1fr 84px 36px; } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 100;
  translate: -50% 0; display: flex; align-items: center; gap: 14px; width: max-content; max-width: min(480px, calc(100% - 32px));
  background: var(--ink); color: var(--bg); padding: 10px 10px 10px 18px; border-radius: 18px; line-height: 1.35;
  box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  animation: toast-in .3s var(--ease-spring);
}
.toast:not(:has(.toast__action:not([hidden]))) { padding-right: 18px; }
.toast[hidden] { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }
.toast__action { border: 0; background: color-mix(in srgb, var(--bg) 16%, transparent); color: var(--bg); font-weight: 700; padding: 7px 14px; border-radius: 999px; }
.toast__action:hover { background: color-mix(in srgb, var(--bg) 26%, transparent); }

/* ---------- reports ---------- */
.report-nav { display: flex; align-items: center; justify-content: space-between; margin: -4px 0; }
.report-nav__label { font-size: 16px; font-weight: 700; letter-spacing: -.01em; text-align: center; }
.report { display: grid; gap: 22px; min-width: 0; }
.report .week { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; display: grid; gap: 2px; min-width: 0; }
.tile__label { font-size: 11.5px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.tile__value { font-size: 22px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile__value small { margin-left: 2px; }
.tile__sub { font-size: 12.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.report-section { min-width: 0; }
.report-section h4 { margin: 0 0 8px; font-size: 12px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.report-cols { display: grid; gap: 22px; }
@media (min-width: 560px) { .report-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.rank { list-style: none; margin: 0; padding: 0; display: grid; }
.rank li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.rank li:first-child { border-top: 0; }
.rank__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rank__meta { color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 13px; }
.rank__empty { color: var(--ink-3); font-size: 13.5px; }
.meal-rows { display: grid; gap: 10px; }
.meal-row { display: grid; grid-template-columns: 76px minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13.5px; font-weight: 600; }
.meal-row__bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.meal-row__bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meal-row__val { color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; min-width: 8ch; }
.report-note { font-size: 12px; color: var(--ink-3); }
.report-empty { padding: 28px 12px; text-align: center; color: var(--ink-3); border: 1.5px dashed var(--line-strong); border-radius: var(--radius-sm); }

/* ---------- import & export ---------- */
.nav-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface);
  transition: background .15s;
}
.nav-row:hover { background: var(--surface-2); }
.nav-row__icon { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 10px; background: var(--accent-soft); color: var(--accent-soft-ink); }
.nav-row__icon svg, .nav-row__chev { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-row__text { flex: 1; min-width: 0; display: grid; }
.nav-row__text span { font-size: 12.5px; color: var(--ink-3); }
.nav-row__chev { flex: none; color: var(--ink-3); }
.sheet__head h2 { flex: 1; min-width: 0; }
#data-back { margin-left: -8px; }

.data-group { display: grid; gap: 2px; }
.data-group h3 { font-size: 12px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 6px; }
.data-row {
  display: grid; gap: 1px; width: 100%; text-align: left; padding: 10px 12px; margin: 0 -12px; width: calc(100% + 24px);
  border: 0; background: none; border-radius: var(--radius-xs); cursor: pointer; transition: background .15s;
}
.data-row:hover, .data-row:focus-within { background: var(--surface-2); }
.data-row strong { font-size: 14.5px; font-weight: 600; }
.data-row span { font-size: 12.5px; color: var(--ink-3); }
.data-row--danger strong { color: var(--danger); }
.data-row.file-btn { position: relative; overflow: hidden; }
.restore-confirm { margin-top: 6px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); display: grid; gap: 10px; font-size: 13.5px; }
.restore-confirm__actions { display: flex; flex-wrap: wrap; gap: 8px; }

.import-src { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.import-src .file-btn { position: relative; overflow: hidden; }
#import-text { font: 500 13.5px/1.5 ui-monospace, "Cascadia Code", Menlo, monospace; min-height: 110px; }
.import-opts { display: grid; gap: 12px; }
@media (min-width: 560px) { .import-opts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.select--block select { width: 100%; height: 42px; }
.import-preview:empty { display: none; }
.import-summary { font-size: 13.5px; font-weight: 600; margin-bottom: 8px; }
.import-table { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); max-height: 34dvh; overflow-y: auto; }
.import-table table { width: 100%; border-collapse: collapse; font-size: 13.5px; table-layout: fixed; }
.import-table th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-size: 11.5px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; padding: 7px 10px; }
.import-table td { padding: 7px 10px; border-top: 1px solid var(--line); vertical-align: top; }
.import-table td:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; width: 72px; }
.import-table th:nth-child(3), .import-table td:nth-child(3) { width: 86px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-soft-ink); white-space: nowrap; }
.badge--dupe { background: var(--surface-3); color: var(--ink-2); }
.badge--bad { background: var(--danger-soft); color: var(--danger); }
.badge--ex { background: var(--surface-2); color: var(--ink-2); margin-right: 4px; }

/* ?debug in the URL outlines anything wider than the screen (see app.js). */
.debug-wide { outline: 2px solid #e11 !important; outline-offset: -2px; }
.debug-panel { position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 999; max-height: 40vh; overflow: auto; background: #111; color: #fff; font: 12px/1.4 ui-monospace, monospace; padding: 10px; border-radius: 10px; white-space: pre-wrap; }

/* Small phones (iPhone SE, or larger iPhones in Display Zoom): tighten everything slightly. */
@media (max-width: 374px) {
  :root { --gutter: 10px; }
  .panel { padding: 14px 12px; }
  .brand { display: none; }
  .topbar { grid-template-columns: auto minmax(0, 1fr); }
  .daynav { justify-self: start; }
  .daynav__label { min-width: 0; font-size: 15px; }
  .icon-btn { width: 36px; height: 36px; }
  .ring { width: 116px; }
  .ring circle { stroke-width: 15; }
  .ring__value { font-size: 26px; }
  .ring__caption { font-size: 11px; }
  .summary { gap: 12px; }
  .stats { gap: 8px; }
  .stat dd { font-size: 17px; }
  .week__plot { gap: 4px; }
  .add-btn { width: 40px; height: 40px; }
  .recipe { gap: 8px; }
  .select select { padding: 0 28px 0 12px; }
  .btn { padding: 0 14px; }
  .meal-opt { padding: 0 11px; }
}

/* iOS zooms the page when a focused field's text is under 16px, which leaves it scrollable sideways. */
@media (pointer: coarse) {
  input, select, textarea, .select select { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media (forced-colors: active) {
  .ring__fill, .ring__over { stroke: Highlight; }
  .day__bar { background: CanvasText !important; }
  .day.is-selected .day__bar { background: Highlight !important; }
}
