/**
 * Animations - Authentic Retro Style
 * NES/SNES/PS1 - Step-based, no smooth transitions
 */

/* ============================================
   KEYFRAME ANIMATIONS
   ============================================ */

/* Floating animation - stepped for retro feel */
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* Classic blinking highlight */
@keyframes blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* Slow blink for selection */
@keyframes slow-blink {
    0%, 70% { opacity: 1; }
    71%, 100% { opacity: 0.5; }
}

/* Shake (for incorrect answers) - chunky 8-bit style */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    12.5% { transform: translateX(-8px); }
    25% { transform: translateX(8px); }
    37.5% { transform: translateX(-8px); }
    50% { transform: translateX(8px); }
    62.5% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
    87.5% { transform: translateX(-2px); }
}

/* Color flash for damage/heal */
@keyframes flash-white {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(2); }
}

@keyframes flash-red {
    0%, 100% { background-color: inherit; }
    50% { background-color: var(--accent-error); }
}

/* Bounce in - stepped retro pop */
@keyframes bounce-in {
    0% { 
        transform: scale(0);
        opacity: 0;
    }
    50% { 
        transform: scale(1.2);
        opacity: 1;
    }
    100% { 
        transform: scale(1);
        opacity: 1;
    }
}

/* Pop in - instant appearance */
@keyframes pop-in {
    0% { 
        transform: scale(0.5);
        opacity: 0;
    }
    100% { 
        transform: scale(1);
        opacity: 1;
    }
}

/* Slide up - stepped */
@keyframes slide-up {
    0% {
        transform: translateY(16px);
        opacity: 0;
    }
    50% {
        transform: translateY(8px);
        opacity: 0.5;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Slide in from right */
@keyframes slide-in-right {
    0% {
        transform: translateX(100%);
        opacity: 0;
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Text typing effect - classic RPG dialog */
@keyframes typewriter {
    from { width: 0; }
    to { width: 100%; }
}

/* XP gain pop */
@keyframes xp-pop {
    0% {
        transform: scale(0) translateY(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2) translateY(-20px);
        opacity: 1;
    }
    100% {
        transform: scale(1) translateY(-40px);
        opacity: 0;
    }
}

/* Level up burst */
@keyframes level-up {
    0% {
        transform: scale(1);
        filter: brightness(1);
    }
    25% {
        transform: scale(1.3);
        filter: brightness(1.5);
    }
    50% {
        transform: scale(1);
        filter: brightness(2);
    }
    75% {
        transform: scale(1.1);
        filter: brightness(1.2);
    }
    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

/* Coin spin */
@keyframes coin-spin {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(360deg); }
}

/* Typing cursor blink */
@keyframes cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Progress bar shimmer */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Sparkle */
@keyframes sparkle {
    0%, 100% {
        opacity: 0;
        transform: scale(0);
    }
    50% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Streak fire flicker */
@keyframes fire-flicker {
    0%, 100% { 
        transform: scaleY(1) scaleX(1);
        filter: brightness(1);
    }
    25% { 
        transform: scaleY(1.1) scaleX(0.9);
        filter: brightness(1.1);
    }
    50% { 
        transform: scaleY(0.9) scaleX(1.1);
        filter: brightness(1.2);
    }
    75% { 
        transform: scaleY(1.05) scaleX(0.95);
        filter: brightness(1.1);
    }
}

/* ============================================
   ANIMATION UTILITY CLASSES
   All use steps() for authentic retro feel
   ============================================ */

.animate-float {
    animation: float 1s steps(4) infinite;
}

.animate-blink {
    animation: blink 0.5s steps(1) infinite;
}

.animate-slow-blink {
    animation: slow-blink 1s steps(1) infinite;
}

.animate-shake {
    animation: shake 0.4s steps(8);
}

.animate-bounce-in {
    animation: bounce-in 0.3s steps(3);
}

.animate-pop-in {
    animation: pop-in 0.15s steps(2);
}

.animate-slide-up {
    animation: slide-up 0.2s steps(3);
}

.animate-slide-in-right {
    animation: slide-in-right 0.2s steps(4);
}

.animate-flash {
    animation: flash-white 0.2s steps(2) 2;
}

/* Delay utilities - shorter for snappy feel */
.animate-delay-1 { animation-delay: 50ms; }
.animate-delay-2 { animation-delay: 100ms; }
.animate-delay-3 { animation-delay: 150ms; }
.animate-delay-4 { animation-delay: 200ms; }
.animate-delay-5 { animation-delay: 250ms; }

/* ============================================
   COMPONENT-SPECIFIC ANIMATIONS
   Retro RPG style - damage numbers, level ups
   ============================================ */

/* XP/damage number pop-up - classic RPG */
@keyframes number-pop {
    0% { 
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    50% {
        transform: translateY(-24px) scale(1.2);
        opacity: 1;
    }
    100% { 
        transform: translateY(-48px) scale(1);
        opacity: 0;
    }
}

.xp-gain {
    position: absolute;
    font-family: var(--font-pixel);
    font-size: var(--font-size-lg);
    color: var(--accent-exp);
    text-shadow: 2px 2px 0 #000000;
    pointer-events: none;
    animation: number-pop 0.8s steps(8) forwards;
}

/* Coin gain indicator */
.coin-gain {
    position: absolute;
    font-family: var(--font-pixel);
    font-size: var(--font-size-md);
    color: var(--coin-color);
    text-shadow: 2px 2px 0 #000000;
    pointer-events: none;
    animation: number-pop 0.8s steps(8) forwards;
}

/* Level up effect - classic flash */
@keyframes level-up {
    0%, 100% { filter: brightness(1); }
    25%, 75% { filter: brightness(2); }
    50% { filter: brightness(3); }
}

.level-up-effect {
    animation: level-up 0.5s steps(4);
}

/* Typing cursor - classic blink */
.typing-cursor {
    display: inline-block;
    width: 8px;
    height: 16px;
    background: var(--text-primary);
    margin-left: 2px;
    animation: blink 0.5s steps(1) infinite;
}

/* Achievement unlock */
.achievement-unlock {
    animation: bounce-in 0.3s steps(3);
}

/* Correct answer - flash green */
.pixel-card.correct {
    animation: flash-white 0.3s steps(3) 2;
}

/* Incorrect shake */
.pixel-card.incorrect {
    animation: shake 0.4s steps(8);
}

/* Notification slide in */
.pixel-notification {
    animation: slide-in-right 0.2s steps(4);
}

/* ============================================
   STAGGER ANIMATIONS (for menu lists)
   Classic RPG menu population
   ============================================ */

.stagger-children > * {
    opacity: 0;
    animation: pop-in 0.1s steps(2) forwards;
}

.stagger-children > *:nth-child(1) { animation-delay: 0.02s; }
.stagger-children > *:nth-child(2) { animation-delay: 0.04s; }
.stagger-children > *:nth-child(3) { animation-delay: 0.06s; }
.stagger-children > *:nth-child(4) { animation-delay: 0.08s; }
.stagger-children > *:nth-child(5) { animation-delay: 0.10s; }
.stagger-children > *:nth-child(6) { animation-delay: 0.12s; }
.stagger-children > *:nth-child(7) { animation-delay: 0.14s; }
.stagger-children > *:nth-child(8) { animation-delay: 0.16s; }

/* ============================================
   SELECTION CURSOR - Classic RPG hand/arrow
   ============================================ */

.selection-cursor {
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 12px solid var(--text-highlight);
    animation: float 0.5s steps(2) infinite;
}

/* ============================================
   REDUCED MOTION - Comprehensive coverage
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    /* Disable all blinking/flashing animations */
    .animate-float,
    .animate-blink,
    .animate-slow-blink,
    .animate-flash,
    .selection-cursor,
    .typing-cursor,
    .mastery-dot.level-5,
    .audio-btn.playing {
        animation: none !important;
    }
    
    /* Keep cursors visible but static */
    .nav-link:hover::before,
    .nav-link:focus::before,
    .nav-link.active::before,
    .action-card:hover::before,
    .action-card:focus::before,
    .quiz-option:hover::before,
    .quiz-option:focus::before,
    .pixel-btn:hover::before,
    .pixel-btn:focus::before {
        animation: none !important;
        opacity: 1 !important;
    }
    
    /* Static states for interactive elements */
    .pixel-card.correct,
    .pixel-card.incorrect,
    .quiz-option.correct,
    .quiz-option.incorrect {
        animation: none !important;
    }
}
