/* ═══════════════════════════════════════════════════════════════════
   DO ARC — historia.css · «Amanecer sobre maqueta»
   Modo oscuro deliberado (contraste con el home tinta-sobre-blanco).
   Estados: body.h-live (scrub 3D) · body.h-static (lámina de capturas).
   El default sin JS = textos apilados legibles (ver @media noscript).
   ═══════════════════════════════════════════════════════════════════ */
:root {
  --h-bg: #050608;
  --h-ink: #e8e4dc;
  --h-ink-soft: #b5afa3;
  --h-ink-ghost: #6f6a61;
  --h-oro: #e8a33d;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-ui: 'Jost', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
  --page-pad: clamp(1.2rem, 5vw, 4.5rem);
  --h-scroll: 1000vh;
  --ease: cubic-bezier(.16, 1, .3, 1);
}
@media (max-width: 767px) { :root { --h-scroll: 700vh; } }

.h-skip {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--h-bg); color: var(--h-ink); padding: .8rem 1.2rem;
}
.h-skip:focus { left: 0; }

.h-nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  display: flex; justify-content: space-between; align-items: center;
  padding: clamp(1.2rem, 3vw, 2rem) var(--page-pad);
}
.h-nav .wordmark {
  font-family: var(--font-display); font-weight: 300; letter-spacing: .28em;
  text-transform: uppercase; color: var(--h-ink); text-decoration: none;
  font-size: clamp(1rem, 1.8vw, 1.3rem); min-height: 44px; display: inline-flex; align-items: center;
}
.h-nav .wordmark em { font-style: italic; font-weight: 400; }
#h-volver {
  font-family: var(--font-mono); font-size: .75rem; letter-spacing: .2em;
  text-transform: uppercase; color: var(--h-ink-ghost); text-decoration: none;
  min-height: 44px; display: inline-flex; align-items: center; transition: color .3s;
}
#h-volver:hover, #h-volver:focus-visible { color: var(--h-ink); }

#cielo { position: fixed; inset: 0; width: 100%; height: 100%; display: none; }
body.h-live #cielo { display: block; }

/* Viñeta del taller: penumbra alrededor de la mesa en el acto 1;
   el timeline la funde a 0 cuando el día toma la escena */
#h-vineta {
  position: fixed; inset: 0; z-index: 1; pointer-events: none; display: none;
  background: radial-gradient(ellipse 62% 55% at 50% 46%, transparent 0%, transparent 55%, rgba(2, 3, 5, .82) 100%);
}
body.h-live #h-vineta { display: block; }

.h-ui {
  position: fixed; bottom: clamp(1.2rem, 3vw, 2rem); left: var(--page-pad);
  right: var(--page-pad); z-index: 90; display: flex;
  justify-content: space-between; align-items: baseline;
  font-family: var(--font-mono); font-size: .8rem; letter-spacing: .18em;
  color: var(--h-ink-ghost); display: none;
}
body.h-live .h-ui { display: flex; }
#h-reloj { font-variant-numeric: tabular-nums; color: var(--h-ink-soft); }
#h-sonido {
  background: none; border: 1px solid var(--h-ink-ghost); border-radius: 999px;
  color: var(--h-ink-ghost); font: inherit; letter-spacing: inherit;
  padding: .35rem 1rem; cursor: pointer; transition: color .3s, border-color .3s;
}
#h-sonido[aria-pressed="true"], #h-sonido:hover { color: var(--h-oro); border-color: var(--h-oro); }

#h-hint {
  position: fixed; bottom: clamp(4rem, 9vh, 6rem); left: 50%; translate: -50% 0;
  z-index: 90; font-family: var(--font-mono); font-size: .7rem;
  letter-spacing: .3em; text-transform: uppercase; color: var(--h-ink);
  opacity: 0; transition: opacity 1s var(--ease); display: none;
  /* Chip con fondo propio: el 3D pasa por fases claras (la lámina de papel
     al amanecer) donde la tinta fantasma suelta era ilegible; en la lámina
     estática el texto de los capítulos fluye justo debajo. El fondo opaco
     garantiza contraste sobre cualquier escena. */
  background: var(--h-bg); padding: .6rem 1rem .45rem;
  border: 1px solid rgba(232, 228, 220, .14); border-radius: 2px;
  max-width: min(86vw, 26rem); text-align: center;
}
body.h-live #h-hint { display: block; }
body.h-live.h-lista #h-hint { opacity: 1; }
/* En la lámina estática (móvil/reduced/sin WebGL) el hint también guía:
   visible desde el arranque, se desvanece al primer scroll (h-movio). */
body.h-static #h-hint { display: block; opacity: 1; }
body.h-live.h-movio #h-hint, body.h-static.h-movio #h-hint { opacity: 0; }

#h-carga {
  position: fixed; inset: 0; z-index: 150; display: none;
  place-items: center; background: var(--h-bg);
  font-family: var(--font-mono); font-size: .8rem; letter-spacing: .22em;
  text-transform: uppercase; color: var(--h-ink-ghost);
  transition: opacity .9s var(--ease);
}
body.h-live #h-carga { display: grid; }
body.h-live.h-lista #h-carga { opacity: 0; pointer-events: none; }
#h-carga b { color: var(--h-ink-soft); font-weight: 300; font-variant-numeric: tabular-nums; }

/* ── Scroll narrativo ── */
body.h-live .h-scroll { height: var(--h-scroll); }
body.h-live .h-frame { position: sticky; top: 0; height: 100dvh; overflow: hidden; }
body.h-live .hc {
  /* SOLO posición aquí — nunca opacidad/fondo. GSAP anima .hc-in (abajo), y
     escribe `translate: none` inline sobre cualquier elemento cuyo x/y anima;
     si esta regla viviera en .hc, ese inline pisaría en silencio nuestro
     `translate: 0 -50%` de centrado (el bloque quedaba anclado por el borde
     superior, no centrado, y en viewports bajos o los capítulos más largos
     el sobrante se salía por abajo y "overflow:hidden" de .h-frame lo
     recortaba). Por la misma razón la tarjeta (fondo/blur/padding) vive en
     .hc-in, no aquí: si .hc tuviera el fondo pero ninguna animación propia de
     opacidad, los 5 capítulos (todos position:absolute, mismo punto) pintarían
     su tarjeta oscura a la vez, apiladas, siempre visibles. */
  position: absolute; left: var(--page-pad); top: 50%; translate: 0 -50%;
  max-width: min(440px, 34vw); z-index: 2;
  /* Los 5 .hc están apilados en el mismo punto (arriba); sin esto el último
     en el DOM (fase 4) intercepta los taps de TODAS las tarjetas anteriores
     aunque su .hc-in esté visibility:hidden — solo "Leer" del último capítulo
     abría el popup en celular. .hc-in reactiva pointer-events abajo. */
  pointer-events: none;
}
@media (max-width: 767px) {
  /* Ancladas arriba (bajo el nav): la maqueta se centra en pantalla y con
     la tarjeta al fondo quedaba tapada — arriba deja la mitad baja libre. */
  body.h-live .hc { left: var(--page-pad); right: var(--page-pad); top: 4.6rem; bottom: auto; translate: none; max-width: none; }
}
body.h-live .hc-in {
  /* width:100% explícito: .hc es position:absolute con solo `left` (sin
     `right`/`width`), así que su ancho sale de shrink-to-fit — y en ese
     cálculo un bloque estático simple no siempre hereda el 100% del ancho ya
     resuelto del padre. Sin esto, .hc-in salía más angosto que .hc (medido:
     296px vs 440px) y la fila de fotos (2×170px + gap ≈ 353px) desbordaba el
     borde de la tarjeta hacia la escena 3D — la queja de "la imagen se sale
     de la tarjeta". */
  width: 100%;
  /* Estado inicial (antes de que corra el timeline de GSAP): evita un
     parpadeo del texto/tarjeta sin animar en el primer frame. visibility
     (no solo opacity) para que las fotos de .hc-fotos no queden tabulables
     ni clicables — y su lightbox abrible — mientras el capítulo todavía es
     invisible (la ventana entre "body.h-live" y que arranca() corra
     g.set(caps,{autoAlpha:0}), que puede ser de varios segundos con el GLB
     aún cargando). GSAP's autoAlpha ya hace lo mismo en runtime; esto solo
     cubre el instante antes de que el timeline exista. */
  opacity: 0;
  visibility: hidden;
  pointer-events: auto;
  padding: clamp(1rem, 3vh, 1.7rem) clamp(1.1rem, 3vh, 1.8rem);
  border-radius: 3px;
  /* Tarjeta de papel blanco (misma paleta que index.html): la carta y el 3D
     son dos versiones de una sola historia, así que el 3D usa el mismo blanco
     #FFF / tinta oscura de la página principal. La tinta oscura de kicker/
     título/texto va scopeada a `body.h-live .hc-in …` (abajo) — nunca a las
     clases globales, que también sirven al fallback sin-JS y a la lámina
     estática sobre fondo oscuro. La sombra separa el papel del cielo 3D. */
  background: #FFFFFF;
  border: 1px solid rgba(28,26,23,.10);
  box-shadow: 0 18px 50px rgba(0,0,0,.28), 0 2px 10px rgba(0,0,0,.12);
}
/* Tinta oscura solo dentro de la tarjeta viva (blanca). Fuera de aquí, kicker/
   título/texto conservan los tokens claros para el fallback y la lámina. El
   hover del CTA se re-scopea para ganar en especificidad al color base. */
body.h-live .hc-in .hc-kicker { color: #6B645A; }
body.h-live .hc-in .hc-title  { color: #1C1A17; }
body.h-live .hc-in .hc-text   { color: #3C3833; }
body.h-live .hc-in .hc-cta a  { color: #1C1A17; border-color: #6B645A; }
body.h-live .hc-in .hc-cta a:hover, body.h-live .hc-in .hc-cta a:focus-visible { color: var(--h-oro); border-color: var(--h-oro); }
.hc-kicker {
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .3em;
  text-transform: uppercase; color: var(--h-ink-ghost); margin-bottom: clamp(.5rem, 1.6vh, .9rem);
}
.hc-title {
  font-family: var(--font-display); font-weight: 400; line-height: 1.08;
  /* clamp con min(vw, vh): en viewports bajos (ventana corta, móvil apaisado)
     el título ya no se sale del marco — antes solo escalaba con el ancho, así
     que en poca altura el bloque (título + texto) superaba el 100dvh del
     .h-frame y "overflow: hidden" recortaba el primer y el último capítulo
     (los más largos: kicker+2 líneas, o 2 líneas+CTA). */
  font-size: clamp(1.9rem, min(5vw, 6vh), 3.9rem); letter-spacing: -.01em; margin-bottom: clamp(.6rem, 1.8vh, 1rem);
}
.hc-title em { font-style: italic; font-weight: 400; }
.hc-text { font-size: clamp(1rem, min(1.3vw, 2vh), 1.2rem); line-height: 1.6; font-weight: 500; color: var(--h-ink-soft); max-width: 44ch; }
.hc-fotos { display: flex; gap: .8rem; margin-top: clamp(.9rem, 2vh, 1.4rem); }
.hc-fotos img {
  /* Ancho vh-aware: en viewports bajos la foto encoge para no desbordar el
     marco fijo (.h-frame 100dvh, overflow:hidden). Filtro igual que la carta. */
  width: clamp(110px, min(20vw, 22vh), 240px); height: auto; border-radius: 3px;
  filter: grayscale(1) sepia(.28) contrast(1.04) brightness(1.02); box-shadow: 0 12px 30px rgba(0,0,0,.28);
  cursor: pointer; transition: filter .3s;
}
.hc-fotos img:hover, .hc-fotos img:focus-visible { filter: grayscale(0) sepia(0) brightness(1); }

/* Botón "Leer +" (indicador de abrir): solo en celular. En ≤767px el cuerpo del
   capítulo colapsa y se lee en #h-texto-modal, para que la tarjeta sea mínima y
   el 3D sea el protagonista. En desktop el texto va inline y este botón no se ve. */
.hc-leer { display: none; }

/* Salvaguarda de ventana baja en DESKTOP (en celular el texto ya está colapsado).
   Sin fotos, pero el texto de carta es largo: en ventanas cortas ensancho la
   tarjeta para que reflowe a menos líneas y no se recorte en el marco 100dvh. */
@media (min-width: 768px) and (max-height: 620px) {
  body.h-live .hc { max-width: min(720px, 82vw); }
  body.h-live .hc-in { padding: clamp(.5rem, 1.6vh, .9rem) clamp(.9rem, 2vh, 1.3rem); }
  body.h-live .hc-in .hc-kicker { margin-bottom: .35rem; }
  body.h-live .hc-in .hc-title { font-size: clamp(1.4rem, 4.4vh, 2.1rem); margin-bottom: .4rem; }
  body.h-live .hc-in .hc-text { font-size: clamp(.85rem, 2.4vh, 1rem); line-height: 1.45; max-width: none; }
}

/* Celular: cuerpo + CTA colapsan en la tarjeta (se leen en el popup) y aparece
   "Leer +". Scopeado a .hc para NO afectar al clon del modal, que vive fuera de .hc. */
@media (max-width: 767px) {
  body.h-live .hc .hc-text, body.h-live .hc .hc-cta { display: none; }
  body.h-live .hc .hc-leer {
    display: inline-flex; align-items: center; gap: .5rem;
    margin-top: clamp(.8rem, 3vh, 1.4rem);
    font-family: var(--font-mono); font-size: .74rem; letter-spacing: .2em;
    text-transform: uppercase; color: #1C1A17;
    background: none; border: 1px solid #6B645A; border-radius: 999px;
    padding: .55rem 1.1rem; min-height: 44px; cursor: pointer;
    transition: color .3s, border-color .3s, background .3s;
  }
  body.h-live .hc .hc-leer:hover, body.h-live .hc .hc-leer:focus-visible {
    color: #FFFFFF; background: #1C1A17; border-color: #1C1A17;
  }
}

/* ── Popup de texto (celular): lectura del capítulo sobre el 3D atenuado ── */
#h-texto-modal {
  position: fixed; inset: 0; z-index: 320;
  display: flex; align-items: center; justify-content: center; padding: var(--page-pad);
  background: rgba(3, 4, 6, .78);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  /* cerrado: invisible, fuera del árbol de foco y sin capturar clics. visibility
     es transicionable, así que el fundido de salida se ve antes de ocultar. */
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .35s var(--ease), visibility .35s var(--ease);
}
#h-texto-modal.open { opacity: 1; visibility: visible; pointer-events: auto; }
.h-tm-panel {
  position: relative; background: #FFFFFF; color: #1C1A17; border-radius: 4px;
  width: 100%; max-width: 60ch; max-height: 82dvh; overflow-y: auto;
  padding: clamp(1.6rem, 6vw, 2.4rem);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
  transform: translateY(14px); transition: transform .45s var(--ease);
}
#h-texto-modal.open .h-tm-panel { transform: none; }
/* el clon usa las clases .hc-* globales (claras); re-tinta oscuro dentro del panel */
.h-tm-panel .hc-kicker { color: #6B645A; margin-bottom: .8rem; }
.h-tm-panel .hc-title { color: #1C1A17; font-size: clamp(1.9rem, 8vw, 2.6rem); margin-bottom: 1.1rem; }
.h-tm-panel .hc-title em { font-style: italic; font-weight: 400; }
.h-tm-panel .hc-text { color: #3C3833; font-size: 1.05rem; line-height: 1.72; max-width: none; }
.h-tm-panel .hc-cta { display: flex; gap: 1.4rem; margin-top: 1.8rem; flex-wrap: wrap; }
.h-tm-panel .hc-cta a {
  font-family: var(--font-mono); font-size: .78rem; letter-spacing: .2em; text-transform: uppercase;
  color: #1C1A17; text-decoration: none; border-bottom: 1px solid #6B645A; padding-bottom: .3rem;
}
.h-tm-close {
  position: absolute; top: 1rem; right: 1rem; z-index: 1;
  background: none; border: none; color: #fff;
  font-family: var(--font-mono); font-size: .75rem; letter-spacing: .2em; text-transform: uppercase;
  min-height: 44px; padding: 0 1rem; cursor: pointer;
}

/* ── Indicador animado de scroll: chevron que rebota bajo el texto del hint ── */
.h-hint-cue {
  display: block; width: 13px; height: 13px; margin: .55rem auto 0;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg); animation: h-cue 1.8s var(--ease) infinite;
}
@keyframes h-cue {
  0%, 100% { transform: rotate(45deg) translate(-2px, -2px); opacity: .35; }
  50%      { transform: rotate(45deg) translate(2px, 2px);   opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  #h-texto-modal, .h-tm-panel { transition: none; }
  .h-tm-panel { transform: none; }
  .h-hint-cue { animation: none; }
}

/* ── Lightbox de fotos: mismo patrón accesible que #lightbox (project.js),
   re-estilado con los tokens oscuros de esta página en vez de los del sitio
   principal. ── */
#h-lightbox {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(3, 4, 6, .92);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center;
}
#h-lightbox.open { display: flex; }
#h-lightbox img {
  max-width: 90vw; max-height: 86dvh; object-fit: contain;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.h-lb-btn {
  background: none; border: none; color: var(--h-ink-ghost);
  min-width: 44px; min-height: 44px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color .3s; font-family: var(--font-ui);
}
.h-lb-btn:hover, .h-lb-btn:focus-visible { color: var(--h-ink); }
.h-lb-close {
  position: absolute; top: 1.2rem; right: 1.2rem;
  font-family: var(--font-mono); font-size: .75rem; letter-spacing: .2em; text-transform: uppercase;
  padding: 0 1rem;
}
.h-lb-prev, .h-lb-next { position: absolute; top: 50%; translate: 0 -50%; font-size: 1.4rem; padding: 1rem; }
.h-lb-prev { left: .6rem; } .h-lb-next { right: .6rem; }
.h-lb-counter {
  position: absolute; bottom: 1.2rem; left: 50%; translate: -50% 0;
  font-family: var(--font-mono); font-size: .7rem; letter-spacing: .3em; color: var(--h-ink-ghost);
}
.hc-cta { display: flex; gap: 2rem; margin-top: clamp(1rem, 2.4vh, 1.6rem); flex-wrap: wrap; }
.hc-cta a {
  font-family: var(--font-mono); font-size: .78rem; letter-spacing: .2em;
  text-transform: uppercase; color: var(--h-ink); text-decoration: none;
  border-bottom: 1px solid var(--h-ink-ghost); padding-bottom: .3rem;
  transition: color .3s, border-color .3s;
}
.hc-cta a:hover, .hc-cta a:focus-visible { color: var(--h-oro); border-color: var(--h-oro); }

/* ── Default (sin JS) y fallback estático: textos apilados legibles ── */
.h-scroll { padding-top: 20vh; }
.hc { padding: 14vh var(--page-pad); max-width: 720px; }
/* La lámina de capturas (body.h-static) la activa historia.js; Task 6 añade .h-lamina figure */
body.h-static .h-scroll { padding-top: 0; }
body.h-static .h-lamina { display: block; }
.h-lamina figure { position: relative; margin: 0; }
.h-lamina img { display: block; width: 100%; height: 100vh; object-fit: cover; }
.h-lamina figcaption {
  position: absolute; left: var(--page-pad); bottom: 10vh; max-width: 440px;
}

/* Apagón de salida (Task 5) */
#h-apagon {
  position: fixed; inset: 0; z-index: 300; background: #000;
  opacity: 0; pointer-events: none; transition: opacity .6s ease;
}
body.h-saliendo #h-apagon { opacity: 1; pointer-events: auto; }

@media (prefers-reduced-motion: reduce) {
  #h-hint, #h-carga { transition: none; }
}

/* Botón para saltar a la versión carta (historia.html ↔ historia-carta.html):
   son dos versiones permanentes de la misma historia. Píldora con borde, mismo
   patrón que #h-sonido. */
.h-nav-links { display: flex; gap: 1.6rem; align-items: center; flex-wrap: wrap; }
.h-alt-link {
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .2em;
  text-transform: uppercase; color: var(--h-ink-ghost); text-decoration: none;
  border: 1px solid var(--h-ink-ghost); border-radius: 999px;
  padding: 0 1rem; min-height: 44px; display: inline-flex; align-items: center;
  transition: color .3s, border-color .3s;
}
.h-alt-link:hover, .h-alt-link:focus-visible { color: var(--h-ink); border-color: var(--h-ink); }
/* Celular: los tres elementos no caben con sus medidas de escritorio y el
   flex-wrap los apilaba desordenados (pill encima del wordmark). Una sola
   fila compacta: wordmark izquierda, links derecha, sin wrap. */
@media (max-width: 767px) {
  .h-nav { padding: .7rem var(--page-pad); gap: .7rem; }
  .h-nav .wordmark { letter-spacing: .16em; font-size: .95rem; }
  .h-nav-links { flex-wrap: nowrap; gap: .7rem; }
  .h-alt-link { font-size: .6rem; letter-spacing: .1em; padding: 0 .7rem; min-height: 38px; white-space: nowrap; }
  #h-volver { font-size: .6rem; letter-spacing: .1em; white-space: nowrap; }
}
