/* ===== RESET & BASE ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-dark: #1a1a2e;
    --bg-panel: #16213e;
    --accent: #e94560;
    --accent2: #f5a623;
    --text: #eee;
    --text-dim: #888;
    --track-color: #3a3a3a;
    --grass-color: #2d5a1e;
    --gravel-color: #c4a55a;
    --kerb-red: #e22;
    --kerb-white: #fff;
    --player-blue: #2196F3;
    --ai1-red: #f44336;
    --ai2-green: #4CAF50;
    --ai3-orange: #FF9800;
    --ai4-purple: #9C27B0;
    --sidebar-w: 280px;
    --header-h: 50px;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ===== SCREENS ===== */
.screen { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* ===== START SCREEN ===== */
#start-screen {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.start-container { text-align: center; max-width: 500px; width: 90%; }

.title-wrapper { margin-bottom: 40px; }

.game-title {
    font-size: 4rem;
    font-weight: 900;
    letter-spacing: 6px;
    color: #fff;
    text-shadow: 0 0 20px var(--accent), 0 0 60px rgba(233, 69, 96, 0.3);
    line-height: 1;
}

.game-title .gp {
    display: inline-block;
    font-size: 2rem;
    color: var(--accent);
    vertical-align: super;
    margin-left: 4px;
}

.subtitle {
    font-size: 1rem;
    color: var(--text-dim);
    letter-spacing: 4px;
    text-transform: uppercase;
    margin-top: 8px;
}

.config-panel {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 30px;
    backdrop-filter: blur(10px);
}

.config-group { margin-bottom: 20px; text-align: left; }
.config-group label {
    display: block;
    font-size: 0.75rem;
    letter-spacing: 2px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.config-group input {
    width: 100%;
    padding: 10px 14px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    color: #fff;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.config-group input:focus { border-color: var(--accent); }

.select-row { display: flex; gap: 8px; flex-wrap: wrap; }

.sel-btn {
    flex: 1;
    min-width: 60px;
    padding: 10px 8px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.sel-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }
.sel-btn.active {
    background: rgba(233, 69, 96, 0.2);
    border-color: var(--accent);
    color: #fff;
}

.start-race-btn {
    width: 100%;
    padding: 16px;
    margin-top: 10px;
    background: linear-gradient(135deg, var(--accent), #c0392b);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 4px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    text-transform: uppercase;
}

.start-race-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(233, 69, 96, 0.4);
}

.start-race-btn.secondary {
    background: rgba(255,255,255,0.1);
    margin-top: 10px;
    font-size: 1rem;
}

/* ===== COUNTDOWN ===== */
#countdown-overlay {
    background: rgba(0,0,0,0.85);
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.countdown-text {
    font-size: 12rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 40px var(--accent), 0 0 100px rgba(233, 69, 96, 0.5);
}

/* ===== GAME HEADER ===== */
#game-header {
    height: var(--header-h);
    background: var(--bg-panel);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.header-title {
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: 3px;
    color: var(--accent);
}

.header-center {
    display: flex;
    gap: 20px;
    align-items: center;
}

#turn-display {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 2px;
}

#current-player-display {
    font-size: 0.9rem;
    color: var(--accent2);
}

.header-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1rem;
}

/* ===== GAME LAYOUT ===== */
#game-screen { flex-direction: column; }

#game-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - var(--header-h));
}

#canvas-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #1a3a12; /* dark green to match grass, no black */
    cursor: crosshair;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-canvas {
    display: block;
    /* Actual size controlled by JS for responsive scaling */
}

/* ===== SIDEBAR ===== */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-panel);
    border-left: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#players-panel { padding: 12px; flex-shrink: 0; }

.player-card {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    transition: border-color 0.3s;
}

.player-card.active-turn {
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(233, 69, 96, 0.2);
}

.player-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.player-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.player-card-name {
    font-weight: 700;
    font-size: 0.85rem;
    flex: 1;
}

.player-card-status {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.player-card-stats {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-dim);
}

.speed-dots {
    display: inline-flex;
    gap: 2px;
}

.speed-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
}

.speed-dot.filled { background: var(--accent2); }

.stat-label { color: var(--text-dim); }
.stat-val { color: #fff; font-weight: 600; }

/* ===== CONTROLS ===== */
#controls-panel {
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

#controls-panel h3 {
    font-size: 0.7rem;
    letter-spacing: 2px;
    color: var(--text-dim);
    margin-bottom: 10px;
}

#speed-controls { display: flex; gap: 6px; margin-bottom: 10px; }

.ctrl-btn {
    flex: 1;
    padding: 8px 4px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    background: rgba(255,255,255,0.05);
    color: var(--text);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
}

.ctrl-btn:hover:not(:disabled) {
    background: rgba(255,255,255,0.12);
}

.ctrl-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.ctrl-btn.selected {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.2);
}

.brake-btn.selected { border-color: #f44336; background: rgba(244, 67, 54, 0.2); }
.accel-btn.selected { border-color: #4CAF50; background: rgba(76, 175, 80, 0.2); }

.validate-btn {
    width: 100%;
    margin-top: 8px;
    padding: 12px;
    background: linear-gradient(135deg, var(--accent), #c0392b);
    border: none;
    font-size: 0.9rem;
    letter-spacing: 2px;
}

.validate-btn:not(:disabled):hover {
    box-shadow: 0 4px 15px rgba(233, 69, 96, 0.4);
}

.info-text {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-align: center;
    padding: 6px 0;
}

/* ===== GAME LOG ===== */
#game-log {
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex: 1;
    overflow-y: auto;
    min-height: 100px;
}

#game-log h3 {
    font-size: 0.7rem;
    letter-spacing: 2px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

#log-entries {
    font-size: 0.72rem;
    line-height: 1.6;
}

.log-entry {
    padding: 2px 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.log-crash { color: #f44336; font-weight: 600; }
.log-finish { color: #FFD700; font-weight: 600; }

/* ===== END SCREEN ===== */
#end-screen {
    background: rgba(0,0,0,0.9);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 200;
}

.end-container { text-align: center; max-width: 550px; width: 90%; }

.end-title {
    font-size: 3rem;
    font-weight: 900;
    letter-spacing: 4px;
    margin-bottom: 30px;
    color: #FFD700;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
}

#final-standings {
    margin-bottom: 20px;
}

.standing-row {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin-bottom: 6px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    gap: 12px;
}

.standing-pos {
    font-size: 1.5rem;
    font-weight: 900;
    width: 40px;
    color: var(--text-dim);
}

.standing-pos.gold { color: #FFD700; }
.standing-pos.silver { color: #C0C0C0; }
.standing-pos.bronze { color: #CD7F32; }

.standing-name { flex: 1; text-align: left; font-weight: 600; }

.standing-detail {
    font-size: 0.8rem;
    color: var(--text-dim);
}

#final-stats {
    margin: 20px 0;
    font-size: 0.85rem;
    color: var(--text-dim);
}

.end-buttons { display: flex; flex-direction: column; gap: 8px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    :root { --sidebar-w: 240px; }
    .game-title { font-size: 3rem; }
}

@media (max-width: 768px) {
    #game-layout { flex-direction: column; }
    #sidebar {
        width: 100%;
        min-width: 100%;
        flex-direction: row;
        overflow-x: auto;
        max-height: 180px;
    }
    #players-panel { display: flex; gap: 8px; min-width: max-content; }
    .player-card { min-width: 200px; }
}
