/* ==========================================================================
   fit · Base components — "Macedonia" theme
   --------------------------------------------------------------------------
   Plain CSS, no build step. Needs `tokens.css` loaded first.

   Ground rules
   - One block = one component = one PHP partial. BEM-style names:
       .block  ·  .block__element  ·  .block--variant  ·  .is-state
   - Colour is not a per-component variant: put a `t-*` tint (see
     tokens.css) on the component or on any container, and components read
     `--accent-*`.
   - Data comes in through attributes and inline variables, never through
     classes: `style="--value: 62"` (percentage 0–100), `style="--share: 25"`.
   - Nothing depends on the page: there are no "screen" styles. Screens are
     built from the layout blocks (`page`, `section`, `grid`, `stack`,
     `cluster`, `split`).
   - Whatever changes between mobile and desktop uses container queries on
     `.app` (`@container app`), not the window width.

   Index
      0. Base
      1. Layout ............. stack, cluster, grid, split
      2. Structure .......... app, nav, brand, topbar, page, section
      3. Text ............... display, text
      4. Icons .............. icon, icon-tile
      5. Card ............... card
      6. Figure ............. stat, delta
      7. Ring ............... ring
      8. Meters ............. meter, meter-row, segbar
      9. Legend ............. legend
     10. Buttons ............ btn, fab
     11. Forms .............. field, input, input-group, search, qty,
                              segmented, switch
     12. Chips and stickers . chips, chip, sticker
     13. Lists .............. list, row, macro-line, kv
     14. Sheet and dialog ... sheet
     15. Notices ............ toasts, toast, callout
     16. Empty and loading .. empty, seeds
     17. Charts ............. chart, chart-tip
     18. Days ............... daynav
     19. Comparisons ........ cascade, rangeplot, compare
   ========================================================================== */


/* ==========================================================================
   0. BASE
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, p, figure, dl, dd {
  margin: 0;
}

ul[class],
ol[class] {
  margin: 0;
  padding: 0;
  list-style: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* Screen readers only. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}


/* ==========================================================================
   1. LAYOUT
   With these four blocks any screen can be built without CSS of its own.
   ========================================================================== */

/* stack — stacks vertically with a fixed gap. */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}
.stack--xs { gap: var(--space-1); }
.stack--sm { gap: var(--space-2); }
.stack--md { gap: var(--space-3); }
.stack--lg { gap: var(--space-6); }
.stack--xl { gap: var(--space-8); }
.stack--center { align-items: center; text-align: center; }

/* cluster — a row that wraps; for buttons, chips, figure + note. */
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.cluster--lg { gap: var(--space-4); }
.cluster--between { justify-content: space-between; }
.cluster--center { justify-content: center; }
.cluster--end { justify-content: flex-end; }
.cluster--baseline { align-items: baseline; }
.cluster--nowrap { flex-wrap: nowrap; }

/* grid — grid of equal columns.
   --2/--3: always. --md-*: from 640 px of container width. --lg-*: from 900 px. */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
  min-width: 0;
}
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--lg-gap { gap: var(--space-4); }
.grid__full { grid-column: 1 / -1; }

@container app (min-width: 640px) {
  .grid--md-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--md-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid--md-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@container app (min-width: 900px) {
  .grid--lg-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--lg-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid--lg-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid--lg-gap { gap: var(--space-5); }
  .grid__span-2 { grid-column: span 2; }
}

/* split — a fixed piece (ring, illustration) + a flexible body next to it.
   If the body cannot reach its minimum width, it drops below. */
.split {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;    /* if the body wraps, the fixed piece stays centred */
  gap: var(--space-4);
  min-width: 0;
}
.split__body {
  flex: 1 1 9rem;
  min-width: 0;
}
.split--top { align-items: flex-start; }


/* ==========================================================================
   2. STRUCTURE
   ========================================================================== */

/* app — the application shell.
   Fills the window; navigation stays put and only `app__main` scrolls.
   Sheets, toasts and the floating button are direct children of `.app` and
   are positioned over it (so no `position: fixed` is needed).
   Variant: app--embedded (fills the height of its container, not the window).
   Input: the section tint (`t-food`, `t-weight`…) for the glow. */
.app {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--color-bg);
  container: app / inline-size;
}
.app--embedded {
  height: 100%;
}
/* app--native: the page is shown inside the iOS app (WKWebView), whose native tab bar replaces .nav. */
.app.app--native > .nav {
  display: none;
}
.app.app--native > .app__main {
  grid-column: 1 / -1;
}
/* The FAB and toasts may sit inside .app__main (page templates): match them at any depth. The WebView already
   ends above the app's own tab bar, so neither the web tab bar height nor the home-indicator inset applies. */
.app.app--native .fab {
  bottom: var(--space-4);
}
.app.app--native .toasts {
  bottom: var(--space-3);
}
.app.app--native .page--fab {
  padding-bottom: calc(58px + var(--space-8));
}

/* Fruit glow at the top: two pastel blots in the tint. */
.app::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 0 auto 0;
  height: 22rem;
  pointer-events: none;
  background:
    radial-gradient(62% 72% at 8% 0%, var(--glow-a) 0%, transparent 100%),
    radial-gradient(58% 64% at 96% 6%, var(--glow-b) 0%, transparent 100%);
}

.app__main {
  grid-column: 1 / -1;
  grid-row: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

/* nav — tab bar at the bottom (mobile) or side column (desktop).
   Each `nav__item` carries its own tint; the active one gets `is-active`
   and `aria-current="page"`. */
.nav {
  grid-column: 1 / -1;
  grid-row: 2;
  z-index: var(--z-nav);
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 6px max(var(--space-2), env(safe-area-inset-left, 0px)) calc(6px + var(--safe-bottom));
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.5) blur(18px);
  backdrop-filter: saturate(1.5) blur(18px);
  border-top: 1px solid var(--color-border);
}
/* `nav__brand` (wraps `brand`) and `nav__spacer` only show on desktop. */
.nav__brand,
.nav__spacer {
  display: none;
}
.nav__item {
  flex: 1 1 0;
  min-width: 0;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-text-3);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}
.nav__icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 30px;
  border-radius: var(--radius-pill);
  transition:
    background-color var(--duration-2) var(--ease-out),
    transform var(--duration-2) var(--ease-spring);
}
.nav__item:active .nav__icon {
  transform: scale(0.9);
}
.nav__item.is-active {
  color: var(--color-text);
}
.nav__item.is-active .nav__icon {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
/* The neutral tab ("Today") needs a slightly more visible pill. */
.nav__item.t-today.is-active .nav__icon,
.nav__item.t-neutral.is-active .nav__icon {
  background: var(--accent-track);
}

@container app (min-width: 900px) {
  .nav {
    grid-column: 1;
    grid-row: 1 / -1;
    width: var(--sidenav-width);
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-5) var(--space-3);
    border-top: 0;
    border-right: 1px solid var(--color-border);
    background: color-mix(in srgb, var(--color-surface) 64%, transparent);
  }
  .nav__brand {
    display: block;
    margin: 0 var(--space-2) var(--space-5);
  }
  .nav__spacer {
    display: block;
    flex: 1;
  }
  .nav__item {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-3);
    min-height: 48px;
    padding: 0 var(--space-2);
    font-size: var(--text-md);
  }
  .nav__item:hover {
    background: var(--color-surface-sunken);
  }
  .nav__icon {
    width: 36px;
    height: 36px;
  }
  .nav__item.is-active {
    background: var(--color-surface);
    box-shadow: var(--shadow-1);
  }
  .app__main {
    grid-column: 2;
    grid-row: 1 / -1;
  }
}

/* brand — the mark: fruit slice + name. */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text);
  font-family: var(--font-display);
  font-variation-settings: var(--font-display-settings);
  font-size: var(--text-2xl);
  font-weight: 650;
  line-height: 1;
  letter-spacing: var(--tracking-tight);
  text-decoration: none;
}
.brand__mark {
  width: 1.15em;
  height: 1.15em;
  flex: none;
}

/* topbar — screen header: eyebrow (date), title and actions.
   The title is the only thing set in the display typeface, and it ends
   with a full stop in the section colour.
   Variant: topbar--compact (small title, for single-step screens such as
   the weigh-in, with a back button in `topbar__lead`). */
.topbar {
  display: flex;
  flex-wrap: wrap;            /* if the actions do not fit, they wrap */
  align-items: flex-end;
  gap: var(--space-3);
  width: 100%;
  max-width: var(--page-max);
  margin-inline: auto;
  padding: calc(var(--space-5) + var(--safe-top)) var(--page-gutter) var(--space-4);
}
.topbar__lead {
  flex: none;
  display: flex;
}
.topbar__text {
  flex: 1 1 auto;
  min-width: 0;
}
.topbar__eyebrow {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-2);
}
.topbar__eyebrow::first-letter {
  text-transform: uppercase;
}
.topbar__title {
  font-family: var(--font-display);
  font-variation-settings: var(--font-display-settings);
  font-size: var(--text-3xl);
  font-weight: 620;
  line-height: 1.05;
  letter-spacing: var(--tracking-tight);
}
.topbar__title::after,
.brand__name::after {
  content: ".";
  color: var(--accent-dot, var(--accent));
}
.topbar__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-left: auto;
}
.topbar--compact {
  align-items: center;
  padding-bottom: var(--space-2);
}
.topbar--compact .topbar__title {
  font-size: var(--text-xl);
}

/* page — the content column of a screen. */
.page {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: var(--space-4);
  width: 100%;
  max-width: var(--page-max);
  margin-inline: auto;
  padding: 0 var(--page-gutter) var(--space-8);
}
/* page--center: content centred vertically (weigh-in, empty states). */
.page--center {
  min-height: 70%;
  align-content: center;
}
/* page--narrow: a single short column (login, small forms). */
.page--narrow {
  max-width: 26rem;
}
/* page--fab: leaves room at the end so the floating button covers nothing. */
.page--fab {
  padding-bottom: calc(58px + var(--space-10));
}

@container app (min-width: 900px) {
  .topbar,
  .page {
    padding-inline: var(--space-8);
  }
  .page {
    gap: var(--space-5);
  }
}

/* section — a titled group inside a page or a sheet. */
.section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}
.section__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}
.section__title {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-text-2);
}
.section__note {
  font-size: var(--text-sm);
  color: var(--color-text-3);
  font-variant-numeric: tabular-nums;
}


/* ==========================================================================
   3. TEXT
   ========================================================================== */

/* display — large words in the display typeface (Fraunces).
   For sheet titles, states and messages. Never for figures. */
.display {
  font-family: var(--font-display);
  font-variation-settings: var(--font-display-settings);
  font-size: var(--text-xl);
  font-weight: 620;
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}
.display--lg { font-size: var(--text-2xl); }
.display--xl { font-size: var(--text-3xl); }

/* text — paragraphs and notes. */
.text {
  font-size: var(--text-base);
  color: var(--color-text);
}
.text--sm { font-size: var(--text-sm); }
.text--md { font-size: var(--text-md); }
.text--muted { color: var(--color-text-2); }
.text--faint { color: var(--color-text-3); }
.text--strong { font-weight: var(--weight-bold); }
.text--accent { color: var(--accent-ink); font-weight: var(--weight-semibold); }
.text--center { text-align: center; }
.text--num { font-variant-numeric: tabular-nums; }
.text--balance { text-wrap: balance; }


/* ==========================================================================
   4. ICONS
   ========================================================================== */

/* icon — stroke icon; inherits the text colour.
   <svg class="icon" aria-hidden="true"><use href="#i-plus"/></svg> */
.icon {
  flex: none;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon--sm { width: 18px; height: 18px; stroke-width: 2; }
.icon--lg { width: 32px; height: 32px; stroke-width: 1.6; }

/* icon-tile — a pastel "fruit" with an icon or an emoji inside.
   Variants: --sm, --lg, --plate (round neutral plate for the emoji of a
   food), --num (a step number instead of an icon, for cards that are read
   in order: 1, 2, 3). */
.icon-tile {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-blob);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 1.25rem;
  line-height: 1;
}
.icon-tile--sm { width: 32px; height: 32px; font-size: 1rem; }
.icon-tile--lg { width: 56px; height: 56px; font-size: 1.75rem; }
.icon-tile--plate {
  border-radius: 50%;
  background: var(--color-surface-sunken);
  box-shadow: inset 0 0 0 1px var(--color-border);
}
.icon-tile--num {
  font-family: var(--font-num);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}


/* ==========================================================================
   5. CARD
   card — rounded white surface. Input: optional tint.
   Variants:
     --hero     the main card of the screen (more air, tint glow)
     --tinted   washed tint background, no shadow (summaries, previews)
     --flat     no shadow
     --compact  less padding (small cards in a 2-column grid)
     --link     the whole card is a link (<a class="card card--link">)
   ========================================================================== */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
  padding: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  color: inherit;
  text-decoration: none;
}
.card--hero {
  padding: var(--space-5);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2);
  background:
    radial-gradient(90% 70% at 100% 0%, var(--accent-wash) 0%, transparent 70%),
    var(--color-surface);
}
.card--tinted {
  background: var(--accent-wash);
  border-color: var(--accent-track);
  box-shadow: none;
}
.card--flat {
  box-shadow: none;
}
.card--compact {
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4) var(--space-4);
}
.card--link {
  cursor: pointer;
  transition:
    transform var(--duration-2) var(--ease-out),
    box-shadow var(--duration-2) var(--ease-out);
}
@media (hover: hover) {
  .card--link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-2);
  }
}
.card--link:active {
  transform: scale(0.985);
}

.card__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}
.card__heading {
  flex: 1;
  min-width: 0;
}
.card__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  line-height: var(--leading-snug);
  letter-spacing: -0.01em;
}
.card__subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-3);
  font-variant-numeric: tabular-nums;
}
.card__action {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: var(--touch);
  margin-block: -10px;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--accent-ink);
  text-decoration: none;
  white-space: nowrap;
}
.card__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}
.card__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}


/* ==========================================================================
   6. FIGURE
   stat — a number with its label and unit. The number is always in ink
   (never in the tint colour) and in the same typeface as the text.
   Inputs: label, value already formatted ("1.256", "81,6"), unit, hint.
   Sizes: --sm (18) · default (24) · --lg (34) · --xl (48) · --hero (68)
   Variants: --center · --live (a figure that changes live: fixed-width
   digits so it does not jitter).
   ========================================================================== */
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.stat__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-2);
}
.stat__value {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 0.16em;
  font-family: var(--font-num);
  font-size: var(--num-md);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text);
}
.stat__unit {
  font-size: max(0.42em, var(--text-sm));
  font-weight: var(--weight-semibold);
  letter-spacing: 0;
  color: var(--color-text-2);
}
/* Error margin: "± 150". */
.stat__margin {
  font-size: max(0.5em, var(--text-sm));
  font-weight: var(--weight-semibold);
  letter-spacing: 0;
  color: var(--color-text-2);
}
.stat__hint {
  font-size: var(--text-sm);
  color: var(--color-text-3);
  font-variant-numeric: tabular-nums;
}
.stat--sm .stat__value { font-size: var(--num-sm); }
.stat--lg .stat__value { font-size: var(--num-lg); }
.stat--xl .stat__value { font-size: var(--num-xl); }
.stat--hero .stat__value { font-size: var(--num-hero); line-height: 1; }
.stat--center { align-items: center; text-align: center; }
.stat--center .stat__value { justify-content: center; }
.stat--live .stat__value { font-variant-numeric: tabular-nums; }

/* delta — a signed change. The icon says which way; the variant says
   whether that is good or bad (for weight, going down is good).
   Variants: --good · --bad · no variant = neutral. */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px var(--space-2) 2px var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--color-surface-sunken);
  color: var(--color-text-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  white-space: nowrap;
}
.delta .icon {
  width: 16px;
  height: 16px;
  stroke-width: 2.2;
}
.delta--good {
  background: var(--color-ok-soft);
  color: var(--color-ok-ink);
}
.delta--bad {
  background: var(--color-danger-soft);
  color: var(--color-danger-ink);
}


/* ==========================================================================
   7. RING
   ring — progress ring shaped like a slice of fruit: the rind is the
   progress, the pulp (with its segments) is the pastel background and the
   centre holds the figure.
   Inputs: `--value` (0–100, % of the target), tint, figure and label.
   Sizes: --sm (44, no text) · default (96) · --lg (136) · --xl (264)
   Variants:
     --busy   rind spinning (measuring, loading)
     --pulse  ripples outwards (searching for the scale)
     --done   rind closed with a small bounce
     --plain  no segments
   State: is-over (target exceeded → danger colour)
   The SVG markup is fixed: see README.md.
   ========================================================================== */
.ring {
  --value: 0;
  --ring-size: 96px;
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: var(--ring-size);
  height: var(--ring-size);
}
.ring--sm { --ring-size: 44px; }
.ring--lg { --ring-size: 136px; }
.ring--xl { --ring-size: min(264px, 72vw); }

.ring__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.ring__pulp {
  fill: var(--accent-soft);
}
.ring__segments {
  fill: none;
  stroke: var(--color-surface);
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.9;
}
.ring--plain .ring__segments {
  display: none;
}
.ring__track,
.ring__arc {
  fill: none;
  stroke-width: 9;
}
.ring__track {
  stroke: var(--accent-track);
}
.ring__arc {
  stroke: var(--accent);
  stroke-linecap: round;
  /* The circles carry pathLength="100": the stroke is measured in percent. */
  stroke-dasharray: var(--value) 100;
  opacity: clamp(0, var(--value), 1);   /* at 0 not even the round cap is drawn */
}
.ring.is-over .ring__arc {
  stroke: var(--color-danger);
}

.ring__center {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 74%;
  text-align: center;
  line-height: 1.15;
}
.ring__num {
  font-family: var(--font-num);
  font-size: calc(var(--ring-size) * 0.25);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  line-height: 1.05;
  color: var(--color-text);
}
.ring__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-2);
}
.ring--xl .ring__center {
  gap: var(--space-1);
  max-width: 82%;
}
.ring--xl .ring__label {
  font-size: var(--text-md);
}

.ring--busy .ring__arc,
.ring--done .ring__arc {
  transition: stroke-dasharray var(--duration-4) var(--ease-out);
}
.ring--busy .ring__arc {
  stroke-dasharray: 26 100;
  opacity: 1;
  transform-origin: 60px 60px;
  animation: ring-spin 1.2s linear infinite;
}
.ring--done .ring__arc {
  stroke-dasharray: 100 100;
  opacity: 1;
}
.ring--done {
  animation: ring-pop var(--duration-3) var(--ease-spring);
}
.ring--pulse::before,
.ring--pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--accent-light);
  border-radius: 50%;
  animation: ring-pulse 2.4s var(--ease-out) infinite;
}
.ring--pulse::after {
  animation-delay: 1.2s;
}

@keyframes ring-spin {
  to { transform: rotate(360deg); }
}
@keyframes ring-pop {
  0% { transform: scale(0.94); }
  100% { transform: scale(1); }
}
@keyframes ring-pulse {
  0% { transform: scale(0.96); opacity: 0.9; }
  100% { transform: scale(1.32); opacity: 0; }
}


/* ==========================================================================
   8. METERS
   ========================================================================== */

/* meter — progress bar towards a target. The track is a lighter step of
   the same fruit.
   Inputs: `--value` (0–100), tint; in the HTML, role="progressbar" with the
   real aria-valuenow / aria-valuemax.
   Sizes: --sm (6) · default (8) · --lg (12)
   Variants:
     --range  also draws the error margin between `--lo` and `--hi`
     --slice  the fill starts at `--from` instead of at zero: one slice of
              a whole (the part a step of a `cascade` adds or takes away)
   State: is-over (target exceeded). */
.meter {
  --value: 0;
  position: relative;
  display: block;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--accent-track);
  overflow: hidden;
}
.meter::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(min(var(--value), 100) * 1%);
  border-radius: inherit;
  background: var(--accent);
}
.meter--sm { height: 6px; }
.meter--lg { height: 12px; }
.meter.is-over::before {
  background: var(--color-danger);
}
.meter--range::after {
  content: "";
  position: absolute;
  inset-block: 0;
  left: calc(var(--lo) * 1%);
  width: calc((var(--hi) - var(--lo)) * 1%);
  border-inline: 2px solid var(--accent-on);
  background: linear-gradient(var(--accent-on), var(--accent-on)) center / 100% 2px no-repeat;
}
/* The slice is the end piece of a longer bar: straight cut on the left,
   round end on the right. */
.meter--slice {
  --from: 0;
}
.meter--slice::before {
  left: calc(var(--from) * 1%);
  width: calc((min(var(--value), 100) - var(--from)) * 1%);
  border-radius: 3px var(--radius-pill) var(--radius-pill) 3px;
}

/* meter-row — name + figure + meter. It is the row of one macro, and it
   also works for comparing two values (real expenditure against Apple).
   The bar can be a `segbar` instead of a `meter` (one whole per row).
   Inputs: name, value, target, unit, `--value`, tint.
   Variant: --compact (smaller text, to sit next to a ring).
   State: is-over (paints the figure as a warning; add it to the meter too). */
.meter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-1) var(--space-3);
  min-width: 0;
}
.meter-row__name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}
.meter-row__name::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.meter-row__figure {
  font-size: var(--text-md);
  color: var(--color-text-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.meter-row__value {
  font-weight: var(--weight-bold);
  color: var(--color-text);
}
.meter-row > .meter,
.meter-row > .segbar {
  flex: 1 0 100%;
}
.meter-row__note {
  flex: 1 0 100%;
  font-size: var(--text-xs);
  color: var(--color-text-3);
}
.meter-row--compact .meter-row__name,
.meter-row--compact .meter-row__figure {
  font-size: var(--text-sm);
}
.meter-row.is-over .meter-row__value {
  color: var(--color-danger-ink);
}

/* segbar — a total split into parts (kcal per macro, body composition).
   Each part carries its tint and `--share` (its weight; the shares need not
   add up to 100).
   Default: thin, no text (the numbers go next to it, in the legend).
   Variants:
     --lg     12 px, no text (two bars compared one above the other)
     --tall   28 px with the figure inside. If a part is too narrow for its
              text (under about 14 %), the partial does not print it.
     --range  error margin of the boundary between two parts, drawn from
              `--lo` to `--hi` (% of the bar), like `meter--range`. Not
              for --tall: it would cross the figures. */
.segbar {
  display: flex;
  gap: 2px;
  height: 8px;
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.segbar__part {
  flex: var(--share, 1) 1 0;
  min-width: 0;
  background: var(--accent);
}
.segbar--tall {
  height: 28px;
  border-radius: 0;
  overflow: visible;
}
.segbar--tall .segbar__part {
  display: flex;
  align-items: center;
  padding-inline: var(--space-2);
  border-radius: 4px;
  color: var(--accent-on);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.segbar--tall .segbar__part:first-child { border-radius: 10px 4px 4px 10px; }
.segbar--tall .segbar__part:last-child { border-radius: 4px 10px 10px 4px; }
.segbar--lg {
  height: 12px;
}
.segbar--range {
  position: relative;
}
.segbar--range::after {
  content: "";
  position: absolute;
  inset-block: 0;
  left: calc(var(--lo) * 1%);
  width: calc((var(--hi) - var(--lo)) * 1%);
  border-inline: 2px solid var(--color-text);
  background: linear-gradient(var(--color-text), var(--color-text)) center / 100% 2px no-repeat;
}


/* ==========================================================================
   9. LEGEND
   legend — names of the series; each item carries its tint (the context
   series, `t-muted`).
   Item variants: --line (line) · --dot (loose points) ·
   --band (margin band). No variant: small filled square.
   ========================================================================== */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-2);
}
.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend__item::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--accent);
}
.legend__item--line::before {
  width: 16px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent-strong);
}
.legend__item--dot::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-light);
}
.legend__item--band::before {
  width: 16px;
  background: var(--accent);
  opacity: 0.3;
}
.legend__value {
  font-weight: var(--weight-bold);
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}


/* ==========================================================================
   10. BUTTONS
   btn — a button, or a link shaped like one.
   Style variants:
     (none)     secondary: white with a border
     --primary  tint fill with dark text of the same fruit
     --soft     pastel tint background
     --ghost    no background
   Sizes: --sm (36) · default (44) · --lg (54) · --block (full width)
   Shape: --icon (round, icon only; needs aria-label)
   States: :disabled / is-disabled · is-loading
   ========================================================================== */
.btn {
  --btn-height: var(--touch);
  --btn-fg: var(--color-text);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--btn-height);
  padding: 0 var(--space-5);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--btn-fg);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition:
    transform var(--duration-1) var(--ease-out),
    background-color var(--duration-1) var(--ease-out),
    filter var(--duration-1) var(--ease-out);
}
.btn:active {
  transform: scale(0.96);
}
.btn:disabled,
.btn.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.btn--primary {
  --btn-fg: var(--accent-on);
  border-color: transparent;
  background: var(--accent);
  /* Darker bottom edge and tint glow: a "gummy sweet" button. */
  box-shadow:
    inset 0 -2px 0 color-mix(in srgb, var(--accent-strong) 55%, transparent),
    0 8px 18px -8px color-mix(in srgb, var(--accent-strong) 70%, transparent);
}
.btn--soft {
  --btn-fg: var(--accent-ink);
  border-color: transparent;
  background: var(--accent-soft);
}
.btn--ghost {
  --btn-fg: var(--accent-ink);
  border-color: transparent;
  background: transparent;
}

/* Hover highlights only exist where there is a mouse: on a phone they
   would stay "stuck" after a tap. */
@media (hover: hover) {
  .btn:hover { background: var(--color-surface-sunken); }
  .btn--primary:hover { background: var(--accent); filter: brightness(1.05) saturate(1.05); }
  .btn--soft:hover { background: var(--accent-track); }
  .btn--ghost:hover { background: var(--accent-soft); }
}

.btn--sm {
  --btn-height: 36px;
  padding-inline: var(--space-4);
  font-size: var(--text-sm);
}
.btn--lg {
  --btn-height: 54px;
  padding-inline: var(--space-6);
  font-size: var(--text-lg);
}
.btn--block {
  display: flex;
  width: 100%;
}
.btn--icon {
  flex: none;
  width: var(--btn-height);
  padding: 0;
}

.btn.is-loading {
  color: transparent;
  pointer-events: none;
}
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--btn-fg);
  border-right-color: transparent;
  border-radius: 50%;
  animation: ring-spin 0.7s linear infinite;
}

/* fab — floating button for the main action of the screen (add).
   Direct child of `.app`. Needs aria-label. */
.fab {
  position: absolute;
  right: var(--space-4);
  bottom: calc(var(--tabbar-height) + var(--safe-bottom) + var(--space-4));
  z-index: var(--z-fab);
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-on);
  cursor: pointer;
  box-shadow:
    inset 0 -3px 0 color-mix(in srgb, var(--accent-strong) 55%, transparent),
    0 10px 24px -8px color-mix(in srgb, var(--accent-strong) 80%, transparent);
  transition: transform var(--duration-2) var(--ease-spring);
}
.fab:active {
  transform: scale(0.92);
}
.fab .icon {
  width: 28px;
  height: 28px;
  stroke-width: 2.2;
}
@container app (min-width: 900px) {
  .fab {
    right: var(--space-8);
    bottom: var(--space-8);
  }
}


/* ==========================================================================
   11. FORMS
   Every field is 16 px or larger (below that, iOS zooms in).
   ========================================================================== */

/* field — label + control + hint or error.
   State: is-invalid (the hint becomes the error message). */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--color-text-2);
}
.field__hint {
  font-size: var(--text-sm);
  color: var(--color-text-3);
}
.field.is-invalid .field__hint {
  color: var(--color-danger-ink);
  font-weight: var(--weight-semibold);
}
.field.is-invalid .input {
  border-color: var(--color-danger);
}

/* input — text or number field. With a unit next to it: wrap it in
   `.input-group` and add `.input-group__affix`. */
.input {
  width: 100%;
  min-height: 48px;
  padding: 0 var(--space-4);
  border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-base);
  font-variant-numeric: tabular-nums;
  transition:
    border-color var(--duration-1) var(--ease-out),
    box-shadow var(--duration-1) var(--ease-out);
}
.input::placeholder {
  color: var(--color-text-3);
}
.input:focus {
  outline: none;
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.input:disabled {
  background: var(--color-surface-sunken);
  color: var(--color-text-disabled);
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}
.input-group .input {
  padding-right: 3.5rem;
  text-align: right;
  font-weight: var(--weight-semibold);
}
.input-group__affix {
  position: absolute;
  right: var(--space-4);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--color-text-3);
  pointer-events: none;
}

/* search — pill-shaped search box. */
.search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-4);
  border: 1.5px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--color-surface-sunken);
  color: var(--color-text-3);
}
.search:focus-within {
  border-color: var(--accent-strong);
  background: var(--color-surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.search__input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  outline: none;
  color: var(--color-text);
  font-size: var(--text-base);
}
.search__input::placeholder {
  color: var(--color-text-3);
}
.search__input::-webkit-search-cancel-button {
  display: none;
}

/* qty — a large quantity: grams of a product or servings of a dish.
   Inputs: value, unit label (grams or servings), step of the buttons.
   The <input> uses inputmode="decimal". Variant: --sm (inside a row). */
.qty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}
.qty__step {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  cursor: pointer;
  transition: transform var(--duration-1) var(--ease-out);
}
.qty__step:active {
  transform: scale(0.9);
  background: var(--accent-track);
}
.qty__field {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  flex: 0 1 10.5rem;
  min-width: 0;
  padding: var(--space-2) var(--space-5);
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  background: var(--color-surface-sunken);
  cursor: text;
  transition:
    border-color var(--duration-1) var(--ease-out),
    box-shadow var(--duration-1) var(--ease-out);
}
.qty__field:focus-within {
  border-color: var(--accent);
  background: var(--color-surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.qty__input {
  width: 3.4ch;
  padding: 0;
  border: 0;
  background: none;
  outline: none;
  color: var(--color-text);
  font-family: var(--font-num);
  font-size: var(--num-xl);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-tight);
  line-height: 1.15;
  text-align: right;
}
.qty__unit {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--color-text-2);
}
.qty--sm .qty__step { width: 36px; height: 36px; }
.qty--sm .qty__field { flex-basis: auto; padding: var(--space-1) var(--space-3); border-radius: var(--radius-md); }
.qty--sm .qty__input { font-size: var(--num-md); }
.qty--sm .qty__unit { font-size: var(--text-md); }

/* segmented — pick one of a few options (14 / 28 days; product / dish).
   Variant: --fit (does not span the full width). */
.segmented {
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-sunken);
  overflow-x: auto;           /* scrolls sideways on very narrow screens */
  scrollbar-width: none;
}
.segmented::-webkit-scrollbar {
  display: none;
}
.segmented--fit {
  display: inline-flex;
}
.segmented__item {
  flex: 1 0 auto;
  display: inline-flex;       /* buttons, links and labels (radio tabs) all centre their text */
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--color-text-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--duration-2) var(--ease-out);
}
.segmented__item.is-active {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-1);
}
/* Rows can be buttons (pick lists in sheets): fill the width like links do. */
button.row {
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
}
/* Items can also be links (server-rendered period pickers, no JS) or labels of radios (forms). */
a.segmented__item {
  text-decoration: none;
}
label.segmented__item:has(input:checked) {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-1);
}
label.segmented__item:has(input:focus-visible) {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

/* switch — toggle (e.g. the "log complete" flag of a day). */
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--touch);
  cursor: pointer;
}
.switch__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.switch__text {
  flex: 1;
  min-width: 0;
}
.switch__label {
  display: block;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}
.switch__hint {
  display: block;
  font-size: var(--text-sm);
  color: var(--color-text-3);
}
.switch__track {
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  border-radius: var(--radius-pill);
  background: var(--seed-500);
  transition: background-color var(--duration-2) var(--ease-out);
}
.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--cream-0);
  box-shadow: var(--shadow-1);
  transition: transform var(--duration-2) var(--ease-spring);
}
.switch__input:checked ~ .switch__track {
  background: var(--accent-strong);
}
.switch__input:checked ~ .switch__track::after {
  transform: translateX(20px);
}
.switch__input:focus-visible ~ .switch__track {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}


/* ==========================================================================
   12. CHIPS AND STICKERS
   ========================================================================== */

/* chips — a row of chips. Scrolls horizontally by default.
   Variants: --wrap (wraps onto new lines) · --center (centred). */
.chips {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar {
  display: none;
}
.chips--wrap {
  flex-wrap: wrap;
  overflow: visible;
}
.chips--center {
  justify-content: center;
}

/* chip — a quick option or filter that can be toggled (<button>).
   State: is-selected (+ aria-pressed="true"). */
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--duration-1) var(--ease-out);
}
.chip:active {
  transform: scale(0.95);
}
.chip.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* sticker — fruit sticker: an oval label for a state or a type.
   Not interactive. Carries a tint (`t-ok`, `t-warn`, `t-food`…).
   Variants: --solid (vivid fill) · --tilt (slightly crooked). */
.sticker {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 2px solid var(--color-surface);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  box-shadow:
    inset 0 0 0 1.5px var(--accent-light),
    0 1px 3px rgb(64 38 70 / 0.12);
  color: var(--accent-ink);
  font-size: var(--text-2xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wide);
  line-height: 1.5;
  text-transform: uppercase;
  white-space: nowrap;
}
.sticker .icon {
  width: 13px;
  height: 13px;
  stroke-width: 2.6;
}
.sticker--solid {
  background: var(--accent);
  box-shadow:
    inset 0 0 0 1.5px rgb(255 255 255 / 0.55),
    0 1px 3px rgb(64 38 70 / 0.16);
  color: var(--accent-on);
}
.sticker--tilt {
  transform: rotate(-3deg);
}


/* ==========================================================================
   13. LISTS
   ========================================================================== */

/* list — a list of rows. Variant: --divided (hairline between rows). */
.list {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.list--divided > * + * {
  border-top: 1px solid var(--color-border);
}
.list__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0 var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-text-2);
}

/* row — generic row: leading piece + title and metadata + value.
   It is a food log entry (with `icon-tile--plate` and `macro-line`), a
   workout, a search result…
   Variants: --link (<a> or <button>) · --dense (shorter).
   State: is-selected. */
.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-width: 0;
  min-height: 60px;
  padding: var(--space-2) 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  text-decoration: none;
}
.row--dense {
  min-height: 48px;
}
.row--link {
  cursor: pointer;
}
.row--link:active {
  opacity: 0.6;
}
.row.is-selected {
  margin-inline: calc(var(--space-3) * -1);
  padding-inline: var(--space-3);
  width: calc(100% + 2 * var(--space-3));   /* not auto: a <button> row would shrink to its content */
  border-radius: var(--radius-md);
  background: var(--accent-wash);
  box-shadow: inset 0 0 0 1.5px var(--accent-track);
}
.row__body {
  flex: 1;
  min-width: 0;
}
.row__title,
.row__meta,
.row__value {
  display: block;
}
.row__title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  overflow-wrap: anywhere;
}
.row__meta {
  font-size: var(--text-sm);
  color: var(--color-text-3);
  font-variant-numeric: tabular-nums;
}
.row__trail {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
}
.row__value {
  font-family: var(--font-num);
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.row__unit {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-2);
}
.row__chevron {
  flex: none;
  color: var(--color-text-3);
}

/* macro-line — the three macros in small print: "H 2,4 · P 2,4 · G 18"
   (H, P and G are the initials shown in the UI for carbs, protein and fat).
   Each item carries its tint; the coloured dot goes with the letter. */
.macro-line {
  display: inline-flex;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.macro-line__item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.macro-line__item::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.macro-line--lg {
  gap: var(--space-3);
  font-size: var(--text-md);
}
.macro-line--lg .macro-line__item::before {
  width: 8px;
  height: 8px;
}

/* kv — key / value pairs (body composition, expenditure breakdown). */
.kv {
  display: flex;
  flex-direction: column;
}
.kv__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 10px 0;
}
.kv__row + .kv__row {
  border-top: 1px solid var(--color-border);
}
.kv__key {
  font-size: var(--text-md);
  color: var(--color-text-2);
}
.kv__value {
  font-family: var(--font-num);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.kv__unit {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-2);
}
/* Total row. */
.kv__row.kv__row--total {
  border-top-color: var(--color-text);
}
.kv__row--total .kv__key {
  font-weight: var(--weight-bold);
  color: var(--color-text);
}


/* ==========================================================================
   14. SHEET AND DIALOG
   sheet — a sheet that slides up from the bottom (mobile) or a centred
   dialog (≥ 700 px).
   Direct child of `.app`. Opens with `is-open`.
   In the HTML: role="dialog" aria-modal="true" aria-labelledby="…".
   Variant: --tall (takes almost the whole screen).
   ========================================================================== */
.sheet {
  position: absolute;
  inset: 0;
  z-index: var(--z-sheet);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear var(--duration-3);
}
.sheet.is-open {
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}
.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: var(--color-overlay);
  opacity: 0;
  transition: opacity var(--duration-3) var(--ease-out);
}
.sheet.is-open .sheet__backdrop {
  opacity: 1;
}
.sheet__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: 88%;
  padding-bottom: var(--safe-bottom);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background: var(--color-surface);
  box-shadow: var(--shadow-3);
  transform: translateY(100%);
  transition: transform var(--duration-3) var(--ease-out);
}
.sheet.is-open .sheet__panel {
  transform: none;
}
.sheet--tall .sheet__panel {
  height: 94%;
  max-height: 94%;
}
.sheet__grabber {
  flex: none;
  align-self: center;
  width: 40px;
  height: 5px;
  margin-top: var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-border-strong);
}
.sheet__header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-2) var(--space-5);
}
.sheet__title {
  font-family: var(--font-display);
  font-variation-settings: var(--font-display-settings);
  font-size: var(--text-xl);
  font-weight: 620;
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
}
.sheet__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-5) var(--space-5);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet__footer {
  flex: none;
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5) var(--space-4);
  border-top: 1px solid var(--color-border);
}

@container app (min-width: 700px) {
  .sheet {
    align-items: center;
    justify-content: center;
  }
  .sheet__panel {
    width: min(520px, calc(100% - var(--space-12)));
    max-height: 84%;
    border-radius: var(--radius-xl);
    opacity: 0;
    transform: translateY(16px) scale(0.98);
    transition:
      transform var(--duration-3) var(--ease-out),
      opacity var(--duration-2) var(--ease-out);
  }
  .sheet.is-open .sheet__panel {
    opacity: 1;
  }
  .sheet__grabber {
    display: none;
  }
}


/* ==========================================================================
   15. NOTICES
   ========================================================================== */

/* toasts — container (direct child of `.app`, one per page).
   toast — a short notice on dark ink. Carries a tint for the icon
   (`t-ok`, `t-warn`, `t-danger`) and, when it applies, an action (undo).
   In the HTML: role="status" (or role="alert" for an error). */
.toasts {
  position: absolute;
  inset-inline: 0;
  bottom: calc(var(--tabbar-height) + var(--safe-bottom) + var(--space-3));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding-inline: var(--page-gutter);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: min(100%, 26rem);
  padding: var(--space-2) var(--space-4) var(--space-2) var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--seed-900);
  box-shadow: var(--shadow-2);
  color: var(--color-text-inverse);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
  pointer-events: auto;
  animation: toast-in var(--duration-3) var(--ease-spring);
}
.toast__icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-on);
}
.toast__icon .icon {
  width: 18px;
  height: 18px;
  stroke-width: 2.4;
}
.toast__text {
  flex: 1;
  min-width: 0;
}
.toast__action {
  flex: none;
  min-height: 32px;
  margin-right: calc(var(--space-2) * -1);
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--accent-light);
  font-weight: var(--weight-bold);
  cursor: pointer;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
}
@container app (min-width: 900px) {
  .toasts {
    bottom: var(--space-6);
  }
}

/* callout — a fixed note inside the page (e.g. "open this site in Bluefy").
   Carries a tint. */
.callout {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--accent-track);
  border-radius: var(--radius-md);
  background: var(--accent-wash);
  font-size: var(--text-md);
  line-height: var(--leading-snug);
}
.callout__icon {
  flex: none;
  color: var(--accent-ink);
}
.callout__body {
  flex: 1;
  min-width: 0;
}
.callout__title {
  font-weight: var(--weight-bold);
}
.callout__text {
  color: var(--color-text-2);
}


/* ==========================================================================
   16. EMPTY STATE AND LOADING
   ========================================================================== */

/* empty — when there is nothing to show: illustration (an emoji or an icon
   on a pastel "fruit"), title, text and action. Carries a tint. */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  text-align: center;
}
.empty__art {
  position: relative;
  display: grid;
  place-items: center;
  width: 104px;
  height: 104px;
  margin-bottom: var(--space-3);
  border-radius: var(--radius-blob);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 2.75rem;
  line-height: 1;
}
.empty__art .icon {
  width: 44px;
  height: 44px;
  stroke-width: 1.5;
}
/* Two loose seeds around it. */
.empty__art::before,
.empty__art::after {
  content: "";
  position: absolute;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: var(--accent-light);
}
.empty__art::before {
  top: 4px;
  right: -10px;
  width: 12px;
  height: 16px;
  transform: rotate(28deg);
}
.empty__art::after {
  bottom: 8px;
  left: -14px;
  width: 9px;
  height: 12px;
  background: var(--accent);
  transform: rotate(-24deg);
}
.empty__title {
  font-family: var(--font-display);
  font-variation-settings: var(--font-display-settings);
  font-size: var(--text-xl);
  font-weight: 620;
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
}
.empty__text {
  max-width: 30ch;
  color: var(--color-text-2);
  font-size: var(--text-md);
}
.empty__action {
  margin-top: var(--space-3);
}

/* seeds — three bouncing seeds: "loading", "searching". Carries a tint.
   <span class="seeds" role="status" aria-label="…"><i></i><i></i><i></i></span> */
.seeds {
  display: inline-flex;
  align-items: flex-end;
  gap: 6px;
  height: 18px;
}
.seeds > i {
  width: 8px;
  height: 11px;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: var(--accent);
  animation: seeds-bounce 1.1s var(--ease-out) infinite;
}
.seeds > i:nth-child(2) { animation-delay: 0.15s; }
.seeds > i:nth-child(3) { animation-delay: 0.3s; }
@keyframes seeds-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-7px); }
}

/* Reduced motion: the token durations are already zeroed; here the looping
   animations stop. The "busy" spin stays, slower, because it is the only
   sign that something is happening. */
@media (prefers-reduced-motion: reduce) {
  .ring--pulse::before,
  .ring--pulse::after,
  .seeds > i {
    animation: none;
  }
  .ring--pulse::before {
    transform: scale(1.12);
    opacity: 0.6;
  }
  .ring--pulse::after {
    transform: scale(1.24);
    opacity: 0.3;
  }
  .ring--busy .ring__arc {
    animation-duration: 3s;
  }
}


/* ==========================================================================
   17. CHARTS
   chart — container for an SVG chart (built in PHP or with JS). The
   `chart__*` classes go on the SVG elements and read the tint.
   Rules (see README.md): 2 px line, a single scale per chart, solid
   hairline grid, few direct labels, text always in ink and never in the
   colour of the series.
   ========================================================================== */
.chart {
  position: relative;
  display: block;
  margin: 0;
}
.chart__svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
/* chart--spark: sparkline with no axes; does not grow too large on desktop. */
.chart--spark {
  max-width: 15rem;
}
.chart__grid {
  stroke: var(--color-border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.chart__axis {
  fill: var(--color-text-3);
  font-family: var(--font-sans);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.chart__line {
  fill: none;
  stroke: var(--accent-strong);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
/* Context series: grey, so the main one stands out. */
.chart__line--muted {
  stroke: var(--seed-500);
}
.chart__area {
  fill: var(--accent);
  opacity: 0.12;
}
/* Error-margin band around a line. */
.chart__band {
  fill: var(--accent);
  opacity: 0.18;
}
/* Loose context points (each weigh-in): "seeds". */
.chart__dot {
  fill: var(--accent-light);
}
/* Highlighted marker (latest value): r ≥ 4 with a ring in the surface colour. */
.chart__marker {
  fill: var(--accent-strong);
  stroke: var(--color-surface);
  stroke-width: 2;
}
.chart__bar {
  fill: var(--accent);
}
.chart__bar--muted {
  fill: var(--accent-track);
}
/* Reference line (target). */
.chart__ref {
  stroke: var(--color-text-3);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.chart__label {
  fill: var(--color-text);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.chart__label--muted {
  fill: var(--color-text-3);
  font-weight: 600;
}

/* chart-tip — floating label when hovering or tapping a point. Positioned
   with inline `left` / `top` (set by the JS) inside `.chart`. */
.chart-tip {
  position: absolute;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--seed-900);
  box-shadow: var(--shadow-2);
  color: var(--color-text-inverse);
  font-size: var(--text-xs);
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
}
.chart-tip__value {
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}
.chart-tip__label {
  color: var(--cream-300);
}


/* ==========================================================================
   18. DAY NAVIGATION
   daynav — previous day / shown day / next day. The arrows are
   `btn btn--icon btn--ghost`; the centre opens the calendar.
   ========================================================================== */
.daynav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  box-shadow: var(--shadow-1);
}
.daynav__current {
  flex: 1;
  min-width: 0;
  min-height: var(--touch);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  line-height: 1.2;
  cursor: pointer;
}
.daynav__day {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
}
.daynav__date {
  font-size: var(--text-xs);
  color: var(--color-text-3);
}


/* ==========================================================================
   19. COMPARISONS
   Blocks that explain a figure and set it against others: how a total
   breaks down (cascade), where other sources fall next to a measured value
   and its margin (rangeplot) and the same figures from two sources side by
   side (compare).
   The measured series carries the tint; what it is compared with goes in
   `t-muted`. Every figure is written out: the marks only help to see it.
   ========================================================================== */

/* cascade — a total peeled step by step on one shared scale (a waterfall):
   the starting figure, what is taken away (or added) and the result after
   each step. Reads top to bottom like a sum on paper, with the operator in
   the left gutter.
   Each step is a row: operator, name, figure, an optional note and a
   `meter`.
   Step variants:
     --level  a level: the starting figure and each result ("="). Bold
              name, large figure; its meter starts at zero and takes
              `meter--range` when the figure has a margin.
     (none)   a part ("−" or "+"): its meter is a `meter--slice` between
              where the bar was and where it ends up; the rest of the bar,
              before the slice, is ghosted.
   Inputs: per step, the tint of what it stands for (activity, food…),
   `--value` / `--from` (and `--lo` / `--hi`) in % of the largest figure. */
.cascade {
  --cascade-rest: var(--accent-track);   /* resolved here: steps carry their own tint */
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}
.cascade__step {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: baseline;
  column-gap: var(--space-2);
  min-width: 0;
}
.cascade__sign {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-surface-sunken);
  color: var(--color-text-2);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  line-height: 1;
}
.cascade__sign:empty {
  visibility: hidden;
}
.cascade__name {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
}
.cascade__note {
  grid-column: 2 / -1;
  font-size: var(--text-xs);
  color: var(--color-text-3);
}
.cascade__figure {
  font-size: var(--text-md);
  color: var(--color-text-2);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.cascade__value {
  font-family: var(--font-num);
  font-weight: var(--weight-bold);
  color: var(--color-text);
}
.cascade__step > .meter {
  grid-column: 2 / -1;
  margin-top: 6px;
  background-color: var(--color-surface-sunken);
}
/* The rest of the bar, before the slice (what is left after taking it away,
   or what there was before adding it): a ghost, with a 2 px gap. */
.cascade__step > .meter--slice {
  background-image: linear-gradient(to right, var(--cascade-rest) calc(var(--from) * 1% - 2px), transparent 0);
}
.cascade__step--level .cascade__sign {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.cascade__step--level .cascade__name {
  font-weight: var(--weight-bold);
}
.cascade__step--level .cascade__value {
  font-size: var(--num-md);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}

/* rangeplot — values from several sources on one shared scale, next to a
   reference value and its margin. The band of the reference (`--lo` to
   `--hi`) is repeated on every row, so it shows at a glance which values
   fall inside it. The scale does not start at zero: positions are compared,
   not lengths.
   Each row: name, figure, track with its dot and an optional note (the
   difference and whether it fits in the margin, with an icon).
   Row variant: --ref (the measured value: its own band, stronger).
   Inputs: `--lo` / `--hi` on the block and `--value` on each track, all in
   % of the scale; a tint per row; the ticks of the scale (`--at`). */
.rangeplot {
  --lo: 0;
  --hi: 100;
  --rangeplot-band: var(--accent-track);   /* resolved here: rows carry their own tint */
  --rangeplot-edge: var(--accent-strong);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}
.rangeplot__row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px var(--space-3);
  min-width: 0;
}
.rangeplot__name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}
.rangeplot__name::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-strong);
}
.rangeplot__figure {
  font-size: var(--text-md);
  color: var(--color-text-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.rangeplot__value {
  font-family: var(--font-num);
  font-size: var(--num-sm);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text);
}
.rangeplot__track {
  --value: 0;
  position: relative;
  flex: 1 0 100%;
  height: 20px;
  margin-block: 2px;
}
/* The rail. */
.rangeplot__track::before {
  content: "";
  position: absolute;
  inset: 50% 0 auto;
  height: 4px;
  margin-top: -2px;
  border-radius: var(--radius-pill);
  background: var(--color-border);
}
/* The margin band of the reference: a zone closed by two caps, like the
   whisker of `meter--range`. On the other rows it is a faded copy. */
.rangeplot__track::after {
  content: "";
  position: absolute;
  inset-block: 0;
  left: calc(var(--lo) * 1%);
  width: calc((var(--hi) - var(--lo)) * 1%);
  border-inline: 2px solid var(--rangeplot-edge);
  border-radius: 5px;
  background: var(--rangeplot-band);
  opacity: 0.45;
}
.rangeplot__row--ref .rangeplot__track::after {
  opacity: 1;
}
.rangeplot__dot {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: calc(var(--value) * 1%);
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid var(--color-surface);
  border-radius: 50%;
  background: var(--accent-strong);
}
.rangeplot__note {
  flex: 1 0 100%;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-sm);
  color: var(--color-text-2);
  font-variant-numeric: tabular-nums;
}
.rangeplot__note .icon {
  width: 15px;
  height: 15px;
  stroke-width: 2.2;
}
.rangeplot__axis {
  position: relative;
  height: 1.3em;
  margin-top: calc(var(--space-1) * -1);
  font-size: var(--text-2xs);
  line-height: 1.3;
  color: var(--color-text-3);
  font-variant-numeric: tabular-nums;
}
.rangeplot__tick {
  position: absolute;
  left: calc(var(--at) * 1%);
  transform: translateX(-50%);
  white-space: nowrap;
}
.rangeplot__tick:first-child { transform: none; }
.rangeplot__tick:last-child { transform: translateX(-100%); }

/* compare — the same figures from two (or three) sources side by side: a
   real table, one column per source and one row per figure. Figures are
   right-aligned with fixed-width digits; the margin goes under its figure.
   Column variant: --main (the source that matters: washed in the tint).
   Row variant: --lead (the headline figure: larger).
   Row label variant: --swatch (with a tint: the square of that series,
   e.g. the parts of a `segbar` drawn above the table). */
.compare {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.compare__col,
.compare__cell {
  padding: 10px 0 10px var(--space-3);
  text-align: right;
  vertical-align: top;
  white-space: nowrap;
}
.compare__col {
  padding-block: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  line-height: var(--leading-snug);
  vertical-align: bottom;
}
.compare__col-note {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  color: var(--color-text-3);
}
.compare__key {
  padding: 10px 0;
  font-size: var(--text-md);
  font-weight: var(--weight-regular);
  color: var(--color-text-2);
  text-align: left;
  vertical-align: top;
}
.compare__key--swatch::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 3px;
  background: var(--accent);
}
.compare__cell {
  font-family: var(--font-num);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
}
.compare__unit {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-2);
}
.compare__margin {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-2);
}
.compare__row > * {
  border-top: 1px solid var(--color-border);
}
.compare__row--lead .compare__key {
  font-weight: var(--weight-bold);
  color: var(--color-text);
}
.compare__row--lead .compare__value {
  font-size: var(--num-md);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}
.compare__col--main,
.compare__cell--main {
  padding-inline: var(--space-3);
  background: var(--accent-wash);
}
.compare__col--main {
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.compare__row:last-child > .compare__cell--main {
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}


/* ==========================================================================
   20. SUPPLEMENTS
   ========================================================================== */

/* chip--check — a chip wrapping a checkbox (e.g. weekdays); selected while checked. */
.chip--check {
  position: relative;
  min-width: 40px;
  justify-content: center;
}
.chip--check input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.chip--check:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.chip--check:has(input:focus-visible) {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

/* doses — one round check button per dose of the day. State: is-taken (+ aria-pressed). */
.doses {
  flex: none;
  display: flex;
  gap: var(--space-2);
}
.dose {
  display: grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  border: 2px dashed var(--accent-light);
  border-radius: 50%;
  background: var(--accent-wash);
  color: transparent;
  cursor: pointer;
  transition: background-color var(--duration-2) var(--ease-out), transform var(--duration-1) var(--ease-out);
}
.dose:active {
  transform: scale(0.9);
}
.dose.is-taken {
  border-style: solid;
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: var(--accent-on);
}
.dose:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}
.row.is-muted {
  opacity: 0.55;
}


/* ==========================================================================
   21. VALUE ANIMATIONS
   --value (rings, meters) and --share (segbar parts) are registered so that
   a change transitions smoothly; app.js changes them from the previous
   figures after a live update or a reload of the same page.
   ========================================================================== */

@property --value {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
@property --share {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}
.ring,
.meter,
.rangeplot__track {
  transition: --value var(--duration-anim) var(--ease-out);
}
.segbar__part {
  transition: --share var(--duration-anim) var(--ease-out);
}
:root {
  --duration-anim: 700ms;
}
@media (prefers-reduced-motion: reduce) {
  :root { --duration-anim: 1ms; }
}


/* ==========================================================================
   22. DISCLOSURE
   A <details> whose <summary> is a row (e.g. one day of workouts); the
   chevron turns when open and the body is indented under the row.
   ========================================================================== */

.disclosure__summary {
  list-style: none;
  cursor: pointer;
}
.disclosure__summary::-webkit-details-marker {
  display: none;
}
.disclosure__summary:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm, 8px);
}
.disclosure__chevron {
  flex: none;
  display: grid;
  color: var(--color-text-3);
  transition: transform var(--duration-2) var(--ease-out);
}
.disclosure[open] .disclosure__chevron {
  transform: rotate(180deg);
}
.disclosure .disclosure__body {   /* two classes: beats the ul[class] reset */
  margin: 0 0 var(--space-3);
  padding: var(--space-1) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface-sunken);
}

/* icon-stack — up to three small overlapping tiles (the kinds of workouts of a day). */
.icon-stack {
  flex: none;
  display: flex;
  width: 72px;                  /* room for three: the text after it starts at the same place on every row */
}
.icon-stack > * + * {
  margin-left: -12px;
}
.icon-stack > * {
  box-shadow: 0 0 0 2px var(--color-surface);
}

/* Sheets: the grabber and header are drag handles (app.js), the content keeps its overscroll to itself. */
.sheet__grabber,
.sheet__header {
  touch-action: none;
}
.sheet__body {
  overscroll-behavior: contain;
}
.sheet__grabber {
  position: relative;
}
.sheet__grabber::after {          /* larger touch target than the 5 px bar */
  content: "";
  position: absolute;
  inset: -12px -40px;
}

/* Time and date inputs: iOS Safari draws them natively with an intrinsic minimum width that overflows the
   field and centres the value; make them behave like the other inputs. */
input.input[type="time"],
input.input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  max-width: 100%;
  line-height: 45px;
}
input.input[type="time"]::-webkit-date-and-time-value,
input.input[type="date"]::-webkit-date-and-time-value {
  min-height: 1.4em;
  text-align: left;
}

/* On touch screens sheets close by dragging down or tapping outside: the X is only kept for screen readers. */
@media (hover: none) and (pointer: coarse) {
  .sheet__header > [data-sheet-close] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}


/* ==========================================================================
   23. GLYPHS
   Drawn icons of foods and pills (colour, sprite food.svg) and the picker.
   The --emoji variant is a typed emoji shown at the same size.
   ========================================================================== */

.glyph {
  flex: none;
  width: 28px;
  height: 28px;
}
.glyph--emoji {
  display: inline-grid;
  place-items: center;
  font-size: 1.35rem;
  line-height: 1;
}
.icon-tile--sm .glyph { width: 22px; height: 22px; }
.icon-tile--lg .glyph { width: 40px; height: 40px; }

.glyph-picker__button {
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}
.glyph-picker__preview {
  display: grid;
  place-items: center;
}
.glyph-picker__preview .glyph {
  width: 32px;
  height: 32px;
}

.glyph-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: var(--space-2);
}
.glyph-grid__item {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  background: var(--color-surface-sunken);
  cursor: pointer;
  transition: transform var(--duration-1) var(--ease-out);
}
.glyph-grid__item:active {
  transform: scale(0.92);
}
.glyph-grid__item[aria-pressed="true"] {
  border-color: var(--accent-strong);
  background: var(--accent-soft);
}
.glyph-grid__item:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}
.glyph-grid__item .glyph {
  width: 34px;
  height: 34px;
}

/* meter-row is-met — a minimum reached (protein): the figure in the row's ink with a check. */
.meter-row.is-met .meter-row__value {
  color: var(--accent-ink);
}
.meter-row.is-met .meter-row__figure .icon {
  vertical-align: -3px;
  color: var(--accent-ink);
}

/* Inside the iOS app: no double-tap zoom either (pinch zoom is off in the viewport meta, see layouts/head.php). */
html:has(.app--native) {
  touch-action: manipulation;
}


/* ==========================================================================
   24. APP LOADER
   iOS app only (html.is-loading, see layouts/app.php): the page is laid out
   hidden (so the fonts load) behind a spinning slice; app.js removes the
   class once the fonts are ready. Without JS it shows anyway after 3 s.
   ========================================================================== */

.app-loader {
  display: none;
}
html.is-loading .app-loader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: var(--color-bg);
  animation: app-loader-out 0s 3s forwards;
}
html.is-loading .app {
  visibility: hidden;
  animation: app-loader-reveal 0s 3s forwards;
}
.app-loader__mark {
  width: 56px;
  height: 56px;
  animation: app-loader-spin 1.1s var(--ease-out) infinite;
}
@keyframes app-loader-spin {
  to { transform: rotate(360deg); }
}
@keyframes app-loader-out {
  to { visibility: hidden; }
}
@keyframes app-loader-reveal {
  to { visibility: visible; }
}
@media (prefers-reduced-motion: reduce) {
  .app-loader__mark { animation: none; }
}


/* sync-dot — state of one Apple Health kind as the iOS app reports it (Salud page):
   is-running (sending, pulses) · is-done (up to date) · is-error. Empty outside the app. */
.sync-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: transparent;
}
.sync-dot.is-done { background: var(--avocado-500); }
.sync-dot.is-error { background: var(--color-danger); }
.sync-dot.is-running {
  background: var(--blueberry-500);
  animation: sync-dot-pulse 1s var(--ease-out) infinite alternate;
}
@keyframes sync-dot-pulse {
  to { opacity: 0.3; }
}
@media (prefers-reduced-motion: reduce) {
  .sync-dot.is-running { animation: none; }
}


/* choice — a radio (or checkbox) with its text, one per line; may carry an inline field (version picker). */
.choice {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch);
  font-size: var(--text-sm);
  cursor: pointer;
}
.choice input[type="radio"],
.choice input[type="checkbox"] {
  flex: none;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent-strong);
}
.choice__text {
  min-width: 0;
}
.input--inline {
  width: auto;
  min-height: 40px;
  padding: 0 var(--space-3);
}
.version-picker {
  margin: 0;
  padding: 0;
  border: 0;
}


/* scanner — camera view of the barcode scanner sheet, with a guide frame. */
.scanner {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-md);
  background: var(--seed-900);
}
.scanner__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner__frame {
  position: absolute;
  inset: 30% 12%;
  border: 3px solid var(--cream-0);
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 999px rgb(0 0 0 / 0.25);
}
.search__action {
  margin-right: calc(var(--space-2) * -1);
}
.cluster--nowrap {
  flex-wrap: nowrap;
}
.cluster--nowrap > .input {
  flex: 1;
  min-width: 0;
}


/* metric-stats — the statistics under a metric chart (average, minimum, maximum, change). */
.metric-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  margin: 0;
}
.metric-stats > div {
  min-width: 0;
}
.metric-stats dt {
  font-size: var(--text-xs);
  color: var(--color-text-3);
}
.metric-stats dd {
  margin: 2px 0 0;
  font-family: var(--font-num);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}
.metric-stats dd .delta {
  font-size: var(--text-sm);
}
/* Phones: average, minimum and maximum in one row, the change (its unit can be long: ml/kg·min) below. */
@media (max-width: 640px) {
  .metric-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric-stats__change { grid-column: 1 / -1; }
}
.metric-stats dd .delta {
  max-width: 100%;
  white-space: normal;
}
.chart__bar--soft {
  fill: var(--accent-light);
}


/* ==========================================================================
   25. INTERACTIVE CHART (hchart, public/assets/js/charts.js)
   Apple Health style: a header with the average of the visible days or the
   selected day (moved above it and joined to it by .hchart__rule), the plot
   (pans sideways; touch-action keeps vertical page scrolling), dimmed bars or
   dots around the selection.
   ========================================================================== */

.hchart {
  position: relative;
}
.hchart__head {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  box-sizing: border-box;
  height: 76px;                 /* the same for the average and a selected day: the chart never moves */
  min-width: 130px;
  white-space: nowrap;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  transition: background-color var(--duration-2) var(--ease-out);
  will-change: transform;
}
.hchart__head.is-selected {
  background: var(--color-surface-sunken);
}
.hchart__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-3);
}
.hchart__value {
  font-size: var(--text-2xl, 1.75rem);
  line-height: 1.1;
}
.hchart__sub {
  min-height: 1.2em;
  font-size: var(--text-sm);
  color: var(--color-text-3);
}
.hchart__plot {
  position: relative;
  margin-top: var(--space-2);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.hchart__plot:active {
  cursor: grabbing;
}
.hchart__svg {
  display: block;
  overflow: visible;
}
.hchart__rule {
  position: absolute;
  width: 1.5px;
  margin-left: -0.75px;
  background: var(--color-text-3);
  pointer-events: none;
}
.hchart .chart__bar {
  fill: var(--accent);
  transition: opacity var(--duration-1) var(--ease-out);
}
.hchart .is-dim {
  opacity: 0.32;
}
.hchart__mark {
  fill: var(--accent-strong);
  stroke: var(--color-surface);
  stroke-width: 2;
}


/* No text selection on touch screens and inside the iOS app (it reads as an app, not a document); fields
   stay selectable. */
@media (hover: none) and (pointer: coarse) {
  body {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
}
html:has(.app--native) body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
input,
textarea,
select,
[contenteditable] {
  -webkit-user-select: text;
  user-select: text;
}


/* Add-food results: the chosen dish's box holds its amount panel (moved there by app.js); the chevron turns
   down while it is open. Tapping the chosen dish folds / unfolds it. */
[data-add-results] > li {
  border-radius: var(--radius-md);
  transition: background-color var(--duration-2) var(--ease-out);
}
[data-add-results] > li.is-picked {
  margin-inline: calc(var(--space-3) * -1);
  padding: 0 var(--space-3);           /* no bottom padding: folded, the row stays centred in its box */
  background: var(--accent-wash);
  box-shadow: inset 0 0 0 1.5px var(--accent-track);
}
[data-add-results] > li.is-picked + li {
  border-top-color: transparent;
}
[data-add-results] > li.is-picked [data-add-amount] {
  padding-bottom: var(--space-3);
}
[data-add-results] .row__chevron .icon {
  transition: transform var(--duration-2) var(--ease-out);
}
[data-add-results] > li.is-open .row__chevron .icon {
  transform: rotate(90deg);
}
@media (prefers-reduced-motion: reduce) {
  [data-add-results] .row__chevron .icon { transition: none; }
}
