:root {
    /* ... (all your existing variables are fine) ... */
    --bg-primary: #0a0a0b;
    --bg-secondary: #111115;
    --glass-bg: rgba(26, 26, 32, 0.7);
    --glass-border: rgba(255, 255, 255, 0.12);
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent-orange: #f59e0b;
    --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --gradient-danger: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
    --gradient-primary: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 100%);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
.background-overlay, .floating-shapes { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; }
.background-overlay { background: radial-gradient(circle at 25% 25%, rgba(139, 92, 246, 0.1) 0%, transparent 50%), radial-gradient(circle at 75% 75%, rgba(6, 182, 212, 0.1) 0%, transparent 50%); }
.shape { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.3; }
.shape-1 { width: 300px; height: 300px; background: var(--accent-purple); top: 10%; left: 10%; }
.shape-2 { width: 400px; height: 400px; background: var(--accent-cyan); top: 50%; right: 5%; }
.app-container { width: 100%; max-width: 800px; display: flex; flex-direction: column; gap: 1.5rem; }
.glass-card { background: var(--glass-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid var(--glass-border); border-radius: var(--radius-xl); padding: 2rem; }
body.game-active { padding: 0; }
body.game-active .app-container { max-width: 100%; height: 100%; gap: 0; }
body.game-active header, body.game-active #start-screen { display: none; }
body.game-active #game-screen { flex-grow: 1; height: 100%; padding: 1rem; border-radius: 0; border: none; background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; position: relative; }
body.game-active #game-area { height: 100%; flex-grow: 1; }
header .header-content { display: flex; align-items: center; gap: 1rem; }
header .logo-icon { font-size: 2rem; }
header h1 { font-size: 1.75rem; }
#start-screen .card-content { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 1rem; }
#start-screen h2 { font-size: 2rem; }
#start-screen p { color: var(--text-secondary); }
#start-screen .start-input-group { width: 100%; max-width: 300px; }
#name-input, #name-input-p2 { width: 100%; padding: 0.75rem 1rem; background: var(--bg-secondary); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: var(--text-primary); font-size: 1rem; text-align: center; }
#name-input:focus, #name-input-p2:focus { outline: none; border-color: var(--accent-purple); box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.3); }
.high-score-text { font-size: 0.9rem; color: var(--text-muted); margin-top: 1rem; }
.player-toggle { display: flex; align-items: center; gap: 1rem; margin: 0.5rem 0; }
.toggle-label { font-size: 0.9rem; color: var(--text-muted); cursor: pointer; transition: color 0.3s ease; }
.toggle-label.active { color: var(--text-primary); font-weight: 600; }
.toggle-switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--bg-secondary); border: 1px solid var(--glass-border); transition: .4s; border-radius: 28px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-image: var(--gradient-primary); }
input:checked + .slider:before { transform: translateX(22px); }
#player2-input-container { display: none; }
#game-screen { display: flex; flex-direction: column; gap: 1rem; }
#game-area { position: relative; width: 100%; border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--glass-border); }
canvas { display: block; width: 100%; height: 100%; }
#hud { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.glass-element { background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: var(--radius-md); padding: 1rem; display: flex; align-items: center; justify-content: center; gap: 1.5rem; }
#stats-display { font-family: 'JetBrains Mono', monospace; font-size: 1rem; flex-wrap: wrap; justify-content: space-around; text-align: center; }
#stats-display span { color: var(--text-secondary); margin-right: 0.5em; }
.player-stats { flex: 1; min-width: 150px; }
.player-stats .player-name { font-weight: bold; display: block; margin-bottom: 0.5rem; font-size: 1.1rem; }
.player-stats .stats-line { font-size: 0.9rem; display: flex; justify-content: space-around; flex-wrap: wrap; gap: 0.5rem; }
.player-stats .stats-line span { font-size: 0.8rem; margin-right: 0.2em;}
.hud-separator { border-left: 1px solid var(--glass-border); opacity: 0.5; align-self: stretch; }
.instruction-text { text-align: center; font-size: 0.875rem; color: var(--text-muted); padding: 0.1rem 0; line-height: 1.5; }
.instruction-text strong { color: var(--text-primary); background-color: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: var(--radius-sm); border: 1px solid var(--glass-border); }
#out-of-fuel-message { position: absolute; top: 35%; left: 50%; transform: translateX(-50%); font-family: 'JetBrains Mono', monospace; font-size: 2.5rem; font-weight: 700; color: var(--accent-orange); text-shadow: 0 0 15px rgba(0, 0, 0, 0.7); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 0.5s ease; z-index: 10; }
#out-of-fuel-message.visible { opacity: 1; visibility: visible; }

.out-of-fuel-multi {
    position: absolute;
    top: 50px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(0,0,0,0.9);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 10;
}
.out-of-fuel-multi.visible { opacity: 1; visibility: visible; }
#out-of-fuel-p1 { left: 20px; color: #ef4444; }
#out-of-fuel-p2 { right: 20px; color: #3b82f6; }


#message-area { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(10, 10, 11, 0.2); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 0.4s ease, visibility 0.4s ease; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 2rem; margin-top: 0; }
#message-area.visible { opacity: 1; visibility: visible; pointer-events: auto; }
#message-title { font-size: 2.25rem; font-weight: 700; }
#message-area.success #message-title { background: var(--gradient-success); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
#message-area.crash #message-title { background: var(--gradient-danger); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
#message-text { color: var(--text-secondary); margin: 1rem 0 1.5rem 0; max-width: 500px; line-height: 1.6; }

#message-stats {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    padding: 1rem 1.5rem;
    font-family: 'JetBrains Mono', monospace;
    margin-bottom: 1.5rem;
    display: none; /* Hidden by default */
    text-align: left;
}
#message-stats.visible { display: block; }
#message-stats div { margin-bottom: 0.5rem; }
#message-stats div:last-child { margin-bottom: 0; }
#message-stats strong { color: var(--text-primary); }
#message-stats span { color: var(--text-secondary); }


.modern-button { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.75rem 1.5rem; border: none; border-radius: var(--radius-md); font-weight: 600; cursor: pointer; transition: all 0.3s ease; }
.modern-button.primary { background: var(--gradient-primary); color: white; }
.modern-button:hover { transform: translateY(-2px); box-shadow: 0 8px 15px rgba(0,0,0,0.2); }

#message-stats .message-stats-label {
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
}

/* --- Touch Controls --- */
#touch-controls-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 25%;
    display: none;
    pointer-events: none;
    z-index: 20;
    padding: 1rem;
    gap: 1rem;
}

#touch-controls-single,
#touch-controls-multi {
    width: 100%;
    height: 100%;
    display: none; 
    justify-content: space-between;
    align-items: center;
}

.touch-group-left, .touch-group-right {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    height: 100%;
}

#touch-controls-single .touch-group-left { width: 50%; }
#touch-controls-single .touch-group-right { width: 50%; }

#touch-controls-multi .touch-group-left,
#touch-controls-multi .touch-group-right {
    width: 45%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.touch-button {
    background: rgba(26, 26, 32, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: all 0.2s ease-in-out;
    width: 15vw;
    height: 15vw;
    max-width: 70px;
    max-height: 70px;
}

.touch-button:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

.touch-button span {
    font-size: 8vw;
    color: white;
    text-shadow: 0 0 5px rgba(0,0,0,0.5);
}

#touch-sp-thrust {
    width: 25vw;
    height: 25vw;
    max-width: 120px;
    max-height: 120px;
}
#touch-sp-thrust span {
    font-size: 12vw;
}

.touch-button.p1 { border-color: rgba(239, 68, 68, 0.5); }
.touch-button.p1:active { background: rgba(239, 68, 68, 0.3); }
.touch-button.p2 { border-color: rgba(59, 130, 246, 0.5); }
.touch-button.p2:active { background: rgba(59, 130, 246, 0.3); }

/* --- Media Queries --- */

/* CHANGE 3: Add Media Query for very small/slim phones */
@media (max-width: 400px) {
    #touch-controls-container {
        padding: 0.5rem;
        gap: 0.5rem;
    }
    .touch-button {
        width: 18vw;   /* Slightly larger % of a smaller screen */
        height: 18vw;
        max-width: 60px; /* But smaller max size */
        max-height: 60px;
    }
    .touch-button span {
        font-size: 9vw;
    }
    #touch-sp-thrust {
        width: 30vw;
        height: 30vw;
        max-width: 95px;
        max-height: 95px;
    }
    #touch-sp-thrust span {
        font-size: 15vw;
    }
}

/* Media Query for Tablets */
@media (min-width: 768px) {
    #touch-controls-container {
        height: 20%;
        padding: 1.5rem;
    }
    .touch-button {
        width: 80px;
        height: 80px;
    }
    .touch-button span {
        font-size: 40px;
    }
    #touch-sp-thrust {
        width: 130px;
        height: 130px;
    }
    #touch-sp-thrust span {
        font-size: 60px;
    }
    #touch-controls-multi .touch-group-left,
    #touch-controls-multi .touch-group-right {
        gap: 1rem;
    }
}