:root {
    --primary: #ffffff;
    --primary-dim: rgba(255, 255, 255, 0.4);
    --secondary: #e0e0e0;
    --accent: #4fa3ff;
    --success: #66cc88;
    --bg-overlay: rgba(20, 30, 40, 0.4);
    --glass-border: rgba(255, 255, 255, 0.3);
    --font-head: 'Orbitron', sans-serif;
    --font-body: 'Rajdhani', sans-serif;
    --text-color: #ffffff;
    --modal-bg: rgba(20, 30, 40, 0.95);
    --modal-border: rgba(79, 163, 255, 0.5);
    --item-bg: rgba(255, 255, 255, 0.05);
    --item-border: rgba(255, 255, 255, 0.1);
    --item-hover: rgba(255, 255, 255, 0.1);
}

body.light-mode {
    --primary: #2b3a42;
    --primary-dim: rgba(43, 58, 66, 0.4);
    --secondary: #555555;
    --text-color: #000000;
    --bg-overlay: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(0, 0, 0, 0.2);
    --modal-bg: rgba(240, 240, 240, 0.95);
    --modal-border: rgba(0, 0, 0, 0.3);
    --item-bg: rgba(0, 0, 0, 0.05);
    --item-border: rgba(0, 0, 0, 0.1);
    --item-hover: rgba(0, 0, 0, 0.1);
}

body {
    margin: 0;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    font-family: var(--font-body);
    background-color: #2b3a42; /* Fallback */
    color: var(--text-color);
    user-select: none;
    touch-action: none;
}

/* --- UI Screen Containers --- */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* KEY: Allows clicks to pass through to canvas */
    z-index: 10;
}

.ui-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: transparent;
    z-index: 10;
    opacity: 1;
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: auto; /* Default for menus */
}

/* HUD must allow clicks through to game */
#hud {
    display: block;
    pointer-events: none !important;
}

.ui-screen.hidden {
    opacity: 0;
    pointer-events: none !important;
    transform: scale(1.05);
    visibility: hidden;
}

/* --- Typography --- */
h1 {
    font-family: var(--font-head);
    font-size: 3.5rem; /* Smaller for mobile fit */
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 5px;
    margin-bottom: 1.5rem;
    color: var(--text-color);
    text-align: center; /* Center the title */
    width: 100%; /* Ensure full width for centering */
    text-shadow: 0 4px 10px rgba(0,0,0,0.3);
    /* Removed neon glow */
}

h2 {
    font-family: var(--font-head);
    font-size: 2rem;
    color: var(--text-color);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--modal-border);
    padding-bottom: 0.5rem;
    display: inline-block;
}

/* --- Buttons --- */
.menu-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.btn {
    font-family: var(--font-head);
    font-size: 1.2rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    padding: 15px 40px;
    background: rgba(20, 30, 40, 0.85); /* Dark background for contrast against snow */
    color: #ffffff;
    border: 2px solid #4fa3ff; /* Blue accent border */
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    border-radius: 8px; /* Slightly squared for tech look */
    min-width: 220px;
    text-align: center;
    backdrop-filter: blur(5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.4), 0 0 15px rgba(79, 163, 255, 0.3);
    pointer-events: auto;
    touch-action: manipulation;
    margin: 10px 0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8); /* Strong text shadow */
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(79, 163, 255, 0.5);
    background: rgba(30, 45, 60, 0.95);
    border-color: #7bc0ff;
}

.btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.btn.primary {
    background: linear-gradient(135deg, #4fa3ff, #0056b3);
    border: none;
    box-shadow: 0 5px 20px rgba(0, 86, 179, 0.4);
}

.btn.secondary {
    background: transparent;
    border: 2px solid rgba(255,255,255,0.5);
}

.btn.icon-btn {
    min-width: 50px;
    width: 50px;
    height: 50px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1.5rem;
}

/* --- HUD --- */
/* #hud moved to top */

.hud-top {
    position: absolute;
    top: 20px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 20px;
    pointer-events: none; /* Container allows clicks through */
    z-index: 2;
}

.hud-top > * {
    pointer-events: auto; /* Children catch clicks */
}

.hud-bottom {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    pointer-events: none; /* Container allows clicks through */
    z-index: 2;
    width: 100%; /* Ensure full width but transparent */
}

.hud-bottom > * {
    pointer-events: auto; /* Children catch clicks */
}

/* Control Group - Vertical Stack */
.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Control Group Label */
.control-group label {
    font-family: var(--font-ui);
    color: white;
    font-size: 1.2rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    margin-bottom: 5px; /* Spacing below label */
    font-weight: 700;
}

/* Custom Range Slider */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%; /* Responsive width */
    max-width: 200px; /* Cap width */
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    outline: none;
    opacity: 0.9;
    transition: opacity .2s;
    margin: 0;
}

input[type=range]:hover {
    opacity: 1;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px; /* Slightly larger thumb */
    height: 24px;
    border-radius: 50%;
    background: #4fa3ff;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(79, 163, 255, 0.5);
    border: 2px solid white;
    margin-top: -9px; /* Center thumb: (24px thumb - 6px track) / 2 = 9px */
}

input[type=range]::-moz-range-thumb {
    appearance: none;
    border: 2px solid white;
    height: 24px;
    width: 24px;
    border-radius: 50%;
    background: #4fa3ff;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(79, 163, 255, 0.5);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

input[type=range]:focus {
    outline: none;
}

input[type=range]::-ms-track {
    width: 100%;
    cursor: pointer;
    background: transparent; 
    border-color: transparent;
    color: transparent;
}

/* Control Group Label */
.control-group label {
    font-family: var(--font-ui);
    color: white;
    font-size: 1.2rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    margin-right: 10px;
    font-weight: 700;
}

#camera-btn {
    position: absolute;
    /* Move to Top-Right area, below HUD top */
    top: 80px; 
    right: 20px;
    bottom: auto; /* Clear bottom */
    pointer-events: auto !important; /* Ensure clickable */
    z-index: 20; /* High z-index */
    width: 50px;
    height: 50px;
    background: rgba(0,0,0,0.6);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(5px);
}

#tap-btn {
    position: absolute;
    bottom: 120px; /* Above HUD bottom */
    left: 50%;
    transform: translateX(-50%);
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: rgba(79, 163, 255, 0.2); /* Accent tint */
    border: 3px solid rgba(255, 255, 255, 0.6);
    font-size: 3rem;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100; /* Increased z-index */
    pointer-events: auto !important;
    transition: all 0.1s;
    backdrop-filter: blur(5px);
    box-shadow: 0 0 20px rgba(79, 163, 255, 0.4);
    /* Animation pulse */
    animation: pulse-btn 2s infinite;
    -webkit-tap-highlight-color: transparent; /* Remove highlight on mobile */
    touch-action: manipulation; /* Optimize for touch */
}

#tap-btn.active {
    transform: translateX(-50%) scale(0.9);
    background: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.6);
}

@keyframes pulse-btn {
    0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4); }
    70% { box-shadow: 0 0 0 20px rgba(255, 255, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

#tap-btn:active {
    transform: translateX(-50%) scale(0.9);
    background: rgba(255, 255, 255, 0.4);
}

.stat-box {
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 15px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.2);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 5px;
    backdrop-filter: blur(5px);
}

/* --- Modals --- */
.modal {
    background: var(--modal-bg);
    padding: 25px; /* Reduced padding */
    border-radius: 15px;
    text-align: center;
    border: 2px solid var(--modal-border);
    box-shadow: 0 0 30px rgba(0,0,0,0.8);
    backdrop-filter: blur(10px);
    max-width: 90%;
    width: 400px;
    position: relative;
    pointer-events: auto;
    max-height: 85vh; /* Ensure it fits on screen */
    overflow-y: auto; /* Scroll if too tall */
    color: var(--text-color);
}

.large-modal {
    width: 600px;
    max-width: 95%;
}

/* Settings Modal Specific - Fit to Screen Readable */
#settings .modal {
    padding: 20px;
    width: 340px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
#settings h2 {
    font-size: 1.5rem;
    margin-bottom: 15px;
    padding-bottom: 10px;
}
#settings .setting-item {
    margin: 8px 0;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
#settings .setting-item label {
    font-size: 1.1rem;
    font-weight: 700;
}
#settings .btn {
    padding: 8px 15px;
    font-size: 0.9rem;
    height: auto;
    min-height: 36px;
}
#settings #close-settings {
    margin-top: 15px;
    height: 44px;
    font-size: 1.1rem;
    padding: 0 30px;
    width: 100%;
}
.language-cycler {
    display: flex;
    align-items: center;
    gap: 10px;
}
.language-cycler span {
    font-size: 1.1rem;
    min-width: 80px;
    text-align: center;
    font-weight: bold;
}
.arrow-btn {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    border-radius: 50%;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Shop Modal Compact but Readable */
#shop .modal {
    padding: 15px;
    width: 90%;
    max-width: 450px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
#shop h2 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    padding-bottom: 5px;
}
.shop-scroll {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 10px;
    padding-right: 5px;
}
#shop-items .shop-item {
    padding: 8px 12px;
    margin-bottom: 6px;
    min-height: 50px;
    border-radius: 8px;
}
#shop-items h3 {
    font-size: 1.1rem;
    margin: 0;
}
#shop-items p {
    font-size: 0.8rem;
    margin-bottom: 2px;
    line-height: 1.2;
}
#shop-items .btn {
    padding: 6px 12px;
    font-size: 0.9rem;
    height: 36px;
    min-width: 70px;
}
#close-shop {
    padding: 10px;
    font-size: 1.1rem;
    height: 44px;
    width: 100%;
    margin-top: 5px;
}

/* Shop Section Titles */
.shop-section-title {
    font-size: 0.8rem;
    color: var(--accent);
    margin: 2px 0 1px 0;
    text-align: left;
    width: 100%;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

/* Shop Item - Row Layout */
.shop-item {
    display: flex;
    flex-direction: row; /* Horizontal */
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    margin-bottom: 6px;
    background: var(--item-bg);
    border: 1px solid var(--item-border);
    border-radius: 8px;
    min-height: 50px;
    width: 100%;
    box-sizing: border-box;
}

.shop-item:hover {
    background: var(--item-hover);
}

.shop-item.equipped {
    background: rgba(79, 163, 255, 0.15);
    border-color: var(--accent);
}

/* Icon Preview */
.item-icon-preview {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: 1px solid var(--modal-border);
    flex-shrink: 0;
}

/* Item Info */
.item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    margin: 0 12px;
    overflow: hidden;
}

.item-info .name {
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: left;
    color: var(--text-color);
}

.item-info .desc {
    display: block;
    font-size: 0.75rem;
    color: var(--secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: left;
}

/* Shop Buttons */
.shop-action-btn {
    padding: 0 12px;
    font-size: 0.9rem;
    min-width: 80px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
    border: none;
    font-weight: 700;
    text-transform: uppercase;
}

.buy-btn {
    background: #ffcc00;
    color: #000;
}
.buy-btn:hover { background: #ffe066; }
.buy-btn:disabled { background: #555; color: #888; cursor: not-allowed; }

.apply-btn {
    background: var(--accent);
    color: white;
}
.apply-btn:hover { background: #7abaff; }

.active-btn {
    background: #66cc88;
    color: white;
    cursor: default;
    opacity: 0.8;
}

/* --- Ad Overlay --- */
#ad-overlay {
    background: rgba(0,0,0,0.95);
    z-index: 1000;
}
.ad-content {
    text-align: center;
}
.loader {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Animations --- */
@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* --- Media Queries --- */
@media (max-width: 768px) {
    h1 { font-size: 2.5rem; }
    .btn { padding: 12px 30px; font-size: 1rem; min-width: 180px; }
    
    .hud-top {
        flex-wrap: wrap;
        gap: 10px;
        top: 10px;
    }
    .stat-box { font-size: 0.9rem; padding: 5px 10px; }
    
    #camera-btn {
        top: 70px; /* Adjust for smaller screens */
        right: 15px;
        width: 45px;
        height: 45px;
    }
}

/* Landscape Mobile (e.g. 800x600ish aspect ratio or rotated phone) */
@media (max-height: 600px) {
    h1 { font-size: 2rem; margin-bottom: 0.5rem; }
    .menu-buttons {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
    }
    .btn { margin: 5px; min-width: 180px; padding: 8px 25px; }
    .modal { padding: 15px; width: 450px; }
    
    .shop-scroll { max-height: 40vh; }
    
    #tap-btn {
        bottom: 80px;
        width: 70px;
        height: 70px;
        font-size: 2.5rem;
    }
    
    .hud-bottom {
        bottom: 10px;
    }
    
    #camera-btn {
        top: 60px;
        width: 40px;
        height: 40px;
    }
}

/* --- Extra Mobile Tweaks --- */
@media (max-width: 600px) {
    h1 {
        font-size: 2.2rem !important; /* Force smaller title */
        margin-bottom: 0.5rem;
    }

    .btn {
        min-width: 160px !important; /* Even smaller buttons */
        padding: 10px 20px !important;
        font-size: 0.9rem !important;
        margin: 5px 0;
    }

    /* Fix for small buttons in UI */
    .arrow-btn {
        min-width: 32px !important;
        width: 32px !important;
        padding: 0 !important;
        margin: 0 5px !important;
    }

    #shop-items .btn {
        min-width: 70px !important;
        width: auto !important;
        padding: 6px 12px !important;
        margin: 0 !important;
    }

    .hud-top {
        top: 5px;
        gap: 5px;
    }

    .stat-box {
        padding: 4px 8px;
        font-size: 0.8rem;
    }

    #camera-btn {
        top: 50px; 
        right: 10px;
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    #tap-btn {
        width: 70px;
        height: 70px;
        bottom: 90px; 
        font-size: 2rem;
    }

    .hud-bottom {
        bottom: 10px;
        width: 95%; 
    }
    
    .control-group label {
        font-size: 1rem;
    }

    /* Modals fit screen */
    .modal {
        width: 95% !important;
        padding: 15px !important;
        max-height: 90vh;
    }
    
    .shop-item {
        padding: 5px 8px;
    }
}

/* --- Side Controls & Vertical Slider --- */
#side-controls {
    position: absolute;
    right: 15px;
    /* Center vertically between camera btn and bottom area */
    top: 50%;
    transform: translateY(-50%);
    -webkit-transform: translateY(-50%);
    z-index: 100;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.vertical-slider-group {
    position: relative; /* For absolute positioning of children */
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 30px;
    border: 1px solid rgba(255,255,255,0.2);
    backdrop-filter: blur(4px);
    width: 50px; /* Fixed width */
    height: 200px; /* Fixed height */
    display: flex;
    justify-content: center;
}

/* Label at the bottom */
.vertical-slider-group label {
    position: absolute;
    bottom: 15px;
    width: 100%;
    text-align: center;
    font-size: 0.7rem;
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 2px black;
    text-transform: uppercase;
    margin: 0;
}

#speed-slider {
    position: absolute;
    top: 45%; /* Slightly higher than center to leave room for label */
    left: 50%;
    /* Width is the length of the slider */
    width: 150px; 
    height: 20px;
    /* Center anchor, then rotate */
    transform: translate(-50%, -50%) rotate(-90deg);
    -webkit-transform: translate(-50%, -50%) rotate(-90deg);
    margin: 0;
}