/* ═══════════════════════════════════════════════════════════════════════
   EL INTRO DE PLAYICFES  ·  solo cuando se abre como app instalada
   ───────────────────────────────────────────────────────────────────────
   Tres segundos y medio de arranque: la noche se abre, Saber aterriza, el
   nombre se enciende letra por letra y ACIE firma. Después, la app.

   Todo el movimiento es CSS: las animaciones corren en el compositor y no
   compiten con el arranque de la página. El JavaScript solo va marcando
   las fases y pone el sonido.

   La clase `pi-app` la escribe un script diminuto en el <head>, ANTES de
   pintar, para que no se alcance a ver la página bajo el telón.
   ═══════════════════════════════════════════════════════════════════════ */

.pi-intro { display: none; }

html.pi-app-intro .pi-intro {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #070e24;
  overflow: hidden;
  /* Cubre también las zonas del notch mientras dura */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
html.pi-app-intro, html.pi-app-intro body { overflow: hidden; }

/* ── El fondo: tres capas que se mueven a distinta velocidad ──────────── */

/* 1. Aurora — dos manchas de color que respiran. */
.pi-in-aurora {
  position: absolute; inset: -30%;
  background:
    radial-gradient(38% 30% at 22% 28%, rgba(22, 196, 107, 0.42), transparent 70%),
    radial-gradient(34% 28% at 78% 68%, rgba(96, 165, 250, 0.30), transparent 70%),
    radial-gradient(30% 24% at 60% 18%, rgba(255, 209, 102, 0.18), transparent 70%);
  filter: blur(28px);
  animation: pi-in-respirar 5s ease-in-out infinite alternate;
}
@keyframes pi-in-respirar {
  from { transform: scale(1) rotate(0deg);      opacity: 0.75; }
  to   { transform: scale(1.18) rotate(8deg);   opacity: 1; }
}

/* 2. Rayos — un abanico que gira detrás de la mascota. */
.pi-in-rayos {
  position: absolute; left: 50%; top: 44%;
  width: 190vmax; height: 190vmax;
  margin: -95vmax 0 0 -95vmax;
  background: repeating-conic-gradient(
    from 0deg,
    rgba(255, 255, 255, 0.055) 0deg 5deg,
    transparent 5deg 15deg);
  opacity: 0;
  animation: pi-in-girar 14s linear infinite, pi-in-rayos-entra 0.9s 0.35s ease-out forwards;
}
@keyframes pi-in-girar     { to { transform: rotate(360deg); } }
@keyframes pi-in-rayos-entra { to { opacity: 1; } }

/* 3. Estrellas — puntos que titilan; se generan desde JS. */
.pi-in-estrella {
  position: absolute;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  animation: pi-in-titilar 2.6s ease-in-out infinite;
}
@keyframes pi-in-titilar {
  0%, 100% { opacity: 0.12; transform: scale(0.7); }
  50%      { opacity: 0.95; transform: scale(1.3); }
}

/* ── El escenario ─────────────────────────────────────────────────────── */
.pi-in-centro {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  padding: 24px;
}

/* Saber cae desde arriba, rebota al aterrizar y se queda flotando. */
.pi-in-saber {
  width: min(38vw, 168px);
  height: auto;
  opacity: 0;
  transform: translateY(-160px) scale(0.35);
  filter: drop-shadow(0 18px 34px rgba(0, 0, 0, 0.55));
  animation: pi-in-aterrizar 0.85s cubic-bezier(0.22, 1.5, 0.36, 1) 0.1s forwards,
             pi-in-flotar 2.6s ease-in-out 1s infinite;
}
@keyframes pi-in-aterrizar {
  0%   { opacity: 0; transform: translateY(-160px) scale(0.35); }
  60%  { opacity: 1; transform: translateY(14px)   scale(1.12); }
  80%  {             transform: translateY(-6px)   scale(0.97); }
  100% { opacity: 1; transform: translateY(0)      scale(1); }
}
@keyframes pi-in-flotar {
  0%, 100% { margin-top: 0; }
  50%      { margin-top: -9px; }
}

/* La onda de choque del aterrizaje. */
.pi-in-onda {
  position: absolute;
  top: 50%; left: 50%;
  width: 40px; height: 40px;
  margin: -20px 0 0 -20px;
  border: 3px solid rgba(22, 196, 107, 0.85);
  border-radius: 50%;
  opacity: 0;
  animation: pi-in-onda 0.75s 0.62s ease-out forwards;
}
@keyframes pi-in-onda {
  0%   { opacity: 0.9; transform: scale(0.3); }
  100% { opacity: 0;   transform: scale(9); }
}

/* ── El nombre, letra por letra ───────────────────────────────────────── */
.pi-in-nombre {
  margin: 20px 0 0;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: clamp(2.3rem, 12vw, 3.6rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1;
  color: #fff;
  white-space: nowrap;
}
.pi-in-letra {
  display: inline-block;
  opacity: 0;
  transform: translateY(26px) rotate(-9deg) scale(0.6);
  animation: pi-in-letra 0.5s cubic-bezier(0.22, 1.4, 0.36, 1) forwards;
}
@keyframes pi-in-letra {
  to { opacity: 1; transform: translateY(0) rotate(0) scale(1); }
}
.pi-in-nombre .verde {
  color: #16c46b;
  text-shadow: 0 0 18px rgba(22, 196, 107, 0.75), 0 0 46px rgba(22, 196, 107, 0.35);
}

/* La firma: «by» encima y el logo de ACIE debajo, en grande y sin recuadro.
   El logo original tiene el texto «ACIE» en negro y sobre la noche
   desaparecía; se usa una copia con la tinta pasada a blanco (los cuatro
   círculos de color se respetan) sobre fondo transparente. */
.pi-in-firma {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 26px;
  opacity: 0;
  transform: translateY(12px);
  animation: pi-in-firma 0.7s 1.9s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes pi-in-firma { to { opacity: 1; transform: translateY(0); } }
.pi-in-by {
  font-family: 'Caveat', cursive, system-ui;
  font-size: 1.9rem;
  line-height: 1;
  color: #a9bcd9;
}
.pi-in-logo-caja {
  position: relative;
  display: block;
  line-height: 0;
}
.pi-in-logo-caja img {
  display: block;
  height: min(27vw, 122px);
  width: auto;
  filter: drop-shadow(0 0 22px rgba(255, 255, 255, 0.22));
}
/* El destello barre SOLO la silueta del logo: la máscara lo recorta, y lo
   que se mueve es el degradado (no el elemento), porque si se moviera el
   elemento se llevaría la máscara consigo y no se vería nada. */
.pi-in-logo-caja::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 42%, rgba(255, 255, 255, 0.9) 50%, transparent 58%);
  background-size: 300% 100%;
  background-position: 200% 0;
  -webkit-mask-image: url('../img/logo_acie_claro.png');
          mask-image: url('../img/logo_acie_claro.png');
  -webkit-mask-size: contain;      mask-size: contain;
  -webkit-mask-repeat: no-repeat;  mask-repeat: no-repeat;
  -webkit-mask-position: center;   mask-position: center;
  animation: pi-in-destello 1s 2.45s ease-out forwards;
  pointer-events: none;
}
@keyframes pi-in-destello { to { background-position: -100% 0; } }

/* ── Salida: un fogonazo y se abre el telón ───────────────────────────── */
.pi-in-flash {
  position: absolute; inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
html.pi-intro-saliendo .pi-in-flash { animation: pi-in-flash 0.5s ease-out forwards; }
@keyframes pi-in-flash {
  0%   { opacity: 0; }
  22%  { opacity: 0.9; }
  100% { opacity: 0; }
}
html.pi-intro-saliendo .pi-intro {
  animation: pi-in-salir 0.55s 0.16s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}
@keyframes pi-in-salir {
  to { opacity: 0; transform: scale(1.14); filter: blur(6px); }
}

/* Saltar: discreto, pero ahí. */
.pi-in-saltar {
  position: absolute;
  bottom: calc(26px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: none; border: 0;
  color: rgba(255, 255, 255, 0.4);
  font: 600 0.78rem/1 system-ui, sans-serif;
  letter-spacing: 0.06em;
  padding: 12px 20px;
  cursor: pointer;
  opacity: 0;
  animation: pi-in-firma 0.5s 1.2s ease-out forwards;
}

/* Quien pidió menos movimiento recibe la misma escena, quieta y corta. */
@media (prefers-reduced-motion: reduce) {
  .pi-in-aurora, .pi-in-rayos, .pi-in-estrella,
  .pi-in-onda, .pi-in-logo-caja::after { animation: none; }
  .pi-in-rayos, .pi-in-onda { opacity: 0; }
  .pi-in-saber { animation: pi-in-firma 0.3s ease-out forwards; transform: none; }
  .pi-in-letra { animation: pi-in-firma 0.3s ease-out forwards; transform: none; }
  .pi-in-firma { animation-delay: 0.3s; }
}
