:root {
    /* Color Palette: Deep Void & Clean Neon */
    --void-bg: #050005;
    --panel-bg: rgba(10, 12, 16, 0.98);
    --panel-border: 1px solid #333;
    
    --neon-cyan: #00f3ff;
    --neon-cyan-dim: rgba(0, 243, 255, 0.1);
    --neon-purple: #b026ff;
    --neon-crimson: #ff003c;
    --neon-green: #39ff14;
    
    --font-header: 'Orbitron', sans-serif;
    --font-body: 'Rajdhani', sans-serif;
    
    --ease-smooth: cubic-bezier(0.23, 1, 0.32, 1);
}

* {
    box-sizing: border-box;
    user-select: none; 
    -webkit-tap-highlight-color: transparent;
}

body, html {
    margin: 0; padding: 0; width: 100%; height: 100%;
    background-color: var(--void-bg); 
    color: #fff; 
    font-family: var(--font-body); 
    overflow: hidden; 
}

/* --- BACKGROUND --- */
#starfield-canvas { 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%; z-index: 10; pointer-events: none; }

/* --- PANEL SYSTEM --- */
section {
    position: absolute; width: 100%; height: 100%; 
    display: flex; flex-direction: column; justify-content: center; align-items: center; 
    background: rgba(0,0,0,0.4); 
    transition: opacity 0.4s var(--ease-smooth), transform 0.4s var(--ease-smooth); 
    pointer-events: all; 
}

.hidden-panel { opacity: 0; pointer-events: none; transform: scale(0.95); z-index: -1; }
.active-panel { opacity: 1; pointer-events: all; transform: scale(1); z-index: 100; }
.hidden-control { display: none !important; }

/* --- TYPOGRAPHY --- */
.game-title { 
    font-family: var(--font-header); font-size: 4rem; letter-spacing: 6px; 
    text-shadow: 0 0 20px var(--neon-cyan); margin-bottom: 0.5rem; text-align: center; 
    background: linear-gradient(to bottom, #fff, var(--neon-cyan)); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.logo-subtitle { 
    text-align: center; color: var(--neon-purple); font-weight: 700; letter-spacing: 12px; 
    font-size: 1.2rem; margin-bottom: 3rem; text-shadow: 0 0 10px var(--neon-purple);
}

/* --- BUTTONS --- */
.cyber-btn {
    background: rgba(0,0,0,0.8); border: 1px solid var(--neon-cyan); color: var(--neon-cyan); 
    padding: 15px 40px; font-family: var(--font-header); font-size: 1.1rem; cursor: pointer; 
    position: relative; overflow: hidden; transition: all 0.3s var(--ease-smooth); 
    width: 100%; max-width: 320px; margin: 10px 0; text-transform: uppercase; 
    clip-path: polygon(15px 0, 100% 0, 100% calc(100% - 15px), calc(100% - 15px) 100%, 0 100%, 0 15px);
}
.cyber-btn:hover { 
    background: var(--neon-cyan); color: #000; 
    box-shadow: 0 0 30px var(--neon-cyan-dim); 
    transform: translateY(-2px);
}
.cyber-btn:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(1); }

.crimson-glow { border-color: var(--neon-crimson); color: var(--neon-crimson); }
.crimson-glow:hover { background: var(--neon-crimson); color: #fff; }

.purple-glow { border-color: var(--neon-purple); color: var(--neon-purple); }
.purple-glow:hover { background: var(--neon-purple); color: #fff; }

.icon-btn { background: none; border: none; color: #666; cursor: pointer; transition: color 0.2s; font-size: 1.2rem; }
.icon-btn:hover { color: #fff; }
.icon-btn.warning:hover { color: var(--neon-crimson); }

/* --- GLASS PANELS --- */
.glass-panel { 
    background: var(--panel-bg); 
    backdrop-filter: blur(20px); 
    border: 1px solid #333; 
    border-radius: 4px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5); 
    position: relative;
    overflow: hidden;
}
.glass-panel::before {
    content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 2px;
    background: linear-gradient(90deg, transparent, var(--neon-cyan), transparent);
    opacity: 0.5;
}

/* --- LOBBY GRID ARCHITECTURE --- */
.lobby-header { 
    width: 95%; display: flex; justify-content: space-between; align-items: center; 
    margin-bottom: 15px; border-bottom: 1px solid #333; padding-bottom: 15px; 
}
.code-readout { 
    font-family: monospace; color: var(--neon-cyan); background: rgba(0, 243, 255, 0.05); 
    padding: 5px 12px; border: 1px solid var(--neon-cyan); border-radius: 4px; margin-left: 15px; 
    box-shadow: 0 0 10px var(--neon-cyan-dim);
}

.lobby-grid { 
    display: grid; 
    grid-template-columns: 350px 1fr 350px; 
    grid-template-rows: 1fr 200px;
    grid-template-areas: 
        "manifest hangar chat"
        "manifest hangar diag";
    gap: 20px; 
    width: 95%; height: 75%; 
}

/* Area Assignments */
.area-manifest { grid-area: manifest; display: flex; flex-direction: column; }
.area-hangar { grid-area: hangar; display: flex; flex-direction: column; position: relative; border: 1px solid var(--neon-cyan); box-shadow: 0 0 20px rgba(0,243,255,0.05); }
.area-chat { grid-area: chat; display: flex; flex-direction: column; }
.area-diag { grid-area: diag; display: flex; flex-direction: column; position: relative; }

/* Panel Headers */
h3 { 
    margin: 0; padding: 15px; font-size: 0.9rem; letter-spacing: 2px; color: #888; 
    background: rgba(255,255,255,0.02); border-bottom: 1px solid #333; 
    display: flex; align-items: center; gap: 10px;
}
h3 i { color: var(--neon-purple); }

/* --- MANIFEST LIST --- */
.player-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex-grow: 1; }
.player-card { 
    padding: 15px; margin: 5px 10px; background: rgba(255,255,255,0.02); 
    border: 1px solid transparent; border-left: 3px solid #444; 
    display: flex; justify-content: space-between; align-items: center; 
    transition: all 0.2s;
}
.player-card.self { 
    border-left-color: var(--neon-cyan); 
    background: linear-gradient(90deg, rgba(0,243,255,0.05), transparent); 
}
.status-led {
    width: 8px; height: 8px; border-radius: 50%; background: #333; box-shadow: 0 0 0 2px #222;
}
.status-led.ready { background: var(--neon-green); box-shadow: 0 0 5px var(--neon-green); }
.status-led.host { background: var(--neon-purple); box-shadow: 0 0 5px var(--neon-purple); }

/* --- SQUADRON HANGAR CANVAS --- */
#squadron-canvas { width: 100%; height: 100%; background: #08080a; }

/* --- CHAT TERMINAL --- */
.chat-log { 
    flex-grow: 1; overflow-y: auto; padding: 15px; font-family: 'Rajdhani', monospace; font-size: 0.9rem; 
    display: flex; flex-direction: column; gap: 5px; 
}
.chat-msg { padding: 4px 8px; border-radius: 2px; background: rgba(0,0,0,0.2); }
.chat-msg.system { color: #666; font-style: italic; border-left: 2px solid #444; }
.chat-input-wrapper { display: flex; padding: 10px; border-top: 1px solid #333; }
.chat-input { 
    flex-grow: 1; background: transparent; border: none; color: #fff; outline: none; font-family: var(--font-body);
}

/* --- SYSTEM DIAGNOSTICS (Waterfall Canvas) --- */
#diag-canvas { width: 100%; height: 100%; position: absolute; top: 0; left: 0; z-index: 0; background: #050508; }
.diag-overlay {
    position: absolute; top: 10px; left: 10px; z-index: 10;
    text-align: left; background: rgba(0,0,0,0.5); padding: 5px; border: 1px solid #333;
}
.diag-text { font-size: 0.7rem; color: var(--neon-purple); font-family: monospace; }
.diag-text span { color: #fff; font-weight: bold; }

/* --- HANGAR OVERLAY (3-COLUMN UPGRADE) --- */
#panel-hangar { z-index: 200; background: rgba(5,5,8,0.98); padding: 40px; }
#hangar-container { 
    display: grid; 
    grid-template-columns: 1fr 300px 400px; /* LEFT | MIDDLE | RIGHT */
    width: 100%; height: 100%; 
    border: 1px solid #333; box-shadow: 0 0 100px rgba(0,0,0,0.8); 
}

/* LEFT: Visual Preview */
.hangar-visuals { 
    position: relative; display: flex; flex-direction: column; 
    background: radial-gradient(circle at center, #1a1a20 0%, #050505 100%); 
    border-right: 1px solid #333;
}
.visuals-header { padding: 20px; border-bottom: 1px solid #333; display: flex; justify-content: space-between; }
.hangar-preview { flex-grow: 1; display: flex; justify-content: center; align-items: center; }
.visuals-footer { padding: 20px; border-top: 1px solid #333; display: flex; flex-direction: column; gap: 10px; }

/* MIDDLE: Stats Radar */
.hangar-stats {
    background: #08080a; border-right: 1px solid #333;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    position: relative;
}
.stats-title {
    position: absolute; top: 20px; width: 100%; text-align: center;
    font-family: var(--font-header); color: #666; letter-spacing: 2px; font-size: 0.8rem;
}
#stats-canvas { width: 250px; height: 250px; }

/* RIGHT: Configuration */
.hangar-config { display: flex; flex-direction: column; background: #0a0a0a; overflow: hidden; }
.hangar-tabs { display: flex; border-bottom: 1px solid #333; }
.tab-btn { flex: 1; background: #111; border: none; color: #666; padding: 15px; cursor: pointer; font-family: var(--font-header); transition: all 0.2s; border-bottom: 2px solid transparent; }
.tab-btn:hover { background: #1a1a1a; color: #fff; }
.tab-btn.active { background: #0a0a0a; color: var(--neon-cyan); border-bottom-color: var(--neon-cyan); }

/* Tab Visibility Logic (FIXED) */
.tab-content { padding: 20px; overflow-y: auto; height: 100%; display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }

.control-group { margin-bottom: 20px; }
.group-title { font-size: 0.7rem; color: #666; text-transform: uppercase; margin-bottom: 10px; letter-spacing: 2px; font-weight: bold; }

/* Hex Color Grid */
.hex-grid { 
    display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; justify-content: center;
}
.hex-btn {
    width: 30px; height: 34px; 
    background-color: #333; 
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    cursor: pointer; transition: transform 0.2s; border: none;
}
.hex-btn:hover { transform: scale(1.2); z-index: 10; }
.hex-btn.selected { 
    box-shadow: inset 0 0 10px #fff; 
    transform: scale(1.1); z-index: 5;
    border: 2px solid #fff; 
}

.pattern-list { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.pattern-btn { 
    padding: 10px; background: #111; border: 1px solid #333; color: #888; 
    cursor: pointer; font-size: 0.8rem; text-align: center; transition: all 0.2s; 
}
.pattern-btn:hover { background: #222; color: #fff; border-color: #666; }
.pattern-btn.selected { 
    background: rgba(0,243,255,0.1); border-color: var(--neon-cyan); color: var(--neon-cyan); 
}

/* Chassis Selection */
.chassis-list { display: flex; flex-direction: column; gap: 10px; }
.chassis-card { 
    display: flex; align-items: center; gap: 15px; padding: 15px; background: #111; 
    border: 1px solid #333; color: #666; cursor: pointer; transition: all 0.2s; position: relative; overflow: hidden;
}
.chassis-card:hover { border-color: #666; color: #fff; }
.chassis-card.selected { 
    border-color: var(--neon-cyan); color: #fff; 
    background: linear-gradient(90deg, rgba(0,243,255,0.1), transparent); 
}
.chassis-card.selected::after {
    content: ''; position: absolute; top:0; left:0; width: 4px; height: 100%; background: var(--neon-cyan);
}

/* --- GAME HUD --- */
#panel-game { justify-content: space-between; padding: 30px; }
.hud-top { position: absolute; top: 30px; width: 100%; text-align: center; pointer-events: none; }
.timer-container { 
    display: inline-block; background: rgba(0,0,0,0.5); padding: 10px 30px; 
    border: 1px solid var(--neon-cyan); border-radius: 20px; 
}
#match-timer { font-size: 2rem; font-family: var(--font-header); color: var(--neon-cyan); text-shadow: 0 0 10px var(--neon-cyan); }

/* --- CRITICAL: HIDDEN ELEMENTS --- */
.overlay-center { display: none !important; }
.overlay-center.active { display: flex !important; }
.health-bar-container, .score-display, .hud-bottom-left, .hud-bottom-center { display: none !important; }

/* --- INPUTS --- */
.main-menu-controls { display: flex; flex-direction: column; align-items: center; gap: 15px; width: 300px; }
.input-wrapper { position: relative; width: 100%; }
.input-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--neon-purple); font-size: 0.9rem; }
input[type="text"] { width: 100%; background: rgba(0,0,0,0.5); border: 1px solid #444; padding: 15px 15px 15px 40px; color: #fff; font-family: var(--font-header); font-size: 1rem; outline: none; transition: all 0.2s; }
input[type="text"]:focus { border-color: var(--neon-cyan); box-shadow: 0 0 15px rgba(0,243,255,0.2); }

/* --- NOTIFICATIONS --- */
.notification-toast { position: fixed; top: 30px; left: 50%; transform: translateX(-50%) translateY(-20px); padding: 15px 30px; background: #111; border-left: 4px solid; color: #fff; font-family: var(--font-header); z-index: 9999; opacity: 0; transition: all 0.3s ease; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.notification-toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.notification-toast.info { border-color: var(--neon-cyan); }
.notification-toast.error { border-color: var(--neon-crimson); }

/* --- MOBILE CONTROLS --- */
#joystick-zone {
    position: absolute; bottom: 50px; right: 50px; width: 150px; height: 150px;
    background: rgba(255, 255, 255, 0.05); border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 50%; touch-action: none; display: none; /* Hidden by default on desktop */
}
#joystick-knob {
    position: absolute; top: 50%; left: 50%; width: 50px; height: 50px;
    background: rgba(0, 243, 255, 0.5); border-radius: 50%; transform: translate(-50%, -50%);
    box-shadow: 0 0 20px var(--neon-cyan); pointer-events: none;
}

@media (max-width: 1024px) {
    .lobby-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
        grid-template-areas: "hangar" "manifest" "chat" "diag";
        height: auto; overflow-y: auto; display: block;
    }
    .area-hangar { height: 300px; margin-bottom: 20px; }
    .glass-panel { margin-bottom: 20px; }
    #hangar-container { grid-template-columns: 1fr; }
    .hangar-visuals { height: 300px; order: -1; }
    .hangar-stats { height: 250px; order: -1; border-right: none; border-bottom: 1px solid #333; }
    #joystick-zone { display: block; }
}