/* ══════════════════════════════════════════════════════════════════════════
   BIOKERNEL — HUD DESIGN SYSTEM
   Single source of truth for colour, type and geometry. Every page links
   this file; nothing below should be redefined in a page's own <style>.

   Palette: signal cyan on near-black. The brand sheet gives ink #07090B and
   accent #22D3EE; the accent is already --cyan below, and --void #05070C is
   two values off the brand ink in one channel — below anything visible, and
   one black in a system is worth more than two almost-identical ones. So
   product surfaces stay on --void and the brand ink is used only for exports
   that have to match the brand sheet byte for byte.

   Amber has exactly two jobs, and this is the whole list:
     1. The race — countdown, the flag on the block, energy burned toward it,
        off target against it. When something is warm here, it is about CIM.
     2. The middle of the readiness ramp — jade / amber / rose is a traffic
        light, and a traffic light needs its middle. Body and Glucose use it
        this way and should keep doing so.
   Anything else warm is a mistake. The fat macro used to be amber and is now
   neutral: carbs and protein are coached against a target, fat is only
   reported, and a colour that means "the race" should not be spent on it.

   Type floor is 11px. The previous UI bottomed out at 8px labels and 13.5px
   body, which is the "too small" problem this system exists to fix.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  /* ── surfaces ── */
  --void:      #05070C;   /* page — blue-black, not neutral black */
  --plate:     #0B1018;   /* panels */
  --plate-2:   #111826;   /* raised */
  --plate-3:   #18212F;   /* bar troughs, wells */
  --line:      #1C2634;   /* hairline */
  --line-2:    #2A3A4E;   /* emphasised edge */

  /* ── text (all pairs verified ≥ 4.5:1 on every surface above) ── */
  --ice:       #EAF2FB;   /* primary    17.8:1 on void */
  --dim:       #A8BAD0;   /* secondary  10.2:1 */
  --faint:     #7D91AA;   /* labels      6.2:1 — never below 11px */

  /* ── accents ── */
  --cyan:      #22D3EE;   /* live data, actions, the system's own voice */
  --cyan-hi:   #8CEEFB;
  --cyan-lo:   #0C5A6B;
  --cyan-ink:  #04252C;   /* text on a cyan fill — 8.9:1 */
  --glow:      rgba(34,211,238,.16);
  --amber:     #F5B942;   /* the race goal only */
  --jade:      #3FD9A4;   /* on target */
  --jade-dim:  #0D2A1E;   /* a completed row's fill, not its text */
  --rose:      #FB7185;   /* deficit, alert */

  /* ── brand ──
     The mark's own values, separated from the UI palette so a HUD retune
     cannot quietly restyle the logo. --bk-glint is the only place the accent
     is allowed to touch the mark: the letterforms are never recoloured. */
  --bk-ink:    #EAF2FB;              /* the BK letterforms — same as --ice */
  --bk-glint:  #E6FBFF;              /* the core of the travelling light */
  --bk-sweep:  4.8s;                 /* one pass of the glint, plus its rest */

  /* ── discipline ──
     Strength is not a running session and the calendar has to say so at a
     glance. This was living in calendar_live.html as a bare "--purple", an
     accent that existed nowhere else in the system. */
  --strength:  #B79BEE;

  /* ── macros ──
     Carbs and protein are coached against a target and carry the two
     accents. Fat is reported, not coached, so it stays neutral — amber is
     the race's colour and should not be spent on a macro. */
  --carb:      var(--cyan);
  --prot:      var(--jade);
  --fat:       var(--dim);

  /* ── type scale ──
     Prose ladder, then a numeral ladder. Pages were shipping 24 distinct
     sizes including 12.5px and 13.5px — sizes chosen by nudging until a row
     looked right, which is how five pages ended up disagreeing about what a
     card metric is. Every font-size in the app resolves to one of these. */
  --t-label:   11px;   /* uppercase labels, units, footnotes */
  --t-small:   13px;   /* secondary prose, table cells, chips */
  --t-ui:      12px;   /* caps inside a control — tab, button, menu item.
                          Uppercase at 11px in a button reads smaller than
                          11px sentence case, so the controls get one step. */
  --t-body:    16px;   /* body copy */
  --t-lead:    18px;   /* lead paragraph */
  --t-title:   20px;   /* the page header, and only the page header */

  --t-num-s:   22px;   /* a number inside a dense row */
  --t-num-m:   28px;   /* a number that is the point of its card */
  --t-num:     34px;   /* a number that is the point of its section */
  --t-num-l:   52px;   /* the one number a page exists to show */

  /* ── tracking ──
     Uppercase needs tracking; the app had eighteen different amounts of it
     between .02em and .18em. Three roles, three values. */
  --ls-label:  .16em;  /* .label — smallest caps, needs the most air */
  --ls-title:  .14em;  /* .page-title, section headings */
  --ls-tight:  .12em;  /* .btn, .chip — caps inside a bounded box */

  /* ── geometry — HUD panels are cut, not rounded ── */
  --r-xs:      1px;    /* the tip of a bar in a chart, nothing else */
  --r:         3px;
  --r-lg:      5px;
  --r-pill:    999px;  /* only for a badge that is genuinely a lozenge */
  --gap:       16px;
  --pad:       20px;

  --ease:      cubic-bezier(.22,1,.36,1);

  /* ── HR training zones ──
     One ramp, cool → hot, shared by the zones panel, the chart bands, the
     zone ruler and the zone-coloured HR line. Amber at Z4 is the readiness
     ramp's traffic-light middle doing its second sanctioned job (see top).
     Seven ordinal hues cannot all clear a colour-blind check against their
     neighbours, so a zone is never shown by colour alone: it always has its
     Z-number and its position on the HR scale. */
  --z1: #6E9BEA;  --z2: #22D3EE;  --z3: #3FD9A4;  --z4: #F5B942;
  --z5: #FB923C;  --z6: #FB7185;  --z7: #E879F9;

  color-scheme: dark;
}

/* ══ LIGHT ══════════════════════════════════════════════════════════════════
   Chosen in the gear menu, stored per browser by /theme.js as
   <html data-theme="light">. Not a flip of the dark set: every accent is
   re-picked to read on white, keeping its hue so a line means the same thing
   in both themes. Accents used as text are ≥ 4.5:1 on --plate (white).
   Because pages paint with custom properties, this block is the whole theme —
   a page only needs its own rule where it hard-codes a colour. */
:root[data-theme="light"] {
  --void:      #F2F5F9;   /* page — cool paper, so white panels lift off it */
  --plate:     #FFFFFF;
  --plate-2:   #F6F8FB;
  --plate-3:   #E8EDF3;
  --line:      #DDE4EC;
  --line-2:    #C3CEDB;

  --ice:       #0F1B2A;   /* 17.3:1 on white */
  --dim:       #475569;   /*  7.6:1 */
  --faint:     #5B6B80;   /*  5.4:1 */

  --cyan:      #0E7C9A;   /*  4.8:1 — same hue, deep enough for text */
  --cyan-hi:   #155E75;   /* "more cyan" means darker on paper */
  --cyan-lo:   #9FD9E6;
  --cyan-ink:  #FFFFFF;
  --glow:      rgba(14,124,154,.10);
  --amber:     #B45309;   /*  5.0:1 */
  --jade:      #047857;   /*  5.5:1 */
  --jade-dim:  #DDF4EA;
  --rose:      #E11D48;   /*  4.7:1 */
  --strength:  #7C3AED;

  --bk-ink:    #0F1B2A;   /* the letterforms go dark on paper; glint stays */

  --z1: #3F6FC4;  --z2: #0E7C9A;  --z3: #047857;  --z4: #A16207;
  --z5: #EA580C;  --z6: #E11D48;  --z7: #A21CAF;

  color-scheme: light;
}
:root[data-theme="light"] body { background-image: none; }

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--void);
  color: var(--ice);
  font-family: 'Instrument Sans', system-ui, sans-serif;
  font-size: var(--t-body);
  line-height: 1.55;
  background-image:
    linear-gradient(rgba(34,211,238,.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34,211,238,.028) 1px, transparent 1px);
  background-size: 64px 64px;
}

/* ── TYPE ROLES ───────────────────────────────────────────────────────────
   One family at both ends of its width axis — and now actually at the ends.
   Archivo's axis runs 62..125; the type roles used to stop at 66 and 118,
   which paid for a variable font and then declined the contrast. Condensed
   is the HUD's whisper (labels, units); expanded is its shout (every number
   read at a glance). Tabular figures everywhere numbers must align. */
.label {
  font-family: 'Archivo', sans-serif;
  font-variation-settings: 'wdth' 62, 'wght' 600;
  font-size: var(--t-label);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--faint);
  line-height: 1.2;
}
/* THE number style. Not one of two.
   Five pages set their metrics in Spline Sans Mono at 17–42px while four set
   them in expanded Archivo, so the same figure — a weekly kilometre total —
   had two different shapes depending on which tab you were looking at. The
   mono family is now what it should always have been: timestamps, IDs, keys
   and raw readouts. Anything an athlete reads at a glance is .num. */
.num {
  font-family: 'Archivo', sans-serif;
  font-variation-settings: 'wdth' 125, 'wght' 780;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
  line-height: 1;
  color: var(--ice);
}
.num.s  { font-size: var(--t-num-s); }
.num.m  { font-size: var(--t-num-m); }
.num.l  { font-size: var(--t-num); }
.num.xl { font-size: var(--t-num-l); }

.mono {
  font-family: 'Spline Sans Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: var(--t-small);
  color: var(--dim);
}
/* .display was five pages' name for .num, and it drove the SAME variable-font
   axis by a different mechanism — font-stretch:125% against .num's
   font-variation-settings 'wdth'. Two routes to one axis meant big numbers
   were not the same width from screen to screen. One rule now. */
.display, .num.display {
  font-family: 'Archivo', sans-serif;
  font-variation-settings: 'wdth' 125, 'wght' 780;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.015em;
}
.unit {
  font-size: .46em; color: var(--faint); letter-spacing: .04em; margin-left: 4px;
  font-variation-settings: 'wdth' 76, 'wght' 600;
}

:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; border-radius: 2px; }
::selection { background: var(--glow); }

/* Available to a screen reader, absent from the screen. Used for the app's
   h1 and for the live region that announces asynchronously loaded figures.
   Not display:none — that would hide it from assistive tech too. */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; border: 0; overflow: hidden; white-space: nowrap;
  clip: rect(0 0 0 0); clip-path: inset(50%);
}

/* ── STATUS ─────────────────────────────────────────────────────────────── */
.s-jade  { color: var(--jade); }
.s-amber { color: var(--amber); }
.s-rose  { color: var(--rose); }
.s-cyan  { color: var(--cyan); }
.dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.dot.jade { background: var(--jade); } .dot.amber { background: var(--amber); }
.dot.rose { background: var(--rose); } .dot.cyan  { background: var(--cyan); }

/* ── PANEL ──────────────────────────────────────────────────────────────── */
.panel {
  background: var(--plate);
  border: 1px solid var(--line);
  border-radius: var(--r);
}

/* ── BUTTONS ────────────────────────────────────────────────────────────── */
.btn {
  font-family: 'Archivo', sans-serif;
  font-variation-settings: 'wdth' 80, 'wght' 650;
  font-size: 12px; letter-spacing: var(--ls-tight); text-transform: uppercase;
  padding: 10px 15px; border-radius: var(--r); cursor: pointer;
  border: 1px solid var(--line-2); background: transparent; color: var(--dim);
  transition: color .18s, border-color .18s, background .18s;
}
.btn:hover { color: var(--ice); border-color: var(--faint); background: var(--plate-2); }
.btn.key {
  background: var(--cyan); border-color: var(--cyan); color: var(--cyan-ink);
  box-shadow: 0 0 22px rgba(34,211,238,.22);
}
.btn.key:hover { background: var(--cyan-hi); border-color: var(--cyan-hi); color: var(--cyan-ink); }

.chip {
  font-family: 'Archivo', sans-serif;
  font-variation-settings: 'wdth' 72, 'wght' 650;
  font-size: var(--t-label); letter-spacing: var(--ls-tight); text-transform: uppercase;
  padding: 4px 9px; border-radius: var(--r); border: 1px solid; line-height: 1.2;
}
.chip.done  { color: var(--jade);  border-color: color-mix(in srgb, var(--jade) 40%, transparent); background: color-mix(in srgb, var(--jade) 8%, transparent); }
.chip.warn  { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 40%, transparent); background: color-mix(in srgb, var(--amber) 7%, transparent); }
.chip.phase { color: var(--dim);   border-color: var(--line-2); }

/* ── LAYOUT & SHARED COMPONENTS ───────────────────────────────────────────
   Every one of these was defined independently on three to nine pages, and
   they had drifted: .card came in 8px and 9px radius while .panel was 3px,
   .state shipped six different paddings, .wrap set eight different content
   widths so the gutters jumped every time you changed tab. One definition
   each, here, is the whole point of the file.

   ALIASES: pages built before this file used --surface / --border / --text /
   --gold and so on. Rather than rewrite every rule on every page, the old
   names now point at the real tokens. Nothing below restates a hex. */
:root {
  --bg:       var(--void);
  --surface:  var(--plate);
  --surface2: var(--plate-2);
  --surface3: var(--plate-3);
  --border:   var(--line);
  --border2:  var(--line-2);
  --text:     var(--ice);
  --muted:    var(--dim);
  --purple:   var(--strength);
  --green-dim: var(--jade-dim);
  /* --gold held #22D3EE — a variable named gold containing cyan, left behind
     by a find-and-replace during the HUD redesign. It aliases the accent now
     and should be retired from pages as they are next touched. */
  --gold:     var(--cyan);
  --gold-hi:  var(--cyan-hi);
  --gold-dim: var(--cyan-lo);
  --green:    var(--jade);
  --red:      var(--rose);
  --blue:     var(--cyan-hi);
}

/* One content width, and one set of page gutters.
   Pages used to pick their own width between 760 and 1080px AND their own
   body padding — 18/20/22px top, 60/70/80px bottom — so the gutters shifted
   twice on every tab change. Both live here now. The shell's <main> is capped
   at this same 1040px and pads its non-iframed views identically, so the
   content column is the same measure whether a view is embedded or not.

   Wide enough for the calendar, narrow enough for a form. */
.wrap { max-width: 1040px; margin: 0 auto; padding: 22px 16px 72px; }

/* ── PAGE HEADER ──────────────────────────────────────────────────────────
   Nine pages had four header patterns: ALL CAPS on body/glucose/nutrition/
   calendar, sentence case on athlete/plan, title case on admin, and none at
   all on home/strength, whose h1 was sr-only. A screen you cannot name is a
   screen you cannot navigate back to.

   Caps, because the rest of the system speaks in caps — .label, .chip, .btn.
   Condensed rather than expanded: the title is a signpost, not a number, and
   at 20px the expanded axis crowds the width the .asof stamp needs beside it.
   Anything that qualifies the title — a week range, a date, a status — goes
   in .page-meta on the right and stays in mono. */
.page-head {
  display: flex; align-items: baseline; justify-content: space-between;
  flex-wrap: wrap; gap: 6px 14px;
  margin-bottom: 20px; padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.page-title {
  font-family: 'Archivo', sans-serif;
  font-variation-settings: 'wdth' 88, 'wght' 800;
  font-size: var(--t-title);
  letter-spacing: var(--ls-title);
  text-transform: uppercase;
  color: var(--ice);
  line-height: 1.15;
}
.page-title em { font-style: normal; color: var(--cyan); }
.page-meta {
  font-family: 'Spline Sans Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: var(--t-label); color: var(--faint);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}

/* A section heading inside a page. Was <h2> at 13px on body/glucose, 11px on
   admin, and a .sec-title class on athlete/plan — three sizes for one job.
   13px, because 11px is the floor for a label and this is a heading. */
.sec-title {
  font-family: 'Archivo', sans-serif;
  font-variation-settings: 'wdth' 76, 'wght' 700;
  font-size: var(--t-small);
  letter-spacing: var(--ls-title);
  text-transform: uppercase;
  color: var(--dim);
  line-height: 1.2;
}

/* A card is a panel with padding. Radius comes from --r-lg so it is visibly
   a container and not a hairline box, and it is the SAME radius everywhere. */
.card {
  background: var(--plate); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 15px 17px;
}
.card.lit { border-color: var(--cyan-lo); }

/* .state and .foot each carried TWO meanings across the pages they were
   copied between, which is the real cost of duplication — not just drift but
   collision. Both are split here, and both keep the name that matched the
   majority of call sites.

   .state — a whole screen with nothing in it yet: loading, empty, failed.
   An empty screen is an invitation to act, so keep the copy at the call site
   specific; this only sets how it sits. */
.state {
  text-align: center; color: var(--faint);
  padding: 46px 16px; font-size: var(--t-small); line-height: 1.6;
}
/* .status — a line of feedback beside a control, not a screen. Used by the
   forms in athlete and plan, which previously got this from their own .state
   and would have been blown out to a 46px-padded centred block. */
.status { color: var(--faint); font-size: var(--t-small); }
.status.err { color: var(--rose); }
.status.ok  { color: var(--jade); }

/* .foot — footnotes: provenance, "as of", the small print under a panel. */
.foot {
  margin-top: 22px; font-size: var(--t-label);
  color: var(--faint); line-height: 1.6;
}
/* .actions — the row of buttons that ends a form. athlete and plan called
   this .foot, so on those two pages .foot meant a flex row and everywhere
   else it meant small grey text. */
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 20px; }
.asof {
  font-family: 'Spline Sans Mono', ui-monospace, monospace;
  font-size: var(--t-label); color: var(--faint);
}

/* Form controls were missing from the system entirely — every page rolled
   its own input, so focus rings and heights disagreed. */
.field {
  background: var(--plate-2); border: 1px solid var(--line-2);
  color: var(--ice); font-family: inherit; font-size: var(--t-body);
  border-radius: var(--r); padding: 10px 12px; min-height: 42px;
  transition: border-color .15s, box-shadow .15s;
}
.field:focus { outline: none; border-color: var(--cyan-lo); box-shadow: 0 0 0 3px rgba(34,211,238,.07); }
.field::placeholder { color: var(--faint); }

/* ── PHONE ────────────────────────────────────────────────────────────────
   Only index.html had a breakpoint. The eight pages it embeds had none: each
   is its own document, so each would have needed its own copy, which is why
   none of them got one. They all link this file now, so the shared rules live
   here once and a page only adds its own where its layout is genuinely its
   own.

   360px is the target — an iPhone SE in portrait, and the narrowest thing the
   athlete is likely to open this on at 5am. */
@media (max-width: 640px) {
  /* Gutters used to be set on each page's own body rule, so this had to
     override eight of them. It sets the one wrapper now. */
  .wrap { padding: 16px 12px 56px; }
  .card { padding: 13px 14px; }
  .state { padding: 34px 12px; }
  .page-head { margin-bottom: 16px; }

  /* The numeral ramp steps down one notch — a 52px hero at 360px leaves no
     room for the words that give it meaning. */
  :root { --t-num-l: 40px; --t-num: 28px; --t-num-m: 24px; --t-num-s: 20px; }

  /* A table of the 26-week plan grid cannot become one column and stay
     readable. Let it scroll sideways inside its own box instead of pushing
     the whole document wide — a horizontally scrolling PAGE is the bug;
     a horizontally scrolling table is the fix. */
  .scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .scroll-x > table { min-width: 460px; }

  /* Inputs sized for a mouse are unusable at 360px. Full width, and at least
     16px of type so iOS Safari does not zoom the viewport on focus. */
  .field, input, select, textarea { max-width: 100%; }
  input, select, textarea { font-size: max(16px, 1em); }
}

/* ── SCROLLBARS ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
