/* 
 * Turbo Typing Test - Animations
 * Enhanced animations for a more engaging typing experience
 */

/* Character animations */
@keyframes charFadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes charCorrect {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

@keyframes charIncorrect {
    0% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    50% { transform: translateX(3px); }
    75% { transform: translateX(-3px); }
    100% { transform: translateX(0); }
}

@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Result card animations */
@keyframes countUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes cardEntrance {
    from { transform: translateY(30px) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

/* Celebration animations */
@keyframes confetti {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

@keyframes celebrate {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes firework {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) scale(1.2); opacity: 0; }
}

/* Button animations */
@keyframes buttonPulse {
    0% { transform: scale(1); box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); }
    50% { transform: scale(1.05); box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2); }
    100% { transform: scale(1); box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); }
}

/* Progress bar animations */
@keyframes progressPulse {
    0% { opacity: 0.8; }
    50% { opacity: 1; }
    100% { opacity: 0.8; }
}

/* Enhanced keyboard animations */
@keyframes keyPressEnhanced {
    0% { transform: translateY(0) scale(1); background-color: var(--keyboard-key-bg); }
    50% { transform: translateY(4px) scale(0.95); background-color: var(--keyboard-key-active); }
    100% { transform: translateY(0) scale(1); background-color: var(--keyboard-key-bg); }
}

@keyframes keyErrorEnhanced {
    0% { transform: translateY(0) rotate(0); background-color: var(--keyboard-key-bg); }
    25% { transform: translateY(2px) rotate(-3deg); background-color: var(--keyboard-key-wrong); }
    50% { transform: translateY(4px) rotate(3deg); background-color: var(--keyboard-key-wrong); }
    75% { transform: translateY(2px) rotate(-3deg); background-color: var(--keyboard-key-wrong); }
    100% { transform: translateY(0) rotate(0); background-color: var(--keyboard-key-bg); }
}

/* Section transition animations */
@keyframes sectionFadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes sectionSlideIn {
    from { opacity: 0; transform: translateX(-30px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Background animations */
@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Timer animation */
@keyframes timerPulse {
    0% { transform: scale(1); color: var(--accent-color); }
    50% { transform: scale(1.1); color: var(--warning-color); }
    100% { transform: scale(1); color: var(--accent-color); }
}

/* Apply animations to elements */
.char {
    animation: charFadeIn 0.2s ease-out;
}

/* Celebration elements */
.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    background-color: var(--accent-color);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1000;
    animation: confetti 4s ease-out forwards;
}

.celebration-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.5s;
}

.celebration-container.active {
    opacity: 1;
}

.firework {
    position: absolute;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: var(--success-color);
    animation: firework 1s ease-out forwards;
}

.char.correct {
    animation: charCorrect 0.3s ease-out;
}

.char.incorrect {
    animation: charIncorrect 0.3s ease-out;
}

.char.current::after {
    animation: cursorBlink 1s infinite;
}

.result-card {
    animation: cardEntrance 0.5s ease-out forwards;
    animation-delay: calc(var(--card-index, 0) * 0.1s);
    opacity: 0;
}

.result-card .value {
    animation: countUp 1s ease-out forwards;
    animation-delay: calc(var(--card-index, 0) * 0.1s + 0.3s);
}

#start-btn:hover {
    animation: buttonPulse 1.5s infinite;
}

#progress-bar {
    animation: progressPulse 2s infinite;
}

.key.active {
    animation: keyPressEnhanced 0.3s ease-out;
}

.key.wrong {
    animation: keyErrorEnhanced 0.5s ease-out;
}

#timer.warning {
    animation: timerPulse 1s infinite;
}

/* Back to top button animations */
@keyframes backToTopFadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes backToTopFadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(20px); }
}

/* Apply background animation */
body {
    background-size: 200% 200%;
    animation: gradientShift 15s ease infinite;
}

/* Section animations */
.test-container, #results, .keyboard-container, #history {
    animation: sectionFadeIn 0.5s ease-out;
}

/* Animate logo */
.logo i {
    animation: buttonPulse 2s infinite;
}
