/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
}

/* ===== Game Container ===== */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 1;
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    z-index: 10;
}

/* ===== Menu Screens ===== */
.menu-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.menu-screen.hidden,
.panel-screen.hidden {
    display: none !important;
    pointer-events: none !important;
}

/* Slide transition */
.menu-screen.slide-out-left {
    animation: slideOutLeft 0.5s ease-in-out forwards;
}
.menu-screen.slide-in-right {
    animation: slideInRight 0.5s ease-in-out forwards;
}
@keyframes slideOutLeft {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-100%); opacity: 0; }
}
@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== Title Screen ===== */
#title-screen {
    background: linear-gradient(135deg, #0a0a2e 0%, #1a1a4e 50%, #0a0a2e 100%);
}

.game-title {
    font-size: 72px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 8px;
    margin-bottom: 10px;
    background: linear-gradient(180deg, #ff6b35, #ff3366, #ff6b35);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    animation: titlePulse 2s ease-in-out infinite;
}

.game-subtitle {
    font-size: 18px;
    color: #888;
    letter-spacing: 4px;
    margin-bottom: 20px;
}

.home-controls {
    max-width: 550px;
    margin: 15px auto 0;
    text-align: left;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 12px;
    color: #bbb;
    line-height: 1.5;
}

.controls-grid {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.control-section {
    flex: 1;
    min-width: 140px;
}

.control-title {
    font-weight: 700;
    color: #ddd;
    margin-bottom: 4px;
    font-size: 13px;
}

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

/* ===== Menu Buttons ===== */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.menu-btn {
    width: 280px;
    padding: 16px 32px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.menu-btn:hover {
    background: rgba(255, 107, 53, 0.3);
    border-color: #ff6b35;
    transform: scale(1.05);
}

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

.menu-btn.primary {
    background: linear-gradient(135deg, #ff6b35, #ff3366);
    border-color: transparent;
    font-size: 24px;
    padding: 20px 40px;
}

.menu-btn.primary:hover {
    filter: brightness(1.2);
    transform: scale(1.05);
}

/* ===== HUD ===== */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none !important;
    z-index: 50;
}

#hud * {
    pointer-events: none !important;
}

#hud.hidden {
    display: none;
}

.hud-position {
    position: absolute;
    top: 20px;
    left: 20px;
    font-size: 48px;
    font-weight: 900;
}

.hud-position .ordinal {
    font-size: 24px;
    vertical-align: super;
}

.hud-position .total {
    font-size: 20px;
    color: #aaa;
}

.hud-lap {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 28px;
    font-weight: 700;
    text-align: right;
}

.hud-lap .label {
    font-size: 14px;
    color: #aaa;
    display: block;
}

.hud-speed {
    position: absolute;
    bottom: 30px;
    right: 30px;
    font-size: 42px;
    font-weight: 700;
    text-align: right;
}

.hud-speed .unit {
    font-size: 16px;
    color: #aaa;
}

.hud-durability {
    position: absolute;
    bottom: 30px;
    left: 30px;
    width: 200px;
}

.hud-durability .label {
    font-size: 12px;
    color: #aaa;
    margin-bottom: 4px;
}

.durability-bar {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    overflow: hidden;
}

.durability-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff3366, #33ff66);
    border-radius: 6px;
    transition: width 0.3s ease;
}

.hud-weapons {
    position: absolute;
    bottom: 75px;
    left: 20px;
    font-size: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 14px;
    border-radius: 10px;
}

.hud-weapon-slot {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-weapon-slot .wkey {
    color: #ffcc00;
    font-weight: 700;
    font-size: 16px;
    min-width: 30px;
}

.hud-weapon-slot .wname {
    font-weight: 700;
    color: #ff6b35;
    font-size: 16px;
}

.hud-weapon-slot .wammo {
    color: #aaa;
    font-size: 15px;
}

.hud-item {
    position: absolute;
    bottom: 80px;
    right: 30px;
    width: 60px;
    height: 60px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    text-align: center;
}

.hud-minimap {
    position: absolute;
    top: 80px;
    right: 20px;
    width: 180px;
    height: 180px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.hud-minimap canvas {
    width: 100%;
    height: 100%;
}

/* ===== HUD Tablet Layout (iPad mini etc) ===== */
@media (max-width: 1024px) and (any-pointer: coarse) {
    .hud-position {
        top: 8px;
        left: 60px;
        font-size: 32px;
    }
    .hud-position .ordinal { font-size: 16px; }
    .hud-position .total { font-size: 14px; }
    .hud-lap {
        top: 150px;
        right: 10px;
        font-size: 18px;
    }
    .hud-speed {
        bottom: 10px;
        right: 80px;
        font-size: 24px;
    }
    .hud-speed .unit { font-size: 12px; }
    .hud-durability {
        bottom: 8px;
        left: 8px;
        width: 120px;
    }
    .hud-durability .label { font-size: 10px; }
    .durability-bar { height: 10px; }
    .hud-weapons {
        top: 8px;
        bottom: auto;
        left: 50%;
        transform: translateX(-50%);
        flex-direction: row;
        font-size: 12px;
        padding: 4px 10px;
        gap: 12px;
    }
    .hud-weapon-slot .wkey { font-size: 11px; min-width: 18px; }
    .hud-weapon-slot .wname { font-size: 11px; }
    .hud-weapon-slot .wammo { font-size: 10px; }
    .hud-item { display: none; }
    .hud-minimap {
        top: 8px;
        right: 8px;
        width: 120px;
        height: 120px;
    }
}

/* ===== HUD Phone Layout (iPhone etc) ===== */
@media (max-width: 667px) and (any-pointer: coarse) {
    .hud-position {
        top: 4px;
        left: 42px;
        font-size: 24px;
    }
    .hud-position .ordinal { font-size: 12px; }
    .hud-position .total { font-size: 10px; }
    .hud-lap {
        top: 105px;
        right: 6px;
        font-size: 14px;
    }
    .hud-lap .label { font-size: 9px; }
    .hud-speed {
        bottom: 6px;
        right: 55px;
        font-size: 18px;
    }
    .hud-speed .unit { font-size: 9px; }
    .hud-durability {
        bottom: 4px;
        left: 4px;
        width: 80px;
    }
    .hud-durability .label { font-size: 8px; }
    .durability-bar { height: 6px; }
    .hud-weapons {
        top: 4px;
        bottom: auto;
        left: 50%;
        transform: translateX(-50%);
        flex-direction: row;
        font-size: 10px;
        padding: 3px 6px;
        gap: 8px;
    }
    .hud-weapon-slot .wkey { font-size: 9px; min-width: 14px; }
    .hud-weapon-slot .wname { font-size: 9px; }
    .hud-weapon-slot .wammo { font-size: 8px; }
    .hud-item { display: none; }
    .hud-minimap {
        top: 4px;
        right: 4px;
        width: 80px;
        height: 80px;
    }
}

/* ===== Countdown ===== */
.countdown-overlay {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex !important;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.3);
}

.countdown-overlay.hidden {
    display: none !important;
}

.countdown-text {
    font-size: 160px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 60px rgba(255, 107, 53, 0.9), 0 0 120px rgba(255, 51, 102, 0.5);
    animation: countdownPop 0.6s ease-out;
}

@keyframes countdownPop {
    0% { transform: scale(3); opacity: 0; }
    60% { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* ===== Garage / Shop ===== */
.panel-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 30, 0.95);
    z-index: 100;
    display: flex;
}

.panel-screen.hidden {
    display: none;
}

.panel-sidebar {
    width: 300px;
    background: rgba(0, 0, 0, 0.3);
    padding: 20px;
    overflow-y: auto;
}

.panel-main {
    flex: 1;
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.vehicle-card {
    padding: 12px;
    margin-bottom: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.vehicle-card:hover, .vehicle-card.selected {
    border-color: #ff6b35;
    background: rgba(255, 107, 53, 0.1);
}

.vehicle-card .name {
    font-weight: 700;
    font-size: 16px;
}

.vehicle-card .type {
    font-size: 12px;
    color: #aaa;
}

.stat-bar {
    display: flex;
    align-items: center;
    margin: 4px 0;
}

.stat-bar .stat-label {
    width: 80px;
    font-size: 12px;
    color: #aaa;
}

.stat-bar .stat-track {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.stat-bar .stat-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}

.stat-fill.speed { background: #ff3366; }
.stat-fill.accel { background: #33ff66; }
.stat-fill.handling { background: #3366ff; }
.stat-fill.durability { background: #ffcc33; }

/* ===== Vehicle Type Tabs ===== */
.vehicle-type-tab.active {
    background: rgba(255, 107, 53, 0.3);
    border-color: #ff6b35;
}

/* ===== Weapon Select ===== */
.weapon-cards {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.weapon-card {
    width: 100%;
    max-width: 260px;
    padding: 10px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.weapon-card:hover, .weapon-card.selected {
    border-color: #ff6b35;
    background: rgba(255, 107, 53, 0.1);
    transform: translateY(-2px);
}

.weapon-card .weapon-icon {
    font-size: 48px;
    margin-bottom: 6px;
}

.weapon-card .weapon-name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
}

.weapon-card .weapon-stats {
    font-size: 11px;
    color: #aaa;
}

.weapon-card .weapon-desc {
    font-size: 11px;
    color: #ccd;
    line-height: 1.4;
    text-align: left;
}

.weapon-card .weapon-controls {
    font-size: 10px;
    color: #8cf;
    text-align: left;
}

/* ===== Course Select ===== */
.course-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    max-width: 900px;
    margin: 0 auto;
}

.course-card {
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.03);
    transition: all 0.2s;
}

.course-card:not(.locked):hover,
.course-card.selected {
    border-color: #ff6b35;
    background: rgba(255, 107, 53, 0.1);
    transform: translateY(-3px);
}

.course-card.locked {
    opacity: 0.4;
    cursor: default;
}

.course-preview,
.course-canvas {
    width: 100%;
    height: 100px;
    border-radius: 8px 8px 0 0;
    display: block;
}

.course-info {
    padding: 8px;
    text-align: center;
}

.course-name {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 2px;
}

.course-level {
    font-size: 11px;
    color: #aaa;
}

/* ===== Result Screen ===== */
#result-screen {
    background: rgba(10, 10, 30, 0.95);
}

.result-content {
    text-align: center;
    max-height: 100vh;
    overflow-y: auto;
    padding: 10px 15px 30px;
    box-sizing: border-box;
}

.result-position {
    font-size: 60px;
    font-weight: 900;
    margin-bottom: 10px;
}

.result-position.gold { color: #ffd700; }
.result-position.silver { color: #c0c0c0; }
.result-position.bronze { color: #cd7f32; }

.result-money {
    font-size: 28px;
    color: #33ff66;
    margin-bottom: 15px;
}

.result-standings {
    margin: 10px 0 15px;
}

.result-standings table {
    margin: 0 auto;
    border-collapse: collapse;
    font-size: 13px;
}

.result-standings th,
.result-standings td {
    padding: 5px 12px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.result-standings th {
    color: #aaa;
    font-size: 11px;
    text-transform: uppercase;
}

@media (max-height: 600px) {
    .result-position { font-size: 40px; margin-bottom: 5px; }
    .result-money { font-size: 22px; margin-bottom: 10px; }
    .result-standings table { font-size: 11px; }
    .result-standings th, .result-standings td { padding: 3px 8px; }
    .result-content { padding: 5px 10px 20px; }
}

/* ===== Settings Screen ===== */
.settings-content {
    width: 100%;
    max-width: 500px;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group label {
    display: block;
    font-size: 14px;
    color: #aaa;
    margin-bottom: 8px;
}

.setting-group input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ff6b35;
    cursor: pointer;
}

.quality-options {
    display: flex;
    gap: 12px;
}

.quality-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.quality-btn.active {
    border-color: #ff6b35;
    background: rgba(255, 107, 53, 0.2);
}

/* ===== Pause Menu ===== */
#pause-menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 300;
    backdrop-filter: blur(5px);
}

#pause-menu.hidden {
    display: none;
}

#pause-menu h2 {
    font-size: 36px;
    margin-bottom: 30px;
}

/* ===== Loading ===== */
#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0a0a2e;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s;
}

#loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: #ff6b35;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    margin-top: 20px;
    font-size: 16px;
    color: #aaa;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .game-title {
        font-size: 40px;
        letter-spacing: 4px;
    }

    .game-subtitle {
        font-size: 14px;
    }

    .menu-btn {
        width: 220px;
        padding: 12px 24px;
        font-size: 16px;
    }

    .menu-btn.primary {
        font-size: 20px;
        padding: 16px 32px;
    }

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

    .hud-speed {
        font-size: 28px;
    }

    .hud-minimap {
        width: 120px;
        height: 120px;
    }

    .weapon-cards {
        flex-direction: column;
        align-items: center;
    }

    .panel-screen {
        flex-direction: column;
    }

    .panel-sidebar {
        width: 100%;
        height: 40%;
    }
}

/* ===== Portrait Orientation Warning ===== */
#orientation-warning {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 30, 0.97);
    z-index: 99999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

#orientation-warning.dismissed {
    display: none !important;
}

.orientation-content {
    text-align: center;
    padding: 40px;
}

.orientation-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: rotateHint 2s ease-in-out infinite;
}

@keyframes rotateHint {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

.orientation-content h2 {
    font-size: 28px;
    margin-bottom: 10px;
    color: #ff6b35;
}

.orientation-content p {
    font-size: 16px;
    color: #888;
    margin-bottom: 30px;
}

#btn-continue-portrait {
    width: auto;
    padding: 12px 30px;
    font-size: 16px;
}

@media (orientation: portrait) and (max-width: 1024px) {
    #orientation-warning:not(.dismissed) {
        display: flex;
    }
}
