/* Learn the Heart — layout, theme and motion. */

:root {
  --paper: #F1ECE3;
  --paper-2: #E8E1D5;
  --card: #FBF8F3;
  --card-2: #F4EFE7;
  --ink: #1E1915;
  --ink-2: #594F47;
  --ink-3: #93887D;
  --line: rgba(30, 25, 21, .1);
  --line-2: rgba(30, 25, 21, .18);
  --accent: #BE4338;
  --accent-soft: rgba(190, 67, 56, .12);
  --blue: #4A71B0;
  --red: #C0443A;
  --spark: #D3901C;
  --valve: #A2765C;
  --muscle: #D7846F;
  --grid: rgba(30, 25, 21, .05);
  --grid-2: rgba(30, 25, 21, .085);
  --label: #3B332D;
  --halo: #F1ECE3;
  --shadow: 0 1px 0 rgba(255, 255, 255, .7) inset, 0 12px 32px -16px rgba(60, 30, 15, .28);
  --ease: cubic-bezier(.22, 1, .36, 1);
  --sans: 'Geist', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14110E;
    --paper-2: #1B1714;
    --card: #1D1916;
    --card-2: #24201C;
    --ink: #F2EBE2;
    --ink-2: #BCB0A4;
    --ink-3: #807569;
    --line: rgba(242, 235, 226, .09);
    --line-2: rgba(242, 235, 226, .17);
    --accent: #E0685C;
    --accent-soft: rgba(224, 104, 92, .14);
    --grid: rgba(242, 235, 226, .035);
    --grid-2: rgba(242, 235, 226, .06);
    --label: #D9CFC4;
    --halo: #14110E;
    --shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 14px 36px -18px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #14110E;
  --paper-2: #1B1714;
  --card: #1D1916;
  --card-2: #24201C;
  --ink: #F2EBE2;
  --ink-2: #BCB0A4;
  --ink-3: #807569;
  --line: rgba(242, 235, 226, .09);
  --line-2: rgba(242, 235, 226, .17);
  --accent: #E0685C;
  --accent-soft: rgba(224, 104, 92, .14);
  --grid: rgba(242, 235, 226, .035);
  --grid-2: rgba(242, 235, 226, .06);
  --label: #D9CFC4;
  --halo: #14110E;
  --shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 14px 36px -18px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color .4s var(--ease), color .4s var(--ease);
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
svg { display: block; }

.mono-cap {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------- App frame ---------- */

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: relative;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 34px; height: 34px; color: var(--ink-2); }
.brand-text { display: grid; gap: 1px; }
.brand-name { font-family: var(--mono); font-weight: 600; font-size: 14px; letter-spacing: .14em; }
.brand-sub { font-family: var(--mono); font-size: 9.5px; letter-spacing: .2em; color: var(--ink-3); }

.top-progress {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
.top-progress svg { width: 16px; height: 16px; fill: none; stroke: var(--ink-2); stroke-width: 1.6; stroke-linejoin: round; }
.tp-bar { width: 72px; height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.tp-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .8s var(--ease); }
.tp-count { color: var(--ink); }

.top-actions { display: flex; align-items: center; gap: 8px; }
.clock { display: grid; text-align: right; gap: 0; line-height: 1.35; padding-left: 8px; min-width: 104px; }
.clock span + span { color: var(--ink); }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  transition: background-color .2s, border-color .2s, transform .2s var(--ease);
}
.icon-btn:hover { border-color: var(--line-2); background: var(--card-2); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn.ghost:hover { background: var(--card-2); }

#soundBtn .ico-waves { opacity: 0; transition: opacity .2s; }
#soundBtn[aria-pressed="true"] .ico-waves { opacity: 1; }
#soundBtn[aria-pressed="true"] .ico-mute { opacity: 0; }
#soundBtn[aria-pressed="true"] { color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Main ---------- */

.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 392px;
  min-height: 0;
}

.stage {
  position: relative;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(var(--grid-2) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-2) 1px, transparent 1px);
  background-size: 24px 24px, 24px 24px, 120px 120px, 120px 120px;
  background-position: -1px -1px;
  overflow: hidden;
}

.stage-side {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 18px 18px;
  min-height: 0;
  z-index: 2;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

/* Narration */

.narr { padding: 18px 18px 16px; }
.narr h2 { margin: 10px 0 6px; font-size: 21px; line-height: 1.2; font-weight: 600; letter-spacing: -.01em; }
.narr p { margin: 0; color: var(--ink-2); font-size: 14.5px; line-height: 1.55; }
.narr-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -4px -6px -4px 0; }
.narr-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; }
.narr-btns { display: flex; align-items: center; gap: 8px; }
.narr-free h2 { margin-top: 8px; }
.narr .details-btn { display: none; }

.dots { display: flex; gap: 6px; align-items: center; }
.dot { width: 7px; height: 7px; border-radius: 99px; background: var(--line-2); transition: width .45s var(--ease), background-color .3s; }
.dot.past { background: var(--ink-3); }
.dot.on { width: 22px; background: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  transition: transform .2s var(--ease), background-color .2s, opacity .2s;
}
.btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; margin-right: -4px; }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { opacity: .9; }
.btn.ghost { border: 1px solid var(--line); }
.btn:active { transform: scale(.96); }

/* Monitor */

.monitor { padding: 14px 14px 12px; }
.mon-head { display: flex; align-items: center; justify-content: space-between; }
.mon-bpm { display: flex; align-items: baseline; gap: 5px; font-family: var(--mono); }
.mon-bpm b { font-size: 20px; font-weight: 600; letter-spacing: -.02em; min-width: 2.2ch; text-align: right; }
.mon-bpm small { font-size: 10px; color: var(--ink-3); letter-spacing: .1em; }
.beat-dot { width: 8px; height: 8px; border-radius: 99px; background: var(--accent); align-self: center; margin-right: 3px; opacity: .45; }
.beat-dot.pulse { animation: beat .5s var(--ease); }
@keyframes beat {
  0% { transform: scale(1); opacity: .45; box-shadow: 0 0 0 0 var(--accent-soft); }
  18% { transform: scale(1.7); opacity: 1; box-shadow: 0 0 0 6px var(--accent-soft); }
  100% { transform: scale(1); opacity: .45; box-shadow: 0 0 0 10px transparent; }
}

.ecg-wrap {
  position: relative;
  margin: 10px 0 8px;
  height: 74px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background-color: var(--card-2);
  background-image:
    linear-gradient(var(--grid-2) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-2) 1px, transparent 1px);
  background-size: 12px 12px;
  overflow: hidden;
}
#ecg { width: 100%; height: 100%; display: block; }
.ecg-head {
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 99px;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft), 0 0 12px var(--accent);
  pointer-events: none;
}

.mon-phase { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 500; }
#phaseName.flash { animation: flash .5s var(--ease); }
@keyframes flash { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.timeline { position: relative; height: 22px; margin: 8px 0 10px; cursor: ew-resize; touch-action: none; }
.tl-track { position: absolute; left: 0; right: 0; top: 8px; height: 6px; border-radius: 6px; overflow: hidden; background: var(--line); }
.tl-seg { position: absolute; top: 0; bottom: 0; }
.tl-fill { background: color-mix(in srgb, var(--blue) 45%, transparent); }
.tl-kick { background: color-mix(in srgb, var(--spark) 70%, transparent); }
.tl-iso { background: color-mix(in srgb, var(--accent) 60%, transparent); }
.tl-eject { background: var(--accent); }
.tl-relax { background: color-mix(in srgb, var(--ink-3) 60%, transparent); }
.tl-head {
  position: absolute;
  top: 3px;
  width: 4px;
  height: 16px;
  margin-left: -2px;
  border-radius: 3px;
  background: var(--ink);
  box-shadow: 0 0 0 3px var(--card);
}

.valve-states { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.vs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
  transition: color .2s, border-color .2s;
}
.vs i { width: 6px; height: 6px; border-radius: 99px; border: 1.5px solid currentColor; transition: background-color .15s; }
.vs.open { color: var(--ink); border-color: var(--line-2); }
.vs.open i { background: var(--accent); border-color: var(--accent); }
.vs:hover { border-color: var(--line-2); }

/* Canvas & SVG */

.canvas { position: relative; min-width: 0; min-height: 0; }
#heart { position: absolute; inset: 0; width: 100%; height: calc(100% - 64px); overflow: visible; outline: none; }

.tip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 4;
  pointer-events: none;
  margin-top: -40px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  translate: -50% 0;
  transition: opacity .15s;
}
.tip.show { opacity: 1; }

.controls {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  max-width: calc(100% - 24px);
  overflow-x: auto;
  scrollbar-width: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--card) 86%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  z-index: 3;
}
.controls::-webkit-scrollbar { display: none; }
.controls .icon-btn { border-color: transparent; background: transparent; flex: none; }
.controls .icon-btn:hover { background: var(--card-2); }
.sep { width: 1px; height: 22px; background: var(--line); flex: none; }

#playBtn .ico-play { display: none; }
#playBtn.paused .ico-play { display: block; fill: currentColor; }
#playBtn.paused .ico-pause { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 11px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
  flex: none;
  transition: background-color .2s, color .2s;
}
.chip i { width: 7px; height: 7px; border-radius: 99px; border: 1.5px solid var(--ink-3); transition: all .25s var(--ease); }
.chip:hover { background: var(--card-2); }
.chip[aria-pressed="true"] { color: var(--ink); background: var(--card-2); }
.chip[aria-pressed="true"] i { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#slowBtn { font-family: var(--mono); font-size: 12px; }
#slowBtn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

.bpm-ctl { display: flex; align-items: center; gap: 8px; padding: 0 6px; flex: none; }
.bpm-ctl output { font-family: var(--mono); font-size: 13px; font-weight: 600; min-width: 3ch; }
#bpm {
  -webkit-appearance: none;
  appearance: none;
  width: 104px;
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 22%), var(--line-2) var(--fill, 22%));
  cursor: pointer;
}
#bpm::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 99px;
  background: var(--card);
  border: 1.5px solid var(--ink);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
}
#bpm::-moz-range-thumb { width: 14px; height: 14px; border-radius: 99px; background: var(--card); border: 1.5px solid var(--ink); }

/* ---------- Diagram styling ---------- */

.ground { fill: #3A1D12; opacity: .14; }

.body { fill: url(#g-muscle); stroke: #8C3B30; stroke-width: 2; }
.fibers, .sheen { pointer-events: none; }
.septum { fill: rgba(130, 45, 35, .07); }
.shell { fill: url(#g-shell); stroke: #7D2F25; stroke-width: 2; }

.t-o, .t-f, .t-h { fill: none; stroke-linecap: butt; }
.t-h { stroke: rgba(255, 255, 255, .26); pointer-events: none; }
.tone-blue .t-o { stroke: #2A4878; }
.tone-blue .t-f { stroke: #4C74B4; }
.tone-blue .j-o { fill: #2A4878; }
.tone-blue .j-f { fill: #4C74B4; }
.tone-red .t-o { stroke: #7F261E; }
.tone-red .t-f { stroke: #C4463C; }
.tone-red .j-o { fill: #7F261E; }
.tone-red .j-f { fill: #C4463C; }
.coronary .t-o { stroke: #6E1F18; }
.coronary .t-f { stroke: #D1493E; }

.cavity.tone-blue .cav { fill: url(#g-blood-blue); }
.cavity.tone-red .cav { fill: url(#g-blood-red); }
.papillary { fill: #D98A77; stroke: #9C4A3C; stroke-width: 1; }

.leaflet { fill: #F5E6D7; stroke: #8E5D49; stroke-width: 1; }
.chord { stroke: #F5E6D7; stroke-width: 1.1; opacity: .85; }
.annulus { fill: #6C2A20; }
.hit { fill: transparent; }
.ring {
  fill: none;
  stroke: #FFE7C2;
  stroke-width: 1.6;
  stroke-dasharray: 3 5;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  transition: opacity .4s var(--ease);
}
.is-sel .ring { opacity: 1; animation: spin 9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.cell { pointer-events: none; }
.cell.tone-blue { fill: #DCE7FA; }
.cell.tone-red { fill: #FFE3DB; }

.e-base { fill: none; stroke: #E9A23B; stroke-width: 2; opacity: .4; stroke-linecap: round; }
.e-glow { fill: none; stroke: #FFC765; stroke-width: 9; opacity: 0; stroke-linecap: round; filter: blur(3px); }
.e-core { fill: none; stroke: #FFF1CF; stroke-width: 2.6; opacity: 0; stroke-linecap: round; }
.e-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; }
.e-twigs { fill: none; stroke: #FFD58A; stroke-width: 1.8; stroke-linecap: round; opacity: 0; }
.e-node { fill: #F2B33D; stroke: #8A5A12; stroke-width: 1.2; }
.e-halo { fill: #FFC765; opacity: .2; filter: blur(2px); }

.label { pointer-events: none; transition: opacity .45s var(--ease); }
.label-text {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .1em;
  fill: var(--label);
  paint-order: stroke;
  stroke: var(--halo);
  stroke-width: 4px;
  stroke-linejoin: round;
}
.leader { stroke: var(--label); stroke-width: 1; opacity: .55; }
.leader-dot { fill: var(--label); }
.abbr { font-family: var(--mono); font-size: 17px; font-weight: 600; fill: #fff; opacity: .92; text-anchor: middle; letter-spacing: .04em; }
.abbr-name { font-family: var(--mono); font-size: 7.5px; font-weight: 500; fill: #fff; opacity: .75; text-anchor: middle; letter-spacing: .12em; }

/* Layers */
.layer-particles, .particles-back, .layer-labels { opacity: 0; transition: opacity .5s var(--ease); }
#heart.show-flow .layer-particles, #heart.show-flow .particles-back, #heart.show-labels .layer-labels { opacity: 1; }
.layer-electrical { opacity: 0; pointer-events: none; transition: opacity .5s var(--ease); }
#heart.show-signal .layer-electrical { opacity: 1; pointer-events: auto; }
.layer-surface { opacity: 0; pointer-events: none; transition: opacity .7s var(--ease); }
#heart.show-surface .layer-surface { opacity: 1; pointer-events: auto; }
#heart.show-surface .layer-particles, #heart.show-surface .particles-back, #heart.show-surface .layer-electrical { opacity: 0; pointer-events: none; }
#heart.show-surface .layer-labels .chamber-label { opacity: 0; }

/* Interaction */
#heart [data-part] { cursor: pointer; transition: opacity .5s var(--ease), filter .3s var(--ease); outline: none; }
#heart [data-part]:hover, #heart [data-part]:focus-visible { filter: brightness(1.07) saturate(1.06); }
#heart.has-sel [data-part]:not(.is-sel) { opacity: .24; }
#heart.has-sel .layer-particles, #heart.has-sel .particles-back { opacity: .35; }
#heart.has-sel.show-surface .shell { opacity: 1; }
#heart.has-sel .label:not(.is-sel) { opacity: .18; }
#heart .is-sel { filter: drop-shadow(0 0 1px rgba(255, 236, 214, .9)) drop-shadow(0 4px 14px rgba(110, 35, 20, .35)); }
#heart .is-sel:hover { filter: drop-shadow(0 0 1px rgba(255, 236, 214, .9)) drop-shadow(0 4px 14px rgba(110, 35, 20, .35)) brightness(1.05); }

/* ---------- Panel ---------- */

.panel {
  border-left: 1px solid var(--line);
  background: var(--card);
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
}
.panel-inner { padding: 22px 22px 18px; display: flex; flex-direction: column; min-height: 100%; }
.sheet-handle { display: none; }

.p-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.p-kicker { display: inline-flex; align-items: center; gap: 8px; }
.p-nav { display: flex; gap: 6px; }
.p-top h1 { margin: 14px 0 6px; font-size: 30px; line-height: 1.1; font-weight: 600; letter-spacing: -.02em; }
.p-sum { margin: 0; font-size: 15.5px; color: var(--ink-2); line-height: 1.5; }
.p-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }

.tone-dot { width: 8px; height: 8px; border-radius: 99px; flex: none; display: inline-block; }
.tone-dot.tone-blue { background: var(--blue); }
.tone-dot.tone-red { background: var(--red); }
.tone-dot.tone-muscle { background: var(--muscle); }
.tone-dot.tone-valve { background: var(--valve); }
.tone-dot.tone-spark { background: var(--spark); }

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  border-radius: 7px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  font-weight: 500;
}
.badge.tone-blue { background: color-mix(in srgb, var(--blue) 14%, transparent); color: color-mix(in srgb, var(--blue) 80%, var(--ink)); }
.badge.tone-red { background: color-mix(in srgb, var(--red) 13%, transparent); color: color-mix(in srgb, var(--red) 82%, var(--ink)); }
.badge.tone-muscle { background: color-mix(in srgb, var(--muscle) 18%, transparent); color: color-mix(in srgb, var(--muscle) 60%, var(--ink)); }
.badge.tone-valve { background: color-mix(in srgb, var(--valve) 16%, transparent); color: color-mix(in srgb, var(--valve) 70%, var(--ink)); }
.badge.tone-spark { background: color-mix(in srgb, var(--spark) 16%, transparent); color: color-mix(in srgb, var(--spark) 70%, var(--ink)); }
.badge.ghost { border: 1px solid var(--line); color: var(--ink-3); }

.tabs {
  position: relative;
  display: flex;
  gap: 2px;
  margin: 22px -22px 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tab {
  padding: 10px 8px 11px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
  transition: color .2s;
}
.tab:hover { color: var(--ink-2); }
.tab[aria-selected="true"] { color: var(--ink); }
.tab-ind {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 2px;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: transform .5s var(--ease), width .5s var(--ease);
}

.p-body { padding: 20px 0 8px; flex: 1; }
.lead { margin: 0 0 16px; font-size: 15px; line-height: 1.65; color: var(--ink); }
.points { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.points li {
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 11px 12px;
  border-radius: 12px;
  background: var(--card-2);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-2);
}
.pt-mark { width: 6px; height: 6px; border-radius: 2px; background: var(--accent); flex: none; transform: translateY(-1px) rotate(45deg); }

.steps { list-style: none; margin: 0; padding: 0; position: relative; }
.steps li { position: relative; display: flex; gap: 14px; padding-bottom: 18px; }
.steps li:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 15px;
  top: 32px;
  bottom: 2px;
  width: 1px;
  background: var(--line-2);
}
.step-n {
  width: 31px;
  height: 31px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid var(--line-2);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  background: var(--card);
}
.steps p { margin: 5px 0 0; font-size: 14.5px; line-height: 1.55; color: var(--ink-2); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { padding: 14px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line); }
.stat-v { font-family: var(--mono); font-size: 24px; font-weight: 600; letter-spacing: -.03em; line-height: 1.1; }
.stat-v small { font-size: 11px; font-weight: 500; color: var(--ink-3); margin-left: 4px; letter-spacing: .02em; }
.stat-l { margin-top: 6px; font-size: 12.5px; line-height: 1.4; color: var(--ink-2); }

.issue { padding: 14px 14px 13px; border-radius: 12px; border: 1px solid var(--line); margin-bottom: 8px; }
.issue h3 { margin: 0 0 4px; font-size: 14.5px; font-weight: 600; }
.issue p { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--ink-2); }
.note { margin: 12px 0 0; font-size: 12.5px; color: var(--ink-3); line-height: 1.5; }

.cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding: 13px 14px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
}
.cta:hover { opacity: .92; }

.p-related { padding: 14px 0 6px; border-top: 1px solid var(--line); }
.rel-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.rel {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-2);
  transition: border-color .2s, color .2s, transform .2s var(--ease);
}
.rel:hover { border-color: var(--line-2); color: var(--ink); transform: translateY(-1px); }
.p-foot { margin-top: 14px; font-size: 11.5px; color: var(--ink-3); }
.p-foot a { color: var(--ink-2); text-underline-offset: 2px; }

/* Staggered entrance used across panel, narration and tab content */
.swap > *, .swap > .steps > li, .swap > .stats > .stat, .swap > .points > li {
  animation: rise .6s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 50ms);
}
.swap > .steps, .swap > .stats, .swap > .points { animation: none; }
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); filter: blur(5px); }
  to { opacity: 1; transform: none; filter: blur(0); }
}

/* ---------- Lessons strip ---------- */

.lessons {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  overflow-x: auto;
  scrollbar-width: none;
}
.lessons::-webkit-scrollbar { display: none; }
.lesson {
  position: relative;
  flex: 1 0 168px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  text-align: left;
  overflow: hidden;
  transition: border-color .25s, transform .3s var(--ease), box-shadow .3s;
}
.lesson:hover { border-color: var(--line-2); transform: translateY(-2px); }
.lesson.active { border-color: var(--ink); box-shadow: var(--shadow); }
.l-icon {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--card-2);
  color: var(--ink-2);
}
.lesson.active .l-icon { background: var(--accent); color: #fff; }
.l-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.l-text { display: grid; gap: 1px; min-width: 0; }
.l-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.l-check {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 16px;
  height: 16px;
  border-radius: 99px;
  background: var(--accent);
  display: grid;
  place-items: center;
  transform: scale(0);
  transition: transform .4s var(--ease);
}
.l-check svg { width: 11px; height: 11px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.lesson.done .l-check { transform: scale(1); }
.l-bar { position: absolute; left: 12px; right: 12px; bottom: 6px; height: 2px; border-radius: 2px; background: var(--line); overflow: hidden; }
.l-bar i { display: block; height: 100%; background: var(--accent); transition: width .6s var(--ease); }

/* ---------- Responsive ---------- */

@media (max-width: 1240px) {
  .main { grid-template-columns: minmax(0, 1fr) 350px; }
  .stage { grid-template-columns: 272px minmax(0, 1fr); }
  .clock { display: none; }
}

@media (max-width: 1040px) {
  .main { grid-template-columns: minmax(0, 1fr) 320px; }
  .stage { grid-template-columns: 248px minmax(0, 1fr); }
  .chip { padding: 0 9px; }
  #bpm { width: 80px; }
}

@media (max-width: 899px) {
  .app { height: auto; min-height: 100dvh; grid-template-rows: 56px auto auto; }
  .topbar { padding: 0 14px; gap: 12px; position: sticky; top: 0; }
  .brand-sub { display: none; }
  .brand-name { font-size: 12.5px; white-space: nowrap; }
  .brand-mark { width: 28px; height: 28px; }
  .top-progress .mono-cap:not(.tp-count), .tp-bar { display: none; }
  .top-progress { padding: 6px 9px; }
  .main { display: block; }
  .stage { display: flex; flex-direction: column; overflow: visible; }
  .canvas { order: 1; height: calc(56svh - 56px); min-height: 330px; }
  #heart { height: calc(100% - 58px); }
  .controls { bottom: 8px; padding: 4px; gap: 2px; }
  .stage-side { order: 2; padding: 0 14px 14px; gap: 12px; }
  .narr h2 { font-size: 19px; }
  .narr .details-btn { display: inline-flex; margin-top: 12px; width: 100%; justify-content: center; }
  .lessons { padding: 12px 14px 18px; }
  .lesson { flex: 0 0 156px; }

  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: min(46dvh, 520px);
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -18px 50px -20px rgba(0, 0, 0, .35);
    transform: translateY(105%);
    transition: transform .55s var(--ease);
    z-index: 20;
  }
  body.sheet-open .panel { transform: none; }
  .sheet-handle {
    display: block;
    position: sticky;
    top: 0;
    width: 100%;
    height: 22px;
    background: var(--card);
    z-index: 2;
  }
  .sheet-handle::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 9px;
    width: 40px;
    height: 4px;
    margin-left: -20px;
    border-radius: 4px;
    background: var(--line-2);
  }
  .panel-inner { padding-top: 4px; }
  .p-top h1 { font-size: 25px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
