:root {
    --primary: #2ecc71; /* Original Green */
    --primary-glow: rgba(46, 204, 113, 0.5);
    --secondary: #27ae60; /* Darker Green */
    --accent: #f1c40f; /* Gold */
    --danger: #e74c3c;
    --glass: rgba(0, 0, 0, 0.7);
    --glass-heavy: rgba(0, 0, 0, 0.9);
    --glass-border: rgba(255, 255, 255, 0.2);
    --text: #ffffff;
    --text-dim: #cccccc;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: 'Montserrat', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    background: #0f172a; /* Deep blue-black for depth */
}

#game-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

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

/* --- HUD --- */
.hud-top {
    position: absolute;
    top: 20px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 20px;
    pointer-events: none;
    padding: 0 20px;
    box-sizing: border-box;
    z-index: 2000; /* High Z-index to ensure visibility */
}

.hud-item {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 15px;
    padding: 8px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
}

.hud-item .label {
    font-size: 0.7rem;
    color: var(--text-dim);
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.hud-item .value {
    font-size: 1.5rem;
    font-weight: 900;
    color: white;
    text-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

#coins-container .value {
    color: var(--accent);
}

/* --- Powerup Timer --- */
#powerup-container {
    position: absolute;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.powerup-timer {
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    border: 1px solid var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.powerup-timer.hidden {
    display: none;
}

.powerup-timer .icon {
    font-size: 1.5rem;
}

.bar-bg {
    width: 150px;
    height: 10px;
    background: rgba(255,255,255,0.2);
    border-radius: 5px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #00ffff);
    width: 100%;
    transition: width 0.1s linear;
}

#magnet-text {
    font-weight: bold;
    color: white;
    min-width: 30px;
}

@keyframes popIn {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* --- Buttons --- */
button {
    pointer-events: auto;
    cursor: pointer;
    font-family: 'Montserrat', sans-serif;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: none;
    outline: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.main-btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    padding: clamp(12px, 4vw, 18px) clamp(30px, 8vw, 45px);
    font-size: clamp(1rem, 4vw, 1.2rem);
    font-weight: 900;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(46, 204, 113, 0.4);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    letter-spacing: 2px;
    width: 100%;
    max-width: clamp(200px, 70vw, 300px);
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
}

.main-btn:hover {
    transform: scale(1.05) translateY(-3px);
    box-shadow: 0 15px 30px rgba(0, 210, 255, 0.5);
}

.main-btn:active {
    transform: scale(0.95);
}

.icon-btn {
    background: var(--glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    padding: clamp(10px, 3vw, 15px) clamp(20px, 5vw, 30px);
    border-radius: 15px;
    font-weight: 700;
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: clamp(0.8rem, 2.5vw, 1rem);
}

.icon-btn:hover {
    background: var(--glass-heavy);
    transform: translateY(-2px);
}

.primary-btn {
    background: var(--primary);
    color: white;
    padding: clamp(10px, 3vw, 12px) clamp(30px, 8vw, 40px);
    border-radius: 12px;
    font-weight: 800;
    text-transform: uppercase;
    font-size: clamp(0.8rem, 2.5vw, 1rem);
}

.primary-btn.small {
    padding: 8px 25px;
    font-size: 0.8rem;
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: clamp(10px, 3vw, 12px) clamp(20px, 5vw, 25px);
    font-size: clamp(0.8rem, 2.5vw, 0.9rem);
    font-weight: 700;
    border-radius: 12px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: clamp(100px, 30vw, 120px);
    justify-content: center;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.game-over-buttons {
    display: flex;
    flex-direction: column;
    gap: clamp(10px, 3vw, 15px);
    margin-top: clamp(20px, 5vw, 30px);
    align-items: center;
    width: 100%;
}

.score-display {
    font-size: clamp(1.5rem, 6vw, 2rem);
    color: var(--accent);
    font-weight: 900;
    margin-bottom: clamp(15px, 4vw, 20px);
}

.camera-btn {
    position: absolute;
    bottom: clamp(15px, 4vw, 30px);
    right: clamp(15px, 4vw, 30px);
    background: var(--glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    padding: clamp(8px, 2.5vw, 12px) clamp(15px, 4vw, 20px);
    border-radius: 50px;
    font-weight: 700;
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: var(--shadow);
    font-size: clamp(0.7rem, 2vw, 0.9rem);
}

.camera-btn.hidden {
    display: none;
}

/* --- Screens --- */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, rgba(0, 40, 80, 0.4), rgba(0, 0, 0, 0.9));
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    pointer-events: auto;
    transition: opacity 0.4s ease, transform 0.4s ease;
    z-index: 1000;
    padding: 20px;
    box-sizing: border-box;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(1.05);
    display: none !important; /* Force hide to prevent overlay issues */
}

/* Ensure countdown overlay is special */
#countdown-overlay {
    background: rgba(0, 0, 0, 0.6) !important;
    backdrop-filter: blur(5px) !important;
    -webkit-backdrop-filter: blur(5px) !important;
    z-index: 3000 !important;
    display: none;
    justify-content: center;
    align-items: center;
}

#countdown-text {
    font-size: clamp(5rem, 20vw, 10rem);
    font-weight: 900;
    color: white;
    text-shadow: 0 0 30px var(--primary-glow);
    transition: transform 0.1s ease;
}

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

.glass {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: clamp(20px, 5vw, 40px);
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    max-width: 400px;
    width: 90%;
}

.game-title {
    font-size: clamp(2rem, 12vw, 4rem);
    font-weight: 900;
    margin: 0;
    color: #fff;
    text-shadow: 0 4px 0 var(--secondary), 0 8px 15px rgba(0,0,0,0.4);
    letter-spacing: -1px;
    line-height: 1;
    text-transform: uppercase;
}

.subtitle {
    font-size: clamp(0.7rem, 2.5vw, 1rem);
    color: var(--accent);
    letter-spacing: 4px;
    text-transform: uppercase;
    margin: 10px 0 30px 0;
    font-weight: 700;
}

.menu-footer {
    display: flex;
    gap: clamp(8px, 2vw, 15px);
    margin-top: clamp(20px, 5vw, 30px);
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

/* --- Settings --- */
.glass-panel {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid var(--glass-border);
    border-radius: 25px;
    padding: clamp(20px, 5vw, 40px);
    width: 100%;
    max-width: clamp(280px, 90vw, 400px);
    box-shadow: var(--shadow);
    box-sizing: border-box;
}

.settings-options {
    margin: clamp(15px, 4vw, 30px) 0;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(10px, 3vw, 15px) 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: #eee;
    font-weight: 600;
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
}

/* --- Loading --- */
.loader-content h1 {
    font-size: clamp(1.5rem, 8vw, 3rem);
    letter-spacing: clamp(5px, 2vw, 15px);
    margin-bottom: clamp(15px, 4vw, 30px);
}

.progress-container {
    width: clamp(200px, 60vw, 300px);
    height: clamp(4px, 1.5vw, 6px);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    overflow: hidden;
}

#progress-bar {
    height: 100%;
    width: 0;
    background: var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
    transition: width 0.3s ease;
}

/* --- Animations --- */
@keyframes slideInDown {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* --- Toggle Switch --- */
.switch {
    position: relative;
    display: inline-block;
    width: clamp(40px, 10vw, 50px);
    height: clamp(22px, 6vw, 26px);
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255,255,255,0.1);
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: clamp(14px, 4vw, 18px);
    width: clamp(14px, 4vw, 18px);
    left: 4px; bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(clamp(18px, 5vw, 24px)); }

/* --- Shop Modal --- */
.shop-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: all 0.3s ease;
    padding: 10px;
    box-sizing: border-box;
}

.shop-modal.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(1.1);
}

.shop-content {
    background: rgba(16, 23, 42, 0.95); /* Updated dark theme background */
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 15px; /* Reduced radius */
    width: 95%; /* Wider for mobile */
    max-width: 450px; /* Further Reduced max width */
    height: auto; /* Auto height based on content */
    max-height: 80vh; /* Limit height */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
}

.shop-header {
    padding: 10px 15px; /* Compact padding */
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: linear-gradient(to right, rgba(255,255,255,0.02), transparent);
    flex-shrink: 0; /* Prevent shrinking */
}

.shop-header h2 {
    margin: 0;
    font-size: 1.2rem; /* Compact title */
    background: linear-gradient(to right, #fff, var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 900;
    letter-spacing: 1px;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem; /* Smaller close button */
    cursor: pointer;
    transition: all 0.3s;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    width: 25px;
    height: 25px;
}

.close-btn:hover {
    color: white;
    background: rgba(255,255,255,0.1);
    transform: rotate(90deg);
}

.shop-tabs {
    display: flex;
    padding: 8px 12px; /* Compact padding */
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-shrink: 0;
}

.shop-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.05);
    color: var(--text-dim);
    padding: 6px 12px; /* Compact tabs */
    cursor: pointer;
    font-weight: 700;
    border-radius: 8px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    white-space: nowrap;
    font-size: 0.75rem; /* Smaller text */
    letter-spacing: 0.5px;
}

.tab-btn:hover {
    background: rgba(255,255,255,0.1);
    transform: translateY(-2px);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 3px 10px var(--primary-glow);
}

.shop-sections {
    flex: 1;
    overflow-y: auto;
    padding: 0 10px 10px; /* Compact padding */
    -webkit-overflow-scrolling: touch;
}

/* Custom Scrollbar */
.shop-sections::-webkit-scrollbar {
    width: 4px; /* Thinner scrollbar */
}
.shop-sections::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
}
.shop-sections::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}

.shop-section {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.shop-section.active {
    display: block;
}

.shop-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); /* Very compact items */
    gap: 8px; /* Tighter gap */
    margin-top: 5px;
    padding: 2px;
}

.shop-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 8px; /* Compact padding */
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    gap: 3px;
    position: relative;
    overflow: hidden;
}

.shop-item:before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.shop-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    border-color: rgba(255,255,255,0.2);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.shop-item:hover:before {
    opacity: 1;
}

.shop-item.selected {
    border-color: var(--primary);
    background: rgba(46, 204, 113, 0.1);
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.2);
}

.shop-item.locked {
    opacity: 0.6;
    filter: grayscale(0.8);
}

.item-icon {
    font-size: 1.2rem; /* Compact icons */
    margin-bottom: 2px;
    filter: drop-shadow(0 0 5px rgba(255,255,255,0.2));
    transition: transform 0.3s;
}

.shop-item:hover .item-icon {
    transform: scale(1.1) rotate(5deg);
}

.item-name {
    font-size: 0.65rem; /* Tiny text */
    font-weight: 700;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-price {
    font-size: 0.6rem; /* Tiny text */
    color: var(--accent);
    font-weight: 600;
    background: rgba(241, 196, 15, 0.1);
    padding: 1px 5px;
    border-radius: 6px;
    align-self: center;
}

/* Ensure buttons inside items are clickable */
.shop-item button {
    position: relative;
    z-index: 10;
    margin-top: 4px;
    pointer-events: auto; /* Ensure clicks work */
}

.buy-btn {
    background: linear-gradient(to right, #27ae60, #2ecc71);
    border: none;
    color: white;
    padding: 4px 10px; /* Smaller button */
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.buy-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(39, 174, 96, 0.4);
}

.select-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 4px 10px; /* Smaller button */
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.7rem;
    transition: background 0.2s;
}

.select-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.shop-footer {
    padding: 8px 15px; /* Compact padding */
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid rgba(255,255,255,0.05);
    flex-shrink: 0;
}

.coins-display {
    font-size: 0.9rem; /* Smaller text */
    font-weight: 700;
    color: var(--accent);
    background: rgba(0,0,0,0.4);
    padding: 4px 12px;
    border-radius: 10px;
    border: 1px solid rgba(241, 196, 15, 0.3);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* --- Mobile Controls Overlay --- */
#mobile-controls-info {
    position: absolute;
    bottom: clamp(10px, 3vw, 20px);
    left: 50%;
    transform: translateX(-50%);
    display: none; /* Controlled by JS and Media Query */
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    width: 100%;
    z-index: 5;
}

#mobile-controls-info.mobile-detected {
    opacity: 0.8;
}

@media (max-width: 800px) {
    #mobile-controls-info {
        display: flex;
    }
}

.touch-hint {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    padding: 6px 15px;
    border-radius: 12px;
    color: white;
    font-size: clamp(0.6rem, 2.5vw, 0.8rem);
    font-weight: 700;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-transform: uppercase;
    letter-spacing: 1px;
}

