:root {
  --bg: #0a0f15;
  --panel: #111922;
  --panel2: #0e151d;
  --line: #1e2a37;
  --line2: #2a3a4b;
  --text: #dbe4ee;
  --muted: #8292a5;
  --accent: #5fe0c4;
  --accent2: #7aa8ff;
  --rest: #6e2630;
  --front: #fff3c0;
  --depol: #e8b23a;
  --repol: #7a86ff;
  --trace: #bff3d3;
  --warn: #ff6b7a;
  --ok: #5fe0a0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { background: var(--bg); color: var(--text); }
body { margin: 0; font: 14px/1.5 Inter, system-ui, -apple-system, sans-serif; padding: 0 16px; }
button, select, input { font: inherit; color: inherit; }
h2 { font-size: 22px; line-height: 1.25; margin: 6px 0 14px; letter-spacing: -0.01em; }
h3 { font-size: 13px; margin: 0; font-weight: 600; letter-spacing: .02em; }
h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin: 18px 0 6px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; padding: 18px 0; max-width: 1600px; margin: 0 auto; }
.top-center { display: flex; justify-content: center; min-width: 0; }
.top-actions { justify-self: end; }
@media (max-width: 760px) { .top { grid-template-columns: 1fr auto; } .top-center { grid-column: 1 / -1; grid-row: 2; } }
.brand { display: flex; gap: 12px; align-items: center; color: var(--accent); }
.brand-name { font-weight: 700; font-size: 26px; color: var(--text); letter-spacing: -0.02em; line-height: 1; }
.brand-sub { font-size: 12px; color: var(--muted); }
.top-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.mode-toggle { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg { background: none; border: 0; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg.on { background: var(--line2); color: var(--text); }
.rhythm-btn { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line2); border-radius: 12px; padding: 9px 14px; cursor: pointer; max-width: 100%; }
.rhythm-btn:hover { border-color: var(--accent); }
.rhythm-btn .lbl { color: var(--muted); font-size: 12px; }
.rhythm-btn .val { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }

.picker { position: fixed; inset: 0; background: rgba(4, 8, 12, .6); z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding: 72px 16px 16px; backdrop-filter: blur(3px); }
.picker-panel { width: min(820px, 100%); max-height: calc(100vh - 100px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line2); border-radius: 16px; box-shadow: 0 30px 80px rgba(0,0,0,.5); overflow: hidden; }
#search { margin: 14px; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--accent); background: var(--panel2); outline: none; }
.picker-list { overflow: auto; padding: 0 14px 14px; }
.pg-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; margin: 14px 4px 6px; font-weight: 600; }
.pg-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 2px 8px; }
.pg-item { text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.pg-item:hover, .pg-item.kb { background: var(--line); }
.pg-item.cur { background: var(--text); color: var(--bg); }
.pg-item .start { display: block; font-size: 10.5px; color: var(--depol); font-weight: 600; }
.pg-item.cur .start { color: #8a5a00; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; max-width: 1600px; margin: 0 auto; }
/* ECG panel + info panel with a draggable divider */
.top-row { display: grid; grid-template-columns: minmax(0, 1fr) 14px var(--sidew, 380px); align-items: start; }
.splitter { align-self: stretch; cursor: col-resize; display: flex; justify-content: center; touch-action: none; outline: none; }
.splitter span { width: 4px; border-radius: 2px; background: var(--line); margin: 40px 0; transition: background .15s; }
.splitter:hover span, .splitter:focus-visible span, .splitter.drag span { background: var(--accent); }
body.resizing { cursor: col-resize; user-select: none; }
.col-side { container-type: inline-size; min-width: 0; }
.info { font-size: clamp(12.5px, 4.1cqi, 17px); }
.info h2 { font-size: clamp(18px, 6.6cqi, 28px); }
@media (max-width: 1000px) { .top-row { grid-template-columns: minmax(0, 1fr); gap: 16px; } .splitter { display: none; } }
.row3 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: stretch; }
.row3 .card + .card { margin-top: 0; }
@media (max-width: 1100px) { .row3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .row3 .axis-card { grid-column: 1 / -1; grid-row: 1; } }
@media (max-width: 700px) { .row3 { grid-template-columns: minmax(0, 1fr); } }
.axis-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.42fr); gap: 12px; align-items: center; }
#axisWheel { width: 100%; aspect-ratio: 1; display: block; max-width: 340px; margin: 0 auto; }
.axis-heart { margin: 0; text-align: center; }
#axisHeart { width: 100%; aspect-ratio: 0.9; display: block; }
.axis-heart figcaption { font-size: 11px; color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; min-width: 0; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs { display: flex; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tab { background: none; border: 0; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: 13px; }
.tab.on { background: var(--line2); color: var(--text); }
.tabs.small .tab { font-size: 12px; padding: 4px 10px; }
.toggles { display: flex; gap: 14px; flex-wrap: wrap; }
.chk { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12.5px; cursor: pointer; user-select: none; }
.chk input { accent-color: var(--accent); }

.ecg-wrap { position: relative; overflow: hidden; border-radius: 10px; background: #0b1218; }
.ecg-wrap canvas { display: block; width: 100%; }
#ecg.calip { cursor: crosshair; }
.controls { display: flex; align-items: center; gap: 14px; margin-top: 12px; flex-wrap: wrap; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line2); background: var(--panel2); display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.time { display: flex; flex-direction: column; line-height: 1.15; }
.time b { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 15px; }
.time span { font-size: 11px; color: var(--muted); }
.speed { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.speed select { background: var(--panel2); border: 1px solid var(--line2); border-radius: 8px; padding: 5px 8px; }
#scrub { flex: 1 1 160px; accent-color: var(--accent); min-width: 120px; }
.jumps { display: flex; gap: 4px; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.jumps button { background: none; border: 0; padding: 4px 9px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.jumps button:hover { background: var(--line2); color: var(--text); }
.caption { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; padding: 10px 12px; background: var(--panel2); border-radius: 10px; border: 1px solid var(--line); min-height: 44px; }
.caption .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; margin-top: 6px; box-shadow: 0 0 10px var(--accent); }

.grid2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 16px; }
.side-stack { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 860px) { .side-stack { grid-template-columns: minmax(0, 1fr); } }
.side-stack .card + .card { margin-top: 0; }
#heart { display: block; width: 100%; margin: 0 auto; border-radius: 10px; }
.heart-stage { position: relative; border-radius: 10px; overflow: hidden; background: radial-gradient(ellipse at 50% 45%, #15212d 0%, #0a0f15 75%); }
#heart.webgl { cursor: grab; }
#heart.webgl.grabbing { cursor: grabbing; }
#heartLabels { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.h3-ctrls { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 12px; align-items: center; background: rgba(10,16,22,.7); border: 1px solid var(--line); border-radius: 10px; padding: 5px 10px; backdrop-filter: blur(4px); }
.h3-ctrls .hint { font-size: 11.5px; color: var(--muted); }
.mini { background: var(--panel2); border: 1px solid var(--line2); border-radius: 7px; padding: 3px 9px; font-size: 12px; cursor: pointer; }
.mini:hover { border-color: var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin-top: 10px; justify-content: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend i.line { width: 16px; height: 3px; border-radius: 2px; background: #f2e3a0; }
.legend .ramp { width: 160px; height: 10px; border-radius: 5px; background: linear-gradient(90deg, #ff3b3b, #ffb13b, #f5f04a, #5fe08a, #3bc2ff, #6a5bff, #b04bff); }
.vectors { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.vectors figure { margin: 0; text-align: center; }
.vectors canvas { width: 100%; aspect-ratio: 1; display: block; }
.vectors figcaption { font-size: 11px; color: var(--muted); }

.meas { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.m { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.m .k { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.m .v { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 17px; font-weight: 600; }
.m .r { font-size: 10.5px; color: var(--muted); }
.m.bad .v { color: var(--warn); }
.m.ok .v { color: var(--ok); }

.info p { margin: 0; color: #c3cfdb; }
.info ul { margin: 0; padding-left: 18px; color: #c3cfdb; }
.info li { margin: 4px 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--line); color: var(--muted); }
.chip.book { background: rgba(95, 224, 196, .12); color: var(--accent); }
.related { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.related button { background: var(--panel2); border: 1px solid var(--line2); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.related button:hover { color: var(--text); border-color: var(--accent); }
.info.hidden-answer h2, .info.hidden-answer .chips, .info.hidden-answer p, .info.hidden-answer ul, .info.hidden-answer h4, .info.hidden-answer .related { filter: blur(7px); user-select: none; pointer-events: none; }

.quiz-opts { display: grid; gap: 8px; margin-top: 12px; }
.quiz-opts button { text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; }
.quiz-opts button:hover:not(:disabled) { border-color: var(--accent); }
.quiz-opts button.right { border-color: var(--ok); background: rgba(95, 224, 160, .12); }
.quiz-opts button.wrong { border-color: var(--warn); background: rgba(255, 107, 122, .12); }
.score { font-family: 'JetBrains Mono', monospace; color: var(--accent); }
.primary { margin-top: 12px; width: 100%; padding: 10px; border-radius: 10px; border: 0; background: var(--accent); color: #05221c; font-weight: 700; cursor: pointer; }
.foot { max-width: 1600px; margin: 24px auto; color: var(--muted); font-size: 12px; text-align: center; padding-bottom: env(safe-area-inset-bottom, 0); }

.sources { font-size: 11px; color: var(--muted); text-align: center; margin: 8px auto 0; max-width: 760px; line-height: 1.45; }

.head-left { display: flex; gap: 8px; flex-wrap: wrap; }
#heart2d { display: block; width: 100%; }
#heartLabels { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.heart-stage.hovering { cursor: pointer; }
.h3-ctrls .only3d[hidden] { display: none !important; }
.focus-card { position: absolute; right: 12px; bottom: 12px; width: min(330px, calc(100% - 24px)); background: rgba(12,18,25,.88); border: 1px solid var(--line2); border-radius: 12px; padding: 12px 14px; backdrop-filter: blur(6px); box-shadow: 0 12px 40px rgba(0,0,0,.45); animation: fcIn .25s ease; }
@keyframes fcIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.focus-card h4 { margin: 2px 0 6px; font-size: 15px; color: var(--text); text-transform: none; letter-spacing: 0; }
.focus-card p { margin: 0 0 6px; font-size: 12.5px; color: #c3cfdb; line-height: 1.45; }
.focus-card .fc-note { color: #f0e2a6; margin: 0; }
.focus-card .fc-kind { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.fc-x { position: absolute; right: 8px; top: 6px; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.fc-x:hover { color: var(--text); }
@media (max-width: 600px) { .focus-card { left: 12px; right: 12px; width: auto; bottom: 56px; } }

.caption .spot { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line2); font-size: 12.5px; color: #f0e2a6; }
.caption .spot b { color: var(--accent); font-weight: 600; }

#valvePlane { position: absolute; top: 10px; right: 10px; width: 200px; pointer-events: none; }
@media (max-width: 600px) { #valvePlane { width: 150px; } }

/* about, credit and references */
.site-info { max-width: 1600px; margin: 8px auto 0; padding: 0 16px; display: grid; gap: 16px; }
.info-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: start; }
.credit-card { max-width: 300px; padding: 12px 16px; }
.credit-card p { margin: 4px 0; }
@media (max-width: 860px) { .info-grid { grid-template-columns: 1fr; } }
.about-card p, .refs-card p { line-height: 1.6; margin: 8px 0; }
.about-card h3, .refs-card h3 { margin: 0 0 6px; }
.howto { margin: 6px 0; padding-left: 20px; line-height: 1.6; }
.byline { font-size: 18px; color: var(--text, #e6edf3); }
.refs { margin: 4px 0 10px; padding-left: 22px; line-height: 1.55; font-size: 13px; }
.refs li { margin: 4px 0; overflow-wrap: anywhere; }
.site-info a, .foot a { color: var(--accent2); text-decoration: none; }
.site-info a:hover, .foot a:hover { text-decoration: underline; }
.info-grid .card + .card { margin-top: 0; }
.further { font-size: 12px; line-height: 1.6; color: var(--muted); margin: 10px 0 6px; }
.further span { color: var(--text); font-weight: 600; }
.zoom { display: inline-flex; gap: 4px; }
.zoom .mini { width: 26px; padding: 3px 0; font-weight: 700; }

/* steady caption: fixed height, text clamped, so changing captions never shift the page */
.caption { height: 138px; overflow: hidden; align-items: flex-start; box-sizing: border-box; }
#captionText { display: block; min-width: 0; }
#captionText .spot { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.capmain { min-height: 4.5em; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
/* memory aid + LITFL link */
.memo { margin: 12px 0 2px; padding: 10px 12px; border-radius: 10px; background: linear-gradient(135deg, rgba(95,224,196,.12), rgba(122,168,255,.08)); border: 1px solid rgba(95,224,196,.3); }
.memo-k { display: inline-block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; color: var(--accent); margin-bottom: 3px; }
.memo p { margin: 0; color: var(--text) !important; font-weight: 500; }
.litfl { display: inline-block; margin-top: 14px; font-size: 12.5px; color: var(--accent2); text-decoration: none; }
.litfl:hover { text-decoration: underline; }
.info.hidden-answer .memo, .info.hidden-answer .litfl { filter: blur(7px); pointer-events: none; user-select: none; }
.ro-h { margin: 14px 0 6px; }
.readorder { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; counter-reset: ro; }
.readorder li { display: grid; grid-template-columns: 22px 64px minmax(0, 1fr); align-items: baseline; gap: 6px; font-size: 12.5px; padding: 5px 8px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); counter-increment: ro; }
.readorder li::before { content: counter(ro); color: var(--accent); font-weight: 700; font-family: 'JetBrains Mono', monospace; }
.readorder li span { color: var(--muted); }
.readorder li b { font-weight: 500; color: var(--text); }
.explain { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); font-size: 12.5px; line-height: 1.55; color: #c3cfdb; }
.explain b { color: var(--text); font-weight: 600; }
.cause-why { margin: 0 0 6px !important; }
.causes { margin: 0; padding-left: 18px; color: #c3cfdb; }
.causes li { margin: 3px 0; }
.causes b { color: var(--text); font-weight: 600; }
.info.hidden-answer #infoCauses { filter: blur(7px); pointer-events: none; user-select: none; }

/* rhythm panel beside the heart */
.heart-card { position: relative; }
.heart-info { position: absolute; z-index: 3; top: 64px; left: 26px; width: min(300px, 28%); padding: 14px 16px; border-radius: 12px; background: rgba(12,18,25,.82); border: 1px solid var(--line2); backdrop-filter: blur(4px); pointer-events: none; }
.heart-info .hi-k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); font-weight: 700; }
.heart-info h3 { font-size: clamp(16px, 1.6vw, 21px); margin: 4px 0 10px; line-height: 1.25; }
.heart-info .hi-sub { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.heart-info ul { margin: 0; padding-left: 16px; font-size: 12.5px; line-height: 1.5; color: #c3cfdb; }
.heart-info li { margin: 5px 0; }
.heart-info b { color: var(--text); }
@media (max-width: 1000px) { .heart-info { position: static; width: auto; margin-bottom: 12px; pointer-events: auto; } }
