/* =====================================================================
   ANIMACIONES
   ===================================================================== */

/* ---------- Animaciones continuas ---------- */
@keyframes girar { to { transform: rotate(360deg); } }
@keyframes orbita { to { --ang: 360deg; } }
@keyframes barrido { 0% { left: -60%; } 55%, 100% { left: 130%; } }
@keyframes eq { from { height: 25%; } to { height: 100%; } }
@keyframes parpadeo { 50% { opacity: 0; } }
@keyframes titilar { 0%, 100% { opacity: .45; transform: translate(-50%, -50%) scale(.72); } 50% { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes rebote { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes mano { 0%, 100% { transform: translateX(9px); } 50% { transform: translateX(-9px); } }
@keyframes flotar {
  0%, 100% { transform: translateY(0) rotateX(5deg) rotateY(-5deg); }
  50% { transform: translateY(-9px) rotateX(2deg) rotateY(5deg); }
}
@keyframes sombra-flotar { 0%, 100% { transform: scaleX(1); opacity: 1; } 50% { transform: scaleX(.86); opacity: .7; } }
@keyframes anillo-sello { 0% { transform: scale(.92); opacity: .85; } 100% { transform: scale(1.75); opacity: 0; } }
@keyframes latido { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes destello { 0% { opacity: 0; } 38% { opacity: 1; } 100% { opacity: 0; } }
@keyframes aparecer { from { opacity: 0; } to { opacity: 1; } }

/* el sobre flota apenas, como sostenido en el aire, y la luz resbala sobre el cuero */
@keyframes sobre-flota {
  0%, 100% { transform: translateY(0) rotateX(7deg) rotateY(-5deg); }
  50% { transform: translateY(-7px) rotateX(2deg) rotateY(4deg); }
}
@keyframes brillo-cuero { 0%, 55% { left: -60%; } 85%, 100% { left: 130%; } }
.sobre__escena { animation: sobre-flota 7s ease-in-out infinite; }
.sobre__sombra { animation: sombra-flotar 7s ease-in-out infinite; }
.sobre__brillo::before { animation: brillo-cuero 6.5s ease-in-out 1s infinite; }
.sello__mitad--izq, .sello__mitad--der { transform-origin: 50% 50%; }
@keyframes latido-sello {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.06); }
}
.sello { animation: latido-sello 2.4s ease-in-out infinite; }
.boton-abrir { animation: latido 2.4s ease-in-out infinite; }
.sonando .ecualizador i { animation: eq .8s ease-in-out infinite alternate; }
.sonando .ecualizador i:nth-child(2) { animation-delay: -.35s; animation-duration: .6s; }
.sonando .ecualizador i:nth-child(3) { animation-delay: -.6s; animation-duration: .95s; }
.tarjeta-lugar__pin { animation: rebote 2.4s ease-in-out infinite; }
.pista-deslizar svg { animation: mano 1.6s ease-in-out infinite; }
.rayos { animation: girar 120s linear infinite; }
.retrato__estrellas svg:nth-child(2n) { animation-delay: -.8s; }
.retrato__estrellas svg:nth-child(3n) { animation-delay: -1.6s; }

/* ---------- Entrada de los elementos al mostrar una página ---------- */
@keyframes entrada-subir { from { opacity: 0; transform: translateY(28px); } to { opacity: 1; transform: none; } }
@keyframes entrada-zoom { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: none; } }
@keyframes entrada-brillo { from { opacity: 0; letter-spacing: .45em; } to { opacity: 1; } }
@keyframes entrada-izquierda { from { opacity: 0; transform: translateX(-34px); } to { opacity: 1; transform: none; } }
@keyframes entrada-derecha { from { opacity: 0; transform: translateX(34px); } to { opacity: 1; transform: none; } }
@keyframes entrada-caer {
  0% { opacity: 0; transform: translateY(-46px) scale(1.12); }
  60% { opacity: 1; transform: translateY(5px) scale(.99); }
  100% { opacity: 1; transform: none; }
}
@keyframes entrada-girar { from { opacity: 0; transform: rotate(-150deg) scale(.3); } to { opacity: 1; transform: none; } }
@keyframes palabra { from { opacity: 0; text-shadow: 0 0 14px rgba(215,160,60,.95); } to { opacity: 1; } }

[data-anim] { opacity: 0; }
.activa [data-anim] {
  animation-duration: .95s;
  animation-timing-function: cubic-bezier(.2,.75,.25,1);
  animation-fill-mode: both;
  animation-delay: var(--d, 0s);
}
.activa [data-anim="subir"] { animation-name: entrada-subir; }
.activa [data-anim="zoom"] { animation-name: entrada-zoom; }
.activa [data-anim="brillo"] { animation-name: entrada-brillo; animation-duration: 1.3s; }
.activa [data-anim="izquierda"] { animation-name: entrada-izquierda; }
.activa [data-anim="derecha"] { animation-name: entrada-derecha; }
.activa [data-anim="caer"] { animation-name: entrada-caer; animation-duration: 1.1s; }
.activa [data-anim="girar"] { animation-name: entrada-girar; animation-duration: 1.2s; }

/* reflejo que recorre los títulos dorados */
.titulo-oro { transition: none; }
.activa .titulo-oro { background-position: -70% 0, 0 0; transition: background-position 2s ease .8s; }

/* manecillas del reloj: llegan a las 9:00 */
.activa .reloj__hora { transform: rotate(270deg); }
.activa .reloj__minuto { transform: rotate(360deg); }

/* palabras que aparecen una a una */
.palabra { opacity: 0; }
.activa .palabra { animation: palabra .7s ease both; animation-delay: calc(var(--i) * 42ms + .7s); }

/* ---------- Transiciones entre páginas ---------- */
/* Pasar página como en un álbum: la hoja gira desde el lomo (borde izquierdo), se oscurece al
   ponerse de canto y la de abajo aparece saliendo de su sombra */
@keyframes pag-pasa { from { transform: perspective(1700px) rotateY(0deg); } to { transform: perspective(1700px) rotateY(-100deg); } }
@keyframes pag-vuelve { from { transform: perspective(1700px) rotateY(-100deg); } to { transform: perspective(1700px) rotateY(0deg); } }
@keyframes sombra-oscurece { from { opacity: 0; } to { opacity: .85; } }
@keyframes sombra-aclara { from { opacity: .85; } to { opacity: 0; } }
@keyframes debajo-aparece { from { opacity: .7; } to { opacity: 0; } }
@keyframes debajo-se-cubre { from { opacity: 0; } to { opacity: .7; } }
@keyframes pag-entra-remolino {
  from { opacity: 0; transform: rotate(-190deg) scale(.25); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: blur(0); }
}
@keyframes pag-sale-remolino {
  from { opacity: 1; transform: none; filter: blur(0); }
  to { opacity: 0; transform: rotate(170deg) scale(1.7); filter: blur(6px); }
}
@keyframes pag-entra-luz {
  0% { opacity: 0; transform: scale(1.06); filter: brightness(2.4); }
  45% { opacity: 1; }
  100% { opacity: 1; transform: none; filter: brightness(1); }
}
@keyframes pag-sale-desvanece { from { opacity: 1; } to { opacity: 0; transform: scale(.96); } }

.pagina.entra-remolino { animation: pag-entra-remolino 1.05s cubic-bezier(.2,.7,.2,1) both; z-index: 2; }
.pagina.sale-remolino { animation: pag-sale-remolino .8s cubic-bezier(.55,0,.8,.45) both; z-index: 1; }
.pagina.entra-luz { animation: pag-entra-luz 1.1s ease both; z-index: 2; }
.pagina.sale-desvanece { animation: pag-sale-desvanece .7s ease both; z-index: 1; }
.pagina { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.pagina::after {
  content: ''; position: absolute; inset: 0; z-index: 40; pointer-events: none; opacity: 0;
  background: linear-gradient(90deg, rgba(0,0,0,.75) 0%, rgba(0,0,0,.45) 45%, rgba(0,0,0,.25) 100%);
}
.pagina.sale-sig { transform-origin: 0 50%; animation: pag-pasa .95s cubic-bezier(.42,.05,.3,1) both; z-index: 3; }
.pagina.sale-sig::after { animation: sombra-oscurece .95s ease-in both; }
.pagina.entra-sig { z-index: 1; }
.pagina.entra-sig::after { animation: debajo-aparece .95s ease-out both; }
.pagina.entra-ant { transform-origin: 0 50%; animation: pag-vuelve .95s cubic-bezier(.42,.05,.3,1) both; z-index: 3; }
.pagina.entra-ant::after { animation: sombra-aclara .95s ease-out both; }
.pagina.sale-ant { z-index: 1; }
.pagina.sale-ant::after { animation: debajo-se-cubre .95s ease-in both; }

/* ---------- Apertura de la invitación ---------- */
.intro .intro__aviso, .intro .intro__encabezado, .intro .boton-abrir, .intro .intro__pista { transition: opacity .5s ease, transform .5s ease; }
.intro.abriendo .intro__aviso, .intro.abriendo .intro__encabezado, .intro.abriendo .boton-abrir, .intro.abriendo .intro__pista { opacity: 0; transform: translateY(12px); }
.intro.abriendo .boton-abrir { animation: none; pointer-events: none; }
.intro.abriendo .sobre { cursor: default; }
.intro.abriendo .sobre__escena, .intro.abriendo .sobre__sombra, .intro.abriendo .sobre__brillo::before { animation-play-state: paused; }
.intro.abriendo .sello { animation: none; }
.intro.abriendo .sello::after { display: none; }

/* 1 · el sello se quiebra y las mitades caen (con gravedad: empiezan lento y aceleran) */
@keyframes sello-cae-izq {
  0% { transform: none; opacity: 1; }
  14% { transform: translate(-9%, -7%) rotate(-10deg); opacity: 1; }
  100% { transform: translate(-70%, 330%) rotate(-95deg); opacity: 0; }
}
@keyframes sello-cae-der {
  0% { transform: none; opacity: 1; }
  14% { transform: translate(9%, -5%) rotate(9deg); opacity: 1; }
  100% { transform: translate(80%, 300%) rotate(110deg); opacity: 0; }
}
.sello-roto .sello__mitad--izq { animation: sello-cae-izq 1s cubic-bezier(.45,0,.85,.55) both; }
.sello-roto .sello__mitad--der { animation: sello-cae-der 1.05s cubic-bezier(.45,0,.85,.55) .03s both; }
/* 2 · la cinta, ya sin sello, se suelta y cae */
@keyframes cinta-cae-izq { to { transform: translate(-4%, 26%) rotate(-7deg); opacity: 0; } }
@keyframes cinta-cae-der { to { transform: translate(5%, 30%) rotate(9deg); opacity: 0; } }
.sello-roto .sobre__cinta--izq { animation: cinta-cae-izq .85s cubic-bezier(.5,0,.9,.5) .08s both; }
.sello-roto .sobre__cinta--der { animation: cinta-cae-der .85s cubic-bezier(.5,0,.9,.5) .12s both; }
/* 3 · la solapa se despega y gira hacia atrás (la luz del frente se apaga al ponerse de canto) */
@keyframes solapa-abre {
  0% { transform: perspective(1100px) rotateX(0deg); animation-timing-function: cubic-bezier(.3,0,.6,1); }
  12% { transform: perspective(1100px) rotateX(9deg); animation-timing-function: cubic-bezier(.45,0,.25,1); }
  100% { transform: perspective(1100px) rotateX(196deg); }
}
@keyframes sombra-frente { 0% { opacity: 0; } 50% { opacity: .7; } 100% { opacity: .7; } }
@keyframes sombra-dorso { 0%, 50% { opacity: .7; } 100% { opacity: .22; } }
.solapa-abierta .sobre__solapa { animation: solapa-abre 1.3s both; }
.solapa-abierta .solapa__cara--frente .solapa__sombra { animation: sombra-frente 1.3s ease-in both; }
.solapa-abierta .solapa__cara--dorso .solapa__sombra { animation: sombra-dorso 1.3s ease-out both; }
.solapa-atras .sobre__solapa { z-index: 1; }
.solapa-abierta .sombra-solapa { opacity: 0; transition: opacity .5s ease; }
.solapa-abierta .sobre__brillo { opacity: 0; transition: opacity .4s ease; }
/* 4 · sale una luz dorada desde adentro */
@keyframes luz-abre { 0% { opacity: 0; transform: scale(.2); } 35% { opacity: 1; } 100% { opacity: .85; transform: scale(1); } }
@keyframes luz-gira { from { transform: scale(1) rotate(0deg); } to { transform: scale(1) rotate(360deg); } }
.luz-abre .sobre__luz { animation: luz-abre 1.6s cubic-bezier(.2,.7,.3,1) both, luz-gira 40s linear 1.6s infinite; }
/* 5 · la tarjeta sube despacio (con peso) */
.sobre__tarjeta { transition: transform 1.5s cubic-bezier(.25,.75,.2,1), box-shadow 1.5s ease; }
.tarjeta-sale .sobre__tarjeta {
  transform: translateY(calc(var(--sw) * -.47));
  box-shadow: inset 0 0 0 2px #c9a24f, inset 0 0 0 6px #fffaf0, inset 0 0 0 7px #b48d42, inset 0 0 26px rgba(150,110,40,.25), 0 10px 30px rgba(0,0,0,.45), 0 0 60px rgba(255,214,140,.45);
}
/* 6 · la cámara se acerca hasta que la tarjeta llena la pantalla */
.tarjeta-cubre .sobre__ranura { overflow: visible; z-index: 20; }
.tarjeta-cubre .sobre__tarjeta {
  transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(var(--escala, 3));
  transition: transform 1.05s cubic-bezier(.65,0,.3,1);
}
.tarjeta-cubre .sobre__bolsillo, .tarjeta-cubre .sobre__solapa, .tarjeta-cubre .sobre__borde, .tarjeta-cubre .sobre__laurel,
.tarjeta-cubre .sobre__nombre, .tarjeta-cubre .sobre__estrellas, .tarjeta-cubre .sobre__interior, .tarjeta-cubre .sobre__sombra,
.tarjeta-cubre .sobre__laurel-ext, .tarjeta-cubre .sobre__luz { opacity: 0; transition: opacity .6s ease; }
.tarjeta-cubre .sobre__luz, .tarjeta-cubre .sobre__sombra { animation: none; }
.intro.desvanece { opacity: 0; transition: opacity .8s ease; pointer-events: none; }
.destello-pantalla.activo { animation: destello 1.5s ease both; }
body.abierta .barra-sup, body.abierta .barra-inf { animation: aparecer .8s ease .4s both; }

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: .001ms !important;
    transition-delay: 0s !important;
  }
  [data-anim], .palabra, .foto-tarjeta { opacity: 1 !important; transform: none !important; }
  .rayos, .retrato__orbita { animation: none !important; }
}
.movimiento-reducido [data-anim], .movimiento-reducido .palabra { opacity: 1 !important; animation: none !important; }

/* ---------- Ventana de foto ampliada ---------- */
@keyframes foto-entra { from { opacity: 0; transform: translateX(calc(var(--dir, 0) * 36px)) scale(.97); } to { opacity: 1; transform: none; } }
.lightbox { opacity: 0; transition: opacity .25s ease; }
.lightbox.abierto { opacity: 1; }
.lightbox__marco { transform: scale(.9); transition: transform .4s cubic-bezier(.2,.8,.2,1); }
.lightbox.abierto .lightbox__marco { transform: none; }
#lightbox-img.entra { animation: foto-entra .45s ease both; }

/* ---------- Portada: el afiche cobra vida ---------- */
@property --vaiven-x { syntax: '<angle>'; inherits: true; initial-value: 0deg; }
@property --vaiven-y { syntax: '<angle>'; inherits: true; initial-value: 0deg; }
@property --vaiven-t { syntax: '<length>'; inherits: true; initial-value: 0px; }
@property --vaiven-g { syntax: '<percentage>'; inherits: true; initial-value: 0%; }
@keyframes afiche-entra {
  0%   { opacity: 0; transform: translateY(46px) scale(.84) rotateX(26deg); filter: blur(12px) brightness(.25); }
  45%  { opacity: 1; filter: blur(0) brightness(1.15); }
  72%  { transform: translateY(-5px) scale(1.012) rotateX(-3deg); filter: brightness(1.04); }
  100% { opacity: 1; transform: none; filter: none; }
}
@keyframes afiche-vaiven {
  0%, 100% { --vaiven-x: 2.2deg; --vaiven-y: -3deg; --vaiven-t: 0px; --vaiven-g: -14%; }
  50%      { --vaiven-x: -1.6deg; --vaiven-y: 3deg; --vaiven-t: -7px; --vaiven-g: 14%; }
}
@keyframes afiche-sombra { 0%, 100% { transform: scaleX(1); opacity: .95; } 50% { transform: scaleX(.88); opacity: .7; } }
@keyframes afiche-barrido { 0%, 62% { left: -70%; } 92%, 100% { left: 125%; } }
@keyframes afiche-chispa {
  0%, 64%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0) rotate(0deg); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(45deg); }
}
@keyframes ambiente {
  from { transform: scale(1.08) translate(0, 0); }
  to   { transform: scale(1.2) translate(-2%, 1.5%); }
}
.activa [data-anim="afiche"] { animation-name: afiche-entra; animation-duration: 2.3s; animation-timing-function: cubic-bezier(.2,.7,.2,1); }
.afiche__tarjeta { animation: afiche-vaiven 9s ease-in-out infinite; }
.afiche__sombra { animation: afiche-sombra 9s ease-in-out infinite; }
.afiche__barrido::before { animation: afiche-barrido 7.5s ease-in-out 2.2s infinite; }
.afiche__destellos svg { animation: afiche-chispa var(--t, 3s) ease-in-out var(--r, 0s) infinite; }
.afiche-ambiente { animation: ambiente 26s ease-in-out infinite alternate; }

@media (prefers-reduced-motion: reduce) {
  .afiche__tarjeta, .afiche__sombra, .afiche-ambiente, .afiche__barrido::before, .afiche__destellos svg { animation: none !important; }
}
.movimiento-reducido .afiche__tarjeta, .movimiento-reducido .afiche__sombra, .movimiento-reducido .afiche-ambiente,
.movimiento-reducido .afiche__barrido::before, .movimiento-reducido .afiche__destellos svg { animation: none !important; }
