/* Anatomical heart, conduction system and hexaxial axis view (ui/heart.mjs).
   Colours come from tokens.css; the few extra shades this view needs are
   declared here for both themes. */
:root {
  --hv-back: #eaf1f8;
  --hv-conduct-edge: #1d1203;
  --hv-kent: #a21caf;
  --hv-wire: #d5dde6;
  --hv-wire-edge: #1f2a36;
  --hv-spark: #4aa8ff;
  --hv-halo: #ffffff;
  --hv-hex-line: #10243b;
  --hv-zone-normal: #1d7f4d;
  --hv-zone-left: #b56a00;
  --hv-zone-right: #6a4bd0;
  --hv-zone-extreme: #c2372f;
  --hv-zone-fill: 0.05;
  --hv-zone-band: 0.6;
}

:root[data-theme="dark"] {
  --hv-back: #0f2238;
  --hv-conduct-edge: #120a00;
  --hv-kent: #f08bea;
  --hv-wire: #a9b8c8;
  --hv-wire-edge: #0a121c;
  --hv-spark: #7cc4ff;
  --hv-halo: #06111f;
  --hv-hex-line: #e7eef8;
  --hv-zone-normal: #5fd39a;
  --hv-zone-left: #f0b35a;
  --hv-zone-right: #a995ff;
  --hv-zone-extreme: #ff7b72;
  --hv-zone-fill: 0.09;
  --hv-zone-band: 0.7;
}

.hv-root {
  container-type: inline-size;
  display: grid;
  gap: 6px;
  width: 100%;
  color: var(--ink);
  font-family: var(--font);
}

.hv-stage {
  position: relative;
  width: 100%;
  max-width: 640px;
  margin-inline: auto;
  aspect-ratio: 1 / 1;
}

.hv-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
}

.hv-svg text {
  font-family: var(--font);
}

/* --- gradient stops ------------------------------------------------------- */
.hv-st-back { stop-color: var(--hv-back); }
.hv-st-shadow { stop-color: #000; }
.hv-st-white { stop-color: #fff; }
.hv-st-conduct { stop-color: var(--conduct); }
.hv-st-conduct-deep { stop-color: var(--conduct); stop-color: color-mix(in srgb, var(--conduct) 70%, #5a3a05); }
.hv-st-impulse { stop-color: var(--impulse); }
.hv-st-depol { stop-color: var(--depol); }
.hv-st-block { stop-color: var(--block); }
.hv-st-isch { stop-color: var(--ischemia); }
.hv-st-spark { stop-color: var(--hv-spark); }

/* --- base illustration ---------------------------------------------------- */
.hv-img { opacity: 0; transition: opacity 0.25s ease; }
.hv-img.hv-img-ready { opacity: 1; }
:root[data-theme="dark"] .hv-img { filter: brightness(0.9) saturate(0.94); }

/* --- activation washes: tint the picture instead of covering it -------------- */
.hv-washes > g { mix-blend-mode: screen; }
.hv-isch { mix-blend-mode: multiply; }

/* --- pacing leads ----------------------------------------------------------- */
.hv-device path { fill: none; stroke-linecap: round; }
.hv-wire-edge { stroke: var(--hv-wire-edge); stroke-width: 4.2; opacity: 0.7; }
.hv-wire { stroke: var(--hv-wire); stroke-width: 2.4; }
.hv-wire-tip { fill: #e8eef5; stroke: var(--hv-wire-edge); stroke-width: 1.2; }
.hv-spark-rays { fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; }
.hv-spark-core { fill: #fff; stroke: var(--hv-spark); stroke-width: 1.4; }

/* --- conduction system ------------------------------------------------------ */
.hv-conduction path,
.hv-conduction circle { stroke-linecap: round; stroke-linejoin: round; }
.hv-c-edge { stroke: var(--hv-conduct-edge); opacity: 0.85; }
.hv-behind .hv-c-edge { opacity: 0.4; }
.hv-behind .hv-c-rest { stroke-dasharray: 2.5 4; opacity: 0.8; }
.hv-c-rest { stroke: var(--conduct); }
.hv-node-edge { fill: var(--hv-conduct-edge); opacity: 0.9; stroke: #fff; stroke-width: 1; stroke-opacity: 0.55; }
.hv-kent,
.hv-label-kent { display: none; }
.hv-kent.hv-on,
.hv-label-kent.hv-on { display: inline; }
.hv-kent .hv-c-rest { stroke: var(--hv-kent); }
.hv-lit { stroke: #fff; }
.hv-lit-glow { stroke: var(--impulse); }
.hv-head-core { fill: #fff; stroke: var(--conduct); stroke-width: 1; }
.hv-loop { fill: none; stroke: var(--conduct); stroke-width: 2; stroke-dasharray: 2 5; }
.hv-loop-lit { stroke: #fff; }
.hv-ivcd .hv-purk .hv-c-rest { stroke-dasharray: 3 3; }
/* A block has to be findable at a glance on a detailed picture: a tinted
   disc draws the eye, the double bar marks the exact break. */
.hv-blockmark-disc { fill: var(--block); fill-opacity: 0.3; stroke: var(--hv-halo); stroke-width: 1.6; stroke-opacity: 0.9; }
.hv-blockmark-halo { fill: none; stroke: var(--hv-halo); stroke-width: 7; stroke-linecap: round; opacity: 0.95; }
.hv-blockmark-bar { fill: none; stroke: var(--block); stroke-width: 3.4; stroke-linecap: round; }
.hv-blockmark[data-slow="1"] .hv-blockmark-bar { stroke-dasharray: 2.5 3.5; }

/* --- labels ----------------------------------------------------------------- */
.hv-labels,
.hv-hex { transition: opacity 0.2s ease; }
.hv-no-labels .hv-labels { opacity: 0; visibility: hidden; }
.hv-no-hex .hv-hex { opacity: 0; visibility: hidden; }
.hv-label text {
  font-size: 12.5px;
  font-weight: 600;
  fill: var(--ink);
  stroke: var(--surface);
  stroke-width: 3.2px;
  stroke-linejoin: round;
  paint-order: stroke;
  dominant-baseline: central;
}
.hv-label-anat text { fill: var(--muted); }
.hv-label-short { display: none; }
.hv-leader { fill: none; stroke: var(--ink); stroke-width: 0.9; opacity: 0.75; }
.hv-leader-halo { fill: none; stroke: var(--hv-halo); stroke-width: 2.8; opacity: 0.55; }
.hv-leader-dot { fill: var(--ink); stroke: var(--hv-halo); stroke-width: 1; }
.hv-label-cond .hv-leader-dot { fill: var(--conduct); stroke: var(--hv-conduct-edge); }
.hv-label-kent .hv-leader-dot { fill: var(--hv-kent); stroke: var(--hv-halo); }
.hv-label-kent text { fill: var(--hv-kent); }
.hv-chamber {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.04em;
  fill: #fff;
  stroke: #1a0a1e;
  stroke-opacity: 0.55;
  stroke-width: 3px;
  stroke-linejoin: round;
  paint-order: stroke;
  opacity: 0.9;
  text-anchor: middle;
  dominant-baseline: central;
}

/* --- hexaxial reference ----------------------------------------------------- */
.hv-zone { opacity: var(--hv-zone-fill); }
.hv-zoneband { opacity: var(--hv-zone-band); }
.hv-zone-normal { fill: var(--hv-zone-normal); }
.hv-zone-left { fill: var(--hv-zone-left); }
.hv-zone-right { fill: var(--hv-zone-right); }
.hv-zone-extreme { fill: var(--hv-zone-extreme); }
.hv-rim { fill: none; stroke: var(--hv-hex-line); stroke-width: 1.2; opacity: 0.8; }
.hv-rim-halo { fill: none; stroke: var(--hv-halo); stroke-width: 3.4; opacity: 0.4; }
.hv-ticks { fill: none; stroke: var(--hv-hex-line); stroke-width: 1; opacity: 0.75; }
.hv-axes path { fill: none; stroke: var(--hv-hex-line); stroke-width: 0.9; opacity: 0.4; }
.hv-axes .hv-axis-aug { stroke-dasharray: 5 4; }
.hv-rimtext text { text-anchor: middle; dominant-baseline: central; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.hv-deg { font-family: var(--mono); font-size: 9.5px; fill: var(--muted); }
.hv-lead-pos rect { fill: var(--surface); stroke: var(--hv-hex-line); stroke-width: 1; }
.hv-lead-pos text { font-size: 11px; font-weight: 700; fill: var(--ink); stroke: none; }
.hv-lead-neg { font-size: 10px; font-weight: 600; fill: var(--muted); }

.hv-arrow-halo { fill: none; stroke: var(--hv-halo); stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; opacity: 0.85; }
.hv-arrow-head-halo { fill: var(--hv-halo); stroke-width: 4; }
.hv-paxis-shaft { fill: none; stroke: var(--accent); stroke-width: 3.5; stroke-linecap: round; stroke-dasharray: 7 5; }
.hv-paxis-head { fill: var(--accent); stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; }
.hv-paxis-dot { fill: var(--accent); stroke: var(--hv-halo); stroke-width: 2; }
.hv-paxis-text { fill: #fff; font-size: 12px; font-weight: 800; }
.hv-arrow-shaft { fill: none; stroke: var(--axis); stroke-width: 5; stroke-linecap: round; }
.hv-arrow-head { fill: var(--axis); stroke: var(--axis); stroke-width: 1.5; stroke-linejoin: round; }
.hv-grip { fill: var(--surface); fill-opacity: 0.85; stroke: var(--axis); stroke-width: 2; stroke-dasharray: 3 3; display: none; }
.hv-paused .hv-grip { display: inline; }
.hv-dragging .hv-grip { stroke-dasharray: none; fill-opacity: 1; }

.hv-trail polyline { stroke: var(--vector); stroke-linecap: round; stroke-linejoin: round; }
.hv-vec-halo { fill: none; stroke: var(--hv-halo); stroke-width: 6; stroke-linecap: round; opacity: 0.95; }
.hv-vec-shaft { fill: none; stroke: var(--vector); stroke-width: 2.6; stroke-linecap: round; }
.hv-vec-head { fill: var(--vector); stroke: var(--hv-halo); stroke-width: 0.8; stroke-linejoin: round; }
.hv-hub { fill: var(--surface); stroke: var(--hv-hex-line); stroke-width: 1.6; }

.hv-readout text { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.hv-readout-title { font-size: 9.5px; font-weight: 700; letter-spacing: 0.08em; fill: var(--muted); }
.hv-readout-value { font-family: var(--mono); font-size: 25px; font-weight: 700; fill: var(--axis); }
.hv-readout { --hv-chip: var(--muted); }
.hv-readout[data-zone="normal"] { --hv-chip: var(--hv-zone-normal); }
.hv-readout[data-zone="left"] { --hv-chip: var(--hv-zone-left); }
.hv-readout[data-zone="right"] { --hv-chip: var(--hv-zone-right); }
.hv-readout[data-zone="extreme"] { --hv-chip: var(--hv-zone-extreme); }
.hv-chip { fill: var(--surface); fill: color-mix(in srgb, var(--hv-chip) 16%, var(--surface)); stroke: var(--hv-chip); stroke-width: 1; }
.hv-readout .hv-chip-text { font-size: 10.5px; font-weight: 700; fill: var(--hv-chip); stroke: none; dominant-baseline: central; }
.hv-legend text { font-size: 9.5px; font-weight: 600; fill: var(--muted); dominant-baseline: central; }
.hv-legend-mean { stroke-width: 4; }
.hv-legend .hv-paxis-shaft { stroke-width: 3; }
.hv-preadout text { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.hv-preadout-value { font-family: var(--mono); font-size: 25px; font-weight: 700; fill: var(--accent); }
.hv-preadout-note { font-size: 10.5px; font-weight: 700; fill: var(--accent); dominant-baseline: central; }
.hv-preadout[data-normal="false"] .hv-preadout-note, .hv-preadout[data-normal="false"] .hv-preadout-value { fill: var(--danger); }

/* --- drag handle (HTML, so it keeps a finger-sized target at any scale) ------ */
.hv-handle {
  position: absolute;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.hv-handle[hidden] { display: none; }
.hv-dragging .hv-handle { cursor: grabbing; }
.hv-handle:focus { outline: none; }
.hv-handle:focus-visible { outline: 3px solid var(--focus, var(--primary)); outline-offset: -4px; }

/* --- caption and tools -------------------------------------------------------- */
.hv-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
  min-height: 2.5em;
  max-width: 640px;
  width: 100%;
  margin-inline: auto;
}
.hv-caption {
  flex: 1 1 14em;
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.3;
  color: var(--muted);
  min-height: 1.3em;
}
.hv-tools { display: flex; align-items: center; gap: 8px; }
.hv-tools:has(> :not([hidden])) { margin-left: auto; }
.hv-hint { font-size: 0.78rem; font-weight: 600; color: var(--axis); }
.hv-hint[hidden], .hv-reset[hidden] { display: none; }
.hv-reset {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--primary);
  cursor: pointer;
}
.hv-reset:hover { border-color: var(--primary); }
.hv-reset:focus-visible { outline: 3px solid var(--focus, var(--primary)); outline-offset: 2px; }
.hv-no-hex .hv-tools { display: none; }

/* --- narrow containers: short labels, larger type ------------------------------ */
@container (max-width: 440px) {
  .hv-label-full { display: none; }
  .hv-label-short { display: inline; }
  .hv-label text { font-size: 17px; stroke-width: 4px; }
  .hv-chamber { font-size: 21px; }
  .hv-deg { display: none; }
  .hv-deg.hv-deg-cardinal { display: inline; font-size: 14px; }
  .hv-lead-pos text { font-size: 14px; }
  .hv-lead-neg { display: none; }
  .hv-readout-title { font-size: 13px; }
  .hv-readout-value, .hv-preadout-value { font-size: 30px; }
  .hv-readout .hv-chip-text { font-size: 11.5px; }
  .hv-legend { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .hv-labels,
  .hv-hex { transition: none; }
}
