/* --- 1. CORE THEME & LAYOUT --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600&family=JetBrains+Mono:wght@400;700&display=swap');

:root {
    --neon-red: #ef4444;
    --bg-dark: #050505;
    --glass: rgba(10, 10, 10, 0.75);
    --glass-border: rgba(239, 68, 68, 0.15);
}

* { box-sizing: border-box; }

body, html {
    margin: 0; padding: 0;
    background-color: var(--bg-dark);
    color: white;
    font-family: 'Inter', sans-serif;
    overflow-x: hidden; /* Prevents side-scroll on desktop too */
    scroll-behavior: smooth;
    cursor: crosshair;
}

/* --- 2. CRT SCANLINE --- */
body::after {
    content: ""; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    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));
    background-size: 100% 2px, 3px 100%;
    pointer-events: none; z-index: 99999;
    opacity: 0.15;
}

/* --- 3. MOUSE GLOW & NOISE --- */
#cursor-glow {
    position: fixed; width: 500px; height: 500px;
    background: radial-gradient(circle, rgba(239,68,68,0.08) 0%, transparent 60%);
    transform: translate(-50%, -50%); pointer-events: none; z-index: 1;
    mix-blend-mode: screen; transition: width 0.1s, height 0.1s;
}

.noise-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 9000; opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* --- 4. PRELOADER --- */
#preloader {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #000; z-index: 10000;
    display: flex; justify-content: center; align-items: center;
    transition: opacity 0.5s ease;
}
.terminal-loader { font-family: 'Courier New', monospace; text-align: center; }
.terminal-loader .text { color: #ef4444; margin-bottom: 10px; font-weight: bold; letter-spacing: 2px; }
.progress-bar { width: 200px; height: 4px; background: #333; margin: 0 auto; position: relative; }
.progress-bar .fill {
    height: 100%; background: #ef4444; width: 0%;
    animation: loadSystem 1.5s ease-in-out forwards;
    box-shadow: 0 0 10px #ef4444;
}
@keyframes loadSystem { 0% { width: 0%; } 100% { width: 100%; } }

/* --- 5. BACKGROUND EFFECTS --- */
#canvas-container { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
.red-pulse {
    position: fixed; top: 50%; left: 50%; width: 80vw; height: 80vw;
    background: radial-gradient(circle, rgba(239, 68, 68, 0.1) 0%, transparent 70%);
    transform: translate(-50%, -50%); filter: blur(80px); z-index: -2;
    animation: pulseGlow 6s infinite alternate ease-in-out;
}
@keyframes pulseGlow { 
    from { opacity: 0.2; transform: translate(-50%, -50%) scale(0.9); } 
    to { opacity: 0.6; transform: translate(-50%, -50%) scale(1.1); } 
}

/* --- 6. SCROLL REVEAL (RESTORED) --- */
.scroll-fade-section {
    opacity: 0;
    filter: blur(20px);
    transform: translateY(100px) scale(0.95);
    transition: all 1.2s cubic-bezier(0.25, 1, 0.5, 1);
}
.scroll-fade-section.visible {
    opacity: 1;
    filter: blur(0px);
    transform: translateY(0) scale(1);
}

/* --- 7. AI INTERFACE (LEFT SIDE + FIXES) --- */
.ai-interface { 
    position: fixed; 
    bottom: 30px; 
    left: 30px; 
    z-index: 9999; 
    display: flex; 
    flex-direction: column; 
    align-items: flex-start;
    /* Allows clicks to pass through empty space */
    pointer-events: none; 
}

/* The Avatar Button (RESTORED VISUALS) */
.ai-avatar-container {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid #ef4444;
    background: #000;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.3s;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
    pointer-events: auto; /* Clickable */
}

.ai-avatar-container:hover {
    transform: scale(1.1);
    box-shadow: 0 0 30px rgba(239, 68, 68, 0.8);
}

.ai-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.status-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #00ff00;
    border-radius: 50%;
    border: 2px solid #000;
    box-shadow: 0 0 5px #00ff00;
    animation: blink 2s infinite;
}
@keyframes blink { 50% { opacity: 0.5; } }

/* The Chat Box (FLEX FIX) */
.ai-chat-box {
    pointer-events: auto; /* Clickable */
    width: 350px;
    height: 400px;
    background: rgba(5, 5, 5, 0.95);
    border: 1px solid #ef4444;
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(0,0,0,0.9);
    display: flex; 
    flex-direction: column; /* Stack vertically */
    overflow: hidden;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    margin-bottom: 15px; /* Space above avatar */
    /* Hidden by default until toggled */
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: 0.3s;
}

/* When the container DOES NOT have the 'closed' class, show the box */
.ai-interface:not(.closed) .ai-chat-box {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Chat Header */
.chat-header {
    background: #111;
    padding: 12px 15px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #ef4444;
    font-weight: bold;
    min-height: 50px;
}

.close-chat {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 1.2rem;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Chat Input */
.chat-input-area {
    padding: 15px;
    border-top: 1px solid #333;
    display: flex;
    gap: 10px;
    background: #080808;
    min-height: 60px;
}

.chat-input-area input {
    flex: 1;
    background: #111;
    border: 1px solid #333;
    color: white;
    padding: 8px;
    border-radius: 4px;
}

/* --- 8. APPLY BUTTON (RIGHT SIDE - RESTORED) --- */
.side-apply-btn {
    position: fixed;
    top: 50%;
    right: 0; /* Stays on the right */
    transform: translateY(-50%) rotate(-90deg);
    transform-origin: right center;
    background: #ef4444;
    color: white;
    border: 2px solid #ef4444;
    padding: 15px 30px;
    font-weight: 900;
    font-size: 1rem;
    letter-spacing: 3px;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    z-index: 10000;
    border-radius: 6px 6px 0 0;
    box-shadow: -5px 0 20px rgba(239, 68, 68, 0.5);
    transition: 0.3s;
    margin-right: -2px; /* Tucks to edge */
}

.side-apply-btn:hover {
    background: black;
    color: #ef4444;
    box-shadow: -5px 0 30px rgba(239, 68, 68, 1);
    padding-bottom: 45px;
}

/* --- 9. MOBILE FIXES (FINAL CORRECTED) --- */
@media (max-width: 768px) {
    /* Hide the cursor glow to prevent horizontal scrolling */
    #cursor-glow { display: none !important; }
    
    /* Ensure no side-scroll */
    body, html { width: 100%; overflow-x: hidden; }

    /* AI Interface Adjustments */
    .ai-interface { 
        bottom: 20px; 
        left: 20px; 
        right: 20px; /* Prevents overflow */
        align-items: flex-start; /* <--- FIX: KEEPS IT ON THE LEFT */
    } 
    
    .ai-chat-box { 
        width: 100%; 
        max-width: 300px; /* Keeps it from getting too wide on phones */
        height: 50vh; 
        margin-bottom: 10px;
    }
}