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

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #87CEEB;
    font-family: 'Fredoka One', cursive;
    color: #fff;
}

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* HUD Overlay */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: none;
}

.hud-box {
    background: #ffaa00;
    border: 4px solid #fff;
    border-radius: 15px;
    padding: 10px 20px;
    text-align: center;
    box-shadow: 0 8px 0 #cc8800, 0 15px 20px rgba(0,0,0,0.4);
    text-shadow: 2px 2px 0px rgba(0,0,0,0.3);
}

#top-left {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    gap: 15px;
}

.hud-box .label {
    font-size: 16px;
    color: #fff;
    margin-bottom: 5px;
}

.hud-box .value {
    font-size: 32px;
    color: #fff;
}

#top-center {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
}

.time-box {
    background: #00ccff;
    box-shadow: 0 8px 0 #0099cc, 0 15px 20px rgba(0,0,0,0.4);
}

#bottom-right {
    position: absolute;
    bottom: 30px;
    right: 30px;
}

.score-box {
    background: #ffcc00;
    box-shadow: 0 8px 0 #ccaa00, 0 15px 20px rgba(0,0,0,0.4);
}

#speedometer {
    background: radial-gradient(circle, #ff3366, #990033);
    border: 8px solid #fff;
    border-radius: 50%;
    width: 180px;
    height: 180px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: 0 10px 0 #cc0033, 0 20px 30px rgba(0,0,0,0.6), inset 0 0 20px rgba(0,0,0,0.5);
    text-shadow: 2px 2px 0px rgba(0,0,0,0.4);
    position: relative;
    overflow: hidden;
}

#speed-needle {
    position: absolute;
    bottom: 50%;
    left: 50%;
    width: 4px;
    height: 80px;
    background: #00ffcc;
    transform-origin: bottom center;
    transform: rotate(-135deg);
    z-index: 1;
    border-radius: 4px;
    box-shadow: 0 0 10px #00ffcc;
    transition: transform 0.1s linear;
}

.speed-content {
    position: relative;
    z-index: 2;
    text-align: center;
    background: rgba(0,0,0,0.3);
    border-radius: 50%;
    padding: 20px;
}

#speed-value {
    font-size: 50px;
    line-height: 50px;
    color: #fff;
}

#speed-unit {
    font-size: 20px;
}

.nitro-bar-container {
    position: absolute;
    bottom: -20px;
    width: 120px;
    height: 25px;
    background: #333;
    border: 3px solid #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 0 #000;
}

#nitro-bar {
    width: 100%;
    height: 100%;
    background: #00ffcc;
    transition: width 0.1s;
}

/* Start Screen */
#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #00ccff, #ff3366);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.menu-box {
    background: #fff;
    padding: 40px;
    border-radius: 30px;
    text-align: center;
    border: 8px solid #333;
    box-shadow: 0 20px 0 #ccc, 0 30px 40px rgba(0,0,0,0.5);
    max-width: 500px;
    width: 90%;
}

.menu-box h1 {
    color: #ff3366;
    font-size: 60px;
    text-shadow: 3px 3px 0 #333;
    margin-bottom: 10px;
}

.menu-box h1 span {
    color: #ffaa00;
}

.menu-box p {
    color: #666;
    font-size: 20px;
    margin-bottom: 30px;
}

.car-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f0f0f0;
    padding: 10px 20px;
    border-radius: 20px;
    border: 4px solid #ccc;
    margin-bottom: 30px;
}

.car-selector button {
    background: #ff3366;
    border: none;
    color: white;
    font-size: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-family: 'Fredoka One', cursive;
    box-shadow: 0 4px 0 #cc0033;
}

.car-selector button:active {
    transform: translateY(4px);
    box-shadow: none;
}

#car-display {
    font-size: 24px;
    color: #333;
}

#btn-start {
    padding: 15px 40px;
    font-size: 32px;
    background: #00ccff;
    color: #fff;
    border: 6px solid #333;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Fredoka One', cursive;
    text-shadow: 2px 2px 0 #333;
    box-shadow: 0 10px 0 #0099cc, 0 15px 20px rgba(0,0,0,0.3);
    transition: transform 0.1s;
    width: 100%;
}

#btn-start:active {
    transform: translateY(10px);
    box-shadow: 0 0 0 #0099cc;
}

.instructions {
    margin-top: 30px;
    color: #888;
    font-size: 14px;
    font-family: sans-serif;
}

/* Mobile Controls */
#mobile-controls {
    display: none;
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 50;
}

.action-btn {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 30px;
    text-shadow: 2px 2px 0 #000;
    pointer-events: auto;
    border: 4px solid #fff;
}

#steer-left { bottom: 30px; left: 20px; width: 80px; height: 80px; border-radius: 50%; background: #ffaa00; box-shadow: 0 8px 0 #cc8800; }
#steer-right { bottom: 30px; left: 120px; width: 80px; height: 80px; border-radius: 50%; background: #ffaa00; box-shadow: 0 8px 0 #cc8800; }

.square {
    border-radius: 20px;
    width: 80px; height: 80px;
    font-size: 18px;
}
.red { background: #ff3366; box-shadow: 0 8px 0 #cc0033; }
.green { background: #00ffcc; box-shadow: 0 8px 0 #00cc99; }
.blue { background: #00ccff; box-shadow: 0 8px 0 #0099cc; }

#pedal-brake { bottom: 30px; right: 120px; }
#pedal-gas { bottom: 30px; right: 20px; }
#btn-nitro { bottom: 130px; right: 20px; width: 180px; height: 50px; border-radius: 15px; }

.action-btn:active {
    transform: translateY(8px);
    box-shadow: none !important;
}

@media (max-width: 900px), (max-height: 600px) {
    #mobile-controls { display: block; }
    
    /* Reset transforms */
    #top-left, #top-center, #bottom-right {
        transform: none !important;
    }

    /* Top HUD Elements */
    #top-left { 
        top: 10px; 
        left: 10px; 
        flex-direction: row;
        gap: 5px;
    }
    
    #top-center { 
        top: 10px; 
        right: 10px; 
        left: auto;
    }

    .hud-box {
        padding: 5px 10px;
        border-width: 3px;
        border-radius: 10px;
    }
    .hud-box .label { font-size: 10px; }
    .hud-box .value { font-size: 18px; }

    /* Speedometer */
    #bottom-right { 
        bottom: 180px; 
        right: 10px; 
    }
    #speedometer {
        width: 100px;
        height: 100px;
        border-width: 4px;
    }
    #speed-value { font-size: 26px; line-height: 26px; }
    #speed-unit { font-size: 10px; }
    #speed-needle { height: 45px; width: 3px; }
    .speed-content { padding: 10px; }
    .nitro-bar-container {
        width: 80px;
        height: 15px;
        bottom: -10px;
    }

    /* Start screen */
    .menu-box { padding: 20px; width: 95%; border-width: 4px; }
    .menu-box h1 { font-size: 32px; }
    #btn-start, #btn-restart { font-size: 20px; padding: 10px; }

    /* Mobile Action Buttons */
    .action-btn {
        font-size: 20px;
        border-width: 3px;
    }
    
    /* Left side (Steering) */
    #steer-left { bottom: 20px; left: 10px; width: 60px; height: 60px; }
    #steer-right { bottom: 20px; left: 80px; width: 60px; height: 60px; }
    
    /* Right side (Pedals & Nitro) */
    .square { width: 60px; height: 60px; font-size: 14px; border-radius: 12px; }
    #pedal-brake { bottom: 20px; right: 80px; }
    #pedal-gas { bottom: 20px; right: 10px; }
    
    /* Nitro above pedals */
    #btn-nitro { 
        bottom: 90px; 
        right: 10px; 
        width: 130px; 
        height: 45px; 
        font-size: 18px;
    }
}

/* Crash Screen Styling */
#crash-screen {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(255, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.crash-box {
    border: 8px solid #ff0000;
    background: #222;
    color: #fff;
}
.crash-box h1 {
    color: #ff3333;
    font-size: 70px;
    text-shadow: 3px 3px 0 #880000;
}
#btn-restart {
    padding: 15px 40px;
    font-size: 32px;
    background: #ff3333;
    color: #fff;
    border: 6px solid #aa0000;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Fredoka One', cursive;
    text-shadow: 2px 2px 0 #333;
    width: 100%;
    margin-top: 10px;
    box-shadow: 0 10px 0 #880000, 0 15px 20px rgba(0,0,0,0.3);
}
#btn-restart:active {
    transform: translateY(10px);
    box-shadow: none;
}

/* Victory Screen Styling */
#victory-screen {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 255, 100, 0.4);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.victory-box {
    border: 8px solid #00ffcc;
    background: #fff;
    box-shadow: 0 20px 0 #00aa99, 0 30px 40px rgba(0,0,0,0.5), 0 0 50px rgba(0,255,200,0.5);
}

.victory-box h1 {
    color: #ff3366;
    text-shadow: 3px 3px 0 #333;
    font-size: 50px;
}

.stats-container {
    background: #f0f0f0;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    font-size: 24px;
    color: #333;
    border: 4px solid #ccc;
}

#btn-next-level {
    padding: 15px 40px;
    font-size: 32px;
    background: #ffcc00;
    color: #fff;
    border: 6px solid #ccaa00;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Fredoka One', cursive;
    text-shadow: 2px 2px 0 #333;
    width: 100%;
    box-shadow: 0 10px 0 #aa8800, 0 15px 20px rgba(0,0,0,0.3);
}

#btn-next-level:active {
    transform: translateY(10px);
    box-shadow: none;
}
