/* ============================================
   CORESAPIAN - Cyberpunk Neural Interface
   Dark Space Future Hacker Theme
   ============================================ */

:root {
    /* Core Colors */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a25;

    /* Accent Colors */
    --cyan: #00f0ff;
    --cyan-dim: #00f0ff80;
    --cyan-glow: #00f0ff40;
    --magenta: #ff00ff;
    --magenta-dim: #ff00ff80;
    --orange: #ff6b00;
    --orange-dim: #ff6b0080;
    --green: #00ff6b;
    --green-dim: #00ff6b80;
    --red: #ff0040;
    --red-dim: #ff004080;

    /* Text Colors */
    --text-primary: #e0e0e0;
    --text-secondary: #808090;
    --text-dim: #505060;

    /* Terminal Colors */
    --terminal-bg: rgba(10, 10, 15, 0.92);
    --terminal-border: var(--cyan-dim);
    --terminal-header: rgba(0, 240, 255, 0.1);

    /* Fonts */
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --font-display: 'Orbitron', sans-serif;

    /* Sizing */
    --terminal-width: 500px;
    --terminal-height: 400px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

/* ============================================
   THREE.JS CANVAS
   ============================================ */

#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#canvas-container canvas {
    display: block;
}

/* ============================================
   OVERLAY EFFECTS
   ============================================ */

.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.1) 0px,
        rgba(0, 0, 0, 0.1) 1px,
        transparent 1px,
        transparent 3px
    );
    animation: scanline-flicker 0.1s infinite;
}

@keyframes scanline-flicker {
    0%, 100% { opacity: 0.03; }
    50% { opacity: 0.05; }
}

.vignette {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
    background: radial-gradient(
        ellipse at center,
        transparent 0%,
        transparent 40%,
        rgba(0, 0, 0, 0.4) 100%
    );
}

/* ============================================
   HUD ELEMENTS
   ============================================ */

.hud-top-left,
.hud-top-right {
    position: fixed;
    top: 20px;
    z-index: 10;
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.hud-top-left {
    left: 20px;
}

.hud-top-right {
    right: 20px;
    text-align: right;
}

.hud-label {
    color: var(--text-dim);
    margin-bottom: 2px;
}

.hud-value {
    color: var(--cyan);
    margin-bottom: 12px;
    text-shadow: 0 0 10px var(--cyan-glow);
}

/* ============================================
   TERMINAL OVERLAY
   ============================================ */

.terminal {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: var(--terminal-width);
    height: var(--terminal-height);
    z-index: 100;
    background: var(--terminal-bg);
    border: 1px solid var(--terminal-border);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 0 30px rgba(0, 240, 255, 0.1),
        inset 0 0 60px rgba(0, 240, 255, 0.02);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    overflow: hidden;
}

.terminal::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 20px;
    right: 20px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--cyan), transparent);
}

.terminal.minimized {
    height: 40px;
}

.terminal.minimized .terminal-body,
.terminal.minimized .terminal-footer {
    display: none;
}

.terminal.maximized {
    width: 800px;
    height: 600px;
}

/* Terminal Header */
.terminal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: var(--terminal-header);
    border-bottom: 1px solid rgba(0, 240, 255, 0.2);
    cursor: move;
}

.terminal-title {
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 700;
    color: var(--cyan);
    letter-spacing: 2px;
    text-shadow: 0 0 10px var(--cyan-glow);
}

.terminal-icon {
    margin-right: 8px;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

.terminal-controls {
    display: flex;
    gap: 8px;
}

.terminal-btn {
    width: 20px;
    height: 20px;
    border: 1px solid var(--cyan-dim);
    background: transparent;
    color: var(--cyan);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.terminal-btn:hover {
    background: var(--cyan);
    color: var(--bg-primary);
}

/* Terminal Body */
.terminal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Terminal Output */
.terminal-output {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    font-size: 12px;
    line-height: 1.6;
}

.terminal-output::-webkit-scrollbar {
    width: 6px;
}

.terminal-output::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.terminal-output::-webkit-scrollbar-thumb {
    background: var(--cyan-dim);
    border-radius: 3px;
}

.terminal-line {
    margin-bottom: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.terminal-line .timestamp {
    color: var(--text-dim);
    font-size: 10px;
}

.terminal-line .prefix {
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 2px;
    font-size: 10px;
    text-transform: uppercase;
}

.terminal-line.system .prefix {
    background: var(--cyan-dim);
    color: var(--bg-primary);
}

.terminal-line.user .prefix {
    background: var(--magenta-dim);
    color: var(--bg-primary);
}

.terminal-line.ai .prefix {
    background: var(--green-dim);
    color: var(--bg-primary);
}

.terminal-line.error .prefix {
    background: var(--red-dim);
    color: var(--bg-primary);
}

.terminal-line .message {
    flex: 1;
    min-width: 200px;
    color: var(--text-primary);
}

.terminal-line.ai .message {
    color: var(--green);
}

.terminal-line.error .message {
    color: var(--red);
}

/* Typing Animation */
.typing::after {
    content: '|';
    animation: cursor-blink 0.8s infinite;
    color: var(--green);
}

@keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Terminal Input */
.terminal-input-container {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-top: 1px solid rgba(0, 240, 255, 0.1);
    background: rgba(0, 0, 0, 0.3);
}

.input-prefix {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 10px;
}

.input-prefix .user {
    font-size: 10px;
    font-weight: 700;
    color: var(--magenta);
    text-transform: uppercase;
}

.input-prefix .arrow {
    color: var(--cyan);
}

.terminal-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 13px;
    caret-color: var(--cyan);
}

.terminal-input::placeholder {
    color: var(--text-dim);
}

/* Voice Button */
.voice-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--cyan-dim);
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-left: 10px;
}

.voice-btn:hover {
    border-color: var(--cyan);
    box-shadow: 0 0 15px var(--cyan-glow);
}

.voice-btn.active {
    background: var(--cyan);
    border-color: var(--cyan);
}

.voice-btn.active .mic-icon {
    fill: var(--bg-primary);
}

.mic-icon {
    width: 18px;
    height: 18px;
    fill: var(--cyan);
    transition: all 0.2s ease;
}

.voice-ripple {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--cyan);
    opacity: 0;
    animation: none;
}

.voice-btn.active .voice-ripple {
    animation: ripple 1s infinite;
}

@keyframes ripple {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.8);
        opacity: 0;
    }
}

/* Terminal Footer */
.terminal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    border-top: 1px solid rgba(0, 240, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
    font-size: 10px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-indicator .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
    animation: pulse 2s infinite;
}

.status-indicator.processing .dot {
    background: var(--orange);
    box-shadow: 0 0 8px var(--orange);
}

.status-indicator.error .dot {
    background: var(--red);
    box-shadow: 0 0 8px var(--red);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-text {
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.model-info {
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ============================================
   LOADING OVERLAY
   ============================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.loader-ring {
    position: absolute;
    width: 100px;
    height: 100px;
    border: 2px solid transparent;
    border-radius: 50%;
}

.loader-ring:nth-child(1) {
    border-top-color: var(--cyan);
    animation: spin 1.5s linear infinite;
}

.loader-ring:nth-child(2) {
    width: 80px;
    height: 80px;
    border-right-color: var(--magenta);
    animation: spin 1.2s linear infinite reverse;
}

.loader-ring:nth-child(3) {
    width: 60px;
    height: 60px;
    border-bottom-color: var(--orange);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.loader-text {
    margin-top: 80px;
    font-family: var(--font-display);
    font-size: 14px;
    color: var(--cyan);
    letter-spacing: 4px;
    text-transform: uppercase;
    animation: flicker 2s infinite;
}

@keyframes flicker {
    0%, 100% { opacity: 1; }
    92% { opacity: 1; }
    93% { opacity: 0.3; }
    94% { opacity: 1; }
    96% { opacity: 0.5; }
    97% { opacity: 1; }
}

.loader-progress {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .terminal {
        width: calc(100% - 20px);
        height: 300px;
        bottom: 10px;
        right: 10px;
    }

    .hud-top-left,
    .hud-top-right {
        display: none;
    }
}

/* ============================================
   GLITCH EFFECTS
   ============================================ */

.glitch {
    position: relative;
}

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

.glitch::before {
    left: 2px;
    text-shadow: -2px 0 var(--magenta);
    clip: rect(24px, 550px, 90px, 0);
    animation: glitch-anim 2s infinite linear alternate-reverse;
}

.glitch::after {
    left: -2px;
    text-shadow: -2px 0 var(--cyan);
    clip: rect(85px, 550px, 140px, 0);
    animation: glitch-anim 3s infinite linear alternate-reverse;
}

@keyframes glitch-anim {
    0% { clip: rect(30px, 9999px, 10px, 0); }
    5% { clip: rect(54px, 9999px, 98px, 0); }
    10% { clip: rect(23px, 9999px, 55px, 0); }
    15% { clip: rect(15px, 9999px, 12px, 0); }
    20% { clip: rect(75px, 9999px, 32px, 0); }
    25% { clip: rect(44px, 9999px, 66px, 0); }
    30% { clip: rect(12px, 9999px, 97px, 0); }
    35% { clip: rect(33px, 9999px, 24px, 0); }
    40% { clip: rect(95px, 9999px, 11px, 0); }
    45% { clip: rect(8px, 9999px, 75px, 0); }
    50% { clip: rect(62px, 9999px, 43px, 0); }
    55% { clip: rect(18px, 9999px, 82px, 0); }
    60% { clip: rect(48px, 9999px, 29px, 0); }
    65% { clip: rect(71px, 9999px, 91px, 0); }
    70% { clip: rect(26px, 9999px, 17px, 0); }
    75% { clip: rect(88px, 9999px, 58px, 0); }
    80% { clip: rect(41px, 9999px, 37px, 0); }
    85% { clip: rect(9px, 9999px, 78px, 0); }
    90% { clip: rect(67px, 9999px, 22px, 0); }
    95% { clip: rect(35px, 9999px, 69px, 0); }
    100% { clip: rect(52px, 9999px, 46px, 0); }
}

/* ============================================
   WEBGL FALLBACK VISUALIZATION
   ============================================ */

.webgl-fallback {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a0f 70%);
    z-index: 1;
}

.fallback-core {
    position: relative;
    width: 200px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fallback-inner {
    position: absolute;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #ffaa00, #ff6600, #ff0066);
    box-shadow: 
        0 0 30px #ff6600,
        0 0 60px #ff0066,
        inset 0 0 20px rgba(255, 100, 0, 0.5);
    animation: core-pulse 2s ease-in-out infinite;
}

.fallback-outer {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 2px solid rgba(0, 240, 255, 0.3);
    box-shadow: 
        0 0 20px rgba(0, 240, 255, 0.3),
        inset 0 0 20px rgba(0, 240, 255, 0.1);
    animation: core-rotate 10s linear infinite;
}

.fallback-ring {
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(0, 240, 255, 0.2);
    animation: ring-pulse 3s ease-in-out infinite;
}

.fallback-ring.ring-1 {
    width: 160px;
    height: 160px;
    animation-delay: 0s;
}

.fallback-ring.ring-2 {
    width: 200px;
    height: 200px;
    animation-delay: 1s;
}

.fallback-ring.ring-3 {
    width: 240px;
    height: 240px;
    animation-delay: 2s;
}

.fallback-message {
    margin-top: 40px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 3px;
    animation: text-flicker 3s infinite;
}

@keyframes core-pulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 0 30px #ff6600, 0 0 60px #ff0066, inset 0 0 20px rgba(255, 100, 0, 0.5);
    }
    50% { 
        transform: scale(1.1);
        box-shadow: 0 0 50px #ff6600, 0 0 100px #ff0066, inset 0 0 30px rgba(255, 100, 0, 0.7);
    }
}

@keyframes core-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes ring-pulse {
    0%, 100% { 
        opacity: 0.3;
        transform: scale(1);
    }
    50% { 
        opacity: 0.6;
        transform: scale(1.05);
    }
}

@keyframes text-flicker {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}
