/* ==========================================================================
   scene.css — la escena de apertura del home
   Es una sección de exactamente 100vh, sin más. No hay pin de ScrollTrigger
   ni distancia de scroll que reservar: js/lib/scrollTimeline.js bloquea el
   scroll del documento entero mientras el vídeo no ha terminado, así que la
   sección nunca necesita ser más alta que la pantalla — no hay nada de lo
   que "sujetarse" durante el desplazamiento, porque el documento no se
   desplaza hasta que el vídeo acaba.
   ========================================================================== */

.scroll-section {
  position: relative;
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
}

.sticky-stage {
  position: relative;
  top: 0;
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
  width: 100%;
  overflow: hidden;
  background: var(--ink);
}

.scene { position: absolute; inset: 0; }

/* js/lib/imageSequence.js fija el tamaño real del buffer (con
   devicePixelRatio); aquí solo se define el hueco CSS. */
.sequence-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Viñeteado y degradados de legibilidad. Van sobre el canvas, no dentro:
   así el motor nunca tiene que redibujar por un cambio de interfaz. */
.scene__veil {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  background:
    linear-gradient(to right, rgba(18, 16, 13, 0.62) 0%, rgba(18, 16, 13, 0.16) 42%, rgba(18, 16, 13, 0) 68%),
    linear-gradient(to top, rgba(18, 16, 13, 0.55) 0%, rgba(18, 16, 13, 0) 38%),
    radial-gradient(120% 90% at 50% 45%, rgba(18, 16, 13, 0) 45%, rgba(18, 16, 13, 0.45) 100%);
}

/* Grano fino: rompe el bandeado de las paredes lisas al escalar el frame a
   pantalla completa. Es un SVG en línea, no un archivo: pesa ~200 bytes. */
.scene__grain {
  position: absolute;
  inset: -50%;
  z-index: 11;
  pointer-events: none;
  opacity: 0.14;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grainShift 7s steps(6) infinite;
}

@keyframes grainShift {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-6%, 3%); }
  40%  { transform: translate(4%, -5%); }
  60%  { transform: translate(-3%, -3%); }
  80%  { transform: translate(5%, 4%); }
  100% { transform: translate(0, 0); }
}

/* ---- Capa de texto -------------------------------------------------------- */

.scene-copy {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  color: var(--light);
}

.scene-copy__stage {
  position: absolute;
  left: clamp(24px, 6.5vw, 96px);
  bottom: clamp(96px, 16vh, 176px);
  max-width: min(600px, 46vw);
  opacity: 0;
  will-change: transform, opacity;
}

.scene-copy__stage--hero {
  bottom: auto;
  top: 50%;
  transform: translateY(-50%);
  max-width: min(760px, 56vw);
}

.scene-copy__kicker {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: var(--fs-micro);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--brass-light);
  margin-bottom: 20px;
}

.scene-copy__kicker::before {
  content: '';
  width: 34px; height: 1px;
  background: currentColor;
  opacity: 0.65;
}

.scene-copy__headline {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2.1rem, 4.4vw, 4.4rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.scene-copy__stage--hero .scene-copy__headline {
  font-size: var(--fs-display);
  line-height: 0.94;
  letter-spacing: -0.032em;
}

/* La máscara necesita un pelín de holgura o los descendentes (g, j, q) se
   recortan al quedar exactamente en el borde del overflow. */
.scene-copy__headline .line-mask { padding-bottom: 0.08em; margin-bottom: -0.08em; }

.scene-copy__subtext {
  margin-top: 22px;
  font-size: var(--fs-lead);
  line-height: 1.6;
  color: rgba(242, 237, 228, 0.76);
  max-width: 44ch;
}

.scene-copy__cta {
  pointer-events: auto;
  margin-top: 34px;
  opacity: 0;
}

/* ---- Pista de scroll ------------------------------------------------------- */

.scene-copy__scroll-hint {
  position: absolute;
  left: 50%;
  bottom: 38px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-size: 9.5px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: rgba(242, 237, 228, 0.7);
  opacity: 0;
}

.scene-copy__scroll-hint::after {
  content: '';
  width: 1px; height: 44px;
  background: linear-gradient(to bottom, currentColor, transparent);
  animation: scrollHintMove 2.1s var(--ease) infinite;
}

@keyframes scrollHintMove {
  0%   { transform: scaleY(0); transform-origin: top; opacity: 0; }
  38%  { transform: scaleY(1); transform-origin: top; opacity: 1; }
  100% { transform: scaleY(1); transform-origin: bottom; opacity: 0; }
}

/* ---- Cronología lateral ------------------------------------------------------ */

.rail {
  position: absolute;
  right: clamp(22px, 3.4vw, 54px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 20px;
  pointer-events: none;
  color: var(--light);
}

/* En la serif de display el "0" y el "1" se confunden con "O" e "I" a este
   tamaño, así que los índices numéricos van siempre en la tipografía de
   interfaz, que sí distingue las cifras. */
.rail__label {
  font-family: var(--font-ui);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  line-height: 1;
  opacity: 0.55;
  font-variant-numeric: tabular-nums lining-nums;
}

.rail__track {
  position: relative;
  width: 1px;
  height: min(340px, 42vh);
  background: rgba(242, 237, 228, 0.22);
}

.rail__bar {
  position: absolute;
  inset: 0;
  background: var(--brass-light);
  transform: scaleY(0);
  transform-origin: top;
}

.rail__marks {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}

.rail__mark {
  position: relative;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: rgba(242, 237, 228, 0.28);
  transition: background 0.4s var(--ease), transform 0.4s var(--ease);
}

.rail__mark.is-past { background: rgba(220, 192, 148, 0.62); }

.rail__mark.is-active {
  background: var(--brass-light);
  transform: scale(1.55);
}

/* Nombre del capítulo, solo el activo */
.rail__mark span {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.4s var(--ease);
}

.rail__mark.is-active span { opacity: 0.82; }

/* ---- Adaptación ---------------------------------------------------------------- */

@media (max-width: 1100px) {
  .rail__mark span { display: none; }
}

@media (max-width: 900px) {
  .scene-copy__stage { max-width: min(520px, 74vw); }
  .scene-copy__stage--hero { max-width: min(560px, 84vw); }
  .scene__veil {
    background:
      linear-gradient(to top, rgba(18, 16, 13, 0.8) 0%, rgba(18, 16, 13, 0.1) 52%),
      radial-gradient(120% 90% at 50% 45%, rgba(18, 16, 13, 0) 40%, rgba(18, 16, 13, 0.5) 100%);
  }
}

@media (max-width: 600px) {
  .scene-copy__stage,
  .scene-copy__stage--hero {
    max-width: calc(100% - 40px);
    left: 20px;
    right: 20px;
  }

  .scene-copy__stage { bottom: clamp(84px, 14vh, 130px); }
  .scene-copy__subtext { max-width: 36ch; font-size: 0.94rem; }

  /* El titular ocupa casi todo el ancho: el número del raíl se le cruzaba
     por encima. En móvil queda solo la pista de puntos, pegada al borde. */
  .rail { right: 10px; gap: 0; }
  .rail__label { display: none; }
  .rail__track { height: 26vh; }

  .scene-copy__stage--hero .scene-copy__headline {
    font-size: clamp(2.9rem, 12.5vw, 4rem);
  }

  /* Sobre la pared clara del primer tramo el texto se quedaba justo de
     contraste: se refuerza el velo por debajo del bloque de texto. */
  .scene__veil {
    background:
      linear-gradient(to top, rgba(18, 16, 13, 0.88) 0%, rgba(18, 16, 13, 0.34) 46%, rgba(18, 16, 13, 0.06) 72%),
      radial-gradient(130% 80% at 50% 55%, rgba(18, 16, 13, 0) 30%, rgba(18, 16, 13, 0.5) 100%);
  }
}

/* ---- Modo estático (prefers-reduced-motion) ---------------------------------
   La clase la pone js/lib/scrollTimeline.js. El escenario deja de ser una
   capa a pantalla completa con texto superpuesto y pasa a ser: plano final
   fijo de 100vh + los siete capítulos en columna, todos legibles sin que
   haga falta que se anime nada. */

body.scene-static .scroll-section { height: auto; }

body.scene-static .sticky-stage {
  height: auto;
  overflow: visible;
}

body.scene-static .scene {
  position: relative;
  inset: auto;
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
}

body.scene-static .scene-copy {
  position: relative;
  inset: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: clamp(40px, 5vw, 76px);
  padding: clamp(56px, 9vw, 120px) var(--gutter);
}

body.scene-static .scene-copy__stage {
  position: relative;
  left: auto; right: auto; top: auto; bottom: auto;
  transform: none;
  opacity: 1;
  max-width: 46ch;
}

body.scene-static .scene-copy__stage--hero {
  grid-column: 1 / -1;
  max-width: none;
}

/* Sin límite de columna el titular respira; el párrafo sí se sigue midiendo
   para no pasar de una línea de lectura cómoda. */
body.scene-static .scene-copy__stage--hero .scene-copy__headline {
  font-size: clamp(2.4rem, 5.2vw, 4.4rem);
  max-width: 16ch;
}

body.scene-static .scene-copy__stage--hero .scene-copy__subtext { max-width: 52ch; }

body.scene-static .rail,
body.scene-static .scene-copy__scroll-hint { display: none; }

@media (prefers-reduced-motion: reduce) {
  .scene__grain { animation: none; }
  .scene-copy__scroll-hint::after { animation: none; }
}
