/* =========================================================================
   HISTORIA · LINEA TEMPORAL (.lfe-hist) — capa de movimiento
   Pareja de assets/js/historia-timeline.js.

   Contrato:
   - Sin JS, sin GSAP o con prefers-reduced-motion todo es visible y quieto.
   - .is-hist-ready la pone el JS justo antes de fijar estados iniciales.
   - Los elementos que hacen de trigger NUNCA se animan:
     .lfe-hist__track, .lfe-hist__chapter, .lfe-hist__media, .lfe-hist__copy.
   - Cada propiedad transform tiene un unico dueño por elemento:
       .lfe-hist__photo-inner   y (profundidad, scrub)
       .lfe-hist__photo-inner img  scale (Ken Burns, scrub)
       .lfe-hist__layer         y (profundidad, scrub)
       .lfe-hist__doc           scale/y/rotation (caida, una vez)
                                (inclinacion base: --hist-rot, la lee el JS)
       .lfe-hist__watermark     y + xPercent (scrub)
       .lfe-hist__curtain       yPercent (una vez)
   - La composicion (columnas, tamaños, posiciones de capas) es orientativa:
     la decide dirección de arte. Lo marcado [MOTION] no se toca sin avisar.
   ========================================================================= */

.lfe-hist {
  --hist-bleed: 8%;               /* [MOTION] = BLEED en el JS */
  --hist-thread-x: 0.75rem;        /* eje del hilo dentro del track */
  --hist-node-y: 0.35rem;
  --hist-gold: var(--stage-gold, #F2B33D);
  --hist-gold-bright: var(--stage-gold-bright, #FAD879);
  --hist-crimson: #8b1a2a;
  --hist-crimson-deep: #5a0f1a;
  position: relative;
}

/* [MOTION] Recorte horizontal sin crear contenedor de scroll: `clip` no rompe
   el sticky del indice; `hidden` si lo romperia. */
@supports (overflow: clip) {
  .lfe-hist { overflow-x: clip; }
}

/* Safari < 16: sin `clip`. Se prefiere perder el sticky del indice a tener
   scroll horizontal a 375 px. */
@supports not (overflow: clip) {
  .lfe-hist { overflow-x: hidden; }
}

/* ---- Layout base: indice lateral + track ------------------------------ */

.lfe-hist__layout { position: relative; }

.lfe-hist__rail { display: none; }

@media (min-width: 1024px) {
  .lfe-hist {
    --hist-thread-x: 50%;
    --hist-node-y: 50%;
  }

  .lfe-hist__layout {
    display: grid;
    grid-template-columns: 7rem minmax(0, 1fr);
    column-gap: clamp(2rem, 4vw, 4rem);
    align-items: start;
  }

  .lfe-hist__rail {
    display: block;
    position: sticky;
    top: calc(var(--lfe-header-h, 88px) + 2rem);
    z-index: 2;
  }
}

/* ---- Indice lateral (programa de mano) -------------------------------- */

.lfe-hist__rail-list {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0 0 0 1.25rem;
}

.lfe-hist__rail-line {
  position: absolute;
  top: 0.5rem;
  bottom: 0.5rem;
  left: 0;
  width: 1px;
  background: rgba(240, 232, 214, 0.16);
}

.lfe-hist__rail-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--hist-gold) 0%, var(--velvet-magenta, #B83A78) 60%, var(--mist-violet, #7B5DC9) 100%);
  transform-origin: 50% 0;
}

.lfe-hist__rail-link {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 36px;                 /* > 24 px WCAG 2.5.8; solo escritorio */
  font-family: var(--lfe-font-display);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--bone-dim, #A8A294);  /* 7,9:1 sobre negro */
  text-decoration: none;
  transition:
    color 320ms var(--lfe-ease-out),
    transform 320ms var(--lfe-ease-out);
}

.lfe-hist__rail-link::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -1.25rem;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}

.lfe-hist__rail-link:hover,
.lfe-hist__rail-link.is-current {
  color: var(--hist-gold-bright);
}

.lfe-hist__rail-link.is-current { transform: translateX(4px); }
.lfe-hist__rail-link.is-current::before { opacity: 1; }

.lfe-hist__rail-link:focus-visible {
  outline: 2px solid var(--hist-gold-bright);
  outline-offset: 4px;
}

/* ---- Track, hilo conductor y marcador --------------------------------- */

.lfe-hist__track { position: relative; }

.lfe-hist__thread {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--hist-thread-x);
  width: 1px;
  margin-left: -0.5px;
  background: rgba(240, 232, 214, 0.12);
  pointer-events: none;
}

.lfe-hist__thread-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--hist-gold) 0%, var(--velvet-magenta, #B83A78) 55%, var(--mist-violet, #7B5DC9) 100%);
  transform-origin: 50% 0;          /* [MOTION] scaleY desde arriba */
}

/* Foco de seguimiento que recorre el hilo. Solo existe con movimiento. */
.lfe-hist__marker {
  display: none;
  position: absolute;
  top: 0;
  left: 50%;
  width: 15px;
  height: 15px;
  margin: -7.5px 0 0 -7.5px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff7df 0 22%, var(--hist-gold-bright) 42%, rgba(242, 179, 61, 0) 72%);
}

.lfe-hist__marker::after {
  content: "";
  position: absolute;
  inset: -22px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(250, 216, 121, 0.35), rgba(250, 216, 121, 0) 70%);
}

.is-hist-ready .lfe-hist__marker { display: block; }

/* ---- Capitulo = escena ------------------------------------------------ */

.lfe-hist__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.lfe-hist__chapter {
  position: relative;
  padding-block: clamp(3rem, 9vw, 7.5rem);
  scroll-margin-top: calc(var(--lfe-header-h, 88px) + 1rem);
}

.lfe-hist__scene {
  position: relative;
  isolation: isolate;               /* la marca de agua vive detras (z -1) */
  display: grid;
  gap: clamp(1.75rem, 5vw, 2.5rem);
  padding-inline-start: calc(var(--hist-thread-x) + 1.75rem);
}

@media (min-width: 1024px) {
  .lfe-hist__scene {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: clamp(4rem, 8vw, 8rem);
    align-items: center;
    padding-inline-start: 0;
  }
  .lfe-hist__copy  { grid-column: 1; grid-row: 1; }
  .lfe-hist__media { grid-column: 2; grid-row: 1; }
  .lfe-hist__chapter:nth-child(even) .lfe-hist__copy  { grid-column: 2; }
  .lfe-hist__chapter:nth-child(even) .lfe-hist__media { grid-column: 1; }
}

/* Nodo del hilo: hueco hasta que el capitulo se ha recorrido. */
.lfe-hist__node {
  position: absolute;
  top: var(--hist-node-y);
  left: var(--hist-thread-x);
  z-index: 2;
  width: 13px;
  height: 13px;
  margin: -6.5px 0 0 -6.5px;
  border: 1px solid rgba(242, 179, 61, 0.6);
  border-radius: 50%;
  background: var(--lfe-black, #0a0a0a);
  transition:
    background-color 500ms var(--lfe-ease-out),
    box-shadow 500ms var(--lfe-ease-out),
    transform 500ms var(--lfe-ease-out);
}

.lfe-hist__chapter.is-passed .lfe-hist__node {
  background: var(--hist-gold);
  box-shadow: 0 0 0 4px rgba(242, 179, 61, 0.18), 0 0 18px rgba(242, 179, 61, 0.5);
}

.lfe-hist__chapter.is-active .lfe-hist__node { transform: scale(1.3); }

/* Año gigante de fondo (decorativo, duplicado del <time> del h3). */
.lfe-hist__watermark {
  position: absolute;
  z-index: -1;
  top: -0.1em;
  inset-inline-start: -0.04em;
  font-family: var(--lfe-font-display);
  font-style: italic;
  font-size: clamp(6rem, 26vw, 21rem);
  line-height: 0.8;
  letter-spacing: -0.03em;
  white-space: nowrap;
  color: transparent;
  -webkit-text-stroke: 1px rgba(242, 179, 61, 0.22);  /* no toca el contraste del texto */
  pointer-events: none;
  user-select: none;
}

@media (min-width: 1024px) {
  .lfe-hist__chapter:nth-child(even) .lfe-hist__watermark {
    inset-inline-start: auto;
    inset-inline-end: -0.04em;
  }
}

/* ---- Foto principal: marco + sangrado + telon ------------------------- */

.lfe-hist__media { position: relative; }   /* [MOTION] trigger: no animar */

.lfe-hist__photo { margin: 0; }

.lfe-hist__frame {
  position: relative;
  overflow: hidden;                   /* [MOTION] recorta sangrado, zoom y telon */
  aspect-ratio: var(--hist-ratio, 4 / 5);
  background: #140f0c;
  border-radius: 2px;
}

.lfe-hist__photo-inner {
  position: absolute;
  inset: calc(var(--hist-bleed) * -1) 0;   /* [MOTION] 8 % arriba y abajo */
}

.lfe-hist__photo-inner picture,
.lfe-hist__photo-inner img {
  display: block;
  width: 100%;
  height: 100%;
}

.lfe-hist__photo-inner img {
  object-fit: cover;
  transform-origin: 50% 40%;
}

/* Luces: la escena en curso se enciende, las demas quedan en penumbra.
   Solo con movimiento activo (sin JS o reducido: todo encendido). */
.lfe-hist__frame::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 700ms var(--lfe-ease-out);
}

.is-hist-ready .lfe-hist__chapter:not(.is-active) .lfe-hist__frame::after {
  opacity: 0.4;
}

/* Telon de terciopelo con galon y flecos dorados. Sube con transform. */
.lfe-hist__curtain {
  display: none;
  position: absolute;
  inset: -1px;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 0, var(--hist-gold) 0 2.5px, rgba(242, 179, 61, 0) 3px) left bottom / 11px 7px repeat-x,
    linear-gradient(0deg, rgba(0, 0, 0, 0) 7px, var(--hist-gold) 7px 10px, rgba(0, 0, 0, 0) 10px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.3) 0 12px, rgba(255, 255, 255, 0.05) 12px 20px, rgba(0, 0, 0, 0.18) 20px 34px),
    linear-gradient(180deg, var(--hist-crimson) 0%, var(--hist-crimson-deep) 72%, #34060f 100%);
}

.is-hist-ready .lfe-hist__curtain { display: block; }

.lfe-hist__caption {
  margin-top: 0.75rem;
  font-size: var(--lfe-fs-xs);
  letter-spacing: 0.04em;
  color: var(--bone-dim, #A8A294);
}

/* ---- Capas secundarias: polaroid, documento, cartel ------------------- */

.lfe-hist__layer {
  position: absolute;
  z-index: 3;
  pointer-events: none;
}

.lfe-hist__layer--a {
  right: -6%;
  bottom: -12%;
  width: clamp(7.5rem, 36%, 15rem);
}

.lfe-hist__layer--b {
  left: -8%;
  top: 10%;
  width: clamp(6.5rem, 28%, 12rem);
}

@media (max-width: 1023.98px) {
  .lfe-hist__layer--a { right: -3%; bottom: -8%; width: 40%; }
  .lfe-hist__layer--b { left: -4%; top: 40%; width: 32%; }  /* nunca por encima: tocaria el texto */
}

.lfe-hist__doc {
  margin: 0;
  rotate: var(--hist-rot, 0deg);     /* [MOTION] base sin JS; con GSAP la absorbe su transform */
  transform-origin: 50% 40%;
  background: #f3ecdc;
  padding: 0.5rem 0.5rem 1.5rem;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.45),
    0 18px 30px -12px rgba(0, 0, 0, 0.75);
}

.lfe-hist__doc img {
  display: block;
  width: 100%;
  height: auto;
}

.lfe-hist__doc--cartel,
.lfe-hist__doc--recorte { padding: 0; }

/* ---- Texto ------------------------------------------------------------ */

.lfe-hist__copy { position: relative; }     /* [MOTION] trigger: no animar */

.lfe-hist { padding-block: clamp(3rem, 6vw, 5rem) clamp(2rem, 5vw, 4rem); }

.lfe-hist__header {
  text-align: center;
  margin-bottom: clamp(2rem, 5vw, 4rem);
}
.lfe-hist__header .lfe-eyebrow { color: var(--hist-gold); }
.lfe-hist__header .lfe-h2 {
  font-family: var(--lfe-font-display);
  font-style: italic;
  color: var(--bone);
  margin-top: 0.5rem;
}

/* Folio de programa de mano: «Cuadro IV». */
.lfe-hist__kicker {
  margin: 0 0 0.9rem;
  font-family: var(--lfe-font-body);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--hist-gold);
}

.lfe-hist__title {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0 0 1rem;
  line-height: 1.05;
}

.lfe-hist__year {
  font-family: var(--lfe-font-display);
  font-style: italic;
  font-size: clamp(2.25rem, 4.6vw, 4rem);
  line-height: 1;
  color: var(--hist-gold);
  font-variant-numeric: lining-nums;
}

.lfe-hist__name {
  font-family: var(--lfe-font-display);
  font-style: italic;
  font-size: clamp(1.5rem, 2.6vw, 2.35rem);
  color: var(--bone);
  text-wrap: balance;
}

.lfe-hist__text {
  margin: 0;
  max-width: 40ch;
  font-size: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  line-height: 1.65;
  color: var(--bone-dim);
}

/* Hilo dorado corto entre folio y texto, eco de la cuerda. */
.lfe-hist__text::before {
  content: "";
  display: block;
  width: 2.5rem;
  height: 1px;
  margin-bottom: 1rem;
  background: var(--hist-gold);
  opacity: 0.6;
}

/* El documento A cae sobre la esquina inferior derecha: el pie de foto
   deja ese hueco libre para no quedar tapado. */
.lfe-hist__media:has(.lfe-hist__layer--a) .lfe-hist__caption {
  padding-inline-end: 42%;
}

/* ---- Capítulo ancho (plano general a sangre de columna) --------------- */

@media (min-width: 1024px) {
  .lfe-hist__chapter--wide .lfe-hist__scene {
    grid-template-columns: minmax(0, 1fr);
    row-gap: clamp(2rem, 4vw, 3rem);
  }
  .lfe-hist__chapter--wide .lfe-hist__copy,
  .lfe-hist__chapter--wide:nth-child(even) .lfe-hist__copy {
    grid-column: 1;
    grid-row: 1;
    max-width: 44rem;
    padding-inline-start: 4rem;
  }
  .lfe-hist__chapter--wide .lfe-hist__media,
  .lfe-hist__chapter--wide:nth-child(even) .lfe-hist__media {
    grid-column: 1;
    grid-row: 2;
  }
  .lfe-hist__chapter--wide .lfe-hist__layer--a {
    top: -9%;
    right: 3%;
    bottom: auto;
    width: clamp(9rem, 17%, 15rem);
  }
  .lfe-hist__chapter--wide .lfe-hist__layer--b {
    top: auto;
    bottom: -7%;
    left: -2%;
    width: clamp(9rem, 20%, 17rem);
  }
  .lfe-hist__chapter--wide .lfe-hist__watermark,
  .lfe-hist__chapter--wide:nth-child(even) .lfe-hist__watermark {
    inset-inline-start: auto;
    inset-inline-end: -0.04em;
  }
}

/* ---- Estados de movimiento -------------------------------------------- */

/* Espejo de los fromTo del JS (mismo tick): evita un fotograma visible entre
   la clase y el primer render de GSAP. Nunca se aplica sin JS. */
.is-hist-ready .lfe-hist__copy > *,
.is-hist-ready .lfe-hist__doc {
  opacity: 0;
}

/* will-change solo en los capitulos que estan en recorrido (.is-hist-live
   la pone/quita el onToggle del scrub). Nunca permanente. */
.is-hist-ready .is-hist-live [data-hist-depth],
.is-hist-ready .is-hist-live .lfe-hist__photo-inner img {
  will-change: transform;
}

/* ---- Movimiento reducido e impresion: todo visible y quieto ----------- */

@media (prefers-reduced-motion: reduce), print {
  .lfe-hist__curtain,
  .lfe-hist__marker {
    display: none !important;
  }

  .lfe-hist__copy > *,
  .lfe-hist__doc {
    opacity: 1 !important;
  }

  .lfe-hist [data-hist-depth],
  .lfe-hist__photo-inner img,
  .lfe-hist__thread-fill,
  .lfe-hist__rail-fill {
    transform: none !important;
    will-change: auto !important;
  }

  .lfe-hist__frame::after { opacity: 0 !important; }
  .lfe-hist__rail-link.is-current { transform: none; }
}
