/* Global Styling & Reset */
:root {
    --bg-dark: #07080d;
    --bg-panel: rgba(13, 15, 24, 0.75);
    --border-neon: rgba(0, 240, 255, 0.25);
    --neon-cyan: #00f0ff;
    --neon-pink: #ff007f;
    --neon-purple: #bc13fe;
    --neon-green: #39ff14;
    --neon-yellow: #fffb00;
    --font-header: 'Orbitron', sans-serif;
    --font-body: 'Inter', sans-serif;
    --glow-cyan: 0 0 10px rgba(0, 240, 255, 0.5), 0 0 20px rgba(0, 240, 255, 0.2);
    --glow-pink: 0 0 10px rgba(ff, 0, 127, 0.5), 0 0 20px rgba(ff, 0, 127, 0.2);
    --glow-green: 0 0 10px rgba(57, 255, 20, 0.5), 0 0 20px rgba(57, 255, 20, 0.2);
    --glow-yellow: 0 0 10px rgba(255, 251, 0, 0.5), 0 0 20px rgba(255, 251, 0, 0.2);
}

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

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

/* Neon Text Helpers */
.text-neon-cyan { color: var(--neon-cyan); text-shadow: var(--glow-cyan); }
.text-neon-pink { color: var(--neon-pink); text-shadow: var(--glow-pink); }
.text-neon-green { color: var(--neon-green); text-shadow: var(--glow-green); }
.text-neon-yellow { color: var(--neon-yellow); text-shadow: var(--glow-yellow); }

/* Scanlines Effect overlay */
body::before {
    content: " ";
    display: block;
    position: fixed;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    z-index: 9999;
    background-size: 100% 4px, 6px 100%;
    pointer-events: none;
}

/* Three.js Canvas Container */
#game-canvas-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* HUD Layer Setup */
.hud-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none; /* Let clicks pass to canvas except on panels */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

.hidden {
    display: none !important;
}

/* Holographic Panel */
.hud-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-neon);
    border-radius: 8px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37), inset 0 0 15px rgba(0, 240, 255, 0.05);
    pointer-events: auto; /* Enable hover/clicks on HUD panels */
    transition: all 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.hud-panel:hover {
    border-color: rgba(0, 240, 255, 0.45);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.45), 0 0 10px rgba(0, 240, 255, 0.1), inset 0 0 20px rgba(0, 240, 255, 0.08);
}

/* Header Status Bar */
.status-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 20px;
}

.stat-box {
    flex: 1;
    max-width: 260px;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.stat-box::after {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 3px; height: 100%;
    background-color: var(--neon-cyan);
    box-shadow: 0 0 8px var(--neon-cyan);
}

.stat-box:nth-child(1)::after { background-color: var(--neon-pink); box-shadow: 0 0 8px var(--neon-pink); }
.stat-box:nth-child(3)::after { background-color: var(--neon-yellow); box-shadow: 0 0 8px var(--neon-yellow); }
.stat-box:nth-child(4)::after { background-color: var(--neon-green); box-shadow: 0 0 8px var(--neon-green); }

.stat-box .label {
    font-family: var(--font-header);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: rgba(224, 230, 237, 0.6);
    margin-bottom: 4px;
}

.stat-box .value-container {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.stat-box .value {
    font-family: var(--font-header);
    font-size: 1.8rem;
    font-weight: 900;
    line-height: 1;
}

.stat-box .value-sub {
    font-family: var(--font-header);
    font-size: 1rem;
    color: rgba(224, 230, 237, 0.5);
}

.stat-box .separator {
    font-size: 1rem;
    color: rgba(224, 230, 237, 0.3);
    margin: 0 4px;
}

.stat-box .unit {
    font-family: var(--font-header);
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(224, 230, 237, 0.5);
    margin-left: 2px;
}

/* Core Integrity Health Bar */
.health-bar-bg {
    width: 100%;
    height: 4px;
    background: rgba(255, 0, 127, 0.1);
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

.health-bar-fill {
    height: 100%;
    background: var(--neon-pink);
    box-shadow: 0 0 8px var(--neon-pink);
    transition: width 0.4s cubic-bezier(0.075, 0.82, 0.165, 1);
}

/* Sidebars layout */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: calc(100vh - 150px);
}

.left-sidebar {
    align-self: flex-start;
    width: 220px;
}

.right-sidebar {
    align-self: flex-start;
    width: 280px;
}

/* Shop and Panels styles */
.panel-title {
    font-family: var(--font-header);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 2px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 240, 255, 0.15);
    background: rgba(0, 240, 255, 0.03);
    border-radius: 8px 8px 0 0;
}

.shop-panel {
    display: flex;
    flex-direction: column;
}

.shop-items {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.shop-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(224, 230, 237, 0.1);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

.shop-item:hover {
    background: rgba(0, 240, 255, 0.05);
    border-color: rgba(0, 240, 255, 0.3);
    transform: translateX(-4px);
}

.shop-item.active {
    background: rgba(0, 240, 255, 0.08);
    border-color: var(--neon-cyan);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.15);
}

/* Colored indicator dots for shop items */
.item-icon {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-right: 12px;
    box-shadow: 0 0 8px currentColor;
}
.laser-icon { background: var(--neon-cyan); color: var(--neon-cyan); }
.plasma-icon { background: var(--neon-pink); color: var(--neon-pink); }
.tesla-icon { background: var(--neon-purple); color: var(--neon-purple); }

.item-details {
    display: flex;
    flex-direction: column;
}

.item-name {
    font-family: var(--font-header);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.item-cost {
    font-family: var(--font-header);
    font-size: 0.7rem;
    color: rgba(224, 230, 237, 0.5);
    margin-top: 2px;
}

/* Tooltips */
.item-tooltip {
    position: absolute;
    right: 295px;
    top: 50%;
    transform: translateY(-50%) translateX(10px);
    width: 250px;
    padding: 15px;
    background: rgba(10, 11, 18, 0.95);
    border: 1px solid var(--neon-cyan);
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.2);
    border-radius: 6px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    z-index: 100;
}

.shop-item:hover .item-tooltip {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.item-tooltip h3 {
    font-family: var(--font-header);
    font-size: 0.8rem;
    color: var(--neon-cyan);
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(0, 240, 255, 0.2);
    padding-bottom: 4px;
}

.item-tooltip p {
    font-size: 0.7rem;
    line-height: 1.4;
    color: rgba(224, 230, 237, 0.8);
    margin-bottom: 10px;
}

.item-tooltip .stats {
    list-style: none;
    font-size: 0.65rem;
    font-family: var(--font-header);
    color: rgba(224, 230, 237, 0.6);
}

.item-tooltip .stats li {
    margin-bottom: 3px;
    display: flex;
    justify-content: space-between;
}

/* Inspector panel */
.inspector-panel {
    margin-top: 10px;
}

.inspector-content {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.unit-name {
    font-family: var(--font-header);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.inspect-stats {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.75rem;
    color: rgba(224, 230, 237, 0.7);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed rgba(224, 230, 237, 0.1);
    padding-bottom: 4px;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 6px;
}

/* Control buttons style */
.btn {
    font-family: var(--font-header);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    padding: 10px 16px;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
    border: 1px solid rgba(224, 230, 237, 0.2);
    color: #e0e6ed;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    outline: none;
}

.action-btn {
    font-size: 0.7rem;
    padding: 8px 12px;
    border-color: currentColor;
    background: rgba(255, 255, 255, 0.02);
}

.action-btn:hover {
    background: currentColor;
    color: #07080d !important;
}

.play-btn {
    width: 100%;
    padding: 15px;
    font-size: 0.9rem;
    font-weight: 900;
    color: var(--neon-cyan);
    border: 1px solid var(--neon-cyan);
    text-shadow: var(--glow-cyan);
    margin-bottom: 10px;
}

.speed-controls {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.speed-btn {
    flex: 1;
    font-family: var(--font-header);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 6px 0;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(224, 230, 237, 0.15);
    border-radius: 4px;
    color: rgba(224, 230, 237, 0.6);
    cursor: pointer;
    transition: all 0.2s ease;
}

.speed-btn.active {
    color: var(--neon-cyan);
    border-color: var(--neon-cyan);
    background: rgba(0, 240, 255, 0.08);
    box-shadow: 0 0 8px rgba(0, 240, 255, 0.2);
}

.utility-btn {
    width: 100%;
    font-size: 0.65rem;
    padding: 6px 0;
    color: rgba(224, 230, 237, 0.5);
    border-color: rgba(224, 230, 237, 0.1);
}

.utility-btn:hover {
    color: #fff;
    border-color: rgba(224, 230, 237, 0.3);
}

.controls-panel {
    padding: 12px;
}

.tutorial-panel {
    padding: 14px;
}

.mini-title {
    font-family: var(--font-header);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: rgba(224, 230, 237, 0.4);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.tutorial-panel ul {
    list-style: none;
    font-size: 0.65rem;
    color: rgba(224, 230, 237, 0.7);
    line-height: 1.6;
}

.tutorial-panel .key {
    color: var(--neon-cyan);
    font-weight: 600;
}

/* Pulse Glowing Animations */
@keyframes pulseGlowCyan {
    0% { box-shadow: 0 0 5px rgba(0, 240, 255, 0.4), inset 0 0 5px rgba(0, 240, 255, 0.1); }
    50% { box-shadow: 0 0 15px rgba(0, 240, 255, 0.7), inset 0 0 10px rgba(0, 240, 255, 0.2); }
    100% { box-shadow: 0 0 5px rgba(0, 240, 255, 0.4), inset 0 0 5px rgba(0, 240, 255, 0.1); }
}

.pulse-glow {
    animation: pulseGlowCyan 2.5s infinite;
}

.pulse-glow:hover {
    background: rgba(0, 240, 255, 0.08);
}

/* Fullscreen Overlays (Menus, Game Over) */
.overlay-panel {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1000;
    background: rgba(5, 6, 10, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

.loader-content {
    text-align: center;
    max-width: 480px;
    padding: 40px;
    border: 1px solid rgba(0, 240, 255, 0.15);
    background: rgba(13, 15, 24, 0.6);
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), inset 0 0 30px rgba(0, 240, 255, 0.02);
}

.loader-content h1 {
    font-family: var(--font-header);
    font-size: 3.5rem;
    font-weight: 900;
    letter-spacing: 6px;
    margin-bottom: 5px;
    line-height: 1;
}

.subtitle {
    font-family: var(--font-header);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 4px;
    color: rgba(224, 230, 237, 0.4);
    margin-bottom: 30px;
}

.loader-bar-container {
    width: 100%;
    height: 2px;
    background: rgba(224, 230, 237, 0.08);
    margin-bottom: 30px;
    overflow: hidden;
    position: relative;
}

.loader-bar {
    width: 40%;
    height: 100%;
    background: var(--neon-cyan);
    box-shadow: 0 0 8px var(--neon-cyan);
    position: absolute;
    animation: loadingBarSlide 1.8s infinite linear;
}

@keyframes loadingBarSlide {
    0% { left: -40%; }
    100% { left: 100%; }
}

.primary-btn {
    width: 100%;
    padding: 16px 0;
    font-size: 0.9rem;
    font-weight: 900;
    color: var(--neon-cyan);
    border: 1px solid var(--neon-cyan);
    text-shadow: var(--glow-cyan);
    background: rgba(0, 240, 255, 0.05);
}

.primary-btn:hover:not(.disabled) {
    background: var(--neon-cyan);
    color: #07080d;
    box-shadow: 0 0 20px var(--neon-cyan);
}

.primary-btn.disabled {
    opacity: 0.5;
    border-color: rgba(224, 230, 237, 0.15);
    color: rgba(224, 230, 237, 0.3);
    cursor: default;
    text-shadow: none;
}

.stats-summary {
    margin-bottom: 30px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-family: var(--font-header);
    font-size: 0.9rem;
    border-top: 1px solid rgba(224, 230, 237, 0.1);
    border-bottom: 1px solid rgba(224, 230, 237, 0.1);
    padding: 15px 0;
}

/* Glitch Title Text Effect */
.glitch-text {
    position: relative;
    color: var(--neon-cyan);
    text-shadow: var(--glow-cyan);
}

.glitch-text::before,
.glitch-text::after {
    content: attr(data-text);
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: transparent;
}

.glitch-text::before {
    left: 2px;
    text-shadow: -1px 0 var(--neon-pink);
    clip: rect(44px, 450px, 56px, 0);
    animation: glitchAnim 5s infinite linear alternate-reverse;
}

.glitch-text::after {
    left: -2px;
    text-shadow: -1px 0 var(--neon-green);
    clip: rect(85px, 450px, 140px, 0);
    animation: glitchAnim2 5s infinite linear alternate-reverse;
}

@keyframes glitchAnim {
    0% { clip: rect(15px, 9999px, 66px, 0); }
    10% { clip: rect(85px, 9999px, 5px, 0); }
    20% { clip: rect(125px, 9999px, 115px, 0); }
    30% { clip: rect(45px, 9999px, 15px, 0); }
    40% { clip: rect(10px, 9999px, 55px, 0); }
    50% { clip: rect(80px, 9999px, 95px, 0); }
    60% { clip: rect(110px, 9999px, 120px, 0); }
    70% { clip: rect(25px, 9999px, 40px, 0); }
    80% { clip: rect(60px, 9999px, 85px, 0); }
    90% { clip: rect(15px, 9999px, 130px, 0); }
    100% { clip: rect(95px, 9999px, 35px, 0); }
}

@keyframes glitchAnim2 {
    0% { clip: rect(70px, 9999px, 105px, 0); }
    10% { clip: rect(20px, 9999px, 45px, 0); }
    20% { clip: rect(95px, 9999px, 35px, 0); }
    30% { clip: rect(115px, 9999px, 125px, 0); }
    40% { clip: rect(30px, 9999px, 90px, 0); }
    50% { clip: rect(5px, 9999px, 65px, 0); }
    60% { clip: rect(135px, 9999px, 5px, 0); }
    70% { clip: rect(80px, 9999px, 110px, 0); }
    80% { clip: rect(45px, 9999px, 15px, 0); }
    90% { clip: rect(110px, 9999px, 75px, 0); }
    100% { clip: rect(55px, 9999px, 140px, 0); }
}

/* Flicker Animation for System Deficit screen */
@keyframes flicker {
    0%, 19.999%, 22%, 62.999%, 64%, 64.999%, 70%, 100% {
        opacity: 0.99;
        text-shadow: var(--glow-pink);
    }
    20%, 21.999%, 63%, 63.999%, 65%, 69.999% {
        opacity: 0.4;
        text-shadow: none;
    }
}
.flicker-text {
    animation: flicker 4s infinite;
}

.pulse-glow-pink {
    border-color: var(--neon-pink);
    color: var(--neon-pink);
    text-shadow: var(--glow-pink);
    background: rgba(255, 0, 127, 0.05);
}
.pulse-glow-pink:hover {
    background: var(--neon-pink);
    color: #07080d;
    box-shadow: 0 0 20px var(--neon-pink);
}

.pulse-glow-green {
    border-color: var(--neon-green);
    color: var(--neon-green);
    text-shadow: var(--glow-green);
    background: rgba(57, 255, 20, 0.05);
}
.pulse-glow-green:hover {
    background: var(--neon-green);
    color: #07080d;
    box-shadow: 0 0 20px var(--neon-green);
}

/* Custom Scrollbar for sidebars */
::-webkit-scrollbar {
    width: 4px;
}
::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.01);
}
::-webkit-scrollbar-thumb {
    background: rgba(0, 240, 255, 0.2);
    border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 240, 255, 0.5);
}
