/* «Por qué nace Bloopy»: historia larga con un panel que la acompaña, sin scripts.
   Cada capítulo lleva su escena; en escritorio la escena se queda fija (sticky) mientras
   se lee el texto, y sus piezas aparecen ligadas al scroll del capítulo (view-timeline).
   Sin soporte de animaciones por scroll se ve el estado final; sin movimiento, nada se anima. */

body.historia header.top,
body.historia main,
body.historia footer.bottom { width: min(1060px, 100% - 2 * var(--ap-gutter)); }
body.historia header.top { position: relative; z-index: 3; }
.h-top-link { color: var(--ap-ink-2); font-size: var(--ap-text-ui); font-weight: 600; text-decoration: none; }
.h-top-link:hover { color: var(--ap-ink); text-decoration: underline; }

/* ---------- Barra de lectura ---------- */
.h-progress { position: sticky; top: 0; z-index: 2; height: 3px; background: transparent; }
.h-progress span { display: block; height: 100%; width: 100%; background: var(--ap-brand); transform-origin: left; transform: scaleX(0); }
@supports (animation-timeline: scroll()) {
  .h-progress span { animation: h-grow linear both; animation-timeline: scroll(root); }
}
@keyframes h-grow { to { transform: scaleX(1); } }

/* ---------- Entrada ---------- */
.h-intro { display: grid; justify-items: center; text-align: center; max-width: 720px; margin: 0 auto; padding: var(--ap-space-6) 0 var(--ap-space-7); }
.h-intro h1 { font-size: clamp(44px, 8vw, 96px); line-height: 0.95; letter-spacing: -0.05em; }
/* Único momento al cargar: el titular sube palabra a palabra. */
.hw { display: inline-block; animation: h-word-in 700ms var(--ap-ease-spring) both; }
.hw:nth-child(2) { animation-delay: 60ms; } .hw:nth-child(3) { animation-delay: 120ms; } .hw:nth-child(4) { animation-delay: 180ms; }
.hw:nth-child(5) { animation-delay: 240ms; } .hw:nth-child(6) { animation-delay: 300ms; } .hw:nth-child(7) { animation-delay: 380ms; }
.hw:nth-child(8) { animation-delay: 440ms; } .hw:nth-child(9) { animation-delay: 500ms; }
@keyframes h-word-in { from { opacity: 0; transform: translateY(0.45em) rotate(4deg); } }
.h-intro .lead { max-width: 600px; }
.h-intro-bloop { width: 150px; height: auto; margin-bottom: var(--ap-space-3); animation: h-bob 3.4s var(--ap-ease) infinite alternate; }
@keyframes h-bob { to { transform: translateY(-10px); } }
body.historia .h-intro .kicker { font-family: var(--ap-font-hand); font-size: 30px; font-weight: 700; letter-spacing: 0; text-transform: none; color: var(--ap-accent); transform: rotate(-2deg); }
.h-scroll-hint { margin-top: var(--ap-space-4); font-size: var(--ap-text-meta); font-weight: 600; letter-spacing: 0.04em; color: var(--ap-accent-deep); }
.h-scroll-hint::after { content: ""; display: block; width: 2px; height: 34px; margin: 10px auto 0; border-radius: 2px; background: linear-gradient(var(--ap-accent), transparent); animation: h-cue 1.8s var(--ap-ease) infinite; }
@keyframes h-cue { from { transform: scaleY(0.3); transform-origin: top; } to { transform: scaleY(1); transform-origin: top; } }

/* ---------- Capítulos ---------- */
.h-chapter { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); gap: var(--ap-space-7); align-items: start; min-height: 150vh; padding: var(--ap-space-6) 0; view-timeline: --h-chapter block; }
/* Texto y panel se quedan fijos mientras pasa su capítulo: la página avanza como diapositivas. */
.h-text { position: sticky; top: calc(50vh - 230px); max-width: 560px; }
.h-text h2 { margin-top: 0; }
/* Capítulos numerados a mano, como en un cuaderno: la historia sí es una secuencia. */
.h-step { margin: 0 0 var(--ap-space-1); font-family: var(--ap-font-hand); font-size: 30px; font-weight: 700; line-height: 1; color: var(--ap-accent); transform: rotate(-2deg); transform-origin: left; }
.h-num { font-size: 44px; }
.h-text h2 { font-size: clamp(30px, 3.4vw, 42px); line-height: 1.04; letter-spacing: -0.035em; }
.h-text p, .h-text li { font-size: 19px; line-height: 1.7; }
.h-text strong { font-weight: 700; }

.h-scene { position: sticky; top: calc(50vh - 170px); margin: 34px 0 0; padding: var(--ap-space-4); border-radius: 26px; border: 1px solid var(--ap-glass-edge); background: var(--ap-glass-2); box-shadow: inset 0 1px 0 var(--ap-reflection, transparent), var(--ap-shadow-3); }
.h-scene-title { margin: 0 0 var(--ap-space-3); font-size: 15px; font-weight: 700; color: var(--ap-ink); }
.h-scene-foot { margin: var(--ap-space-3) 0 0; font-size: var(--ap-text-ui); color: var(--ap-ink-2); }
.h-scene-foot b { color: var(--ap-accent-deep); }
.h-scene p { font-size: 14px; line-height: 1.4; }

/* 1 · Semana */
.h-week-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); grid-auto-rows: auto; gap: 6px; }
.h-day { grid-row: 1; text-align: center; font-size: 11px; font-weight: 700; color: var(--ap-ink-2); }
.h-c1 { grid-column: 1; } .h-c2 { grid-column: 2; } .h-c3 { grid-column: 3; } .h-c4 { grid-column: 4; } .h-c5 { grid-column: 5; }
.h-r2 { grid-row: 2; } .h-r3 { grid-row: 3; }
.h-block { display: grid; place-items: center; min-height: 58px; padding: 6px 4px; border-radius: 10px; font-size: 11px; font-weight: 700; line-height: 1.25; text-align: center; color: var(--ap-ink); }
.h-class { background: var(--ap-accent-soft); }
.h-clash { background: color-mix(in srgb, var(--ap-warning) 16%, transparent); color: var(--ap-warning); outline: 2px dashed color-mix(in srgb, var(--ap-warning) 60%, transparent); outline-offset: -2px; }
.h-ok { background: color-mix(in srgb, var(--ap-success) 14%, transparent); color: var(--ap-success); }

/* 2 · Chat */
.h-chat { display: grid; gap: 8px; }
.h-msg { max-width: 85%; margin: 0; padding: 8px 12px; border-radius: 16px; color: var(--ap-ink); background: var(--ap-glass-3); box-shadow: var(--ap-shadow-1); }
.h-msg b { display: block; font-size: 11px; color: var(--ap-accent-deep); }
.h-msg-in { justify-self: start; border-bottom-left-radius: 4px; }
.h-msg-out { justify-self: end; border-bottom-right-radius: 4px; background: var(--ap-accent-soft); }
.h-msg-audio { justify-self: start; display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; font-size: 12px; }
.h-play { width: 0; height: 0; border-left: 10px solid var(--ap-accent-deep); border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.h-mini-wave { display: flex; align-items: center; gap: 2px; height: 18px; width: 90px; }
.h-mini-wave i { flex: 1; height: 40%; border-radius: 2px; background: var(--ap-brand); animation: h-wave 1s var(--ap-ease) infinite alternate; }
.h-mini-wave i:nth-child(2n) { animation-delay: -0.4s; } .h-mini-wave i:nth-child(3n) { animation-delay: -0.7s; }
@keyframes h-wave { to { height: 100%; } }

/* 3 · Audios pendientes */
.h-file { position: relative; display: flex; justify-content: space-between; gap: var(--ap-space-3); margin: 0 0 8px; padding: 10px 12px; border-radius: 12px; background: var(--ap-glass-3); font-variant-numeric: tabular-nums; overflow: hidden; }
.h-file span:first-child { font-weight: 700; color: var(--ap-ink); }
.h-file span:last-child { color: var(--ap-ink-2); }
.h-file i { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--ap-line-strong); }
.h-file i::after { content: ""; position: absolute; inset: 0; width: 4%; background: var(--ap-brand); }

/* 4 · Buscar apuntes de otros */
.h-found { display: grid; margin: 0 0 8px; padding: 10px 12px; border-radius: 12px; background: var(--ap-glass-3); border-left: 3px solid color-mix(in srgb, var(--ap-warning) 55%, transparent); }
.h-found b { color: var(--ap-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-found span { font-size: 12px; color: var(--ap-warning); }

/* 5 · El detalle: el sello rojo «EXAMEN» encima de lo que se dijo de palabra */
body.historia { --h-red: #d1223a; }
@media (prefers-color-scheme: dark) { body.historia { --h-red: #ff5d6c; } }
.h-said { position: relative; }
.h-stamp { position: absolute; top: -22px; right: -8px; z-index: 1; padding: 4px 14px 2px; border: 3px solid var(--h-red); border-radius: 8px; font-family: var(--ap-font-display); font-size: 26px; font-weight: 800; letter-spacing: 0.08em; line-height: 1.1; color: var(--h-red); background: color-mix(in srgb, var(--ap-bg) 82%, transparent); transform: rotate(-12deg); box-shadow: 0 6px 16px -8px var(--h-red); }
.h-slide-line { margin: 0 0 6px; padding: 8px 12px; border-radius: 8px; background: var(--ap-glass-3); font-weight: 700; color: var(--ap-ink); }
.h-slide-short { width: 70%; font-weight: 600; color: var(--ap-ink-2); }
.h-said, .h-lost { margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; }
.h-said { border: 2px solid var(--ap-brand); background: var(--ap-accent-tint); color: var(--ap-ink); }
.h-lost { border: 2px dashed var(--ap-line-strong); color: var(--ap-ink-2); text-align: center; }
.h-said-tag { display: block; margin-bottom: 4px; font-size: 10px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ap-accent-deep); }
.h-lost .h-said-tag { color: var(--ap-ink-2); }

/* 5 · Bloopy */
.h-bloopy { display: grid; gap: 8px; }
.h-bloopy-bloop { justify-self: center; width: 110px; height: auto; animation: h-bob 3s var(--ap-ease) infinite alternate; }
.h-line { display: block; height: 8px; border-radius: 4px; background: var(--ap-line-strong); }
.h-line-title { width: 55%; height: 11px; background: var(--ap-ink-2); }
.h-line-short { width: 60%; }
.h-line-doubt { background: color-mix(in srgb, var(--ap-brand) 60%, transparent); }
.h-doubt-chip { justify-self: start; margin: 6px 0 0; padding: 8px 12px; border-radius: var(--ap-radius-pill); background: var(--ap-glass-3); box-shadow: var(--ap-shadow-2); color: var(--ap-ink-2); }
.h-doubt-chip b { color: var(--ap-accent-deep); }

/* 6 · Futuro */
.h-search { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; padding: 10px 14px; border-radius: var(--ap-radius-pill); border: 1px solid var(--ap-line-strong); background: var(--ap-glass-3); }
.h-search::before { content: ""; width: 12px; height: 12px; border: 2px solid var(--ap-ink-2); border-radius: 50%; flex: none; }
.h-search-text { display: inline-block; font-weight: 700; color: var(--ap-ink); overflow: hidden; white-space: nowrap; border-right: 2px solid var(--ap-accent); padding-right: 2px; }
.h-result { display: grid; margin: 0 0 8px; padding: 10px 12px; border-radius: 12px; background: var(--ap-glass-3); }
.h-result b { color: var(--ap-ink); }
.h-result span { font-size: 12px; color: var(--ap-ink-2); }

/* ---------- Final ---------- */
.h-end { display: grid; justify-items: center; text-align: center; max-width: 640px; margin: var(--ap-space-6) auto 0; padding: var(--ap-space-6) var(--ap-space-5); border-radius: 30px; border: 1px solid var(--ap-glass-edge); background: var(--ap-glass-1); }
.h-end img { width: 140px; height: auto; }
.h-end h2 { margin-top: var(--ap-space-3); }
.h-cta { display: inline-flex; align-items: center; gap: 12px; margin-top: var(--ap-space-4); padding: 16px 34px 16px 22px; border-radius: var(--ap-radius-pill); font-family: var(--ap-font-display); font-size: 24px; font-weight: 800; letter-spacing: -0.02em; color: var(--ap-on-brand); text-decoration: none; background: linear-gradient(180deg, var(--ap-brand-hi), var(--ap-brand-lo)); box-shadow: inset 0 1px 0 var(--ap-brand-sheen), 0 18px 40px -14px var(--ap-brand-glow-strong); animation: h-cta-pulse 2.6s var(--ap-ease) infinite; transition: transform var(--ap-dur-base) var(--ap-ease-spring); }
.h-cta img { width: 34px; height: 34px; padding: 4px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); }
.h-cta:hover { transform: translateY(-3px) scale(1.03); color: var(--ap-on-brand); }
.h-cta:focus-visible { outline: 3px solid var(--ap-accent); outline-offset: 4px; }
@keyframes h-cta-pulse { 0%, 100% { box-shadow: inset 0 1px 0 var(--ap-brand-sheen), 0 18px 40px -14px var(--ap-brand-glow-strong); } 50% { box-shadow: inset 0 1px 0 var(--ap-brand-sheen), 0 18px 40px -14px var(--ap-brand-glow-strong), 0 0 0 12px color-mix(in srgb, var(--ap-brand) 18%, transparent); } }
.h-cta-note { margin: var(--ap-space-2) 0 0; font-size: var(--ap-text-ui); font-weight: 600; color: var(--ap-ink-2); }
.h-end-links { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--ap-space-2) var(--ap-space-4); margin: var(--ap-space-3) 0 0; }
.h-end-links a { font-weight: 700; }

/* ---------- Animaciones ligadas al scroll de cada capítulo ---------- */
@supports (animation-timeline: view()) {
  .h-scene { animation: h-scene-in linear both; animation-timeline: --h-chapter; animation-range: entry 10% entry 70%; }

  .h-block { animation: h-pop linear both; animation-timeline: --h-chapter; }
  .h-class { animation-range: entry 40% entry 80%; }
  .h-clash, .h-ok { animation-range: contain 0% contain 25%; }
  .h-week .h-scene-foot { animation: h-rise linear both; animation-timeline: --h-chapter; animation-range: contain 20% contain 35%; }

  .h-msg { animation: h-rise linear both; animation-timeline: --h-chapter; }
  .h-msg:nth-of-type(1) { animation-range: entry 50% entry 90%; }
  .h-msg:nth-of-type(2) { animation-range: contain 0% contain 8%; }
  .h-msg:nth-of-type(3) { animation-range: contain 8% contain 16%; }
  .h-msg:nth-of-type(4) { animation-range: contain 16% contain 24%; }
  .h-msg:nth-of-type(5) { animation-range: contain 24% contain 32%; }

  .h-file { animation: h-rise linear both; animation-timeline: --h-chapter; }
  .h-file:nth-of-type(1) { animation-range: entry 50% entry 90%; }
  .h-file:nth-of-type(2) { animation-range: contain 0% contain 8%; }
  .h-file:nth-of-type(3) { animation-range: contain 8% contain 16%; }
  .h-file:nth-of-type(4) { animation-range: contain 16% contain 24%; }
  .h-files .h-scene-foot { animation: h-rise linear both; animation-timeline: --h-chapter; animation-range: contain 24% contain 34%; }

  .h-found { animation: h-rise linear both; animation-timeline: --h-chapter; }
  .h-found:nth-of-type(1) { animation-range: entry 50% entry 90%; }
  .h-found:nth-of-type(2) { animation-range: contain 0% contain 8%; }
  .h-found:nth-of-type(3) { animation-range: contain 8% contain 16%; }
  .h-found:nth-of-type(4) { animation-range: contain 16% contain 24%; }
  .h-search-web .h-scene-foot { animation: h-pop linear both; animation-timeline: --h-chapter; animation-range: contain 24% contain 34%; }
  .h-stamp { animation: h-stamp linear both; animation-timeline: --h-chapter; animation-range: contain 14% contain 26%; }
  .h-said { animation: h-glow linear both; animation-timeline: --h-chapter; animation-range: contain 0% contain 18%; }
  .h-lost { animation: h-fade-out linear both; animation-timeline: --h-chapter; animation-range: contain 18% contain 34%; }

  .h-line { transform-origin: left; animation: h-write linear both; animation-timeline: --h-chapter; }
  .h-line-title { animation-range: entry 60% entry 100%; }
  .h-line:nth-of-type(2) { animation-range: contain 0% contain 6%; }
  .h-line:nth-of-type(3) { animation-range: contain 6% contain 12%; }
  .h-line:nth-of-type(4) { animation-range: contain 12% contain 18%; }
  .h-line:nth-of-type(5) { animation-range: contain 18% contain 24%; }
  .h-doubt-chip { animation: h-pop linear both; animation-timeline: --h-chapter; animation-range: contain 22% contain 32%; }

  .h-search-text { animation: h-type linear both; animation-timeline: --h-chapter; animation-range: entry 60% contain 6%; }
  .h-result { animation: h-rise linear both; animation-timeline: --h-chapter; }
  .h-result:nth-of-type(2) { animation-range: contain 6% contain 14%; }
  .h-result:nth-of-type(3) { animation-range: contain 14% contain 22%; }
  .h-result:nth-of-type(4) { animation-range: contain 22% contain 30%; }
}
/* En una columna el capítulo es más alto que la pantalla: cada pieza aparece al entrar ella misma. */
@supports (animation-timeline: view()) {
  @media (max-width: 860px), (max-height: 580px) {
    .h-scene, .h-note, .h-block, .h-scene-foot, .h-msg, .h-file, .h-said, .h-lost, .h-found, .h-stamp, .h-line, .h-doubt-chip, .h-search-text, .h-result {
      animation-timeline: view(); animation-range: entry 0% entry 70%;
    }
    .h-lost { animation-range: entry 40% cover 60%; }
  }
}
@keyframes h-stamp { 0% { opacity: 0; transform: rotate(-24deg) scale(2.4); } 70% { opacity: 1; transform: rotate(-10deg) scale(0.92); } 100% { opacity: 1; transform: rotate(-12deg) scale(1); } }
@keyframes h-rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes h-scene-in { from { opacity: 0; transform: translateY(40px) scale(0.96); } }
@keyframes h-pop { from { opacity: 0; transform: scale(0.6); } }
@keyframes h-glow { from { border-color: transparent; background: transparent; } }
@keyframes h-fade-out { to { opacity: 0.25; filter: blur(2px); } }
@keyframes h-write { from { transform: scaleX(0); } }
@keyframes h-type { from { max-width: 0; } to { max-width: 5ch; } }

/* ---------- Frases grandes entre capítulos: se leen palabra a palabra al bajar ---------- */
.h-beat { position: relative; height: 170vh; view-timeline: --h-beat block; }
.h-big { position: sticky; top: 0; display: flex; flex-wrap: wrap; align-content: center; gap: 0 0.28em; min-height: 100vh; max-width: 18ch; margin: 0 auto; font-family: var(--ap-font-display); font-size: clamp(40px, 6.4vw, 84px); font-weight: 800; line-height: 1.02; letter-spacing: -0.045em; color: var(--ap-ink); text-wrap: balance; }
.h-big .w { display: inline-block; }
@supports (animation-timeline: view()) {
  .h-big .w { animation: h-read linear both; animation-timeline: --h-beat; }
  .h-big .w:nth-child(1) { animation-range: contain 11.6% contain 16.6%; }
  .h-big .w:nth-child(2) { animation-range: contain 15.2% contain 20.2%; }
  .h-big .w:nth-child(3) { animation-range: contain 18.8% contain 23.8%; }
  .h-big .w:nth-child(4) { animation-range: contain 22.4% contain 27.4%; }
  .h-big .w:nth-child(5) { animation-range: contain 26.0% contain 31.0%; }
  .h-big .w:nth-child(6) { animation-range: contain 29.6% contain 34.6%; }
  .h-big .w:nth-child(7) { animation-range: contain 33.2% contain 38.2%; }
  .h-big .w:nth-child(8) { animation-range: contain 36.8% contain 41.8%; }
  .h-big .w:nth-child(9) { animation-range: contain 40.4% contain 45.4%; }
  .h-big .w:nth-child(10) { animation-range: contain 44.0% contain 49.0%; }
  .h-big .w:nth-child(11) { animation-range: contain 47.6% contain 52.6%; }
  .h-big .w:nth-child(12) { animation-range: contain 51.2% contain 56.2%; }
  .h-big .w:nth-child(13) { animation-range: contain 54.8% contain 59.8%; }
  .h-big .w:nth-child(14) { animation-range: contain 58.4% contain 63.4%; }
  .h-big .w:nth-child(15) { animation-range: contain 62.0% contain 67.0%; }
  .h-big .w:nth-child(16) { animation-range: contain 65.6% contain 70.6%; }
  .h-big .w:nth-child(17) { animation-range: contain 69.2% contain 74.2%; }
  .h-big .w:nth-child(18) { animation-range: contain 72.8% contain 77.8%; }
  .h-big .w:nth-child(19) { animation-range: contain 76.4% contain 81.4%; }
  .h-big .w:nth-child(20) { animation-range: contain 80.0% contain 85.0%; }
}
@keyframes h-read { from { opacity: 0.12; transform: translateY(0.12em); filter: blur(3px); } }

/* Rotulador: las frases clave se subrayan al llegar a ellas. */
.h-mark { padding: 0 0.12em; margin: 0 -0.06em; border-radius: 0.2em; color: inherit; background: linear-gradient(transparent 52%, color-mix(in srgb, var(--ap-brand) 38%, transparent) 52%, color-mix(in srgb, var(--ap-brand) 38%, transparent) 92%, transparent 92%) no-repeat 0 0 / 100% 100%; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
@supports (animation-timeline: view()) {
  .h-mark { animation: h-marker linear both; animation-timeline: view(); animation-range: entry 100% cover 45%; }
}
@keyframes h-marker { from { background-size: 0% 100%; } }

/* Notas a mano al margen de cada escena. */
.h-note { position: absolute; top: -34px; right: 10px; font-family: var(--ap-font-hand); font-size: 26px; font-weight: 700; line-height: 1; color: var(--ap-accent); transform: rotate(-3deg); white-space: nowrap; pointer-events: none; }
.h-note::after { content: ""; position: absolute; left: 12%; right: 4%; bottom: -6px; height: 3px; border-radius: 3px; background: currentColor; opacity: 0.5; transform-origin: left; }
@supports (animation-timeline: view()) {
  .h-note { animation: h-write-note linear both; animation-timeline: --h-chapter; animation-range: contain 2% contain 16%; }
}
@keyframes h-write-note { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* ---------- Móvil y tableta ---------- */
@media (max-width: 860px), (max-height: 580px) {
  .h-chapter { grid-template-columns: 1fr; gap: var(--ap-space-4); min-height: 0; padding: var(--ap-space-5) 0; }
  .h-text { position: static; }
  /* En una columna el panel no se queda fijo: va después del texto que ilustra. */
  .h-scene { position: relative; top: auto; }
  .h-beat { height: 130vh; }
  .h-big { max-width: 14ch; font-size: clamp(36px, 10vw, 52px); padding: 0 4px; }
  .h-note { font-size: 22px; right: 6px; }
  .h-text p, .h-text li { font-size: 18px; }
}
@media (max-width: 420px) {
  .h-block { min-height: 52px; font-size: 10px; padding: 4px 2px; }
  .h-scene { padding: var(--ap-space-3); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
  .h-progress { display: none; }
}
