* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #000;
    overflow: hidden;
    font-family: 'Arial', sans-serif;
    touch-action: none;
    /* 모든 터치 제스처 차단 (핀치 줌 포함) */
}

#gameCanvas {
    display: block;
    width: 100vw;
    height: 100vh;
    touch-action: none;
    /* Prevent default touch behaviors */
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
    /* 배경 레이어 */
}

#ui-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
    /* UI 레이어 */
}

.hud-panel {
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    padding: 10px 20px;
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

#race-ui div {
    margin-bottom: 5px;
    font-size: 20px;
}

#lap-counter {
    color: #ffff00;
}

#lap-timer {
    font-size: 28px;
    color: #00ff00;
}

#minimap-container {
    width: 250px;
    height: 180px;
}

#minimapCanvas {
    width: 100%;
    height: 100%;
}

.warning {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 0, 0, 0.7);
    color: #fff;
    padding: 10px 40px;
    font-size: 32px;
    font-weight: bold;
    border-radius: 10px;
    animation: blink 0.5s infinite alternate;
}

@keyframes blink {
    from {
        opacity: 1;
    }

    to {
        opacity: 0.3;
    }
}

#countdown-overlay.hidden {
    display: none;
}

#speedometer {
    top: auto;
    bottom: 20px;
    left: 20px;
}

/* Mobile Controls */
#mobile-controls {
    pointer-events: none;
    /* ⭐ 컨테이너는 투명, 자식(조이스틱)만 터치 가능 */
    position: fixed;
    z-index: 200;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.touch-zone {
    width: 150px;
    height: 150px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    position: absolute;
    touch-action: none;
    z-index: 2000;
    pointer-events: auto;
    /* 명시적으로 이벤트 활성화 */
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
}

.touch-knob {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    position: absolute;
    /* Center the knob */
    top: 50%;
    left: 50%;
    margin-top: -25px;
    margin-left: -25px;

    pointer-events: none;
    /* Let clicks pass through to zone */
    transition: transform 0.05s;
    /* Faster update */
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.zone-label {
    position: absolute;
    color: rgba(255, 255, 255, 0.5);
    font-weight: bold;
    font-size: 20px;
    pointer-events: none;
    text-align: center;
}

.zone-label.top {
    top: 10px;
}

.zone-label.bottom {
    bottom: 10px;
}

.zone-label.left {
    left: 10px;
}

.zone-label.right {
    right: 10px;
}

.zone-center {
    width: 10px;
    height: 10px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
}

/* Zone Positioning */
#zone-pedal {
    bottom: 40px;
    left: 40px;
}

#zone-steer {
    bottom: 40px;
    right: 40px;
}

/* Adjust HUD for mobile */
@media (max-width: 768px) {

    /* Lap Info 30% 더 축소 (0.5 -> 0.7) */
    #race-ui {
        transform: scale(0.7);
        transform-origin: top left;
        top: 10px;
        left: 10px;
    }

    /* Minimap 30% 더 축소 (0.5 -> 0.35) */
    #minimap-container {
        transform: scale(0.35);
        transform-origin: top right;
        top: 10px;
        right: 10px;
    }

    /* Speedometer를 Lap Info 아래로, 30% 축소 */
    /* Speedometer를 Lap Info 아래로, 30% 축소 */
    #speedometer {
        transform: scale(0.7);
        transform-origin: top left;
        top: 120px;
        left: 10px;
        bottom: auto;

        /* 강제 크기 조정 - 배경 길이 문제 해결 */
        width: fit-content !important;
        height: fit-content !important;
        min-height: 0 !important;

        font-size: 20px !important;
        padding: 5px 10px !important;
        line-height: normal !important;
        display: inline-block !important;
    }

    /* Smaller screens: Reduce joystick size and separate them */
    .touch-zone {
        width: 120px;
        height: 120px;
    }

    #zone-pedal {
        bottom: 20px;
        left: 20px;
    }

    #zone-steer {
        bottom: 20px;
        right: 20px;
    }
}

/* The #lap-timer rule was moved into #race-ui div, so this old one is removed */

#off-road-warning {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 0, 0, 0.7);
    color: #fff;
    padding: 30px 60px;
    border-radius: 15px;
    font-size: 48px;
    font-weight: bold;
    text-align: center;
    animation: pulse 0.5s ease-in-out infinite alternate;
}

#wrong-way-warning {
    position: absolute;
    top: 60%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 165, 0, 0.7);
    color: #fff;
    padding: 30px 60px;
    border-radius: 15px;
    font-size: 48px;
    font-weight: bold;
    text-align: center;
    animation: pulse 0.5s ease-in-out infinite alternate;
}

#off-road-warning.hidden,
#wrong-way-warning.hidden {
    display: none;
}

@keyframes pulse {
    from {
        transform: translate(-50%, -50%) scale(1);
    }

    to {
        transform: translate(-50%, -50%) scale(1.05);
    }
}

.hidden {
    display: none !important;
}

/* Main Menu */
#main-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#main-menu h1 {
    color: #fff;
    font-size: 64px;
    margin-bottom: 50px;
    text-shadow: 0 0 20px #00ff00;
}

.menu-buttons {
    display: flex;
    gap: 30px;
}

.menu-btn {
    padding: 20px 40px;
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    background: #333;
    border: 3px solid #00ff00;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.menu-btn:hover {
    background: #00ff00;
    color: #000;
    transform: scale(1.05);
}

/* Editor UI */
#editor-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    background: #222;
}

#editorCanvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

#editor-ui {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
}

.editor-info {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 10px 20px;
    border-radius: 5px;
    border: 1px solid #aaa;
    font-family: monospace;
    font-size: 16px;
}

.editor-info span {
    margin-right: 20px;
}

.editor-controls {
    pointer-events: auto;
    display: flex;
    gap: 10px;
}

.editor-controls button {
    padding: 10px 20px;
    font-size: 16px;
    background: #444;
    color: #fff;
    border: 1px solid #aaa;
    border-radius: 5px;
    cursor: pointer;
}

.editor-controls button:hover {
    background: #666;
}

.editor-controls button.danger {
    background: #aa3333;
    border-color: #ff5555;
}

.editor-controls button.danger:hover {
    background: #cc4444;
}

#editor-help {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: #aaa;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 14px;
    pointer-events: none;
}