:root {
  --bg: #05080d;
  --card: #0c121b;
  --card-2: #121a26;
  --line: #1c2735;
  --text: #dfe7f1;
  --muted: #8191a6;
  --accent: #8fc3f0;
  --accent-ink: #06121f;
  --good: #5fd38a;
  --warn: #ffc857;
  --bad: #ff6464;
  --danger: #ff5d5d;
  --ar: 1.7778;
  --side: 380px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; }
button, select, input { font: inherit; color: inherit; }

/* ---------- distribución: video a la izquierda, controles a la derecha ---------- */
.app { display: grid; grid-template-columns: minmax(0, 1fr) var(--side); height: 100dvh; }
.stage-area { display: grid; place-items: center; padding: 12px; min-width: 0; min-height: 0; background: #000; }
.side { border-left: 1px solid var(--line); background: var(--card); overflow-y: auto; overscroll-behavior: contain; min-height: 0; }

/* ---------- escenario ---------- */
.stage { position: relative; width: min(100%, calc((100dvh - 24px) * var(--ar))); aspect-ratio: var(--ar); background: #000; overflow: hidden; border-radius: 10px; }
.stage canvas, .stage video { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage video { opacity: 0; pointer-events: none; }
.stage.mirrored #bg, .stage.mirrored #gl, .stage.mirrored #track { transform: scaleX(-1); }
#labels { pointer-events: none; }
#intro { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 14px; padding: 24px;
  background: radial-gradient(ellipse at center, rgba(20, 40, 70, .55), rgba(0, 0, 0, .92) 70%); }
#intro h1 { margin: 0; font-size: clamp(26px, 5vw, 50px); letter-spacing: .18em; font-weight: 300; color: #cfe6ff; text-shadow: 0 0 24px rgba(110, 170, 255, .6); }
#intro p { max-width: 520px; margin: 0 auto; color: #b4c3d6; }
#intro .hint { font-size: 12px; color: var(--muted); }
.intro-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.stage.live #intro { display: none; }
.hud-top { position: absolute; left: 10px; top: 10px; display: flex; gap: 8px; pointer-events: none; }
#status { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(0, 0, 0, .55); color: #9fd3a8; }
#status:empty { display: none; }
#status.warn { color: var(--warn); }
#status.err { color: var(--danger); }
#recBadge { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(160, 0, 0, .75); color: #fff; }
.hud-tools { position: absolute; right: 10px; top: 10px; display: none; gap: 6px; }
.stage.live .hud-tools { display: flex; }
.hud-tools button { width: 34px; height: 34px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .15); background: rgba(0, 0, 0, .5); cursor: pointer; font-size: 14px; }
.hud-tools button:hover { background: rgba(30, 50, 80, .8); }
.hud-tools button[hidden] { display: none; }
.hud-tools button.on { background: var(--accent); color: var(--accent-ink); }
#record.on { background: #c22; color: #fff; }
#coach { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); width: min(92%, 460px); padding: 8px 12px; border-radius: 10px;
  background: rgba(4, 10, 18, .78); border: 1px solid rgba(143, 195, 240, .3); backdrop-filter: blur(4px); pointer-events: none; }
.coach-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.coach-head b { color: var(--accent); font-size: 13px; }
#coachMsg { font-size: 15px; font-weight: 600; margin-top: 2px; }
#coachMsg.good { color: var(--good); } #coachMsg.warn { color: var(--warn); } #coachMsg.bad { color: var(--bad); }

/* ---------- panel lateral ---------- */
.tabs { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: repeat(6, 1fr); background: var(--card); border-bottom: 1px solid var(--line); }
.tabs button { padding: 11px 1px 9px; border: 0; border-bottom: 2px solid transparent; background: none; cursor: pointer; font-size: 12px; color: var(--muted); }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.pane { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.pane[hidden] { display: none; }
.pane h3 { margin: 6px 0 0; font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.presets button, .seg button { padding: 6px 4px; border-radius: 7px; border: 1px solid var(--line); background: var(--card-2); cursor: pointer; font-size: 13px; }
.presets button:hover, .seg button:hover { border-color: #2c3d52; }
.layers { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 10px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.check i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.row-split { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.row-split.top { border-top: 0; padding-top: 0; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.seg.small button { padding: 2px 10px; font-size: 12px; }
.range, .select { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); align-items: center; column-gap: 12px; font-size: 13px; }
.range output { font-size: 11px; color: var(--muted); }
.range input { grid-column: 2; grid-row: 1 / span 2; width: 100%; accent-color: var(--accent); }
select { background: var(--card-2); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-align: left; font-size: 13px; }
.tip { margin: 0; font-size: 12px; color: var(--muted); }
.fine { margin: 0; font-size: 12px; color: var(--muted); }
.reps { font-size: 13px; color: var(--muted); }
.reps b { color: var(--accent); font-size: 16px; margin-left: 4px; }
kbd { font: 11px ui-monospace, monospace; padding: 0 4px; border: 1px solid var(--line); border-radius: 4px; background: var(--card-2); }

/* ---------- tabla de medidas ---------- */
.metrics { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.metrics th { text-align: left; font-weight: 500; color: var(--muted); font-size: 11px; padding: 4px 4px; border-bottom: 1px solid var(--line); }
.metrics td { padding: 5px 4px; border-bottom: 1px solid rgba(28, 39, 53, .6); white-space: nowrap; }
.metrics td:first-child { white-space: normal; }
.metrics th:not(:first-child), .metrics td:not(:first-child) { text-align: right; }
.metrics td.na { color: #4c5a6c; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #3a4656; vertical-align: 1px; }
.dot.good { background: var(--good); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.metrics tr.group td { color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; padding-top: 10px; border-bottom: 0; }

.primary, .ghost { padding: 10px 18px; border-radius: 999px; border: 1px solid var(--accent); cursor: pointer; font-weight: 600; }
.primary { background: var(--accent); color: var(--accent-ink); }
.ghost { background: transparent; color: var(--accent); }
.file input { display: none; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px; background: #13202f; border: 1px solid #24364b; z-index: 10; }
#toast.err { border-color: var(--danger); color: #ffd0d0; }

/* ---------- teléfono y pantallas angostas: video fijo arriba, controles debajo ---------- */
@media (max-width: 900px) {
  .app { display: block; height: auto; }
  .stage-area { position: sticky; top: 0; z-index: 5; padding: 0; }
  .stage { width: min(100%, calc(52dvh * var(--ar))); border-radius: 0; }
  .side { border-left: 0; overflow: visible; }
  .tabs { position: static; }
  .pane { padding: 14px 16px 28px; }
  #coach { bottom: 6px; padding: 4px 9px; }
  #coachMsg { font-size: 13px; }
  .coach-head { font-size: 11px; }
}

/* ---------- estudio médico ---------- */
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack[hidden] { display: none; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field input, .field textarea, .field select { background: var(--card-2); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; color: var(--text); font-size: 13px; width: 100%; }
.field textarea { resize: vertical; font-family: inherit; }
.btnrow button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btnrow button:disabled, .primary:disabled { opacity: .5; cursor: default; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
#testList { display: flex; flex-direction: column; gap: 6px; }
#testList .tgroup { border-top: 1px solid var(--line); padding-top: 8px; }
#testList .tgroup > b { display: block; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
#testList .tgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 10px; }
#testList .check { font-size: 12.5px; }
.presets button.on { border-color: var(--accent); color: var(--accent); }
.run-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.pill { padding: 2px 10px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); font-size: 12px; }
.pill.rec { background: #3a0d12; border-color: #8a2230; color: #ffb4bd; }
.pill.prep { color: var(--warn); }
.pill.ok { color: var(--good); }
#runTitle, #studyDone h2 { margin: 0; font-size: 18px; font-weight: 600; }
.tip.big { font-size: 14px; color: var(--text); }
.btnrow { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.btnrow button { padding: 7px 4px; border-radius: 7px; border: 1px solid var(--line); background: var(--card-2); cursor: pointer; font-size: 13px; }
.primary.small { padding: 7px 4px; border-radius: 7px; }
.runlist { margin: 0; padding-left: 20px; font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.runlist li.cur { color: var(--text); font-weight: 600; }
.runlist li.done::marker { color: var(--good); }
.runlist li.skip { text-decoration: line-through; }
.link.danger { color: var(--bad); }
#coachSub { font-size: 12px; color: #c7d3e1; margin-top: 2px; }
#coachSub:empty { display: none; }
.bar { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .12); margin-top: 6px; overflow: hidden; }
.bar[hidden] { display: none; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); }
#countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(60px, 14vw, 160px); font-weight: 200; color: #fff; text-shadow: 0 0 30px rgba(0, 0, 0, .8); pointer-events: none; }
#countdown[hidden] { display: none; }
