/* Reset and layout alignment */
body {
    margin: 0;
    padding: 0;
    background: #111;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #fff;
    user-select: none;
    touch-action: none; /* Prevents mobile double-tap zoom glitches */
}

/* Container locking the aspect ratio and placing overlays */
#gameContainer {
    position: relative;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.9);
    border-radius: 4px;
    overflow: hidden;
    width: 100%;
    max-width: 800px;
    height: auto;
    aspect-ratio: 4 / 3;
}

/* Primary gameplay canvas */
canvas {
    display: block;
    width: 100%;
    height: 100%;
    background-color: #4a6fa5;
}

/* Live dynamic gameplay data overlay */
#hud {
    position: absolute;
    top: 20px;
    left: 20px;
    font-size: 4vw; /* Scales text neatly across viewport sizes */
    font-weight: 800;
    letter-spacing: 1px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.9);
    z-index: 10;
}

@media (min-width: 800px) {
    #hud { font-size: 22px; }
}

/* Input helper panel at the footer */
#controls {
    position: absolute;
    bottom: 20px;
    width: 100%;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: #ddd;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.9);
    z-index: 5;
}

/* Mobile D-Pad layout engine */
#mobileControls {
    display: none; /* Hidden by default on desktops */
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 35%;
    box-sizing: border-box;
    padding: 20px;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 20;
    pointer-events: none; /* Keeps background areas interactive */
}

.controlGroup {
    display: flex;
    gap: 15px;
    pointer-events: auto; /* Re-enables touch mapping on target buttons */
}

/* Universal touch buttons configurations */
.touchBtn {
    width: 70px;
    height: 70px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    color: #fff;
    font-size: 24px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    transition: background 0.1s, transform 0.1s;
}

.touchBtn:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.92);
}

/* Pedals shape overrides */
.gasBtn, .brakeBtn {
    border-radius: 12px;
    width: 85px;
    height: 90px;
    font-size: 14px;
}

.gasBtn { background: rgba(85, 166, 48, 0.3); border-color: #55a630; }
.brakeBtn { background: rgba(230, 57, 70, 0.3); border-color: #e63946; }

/* Responsive break trigger revealing mobile setup on physical touch hardware profiles */
@media (pointer: coarse) {
    #mobileControls { display: flex; }
    #controls { display: none; } /* Hide clutter keyboard guide on mobile screens */
}
