:root {
  --bg: #0a0e16;
  --bg2: #0f1522;
  --panel: #121a29;
  --panel2: #172134;
  --line: #22304a;
  --line2: #2d3e5e;
  --text: #e8eef8;
  --muted: #93a3bd;
  --dim: #64748f;
  --accent: #ffd166;
  --accent2: #ff7a45;
  --blue: #5aa9ff;
  --teal: #3fd0c0;
  --green: #7cffb2;
  --red: #ff5d73;
  --accent-ink: #ffd166;
  --accent-fill: #ffd166;
  --on-accent: #1a1406;
  --body2: #cfd9ea;
  --body3: #d7e0ee;
  --hover-line: #45608f;
  --bar-bg: rgba(10, 14, 22, .92);
  --menu-bg: #121a2a;
  --menu-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  --tip-bg: rgba(9, 13, 21, .94);
  --tip-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  --chip-on-bg: rgba(255, 209, 102, .12);
  --chip-on-line: rgba(255, 209, 102, .45);
  --chip-on-text: #ffe39d;
  --sel-bg: rgba(255, 209, 102, .1);
  --lead-on-bg: rgba(124, 255, 178, .12);
  --lead-on-line: rgba(124, 255, 178, .5);
  --lead-on-text: #7cffb2;
  --proj-bg: rgba(124, 255, 178, .07);
  --watch-bg: rgba(90, 169, 255, .08);
  --danger-bg: rgba(255, 93, 115, .14);
  --danger-bg2: rgba(255, 93, 115, .28);
  --danger-line: rgba(255, 93, 115, .55);
  --danger-text: #ffb3bf;
  --ok: #3ddc97;
  --ok-bg: rgba(61, 220, 151, .12);
  --bad-bg: rgba(255, 93, 115, .12);
  --warn: #ffb36b;
  --scrim: rgba(3, 6, 12, .7);
  --spot: rgba(255, 209, 102, .85);
  --spot-glow: rgba(255, 209, 102, .35);
  --spot2: rgba(255, 209, 102, .35);
  --spot2-glow: rgba(255, 209, 102, .15);
  --pl-bg: rgba(13, 20, 34, .8);
  --pl-text: #c3cee0;
  /* colours used inside explanatory text: match the traces */
  --c-p: #ffd166; --c-qrs: #ff8a3d; --c-t: #5aa9ff;
  --c-up: #7cffb2; --c-down: #ff8d9c;
  --c-mitral: #4dd4ac; --c-aortic: #ffb347;
  --c-lv: #ff5d73; --c-la: #6cb4ff; --c-vol: #8ce99a;
  --c-endo: #ff6b8b; --c-epi: #8ab4ff;
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

/* ---------- light theme: white page, ECG drawn as pink-grid paper ---------- */
:root[data-theme="light"] {
  --bg: #f3f5f9;
  --bg2: #eef1f6;
  --panel: #ffffff;
  --panel2: #e9eef5;
  --line: #dde3ec;
  --line2: #c8d1de;
  --text: #111318;
  --muted: #4a5263; /* secondary: units, hints, descriptions, notes (7-8:1) */
  --dim: #646b79;   /* tertiary: timestamps, tick numbers, footnotes (>=4.6:1 on every surface) */
  --accent: #e0a100;
  --accent2: #e0612a;
  --blue: #2f7fe0;
  --teal: #0f9a8b;
  --green: #0f7a45;
  --red: #d9364f;
  --accent-ink: #8f6200;
  --accent-fill: #ffcc4d;
  --on-accent: #2a1e00;
  --body2: #111318;
  --body3: #111318;
  --hover-line: #93a6c2;
  --bar-bg: rgba(255, 255, 255, .9);
  --menu-bg: #ffffff;
  --menu-shadow: 0 18px 50px rgba(20, 30, 50, .18);
  --tip-bg: rgba(255, 255, 255, .97);
  --tip-shadow: 0 8px 24px rgba(20, 30, 50, .16);
  --chip-on-bg: rgba(240, 170, 0, .14);
  --chip-on-line: rgba(200, 140, 0, .55);
  --chip-on-text: #111318;
  --sel-bg: rgba(240, 170, 0, .12);
  --lead-on-bg: rgba(23, 99, 199, .1);
  --lead-on-line: rgba(23, 99, 199, .5);
  --lead-on-text: #111318;
  --proj-bg: rgba(19, 138, 79, .07);
  --watch-bg: rgba(47, 127, 224, .08);
  --danger-bg: rgba(217, 54, 79, .1);
  --danger-bg2: rgba(217, 54, 79, .2);
  --danger-line: rgba(217, 54, 79, .55);
  --danger-text: #b0213a;
  --ok: #16a061;
  --ok-bg: rgba(22, 160, 97, .1);
  --bad-bg: rgba(217, 54, 79, .1);
  --warn: #a35800;
  --scrim: rgba(20, 28, 42, .45);
  --spot: rgba(224, 150, 0, .9);
  --spot-glow: rgba(240, 170, 0, .35);
  --spot2: rgba(224, 150, 0, .4);
  --spot2-glow: rgba(240, 170, 0, .12);
  --pl-bg: rgba(255, 255, 255, .88);
  --pl-text: #2a3444;
  --c-p: #865c00; --c-qrs: #aa3d0e; --c-t: #195fb8;
  --c-up: #0f7a45; --c-down: #c8304c;
  --c-mitral: #0a7558; --c-aortic: #985700;
  --c-lv: #d92f4b; --c-la: #1f68c4; --c-vol: #17793c;
  --c-endo: #d12f55; --c-epi: #2a68d6;
  color-scheme: light;
}
/* heart legend colours (also used in the help text) */
:root { --h-rest: #8a3e52; --h-front: #fff6c8; --h-dep: #ff8a3d; --h-repol: #5aa9ff; --h-cond: #3fd0c0; }
:root[data-theme="light"] { --h-rest: #d68c9e; --h-front: #8c0e30; --h-dep: #f2702a; --h-repol: #3076e4; --h-cond: #10968a; }
/* words that name the wavefront colour change with the theme */
.cw-front::before { content: "white-yellow"; }
:root[data-theme="light"] .cw-front::before { content: "dark red"; }
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
body { padding-bottom: 78px; min-height: 100vh; }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd { font: 12px var(--mono); background: var(--panel2); border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; }
h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: .01em; }
h3 { font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: .08em; font-weight: 600; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px; padding: 10px 18px;
  background: var(--bar-bg); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 30px; height: 30px; fill: none; stroke: var(--red); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 6px rgba(255, 93, 115, .5)); }
.brand strong { display: block; font-size: 16px; letter-spacing: .01em; }
.brand small { display: block; color: var(--muted); font-size: 11.5px; margin-top: -2px; }
.modes { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.modes button { border: 0; background: none; padding: 6px 14px; border-radius: 7px; color: var(--muted); font-weight: 550; }
.modes button.active { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line2); }
.modes button:hover:not(.active) { color: var(--text); }
.rhythm-picker { position: relative; flex: 1; min-width: 0; display: flex; justify-content: center; }
#rhythmBtn {
  display: flex; align-items: center; gap: 10px; max-width: 100%;
  background: var(--panel); border: 1px solid var(--line2); border-radius: 10px; padding: 7px 12px 7px 14px;
}
#rhythmBtn:hover { border-color: var(--hover-line); }
#rhythmBtn .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
#rhythmName { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { width: 12px; height: 12px; fill: none; stroke: var(--muted); stroke-width: 1.8; flex: none; }
.menu {
  position: absolute; top: calc(100% + 6px); z-index: 50; background: var(--menu-bg); border: 1px solid var(--line2);
  border-radius: 12px; box-shadow: var(--menu-shadow); padding: 8px;
}
#rhythmMenu { width: min(760px, 94vw); max-height: 72vh; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 14px; }
#rhythmMenu[hidden], .menu[hidden] { display: none; }
.menu .grp { grid-column: 1 / -1; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); padding: 8px 8px 2px; }
.menu .item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 9px; border-radius: 8px; color: var(--text); }
.menu .item small { display: block; color: var(--muted); font-size: 11.5px; }
.menu .item:hover, .menu .item:focus-visible { background: var(--panel2); outline: none; }
.menu .item.sel { background: var(--sel-bg); box-shadow: inset 2px 0 0 var(--accent); }
.menu.small { right: 0; min-width: 190px; }
.menu.small label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.menu.small label:hover { background: var(--panel2); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.sound-select { display: flex; align-items: center; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 0 4px 0 8px; }
.sound-select svg { width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linejoin: round; }
.sound-select select { border: 0; background: none; padding: 6px 2px; }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
select option { background: var(--panel); color: var(--text); }
.icon-btn { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line2); background: var(--panel); font-weight: 700; color: var(--muted); }
.icon-btn:hover { color: var(--text); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(360px, 41%) minmax(0, 1fr); gap: 14px; padding: 14px 18px; max-width: 1800px; margin: 0 auto; }
.col-left, .col-right { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.disclaimer { max-width: 1800px; margin: 0 auto; padding: 0 18px 4px; text-align: center; font-size: 12.5px; color: var(--text); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head.tight { margin-bottom: 6px; }
/* card pairs under the two main panels: [vector | measurements] under the heart, [narration | rhythm info] under the traces */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.pair-right { grid-template-columns: 1.4fr 1fr; }

/* segmented / chips */
.seg { display: inline-flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 7px; color: var(--muted); font-size: 12.5px; font-weight: 550; }
.seg button.active { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line2); }
.seg.small button { padding: 3px 8px; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { border: 1px solid var(--line2); background: transparent; color: var(--muted); padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 550; }
.chip:hover { color: var(--text); border-color: var(--hover-line); }
.chip.on { background: var(--chip-on-bg); border-color: var(--chip-on-line); color: var(--chip-on-text); }

/* heart */
.heart-wrap { position: relative; border-radius: 10px; overflow: hidden; background: radial-gradient(120% 90% at 50% 40%, #121b2c 0%, #0a0f18 70%); aspect-ratio: 1 / 1.02; }
#heart { width: 100%; height: 100%; display: block; touch-action: none; }
.heart-wrap.tool-probe #heart { cursor: crosshair; }
.heart-wrap.tool-stim #heart { cursor: cell; }
.heart-legend { position: absolute; left: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); background: rgba(10, 14, 22, .6); padding: 6px 8px; border-radius: 8px; pointer-events: none; }
.heart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 6px; vertical-align: -1px; }
.heart-legend.iso i { display: none; }
.heart-actions { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
.heart-actions button { font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 8px; }
.ghost { background: rgba(18, 26, 41, .85); border: 1px solid var(--line2); color: var(--text); }
.ghost:hover { border-color: var(--hover-line); }
.danger { background: var(--danger-bg); border: 1px solid var(--danger-line); color: var(--danger-text); }
.danger:hover { background: var(--danger-bg2); }
.hint { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); font-size: 12px; color: #ffe39d; background: rgba(10, 14, 22, .75); border: 1px solid rgba(255, 209, 102, .3); padding: 4px 10px; border-radius: 999px; pointer-events: none; white-space: nowrap; transition: opacity .2s; }
.hint:empty { opacity: 0; }
.tip { position: absolute; z-index: 10; pointer-events: none; background: var(--tip-bg); color: var(--text); border: 1px solid var(--line2); border-radius: 8px; padding: 6px 9px; font-size: 12px; max-width: 260px; box-shadow: var(--tip-shadow); }
.tip b { color: var(--accent-ink); }
.flash { animation: flash .6s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 2px var(--spot); } to { box-shadow: 0 0 0 2px transparent; } }

/* now card */
.now-card { padding: 14px 16px; }
.now-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.now-seg { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.now-title { font-size: 18px; font-weight: 700; margin: 6px 0 4px; }
.now-body { color: var(--body2); margin: 0 0 8px; }
.now-body b { color: var(--text); }
.now-sub { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.now-box { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.now-box h4 { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 3px; }
.now-box p { margin: 0; font-size: 13px; color: var(--body2); }
.states { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 2px; }
.state { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); color: var(--muted); }
.state i { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #445); box-shadow: 0 0 6px var(--c, transparent); }
.state b { color: var(--text); font-weight: 600; }
.evlog { list-style: none; padding: 0; margin: 10px 0 0; font-size: 12.5px; border-top: 1px solid var(--line); padding-top: 8px; }
.evlog li { display: flex; gap: 8px; padding: 2px 4px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.evlog li:hover { background: var(--panel2); color: var(--text); }
.evlog li.now { color: var(--text); }
.evlog .dt { font-family: var(--mono); font-size: 11.5px; color: var(--dim); min-width: 62px; text-align: right; }
.proj { font-size: 13px; color: var(--body2); margin: 8px 0 0; padding: 8px 10px; border-radius: 10px; background: linear-gradient(90deg, var(--proj-bg), transparent); border-left: 2px solid var(--green); }

/* traces */
.leads { display: flex; flex-wrap: wrap; gap: 3px; }
.leads button { border: 1px solid var(--line); background: var(--bg2); color: var(--muted); font: 600 12px var(--mono); padding: 3px 7px; border-radius: 6px; min-width: 34px; }
.leads button:hover { color: var(--text); }
.leads button.active { background: var(--lead-on-bg); border-color: var(--lead-on-line); color: var(--lead-on-text); }
.trace-opts { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.trace-opts select { padding: 3px 6px; font-size: 12px; }
.dropdown { position: relative; }
.traces-wrap { position: relative; }
#traces { width: 100%; display: block; border-radius: 8px; touch-action: none; }
.traces-wrap.cal #traces { cursor: ew-resize; }

#probeLegend { position: absolute; display: flex; flex-wrap: wrap; gap: 3px 8px; font-size: 10.5px; pointer-events: auto; }
.pl { display: inline-flex; align-items: center; gap: 4px; color: var(--pl-text); background: var(--pl-bg); padding: 0 5px; border-radius: 4px; line-height: 16px; }
.pl i { width: 8px; height: 8px; border-radius: 2px; }
.pl b { cursor: pointer; color: var(--muted); padding-left: 2px; }
.pl b:hover { color: var(--red); }

/* measurements */
.meas { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; margin-top: 8px; }
.meas div { background: var(--bg2); border: 1px solid var(--line); border-radius: 9px; padding: 6px 9px; }
.meas span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.meas b { font: 650 17px/1.3 var(--mono); }
.meas b small { font: 500 11px var(--font); color: var(--muted); margin-left: 2px; }
.meas .warn b { color: var(--warn); }
.meas .bad b { color: var(--red); }

/* vector */
.vector-card canvas { width: 100%; max-width: 360px; margin: 0 auto; aspect-ratio: 1; display: block; }
.vec-caption { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

/* info card */
.info-card h2 { font-size: 17px; margin-bottom: 4px; }
.info-card .grp { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.info-card p { margin: 6px 0; color: var(--body2); }
.info-card ul { margin: 6px 0; padding-left: 18px; }
.info-card li { margin: 2px 0; }
.info-card .watch { background: var(--watch-bg); border-left: 2px solid var(--blue); padding: 6px 10px; border-radius: 6px; font-size: 13px; }
.info-card details summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.jumps { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.jumps button, .btn { border: 1px solid var(--line2); background: var(--panel2); padding: 5px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 600; }
.jumps button:hover, .btn:hover { border-color: var(--hover-line); }
.btn.primary { background: var(--accent-fill); color: var(--on-accent); border-color: var(--accent-fill); }
.btn.primary:hover { filter: brightness(1.06); }

/* controls */
/* ---------- physiology controls ---------- */
.controls-card summary { list-style: none; cursor: pointer; margin: 0; }
.controls-card summary::-webkit-details-marker { display: none; }
.ctl-head h3 { margin: 0; flex: 1; }
.ctl-head { gap: 10px; }
.ctl-note { font-size: 11.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.nrm-key { display: inline-block; width: 2px; height: 11px; background: var(--text); opacity: .6; border-radius: 1px; }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: default; }
.ctl-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); gap: 8px 20px; margin-top: 12px; }
.ctl-group h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 6px; }
.ctl { padding: 6px 0 8px; border-bottom: 1px solid var(--line); }
.ctl-top { display: flex; align-items: baseline; gap: 6px; }
.ctl-name { font-size: 13px; font-weight: 600; color: var(--text); flex: 1; }
.ctl-val { font: 650 13px var(--mono); color: var(--text); white-space: nowrap; }
.ctl-val small { font: 500 11px var(--font); color: var(--muted); }
.ctl-reset { visibility: hidden; border: 1px solid var(--line2); background: var(--panel); color: var(--text); border-radius: 6px; width: 22px; height: 20px; font-size: 12px; line-height: 1; padding: 0; }
.ctl.changed .ctl-reset { visibility: visible; }
.ctl.changed .ctl-val::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: 5px; vertical-align: 2px; }
.ctl-row { display: flex; align-items: center; gap: 6px; margin: 4px 0 2px; }
.step { flex: none; width: 24px; height: 24px; border-radius: 7px; border: 1px solid var(--line2); background: var(--panel); color: var(--text); font: 600 15px/1 var(--font); padding: 0; }
.step:hover { border-color: var(--hover-line); }
/* custom track: the native input sits on top (keyboard, touch, a11y) with only its thumb visible */
.rng { position: relative; flex: 1; height: 24px; --n: .5; --d0: .5; --d1: .5; --b0: 0; --b1: 0; }
.rng .trk, .rng .band, .rng .dev { position: absolute; top: 10px; height: 4px; border-radius: 2px; }
.rng .trk { left: 9px; right: 9px; background: var(--line2); }
.rng .band { left: calc(9px + (100% - 18px) * var(--b0)); width: calc((100% - 18px) * (var(--b1) - var(--b0))); background: var(--ok); opacity: .35; }
.rng .dev { left: calc(9px + (100% - 18px) * var(--d0)); width: calc((100% - 18px) * (var(--d1) - var(--d0))); background: var(--accent); }
.rng .nrm { position: absolute; top: 4px; height: 16px; width: 2px; left: calc(9px + (100% - 18px) * var(--n) - 1px); background: var(--text); opacity: .6; border-radius: 1px; }
.rng input { position: absolute; inset: 0; width: 100%; height: 24px; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.rng input::-webkit-slider-runnable-track { height: 24px; background: transparent; }
.rng input::-moz-range-track { height: 24px; background: transparent; }
.rng input::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: 3px; border-radius: 50%; background: var(--accent-fill); border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--accent), 0 1px 3px rgba(0, 0, 0, .3); }
.rng input::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent-fill); border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--accent), 0 1px 3px rgba(0, 0, 0, .3); }
.rng input:focus-visible { outline: none; }
.rng input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--chip-on-line); }
.rng input:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--chip-on-line); }
.ctl-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 10px; font-size: 11.5px; }
.ctl-foot .eff { font: 600 12px var(--mono); color: var(--text); }
.ctl-foot .hint { color: var(--muted); }
.ctl-seg { display: flex; flex-direction: column; gap: 6px; padding: 9px 0 4px; }
.ctl-seg .seg { display: flex; }
.ctl-seg .seg button { flex: 1; white-space: nowrap; padding: 4px 6px; }
.sws { display: flex; flex-direction: column; gap: 9px; padding: 4px 0 8px; border-bottom: 1px solid var(--line); }
.sw { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text); cursor: pointer; }
.sw input { -webkit-appearance: none; appearance: none; flex: none; width: 32px; height: 18px; margin: 0; border-radius: 9px; background: var(--line2); position: relative; cursor: pointer; transition: background .15s; }
.sw input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: left .15s; }
.sw input:checked { background: var(--accent); }
.sw input:checked::after { left: 16px; }
.sw input:focus-visible { outline: 2px solid var(--chip-on-line); outline-offset: 2px; }

/* quiz */
.quiz-q { font-size: 15px; font-weight: 650; margin: 2px 0 8px; }
.quiz-opts { display: grid; gap: 6px; }
.quiz-opts button { text-align: left; border: 1px solid var(--line2); background: var(--bg2); padding: 8px 10px; border-radius: 9px; }
.quiz-opts button:hover:not(:disabled) { border-color: var(--hover-line); }
.quiz-opts button.right { border-color: var(--ok); background: var(--ok-bg); }
.quiz-opts button.wrong { border-color: var(--red); background: var(--bad-bg); }
.quiz-score { font-family: var(--mono); color: var(--muted); font-size: 12px; }
.hide-heart #heart { filter: blur(26px) brightness(.35); }
.hide-heart .heart-legend, .hide-heart .heart-actions { visibility: hidden; }
.hide-heart::after { content: "Heart hidden — read the ECG!"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-weight: 600; }

/* tour */
.tour-card { border-color: var(--chip-on-line); background: linear-gradient(180deg, var(--sel-bg), var(--panel) 60%); }
.tour-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tour-step { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--accent-ink); font-weight: 700; }
.tour-card h2 { font-size: 18px; margin: 4px 0 6px; }
.tour-card p { margin: 6px 0; color: var(--body3); }
.tour-card .tour-nav { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.tour-dots { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tour-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line2); cursor: pointer; }
.tour-dots i.on { background: var(--accent); }
.spot { position: relative; }
.spot::after { content: ""; position: absolute; inset: -3px; border-radius: 14px; box-shadow: 0 0 0 2px var(--spot), 0 0 24px var(--spot-glow); pointer-events: none; animation: spot 1.8s ease-in-out infinite; }
@keyframes spot { 50% { box-shadow: 0 0 0 2px var(--spot2), 0 0 12px var(--spot2-glow); } }

/* transport */
.transport {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: 66px;
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: var(--bar-bg); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.tbtns { display: flex; align-items: center; gap: 4px; }
.tbtns button { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; }
.tbtns button:hover { border-color: var(--hover-line); }
.tbtns svg { width: 16px; height: 16px; fill: var(--text); stroke: var(--text); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tbtns button:not(.play) svg { fill: none; }
.tbtns button#bPrevEv svg path:last-child, .tbtns button#bNextEv svg path:last-child { fill: var(--text); }
.tbtns .play { width: 46px; height: 46px; border-radius: 50%; background: var(--accent-fill); border-color: var(--accent-fill); }
.tbtns .play svg { fill: var(--on-accent); stroke: var(--on-accent); width: 18px; height: 18px; }
.tbtns .play .i-pause { display: none; }
.playing .tbtns .play .i-pause { display: block; }
.playing .tbtns .play .i-play { display: none; }
.speed { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.speed-seg button { font: 600 12px var(--mono); padding: 5px 9px; min-width: 44px; }
.speed-seg button.active { color: var(--text); }
.timeline { flex: 1; min-width: 120px; height: 44px; position: relative; }
#timeline { width: 100%; height: 100%; display: block; cursor: pointer; border-radius: 8px; touch-action: none; }
.tinfo { display: flex; align-items: center; gap: 8px; }
#tLabel { font: 600 13px var(--mono); color: var(--muted); min-width: 74px; text-align: right; }
.latest { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--chip-on-line); background: var(--chip-on-bg); color: var(--text); font: 650 12px var(--font); padding: 5px 9px 5px 11px; border-radius: 8px; visibility: hidden; opacity: 0; transition: opacity .15s; }
.latest.behind { visibility: visible; opacity: 1; }
.latest .short { display: none; }
.latest:hover { filter: brightness(1.08); }
.latest svg { width: 12px; height: 12px; fill: currentColor; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
@keyframes blink { 50% { opacity: .3; } }

/* modal */
.modal { position: fixed; inset: 0; z-index: 60; background: var(--scrim); display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-box { position: relative; width: min(980px, 100%); max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--line2); border-radius: 16px; padding: 22px 24px; }
.modal-box .close { position: absolute; right: 14px; top: 10px; border: 0; background: none; font-size: 26px; color: var(--muted); }
.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; margin-top: 12px; }
.help-grid h4 { margin: 10px 0 4px; color: var(--accent-ink); }
.help-grid ul { padding-left: 18px; margin: 4px 0; }
.help-grid li { margin: 4px 0; }
.fine { color: var(--dim); font-size: 12px; margin-top: 14px; }

#loading { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--muted); transition: opacity .4s; }
#loading.gone { opacity: 0; pointer-events: none; }
#loading svg { width: 64px; height: 64px; fill: none; stroke: var(--red); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 60; animation: draw 1.2s linear infinite; }
@keyframes draw { from { stroke-dashoffset: 60; } to { stroke-dashoffset: -60; } }

/* ---------- responsive ---------- */
@media (max-width: 1350px) {
}
@media (max-width: 1060px) {
  .layout { grid-template-columns: 1fr; }
  .col-left { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .tour-card { grid-column: 1 / -1; }
  .topbar { flex-wrap: wrap; }
  .rhythm-picker { order: 3; flex-basis: 100%; }
}
@media (max-width: 760px) {
  body { padding-bottom: 112px; font-size: 13.5px; }
  .layout { padding: 10px; gap: 10px; }
  .disclaimer { padding: 0 10px 4px; font-size: 12px; }
  .layout { display: flex; flex-direction: column; }
  .col-left, .col-right { display: contents; }
  .pair { display: contents; }
  .tour-card { order: 0; } .heart-card { order: 1; } .traces-card { order: 2; } .vector-card { order: 3; } .now-card { order: 4; } #measureCard { order: 5; } .info-card { order: 6; } .controls-card { order: 7; }
  .heart-legend { display: none; }
  #probeLegend { font-size: 9.5px; }
  .topbar { padding: 8px 10px; gap: 8px; }
  .brand small { display: none; }
  .modes button { padding: 5px 9px; }
  .now-sub { grid-template-columns: 1fr; }
  .transport { height: auto; flex-wrap: wrap; padding: 8px 10px; gap: 8px; }
  .timeline { order: 5; flex-basis: 100%; height: 36px; }
  .speed-lbl { display: none; }
  .latest .long { display: none; } .latest .short { display: inline; }
  .latest { padding: 5px 8px; font-size: 11.5px; }
  #tLabel { min-width: 0; font-size: 12px; }
  .speed-seg button { min-width: 0; padding: 5px 7px; font-size: 11.5px; }
  .heart-legend { font-size: 10px; }
  .chips .chip { font-size: 11px; padding: 2px 7px; }
}

:root[data-theme="light"] .brand svg { filter: none; }
:root[data-theme="light"] .card { box-shadow: 0 1px 2px rgba(20, 30, 50, .05); }

/* light theme: the heart drawn as a light anatomical illustration */
:root[data-theme="light"] .heart-wrap {
  background: radial-gradient(120% 95% at 50% 42%, #ffffff 0%, #f6f8fb 60%, #eef2f7 100%);
  box-shadow: inset 0 0 0 1px var(--line);
}
:root[data-theme="light"] .heart-legend { background: rgba(255, 255, 255, .88); color: var(--muted); box-shadow: 0 0 0 1px var(--line); }
:root[data-theme="light"] .hint { background: rgba(255, 255, 255, .94); color: var(--chip-on-text); border-color: var(--chip-on-line); }
:root[data-theme="light"] .ghost { background: rgba(255, 255, 255, .92); }
:root[data-theme="light"] .hide-heart #heart { filter: blur(26px) opacity(.45); }

/* light theme: segmented controls as a grey track with a raised white "selected" pill, darker labels */
:root[data-theme="light"] .modes,
:root[data-theme="light"] .seg { background: var(--panel2); border-color: var(--line); }
:root[data-theme="light"] .modes button,
:root[data-theme="light"] .seg button { color: var(--body2); font-weight: 600; }
:root[data-theme="light"] .modes button.active,
:root[data-theme="light"] .seg button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(20, 30, 50, .14), 0 0 0 1px rgba(20, 30, 50, .06); }
:root[data-theme="light"] .modes button:hover:not(.active),
:root[data-theme="light"] .seg button:hover:not(.active) { color: var(--text); background: rgba(255, 255, 255, .5); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 4px; vertical-align: -1px; box-shadow: 0 0 0 1px rgba(127, 127, 127, .25); }

/* light theme: black for anything people read or click; grey only for true fine print
   (units, hints, timestamps, menu descriptions); colour only where it encodes meaning */
:root[data-theme="light"] :is(h3, .now-box h4, .meas span, .info-card .grp, .info-card details summary,
  .chip, .leads button, .evlog li, .vec-caption, .ctl label, .toggles .lbl, .speed, #tLabel,
  .heart-legend, .hint, .tip b, .tour-step, .help-grid h4, .hide-heart::after, .modal-box .close, .pl b, .icon-btn) { color: var(--text); }
:root[data-theme="light"] .leads button.active { font-weight: 700; }
:root[data-theme="light"] .chip.on { font-weight: 650; }
/* light theme gray tiers: slider hints are teaching content -> secondary, not tertiary;
   rhythm-menu group headers are headings -> secondary + bold */
:root[data-theme="light"] .menu .grp { color: var(--muted); font-weight: 700; }
.seg[hidden] { display: none; }
#lay12 button { padding: 3px 8px; font-size: 12px; }
#winSel:disabled { opacity: .55; cursor: not-allowed; }
/* measurement tiles that link to the control that sets them */
.meas .linked { cursor: pointer; transition: border-color .15s; }
.meas .linked:hover, .meas .linked:focus-visible { border-color: var(--chip-on-line); outline: none; }
.meas .linked span { display: flex; justify-content: space-between; gap: 4px; }
.meas .linked i { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--muted); opacity: 0; transition: opacity .15s; }
.meas .linked:hover i, .meas .linked:focus-visible i { opacity: 1; }
@media (hover: none) { .meas .linked i { opacity: 1; } }
.ctl.flash { animation: flash .9s ease-out; border-radius: 8px; }
/* quiz in the top card */
.quiz-card .quiz-opts { grid-template-columns: 1fr 1fr; }
.quiz-card .quiz-q { margin-top: 4px; }
@media (max-width: 760px) { .quiz-card .quiz-opts { grid-template-columns: 1fr; } }
.guide { margin: 6px 0 0; padding-left: 20px; font-size: 13px; }
.guide li { margin: 4px 0; color: var(--body2); }
/* panel presets */
.presets { display: grid; gap: 4px; }
.preset { text-align: left; border: 1px solid var(--line); background: var(--bg2); color: var(--text); border-radius: 8px; padding: 6px 9px; font-weight: 600; font-size: 12.5px; }
.preset small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.preset.on { border-color: var(--chip-on-line); background: var(--chip-on-bg); }
.preset:hover { border-color: var(--hover-line); }
.menu-sep { height: 1px; background: var(--line); margin: 8px 2px 4px; }
#laneMenu { min-width: 230px; }
#probeLegend[hidden] { display: none; }
