/* ==========================================================================
   MediSim design system — shared by the player page (ui.html), the admin
   dashboard (dashboard.html) and the 403 page. Served at /styles/system.css.

   THE IDEA: A FACEPLATE
   Each screen is one flat, machined faceplate in cool aluminium, divided by
   engraved 1px hairlines. No floating cards and no blurred shadows: areas of
   the plate are cut apart by rules, never lifted. Three radii only — 4 for
   keys, 6 for screens and cut-in panels, 8 for the face — and lamps are
   round. Only things you press wear the warm bone cap (--cap), so every
   control is findable by temperature alone; each key stands on a hard 2px
   skirt in its own channel colour and travels 2px when pressed.

   Colour lives only on small parts: keys, flat lit-lens lamps and 3–4px
   edges. Four channels, each a job, never decoration:

     blue   primary action, navigation, "this is live"
     green  correct / done / passing / the patient's own voice
     red    danger, end, wrong, critical
     amber  attention, pending, a warning that is not yet a failure

   Each channel ships a FILL (key caps), an INK (text on the chassis; every
   ink clears WCAG AA 4.5:1 on --chassis and --plate), a WASH (large tinted
   surfaces), an EDGE (skirts and 3–4px edges) and a LED (lit lamps). Amber
   is never text: it is a fill with ink on it, or an edge. The status trio
   still always travels with a glyph or a word; colour is never the only
   carrier.

   Dark glass is rationed to live state: the monitor, the sim clock, the
   scenario readout and job logs. The cardiac monitor itself is deliberately
   NOT themed by any of this (see styles/monitor.css); no rule here selects
   inside .monitorCard except the pins that keep its inherited values fixed
   (end of the Base block).

   TYPE: Archivo only, at named widths (the same woff2 declared three times,
   its wdth axis clamped by the descriptor): 125% "Archivo Display" for the
   maker's mark and the verdict, 100% for text and keys, 80% "Archivo
   Legend" for short legends and moving numbers. JetBrains Mono survives
   only for literal identifiers (protocol ids, slugs, logs): --font-code.

   RULES FOR EVERY SHEET THAT BUILDS ON THIS ONE
   1. New colours come from the tokens below; add a token rather than a hex.
   2. No element may start invisible: reduced-motion kills every animation
      (bottom of this file), so base states are always the final states and
      motion is additive inside `prefers-reduced-motion: no-preference`.
   3. Interactive text is never --ink-3 (that tone is for captions only).
   4. Legends are caps only for three words or fewer; a longer label is set
      as text (`.legend--text`).
   5. A hand-rolled key (a button that is not `.key`) wears the same cap:
      `box-shadow: var(--key-shadow)` and `transition: var(--key-transition)`
      on its own rule, and its sheet lists it in that sheet's key-mechanics
      block (press, hover, focus).
   ========================================================================== */

@font-face {
  font-family: "Archivo";
  src: url("/styles/fonts/archivo.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Archivo Legend";
  src: url("/styles/fonts/archivo.woff2") format("woff2");
  font-weight: 100 900; font-stretch: 80%; font-display: swap;
}
@font-face {
  font-family: "Archivo Display";
  src: url("/styles/fonts/archivo.woff2") format("woff2");
  font-weight: 100 900; font-stretch: 125%; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/styles/fonts/jetbrains-mono.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

:root {
  /* ── Chassis: cool body, wide grey steps, warm caps ───────────────────── */
  --chassis: #dadde0;        /* the body: page background */
  --chassis-2: #cdd1d4;      /* recessed zones, wells */
  --plate: #eef0f1;          /* the face and its cells */
  --plate-2: #e4e7e9;        /* a band inside a plate (orders, dispatch) */
  --cap: #fcfaf6;            /* bone: pressables and inputs only */
  --rule: #c3c6c9;           /* engraved hairlines */
  --rule-2: #9b9fa3;         /* strong hairlines, skirts */
  --ink: #1c1c1e;
  --ink-2: #47474b;          /* secondary text — 7:1 on chassis */
  --ink-3: #5c5e61;          /* captions only — 4.7:1 on chassis, 5.6:1 on plate */
  --keygrey: #cdcac5;        /* the second plastic: nav keys */
  --keygrey-2: #c0bdb7;
  --keygrey-edge: #9e9b94;
  --graphite: #29292c;
  --graphite-2: #3b3b3f;
  --screen: #151618;         /* dark glass: live readouts only */
  --screen-ink: #ededea;
  --screen-dim: #8f9196;

  /* ── Colour channels, rebalanced (blue is no longer the weakest); red is
     vermilion ─────────────────────────────────────────────────────────── */
  --blue: #7cb6f1;  --blue-ink: #1e5ea4;  --blue-wash: #e1edfa;  --blue-edge: #4f8ac6;
  --green: #7fd497; --green-ink: #1f6a3b; --green-wash: #e2f2e5; --green-edge: #4ca167;
  --red: #f6927b;   --red-ink: #aa3023;   --red-wash: #fbe8e2;   --red-edge: #cc624e;
  --amber: #fcbf4d; --amber-ink: #7e5200; --amber-wash: #f8edd8; --amber-edge: #cd7d09;
  /* Lit-lamp fills. */
  --led-blue: #4892e1; --led-green: #43b966; --led-red: #e55745; --led-amber: #f7a921;
  /* A lamp is a lit lens: dark rim, specular top, no bloom. Off is a ring. */
  --lens: inset 0 0 0 1px rgba(0,0,0,.22), inset 0 1.5px 1px rgba(255,255,255,.55);
  --lens-off: inset 0 0 0 1.5px var(--rule-2);

  /* ── ECG paper (trainer mini-strips; the printout keeps its own) ───── */
  --strip-paper: #fbf6f2;
  --strip-minor: #f1dcd5;
  --strip-major: #e2b3a8;
  --strip-trace: #1c1c1e;

  /* ── Type: one family, three widths, seven sizes ──────────────────────── */
  --font-ui: "Archivo", "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-legend: "Archivo Legend", "Arial Narrow", sans-serif;
  --font-display: "Archivo Display", "Archivo", sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  /* Legacy name: before the faceplate every label was mono. It now means
     the legend voice; literal identifiers name --font-code. */
  --font-mono: var(--font-legend);
  --fs-legend: 11px;  --lh-legend: 16px;
  --fs-small: 13px;   --lh-small: 20px;
  --fs-body: 15px;    --lh-body: 24px;
  --fs-title: 18px;   --lh-title: 24px;
  --fs-head: 24px;    --lh-head: 28px;
  --fs-read: 36px;    --lh-read: 36px;
  --fs-mark: clamp(40px, 6vw, 72px);
  --tr-legend: .06em;
  --tr-display: -.02em;

  /* ── Geometry: machined radii ─────────────────────────────────────────── */
  --r-sm: 2px;
  --r: 4px;       /* keys */
  --r-lg: 6px;    /* screens, cut-in panels */
  --r-xl: 8px;    /* the face */
  --gap: 16px;
  --u: 8px;
  --rail-h: 60px;
  --ctl-h: 40px;

  /* ── Depth: the face is flat; only keys stand proud and only true layers
     (modals) cast a shadow ─────────────────────────────────────────────── */
  --plate-shadow: none;
  --well-shadow: inset 0 1px 2px rgba(30,36,42,.16);
  --lift-shadow: 0 0 0 1px rgba(28,28,30,.08), 0 18px 36px -22px rgba(28,28,30,.55);
  --focus: 0 0 0 2px var(--chassis), 0 0 0 4px var(--ink);
  --key-skirt: var(--rule-2);

  /* ── Motion: mechanical, not cinematic ────────────────────────────────── */
  --m-press: 24ms;  --m-hover: 90ms;  --m-release: 150ms;
  --m-seat: 180ms;  --m-leave: 110ms; --m-step: 45ms;
  --e-press: linear;
  --e-spring: cubic-bezier(.3, 1.55, .55, 1);
  --e-settle: cubic-bezier(.25, .9, .35, 1);
  --e-seat: cubic-bezier(.16, .84, .3, 1);
  --e-leave: cubic-bezier(.5, 0, .9, .4);
  /* Release about 150ms with a small spring; hover a 90ms glaze. */
  --key-transition:
    transform var(--m-release) var(--e-spring),
    box-shadow var(--m-release) var(--e-settle),
    background-color var(--m-hover) linear,
    border-color var(--m-hover) linear,
    color var(--m-hover) linear;
  --t-key: 70ms;
  --t-ui: 160ms;
  --ease: cubic-bezier(.2,.7,.2,1);

  /* ── Legacy names ──────────────────────────────────────────────────────
     The tokens every sheet used before the redesign, mapped onto the new
     chassis so a rule that still names one renders in-family. Prefer the
     new names in new rules. */
  --bg: var(--chassis);
  --panel: var(--plate);
  --panel-2: var(--cap);
  --border: var(--rule);
  --border-strong: var(--rule-2);
  --text: var(--ink);
  --dim: var(--ink-2);
  --faint: var(--ink-3);
  --accent: var(--blue-ink);
  --accent-dim: var(--blue);
  --ok: var(--green-ink);
  --bad: var(--red-ink);
  --warn: var(--amber-ink);
  --na: var(--ink-3);
  --spark: var(--ink-3);
  --radius: var(--r);
  --radius-lg: var(--r-lg);

  color-scheme: light;
  font-synthesis-weight: none;
  accent-color: var(--blue-ink);
}
@media (max-width: 720px) { :root { --fs-legend: 12px; --ctl-h: 36px; } }
/* Touch: desktop density stays; coarse pointers get 44px controls. */
@media (pointer: coarse) { :root { --ctl-h: 44px; } }

/* Key shadow recipes are declared on every element (not only on :root) so
   each key resolves its OWN --key-skirt: a custom property that references
   another is substituted where it is declared, then inherited as text. Four
   layers in every state, so a press interpolates as geometry. The monitor
   card is excluded: it inherits exactly what it always has. */
:where(body *:not(.monitorCard, .monitorCard *)) {
  --key-shadow:
    inset 0 1px 0 rgba(255,255,255,.9),
    0 2px 0 0 var(--key-skirt),
    0 3px 1px -1px rgba(30,30,32,.16),
    inset 0 0 0 99px rgba(255,255,255,0);
  --key-shadow-hover:
    inset 0 1px 0 rgba(255,255,255,1),
    0 2px 0 0 var(--key-skirt),
    0 3px 1px -1px rgba(30,30,32,.16),
    inset 0 0 0 99px rgba(255,255,255,.10);
  --key-shadow-press:
    inset 0 1px 2px rgba(30,30,32,.24),
    0 0 0 0 var(--key-skirt),
    0 0 0 -1px rgba(30,30,32,0),
    inset 0 0 0 99px rgba(30,30,32,.05);
  /* Disabled: unavailable, not pressed. Full height, faded, a plain skirt. */
  --key-shadow-off: inset 0 0 0 99px rgba(255,255,255,0), 0 2px 0 0 var(--rule);
}

/* ── Base ─────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--chassis);
  color: var(--ink);
  font: 400 15px/1.5 var(--font-ui);
  font-stretch: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue-ink); text-underline-offset: 2px; }
::selection { background: var(--amber); color: var(--ink); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
/* Focus rings that are drawn with box-shadow (keys, switches, fields) keep a
   TRANSPARENT outline underneath instead of `outline: none`: invisible in the
   normal palette, but forced-colours mode (Windows High Contrast) strips
   box-shadow and repaints outlines in a system colour, so the ring survives.
   Sheets that still say `outline: none` are covered by the forced-colours
   block at the bottom of this file. */
[hidden] { display: none !important; }

* { scrollbar-width: thin; scrollbar-color: var(--rule-2) transparent; }
/* The monitor keeps the two inherited values it has always had (its accent
   and scrollbar colours came from tokens the faceplate re-tuned), so its
   computed style stays identical to the monitor-shots baseline. */
#monitorOverlay .monitorCard { accent-color: #1f5fa6; }
#monitorOverlay .monitorCard, #monitorOverlay .monitorCard * { scrollbar-color: #a9a9a3 transparent; }

/* ── Legends: engraved labels in the 80% voice ────────────────────────── */
.legend {
  display: flex; align-items: center; gap: 8px;
  font: 600 var(--fs-legend)/var(--lh-legend) var(--font-legend);
  text-transform: uppercase; letter-spacing: var(--tr-legend);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}
.legend .rule { flex: 1; height: 1px; background: var(--rule); }
/* Caps only for three words or fewer: a label that carries a whole title is
   set as text. */
.legend.legend--text {
  text-transform: none; letter-spacing: 0;
  font: 600 var(--fs-small)/var(--lh-small) var(--font-ui);
}
.mono { font-family: var(--font-code); font-variant-numeric: tabular-nums; }

/* ── Surfaces ─────────────────────────────────────────────────────────── */
.plate {
  background: var(--plate); border: 1px solid var(--rule);
  border-radius: var(--r-lg); box-shadow: var(--plate-shadow);
}
.well {
  background: var(--chassis-2); border-radius: var(--r);
  box-shadow: var(--well-shadow);
}
/* Dark glass: one spec, rationed to live state. */
.screen {
  background: var(--screen); color: var(--screen-ink);
  border-radius: var(--r-lg); box-shadow: inset 0 0 0 1px #000;
  font-family: var(--font-legend);
}

/* ── LEDs: flat lit lenses, lit only when they report something ───────── */
.led {
  display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 50%;
  background: var(--rule-2); box-shadow: inset 0 -1px 1px rgba(0,0,0,.25);
}
.led.is-blue  { background: var(--led-blue);  box-shadow: var(--lens); }
.led.is-green { background: var(--led-green); box-shadow: var(--lens); }
.led.is-red   { background: var(--led-red);   box-shadow: var(--lens); }
.led.is-amber { background: var(--led-amber); box-shadow: var(--lens); }

/* ── Keys ─────────────────────────────────────────────────────────────────
   Every button is a key: a bone cap (or a channel cap) on a hard 2px skirt
   tinted from its own channel edge, no blur. Press: 2px travel in 24ms, the
   skirt folding under. Release: ~150ms with a small spring. Hover: a 10%
   glaze and an edge in the cap's own ink, never a lift. */
.key {
  --key-bg: var(--cap); --key-ink: var(--ink); --key-edge: var(--rule-2);
  --key-skirt: var(--key-edge);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--key-edge); border-radius: var(--r);
  background: var(--key-bg); color: var(--key-ink);
  font: 600 var(--fs-body)/1 var(--font-ui); letter-spacing: 0;
  box-shadow: var(--key-shadow);
  transition: var(--key-transition);
  user-select: none; -webkit-tap-highlight-color: transparent;
  text-decoration: none; white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) {
  .key:hover:not(:active):not(:focus-visible):not(:disabled):not([aria-disabled="true"]):not([data-armed]):not([aria-busy="true"]) {
    box-shadow: var(--key-shadow-hover); border-color: var(--ink-2);
  }
  .key--blue:hover:not(:disabled):not([aria-busy="true"]) { border-color: var(--blue-ink); }
}
.key:active:not(:disabled):not([aria-disabled="true"]) {
  transition-duration: var(--m-press); transition-timing-function: var(--e-press);
  transform: translateY(2px); box-shadow: var(--key-shadow-press);
}
.key:focus-visible { outline: 2px solid transparent; outline-offset: 2px; box-shadow: var(--key-shadow), var(--focus); }
.key:disabled, .key[aria-disabled="true"] { opacity: .45; cursor: default; box-shadow: var(--key-shadow-off); transform: none; }
.key--blue  { --key-bg: var(--blue);  --key-edge: var(--blue-edge); }
.key--green { --key-bg: var(--green); --key-edge: var(--green-edge); }
.key--red   { --key-bg: var(--red);   --key-edge: var(--red-edge); }
.key--amber { --key-bg: var(--amber); --key-edge: var(--amber-edge); }
/* The second plastic: nav keys leave the page; they are not the loudest
   thing on it. Mid-grey, ink legend. */
.key--dark  { --key-bg: var(--keygrey); --key-ink: var(--ink); --key-edge: var(--keygrey-edge); }
.key--ghost { --key-bg: transparent; box-shadow: none; border-color: var(--rule-2); }
.key--ghost:active:not(:disabled) { box-shadow: var(--key-shadow-press); }
.key--sm { min-height: 32px; padding: 0 11px; font-size: var(--fs-small); }
.key--lg { min-height: 56px; padding: 0 22px; font-size: 16px; }
.key--round { width: 40px; padding: 0; }
@media (pointer: coarse) { .key--sm { min-height: 44px; } }

/* Armed: the first press of a two-press confirm (ekgsim/ui/arm-key.js). A
   live state: full height (never sunk; sunk is pressed), filled red, a lamp
   blinking 2.5 Hz. Any button can be armed, keyed or not, so the rule is
   attribute-only. */
button[data-armed="true"] {
  --key-skirt: #7d211a;
  background: var(--red-ink); color: var(--cap); border-color: #7d211a;
  box-shadow: var(--key-shadow); transform: none;
}
button[data-armed="true"]::before {
  content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%;
  background: #ffd9d3; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
}
@media (prefers-reduced-motion: no-preference) {
  button[data-armed="true"]::before { animation: armBlink .4s step-end infinite; }
}
@keyframes armBlink { 50% { opacity: .15; } }

/* Busy: a key working on your request. Not the disabled look: full
   strength, at rest height, one legend saying what it is doing and an
   amber lens that blinks at 1 Hz (steady under reduced motion). Any button
   can be busy, keyed or not, so the rule is attribute-only. */
button[aria-busy="true"] {
  opacity: 1; cursor: progress; transform: none;
  font-family: var(--font-legend); font-size: var(--fs-legend); font-weight: 600;
  text-transform: uppercase; letter-spacing: var(--tr-legend); font-variant-numeric: tabular-nums;
}
button[aria-busy="true"]::before, .busyLed {
  content: ""; display: inline-block; flex: none; vertical-align: middle;
  width: 7px; height: 7px; margin-right: 7px; border-radius: 50%;
  background: var(--led-amber); box-shadow: var(--lens);
}
.key[aria-busy="true"]::before { margin-right: 0; } /* the key's own gap spaces it */
.key--lg[aria-busy="true"] { font-size: var(--fs-legend); }
@media (prefers-reduced-motion: no-preference) {
  button[aria-busy="true"]::before, .busyLed { animation: busyBlink 1s step-end infinite; }
}
@keyframes busyBlink { 50% { opacity: .2; } }

/* ── Switch: a checkbox that looks like a slide switch ────────────────── */
.switch {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  position: relative; width: 40px; height: 24px; border-radius: var(--r);
  background: var(--chassis-2); box-shadow: var(--well-shadow);
  border: 1px solid var(--rule-2); cursor: pointer;
  transition: background-color var(--m-hover) linear;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: var(--r-sm);
  background: var(--cap); border: 1px solid var(--rule-2);
  box-shadow: 0 1px 0 var(--rule-2);
  transition: transform var(--m-release) var(--e-spring);
}
.switch:checked { background: var(--blue); border-color: var(--blue-edge); }
.switch:checked::after { transform: translateX(16px); }
.switch:focus-visible { outline: 2px solid transparent; outline-offset: 2px; box-shadow: var(--well-shadow), var(--focus); }

/* ── Fields ───────────────────────────────────────────────────────────── */
.input {
  width: 100%; min-height: 42px; padding: 9px 12px;
  background: var(--cap); color: var(--ink);
  border: 1px solid var(--rule-2); border-radius: var(--r);
  box-shadow: var(--well-shadow);
  transition: border-color var(--t-ui) var(--ease), box-shadow var(--t-ui) var(--ease);
}
.input::placeholder { color: var(--ink-3); }
.input:focus { outline: 2px solid transparent; outline-offset: 1px; border-color: var(--ink); box-shadow: var(--well-shadow), 0 0 0 3px rgba(30,94,164,.18); }

/* ── Chips ────────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 28px; padding: 0 11px; border-radius: var(--r);
  background: var(--cap); color: var(--ink-2);
  border: 1px solid var(--rule); font-size: var(--fs-small);
}

/* ── Scrim behind every modal layer ───────────────────────────────────── */
.scrim { background: rgba(28,28,30,.42); }

/* ── Motion ───────────────────────────────────────────────────────────── */
/* Lamps switch, they never fade. */
.led, .busyLed { transition: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important; animation: none !important; scroll-behavior: auto !important;
  }
}

/* ── Forced colours (Windows High Contrast) ─────────────────────────────
   Every page sheet draws its focus ring with box-shadow, which forced-colours
   mode removes, and several still set `outline: none`. One rule restores a
   real outline in the user's Highlight colour for all of them. The cardiac
   monitor's glass is left to its own sheet. */
/* The monitor glass is the one dark surface: an ink ring there is ~1.1:1, and
   the monitor now takes focus when it opens. A light ring, focus state only —
   the monitor's resting computed styles (monitor-shots baseline) are untouched. */
#monitorOverlay .monitorCard :focus-visible { outline: 2px solid var(--screen-ink); outline-offset: 2px; }
@media (forced-colors: active) {
  :focus-visible:not(.monitorCard *) { outline: 3px solid Highlight !important; outline-offset: 2px !important; }
}

/* Screen-reader-only text: present to assistive tech, off the glass. */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
