:root {
  --bg: #0a0b0e;
  --panel: rgba(19, 20, 25, 0.78);
  --panel-solid: #15161b;
  --border: rgba(255, 255, 255, 0.08);
  --border-2: rgba(255, 255, 255, 0.14);
  --text: #eceef3;
  --muted: #8d919c;
  --faint: #5d616b;
  --up: #ff9147;
  --down: #4cc9ff;
  --lad: #ffc94d;
  --lcx: #b48cff;
  --rca: #45e0b5;
  --danger: #ff5d5d;
  --sans: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "DM Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --gutter: 20px;
  --col: min(470px, 33vw);
  --dock-h: 62px;
  --ecg-h: min(42vh, 360px);
  --ecg-bottom: calc(var(--gutter) + var(--dock-h) + 14px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body { overflow: hidden; }
button { font: inherit; color: inherit; }

#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* ---------- 3D labels ---------- */
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.tag {
  position: absolute; left: 0; top: 0;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 10px 5px 9px;
  background: rgba(12, 13, 17, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 6px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.01em; white-space: nowrap;
  transform: translate(-50%, -50%);
  transition: opacity 0.25s;
  will-change: transform, opacity;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dot, #fff); box-shadow: 0 0 8px var(--dot, #fff); flex: none; }
.tag small { font-family: var(--mono); font-size: 11.5px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.tag.lead { padding: 3px 8px 3px 7px; font-size: 12px; font-family: var(--mono); font-weight: 500; }
.tag.lead::before { width: 6px; height: 6px; }
.tag.lead.hot { border-color: rgba(255, 145, 71, 0.55); color: #ffd2b3; }
.tag.lead.cold { border-color: rgba(76, 201, 255, 0.5); color: #c6ecff; }
.tag.big { font-size: 14px; padding: 7px 12px; }

.hint {
  position: absolute; left: 50%; top: 22px; transform: translateX(-50%);
  padding: 7px 14px; border-radius: 999px; background: rgba(12, 13, 17, 0.7); border: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted); pointer-events: none; transition: opacity 0.4s; white-space: nowrap;
}
.hint:empty { opacity: 0; }
.hint b { color: var(--text); font-weight: 600; }

/* ---------- brand ---------- */
.brand {
  position: absolute; left: var(--gutter); top: 18px; z-index: 5;
  display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none;
}
.brand svg { width: 64px; height: 24px; color: var(--up); filter: drop-shadow(0 0 6px rgba(255, 145, 71, 0.6)); }
.brand span { font-size: 25px; font-weight: 700; letter-spacing: 0.14em; }
.brand b { font-weight: 400; color: var(--muted); margin-left: 3px; }

/* ---------- panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.controls { position: absolute; top: var(--gutter); right: var(--gutter); width: var(--col); padding: 14px 16px 16px; z-index: 4; max-height: calc(100vh - var(--ecg-h) - var(--ecg-bottom) - var(--gutter) - 12px); overflow-y: auto; scrollbar-width: thin; }
.ctl + .ctl { margin-top: 14px; }
.ctl-label { font-size: 12.5px; color: var(--muted); margin-bottom: 7px; display: flex; justify-content: space-between; }
.ctl-label em { font-style: normal; font-family: var(--mono); color: var(--text); font-size: 12px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button {
  border: 0; background: transparent; padding: 8px 12px; border-radius: 7px; cursor: pointer;
  font-size: 13.5px; font-weight: 500; color: var(--text); display: inline-flex; align-items: center; gap: 7px;
  transition: background 0.15s, color 0.15s;
}
.seg button:hover { background: rgba(255, 255, 255, 0.06); }
.seg button.on, .seg.presets button.on { background: #f4f5f7; color: #0b0c0f; }
.seg button i { width: 7px; height: 7px; border-radius: 50%; background: var(--c, #fff); box-shadow: 0 0 6px var(--c, #fff); }
.seg.presets button { flex: 1 1 calc(33% - 4px); justify-content: flex-start; flex-direction: column; align-items: flex-start; gap: 1px; padding: 8px 10px; text-align: left; background: rgba(255, 255, 255, 0.03); }
.seg.presets button small { font-family: var(--mono); font-size: 10.5px; color: var(--muted); font-weight: 400; }
.seg.presets button.on small { color: #4b4f58; }
.ctl input[type=range] { width: 100%; accent-color: var(--up); }
.range-ticks { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.range-ticks span.on { color: var(--text); }
.ctl .note { font-size: 12px; color: var(--muted); line-height: 1.45; margin: 6px 0 0; }

/* ---------- ECG card ---------- */
.ecg-card {
  position: absolute; right: var(--gutter); bottom: var(--ecg-bottom);
  width: var(--col); height: var(--ecg-h); padding: 10px 10px 8px; z-index: 4;
  display: flex; flex-direction: column; transition: width 0.35s, height 0.35s;
}
#app:has(.ecg-card.tall) { --ecg-h: min(50vh, 440px); }
.ecg-card.expanded { width: min(1100px, calc(100vw - 2 * var(--gutter))); height: min(70vh, 620px); z-index: 9; }
.ecg-head { display: flex; align-items: center; gap: 10px; padding: 0 4px 8px; }
.ecg-title { font-weight: 600; font-size: 13.5px; }
.ecg-meta { font-family: var(--mono); font-size: 11px; color: var(--muted); flex: 1; }
.icon-btn { background: transparent; border: 0; width: 28px; height: 28px; border-radius: 6px; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.07); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.ecg-scroll { flex: 1; min-height: 0; border-radius: 7px; overflow: hidden; background: #0d0e12; }
.ecg-scroll.scrolls { overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
#ecg { width: 100%; height: 100%; display: block; }
.swipe-hint { display: none; margin-left: auto; color: var(--text); }
.ecg-card.scrolls .swipe-hint { display: inline; }
.ecg-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 7px 4px 0; font-size: 11px; color: var(--muted); }
.ecg-legend span { white-space: nowrap; }
.ecg-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

/* ---------- info (stats + story) ---------- */
.info { position: absolute; left: var(--gutter); bottom: var(--gutter); width: min(470px, calc(100vw - var(--col) - 3 * var(--gutter))); z-index: 4; display: flex; flex-direction: column; gap: 10px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px 12px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); min-width: 0; }
.stat .k { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v { font-family: var(--mono); font-size: 19px; font-weight: 500; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v.up { color: var(--up); } .stat .v.down { color: var(--down); } .stat .v.bad { color: var(--danger); } .stat .v.ok { color: var(--rca); }
.stat .v small { font-size: 12px; color: var(--muted); margin-left: 4px; }
.story { padding: 15px 18px 16px; font-size: 15px; line-height: 1.55; max-height: 40vh; overflow: auto; }
.story h1 { font-size: 25px; line-height: 1.15; margin: 0 0 10px; letter-spacing: -0.01em; }
.story h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.story p { margin: 0 0 10px; }
.story p:last-child { margin-bottom: 0; }
.story b { font-weight: 700; }
.story .up { color: var(--up); font-weight: 600; } .story .down { color: var(--down); font-weight: 600; }
.story .lad { color: var(--lad); font-weight: 600; } .story .lcx { color: var(--lcx); font-weight: 600; } .story .rca { color: var(--rca); font-weight: 600; }
.story .warn { color: var(--danger); font-weight: 600; }
.story code { font-family: var(--mono); font-size: 0.88em; background: rgba(255, 255, 255, 0.07); padding: 1px 5px; border-radius: 4px; }
.story .small { font-size: 13px; color: var(--muted); }
.story .cta { margin-top: 12px; display: inline-flex; align-items: center; gap: 8px; background: #f4f5f7; color: #0b0c0f; border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 600; font-size: 14px; cursor: pointer; }
.story .cta:hover { background: #fff; }
.plane { display: flex; gap: 12px; align-items: center; margin: 12px 0 10px; padding: 10px 12px; background: rgba(255, 255, 255, 0.03); border: 1px solid var(--border); border-radius: 9px; }
.plane svg { flex: none; width: 150px; height: 150px; }
.plane p { font-size: 13px; line-height: 1.45; margin: 0 0 6px; color: #c9ccd4; }
.plane p:last-child { margin: 0; }
.contig { display: grid; gap: 6px; margin: 10px 0 4px; }
.contig .row { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.contig .row span.lbl { font-size: 11px; color: var(--muted); width: 50px; }
.contig .chip { font-family: var(--mono); font-size: 11.5px; padding: 3px 7px; border-radius: 5px; background: rgba(255, 255, 255, 0.05); color: var(--muted); border: 1px solid transparent; }
.contig .chip.hit { color: #ffd2b3; border-color: rgba(255, 145, 71, 0.5); }
.contig .chip.met { background: var(--up); color: #1a0d04; }
.contig .chip.low { color: #c6ecff; border-color: rgba(76, 201, 255, 0.4); }

/* ---------- dock ---------- */
.dock {
  position: absolute; bottom: var(--gutter); right: var(--gutter); z-index: 5; height: var(--dock-h);
  display: flex; align-items: stretch; gap: 2px; padding: 5px;
  max-width: calc(100vw - min(470px, calc(100vw - var(--col) - 3 * var(--gutter))) - 3 * var(--gutter));
  overflow-x: auto; scrollbar-width: none;
}
.dock::-webkit-scrollbar { display: none; }
.dock button {
  border: 0; background: transparent; border-radius: 8px; cursor: pointer; padding: 6px 16px 6px 14px;
  display: grid; grid-template-columns: 8px auto; column-gap: 10px; align-items: center; text-align: left; flex: none;
  transition: background 0.15s;
}
.dock button:hover { background: rgba(255, 255, 255, 0.05); }
.dock button i { grid-row: span 2; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.dock button b { font-size: 15px; font-weight: 600; line-height: 1.2; }
.dock button small { font-size: 12.5px; color: var(--muted); line-height: 1.2; }
.dock button.on { background: #f4f5f7; color: #0b0c0f; }
.dock button.on i { background: #0b0c0f; }
.dock button.on small { color: #555a63; }
.dock button.home { grid-template-columns: auto; padding: 0 14px; }
.dock button.home svg { width: 20px; height: 20px; }

/* ---------- next-module sign-up ---------- */
.cta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.cta-row .cta { margin-top: 0; }
.story .cta.ghost { background: transparent; color: var(--text); border: 1px solid var(--border-2); }
.story .cta.ghost:hover { background: rgba(255, 255, 255, 0.06); }
.next-cta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 13.5px; color: var(--muted); }
.next-cta button { border: 0; background: rgba(255, 145, 71, 0.14); color: #ffc29a; font-weight: 600; font-size: 13.5px; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.next-cta button:hover { background: rgba(255, 145, 71, 0.24); }
.next-cta.done { color: var(--rca); }
.next-cta.done b { color: var(--text); }
.next-cta.big { display: block; padding: 14px; border: 1px solid rgba(255, 145, 71, 0.35); border-radius: 10px; background: rgba(255, 145, 71, 0.06); }
.next-cta.big p { margin: 0 0 10px; color: var(--text); font-size: 14px; }
.next-picks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.next-picks button { text-align: left; background: rgba(255, 255, 255, 0.05); color: var(--text); font-weight: 500; }
.next-picks button:hover { background: rgba(255, 145, 71, 0.18); }

.signup { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 20px; background: rgba(5, 6, 8, 0.62); opacity: 0; transition: opacity 0.2s; }
.signup[hidden] { display: none; }
.signup.open { opacity: 1; }
.signup-card { position: relative; width: min(460px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 22px 22px 16px; background: rgba(19, 20, 25, 0.97); transform: translateY(10px); transition: transform 0.2s; }
.signup.open .signup-card { transform: none; }
.signup-close { position: absolute; top: 10px; right: 10px; }
.signup h2 { font-size: 21px; line-height: 1.2; margin: 0 34px 6px 0; }
.signup-sub { color: var(--muted); margin: 0 0 14px; font-size: 14.5px; }
.signup fieldset { border: 0; margin: 0 0 12px; padding: 0; min-width: 0; }
.vote { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vote-opt { position: relative; cursor: pointer; }
.vote-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.vote-opt span { display: flex; flex-direction: column; gap: 2px; height: 100%; padding: 11px 12px; border-radius: 9px; border: 1px solid var(--border-2); background: rgba(255, 255, 255, 0.03); transition: border-color 0.15s, background 0.15s; }
.vote-opt b { font-size: 14px; font-weight: 600; }
.vote-opt small { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.vote-opt:hover span { background: rgba(255, 255, 255, 0.06); }
.vote-opt input:checked + span { border-color: var(--up); background: rgba(255, 145, 71, 0.12); box-shadow: 0 0 0 1px var(--up) inset; }
.vote-opt input:focus-visible + span { outline: 2px solid var(--down); outline-offset: 2px; }
.signup .formkit-fields { display: flex; gap: 8px; }
.signup .formkit-field { flex: 1; min-width: 0; }
.signup .formkit-input { width: 100%; height: 46px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--border-2); background: #0d0e12; color: var(--text); font: 500 16px var(--sans); }
.signup .formkit-input::placeholder { color: var(--faint); }
.signup .formkit-input:focus { outline: none; border-color: var(--up); }
.signup .formkit-submit { position: relative; flex: none; height: 46px; padding: 0 16px; border: 0; border-radius: 9px; background: #f4f5f7; color: #0b0c0f; font: 700 14.5px var(--sans); cursor: pointer; overflow: hidden; }
.signup .formkit-submit:hover { background: #fff; }
.signup .formkit-submit:disabled { opacity: 0.5; cursor: default; }
.signup .formkit-spinner { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; gap: 5px; }
.signup .formkit-spinner > div { width: 7px; height: 7px; border-radius: 50%; background: #0b0c0f; animation: signup-dot 1s infinite ease-in-out both; }
.signup .formkit-spinner > div:nth-child(2) { animation-delay: 0.15s; }
.signup .formkit-spinner > div:nth-child(3) { animation-delay: 0.3s; }
.signup .formkit-submit[data-active] .formkit-spinner { display: flex; }
.signup .formkit-submit[data-active] span { visibility: hidden; }
@keyframes signup-dot { 0%, 80%, 100% { transform: scale(0.4); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }
.signup .formkit-alert { list-style: none; margin: 0 0 10px; padding: 9px 12px; border-radius: 8px; font-size: 13px; }
.signup .formkit-alert:empty { display: none; }
.signup .formkit-alert-error { background: rgba(255, 93, 93, 0.12); border: 1px solid rgba(255, 93, 93, 0.4); color: #ffb3b3; }
.signup .formkit-alert-success { display: none; }
.signup-offline { color: #ffb3b3; font-size: 13px; margin: 8px 0 0; }
.signup-privacy { color: var(--faint); font-size: 11.5px; line-height: 1.45; margin: 10px 0 6px; }
.signup .formkit-powered-by-convertkit-container { text-align: right; }
.signup .formkit-powered-by-convertkit { color: var(--faint); font-size: 11px; text-decoration: none; }
.signup-done { text-align: center; padding: 8px 4px 6px; }
.signup-done .done-mark { width: 52px; height: 52px; margin: 4px auto 12px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; color: #0b0c0f; background: var(--rca); }
.signup-done h2 { margin: 0 0 8px; }
.signup-done p { color: var(--muted); font-size: 14.5px; line-height: 1.5; margin: 0 0 16px; }
.signup-done .cta { border: 0; border-radius: 8px; padding: 11px 18px; background: #f4f5f7; color: #0b0c0f; font-weight: 600; cursor: pointer; }

/* ---------- loader ---------- */
.loader { position: absolute; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--bg); transition: opacity 0.6s; color: var(--up); }
.loader svg { width: 200px; }
.loader .beat { stroke-dasharray: 260; stroke-dashoffset: 260; animation: trace 1.4s ease-in-out infinite; filter: drop-shadow(0 0 6px rgba(255, 145, 71, 0.8)); }
.loader p { color: var(--muted); font-size: 14px; margin: 0; }
@keyframes trace { to { stroke-dashoffset: -260; } }
#app:not(.loading) .loader { opacity: 0; pointer-events: none; }

/* ---------- mid widths: dock becomes a single row under the logo ---------- */
@media (max-width: 1480px) and (min-width: 901px) {
  .dock { top: 62px; bottom: auto; left: var(--gutter); right: auto; height: 44px; max-width: calc(100vw - var(--col) - 3 * var(--gutter)); }
  .dock button { grid-template-columns: 6px auto; padding: 6px 11px; }
  .dock button i { grid-row: auto; }
  .dock button b { font-size: 14px; }
  .dock button small { display: none; }
  .brand span { font-size: 21px; }
  .brand svg { width: 48px; }
  :root { --ecg-bottom: var(--gutter); }
  .hint { top: auto; bottom: 20px; left: auto; right: calc(var(--col) + 2 * var(--gutter)); transform: none; }
}
@media (max-width: 1180px) and (min-width: 901px) {
  .hint { display: none; }
}

/* ---------- phones / narrow ---------- */
@media (max-width: 900px) {
  :root { --gutter: 16px; --col: 100%; }
  body { overflow: auto; }
  #app { position: static; display: flex; flex-direction: column; min-height: 100%; }
  /* the heart stays pinned on top while the lesson scrolls underneath it */
  html, body { overscroll-behavior-y: none; }
  #stage { position: sticky; top: 0; height: 46vh; height: 46svh; z-index: 6; background: var(--bg); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55); }
  .brand { z-index: 7; }
  .brand { position: fixed; top: 12px; left: 16px; }
  .brand span { font-size: 18px; }
  .brand svg { width: 40px; }
  .dock { position: relative; order: 2; inset: auto; margin: 10px 16px 0; max-width: none; height: auto; z-index: 2; }
  .dock button { padding: 6px 12px; }
  .dock button b { font-size: 14px; }
  .dock button small { font-size: 11.5px; }
  .info { position: relative; order: 3; inset: auto; width: auto; margin: 10px 16px 0; z-index: 2; }
  .story { max-height: none; font-size: 15px; }
  .story h1 { font-size: 22px; }
  .stats { gap: 8px; }
  .stat { padding: 9px 11px 10px; }
  .stat .k { font-size: 11.5px; }
  .stat .v { font-size: 15px; white-space: normal; line-height: 1.25; }
  .stat .v small { display: block; margin: 2px 0 0; font-size: 11px; }
  .controls { position: relative; order: 4; inset: auto; width: auto; margin: 10px 16px 0; z-index: 2; max-height: none; }
  .ecg-card, .ecg-card.tall { position: relative; order: 5; inset: auto; width: auto; height: auto; margin: 10px 16px 24px; z-index: 2; }
  .ecg-scroll { flex: none; height: 420px; }
  .ecg-scroll.scrolls { height: auto; }
  .ecg-card.tall .ecg-scroll { height: 340px; }
  .ecg-card.expanded .ecg-scroll { flex: 1; height: auto; }
  .ecg-card.expanded { position: fixed; inset: 10px; width: auto; height: auto; margin: 0; }
  .tag { font-size: 11.5px; padding: 3px 8px 3px 7px; }
  .tag small { font-size: 10px; }
  .hint { top: auto; bottom: 10px; font-size: 11.5px; white-space: normal; text-align: center; width: max-content; max-width: calc(100% - 24px); }
  #stage { overflow: hidden; }
  .icon-btn { width: 40px; height: 40px; margin: -6px -6px -6px 0; }
  .icon-btn svg { width: 18px; height: 18px; }
  .seg.presets button { flex-basis: calc(50% - 4px); }
  .signup { place-items: end stretch; padding: 0; }
  .signup-card { width: 100%; max-height: 92svh; border-radius: 16px 16px 0 0; padding: 20px 16px calc(14px + env(safe-area-inset-bottom)); transform: translateY(40px); }
  .signup .formkit-fields { flex-direction: column; }
  .signup .formkit-submit { width: 100%; }
  html.signup-open, html.signup-open body { overflow: hidden; }
  .next-picks { grid-template-columns: 1fr; }
  .plane { flex-direction: column; align-items: center; }
  .plane svg { width: 190px; height: 190px; }
}
@media (prefers-reduced-motion: reduce) {
  .loader .beat { animation: none; stroke-dashoffset: 0; }
}
