/* =========================================================================
   motion.css — Secuencia de entrada de la portada y revelados al desplazar.

   - Sin pantalla de carga: la entrada comienza en el primer fotograma.
   - El contenido solo se oculta cuando hay JavaScript; si los scripts no
     llegan a ejecutarse, una animación de respaldo lo muestra a los 3 s.
   - prefers-reduced-motion desactiva todo el movimiento.
   ========================================================================= */

@keyframes failsafe { to { opacity: 1; transform: none; clip-path: none; } }

@keyframes char-in {
    from { transform: translateY(110%) rotate(6deg) scale(0.96); opacity: 0; }
    40% { opacity: 1; }
    to { transform: none; opacity: 1; }
}

@keyframes rise-in {
    from { opacity: 0; transform: translateY(24px); filter: blur(6px); }
    to { opacity: 1; transform: none; filter: none; }
}

@keyframes mask-in {
    from { transform: translateY(105%); }
    to { transform: none; }
}

@keyframes cue {
    0% { transform: translateY(0); opacity: 0; }
    20% { opacity: 1; }
    70% { transform: translateY(11px); opacity: 0; }
    100% { transform: translateY(11px); opacity: 0; }
}

@keyframes photo-in {
    from { opacity: 0; transform: scale(0.94); filter: brightness(1.6) saturate(0.6); }
    to { opacity: 1; transform: none; filter: none; }
}

@keyframes scan {
    0% { top: 0; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { top: 100%; opacity: 0; }
}

@media (prefers-reduced-motion: no-preference) {

    /* ------------------------- Entrada de la portada ------------------------- */
    .js .hero [data-intro] {
        opacity: 0;
        animation: failsafe 1ms linear 3s forwards;
    }

    .js .hero .char {
        transform: translateY(108%);
        animation: failsafe 1ms linear 3s forwards;
    }

    .js .hero.is-ready .char {
        animation: char-in 1100ms var(--ease) both;
        animation-delay: calc(120ms + var(--i) * 45ms);
    }

    .js .hero.is-ready [data-intro] {
        animation: rise-in 1000ms var(--ease) both;
    }

    .js .hero.is-ready [data-intro="1"] { animation-delay: 80ms; }
    .js .hero.is-ready [data-intro="2"] { animation-delay: 720ms; }
    .js .hero.is-ready [data-intro="3"] { animation-delay: 860ms; }
    .js .hero.is-ready [data-intro="4"] { animation-delay: 1000ms; }
    .js .hero.is-ready [data-intro="5"] { animation-delay: 1400ms; }

    .js .hero.is-ready .hero-role .mask > span {
        animation: mask-in 1000ms var(--ease) 760ms both;
    }

    .scroll-cue-mouse span {
        animation: cue 2.2s var(--ease-in-out) 2s infinite;
    }

    .hero.is-scrolled-out .scroll-cue-mouse span {
        animation-play-state: paused;
    }

    /* ------------------------- Revelados al desplazar ------------------------- */
    .js [data-reveal] {
        opacity: 0;
        transform: translateY(32px);
        transition: opacity 900ms var(--ease) var(--d, 0ms), transform 1000ms var(--ease) var(--d, 0ms);
        animation: failsafe 1ms linear 3s forwards;
    }

    .js.motion-ready [data-reveal] {
        animation: none;
    }

    .js [data-reveal].is-visible {
        opacity: 1;
        transform: none;
    }

    /* Revelado por líneas con máscara */
    .js [data-reveal="lines"] {
        opacity: 1;
        transform: none;
    }

    .js.motion-ready [data-reveal="lines"] .mask > span {
        transform: translateY(105%);
        transition: transform 1100ms var(--ease);
    }

    .js.motion-ready [data-reveal="lines"] .mask:nth-child(2) > span {
        transition-delay: 120ms;
    }

    .js.motion-ready [data-reveal="lines"].is-visible .mask > span {
        transform: none;
    }

    /* Fotografía: se descubre de arriba abajo con una línea de escaneo */
    .js [data-reveal="photo"] {
        opacity: 1;
        transform: none;
    }

    .js.motion-ready [data-reveal="photo"] .portrait-frame {
        opacity: 0;
        transform: scale(0.94);
    }

    .js.motion-ready [data-reveal="photo"].is-visible .portrait-frame {
        animation: photo-in 1400ms var(--ease) both;
    }

    .js.motion-ready [data-reveal="photo"].is-visible .scan-line {
        animation: scan 1400ms var(--ease) both;
    }

    .js.motion-ready [data-reveal="photo"] .portrait-tag {
        opacity: 0;
        transform: translate(-50%, 12px);
        transition: opacity 600ms ease 1100ms, transform 900ms var(--ease) 1100ms;
    }

    .js.motion-ready [data-reveal="photo"].is-visible .portrait-tag { opacity: 1; transform: translate(-50%, 0); }

    /* Puntos de cada capítulo de la trayectoria */
    .js.motion-ready .chapter-body .chapter-points li {
        opacity: 0;
        transform: translateY(8px);
        transition: opacity 500ms ease, transform 600ms var(--ease);
    }

    .js.motion-ready .chapter.is-reached .chapter-body .chapter-points li { opacity: 1; transform: none; }
    .js.motion-ready .chapter.is-reached .chapter-body .chapter-points li:nth-child(2) { transition-delay: 50ms; }
    .js.motion-ready .chapter.is-reached .chapter-body .chapter-points li:nth-child(3) { transition-delay: 100ms; }
    .js.motion-ready .chapter.is-reached .chapter-body .chapter-points li:nth-child(4) { transition-delay: 150ms; }
    .js.motion-ready .chapter.is-reached .chapter-body .chapter-points li:nth-child(5) { transition-delay: 200ms; }
    .js.motion-ready .chapter.is-reached .chapter-body .chapter-points li:nth-child(6) { transition-delay: 250ms; }
    .js.motion-ready .chapter.is-reached .chapter-body .chapter-points li:nth-child(7) { transition-delay: 300ms; }
    .js.motion-ready .chapter.is-reached .chapter-body .chapter-points li:nth-child(8) { transition-delay: 350ms; }

    /* Animaciones continuas pausadas fuera de pantalla */
    .is-paused .preview-float { animation-play-state: paused; }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
        transition-delay: 0ms !important;
        scroll-behavior: auto !important;
    }
}
