/* Academia IVI — sala oscura, llama naranja del Instituto. Sin estilos en línea (CSP): los anchos se ponen por CSSOM. */
:root {
  --bg: #0c0a09;
  --bg-2: #120f0d;
  --surface: #191512;
  --raised: #221c18;
  --line: #2f2723;
  --line-strong: #43382f;
  --ink: #f6f0e9;
  --muted: #b8aa9e;
  --faint: #9a8c80;
  --flame: #e8672a;
  --flame-hi: #f4874a;
  --flame-deep: #b8481a;
  --flame-btn: #c2410c; /* naranja de acción: 5,2:1 con texto blanco (el --flame puro da 3,3:1) */
  --flame-btn-hi: #9a3412;
  --ember: #f2a650;
  --ok: #67c79a;
  --danger: #f08a7f;
  --focus: #ffb37f;
  --radius: 10px;
  --radius-lg: 16px;
  --gutter: clamp(16px, 4vw, 56px);
  --header: 68px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header) + 12px); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--flame-hi); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; padding: 10px 16px; background: var(--ink); color: var(--bg); border-radius: 8px; font-weight: 700; }
.skip:focus { top: 12px; }
main:focus, [tabindex="-1"]:focus { outline: none; }
.noscript { padding: 40px; text-align: center; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.boot img { width: 34px; animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.35; transform: scale(0.94); } }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 46px; padding: 0 22px; border-radius: 8px; border: 0;
  font-weight: 800; font-size: 15px; letter-spacing: 0.01em; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: transform 0.15s var(--ease), background 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.play { background: var(--ink); color: #120d0a; }
.btn.play:hover { background: #fff; }
.btn.flame { background: var(--flame-btn); color: #fff; }
.btn.flame:hover { background: var(--flame-btn-hi); }
.btn.glass { background: rgba(120, 104, 94, 0.42); color: var(--ink); backdrop-filter: blur(6px); }
.btn.glass:hover { background: rgba(140, 122, 110, 0.55); }
.btn.line { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
.btn.line:hover { box-shadow: inset 0 0 0 1px var(--muted); }
.btn.done { background: rgba(103, 199, 154, 0.14); color: var(--ok); box-shadow: inset 0 0 0 1px rgba(103, 199, 154, 0.4); }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.link-btn { border: 0; background: none; padding: 0; color: var(--flame-hi); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Encabezado ---------- */
.top {
  position: fixed; inset: 0 0 auto; z-index: 40; height: var(--header);
  display: flex; align-items: center; gap: 28px; padding: 0 var(--gutter);
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(180deg, rgba(12, 10, 9, 0.9), rgba(12, 10, 9, 0));
  transition: background 0.3s;
}
.top.solid { background: rgba(12, 10, 9, 0.96); box-shadow: 0 1px 0 var(--line); backdrop-filter: blur(10px); }
.wordmark { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; flex: none; }
.wordmark img { width: 20px; height: auto; }
.wordmark span { font-family: Cinzel, Georgia, serif; font-weight: 600; font-size: 15px; letter-spacing: 0.2em; }
.wordmark small { display: block; font-family: Manrope, sans-serif; font-size: 10px; letter-spacing: 0.22em; color: var(--muted); text-transform: uppercase; margin-top: -2px; }
.top nav { display: flex; gap: 20px; min-width: 0; }
.top nav a { color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap; }
.top nav a:hover, .top nav a[aria-current="page"] { color: var(--ink); }
.top nav a[aria-current="page"] { font-weight: 800; }
.top .spacer { flex: 1; }
.user { display: contents; }
.avatar-btn {
  display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 4px; cursor: pointer; border-radius: 10px;
}
.avatar {
  width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--flame-btn), var(--flame-deep)); color: #fff; font-weight: 800; font-size: 14px;
}
.avatar-btn svg { width: 14px; height: 14px; color: var(--muted); transition: transform 0.2s; }
.avatar-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.menu {
  position: absolute; right: var(--gutter); top: calc(var(--header) - 6px); min-width: 230px;
  background: rgba(20, 16, 14, 0.98); border: 1px solid var(--line); border-radius: 12px; padding: 8px; box-shadow: var(--shadow);
}
.menu[hidden] { display: none; }
.menu .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu .who strong { display: block; font-size: 14px; }
.menu .who span { font-size: 13px; color: var(--muted); word-break: break-all; }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px; border: 0; background: none; color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 600; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--raised); }

main { display: block; min-height: 100vh; }
.page-pad { padding: calc(var(--header) + 28px) var(--gutter) 80px; }

/* ---------- Hero ---------- */
.hero { position: relative; min-height: min(86vh, 760px); display: flex; align-items: flex-end; overflow: hidden; isolation: isolate; }
.hero .art { position: absolute; inset: 0; z-index: -2; }
.hero .art img, .hero .art .fallback { width: 100%; height: 100%; object-fit: cover; }
.hero .art::after {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(90deg, rgba(12, 10, 9, 0.94) 0%, rgba(12, 10, 9, 0.7) 34%, rgba(12, 10, 9, 0.08) 70%),
    linear-gradient(0deg, var(--bg) 0%, rgba(12, 10, 9, 0) 38%);
}
.hero .copy { width: min(640px, 100%); padding: 0 var(--gutter) clamp(48px, 10vh, 110px); animation: rise 0.7s var(--ease) both; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 800; letter-spacing: 0.22em; text-transform: uppercase; color: var(--flame-hi); margin-bottom: 14px; }
.eyebrow img { width: 12px; }
.hero h1 { margin: 0; font-size: clamp(34px, 6vw, 66px); line-height: 1.02; font-weight: 800; letter-spacing: -0.03em; text-wrap: balance; }
.hero .sub { margin: 12px 0 0; font-size: clamp(17px, 2vw, 21px); font-weight: 600; color: var(--ink); opacity: 0.92; }
.hero .desc { margin: 14px 0 0; color: var(--muted); font-size: 16px; max-width: 54ch; }
.hero .desc p { margin: 0 0 8px; }
.hero .desc p:last-child { margin-bottom: 0; }
.hero .desc.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.desc-toggle { margin-top: 6px; font-size: 14px; }
.hero .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 16px; font-size: 14px; color: var(--muted); font-weight: 600; }
.hero .meta .sep { width: 4px; height: 4px; border-radius: 50%; background: var(--faint); }
.hero .actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.hero .resume-note { margin-top: 12px; font-size: 14px; color: var(--muted); }
.hero .resume-note strong { color: var(--ink); }
.hero.course { min-height: min(70vh, 620px); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

.bar { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.16); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--flame); border-radius: inherit; }
.hero .progress { display: flex; align-items: center; gap: 12px; margin-top: 18px; max-width: 360px; font-size: 13px; font-weight: 700; color: var(--muted); }
.hero .progress .bar { flex: 1; }

/* ---------- Filas ---------- */
.rows { position: relative; z-index: 2; margin-top: -40px; padding-bottom: 80px; }
.row { margin: 0 0 clamp(28px, 4vw, 44px); }
.row-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 0 var(--gutter); margin-bottom: 4px; }
.row-head h2 { margin: 0; font-size: clamp(18px, 2vw, 22px); font-weight: 800; letter-spacing: -0.01em; }
.row-head a { font-size: 14px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.row-head a:hover { text-decoration: underline; }
.rail-wrap { position: relative; }
.rail {
  display: grid; grid-auto-flow: column; grid-auto-columns: var(--card-w, clamp(240px, 26vw, 330px)); gap: 12px;
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scroll-padding: 0 var(--gutter);
  padding: 10px var(--gutter) 20px; scrollbar-width: none;
  --fade: clamp(24px, 4vw, 56px); --fl: 0px; --fr: 0px;
}
/* Fundido en los bordes que aún tienen más contenido (clases puestas por bindRails). */
.rail-wrap.can-prev .rail { --fl: var(--fade); }
.rail-wrap.can-next .rail { --fr: var(--fade); }
.rail-wrap.can-prev .rail, .rail-wrap.can-next .rail {
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%);
}
.rail::-webkit-scrollbar { display: none; }
.rail > * { scroll-snap-align: start; }
.rail.courses { --card-w: clamp(260px, 31vw, 420px); }
.rail-btn {
  position: absolute; top: 10px; bottom: 20px; width: calc(var(--gutter) - 4px); min-width: 44px; z-index: 3;
  border: 0; background: rgba(12, 10, 9, 0.55); color: var(--ink); cursor: pointer; display: grid; place-items: center;
  opacity: 0; transition: opacity 0.2s;
}
.rail-btn svg { width: 26px; height: 26px; }
.rail-btn { transition: opacity 0.2s, background 0.15s; }
.rail-btn:hover { background: rgba(12, 10, 9, 0.85); }
.rail-btn.prev { left: 0; border-radius: 0 8px 8px 0; }
.rail-btn.next { right: 0; border-radius: 8px 0 0 8px; }
.rail-wrap:hover .rail-btn:not([hidden]), .rail-btn:focus-visible { opacity: 1; }
.rail-btn[hidden] { display: none; }
@media (hover: none) { .rail-btn { display: none; } }

/* ---------- Tarjetas ---------- */
.card { position: relative; display: block; color: inherit; text-decoration: none; border-radius: var(--radius); transition: transform 0.3s var(--ease); }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04); transition: box-shadow 0.25s; }
.thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s var(--ease); }
.thumb::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0) 55%); pointer-events: none; }
.thumb .bar { position: absolute; left: 10px; right: 10px; bottom: 9px; z-index: 2; height: 3px; }
.thumb .badge { position: absolute; top: 9px; left: 9px; z-index: 2; display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 800; letter-spacing: 0.04em; background: rgba(12, 10, 9, 0.78); color: var(--ink); backdrop-filter: blur(4px); }
.thumb .badge svg { width: 12px; height: 12px; }
.thumb .badge.ok { color: var(--ok); }
.thumb .dur { position: absolute; right: 9px; top: 9px; z-index: 2; padding: 2px 7px; border-radius: 6px; font-size: 12px; font-weight: 700; background: rgba(12, 10, 9, 0.78); }
.thumb .play-badge {
  position: absolute; z-index: 2; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(12, 10, 9, 0.6); border: 2px solid rgba(255, 255, 255, 0.85);
  opacity: 0; transform: scale(0.85); transition: opacity 0.2s, transform 0.25s var(--ease);
}
.thumb .play-badge svg { width: 22px; height: 22px; margin-left: 3px; }
.card .label { padding: 10px 2px 0; }
.card .label strong { display: block; font-size: 15px; font-weight: 700; line-height: 1.3; }
.card .label span { display: block; font-size: 13px; color: var(--muted); margin-top: 3px; }
.card.overlay .label { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; padding: 14px 16px 18px; }
.card.overlay .label strong { font-size: clamp(17px, 1.6vw, 21px); font-weight: 800; letter-spacing: -0.01em; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6); }
.card.overlay .thumb::after { background: linear-gradient(0deg, rgba(0, 0, 0, 0.82), rgba(0, 0, 0, 0) 65%); }
.card.overlay .thumb .bar { bottom: 10px; left: 16px; right: 16px; }
.card.overlay .label { padding-bottom: 26px; }
@media (hover: hover) {
  .card:hover .thumb img { transform: scale(1.05); }
  .card:hover .play-badge { opacity: 1; transform: none; }
  .rail .card:hover { transform: translateY(-4px); }
  .card:hover .thumb { box-shadow: 0 0 0 2px var(--flame), 0 16px 32px rgba(0, 0, 0, 0.55); }
}
.card:focus-visible { outline: none; }
.card:focus-visible .thumb { box-shadow: 0 0 0 3px var(--focus), 0 16px 32px rgba(0, 0, 0, 0.55); }
.card:focus-visible { transform: translateY(-4px); }

/* Portada de respaldo: llama y título sobre un degradado (cada contenido con su tono). */
.fallback { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 10px; padding: 16px; text-align: center; overflow: hidden; }
.fallback::before { content: ""; position: absolute; inset: 0; z-index: 0; background: url("/assets/cover-default.jpg") center / cover no-repeat; opacity: 0.45; mix-blend-mode: screen; }
.fallback > * { position: relative; z-index: 1; }
.fallback img { width: 15%; min-width: 22px; max-width: 64px; height: auto; object-fit: contain; filter: drop-shadow(0 6px 20px rgba(232, 103, 42, 0.5)); transform: none !important; }
.fallback b { font-family: Cinzel, Georgia, serif; font-weight: 600; font-size: clamp(12px, 1.3vw, 17px); letter-spacing: 0.08em; text-transform: uppercase; color: rgba(246, 240, 233, 0.9); line-height: 1.25; max-width: 90%; }
.fallback.v0 { background: radial-gradient(120% 90% at 20% 10%, #5a2410 0%, #1d120d 55%, #0f0b09 100%); }
.fallback.v1 { background: radial-gradient(120% 90% at 80% 20%, #6b3a12 0%, #24160d 55%, #0f0b09 100%); }
.fallback.v2 { background: radial-gradient(120% 100% at 50% 0%, #4a1c22 0%, #1c1013 55%, #0f0b09 100%); }
.fallback.v3 { background: radial-gradient(120% 90% at 10% 90%, #613011 0%, #1f140e 60%, #0f0b09 100%); }
.fallback.v4 { background: radial-gradient(130% 90% at 90% 80%, #3d2a14 0%, #1b140d 55%, #0f0b09 100%); }
.hero .fallback b, .lesson-player .fallback b { display: none; }
.hero .fallback img { position: absolute; right: 12%; top: 50%; width: min(22vw, 220px); max-width: none; transform: translateY(-50%) !important; opacity: 0.85; }

/* ---------- Programa ---------- */
.course-body { padding: 8px var(--gutter) 80px; max-width: 1400px; }
.season { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; margin: 0 0 18px; }
.season h2 { margin: 0; font-size: 22px; font-weight: 800; }
.select-wrap { position: relative; }
.select-wrap select {
  appearance: none; min-height: 44px; padding: 0 44px 0 16px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--raised); font-weight: 700; font-size: 15px; cursor: pointer; max-width: 82vw;
}
.select-wrap svg { position: absolute; right: 14px; top: 50%; width: 16px; height: 16px; margin-top: -8px; pointer-events: none; color: var(--muted); }
.module-desc { margin: -6px 0 20px; color: var(--muted); max-width: 70ch; }
.module-empty { margin: 0 0 20px; padding: 16px 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-weight: 600; }
.episodes { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.episode { border-bottom: 1px solid var(--line); }
.episode > a, .episode > div {
  display: grid; grid-template-columns: 32px clamp(130px, 18vw, 210px) 1fr; gap: 6px 20px; align-items: center;
  padding: 18px 14px; color: inherit; text-decoration: none; border-radius: var(--radius);
}
.episode > a:hover { background: var(--surface); }
.episode .num { font-size: 22px; font-weight: 700; color: var(--faint); text-align: center; }
.episode .thumb { box-shadow: none; }
.episode .info { min-width: 0; }
.episode .info .head { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; }
.episode .info strong { font-size: 16px; font-weight: 700; line-height: 1.3; }
.episode .info time { flex: none; font-size: 14px; color: var(--muted); font-weight: 600; }
.episode .info p { margin: 6px 0 0; font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.episode .tags { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.episode .tags .ok { color: var(--ok); }
.episode .tags span { display: inline-flex; align-items: center; gap: 5px; }
.episode .tags svg { width: 14px; height: 14px; }
.episode.locked > div { opacity: 0.55; }
.episode.locked .thumb::before { content: ""; position: absolute; inset: 0; z-index: 1; background: rgba(12, 10, 9, 0.5); }
.lock { position: absolute; z-index: 2; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; color: var(--ink); }
@media (hover: hover) { .episode > a:hover .play-badge { opacity: 1; transform: none; } }

/* ---------- Clase ---------- */
.lesson-page { padding-top: var(--header); }
.lesson-player { position: relative; background: #000; }
.lesson-player .frame { position: relative; width: min(100%, calc((100vh - var(--header) - 120px) * 16 / 9)); min-width: min(100%, 560px); margin: 0 auto; aspect-ratio: 16 / 9; background: #000; }
.lesson-player video, .lesson-player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }
.lesson-player .novideo { position: absolute; inset: 0; }
/* Tapa el botón de Drive que abre el video fuera de la Academia (esquina superior derecha del reproductor). */
.lesson-player .drive-shield { position: absolute; top: 0; right: 0; width: 96px; height: 72px; z-index: 2; }
.lesson-player .novideo img:not(.mark) { width: 100%; height: 100%; object-fit: cover; opacity: 0.4; }
.lesson-player .novideo p { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: 20px var(--gutter); background: linear-gradient(0deg, rgba(0, 0, 0, 0.8), transparent); color: var(--muted); font-weight: 600; text-align: center; }
.embed-note { margin: 0; padding: 10px var(--gutter); background: var(--bg-2); color: var(--muted); font-size: 14px; text-align: center; }
.up-next {
  position: absolute; right: 18px; bottom: 70px; z-index: 5; width: min(340px, calc(100% - 36px));
  background: rgba(18, 14, 12, 0.94); border: 1px solid var(--line-strong); border-radius: 12px; padding: 14px; box-shadow: var(--shadow);
  animation: rise 0.35s var(--ease) both;
}
.up-next small { display: block; font-size: 12px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--flame-hi); }
.up-next .info { min-width: 0; }
.up-next strong { display: block; margin: 4px 0 12px; font-size: 16px; line-height: 1.3; }
.up-next .actions { display: flex; gap: 8px; }
.up-next .count { font-variant-numeric: tabular-nums; }

.lesson-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 360px); gap: 40px; padding: 28px var(--gutter) 90px; max-width: 1320px; margin: 0 auto; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 10px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink); text-decoration: underline; }
.crumbs svg { width: 12px; height: 12px; opacity: 0.6; }
.lesson-body h1 { margin: 0; font-size: clamp(26px, 3.4vw, 38px); line-height: 1.1; font-weight: 800; letter-spacing: -0.02em; text-wrap: balance; }
.lesson-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 26px; }
.prose { color: #ddd2c7; max-width: 70ch; font-size: 16px; line-height: 1.7; }
.prose p { margin: 0 0 14px; }
.prose a { word-break: break-word; }
.section-title { margin: 34px 0 14px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-title h2 { margin: 0; font-size: 19px; font-weight: 800; }
.section-title span { font-size: 14px; font-weight: 700; color: var(--muted); }
.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.task label {
  display: grid; grid-template-columns: 26px 1fr; gap: 14px; align-items: start; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.task label:hover { border-color: var(--line-strong); }
.task input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.task .box { width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line-strong); display: grid; place-items: center; transition: background 0.15s, border-color 0.15s; margin-top: 1px; }
.task .box svg { width: 15px; height: 15px; color: #fff; opacity: 0; transform: scale(0.6); transition: opacity 0.15s, transform 0.2s var(--ease); }
.task input:checked + .box { background: var(--flame); border-color: var(--flame); }
.task input:checked + .box svg { opacity: 1; transform: none; }
.task input:focus-visible + .box { outline: 2px solid var(--focus); outline-offset: 2px; }
.task .text { line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.task input:disabled + .box { opacity: 0.6; }
.task input:checked ~ .text { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(184, 170, 158, 0.5); }
.tasks-done { margin-top: 14px; padding: 14px 16px; border-radius: 12px; background: rgba(232, 103, 42, 0.1); border: 1px solid rgba(232, 103, 42, 0.35); color: var(--ember); font-weight: 700; display: flex; gap: 10px; align-items: center; animation: rise 0.4s var(--ease) both; }
.tasks-done img { width: 14px; }

.side-list { position: sticky; top: calc(var(--header) + 20px); align-self: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; max-height: calc(100vh - var(--header) - 40px); overflow: auto; }
.side-list h2 { margin: 2px 4px 2px; font-size: 16px; font-weight: 800; }
.side-list .sub { margin: 0 4px 12px; font-size: 13px; color: var(--muted); }
.side-list ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.side-list li a, .side-list li > div { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; padding: 8px; border-radius: 10px; color: inherit; text-decoration: none; }
.side-list li a:hover { background: var(--raised); }
.side-list li a[aria-current="page"] { background: var(--raised); box-shadow: inset 3px 0 0 var(--flame); }
.side-list li > div { opacity: 0.5; }
.side-list .thumb { border-radius: 6px; }
.side-list .thumb .bar { left: 6px; right: 6px; bottom: 5px; }
.side-list strong { display: block; font-size: 14px; line-height: 1.3; font-weight: 700; }
.side-list small { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 3px; font-weight: 600; }
.side-list small svg { width: 12px; height: 12px; }
.side-list small.ok { color: var(--ok); }

/* ---------- Acceso (entrar, activar, recuperar) ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 40px 16px; position: relative; overflow: hidden; isolation: isolate; }
.auth::after {
  content: ""; position: absolute; inset: 0; z-index: -2;
  background: linear-gradient(180deg, rgba(12, 10, 9, 0.35) 0%, rgba(12, 10, 9, 0.7) 32%, rgba(12, 10, 9, 0.94) 55%, var(--bg) 72%), url("/assets/auth-hero.jpg") center top / cover no-repeat;
}
.auth::before {
  content: ""; position: absolute; inset: -20%; z-index: -1;
  background:
    radial-gradient(40% 35% at 50% 22%, rgba(232, 103, 42, 0.32), transparent 70%),
    radial-gradient(60% 50% at 80% 100%, rgba(184, 72, 26, 0.18), transparent 70%),
    radial-gradient(50% 45% at 0% 70%, rgba(242, 166, 80, 0.08), transparent 70%);
  animation: glow 12s ease-in-out infinite alternate;
}
@keyframes glow { to { transform: translate3d(0, -3%, 0) scale(1.06); } }
.auth-card { width: min(420px, 100%); animation: rise 0.6s var(--ease) both; }
.auth-brand { text-align: center; margin-bottom: 28px; }
.auth-brand img { width: 58px; margin: 0 auto 16px; filter: drop-shadow(0 10px 30px rgba(232, 103, 42, 0.45)); }
.auth-brand .name { font-family: Cinzel, Georgia, serif; font-weight: 600; font-size: 15px; letter-spacing: 0.24em; color: var(--muted); }
.auth-brand h1 { margin: 10px 0 0; font-size: clamp(28px, 6vw, 34px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.auth-brand p { margin: 10px auto 0; color: var(--muted); max-width: 34ch; }
.form { display: grid; gap: 14px; padding: 26px; background: rgba(25, 21, 18, 0.86); border: 1px solid var(--line); border-radius: var(--radius-lg); backdrop-filter: blur(12px); box-shadow: var(--shadow); }
.field { display: grid; gap: 6px; }
.field > span, .field > label { font-size: 14px; font-weight: 700; color: var(--muted); }
.input-wrap { position: relative; }
.form input[type="email"], .form input[type="password"], .form input[type="text"] {
  width: 100%; height: 50px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: #110e0c; font-size: 16px; transition: border-color 0.15s, box-shadow 0.15s;
}
.form input:focus { outline: none; border-color: var(--flame); box-shadow: 0 0 0 3px rgba(232, 103, 42, 0.25); }
.form input[aria-invalid="true"] { border-color: var(--danger); }
.input-wrap input { padding-right: 76px; }
.reveal { position: absolute; right: 6px; top: 7px; height: 36px; padding: 0 10px; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer; }
.reveal:hover, .reveal[aria-pressed="true"] { color: var(--ink); background: var(--raised); }
.form .hint { font-size: 13px; color: var(--faint); margin: 0; }
.form .error { min-height: 0; margin: 0; color: var(--danger); font-size: 14px; font-weight: 600; }
/* Vacío se oculta a la vista pero el nodo (role=alert) sigue en el árbol para anunciar el error cuando llegue. */
.form .error:empty { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.form .ok-msg { margin: 0; padding: 12px 14px; border-radius: 8px; background: rgba(103, 199, 154, 0.12); color: var(--ok); font-weight: 600; font-size: 14px; }
.auth-foot { margin-top: 18px; text-align: center; font-size: 14px; color: var(--muted); display: grid; gap: 8px; }
.auth-foot a { font-weight: 700; }
.strength { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.strength i { height: 3px; border-radius: 3px; background: var(--line-strong); transition: background 0.2s; }
.strength[data-level="1"] i:nth-child(-n+1) { background: var(--danger); }
.strength[data-level="2"] i:nth-child(-n+2) { background: var(--ember); }
.strength[data-level="3"] i:nth-child(-n+3) { background: var(--ok); }
.strength[data-level="4"] i { background: var(--ok); }

/* ---------- Cuenta y vacíos ---------- */
.narrow { max-width: 560px; margin: 0 auto; }
.narrow h1 { font-size: clamp(28px, 4vw, 36px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; margin: 0 0 6px; }
.narrow > p { color: var(--muted); margin: 0 0 26px; }
.narrow .form { margin-bottom: 22px; background: var(--surface); backdrop-filter: none; box-shadow: none; }
.narrow .form h2 { margin: 0; font-size: 18px; font-weight: 800; }
.empty-state { min-height: 80vh; display: grid; place-items: center; padding: calc(var(--header) + 20px) var(--gutter) 60px; text-align: center; }
.empty-state > div { max-width: 460px; }
.empty-state img { width: 52px; margin: 0 auto 20px; opacity: 0.9; }
.empty-state h1 { margin: 0 0 10px; font-size: clamp(24px, 4vw, 32px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; text-wrap: balance; }
.empty-state p { color: var(--muted); margin: 0 0 22px; }
.empty-state .actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Esqueletos y aviso ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--raised) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: var(--radius); }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-hero { height: min(70vh, 600px); border-radius: 0; }
.sk-row { display: grid; grid-auto-flow: column; grid-auto-columns: clamp(240px, 26vw, 330px); gap: 12px; padding: 0 var(--gutter); overflow: hidden; margin-top: 28px; }
.sk-row div { aspect-ratio: 16 / 9; }
.sk-line { height: 14px; border-radius: 6px; max-width: 100%; }
.sk-line.big { height: 34px; }
.sk-player { width: min(100%, calc((100vh - var(--header) - 120px) * 16 / 9)); margin: 0 auto; aspect-ratio: 16 / 9; border-radius: 0; background-color: #0d0b0a; }
.sk-body { display: grid; gap: 14px; padding: 28px var(--gutter); max-width: 1320px; margin: 0 auto; }
.sk-course { height: min(46vh, 420px); }
.sk-list { display: grid; gap: 14px; padding: 28px var(--gutter); }
.sk-ep { display: grid; grid-template-columns: clamp(116px, 18vw, 210px) 1fr; gap: 16px; align-items: center; }
.sk-ep > .skeleton { aspect-ratio: 16 / 9; }
.sk-ep > div:last-child { display: grid; gap: 10px; }

#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 90; transform: translate(-50%, 20px);
  max-width: min(92vw, 480px); padding: 12px 18px; border-radius: 10px; background: var(--ink); color: #120d0a;
  font-weight: 700; font-size: 14px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.25s var(--ease);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: #3a1914; color: #ffd9d3; box-shadow: inset 0 0 0 1px #6b2a22, var(--shadow); }

footer.foot { padding: 30px var(--gutter) calc(40px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--faint); font-size: 13px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; }
footer.foot img { width: 12px; display: inline-block; vertical-align: -1px; margin-right: 6px; }

/* ---------- Pantallas chicas ---------- */
@media (max-width: 960px) {
  .lesson-body { grid-template-columns: 1fr; gap: 10px; }
  .side-list { position: static; max-height: none; margin-top: 24px; }
}
@media (max-width: 720px) {
  :root { --header: 58px; }
  .top { gap: 14px; }
  .top nav { display: none; }
  .wordmark small { display: none; }
  .wordmark span { font-size: 13px; letter-spacing: 0.16em; }
  .hero { min-height: auto; display: block; padding-top: var(--header); }
  .hero .art { position: relative; inset: auto; aspect-ratio: 4 / 3; max-height: 62vh; width: 100%; }
  .hero .art img { object-position: 78% 50%; }
  .hero .art::after { background: linear-gradient(0deg, var(--bg) 0%, rgba(12, 10, 9, 0.3) 45%, rgba(12, 10, 9, 0.05) 100%); }
  .hero .copy { margin-top: -80px; padding-bottom: 34px; position: relative; }
  .hero .fallback img { right: 50%; transform: translate(50%, -50%) !important; width: 90px; }
  .hero .actions .btn { flex: 1 1 140px; }
  .hero .desc.clamp { -webkit-line-clamp: 4; }
  .rows { margin-top: 0; }
  .rail { --card-w: 74vw; gap: 10px; }
  .rail.courses { --card-w: 84vw; }
  .episode > a, .episode > div { grid-template-columns: 116px 1fr; padding: 14px 4px; gap: 4px 14px; }
  .episode .num { display: none; }
  .episode .info .head { flex-direction: column; gap: 2px; }
  .episode .info p { -webkit-line-clamp: 2; font-size: 13px; }
  .lesson-player .frame { width: 100%; min-width: 0; }
  .lesson-actions .btn { flex: 1 1 150px; }
  /* Barra compacta bajo el frame, en el flujo (el JS la inserta tras él): encima del video taparía sus controles nativos. */
  .up-next { position: static; width: auto; border-radius: 0; border-width: 1px 0 0; padding: 8px 12px 10px; box-shadow: none; }
  .up-next .info { display: flex; align-items: baseline; gap: 8px; }
  .up-next small { flex: none; font-size: 11px; letter-spacing: 0.1em; }
  .up-next strong { margin: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .up-next .actions { margin-top: 8px; }
  .up-next .actions .btn { flex: 1 1 0; padding: 0 10px; }
  .form { padding: 20px; }
}

/* Áreas táctiles de al menos 44 px en móvil y pantallas táctiles. */
@media (max-width: 720px), (pointer: coarse) {
  .btn.small { min-height: 44px; }
  .reveal { top: 3px; height: 44px; min-width: 44px; }
  .avatar-btn { min-height: 44px; min-width: 44px; justify-content: center; }
  .menu a, .menu button { min-height: 44px; display: flex; align-items: center; }
  .row-head { align-items: center; }
  .row-head a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; }
  .crumbs { row-gap: 0; }
  .crumbs a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 2px; margin: -9px 0; }
  .desc-toggle { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
  .card:hover, .rail .card:hover, .card:focus-visible { transform: none !important; }
  .card:hover .thumb img { transform: none !important; }
  .skeleton { animation: none; }
}

@media (max-width: 420px) { .btn { padding: 0 16px; gap: 8px; } .hero .actions .btn { flex: 1 1 auto; } }

/* Títulos largos o sin espacios no rompen el diseño. */
.hero h1, .lesson-body h1, .auth-brand h1, .empty-state h1, .card .label strong, .episode .info strong, .side-list strong, .crumbs a { overflow-wrap: anywhere; }
