/* ═══════════════════════════════════════════════════════
   ANIMATIONS & KEYFRAMES
   ═══════════════════════════════════════════════════════ */

/* ─── Confetti Win Screen ─── */
.confetti {
    position: fixed;
    width: 8px;
    height: 8px;
    z-index: calc(var(--z-overlay) + 1);
    pointer-events: none;
    animation: confettiFall var(--fall-dur, 3s) ease-in forwards;
    animation-delay: var(--delay, 0s);
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translateY(-20px) rotate(0deg) scale(1);
    }

    80% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(var(--rot, 720deg)) scale(0.5);
    }
}

/* ─── Screen Shake ─── */
@keyframes screenShake {

    0%,
    100% {
        transform: translateX(0);
    }

    10% {
        transform: translateX(-3px) translateY(1px);
    }

    20% {
        transform: translateX(3px) translateY(-1px);
    }

    30% {
        transform: translateX(-2px);
    }

    40% {
        transform: translateX(2px) translateY(1px);
    }

    50% {
        transform: translateX(-1px);
    }
}

.shake {
    animation: screenShake 0.4s ease-out;
}

/* ─── Pop In ─── */
@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    60% {
        transform: scale(1.15);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.pop-in {
    animation: popIn 0.4s var(--ease-elastic) forwards;
}

/* ─── Pulse Scale ─── */
@keyframes pulseScale {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.pulse {
    animation: pulseScale 2s ease-in-out infinite;
}

/* ─── Fade In ─── */
@keyframes fadeIn {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

/* ─── Fade Out ─── */
@keyframes fadeOut {
    0% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

/* ─── Slide Up Fade ─── */
@keyframes slideUpFade {
    0% {
        opacity: 1;
        transform: translateY(0) translateX(-50%);
    }

    100% {
        opacity: 0;
        transform: translateY(-60px) translateX(-50%);
    }
}

/* ─── Slide In From Right ─── */
@keyframes slideInRight {
    0% {
        transform: translateX(100%);
    }

    100% {
        transform: translateX(0);
    }
}

/* ─── Slide In From Left ─── */
@keyframes slideInLeft {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(0);
    }
}

/* ─── Slide In From Bottom ─── */
@keyframes slideInBottom {
    0% {
        transform: translateY(100%);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ─── Slide In From Top ─── */
@keyframes slideInTop {
    0% {
        transform: translateY(-100%) translateX(-50%);
    }

    100% {
        transform: translateY(0) translateX(-50%);
    }
}

/* ─── Glow Pulse ─── */
@keyframes glowPulseGeneric {

    0%,
    100% {
        box-shadow: 0 0 10px var(--glow-color, rgba(255, 215, 0, 0.3));
    }

    50% {
        box-shadow: 0 0 25px var(--glow-color, rgba(255, 215, 0, 0.6));
    }
}

/* ─── Spin ─── */
@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* ─── Golden Shimmer Overlay ─── */
.golden-shimmer::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg,
            transparent 30%,
            rgba(255, 215, 0, 0.15) 45%,
            rgba(255, 215, 0, 0.25) 50%,
            rgba(255, 215, 0, 0.15) 55%,
            transparent 70%);
    background-size: 200% 200%;
    animation: shimmerSweep 2s linear infinite;
    pointer-events: none;
    border-radius: inherit;
    z-index: 10;
}

@keyframes shimmerSweep {
    0% {
        background-position: 200% 200%;
    }

    100% {
        background-position: -200% -200%;
    }
}

/* ─── Gold Aura (for Time Warp / Golden Age) ─── */
#grid-wrapper.gold-aura {
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3), 0 0 60px rgba(255, 215, 0, 0.15);
    animation: goldAuraPulse 2s ease-in-out infinite;
}

@keyframes goldAuraPulse {

    0%,
    100% {
        box-shadow: 0 0 30px rgba(255, 215, 0, 0.3), 0 0 60px rgba(255, 215, 0, 0.15);
    }

    50% {
        box-shadow: 0 0 50px rgba(255, 215, 0, 0.5), 0 0 100px rgba(255, 215, 0, 0.25);
    }
}

/* ─── Cell Spawn Highlight ─── */
@keyframes cellSpawnHighlight {
    0% {
        background: rgba(255, 215, 0, 0.2);
    }

    100% {
        background: var(--cell-bg);
    }
}

.spawn-highlight {
    animation: cellSpawnHighlight 0.5s ease-out;
}

/* ─── Button Press Ripple ─── */
.btn-ripple {
    position: relative;
    overflow: hidden;
}

.btn-ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    transform: translate(-50%, -50%);
    transition: width 0.3s, height 0.3s;
}

.btn-ripple:active::after {
    width: 200px;
    height: 200px;
}

/* ─── Transform-only tile upgrade flash ─── */
@keyframes upgradeFlash {
    0% {
        filter: brightness(1);
    }

    50% {
        filter: brightness(3);
    }

    100% {
        filter: brightness(1);
    }
}

.upgrade-flash {
    animation: upgradeFlash 0.6s ease-out;
}

/* ─── Tooltip fade ─── */
@keyframes tooltipFadeIn {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(4px);
    }

    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ─── Loading spinner ─── */
.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--surface);
    border-top-color: var(--gold-400);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}