/* Jeff Labs — "field instrument".
 *
 * The reference object is a piece of measuring equipment, not a dashboard:
 * a near-black ground, one phosphor accent that repaints per section, hairlines
 * instead of boxes, and oversized tabular numerals wherever a number is the
 * point. Colour carries meaning and nothing else, so a red thing on this site
 * is always a red thing in the body.
 *
 * Every face here ships with macOS and iOS. No @font-face, no remote host: the
 * CSP in .htaccess allows font-src 'self' only, and a webfont that fails to
 * load is a page that reflows on the phone at the hangboard. Futura and Avenir
 * are a deliberate pair rather than a fallback chain — Avenir was Frutiger's
 * humanist answer to Futura's geometry. Futura is held to short uppercase
 * labels because its lowercase is weak below about 14px.
 */

:root {
  --ground: #0A0D10;
  --ground-lift: #0E1317;
  --panel: #131A20;
  --panel-lift: #18212A;
  --line: #202A33;
  --line-lit: #2F3E4B;

  --text: #E7EEF4;
  --text-dim: #AEBCC8;
  --muted: #78868F;

  --go: #4CE0B3;
  --caution: #F0B429;
  --flag: #FF6B6B;
  --data: #6BA8F5;
  --silver: #C4CEDA;
  --locked: #5E6E7E;

  --accent: var(--go);

  --display: Futura, 'Futura PT', 'Trebuchet MS', sans-serif;
  --sans: 'Avenir Next', Avenir, 'Helvetica Neue', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, monospace;

  --rail: 14.5rem;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* The accent is the only thing that moves between sections. Labs is the blue of
 * a reference range, tendon the amber of a load warning, gray hair silver.
 * Navigating therefore feels like changing instruments, not changing pages. */
body[data-section='labs']      { --accent: var(--data); }
body[data-section='wearable']  { --accent: var(--data); }
body[data-section='tendon']    { --accent: var(--caution); }
body[data-section='gray-hair'] { --accent: var(--silver); }
body[data-section='today']     { --accent: var(--go); }
body[data-section='training']  { --accent: var(--go); }
body[data-section='chat']      { --accent: var(--go); }
body[data-section='todos']     { --accent: var(--go); }
body[data-section='settings']  { --accent: var(--muted); }

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

/* The whole app hides and reveals itself through the hidden attribute, and
 * every one of those elements also carries a display rule from its own class.
 * A later `display: grid` outranks the user-agent `[hidden] { display: none }`,
 * which does not merely leave the element visible: #stage is position:fixed
 * inset:0, so a hidden stage silently swallowed every click on the page.
 * !important is the right tool here -- hidden is not a style preference, it is
 * a statement that the element is not in the page. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ground);
  color: var(--text);
  font: 400 16px/1.55 var(--sans);
  letter-spacing: 0.005em;
  -webkit-font-smoothing: antialiased;
}

/* Atmosphere: two soft pools of the current accent, so the ground is never a
 * flat fill. Transitioned slowly enough that a route change reads as the room
 * lighting shifting rather than a repaint. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(80rem 40rem at 12% -8%,
      color-mix(in oklab, var(--accent) 9%, transparent), transparent 65%),
    radial-gradient(60rem 45rem at 105% 12%,
      color-mix(in oklab, var(--accent) 5%, transparent), transparent 60%);
  transition: background 600ms var(--ease);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: var(--grain);
  opacity: 0.035;
  mix-blend-mode: overlay;
}

body > * { position: relative; z-index: 1; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 0.98rem; }
p { margin: 0 0 0.85rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration: none; }

.muted { color: var(--muted); }
.dim { color: var(--text-dim); }

.eyebrow {
  margin: 0 0 0.6rem;
  font-family: var(--display);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Capped at a measure somebody can read rather than at the panel's width. The
 * consent gate and the bed's disclosure are the two longest things anybody has
 * to read here, and both were running the full width of a desktop panel, which
 * is about 130 characters -- roughly twice the line length the eye can return
 * from without losing its place. */
.prose {
  max-width: 68ch;
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.65;
}
.prose strong { color: var(--text); font-weight: 600; }

/* Same measure and same size, one step quieter. For the paragraph that follows
 * a lede and matters less than it: setting it in .muted alone left it at the
 * body size, which made the least important text on the card the largest thing
 * on it. */
.prose--dim { color: var(--muted); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------------------------------------------------------------- boot */

.boot {
  display: grid;
  place-content: center;
  min-height: 100vh;
  margin: 0;
  font-family: var(--display);
  font-size: 0.8rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.ellipsis::after {
  content: '';
  animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
}

/* ---------------------------------------------------------------- gates */

.gate {
  width: min(26rem, calc(100vw - 2.5rem));
  margin: min(14vh, 7rem) auto;
  padding: 2rem 1.9rem 1.75rem;
  display: grid;
  gap: 1rem;
  background: linear-gradient(180deg, var(--panel-lift), var(--panel));
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 30px 70px -40px #000, 0 0 0 1px #ffffff06 inset;
}

.gate--wide { width: min(44rem, calc(100vw - 2.5rem)); }

.gate__title {
  font-size: 1.5rem;
  line-height: 1.2;
  margin-bottom: 0.25rem;
}

.gate__error {
  min-height: 1.2em;
  margin: 0;
  font-size: 0.85rem;
  color: var(--flag);
}

/* The enrolment QR. The white plate under it is not decoration: the code is
 * black modules on transparent, and against this background a camera sees one
 * unbroken dark square. */
.qr {
  display: block;
  width: 200px;
  height: 200px;
  padding: 0.5rem;
  background: #fff;
  border-radius: 6px;
}

/* The same secret the QR carries, for a camera that will not focus. It gets
 * typed character by character, so it is set in a face that keeps 0 apart
 * from O, and select-all on click saves the typing where a clipboard is
 * available. */
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
  user-select: all;
}

/* The line a card writes its own progress into. The height is held open
 * whether or not there is anything in it, because otherwise the first message
 * of a sync pushes every button on the card down by a line under the thumb
 * that pressed one. */
.status-line {
  min-height: 1.3em;
  margin: 0.8rem 0 0;
  font-size: 0.85rem;
}

/* The word, not the colour. Set as a label so it is read ahead of the sentence
 * rather than as the start of it, and coloured with the tone so the two say
 * the same thing twice. */
.status__flag {
  margin-right: 0.5rem;
  font-family: var(--display);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.status--error { color: var(--flag); }
.status--caution { color: var(--caution); }

.check {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.7rem;
  align-items: start;
  padding: 0.8rem 0.9rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-dim);
  background: #0000002e;
  border: 1px solid var(--line);
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 160ms var(--ease), background 160ms var(--ease);
}

.check:has(input:checked) {
  border-color: color-mix(in oklab, var(--accent) 55%, var(--line));
  background: color-mix(in oklab, var(--accent) 7%, transparent);
  color: var(--text);
}

.check input {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0.15rem 0 0;
  accent-color: var(--accent);
}

.check em { color: var(--accent); font-style: normal; font-weight: 600; }

.field { display: grid; gap: 0.4rem; }

.field > span {
  font-family: var(--display);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.field--nested { margin: -0.4rem 0 0 2.5rem; }

input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: #00000045;
  border: 1px solid var(--line-lit);
  border-radius: 3px;
}

input[type='checkbox'] { width: auto; }
textarea { min-height: 5rem; resize: vertical; }

input::placeholder, textarea::placeholder { color: var(--muted); }

/* ---------------------------------------------------------------- buttons */

.btn {
  padding: 0.68rem 1.15rem;
  font-family: var(--display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #05100C;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  transition: transform 120ms var(--ease), filter 160ms var(--ease);
}

.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; filter: none; }

.btn--quiet {
  color: var(--text-dim);
  background: transparent;
  border-color: var(--line-lit);
}

.btn--quiet:hover { color: var(--text); border-color: var(--accent); filter: none; }

.btn--small { padding: 0.4rem 0.7rem; font-size: 0.68rem; }

/* ---------------------------------------------------------------- shell */

.app {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.6rem 1.1rem 1.3rem;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--ground-lift), #0A0D1000);
}

.rail__brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-family: var(--display);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text);
}

/* A drawn sight, not an icon font: two rings in the live accent. */
.rail__mark {
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 2px var(--accent),
    inset 0 0 0 5px transparent,
    inset 0 0 0 7px color-mix(in oklab, var(--accent) 45%, transparent);
  transition: box-shadow 400ms var(--ease);
}

.rail__nav { display: grid; gap: 0.1rem; }
.rail__nav .eyebrow { margin: 1.1rem 0 0.35rem 0.6rem; font-size: 0.62rem; }
.rail__nav .eyebrow:first-child { margin-top: 0; }

.rail__nav a {
  position: relative;
  padding: 0.5rem 0.6rem 0.5rem 0.85rem;
  font-size: 0.93rem;
  color: var(--text-dim);
  border-radius: 3px;
  transition: color 140ms var(--ease), background 140ms var(--ease);
}

.rail__nav a::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 2px;
  height: 0;
  background: var(--accent);
  transform: translateY(-50%);
  transition: height 220ms var(--ease);
}

.rail__nav a:hover { color: var(--text); background: #ffffff08; }

.rail__nav a[aria-current='page'] {
  color: var(--text);
  background: color-mix(in oklab, var(--accent) 9%, transparent);
}

.rail__nav a[aria-current='page']::before { height: 1.35rem; }

.rail__out { margin-top: auto; }

/* There is room for all nine sections on a desktop rail, so there is nothing
 * for this to open. */
.rail__menu { display: none; }

.shell { display: flex; flex-direction: column; min-width: 0; }

.crest {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 1rem;
  padding: 1.7rem clamp(1.1rem, 3.5vw, 2.5rem) 1.1rem;
  border-bottom: 1px solid var(--line);
}

.crest .eyebrow { margin: 0; color: var(--accent); font-size: 0.72rem; }
.crest__date { margin: 0; font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }
.crest__who { margin: 0; font-size: 0.8rem; margin-left: auto; }

.view { padding: clamp(1.1rem, 3.5vw, 2.5rem); }

/* The stack the page actually assembles into. It is a per-navigation element
 * the router throws away, which is why the layout lives here and not on .view:
 * the padding must survive the swap and the grid must be reborn with the page.
 */
.view__page {
  display: grid;
  gap: 1.15rem;
  align-content: start;
}

/* The one orchestrated moment. The router hands each navigation a new
 * .view__page, so these delays replay every time and each page assembles
 * itself. */
@keyframes rise {
  from { opacity: 0; transform: translateY(9px); }
  to   { opacity: 1; transform: none; }
}

.view__page > * { animation: rise 420ms var(--ease) both; }
.view__page > *:nth-child(1) { animation-delay: 0ms; }
.view__page > *:nth-child(2) { animation-delay: 70ms; }
.view__page > *:nth-child(3) { animation-delay: 140ms; }
.view__page > *:nth-child(4) { animation-delay: 210ms; }
.view__page > *:nth-child(n+5) { animation-delay: 280ms; }

/* ---------------------------------------------------------------- panels */

.panel {
  position: relative;
  padding: 1.25rem 1.35rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}

/* A hairline of light along the top edge, the way a bezel catches it. */
.panel::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, #ffffff1f 25%, #ffffff1f 75%, transparent);
}

.panel--accent { border-color: color-mix(in oklab, var(--accent) 40%, var(--line)); }
.panel__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.9rem;
}

.grid { display: grid; gap: 1.15rem; }
/* The floor collapses to the container. A bare 19rem floor is wider than a
 * panel's content box on a 390px screen, and because these grids sit inside
 * other grids the oversized track stretched every sibling to match: on a
 * phone a settings form spilled 39px past its own border, and so did the
 * paragraph under it. */
.grid--two { grid-template-columns: repeat(auto-fit, minmax(min(19rem, 100%), 1fr)); }

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

/* A row of fields rather than a row of buttons. Without a basis they collapse
 * to the width of their own labels, which leaves an email address in a box too
 * narrow to read back. Opt-in, because four other pages put a .field inside a
 * .row and mean the tighter thing by it. */
.row--fields > .field { flex: 1 1 14rem; }

/* Beside the control, not beside the label-and-control stack: without this a
 * button centres against the whole two-line field and floats above the input
 * it belongs to. */
.row--fields > .btn { align-self: flex-end; }

/* ---------------------------------------------------------------- data */

.hero__value {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(3.25rem, 11vw, 5.5rem);
  font-variant-numeric: tabular-nums;
  line-height: 0.95;
  letter-spacing: -0.03em;
  color: var(--text);
}

.hero__unit { font-size: 0.3em; color: var(--muted); letter-spacing: 0.05em; }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}

.metric { padding: 0.95rem 1rem; background: var(--panel); }
.metric dt {
  font-family: var(--display);
  font-size: 0.64rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.metric dd {
  margin: 0.3rem 0 0;
  font-family: var(--mono);
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.metric dd small { font-size: 0.55em; color: var(--muted); }

.signal {
  display: grid;
  gap: 0.7rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.signal li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.3rem 1rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--line);
}

.signal li:last-child { border-bottom: 0; padding-bottom: 0; }

.signal__name { font-size: 0.95rem; }
.signal__value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.signal__note { grid-column: 1 / -1; font-size: 0.82rem; color: var(--muted); }

.signal__bar {
  grid-column: 1 / -1;
  height: 3px;
  border-radius: 2px;
  background: var(--line-lit);
  overflow: hidden;
}
.signal__bar > span { display: block; height: 100%; background: var(--accent); }

/* A cause printed beside the number it explains. Jeff's creatinine is high
 * because he takes creatine daily; a dashboard that shows the number without
 * the note invites the wrong conclusion every single time it is read. */
.because {
  grid-column: 1 / -1;
  margin-top: 0.4rem;
  padding: 0.55rem 0.7rem;
  font-size: 0.83rem;
  line-height: 1.5;
  color: var(--text-dim);
  background: color-mix(in oklab, var(--data) 8%, transparent);
  /* A hairline the whole way round rather than a bar down one side. A coloured
   * left edge is decoration that reads as structure: it points at nothing,
   * survives no reflow, and every other tinted block on the site is bounded.
   * The tint and the eyebrow already carry the colour. */
  border: 1px solid color-mix(in oklab, var(--data) 32%, transparent);
  border-radius: 3px;
}

.because b {
  display: block;
  font-family: var(--display);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--data);
}

/* What you are agreeing to, set apart from the paragraph that reassures you
 * about it. A full hairline rather than a heavy edge down one side: a stripe
 * reads as decoration and this block has to stop somebody mid-scroll. The tint
 * is amber because it is the site's colour for a load you have to think about,
 * and nothing here is an error yet -- nobody has done anything wrong by
 * reading it. */
.warn {
  max-width: 68ch;
  margin: 0 0 0.85rem;
  padding: 0.7rem 0.85rem 0.75rem;
  color: var(--text-dim);
  background: color-mix(in oklab, var(--caution) 7%, transparent);
  border: 1px solid color-mix(in oklab, var(--caution) 34%, var(--line));
  border-radius: 3px;
}

.warn__label {
  display: block;
  margin-bottom: 0.45rem;
  font-family: var(--display);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--caution);
}

.warn ul {
  margin: 0;
  padding-left: 1.05rem;
  font-size: 0.87rem;
  line-height: 1.55;
}

.warn li + li { margin-top: 0.4rem; }
.warn li::marker { color: var(--caution); }

/* The evidence under a connection's badge: when the last night actually
 * arrived, and why it did not. Ordinary hint text while the history is
 * current, because a source that is working should not compete for attention
 * with one that has stopped. It does not get the .warn treatment either: a
 * bordered block per card would put two boxes on every panel and teach the eye
 * to skip both. */
.freshness {
  max-width: 68ch;
  margin: -0.15rem 0 0.7rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--muted);
}

.freshness--behind { color: var(--caution); }

/* ---------------------------------------------------------------- pills */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.55rem;
  font-family: var(--display);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  border-radius: 2px;
  white-space: nowrap;
}

.pill--go { color: var(--go); }
.pill--caution { color: var(--caution); }
.pill--flag { color: var(--flag); background: color-mix(in oklab, var(--flag) 12%, transparent); }
.pill--data { color: var(--data); }
.pill--muted { color: var(--muted); }

/* Locked is slate with a drawn bar, never red: not-yet-available is not a
 * danger state, and colouring it like one teaches you to ignore red. */
.pill--locked { color: var(--locked); }
.pill--locked::before {
  content: '';
  width: 0.5rem;
  height: 0.42rem;
  border: 1px solid currentColor;
  border-radius: 1px;
  box-shadow: 0 -0.26rem 0 -0.12rem currentColor;
}

/* Evidence grade, ramped by study design. Expert opinion is outlined grey on
 * purpose — it must never read as strongly as the RCT-backed work. */
.grade--rct { color: #05100C; background: var(--go); border-color: var(--go); }
.grade--cohort { color: #9BE7D6; background: #4CE0B31f; border-color: #4CE0B355; }
.grade--mechanistic { color: var(--caution); background: #F0B4291a; border-color: #F0B42955; }
.grade--expert { color: var(--muted); background: transparent; }

/* ---------------------------------------------------------------- labs */

/* Named for the first thing it held and since reused by ten forms, only two of
 * which take a file at all. The dashes it used to be drawn with were the
 * universal mark of a drop target, and nothing on this site has ever accepted
 * a dropped file: the border was promising a gesture that silently does
 * nothing, on forms where the gesture makes no sense. Solid, so it reads as
 * what it is, an inset region you fill in. */
.upload {
  display: grid;
  gap: 0.75rem;
  padding: 1.4rem;
  text-align: center;
  border: 1px solid var(--line-lit);
  border-radius: 4px;
  background: #00000026;
}

.table-scroll { overflow-x: auto; margin: 0 -1.35rem -1.25rem; padding: 0 1.35rem 1.25rem; }

table.review { width: 100%; border-collapse: collapse; font-size: 0.88rem; }

/* Set as an aside above the columns rather than as a title, because the card's
 * own heading has already named the table. This is for what the heading cannot
 * say: which way the rows run, and that there are more of them than this. */
table.review caption {
  padding: 0 0.6rem 0.55rem;
  text-align: left;
  font-size: 0.78rem;
  color: var(--muted);
}

table.review th {
  position: sticky;
  top: 0;
  padding: 0.45rem 0.6rem;
  text-align: left;
  font-family: var(--display);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--panel);
  border-bottom: 1px solid var(--line-lit);
}

table.review td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.review__value { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.review__unit { color: var(--muted); font-size: 0.85em; }
.review__unmapped { color: var(--caution); }

.banner {
  padding: 1rem 1.15rem;
  border: 1px solid var(--flag);
  border-left-width: 3px;
  border-radius: 3px;
  background: color-mix(in oklab, var(--flag) 12%, transparent);
}

.banner h2 { color: var(--flag); margin-bottom: 0.4rem; }

/* ---------------------------------------------------------------- todos */

.todo {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.5rem 0.8rem;
  align-items: center;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}

.todo:last-child { border-bottom: 0; }
.todo__title { font-size: 0.95rem; }
.todo__detail { grid-column: 2 / -1; font-size: 0.82rem; color: var(--muted); }
.todo--done .todo__title { color: var(--muted); text-decoration: line-through; }

/* --------------------------------------------------------------- clearances */

/* Four controls on a row: the box, what it covers, the date it was given and
 * who gave it. The source is not decoration -- it is what distinguishes an arm
 * cleared by a surgeon from an arm its owner cleared because nobody operated
 * on it. */
.clear {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 0.5rem 0.8rem;
  align-items: center;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}

.clear__what { font-size: 0.95rem; }
.clear__who { font-size: 0.82rem; color: var(--muted); }

/* ---------------------------------------------------------------- arms */

.arm {
  display: grid;
  gap: 0.35rem;
  padding: 0.85rem 1rem;
  background: var(--panel-lift);
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: 0 3px 3px 0;
}

.arm--control { border-left-color: var(--muted); }
.arm--gated { border-left-color: var(--locked); opacity: 0.75; }
.arm__treatment { font-size: 0.85rem; color: var(--text-dim); }
.arm__gate { font-size: 0.82rem; color: var(--caution); }

/* ---------------------------------------------------------------- protocol */

/* A two-column reference read mid-experiment, so the cue column is fixed and
 * the instruction wraps under itself rather than centring on the cue. */
.proto { display: grid; gap: 0.55rem; }

.proto__row {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.75rem;
  align-items: baseline;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--line);
}

.proto__row:last-child { padding-bottom: 0; border-bottom: 0; }

.proto__when {
  font-family: var(--display);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.proto__what { font-size: 0.85rem; color: var(--text-dim); }

.rules {
  display: grid;
  gap: 0.4rem;
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.rules li::marker { color: var(--caution); }

/* ---------------------------------------------------------------- samples */

/* This code is read off a screen and copied onto a bag with a pen, weeks
 * before it is typed back in. So it is set large, monospaced and widely
 * tracked: 8/B and 0/D are the pairs that get miswritten at a bench, and
 * tracking is what pulls them apart. Tapping selects the whole thing, because
 * a partial selection is how you get a five-character code. */
.code {
  margin: 0.2rem 0 0;
  font-family: var(--mono);
  font-size: 1.8rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: var(--accent);
  -webkit-user-select: all;
  user-select: all;
}

.code:empty { display: none; }

.codes { display: grid; gap: 0.3rem; margin: 0; padding: 0; list-style: none; }

/* Wraps rather than using a fixed column grid: a long note on a narrow phone
 * would otherwise squeeze the code itself, which is the one part that has to
 * stay readable. */
.code-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.7rem;
  padding: 0.45rem 0.65rem;
  background: var(--panel-lift);
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 0.85rem;
}

.code-row--done { opacity: 0.55; }

.code-row__code {
  min-width: 4.6rem;
  font-family: var(--mono);
  letter-spacing: 0.1em;
  -webkit-user-select: all;
  user-select: all;
}

.code-row__when { color: var(--muted); }
.code-row__note { flex: 1 1 12rem; color: var(--text-dim); }

/* ---------------------------------------------------------------- pain scale */

/* Segmented and tappable, not a drag slider. The Tendons spec is explicit that
 * a slider produces anchoring and mis-taps on a phone held in a chalked hand;
 * eleven discrete targets cannot be dragged past the number you meant. */
.scale {
  display: grid;
  grid-template-columns: repeat(11, minmax(0, 1fr));
  gap: 2px;
}

.scale__step {
  min-height: 2.75rem;
  padding: 0;
  font-family: var(--mono);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  background: var(--panel-lift);
  border: 1px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
}

.scale__step:hover { border-color: var(--line-lit); color: var(--text); }

.scale__step[aria-pressed='true'] {
  color: #05100C;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.scale__legend {
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--muted);
}

/* --------------------------------------------------------------- which one */

/* Targets, not a dropdown. Both readers of this -- which arm a tendon verdict
 * is about, which half of the mattress this account sleeps on -- are touched
 * before anything else and change every number under them, so they have to
 * read as a position you are standing in rather than a field you filled in. */
.pick {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
}

.pick--pair { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.pick__target {
  min-height: 2.75rem;
  padding: 0 0.5rem;
  font-family: var(--display);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--panel-lift);
  border: 1px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
}

.pick__target:hover { border-color: var(--line-lit); color: var(--text); }

.pick__target[aria-pressed='true'] {
  color: #05100C;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

/* ---------------------------------------------------------------- chat */

.chat { display: grid; gap: 0.8rem; }

.turn {
  max-width: 44rem;
  padding: 0.8rem 1rem;
  font-size: 0.95rem;
  line-height: 1.6;
  border-radius: 3px;
}

.turn--you {
  justify-self: end;
  color: var(--text);
  background: var(--panel-lift);
  border: 1px solid var(--line-lit);
}

.turn--engine {
  color: var(--text-dim);
  background: color-mix(in oklab, var(--accent) 6%, transparent);
  border-left: 2px solid var(--accent);
}

.turn--engine strong { color: var(--text); }

/* ---------------------------------------------------------------- stage */

/* Full-bleed, because from arm's length on a hangboard the only legible signal
 * is the whole screen changing colour. The numeral is secondary; the wash is
 * what tells you to pull. */
.stage {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem 1.25rem calc(2rem + env(safe-area-inset-bottom));
  text-align: center;
  background: #14191F;
  transition: background 180ms linear;
}

.stage[data-phase='prepare'] { background: #1E2733; }
.stage[data-phase='work']    { background: #0E7A5F; }
.stage[data-phase='rest']    { background: #6B4B08; }
.stage[data-phase='switch']  { background: #1D3F6B; }
.stage[data-phase='paused']  { background: #14191F; }
.stage[data-phase='done']    { background: #0A0D10; }

.stage__protocol {
  margin: 0;
  font-family: var(--display);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #ffffffa8;
}

.stage__phase {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.1rem, 5vw, 1.6rem);
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #fff;
}

.stage__count {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(6rem, 34vw, 15rem);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  line-height: 0.9;
  letter-spacing: -0.04em;
  color: #fff;
}

.stage__next, .stage__progress {
  margin: 0;
  font-size: 0.9rem;
  color: #ffffffbf;
}

.stage__bar {
  width: min(28rem, 100%);
  height: 4px;
  margin: 0.75rem 0 1.25rem;
  border-radius: 2px;
  background: #ffffff26;
  overflow: hidden;
}

.stage__bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: #fff;
  transition: width 200ms linear;
}

/* Controls sit in the bottom thumb zone: the one place on this site where the
 * hand holding the phone is also the hand that just let go of the bar. */
.stage__controls {
  display: flex;
  gap: 0.6rem;
  width: min(28rem, 100%);
  margin-top: auto;
}

.btn--stage {
  flex: 1;
  min-height: 3.25rem;
  color: #fff;
  background: #ffffff1f;
  border-color: #ffffff3d;
}

.btn--stage:hover { background: #ffffff30; filter: none; }
.btn--stage-end { color: #fff; background: #b3333340; border-color: #ff6b6b7a; }

/* ---------------------------------------------------------------- mobile */

/* A five-slot bottom tab bar was the obvious move and the wrong one: there are
 * nine destinations, and hiding four of them behind "more" is how a project
 * stops getting looked at. A scrollable strip shows all nine. The thumb-zone
 * argument is honoured where it actually matters — the in-session stage. */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  /* The fixed cue column is what breaks first at 390px: "Baseline" and a full
   * sentence cannot share a row that narrow without the sentence going to three
   * words per line. */
  .proto__row { grid-template-columns: minmax(0, 1fr); gap: 0.2rem; }

  /* A checkbox, a label, a date picker and a select do not fit across 390px.
   * The two controls drop under the label rather than shrinking, because a
   * squeezed date input is the one that gets mis-tapped. */
  .clear { grid-template-columns: auto minmax(0, 1fr); }
  .clear > :nth-child(3), .clear > :nth-child(4) { grid-column: 2; }

  .rail {
    position: sticky;
    top: 0;
    z-index: 20;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.85rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: #0A0D10e6;
    backdrop-filter: blur(12px);
  }

  /* The wordmark goes, the sight stays, and the link keeps a full target
   * around it -- it is still the way back to Today, and a 17px sight is not
   * something a thumb hits. */
  .rail__brand span:last-child { display: none; }

  .rail__brand {
    justify-content: center;
    min-width: 2.75rem;
    min-height: 2.75rem;
    margin-left: -0.6rem;
  }

  /* The section you are in, and the way to every other one. Naming the current
   * section means the bar is not a mystery glyph. */
  .rail__menu {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    margin-left: auto;
    padding: 0 0.85rem;
    font-family: var(--display);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text);
    background: var(--panel-lift);
    border: 1px solid var(--line-lit);
    border-radius: 2px;
    cursor: pointer;
  }

  .rail__caret {
    width: 0.42rem;
    height: 0.42rem;
    border-right: 1.5px solid var(--accent);
    border-bottom: 1.5px solid var(--accent);
    transform: translateY(-0.12rem) rotate(45deg);
    transition: transform 180ms var(--ease);
  }

  .rail__menu[aria-expanded='true'] .rail__caret {
    transform: translateY(0.05rem) rotate(-135deg);
  }

  /* A sheet, not a strip. Every destination is on screen at once and nothing
   * is reachable only by a horizontal drag nobody knows to try. */
  .rail__nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    padding: 0.6rem 0.85rem calc(0.9rem + env(safe-area-inset-bottom));
    background: #0A0D10f7;
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
  }

  .rail__nav[data-open='true'] { display: grid; }

  .rail__nav .eyebrow { margin: 0.8rem 0 0.2rem 0.85rem; }
  .rail__nav .eyebrow:first-child { margin-top: 0.2rem; }

  .rail__nav a {
    display: flex;
    align-items: center;
    min-height: 2.75rem;
    font-size: 1rem;
  }

  .rail__out { padding: 0 0.7rem; min-height: 2.75rem; font-size: 0.62rem; }

  /* A thumb is not a mouse pointer. 2.75rem is the Apple minimum and these are
   * the controls a whole page hangs off: the primary action on every form, and
   * the only way into a project from the board. */
  .btn, .btn--small { min-height: 2.75rem; }

  /* The native box renders at 13px, which is under the 24px WCAG floor, and
   * these two are the worst of them: one flips whether a protocol is allowed
   * on an arm, the other marks a to-do done. */
  .clear input[type='checkbox'], .todo > input[type='checkbox'] {
    width: 1.5rem;
    height: 1.5rem;
    accent-color: var(--accent);
  }

  /* A link alone in its own paragraph is a button that was never dressed as
   * one. Inline links inside a sentence are left alone. */
  .view p > a:only-child {
    display: inline-flex;
    align-items: center;
    min-height: 1.5rem;
  }

  .crest { padding-top: 1.2rem; }
  .crest__who { margin-left: 0; width: 100%; }

  .table-scroll { margin: 0 -1.1rem -1.1rem; padding: 0 1.1rem 1.1rem; }
}

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