/* ==========================================================================
   Design System & Variable Declarations
   ========================================================================== */
:root {
    --bg-desktop: radial-gradient(circle at center, #1e1e2f 0%, #0d0d15 100%);
    --titanium-bezel: linear-gradient(135deg, #8e8e93 0%, #48484a 50%, #8e8e93 100%);
    --screen-bezel-color: #0b0b0d;
    --ios-active-color: #30d158;
    --hud-bg: rgba(18, 18, 24, 0.6);
    --hud-border: rgba(255, 255, 255, 0.12);
    --neon-yellow: #ffe600;
    --neon-orange: #ff5e00;
    --brake-color: #ff3b30;
    --joystick-base: rgba(255, 255, 255, 0.15);
    --joystick-knob: radial-gradient(circle, #ffffff 0%, #a1a1a1 100%);
    
    /* Layout Sizes */
    --sim-width: 920px;
    --sim-height: 440px;
    --screen-radius: 42px;
}

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

body {
    background: #08080f;
    font-family: 'Outfit', sans-serif;
    overflow: hidden;
    color: #ffffff;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ==========================================================================
   WebGL Canvas
   ========================================================================== */
#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    display: block;
    touch-action: none;
}


/* ==========================================================================
   Heads Up Display Overlay (HUD)
   ========================================================================== */
.game-hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 40;
    pointer-events: none; /* Let clicks fall through to touch zones */
}

/* Speedometer */
.hud-widget {
    position: absolute;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 18px;
    padding: 10px 18px;
    color: #ffffff;
    pointer-events: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 60;
}
.speedometer {
    bottom: 20px;
    left: max(20px, env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100px;
}
.speed-value {
    font-family: 'Outfit', sans-serif;
    font-size: 28px;
    font-weight: 800;
    line-height: 1;
    color: var(--neon-yellow);
    text-shadow: 0 0 10px rgba(255, 230, 0, 0.3);
}
.speed-unit {
    font-size: 9px;
    font-weight: 600;
    color: rgba(255,255,255,0.6);
    letter-spacing: 1px;
    margin-top: 2px;
}
.gear-indicator {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--neon-orange);
    color: #000;
    font-weight: 800;
    font-size: 11px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

/* Mini-Map GPS */
.minimap-container {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
    left: auto;
    transform: none;
    width: 90px;
    height: 90px;
    background: rgba(0, 0, 0, 0.45);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5), inset 0 2px 5px rgba(0,0,0,0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow: hidden;
    z-index: 60;
    pointer-events: none;
}
#minimapCanvas {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: block;
}
.minimap-container::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 50%;
    box-shadow: inset 0 0 10px rgba(0,255,255,0.2);
    pointer-events: none;
}

/* Coin Counter */
.coin-counter {
    top: max(20px, env(safe-area-inset-top));
    left: max(20px, env(safe-area-inset-left));
    font-weight: 800;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #ffd700; /* Gold */
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
    border-color: rgba(255, 215, 0, 0.2);
}
.coin-counter i {
    animation: spin-slow 8s infinite linear;
}

@keyframes spin-slow {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(360deg); }
}

/* Upgrade Widget */
.upgrade-widget {
    top: max(68px, calc(env(safe-area-inset-top) + 48px));
    left: max(20px, env(safe-area-inset-left));
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-color: rgba(255, 255, 255, 0.15);
}
.car-level-badge {
    font-weight: 800;
    font-size: 9px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 3px 6px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    letter-spacing: 0.5px;
}
.upgrade-btn {
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 10px;
    padding: 5px 12px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, #00f0ff 0%, #0072ff 100%);
    color: #fff;
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.upgrade-btn.disabled {
    background: #444;
    color: #888;
    cursor: not-allowed;
    box-shadow: none;
}
.upgrade-btn:not(.disabled):hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.6);
}
.upgrade-btn:not(.disabled):active {
    transform: scale(0.95);
}
/* Pulse animation for upgrade when affordable */
.upgrade-btn.active-pulse {
    animation: button-pulse 1.5s infinite ease-in-out;
}
@keyframes button-pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(0, 240, 255, 0.4); }
    50% { box-shadow: 0 0 20px rgba(0, 240, 255, 0.8); }
}

/* Quick Tools Menu */
.quick-utils {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    right: max(130px, calc(env(safe-area-inset-right) + 110px));
    display: flex;
    gap: 8px;
    pointer-events: auto;
    z-index: 65;
}
.util-btn {
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #fff;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 11px;
    padding: 6px 12px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}
.util-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}
.util-btn:active {
    transform: scale(0.95);
}

/* ==========================================================================
   Touch Control Zones (Split Screen)
   ========================================================================== */
.camera-zone {
    position: absolute;
    top: 28px; /* Below status bar */
    left: 0;
    width: 100%;
    height: 35%;
    z-index: 35;
    touch-action: none;
}

.touch-zones {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 65%;
    display: flex;
    z-index: 30;
    touch-action: none;
}
.zone {
    width: 50%;
    height: 100%;
    position: relative;
    pointer-events: auto; /* Active for touch events */
    touch-action: none;
}
.left-zone {
    /* Brake Zone */
}
.right-zone {
    /* Joystick Zone */
    position: absolute;
    right: 0;
    width: 50%;
}

/* Brake HUD feedback (Left half) */
.brake-indicator {
    position: absolute;
    bottom: 25px;
    left: 205px; /* Positioned nicely near brake zone */
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 59, 48, 0.15);
    border: 1.5px dashed rgba(255, 59, 48, 0.4);
    padding: 8px 16px;
    border-radius: 20px;
    color: var(--brake-color);
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.5px;
    opacity: 0.6;
    transition: all 0.15s ease;
}
.left-zone:active .brake-indicator,
.brake-active .brake-indicator {
    opacity: 1;
    background: rgba(255, 59, 48, 0.45);
    border-color: var(--brake-color);
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(255, 59, 48, 0.3);
}

/* Virtual Joystick graphical elements (Right half) */
.joystick-ring {
    position: absolute;
    width: 90px;
    height: 90px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    background: var(--joystick-base);
    border-radius: 50%;
    display: none; /* Managed dynamically via JS */
    justify-content: center;
    align-items: center;
    pointer-events: none;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 18px rgba(255, 255, 255, 0.1);
    z-index: 90;
    transition: border-color 0.15s, background-color 0.15s;
}
.joystick-dot {
    width: 36px;
    height: 36px;
    background: var(--joystick-knob);
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4), inset 0 2px 2px rgba(255,255,255,0.6);
}

/* ==========================================================================
   Start Screen & Lock Screen Overlay
   ========================================================================== */
.start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 16, 0.85);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 80;
    padding: 30px 60px;
    transition: opacity 0.5s ease, visibility 0.5s;
    pointer-events: auto;
}
.start-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.start-title {
    text-align: center;
    margin-bottom: 20px;
}
.start-title h1 {
    font-family: 'Fredoka', sans-serif;
    font-size: 46px;
    font-weight: 700;
    letter-spacing: -1px;
    background: linear-gradient(135deg, var(--neon-yellow) 0%, var(--neon-orange) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 10px 20px rgba(255, 94, 0, 0.15);
    line-height: 1.1;
}
.start-subtitle {
    font-size: 13px;
    letter-spacing: 3px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    font-weight: 600;
    margin-top: 4px;
}
.instructions-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 25px;
    width: 100%;
    max-width: 420px;
}
.instruction-row {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 8px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.action-side {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.5px;
    padding: 3px 8px;
    border-radius: 6px;
}
.left-side {
    background: rgba(255, 59, 48, 0.2);
    color: var(--brake-color);
}
.right-side {
    background: rgba(48, 209, 88, 0.2);
    color: var(--ios-active-color);
}
.action-desc {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 6px;
}
.start-btn {
    font-family: 'Fredoka', sans-serif;
    background: linear-gradient(135deg, #ff9f0a 0%, var(--neon-orange) 100%);
    border: none;
    color: #fff;
    padding: 12px 36px;
    font-size: 15px;
    font-weight: 600;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(255, 94, 0, 0.4), inset 0 2px 2px rgba(255,255,255,0.4);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px rgba(255, 94, 0, 0.5);
}
.start-btn:active {
    transform: translateY(1px);
}

