:root {
  --bg: #000;
  --ink: #eaf6ff;
  --muted: #8a9aa8;
  --cian: #8fd8ff;
  --amarillo: #ffe66b;
  --verde: #7dffb0;
  --rosa: #ff9ecb;
  --rojo: #ff7a7a;
  --line: rgba(143, 216, 255, .22);
  --panel: rgba(12, 17, 24, .86);
  --radius: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--bg); color-scheme: dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--cian); outline-offset: 2px; }

/* ---------- Cabecera ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px max(16px, env(safe-area-inset-left));
  max-width: 1240px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 11px;
  color: var(--cian); font-size: 20px;
  text-shadow: 0 0 10px rgba(143, 216, 255, .8);
}
.brand strong { display: block; font-size: 15px; letter-spacing: .01em; }
.brand small { color: var(--muted); font-size: 12.5px; }
.chip {
  font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--amarillo); border: 1px solid rgba(255, 230, 107, .4);
  padding: 4px 10px; border-radius: 99px;
}

main { max-width: 1240px; margin: 0 auto; padding: 0 16px 40px; }

.lesson-head { margin: 6px 0 14px; }
.level { margin: 0; color: var(--cian); font-size: 12.5px; letter-spacing: .1em; text-transform: uppercase; }
h1 { margin: 2px 0 4px; font-size: clamp(1.25rem, 2.6vw, 1.75rem); font-weight: 650; line-height: 1.2; }
.statement { margin: 0; color: #c9d6e0; font-size: 1.02rem; }
.provisional {
  margin: 10px 0 0; padding: 7px 12px; font-size: 13px;
  color: var(--amarillo); background: rgba(255, 230, 107, .07);
  border: 1px dashed rgba(255, 230, 107, .4); border-radius: 10px;
  display: inline-block;
}
.load-error {
  padding: 14px 16px; border: 1px solid rgba(255, 122, 122, .5);
  background: rgba(255, 122, 122, .08); border-radius: 12px; color: #ffd0d0;
}

/* ---------- Escena: el vidrio ---------- */
.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: max(420px, calc(100dvh - 285px));
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background:
    radial-gradient(120% 90% at 78% 110%, rgba(143, 216, 255, .10), transparent 60%),
    linear-gradient(135deg, rgba(255, 255, 255, .045), rgba(255, 255, 255, .008) 45%, rgba(255, 255, 255, .03));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .14),
    inset 0 0 60px rgba(143, 216, 255, .05),
    0 0 0 1px rgba(0, 0, 0, .6),
    0 30px 80px -30px rgba(143, 216, 255, .18);
  overflow: hidden;
  isolation: isolate;
}
/* Reflejo del vidrio: por delante de la Preparadora, por detrás del trazo */
.stage::after {
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background:
    linear-gradient(112deg, transparent 0 38%, rgba(255, 255, 255, .055) 41%, transparent 47% 62%, rgba(255, 255, 255, .03) 64%, transparent 68%);
}

.tutor {
  position: absolute; z-index: 1;
  right: 0; top: 0; bottom: 0; width: 40%;
  display: flex; align-items: flex-end; justify-content: center;
}
.tutor video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 42% 0;
  background: transparent;
}
.tutor-ph {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
}
.tutor-ph img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 42% 0; }
.ph-label {
  position: absolute; top: 14px; right: 14px; margin: 0;
  font-size: 11.5px; line-height: 1.35; text-align: right; color: var(--muted);
  z-index: 1; padding: 5px 9px; border-radius: 8px; background: rgba(0, 0, 0, .55);
}
.ph-label b { color: var(--cian); font-weight: 600; }

.caption {
  position: relative; z-index: 4; margin: 0 14px 14px; padding: 8px 12px;
  font-size: 13px; line-height: 1.4; color: #dbe7f0; text-align: center;
  background: rgba(0, 0, 0, .62); border-radius: 10px;
  max-width: 34em;
}
.caption:empty { display: none; }

/* ---------- Pizarra: trazo luminoso ---------- */
.board {
  position: absolute; z-index: 3;
  left: 0; top: 0; bottom: 0; width: 62%;
  display: flex;
}
.board-lines {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: clamp(16px, 2.6vw, 34px);
  scrollbar-width: thin; scrollbar-color: rgba(143, 216, 255, .25) transparent;
  mask-image: linear-gradient(to bottom, transparent 0, #000 22px, #000 calc(100% - 22px), transparent 100%);
}
.paso { display: none; margin-bottom: 1.1em; transition: opacity .5s; }
.paso.on { display: block; }
.paso.previo { opacity: .42; }
.paso-t {
  margin: 0 0 .5em; font-size: 12px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase; color: var(--cian);
  text-shadow: 0 0 10px rgba(143, 216, 255, .6);
}
.paso-t span { opacity: .6; margin-right: .5em; }

.ln {
  display: none;
  width: fit-content; max-width: 100%;
  margin: 0 0 .55em;
  color: var(--ink);
  font-size: clamp(1.05rem, 1.95vw, 1.6rem);
  filter: drop-shadow(0 0 5px rgba(170, 225, 255, .55)) drop-shadow(0 0 16px rgba(120, 200, 255, .22));
}
.ln.on { display: block; animation: trazo .95s cubic-bezier(.3, .1, .3, 1) both; }
.ln.nota { font-size: clamp(.92rem, 1.35vw, 1.08rem); color: #b9cbd8; font-style: italic; }
.ln.c-amarillo { color: var(--amarillo); filter: drop-shadow(0 0 5px rgba(255, 230, 107, .6)) drop-shadow(0 0 16px rgba(255, 210, 60, .25)); }
.ln.c-verde { color: var(--verde); filter: drop-shadow(0 0 5px rgba(125, 255, 176, .55)) drop-shadow(0 0 16px rgba(80, 255, 150, .22)); }
.ln.c-rosa { color: var(--rosa); filter: drop-shadow(0 0 5px rgba(255, 158, 203, .55)) drop-shadow(0 0 16px rgba(255, 110, 180, .22)); }
.ln.c-cian { color: var(--cian); }
.ln .katex { font-size: 1em; }
.ln .katex-display { margin: 0; text-align: left; }
.ln .katex-display > .katex { text-align: left; white-space: nowrap; }
@keyframes trazo {
  from { clip-path: inset(-40% 100% -40% -4%); opacity: .2; }
  to   { clip-path: inset(-40% -4% -40% -4%); opacity: 1; }
}

/* ---------- Pregunta ---------- */
.quiz {
  position: absolute; z-index: 5;
  right: 16px; top: 16px; bottom: 16px; width: min(41%, 450px);
  overflow-y: auto;
  padding: 18px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .7);
  animation: entra .35s ease both;
}
@keyframes entra { from { opacity: 0; transform: translateY(10px); } }
.quiz.nudge { animation: nudge .4s; }
@keyframes nudge { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.quiz-kicker { margin: 0 0 4px; font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--amarillo); }
.quiz-q { margin: 0 0 12px; font-size: 1.02rem; line-height: 1.45; }
.quiz-opts { display: grid; gap: 8px; }
.opt {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 48px; padding: 9px 12px; text-align: left;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .14); border-radius: 11px;
  transition: border-color .15s, background .15s;
}
.opt:hover:not(:disabled) { border-color: rgba(143, 216, 255, .6); }
.opt .key {
  flex: none; width: 26px; height: 26px; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid rgba(255, 255, 255, .3);
  font-size: 12.5px; font-weight: 600; text-transform: uppercase;
}
.opt[aria-checked="true"] { border-color: var(--cian); background: rgba(143, 216, 255, .1); }
.opt[aria-checked="true"] .key { background: var(--cian); color: #001018; border-color: var(--cian); }
.opt.mal { border-color: rgba(255, 122, 122, .7); background: rgba(255, 122, 122, .08); }
.opt.mal .key { background: var(--rojo); color: #200; border-color: var(--rojo); }
.opt.bien { border-color: var(--verde); background: rgba(125, 255, 176, .1); }
.opt.bien .key { background: var(--verde); color: #012; border-color: var(--verde); }
.opt:disabled { cursor: default; }
.opt.tried:not(.mal) { opacity: .55; }

.quiz-fb { margin-top: 12px; padding: 12px 14px; border-radius: 11px; font-size: .95rem; line-height: 1.45; }
.quiz-fb.mal { background: rgba(255, 122, 122, .08); border: 1px solid rgba(255, 122, 122, .4); }
.quiz-fb.bien { background: rgba(125, 255, 176, .08); border: 1px solid rgba(125, 255, 176, .4); }
.quiz-fb .fb-tag { display: block; margin-bottom: 3px; font-size: 11.5px; letter-spacing: .09em; text-transform: uppercase; }
.quiz-fb.mal .fb-tag { color: var(--rojo); }
.quiz-fb.bien .fb-tag { color: var(--verde); }
.quiz-fb .fb-err { display: block; font-weight: 600; margin-bottom: 4px; }
.quiz-fb ul { margin: 6px 0 0; padding-left: 1.1em; }
.quiz-fb li { margin-bottom: 6px; }

.quiz-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn {
  min-height: 44px; padding: 9px 16px; border-radius: 11px; font-weight: 600;
  background: var(--cian); color: #001018; border: 1px solid var(--cian);
}
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border-color: rgba(255, 255, 255, .25); }

/* ---------- Controles ---------- */
.controls { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.play {
  flex: none; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--cian); border: 0; color: #001018;
  box-shadow: 0 0 22px rgba(143, 216, 255, .45);
}
.play svg { width: 22px; height: 22px; fill: currentColor; }
.play .i-pause, .play.is-playing .i-play { display: none; }
.play.is-playing .i-pause { display: block; }
.track { position: relative; flex: 1; height: 44px; display: flex; align-items: center; }
.ticks { position: absolute; left: 8px; right: 8px; top: 50%; height: 0; pointer-events: none; z-index: 1; }
.tick { position: absolute; width: 2px; height: 12px; margin: -6px 0 0 -1px; background: rgba(255, 255, 255, .5); border-radius: 1px; }
.tick.q { width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; background: var(--amarillo); transform: rotate(45deg); border-radius: 2px; }
.tick.q.ok { background: var(--verde); }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 44px; margin: 0;
  background: transparent; cursor: pointer; --p: 0%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--cian) var(--p), rgba(255, 255, 255, .16) var(--p));
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .16); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--cian); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 10px rgba(143, 216, 255, .9); position: relative; z-index: 2;
}
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; }
.time { flex: none; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); min-width: 84px; text-align: right; }

.steps { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.step {
  min-height: 40px; padding: 7px 13px; border-radius: 99px; font-size: 13.5px;
  background: transparent; border: 1px solid rgba(255, 255, 255, .16); color: #c9d6e0;
}
.step b { color: var(--muted); margin-right: 6px; font-weight: 600; }
.step.actual { border-color: var(--cian); color: #fff; background: rgba(143, 216, 255, .08); }
.step.actual b { color: var(--cian); }
.step:disabled { opacity: .4; cursor: default; }

/* ---------- Móvil ---------- */
@media (max-width: 820px) {
  .stage { aspect-ratio: auto; max-height: none; display: flex; flex-direction: column; }
  .tutor { position: relative; width: 100%; height: 27dvh; min-height: 170px; flex: none; }
  .board { position: relative; width: 100%; height: 40dvh; min-height: 250px; flex: none; border-top: 1px solid rgba(143, 216, 255, .12); }
  .ln { font-size: 1.12rem; }
  .ln.nota { font-size: .95rem; }
  .ln.on { overflow-x: auto; overflow-y: hidden; }
  .quiz {
    position: relative; inset: auto; width: auto; margin: 0 10px 10px; flex: none;
    max-height: none;
  }
  .caption { font-size: 12.5px; margin: 0 10px 10px; }
  .ph-label { left: 10px; right: auto; top: 10px; max-width: 108px; text-align: left; font-size: 10.5px; }
  .time { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ln.on, .quiz { animation: none; }
}
