:root {
    --bg-color: #1A150A;
    --primary: #F39C12;
    --accent: #3498DB;
    --text-main: #FFFFFF;
    --text-dim: #8A877E;
    --error: #E74C3C;
    --correct: #2ECC71;
    --panel-bg: rgba(30, 25, 15, 0.95);
    
    --font-ui: 'Inter', sans-serif;
    --font-mono: 'Fira Code', monospace;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-ui);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#app {
    width: 100%;
    max-width: 900px;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

.primary { color: var(--primary); }
.accent { color: var(--accent); }
.mt-lg { margin-top: 2rem; }

/* Main Game Interface */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    gap: 2rem;
}

.stats-header {
    display: flex;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.03);
    padding: 1rem 2rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

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

.stat-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 1px;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

/* Race Track */
.race-track {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    position: relative;
}

.lane {
    position: relative;
    padding: 0.5rem 0;
    border-bottom: 2px dashed rgba(255,255,255,0.1);
}

.lane:last-child {
    border-bottom: none;
}

.racer {
    position: absolute;
    top: -20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: left 0.2s linear;
    z-index: 10;
    transform: translateX(-50%);
    width: 60px;
}

.racer-icon {
    font-size: 2rem;
    filter: drop-shadow(0 0 10px rgba(255,255,255,0.2));
}

.racer.player .racer-icon { filter: drop-shadow(0 0 10px var(--primary)); }
.racer.opponent .racer-icon { filter: drop-shadow(0 0 10px var(--accent)); }

.racer-name {
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 0.25rem;
    background: var(--bg-color);
    padding: 2px 6px;
    border-radius: 4px;
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.05);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 15px;
}

.progress-bar {
    height: 100%;
    width: 0%;
    transition: width 0.2s linear;
}

#player-progress { background: var(--primary); box-shadow: 0 0 10px var(--primary); }
#bot-progress { background: var(--accent); box-shadow: 0 0 10px var(--accent); }

/* Finish Line */
.race-track::after {
    content: '';
    position: absolute;
    right: 20px;
    top: 10px;
    bottom: 10px;
    width: 10px;
    background: repeating-linear-gradient(45deg, #FFF, #FFF 5px, #000 5px, #000 10px);
    opacity: 0.5;
}

/* Typing Section */
.typing-section {
    flex: 1;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
    cursor: text;
}

.text-display {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    line-height: 1.6;
    color: var(--text-dim);
    white-space: pre-wrap;
    word-break: break-word;
    user-select: none;
}

.text-display .word {
    display: inline-block;
    margin-right: 0.5em; /* standard space */
}

/* Character states */
.char {
    position: relative;
    display: inline-block;
    color: var(--text-dim);
}

.char.correct { color: var(--text-main); }
.char.incorrect {
    color: var(--error);
    background: rgba(231, 76, 60, 0.2);
    border-radius: 2px;
}
.char.extra {
    color: var(--error);
    opacity: 0.7;
}

/* Caret */
.char.active::before {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0px;
    width: 2px;
    height: 90%;
    background-color: var(--primary);
    animation: blink 1s step-end infinite;
}

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

/* Must keep an invisible input to pop up mobile keyboard */
#hidden-input {
    position: absolute;
    opacity: 0;
    top: 50%;
    left: 50%;
    width: 1px;
    height: 1px;
    z-index: -1;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal {
    background: var(--panel-bg);
    padding: 3rem;
    border-radius: 16px;
    border: 1px solid rgba(243, 156, 18, 0.2);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    text-align: center;
    max-width: 500px;
    width: 90%;
}

.title {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

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

.settings-group { margin-bottom: 2rem; }
.settings-group h3 {
    margin-bottom: 1rem;
    color: var(--text-dim);
    font-size: 0.9rem;
    text-transform: uppercase;
}

.difficulty-selector {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.diff-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--text-main);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.2s;
}

.diff-btn:hover { border-color: var(--text-main); }
.diff-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #000;
}

/* Special Button */
.action-btn {
    background: var(--primary);
    color: #000;
    border: none;
    padding: 1rem 3rem;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(243, 156, 18, 0.4);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(243, 156, 18, 0.6);
}

.action-btn:active {
    transform: translateY(1px);
}

.action-btn.secondary {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--text-main);
    box-shadow: none;
}
.action-btn.secondary:hover { background: rgba(255,255,255,0.05); border-color: var(--text-main); }

.action-group {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
}

/* Result Stats */
.result-stats {
    display: flex;
    justify-content: space-around;
    background: rgba(0,0,0,0.3);
    padding: 1.5rem;
    border-radius: 12px;
    margin: 2rem 0;
}

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

.result-box .label {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}

.result-box .val {
    font-size: 2rem;
    font-weight: 800;
    font-family: var(--font-mono);
}

.feedback {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--correct);
    min-height: 1.5rem;
    margin-bottom: 1rem;
}

/* Leaderboard */
.leaderboard h3 {
    margin-bottom: 1rem;
    color: var(--text-dim);
    font-size: 0.9rem;
    text-transform: uppercase;
    text-align: center;
}

.record-list {
    list-style: none;
    text-align: left;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    padding: 0.5rem 1rem;
}

.record-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px dashed rgba(255,255,255,0.1);
    font-family: var(--font-mono);
    font-size: 0.9rem;
}
.record-list li:last-child { border-bottom: none; }
.record-list .empty-state {
    justify-content: center;
    color: var(--text-dim);
    font-style: italic;
    font-family: var(--font-ui);
}

@media (max-width: 600px) {
    .stats-header {
        flex-wrap: wrap;
        gap: 1rem;
        justify-content: center;
    }
    .text-display { font-size: 1.2rem; }
    .action-group { flex-direction: column; }
    .modal { padding: 2rem 1.5rem; }
}
