/* ECG Beat Classifier, demo page. Light and minimal: white page, thin lines, small type.
   Colour is reserved for the three classes (N grey, S orange, V blue); everything else is ink. */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --ink: #0b1c30;
  --ink-2: #4b5565;
  --ink-3: #868fa0;
  --line: #eceef2;
  --line-2: #d9dde4;

  --n: #7a8496;
  --s: #e0600f;
  --v: #1f6fb2;
  --on-s: #1f0c00;   /* letters on an S pill: white on this orange is only 3.4:1 */
  --on-v: #ffffff;
  --err: #c0262d;
  --ok: #1d7a4c;
  --warn: #b26a00;

  --scope-bg: #ffffff;
  --grid-minor: #f8f0eb;
  --grid-major: #f1e1d7;
  --trace: #0b1c30;
  --surface: #ffffff;
  --surface-2: #f2f4f7;

  --font: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r: 8px;
  --r-lg: 12px;
  --gutter: 16px;
  --gutter-w: 92px;      /* the lane names left of the strip */
  --lane-model: 48px;
  --lane-trace: 188px;
  --lane-truth: 34px;
  --lane-axis: 22px;
  --shadow: 0 12px 40px rgba(11, 28, 48, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --bg-soft: #151c25; --ink: #e7edf6; --ink-2: #b3bfd1; --ink-3: #7f8a9d;
    --line: #1f2834; --line-2: #2e3a4a;
    --n: #7f8899; --s: #e06a22; --v: #4592d6; --on-s: #1f0c00; --on-v: #07121f;
    --err: #f0656b; --ok: #4cc28a; --warn: #e2a33c;
    --scope-bg: #0f141b; --grid-minor: #18191c; --grid-major: #262321; --trace: #e7edf6;
    --surface: #151c25; --surface-2: #1b2430;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --bg-soft: #151c25; --ink: #e7edf6; --ink-2: #b3bfd1; --ink-3: #7f8a9d;
  --line: #1f2834; --line-2: #2e3a4a;
  --n: #7f8899; --s: #e06a22; --v: #4592d6; --on-s: #1f0c00; --on-v: #07121f;
  --err: #f0656b; --ok: #4cc28a; --warn: #e2a33c;
  --scope-bg: #0f141b; --grid-minor: #18191c; --grid-major: #262321; --trace: #e7edf6;
  --surface: #151c25; --surface-2: #1b2430;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
a { color: inherit; text-underline-offset: 3px; }
button, input, textarea { font: inherit; color: inherit; }
svg { display: block; }
b { font-weight: 600; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 0.92em; }
.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 var(--gutter); }
@media (min-width: 720px) { :root { --gutter: 28px; } }
@media (max-width: 560px) { :root { --gutter-w: 74px; --lane-trace: 160px; } }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.noscript { padding: 12px var(--gutter); }
.hint { font-size: 0.8rem; color: var(--ink-3); }
.label { font-size: 0.8rem; font-weight: 500; color: var(--ink-3); }
.ink-n { color: var(--ink-2); font-weight: 600; }
.ink-s { color: var(--s); font-weight: 600; }
.ink-v { color: var(--v); font-weight: 600; }

/* ---------- Top bar ---------- */
.topbar { border-bottom: 1px solid var(--line); }
.topbar__inner { height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.brand__mark { width: 24px; height: 24px; flex: none; }
.brand__mark rect { fill: var(--ink); }
.brand__mark path { fill: none; stroke: var(--bg); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.topbar__nav { display: flex; align-items: center; gap: 2px; }
.lang { display: inline-flex; margin-left: 8px; border: 1px solid var(--line-2); border-radius: 999px; padding: 2px; }
.lang button { border: 0; background: none; padding: 3px 8px; border-radius: 999px; font: 600 0.72rem/1.2 var(--mono); color: var(--ink-3); cursor: pointer; }
.lang button[aria-current="true"] { background: var(--ink); color: var(--bg); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.link-button { border: 0; background: none; padding: 7px 10px; border-radius: var(--r); color: var(--ink-2); font-weight: 500; cursor: pointer; white-space: nowrap; }
.link-button:hover { background: var(--bg-soft); color: var(--ink); }
@media (max-width: 420px) { .link-button { padding: 7px 7px; font-size: 0.9rem; } }
/* on phones the mark stands for the name, so the two buttons and EN / IT fit (the name stays for screen readers) */
@media (max-width: 480px) { .brand__name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } }

/* ---------- Buttons and inputs ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: var(--r);
  border: 1px solid var(--line-2); background: var(--bg); color: var(--ink);
  font-weight: 500; font-size: 0.9rem; cursor: pointer; white-space: nowrap;
}
.button:hover:not(:disabled) { background: var(--bg-soft); }
.button:disabled { cursor: default; opacity: 0.5; }
.button--primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.button--primary:hover:not(:disabled) { background: var(--ink); filter: brightness(1.2); }
.button--primary svg { width: 13px; height: 13px; fill: currentColor; }
.button--primary.is-done { background: var(--bg); color: var(--ink-2); border-color: var(--line-2); opacity: 1; }
.button--icon { width: 36px; padding: 0; flex: none; }
.button--icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.button[aria-expanded="true"] { background: var(--bg-soft); border-color: var(--ink-3); }
.spinner { width: 13px; height: 13px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.range { flex: 1; min-width: 0; height: 24px; margin: 0; background: transparent; cursor: pointer; -webkit-appearance: none; appearance: none; --thumb-w: 18px; }
.range::-webkit-slider-runnable-track { height: 4px; border-radius: 999px; background: var(--line-2); }
.range::-moz-range-track { height: 4px; border-radius: 999px; background: var(--line-2); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: var(--thumb-w); height: 14px; margin-top: -5px; border-radius: 4px; background: var(--ink); border: 0; }
.range::-moz-range-thumb { width: var(--thumb-w); height: 14px; border-radius: 4px; background: var(--ink); border: 0; }
.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--ink); outline-offset: 2px; }
.range:focus-visible::-moz-range-thumb { outline: 2px solid var(--ink); outline-offset: 2px; }

.segmented { display: flex; align-items: center; gap: 0; border: 0; margin: 0; padding: 0; min-width: 0; }
.segmented legend { float: left; margin-right: 8px; padding: 0; font-size: 0.8rem; color: var(--ink-3); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: inline-grid; place-items: center; height: 28px; padding: 0 9px; border: 1px solid var(--line-2); margin-left: -1px; font: 500 0.75rem/1 var(--mono); color: var(--ink-2); background: var(--bg); }
.segmented label:first-of-type span { border-radius: 6px 0 0 6px; margin-left: 0; }
.segmented label:last-of-type span { border-radius: 0 6px 6px 0; }
.segmented input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); position: relative; z-index: 1; }
.segmented input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; position: relative; z-index: 2; }

/* ---------- App ---------- */
.app { padding-top: 24px; padding-bottom: 40px; }
.intro { grid-area: intro; color: var(--ink-2); max-width: 66ch; margin: 0; }

.layout {
  display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px 36px; align-items: start;
  grid-template-areas: "side intro" "side stage";
}
.recordings { grid-area: side; }
.stage { grid-area: stage; display: grid; gap: 20px; min-width: 0; }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 20px; grid-template-areas: "intro" "side" "stage"; }
}

/* Recordings: a list on the left, cards in a row on narrow screens */
.recordings { position: sticky; top: 16px; display: grid; gap: 4px; }
.recordings__title { font-size: 0.95rem; }
.rec-list { display: grid; gap: 8px; margin-top: 10px; }
@media (max-width: 900px) {
  .recordings { position: static; }
  .rec-list { grid-auto-flow: column; grid-auto-columns: minmax(200px, 1fr); overflow-x: auto; scrollbar-width: none; margin: 8px calc(-1 * var(--gutter)) 0; padding: 2px var(--gutter) 4px; scroll-snap-type: x mandatory; }
  .rec { scroll-snap-align: start; }
}
.rec {
  display: grid; gap: 6px; width: 100%; text-align: left; cursor: pointer;
  padding: 12px 14px; border-radius: var(--r-lg); border: 1px solid var(--line-2); background: var(--bg);
}
.rec:hover { border-color: var(--ink-3); }
.rec[aria-checked="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: var(--bg-soft); }
.rec__title { font-weight: 600; font-size: 0.95rem; line-height: 1.3; }
.rec__where { font: 400 0.72rem/1.3 var(--mono); color: var(--ink-3); }
.rec__bar { display: flex; gap: 2px; height: 6px; margin-top: 2px; }
.rec__bar span { border-radius: 2px; min-width: 3px; }
.rec__counts { display: flex; gap: 10px; flex-wrap: wrap; font: 400 0.7rem/1.2 var(--mono); color: var(--ink-2); }
.rec__counts i { display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: 4px; }

.stage__head { display: grid; gap: 4px; }
.stage__title { font-size: 1.3rem; font-weight: 600; letter-spacing: -0.015em; }
.stage__about { font-size: 0.875rem; color: var(--ink-3); max-width: 78ch; }
.stage__about b { color: var(--ink-2); font-weight: 500; }

/* ---------- Viewer ---------- */
.viewer { display: grid; gap: 10px; min-width: 0; }
.viewer__head { display: flex; justify-content: space-between; align-items: center; gap: 10px 16px; flex-wrap: wrap; }
.viewer__where { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; font-size: 0.875rem; }
.viewer__facts { color: var(--ink-3); font-size: 0.8rem; }
.run { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.run__status { display: inline-flex; align-items: center; gap: 7px; font-size: 0.8rem; color: var(--ink-3); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex: none; }
.run__status[data-state="ok"] .dot { background: var(--ok); }
.run__status[data-state="waking"] .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.run__status[data-state="error"] .dot { background: var(--err); }
@keyframes pulse { 50% { opacity: 0.3; } }

/* The strip: lane names on the left, a horizontally scrolling paper on the right */
.strip {
  position: relative; display: grid; grid-template-columns: var(--gutter-w) minmax(0, 1fr);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  height: calc(var(--lane-model) + var(--lane-trace) + var(--lane-truth) + var(--lane-axis));
}
.strip__gutter { display: grid; grid-template-rows: var(--lane-model) var(--lane-trace) var(--lane-truth) var(--lane-axis); border-right: 1px solid var(--line); }
.lane-name { display: flex; flex-direction: column; justify-content: center; padding-right: 10px; font-size: 0.8rem; font-weight: 600; line-height: 1.2; }
.lane-name small { font-weight: 400; color: var(--ink-3); font-size: 0.72rem; }
.lane-name--ecg { color: var(--ink-3); font-weight: 500; }
.lane-name--truth { background: var(--bg-soft); padding-left: 0; }
.strip__scroll { position: relative; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.strip__placeholder {
  position: absolute; left: var(--gutter-w); right: 0; top: 0; height: var(--lane-model);
  display: flex; align-items: center; padding: 0 16px; font-size: 0.85rem; color: var(--ink-3); pointer-events: none;
}
.strip__placeholder b { color: var(--ink-2); font-weight: 600; }
.strip__overlay {
  position: absolute; left: var(--gutter-w); right: 0; top: 0; bottom: 0; z-index: 6;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 16px; text-align: center;
  background: color-mix(in srgb, var(--bg) 86%, transparent); color: var(--ink-2); font-size: 0.9rem;
}
.strip__message { max-width: 34rem; }
.strip__overlay[data-kind="loading"] .strip__message::before,
.strip__overlay[data-kind="waking"] .strip__message::before {
  content: ""; display: block; width: 18px; height: 18px; margin: 0 auto 10px; border-radius: 50%;
  border: 2px solid var(--line-2); border-top-color: var(--ink); animation: spin 0.9s linear infinite;
}

.paper { position: relative; height: 100%; }
.paper__lane-model { position: absolute; left: 0; right: 0; top: 0; height: var(--lane-model); border-bottom: 1px solid var(--line); }
.paper__grid { position: absolute; left: 0; right: 0; top: var(--lane-model); height: var(--lane-trace); pointer-events: none; }
.paper__trace { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.paper__trace path { fill: none; stroke: var(--trace); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.paper__lane-truth { position: absolute; left: 0; right: 0; top: calc(var(--lane-model) + var(--lane-trace)); height: var(--lane-truth); background: var(--bg-soft); border-top: 1px solid var(--line); }
.paper__axis { position: absolute; left: 0; right: 0; bottom: 0; height: var(--lane-axis); border-top: 1px solid var(--line); }
.tick { position: absolute; bottom: 4px; transform: translateX(-50%); font: 400 0.68rem/1 var(--mono); color: var(--ink-3); white-space: nowrap; }
.paper { cursor: pointer; }
.hover-band { position: absolute; z-index: 1; top: 0; bottom: var(--lane-axis); background: color-mix(in srgb, var(--ink) 3.5%, transparent); border-left: 1px dashed var(--line-2); border-right: 1px dashed var(--line-2); pointer-events: none; }
.strip__scroll:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; border-radius: 0; }
.band { position: absolute; z-index: 1; top: 0; bottom: var(--lane-axis); background: color-mix(in srgb, var(--ink) 6%, transparent); pointer-events: none; }
.scan { position: absolute; top: var(--lane-model); height: var(--lane-trace); width: 80px; pointer-events: none; z-index: 3;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--ink) 8%, transparent) 75%, color-mix(in srgb, var(--ink) 35%, transparent) 98%, transparent); }

/* Model lane: one filled pill per beat */
.pill {
  position: absolute; top: calc((var(--lane-model) - 24px) / 2); transform: translateX(-50%); z-index: 2;
  display: grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 999px;
  border: 0; font: 700 0.72rem/1 var(--mono); cursor: pointer; color: #fff; background: var(--n);
}
.pill--N { background: var(--bg); color: var(--ink-2); box-shadow: inset 0 0 0 1.5px var(--n); }
.pill--S { background: var(--s); color: var(--on-s); }
.pill--V { background: var(--v); color: var(--on-v); }
.pill--none { background: var(--bg); color: var(--ink-3); outline: 1.5px dashed var(--ink-3); outline-offset: -1.5px; }
.pill--mismatch { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--err); }
.pill--N.pill--mismatch { box-shadow: inset 0 0 0 1.5px var(--n), 0 0 0 2px var(--bg), 0 0 0 3.5px var(--err); }
.pill[aria-pressed="true"] { transform: translateX(-50%) scale(1.18); }
.pill[aria-pressed="true"]::after { content: ""; position: absolute; bottom: -9px; left: 50%; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--ink); }
.pill:hover { transform: translateX(-50%) scale(1.1); }
.pill:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.strip.is-revealing .pill { animation: pop 0.3s cubic-bezier(.2, .9, .3, 1.3) both; animation-delay: var(--d, 0ms); }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) translateY(8px) scale(0.6); } to { opacity: 1; transform: translateX(-50%); } }

/* Annotation lane: small letters, coloured by class, never filled */
.truth { position: absolute; top: calc((var(--lane-truth) - 18px) / 2); transform: translateX(-50%); min-width: 18px; height: 18px; padding: 0 3px; text-align: center; font: 600 0.72rem/18px var(--mono); color: var(--ink-3); border-radius: 4px; }
.truth--S { color: var(--s); }
.truth--V { color: var(--v); }
.truth--other { font-weight: 400; font-style: italic; }
.truth--mismatch { box-shadow: inset 0 0 0 1.5px var(--err); }

.controls { display: flex; justify-content: space-between; align-items: center; gap: 10px 24px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 8px; flex: 1 1 280px; min-width: 0; max-width: 520px; }
.options { display: flex; gap: 18px; flex-wrap: wrap; }

.tooltip { position: fixed; z-index: 60; pointer-events: none; padding: 8px 10px; border-radius: 6px; background: var(--ink); color: var(--bg); font-size: 0.78rem; line-height: 1.45; box-shadow: var(--shadow); max-width: 240px; }
.tooltip .num { font-size: 0.76rem; }

/* ---------- Outcome of a run ---------- */
.outcome { display: grid; gap: 12px; padding-top: 4px; }
.outcome__line { font-size: 0.95rem; }
.outcome__counts { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.85rem; color: var(--ink-2); }
.count { display: inline-flex; align-items: center; gap: 7px; }
.count .num { color: var(--ink); font-weight: 600; }
.outcome__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.disagreements { display: flex; flex-wrap: wrap; gap: 6px; }
.flag { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--err) 45%, var(--line-2)); background: var(--bg); font: 500 0.75rem/1 var(--mono); cursor: pointer; }
.flag:hover { background: var(--bg-soft); }

.mark { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px; font: 700 0.65rem/1 var(--mono); color: #fff; flex: none; }
.mark--N { background: var(--bg); color: var(--ink-2); box-shadow: inset 0 0 0 1.5px var(--n); }
.mark--S { background: var(--s); color: var(--on-s); }
.mark--V { background: var(--v); color: var(--on-v); }
.mark--none { background: var(--bg); color: var(--ink-3); outline: 1.5px dashed var(--ink-3); outline-offset: -1.5px; }

/* ---------- Explanation of one beat ---------- */
.explain { border-top: 1px solid var(--line); padding-top: 20px; display: grid; gap: 14px; }
.explain__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.explain__head .hint { margin-top: 3px; }
.verdict { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.85rem; }
.verdict__item { display: inline-flex; align-items: center; gap: 7px; padding: 4px 10px 4px 5px; border-radius: 999px; background: var(--bg-soft); }
.verdict__outcome { font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.verdict__outcome--ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 11%, transparent); }
.verdict__outcome--err { color: var(--err); background: color-mix(in srgb, var(--err) 11%, transparent); }
.verdict__outcome--na { color: var(--ink-2); background: var(--bg-soft); }
.explain__body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px 28px; }
.explain__body.is-loading { opacity: 0.5; transition: opacity 0.2s 0.15s; }
@media (max-width: 760px) { .explain__body { grid-template-columns: minmax(0, 1fr); } }
.placeholder { color: var(--ink-3); grid-column: 1 / -1; font-size: 0.9rem; }
.block { min-width: 0; }
.block--shape { grid-column: 1 / -1; }
.block__lead { color: var(--ink-3); font-size: 0.8rem; margin-top: 3px; }
.block__chart { margin-top: 8px; position: relative; min-height: 250px; }
.block__chart svg { display: block; overflow: visible; }
.block__note { margin-top: 6px; font-size: 0.8rem; color: var(--ink-3); }
.readout { position: absolute; top: 0; right: 0; font: 400 0.7rem/1.35 var(--mono); color: var(--ink-2); background: color-mix(in srgb, var(--bg) 90%, transparent); padding: 2px 4px; border-radius: 4px; pointer-events: none; text-align: right; }

.svg-ink { stroke: var(--trace); }
.svg-template { stroke: var(--ink-3); stroke-dasharray: 4 3; }
.svg-axis { stroke: var(--line-2); }
.svg-grid { stroke: var(--line); }
.svg-text { fill: var(--ink-3); font: 400 11px var(--mono); }
.svg-label { fill: var(--ink-2); font: 500 12px var(--font); }

.rr-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 10px; }
.rr-item { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; align-items: baseline; }
.rr-item__name { font-size: 0.85rem; font-weight: 500; }
.rr-item__value { font: 600 0.82rem/1 var(--mono); }
.rr-scale { grid-column: 1 / -1; position: relative; height: 18px; margin: 0 6px; }
.rr-scale::before { content: ""; position: absolute; left: 0; right: 0; top: 8px; height: 2px; border-radius: 1px; background: var(--line-2); }
.rr-scale__ref { position: absolute; top: 3px; width: 1.5px; height: 12px; margin-left: -0.75px; background: var(--ink-3); }
.rr-scale__seg { position: absolute; top: 8px; height: 2px; background: var(--ink); }
.rr-scale__dot { position: absolute; top: 4px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--ink); }
.rr-scale__dot--over { background: var(--bg); box-shadow: inset 0 0 0 2px var(--ink); }
.rr-item__text { grid-column: 1 / -1; font-size: 0.78rem; color: var(--ink-3); }

.decision { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.decision__step { border-radius: var(--r); padding: 10px 12px; background: var(--bg-soft); }
.decision__step--skipped { background: none; border: 1px dashed var(--line-2); color: var(--ink-3); }
.decision__q { display: flex; justify-content: space-between; gap: 8px; font-size: 0.85rem; font-weight: 500; }
.decision__p { font: 600 0.82rem/1.2 var(--mono); }
.prob { position: relative; height: 8px; margin: 8px 0 6px; border-radius: 999px; background: var(--bg); box-shadow: inset 0 0 0 1px var(--line-2); }
.prob__fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; min-width: 4px; }
.prob__cut { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); border-radius: 1px; }
.decision__a { font-size: 0.78rem; color: var(--ink-2); }
.decision__final { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.9rem; padding: 4px 2px 0; }
.chart__legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 6px 0 0; padding: 0; list-style: none; font-size: 0.78rem; color: var(--ink-2); }
.chart__legend li { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Footer ---------- */
.footer { padding-top: 16px; padding-bottom: 28px; border-top: 1px solid var(--line); font-size: 0.78rem; color: var(--ink-3); display: grid; gap: 4px; }
.footer b { color: var(--ink-2); font-weight: 600; }

/* ---------- Ask (chat): a launcher in the corner and a panel; the replies come from /api/chat ---------- */
.chat-icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; flex: none; }
.chat-launcher {
  position: fixed; right: 20px; bottom: 20px; z-index: 30;
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px; border-radius: 999px;
  border: 0; background: var(--ink); color: var(--bg); font-weight: 600; font-size: 0.9rem; cursor: pointer; box-shadow: var(--shadow);
}
.chat-launcher:hover { filter: brightness(1.2); }
.chat-launcher[aria-expanded="true"] { display: none; }
@media (max-width: 560px) { .chat-launcher span { display: none; } .chat-launcher { width: 48px; height: 48px; padding: 0; justify-content: center; right: 14px; bottom: 14px; } }
.chat {
  position: fixed; right: 20px; bottom: 20px; z-index: 31; width: min(400px, calc(100vw - 40px)); height: min(600px, calc(100dvh - 40px));
  display: flex; flex-direction: column; background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden;
}
.chat[hidden] { display: none; }
@media (max-width: 560px) { .chat { right: 0; bottom: 0; width: 100vw; height: 100dvh; border-radius: 0; border: 0; } }
.chat__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 14px 14px 10px 16px; border-bottom: 1px solid var(--line); }
.chat__head h2 { font-size: 1rem; }
.chat__context { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 14px 0; padding: 8px 10px; border-radius: var(--r); background: var(--bg-soft); font-size: 0.8rem; color: var(--ink-2); }
.chat__context button { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 1rem; line-height: 1; padding: 2px 4px; }
.chat__log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: 0.875rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg--user { align-self: flex-end; background: var(--ink); color: var(--bg); border-bottom-right-radius: 4px; }
.msg--bot { align-self: flex-start; background: var(--bg-soft); border-bottom-left-radius: 4px; }
.msg--note { align-self: center; max-width: 100%; background: none; color: var(--ink-3); font-size: 0.8rem; text-align: center; }
.msg--typing { color: var(--ink-3); }
.chat__suggestions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
.chat__suggestions button { border: 1px solid var(--line-2); background: var(--bg); color: var(--ink-2); border-radius: 999px; padding: 5px 10px; font-size: 0.78rem; cursor: pointer; text-align: left; }
.chat__suggestions button:hover { border-color: var(--ink-3); color: var(--ink); }
.chat__form { display: flex; gap: 8px; align-items: flex-end; padding: 10px 14px 6px; border-top: 1px solid var(--line); }
.chat__form textarea { flex: 1; resize: none; min-height: 40px; max-height: 120px; padding: 9px 10px; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--bg); font-size: 0.875rem; line-height: 1.4; }
.chat__form textarea:focus-visible { outline: 2px solid var(--ink); outline-offset: 0; }
.chat__note { padding: 0 14px 12px; font-size: 0.72rem; }
.explain__actions { display: flex; gap: 8px; align-items: center; }
/* on phones the title and its hint keep the full width; the buttons go under them, × on the right */
@media (max-width: 560px) { .explain__head { flex-wrap: wrap; } .explain__head > :first-child { flex: 1 1 100%; } .explain__actions { flex: 1 1 100%; } .explain__actions > :last-child { margin-left: auto; } }

/* ---------- Drawers (How it works, Results) ---------- */
.drawer {
  position: fixed; inset: 0 0 0 auto; margin: 0 0 0 auto; padding: 0; border: 0;
  width: min(780px, 100vw); height: 100dvh; max-height: none; max-width: 100vw;
  background: var(--bg); color: var(--ink); box-shadow: var(--shadow); overflow: hidden;
}
.drawer[open] { display: flex; flex-direction: column; animation: slide-in 0.24s cubic-bezier(.2, .8, .2, 1); }
.drawer::backdrop { background: rgba(11, 28, 48, 0.28); }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px var(--gutter) 14px 24px; border-bottom: 1px solid var(--line); }
@media (max-width: 560px) { .drawer__head { padding-left: var(--gutter); } }
.drawer--wide { width: min(1180px, 100vw); }
.drawer__body { flex: 1; overflow-y: auto; padding: 0 24px; display: grid; gap: 18px; align-content: start; }
@media (max-width: 560px) { .drawer__body { padding: 0 var(--gutter); } }
.drawer__intro { margin-top: 18px; max-width: 76ch; }
/* The tab bar and the Previous/Next buttons stay in view however long a step is */
.drawer__body > .tabs { position: sticky; top: 0; z-index: 4; background: var(--bg); padding-top: 6px; }
.drawer__pager { position: sticky; bottom: 0; z-index: 4; background: var(--bg); border-top: 1px solid var(--line); padding: 12px 0 16px; margin-top: 4px; }
.drawer__body > .result:last-child, .drawer__body > .result { padding-bottom: 24px; }
.drawer__intro { color: var(--ink-2); font-size: 0.9rem; }
.drawer__pager { display: flex; justify-content: space-between; gap: 8px; }

.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); }   /* wraps, never scrolls: a scrolling bar gets squeezed in a tall step */
.tabs [role="tab"] {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px 9px; border: 0; background: none; cursor: pointer;
  color: var(--ink-3); font-size: 0.85rem; font-weight: 500; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs [role="tab"]:hover { color: var(--ink); }
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs .num { font-size: 0.72rem; color: var(--ink-3); }

.step { display: grid; gap: 10px; width: 100%; max-width: 820px; justify-self: center; }
.step--wide { max-width: none; }

/* Step 6: the architecture diagram next to the animation of one beat going through it */
.inside { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.95fr); gap: 24px; align-items: start; }
@media (max-width: 900px) { .inside { grid-template-columns: minmax(0, 1fr); } .inside .loop { order: -1; } }
.arch { display: grid; gap: 10px; }
.arch__note { min-height: 4.6em; overflow: hidden; padding: 10px 12px; border-radius: var(--r); background: var(--bg-soft); font-size: 0.85rem; color: var(--ink-2); }
.arch__note b { color: var(--ink); }
.arch__graphs { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
@media (max-width: 560px) { .arch__graphs { grid-template-columns: minmax(0, 1fr); } }
.arch__graph svg { display: block; width: 100%; height: auto; overflow: visible; }
.arch__graph--enc { border: 1px dashed var(--line-2); border-radius: var(--r-lg); padding: 6px; }
.arch__graph--enc.is-on { border: 1px solid var(--ink); }
.arch-node rect { fill: var(--bg); stroke: var(--line-2); stroke-width: 1.2; transition: fill 0.2s, stroke 0.2s; }
.arch-node--input rect { fill: var(--bg-soft); }
.arch-node--op rect { stroke-dasharray: 3 3; }
.arch-node.is-on rect { fill: var(--bg-soft); stroke: var(--ink); stroke-width: 2; }
.arch-node:focus { outline: none; }
.arch-node:focus-visible rect, .arch-node:hover rect { stroke: var(--ink); }
.arch-node text { fill: var(--ink); font: 600 12px var(--font); }
.arch-node .arch-sub { fill: var(--ink-3); font: 400 10.5px var(--font); }
.arch-edge { fill: none; stroke: var(--ink-3); stroke-width: 1.3; }
.arch-edge.is-on { stroke: var(--ink); stroke-width: 2; }
.arch-edge--skip { stroke-dasharray: 4 3; }
.arch-shape { fill: var(--ink-3); font: 400 10px var(--mono); }
.arch-title { fill: var(--ink-2); font: 600 11.5px var(--font); }
.arch-arrow { fill: var(--ink-3); }
.step p, .result > p { color: var(--ink-2); font-size: 0.9rem; }
.step h3 { margin-top: 4px; font-size: 1rem; }

.loop { margin: 0; position: relative; }
.loop__canvas { display: block; width: 100%; aspect-ratio: 16 / 10; border-radius: var(--r-lg); background: var(--bg-soft); }
@media (max-width: 560px) { .loop__canvas { aspect-ratio: 4 / 3; } }
.loop__caption { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-top: 8px; font-size: 0.76rem; color: var(--ink-3); }
.loop__stage { position: relative; }
.loop__canvas { cursor: pointer; }
.loop__play {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px;
  border: 0; border-radius: var(--r-lg); background: color-mix(in srgb, var(--bg) 30%, transparent); cursor: pointer; color: var(--ink);
}
.loop__play-icon { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: var(--bg); box-shadow: var(--shadow); transition: transform 0.15s; }
.loop__play-icon svg { width: 22px; height: 22px; fill: currentColor; margin-left: 3px; }
.loop__play:hover .loop__play-icon { transform: scale(1.06); }
.loop__play-text { font-size: 0.8rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--bg) 85%, transparent); }
.loop__corner { position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--line-2); background: color-mix(in srgb, var(--bg) 88%, transparent); color: var(--ink); cursor: pointer; opacity: 0.75; }
.loop__corner:hover, .loop__corner:focus-visible { opacity: 1; }
.loop__corner svg { width: 12px; height: 12px; fill: currentColor; }
.loop--tall { width: 100%; max-width: 600px; justify-self: center; }
.loop--tall .loop__canvas { aspect-ratio: 5 / 6; }
@media (max-width: 560px) { .loop--tall .loop__canvas { aspect-ratio: 3 / 4; } }
.inside__bar { display: flex; justify-content: space-between; align-items: center; gap: 10px 20px; flex-wrap: wrap; }
.inside__hint { margin-top: -4px; }
.switch-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.switch-buttons--quiet button { height: 28px; font-size: 0.78rem; }
.arch--pick .arch-node { cursor: pointer; }
.dataview { display: grid; gap: 8px; align-content: start; padding: 14px; border-radius: var(--r-lg); background: var(--bg-soft); }
@media (min-width: 901px) { .dataview { position: sticky; top: 58px; } }   /* stays in view below the tab bar while the diagram scrolls */
@media (max-width: 900px) { .inside .dataview { order: -1; } }
.dataview__head { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 12px; flex-wrap: wrap; }
.dataview__title { margin: 0; font-size: 0.95rem; font-weight: 650; }
.dataview__shape { font-size: 0.75rem; color: var(--ink-3); }
.dataview__canvas { width: 100%; aspect-ratio: 4 / 3; border-radius: var(--r); background: var(--bg); display: block; }
.dataview__caption { font-size: 0.85rem; color: var(--ink-2); min-height: 4.5em; }
.dataview__nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.switch-buttons button { height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--bg); color: var(--ink-2); font-size: 0.82rem; font-weight: 500; cursor: pointer; }
.switch-buttons button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.result { display: grid; gap: 14px; }
.chart { margin: 0; min-width: 0; position: relative; }
.chart__title { font-weight: 600; font-size: 0.88rem; }
.chart__sub { color: var(--ink-3); font-size: 0.78rem; margin-top: 2px; }
.chart__svg { width: 100%; height: auto; margin-top: 8px; overflow: visible; }
.chart__panels { display: grid; gap: 8px 24px; }
.chart__panel-title { font-size: 0.82rem; font-weight: 600; margin-top: 12px; display: flex; align-items: center; gap: 8px; }
.chart details { margin-top: 10px; font-size: 0.82rem; }
.chart summary { cursor: pointer; color: var(--ink-2); width: max-content; }
.table-wrap { overflow-x: auto; margin-top: 8px; }
.data-table { border-collapse: collapse; width: 100%; font-size: 0.78rem; }
.data-table th, .data-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { font-weight: 600; color: var(--ink-2); }
.data-table td { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.limit-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 24px; }
.limit-list li { padding: 14px 0; border-top: 1px solid var(--line); }
.limit-list p { margin-top: 4px; color: var(--ink-2); font-size: 0.85rem; }

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
@media (forced-colors: active) { .pill, .mark { border: 1px solid CanvasText; } }

/* ---------- Results: all patients / without the hardest one, confusion matrices, mistakes ---------- */
.drawer--results { width: min(880px, 100vw); }
.patients-switch { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.patients-switch .label { margin-right: 2px; }
.removed { display: grid; gap: 8px; padding: 12px 14px; border-radius: var(--r-lg); background: var(--bg-soft); font-size: 0.85rem; color: var(--ink-2); }
.removed h3 { font-size: 0.9rem; color: var(--ink); }
.removed .data-table td, .removed .data-table th { white-space: normal; }
.cm-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px 20px; }
.cm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px 22px; }
.cm h3 { font-size: 0.88rem; }
.cm .hint { margin-top: 1px; }
.cm table { border-collapse: separate; border-spacing: 3px; margin-top: 8px; font-size: 0.78rem; }
.cm th { font-weight: 600; color: var(--ink-3); font-size: 0.72rem; padding: 2px 4px; text-align: center; }
.cm th[scope="row"] { text-align: right; padding-right: 6px; }
.cm td { width: 62px; height: 40px; text-align: center; border-radius: 6px; font-family: var(--mono); font-variant-numeric: tabular-nums; position: relative; }
.cm td.is-diag { box-shadow: inset 0 0 0 1.5px var(--ink); }
.cm td { color: var(--ink); }
.cm td.on-dark { color: var(--bg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cm td.on-mid { color: var(--bg); } }
:root[data-theme="dark"] .cm td.on-mid { color: var(--bg); }
.cm caption { caption-side: bottom; text-align: left; font-size: 0.72rem; color: var(--ink-3); padding-top: 4px; }
.mistakes { display: grid; gap: 12px; }
.mistake { display: grid; gap: 6px; padding: 14px; border: 1px solid var(--line-2); border-radius: var(--r-lg); }
.mistake__head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mistake__head h3 { font-size: 0.95rem; }
.mistake__where { font: 400 0.75rem/1.3 var(--mono); color: var(--ink-3); }
.mistake p { font-size: 0.875rem; color: var(--ink-2); }
.mistake .button { justify-self: start; margin-top: 4px; }
.arrow-to { color: var(--ink-3); font-size: 0.8rem; }
