:root {
    --primary: #7C3AED;
    --primary-dark: #6D28D9;
    --primary-light: #A78BFA;
    --secondary: #4F46E5;
    --accent: #C084FC;
    
    --success: #10B981;
    --error: #EF4444;
    --warning: #F59E0B;
    
    --bg-white: #FFFFFF;
    --bg-light: #F9FAFB;
    --bg-purple-light: #FAF5FF;
    --text-dark: #1F2937;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    
    --gradient-primary: linear-gradient(135deg, #7C3AED, #C084FC);
    --gradient-purple: linear-gradient(135deg, #A78BFA, #C084FC);
    --gradient-success: linear-gradient(135deg, #10B981, #059669);
    --gradient-error: linear-gradient(135deg, #EF4444, #DC2626);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(180deg, #FFFFFF 0%, #FAF5FF 50%, #F3E8FF 100%);
    color: var(--text-dark);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 30%, rgba(124, 58, 237, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(192, 132, 252, 0.08) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

body > * {
    position: relative;
    z-index: 1;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

::selection {
    background: var(--primary);
    color: white;
}

/* Header */
.header {
    background: var(--gradient-primary);
    background-size: 200% 200%;
    animation: gradientShift 10s ease infinite;
    padding: 2rem 0;
    text-align: center;
    box-shadow: 0 10px 40px rgba(79, 70, 229, 0.3);
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 50px;
    height: 50px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
}

.tagline {
    opacity: 0.9;
    font-size: 1.1rem;
}

/* Ad Container */
.ad-container {
    display: flex;
    justify-content: center;
    min-height: 90px;
    margin: 1.5rem auto;
}

.ad-container:empty,
.ad-container ins iframe[style*="height: 1px"] {
    display: none;
}

/* Main Content */
.main {
    flex: 1;
    padding: 2rem 0;
    animation: fadeIn 0.6s ease-out;
}

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

/* Config Panel */
.config-panel {
    background: var(--bg-white);
    border: 2px solid rgba(124, 58, 237, 0.1);
    border-radius: 1.5rem;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 20px 60px rgba(124, 58, 237, 0.15);
    animation: scaleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.config-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.config-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.duration-btns, .difficulty-btns {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.duration-btn, .difficulty-btn, .language-btn, .option-btn {
    flex: 1;
    min-width: 80px;
    padding: 0.75rem;
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 0.75rem;
    color: var(--text-dark);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.option-btn span {
    font-size: 1rem;
}

.duration-btn:hover, .difficulty-btn:hover, .language-btn:hover, .option-btn:hover {
    background: var(--bg-purple-light);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.duration-btn.active, .difficulty-btn.active, .language-btn.active, .option-btn.active {
    background: var(--gradient-primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 8px 20px rgba(124, 58, 237, 0.4);
}

.start-btn {
    width: 100%;
    padding: 1.25rem;
    background: var(--gradient-primary);
    border: none;
    border-radius: 1rem;
    color: white;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    box-shadow: 0 10px 30px rgba(79, 70, 229, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.start-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 15px 40px rgba(79, 70, 229, 0.6);
}

.start-btn:active {
    transform: translateY(-1px) scale(0.98);
}

.start-icon {
    font-size: 1.5rem;
    animation: pulse 2s infinite;
}

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

/* Test Container */
.test-container {
    background: var(--bg-white);
    border: 2px solid rgba(124, 58, 237, 0.1);
    border-radius: 1.5rem;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(124, 58, 237, 0.15);
    animation: scaleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
}

.exit-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    background: rgba(255, 255, 255, 0.85);
    border: 2px solid rgba(239, 68, 68, 0.25);
    border-radius: 999px;
    color: var(--error);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 12px 30px rgba(239, 68, 68, 0.2);
    backdrop-filter: blur(6px);
    z-index: 120;
}

.exit-btn:hover {
    background: var(--gradient-error);
    color: #FFFFFF;
    border-color: transparent;
    transform: translateY(-2px);
    box-shadow: 0 16px 36px rgba(239, 68, 68, 0.35);
}

.exit-btn:active {
    transform: translateY(0);
}

.exit-icon {
    font-size: 1.2rem;
    line-height: 1;
}

/* Combo Display */
.combo-display {
    position: absolute;
    top: 50%;
    left: 50%;
    text-align: center;
    z-index: 100;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
    transition: none;
}

.combo-display.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    animation: comboAppear 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.combo-display.hide {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8) translateY(-30px);
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    animation: none;
}

@keyframes comboAppear {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5) rotate(-10deg);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2) rotate(5deg);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }
}

.combo-value {
    font-size: 6rem;
    font-weight: 900;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 40px rgba(124, 58, 237, 0.5);
    animation: comboShake 0.3s ease-in-out;
}

@keyframes comboShake {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

.combo-label {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: -1rem;
    letter-spacing: 0.3rem;
}

.combo-fire {
    font-size: 3rem;
    animation: firePulse 0.5s infinite;
}

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

/* Particles Canvas */
.particles-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* Stats Bar */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-item {
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    text-align: center;
    transition: all 0.3s ease;
}

.stat-item:hover {
    background: var(--bg-purple-light);
    border-color: var(--primary-light);
    transform: translateY(-2px);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Progress Ring */
.progress-ring {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.progress-ring-bg {
    fill: none;
    stroke: var(--border);
    stroke-width: 8;
}

.progress-ring-fill {
    fill: none;
    stroke: url(#gradient);
    stroke-width: 8;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    stroke-dasharray: 339.292;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s linear;
}

.progress-text {
    fill: var(--primary);
    font-size: 1.5rem;
    font-weight: 700;
    text-anchor: middle;
}

/* Text Display */
.text-display {
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 1rem;
    padding: 2rem;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    line-height: 2;
    font-family: 'Courier New', monospace;
    color: var(--text-muted);
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    user-select: none;
    word-wrap: break-word;
}

.text-display span {
    display: inline;
}

.text-display .correct {
    color: var(--success);
    animation: charCorrect 0.2s ease-out;
}

@keyframes charCorrect {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); color: #22C55E; }
    100% { transform: scale(1); }
}

.text-display .incorrect {
    color: var(--error);
    background: rgba(239, 68, 68, 0.2);
    border-radius: 0.25rem;
    animation: charShake 0.3s ease-in-out;
}

@keyframes charShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

.text-display .current {
    color: var(--primary);
    background: rgba(124, 58, 237, 0.1);
    padding: 0 0.25rem;
    border-radius: 0.25rem;
    animation: blink 1s infinite;
}

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

/* Input */
.text-input {
    width: 100%;
    padding: 1.25rem;
    background: var(--bg-white);
    border: 2px solid var(--border);
    border-radius: 1rem;
    color: var(--text-dark);
    font-size: 1.25rem;
    font-family: 'Courier New', monospace;
    transition: all 0.3s ease;
}

.text-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.1);
}

/* Result Panel */
.result-panel {
    background: var(--bg-white);
    border: 2px solid rgba(124, 58, 237, 0.1);
    border-radius: 1.5rem;
    padding: 3rem 2rem;
    box-shadow: 0 20px 60px rgba(124, 58, 237, 0.15);
    text-align: center;
    margin-bottom: 2rem;
    animation: scaleIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.result-title {
    font-size: 2rem;
    margin-bottom: 2rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.result-main {
    margin-bottom: 2rem;
}

.result-wpm {
    background: var(--gradient-primary);
    border-radius: 1.5rem;
    padding: 2rem;
    margin-bottom: 1rem;
    box-shadow: 0 15px 40px rgba(79, 70, 229, 0.4);
    animation: float 3s ease-in-out infinite;
}

.result-wpm-label {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: white;
}

.result-wpm-value {
    font-size: 5rem;
    font-weight: 900;
    line-height: 1;
    color: white;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.result-wpm-unit {
    font-size: 1.25rem;
    opacity: 0.9;
    margin-top: 0.5rem;
    color: white;
}

.result-grade {
    display: inline-block;
    padding: 0.75rem 2rem;
    background: var(--bg-purple-light);
    border: 2px solid var(--primary-light);
    border-radius: 2rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-dark);
}

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

.result-stat {
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 1rem;
    padding: 1.25rem;
    transition: all 0.3s ease;
}

.result-stat:hover {
    background: var(--bg-purple-light);
    border-color: var(--primary-light);
    transform: translateY(-4px);
    box-shadow: 0 10px 25px rgba(124, 58, 237, 0.2);
}

.result-stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.result-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.share-buttons {
    display: flex;
    gap: 0.75rem;
    width: 100%;
}

.btn-share {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 0.75rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    color: white;
}

.btn-twitter {
    background: #000000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-twitter:hover {
    background: #333333;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.btn-share:active {
    transform: translateY(0);
}

.btn {
    flex: 1;
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 1rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.4);
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 30px rgba(79, 70, 229, 0.5);
}

.btn-primary:active {
    transform: translateY(-1px) scale(0.98);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

/* History Section */
.history-section {
    background: var(--bg-white);
    border: 2px solid rgba(124, 58, 237, 0.1);
    border-radius: 1.5rem;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(124, 58, 237, 0.15);
    margin-bottom: 2rem;
}

.history-toggle {
    width: 100%;
    padding: 1.25rem 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-dark);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.history-toggle:hover {
    background: var(--bg-purple-light);
}

.toggle-icon {
    transition: transform 0.3s ease;
}

.history-toggle.active .toggle-icon {
    transform: rotate(180deg);
}

.history-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
}

.history-content.active {
    max-height: 800px;
    overflow-y: visible;
}

/* History list is already scrollable, no need to override */

.stats-overview {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    padding: 0 1.5rem 1.5rem;
}

.overview-card {
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    text-align: center;
    transition: all 0.3s ease;
}

.overview-card:hover {
    background: var(--bg-purple-light);
    border-color: var(--primary-light);
    transform: translateY(-4px);
}

.overview-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.overview-value {
    font-size: 2rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.history-list {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    max-height: 500px;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    
    /* Firefox scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--primary-light) var(--bg-light);
}

/* Webkit browsers scrollbar (Chrome, Safari, Edge) */
.history-list::-webkit-scrollbar {
    width: 8px;
}

.history-list::-webkit-scrollbar-track {
    background: var(--bg-light);
    border-radius: 4px;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--primary-light);
    border-radius: 4px;
    transition: background 0.3s ease;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    margin-bottom: 0.75rem;
    transition: all 0.2s ease;
}

.history-item:hover {
    background: var(--bg-purple-light);
    border-color: var(--primary-light);
}

.history-info {
    flex: 1;
}

.history-wpm {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.history-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.clear-history-btn {
    margin: 0 1.5rem 1.5rem;
    padding: 0.75rem;
    background: var(--gradient-error);
    border: none;
    border-radius: 0.75rem;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.clear-history-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.4);
}

.placeholder {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
    font-style: italic;
}

/* Achievements */
.achievements {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--border);
}

.achievement-badge {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.15), rgba(192, 132, 252, 0.15));
    color: var(--text-light);
    padding: 1rem;
    border-radius: 0.75rem;
    font-size: 0.95rem;
    font-weight: 600;
    border: 2px solid rgba(124, 58, 237, 0.3);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.2);
    animation: badgePop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.achievement-badge::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-primary);
    opacity: 0.8;
}

.achievement-badge:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(124, 58, 237, 0.4);
    border-color: var(--primary);
}

.achievement-badge .badge-icon {
    font-size: 2rem;
    line-height: 1;
    margin-bottom: 0.25rem;
}

.achievement-badge .badge-text {
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0.95;
}

/* Code Explanation */
.code-explanation {
    margin-top: 2rem;
    padding: 1.5rem;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(147, 197, 253, 0.1));
    border: 2px solid rgba(59, 130, 246, 0.3);
    border-radius: 1rem;
    animation: fadeIn 0.5s ease;
}

.code-explanation-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-light);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.code-explanation-content {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-light);
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    border-radius: 0.5rem;
}

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

/* Achievements Grid */
.achievements-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
}

.achievement-stat {
    text-align: center;
    padding: 1rem;
    background: var(--bg-light);
    border-radius: 1rem;
    border: 2px solid var(--border);
}

.achievement-stat-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.achievement-stat-value {
    font-size: 2rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.achievements-grid {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.achievement-category {
    background: var(--bg-light);
    border-radius: 1rem;
    padding: 1.5rem;
    border: 2px solid var(--border);
}

.achievement-category-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-light);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
}

.achievement-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.achievement-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-radius: 0.75rem;
    border: 2px solid var(--border);
    transition: all 0.3s ease;
    position: relative;
    background: var(--bg);
}

.achievement-item.unlocked {
    border-color: var(--primary);
    background: rgba(124, 58, 237, 0.1);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.2);
}

.achievement-item.locked {
    opacity: 0.6;
    filter: grayscale(0.5);
}

.achievement-item.unlocked:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.3);
}

.achievement-icon {
    font-size: 2rem;
    line-height: 1;
    flex-shrink: 0;
}

.achievement-info {
    flex: 1;
    min-width: 0;
}

.achievement-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 0.25rem;
}

.achievement-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.achievement-badge-check {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 24px;
    height: 24px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.4);
}

.achievement-badge-lock {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-size: 1rem;
    opacity: 0.5;
}

@media (max-width: 768px) {
    .achievements-stats {
        grid-template-columns: 1fr;
    }
    
    .achievement-items {
        grid-template-columns: 1fr;
    }
    
    .achievement-stat-value {
        font-size: 1.5rem;
    }
}

@keyframes badgePop {
    0% {
        opacity: 0;
        transform: scale(0) rotate(-10deg);
    }
    50% {
        transform: scale(1.1) rotate(5deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

/* Footer */
.footer {
    background: var(--bg-white);
    padding: 2rem 0;
    text-align: center;
    border-top: 2px solid var(--border);
    margin-top: auto;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s ease;
}

.footer-links a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.footer-links span {
    color: var(--text-muted);
}

.footer p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Notification */
.notification {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    background: var(--gradient-success);
    color: white;
    border-radius: 1rem;
    box-shadow: 0 10px 30px rgba(16, 185, 129, 0.4);
    font-weight: 600;
    opacity: 0;
    transform: translateX(400px);
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1000;
}

.notification.show {
    opacity: 1;
    transform: translateX(0);
}

.notification.error {
    background: var(--gradient-error);
    box-shadow: 0 10px 30px rgba(239, 68, 68, 0.4);
}

/* Custom Text Section */
.custom-text-section {
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    animation: slideDown 0.3s ease-out;
}

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

.custom-text-section label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.custom-text-input {
    width: 100%;
    min-height: 120px;
    padding: 1rem;
    background: var(--bg-white);
    border: 2px solid var(--border);
    border-radius: 0.75rem;
    font-size: 1rem;
    font-family: 'Courier New', monospace;
    resize: vertical;
    transition: all 0.3s ease;
}

.custom-text-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.1);
}

.custom-text-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.custom-text-toggle-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 0.75rem;
    color: var(--text-dark);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.custom-text-toggle-btn:hover {
    background: var(--bg-purple-light);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.custom-text-toggle-btn.active {
    background: var(--gradient-primary);
    color: white;
    border-color: var(--primary);
}

/* Daily Challenge */
.daily-challenge-box {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.1), rgba(192, 132, 252, 0.1));
    border: 2px solid rgba(124, 58, 237, 0.3);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    animation: pulseGlow 3s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(124, 58, 237, 0.2);
    }
    50% {
        box-shadow: 0 0 30px rgba(124, 58, 237, 0.4);
    }
}

.challenge-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.challenge-icon {
    font-size: 2rem;
    line-height: 1;
}

.challenge-info {
    flex: 1;
    min-width: 200px;
}

.challenge-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 0.25rem;
}

.challenge-desc {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.challenge-btn {
    padding: 0.75rem 1.5rem;
    white-space: nowrap;
    background: var(--gradient-primary) !important;
    color: white !important;
    border: 2px solid var(--primary) !important;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.4);
}

.challenge-btn:hover {
    background: var(--gradient-primary) !important;
    border-color: var(--primary) !important;
    color: white !important;
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 30px rgba(79, 70, 229, 0.5);
}

/* Next Character Hint */
.next-char-hint {
    text-align: center;
    margin-top: 1rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--bg-purple-light);
    border: 2px solid var(--primary-light);
    border-radius: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    min-height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.next-char-hint::before {
    content: "Next: ";
    font-size: 1rem;
    color: var(--text-muted);
    margin-right: 0.5rem;
    font-weight: 500;
}

.next-char-hint:empty::before {
    content: "";
}

/* Typing Rhythm Visualization */
.rhythm-visualization {
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 1rem;
    padding: 1rem;
    margin-bottom: 1.5rem;
    display: none;
}

.rhythm-visualization.active {
    display: block;
}

.rhythm-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.rhythm-canvas {
    width: 100%;
    height: 100px;
    border-radius: 0.5rem;
}

/* Error Analysis */
.error-analysis {
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.error-analysis-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-dark);
}

.error-chars {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.error-char-item {
    background: var(--bg-white);
    border: 2px solid var(--error);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 60px;
}

.error-char {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--error);
    margin-bottom: 0.25rem;
}

.error-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* WPM Chart */
.wpm-chart-section {
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-dark);
}

.wpm-chart {
    width: 100%;
    height: 200px;
}

/* Shortcut Hint */
.shortcut-hint {
    font-size: 0.75rem;
    opacity: 0.7;
    font-weight: 400;
    margin-left: 0.5rem;
}

/* Enhanced Error Display */
.text-display .incorrect {
    color: var(--error);
    background: rgba(239, 68, 68, 0.25);
    border-radius: 0.25rem;
    padding: 0 0.2rem;
    animation: errorPulse 0.4s ease-out;
    text-decoration: underline;
    text-decoration-color: var(--error);
    text-underline-offset: 2px;
}

@keyframes errorPulse {
    0%, 100% {
        background: rgba(239, 68, 68, 0.25);
        transform: scale(1);
    }
    50% {
        background: rgba(239, 68, 68, 0.4);
        transform: scale(1.05);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .header h1 {
        font-size: 1.5rem;
    }
    
    .exit-btn {
        top: 0.75rem;
        right: 0.75rem;
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
    
    .achievements {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 0.75rem;
    }
    
    .achievement-badge {
        padding: 0.75rem;
    }
    
    .achievement-badge .badge-icon {
        font-size: 1.5rem;
    }
    
    .achievement-badge .badge-text {
        font-size: 0.8rem;
    }

    .exit-icon {
        font-size: 1rem;
    }

    .config-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .progress-ring {
        position: static;
        margin: 0 auto 1rem;
    }
    
    .text-display {
        font-size: 1.1rem;
        padding: 1.5rem;
    }
    
    .result-wpm-value {
        font-size: 3.5rem;
    }
    
    .stats-overview {
        grid-template-columns: 1fr;
    }
    
    .result-actions {
        flex-direction: column;
    }
    
    .share-buttons {
        flex-direction: column;
    }
    
    .rhythm-visualization {
        display: none !important;
    }
    
    .wpm-chart {
        height: 150px;
    }
    
    /* Mobile history list scroll */
    .history-list {
        max-height: 300px;
    }
    
    .history-content.active {
        max-height: 600px;
    }
}

