:root {
    --bg: #0a0a12;
    --fg: #e8e8f0;
    --muted: #7a7a90;
    --accent: #ff4d00;
    --accent2: #00b8d4;
    --card: rgba(8, 8, 18, 0.88);
    --border: rgba(255, 77, 0, 0.22);
    --glass: rgba(8, 8, 18, 0.88)
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box
}

body {
    background: var(--bg);
    color: var(--fg);
    font-family: 'Rajdhani', sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    cursor: default;
    user-select: none
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%
}

/* ==========================================
   开始界面
   ========================================== */
#start-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #dce8f4 0%, #b8d4ec 30%, #e8e0d0 70%, #f0e6d4 100%)
}

#start-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 40% 50%, rgba(255, 77, 0, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 30%, rgba(0, 180, 210, 0.04) 0%, transparent 50%)
}

.start-title {
    font-family: 'Orbitron', monospace;
    font-size: clamp(40px, 8vw, 90px);
    font-weight: 900;
    letter-spacing: 6px;
    background: linear-gradient(135deg, #ff4d00, #ff8800, #ffcc00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    position: relative;
    z-index: 1;
    animation: titlePulse 3s ease-in-out infinite;
    filter: drop-shadow(0 2px 8px rgba(255, 77, 0, 0.3))
}

@keyframes titlePulse {
    0%,
    100% {
        transform: scale(1)
    }
    50% {
        transform: scale(1.02)
    }
}

.start-sub {
    font-family: 'Orbitron', monospace;
    font-size: clamp(12px, 2vw, 18px);
    color: #5a6a7a;
    letter-spacing: 12px;
    margin-top: 8px;
    position: relative;
    z-index: 1
}

.car-selector {
    margin-top: 30px;
    display: flex;
    gap: 12px;
    align-items: center;
    position: relative;
    z-index: 1;
    background: rgba(0, 0, 0, 0.08);
    padding: 12px 24px;
    border-radius: 8px;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1)
}

.car-selector label {
    color: #3a4a5a;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 2px
}

.car-selector select {
    padding: 8px 20px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 14px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid rgba(255, 77, 0, 0.3);
    border-radius: 6px;
    color: #1a1a2a;
    cursor: pointer;
    outline: none;
    transition: all .3s;
    min-width: 150px
}

.car-selector select:hover {
    border-color: var(--accent)
}

.car-selector select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 20px rgba(255, 77, 0, 0.2)
}

.car-selector .car-preview {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    border: 1px solid rgba(255, 255, 255, 0.1)
}

.start-btn {
    margin-top: 30px;
    padding: 16px 60px;
    font-family: 'Orbitron', monospace;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #ff4d00, #cc3300);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    z-index: 1;
    transition: all .3s;
    clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
    box-shadow: 0 4px 20px rgba(255, 77, 0, 0.3)
}

.start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 30px rgba(255, 77, 0, 0.5)
}

.controls-hint {
    margin-top: 30px;
    color: #5a6a7a;
    font-size: 14px;
    position: relative;
    z-index: 1;
    text-align: center;
    line-height: 2.2
}

.controls-hint kbd {
    display: inline-block;
    padding: 2px 8px;
    margin: 0 2px;
    background: rgba(0, 0, 0, 0.07);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 3px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 13px;
    color: #333
}

.controls-hint .gamepad-hint {
    color: var(--accent2);
    font-size: 13px;
    display: block;
    margin-top: 4px;
}

.start-deco {
    position: absolute;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    border: 1px solid rgba(255, 77, 0, 0.08);
    animation: decoSpin 25s linear infinite
}

.start-deco:nth-child(1) {
    top: -80px;
    right: -80px;
    width: 400px;
    height: 400px
}

.start-deco:nth-child(2) {
    bottom: -60px;
    left: -60px;
    animation-direction: reverse
}

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

/* ==========================================
   HUD 容器
   ========================================== */
#hud {
    position: fixed;
    inset: 0;
    z-index: 10;
    pointer-events: none
}

#hud > * {
    pointer-events: auto
}

/* ==========================================
   速度表
   ========================================== */
#speedometer {
    position: absolute;
    bottom: 30px;
    left: 30px;
    width: 180px;
    padding: 15px;
    background: var(--glass);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3)
}

#speed-value {
    font-family: 'Orbitron', monospace;
    font-size: 48px;
    font-weight: 900;
    color: var(--accent);
    line-height: 1
}

#speed-unit {
    font-family: 'Orbitron', monospace;
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 3px;
    margin-top: 2px
}

#speed-bar {
    margin-top: 10px;
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: hidden
}

#speed-fill {
    height: 100%;
    width: 0%;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--accent), #ffaa00);
    transition: width .1s
}

#gear-display {
    margin-top: 8px;
    font-family: 'Orbitron', monospace;
    font-size: 20px;
    color: var(--accent2)
}

/* ==========================================
   圈速信息
   ========================================== */
#lap-info {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    min-width: 200px;
    background: var(--glass);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    line-height: 1.8;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3)
}

#lap-info .label {
    color: var(--muted)
}

#lap-info .val {
    font-family: 'Orbitron', monospace;
    color: var(--fg);
    font-weight: 700
}

#lap-info .val.best {
    color: var(--accent2)
}

/* ==========================================
   小地图
   ========================================== */
#minimap-wrap {
    position: absolute;
    bottom: 30px;
    right: 20px;
    width: 160px;
    height: 160px;
    background: var(--glass);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 5px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3)
}

#minimap-canvas {
    width: 100%;
    height: 100%;
    border-radius: 6px
}

/* ==========================================
   控制面板
   ========================================== */
#control-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 20;
    pointer-events: none;
    max-width: 240px;
}

#control-panel > * {
    pointer-events: auto;
}

/* 视角按钮行 */
#view-btns {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    background: rgba(8, 8, 18, 0.85);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 6px 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.vbtn {
    padding: 4px 10px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: #7a7a90;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all .2s;
    line-height: 1.4;
}

.vbtn:hover {
    color: #e8e8f0;
    border-color: rgba(255, 255, 255, 0.1);
}

.vbtn.active {
    color: #ff4d00;
    border-color: #ff4d00;
    background: rgba(255, 77, 0, 0.15);
}

/* 控制模式行 */
#control-mode-toggle {
    display: flex;
    gap: 4px;
    background: rgba(8, 8, 18, 0.85);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 6px 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.cmbtn {
    padding: 4px 12px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: #7a7a90;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all .2s;
    line-height: 1.4;
}

.cmbtn:hover {
    color: #e8e8f0;
}

.cmbtn.active {
    color: #00b8d4;
    border-color: #00b8d4;
    background: rgba(0, 184, 212, 0.12);
}

/* 功能按钮行 */
#action-btns {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    background: rgba(8, 8, 18, 0.85);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 6px 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

#action-btns button {
    padding: 4px 12px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: #7a7a90;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all .2s;
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.4;
}

#action-btns button:hover {
    color: #e8e8f0;
    border-color: rgba(255, 255, 255, 0.1);
}

#action-btns #audio-toggle.on {
    color: #00b8d4;
    border-color: rgba(0, 184, 212, 0.3);
}

#action-btns #audio-toggle.off {
    color: #7a7a90;
    border-color: transparent;
}

#action-btns #reset-btn:hover {
    color: #ff4d00;
    border-color: #ff4d00;
    background: rgba(255, 77, 0, 0.12);
}

#action-btns .key-hint {
    font-size: 9px;
    color: #5a5a70;
}

/* ==========================================
   暂停按钮（居中顶部）
   ========================================== */
#pause-btn {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    color: var(--muted);
    font-size: 16px;
    cursor: pointer;
    transition: all .2s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2)
}

#pause-btn:hover {
    color: var(--fg);
    border-color: rgba(255, 255, 255, 0.15)
}

/* ==========================================
   游戏手柄状态
   ========================================== */
#gamepad-status {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 50px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    color: var(--accent2);
    border: 1px solid rgba(0, 184, 212, 0.2);
}

#gamepad-status.show {
    opacity: 1;
}

/* ==========================================
   路面指示器
   ========================================== */
#surface-indicator {
    position: absolute;
    bottom: 30px;
    left: 230px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    background: var(--glass);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    transition: all .3s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2)
}

#surface-indicator.track {
    color: #8f8;
    border-color: rgba(100, 255, 100, 0.2)
}

#surface-indicator.grass {
    color: #fa4;
    border-color: rgba(255, 170, 50, 0.2)
}

/* ==========================================
   遮罩层
   ========================================== */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(5, 5, 10, 0.75);
    backdrop-filter: blur(10px)
}

.overlay.show {
    display: flex
}

.overlay-box {
    text-align: center;
    padding: 50px 60px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5)
}

.overlay-title {
    font-family: 'Orbitron', monospace;
    font-size: 36px;
    font-weight: 900;
    color: var(--accent);
    margin-bottom: 20px
}

.overlay-stat {
    font-size: 16px;
    color: var(--muted);
    margin: 8px 0;
    line-height: 1.6
}

.overlay-stat span {
    font-family: 'Orbitron', monospace;
    color: var(--fg);
    font-weight: 700
}

.overlay-stat span.best {
    color: var(--accent2)
}

.overlay-btn {
    margin-top: 30px;
    padding: 12px 40px;
    font-family: 'Orbitron', monospace;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #ff4d00, #cc3300);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all .3s;
    margin: 6px
}

.overlay-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(255, 77, 0, 0.3)
}

.overlay-btn.secondary {
    background: transparent;
    border: 1px solid var(--muted);
    color: var(--muted)
}

.overlay-btn.secondary:hover {
    border-color: var(--fg);
    color: var(--fg);
    box-shadow: none
}

/* ==========================================
   倒计时
   ========================================== */
#countdown {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.25)
}

#countdown.show {
    display: flex
}

#countdown-text {
    font-family: 'Orbitron', monospace;
    font-size: 120px;
    font-weight: 900;
    color: var(--accent);
    animation: countPop .5s ease-out;
    text-shadow: 0 4px 30px rgba(255, 77, 0, 0.5)
}

@keyframes countPop {
    0% {
        transform: scale(2);
        opacity: 0
    }
    60% {
        transform: scale(.9);
        opacity: 1
    }
    100% {
        transform: scale(1)
    }
}

/* ==========================================
   Toast 提示
   ========================================== */
.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    padding: 10px 24px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 15px;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 184, 212, 0.4);
    color: var(--accent2);
    border-radius: 6px;
    animation: toastIn .3s ease-out, toastOut .3s ease-in 1.7s forwards
}

.toast.gamepad-toast {
    border-color: rgba(0, 184, 212, 0.6);
    color: #00ff88;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px)
    }
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px)
    }
}

/* ==========================================
   响应式适配
   ========================================== */
@media (max-width: 640px) {
    #speedometer {
        width: 130px;
        padding: 10px;
        bottom: 15px;
        left: 15px
    }

    #speed-value {
        font-size: 34px
    }

    #lap-info {
        top: 10px;
        right: 10px;
        padding: 10px 14px;
        font-size: 13px;
        min-width: auto
    }

    #minimap-wrap {
        width: 110px;
        height: 110px;
        bottom: 15px;
        right: 10px
    }

    #surface-indicator {
        left: 160px;
        bottom: 15px;
        font-size: 11px;
        padding: 4px 10px;
    }

    /* 控制面板移动端 */
    #control-panel {
        top: 10px;
        left: 10px;
        max-width: 180px;
        gap: 4px;
    }

    #view-btns {
        padding: 4px 6px;
        gap: 2px;
    }

    .vbtn {
        padding: 3px 7px;
        font-size: 10px;
    }

    #control-mode-toggle {
        padding: 4px 6px;
    }

    .cmbtn {
        padding: 3px 8px;
        font-size: 10px;
    }

    #action-btns {
        padding: 4px 6px;
        gap: 4px;
    }

    #action-btns button {
        padding: 3px 8px;
        font-size: 10px;
    }

    #action-btns .key-hint {
        font-size: 8px;
    }

    #pause-btn {
        width: 32px;
        height: 32px;
        font-size: 13px;
        top: 10px;
    }

    #gamepad-status {
        top: 10px;
        font-size: 10px;
        padding: 2px 8px;
        margin-top: 40px;
    }

    /* 开始界面移动端 */
    .car-selector {
        flex-direction: column;
        padding: 12px;
        gap: 8px;
        width: 90%;
    }

    .car-selector select {
        min-width: 120px;
        width: 100%;
    }

    .controls-hint {
        font-size: 12px;
        padding: 0 16px;
    }
}

/* ==========================================
   超小屏适配
   ========================================== */
@media (max-width: 400px) {
    #control-panel {
        max-width: 140px;
    }

    .vbtn {
        font-size: 9px;
        padding: 2px 5px;
    }

    .cmbtn {
        font-size: 9px;
        padding: 2px 6px;
    }

    #action-btns button {
        font-size: 9px;
        padding: 2px 6px;
        gap: 4px;
    }

    #action-btns .key-hint {
        font-size: 7px;
    }

    #speedometer {
        width: 100px;
        padding: 8px;
        bottom: 10px;
        left: 10px;
    }

    #speed-value {
        font-size: 28px;
    }

    #minimap-wrap {
        width: 80px;
        height: 80px;
        bottom: 10px;
        right: 8px;
    }

    #lap-info {
        top: 8px;
        right: 8px;
        padding: 8px 10px;
        font-size: 11px;
        min-width: auto;
    }

    #surface-indicator {
        left: 120px;
        bottom: 10px;
        font-size: 10px;
        padding: 3px 8px;
    }
}


/* ==========================================
   地图指示器
   ========================================== */

#current-map-indicator {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 16px;
    font-size: 14px;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    pointer-events: none;
    opacity: 0.7;
    z-index: 5;
    font-family: 'Rajdhani', sans-serif;
    letter-spacing: 1px;
}

/* ==========================================
   地图选择器
   ========================================== */

#map-selector-container {
    margin-top: 10px;
}

.map-preview {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#map-selector-container select {
    padding: 8px 20px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 14px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid rgba(255, 77, 0, 0.3);
    border-radius: 6px;
    color: #1a1a2a;
    cursor: pointer;
    outline: none;
    transition: all .3s;
    min-width: 150px;
}

#map-selector-container select:hover {
    border-color: var(--accent);
}

#map-selector-container select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 20px rgba(255, 77, 0, 0.2);
}

/* ==========================================
   移动端适配
   ========================================== */

@media (max-width: 640px) {
    #current-map-indicator {
        top: 60px;
        font-size: 11px;
        padding: 3px 12px;
        opacity: 0.8;
    }

    .map-preview {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    #map-selector-container {
        margin-top: 8px;
    }

    #map-selector-container select {
        padding: 6px 14px;
        font-size: 12px;
        min-width: 120px;
    }
}

@media (max-width: 400px) {
    #current-map-indicator {
        top: 50px;
        font-size: 10px;
        padding: 2px 10px;
    }
}