/* Dipole design tokens and layout.
   One sans with character for everything, a mono for measurements, cool paper,
   a faded rose ECG grid (the one traditional reference), one cobalt accent used
   only for "electricity": active myocardium, the heart vector, and controls. */

:root {
  --paper: #f4f5f3;
  --paper-2: #eaece8;
  --paper-3: #dfe2dd;
  --ink: #1b1f23;
  --ink-2: #4a5159;
  --ink-3: #868e96;
  --line: #d6d9d4;
  --line-2: #c3c7c1;
  --accent: #2b55d6;
  --accent-2: #5d7fe6;
  --accent-soft: rgba(43, 85, 214, 0.10);
  --on-accent: #ffffff;
  --rest: #cfd3cd;          /* resting myocardium */
  --rest-3d: #c6c9c3;
  --cavity: #f7f8f6;        /* blood pool */
  --grid-minor: rgba(203, 110, 122, 0.22);
  --grid-major: rgba(203, 110, 122, 0.48);
  --trace: #1b1f23;
  --trace-dim: rgba(27, 31, 35, 0.35);
  --scar: #a9aeab;
  --warn: #b9532a;
  --ok: #2e7d4f;
  --radius: 6px;
  --shadow: 0 1px 0 rgba(27, 31, 35, 0.04), 0 8px 24px -16px rgba(27, 31, 35, 0.25);
  --sans: "Schibsted Grotesk", "Segoe UI Variable", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --display: "Geist", "Schibsted Grotesk", "Segoe UI Variable", sans-serif;
  --top-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15171a; --paper-2: #1c1f23; --paper-3: #24282d; --ink: #e8eae7; --ink-2: #aeb4b9; --ink-3: #737a81;
    --line: #2a2e33; --line-2: #383d43; --accent: #6f8ff6; --accent-2: #8aa3f8; --accent-soft: rgba(111, 143, 246, 0.14);
    --on-accent: #0e1220; --rest: #3a4046; --rest-3d: #4b5158; --cavity: #121416; --grid-minor: rgba(214, 105, 120, 0.16); --grid-major: rgba(214, 105, 120, 0.38);
    --trace: #e8eae7; --trace-dim: rgba(232, 234, 231, 0.35); --scar: #4c5157; --warn: #e0875f; --ok: #6cc08f; color-scheme: dark;
    --shadow: 0 1px 0 rgba(0,0,0,.2), 0 8px 24px -16px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  --paper: #15171a; --paper-2: #1c1f23; --paper-3: #24282d; --ink: #e8eae7; --ink-2: #aeb4b9; --ink-3: #737a81;
  --line: #2a2e33; --line-2: #383d43; --accent: #6f8ff6; --accent-2: #8aa3f8; --accent-soft: rgba(111, 143, 246, 0.14);
  --on-accent: #0e1220; --rest: #3a4046; --rest-3d: #4b5158; --cavity: #121416; --grid-minor: rgba(214, 105, 120, 0.16); --grid-major: rgba(214, 105, 120, 0.38);
  --trace: #e8eae7; --trace-dim: rgba(232, 234, 231, 0.35); --scar: #4c5157; --warn: #e0875f; --ok: #6cc08f; color-scheme: dark;
  --shadow: 0 1px 0 rgba(0,0,0,.2), 0 8px 24px -16px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---- top bar ------------------------------------------------------------- */
.top { height: var(--top-h); display: flex; align-items: center; gap: 28px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--paper); position: sticky; top: 0; z-index: 30; }
.wordmark { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 700; font-size: 20px; letter-spacing: -0.04em; }
.wordmark .mark { width: 34px; height: 20px; color: var(--accent); }
.nav { display: flex; gap: 2px; }
.nav a { padding: 7px 12px; border-radius: var(--radius); color: var(--ink-2); font-weight: 500; }
.nav a:hover { color: var(--ink); background: var(--paper-2); }
.nav a.active { color: var(--ink); background: var(--paper-3); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.depth { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; }
.depth button { padding: 6px 11px; font-size: 13px; color: var(--ink-2); border-right: 1px solid var(--line-2); }
.depth button:last-child { border-right: 0; }
.depth button:hover { background: var(--paper-2); color: var(--ink); }
.depth button.on { background: var(--ink); color: var(--paper); }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: var(--radius); color: var(--ink-2); }
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }

main { min-height: calc(100vh - var(--top-h)); }

/* ---- generic controls ---------------------------------------------------- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--paper); color: var(--ink); font-weight: 500; font-size: 14px; line-height: 1; white-space: nowrap; }
.btn:hover { background: var(--paper-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.quiet { border-color: transparent; color: var(--ink-2); }
.btn.quiet:hover { color: var(--ink); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; }
.seg button { padding: 6px 10px; font-size: 13px; color: var(--ink-2); border-right: 1px solid var(--line-2); min-width: 36px; }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--paper-2); color: var(--ink); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
select.select { appearance: none; -webkit-appearance: none; padding: 8px 32px 8px 12px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--paper) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%23868e96' stroke-width='1.6'/></svg>") no-repeat right 11px center; font-weight: 500; max-width: 100%; }
select.select:hover { background-color: var(--paper-2); }
.range { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; font-size: 13px; }
.range label { color: var(--ink-2); grid-column: 1; }
.range output { grid-column: 2; font-family: var(--mono); font-size: 12px; color: var(--ink); min-width: 56px; text-align: right; }
.range input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); margin: 2px 0 8px; height: 22px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line-2); font-size: 12px; color: var(--ink-2); line-height: 1.4; }
.chip.accent { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.chip.warn { border-color: transparent; background: rgba(185, 83, 42, 0.12); color: var(--warn); }
.chip.ok { border-color: transparent; background: rgba(46, 125, 79, 0.12); color: var(--ok); }
.kbd { font-family: var(--mono); font-size: 11.5px; padding: 1px 6px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; color: var(--ink-2); }
hr.rule { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 9px 14px; border-radius: var(--radius); font-size: 13.5px; box-shadow: var(--shadow); z-index: 50; }

/* ---- explore layout ------------------------------------------------------ */
.explore { display: grid; grid-template-columns: minmax(0, 1fr) 380px; height: calc(100vh - var(--top-h)); min-height: 560px; }
.stage { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; border-right: 1px solid var(--line); }
.stage-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.stage-head .grow { flex: 1; }
.stage-body { display: grid; grid-template-columns: minmax(320px, 46%) minmax(0, 1fr); min-height: 0; }
.heart-pane { position: relative; border-right: 1px solid var(--line); background: var(--paper); min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.heart-pane svg.heart { width: 100%; height: 100%; display: block; }
.heart-foot { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.heart-foot .sp { flex: 1; }
/* the vector readout is rewritten while playing: fixed width, tabular digits, no reflow */
#vec-readout { display: inline-block; min-width: 30ch; white-space: pre; font-variant-numeric: tabular-nums; }
.ecg-pane { position: relative; min-width: 0; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; background: var(--paper); }
.ecg-pane canvas { display: block; width: 100%; height: 100%; }
.ecg-wrap { position: relative; min-height: 0; overflow: hidden; }
.ecg-foot { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.transport { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--paper); }
.transport .tl { position: relative; height: 54px; border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; background: var(--paper); cursor: ew-resize; }
.transport .tl canvas { width: 100%; height: 100%; display: block; }
.transport .clock { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); min-width: 86px; text-align: right; }
.play { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }
.play:hover { background: var(--accent-2); }
.panel { overflow-y: auto; padding: 18px 20px 40px; min-height: 0; }
.panel h2 { font-size: 18px; margin-bottom: 2px; }
.panel .lead-in { color: var(--ink-2); margin-bottom: 14px; font-size: 14px; }
.now { border: 1px solid var(--line-2); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 10px 12px; margin: 0 0 16px; background: var(--paper-2); min-height: 92px; }
.now .phase { font-family: var(--mono); font-size: 11.5px; letter-spacing: .04em; color: var(--accent); text-transform: uppercase; margin-bottom: 4px; }
.now .what { font-size: 14px; line-height: 1.45; }
.now .what b { font-weight: 600; }
.sec { margin: 14px 0; }
.sec h3 { font-size: 13px; color: var(--ink-3); font-weight: 600; margin-bottom: 6px; }
.sec p, .sec li { font-size: 14px; }
.sec ul { margin: 0; padding-left: 18px; }
.sec li { margin-bottom: 4px; }
.vital { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0 16px; }
.vital div { border-top: 1px solid var(--line-2); padding-top: 6px; }
.vital .k { font-size: 11.5px; color: var(--ink-3); }
.vital .v { font-family: var(--mono); font-size: 15px; }
.vital .v.bad { color: var(--warn); }
.params { display: grid; gap: 4px; margin-top: 8px; }
.depth-inline { display: none; margin-bottom: 12px; }
@media (max-width: 640px) { .depth-inline { display: inline-flex; } }
.details { border-top: 1px solid var(--line); }
.details summary { cursor: pointer; padding: 10px 0; font-weight: 600; font-size: 14px; list-style: none; display: flex; align-items: center; gap: 8px; }
.details summary::-webkit-details-marker { display: none; }
.details summary::after { content: ""; width: 7px; height: 7px; border-right: 1.6px solid var(--ink-3); border-bottom: 1.6px solid var(--ink-3); transform: rotate(45deg); margin-left: auto; transition: transform .2s; }
.details[open] summary::after { transform: rotate(-135deg); }
.details .inner { padding: 0 0 12px; }

/* heart svg styling */
.heart .wall { fill: var(--rest); stroke: var(--paper); stroke-width: 1.2; transition: none; }
.heart .cavity { fill: var(--cavity); stroke: none; }
.heart .outline { fill: none; stroke: var(--line-2); stroke-width: 1.2; }
.heart .cond { fill: none; stroke: var(--ink-3); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.heart .cond.lit { stroke: var(--accent); }
.heart .cond.blocked { stroke-dasharray: 3 5; opacity: .5; }
.heart .node { fill: var(--ink-3); }
.heart .node.lit { fill: var(--accent); }
.heart .label { font-family: var(--mono); font-size: 11px; fill: var(--ink-3); }
.heart .label.big { font-family: var(--sans); font-size: 12px; fill: var(--ink-2); font-weight: 500; }
.heart .axis-line { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 2 4; opacity: .55; }
.heart .axis-line.sel { stroke: var(--ink); stroke-dasharray: none; stroke-width: 1.3; }
.heart .proj { stroke: var(--accent); stroke-width: 5; stroke-linecap: round; opacity: .85; }
.heart .proj-drop { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; opacity: .7; }
.heart .vec { stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }
.heart .vec-head { fill: var(--accent); }
.heart .loop { fill: none; stroke: var(--accent); stroke-width: 1.2; opacity: .45; }
.heart .torso { fill: var(--paper-2); stroke: var(--line-2); stroke-width: 1.2; }
.heart .electrode { fill: var(--paper); stroke: var(--ink-2); stroke-width: 1.4; }
.heart .electrode.sel { fill: var(--accent); stroke: var(--accent); }
.heart .elabel { font-family: var(--mono); font-size: 11.5px; fill: var(--ink-2); font-weight: 500; }
.heart .elabel.sel { fill: var(--accent); }
.heart .x-mark { stroke: var(--warn); stroke-width: 2.2; stroke-linecap: round; }
.heart .hatch { fill: url(#hatch); }

/* ---- pages --------------------------------------------------------------- */
.page { max-width: 1120px; margin: 0 auto; padding: 36px 24px 80px; }
.page-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; align-items: end; margin-bottom: 28px; }
.page-head p { color: var(--ink-2); max-width: 62ch; margin: 8px 0 0; font-size: 16px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card { border: 1px solid var(--line-2); border-radius: var(--radius); padding: 16px 16px 14px; background: var(--paper); display: flex; flex-direction: column; gap: 8px; min-height: 150px; text-align: left; transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--ink-3); }
.card:active { transform: translateY(1px); }
.card h3 { font-size: 16px; }
.card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.card .desc { color: var(--ink-2); font-size: 13.5px; }
.card .thumb { height: 54px; width: 100%; display: block; }
.group-h { margin: 30px 0 12px; display: flex; align-items: baseline; gap: 12px; }
.group-h h2 { font-size: 18px; }
.group-h span { color: var(--ink-3); font-size: 13px; }
.lesson-list { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 32px; }
.lesson-list nav { position: sticky; top: calc(var(--top-h) + 20px); align-self: start; }
.lesson-list nav .tier { font-size: 12px; color: var(--ink-3); font-weight: 600; margin: 16px 0 6px; }
.lesson-list nav a { display: block; padding: 6px 10px; border-radius: var(--radius); color: var(--ink-2); font-size: 14px; }
.lesson-list nav a:hover { background: var(--paper-2); color: var(--ink); }
.lesson-list nav a.active { background: var(--paper-3); color: var(--ink); }
.lesson-list nav a.done::after { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); margin-left: 8px; vertical-align: middle; }
.article { max-width: 68ch; font-size: 16px; }
.article h1 { margin-bottom: 6px; }
.article .tier-tag { color: var(--ink-3); font-size: 13px; margin-bottom: 20px; }
.article h2 { font-size: 20px; margin: 28px 0 8px; }
.article p { margin: 0 0 12px; }
.article ul, .article ol { padding-left: 20px; margin: 0 0 12px; }
.article li { margin-bottom: 4px; }
.article .try { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line-2); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 10px 12px; margin: 14px 0; background: var(--paper-2); font-size: 14.5px; }
.article .try .btn { margin-left: auto; }
.article .aside { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 10px 0; margin: 16px 0; color: var(--ink-2); font-size: 14.5px; }
.article .deep { display: none; }
.article .clin { display: none; }
body[data-depth="2"] .article .clin, body[data-depth="3"] .article .clin, body[data-depth="3"] .article .deep { display: block; }
.article table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 8px 0 14px; }
.article th, .article td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.article th { color: var(--ink-3); font-weight: 600; font-size: 12.5px; }
.article .mini { height: 120px; width: 100%; display: block; border: 1px solid var(--line); border-radius: var(--radius); margin: 8px 0 14px; }
.article figure.fig { margin: 16px 0 20px; }
.article figure.fig .figsvg { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.article figure.fig figcaption { font-family: var(--sans); font-size: 13.5px; color: var(--ink-2); margin-top: 8px; line-height: 1.45; }
.article .foot-nav { display: flex; justify-content: space-between; margin-top: 36px; gap: 12px; }
.tier-pick { display: inline-flex; gap: 6px; }

/* practice */
.quiz { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.quiz .ecg-big { border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; background: var(--paper); }
.quiz .ecg-big canvas { width: 100%; display: block; }
.quiz .vignette { font-size: 15px; margin: 12px 0; color: var(--ink-2); }
.options { display: grid; gap: 8px; }
.options button { text-align: left; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--paper); font-size: 14.5px; }
.options button:hover { background: var(--paper-2); }
.options button.right { border-color: var(--ok); background: rgba(46,125,79,.1); }
.options button.wrong { border-color: var(--warn); background: rgba(185,83,42,.1); }
.feedback { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 14px; font-size: 14.5px; }
.score-row { display: flex; gap: 14px; align-items: center; font-size: 13.5px; color: var(--ink-2); margin-bottom: 12px; flex-wrap: wrap; }
.mode-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 16px 0 26px; }

/* about */
.about { max-width: 72ch; font-size: 16px; }
.about h2 { margin: 26px 0 8px; font-size: 19px; }
.about li { margin-bottom: 6px; }
.about .ref { font-size: 14px; }

/* ---- responsive ---------------------------------------------------------- */
@media (max-width: 1100px) {
  .explore { grid-template-columns: minmax(0, 1fr) 330px; }
}
@media (max-width: 900px) {
  .top { gap: 14px; padding: 0 14px; }
  .depth button { padding: 6px 8px; font-size: 12px; }
  .explore { grid-template-columns: 1fr; height: auto; }
  .stage { border-right: 0; }
  .stage-body { grid-template-columns: 1fr; }
  .heart-pane { border-right: 0; border-bottom: 1px solid var(--line); height: 52vh; }
  .ecg-wrap { height: 46vh; }
  .panel { border-top: 1px solid var(--line); }
  .lesson-list { grid-template-columns: 1fr; }
  .lesson-list nav { position: static; display: flex; flex-wrap: wrap; gap: 4px; }
  .lesson-list nav .tier { width: 100%; }
  .quiz { grid-template-columns: 1fr; }
  .vital { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .nav a { padding: 6px 8px; font-size: 14px; }
  .top-right .depth { display: none; }
  .page { padding: 24px 16px 60px; }
  .page-head { grid-template-columns: 1fr; }
  .transport { grid-template-columns: auto 1fr; }
  .transport .clock { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .card, .btn { transition: none; }
}

/* narrow-screen overflow fixes */
@media (max-width: 640px) {
  .stage-head { padding: 8px 12px; gap: 8px; }
  .stage-head .seg { flex-wrap: wrap; }
  #lead-seg button { min-width: 0; flex: 1 0 auto; padding: 6px 7px; }
  #lead-seg button:nth-child(6) { border-right: 0; }
  .transport { grid-template-columns: auto 1fr; gap: 10px; padding: 8px 12px; }
  .transport > div:last-child { grid-column: 1 / -1; flex-wrap: wrap; gap: 6px; }
  .heart-foot, .ecg-foot { padding: 6px 10px; }
  .panel { padding: 14px 16px 40px; }
  .page-head input.select { min-width: 0; width: 100%; }
}
html, body { overflow-x: hidden; }
/* the case select must not set the page width from its longest option */
.stage-head .select { flex: 1 1 180px; min-width: 0; width: auto; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
@media (max-width: 640px) {
  .top { gap: 10px; padding: 0 12px; }
  .wordmark span { display: none; }
  .nav a { padding: 6px 7px; font-size: 13.5px; }
  .stage-head .select { flex-basis: 100%; }
}
@media (max-width: 640px) { .top-right { gap: 2px; } .icon-btn { width: 30px; } .nav { gap: 0; } }
/* the stage column must not inherit the select's intrinsic width */
.stage { grid-template-columns: minmax(0, 1fr); }
.stage > * { min-width: 0; }
.transport > div:last-child { min-width: 0; }
@media (max-width: 640px) { #lead-seg button { flex: 1 0 16.66%; } #lead-seg button:nth-child(6) { border-right: 0; } }

/* 3-D heart */
/* the 3-D canvas and the SVG share grid row 1, so the footer may wrap to two rows without overlapping either */
.heart-pane .three { position: relative; grid-area: 1 / 1; min-height: 0; }
.heart-pane svg.heart { grid-area: 1 / 1; }
.heart-pane .three canvas { outline: none; }
.heart-pane.mode-3d svg.heart { visibility: hidden; }
.heart-pane:not(.mode-3d) .three { display: none; }
.hud-err { position: absolute; left: 12px; top: 12px; right: 12px; font-size: 12.5px; color: var(--warn); }
.heart-pane .loading { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); font-size: 13px; color: var(--ink-3); pointer-events: none; }
.heart-foot .three-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* static reading panel */
.now .reading { margin: 0; display: grid; grid-template-columns: 56px 1fr; gap: 5px 10px; font-size: 13.5px; line-height: 1.4; }
.now .reading dt { color: var(--ink-3); font-family: var(--mono); font-size: 11.5px; padding-top: 2px; }
.now .reading dd { margin: 0; }
/* 3-D stage backdrop */
.heart-pane.mode-3d { background: radial-gradient(120% 90% at 50% 40%, var(--paper) 0%, var(--paper-2) 60%, var(--paper-3) 100%); }

/* ---- typography: Geist for the name and titles, Newsreader for long-form reading ---- */
.display, .page-head h1, .article h1, .article h2, .about h1, .about h2, .home h1, .home h2, .panel h2, .group-h h2, .quiz h1 { font-family: var(--display); font-weight: 600; letter-spacing: -0.035em; }
.page-head h1, .home h1 { font-size: 42px; line-height: 1.04; font-weight: 600; }
.article h1 { font-size: 38px; line-height: 1.1; }
.article h2 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin: 30px 0 8px; }
.article p, .article li, .article .aside, .article .try { font-family: var(--serif); font-size: 18px; line-height: 1.55; font-variation-settings: "opsz" 16; }
.article .try .btn, .article table { font-family: var(--sans); }
.article table { font-size: 14px; }
.article .tier-tag { font-family: var(--sans); }
.panel h2 { font-size: 22px; line-height: 1.15; }
.about p, .about li { font-family: var(--serif); font-size: 17.5px; line-height: 1.55; }
.about .ref, .about .mono, .about .kbd, .about .chip { font-family: var(--sans); font-size: 14px; }
.about .ref .mono { font-family: var(--mono); }
.card h3 { font-family: var(--serif); font-size: 18px; font-weight: 500; }
.gloss { text-decoration: none; border-bottom: 1px dotted var(--accent); cursor: help; }
.gloss:focus-visible { outline-offset: 1px; }

/* ---- skip link ---- */
.skip { position: absolute; left: -9999px; top: 8px; background: var(--ink); color: var(--paper); padding: 8px 12px; border-radius: var(--radius); z-index: 100; }
.skip:focus { left: 12px; }

/* ---- home ---- */
.home { max-width: 1120px; margin: 0 auto; padding: 48px 24px 80px; }
.home-hero { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 40px; align-items: center; margin-bottom: 56px; }
.home-sub { font-size: 18px; color: var(--ink-2); max-width: 54ch; margin: 18px 0 24px; line-height: 1.5; }
.home-cta { display: flex; gap: 10px; flex-wrap: wrap; }
.btn.lg { padding: 12px 18px; font-size: 15px; }
.home-return { margin-top: 16px; font-size: 14px; }
.home-live { position: relative; border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; aspect-ratio: 5 / 3; background: var(--paper); box-shadow: var(--shadow); }
.home-live canvas { width: 100%; height: 100%; display: block; }
.home-live-label { position: absolute; right: 10px; bottom: 8px; font-size: 11px; color: var(--ink-3); background: var(--paper); padding: 2px 6px; border-radius: 4px; }
.home-doors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 56px; }
.door { border: 1px solid var(--line-2); border-radius: var(--radius); padding: 22px 20px 18px; background: var(--paper); display: flex; flex-direction: column; gap: 8px; transition: border-color .15s, transform .15s; }
.door:hover { border-color: var(--ink-3); transform: translateY(-1px); }
.door .door-k { font-family: var(--mono); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.door h2 { font-size: 22px; line-height: 1.2; }
.door p { color: var(--ink-2); font-size: 14.5px; margin: 0; }
.home-how { max-width: 72ch; margin-bottom: 48px; }
.home-how h2 { font-size: 28px; margin-bottom: 14px; }
.how-steps { padding-left: 22px; font-size: 16.5px; line-height: 1.55; }
.how-steps li { margin-bottom: 8px; }
.home-foot { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--ink-3); border-top: 1px solid var(--line); padding-top: 16px; }
.home-credit { color: var(--ink-2); font-weight: 500; }
.home-foot a { color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; }
@media (max-width: 900px) { .home-hero { grid-template-columns: 1fr; } .home-doors { grid-template-columns: 1fr; } .page-head h1, .home h1 { font-size: 32px; } }

/* ---- tour ---- */
.tour-mask { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.tour-card { position: fixed; z-index: 61; width: min(340px, calc(100vw - 32px)); background: var(--ink); color: var(--paper); padding: 14px 16px; border-radius: var(--radius); box-shadow: 0 16px 40px -12px rgba(0,0,0,.45); font-size: 14px; line-height: 1.45; }
.tour-card .step { font-family: var(--mono); font-size: 11px; letter-spacing: .05em; opacity: .7; margin-bottom: 4px; }
.tour-card .row { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.tour-card .btn { border-color: transparent; background: var(--paper); color: var(--ink); }
.tour-card .btn.quiet { background: transparent; color: var(--paper); opacity: .8; }
.tour-target { outline: 2px solid var(--accent) !important; outline-offset: 3px; border-radius: var(--radius); position: relative; z-index: 59; }

/* ---- callipers + compare ---- */
.ecg-wrap.calipers { cursor: crosshair; }
.chip.toggle { cursor: pointer; user-select: none; }
.chip.toggle.on { border-color: transparent; background: var(--accent-soft); color: var(--accent); }

/* ---- presentation mode ---- */
body.present .top, body.present .panel, body.present .stage-head .select { display: none; }
body.present .explore { grid-template-columns: 1fr; height: 100vh; }
body.present .stage { border-right: 0; }
body.present main { min-height: 100vh; }

/* ---- anatomy explorer ---- */
.anatomy { display: grid; grid-template-columns: minmax(0, 1fr) 380px; height: calc(100vh - var(--top-h)); min-height: 560px; }
.anatomy .stage { grid-template-rows: auto minmax(0, 1fr) auto; }
.anatomy .layers { display: flex; gap: 6px; flex-wrap: wrap; }
.an-stage { position: relative; min-height: 0; background: radial-gradient(120% 90% at 50% 40%, var(--paper) 0%, var(--paper-2) 60%, var(--paper-3) 100%); }
.an-stage .three { position: absolute; inset: 0; }
.an-stage .three canvas { outline: none; }
.an-leaders { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.an-leader { stroke: var(--ink-3); stroke-width: 1; opacity: .55; }
.an-leader.on { stroke: var(--accent); stroke-width: 1.4; opacity: 1; }
.an-labels { position: absolute; inset: 0; pointer-events: none; }
.an-label { position: absolute; left: 0; top: 0; pointer-events: auto; font-family: var(--sans); font-size: 12px; font-weight: 500; color: var(--ink-2); background: var(--paper); border: 1px solid var(--line-2); border-radius: 999px; padding: 2px 9px; white-space: nowrap; line-height: 1.4; transition: color .12s, border-color .12s, background .12s; }
.an-label:hover, .an-label.hover { color: var(--ink); border-color: var(--ink-3); }
.an-label.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.an-label.lit { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }
.an-label.off { opacity: .25; }
.an-walk { position: absolute; left: 12px; bottom: 12px; font-size: 12px; color: var(--ink-2); background: var(--paper); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 6px 10px; pointer-events: none; }
.an-foot { display: flex; gap: 16px; justify-content: space-between; flex-wrap: wrap; padding: 8px 16px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); }
.an-list { padding-left: 20px; margin: 0 0 16px; }
.an-list li { margin-bottom: 4px; }
.an-pick { color: var(--ink); font-size: 14.5px; text-align: left; border-bottom: 1px dotted var(--line-2); }
.an-pick:hover { color: var(--accent); border-bottom-color: var(--accent); }
.an-cases { display: flex; gap: 6px; flex-wrap: wrap; }
.an-refs { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink-2); }
.an-refs li { margin-bottom: 6px; }
@media (max-width: 1100px) { .anatomy { grid-template-columns: minmax(0, 1fr) 330px; } }
@media (max-width: 900px) { .anatomy { grid-template-columns: 1fr; height: auto; } .an-stage { height: 60vh; } .anatomy .panel { border-top: 1px solid var(--line); } }

/* ---- coronaries explorer ---- */
.coronary { display: grid; grid-template-columns: 300px minmax(0, 1fr) 380px; height: calc(100vh - var(--top-h)); min-height: 600px; }
.cor-left { border-right: 1px solid var(--line); overflow-y: auto; padding: 16px 16px 24px; min-width: 0; }
.cor-head h1 { font-size: 24px; margin-bottom: 4px; }
.cor-head p { font-size: 13.5px; margin-bottom: 8px; }
.cor-tree { width: 100%; height: auto; display: block; margin: 4px 0 8px; }
.cor-aorta { fill: var(--paper-2); stroke: var(--line-2); stroke-width: 1.2; }
.cor-txt { font-family: var(--mono); font-size: 11px; fill: var(--ink-3); pointer-events: none; }
.cor-seg { cursor: pointer; outline: none; }
.cor-seg .cor-hit { fill: none; stroke: transparent; stroke-width: 18; stroke-linecap: round; }
.cor-seg .cor-vessel { fill: none; stroke: #b0423a; stroke-width: 5; stroke-linecap: round; transition: stroke .12s, stroke-width .12s; }
.cor-seg:hover .cor-vessel, .cor-seg:focus-visible .cor-vessel { stroke-width: 7; }
.cor-seg.lost .cor-vessel { stroke: var(--warn); opacity: .55; stroke-dasharray: 5 4; }
.cor-seg.on .cor-vessel { stroke: var(--warn); stroke-width: 7; }
.cor-seg.on .cor-txt { fill: var(--ink); font-weight: 600; }
.cor-occl { fill: var(--paper); stroke: var(--ink); stroke-width: 2.4; pointer-events: none; }
.cor-occl.subtotal { stroke-dasharray: 3 2; }
.cor-controls { display: grid; gap: 10px; }
.cor-controls .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cor-controls .k { font-size: 12px; color: var(--ink-3); min-width: 72px; }
.cor-stage { display: grid; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); min-width: 0; min-height: 0; border-right: 1px solid var(--line); }
.cor-three-wrap { position: relative; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; background: radial-gradient(120% 90% at 50% 40%, var(--paper) 0%, var(--paper-2) 60%, var(--paper-3) 100%); border-bottom: 1px solid var(--line); }
.cor-three-wrap .three { position: relative; min-height: 0; }
.cor-three-wrap .three canvas { outline: none; }
.cor-three-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-2); background: var(--paper); }
.cor-ecg { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; }
.cor-ecg canvas { display: block; width: 100%; height: 100%; }
.cor-ecg-foot { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-2); }
.cor-ecg-foot .sp { flex: 1; }
.play.sm { width: 26px; height: 26px; }
.cor-st { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; height: 92px; align-items: stretch; }
.st-col { position: relative; display: grid; grid-template-rows: 1fr auto; font-family: var(--mono); font-size: 10px; color: var(--ink-3); text-align: center; height: 78px; }
.st-col::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--line-2); }
.st-col .st-bar { position: absolute; left: 20%; right: 20%; background: var(--line-2); border-radius: 2px; max-height: 50%; }
.st-col .st-bar.up { background: var(--warn); }
.st-col .st-bar.down { background: var(--accent); }
.st-col span { position: absolute; left: 0; right: 0; bottom: -16px; }
.article .go { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line-2); border-left: 3px solid var(--warn); border-radius: var(--radius); padding: 10px 12px; margin: 14px 0; background: var(--paper-2); font-family: var(--serif); font-size: 18px; line-height: 1.55; }
.article .go .btn { margin-left: auto; font-family: var(--sans); }
@media (max-width: 1200px) { .coronary { grid-template-columns: 280px minmax(0, 1fr) 340px; } }
@media (max-width: 1000px) { .coronary { grid-template-columns: 280px minmax(0, 1fr); height: auto; } .coronary .panel { grid-column: 1 / -1; border-top: 1px solid var(--line); } .cor-stage { height: 90vh; } }
@media (max-width: 700px) { .coronary { grid-template-columns: 1fr; } .cor-left { border-right: 0; border-bottom: 1px solid var(--line); } .cor-stage { height: 100vh; border-right: 0; } }
.cor-controls .row[hidden] { display: none; }
