/* ============================
   RUSH - Futuristic F1
   ============================ */

:root {
    --primary: #00e5ff;
    --accent: #7c4dff;
    --sky: #0a1628;
    --green: #0d1117;
    --green-dark: #060a10;
    --bg-dark: #080c14;
    --bg-panel: rgba(6, 10, 20, 0.85);
    --surface: rgba(0, 229, 255, 0.08);
    --surface-strong: rgba(0, 229, 255, 0.15);
    --border: rgba(0, 229, 255, 0.25);
    --text: #e0f0ff;
    --text-dim: rgba(200, 220, 255, 0.6);
    --danger: #ff3d00;
    --ok: #00e676;
    --font-display: 'Lilita One', cursive;
    --font-body: 'Nunito', sans-serif;
    --border-radius: 8px;
    --panel-shadow: 0 4px 30px rgba(0, 0, 0, 0.6), 0 0 1px rgba(0, 229, 255, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--green);
    color: var(--text);
    font-family: var(--font-body);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

#game-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.hidden {
    display: none !important;
}

/* --- Loading Screen --- */
#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: linear-gradient(180deg, #0a1628 0%, #060a10 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#loading-screen::before {
    content: none;
}

#loading-screen::after {
    content: none;
}

.loader-content {
    text-align: center;
    position: relative;
    z-index: 2;
}

.game-title {
    font-family: var(--font-display);
    font-size: clamp(56px, 13vw, 110px);
    color: #ffffff;
    letter-spacing: 8px;
    line-height: 1;
    text-shadow:
        0 0 30px rgba(0, 229, 255, 0.4),
        0 0 60px rgba(0, 229, 255, 0.15);
    -webkit-text-stroke: 1px rgba(0, 229, 255, 0.3);
}

.game-subtitle {
    font-family: var(--font-display);
    font-size: clamp(18px, 4vw, 30px);
    color: var(--primary);
    letter-spacing: 10px;
    margin-top: 2px;
    text-shadow: 0 0 15px rgba(0, 229, 255, 0.4);
}

.loader-bar-wrap {
    width: 280px;
    max-width: 80vw;
    margin: 28px auto 10px;
    height: 4px;
    background: rgba(0, 229, 255, 0.08);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid rgba(0, 229, 255, 0.15);
}

.loader-bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    background: linear-gradient(90deg, #00e5ff, #7c4dff);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.5);
    transition: width 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.loader-text {
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.loader-percent {
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 1px;
}

/* --- Screens / Panels --- */
.screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Full-screen 3D Menu Background --- */
#menu-bg-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.menu-overlay {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    pointer-events: none;
}

.menu-overlay > * {
    pointer-events: auto;
}

.menu-help-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(0, 229, 255, 0.25);
    background: rgba(6, 10, 20, 0.6);
    color: rgba(0, 229, 255, 0.7);
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 0 15px rgba(0, 229, 255, 0.1);
}

.menu-help-btn:hover {
    background: rgba(0, 229, 255, 0.08);
    border-color: rgba(0, 229, 255, 0.4);
    color: var(--primary);
    transform: scale(1.08);
}

.menu-help-btn:active {
    transform: scale(0.98);
}

/* Header / Title */
.menu-header {
    text-align: center;
    padding: 24px 24px 0;
}

.menu-header .game-title {
    font-size: clamp(44px, 9vw, 90px);
    letter-spacing: 4px;
}

.title-dot {
    color: var(--primary);
}

.title-racing {
    color: #ffe44d;
    font-size: 0.6em;
    letter-spacing: 8px;
    vertical-align: middle;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
}

/* Main menu content and control panel — orderly stack */
.menu-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px 24px 24px;
    padding-bottom: 40vh;
}

.menu-control-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    max-width: 300px;
}

.menu-control-panel .control-group {
    width: 100%;
    max-width: 240px;
    text-align: center;
}

.menu-control-panel .control-group + .control-group {
    margin-top: 0;
}

.control-label {
    display: block;
    font-family: var(--font-display);
    font-size: 12px;
    letter-spacing: 2px;
    color: var(--text-dim);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.menu-control-panel > .btn {
    margin: 0;
    width: 240px;
    max-width: 240px;
    padding: 12px 20px;
    font-size: 16px;
    letter-spacing: 2px;
}

.party-controls {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 8px;
    width: 240px;
    max-width: 240px;
}

.party-controls .btn-join {
    flex: 0 0 auto;
    width: 72px;
    min-height: 44px;
    margin: 0;
    padding: 12px 10px;
    font-size: 13px;
}

.join-input-compact {
    flex: 1;
    min-width: 0;
    width: auto;
    height: 44px;
    padding: 0 8px;
    background: rgba(0, 229, 255, 0.04);
    border: 1px solid rgba(0, 229, 255, 0.2);
    border-radius: var(--border-radius);
    color: #e0f0ff;
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    letter-spacing: 2px;
    text-transform: uppercase;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.join-input-compact:focus {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.2);
}

/* Spacer — car is visible through this area */
.menu-spacer {
    flex: 1;
    min-height: 40px;
    pointer-events: none;
}

/* Bottom panel — all controls */
.menu-bottom-panel {
    background: linear-gradient(0deg, rgba(6,10,16,0.9) 0%, rgba(6,10,16,0.6) 75%, transparent 100%);
    padding: 20px 24px 18px;
}

.menu-center-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    max-width: 300px;
    margin: 0 auto;
}

.menu-center-col .neon-input {
    width: 240px;
    text-align: center;
    font-size: 14px;
    padding: 8px 12px;
}

.btn-full {
    width: 240px;
    max-width: 240px;
}

.party-row {
    display: flex;
    gap: 6px;
    width: 240px;
    align-items: stretch;
}

.btn-half {
    flex: 1;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 8px 6px;
    font-size: 13px;
}

.join-inline {
    display: flex;
    gap: 4px;
    flex: 1;
}

.join-inline .join-input-small {
    width: 60px;
    flex: 1;
    padding: 8px 6px;
    font-size: 12px;
    letter-spacing: 2px;
}

.join-inline .btn-join {
    margin: 0;
    padding: 8px 10px;
    font-size: 12px;
}

.btn-play {
    font-size: 18px;
    letter-spacing: 3px;
}

.join-row {
    display: flex;
    gap: 6px;
}

.join-input-small {
    width: 80px;
    padding: 8px 10px;
    background: rgba(0, 229, 255, 0.04);
    border: 1px solid rgba(0, 229, 255, 0.2);
    border-radius: var(--border-radius);
    color: #e0f0ff;
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 400;
    outline: none;
    text-transform: uppercase;
    letter-spacing: 3px;
    text-align: center;
}

.join-input-small:focus {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.2);
}

.btn-join {
    max-width: none;
    width: auto;
    padding: 8px 16px;
    flex-shrink: 0;
    font-size: 13px;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 12px;
    width: auto;
    max-width: none;
}

.btn-link {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-family: var(--font-display);
    font-size: 13px;
    letter-spacing: 2px;
    cursor: pointer;
    padding: 4px 8px;
    transition: color 0.2s;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.btn-link:hover {
    color: #ffffff;
}

/* --- Instructions Overlay --- */
.instructions-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(4, 6, 12, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
}

.instructions-panel {
    background: rgba(6, 10, 20, 0.92);
    border: 1px solid rgba(0, 229, 255, 0.15);
    border-radius: 12px;
    padding: 28px 32px;
    max-width: 420px;
    width: 92%;
    text-align: center;
    box-shadow: var(--panel-shadow);
}

.instructions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 16px 0;
}

.instruction-item {
    background: rgba(0, 229, 255, 0.04);
    border: 1px solid rgba(0, 229, 255, 0.1);
    border-radius: var(--border-radius);
    padding: 12px 8px;
}

.instruction-keys {
    font-family: var(--font-display);
    font-size: 18px;
    color: #ffe44d;
    margin-bottom: 4px;
    letter-spacing: 1px;
}

.key-arrow {
    font-size: 14px;
}

.instruction-label {
    font-family: var(--font-body);
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 700;
}

.instructions-tip {
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
    font-weight: 700;
    margin: 12px 0 16px;
    font-style: italic;
}

/* --- Panels (other screens) --- */
.menu-bg {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: linear-gradient(180deg, var(--sky) 0%, #87ceeb 100%);
}

.panel-content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 28px;
    max-width: 480px;
    width: 94%;
    background: rgba(6, 10, 20, 0.88);
    border: 1px solid rgba(0, 229, 255, 0.15);
    border-radius: 12px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--panel-shadow);
    backdrop-filter: blur(12px);
}

.panel-title {
    font-family: var(--font-display);
    font-size: 28px;
    color: #e0f0ff;
    margin-bottom: 18px;
    letter-spacing: 3px;
    text-shadow: 0 0 15px rgba(0, 229, 255, 0.3);
}

/* --- Inputs --- */
.input-label {
    display: block;
    text-align: center;
    font-family: var(--font-display);
    font-size: 16px;
    color: var(--text-dim);
    letter-spacing: 2px;
    margin: 12px 0 6px;
    text-shadow: none;
}

.neon-input {
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    display: block;
    padding: 12px 16px;
    background: rgba(0, 229, 255, 0.04);
    border: 1px solid rgba(0, 229, 255, 0.2);
    border-radius: var(--border-radius);
    color: #e0f0ff;
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 700;
    outline: none;
    text-align: center;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.neon-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.2);
}

.code-input {
    font-family: var(--font-display);
    font-size: 30px;
    letter-spacing: 8px;
    text-transform: uppercase;
}

/* --- Color Picker --- */
.color-picker {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 2px 0 4px;
}

.color-option {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease, border-color 0.15s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.color-option:hover {
    transform: scale(1.15);
}

.color-option.selected {
    border-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.2), 0 2px 8px rgba(0, 0, 0, 0.3);
    transform: scale(1.1);
}

/* --- Buttons --- */
.btn {
    display: block;
    width: 100%;
    max-width: 300px;
    margin: 10px auto;
    padding: 14px 20px;
    border-radius: var(--border-radius);
    font-family: var(--font-display);
    font-size: 18px;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-transform: uppercase;
    border: 1px solid transparent;
    text-shadow: none;
}

.btn-primary {
    background: linear-gradient(135deg, #00e5ff 0%, #00b0cc 100%);
    color: #0a0a12;
    border-color: rgba(0, 229, 255, 0.3);
    box-shadow: 0 0 20px rgba(0, 229, 255, 0.25), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 30px rgba(0, 229, 255, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
}

.btn-primary:active {
    transform: translateY(1px);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.2), 0 1px 4px rgba(0, 0, 0, 0.3);
}

.btn-accent {
    background: linear-gradient(135deg, #7c4dff 0%, #5c35cc 100%);
    color: #ffffff;
    border-color: rgba(124, 77, 255, 0.3);
    box-shadow: 0 0 20px rgba(124, 77, 255, 0.2), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.btn-accent:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 30px rgba(124, 77, 255, 0.35), 0 4px 16px rgba(0, 0, 0, 0.3);
}

.btn-accent:active {
    transform: translateY(1px);
    box-shadow: 0 0 12px rgba(124, 77, 255, 0.15), 0 1px 4px rgba(0, 0, 0, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: #e0f0ff;
    border-color: rgba(255, 255, 255, 0.15);
    text-shadow: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-secondary:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.btn-secondary:active {
    transform: translateY(1px);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.btn-ghost {
    background: rgba(0, 229, 255, 0.05);
    color: rgba(224, 240, 255, 0.85);
    border-color: rgba(0, 229, 255, 0.15);
    text-shadow: none;
}

.btn-ghost:hover {
    background: rgba(0, 229, 255, 0.1);
    color: #ffffff;
    border-color: rgba(0, 229, 255, 0.3);
}

.btn-small {
    display: inline-block;
    width: auto;
    max-width: none;
    padding: 7px 14px;
    font-size: 12px;
    margin: 0 4px;
}

.btn-icon {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    transition: color 0.2s ease, transform 0.2s ease;
}

.btn-icon:hover {
    color: #ffffff;
    transform: scale(1.15);
}

.menu-buttons {
    margin-top: 16px;
}

/* --- Track Selection --- */
.track-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.track-card {
    background: rgba(0, 229, 255, 0.04);
    border: 1px solid rgba(0, 229, 255, 0.12);
    border-radius: var(--border-radius);
    padding: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
}

.track-card:hover {
    background: rgba(0, 229, 255, 0.08);
    transform: translateY(-3px);
    border-color: rgba(0, 229, 255, 0.25);
}

.track-card.selected {
    border-color: var(--primary);
    background: rgba(0, 229, 255, 0.1);
    box-shadow: 0 0 20px rgba(0, 229, 255, 0.15);
}

.track-card h3 {
    font-family: var(--font-display);
    font-size: 14px;
    color: #ffffff;
    margin-top: 8px;
}

.track-card p {
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 700;
}

.track-meta {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.track-meta span {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-dim);
}

.track-difficulty.easy { color: #4ade80; background: rgba(74, 222, 128, 0.12); }
.track-difficulty.medium { color: #fbbf24; background: rgba(251, 191, 36, 0.12); }
.track-difficulty.hard { color: #f87171; background: rgba(248, 113, 113, 0.12); }

.track-preview {
    width: 100%;
    height: 100px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.track-preview-canvas {
    width: 100%;
    height: 100%;
}

.track-buttons {
    display: flex;
    gap: 12px;
}

.track-buttons .btn {
    flex: 1;
}

/* --- Party Lobby --- */
.party-code-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px;
    background: rgba(0, 229, 255, 0.04);
    border-radius: var(--border-radius);
    border: 1px solid rgba(0, 229, 255, 0.2);
    margin-bottom: 14px;
    font-family: var(--font-display);
}

.code-value {
    font-size: 30px;
    letter-spacing: 6px;
    color: var(--primary);
    text-shadow: 0 0 15px rgba(0, 229, 255, 0.4);
}

.party-track {
    margin-bottom: 14px;
    font-size: 14px;
    color: var(--text-dim);
    font-weight: 700;
}

.player-list {
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 14px;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(0, 229, 255, 0.03);
    border: 1px solid rgba(0, 229, 255, 0.1);
    border-radius: var(--border-radius);
    margin-bottom: 6px;
}

.player-color {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0, 229, 255, 0.3);
}

.player-name {
    flex: 1;
    text-align: left;
    font-weight: 800;
}

.player-host {
    font-size: 11px;
    color: #ffe44d;
    font-family: var(--font-display);
    letter-spacing: 1px;
}

.player-ready {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 999px;
    font-weight: 800;
}

.player-ready.is-ready {
    background: rgba(163, 230, 53, 0.2);
    color: var(--ok);
    border: 2px solid rgba(163, 230, 53, 0.3);
}

.player-ready.not-ready {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-dim);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.waiting-text {
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 700;
    animation: pulse 2s infinite;
}

.lobby-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* --- Leaderboard --- */
.lb-track-filter {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 14px;
}

.lb-filter.active {
    background: rgba(0, 229, 255, 0.12);
    color: var(--primary);
    border-color: var(--primary);
}

.lb-table-container {
    max-height: 350px;
    overflow-y: auto;
    margin-bottom: 14px;
}

.lb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.lb-table th {
    font-family: var(--font-display);
    font-size: 12px;
    color: var(--primary);
    padding: 10px 6px;
    text-align: left;
    border-bottom: 2px solid rgba(255, 255, 255, 0.15);
    letter-spacing: 1px;
}

.lb-table td {
    padding: 9px 6px;
    border-bottom: 1px solid rgba(0, 229, 255, 0.06);
    color: #e0f0ff;
    font-weight: 700;
}

/* --- HUD --- */
#hud {
    position: fixed;
    inset: 0;
    z-index: 50;
    pointer-events: none;
}

#hud button,
#hud .hud-minimap {
    pointer-events: auto;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 14px 16px;
}

.hud-position {
    font-family: var(--font-display);
    font-size: 32px;
    color: #e0f0ff;
    background: rgba(6, 10, 20, 0.75);
    border: 1px solid rgba(0, 229, 255, 0.2);
    border-radius: var(--border-radius);
    padding: 6px 14px;
    text-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
    min-width: 70px;
    text-align: center;
}

.hud-lap {
    font-family: var(--font-display);
    font-size: 18px;
    color: var(--primary);
    background: rgba(6, 10, 20, 0.75);
    border: 1px solid rgba(0, 229, 255, 0.15);
    padding: 8px 14px;
    border-radius: var(--border-radius);
    text-shadow: 0 0 8px rgba(0, 229, 255, 0.3);
    min-width: 100px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.hud-time {
    font-family: var(--font-display);
    font-size: 22px;
    color: #e0f0ff;
    background: rgba(6, 10, 20, 0.75);
    border: 1px solid rgba(0, 229, 255, 0.15);
    border-radius: var(--border-radius);
    padding: 7px 14px;
    min-width: 130px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.hud-bottom {
    position: fixed;
    bottom: 14px;
    left: 14px;
    right: 14px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.hud-speed {
    font-family: var(--font-display);
    font-size: 56px;
    color: #e0f0ff;
    line-height: 0.9;
    background: rgba(6, 10, 20, 0.75);
    border: 1px solid rgba(0, 229, 255, 0.2);
    border-radius: var(--border-radius);
    padding: 14px 16px 12px;
    min-width: 170px;
    text-shadow: 0 0 12px rgba(0, 229, 255, 0.25);
    font-variant-numeric: tabular-nums;
}

.speed-unit {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-dim);
    letter-spacing: 2px;
    text-shadow: none;
}

.boost-bar-container {
    margin-top: 10px;
    width: 170px;
}

.boost-bar-label {
    font-family: var(--font-display);
    font-size: 12px;
    color: var(--primary);
    letter-spacing: 1.5px;
    margin-bottom: 4px;
}

.boost-key-hint {
    font-size: 10px;
    color: var(--text-dim);
    letter-spacing: 0.8px;
}

.boost-bar-bg {
    width: 100%;
    height: 8px;
    background: rgba(0, 229, 255, 0.06);
    border: 1px solid rgba(0, 229, 255, 0.15);
    border-radius: 999px;
    overflow: hidden;
}

.boost-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #1565c0, #42a5f5);
    border-radius: 999px;
    transition: width 0.08s linear;
}

.boost-bar-fill.boosting {
    background: linear-gradient(90deg, #0d47a1, #2196f3);
}

.hud-minimap canvas {
    border: 1px solid rgba(0, 229, 255, 0.25);
    border-radius: var(--border-radius);
    background: rgba(6, 10, 20, 0.7);
}

.hud-checkpoint {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-display);
    font-size: 34px;
    color: var(--primary);
    text-shadow: 0 0 20px rgba(0, 229, 255, 0.5);
    animation: flashIn 0.8s forwards;
}

.hud-lap-time {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-display);
    font-size: 22px;
    color: #e0f0ff;
    background: rgba(6, 10, 20, 0.8);
    border: 1px solid rgba(0, 229, 255, 0.2);
    padding: 12px 22px;
    border-radius: var(--border-radius);
    animation: slideUp 2s forwards;
}

.hud-wrong-way {
    position: fixed;
    top: 22%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-display);
    font-size: 42px;
    color: #ffffff;
    background: var(--danger);
    padding: 12px 34px;
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 61, 0, 0.4);
    z-index: 999;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 14px;
    text-shadow: 0 0 15px rgba(255, 61, 0, 0.5);
    animation: wrongWayPulse 0.4s ease-in-out infinite alternate;
    box-shadow: 0 0 30px rgba(255, 61, 0, 0.3);
}

@keyframes wrongWayPulse {
    0% { transform: translate(-50%, -50%) scale(1); }
    100% { transform: translate(-50%, -50%) scale(1.05); }
}

.wrong-way-icon {
    font-size: 44px;
}

.hud-menu-btn {
    position: fixed;
    top: 60px;
    right: 14px;
    font-size: 26px;
    color: rgba(255, 255, 255, 0.6);
}

.hud-menu-btn:hover {
    color: #ffffff;
}

/* --- Countdown --- */
#countdown {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

#countdown-text {
    font-family: var(--font-display);
    font-size: 130px;
    color: #ffffff;
    text-shadow:
        0 0 40px rgba(0, 229, 255, 0.6),
        0 0 80px rgba(0, 229, 255, 0.2);
    animation: countPulse 1s ease-out;
}

/* --- Race Results --- */
.results-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    justify-content: center;
}

.result-item {
    flex: 1;
    min-width: 110px;
    padding: 14px;
    background: rgba(0, 229, 255, 0.04);
    border: 1px solid rgba(0, 229, 255, 0.15);
    border-radius: var(--border-radius);
}

.result-label {
    display: block;
    font-family: var(--font-display);
    font-size: 11px;
    color: var(--primary);
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.result-value {
    font-family: var(--font-display);
    font-size: 24px;
    color: #e0f0ff;
    text-shadow: 0 0 8px rgba(0, 229, 255, 0.2);
}

.results-players {
    margin-bottom: 14px;
}

.result-buttons {
    display: flex;
    gap: 12px;
}

.result-buttons .btn {
    flex: 1;
}

/* --- Mobile Controls --- */
#mobile-controls {
    position: fixed;
    inset: 0;
    z-index: 60;
    pointer-events: none;
}

.touch-steer-zone {
    position: absolute;
    bottom: 18px;
    left: 18px;
    width: 140px;
    height: 140px;
    pointer-events: auto;
}

.touch-joystick {
    width: 120px;
    height: 120px;
    border: 1px solid rgba(0, 229, 255, 0.25);
    border-radius: 50%;
    position: relative;
    background: rgba(6, 10, 20, 0.6);
}

.joystick-knob {
    width: 44px;
    height: 44px;
    background: rgba(0, 229, 255, 0.2);
    border: 2px solid rgba(0, 229, 255, 0.5);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: none;
}

.touch-buttons {
    position: absolute;
    bottom: 18px;
    right: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: auto;
}

.touch-btn {
    width: 78px;
    height: 78px;
    border-radius: 50%;
    border: 1px solid rgba(0, 229, 255, 0.25);
    font-family: var(--font-display);
    font-size: 14px;
    color: #e0f0ff;
    background: rgba(6, 10, 20, 0.6);
    text-shadow: none;
}

.touch-gas {
    background: rgba(0, 230, 118, 0.2);
    border-color: rgba(0, 230, 118, 0.4);
}

.touch-brake {
    background: rgba(255, 61, 0, 0.2);
    border-color: rgba(255, 61, 0, 0.4);
}

.touch-boost {
    background: rgba(0, 229, 255, 0.15);
    border-color: rgba(0, 229, 255, 0.4);
    color: var(--primary);
    font-size: 15px;
}

.touch-boost:active {
    background: rgba(0, 229, 255, 0.3);
}

.touch-btn:active {
    transform: scale(0.92);
}

/* --- Error Text --- */
.error-text {
    color: #ff6b6b;
    font-size: 14px;
    margin-top: 12px;
    font-weight: 800;
}

.join-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.join-buttons .btn {
    flex: 1;
}

/* --- Animations --- */
@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

@keyframes flashIn {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.4);
    }
    30% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes slideUp {
    0% {
        opacity: 0;
        transform: translate(-50%, 0);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
    80% {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -90%);
    }
}

@keyframes countPulse {
    0% {
        transform: scale(1.6);
        opacity: 0;
    }
    30% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(0.85);
        opacity: 0;
    }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .menu-header .game-title {
        font-size: 40px;
    }

    .menu-center-col .neon-input {
        width: 220px;
    }

    .menu-secondary-row {
        flex-direction: column;
        gap: 6px;
    }

    .btn-play {
        font-size: 18px;
    }

    .panel-content {
        padding: 20px 14px;
    }

    .game-title {
        letter-spacing: 2px;
    }

    .hud-speed {
        font-size: 38px;
        min-width: 145px;
    }

    .hud-position {
        font-size: 26px;
    }

    .track-grid {
        grid-template-columns: 1fr;
    }

    .results-stats {
        flex-direction: column;
    }

    .btn {
        font-size: 16px;
        padding: 12px 16px;
    }
}
