:root {
    --bg-color: #0d0e12;
    --surface-color: #16181d;
    --primary-color: #6466f1;
    --primary-hover: #4f51d1;
    --text-main: #e2e8f0;
    --text-muted: #64748b;
    --text-correct: #e2e8f0;
    --text-incorrect: #ef4444;
    --word-default: #475569;
    --caret-color: #fbbf24;
    --font-heading: 'Inter', sans-serif;
    --font-mono: 'Roboto Mono', monospace;
    --radius-lg: 16px;
    --radius-md: 8px;
    --shadow-soft: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-heading);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.app-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30px 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--text-main);
}

.logo-icon {
    color: var(--primary-color);
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    margin-left: 20px;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-links a:hover, .nav-links a.active {
    color: var(--primary-color);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px 0 60px;
    position: relative;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    gap: 40px;
    margin-bottom: 40px;
    background: var(--surface-color);
    padding: 15px 30px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

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

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--primary-color);
}

#timer {
    color: var(--caret-color);
}

/* Typing Area */
.typing-container {
    position: relative;
    width: 100%;
    max-width: 900px;
    margin-bottom: 30px;
}

.typing-area {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    line-height: 1.6;
    color: var(--word-default);
    word-break: keep-all; /* Prevent splitting words mid-typing */
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem; /* Space between words */
    user-select: none;
    position: relative;
    min-height: 150px;
    /* Mask effect to fade out top/bottom lines if we were scrolling, 
       but for this design we'll keep it simple first */
}

/* Words and Letters */
.word {
    display: inline-flex;
    position: relative;
    margin-right: 8px;
    border-radius: 4px;
}

.letter {
    position: relative;
    transition: color 0.1s ease;
}

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

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

/* Caret */
.caret {
    position: absolute;
    width: 2px;
    height: 1.5em;
    background-color: var(--caret-color);
    animation: blink 1s infinite;
    transition: left 0.1s ease, top 0.1s ease;
    border-radius: 2px;
    z-index: 10;
    display: none; /* JS will show and position it */
}

.caret.active {
    display: block;
}

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

/* Hidden Input */
.hidden-input {
    position: absolute;
    opacity: 0;
    top: 0;
    left: 0;
    pointer-events: none; /* But we need to focus it */
}

/* Instructions */
.instructions {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 20px;
    opacity: 0.7;
}

.instructions span {
    background: var(--surface-color);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.1);
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

/* Results Overlay */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(13, 14, 18, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 20;
    border-radius: var(--radius-lg);
}

.overlay.show {
    opacity: 1;
    pointer-events: all;
}

.results-card {
    background: var(--surface-color);
    padding: 40px;
    border-radius: var(--radius-lg);
    text-align: center;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
    transform: translateY(20px);
    transition: transform 0.3s ease;
    border: 1px solid rgba(255,255,255,0.05);
}

.overlay.show .results-card {
    transform: translateY(0);
}

.results-card h2 {
    margin-bottom: 30px;
    font-size: 2rem;
}

.result-grid {
    display: flex;
    gap: 30px;
    margin-bottom: 30px;
    justify-content: center;
}

.result-box {
    display: flex;
    flex-direction: column;
}

.result-number {
    font-size: 3rem;
    font-weight: 800;
    color: var(--primary-color);
    line-height: 1;
}

.result-label {
    color: var(--text-muted);
    margin-top: 5px;
}

.restart-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

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

/* Footer */
.footer {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Correct/Error Shake Animation for container maybe? (Optional) */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.error-shake {
    animation: shake 0.2s ease-in-out;
}
