/* ==========================================================================
   PROJECT 13: CINEMATIC RITUAL ANIMATIONS
   Purposeful, candlelit, and respectful of prefers-reduced-motion.
   ========================================================================== */

@keyframes flameFlicker {
    0%, 100% {
        transform: scale(1) rotate(-1deg);
        opacity: 0.96;
    }
    25% {
        transform: scale(1.05, 0.97) rotate(1.5deg);
        opacity: 1;
    }
    50% {
        transform: scale(0.97, 1.04) rotate(-1.5deg);
        opacity: 0.92;
    }
    75% {
        transform: scale(1.03, 0.99) rotate(1deg);
        opacity: 0.98;
    }
}

@keyframes haloPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.75;
    }
    50% {
        transform: scale(1.12);
        opacity: 1;
    }
}

@keyframes starTwinkle {
    0%, 100% { opacity: 0.35; transform: scale(0.95); }
    50% { opacity: 0.95; transform: scale(1.1); }
}

@keyframes emberRise {
    0% {
        transform: translateY(0) translateX(0) scale(1);
        opacity: 0.95;
    }
    50% {
        opacity: 0.85;
    }
    100% {
        transform: translateY(-290px) translateX(var(--drift-x, 22px)) scale(0.2);
        opacity: 0;
    }
}

@keyframes paperFoldTransition {
    0% {
        opacity: 1;
        transform: perspective(900px) rotateY(0deg);
    }
    45% {
        opacity: 0.35;
        transform: perspective(900px) rotateY(-14deg) scale(0.98);
    }
    100% {
        opacity: 1;
        transform: perspective(900px) rotateY(0deg) scale(1);
    }
}

@keyframes letterUnfoldReveal {
    0% {
        opacity: 0;
        transform: perspective(1000px) rotateX(-25deg) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: perspective(1000px) rotateX(0deg) scale(1);
    }
}

.candle-flame,
.flame-tongue {
    animation: flameFlicker 3.2s infinite ease-in-out;
    transform-origin: bottom center;
}

.candle-halo,
.flame-halo {
    animation: haloPulse 4s infinite ease-in-out;
}

.star-dot {
    animation: starTwinkle 4.5s infinite ease-in-out;
}
.star-dot.s2 { animation-delay: 1.1s; }
.star-dot.s3 { animation-delay: 2.2s; }
.star-dot.s4 { animation-delay: 0.6s; }
.star-dot.s5 { animation-delay: 1.8s; }

/* Fade-in reveal on scroll */
.fade-in-up {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity 0.8s cubic-bezier(0.22, 1, 0.36, 1), transform 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.fade-in-up.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.delay-1 { transition-delay: 0.12s; }
.delay-2 { transition-delay: 0.24s; }

/* Sheet flip animation */
.sheet-turning {
    animation: paperFoldTransition 0.42s ease;
}

/* Digital Burning Sequence States */
.folded-wish-artifact.is-igniting .burn-glow-edge {
    opacity: 1;
    box-shadow: inset 0 0 28px rgba(255, 115, 29, 0.95), 0 0 26px rgba(255, 140, 40, 0.7);
    transition: opacity 1s ease, box-shadow 1.2s ease;
}

.folded-wish-artifact.is-burning .burn-char-overlay {
    opacity: 1;
    transform: scale(1.25);
    transition: opacity 2.2s ease-in, transform 2.4s ease-in;
}

.folded-wish-artifact.is-burning .artifact-paper {
    background: linear-gradient(145deg, #593524, #241310);
    border-color: #d96b27;
    transform: translateY(-18px) scale(0.92);
    opacity: 0.18;
    transition: all 2.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.folded-wish-artifact.is-embers .artifact-paper {
    opacity: 0;
    transform: translateY(-48px) scale(0.75);
    transition: all 1.1s ease-out;
}

/* Floating Golden Ember Particles */
.golden-ember {
    position: absolute;
    bottom: 34%;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: radial-gradient(circle, #fff3c4 0%, #f5b041 60%, #d35400 100%);
    box-shadow: 0 0 10px rgba(245, 176, 65, 0.9);
    animation: emberRise var(--duration, 3.2s) ease-out forwards;
    pointer-events: none;
}

/* Final Wish Unfolding Animation */
.envelope-wrapper.opened .unfolded-letter {
    animation: letterUnfoldReveal 1.1s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* Respect Reduced Motion Accessibility Preferences */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    .candle-flame,
    .flame-tongue,
    .candle-halo,
    .flame-halo,
    .star-dot,
    .sheet-turning,
    .envelope-wrapper.opened .unfolded-letter {
        animation: none !important;
    }
    .fade-in-up {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
    .golden-ember {
        display: none !important;
    }
}
