/* ===== ANIMATION KEYFRAMES ===== */

/* Loading animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes bounce {
    0%, 20%, 53%, 80%, 100% { transform: translateY(0); }
    40%, 43% { transform: translateY(-10px); }
    70% { transform: translateY(-5px); }
    90% { transform: translateY(-2px); }
}

/* Slide animations */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutUp {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-30px);
    }
}

@keyframes slideOutDown {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(30px);
    }
}

/* Scale animations */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes scaleOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

/* Fade animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Shake animation for errors */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Progress bar fill animation */
@keyframes fillProgress {
    from { width: 0%; }
    to { width: var(--target-width); }
}

/* Confetti animation */
@keyframes confetti {
    0% {
        transform: translateY(-100vh) rotateZ(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotateZ(360deg);
        opacity: 0;
    }
}

/* Typing animation */
@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes blinkCaret {
    from, to { border-color: transparent; }
    50% { border-color: currentColor; }
}

/* Glow animation */
@keyframes glow {
    0%, 100% { box-shadow: 0 0 5px var(--primary-color); }
    50% { box-shadow: 0 0 20px var(--primary-color), 0 0 30px var(--primary-color); }
}

/* Wave animation */
@keyframes wave {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Flip animation */
@keyframes flipIn {
    from {
        opacity: 0;
        transform: perspective(400px) rotateY(90deg);
    }
    to {
        opacity: 1;
        transform: perspective(400px) rotateY(0deg);
    }
}

@keyframes flipOut {
    from {
        opacity: 1;
        transform: perspective(400px) rotateY(0deg);
    }
    to {
        opacity: 0;
        transform: perspective(400px) rotateY(90deg);
    }
}

/* ===== ANIMATION CLASSES ===== */

/* Loading states */
.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

.spinning {
    animation: spin 1s linear infinite;
}

.bouncing {
    animation: bounce 1s ease-in-out infinite;
}

/* Entrance animations */
.animate-slide-in-up {
    animation: slideInUp 0.5s ease-out forwards;
}

.animate-slide-in-down {
    animation: slideInDown 0.5s ease-out forwards;
}

.animate-slide-in-left {
    animation: slideInLeft 0.5s ease-out forwards;
}

.animate-slide-in-right {
    animation: slideInRight 0.5s ease-out forwards;
}

.animate-scale-in {
    animation: scaleIn 0.3s ease-out forwards;
}

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

/* Exit animations */
.animate-slide-out-up {
    animation: slideOutUp 0.3s ease-in forwards;
}

.animate-slide-out-down {
    animation: slideOutDown 0.3s ease-in forwards;
}

.animate-scale-out {
    animation: scaleOut 0.3s ease-in forwards;
}

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

/* Interaction animations */
.animate-shake {
    animation: shake 0.5s ease-in-out;
}

.animate-glow {
    animation: glow 2s ease-in-out infinite;
}

.animate-wave {
    animation: wave 1s ease-in-out infinite;
}

/* Flip animations */
.animate-flip-in {
    animation: flipIn 0.6s ease-out forwards;
}

.animate-flip-out {
    animation: flipOut 0.6s ease-in forwards;
}

/* ===== COMPONENT-SPECIFIC ANIMATIONS ===== */

/* Welcome screen animations */
.welcome-screen.entering {
    animation: fadeIn 0.8s ease-out forwards;
}

.welcome-screen.exiting {
    animation: slideOutUp 0.5s ease-in forwards;
}

.welcome-content h2 {
    animation: slideInDown 0.6s ease-out 0.2s both;
}

.welcome-content .subtitle {
    animation: slideInUp 0.6s ease-out 0.4s both;
}

.welcome-content .feature-highlights {
    animation: slideInUp 0.6s ease-out 0.6s both;
}

.welcome-content .primary-btn {
    animation: scaleIn 0.6s ease-out 0.8s both;
}

.welcome-content .game-info {
    animation: fadeIn 0.6s ease-out 1s both;
}

/* Question screen animations */
.question-screen.entering {
    animation: slideInRight 0.5s ease-out forwards;
}

.question-screen.exiting {
    animation: slideOutLeft 0.3s ease-in forwards;
}

.question-title {
    animation: slideInDown 0.5s ease-out 0.1s both;
}

.option-card {
    transform: translateY(20px);
    opacity: 0;
    animation: slideInUp 0.5s ease-out forwards;
}

.option-card:nth-child(1) {
    animation-delay: 0.2s;
}

.option-card:nth-child(3) {
    animation-delay: 0.4s;
}

.vs-separator {
    animation: scaleIn 0.4s ease-out 0.3s both;
}

/* Option selection animations */
.option-card.selecting {
    animation: scaleIn 0.2s ease-out forwards;
    transform: scale(1.05);
}

.option-card.selected {
    animation: glow 1s ease-in-out;
}

.option-card.not-selected {
    animation: fadeOut 0.3s ease-in forwards;
    opacity: 0.3;
}

/* Results screen animations */
.results-screen.entering {
    animation: slideInUp 0.6s ease-out forwards;
}

.results-title {
    animation: slideInDown 0.5s ease-out 0.1s both;
}

.user-choice-indicator {
    animation: scaleIn 0.5s ease-out 0.2s both;
}

.result-option {
    opacity: 0;
    animation: slideInLeft 0.5s ease-out forwards;
}

.result-option:nth-child(1) {
    animation-delay: 0.3s;
}

.result-option:nth-child(2) {
    animation-delay: 0.5s;
}

.progress-fill {
    width: 0%;
    animation: fillProgress 1.5s ease-out 0.7s forwards;
}

.vote-count {
    animation: fadeIn 0.5s ease-out 2.2s both;
}

.results-actions {
    animation: slideInUp 0.5s ease-out 2.4s both;
}

/* Modal animations */
.modal.entering {
    animation: fadeIn 0.3s ease-out forwards;
}

.modal.entering .modal-content {
    animation: scaleIn 0.3s ease-out forwards;
}

.modal.exiting {
    animation: fadeOut 0.3s ease-in forwards;
}

.modal.exiting .modal-content {
    animation: scaleOut 0.3s ease-in forwards;
}

/* Toast animations */
.toast {
    transform: translateX(100%);
    animation: slideInRight 0.3s ease-out forwards;
}

.toast.removing {
    animation: slideOutRight 0.3s ease-in forwards;
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* Confetti effect */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1500;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--primary-color);
    animation: confetti 3s ease-in-out forwards;
}

.confetti:nth-child(even) {
    background: var(--secondary-color);
}

.confetti:nth-child(3n) {
    background: var(--accent-color);
}

/* Typing effect */
.typing-text {
    overflow: hidden;
    border-right: 2px solid currentColor;
    white-space: nowrap;
    animation: 
        typing 2s steps(40, end),
        blinkCaret 0.75s step-end infinite;
}

/* Hover animations */
.hover-lift {
    transition: transform var(--transition-fast);
}

.hover-lift:hover {
    transform: translateY(-2px);
}

.hover-scale {
    transition: transform var(--transition-fast);
}

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

.hover-rotate {
    transition: transform var(--transition-fast);
}

.hover-rotate:hover {
    transform: rotate(5deg);
}

/* Focus animations */
.focus-glow:focus {
    animation: glow 0.3s ease-out;
}

/* ===== STAGGERED ANIMATIONS ===== */
.stagger-children > * {
    opacity: 0;
    transform: translateY(20px);
    animation: slideInUp 0.5s ease-out forwards;
}

.stagger-children > *:nth-child(1) { animation-delay: 0.1s; }
.stagger-children > *:nth-child(2) { animation-delay: 0.2s; }
.stagger-children > *:nth-child(3) { animation-delay: 0.3s; }
.stagger-children > *:nth-child(4) { animation-delay: 0.4s; }
.stagger-children > *:nth-child(5) { animation-delay: 0.5s; }
.stagger-children > *:nth-child(6) { animation-delay: 0.6s; }
.stagger-children > *:nth-child(7) { animation-delay: 0.7s; }
.stagger-children > *:nth-child(8) { animation-delay: 0.8s; }

/* ===== ANIMATION SPEED CONTROLS ===== */
.speed-slow * {
    animation-duration: calc(var(--animation-duration, 0.5s) * 2) !important;
    transition-duration: calc(var(--transition-duration, 0.3s) * 2) !important;
}

.speed-fast * {
    animation-duration: calc(var(--animation-duration, 0.5s) * 0.5) !important;
    transition-duration: calc(var(--transition-duration, 0.3s) * 0.5) !important;
}

.no-animations * {
    animation: none !important;
    transition: none !important;
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
.will-animate {
    will-change: transform, opacity;
}

/* Use GPU acceleration for better performance */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* ===== ACCESSIBILITY CONSIDERATIONS ===== */
@media (prefers-reduced-motion: reduce) {
    .animate-slide-in-up,
    .animate-slide-in-down,
    .animate-slide-in-left,
    .animate-slide-in-right,
    .animate-scale-in,
    .animate-fade-in,
    .animate-slide-out-up,
    .animate-slide-out-down,
    .animate-scale-out,
    .animate-fade-out,
    .animate-flip-in,
    .animate-flip-out {
        animation: fadeIn 0.01s ease-out forwards;
    }
    
    .option-card,
    .result-option,
    .modal-content {
        animation: fadeIn 0.01s ease-out forwards;
    }
    
    .progress-fill {
        animation: none;
        width: var(--target-width);
    }
    
    .spinning,
    .bouncing,
    .animate-glow,
    .animate-wave {
        animation: none;
    }
    
    .confetti {
        display: none;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .animate-slide-in-up,
    .animate-slide-in-down,
    .animate-slide-in-left,
    .animate-slide-in-right,
    .animate-scale-in,
    .animate-fade-in,
    .animate-slide-out-up,
    .animate-slide-out-down,
    .animate-scale-out,
    .animate-fade-out,
    .animate-flip-in,
    .animate-flip-out,
    .spinning,
    .bouncing,
    .animate-glow,
    .animate-wave {
        animation: none !important;
    }
}