/* LEGENDARY ANIMATIONS & TRANSITIONS */

@keyframes pageEnter {
    0% {
        opacity: 0;
        transform: perspective(1000px) translateZ(0px) scale(1);
        filter: blur(0);
    }
    100% {
        opacity: 1;
        transform: perspective(1000px) translateZ(0px) scale(1);
        filter: blur(0);
    }
}

@keyframes pageExit {
    0% {
        opacity: 1;
        transform: perspective(1000px) translateZ(0px) scale(1);
    }
    100% {
        opacity: 0;
        transform: perspective(1000px) translateZ(0px) scale(1);
        filter: blur(0);
    }
}

@keyframes burnInEffect {
    0% {
        opacity: 0;
        transform: perspective(800px) translateZ(0px);
        text-shadow: 0 0 0 rgba(212, 175, 55, 0);
    }
    50% {
        transform: perspective(800px) translateZ(0px);
        text-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
    }
    100% {
        opacity: 1;
        transform: perspective(800px) translateZ(0px);
        text-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
    }
}

@keyframes glowPulse {
    0%, 100% {
        box-shadow: 0 0 10px rgba(212, 175, 55, 0.2);
        transform: perspective(1000px) translateZ(0px);
    }
    50% {
        box-shadow: 0 0 30px rgba(212, 175, 55, 0.5);
        transform: perspective(1000px) translateZ(0px);
    }
}

@keyframes shimmer {
    0% { transform: translateX(0); }
    100% { transform: translateX(0); }
}

@keyframes fadeInScale {
    0% {
        opacity: 0;
        transform: perspective(1200px) translateZ(0px) scale(1);
    }
    100% {
        opacity: 1;
        transform: perspective(1200px) translateZ(0px) scale(1);
    }
}

@keyframes slideFromRight {
    0% {
        opacity: 0;
        transform: perspective(1000px) translateZ(0px);
    }
    100% {
        opacity: 1;
        transform: perspective(1000px) translateZ(0px);
    }
}

@keyframes slideFromLeft {
    0% {
        opacity: 0;
        transform: perspective(1000px) translateZ(0px) scale(1);
    }
    100% {
        opacity: 1;
        transform: perspective(1000px) translateZ(0px) scale(1);
    }
}

@keyframes rotateIn {
    0% {
        opacity: 0;
        transform: perspective(800px) translateZ(0px);
    }
    100% {
        opacity: 1;
        transform: perspective(800px) translateZ(0px);
    }
}

/* PAGE TRANSITION WRAPPER */
html.page-transitioning body {
    animation: pageExit 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

html:not(.page-transitioning) body {
    animation: pageEnter 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    perspective: 1200px;
    transform-style: preserve-3d;
}

/* LEGENDARY STYLING */
.legendary-hero {
    animation: burnInEffect 1.2s ease-out;
    transform-style: preserve-3d;
}

.legendary-card {
    animation: fadeInScale 0.7s ease-out;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-style: preserve-3d;
}

.legendary-card:hover {
    animation: glowPulse 2s infinite;
    transform: perspective(1000px) translateY(-15px) translateZ(30px) rotateX(-5deg) scale(1.05);
}

.legendary-button {
    position: relative;
    overflow: hidden;
}

.legendary-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.2);
    animation: shimmer 2s infinite;
}

/* SECTION ANIMATIONS */
.menu-section {
    animation: slideFromLeft 0.8s ease-out;
}

.content-section {
    animation: slideFromRight 0.8s ease-out;
}

.gallery-item {
    animation: rotateIn 0.6s ease-out;
    animation-fill-mode: both;
    transform-style: preserve-3d;
}

.gallery-item:nth-child(1) { animation-delay: 0.1s; }
.gallery-item:nth-child(2) { animation-delay: 0.2s; }
.gallery-item:nth-child(3) { animation-delay: 0.3s; }
.gallery-item:nth-child(4) { animation-delay: 0.4s; }
.gallery-item:nth-child(5) { animation-delay: 0.5s; }
.gallery-item:nth-child(6) { animation-delay: 0.6s; }

/* THEME-SPECIFIC ANIMATIONS */
.horror-pulse {
    animation: glowPulse 2s infinite;
    filter: drop-shadow(0 0 10px rgba(255, 0, 0, 0.3));
}

.fantasy-shimmer::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent 30%, rgba(212, 175, 55, 0.1) 50%, transparent 70%);
    animation: shimmer 3s infinite;
    pointer-events: none;
}

.romance-fade {
    animation: fadeInScale 1s ease-out;
}

.poetry-bloom {
    animation: burnInEffect 1.5s ease-out;
}

/* TRANSITION OVERLAY */
.page-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(212, 175, 55, 0.1) 0%, rgba(2, 4, 10, 0.8) 100%);
    opacity: 0;
    pointer-events: none;
    z-index: 999;
    animation: fadeInScale 0.3s ease-out forwards;
}

/* STAGGERED CHILDREN */
.staggered-children > * {
    animation: slideFromLeft 0.6s ease-out forwards;
    opacity: 0;
}

.staggered-children > *:nth-child(1) { animation-delay: 0.1s; }
.staggered-children > *:nth-child(2) { animation-delay: 0.2s; }
.staggered-children > *:nth-child(3) { animation-delay: 0.3s; }
.staggered-children > *:nth-child(4) { animation-delay: 0.4s; }
.staggered-children > *:nth-child(5) { animation-delay: 0.5s; }

/* SMOOTH SCROLLING ENHANCED */
@supports (scroll-behavior: smooth) {
    html {
        scroll-behavior: smooth;
    }
}

/* Loading States */
.legendary-loading {
    background: linear-gradient(90deg, rgba(212, 175, 55, 0.1) 25%, rgba(212, 175, 55, 0.2) 50%, rgba(212, 175, 55, 0.1) 75%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite;
}

/* MODAL/POPUP ANIMATIONS */
.modal-enter {
    animation: rotateIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-exit {
    animation: pageExit 0.4s ease-in;
}

/* HOVER EFFECTS */
.hover-lift:hover {
    transform: translateY(-15px);
    box-shadow: 0 20px 40px rgba(212, 175, 55, 0.2);
}

.hover-glow:hover {
    box-shadow: 0 0 30px rgba(212, 175, 55, 0.6);
    border-color: rgba(212, 175, 55, 0.8);
}

.hover-scale:hover {
    transform: scale(1.05);
}

/* TEXT EFFECTS */
.text-shimmer {
    background: linear-gradient(90deg, white, rgba(212, 175, 55, 0.8), white);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 3s linear infinite;
}

.text-glow {
    color: rgba(212, 175, 55, 0.9);
    text-shadow: 0 0 10px rgba(212, 175, 55, 0.8), 0 0 20px rgba(212, 175, 55, 0.4);
    animation: glowPulse 3s ease-in-out infinite;
}

/* THEME COLORS */
.theme-horror {
    --theme-color: #ff4444;
    --theme-glow: rgba(255, 68, 68, 0.3);
}

.theme-fantasy {
    --theme-color: #a78bfa;
    --theme-glow: rgba(167, 139, 250, 0.3);
}

.theme-romance {
    --theme-color: #ec4899;
    --theme-glow: rgba(236, 72, 153, 0.3);
}

.theme-poetry {
    --theme-color: #d4af37;
    --theme-glow: rgba(212, 175, 55, 0.3);
}

.theme-junior {
    --theme-color: #38bdf8;
    --theme-glow: rgba(56, 189, 248, 0.3);
}

/* RESPONSIVE */
@media (max-width: 768px) {
    @keyframes pageEnter {
        0% {
            opacity: 0;
            transform: translateY(20px);
        }
        100% {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .gallery-item:nth-child(n) { animation-delay: 0s !important; }
    .staggered-children > * { animation-delay: 0s !important; }
}
