:root {
    --bg-main: #0b0f19;
    --panel-bg: rgba(17, 24, 39, 0.7);
    --panel-border: rgba(255, 255, 255, 0.08);
    --panel-glow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --text-primary: #f8fafc;
    --text-secondary: #a3b8cc;
    --text-muted: #98a6b8;
    --accent-primary: #a5b4fc;
    --accent-secondary: #c084fc;
    --accent-gradient: linear-gradient(135deg, #a5b4fc 0%, #d8b4fe 100%);
    --accent-glow: rgba(165, 180, 252, 0.35);
    --success: #34d399;
    --success-bg: rgba(52, 211, 153, 0.15);
    --success-border: rgba(52, 211, 153, 0.3);
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-bg: rgba(239, 68, 68, 0.15);
    --danger-border: rgba(239, 68, 68, 0.3);
    --warning: #fbbf24;
    --warning-bg: rgba(251, 191, 36, 0.15);
    --warning-border: rgba(251, 191, 36, 0.3);
    --road-color: #1e293b;
    --sky-color: linear-gradient(to bottom, #020617 0%, #0b0f19 100%);
    --grass-color: #064e3b;
}

body.light-mode {
    --bg-main: #f8fafc;
    --panel-bg: rgba(255, 255, 255, 0.75);
    --panel-border: rgba(0, 0, 0, 0.08);
    --panel-glow: 0 8px 32px 0 rgba(31, 38, 135, 0.06);
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #475569;
    --accent-primary: #3730a3;
    --accent-secondary: #4338ca;
    --accent-gradient: linear-gradient(135deg, #4338ca 0%, #6b21a8 100%);
    --accent-glow: rgba(67, 56, 202, 0.15);
    --success: #166534;
    --success-bg: rgba(22, 101, 52, 0.1);
    --success-border: rgba(22, 101, 52, 0.2);
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --danger-border: rgba(239, 68, 68, 0.2);
    --warning: #854d0e;
    --warning-bg: rgba(133, 77, 14, 0.1);
    --warning-border: rgba(133, 77, 14, 0.2);
    --road-color: #334155;
    --sky-color: linear-gradient(to bottom, #bae6fd 0%, #e0f2fe 100%);
    --grass-color: #059669;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    user-select: none;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* HUD / HUD bar Styles */
.game-hud {
    background: var(--panel-bg);
    border-bottom: 1px solid var(--panel-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 100;
}

.hud-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
}

.back-link {
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    padding: 8px 16px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--panel-border);
    font-size: 14px;
    transition: all 0.2s ease;
}

.back-link:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent-primary);
    transform: translateX(-2px);
}

.hud-stats {
    display: flex;
    gap: 12px;
}

.hud-stat-box {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 4px 14px;
    text-align: center;
    display: flex;
    flex-direction: column;
    min-width: 80px;
}

body.light-mode .hud-stat-box {
    background: rgba(0, 0, 0, 0.02);
}

.hud-stat-box .lbl {
    font-size: 9px;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    font-weight: 600;
}

.hud-stat-box .val {
    font-size: 15px;
    font-weight: 800;
    color: var(--accent-primary);
}

.score-box .val {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.streak-box .val {
    color: #ff7a45;
}

.theme-toggle-btn, .hud-btn {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--text-primary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s;
}

.theme-toggle-btn:hover, .hud-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--accent-primary);
}

/* Game Wrapper Layout */
.game-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
}

.game-view-viewport {
    position: relative;
    width: 100%;
    max-width: 1000px;
    height: 100%;
    background-color: var(--grass-color);
    border-radius: 20px;
    border: 2px solid var(--panel-border);
    overflow: hidden;
    box-shadow: var(--panel-glow);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

/* Background parallel/mountains styling */
.sky-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: var(--sky-color);
    z-index: 1;
    overflow: hidden;
}

.clouds {
    position: absolute;
    top: 15%;
    width: 200%;
    height: 40px;
    background-image: 
        radial-gradient(circle at 10% 80%, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.1) 20%, transparent 21%),
        radial-gradient(circle at 12% 70%, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0.08) 30%, transparent 31%),
        radial-gradient(circle at 15% 80%, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.1) 20%, transparent 21%),
        radial-gradient(circle at 80% 80%, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.1) 20%, transparent 21%),
        radial-gradient(circle at 83% 70%, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0.08) 30%, transparent 31%);
    background-size: 800px 40px;
    animation: drift-clouds 90s linear infinite;
}

@keyframes drift-clouds {
    from { background-position-x: 0px; }
    to { background-position-x: 800px; }
}

.mountains {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50px;
    background-image: linear-gradient(135deg, #1d4ed8 0%, #1e3a8a 100%);
    clip-path: polygon(0% 100%, 8% 40%, 15% 70%, 25% 30%, 35% 65%, 48% 20%, 60% 60%, 72% 35%, 85% 75%, 93% 45%, 100% 100%);
    opacity: 0.15;
    z-index: 2;
}

body.light-mode .mountains {
    background-image: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    opacity: 0.25;
}

/* Pseudo-3D Road Perspective */
.perspective-road-box {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    height: 70%;
    perspective: 250px;
    z-index: 3;
}

.road-surface {
    position: absolute;
    bottom: 0;
    left: 20%;
    width: 60%;
    height: 100%;
    background-color: var(--road-color);
    transform-origin: bottom center;
    transform: rotateX(75deg);
    border-left: 8px solid #fbbf24;
    border-right: 8px solid #fbbf24;
    overflow: hidden;
}

.road-lanes {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 200%;
    background-image: linear-gradient(to bottom, #f8fafc 50%, transparent 50%);
    background-size: 100% 80px;
    background-position: 0 0;
}

/* Road Scrolling active class */
.road-surface.scrolling .road-lanes {
    animation: scroll-road 0.6s linear infinite;
}

@keyframes scroll-road {
    from { background-position-y: 0px; }
    to { background-position-y: 80px; }
}

/* Dynamic Signpost Elements */
.signpost-item {
    position: absolute;
    width: 60px;
    height: 24vh;
    transform-origin: bottom center;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    bottom: 0; /* will animate top/depth */
}

/* Visual Pole */
.sign-pole {
    width: 4px;
    height: 100%;
    background: linear-gradient(to right, #64748b, #475569);
    box-shadow: 2px 0 5px rgba(0,0,0,0.3);
}

/* Traffic Sign Face Board */
.sign-board {
    width: 50px;
    height: 50px;
    background: #ffffff;
    border: 3px solid #ef4444;
    border-radius: 50%; /* circular standard sign */
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: absolute;
    top: 0;
}

.sign-board img {
    width: 82%;
    height: 82%;
    object-fit: contain;
}

/* Roadside Palm Trees Parallax */
.roadside-scenery {
    position: absolute;
    top: 30%;
    width: 100%;
    height: 70%;
    z-index: 4;
    pointer-events: none;
}

.palm-trees {
    position: absolute;
    bottom: 0;
    width: 25%;
    height: 100%;
}

.palm-trees.left {
    left: 0;
    background-image: radial-gradient(circle at 10% 50%, rgba(16, 185, 129, 0.15) 0%, transparent 60%);
}

.palm-trees.right {
    right: 0;
    background-image: radial-gradient(circle at 90% 50%, rgba(16, 185, 129, 0.15) 0%, transparent 60%);
}

/* Blue Hatchback Dashboard Car Styling */
.car-container {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    transition: transform 0.1s ease;
}

.car-svg {
    display: block;
}

/* Engine Vibration Animation when driving */
.car-container.engine-on {
    animation: engine-rumble 0.15s linear infinite;
}

@keyframes engine-rumble {
    0% { transform: translate(-50%, 0px); }
    50% { transform: translate(-50%, -1px); }
    100% { transform: translate(-50%, 1px); }
}

/* Exhaust Particles smoke */
.car-exhaust-particles {
    position: absolute;
    bottom: 2px;
    left: 35px;
    width: 1px;
    height: 1px;
    pointer-events: none;
}

.smoke-puff {
    position: absolute;
    background: rgba(156, 163, 175, 0.4);
    border-radius: 50%;
    animation: drift-smoke 0.8s ease-out forwards;
}

@keyframes drift-smoke {
    0% { transform: translate(0, 0) scale(4); opacity: 0.8; }
    50% { opacity: 0.4; }
    100% { transform: translate(-30px, 15px) scale(18); opacity: 0; }
}

/* Overlay Panels (Glassmorphic cards) */
.game-overlay-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    padding: 35px;
    max-width: 500px;
    width: 100%;
    max-height: 95%;
    overflow-y: auto;
    box-shadow: var(--panel-glow);
    text-align: center;
    animation: modal-enter 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modal-enter {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.overlay-icon {
    font-size: 55px;
    display: block;
    margin-bottom: 15px;
}

.game-overlay-panel h2 {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 10px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.text-muted {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 25px;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: var(--accent-gradient);
    color: #0b0f19;
    box-shadow: 0 4px 15px var(--accent-glow);
}

body.light-mode .btn-primary {
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-glow);
    filter: brightness(1.05);
}

.btn-warning {
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid var(--warning-border);
    color: var(--warning-text);
}

.btn-warning:hover {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: #0b0f19;
    border-color: transparent;
    transform: translateY(-2px);
}

body.light-mode .btn-warning:hover {
    color: white;
}

/* Questions Glass Card layout */
.question-glass-card {
    max-width: 580px;
    padding: 25px;
    text-align: left;
}

.question-glass-card h3 {
    font-size: 19px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.question-glass-card .ml-text {
    font-size: 15px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 20px;
}

.badge {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    color: var(--accent-primary);
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-block;
    margin-bottom: 12px;
}

.sign-closeup-container {
    width: 100%;
    height: 140px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--panel-border);
    margin-bottom: 20px;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.2);
}

body.light-mode .sign-closeup-container {
    background: rgba(0,0,0,0.02);
}

.sign-closeup-img {
    height: 80%;
    object-fit: contain;
}

.sign-closeup-container img {
    max-height: 110px;
    object-fit: contain;
}

/* Answer option buttons Grid */
.game-options-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.option-btn {
    width: 100%;
    text-align: left;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 12px 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
}

body.light-mode .option-btn {
    background: rgba(0,0,0,0.015);
}

.option-btn:hover {
    background: rgba(99, 102, 241, 0.06);
    border-color: rgba(99, 102, 241, 0.35);
    transform: translateX(3px);
}

.option-btn .opt-en {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.option-btn .opt-ml {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Answer Feedback Overlay */
.feedback-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 60;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.feedback-message {
    padding: 20px 40px;
    border-radius: 12px;
    font-size: 24px;
    font-weight: 800;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: feedback-pop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes feedback-pop {
    0% { transform: scale(0.6); opacity: 0; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.feedback-overlay.correct {
    display: flex;
    background: rgba(52, 211, 153, 0.15);
}

.feedback-overlay.correct .feedback-message {
    background: #34d399;
    color: #0b0f19;
}

.feedback-overlay.incorrect {
    display: flex;
    background: rgba(239, 68, 68, 0.15);
}

.feedback-overlay.incorrect .feedback-message {
    background: #ef4444;
    color: #ffffff;
}

/* Gameover Results Panel recap */
.results-recap {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.recap-box {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 12px 20px;
    min-width: 110px;
    text-align: center;
}

body.light-mode .recap-box {
    background: rgba(0,0,0,0.02);
}

.recap-box .lbl {
    font-size: 9px;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 4px;
}

.recap-box .val {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-primary);
}

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

/* Media Queries */
@media (max-width: 768px) {
    .hud-container {
        padding: 8px 12px;
    }
    
    .hud-stats {
        gap: 6px;
    }

    .hud-stat-box {
        min-width: 65px;
        padding: 2px 8px;
    }
    
    .hud-stat-box .val {
        font-size: 13px;
    }

    .back-link {
        padding: 6px 12px;
        font-size: 12px;
    }

    .theme-toggle-btn, .hud-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .game-wrapper {
        padding: 10px;
    }

    .game-view-viewport {
        border-radius: 12px;
    }

    .glass-panel {
        padding: 18px;
        max-width: 95%;
    }

    .question-glass-card h3 {
        font-size: 16px;
    }

    .question-glass-card .ml-text {
        font-size: 13px;
        margin-bottom: 12px;
    }

    .sign-closeup-container {
        height: 100px;
        margin-bottom: 12px;
    }

    .sign-closeup-container img {
        max-height: 80px;
    }

    .option-btn {
        padding: 10px 14px;
    }

    .option-btn .opt-en {
        font-size: 13px;
    }

    .option-btn .opt-ml {
        font-size: 11px;
    }

    /* Constrain the player car size on narrow screens */
    .car-container {
        transform: translateX(-50%) scale(0.85);
        bottom: 15px;
    }

    @keyframes engine-rumble {
        0% { transform: translate(-50%, 0px) scale(0.85); }
        50% { transform: translate(-50%, -1px) scale(0.85); }
        100% { transform: translate(-50%, 1px) scale(0.85); }
    }
}

/* Extra small height viewports (landscape mode or short screen mobiles) */
@media (max-height: 650px) {
    .glass-panel {
        padding: 12px 18px;
        max-height: 96vh;
        overflow-y: auto;
    }
    
    .question-glass-card {
        margin: 5px auto;
    }

    .question-glass-card h3 {
        font-size: 15px;
    }

    .question-glass-card .ml-text {
        font-size: 12px;
        margin-bottom: 8px;
    }

    .sign-closeup-container {
        height: 80px;
        margin-bottom: 10px;
    }

    .sign-closeup-container img {
        max-height: 65px;
    }

    .option-btn {
        padding: 8px 12px;
    }

    .option-btn .opt-en {
        font-size: 12.5px;
    }

    .option-btn .opt-ml {
        font-size: 11px;
        margin-top: 1px;
    }

    .game-overlay-panel {
        align-items: flex-start;
        overflow-y: auto;
        padding: 10px;
    }
    
    .car-container {
        transform: translateX(-50%) scale(0.7);
        bottom: 10px;
    }

    @keyframes engine-rumble {
        0% { transform: translate(-50%, 0px) scale(0.7); }
        50% { transform: translate(-50%, -1px) scale(0.7); }
        100% { transform: translate(-50%, 1px) scale(0.7); }
    }
}

/* Landscape Mode Adjustments for mobile viewports */
@media (orientation: landscape) and (max-height: 550px) {
    .question-glass-card {
        max-width: 90% !important;
        width: 90% !important;
        display: grid !important;
        grid-template-columns: 1fr 1.6fr !important;
        gap: 20px !important;
        align-items: center !important;
        padding: 12px 18px !important;
    }
    
    .sign-closeup-container {
        height: 100% !important;
        min-height: 140px !important;
        margin-bottom: 0 !important;
    }

    .sign-closeup-container img {
        max-height: 120px !important;
    }

    .question-glass-card h3 {
        font-size: 15px !important;
        margin-bottom: 3px !important;
        margin-top: 0 !important;
    }

    .question-glass-card .ml-text {
        font-size: 12px !important;
        margin-bottom: 8px !important;
    }

    .game-options-grid {
        gap: 8px !important;
    }

    .option-btn {
        padding: 8px 12px !important;
    }

    .option-btn .opt-en {
        font-size: 12.5px !important;
    }

    .option-btn .opt-ml {
        font-size: 11px !important;
    }
    
    .game-overlay-panel {
        align-items: center !important;
    }
    
    .car-container {
        transform: translateX(-50%) scale(0.65) !important;
        bottom: 8px !important;
    }

    @keyframes engine-rumble {
        0% { transform: translate(-50%, 0px) scale(0.65); }
        50% { transform: translate(-50%, -1px) scale(0.65); }
        100% { transform: translate(-50%, 1px) scale(0.65); }
    }
}
