/* Steady — soft UI (neumorphism).
   Panels are the same colour as the page and are pressed out of it by a pair
   of shadows (light from the top-left, dark to the bottom-right). Pressed and
   selected things are pushed into the surface instead. No borders.
   Blue marks your data; coral marks what you tap and your goal. Status colours
   always come with an icon and a label. */

:root {
  /* One knob for all text sizes: 1 = original size. */
  --font-scale: 0.92;
  color-scheme: light;
  --bg: #e4e8ee;
  --bg-glow-1: transparent;
  --bg-glow-2: transparent;
  /* Soft UI: surfaces are the page colour; depth comes from paired shadows. */
  --surface: #e4e8ee;
  --surface-2: #e4e8ee;
  --surface-3: #d8dde5;
  --border: #d3d9e2;
  --text: #141821;
  --text-2: #444c59;
  --text-3: #5a6271;
  --accent: #d94a2a;
  --accent-strong: #cc391c;
  --accent-hi: #dc4526;
  --accent-ink: #ffffff;
  --accent-soft: #f5ddd5;
  --accent-soft-ink: #b5361a;
  --accent-shadow: rgb(204 57 28 / .35);
  --data: #3d5bd9;
  --data-strong: #2f47b0;
  --data-soft: #d6ddf5;
  --data-ink: #2f47b0;
  --data-on: #ffffff;
  --mark-muted: #949cab;
  --grid: #d6dbe3;
  --good: #13703a;  --good-soft: #d5ecdb;
  --warn: #a14a07;  --warn-soft: #f4e2c6;
  --danger: #b8232a;
  --drum-edge: #d2d8e1;
  --drum-mid: #f3f5f8;
  --hl: rgb(255 255 255 / .6);
  --drum-shade: rgb(80 95 120 / .25);
  --needle-ring: rgb(255 255 255 / .8);
  --needle-glow: rgb(217 74 42 / .35);
  /* the two light sources of soft UI */
  --neu-light: rgb(255 255 255 / .9);
  --neu-dark: rgb(160 170 188 / .6);
  --shadow-sm: none;
  --shadow: none;
  --shadow-lift: none;
  --raise:    7px 7px 16px var(--neu-dark), -7px -7px 16px var(--neu-light);
  --raise-sm: 4px 4px 9px var(--neu-dark), -4px -4px 9px var(--neu-light);
  --raise-xs: 2px 2px 5px var(--neu-dark), -2px -2px 5px var(--neu-light);
  --inset:    inset 4px 4px 9px var(--neu-dark), inset -4px -4px 9px var(--neu-light);
  --inset-sm: inset 2px 2px 5px var(--neu-dark), inset -2px -2px 5px var(--neu-light);
  --radius: 28px;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #2b3039;
    --bg-glow-1: transparent;
    --bg-glow-2: transparent;
    --surface: #2b3039;
    --surface-2: #2b3039;
    --surface-3: #353b45;
    --border: #3a414c;
    --text: #eef1f6;
    --text-2: #c8ced8;
    --text-3: #a3abb8;
    --accent: #ff7a59;
    --accent-strong: #cc391c;
    --accent-hi: #dc4526;
    --accent-soft: #4a3029;
    --accent-soft-ink: #ff9b80;
    --accent-shadow: rgb(0 0 0 / .5);
    --data: #7d97ff;
    --data-strong: #7d97ff;
    --data-soft: #363f5c;
    --data-ink: #a9baff;
    --data-on: #0e1430;
    --mark-muted: #78808e;
    --grid: #353b45;
    --good: #4ade80;  --good-soft: #24402d;
    --warn: #fbbf24;  --warn-soft: #47391a;
    --danger: #f87171;
    --drum-edge: #20242b;
    --drum-mid: #363c46;
    --hl: rgb(255 255 255 / .04);
    --drum-shade: rgb(0 0 0 / .55);
    --needle-ring: rgb(0 0 0 / .4);
    --needle-glow: rgb(255 122 89 / .45);
    --neu-light: rgb(255 255 255 / .06);
    --neu-dark: rgb(0 0 0 / .42);
    --shadow-sm: none;
    --shadow: none;
    --shadow-lift: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #2b3039;
  --bg-glow-1: transparent;
  --bg-glow-2: transparent;
  --surface: #2b3039;
  --surface-2: #2b3039;
  --surface-3: #353b45;
  --border: #3a414c;
  --text: #eef1f6;
  --text-2: #c8ced8;
  --text-3: #a3abb8;
  --accent: #ff7a59;
  --accent-strong: #cc391c;
  --accent-hi: #dc4526;
  --accent-soft: #4a3029;
  --accent-soft-ink: #ff9b80;
  --accent-shadow: rgb(0 0 0 / .5);
  --data: #7d97ff;
  --data-strong: #7d97ff;
  --data-soft: #363f5c;
  --data-ink: #a9baff;
  --data-on: #0e1430;
  --mark-muted: #78808e;
  --grid: #353b45;
  --good: #4ade80;  --good-soft: #24402d;
  --warn: #fbbf24;  --warn-soft: #47391a;
  --danger: #f87171;
  --drum-edge: #20242b;
  --drum-mid: #363c46;
  --hl: rgb(255 255 255 / .04);
  --drum-shade: rgb(0 0 0 / .55);
  --needle-ring: rgb(0 0 0 / .4);
  --needle-glow: rgb(255 122 89 / .45);
  --neu-light: rgb(255 255 255 / .06);
  --neu-dark: rgb(0 0 0 / .42);
  --shadow-sm: none;
  --shadow: none;
  --shadow-lift: none;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; min-height: 100vh;
  background:
    radial-gradient(900px 500px at 10% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(700px 500px at 110% 20%, var(--bg-glow-2), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: calc(15px * var(--font-scale))/1.5 var(--font);
  font-feature-settings: "tnum" 1, "cv11" 1;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button, .dial, input, a { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--text-3); }
.center { text-align: center; }
[hidden] { display: none !important; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- layout ---------- */
.top {
  max-width: 880px; margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) 6px calc(20px + env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: calc(19px * var(--font-scale)); letter-spacing: -.02em; }
.brand img { display: block; transition: transform .5s var(--ease-spring); }
.brand:hover img { transform: rotate(-8deg) scale(1.06); }
.top-right { display: flex; align-items: center; gap: 8px; }
main {
  max-width: 880px; margin: 0 auto; display: grid; gap: 16px;
  padding: 8px calc(20px + env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
}
.foot { text-align: center; font-size: calc(13px * var(--font-scale)); padding-top: 4px; }

/* Sections rise in gently on load, one after another. */
main > * { animation: rise-in .5s var(--ease-out) both; }
main > *:nth-child(2) { animation-delay: .06s; }
main > *:nth-child(3) { animation-delay: .12s; }
main > *:nth-child(4) { animation-delay: .18s; }
main > *:nth-child(5) { animation-delay: .24s; }
@keyframes rise-in { from { opacity: 0; transform: translateY(10px); } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; flex-wrap: wrap; }
h1, h2 { margin: 0; letter-spacing: -.015em; }
h2 { font-size: calc(16px * var(--font-scale)); font-weight: 650; }

.banner {
  display: flex; gap: 10px; align-items: center;
  background: var(--warn-soft); color: var(--text); border: 1px solid var(--warn);
  border-radius: 14px; padding: 10px 14px; font-size: calc(14px * var(--font-scale));
}
.banner .i { color: var(--warn); }
.banner.info { background: var(--accent-soft); border-color: transparent; }
.banner.info .i { color: var(--accent-soft-ink); }
.banner.info span { flex: 1; }
.banner.info a { color: var(--accent-soft-ink); font-weight: 650; }
.banner .icon-btn { width: 30px; height: 30px; }

/* ---------- pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px;
  padding: 3px 10px 3px 8px; font-size: calc(13px * var(--font-scale)); font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
}
.pill .i { width: 14px; height: 14px; stroke-width: 2.4; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.accent { background: var(--accent-soft); color: var(--accent-soft-ink); }
.streak { border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); }
.streak .i { color: var(--accent); }
.streak:hover .i { animation: flicker .6s ease-in-out; }
@keyframes flicker { 30% { transform: scale(1.2) rotate(-6deg); } 60% { transform: scale(.95) rotate(4deg); } }

/* ---------- buttons ---------- */
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid transparent;
  background: transparent; display: grid; place-items: center; color: var(--text-2);
  transition: background .2s ease, border-color .2s ease, transform .15s var(--ease-spring), color .2s ease;
}
.icon-btn:hover { background: var(--surface); border-color: var(--border); color: var(--text); transform: translateY(-1px); }
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#open-settings:hover svg { animation: spin-a-bit .6s var(--ease-out); }
@keyframes spin-a-bit { to { transform: rotate(60deg); } }

.primary {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, var(--accent-hi), var(--accent-strong));
  color: var(--accent-ink); border: 0; border-radius: 16px; padding: 14px 20px;
  font-weight: 650; font-size: calc(16px * var(--font-scale)); letter-spacing: -.005em;
  box-shadow: 0 1px 0 rgb(255 255 255 / .22) inset, 0 6px 16px -6px var(--accent-shadow);
  transition: transform .15s var(--ease-spring), box-shadow .2s ease, filter .2s ease, background .3s ease;
}
.primary:hover { transform: translateY(-1px); box-shadow: 0 1px 0 rgb(255 255 255 / .22) inset, 0 10px 22px -8px var(--accent-shadow); filter: saturate(1.08); }
.primary:active { transform: translateY(0) scale(.97); }
.primary:disabled { cursor: default; transform: none; }
.primary.small { padding: 9px 16px; font-size: calc(14px * var(--font-scale)); border-radius: 12px; }
.primary.done { background: var(--good); box-shadow: none; }
.primary .check { display: inline-flex; align-items: center; gap: 6px; animation: pop .35s var(--ease-spring); }
.primary .check svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
/* Ripple, positioned by JS at the press point. */
.ripple {
  position: absolute; border-radius: 50%; pointer-events: none; transform: scale(0);
  background: rgb(255 255 255 / .4); animation: ripple .6s ease-out forwards;
}
@keyframes ripple { to { transform: scale(1); opacity: 0; } }

.ghost {
  background: transparent; border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 14px; color: var(--text-2); font-size: calc(14px * var(--font-scale)); font-weight: 550;
  transition: background .2s ease, transform .15s var(--ease-spring), border-color .2s ease;
}
.ghost:hover { background: var(--surface-2); border-color: var(--surface-3); }
.ghost:active { transform: scale(.97); }
.ghost.wide { width: 100%; margin-top: 8px; }
.danger-ghost { background: transparent; border: 0; color: var(--danger); padding: 8px 4px; font-size: calc(14px * var(--font-scale)); font-weight: 550; }
.danger-ghost:hover { text-decoration: underline; }
.link {
  display: inline-flex; align-items: center; gap: 6px; color: var(--accent-soft-ink); text-decoration: none;
  font-size: calc(14px * var(--font-scale)); font-weight: 600; padding: 6px 10px; border-radius: 10px; transition: background .2s ease;
}
.link:hover { background: var(--accent-soft); }
button.link { border: 0; background: transparent; cursor: pointer; transition: background .2s ease, transform .15s var(--ease-spring); }
button.link:active { transform: scale(.96); }
.link .i { width: 16px; height: 16px; }

.input {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; font-size: calc(14px * var(--font-scale)); min-width: 0; transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
.input:hover { border-color: var(--surface-3); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); background: var(--surface); }

.header-log { display: inline-flex; align-items: center; gap: 6px; }
.header-log svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; transition: transform .3s var(--ease-spring); }
.header-log:hover svg { transform: rotate(90deg); }
.install {
  display: inline-flex; align-items: center; gap: 6px; font-size: calc(13px * var(--font-scale)); font-weight: 600;
  background: var(--accent-soft); color: var(--accent-soft-ink); border: 0; border-radius: 999px; padding: 6px 12px;
  transition: transform .15s var(--ease-spring);
}
.install:hover { transform: translateY(-1px); }
.install svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#theme-toggle svg { display: none; }
:root:not([data-theme]) #theme-toggle [data-icon="system"],
:root[data-theme="light"] #theme-toggle [data-icon="light"],
:root[data-theme="dark"] #theme-toggle [data-icon="dark"] { display: block; }

/* ---------- hero chart ---------- */
.hero { padding: 24px 24px 20px; }
.hero-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.hero-label { font-size: calc(12.5px * var(--font-scale)); font-weight: 650; color: var(--text-3); letter-spacing: .06em; text-transform: uppercase; }
.hero-value { margin: 4px 0 0; display: flex; align-items: baseline; gap: 6px; }
#hero-kg { font-size: calc(52px * var(--font-scale)); font-weight: 720; letter-spacing: -.045em; line-height: 1; font-variant-numeric: tabular-nums; }
.hero-sub { margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 26px; }
.hero .chart { height: 380px; }
.insight {
  margin: 14px 0 0; display: flex; gap: 10px; align-items: flex-start; font-size: calc(14px * var(--font-scale)); color: var(--text-2);
  background: var(--data-soft); border-radius: 14px; padding: 10px 12px;
}
.insight .i { color: var(--data); margin-top: 1px; }

/* Segmented control with a sliding thumb. */
.seg { position: relative; display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 0; width: 0; border-radius: 9px; background: var(--surface);
  box-shadow: 0 1px 3px rgb(30 45 20 / .14); transition: transform .35s var(--ease-spring), width .35s var(--ease-spring);
}
.seg button {
  position: relative; z-index: 1; border: 0; background: transparent; border-radius: 9px; padding: 5px 12px;
  font-size: calc(13px * var(--font-scale)); color: var(--text-3); font-weight: 650; transition: color .2s ease;
}
.seg button:hover, .seg button[aria-selected="true"] { color: var(--text); }

.legend { display: flex; gap: 16px; font-size: calc(12.5px * var(--font-scale)); color: var(--text-2); margin: 2px 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mark-muted); display: inline-block; }
.lg-line { width: 16px; height: 3px; border-radius: 2px; background: var(--data); display: inline-block; }
.lg-goal { width: 16px; height: 0; border-top: 2px dashed var(--accent); display: inline-block; }

.chart { position: relative; height: 300px; border-radius: 12px; cursor: crosshair; }
.chart:focus-visible { outline-offset: 4px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart-empty {
  position: absolute; inset: 0; display: grid; gap: 12px; align-content: center; justify-items: center;
  text-align: center; color: var(--text-3); font-size: calc(14px * var(--font-scale));
}
.chart-empty p { margin: 0; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--text-3); font-size: calc(11.5px * var(--font-scale)); }
.chart .dot { fill: var(--mark-muted); }
.chart.animate .dot { animation: fade-in .6s ease-out both; animation-delay: .35s; }
.chart .area-stop-1 { stop-color: var(--data); stop-opacity: .24; }
.chart .area-stop-2 { stop-color: var(--data); stop-opacity: 0; }
.chart.animate .area { animation: fade-in 1s ease-out .3s both; }
.chart .trend { fill: none; stroke: var(--data); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart.animate .trend { animation: draw 1.1s var(--ease-out) both; }
@keyframes draw { from { stroke-dashoffset: var(--len); } }
.chart .goal { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 5; opacity: .85; }
.chart .goal-label { fill: var(--accent-soft-ink); font-size: calc(11.5px * var(--font-scale)); font-weight: 650; }
.chart .end-dot { fill: var(--data); stroke: var(--surface); stroke-width: 2.5; }
.chart .end-pulse { fill: var(--data); transform-box: fill-box; transform-origin: center; animation: pulse 2.4s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(1); opacity: .45; } 70%, 100% { transform: scale(3.4); opacity: 0; } }
.chart .end-label rect { fill: var(--data-strong); }
.chart .end-label text { fill: var(--data-on); font-size: calc(12px * var(--font-scale)); font-weight: 700; }
.chart.animate .end-group { animation: fade-in .4s ease-out 1s both; }
.chart .cross { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hl-dot { fill: var(--text); stroke: var(--surface); stroke-width: 2; }
.chart .hl-trend { fill: var(--data); stroke: var(--surface); stroke-width: 2; }
.chart .new-ring { fill: none; stroke: var(--data); stroke-width: 2; transform-box: fill-box; transform-origin: center; animation: ring 1.2s ease-out 3 both; }
@keyframes ring { from { transform: scale(.6); opacity: 1; } to { transform: scale(2.8); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }

.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 11px; font-size: calc(13px * var(--font-scale)); box-shadow: var(--shadow-lift);
  min-width: 150px; transform: translate(-50%, 0); white-space: nowrap; z-index: 2;
  transition: left .12s var(--ease-out), top .12s var(--ease-out);
}
.tooltip .t-date { color: var(--text-3); font-size: calc(12px * var(--font-scale)); margin-bottom: 4px; font-weight: 550; }
.tooltip .t-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.tooltip .t-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.tooltip b { font-weight: 650; }
.tooltip .t-hint { color: var(--accent-soft-ink); font-size: calc(11.5px * var(--font-scale)); font-weight: 600; margin-top: 5px; }
.tooltip .t-note { color: var(--text-2); margin-top: 4px; max-width: 220px; white-space: normal; font-style: italic; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 760px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; text-align: left; color: var(--text);
  transition: transform .25s var(--ease-spring), box-shadow .25s ease, border-color .25s ease;
  animation: rise-in .5s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 60ms + .1s);
}
.tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); border-color: var(--surface-3); }
button.tile { cursor: pointer; font: inherit; }
button.tile:active { transform: translateY(-1px) scale(.98); }
.tile-top { display: flex; align-items: center; gap: 8px; }
.tile-icon {
  width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center;
  background: var(--data-soft); color: var(--data-ink); flex: none;
  transition: transform .35s var(--ease-spring);
}
.tile:hover .tile-icon { transform: rotate(-8deg) scale(1.1); }
.tile-icon .i { width: 16px; height: 16px; stroke-width: 2.1; }
.tile .label { font-size: calc(12.5px * var(--font-scale)); color: var(--text-3); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .value { font-size: calc(24px * var(--font-scale)); font-weight: 700; letter-spacing: -.025em; margin-top: 10px; white-space: nowrap; display: flex; align-items: baseline; gap: 3px; }
.tile .value small { font-size: calc(13px * var(--font-scale)); font-weight: 550; color: var(--text-3); letter-spacing: 0; }
.tile .sub { font-size: calc(12.5px * var(--font-scale)); color: var(--text-2); margin-top: 4px; display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub .pill { font-size: calc(11.5px * var(--font-scale)); padding: 1px 8px 1px 6px; }
.tile .sub .pill .i { width: 12px; height: 12px; }

/* ---------- history ---------- */
.history { list-style: none; margin: 0; padding: 0; }
.history li {
  display: grid; grid-template-columns: 1fr auto auto 32px; align-items: center; gap: 14px;
  padding: 10px 8px; border-radius: 12px; position: relative; transition: background .2s ease;
  animation: rise-in .4s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 25ms);
}
.history li + li::before { content: ""; position: absolute; left: 8px; right: 8px; top: 0; border-top: 1px solid var(--border); transition: opacity .2s ease; }
.history li { cursor: pointer; }
.history li:hover { background: var(--surface-2); }
.history li:active { transform: scale(.99); }
.history li:hover::before, .history li:hover + li::before { opacity: 0; }
.h-when { min-width: 0; }
.h-date { font-weight: 600; }
.h-time { color: var(--text-3); font-size: calc(13px * var(--font-scale)); margin-left: 6px; }
.h-note { display: block; color: var(--text-2); font-size: calc(13px * var(--font-scale)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-kg { font-weight: 680; font-size: calc(16px * var(--font-scale)); text-align: right; }
.h-delta { justify-self: end; }
.h-delta.pill { font-size: calc(12px * var(--font-scale)); padding: 2px 8px 2px 6px; }
.h-delta.pill .i { width: 12px; height: 12px; }
.h-edit { opacity: 0; width: 32px; height: 32px; transform: translateX(-4px); transition: opacity .2s ease, transform .2s var(--ease-out), background .2s ease; }
.history li:hover .h-edit, .h-edit:focus-visible { opacity: 1; transform: none; }
@media (hover: none) { .h-edit { opacity: .7; transform: none; } }

/* ---------- floating add button (phones only) ---------- */
.fab {
  display: none; position: fixed; z-index: 5;
  right: calc(18px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  width: 64px; height: 64px; border-radius: 22px; border: 0; place-items: center;
  background: linear-gradient(160deg, var(--accent-hi), var(--accent-strong));
  color: var(--accent-ink);
  box-shadow: 0 1px 0 rgb(255 255 255 / .25) inset, 0 14px 30px -10px var(--accent-shadow), 0 3px 8px rgb(30 45 20 / .18);
  transition: transform .25s var(--ease-spring), box-shadow .25s ease;
  animation: fab-in .5s var(--ease-spring) .3s both;
}
.fab svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; transition: transform .35s var(--ease-spring); }
.fab:hover svg { transform: rotate(90deg); }
.fab:active { transform: scale(.9); }
.fab.away { transform: translateY(calc(100% + 40px)) scale(.8); }
@keyframes fab-in { from { transform: scale(0) rotate(-45deg); } }

/* ---------- log sheet ---------- */
.log-head { text-align: center; margin-bottom: 4px; }
.log-head h2 { font-size: calc(19px * var(--font-scale)); }
.log-head p { margin: 4px 0 0; font-size: calc(14px * var(--font-scale)); }
#log-form { display: grid; gap: 14px; justify-items: center; }
.scale { width: 100%; display: grid; gap: 10px; justify-items: center; }
.readout-wrap { display: grid; justify-items: center; min-height: 112px; }
.readout, .readout-type {
  display: flex; align-items: baseline; gap: 6px; background: none; border: 0; padding: 0 8px;
  border-radius: 14px; font-variant-numeric: tabular-nums; transition: background .2s ease;
}
.readout:hover { background: var(--surface-2); }
#readout-value, #weight-type { font-size: calc(72px * var(--font-scale)); font-weight: 720; letter-spacing: -.045em; line-height: 1.1; }
#weight-type { width: 4.4ch; border: 0; background: transparent; text-align: right; padding: 0; box-shadow: 0 3px 0 var(--accent); }
#weight-type:focus { outline: none; }
.unit { font-size: calc(22px * var(--font-scale)); color: var(--text-3); font-weight: 550; letter-spacing: 0; }
.readout-delta { margin: 6px 0 0; min-height: 26px; }
.hint { margin: 0; font-size: calc(12px * var(--font-scale)); color: var(--text-3); }

.dial {
  position: relative; width: 100%; height: 108px; border-radius: 18px;
  background: linear-gradient(90deg, var(--drum-edge), var(--drum-mid) 30%, var(--drum-mid) 70%, var(--drum-edge));
  box-shadow:
    inset 0 1px 0 var(--hl),
    inset 0 12px 16px -12px var(--drum-shade),
    inset 0 -12px 16px -12px var(--drum-shade),
    0 0 0 1px var(--border);
  cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; overflow: hidden;
  transition: box-shadow .25s ease;
}
.dial:hover {
  box-shadow: inset 0 1px 0 var(--hl), inset 0 12px 16px -12px var(--drum-shade),
              inset 0 -12px 16px -12px var(--drum-shade), 0 0 0 1px var(--accent);
}
.dial.dragging { cursor: grabbing; }
.dial:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.dial canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.needle {
  position: absolute; left: 50%; top: 8px; bottom: 8px; width: 3px; margin-left: -1.5px;
  background: var(--accent); border-radius: 3px;
  box-shadow: 0 0 0 2px var(--needle-ring), 0 0 16px var(--needle-glow);
}
.needle::before {
  content: ""; position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: var(--accent); border-bottom: 0;
}
.when-row { display: flex; justify-content: center; width: 100%; }
.chip .chev { width: 15px; height: 15px; transition: transform .3s var(--ease-spring); }
.chip[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-soft-ink); }
.chip[aria-expanded="true"] .chev { transform: rotate(180deg); }
.when-panel {
  width: 100%; display: grid; gap: 10px; padding: 12px; border-radius: 16px;
  background: var(--surface-2); border: 1px solid var(--border);
  animation: panel-in .3s var(--ease-out);
}
@keyframes panel-in { from { opacity: 0; transform: translateY(-6px); } }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.qchip {
  flex: 1; border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: 999px; padding: 7px 10px; font-size: calc(13.5px * var(--font-scale)); font-weight: 600;
  transition: background .2s ease, color .2s ease, border-color .2s ease, transform .15s var(--ease-spring);
}
.qchip:hover { border-color: var(--accent); color: var(--accent-soft-ink); }
.qchip:active { transform: scale(.95); }
.qchip[aria-pressed="true"] { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.when-inputs { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
.when-inputs .field { margin: 0; }
.when-inputs .input { width: 100%; background: var(--surface); }
#log-form > .note { width: 100%; }
.sheet .danger-ghost { padding: 14px 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 8px 13px; font-size: calc(14px * var(--font-scale)); color: var(--text-2); font-weight: 550;
  transition: border-color .2s ease, background .2s ease, color .2s ease, transform .15s var(--ease-spring);
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-soft-ink); }
.chip:active { transform: scale(.96); }
.chip svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  color: var(--text); padding: 22px; width: min(400px, calc(100vw - 32px)); box-shadow: 0 30px 80px -20px rgb(20 30 10 / .4);
}
dialog::backdrop { background: rgb(16 24 10 / .34); backdrop-filter: blur(3px); }
dialog h2 { margin-bottom: 14px; }
dialog.sheet { width: min(520px, calc(100vw - 32px)); padding: 22px 22px 20px; }
dialog.sheet h2 { margin-bottom: 0; }
.sheet-grip { display: none; }
.sheet-actions { display: flex; gap: 10px; width: 100%; }
.sheet-actions .ghost { flex: 0 0 auto; padding: 14px 18px; border-radius: 16px; font-size: calc(15px * var(--font-scale)); }
.sheet-actions .primary { flex: 1; }
dialog[open] { animation: dialog-in .32s var(--ease-spring); }
dialog[open]::backdrop { animation: fade-in .25s ease-out; }
dialog.closing { animation: dialog-out .18s ease-in forwards; }
dialog.closing::backdrop { animation: fade-out .18s ease-in forwards; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(16px) scale(.96); } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes fade-out { to { opacity: 0; } }
.field { display: grid; gap: 5px; margin-bottom: 12px; font-size: calc(13px * var(--font-scale)); color: var(--text-2); font-weight: 550; }
.field em { font-style: normal; font-weight: 400; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.spacer { flex: 1; }
.error { color: var(--danger); font-size: calc(13px * var(--font-scale)); margin: 0 0 8px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 10;
  background: var(--text); color: var(--bg); border-radius: 14px; padding: 11px 16px;
  display: flex; gap: 10px; align-items: center; font-size: calc(14px * var(--font-scale)); font-weight: 550;
  box-shadow: 0 14px 36px -10px rgb(20 30 10 / .45);
  animation: toast-in .35s var(--ease-spring);
}
.toast-btn { background: transparent; border: 0; color: inherit; text-decoration: underline; text-underline-offset: 3px; font-weight: 700; padding: 0 0 0 6px; }
.toast-btn:hover { text-decoration: underline; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 16px) scale(.95); } }

@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }
.pop { animation: pop .35s var(--ease-spring); }

/* ---------- phones ---------- */
@media (max-width: 560px) {
  .top { padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(12px + env(safe-area-inset-right)); }
  main {
    padding-left: calc(10px + env(safe-area-inset-left)); padding-right: calc(10px + env(safe-area-inset-right));
    padding-bottom: calc(104px + env(safe-area-inset-bottom)); gap: 12px;
  }
  .card { padding: 18px 14px; border-radius: 20px; }
  .header-log, .streak { display: none; }
  .fab { display: grid; }
  .hero { padding: 18px 10px 14px; }
  .hero-head, .legend { padding: 0 8px; }
  #hero-kg { font-size: calc(46px * var(--font-scale)); }
  .hero .chart { height: 50vh; min-height: 280px; max-height: 460px; }
  .insight { margin-left: 4px; margin-right: 4px; }
  .seg { width: 100%; }
  .seg button { flex: 1; padding: 7px 0; }
  .tiles { gap: 10px; }
  .tile { padding: 12px 14px; }
  .tile .value { font-size: calc(22px * var(--font-scale)); }
    .history li { gap: 10px; padding: 12px 4px; }
  .icon-btn { width: 40px; height: 40px; }
  .hint { display: none; }
  #readout-value, #weight-type { font-size: calc(64px * var(--font-scale)); }
  .readout-wrap { min-height: 104px; }
  .dial { height: 116px; border-radius: 16px; }

  /* The log dialog becomes a bottom sheet. */
  dialog.sheet {
    width: 100%; max-width: none; margin: auto 0 0; border-radius: 26px 26px 0 0;
    border-bottom: 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92vh;
  }
  dialog.sheet[open] { animation: sheet-up .38s var(--ease-out); }
  dialog.sheet.closing { animation: sheet-down .22s ease-in forwards; }
  .sheet-grip { display: block; width: 42px; height: 5px; border-radius: 3px; background: var(--surface-3); margin: 0 auto 12px; }
  .toast { bottom: calc(100px + env(safe-area-inset-bottom)); }
}
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes sheet-down { to { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ======================================================================
   Soft UI shape layer. Kept last so it decides shape (shadows, borders,
   corners) everywhere; colours stay with the tokens above.
   ====================================================================== */

/* Raised panels */
.card, .tile, dialog, .sheet {
  background: var(--bg); border: 0; box-shadow: var(--raise);
}
.card { border-radius: var(--radius); }
.tile { border-radius: 22px; box-shadow: var(--raise-sm); }
.tile:hover { box-shadow: var(--raise); transform: translateY(-2px); border-color: transparent; }
button.tile:active { box-shadow: var(--inset); transform: none; }
dialog { box-shadow: var(--raise), 0 30px 80px -30px rgb(0 0 0 / .35); }

/* Raised controls that press in */
.icon-btn {
  background: var(--bg); border: 0; border-radius: 14px; box-shadow: var(--raise-xs);
}
.icon-btn:hover { background: var(--bg); box-shadow: var(--raise-sm); transform: none; }
.icon-btn:active { box-shadow: var(--inset-sm); transform: none; }
.ghost, .chip, .qchip, .install, button.link {
  background: var(--bg); border: 0; box-shadow: var(--raise-xs);
}
.ghost:hover, .chip:hover, .qchip:hover, .install:hover, button.link:hover {
  background: var(--bg); box-shadow: var(--raise-sm); transform: none;
}
.ghost:active, .chip:active, .qchip:active, .install:active, button.link:active {
  box-shadow: var(--inset-sm); transform: none;
}
.chip[aria-expanded="true"], .qchip[aria-pressed="true"] {
  background: var(--bg); color: var(--accent-soft-ink); box-shadow: var(--inset-sm);
}
.link { border-radius: 12px; }
a.link:hover { background: transparent; text-decoration: underline; }
.install { color: var(--accent-soft-ink); }

/* Accent buttons: coral, convex, press in */
.primary {
  border-radius: 18px;
  box-shadow: var(--raise-sm), inset 0 1px 0 rgb(255 255 255 / .2);
}
.primary:hover { box-shadow: var(--raise), inset 0 1px 0 rgb(255 255 255 / .2); transform: none; filter: brightness(1.04); }
.primary:active { box-shadow: inset 3px 3px 7px rgb(0 0 0 / .25), inset -2px -2px 5px rgb(255 255 255 / .15); transform: none; }
.primary.small { border-radius: 14px; }
.fab {
  border-radius: 50%;
  box-shadow: var(--raise), inset 0 1px 0 rgb(255 255 255 / .25);
}
.fab:active { box-shadow: inset 3px 3px 8px rgb(0 0 0 / .3); transform: none; }
.fab.away { transform: translateY(calc(100% + 40px)) scale(.8); }

/* Sunken wells */
.input, #weight-type {
  background: var(--bg); border: 0; box-shadow: var(--inset-sm); border-radius: 14px;
}
.input:hover { box-shadow: var(--inset-sm); }
.input:focus { background: var(--bg); box-shadow: var(--inset-sm), 0 0 0 2px var(--accent); }
#weight-type { box-shadow: var(--inset-sm); padding: 0 6px; }
.insight { background: var(--bg); box-shadow: var(--inset-sm); border-radius: 18px; }
.when-panel { background: var(--bg); border: 0; box-shadow: var(--inset); border-radius: 22px; }
.when-inputs .input { background: var(--bg); }
.banner { background: var(--bg); border: 0; box-shadow: var(--inset-sm); border-radius: 18px; }
.banner.info { background: var(--bg); }
.offline-banner, #offline { color: var(--warn); }

/* Segmented control: a carved track with a raised thumb */
.seg { background: var(--bg); box-shadow: var(--inset); border-radius: 16px; padding: 5px; }
.seg-thumb { top: 5px; bottom: 5px; border-radius: 12px; background: var(--bg); box-shadow: var(--raise-xs); }
.seg button { border-radius: 12px; }
.seg button[aria-selected="true"] { color: var(--accent-soft-ink); }

/* Tile icons and pills: small raised / sunken shapes */
.tile-icon { border-radius: 12px; box-shadow: var(--raise-xs); background: var(--bg); color: var(--data-ink); }
.pill { box-shadow: none; }
.streak { background: var(--bg); border: 0; box-shadow: var(--raise-xs); }
.brand img { border-radius: 9px; box-shadow: var(--raise-xs); }

/* Goal progress: a carved groove with a raised coral fill.
   The fill never shrinks below a small knob, so "you are here" shows at 0% too. */
.goal-bar { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.goal-track {
  flex: 1; height: 12px; padding: 3px; border-radius: 8px;
  background: var(--bg); box-shadow: var(--inset-sm); display: block;
}
.goal-track i {
  display: block; height: 100%; width: 0; min-width: 6px; border-radius: 5px;
  background: linear-gradient(90deg, var(--accent-hi), var(--accent));
  transition: width 1.3s var(--ease-out) .2s;
}
.goal-pct { font-size: calc(12.5px * var(--font-scale)); font-weight: 700; color: var(--text-2); min-width: 4ch; text-align: right; font-variant-numeric: tabular-nums; }

/* History rows lift out on hover instead of tinting */
.history li { border-radius: 16px; transition: box-shadow .25s ease, background .2s ease; }
.history li:hover { background: transparent; box-shadow: var(--raise-sm); }
.history li + li::before { border-top-color: var(--border); }

/* Scale: the drum sits in a recessed window */
.dial {
  border-radius: 22px;
  box-shadow: var(--inset), inset 0 14px 18px -14px var(--drum-shade), inset 0 -14px 18px -14px var(--drum-shade);
}
.dial:hover {
  box-shadow: var(--inset), inset 0 14px 18px -14px var(--drum-shade), inset 0 -14px 18px -14px var(--drum-shade), 0 0 0 2px var(--accent);
}
.readout:hover { background: transparent; box-shadow: var(--raise-xs); }

/* Tooltip and toast: floating, so they keep a real drop shadow */
.tooltip { background: var(--bg); border: 0; box-shadow: var(--raise-sm), 0 12px 28px -12px rgb(0 0 0 / .25); }

/* Phones: slightly smaller shadows so panels don't crowd each other */
@media (max-width: 560px) {
  :root {
    --raise:    5px 5px 12px var(--neu-dark), -5px -5px 12px var(--neu-light);
    --raise-sm: 3px 3px 8px var(--neu-dark), -3px -3px 8px var(--neu-light);
  }
  .card { border-radius: 24px; }
  dialog.sheet { box-shadow: 0 -10px 40px -10px rgb(0 0 0 / .3); border-radius: 30px 30px 0 0; }
  /* Narrow header: install becomes a round icon button. */
  .install { width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 14px; }
  .install-text { display: none; }
  .top-right { gap: 6px; }
  /* History rows are tappable to edit, so the pencil can go and dates stay on one line. */
  .history li { grid-template-columns: 1fr auto auto; }
  .h-edit { display: none; }
  .h-date { white-space: nowrap; }
}

/* ---------- privacy mode ----------
   Numbers on the main screen turn into blank, sunken placeholders. The chart
   keeps its shape (trend line, dots, goal line) but drops its number labels in JS.
   Inside the log/edit sheet numbers stay visible: you need them to enter a weight. */
.num { transition: color .25s ease, background-color .25s ease, box-shadow .25s ease; border-radius: 7px; }
:root.privacy main .num {
  color: transparent !important;
  background: var(--surface-3);
  box-shadow: var(--inset-sm);
  user-select: none; -webkit-user-select: none;
}
:root.privacy main .pill .num { padding: 0 2px; }
#privacy-toggle svg { display: none; }
:root:not(.privacy) #privacy-toggle [data-icon="shown"],
:root.privacy #privacy-toggle [data-icon="hidden"] { display: block; }
:root.privacy #privacy-toggle { color: var(--accent-soft-ink); box-shadow: var(--inset-sm); }

/* ---------- app-like touch behaviour ----------
   No accidental text selection or long-press callouts while scrolling;
   text fields stay selectable. The chart keeps vertical page scrolling. */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea, .h-note, .t-note { -webkit-user-select: text; user-select: text; }
.chart { touch-action: pan-y; -webkit-touch-callout: none; }

/* ======================================================================
   Tabs
   ====================================================================== */
.tabbar {
  display: flex; gap: 4px; padding: 5px; margin: 0 auto 2px; width: min(360px, 100%);
  background: var(--bg); box-shadow: var(--inset); border-radius: 18px;
}
.tabbar button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; background: transparent; border-radius: 14px; padding: 9px 12px;
  font-size: calc(14.5px * var(--font-scale)); font-weight: 650; color: var(--text-3);
  transition: color .2s ease, box-shadow .25s ease, transform .15s var(--ease-spring);
}
.tabbar button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button:hover { color: var(--text); }
.tabbar button[aria-selected="true"] { color: var(--accent-soft-ink); background: var(--bg); box-shadow: var(--raise-xs); }
.tabbar button:active { transform: scale(.97); }
.tab-panel { display: grid; gap: 16px; animation: rise-in .35s var(--ease-out) both; }
.tab-panel[hidden] { display: none; }

/* ======================================================================
   Food: day view
   ====================================================================== */
.small { font-size: calc(13px * var(--font-scale)); }
.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.day-nav .icon-btn svg { width: 18px; height: 18px; }
.day-nav .icon-btn:disabled { opacity: .35; cursor: default; box-shadow: none; }
.day-title { font-size: calc(17px * var(--font-scale)); font-weight: 700; text-align: center; flex: 1; }
.kcal-hero { text-align: center; display: grid; justify-items: center; gap: 6px; }
.kcal-hero .hero-value { justify-content: center; }
#day-kcal { font-size: calc(52px * var(--font-scale)); font-weight: 720; letter-spacing: -.045em; line-height: 1; font-variant-numeric: tabular-nums; }
.kcal-sub { margin: 0; color: var(--text-2); font-size: calc(14px * var(--font-scale)); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; }
.link.inline { padding: 2px 6px; font-size: calc(14px * var(--font-scale)); }
.kcal-hero .goal-bar { width: min(420px, 100%); margin-top: 4px; }
.goal-bar.over .goal-track i { background: linear-gradient(90deg, var(--warn), var(--warn)); }

.macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 18px 0 6px; }
.macros:empty { display: none; }
.macro {
  display: grid; gap: 2px; padding: 10px 10px; border-radius: 16px; text-align: center;
  background: var(--bg); box-shadow: var(--inset-sm); min-width: 0;
}
.macro-label { font-size: calc(12px * var(--font-scale)); font-weight: 650; color: var(--text-3); }
.macro-value { font-size: calc(19px * var(--font-scale)); font-weight: 700; letter-spacing: -.02em; }
.macro-value small { font-size: calc(12px * var(--font-scale)); font-weight: 550; color: var(--text-3); margin-left: 1px; }
.macro-sub { font-size: calc(11.5px * var(--font-scale)); color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.meal-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; }
.meal-list li { animation: rise-in .4s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 30ms); }
.meal-row {
  width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  text-align: left; border: 0; background: var(--bg); color: var(--text); padding: 11px 12px; border-radius: 16px;
  transition: box-shadow .25s ease, transform .15s var(--ease-spring);
}
.meal-row:hover { box-shadow: var(--raise-sm); }
.meal-row:active { box-shadow: var(--inset-sm); transform: none; }
.meal-time { font-size: calc(13px * var(--font-scale)); color: var(--text-3); font-variant-numeric: tabular-nums; }
.meal-main { min-width: 0; display: grid; }
.meal-name { font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-desc { font-size: calc(13px * var(--font-scale)); color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-kcal { font-weight: 680; white-space: nowrap; }
.meal-kcal small { color: var(--text-3); font-weight: 550; }
.food-empty { display: grid; justify-items: center; gap: 10px; padding: 18px 0 6px; color: var(--text-3); }
.food-empty p { margin: 0; }

.spin {
  width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* History per day */
.day-history { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.day-history li { animation: rise-in .4s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 25ms); }
.day-row {
  width: 100%; border: 0; background: var(--bg); color: var(--text); border-radius: 14px; padding: 10px 10px;
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name kcal" "bar count"; gap: 6px 12px; align-items: center; text-align: left;
  transition: box-shadow .25s ease;
}
.day-row:hover { box-shadow: var(--raise-sm); }
.day-row:active, .day-row.current { box-shadow: var(--inset-sm); }
.day-name { grid-area: name; font-weight: 620; }
.day-kcal { grid-area: kcal; font-weight: 680; text-align: right; white-space: nowrap; }
.day-kcal small { color: var(--text-3); font-weight: 550; }
.day-count { grid-area: count; font-size: calc(12.5px * var(--font-scale)); color: var(--text-3); text-align: right; white-space: nowrap; }
.day-bar { grid-area: bar; position: relative; height: 8px; border-radius: 6px; box-shadow: var(--inset-sm); }
.day-bar i { position: absolute; left: 2px; top: 2px; bottom: 2px; max-width: calc(100% - 4px); border-radius: 4px; background: var(--data); }
.day-bar.over i { background: var(--warn); }
.day-bar b { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--accent); border-radius: 2px; opacity: .8; }

/* ======================================================================
   Food: log-a-meal sheet with in-app camera
   ====================================================================== */
#meal-form { display: grid; gap: 12px; }
#meal-form h2 { margin: 0; font-size: calc(19px * var(--font-scale)); }
.camera {
  position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 46vh; border-radius: 22px; overflow: hidden;
  background: #0d0f12; box-shadow: var(--inset);
}
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .3s ease; }
.camera.live video { opacity: 1; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cam-flash.go { animation: flash .35s ease-out; }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }
.cam-msg {
  position: absolute; inset: 0; margin: 0; display: grid; place-items: center; padding: 24px; text-align: center;
  color: #e9ecf2; font-size: calc(14.5px * var(--font-scale)); line-height: 1.45;
}
.shutter {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: 72px; height: 72px; border-radius: 50%; border: 4px solid rgb(255 255 255 / .9); background: transparent; padding: 5px;
  display: none; transition: transform .15s var(--ease-spring);
}
.camera.live .shutter { display: block; }
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .15s ease; }
.shutter:active { transform: translateX(-50%) scale(.92); }
.shutter:active span { transform: scale(.88); }
.cam-count {
  position: absolute; top: 12px; right: 12px; font-size: calc(12.5px * var(--font-scale)); font-weight: 700; color: #fff;
  background: rgb(0 0 0 / .45); padding: 3px 9px; border-radius: 999px;
}
.shots { display: flex; gap: 10px; flex-wrap: wrap; }
.shots:empty { display: none; }
.shot { position: relative; margin: 0; width: 86px; height: 86px; border-radius: 16px; overflow: hidden; box-shadow: var(--raise-sm); animation: pop .3s var(--ease-spring); }
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot-x {
  position: absolute; top: 5px; right: 5px; width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: rgb(0 0 0 / .55); color: #fff; display: grid; place-items: center; padding: 0;
}
.shot-x svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.photo-actions .link { font-size: calc(14px * var(--font-scale)); }
#meal-desc { width: 100%; resize: vertical; min-height: 54px; font-size: calc(15px * var(--font-scale)); line-height: 1.4; }
.meal-when { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.fine { margin: 0; font-size: calc(12.5px * var(--font-scale)); color: var(--text-3); text-align: center; }

/* ======================================================================
   Food: meal detail sheet
   ====================================================================== */
.md { display: grid; gap: 12px; }
.md-head h2 { margin: 0; font-size: calc(20px * var(--font-scale)); }
.md-head p { margin: 2px 0 0; font-size: calc(13.5px * var(--font-scale)); }
.md-status { display: flex; gap: 10px; align-items: flex-start; padding: 11px 13px; border-radius: 16px; font-size: calc(14px * var(--font-scale)); box-shadow: var(--inset-sm); }
.md-status.analyzing { color: var(--data-ink); }
.md-status.failed { color: var(--warn); }
.md-status.failed span { color: var(--text-2); }
.md-status .spin { margin-top: 3px; }
.md-kcal { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.md-kcal-value { font-size: calc(40px * var(--font-scale)); font-weight: 720; letter-spacing: -.04em; line-height: 1; }
.md-kcal .pill { margin-left: 6px; align-self: center; }
.label-table { width: 100%; border-collapse: collapse; font-size: calc(14.5px * var(--font-scale)); border-radius: 16px; box-shadow: var(--inset-sm); }
.label-table caption { text-align: left; font-size: calc(12.5px * var(--font-scale)); font-weight: 650; color: var(--text-3); padding: 0 2px 6px; caption-side: top; }
.label-table th, .label-table td { padding: 7px 12px; border-top: 1px solid var(--border); }
.label-table tr:first-child th, .label-table tr:first-child td { border-top: 0; }
.label-table th { text-align: left; font-weight: 600; }
.label-table td { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.label-table tr.sub th { font-weight: 450; color: var(--text-2); padding-left: 26px; }
.label-table tr.sub td { color: var(--text-2); }
.label-table td .input { width: 110px; text-align: right; padding: 6px 9px; }
.label-table td #md-edit-name, .label-table td #md-edit-when { width: 100%; text-align: left; }
.md-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: calc(14px * var(--font-scale)); }
.md-items li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; padding: 4px 2px; }
.md-items li span:last-child { font-variant-numeric: tabular-nums; color: var(--text-2); }
.md-notes { margin: 0; display: flex; gap: 8px; align-items: flex-start; font-size: calc(14px * var(--font-scale)); color: var(--text-2); padding: 10px 12px; border-radius: 16px; box-shadow: var(--inset-sm); }
.md-notes .i { color: var(--data); margin-top: 1px; }
.md-desc { margin: 0; font-size: calc(14px * var(--font-scale)); color: var(--text-2); font-style: italic; }
.md-clarify { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.md-clarify .field { margin: 0; }
.md-clarify .ghost { padding: 10px 14px; }

/* ======================================================================
   Phones: tabs at the bottom, FAB above them
   ====================================================================== */
@media (max-width: 560px) {
  /* A slim, flat navigation bar along the bottom edge. */
  .tabbar {
    position: fixed; z-index: 6; left: 0; right: 0; bottom: 0; width: auto; margin: 0;
    border-radius: 0; gap: 0; padding: 2px 12px env(safe-area-inset-bottom);
    background: var(--bg);
    box-shadow: 0 -1px 0 var(--border), 0 -8px 20px -14px rgb(0 0 0 / .25);
  }
  .tabbar button {
    position: relative; flex-direction: column; gap: 1px; padding: 7px 6px 6px; border-radius: 10px;
    font-size: calc(11.5px * var(--font-scale)); font-weight: 600; background: transparent; box-shadow: none;
  }
  .tabbar button svg { width: 21px; height: 21px; }
  .tabbar button[aria-selected="true"] { background: transparent; box-shadow: none; }
  /* The active tab gets a short line along the top edge of the bar. */
  .tabbar button::before {
    content: ""; position: absolute; top: -2px; left: 50%; width: 28px; height: 3px; margin-left: -14px;
    border-radius: 0 0 3px 3px; background: var(--accent); transform: scaleX(0); transition: transform .25s var(--ease-spring);
  }
  .tabbar button[aria-selected="true"]::before { transform: scaleX(1); }
  /* "+" floats just above the bar. */
  .fab { bottom: calc(68px + env(safe-area-inset-bottom)); right: calc(16px + env(safe-area-inset-right)); width: 56px; height: 56px; }
  main { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(136px + env(safe-area-inset-bottom)); }
  .macros { grid-template-columns: repeat(2, 1fr); }
  #day-kcal { font-size: calc(46px * var(--font-scale)); }
  .camera { aspect-ratio: 3 / 4; max-height: 52vh; }
  .shot { width: 72px; height: 72px; }
}

/* ======================================================================
   Suggested targets
   ====================================================================== */
.suggest-btn {
  width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; margin: 0 0 16px;
  border: 0; border-radius: 18px; padding: 12px 14px; background: var(--bg); color: var(--text);
  box-shadow: var(--raise-sm); transition: box-shadow .25s ease, transform .15s var(--ease-spring);
}
.suggest-btn:hover { box-shadow: var(--raise); }
.suggest-btn:active { box-shadow: var(--inset-sm); }
.suggest-btn .i { width: 26px; height: 26px; color: var(--data); flex: none; }
.suggest-btn span { display: grid; gap: 2px; }
.suggest-btn small { color: var(--text-3); font-size: calc(12.5px * var(--font-scale)); }
#settings-dialog { width: min(440px, calc(100vw - 32px)); }

.tg { display: grid; gap: 14px; }
.tg h2 { margin: 0; font-size: calc(19px * var(--font-scale)); }
.tg > p { margin: 0; }
.tg-q { display: grid; gap: 7px; }
.tg-label { font-size: calc(13px * var(--font-scale)); font-weight: 650; color: var(--text-2); }
.tg-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tg-row .field { margin: 0; }
.tg-row .input { width: 100%; }
.choice { display: flex; gap: 6px; padding: 5px; border-radius: 16px; box-shadow: var(--inset-sm); }
.choice button {
  flex: 1; border: 0; background: transparent; color: var(--text-2); border-radius: 12px; padding: 9px 8px;
  font-size: calc(14px * var(--font-scale)); font-weight: 600; transition: box-shadow .2s ease, color .2s ease;
}
.choice button:hover { color: var(--text); }
.choice button[aria-checked="true"] { background: var(--bg); color: var(--accent-soft-ink); box-shadow: var(--raise-xs); }
.choice.vertical { flex-direction: column; }
.choice.vertical button { display: grid; gap: 1px; text-align: left; padding: 9px 12px; }
.choice.vertical small { font-weight: 450; font-size: calc(12.5px * var(--font-scale)); color: var(--text-3); }
#tg-notes { width: 100%; resize: vertical; }

.tg-result { display: grid; gap: 14px; }
.tg-result h2 { margin: 0; font-size: calc(19px * var(--font-scale)); }
.tg-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tg-card { display: grid; gap: 3px; padding: 12px 14px; border-radius: 18px; box-shadow: var(--raise-sm); }
.tg-card span { font-size: calc(12.5px * var(--font-scale)); font-weight: 650; color: var(--text-3); }
.tg-card b { font-size: calc(22px * var(--font-scale)); font-weight: 720; letter-spacing: -.02em; }
.tg-rationale { margin: 0; font-size: calc(15px * var(--font-scale)); line-height: 1.5; color: var(--text-2); }
#tg-adjusted { margin: 0; }
@media (max-width: 560px) {
  .tg-row { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .choice button { font-size: calc(13px * var(--font-scale)); padding: 9px 4px; }
}

/* ======================================================================
   Filling progress bar (AI analysis)
   ====================================================================== */
.progress-wrap { display: grid; gap: 6px; width: 100%; }
.progress-label { font-size: calc(13px * var(--font-scale)); font-weight: 600; color: var(--data-ink); }
.progress {
  position: relative; display: block; height: 8px; border-radius: 6px; overflow: hidden;
  background: var(--bg); box-shadow: var(--inset-sm);
}
.progress i {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 6px;
  background: linear-gradient(90deg, var(--data), color-mix(in srgb, var(--data) 70%, white));
  transition: width .25s linear;
}
/* A soft sheen sweeping over the filled part, so it never looks stuck. */
.progress i::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgb(255 255 255 / .45), transparent);
  transform: translateX(-100%); animation: sheen 1.6s ease-in-out infinite;
}
@keyframes sheen { to { transform: translateX(100%); } }
.meal-main .progress-wrap { margin-top: 6px; gap: 4px; }
.meal-main .progress-label { font-size: calc(12.5px * var(--font-scale)); }
.md-status.analyzing { display: block; }
.tg-working { display: grid; gap: 14px; padding: 6px 0 10px; }
.tg-working h2 { margin: 0; font-size: calc(19px * var(--font-scale)); }
.tg-working .progress { height: 10px; }
.tg-working p { margin: 0; }

/* Panels that take focus themselves (so no text box opens the phone keyboard). */
.md:focus { outline: none; }

/* ---------- scrolling inside panels ----------
   Panels scroll on their own and keep the gesture to themselves; without this a
   swipe inside a meal panel scrolled the page behind it, and at the top Chrome
   turned it into pull-to-refresh. Pull-to-refresh must be disabled on <html>. */
html { overscroll-behavior-y: none; }
dialog {
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 560px) {
  dialog.sheet { max-height: calc(100dvh - 16px); }
}
/* While a panel is open, the page behind it must not scroll: only the panel does. */
html:has(dialog[open]) { overflow: hidden; }
/* Hidden meal names keep a sensible placeholder width. */
:root.privacy main .meal-name .num, :root.privacy main .meal-desc .num { display: inline-block; min-width: 7em; max-width: 100%; }

/* ---------- camera shutter bar ---------- */
.cam-bar { display: none; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 6px; }
#meal-form.shooting .cam-bar { display: flex; }
.cam-bar .shutter {
  position: static; transform: none; display: block; flex: none;
  width: 74px; height: 74px; padding: 5px; border-radius: 50%;
  border: 4px solid var(--accent); background: var(--bg); box-shadow: var(--raise-sm);
}
.cam-bar .shutter span { background: var(--accent); }
.cam-bar .shutter:active { transform: scale(.93); }
.cam-side {
  width: 52px; height: 52px; border-radius: 16px; border: 0; display: grid; place-items: center;
  background: var(--bg); color: var(--text-2); box-shadow: var(--raise-xs);
}
.cam-side:active { box-shadow: var(--inset-sm); }
.cam-side .i { width: 22px; height: 22px; }
.cam-side.text { width: auto; min-width: 52px; padding: 0 14px; font-size: calc(14px * var(--font-scale)); font-weight: 600; }

@media (max-width: 560px) {
  /* While the camera is on, the panel is all viewfinder with the shutter bar at the bottom. */
  #meal-form.shooting { display: flex; flex-direction: column; min-height: calc(100dvh - 60px - env(safe-area-inset-bottom)); }
  #meal-form.shooting .camera { flex: 1; aspect-ratio: auto; max-height: none; min-height: 45vh; }
  #meal-form.shooting > :is(.shots, .photo-actions, #meal-desc, .meal-when, .fine, .sheet-actions) { display: none; }
  #meal-form.shooting .cam-bar { padding: 6px 10px calc(4px + env(safe-area-inset-bottom)); }
}
/* Language picker in Settings */
.lang-field select { width: 100%; appearance: none; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }

/* Day totals as a nutrition table */
.day-nutrition { margin: 18px 0 6px; }
.day-nutrition:empty { display: none; }

/* ---------- health grade A–E ---------- */
.health {
  display: inline-grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 8px;
  font-size: calc(13px * var(--font-scale)); font-weight: 800; line-height: 1; box-shadow: var(--raise-xs);
}
.health.h-A { background: #1e7f45; color: #fff; }
.health.h-B { background: #78b041; color: #10220a; }
.health.h-C { background: #f0b400; color: #2b1d00; }
.health.h-D { background: #c4561a; color: #fff; }
.health.h-E { background: #b3261e; color: #fff; }
.meal-right { display: inline-flex; align-items: center; gap: 8px; }
.md-health { margin: 0; display: flex; gap: 10px; align-items: flex-start; font-size: calc(14px * var(--font-scale)); color: var(--text-2);
  padding: 10px 12px; border-radius: 16px; box-shadow: var(--inset-sm); }
.md-health .health { margin-top: -1px; }
.md-health b { color: var(--text); font-weight: 650; margin-right: 4px; }

/* Camera: the live picture fills the whole viewfinder. */
.camera video { position: absolute; inset: 0; }

/* ======================================================================
   Settings: grouped cards, rows with the control on the right
   ====================================================================== */
#settings-dialog { width: min(480px, calc(100vw - 32px)); }
.set { display: grid; gap: 18px; }
.set-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.set-head h2 { margin: 0; font-size: calc(20px * var(--font-scale)); }
.set-saved { display: inline-flex; align-items: center; gap: 5px; font-size: calc(13px * var(--font-scale)); font-weight: 650; color: var(--good); animation: fade-in .2s ease-out; }
.set-saved .i { width: 16px; height: 16px; stroke-width: 2.6; }
.set-group { display: grid; gap: 8px; }
.set-group h3 { margin: 0 4px; font-size: calc(12.5px * var(--font-scale)); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.set-card { border-radius: 20px; box-shadow: var(--inset-sm); overflow: hidden; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; padding: 8px 14px; color: var(--text); text-decoration: none;
}
.set-row + .set-row { border-top: 1px solid var(--border); }
.set-label { display: grid; font-size: calc(15px * var(--font-scale)); font-weight: 550; }
.set-label small { font-size: calc(12.5px * var(--font-scale)); font-weight: 450; color: var(--text-3); }
.set-hint { margin: 0 4px; font-size: calc(12.5px * var(--font-scale)); color: var(--text-3); }
.set-link { cursor: pointer; transition: background .2s ease; }
.set-link:hover { background: var(--surface-3); }
.set-link .i { width: 18px; height: 18px; color: var(--text-3); }

/* A number field with its unit inside */
.unit-input {
  display: inline-flex; align-items: baseline; gap: 6px; padding: 8px 12px; border-radius: 12px;
  background: var(--bg); box-shadow: var(--raise-xs); transition: box-shadow .2s ease;
}
.unit-input:focus-within { box-shadow: var(--inset-sm), 0 0 0 2px var(--accent); }
.unit-input input {
  width: 5.5ch; border: 0; background: transparent; text-align: right; padding: 0;
  font-size: calc(16px * var(--font-scale)); font-weight: 650; font-variant-numeric: tabular-nums;
}
.unit-input input:focus { outline: none; }
.unit-input em { font-style: normal; font-size: calc(13px * var(--font-scale)); color: var(--text-3); font-weight: 550; }

/* Compact choices for language and theme */
.choice.compact { padding: 3px; gap: 2px; border-radius: 12px; flex: none; }
.choice.compact button { flex: none; padding: 6px 10px; font-size: calc(13px * var(--font-scale)); border-radius: 9px; }

/* On/off switch */
.switch {
  position: relative; width: 50px; height: 30px; border: 0; border-radius: 999px; flex: none;
  background: var(--bg); box-shadow: var(--inset-sm); transition: background .25s ease;
}
.switch i {
  position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg); box-shadow: var(--raise-xs); transition: transform .3s var(--ease-spring), background .25s ease;
}
.switch[aria-checked="true"] { background: var(--accent-strong); }
.switch[aria-checked="true"] i { transform: translateX(20px); background: #fff; }

.suggest-btn { margin: 0; }
.suggest-btn .chev { width: 18px; height: 18px; color: var(--text-3); margin-left: auto; }
#settings-dialog .sheet-actions .primary { flex: 1; }

/* Day table: values above the daily reference */
.label-table tr.is-high td { color: var(--warn); font-weight: 650; }
.label-table .pill.high { font-size: calc(11.5px * var(--font-scale)); padding: 1px 8px 1px 5px; margin-right: 8px; vertical-align: 1px; }
.label-table .pill.high .i { width: 12px; height: 12px; }
.high-note { margin: 8px 4px 0; }
/* Settings: the panel takes focus itself (no keyboard), and is full width on phones */
#settings-form:focus { outline: none; }
@media (max-width: 560px) { #settings-dialog { width: 100%; } }

/* Camera: a calm placeholder until the live picture arrives; dark only while live. */
.camera { background: var(--bg); }
.camera.live { background: #0d0f12; }
.cam-starting {
  position: absolute; inset: 0; margin: 0; display: grid; place-items: center;
  font-size: calc(14px * var(--font-scale)); font-weight: 600; color: var(--text-3);
}
.camera.live .cam-starting, .camera:has(.cam-msg:not([hidden])) .cam-starting { display: none; }
.cam-msg { color: var(--text-2); }
.camera video { min-width: 100%; min-height: 100%; }
/* Focus targets at the top of panels: invisible */
.sheet-grip:focus { outline: none; }

/* ---------- button rows on phones ----------
   The main action gets its own full-width row at the bottom; other buttons share
   the row above. Long labels (e.g. in Dutch) wrap instead of squeezing. */
.sheet-actions button, .dialog-actions button { white-space: normal; line-height: 1.25; }
@media (max-width: 560px) {
  .sheet-actions { flex-wrap: wrap; gap: 10px; }
  .sheet-actions > .spacer { display: none; }
  .sheet-actions > button { flex: 1 1 0; min-height: 48px; }
  .sheet-actions > .primary { flex: 1 1 100%; order: 10; min-height: 54px; }
  .sheet-actions > .danger-ghost { flex: 0 0 auto; padding: 0 10px; }
  .md-clarify { grid-template-columns: 1fr; }
  .md-clarify .ghost { width: 100%; min-height: 46px; }
}

/* Meal date/time: a tappable line under the name */
.md-when {
  display: inline-flex; align-items: center; gap: 7px; margin-top: 4px; padding: 6px 10px; border: 0; border-radius: 12px;
  background: var(--bg); color: var(--text-2); font-size: calc(13.5px * var(--font-scale)); box-shadow: var(--raise-xs);
}
.md-when .i { width: 15px; height: 15px; color: var(--text-3); }
.md-when .pen { color: var(--accent-soft-ink); }
.md-when[aria-expanded="true"] { box-shadow: var(--inset-sm); color: var(--accent-soft-ink); }
.md-when-panel { display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px; margin-top: 10px; padding: 12px; border-radius: 18px; box-shadow: var(--inset-sm); animation: panel-in .3s var(--ease-out); }
.md-when-panel .field { margin: 0; }
.md-when-panel .input { width: 100%; }

/* ======================================================================
   Trends tab
   ====================================================================== */
.trends-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 0 4px; }
.trends-top .day-title { text-align: left; flex: 1 1 auto; }
.tr-chart { position: relative; height: 340px; }
.tr-chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.tr-chart .grid line { stroke: var(--grid); stroke-width: 1; }
.tr-chart .axis text, .tr-nodata { fill: var(--text-3); font-size: calc(11px * var(--font-scale)); }
.tr-bar { fill: var(--data); opacity: .9; transform-box: fill-box; transform-origin: bottom; }
.tr-chart.animate .tr-bar { animation: grow .5s var(--ease-out) both; animation-delay: calc(var(--i) * 12ms); }
@keyframes grow { from { transform: scaleY(0); } }
.tr-chart .goal { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 5; }
.tr-chart .trend { fill: none; stroke: var(--data); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.tr-chart .end-dot { fill: var(--data); stroke: var(--bg); stroke-width: 2; }
.tr-chart .cross { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
.lg-bar { width: 10px; height: 10px; border-radius: 3px; background: var(--data); display: inline-block; }

/* Energy split: protein / carbs / fat in fixed category colours, always labelled */
:root { --cat-1: #2a78d6; --cat-2: #eb6834; --cat-3: #1baf7a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; } }
:root[data-theme="dark"] { --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; }
.split { display: flex; gap: 2px; height: 34px; border-radius: 12px; overflow: hidden; box-shadow: var(--inset-sm); }
.split span { display: grid; place-items: center; min-width: 34px; color: #fff; font-size: calc(12.5px * var(--font-scale)); }
.split-protein, .lg-protein { background: var(--cat-1); }
.split-carbs, .lg-carbs { background: var(--cat-2); }
.split-fat, .lg-fat { background: var(--cat-3); }
.split-legend { margin: 10px 0 6px; flex-wrap: wrap; }
.split-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Health grades A–E */
.grades { display: grid; gap: 8px; }
.grade-row { display: grid; grid-template-columns: 24px 1fr 32px; gap: 10px; align-items: center; }
.grade-bar { height: 10px; border-radius: 6px; box-shadow: var(--inset-sm); overflow: hidden; }
.grade-bar i { display: block; height: 100%; border-radius: 6px; min-width: 2px; }
.grade-bar i.h-A { background: #1e7f45; } .grade-bar i.h-B { background: #78b041; } .grade-bar i.h-C { background: #f0b400; }
.grade-bar i.h-D { background: #c4561a; } .grade-bar i.h-E { background: #b3261e; }
.grade-n { text-align: right; font-weight: 650; color: var(--text-2); font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .tr-chart { height: 300px; } .tabbar button span { font-size: calc(11px * var(--font-scale)); } }

/* Tile labels and subtitles wrap (up to two lines) instead of being cut off, e.g. in Dutch. */
.tile .label, .tile .sub { white-space: normal; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-height: 1.3; }
.tile .sub { display: -webkit-box; }
.tile-top { align-items: flex-start; }
.tile-top .label { padding-top: 5px; }

/* Settings as a tab */
.tabbar { width: min(520px, 100%); }
.settings-card { padding-top: 20px; }
.settings-card .set-head { padding: 0 2px; }
.settings-card .set-head .day-title { text-align: left; }

/* ---------- sign-in ---------- */

/* Until the signed-in state is known, and while signed out, only the sign-in screen shows. */
body.auth-pending > header, body.auth-pending > main, body.auth-pending > nav,
body.signed-out > header, body.signed-out > main, body.signed-out > nav { display: none; }
body.auth-pending .fab, body.signed-out .fab { display: none; }

.signin {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  animation: fade-in .3s ease-out;
}
.signin-card {
  width: min(380px, 100%); display: grid; justify-items: center; gap: 14px; text-align: center;
  padding: 36px 26px 28px; border-radius: 28px; background: var(--bg); box-shadow: var(--raise);
}
.signin-logo { animation: signin-bob 3.2s ease-in-out infinite; filter: drop-shadow(0 8px 14px var(--accent-shadow)); }
@keyframes signin-bob { 50% { transform: translateY(-5px) rotate(-3deg); } }
@media (prefers-reduced-motion: reduce) { .signin-logo { animation: none; } }
.signin h1 { margin: 4px 0 0; font-size: calc(30px * var(--font-scale)); letter-spacing: -.02em; }
.signin-tag { margin: 0 0 10px; color: var(--text-2); font-size: calc(15.5px * var(--font-scale)); }
.signin-form, .signin-verify { width: 100%; display: grid; gap: 10px; text-align: left; }
.signin-form .field { margin: 0; }
.signin-form .input { width: 100%; box-sizing: border-box; font-size: calc(16px * var(--font-scale)); }
.signin-verify p { margin: 0 0 4px; color: var(--text-2); text-align: center; overflow-wrap: anywhere; }
.signin-btn { width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 10px; margin-top: 4px; }
.signin-link { justify-self: center; }
.signin-msg { margin: 0; text-align: center; font-size: calc(13px * var(--font-scale)); color: var(--good); }
.signin-btn:disabled { opacity: .7; }
.signin-error { margin: 0; text-align: center; }
.signin-note { margin: 6px 0 0; font-size: calc(12.5px * var(--font-scale)); color: var(--text-3); }

/* ---------- account & AI costs ---------- */

.acct-email { overflow-wrap: anywhere; }
.spend-value { font-size: calc(17px * var(--font-scale)); font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }
button.set-row, label.set-row { width: 100%; border: 0; background: transparent; font: inherit; text-align: left; }
button.set-row + .set-row, label.set-row + .set-row, input + .set-row { border-top: 1px solid var(--border); }

/* Kept meal photos (small copies, for 7 days) in the meal details */
.md-photos { display: flex; gap: 8px; overflow-x: auto; margin: 4px 0 12px; scrollbar-width: none; }
.md-photos img { height: 112px; width: auto; max-width: 70%; border-radius: 14px; object-fit: cover; flex: none; box-shadow: var(--raise-xs); }
html.privacy .md-photos { display: none; }

/* Goal date in Settings */
.unit-input.date-input input { width: auto; font-size: calc(15px * var(--font-scale)); }
.goal-plan { display: grid; gap: 8px; padding: 12px 14px; border-radius: 16px; box-shadow: var(--inset-sm); font-size: calc(14px * var(--font-scale)); color: var(--text-2); line-height: 1.45; }
.goal-plan p { margin: 0; }
.goal-plan .pill { justify-self: start; }
.goal-plan button { justify-self: start; }

/* Protein and fibre next to their daily goals in the day's nutrition table */
.label-table .of-goal { color: var(--text-3); font-weight: 450; }
.label-table tr.is-met td { color: var(--good); }
.label-table .pill.met { padding: 1px 5px; margin-right: 4px; vertical-align: middle; }
.label-table .pill.met .i { width: 12px; height: 12px; margin: 0; }

/* ---------- Ask Steady ---------- */
.ask-btn { color: var(--accent-soft-ink); }
.ask { display: grid; gap: 12px; }
.ask-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ask-head h2 { margin: 0; }
.ask-intro { margin: -6px 0 0; font-size: calc(14px * var(--font-scale)); }
.ask-chat { display: grid; gap: 10px; max-height: 52vh; overflow-y: auto; scroll-behavior: smooth; }
.ask-chat:empty { display: none; }
.ask-msg { max-width: 88%; padding: 10px 14px; border-radius: 18px; line-height: 1.45; font-size: calc(15px * var(--font-scale)); animation: fade-in .25s ease-out; overflow-wrap: anywhere; }
.ask-msg p { margin: 0 0 6px; }
.ask-msg p:last-child { margin: 0; }
.ask-msg ul { margin: 4px 0; padding-left: 18px; }
.ask-msg.me { justify-self: end; background: var(--accent-soft); color: var(--accent-soft-ink); border-bottom-right-radius: 6px; }
.ask-msg.steady { justify-self: start; box-shadow: var(--inset-sm); color: var(--text); border-bottom-left-radius: 6px; }
.ask-msg.error { justify-self: start; color: var(--danger); box-shadow: var(--inset-sm); }
.ask-typing { display: inline-flex; gap: 4px; }
.ask-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: ask-dot 1s ease-in-out infinite; }
.ask-typing i:nth-child(2) { animation-delay: .15s; }
.ask-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ask-dot { 50% { transform: translateY(-4px); opacity: .5; } }
.ask-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ask-chips .chip { font-size: calc(13.5px * var(--font-scale)); }
.ask-form { display: flex; gap: 8px; align-items: flex-end; }
.ask-form textarea { flex: 1; resize: none; min-height: 46px; font-size: calc(15px * var(--font-scale)); line-height: 1.35; }
.ask-form .primary { flex: none; width: 46px; height: 46px; padding: 0; display: grid; place-items: center; }
.ask-form .primary svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* Trends: one calendar week or month at a time */
.tr-nav { margin: -4px 0 4px; }
.tr-period { margin: 0; font-size: calc(17px * var(--font-scale)); font-weight: 650; text-align: center; flex: 1; }
.tile .vs { font-size: calc(12px * var(--font-scale)); color: var(--text-3); }
