/* =========================================================================
   IAbyLio, hero de la Home: "El lunes que se repite" (prefijo hh-)

   Ocho tiempos de una sola escena. El copy es el aprobado por Lio.

   Dos modos, mismo HTML:

   1. ESTATICO (por defecto: sin JS, reduced motion, sin WebGL, impresion).
      Los ocho tiempos son ocho bloques 16:9 (9:16 en vertical), cada uno con
      su fotograma fijo (render de Blender del storyboard) y su texto encima.
      La historia se lee entera sin tres ni gsap.

   2. VIVO (html.hh-vivo, lo pone el <head> si hay JS y no hay reduced motion).
      La seccion se fija (position: sticky) durante un recorrido largo; un canvas
      3D a pantalla completa va detras y los ocho <article> se apilan encima:
      js/hero-historia.js les da opacidad y desplazamiento segun el scroll.

   Unidad de maqueta --hh-u: el 1 % del ancho del cuadro (cqw), limitada en
   modo vivo por la altura (1,78 svh) para que en ventanas anchas y bajas el
   texto no se salga. Todas las medidas del texto salen de ella, como en el
   storyboard (_storyboard/hero-historia/).

   Solo se animan transform y opacity. Radios de la escala bloqueada.
   ========================================================================= */

:root {
  /* Largo del recorrido fijado (sin contar la pantalla del propio hero). */
  --hh-recorrido: 770vh;
  --hh-fondo: #05070f;
}
@media (max-aspect-ratio: 1/1) {
  :root { --hh-recorrido: 520vh; }
}

.hh {
  position: relative;
  background: var(--hh-fondo);
  /* Unidad de maqueta y margen izquierdo del texto: el mismo que el del logo
     de la cabecera (barra de max-width --ancho, centrada). */
  --hh-u: 1cqw;
  --hh-izq: max(var(--margen), calc((100cqw - var(--ancho)) / 2 + var(--margen)));
}

/* ======================================================================== *
 * 1. ESTATICO
 * ======================================================================== */
.hh-t {
  position: relative;
  container-type: inline-size;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  width: min(100%, 177.78vh);
  width: min(100%, 177.78svh);
  margin: 0 auto;
  background: var(--hh-fondo);
}
.hh-t + .hh-t { border-top: 1px solid var(--linea); }

.hh-img,
.hh-img img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.hh-img img { object-fit: cover; }

.hh-fondo,
.hh-avance,
.hh-rebobinar,
.hh-pausa { display: none; }

/* Velos: lo unico que se pone entre la escena y la frase. */
.hh-velo { position: absolute; inset: 0; pointer-events: none; }
.hh-velo--izq {
  background: linear-gradient(90deg, rgba(5, 7, 15, 0.86) 0%, rgba(5, 7, 15, 0.55) 30%, rgba(5, 7, 15, 0) 56%);
}
.hh-velo--abajo {
  background:
    linear-gradient(0deg, rgba(5, 7, 15, 0.9) 0%, rgba(5, 7, 15, 0.5) 34%, rgba(5, 7, 15, 0) 62%),
    linear-gradient(90deg, rgba(5, 7, 15, 0.6), rgba(5, 7, 15, 0) 50%);
}
.hh-velo--pausa { background: radial-gradient(90% 70% at 50% 46%, rgba(5, 7, 15, 0.84), rgba(5, 7, 15, 0.7)); }
.hh-t--pausa .hh-img img { filter: saturate(0.4) brightness(0.8); }

/* El texto: HTML real encima de la escena. */
.hh-texto {
  position: absolute;
  left: var(--hh-izq);
  width: min(calc(33 * var(--hh-u)), calc(100cqw - var(--hh-izq) - 52cqw));
  display: grid;
  gap: calc(1.5 * var(--hh-u));
}
.hh-texto--alto { top: calc(15 * var(--hh-u)); }
.hh-texto--alto-4 { top: calc(12 * var(--hh-u)); }
/* La linea del 4 se queda a la izquierda del portatil, que en ese encuadre llega hasta el 34 % del ancho. */
.hh-texto--alto-4 .hh-linea { max-width: calc(21 * var(--hh-u)); }
.hh-texto--medio { top: 50%; transform: translateY(-50%); }
.hh-texto--bajo { bottom: calc(8.6 * var(--hh-u)); }
.hh-texto--estrecho { width: min(calc(27 * var(--hh-u)), calc(100cqw - var(--hh-izq) - 52cqw)); }
.hh-texto--ancho { width: min(calc(35 * var(--hh-u)), calc(100cqw - var(--hh-izq) - 50cqw)); }
.hh-texto--centro {
  left: 50%;
  top: 46%;
  width: min(calc(62 * var(--hh-u)), 90cqw);
  transform: translate(-50%, -50%);
  justify-items: center;
  text-align: center;
}

.hh-frase {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
  font-size: max(1.875rem, calc(4.5 * var(--hh-u)));
  color: var(--texto);
  text-wrap: balance;
}
.hh-frase--larga {
  font-size: max(1.625rem, calc(3.25 * var(--hh-u)));
  line-height: 1.04;
}
.hh-frase em { font-style: normal; color: var(--azul-claro); }
.hh-ren { display: block; }

.hh-linea {
  margin: 0;
  max-width: calc(31 * var(--hh-u));
  font-size: max(0.9375rem, calc(1.34 * var(--hh-u)));
  line-height: 1.5;
  color: var(--hm-texto-2);
  text-wrap: pretty;
}
.hh-linea--baja {
  display: inline-flex;
  align-items: center;
  gap: 0.7em;
  color: var(--texto);
  font-weight: 600;
}
.hh-linea--baja::after {
  content: '↓';
  font-family: var(--f-display);
  color: var(--azul-claro);
  font-size: 1.12em;
}

/* El dato: la cifra manda. */
.hh-cifra {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 0.86;
  /* "Más del 80%" cabe en una linea (5,25 em de ancho): nunca parte el % de la cifra. */
  font-size: max(3rem, calc(10.4 * var(--hh-u)));
  white-space: nowrap;
  color: var(--texto);
}
/* Ancho fijo de dos cifras (tabulares): la cuenta no mueve el % ni deja hueco al llegar a 80. */
.hh-cifra__num { display: inline-block; font-variant-numeric: tabular-nums; min-width: calc(2ch - 0.1em); text-align: left; }
.hh-cifra small {
  display: block;
  margin: calc(2 * var(--hh-u)) auto 0;
  max-width: 26ch;
  white-space: normal;
  font-weight: 600;
  font-size: max(1.375rem, calc(3.1 * var(--hh-u)));
  line-height: 1.06;
  letter-spacing: -0.035em;
}
.hh-cita {
  max-width: none;
  font-family: var(--f-mono);
  font-weight: 500;
  font-size: max(0.9375rem, calc(1.3 * var(--hh-u)));
  line-height: 1.5;
  color: #d4dee6;
  text-shadow: 0 1px 14px rgba(3, 5, 12, 0.9);
}

.hh-boton {
  justify-self: start;
  margin-top: calc(0.4 * var(--hh-u));
  font-size: max(1rem, calc(1.2 * var(--hh-u)));
  padding: max(1rem, calc(1.15 * var(--hh-u))) max(1.4rem, calc(1.6 * var(--hh-u)));
}

/* ----- vertical (movil y tabletas en vertical): texto arriba, escena abajo */
@media (max-aspect-ratio: 1/1) {
  .hh-t {
    aspect-ratio: 9 / 16;
    width: 100%;
  }
  .hh-velo--izq,
  .hh-velo--abajo {
    background: linear-gradient(180deg, rgba(5, 7, 15, 0.92) 0%, rgba(5, 7, 15, 0.6) 30%, rgba(5, 7, 15, 0) 52%);
  }
  .hh-texto,
  .hh-texto--estrecho,
  .hh-texto--ancho {
    left: calc(5.5 * var(--hh-u));
    right: calc(5.5 * var(--hh-u));
    width: auto;
    top: calc(23 * var(--hh-u));
    bottom: auto;
    transform: none;
    gap: calc(4 * var(--hh-u));
  }
  .hh-texto--alto-4 { top: calc(21 * var(--hh-u)); }
  .hh-texto--alto-4 .hh-linea { max-width: none; }
  .hh-texto--ancho { top: calc(20 * var(--hh-u)); gap: calc(3.4 * var(--hh-u)); }
  .hh-texto--centro {
    top: calc(26 * var(--hh-u));
    left: calc(5.5 * var(--hh-u));
    right: calc(5.5 * var(--hh-u));
    width: auto;
    transform: none;
  }
  .hh-frase { font-size: max(1.75rem, calc(10.4 * var(--hh-u))); }
  .hh-frase--larga { font-size: max(1.5rem, calc(7.3 * var(--hh-u))); line-height: 1.05; }
  .hh-linea { max-width: none; font-size: max(0.9375rem, calc(4.1 * var(--hh-u))); }
  .hh-cifra { font-size: max(3rem, calc(15 * var(--hh-u))); }
  .hh-cifra small { font-size: max(1.25rem, calc(6.2 * var(--hh-u))); margin-top: calc(3.6 * var(--hh-u)); }
  .hh-cita { font-size: max(0.875rem, calc(3.7 * var(--hh-u))); }
  /* En movil el ultimo tiempo no lleva boton propio: basta el de la cabecera. */
  .hh-boton { display: none; }
}

/* ======================================================================== *
 * 2. VIVO: seccion fijada, canvas 3D detras, ocho textos apilados encima
 * ======================================================================== */
@media screen {
  html.hh-vivo .hh {
    --hh-u: min(1cqw, 1.78vh);
    --hh-u: min(1cqw, 1.78svh);
  }
  html.hh-vivo .hh-pista {
    height: calc(100vh + var(--hh-recorrido));
    height: calc(100svh + var(--hh-recorrido));
    position: relative;
    /* La escena arranca pegada al borde de arriba: la cabecera (transparente
       mientras dura el hero) va encima. */
    margin-top: calc(-1 * var(--hm-cab));
  }
  html.hh-vivo .hh-escenario {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100svh;
    overflow: hidden;
    container-type: inline-size;
    background: var(--hh-fondo);
  }

  /* Cabecera sobre la escena; vuelve a ser opaca al terminar el hero. */
  html.hh-vivo .hm-cabecera.hm-cabecera--sobre {
    background: transparent;
    border-bottom-color: transparent;
  }

  html.hh-vivo .hh-fondo {
    display: block;
    position: absolute;
    inset: 0;
  }
  html.hh-vivo .hh-fondo picture,
  html.hh-vivo .hh-poster {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
  }
  html.hh-vivo .hh-poster { object-fit: cover; }
  html.hh-vivo .hh-lienzo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    opacity: 0;
    transition: opacity 700ms var(--ease);
  }
  html.hh-vivo .hh-3d .hh-lienzo { opacity: 1; }
  html.hh-vivo .hh-3d .hh-poster { opacity: 0; transition: opacity 700ms var(--ease) 200ms; }

  /* Oscurece los bordes: la escena queda en el centro de atencion. */
  html.hh-vivo .hh-escenario::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background: radial-gradient(120% 92% at 62% 56%, rgba(3, 5, 12, 0) 38%, rgba(3, 5, 12, 0.78) 100%);
  }

  html.hh-vivo .hh-tiempos { position: absolute; inset: 0; z-index: 2; }
  html.hh-vivo .hh-t {
    position: absolute;
    inset: 0;
    width: auto;
    aspect-ratio: auto;
    margin: 0;
    container-type: normal;
    overflow: visible;
    background: transparent;
    border-top: 0;
    opacity: 0;
    pointer-events: none;
  }
  /* Antes de que el JS escriba las opacidades: ya se lee el primer tiempo. */
  html.hh-vivo .hh-t[data-t="0"] { opacity: 1; }
  html.hh-vivo .hh-t.is-activo .hh-boton { pointer-events: auto; }
  html.hh-vivo .hh-img { display: none; }

  /* Sin 3D (WebGL ausente o roto): los fotogramas fijos, con fundido entre tiempos. */
  html.hh-vivo.hh-imagenes .hh-img { display: block; }
  html.hh-vivo.hh-imagenes .hh-fondo { display: none; }

  /* Interfaz minima: una barra continua que se llena con el scroll. */
  html.hh-vivo .hh-avance {
    display: block;
    position: absolute;
    z-index: 3;
    left: var(--hh-izq);
    bottom: max(calc(3.3 * var(--hh-u)), env(safe-area-inset-bottom));
    width: 240px;
    height: 2px;
    border-radius: 1px;
    background: rgba(143, 176, 200, 0.4);
    pointer-events: none;
  }
  .hh-avance__relleno {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--azul-claro);
    border-radius: 1px;
    box-shadow: 0 0 10px 1px rgba(79, 180, 232, 0.85);
    transform-origin: 0 50%;
    transform: scaleX(0);
  }

  /* Rebobinado (tiempo 5): lineas de cinta sobre la escena mientras todo va marcha atras. */
  html.hh-vivo .hh-rebobinar {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    background:
      repeating-linear-gradient(0deg, rgba(120, 175, 225, 0.13) 0 2px, rgba(120, 175, 225, 0) 2px 6px),
      linear-gradient(90deg, rgba(10, 143, 208, 0.12), rgba(10, 143, 208, 0) 40%, rgba(10, 143, 208, 0.12));
  }

  /* Luz del tiempo 8: un disco de gradiente gigante que crece desde el centro de la pantalla del
     portatil (hero-historia.js le pone posicion y escala) hasta cubrir el cuadro. Color = fondo del caso. */
  /* Marca de pausa (tiempo 6): la escena se queda detenida. */
  html.hh-vivo .hh-pausa {
    display: flex;
    gap: calc(0.5 * var(--hh-u));
    position: absolute;
    z-index: 3;
    right: calc(4.4 * var(--hh-u));
    bottom: max(calc(3.1 * var(--hh-u)), env(safe-area-inset-bottom));
    opacity: 0;
    pointer-events: none;
  }
  .hh-pausa i {
    display: block;
    width: max(5px, calc(0.55 * var(--hh-u)));
    height: max(16px, calc(1.9 * var(--hh-u)));
    border-radius: 1px;
    background: rgba(230, 230, 225, 0.6);
  }

  @media (max-aspect-ratio: 1/1) {
    html.hh-vivo .hh-avance {
      left: calc(5.5 * var(--hh-u));
      bottom: max(calc(6 * var(--hh-u)), env(safe-area-inset-bottom));
      width: calc(45 * var(--hh-u));
    }
    html.hh-vivo .hh-pausa { right: calc(5.5 * var(--hh-u)); bottom: max(calc(6 * var(--hh-u)), env(safe-area-inset-bottom)); }
    html.hh-vivo .hh-escenario::before {
      background: radial-gradient(130% 80% at 50% 70%, rgba(3, 5, 12, 0) 42%, rgba(3, 5, 12, 0.75) 100%);
    }
  }
}

/* Tactil (iPhone, iPad, movil; html.hm-tactil lo pone el <head> de index.html): las piezas de texto cambian de opacidad y de
   posicion en casi cada cuadro de scroll. Cada una en su capa de GPU: moverlas es componer, no repintar texto a 3x. Solo las hojas
   (frases, lineas, boton, cifra): el contenedor de cada tiempo ocupa toda la pantalla y no se promueve. En escritorio no aplica. */
html.hm-tactil.hh-vivo .hh-t :is(.hh-frase, .hh-linea, .hh-boton, .hh-cifra, .hh-ren) { will-change: transform, opacity; }

/* Quien pide menos transparencia no pierde nada: el hero no usa vidrio CSS. */
@media print {
  .hh-t { break-inside: avoid; }
}
