/* ============================================================
   EstateOS AI — Secuencia de apertura cinematográfica
   ------------------------------------------------------------
   Contrato de rendimiento (no negociable):
     · Solo se animan `transform`, `opacity`, `clip-path` y
       `stroke-dashoffset`. Ninguna propiedad que dispare
       layout o paint del árbol → todo vive en el compositor.
     · `will-change` se declara únicamente en las capas que
       realmente se mueven, y se libera al terminar el acto.
     · La secuencia completa dura 3.05 s y es interrumpible en
       cualquier fotograma (clic, tecla, scroll).
     · `prefers-reduced-motion: reduce` la elimina por completo:
       el overlay ni se pinta.

   Estructura dramática:
     ACTO I   (0.00–1.05 s)  El trazo. Una línea de luz nace del
                             centro y se convierte en el monograma.
     ACTO II  (0.85–2.20 s)  El plano. Una retícula arquitectónica
                             se dibuja y las palabras se revelan.
     ACTO III (2.20–3.05 s)  La apertura. El telón se parte en dos
                             y la página real emerge por detrás.
   ============================================================ */

/* ---------- Capa raíz ---------- */

#intro {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #0a0f0c;
  /* Aísla el subárbol: el navegador no recalcula nada de la página
     por lo que ocurra aquí dentro. */
  contain: strict;
}

/* El documento no debe poder desplazarse mientras el telón está
   bajado, ni siquiera con el teclado. */
html[data-intro='running'],
html[data-intro='running'] body {
  overflow: hidden;
  /* Evita el salto de layout al reaparecer la barra de scroll. */
  scrollbar-gutter: stable;
}

/* ---------- Telón (ACTO III) ----------
   Dos mitades que se separan revelando la página. El pseudo-relleno
   interno mantiene el color al 100% durante los actos I y II. */

.intro__curtain {
  position: absolute;
  inset: 0;
  display: flex;
  pointer-events: none;
}

.intro__panel {
  flex: 1 1 50%;
  background: linear-gradient(180deg, #0d1410 0%, #0a0f0c 55%, #070b09 100%);
  will-change: transform;
  transform: translate3d(0, 0, 0);
}

/* Costura luminosa: una hebra vertical de luz en el centro que
   se apaga justo cuando el telón empieza a abrirse. */
.intro__seam {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  margin-left: -0.5px;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(190, 232, 208, 0.5) 22%,
    rgba(226, 176, 88, 0.85) 50%,
    rgba(190, 232, 208, 0.5) 78%,
    transparent 100%
  );
  opacity: 0;
  transform: scaleY(0.2);
  transform-origin: 50% 50%;
  animation:
    intro-seam-open 620ms cubic-bezier(0.16, 1, 0.3, 1) 60ms forwards,
    intro-seam-fade 340ms ease-out 2100ms forwards;
  will-change: transform, opacity;
}

@keyframes intro-seam-open {
  0% { opacity: 0; transform: scaleY(0.08); }
  55% { opacity: 1; }
  100% { opacity: 0.9; transform: scaleY(1); }
}
@keyframes intro-seam-fade {
  to { opacity: 0; }
}

/* ---------- Escenario central ---------- */

.intro__stage {
  position: relative;
  width: min(92vw, 720px);
  display: grid;
  place-items: center;
  gap: 1.75rem;
  text-align: center;
  z-index: 2;
}

/* ---------- Halo atmosférico ----------
   Un solo elemento con blur; se escala en lugar de re-difuminarse,
   porque cambiar `filter: blur()` en cada fotograma es carísimo. */

.intro__halo {
  position: absolute;
  width: 620px;
  height: 620px;
  border-radius: 50%;
  background: radial-gradient(
    circle at 50% 50%,
    rgba(47, 122, 91, 0.42) 0%,
    rgba(30, 74, 58, 0.24) 38%,
    transparent 70%
  );
  filter: blur(46px);
  opacity: 0;
  transform: scale(0.42);
  animation: intro-halo 2400ms cubic-bezier(0.22, 1, 0.36, 1) 120ms forwards;
  will-change: transform, opacity;
  pointer-events: none;
}

@keyframes intro-halo {
  0% { opacity: 0; transform: scale(0.42); }
  35% { opacity: 1; }
  100% { opacity: 0.55; transform: scale(1.18); }
}

/* ---------- ACTO I · El monograma que se dibuja ---------- */

.intro__mark {
  position: relative;
  width: clamp(76px, 12vw, 108px);
  height: clamp(76px, 12vw, 108px);
  opacity: 0;
  transform: scale(0.9);
  animation: intro-mark-in 760ms cubic-bezier(0.16, 1, 0.3, 1) 180ms forwards;
  will-change: transform, opacity;
}

@keyframes intro-mark-in {
  0% { opacity: 0; transform: scale(0.9) rotate(-3deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

/* El contorno se dibuja a sí mismo. `stroke-dashoffset` se anima en
   el hilo principal pero sobre un único path corto: coste marginal. */
.intro__mark-outline {
  stroke-dasharray: 132;
  stroke-dashoffset: 132;
  animation: intro-draw 1080ms cubic-bezier(0.65, 0, 0.35, 1) 240ms forwards;
}
.intro__mark-glyph {
  opacity: 0;
  animation: intro-glyph 520ms ease-out 900ms forwards;
}
.intro__mark-sweep {
  opacity: 0;
  transform-origin: 50% 50%;
  animation: intro-sweep 1500ms cubic-bezier(0.33, 1, 0.68, 1) 760ms forwards;
}

@keyframes intro-draw {
  to { stroke-dashoffset: 0; }
}
@keyframes intro-glyph {
  0% { opacity: 0; transform: translate3d(0, 5%, 0); }
  100% { opacity: 1; transform: translate3d(0, 0, 0); }
}
@keyframes intro-sweep {
  0% { opacity: 0; transform: rotate(0deg); }
  25% { opacity: 0.85; }
  100% { opacity: 0; transform: rotate(220deg); }
}

/* ---------- ACTO II · El plano arquitectónico ----------
   Retícula de líneas que se despliegan como un blueprint.
   `mask-image` la desvanece en los bordes sin un segundo elemento. */

.intro__blueprint {
  position: absolute;
  inset: -12%;
  opacity: 0;
  animation: intro-blueprint 1900ms ease-out 620ms forwards;
  -webkit-mask-image: radial-gradient(ellipse at 50% 50%, #000 28%, transparent 74%);
  mask-image: radial-gradient(ellipse at 50% 50%, #000 28%, transparent 74%);
  pointer-events: none;
}
.intro__blueprint line {
  stroke: rgba(190, 232, 208, 0.3);
  stroke-width: 0.6;
  stroke-dasharray: 200;
  stroke-dashoffset: 200;
  animation: intro-draw 1500ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.intro__blueprint circle {
  fill: none;
  stroke: rgba(226, 176, 88, 0.5);
  stroke-width: 0.7;
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
  animation: intro-draw 1700ms cubic-bezier(0.22, 1, 0.36, 1) 260ms forwards;
}

@keyframes intro-blueprint {
  0% { opacity: 0; transform: scale(1.06); }
  40% { opacity: 1; }
  100% { opacity: 0.62; transform: scale(1); }
}

/* ---------- ACTO II · Tipografía revelada por máscara ----------
   El texto no aparece con fade: se descubre. `clip-path` sobre un
   inset animado da el efecto de cortinilla tipográfica de cine. */

.intro__wordmark {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(1.9rem, 6.2vw, 3.4rem);
  font-weight: 400;
  letter-spacing: -0.022em;
  line-height: 1.06;
  color: #f4faf6;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 0.34em;
}

.intro__word {
  display: inline-block;
  clip-path: inset(0 0 110% 0);
  transform: translate3d(0, 0.42em, 0);
  opacity: 0;
  animation: intro-word 900ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: calc(880ms + var(--w) * 105ms);
  will-change: transform, clip-path, opacity;
}
.intro__word em {
  font-style: italic;
  color: #e2b058;
}

@keyframes intro-word {
  0% { clip-path: inset(0 0 110% 0); transform: translate3d(0, 0.42em, 0); opacity: 0; }
  100% { clip-path: inset(0 0 -12% 0); transform: translate3d(0, 0, 0); opacity: 1; }
}

/* ---------- ACTO II · Filete y subtítulo ---------- */

.intro__rule {
  width: min(320px, 52vw);
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(226, 176, 88, 0.9), transparent);
  transform: scaleX(0);
  transform-origin: 50% 50%;
  animation: intro-rule 760ms cubic-bezier(0.16, 1, 0.3, 1) 1420ms forwards;
  will-change: transform;
}

@keyframes intro-rule {
  to { transform: scaleX(1); }
}

.intro__sub {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: clamp(0.7rem, 1.9vw, 0.82rem);
  letter-spacing: 0.19em;
  text-transform: uppercase;
  font-weight: 600;
  color: rgba(190, 232, 208, 0.72);
  margin: 0;
  opacity: 0;
  transform: translate3d(0, 8px, 0);
  animation: intro-sub 720ms ease-out 1620ms forwards;
  will-change: transform, opacity;
}

@keyframes intro-sub {
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}

/* ---------- Barra de progreso del acto ---------- */

.intro__meter {
  position: absolute;
  left: 50%;
  bottom: clamp(2.2rem, 7vh, 4rem);
  transform: translateX(-50%);
  width: min(220px, 44vw);
  height: 2px;
  border-radius: 2px;
  background: rgba(190, 232, 208, 0.14);
  overflow: hidden;
  z-index: 3;
}
.intro__meter i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, rgba(47, 122, 91, 0.9), #e2b058);
  transform: scaleX(0);
  transform-origin: 0 50%;
  animation: intro-meter 2200ms cubic-bezier(0.42, 0, 0.58, 1) 120ms forwards;
  will-change: transform;
}

@keyframes intro-meter {
  to { transform: scaleX(1); }
}

/* ---------- Salida accesible ----------
   Un botón real, no un div: enfocable, anunciable y operable con
   teclado desde el primer fotograma de la secuencia. */

.intro__skip {
  position: absolute;
  right: clamp(1rem, 3vw, 2.25rem);
  top: clamp(1rem, 3vh, 2rem);
  z-index: 4;
  appearance: none;
  border: 1px solid rgba(190, 232, 208, 0.28);
  background: rgba(10, 15, 12, 0.55);
  color: rgba(244, 250, 246, 0.86);
  font: 600 0.72rem/1 system-ui, -apple-system, sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.62rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0;
  animation: intro-sub 500ms ease-out 700ms forwards;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}
.intro__skip:hover {
  border-color: rgba(226, 176, 88, 0.75);
  background: rgba(30, 74, 58, 0.6);
}
.intro__skip:focus-visible {
  outline: 2px solid #e2b058;
  outline-offset: 3px;
  opacity: 1;
  animation: none;
}
@media (pointer: coarse) {
  .intro__skip { min-height: 44px; padding-inline: 1.15rem; }
}

/* ---------- ACTO III · La apertura ----------
   Se activa por clase, no por retardo: así el guion en JS conserva
   el control del momento exacto y del caso "usuario la salta". */

#intro[data-act='out'] .intro__panel:first-child {
  animation: intro-part-left 780ms cubic-bezier(0.76, 0, 0.24, 1) forwards;
}
#intro[data-act='out'] .intro__panel:last-child {
  animation: intro-part-right 780ms cubic-bezier(0.76, 0, 0.24, 1) forwards;
}
#intro[data-act='out'] .intro__stage {
  animation: intro-stage-out 480ms cubic-bezier(0.4, 0, 1, 1) forwards;
}
#intro[data-act='out'] .intro__halo,
#intro[data-act='out'] .intro__meter {
  animation: intro-fade-out 340ms ease-out forwards;
}
#intro[data-act='out'] .intro__skip {
  animation: intro-fade-out 200ms ease-out forwards;
  pointer-events: none;
}

@keyframes intro-part-left {
  to { transform: translate3d(-101%, 0, 0); }
}
@keyframes intro-part-right {
  to { transform: translate3d(101%, 0, 0); }
}
@keyframes intro-stage-out {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.07); }
}
@keyframes intro-fade-out {
  to { opacity: 0; }
}

/* Salto inmediato: cero animación, cero fotograma intermedio. */
#intro[data-act='skip'] {
  display: none;
}

/* ---------- Entrada escalonada del contenido real ----------
   La página que hay detrás del telón no aparece de golpe: sus
   bandas suben en cascada mientras el telón todavía se separa.
   Se activa con `data-reveal` para que el HTML sea válido y
   visible sin JavaScript. */

[data-reveal] {
  opacity: 0;
  transform: translate3d(0, 22px, 0);
}
html[data-intro='done'] [data-reveal],
html:not([data-intro]) [data-reveal] {
  animation: intro-reveal 820ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: calc(var(--r, 0) * 110ms);
}

@keyframes intro-reveal {
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}

/* ---------- Respeto absoluto por la preferencia del usuario ---------- */

@media (prefers-reduced-motion: reduce) {
  #intro { display: none !important; }
  html[data-intro='running'],
  html[data-intro='running'] body { overflow: auto; }
  [data-reveal] {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }
}

/* Sin JS el telón nunca debe quedarse puesto. Si el script no se
   ejecuta, esta regla lo retira sola tras la secuencia. */
html.no-js #intro {
  display: none;
}
