* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --neon-cyan: #00d4ff;
    --neon-magenta: #ff2d55;
    --neon-green: #39ff14;
    --neon-orange: #ff9500;
    --neon-yellow: #ffd60a;
    --dark-bg: #0a0a1a;
    --darker-bg: #050510;
}

body {
    overflow: hidden;
    background: var(--dark-bg);
    font-family: 'Orbitron', monospace;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

#scene-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

#scene-container canvas {
    display: block;
}

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    pointer-events: auto;
}

.hidden {
    display: none !important;
}

/* Title Screen */
.title-container {
    text-align: center;
    margin-bottom: 20px;
}

.game-title {
    font-family: 'Orbitron', monospace;
    font-size: clamp(2.5rem, 8vw, 5rem);
    font-weight: 900;
    letter-spacing: 4px;
    background: linear-gradient(180deg, #fff 0%, #aaa 30%, #fff 50%, #888 70%, #ccc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 20px rgba(0, 212, 255, 0.5)) drop-shadow(0 0 40px rgba(0, 212, 255, 0.3));
    animation: titlePulse 3s ease-in-out infinite;
}

@keyframes titlePulse {
    0%, 100% { filter: drop-shadow(0 0 20px rgba(0, 212, 255, 0.5)) drop-shadow(0 0 40px rgba(0, 212, 255, 0.3)); }
    50% { filter: drop-shadow(0 0 30px rgba(0, 212, 255, 0.8)) drop-shadow(0 0 60px rgba(255, 45, 85, 0.4)); }
}

.game-subtitle {
    font-family: 'Rajdhani', sans-serif;
    font-size: clamp(1rem, 3vw, 1.5rem);
    color: var(--neon-cyan);
    text-shadow: 0 0 10px var(--neon-cyan);
    margin-top: 8px;
    font-weight: 300;
    letter-spacing: 6px;
}

/* Car Color Picker */
.car-color-picker {
    margin: 16px 0;
    text-align: center;
}

.picker-label {
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.85rem;
    color: #666;
    letter-spacing: 4px;
    margin-bottom: 12px;
}

.color-options {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.color-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid #333;
    background: var(--btn-color);
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
}

.color-btn:hover {
    transform: scale(1.15);
}

.color-btn.selected {
    border-color: var(--neon-cyan);
    box-shadow: 0 0 15px var(--neon-cyan);
    transform: scale(1.2);
}

/* High Score */
.high-score-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 16px 0;
}

.hs-label {
    font-size: 0.7rem;
    letter-spacing: 4px;
    color: #555;
}

.hs-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--neon-yellow);
    text-shadow: 0 0 10px var(--neon-yellow);
}

/* Buttons */
.btn-start {
    font-family: 'Orbitron', monospace;
    font-size: clamp(1rem, 3vw, 1.3rem);
    font-weight: 700;
    padding: 16px 48px;
    border: 2px solid var(--neon-green);
    background: transparent;
    color: var(--neon-green);
    cursor: pointer;
    letter-spacing: 3px;
    transition: all 0.3s;
    animation: btnPulse 2s ease-in-out infinite;
    margin: 8px 0;
}

@keyframes btnPulse {
    0%, 100% { box-shadow: 0 0 10px rgba(57, 255, 20, 0.3), inset 0 0 10px rgba(57, 255, 20, 0.1); }
    50% { box-shadow: 0 0 25px rgba(57, 255, 20, 0.6), inset 0 0 20px rgba(57, 255, 20, 0.2); }
}

.btn-start:hover {
    background: rgba(57, 255, 20, 0.15);
    transform: scale(1.05);
}

.btn-controls {
    font-family: 'Orbitron', monospace;
    font-size: 0.7rem;
    padding: 8px 24px;
    border: 1px solid #444;
    background: transparent;
    color: #666;
    cursor: pointer;
    letter-spacing: 2px;
    transition: all 0.3s;
    margin-top: 4px;
}

.btn-controls:hover {
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
}

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

.modal-content {
    background: #111;
    border: 1px solid #333;
    padding: 32px;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.modal-content h2 {
    font-size: 1.5rem;
    color: var(--neon-cyan);
    margin-bottom: 24px;
    letter-spacing: 4px;
}

.controls-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.control-item {
    font-family: 'Rajdhani', sans-serif;
    font-size: 1.1rem;
    color: #ccc;
}

.key {
    display: inline-block;
    background: #222;
    border: 1px solid #444;
    padding: 4px 10px;
    border-radius: 4px;
    font-family: 'Orbitron', monospace;
    font-size: 0.8rem;
    color: var(--neon-green);
    margin: 0 4px;
}

.desc {
    color: #888;
    margin-left: 8px;
}

.mobile-controls-info {
    margin: 16px 0;
    padding: 12px;
    border: 1px solid #222;
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.9rem;
    color: #777;
}

.btn-close {
    font-family: 'Orbitron', monospace;
    font-size: 0.9rem;
    padding: 10px 32px;
    border: 1px solid var(--neon-cyan);
    background: transparent;
    color: var(--neon-cyan);
    cursor: pointer;
    letter-spacing: 2px;
}

/* HUD */
#hud {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
}

.hud-top-left {
    position: absolute;
    top: 16px;
    left: 16px;
}

.lives-display {
    display: flex;
    gap: 6px;
}

.life {
    font-size: 1.5rem;
    transition: all 0.3s;
    filter: drop-shadow(0 0 4px rgba(255,255,255,0.3));
}

.life.lost {
    opacity: 0.2;
    filter: grayscale(1);
}

.life.hit {
    animation: lifeHit 0.5s ease;
}

@keyframes lifeHit {
    0% { transform: scale(1); filter: drop-shadow(0 0 4px red); }
    50% { transform: scale(1.4); filter: drop-shadow(0 0 12px red) brightness(2); }
    100% { transform: scale(1); opacity: 0.2; filter: grayscale(1); }
}

.hud-top-right {
    position: absolute;
    top: 16px;
    right: 16px;
    text-align: right;
}

.score-display {
    display: flex;
    flex-direction: column;
}

.score-label {
    font-size: 0.6rem;
    color: #555;
    letter-spacing: 3px;
}

.score-value {
    font-size: clamp(1.5rem, 4vw, 2.2rem);
    font-weight: 700;
    color: #fff;
    text-shadow: 0 0 8px rgba(255,255,255,0.3);
}

.timer-display {
    margin-top: 4px;
}

.timer-value {
    font-family: 'Rajdhani', sans-serif;
    font-size: 1rem;
    color: #666;
}

.hud-bottom-center {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
}

.nitro-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nitro-label {
    font-size: 0.65rem;
    color: var(--neon-cyan);
    letter-spacing: 2px;
}

.nitro-bar-bg {
    width: clamp(120px, 30vw, 200px);
    height: 8px;
    background: #222;
    border: 1px solid #333;
    border-radius: 4px;
    overflow: hidden;
}

.nitro-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--neon-cyan), var(--neon-magenta));
    border-radius: 4px;
    transition: width 0.2s;
    box-shadow: 0 0 8px var(--neon-cyan);
}

.nitro-ready {
    font-size: 0.65rem;
    color: var(--neon-green);
    animation: readyBlink 0.5s ease-in-out infinite;
}

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

.hud-bottom-right {
    position: absolute;
    bottom: 16px;
    right: 16px;
}

.speedometer {
    position: relative;
}

.speed-text {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
}

.speed-number {
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 900;
    display: block;
    line-height: 1;
}

.speed-unit {
    font-size: 0.5rem;
    color: #666;
    letter-spacing: 2px;
}

.near-miss-popup {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--neon-yellow);
    text-shadow: 0 0 15px var(--neon-yellow);
    animation: nearMissAnim 1s ease-out forwards;
    pointer-events: none;
}

@keyframes nearMissAnim {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(0.5); }
    30% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

/* Mobile Touch Controls */
#mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    z-index: 40;
    pointer-events: auto;
    display: flex;
}

.touch-left, .touch-right {
    flex: 1;
    opacity: 0;
}

/* Game Over */
#game-over-screen {
    background: rgba(5, 5, 16, 0.92);
}

.wrecked-title {
    font-size: clamp(3rem, 10vw, 6rem);
    font-weight: 900;
    color: var(--neon-magenta);
    text-shadow: 0 0 30px var(--neon-magenta), 0 0 60px rgba(255,45,85,0.5);
    animation: wreckedShake 0.5s ease-out;
    margin-bottom: 24px;
}

@keyframes wreckedShake {
    0% { transform: scale(3) rotate(-5deg); opacity: 0; }
    40% { transform: scale(1.1) rotate(2deg); opacity: 1; }
    60% { transform: scale(0.95) rotate(-1deg); }
    100% { transform: scale(1) rotate(0); }
}

.final-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
    min-width: 250px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    border-bottom: 1px solid #222;
}

.stat-label {
    font-size: 0.7rem;
    color: #555;
    letter-spacing: 2px;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--neon-cyan);
}

.new-high-score {
    font-size: 1.2rem;
    color: var(--neon-yellow);
    text-shadow: 0 0 15px var(--neon-yellow);
    margin-bottom: 16px;
    animation: hsGlow 1s ease-in-out infinite;
}

@keyframes hsGlow {
    0%, 100% { text-shadow: 0 0 15px var(--neon-yellow); }
    50% { text-shadow: 0 0 30px var(--neon-yellow), 0 0 50px var(--neon-orange); }
}

.btn-share {
    font-family: 'Orbitron', monospace;
    font-size: 0.75rem;
    padding: 10px 24px;
    border: 1px solid #444;
    background: transparent;
    color: #888;
    cursor: pointer;
    letter-spacing: 2px;
    margin-top: 4px;
    transition: all 0.3s;
}

.btn-share:hover {
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
}

/* Collision Flash */
#collision-flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 0, 0, 0.3);
    z-index: 60;
    pointer-events: none;
    animation: flashAnim 0.3s ease-out forwards;
}

@keyframes flashAnim {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

.remix-link {
    position: absolute;
    bottom: 12px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.75rem;
    color: #333;
    text-decoration: none;
    letter-spacing: 1px;
}

.remix-link:hover {
    color: #666;
}

/* Rainbow mode */
.rainbow-active .game-title {
    background: linear-gradient(90deg, #ff0000, #ff9900, #ffff00, #00ff00, #0099ff, #6633ff, #ff0000);
    background-size: 400% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    animation: rainbowText 2s linear infinite;
}

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

/* Nitro active screen effect */
.nitro-screen-effect {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 45;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 212, 255, 0.08) 100%);
    animation: nitroVignette 0.3s ease-in-out infinite alternate;
}

@keyframes nitroVignette {
    0% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Responsive */
@media (max-width: 600px) {
    .hud-bottom-right {
        display: none;
    }
    
    .btn-start {
        padding: 14px 36px;
    }
    
    .final-stats {
        min-width: 200px;
    }
}