/* --- RESET & BASE --- */
:root {
    --bg-color: #0b0c10;
    --primary: #45a29e;
    --primary-glow: rgba(69, 162, 158, 0.6);
    --secondary: #1f2833;
    --accent: #c5c6c7;
    --danger: #ff4c4c;
    --danger-glow: rgba(255, 76, 76, 0.6);
    --success: #66ff66;
    --warning: #ffcc00;
    --panel-bg: rgba(15, 20, 25, 0.85);
    --border-radius: 4px;
    --font-main: 'Quantico', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body, html {
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    overflow: hidden;
    font-family: var(--font-main);
    color: var(--accent);
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: #000;
    /* subtle scanline effect for military feel */
    background-image: repeating-linear-gradient(
        0deg,
        rgba(0,0,0,0.15),
        rgba(0,0,0,0.15) 1px,
        transparent 1px,
        transparent 2px
    );
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* --- UI LAYERS --- */
.ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    pointer-events: auto;
    transition: opacity 0.3s ease;
}

.ui-layer.hidden {
    opacity: 0;
    pointer-events: none;
    display: none; /* Changed from just opacity to fix pointer events fully */
}

.ui-layer.active {
    display: flex;
    opacity: 1;
}

.pointer-events-none {
    pointer-events: none !important;
}

/* --- PANELS & MODALS --- */
.panel {
    background: var(--panel-bg);
    border: 2px solid var(--primary);
    box-shadow: 0 0 20px var(--primary-glow), inset 0 0 20px rgba(0,0,0,0.8);
    border-radius: var(--border-radius);
    padding: 2rem;
    text-align: center;
    max-width: 90%;
    width: 450px;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    transform: translateY(0);
    animation: panelIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.panel.large {
    width: 800px;
    max-width: 95%;
}

@keyframes panelIn {
    0% { opacity: 0; transform: translateY(50px) scale(0.9); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

h1, h2, h3 {
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 1rem;
    text-shadow: 0 0 10px rgba(255,255,255,0.3);
}

.game-title {
    font-size: 4rem;
    font-weight: 700;
    color: var(--primary);
    text-shadow: 2px 2px 0px rgba(0,0,0,1), 4px 4px 20px var(--primary-glow);
    margin-bottom: 2rem;
    position: relative;
    letter-spacing: 5px;
}

.danger-text { color: var(--danger); text-shadow: 0 0 15px var(--danger-glow); }
.victory-text { color: var(--warning); text-shadow: 0 0 15px rgba(255, 204, 0, 0.6); }
.neon-text { color: var(--primary); text-shadow: 0 0 10px var(--primary-glow); }

/* --- BUTTONS --- */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.5rem;
    width: 100%;
}

button {
    font-family: var(--font-main);
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 1rem 2rem;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

button::before {
    content: '';
    position: absolute;
    top: 0; left: -100%; width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s ease;
}

button:hover::before { left: 100%; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border: 2px solid #fff;
    box-shadow: 0 0 15px var(--primary-glow);
}

.btn-primary:hover {
    background: #5cdbca;
    transform: scale(1.05);
    box-shadow: 0 0 25px var(--primary-glow);
}

.btn-secondary {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-secondary:hover {
    background: rgba(69, 162, 158, 0.2);
    transform: scale(1.02);
}

.btn-buy {
    background: var(--secondary);
    color: var(--accent);
    border: 1px solid var(--primary);
    padding: 0.5rem 1rem;
    font-size: 1rem;
    margin-top: 1rem;
    width: 100%;
}
.btn-buy:hover:not(:disabled) {
    background: var(--primary);
    color: #fff;
}
.btn-buy:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #555;
    color: #888;
}

/* --- LOGIN FORM --- */
.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 2rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    text-align: left;
    gap: 0.5rem;
}

.input-group label {
    color: var(--primary);
    font-weight: bold;
    letter-spacing: 1px;
}

.input-group input {
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--secondary);
    color: #fff;
    padding: 1rem;
    font-family: var(--font-main);
    font-size: 1.2rem;
    border-radius: var(--border-radius);
    transition: all 0.3s ease;
    outline: none;
}

.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
    background: rgba(255,255,255,0.05);
}

.pulse {
    animation: pulseGlow 2s infinite;
}
@keyframes pulseGlow {
    0% { box-shadow: 0 0 10px var(--primary-glow); }
    50% { box-shadow: 0 0 30px var(--primary-glow), inset 0 0 10px rgba(255,255,255,0.5); }
    100% { box-shadow: 0 0 10px var(--primary-glow); }
}

/* --- HUD --- */
#ui-hud {
    justify-content: space-between;
    padding: 1.5rem;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: flex-start;
}

.hud-item {
    background: rgba(11, 12, 16, 0.8);
    border: 2px solid var(--secondary);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    backdrop-filter: blur(3px);
}

.health-container .bar-bg {
    width: 150px;
    height: 15px;
    background: #333;
    border-radius: 2px;
    overflow: hidden;
    border: 1px solid #111;
}

.bar-fill {
    height: 100%;
    transition: width 0.2s ease, background-color 0.2s ease;
}

.bar-fill.health { background: var(--success); }
.bar-fill.health.low { background: var(--danger); animation: pulseDanger 1s infinite; }

@keyframes pulseDanger {
    0% { background: var(--danger); }
    50% { background: #ffaaaa; }
    100% { background: var(--danger); }
}

.hud-center {
    text-align: center;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}
.level-display { font-size: 2rem; font-weight: bold; color: var(--warning); letter-spacing: 2px;}
.score-display { font-size: 1.2rem; color: #fff; }

.hud-bottom {
    width: 100%;
    display: flex;
    justify-content: center;
    padding-bottom: 2rem;
}

.reload-container {
    text-align: center;
}
.reload-container .bar-bg {
    width: 200px;
    height: 8px;
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--primary);
    border-radius: 4px;
}
.bar-fill.reload { background: var(--warning); width: 0%; }

.minimap-container {
    position: absolute;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 154px;
    height: 154px;
    background: rgba(11, 12, 16, 0.8);
    border: 2px solid var(--primary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 10px rgba(0,0,0,0.8);
}
#minimap-canvas { display: block; }

/* --- SHOP / UPGRADES --- */
.upgrades-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin: 2rem 0;
    text-align: left;
}

.upgrade-card {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--secondary);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    transition: transform 0.2s, border-color 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}
.upgrade-card:hover { transform: translateY(-5px); border-color: var(--primary); }
.upgrade-card h3 { font-size: 1.2rem; color: #fff; margin-bottom: 0.5rem; }
.u-desc { font-size: 0.9rem; color: #aaa; margin-bottom: 1rem; flex-grow: 1;}
.u-stats { font-weight: bold; color: var(--warning); }
.currency-display { font-size: 1.5rem; color: var(--success); font-weight: bold; text-shadow: 0 0 10px rgba(102, 255, 102, 0.5);}

/* --- INSTRUCTIONS --- */
.instruction-grid {
    display: flex;
    justify-content: space-around;
    margin: 2rem 0;
    gap: 1rem;
}
.inst-item {
    background: rgba(0,0,0,0.4);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #333;
}
.inst-item .icon { font-weight: bold; color: var(--primary); margin-bottom: 0.5rem; }
.intel { font-style: italic; color: #bbb; margin-bottom: 1.5rem; }

/* --- MOBILE CONTROLS --- */
#ui-mobile-controls {
    justify-content: flex-end;
    pointer-events: none; /* Let touches pass through to document where needed, but joysticks catch */
}

.virtual-joystick {
    position: absolute;
    bottom: 40px;
    width: 140px;
    height: 140px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    pointer-events: auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

#joystick-left { left: 40px; }
#joystick-right { right: 40px; }

.virtual-joystick .stick {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    position: absolute;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
    pointer-events: none;
    transform: translate(0, 0);
}

.fire-btn {
    position: absolute;
    top: -80px;
    right: 0;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(255, 76, 76, 0.6);
    border: 3px solid var(--danger);
    color: white;
    font-weight: bold;
    font-size: 1.2rem;
    pointer-events: auto;
    box-shadow: 0 0 15px var(--danger-glow);
}
.fire-btn:active { background: rgba(255, 76, 76, 0.9); transform: scale(0.95); }

/* --- UTILS --- */
.sound-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 100;
    background: rgba(11, 12, 16, 0.7);
    color: white;
    border: 1px solid #333;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    font-size: 1.2rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- RESPONSIVE ADJUSTMENTS --- */
@media (max-width: 768px) {
    .game-title { font-size: 2.2rem; }
    .hud-top { 
        flex-direction: column; 
        align-items: flex-start; 
        gap: 0.3rem; 
        width: calc(100% - 110px); /* Leave space for minimap */
    }
    .hud-center { width: auto; order: -1; margin-bottom: 0.2rem; text-align: left; }
    .panel { padding: 1rem; }
    .minimap-container { width: 90px; height: 90px; bottom: auto; top: 1.5rem; right: 1.5rem; }
    .hud-item { font-size: 0.8rem; padding: 0.4rem 0.6rem; }
    .health-container .bar-bg { width: 100px; height: 12px; }
    .level-display { font-size: 1.6rem; }
    .score-display { font-size: 1.1rem; }
    .instruction-grid { flex-direction: column; }
    #ui-mobile-controls { display: block; }
    .sound-toggle { top: auto; bottom: 1.5rem; left: auto; right: 1.5rem; transform: none; }
}

@media (min-width: 769px) {
    #ui-mobile-controls { display: none !important; }
}
