
:root{
  --bg:#eef2f0; --surface:#ffffff; --surface2:#e3e9e6; --ink:#14232b; --muted:#5d6d72; --line:#d3dcd8;
  --accent:#c8323c; --accent-ink:#ffffff;
  --oxy:#f6d3d1; --deoxy:#d4ddf1; --wall:#8b2f36; --vwall:#3e5a96;
  --valve:#14232b; --calc:#c99520; --jet:#e8890c; --defect:#8a4fb0;
  --paper:#fdf4f2; --grid1:#f3d5d1; --grid2:#e9b4ad; --trace:#14232b;
  color-scheme: light;
  box-sizing:border-box; padding-top:env(safe-area-inset-top,0px); padding-bottom:env(safe-area-inset-bottom,0px);
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#0e1619; --surface:#152127; --surface2:#1c2b32; --ink:#e4edef; --muted:#93a6ab; --line:#26373e;
    --accent:#ff5d63; --accent-ink:#150a0b;
    --oxy:#4a2026; --deoxy:#1f2c4d; --wall:#e0727a; --vwall:#8aa6e8;
    --valve:#e4edef; --calc:#f0c04a; --jet:#ffa733; --defect:#c58be6;
    --paper:#1a1416; --grid1:#2e2023; --grid2:#4a2c30; --trace:#f1e6e6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"]{
  --bg:#0e1619; --surface:#152127; --surface2:#1c2b32; --ink:#e4edef; --muted:#93a6ab; --line:#26373e;
  --accent:#ff5d63; --accent-ink:#150a0b;
  --oxy:#4a2026; --deoxy:#1f2c4d; --wall:#e0727a; --vwall:#8aa6e8;
  --valve:#e4edef; --calc:#f0c04a; --jet:#ffa733; --defect:#c58be6;
  --paper:#1a1416; --grid1:#2e2023; --grid2:#4a2c30; --trace:#f1e6e6;
  color-scheme: dark;
}
html{scroll-padding-top:env(safe-area-inset-top,0px)}
*{box-sizing:border-box}
body{margin:0;background:var(--bg);color:var(--ink);font-family:'Atkinson Hyperlegible',system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;font-size:16px;line-height:1.5;-webkit-font-smoothing:antialiased}
.wrap{max-width:1120px;margin:0 auto;padding:18px 14px 40px}
h1,h2,h3{font-family:'Bricolage Grotesque','Atkinson Hyperlegible',system-ui,sans-serif;margin:0;letter-spacing:-.015em}
h1{font-size:clamp(30px,6vw,46px);font-weight:800;line-height:1.02}
h2{font-size:24px;font-weight:800}
h3{font-size:17px;font-weight:600}
.sub{color:var(--muted);margin:8px 0 18px;max-width:62ch}
button{font:inherit;color:inherit;cursor:pointer}
button:focus-visible,input:focus-visible,[tabindex]:focus-visible{outline:3px solid var(--jet);outline-offset:2px}

/* picker */
.picker{display:grid;gap:10px;margin-bottom:16px}
.grp{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
.grp-label{font-size:13px;color:var(--muted);width:100%;margin-bottom:-1px}
@media(min-width:760px){.grp{position:relative;flex-wrap:wrap;padding-left:156px}.grp-label{position:absolute;left:0;top:7px;width:144px;margin:0}}
.chip{border:1.5px solid var(--line);background:var(--surface);border-radius:999px;padding:7px 13px;font-size:15px;line-height:1.2;transition:background .15s,border-color .15s}
.chip:hover{border-color:var(--muted)}
.chip[aria-pressed="true"]{background:var(--ink);color:var(--bg);border-color:var(--ink)}

/* layout */
.grid{display:grid;grid-template-columns:1fr;gap:14px}
.col{display:contents}
.heartcard{order:1}.pcgcard{order:2}.ctrl{order:3}.chest{order:4}.info{order:5}
@media(min-width:880px){
  .grid{grid-template-columns:minmax(0,1.2fr) minmax(0,1fr);align-items:start}
  .col{display:flex;flex-direction:column;gap:14px}
}
.panel{background:var(--surface);border:1px solid var(--line);border-radius:20px;padding:14px}
.heartcard{position:relative;padding:10px 10px 12px}
#heart{display:block;width:100%;height:auto;max-height:62vh;margin:0 auto}
.phase{position:absolute;top:12px;left:12px;right:12px;display:flex;flex-wrap:wrap;gap:6px 10px;align-items:baseline;pointer-events:none}
.phase b{font-family:'Bricolage Grotesque',sans-serif;font-size:15px;padding:3px 10px;border-radius:999px;background:var(--surface2)}
.phase b.sys{background:var(--accent);color:var(--accent-ink)}
.phase span{font-size:13px;color:var(--muted)}
.legend{display:flex;flex-wrap:wrap;gap:6px 14px;font-size:13px;color:var(--muted);padding:2px 6px 0}
.legend i{display:inline-block;width:12px;height:12px;border-radius:3px;vertical-align:-1px;margin-right:5px}

/* svg styling */
.ch{stroke:var(--wall);stroke-width:3.5}
.ch.o{fill:var(--oxy)} .ch.d{fill:var(--deoxy);stroke:var(--vwall)}
.ch.rvh{stroke-width:9}
.sept{fill:var(--wall)}
.vw{fill:none;stroke:var(--wall)} .vw.d{stroke:var(--vwall)}
.vl{fill:none} .vl.o{stroke:var(--oxy)} .vl.d{stroke:var(--deoxy)}
.chan.o{fill:var(--oxy)} .chan.d{fill:var(--deoxy)}
.chanEdge{stroke:var(--wall);stroke-width:3.5} .chanEdge.d{stroke:var(--vwall)}
.leaf{stroke:var(--valve);stroke-width:4;stroke-linecap:round}
.leaf.calc{stroke:var(--calc);stroke-width:7}
.nub{fill:var(--valve)}
.clabel{font-family:'Bricolage Grotesque',sans-serif;font-weight:800;font-size:19px;fill:var(--ink);opacity:.75;text-anchor:middle}
.vlabel{font-size:11px;fill:var(--ink);opacity:.7;text-anchor:middle}
.dlabel{font-size:11px;font-weight:700;fill:var(--defect);text-anchor:middle}
.defect{display:none}
.defect.on{display:inline}
.hole{fill:var(--defect);fill-opacity:.35;stroke:var(--defect);stroke-width:2;stroke-dasharray:3 2}
.jet{fill:none;stroke:var(--jet);stroke-width:6;stroke-linecap:round;stroke-dasharray:9 8;animation:flow var(--jd,.9s) linear infinite;opacity:0}
.ahp{fill:var(--jet)}
.fdot{pointer-events:none}.fdot.d{fill:var(--vwall)}.fdot.o{fill:var(--wall)}
.fpath{fill:none;stroke:none}
.flowbtn{border:1.5px solid var(--line);background:var(--surface2);border-radius:999px;padding:2px 11px;font-size:13px}
.flowbtn[aria-pressed="true"]{border-color:var(--ink)}
@keyframes flow{to{stroke-dashoffset:-17}}
@media (prefers-reduced-motion: reduce){.jet{animation:none;stroke-dasharray:none}}

/* controls */
.play{width:100%;display:flex;align-items:center;justify-content:center;gap:10px;background:var(--accent);color:var(--accent-ink);border:0;border-radius:14px;padding:14px;font-size:18px;font-weight:700}
.play svg{width:22px;height:22px}
.hint{font-size:13px;color:var(--muted);margin:8px 2px 12px}
.row{display:grid;grid-template-columns:120px 1fr;align-items:center;gap:10px;margin:6px 0}
.row label{font-size:14px}
input[type=range]{width:100%;accent-color:var(--accent)}
.lbl{font-size:14px;font-weight:700;margin:14px 0 6px}
.seg{display:flex;flex-wrap:wrap;gap:6px}
.seg button{border:1.5px solid var(--line);background:var(--surface2);border-radius:10px;padding:7px 11px;font-size:14px}
.seg button[aria-pressed="true"]{border-color:var(--ink);background:var(--ink);color:var(--bg)}
.effect{font-size:14px;margin:10px 0 0;padding:10px 12px;border-radius:12px;background:var(--surface2);min-height:44px}
.effect strong{font-weight:700}

/* pcg */
.pcghead{display:flex;justify-content:space-between;align-items:baseline;gap:10px;margin:0 4px 8px}
.pcghead span{font-size:13px;color:var(--muted)}
#pcg{display:block;width:100%;height:160px;border-radius:12px}

/* chest */
.chestwrap{display:grid;grid-template-columns:150px 1fr;gap:12px;align-items:center;margin-top:6px}
#chestsvg{width:150px;height:auto;display:block}
.torso{fill:var(--surface2);stroke:var(--line);stroke-width:2}
.bone{fill:none;stroke:var(--muted);stroke-width:1.5;opacity:.45}
.site circle{fill:var(--surface);stroke:var(--muted);stroke-width:2;cursor:pointer}
.site text{font-size:10px;font-weight:700;fill:var(--ink);text-anchor:middle;pointer-events:none}
.site.best circle{stroke:var(--accent);stroke-width:3}
.site.sel circle{fill:var(--accent);stroke:var(--accent)}
.site.sel text{fill:var(--accent-ink)}
.rad{fill:none;stroke:var(--jet);stroke-width:2.5;stroke-dasharray:4 3;display:none}
.rad.on{display:inline}
.radt{font-size:9px;fill:var(--jet);font-weight:700;display:none}
.radt.on{display:inline}
.sitename{font-weight:700}
.sitewhere{font-size:14px;color:var(--muted)}
.siteloud{font-size:14px;margin-top:6px}
.tapnote{font-size:12px;color:var(--muted);margin-top:6px}

/* info */
.info .tag{display:inline-block;font-size:13px;padding:2px 10px;border-radius:999px;background:var(--surface2);margin:6px 0 10px}
.info p{margin:0 0 12px;max-width:66ch}
.info dl{display:grid;grid-template-columns:1fr;gap:0;margin:0}
.info dl div{padding:9px 0;border-top:1px solid var(--line)}
.info dt{font-size:13px;color:var(--muted)}
.info dd{margin:2px 0 0}
@media(min-width:560px){.info dl div{display:grid;grid-template-columns:130px 1fr;gap:12px}.info dd{margin:0}}
.foot{font-size:13px;color:var(--muted);margin-top:22px;max-width:70ch}
/* ECG RX shared lab switcher */
.labnav{display:flex;align-items:center;flex-wrap:wrap;gap:6px;margin:0 0 16px}
.labbrand{font-family:'Bricolage Grotesque',system-ui,sans-serif;font-weight:800;font-size:13px;letter-spacing:.08em;text-transform:uppercase;color:var(--accent);margin-right:4px}
.labnav a{font-size:13px;text-decoration:none;color:var(--muted);border:1.5px solid var(--line);background:var(--surface);border-radius:999px;padding:5px 11px;line-height:1.2}
.labnav a:hover{border-color:var(--muted);color:var(--ink)}
.labnav a[aria-current="page"]{background:var(--ink);color:var(--bg);border-color:var(--ink)}

/* ================= ECG RX polish layer ================= */
*{-webkit-tap-highlight-color:transparent}
body{transition:background .35s ease,color .35s ease}
.panel{transition:transform .28s cubic-bezier(.2,.7,.3,1),box-shadow .28s ease,border-color .28s ease}
@media (hover:hover) and (pointer:fine){
  .panel:hover{transform:translateY(-2px);box-shadow:0 20px 44px -26px rgba(0,0,0,.5);border-color:color-mix(in srgb,var(--muted) 42%,var(--line))}
}
.chip{transition:background .18s ease,border-color .18s ease,color .18s ease,transform .12s ease,box-shadow .2s ease}
.chip:active{transform:scale(.96)}
.chip[aria-pressed="true"]{box-shadow:0 8px 18px -12px rgba(0,0,0,.75)}
.play,.tog,.seg button,.flowbtn{transition:background .18s,border-color .18s,color .18s,transform .12s,box-shadow .2s}
.play:active,.tog:active,.seg button:active,.flowbtn:active{transform:scale(.97)}
.play{box-shadow:0 12px 26px -16px var(--accent)}
#pcg{filter:drop-shadow(0 0 2px color-mix(in srgb,var(--trace) 45%,transparent))}
@keyframes rxRise{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}
.rx-in{animation:rxRise .55s cubic-bezier(.2,.7,.3,1) both}
@keyframes rxFlash{0%{box-shadow:0 0 0 0 color-mix(in srgb,var(--accent) 48%,transparent)}100%{box-shadow:0 0 0 15px transparent}}
.rx-flash{animation:rxFlash .65s ease-out}
@keyframes rxPulse{0%{box-shadow:0 0 0 0 color-mix(in srgb,var(--accent) 55%,transparent)}72%{box-shadow:0 0 0 9px transparent}100%{box-shadow:0 0 0 0 transparent}}
.rx-bar{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin:0 0 15px;font-size:13px;color:var(--muted)}
.rx-live{display:inline-flex;align-items:center;gap:7px;font-weight:700;color:var(--ink);font-size:13px}
.rx-live i{width:8px;height:8px;border-radius:50%;background:var(--accent);animation:rxPulse 1s ease-out infinite}
.rx-live.idle i{animation:none;background:var(--muted);opacity:.55}
.rx-sep{width:1px;height:18px;background:var(--line);display:none}
@media(min-width:700px){.rx-sep{display:block}}
.rx-hint{display:none}
@media(min-width:900px){.rx-hint{display:inline}}
.rx-hint kbd{font:inherit;font-size:11px;border:1px solid var(--line);border-bottom-width:2px;border-radius:5px;padding:1px 5px;background:var(--surface2);color:var(--ink)}
.rx-bar .spacer{flex:1}
@media (prefers-reduced-motion: reduce){
  .rx-in,.rx-live i,.rx-flash{animation:none!important}
  .panel:hover{transform:none}
}
