@font-face {
  font-family: 'Bricolage Grotesque'; src: url('../fonts/BricolageGrotesque.ttf') format('truetype');
  font-weight: 200 800; font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible'; src: url('../fonts/Atkinson-Regular.ttf') format('truetype');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible'; src: url('../fonts/Atkinson-Bold.ttf') format('truetype');
  font-weight: 700; font-display: swap;
}

:root {
  --motion-press: 120ms;
  --motion-select: 180ms;
  --motion-exit: 220ms;
  --motion-sheet: 320ms;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-move: cubic-bezier(.77, 0, .175, 1);
  --ease-drawer: cubic-bezier(.32, .72, 0, 1);
  color-scheme: light;
  --navy: #252943; --accent: #ff7200; --accent-secondary: #f36523;
  --bg: #fff8f2; --surface: #fff; --sunk: #f2e8df; --ink: var(--navy);
  --muted: #625c60; --line: #d8cac0; --control-line: #93847b;
  --link: #993c09; --on-link: white; --accent-soft: #ffe2cc;
  --secondary: #515471; --secondary-soft: #ece9f0; --notice: #f6e9d9;
  --chart-accent: #ae5118; --protein: #ad4514; --carbs: #895a1e; --fat: #70658d;
  --fill: var(--accent-secondary); --grain: #ffe7cf;
  --focus: #984100; --danger: #a12d34; --scrim: rgb(17 19 35 / .47);
  --shadow: none; --shadow-lift: 0 6px 20px rgb(25 24 45 / .14);
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --body: 'Atkinson Hyperlegible', system-ui, sans-serif;
  --r-panel: 16px; --r-control: 12px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #181b2c; --surface: #252943; --sunk: #31354b; --ink: #fff8f2;
  --muted: #c5bdc3; --line: #46495e; --control-line: #8c899c;
  --link: #ffaf73; --on-link: var(--navy); --accent-soft: #48322f;
  --secondary: #d2c3e3; --secondary-soft: #373246; --notice: #373044;
  --chart-accent: #ffaf73; --protein: #ffaf73; --carbs: #eec181; --fat: #c5b0e3;
  --focus: #ffaf73; --danger: #ffaaaa; --scrim: rgb(7 9 19 / .72);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }

.app { max-width: 560px; margin: 0 auto; min-height: 100vh; }
.view {
  display: flex; flex-direction: column; gap: 16px;
  padding-block: 20px calc(110px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  outline: none;
}

h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.15; text-wrap: balance; }
h1 { font-size: 2.125rem; font-weight: 800; letter-spacing: -0.025em; }
h2 { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.01em; }
h3 { font-size: 1rem; font-weight: 600; }
h3.label { font-family: var(--body); font-size: 0.875rem; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.stack > * + * { margin-top: 12px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head .muted { font-size: 0.875rem; }

/* ---------- Bottom bar ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  max-width: 560px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  padding-block: 8px calc(10px + env(safe-area-inset-bottom, 0px));
  padding-left: max(8px, env(safe-area-inset-left, 0px));
  padding-right: max(8px, env(safe-area-inset-right, 0px));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: 0; padding: 2px 0; color: var(--muted);
  font-size: 0.75rem; font-weight: 700; cursor: pointer;
}
.tab-icon { display: grid; place-items: center; width: 56px; height: 30px; border-radius: 15px; position: relative; }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current='page'] { color: var(--ink); }
.tabs button[aria-current='page'] .tab-icon { color: var(--link); }
.tabs .tab-log {
  justify-self: center; width: 54px; height: 54px; margin-top: -12px; padding: 0;
  border-radius: 50%; background: var(--accent); color: var(--navy);
  box-shadow: var(--shadow-lift); justify-content: center;
  position: relative; z-index: 1;
}
.tabs .tab-log svg { width: 28px; height: 28px; stroke-width: 2.6; }

/* ---------- Today ---------- */
.today-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.eyebrow { color: var(--muted); font-size: 0.875rem; font-weight: 700; }
.small-btn { min-height: 36px; padding: 6px 12px; font-size: 0.875rem; }

.day-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; border-radius: 16px; border: 0;
  background: var(--surface); cursor: pointer;
}
.day-name { font-size: 0.75rem; color: var(--muted); font-weight: 700; }
.day-num { font-family: var(--display); font-size: 1.125rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.day-dot { width: 5px; height: 5px; border-radius: 50%; background: transparent; }
.day-dot.on { background: var(--link); }
.day[aria-pressed='true'] { background: var(--ink); color: var(--bg); }
.day[aria-pressed='true'] .day-name { color: inherit; opacity: 0.75; }
.day[aria-pressed='true'] .day-dot.on { background: var(--chart-accent); }

.hero { text-align: center; padding: 8px 0 4px; }
.bowl { width: min(100%, 300px); height: auto; overflow: visible; display: block; margin: 0 auto; }
.hero-num {
  font-family: var(--display); font-size: 3.75rem; font-weight: 800; line-height: 1;
  letter-spacing: -0.04em; font-variant-numeric: tabular-nums; margin-top: 14px;
}
.hero-unit { color: var(--muted); font-weight: 700; margin-top: 4px; }
.hero-words { font-family: var(--display); font-size: 1.75rem; font-weight: 800; margin-top: 14px; }
.hero-stats { display: flex; justify-content: center; gap: 32px; margin-top: 14px; }
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats span { font-size: 0.8125rem; color: var(--muted); }
.hero-stats b { font-size: 1.125rem; font-variant-numeric: tabular-nums; }

.macros {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
  padding: 16px; border-radius: var(--r-panel); background: var(--surface); box-shadow: var(--shadow);
}
.macro { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.macro-label { font-size: 0.8125rem; font-weight: 700; color: var(--muted); }
.macro-val { font-size: 0.875rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.macro-val b { font-size: 1.0625rem; color: var(--ink); }
.bar { height: 6px; border-radius: 3px; background: var(--sunk); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--link); transform-origin: left center; }
.macro-protein .bar i { background: var(--protein); }
.macro-carbs .bar i { background: var(--carbs); }
.macro-fat .bar i { background: var(--fat); }

.notes { display: flex; flex-direction: column; gap: 10px; }
.notes:empty { display: none; }
.note {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-radius: 18px; background: var(--notice); color: var(--ink);
}
.note > span { min-width: 0; }
.note .btn { max-inline-size: 100%; white-space: normal; overflow-wrap: anywhere; }
.note.leaf { background: var(--accent-soft); }

.meals { display: flex; flex-direction: column; gap: 12px; }
.meal-card { background: var(--surface); border-radius: var(--r-panel); padding: 14px 16px; box-shadow: var(--shadow); }
.meal-head { display: flex; align-items: center; gap: 10px; }
.meal-kcal { color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.add-round {
  width: 38px; height: 38px; border-radius: 13px; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--link);
}
.add-round svg, .quick-chip svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.meal-card .list { margin-top: 6px; }
.meal-card .row:last-child { border-bottom: 0; }
.meal-foot { display: block; margin-top: 4px; }
.meal-empty { color: var(--muted); font-size: 0.9375rem; margin-top: 4px; }
.quick-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.quick-chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  padding: 6px 12px 6px 8px; border-radius: 999px; border: 1px dashed var(--line);
  background: none; cursor: pointer; font-size: 0.875rem;
}
.quick-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quick-chip svg { width: 16px; height: 16px; color: var(--link); flex-shrink: 0; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; flex-shrink: 0; }
.btn svg circle { fill: currentColor; stroke: none; }
.pick-count { color: var(--muted); font-weight: 700; text-align: center; padding: 8px 0; }
.pick-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 20px; border-radius: 22px; background: var(--surface);
  border: 2px solid var(--secondary); box-shadow: var(--shadow);
}
.pick-where { font-size: 0.875rem; font-weight: 700; color: var(--secondary); }
.pick-name { font-family: var(--display); font-size: 1.875rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; text-wrap: balance; min-height: 1.1em; }
.pick-meta { color: var(--muted); font-variant-numeric: tabular-nums; }
.pick-missing { font-size: 0.875rem; color: var(--muted); }
.reasons { display: flex; flex-wrap: wrap; gap: 6px; }
.reason { font-size: 0.8125rem; font-weight: 700; padding: 5px 10px; border-radius: 999px; background: var(--secondary-soft); }
.pick-card .btn-row { margin-top: 6px; }
.list.alt-list { background: var(--surface); border-radius: 18px; padding: 0 16px; }
.alt-list li:last-child .row { border-bottom: 0; }

/* ---------- Lists and rows ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.section { display: flex; flex-direction: column; }
.section > .list, ul.list.section {
  background: var(--surface); border-radius: var(--r-panel); padding: 2px 16px; box-shadow: var(--shadow);
}
.section > .list .row:last-child, ul.list.section li:last-child .row { border-bottom: 0; }
.row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left; cursor: pointer;
}
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 700; overflow-wrap: anywhere; }
.row-sub { display: block; font-size: 0.875rem; color: var(--muted); }
.row-num { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 700; }
.row-num.small { white-space: normal; text-align: right; max-width: 42%; font-weight: 400; color: var(--muted); }
.row-unit { font-weight: 400; color: var(--muted); font-size: 0.875rem; }
.empty { padding: 14px 0; color: var(--muted); }

.tag {
  display: inline-block; font-size: 0.75rem; line-height: 1; font-weight: 700;
  padding: 4px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 2px;
  background: var(--accent-soft); color: var(--ink);
}
.tag.est { background: var(--notice); }
.tag.pot { background: var(--secondary-soft); }

/* ---------- Panels (Progress) ---------- */
.panel { background: var(--surface); border-radius: var(--r-panel); padding: 18px 16px; box-shadow: var(--shadow); }

.plan-card {
  background: var(--navy); color: #fff8f2;
  border-radius: 26px; padding: 22px 20px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow-lift);
}
.plan-kicker { font-size: 0.875rem; font-weight: 700; color: #ffbc91; }
.plan-card h2 { font-size: 1.75rem; letter-spacing: -0.02em; color: #FFFFFF; }
.plan-eta { color: #ede4de; }
.plan-eta b { color: #FFFFFF; }
.plan-track { position: relative; height: 12px; border-radius: 6px; background: rgba(255, 255, 255, 0.18); margin-top: 6px; }
.plan-track i { position: absolute; inset: 0 auto 0 0; border-radius: 6px; background: var(--accent); }
.plan-track b {
  position: absolute; top: 50%; width: 22px; height: 22px; margin-left: -11px; transform: translateY(-50%);
  border-radius: 50%; background: #FFFFFF; border: 4px solid var(--accent);
}
.plan-ends { display: flex; justify-content: space-between; font-size: 0.8125rem; color: #ffbc91; font-variant-numeric: tabular-nums; }
.plan-ends span:nth-child(2) { color: #FFFFFF; font-weight: 700; }
.plan-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.plan-stats div { background: rgba(255, 255, 255, 0.1); border-radius: 16px; padding: 10px 12px; display: flex; flex-direction: column; }
.plan-stats span { font-size: 0.8125rem; color: #ffbc91; }
.plan-stats b { font-size: 1.125rem; color: #FFFFFF; font-variant-numeric: tabular-nums; }
.plan-note { font-size: 0.875rem; color: #ede4de; }
.plan-note .link { color: #FFFFFF; }
.btn.on-leaf { background: #FFFFFF; color: var(--navy); border-color: #FFFFFF; }

.chart-wrap { overflow-x: auto; }
.chart { width: 100%; height: auto; display: block; }
.chart text { font: 12px var(--body); fill: var(--muted); }
.chart-key { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 0.8125rem; color: var(--muted); margin-top: 4px; }
.key-plan, .key-goal { display: inline-block; width: 18px; height: 0; border-top: 2px dashed var(--chart-accent); }
.key-goal { border-top: 2px dotted var(--link); margin-left: 8px; }

.weigh-in { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 14px; }
@media (min-width: 420px) { .weigh-in { grid-template-columns: 1fr auto; } }

.stat-line { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.stat-line:last-of-type { border-bottom: 0; }
.stat-line b { font-variant-numeric: tabular-nums; text-align: right; }

.setting-row {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 10px 0; border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left; cursor: pointer; font-weight: 700;
}
.setting-row.danger { color: var(--danger); border-bottom: 0; }
.setting-row input { width: 22px; height: 22px; accent-color: var(--link); flex-shrink: 0; }

/* ---------- Buttons and controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 18px; border-radius: var(--r-control);
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 700;
}
.btn.primary { background: var(--accent); color: var(--navy); border-color: var(--accent); }
.btn.quiet { background: none; border-color: transparent; color: var(--link); padding-left: 8px; padding-right: 8px; min-height: 36px; }
.btn.danger { color: var(--danger); }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: var(--bg); }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.link { background: none; border: 0; padding: 0; color: var(--link); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 38px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700; font-size: 0.9375rem;
}
.chip[aria-pressed='true'] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.field { display: block; }
.field > span { display: block; font-size: 0.875rem; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.food-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
[data-food-browser] [hidden] { display: none; }
.food-filters select { width: 100%; min-height: 44px; padding-inline: 10px; }
.food-filters .btn { align-self: end; justify-self: start; min-height: 44px; }
.food-count { margin-block: 8px; }
.food-count:empty { margin: 0; }
.food-group, .picker-filters { border-block-end: 1px solid var(--line); }
.food-group summary, .picker-filters summary { min-height: 44px; cursor: pointer; padding: 10px 0; }
.food-group summary > span { font-weight: 700; }
.food-group summary small { color: var(--muted); margin-inline-start: 8px; font-variant-numeric: tabular-nums; }
.food-group-body { padding-bottom: 8px; }
.food-more { min-height: 44px; }
.picker-food-browser { display: grid; gap: 6px; }
.picker-filters[open] { padding-bottom: 8px; }
@supports (interpolate-size: allow-keywords) and selector(::details-content) {
  @media (prefers-reduced-motion: no-preference) {
    .food-group { interpolate-size: allow-keywords; }
    .food-group::details-content {
      block-size: 0; overflow: clip;
      transition: block-size var(--motion-select) var(--ease-out), content-visibility var(--motion-select) allow-discrete;
    }
    .food-group[open]::details-content { block-size: auto; }
  }
}
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: var(--r-control); background: var(--surface);
  font-size: 1rem;
}
.input:focus { border-color: var(--link); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 84px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 380px) { .grid4 { grid-template-columns: 1fr 1fr; } }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--link); flex-shrink: 0; }
.search { position: relative; display: block; }
.search .input { padding-left: 42px; }
.search svg { position: absolute; left: 14px; top: 14px; width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.error { color: var(--danger); font-size: 0.875rem; font-weight: 700; }

.stepper { display: grid; grid-template-columns: 48px 1fr 48px; gap: 8px; align-items: center; }
.step-btn {
  height: 48px; border-radius: var(--r-control); border: 0; cursor: pointer;
  background: var(--sunk); font-size: 1.5rem; font-weight: 700; line-height: 1;
}
.stepper .input { text-align: center; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.unit-input { position: relative; display: block; }
.unit-input span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; font-size: 0.9375rem; }
.stepper .unit-input .input { padding-right: 48px; padding-left: 48px; }
.extra-add .unit-input .input { padding-right: 28px; }

.options { display: flex; flex-direction: column; gap: 8px; }
.option {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  padding: 14px 16px; border-radius: 18px; border: 2px solid var(--line);
  background: var(--surface); cursor: pointer;
}
.option-title { font-weight: 700; }
.option-desc { font-size: 0.875rem; color: var(--muted); }
.option[aria-pressed='true'] { border-color: var(--link); background: var(--accent-soft); }
.option:disabled { opacity: 0.5; cursor: default; }

.result { padding: 16px; border-radius: 18px; background: var(--accent-soft); display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.result.bad { background: var(--notice); }
.result .btn { align-self: flex-start; }
.result-num { font-family: var(--display); font-size: 2.125rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.result-num span { font-family: var(--body); font-size: 1rem; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.result.big .result-num { font-size: 2.875rem; }
.macro-plan { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.macro-plan div { background: var(--surface); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; border: 1px solid var(--line); }
.macro-plan span { font-size: 0.8125rem; color: var(--muted); }
.macro-plan b { font-size: 1.125rem; font-variant-numeric: tabular-nums; }

.step-dots { display: flex; gap: 6px; }
.step-dots i { height: 6px; flex: 1; border-radius: 3px; background: var(--line); }
.step-dots i.done { background: var(--accent-soft); }
.step-dots i.on { background: var(--link); }

/* Ingredient and extra rows */
.ing { display: grid; grid-template-columns: 1fr 72px 112px 36px; gap: 6px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ing-name { font-weight: 700; font-size: 0.9375rem; min-width: 0; }
.ing-name small { display: block; font-weight: 400; color: var(--muted); font-size: 0.8125rem; }
.ing .input { min-height: 40px; padding: 6px 8px; }
.x-btn { width: 36px; height: 36px; border-radius: 50%; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 1.375rem; line-height: 1; }
.extra-add { display: grid; grid-template-columns: 1fr 84px auto; gap: 8px; margin-top: 8px; align-items: center; }

.preview {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
  padding: 16px; border-radius: 18px; background: var(--accent-soft);
}
.preview strong { font-family: var(--display); font-size: 1.875rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.preview span { font-size: 0.875rem; color: var(--muted); }

/* ---------- Sheets and dialogs ---------- */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-wrap[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 26px 26px 0 0; box-shadow: var(--shadow-lift);
  position: relative;
}
.sheet::before { content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: var(--line); }
.sheet-scrim { position: absolute; inset: 0; background: var(--scrim); }
.sheet-wrap.closing { pointer-events: none; }
.sheet-wrap.closing .sheet-head { pointer-events: auto; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding-top: 22px; padding-bottom: 10px; }
.sheet-head h2 { flex: 1; font-size: 1.5rem; }
.sheet-body { padding-top: 8px; padding-bottom: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding-top: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--bg); }
.sheet-head, .sheet-body, .sheet-foot {
  padding-left: max(18px, env(safe-area-inset-left, 0px));
  padding-right: max(18px, env(safe-area-inset-right, 0px));
}
.sheet-body h3 { margin-bottom: 8px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.dialog-wrap {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--scrim);
}
.dialog-wrap[hidden] { display: none; }
.dialog { width: 100%; max-width: 420px; display: grid; gap: 14px; padding: 22px; border-radius: 24px; background: var(--bg); box-shadow: var(--shadow-lift); }

.export-text { min-height: 220px; font-size: 0.8125rem; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; white-space: pre; overflow: auto; }

.facts { width: 100%; border-collapse: collapse; }
.facts td { padding: 9px 0; border-bottom: 1px solid var(--line); }
.facts td:last-child { text-align: right; font-variant-numeric: tabular-nums; }


/* ---------- Sodium, cost, plan, grocery, scan, import ---------- */
.macros-wrap { display: flex; flex-direction: column; gap: 14px; padding: 16px; border-radius: var(--r-panel); background: var(--surface); box-shadow: var(--shadow); }
.macros-wrap .macros { padding: 0; box-shadow: none; border-radius: 0; background: none; }
.sodium-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sodium .bar i { background: var(--muted); }
.sodium.over .bar i { background: var(--chart-accent); }
.note.care { background: var(--secondary-soft); align-items: flex-start; }
.note.care p { line-height: 1.45; }
.quick-chip.planned { border-style: solid; border-color: var(--link); background: var(--accent-soft); }

.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.mini-stats div { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; }
.mini-stats span { font-size: 0.8125rem; color: var(--muted); }
.mini-stats b { font-size: 1.0625rem; font-variant-numeric: tabular-nums; }

.price-box { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); }
.price-row { display: grid; grid-template-columns: 1fr auto 72px 1fr; gap: 6px; align-items: center; }
.price-row.per { grid-template-columns: 1fr auto; }
.price-row .unit-input .input { padding-left: 30px; padding-right: 10px; }
.price-row .unit-input span { left: 12px; right: auto; }
.price-row .input { min-height: 42px; padding: 6px 8px; }
.price-box .btn { align-self: flex-start; }
.price-item { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }

.plan-cta {
  display: flex; flex-direction: column; gap: 12px; padding: 16px; border-radius: var(--r-panel);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--link) 25%, transparent);
}
.plan-cta > div:first-child { display: flex; flex-direction: column; }
.plan-cta b { font-family: var(--display); font-size: 1.1875rem; font-weight: 800; }
.plan-cta span { color: var(--muted); font-size: 0.875rem; }
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.plan-day { background: var(--surface); border-radius: 18px; padding: 12px 14px; box-shadow: var(--shadow); }
.plan-day h3 { margin-bottom: 6px; }
.plan-slot { display: grid; grid-template-columns: 86px 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); align-items: start; }
.plan-meal { font-size: 0.875rem; color: var(--muted); font-weight: 700; padding-top: 6px; }
.plan-items { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 0; }
.plan-item { display: inline-flex; align-items: center; gap: 2px; padding: 4px 4px 4px 10px; border-radius: 999px; background: var(--accent-soft); font-size: 0.875rem; font-weight: 700; }
.plan-item .x-btn { width: 28px; height: 28px; font-size: 1.125rem; }
.grocery { background: var(--surface); border-radius: 16px; padding: 0 14px; }
.grocery-item { padding: 6px 0; border-bottom: 1px solid var(--line); }
.grocery li:last-child .grocery-item { border-bottom: 0; }
.grocery-item.done .row-title { text-decoration: line-through; color: var(--muted); }

.scan-box { display: flex; flex-direction: column; gap: 6px; }
.scan-box video { width: 100%; max-height: 260px; border-radius: 18px; background: #000; object-fit: cover; }
.import-text { min-height: 220px; }
.import-line { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.import-line.warn p { color: var(--danger); }
.import-fix { display: grid; grid-template-columns: 1fr 104px; gap: 6px; }
.import-fix .input { min-height: 42px; padding: 6px 8px; }
.import-fix .unit-input .input { padding-right: 26px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px); opacity: 0; width: max-content; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg);
  padding: 12px 20px; border-radius: 999px; font-weight: 700;
  pointer-events: none; transition: opacity var(--motion-press) var(--ease-out), transform var(--motion-select) var(--ease-out); z-index: 50;
}
.toast { display: flex; align-items: center; gap: 8px; overflow-wrap: anywhere; }
.save-check { display: none; width: 22px; height: 22px; flex: none; }
.committed .save-check { display: block; }
.save-check circle { fill: var(--accent); }
.save-check path { fill: none; stroke: var(--navy); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.sheet-wrap:not([hidden], .closing) ~ .toast { bottom: auto; top: calc(16px + env(safe-area-inset-top, 0px)); }

/* Trend, learned maintenance and insights */
.key-trend, .key-dot { display: inline-block; vertical-align: middle; margin: 0 4px 0 8px; }
.key-trend { width: 16px; height: 3px; border-radius: 2px; background: var(--link); }
.key-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--link); opacity: .4; }
.trend-stat { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.trend-stat b { font-family: var(--display); font-size: 1.625rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.trend-stat span { color: var(--muted); font-weight: 700; }
.trend-stat + .muted { margin: 4px 0 12px; }
.learn-card { border: 2px dashed color-mix(in srgb, var(--link) 35%, var(--line)); }
.learn-card.ready { border-style: solid; }
.unlock { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 8px; }
.unlock li { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.unlock .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 0.8125rem; flex-shrink: 0; }
.unlock li.done { color: var(--muted); }
.unlock li.done .tick { background: var(--link); border-color: var(--link); color: var(--on-link, #fff); }
.learn-num { margin: 6px 0 4px; }
.learn-num b { font-family: var(--display); font-size: 2.75rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.conf { font-size: 0.75rem; font-weight: 800; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.conf-high { background: var(--accent-soft); color: var(--link); }
.conf-medium { background: var(--notice); color: color-mix(in srgb, var(--chart-accent) 70%, var(--ink)); }
.conf-low { background: var(--sunk); color: var(--muted); }
.learn-card .note { margin-top: 10px; }
.learn-card .setting-row { margin-top: 10px; }
.insights { list-style: none; padding: 0; margin: 4px 0 8px; display: grid; gap: 12px; }
.insights li { display: grid; gap: 2px; padding-left: 12px; border-left: 3px solid var(--secondary); }
.insights b { font-family: var(--display); font-size: 1.0625rem; }
.insights span { color: var(--muted); font-size: 0.9375rem; }

/* Missed and partly logged days */
.day-dot.rough { background: transparent; box-shadow: inset 0 0 0 1.5px var(--link); }
.day[aria-pressed='true'] .day-dot.rough { box-shadow: inset 0 0 0 1.5px var(--chart-accent); }
.day-status { display: grid; gap: 8px; padding: 14px 16px; border-radius: 18px; background: var(--sunk); }
.sheet .day-status + .day-status { margin-top: 10px; }
.notes .day-status { margin-top: 0; }
.day-status-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; }
.day-status-head b { font-family: var(--display); font-size: 1.0625rem; }
.day-status-head span { color: var(--muted); font-weight: 700; font-size: 0.875rem; }
.day-status .chips { gap: 6px; }
.day-status p { margin: 0; }

/* Totals use native buttons for their contribution sheets. */
button.macro, .total-button { background: none; border: 0; text-align: left; padding: 0; color: inherit; }
button.macro { min-height: 44px; align-items: flex-start; }
button.macro .bar { align-self: stretch; }
button.macro small { color: var(--muted); }
.hero-stats .total-button { display: flex; flex-direction: column; }

/* The journal header, summary and meal rows form one reading column. */
body { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
::selection { background: var(--accent-soft); color: var(--ink); }
.masthead {
  display: flex; align-items: center; gap: 9px; margin-inline: 16px;
  padding-block: max(16px, env(safe-area-inset-top)) 14px; border-bottom: 1px solid var(--line);
  font: 800 1.6rem/1 var(--display); letter-spacing: -.04em;
}
.view { padding-top: 18px; }
h1 { font-size: 2.6rem; }
.today-head, .page-head { align-items: center; flex-wrap: wrap; }
.journal-month { color: var(--muted); font-weight: 700; }
.day-strip { gap: 0; padding-block: 3px; border-block: 1px solid var(--line); }
.day { background: none; min-width: 0; min-height: 48px; border-radius: 12px; }
.day[aria-pressed='true'] { background: var(--accent); color: var(--navy); }
.day[aria-pressed='true'] .day-name { opacity: 1; }
.day[aria-pressed='true'] .day-dot.on { background: var(--navy); }
.nutrition { background: var(--navy); border-radius: var(--r-panel); color: #fff8f2; }
.hero { text-align: left; padding: 18px 20px; }
.hero h2 { font: 700 1rem var(--body); color: #ffb782; }
.hero-num { display: block; font-size: 3.4rem; margin-top: 3px; }
.hero-unit, .hero-stats span { color: #e2dce0; }
.hero-stats { justify-content: flex-start; flex-wrap: wrap; gap: 8px 22px; }
.hero .bowl { width: 140px; --ink: #fff8f2; }
.nutrition .macros-wrap {
  margin: 0 20px; padding: 12px 0 16px; border-top: 1px solid #646479;
  background: none; border-radius: 0; --ink: #fff8f2; --muted: #dfd8df; --sunk: #4f5169;
  --protein: #ffac75; --carbs: #eec181; --fat: #d5c2eb;
}
.nutrition :focus-visible { outline-color: #ffaf73; }
.hero .calorie-progress { margin-top: 12px; background: #4a4d67; }
.hero .calorie-progress i { background: #ffb782; }
.activity-overview { padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r-panel); background: var(--surface); }
.activity-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.activity-heading h2 { font-size: 1.25rem; }
.activity-duration { color: var(--muted); font-variant-numeric: tabular-nums; }
.activity-duration strong { color: var(--ink); }
.activity-metrics { display: grid; gap: 4px; margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--line); }
.activity-metrics div { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto); gap: 10px; align-items: baseline; overflow-wrap: anywhere; }
.activity-metrics dt { font-size: .875rem; font-weight: 700; line-height: 1.25; }
.activity-metrics dd { margin: 0; color: var(--muted); font-size: .8125rem; }
.meals { gap: 0; }
.meals > .section-head { margin: 3px 0 0; align-items: center; padding-bottom: 9px; border-bottom: 2px solid var(--ink); }
.meals > .section-head h2 { font-size: 1.6rem; }
.meals .meal-card { border-bottom: 1px solid var(--line); border-radius: 0; padding: 11px 0; background: none; }
.meals .meal-empty { margin-top: -4px; padding-right: 50px; }
.meal-head :is(h2, h3) { flex: 1; font: 800 1.2rem var(--display); }
.add-round, .icon-btn { width: 46px; height: 46px; flex-shrink: 0; }
.add-round { border-radius: 50%; }
.tabs button { min-height: 48px; align-self: center; }
.tab-icon { max-width: 100%; }
.segments { position: relative; display: flex; gap: 3px; padding: 4px; background: var(--sunk); border-radius: 14px; }
.segments button { flex: 1; min-width: 0; min-height: 44px; border: 0; border-radius: 10px; font-weight: 700; background: none; cursor: pointer; }
.tabs, .segments { isolation: isolate; }
.segments button { position: relative; }
.selection-marker { position: absolute; inset: 0; z-index: -1; border-radius: inherit; background: var(--accent-soft); pointer-events: none; }
#food-content { display: contents; }
.segments::before {
  content: ""; position: absolute; inset-block: 4px; left: 4px; width: calc((100% - 14px) / 3);
  border-radius: 10px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--control-line);
  transition: transform var(--motion-select) var(--ease-move); pointer-events: none;
}
.segments[data-section="recipes"]::before { transform: translateX(calc(100% + 3px)); }
.segments[data-section="usuals"]::before { transform: translateX(calc(200% + 6px)); }
.segments:has(:focus-visible)::before { transition: none; }
.segments [aria-pressed="true"] { color: var(--link); }
button { touch-action: manipulation; user-select: none; }
@media (prefers-reduced-motion: no-preference) {
  .tab-log svg { transition: transform var(--motion-select) var(--ease-out); }
  .tab-log[aria-expanded="true"] svg { transform: scale(.9); }
  :where(button):not(:disabled) { transition: transform var(--motion-press) var(--ease-out); }
  :where(button):not(:disabled, :focus-visible):active { transform: scale(.97); }
}
@media (prefers-reduced-motion: reduce) {
  button:not(:disabled):active { opacity: .8; }
}
.profile-links { display: flex; gap: 0 14px; flex-wrap: wrap; border-block: 1px solid var(--line); }
.profile-links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--link); text-underline-offset: 4px; }
#appearance { width: auto; }
.input, select.input, textarea.input { border-color: var(--control-line); min-width: 0; }
.input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.field, .grid2 > *, .grid4 > * { min-width: 0; }
.sheet-head { touch-action: none; user-select: none; }
.sheet-body { overscroll-behavior: contain; }
body:has(.sheet-wrap:not([hidden], .closing), .dialog-wrap:not([hidden])) { overflow: hidden; }
.note { flex-wrap: wrap; }
.note > span { flex: 1 1 12rem; }
.chip { min-height: 44px; }
@media (min-width: 680px) {
  .app, .tabs { max-width: 700px; }
  .view { padding-inline: 32px; }
  .masthead { margin-inline: 32px; }
}
@media (min-width: 980px) {
  .app { max-width: 960px; display: grid; grid-template-columns: 190px minmax(0, 1fr); align-content: start; }
  .masthead { grid-column: 1 / -1; padding-block: 25px 18px; }
  .view { grid-column: 2; grid-row: 2; padding-block: 28px 4rem; }
  .tabs { grid-column: 1; grid-row: 2; position: sticky; top: 18px; align-self: start; margin: 28px 0 0 32px; padding: 0; border: 0; background: none; display: flex; flex-direction: column; align-items: stretch; gap: 5px; }
  .tabs button { flex-direction: row; gap: 6px; align-self: stretch; font-size: 1rem; }
  .tabs .tab-log { width: 100%; height: 48px; margin-block: 6px; border-radius: 12px; box-shadow: none; }
  .tab-log::after { content: 'Quick log'; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; }
}
