* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #0f0f1e 0%, #1a1a2e 50%, #16213e 100%);
    color: #eee;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(77, 184, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(77, 184, 255, 0.05) 0%, transparent 50%);
    pointer-events: none;
}

.container {
    width: 90%;
    max-width: 1000px;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

/* Header Section */
.header-section {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1.5rem;
    position: relative;
    transition: all 0.5s ease;
}

.header-section.game-active {
    justify-content: space-between;
}

h1 {
    font-size: 2.5rem;
    background: linear-gradient(45deg, #4db8ff, #3da9f5, #4ecdc4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(77, 184, 255, 0.3);
    font-weight: 800;
    letter-spacing: -1px;
    margin: 0;
    transition: transform 0.5s ease;
}

.header-timer {
    font-size: 2.5rem;
    font-weight: bold;
    color: #4db8ff;
    min-width: 120px;
    text-align: right;
    display: none; /* Hidden by default, shown during test */
    opacity: 0;
    transition: opacity 0.5s ease;
}

.header-section.game-active .header-timer {
    opacity: 1;
}

.header-timer.warning {
    animation: warningFlash 1s ease-in-out infinite;
}

.stats-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: linear-gradient(145deg, #1e2942 0%, #16213e 100%);
    padding: 2rem 1.5rem;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(77, 184, 255, 0.1);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(77, 184, 255, 0.05) 0%, transparent 70%);
    transform: rotate(45deg);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px rgba(77, 184, 255, 0.2);
    border-color: rgba(77, 184, 255, 0.3);
}

.stat-card h3 {
    font-size: 0.85rem;
    color: #94a3b8;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.stat-card p {
    font-size: 2.2rem;
    font-weight: 700;
    background: linear-gradient(45deg, #4db8ff, #4ecdc4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.test-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.test-controls label {
    font-size: 1rem;
}

.test-controls select {
    padding: 0.75rem 1.5rem;
    border-radius: 25px;
    border: 1px solid rgba(77, 184, 255, 0.3);
    background: rgba(22, 33, 62, 0.8);
    color: #eee;
    font-size: 1rem;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.test-controls select:hover {
    border-color: rgba(77, 184, 255, 0.5);
    background: rgba(22, 33, 62, 0.9);
}

.test-controls select:focus {
    outline: none;
    border-color: #4db8ff;
    box-shadow: 0 0 0 3px rgba(77, 184, 255, 0.2);
}

.btn-primary, .btn-secondary {
    padding: 1rem 2.5rem;
    border: none;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(45deg, #4db8ff, #3da9f5);
    color: #0f0f1e;
    box-shadow: 0 4px 15px rgba(77, 184, 255, 0.3);
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s ease;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(77, 184, 255, 0.4);
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-secondary {
    background: rgba(108, 117, 125, 0.3);
    color: #94a3b8;
    border: 1px solid rgba(148, 163, 184, 0.3);
    backdrop-filter: blur(10px);
}

.btn-secondary:hover {
    background: rgba(108, 117, 125, 0.5);
    border-color: rgba(148, 163, 184, 0.5);
    transform: translateY(-2px);
}

/* Hotkey hints */
.hotkey {
    font-size: 0.85em;
    opacity: 0.7;
    margin-left: 0.5rem;
    font-weight: normal;
}

@keyframes warningFlash {
    0%, 100% {
        color: #ff3333;
        text-shadow: 0 0 20px rgba(255, 51, 51, 0.8);
        transform: scale(1);
    }
    25% {
        color: #ffcc00;
        text-shadow: 0 0 20px rgba(255, 204, 0, 0.8);
        transform: scale(1.05);
    }
    50% {
        color: #ff6b6b;
        text-shadow: 0 0 30px rgba(255, 107, 107, 1);
        transform: scale(1.1);
    }
    75% {
        color: #ffa500;
        text-shadow: 0 0 20px rgba(255, 165, 0, 0.8);
        transform: scale(1.05);
    }
}

.test-area {
    margin-bottom: 2rem;
}

.prompt-text {
    background: linear-gradient(145deg, #1e2942 0%, #16213e 100%);
    padding: 1.5rem 2rem;
    border-radius: 20px;
    font-size: 1.6rem;
    line-height: 1.8;
    margin-bottom: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    height: calc(3 * 1.6rem * 1.8 + 3rem); /* 3 lines of text + padding */
    overflow-y: auto;
    scroll-behavior: smooth;
    position: relative;
    border: 1px solid rgba(77, 184, 255, 0.1);
    font-family: 'Courier New', Courier, monospace;
    /* GPU acceleration */
    transform: translateZ(0);
    will-change: scroll-position;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Contain layout changes */
    contain: layout style paint;
}

.prompt-text::-webkit-scrollbar {
    width: 8px;
}

.prompt-text::-webkit-scrollbar-track {
    background: #0f1724;
    border-radius: 4px;
}

.prompt-text::-webkit-scrollbar-thumb {
    background: #4db8ff;
    border-radius: 4px;
}

.prompt-text::-webkit-scrollbar-thumb:hover {
    background: #3da9f5;
}


.prompt-text .correct {
    color: #4ade80;
    /* Prevent repaints */
    transform: translateZ(0);
}

.prompt-text .incorrect {
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.2);
}

.prompt-text .current {
    background-color: #4db8ff;
    color: #1a1a2e;
    animation: blink 1s infinite;
    position: relative;
    /* GPU acceleration for smoother animation */
    transform: translateZ(0);
    will-change: opacity, transform;
    backface-visibility: hidden;
}

.prompt-text .current.error {
    background-color: #ef4444;
    animation: shake 0.5s ease-in-out infinite;
    /* Force GPU acceleration */
    transform: translateZ(0);
    will-change: transform;
}

@keyframes blink {
    0%, 50% { 
        opacity: 1;
        transform: translateZ(0);
    }
    51%, 100% { 
        opacity: 0.3;
        transform: translateZ(0);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0) translateZ(0); }
    25% { transform: translateX(-4px) translateZ(0); }
    75% { transform: translateX(4px) translateZ(0); }
}

.error-hint {
    position: absolute;
    background-color: #ef4444;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    font-size: 0.9rem;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    animation: fadeIn 0.3s ease-in;
}

.error-hint::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 8px solid transparent;
    border-top-color: #ef4444;
}

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

.user-input {
    width: 100%;
    padding: 1rem;
    border-radius: 10px;
    border: 2px solid #4db8ff;
    background-color: #16213e;
    color: #eee;
    font-size: 1.5rem;
    font-family: inherit;
    resize: none;
    min-height: 120px;
}

.user-input:focus {
    outline: none;
    border-color: #3da9f5;
    box-shadow: 0 0 0 3px rgba(77, 184, 255, 0.2);
}

.results-section {
    text-align: center;
}

.results-section .button-group {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
    flex-wrap: wrap;
}

.results-section h2 {
    font-size: 2.5rem;
    margin-bottom: 2rem;
    background: linear-gradient(45deg, #4ade80, #4db8ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
    font-weight: 700;
}


.result-details {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.result-details p {
    font-size: 1.1rem;
}

.result-details span {
    font-weight: bold;
    color: #4db8ff;
}

/* Stats Summary on Results Page */
.stats-summary {
    margin-top: 2rem;
    padding: 2rem;
    background: linear-gradient(145deg, #1e2942 0%, #16213e 100%);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(77, 184, 255, 0.1);
}

.stats-summary h3 {
    text-align: center;
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: #4db8ff;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
}

.stat-item {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.9rem;
    color: #94a3b8;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    display: block;
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(45deg, #4db8ff, #4ecdc4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

@media (max-width: 600px) {
    .header-section {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
    
    .header-section.game-active {
        flex-direction: row;
        justify-content: space-between;
    }
    
    h1 {
        font-size: 1.8rem;
    }
    
    .header-timer {
        font-size: 1.8rem;
        text-align: center;
    }
    
    .container {
        padding: 1rem;
    }
    
    .stats-section {
        grid-template-columns: 1fr;
    }
    
    .test-controls {
        flex-direction: column;
    }
    
    .prompt-text {
        font-size: 1.4rem;
        height: calc(3 * 1.4rem * 1.8 + 2rem);
    }
}

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

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #f0f0f0;
    top: -10px;
    animation: confetti-fall 3s linear forwards;
}

@keyframes confetti-fall {
    to {
        transform: translateY(100vh) rotate(360deg);
        opacity: 0;
    }
}

.confetti:nth-child(odd) {
    width: 8px;
    height: 8px;
    animation-duration: 2.5s;
}

.confetti:nth-child(3n) {
    width: 6px;
    height: 6px;
    animation-duration: 3.5s;
}

.confetti:nth-child(1) { left: 10%; background-color: #ff6b6b; animation-delay: 0s; }
.confetti:nth-child(2) { left: 20%; background-color: #4ecdc4; animation-delay: 0.1s; }
.confetti:nth-child(3) { left: 30%; background-color: #ffe66d; animation-delay: 0.2s; }
.confetti:nth-child(4) { left: 40%; background-color: #a8e6cf; animation-delay: 0.3s; }
.confetti:nth-child(5) { left: 50%; background-color: #ff8b94; animation-delay: 0.4s; }
.confetti:nth-child(6) { left: 60%; background-color: #c7ceea; animation-delay: 0.5s; }
.confetti:nth-child(7) { left: 70%; background-color: #ffd3e1; animation-delay: 0.6s; }
.confetti:nth-child(8) { left: 80%; background-color: #d4a5a5; animation-delay: 0.7s; }
.confetti:nth-child(9) { left: 90%; background-color: #9a8c98; animation-delay: 0.8s; }
.confetti:nth-child(10) { left: 15%; background-color: #ff6b6b; animation-delay: 0.9s; }
.confetti:nth-child(11) { left: 25%; background-color: #4ecdc4; animation-delay: 1s; }
.confetti:nth-child(12) { left: 35%; background-color: #ffe66d; animation-delay: 1.1s; }
.confetti:nth-child(13) { left: 45%; background-color: #a8e6cf; animation-delay: 1.2s; }
.confetti:nth-child(14) { left: 55%; background-color: #ff8b94; animation-delay: 1.3s; }
.confetti:nth-child(15) { left: 65%; background-color: #c7ceea; animation-delay: 1.4s; }
.confetti:nth-child(16) { left: 75%; background-color: #ffd3e1; animation-delay: 1.5s; }
.confetti:nth-child(17) { left: 85%; background-color: #d4a5a5; animation-delay: 1.6s; }
.confetti:nth-child(18) { left: 95%; background-color: #9a8c98; animation-delay: 1.7s; }
.confetti:nth-child(19) { left: 5%; background-color: #ff6b6b; animation-delay: 1.8s; }
.confetti:nth-child(20) { left: 50%; background-color: #4ecdc4; animation-delay: 1.9s; }

.new-high-score {
    font-size: 2rem;
    color: #4ade80;
    font-weight: bold;
    text-align: center;
    margin-bottom: 1rem;
    animation: pulse 1s ease-in-out infinite;
}

.tied-high-score {
    font-size: 1.8rem;
    color: #4db8ff;
    font-weight: bold;
    text-align: center;
    margin-bottom: 1rem;
    animation: pulse 1.2s ease-in-out infinite;
}

.near-miss {
    font-size: 1.6rem;
    color: #ffa500;
    font-weight: bold;
    text-align: center;
    margin-bottom: 1rem;
    animation: slowPulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes slowPulse {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.02); opacity: 1; }
}

/* Countdown and stoplight */
.countdown-section {
    text-align: center;
    margin: 2rem 0;
}

.stoplight {
    display: inline-block;
    background-color: #222;
    padding: 1rem;
    border-radius: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    margin-bottom: 2rem;
}

.light {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin: 0.5rem;
    background-color: #444;
    transition: all 0.3s ease;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.light.red {
    background-color: #444;
}

.light.red.active {
    background-color: #ff3333;
    box-shadow: 0 0 30px #ff3333, inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.light.yellow {
    background-color: #444;
}

.light.yellow.active {
    background-color: #ffcc00;
    box-shadow: 0 0 30px #ffcc00, inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.light.green {
    background-color: #444;
}

.light.green.active {
    background-color: #33ff33;
    box-shadow: 0 0 30px #33ff33, inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.countdown-text {
    font-size: 5rem;
    font-weight: bold;
    color: #4db8ff;
    text-shadow: 0 0 20px rgba(77, 184, 255, 0.5);
    animation: countdownPulse 1s ease-in-out;
}

@keyframes countdownPulse {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.countdown-text.go {
    color: #33ff33;
    text-shadow: 0 0 30px rgba(51, 255, 51, 0.8);
    animation: goPulse 0.5s ease-in-out;
}

@keyframes goPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Caps Lock Warning */
.caps-lock-warning {
    background-color: #ff4444;
    color: white;
    padding: 1rem;
    border-radius: 10px;
    margin: 1rem 0;
    text-align: center;
    font-weight: bold;
    animation: warningPulse 2s ease-in-out infinite;
}

@keyframes warningPulse {
    0%, 100% { 
        background-color: #ff4444;
        box-shadow: 0 0 10px rgba(255, 68, 68, 0.5);
    }
    50% { 
        background-color: #ff6666;
        box-shadow: 0 0 20px rgba(255, 68, 68, 0.8);
    }
}

/* Sound toggle button */
.sound-toggle-btn {
    position: fixed;
    top: 10px;
    right: 10px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(22, 33, 62, 0.9);
    color: #4ade80;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.sound-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.sound-toggle-btn.sound-off {
    color: #ef4444;
}

.sound-toggle-btn .sound-icon {
    width: 24px;
    height: 24px;
}

.sound-toggle-btn.sound-off .speaker {
    opacity: 0.7;
}

.sound-toggle-btn.sound-off .slash {
    display: block !important;
}