:root {
    --neon-cyan: #00f3ff;
    --neon-gold: #ffd60a;
    --neon-pink: #ff5e78;
    --warm-red: #e63946;
    --bg-deep: #0f0a1f;
    --glass-bg: rgba(15, 10, 31, 0.55);
    --glass-border: rgba(255, 255, 255, 0.15);
    /* HUD scales relative to viewport but caps at sensible sizes */
    --hud-scale: clamp(0.7, 1vw, 1.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Nunito', 'Segoe UI', sans-serif;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: linear-gradient(135deg, #1a0a2e 0%, #16213e 50%, #0f3460 100%);
    color: #fff;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

#game-container {
    position: relative;
    width: min(100vw, calc(100vh * 16 / 9));
    height: min(100vh, calc(100vw * 9 / 16));
    max-width: 100vw;
    max-height: 100vh;
    aspect-ratio: 16 / 9;
    box-shadow: 0 0 80px rgba(0, 243, 255, 0.2), 0 20px 60px rgba(0,0,0,0.5);
    background: #87ceeb;
    overflow: hidden;
    border-radius: 8px;
}

#game-container:fullscreen,
#game-container:-webkit-full-screen {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    border-radius: 0;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* === HUD — responsive, always visible === */
#hud {
    position: absolute;
    top: clamp(8px, 1.5%, 20px);
    left: clamp(8px, 1.5%, 20px);
    right: clamp(8px, 1.5%, 20px);
    display: flex;
    justify-content: space-between;
    gap: clamp(6px, 1%, 14px);
    pointer-events: none;
    z-index: 10;
    flex-wrap: wrap;
    align-items: flex-start;
}

.hud-item {
    background: var(--glass-bg);
    backdrop-filter: blur(14px) saturate(150%);
    -webkit-backdrop-filter: blur(14px) saturate(150%);
    border: 1.5px solid var(--glass-border);
    padding: clamp(4px, 0.8vw, 10px) clamp(10px, 1.4vw, 20px);
    border-radius: clamp(8px, 1.2vw, 16px);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255,255,255,0.1);
    min-width: clamp(60px, 8vw, 100px);
}

.hud-label {
    font-size: clamp(8px, 0.85vw, 11px);
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 2px;
    font-weight: 700;
    text-transform: uppercase;
}

.hud-value {
    font-size: clamp(16px, 2vw, 28px);
    font-weight: 900;
    color: var(--neon-cyan);
    text-shadow: 0 0 12px rgba(0, 243, 255, 0.7), 0 2px 4px rgba(0,0,0,0.5);
    letter-spacing: 1px;
    font-family: 'Courier New', monospace;
    line-height: 1;
    margin-top: 2px;
}

#nitro-charges {
    display: flex;
    gap: clamp(2px, 0.4vw, 6px);
    margin-top: 4px;
}

.nitro-charge {
    width: clamp(8px, 1vw, 14px);
    height: clamp(14px, 1.8vw, 24px);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transform: skewX(-15deg);
    transition: all 0.2s;
    border-radius: 2px;
}

.nitro-charge.active {
    background: linear-gradient(180deg, #ffd60a, #ff8800);
    border-color: #fff;
    box-shadow: 0 0 10px var(--neon-gold), inset 0 0 4px rgba(255,255,255,0.5);
}

.hud-buttons {
    display: flex;
    gap: clamp(4px, 0.5vw, 8px);
    pointer-events: auto;
}

.hud-btn {
    background: var(--glass-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1.5px solid var(--glass-border);
    color: #fff;
    width: clamp(36px, 4vw, 52px);
    height: clamp(36px, 4vw, 52px);
    border-radius: clamp(8px, 1.2vw, 16px);
    font-size: clamp(16px, 2vw, 24px);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

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

/* === Modals === */
.modal-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(15,10,31,0.85) 0%, rgba(5,7,15,0.95) 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
    background: linear-gradient(145deg, rgba(30, 20, 60, 0.95), rgba(15, 10, 40, 0.95));
    border: 2px solid rgba(255, 214, 10, 0.3);
    padding: clamp(20px, 3vw, 36px) clamp(24px, 4vw, 44px);
    border-radius: 24px;
    max-width: 520px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 60px rgba(255, 214, 10, 0.2), inset 0 1px 0 rgba(255,255,255,0.1);
    max-height: 92vh;
    overflow-y: auto;
}

.modal-content.welcome {
    border-color: rgba(0, 243, 255, 0.4);
    box-shadow: 0 0 80px rgba(0, 243, 255, 0.25);
}

.modal-content h1 {
    font-size: clamp(28px, 4vw, 42px);
    font-weight: 900;
    letter-spacing: 1px;
    line-height: 1.1;
    margin-bottom: 8px;
    background: linear-gradient(90deg, #ffd60a, #ff5e78, #00f3ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 30px rgba(255, 214, 10, 0.4);
}

.modal-content h2 { font-size: clamp(22px, 2.5vw, 28px); margin-bottom: 12px; }
.modal-content h3 {
    font-size: clamp(13px, 1.4vw, 16px);
    margin: 18px 0 8px;
    letter-spacing: 2px;
    color: var(--neon-gold);
    text-shadow: 0 0 12px rgba(255, 214, 10, 0.5);
}

.modal-content p {
    color: rgba(255, 255, 255, 0.75);
    font-size: clamp(13px, 1.3vw, 16px);
    margin-bottom: 16px;
}

.subtitle { font-size: clamp(13px, 1.4vw, 16px) !important; color: rgba(255,255,255,0.8) !important; }

.title-block { margin-bottom: 20px; }

.name-input-wrap { margin-bottom: 16px; }

#player-name-input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: clamp(15px, 1.5vw, 18px);
    text-align: center;
    letter-spacing: 1px;
    border-radius: 12px;
    outline: none;
    font-weight: 700;
    transition: all 0.2s;
}

#player-name-input:focus {
    border-color: var(--neon-cyan);
    background: rgba(0, 0, 0, 0.6);
    box-shadow: 0 0 16px rgba(0, 243, 255, 0.3);
}

#player-name-input::placeholder { color: rgba(255,255,255,0.4); font-weight: 500; }

.big-btn {
    width: 100%;
    padding: clamp(12px, 1.6vw, 18px);
    border: none;
    color: white;
    font-size: clamp(16px, 1.8vw, 22px);
    font-weight: 900;
    letter-spacing: 2px;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 12px;
    text-transform: uppercase;
    font-family: inherit;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.big-btn.primary {
    background: linear-gradient(90deg, #ff5e78, #ffd60a, #ff8800);
    background-size: 200% 100%;
    animation: shimmer 3s linear infinite;
}

@keyframes shimmer {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

.big-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 32px rgba(255, 94, 120, 0.4);
}

.big-btn:active { transform: translateY(-1px) scale(1.0); }

.text-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.5);
    font-size: clamp(11px, 1.1vw, 13px);
    cursor: pointer;
    padding: 8px;
    text-decoration: underline;
    font-family: inherit;
    transition: color 0.2s;
}

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

.controls-hint { font-size: clamp(11px, 1.2vw, 14px); color: rgba(255,255,255,0.7); margin-bottom: 12px; }

kbd {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    padding: 3px 8px;
    font-family: monospace;
    font-size: clamp(10px, 1vw, 12px);
    margin: 0 2px;
}

/* === Leaderboard === */
.mini-board, #leaderboard-table {
    margin: 12px 0;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    padding: 10px 12px;
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid rgba(255,255,255,0.1);
}

.leaderboard-row {
    display: grid;
    grid-template-columns: 30px 1fr auto;
    gap: 12px;
    padding: 6px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: clamp(12px, 1.3vw, 14px);
    align-items: center;
}

.leaderboard-row:last-child { border-bottom: none; }
.lb-rank { color: var(--neon-gold); font-weight: 900; text-align: center; }
.lb-name { text-align: left; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { color: var(--neon-cyan); font-weight: 700; font-family: monospace; }

.leaderboard-row.current-player { background: rgba(255, 214, 10, 0.15); border-radius: 6px; }
.leaderboard-row.current-player .lb-name { color: var(--neon-gold); }
.empty-board { text-align: center; color: rgba(255,255,255,0.4); font-size: 13px; padding: 10px; }

/* === End screen === */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 16px 0;
}

.stat {
    background: rgba(0,0,0,0.3);
    padding: 12px 8px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label { font-size: 11px; color: rgba(255,255,255,0.5); letter-spacing: 1px; text-transform: uppercase; }
.stat-value {
    font-size: clamp(18px, 2.2vw, 26px);
    font-weight: 900;
    color: var(--neon-gold);
    text-shadow: 0 0 8px rgba(255, 214, 10, 0.5);
    margin-top: 4px;
    font-family: 'Courier New', monospace;
}

/* Spinner */
.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255,255,255,0.1);
    border-top-color: var(--neon-cyan);
    border-radius: 50%;
    margin: 16px auto;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }
