:root {
    /* --- ATOMIC AGE PALETTE --- */
    --color-teal: #2A9D8F;      /* Retro Teal - Primary Accent */
    --color-teal-bright: #4ECDC4; /* Hover state */
    --color-charcoal: #000000;  /* Background Deep */
    --color-dark: #1a2e38;      /* Panel Background */
    --color-orange: #F4A261;    /* Secondary Accent / Highlight */
    --color-red: #E76F51;       /* Alert / Danger */
    --color-yellow: #E9C46A;    /* Info / Gold */
    --color-cream: #FDF6E3;     /* Text / Paper White */
    
    /* UI Variables */
    --bg-main: var(--color-charcoal);
    --bg-panel: var(--color-dark);
    --border-color: var(--color-teal);
    --text-main: var(--color-cream);
    --shadow-retro: 6px 6px 0px 0px rgba(0,0,0,0.5);
    --shadow-retro-hover: 8px 8px 0px 0px rgba(0,0,0,0.6);
}

/* Font Imports handled in HTML, applied here */
body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--color-charcoal);
    color: var(--color-cream);
    /* Disable accidental text highlighting/drag-select across the whole UI. */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Keep real text fields selectable/editable so chat, search and auth still work. */
input, textarea, [contenteditable="true"] {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

body.is-desktop { overflow: hidden; }
body.is-mobile { overflow-x: hidden; overflow-y: auto; }

canvas { display: block; position: absolute; top: 0; left: 0; }

/* Prevent the browser from interpreting touch gestures so the game owns them. */
#gameCanvas { touch-action: none; -ms-touch-action: none; }

/* In-game black inset frame: ~1/2 inch (~48px) solid black band around the
   renderer, sitting above the canvas (static) but below the HUD (z-index >= 10).
   Visual only — never intercepts aim/click/touch. */
#renderer-border-frame {
    position: absolute;
    inset: 0;
    pointer-events: none;
    border: 48px solid #000;
    box-sizing: border-box;
    z-index: 5;
}

/* Black-hole proximity warning. Sits above the border frame (z 5) and most HUD.
   Opacity is driven inline by game.js (ramps up toward the core); the keyframe
   pulse keeps it alive/urgent. pointer-events:none so it never blocks input. */
#black-hole-warning {
    position: absolute;
    top: 12%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    pointer-events: none;
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    letter-spacing: 0.15em;
    font-size: clamp(1rem, 2.5vw, 1.75rem);
    color: #ff4d4d;
    text-shadow: 0 0 12px rgba(255, 77, 77, 0.9);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    animation: bhw-pulse 0.8s ease-in-out infinite;
}
#black-hole-warning.hidden { display: none; }
.bhw-icon { font-size: 1.3em; }
@keyframes bhw-pulse { 0%, 100% { filter: brightness(0.8); } 50% { filter: brightness(1.4); } }

/* --- Helper Utility Classes --- */
.text-teal { color: var(--color-teal) !important; }
.text-orange { color: var(--color-orange) !important; }
.text-yellow { color: var(--color-yellow) !important; }
.text-red { color: var(--color-red) !important; }
.text-cream { color: var(--color-cream) !important; }
.bg-charcoal { background-color: var(--color-charcoal) !important; }
.bg-dark { background-color: var(--color-dark) !important; }

/* --- Panel Styling (The Retro Look) --- */
.panel {
    background-color: var(--bg-panel);
    border: 3px solid var(--color-teal);
    border-radius: 16px; /* Modern rounded corners */
    box-shadow: var(--shadow-retro);
    padding: 24px;
    display: flex;
    flex-direction: column;
    max-width: 1200px;
    width: 100%;
    height: 650px;
    position: relative;
    overflow: hidden;
    /* Render main-menu panels at 90% size. Kept in sync with the panel-fade
       keyframes below so the entrance/exit animation doesn't drop the scale. */
    transform: scale(0.9);
    transform-origin: center center;
}

/* Decorative Striped Bar at Bottom of Panels */
.panel::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; width: 100%; height: 12px;
    background: repeating-linear-gradient(
        45deg,
        var(--color-orange),
        var(--color-orange) 10px,
        var(--color-charcoal) 10px,
        var(--color-charcoal) 20px
    );
    border-top: 2px solid var(--color-charcoal);
    z-index: 1;
}

.panel-header {
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--color-teal);
    margin-bottom: 1.5rem;
    font-family: 'Orbitron', sans-serif;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.panel-content-area {
    flex-grow: 1;
    overflow-y: auto;
    min-height: 0;
    padding-right: 8px;
}

/* --- Retro Buttons --- */
.retro-btn-primary {
    background-color: var(--color-orange);
    color: var(--color-charcoal);
    border: 2px solid var(--color-cream);
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    box-shadow: 4px 4px 0px 0px #000;
    transition: transform 0.1s, box-shadow 0.1s, background-color 0.2s;
    cursor: pointer;
}
.retro-btn-primary:hover {
    background-color: #ffb074; /* Lighter orange */
    transform: translate(-1px, -1px);
    box-shadow: 6px 6px 0px 0px #000;
}
.retro-btn-primary:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0px 0px #000;
}

.retro-btn-secondary {
    background-color: var(--color-teal);
    color: var(--color-charcoal);
    border: 2px solid var(--color-dark);
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    box-shadow: 4px 4px 0px 0px #000;
    transition: all 0.1s;
    cursor: pointer;
}
.retro-btn-secondary:hover {
    background-color: var(--color-teal-bright);
    transform: translate(-1px, -1px);
    box-shadow: 6px 6px 0px 0px #000;
}

/* --- Navigation Buttons --- */
.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    color: var(--color-cream);
    border-left: 4px solid transparent;
    transition: all 0.2s;
    opacity: 0.7;
    cursor: pointer;
}
.nav-btn:hover {
    background: linear-gradient(90deg, rgba(42, 157, 143, 0.2), transparent);
    border-left-color: var(--color-yellow);
    opacity: 1;
    color: var(--color-yellow);
}
.nav-btn.active {
    background: linear-gradient(90deg, rgba(244, 162, 97, 0.2), transparent);
    border-left-color: var(--color-orange);
    color: var(--color-orange);
    opacity: 1;
    text-shadow: 0 0 5px rgba(244, 162, 97, 0.5);
}

.sub-nav-btn {
    cursor: pointer;
    transition: all 0.2s;
}
.sub-nav-btn.active {
    color: var(--color-cream);
}

/* --- Game Mode Cards --- */
.game-mode-btn {
    background-color: rgba(0,0,0,0.2);
    border: 2px solid var(--color-charcoal);
    border-radius: 4px;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    cursor: pointer;
}
/* Scanline effect on cards */
.game-mode-btn::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: repeating-linear-gradient(45deg, transparent, transparent 5px, rgba(255,255,255,0.03) 5px, rgba(255,255,255,0.03) 10px);
    opacity: 0.5;
    pointer-events: none;
}
.game-mode-btn:hover {
    border-color: var(--color-teal);
    background-color: rgba(42, 157, 143, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

/* --- Main Menu / Campaign Buttons --- */
.main-menu-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    text-align: center;
    transition: background-color 0.3s;
    cursor: pointer;
}
.main-menu-btn-title {
    font-size: 2.5rem;
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
}

/* --- News Items --- */
.news-item {
    background-color: rgba(0,0,0,0.2);
    border-left: 4px solid var(--color-yellow);
    padding: 12px;
    margin-bottom: 8px;
    font-family: 'Inter', sans-serif;
}
.news-title {
    color: var(--color-yellow);
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    margin-bottom: 4px;
}
.news-date {
    color: var(--color-teal);
    font-size: 0.75rem;
    text-transform: uppercase;
    margin-bottom: 4px;
}
.news-content {
    font-size: 0.9rem;
    color: #ddd;
    line-height: 1.4;
}

/* --- Form Elements / Sliders --- */
.custom-slider {
    -webkit-appearance: none;
    height: 12px;
    background: var(--color-charcoal);
    border: 1px solid var(--color-teal);
    outline: none;
    border-radius: 6px;
}
.custom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    background: var(--color-orange);
    border: 2px solid var(--color-cream);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}

/* --- Custom Scrollbars --- */
.custom-scrollbar::-webkit-scrollbar { width: 10px; }
.custom-scrollbar::-webkit-scrollbar-track { background: var(--color-charcoal); }
.custom-scrollbar::-webkit-scrollbar-thumb { 
    background: var(--color-teal); 
    border: 2px solid var(--color-charcoal); 
    border-radius: 5px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: var(--color-orange); }

/* --- Effects & Animations --- */
.shadow-retro { box-shadow: var(--shadow-retro); border-radius: 14px; }
.drop-shadow-retro { text-shadow: 4px 4px 0px rgba(0,0,0,0.8); }

/* Panel Transitions */
.panel-entering { animation: panel-fade-in 0.4s ease-out forwards; }
.panel-exiting { animation: panel-fade-out 0.3s ease-in forwards; }

@keyframes panel-fade-in {
    from { opacity: 0; transform: translateY(20px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(0.9); }
}
@keyframes panel-fade-out {
    from { opacity: 1; transform: translateY(0) scale(0.9); }
    to { opacity: 0; transform: translateY(20px) scale(0.9); }
}

/* Login / Join (auth) modal at 90% size, matching the main panels. */
#auth-modal > div {
    transform: scale(0.9);
    transform-origin: center center;
}

/* Chevron for Collapsibles */
.chevron {
    border-style: solid;
    border-width: 0 3px 3px 0;
    display: inline-block;
    padding: 4px;
    transition: transform 0.3s;
    margin-left: auto;
}
.chevron.down { transform: translateY(-2px) rotate(45deg); }
.chevron.right { transform: translateY(0px) rotate(-45deg); }

.collapsible-content {
    transition: max-height 0.4s ease-in-out, opacity 0.3s ease-in-out;
    max-height: 1000px;
    opacity: 1;
}
.collapsible-content.collapsed {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
}

/* Loading Mask Helper */
#loading-mask {
    /* Height manipulated by JS, transition handled here */
    transition: height 0.05s linear; 
}

/* Event Log Styling */
.log-entry {
    font-weight: bold;
    text-shadow: 1px 1px 0 #000;
    margin-bottom: 2px;
    animation: slideUpFade 0.3s ease-out forwards;
}
.log-user { color: var(--color-teal-bright); }
.log-other { color: var(--color-yellow); }
.log-entry.fade-out { opacity: 0; transition: opacity 1s; }

@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Device Visibility */
body.is-desktop .is-desktop-hidden { display: none !important; }
body.is-mobile .is-mobile-hidden { display: none !important; }

/* --- Mobile Virtual Controls --- */
#joystick-base {
    position: fixed;
    width: 160px;
    height: 160px;
    border: 2px solid rgba(253, 246, 227, 0.35);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(42,157,143,0.10), rgba(0,0,0,0.25));
    pointer-events: none;
    z-index: 20;
    box-shadow: 0 0 12px rgba(0,0,0,0.4);
}
#joystick-stick {
    position: fixed;
    width: 80px;
    height: 80px;
    border: 2px solid rgba(253, 246, 227, 0.7);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(244,162,97,0.65), rgba(42,157,143,0.45));
    pointer-events: none;
    z-index: 21;
    box-shadow: 0 0 8px rgba(0,0,0,0.5);
}

/* Mobile-only: show a faint resting joystick so the player can find it. */
body.is-mobile #joystick-base.joystick-resting {
    display: block !important;
    left: calc(env(safe-area-inset-left, 0px) + 80px - 80px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 140px - 80px);
    top: auto;
    opacity: 0.35;
}
body.is-mobile #joystick-stick.joystick-resting {
    display: block !important;
    left: calc(env(safe-area-inset-left, 0px) + 80px - 40px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 140px - 40px);
    top: auto;
    opacity: 0.45;
}

/* Safe-area padding for the ability bar on iPhones with home indicators. */
body.is-mobile #bottom-ui {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 32px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}
body.is-mobile #mobile-hud-top {
    top: calc(env(safe-area-inset-top, 0px) + 20px);
    left: calc(env(safe-area-inset-left, 0px) + 20px);
    right: calc(env(safe-area-inset-right, 0px) + 20px);
}
.hidden { display: none !important; }