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

:root {
    --bg: #0a0a0a;
    --surface: #1a1a1a;
    --surface-hover: #252525;
    --text: #e8e8e8;
    --text-dim: #666;
    --accent: #646cff;
    --accent-hover: #535bf2;
    --error: #ff5555;
    --correct: #50fa7b;
    --warning: #ffb86c;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: rgba(0, 0, 0, 0.3);
}

body.light {
    --bg: #fafafa;
    --surface: #ffffff;
    --surface-hover: #f0f0f0;
    --text: #1a1a1a;
    --text-dim: #999;
    --border: rgba(0, 0, 0, 0.1);
    --shadow: rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

#bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    opacity: 0.4;
}

/* Navigation */
.nav {
    position: relative;
    z-index: 10;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
}

.nav-links {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.nav-link {
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: 6px;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.nav-link:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.nav-link.active {
    color: var(--accent);
}

.icon-btn {
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 1.2rem;
}

.icon-btn:hover {
    background: var(--accent);
    color: white;
}

/* Container */
.container {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.section {
    margin-bottom: 3rem;
}

.section h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

/* Config Bar */
.config-bar {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    flex-wrap: wrap;
}

.config-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.config-group.hidden {
    display: none;
}

.config-group label {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.config-options {
    display: flex;
    gap: 0.25rem;
}

.config-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.config-btn:hover {
    color: var(--text);
    border-color: var(--accent);
}

.config-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.language-select {
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}

/* Live Stats */
.live-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 1.5rem;
}

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

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
    margin-bottom: 0.3rem;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* WPM Mini Chart */
.wpm-mini-chart {
    height: 60px;
    margin-bottom: 2rem;
    padding: 0 2rem;
}

#live-chart {
    width: 100% !important;
    height: 100% !important;
}

/* Typing Area */
.typing-area {
    position: relative;
    margin-bottom: 2rem;
}

.words {
    font-size: 1.5rem;
    line-height: 2;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    color: var(--text-dim);
    user-select: none;
    padding: 3rem;
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    min-height: 180px;
    overflow: hidden;
    position: relative;
}

.word {
    display: inline-block;
    margin: 0 0.5rem 0.5rem 0;
}

.letter {
    position: relative;
    transition: color 0.05s;
}

.letter.correct {
    color: var(--text);
}

.letter.incorrect {
    color: var(--error);
}

.letter.current::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 2px;
    background: var(--accent);
    animation: blink 1s infinite;
}

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

.input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* Restart Button */
.restart-btn {
    display: block;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.75rem 2rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.restart-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Profile Page */
.profile-header {
    text-align: center;
    padding: 2rem;
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 2rem;
}

.profile-header h1 {
    font-size: 2rem;
    margin-bottom: 1rem;
    outline: none;
}

.profile-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    font-size: 1.1rem;
}

.profile-stats strong {
    color: var(--accent);
}

.chart-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
    height: 300px;
}

.test-history {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.test-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Keyboard Heatmap */
.keyboard-heatmap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.heatmap-row {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.heatmap-key {
    width: 60px;
    height: 60px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.heatmap-key-letter {
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: uppercase;
}

.heatmap-key-count {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 0.25rem;
}

.heatmap-legend {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
    width: 100%;
}

.legend-title {
    font-size: 0.9rem;
    color: var(--text-dim);
    text-align: center;
    margin-bottom: 1rem;
}

.legend-gradient {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.legend-bar {
    flex: 1;
    height: 20px;
    border-radius: 10px;
    background: linear-gradient(90deg, 
        rgba(100, 108, 255, 0.3),
        rgba(80, 250, 123, 0.4),
        rgba(255, 184, 108, 0.6),
        rgba(255, 121, 198, 0.7),
        rgba(255, 85, 85, 0.9)
    );
}

.legend-label {
    font-size: 0.85rem;
    color: var(--text-dim);
}

.legend-stats {
    display: flex;
    justify-content: space-around;
    font-size: 0.85rem;
    color: var(--text-dim);
}

.heatmap-controls {
    margin-bottom: 1rem;
}

.btn-secondary {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
}

/* Keyboard Tester */
.keyboard-tester-header {
    text-align: center;
    margin-bottom: 3rem;
}

.subtitle {
    color: var(--text-dim);
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

.tester-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 2rem;
}

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

.tester-stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.tester-stat-label {
    font-size: 0.85rem;
    color: var(--text-dim);
    text-transform: uppercase;
}

.visual-keyboard {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
    display: flex;
    gap: 2rem;
    justify-content: center;
    align-items: center;
}

.keyboard-main {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.keyboard-row {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.key {
    background: var(--surface-hover);
    border: 2px solid var(--border);
    color: var(--text);
    padding: 0.75rem 0.5rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
    user-select: none;
}

.key.pressed {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    transform: translateY(2px);
}

.key.tested {
    background: var(--correct);
    border-color: var(--correct);
    color: white;
}

.key.tested.pressed {
    background: var(--accent);
    border-color: var(--accent);
}

.key-spacer {
    height: 48px;
}

.arrow-keys {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.arrow-row {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.arrow-key {
    width: 48px !important;
    font-size: 1.2rem;
}

.keyboard-info {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
}

.keyboard-info h3 {
    margin-bottom: 1rem;
}

.keyboard-info ul {
    list-style: none;
    padding-left: 0;
}

.keyboard-info li {
    padding: 0.5rem 0;
    color: var(--text-dim);
}

/* Leaderboard */
.leaderboard-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 60px 1fr 100px 100px;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.rank {
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--accent);
}

/* Settings */
.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.setting-item label {
    flex: 1;
}

.setting-item input[type="range"] {
    flex: 2;
}

.setting-item select {
    flex: 2;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem;
    border-radius: 6px;
}

.btn-danger {
    background: var(--error);
    border: none;
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-danger:hover {
    opacity: 0.8;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin-bottom: 1.5rem;
    text-align: center;
}

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

.result-big {
    text-align: center;
}

.result-big > div:first-child {
    font-size: 3rem;
    font-weight: 700;
    color: var(--accent);
}

.result-big > div:last-child {
    font-size: 0.9rem;
    color: var(--text-dim);
    text-transform: uppercase;
}

#result-chart {
    height: 200px;
    margin-bottom: 1.5rem;
}

.btn-primary {
    display: block;
    width: 100%;
    background: var(--accent);
    border: none;
    color: white;
    padding: 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

/* Responsive */
@media (max-width: 768px) {
    .nav-container {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }
    
    .container {
        padding: 1rem;
    }
    
    .config-bar {
        gap: 1rem;
    }
    
    .live-stats {
        gap: 1.5rem;
    }
    
    .stat-value {
        font-size: 2rem;
    }
    
    .words {
        font-size: 1.2rem;
        padding: 1.5rem;
    }
    
    .visual-keyboard {
        flex-direction: column;
        padding: 1rem;
    }
    
    .key {
        font-size: 0.7rem;
        padding: 0.5rem 0.25rem;
        min-height: 40px;
    }
    
    .heatmap-key {
        width: 45px;
        height: 45px;
    }
}
