/* ═══════════════════════════════════════════
 * Nisha.AI — Design System v2.1
 * Neural / Cyberpunk Aesthetic
   ═══════════════════════════════════════════ */

:root {
    --accent: #40e0d0;
    --accent-dim: rgba(64, 224, 208, 0.15);
    --accent-glow: rgba(64, 224, 208, 0.3);
    --purple: #007bff;
    --purple-dim: rgba(0, 123, 255, 0.15);
    --bg: #010a14;
    --surface: rgba(4, 15, 30, 0.75);
    --surface-hover: rgba(8, 25, 50, 0.85);
    --border: rgba(64, 224, 208, 0.15);
    --border-hover: rgba(64, 224, 208, 0.4);
    --text-primary: #ffffff;
    --text-secondary: #a0c4ff;
    --text-muted: #5e7ba8;
    --success: #00e676;
    --error: #ff5252;
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text-primary);
    font-family: var(--font-sans);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── AMBIENT GLOW ── */
.glow-orb {
    position: fixed;
    width: 700px;
    height: 700px;
    border-radius: 50%;
    filter: blur(120px);
    z-index: 0;
    pointer-events: none;
    animation: float 18s infinite alternate ease-in-out;
}
#glow-1 {
    background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
    top: -250px;
    left: -150px;
}
#glow-2 {
    background: radial-gradient(circle, rgba(99, 102, 241, 0.12) 0%, transparent 70%);
    bottom: -300px;
    right: -200px;
    animation-delay: -8s;
}
@keyframes float {
    0% { transform: translate(0, 0) scale(1); opacity: 0.3; }
    50% { transform: translate(30px, -20px) scale(1.1); opacity: 0.5; }
    100% { transform: translate(-20px, 15px) scale(0.95); opacity: 0.35; }
}

/* ── MAIN LAYOUT: Fullscreen Spline + Hologram Chat ── */
#app {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* ── IMMERSIVE 3D BACKGROUND ── */
#character-viewport {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background-color: transparent;
    z-index: 0;
}
#character-viewport::after {
    content: '';
    position: absolute;
    inset: 0;
    /* Soften and dim the artwork slightly so the 3D character and HUD UI remain legible */
    background: linear-gradient(to right, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.3) 50%, rgba(0,0,0,0.8) 100%);
    pointer-events: none;
    z-index: 1;
}

#spline-robot {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    display: block;
}

#spline-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Loading Overlay */
#loading-overlay {
    position: absolute;
    inset: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 50;
    transition: opacity 0.5s ease;
}
.loader-ring {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 3px;
    color: var(--accent);
}

/* HUD overlay on 3D viewport */
#character-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    z-index: 10;
}

.hud-brand {
    pointer-events: auto;
}
.logo {
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: 5px;
    color: var(--accent);
    text-shadow: 0 0 30px var(--accent-glow), 0 2px 8px rgba(0,0,0,0.8);
}
.sub {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 4px;
}

.hud-stats {
    display: flex;
    gap: 12px;
    align-self: flex-start;
}
.hud-stat {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(15px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.hud-stat-val { font-weight: 800; color: var(--accent); font-size: 1.1rem; }
.hud-stat-label { font-size: 0.55rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

.hud-status {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(15px);
    border: 1px solid var(--border);
    border-radius: 30px;
    padding: 8px 18px;
    align-self: flex-start;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-secondary);
}
.pulse {
    width: 8px; height: 8px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 12px var(--success);
    animation: blink 2s infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }

#voice-panel {
    display: flex;
    align-items: center;
    gap: 14px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(15px);
    border: 1px solid var(--border);
    border-radius: 30px;
    padding: 8px 18px;
    align-self: flex-start;
}
.voice-bars {
    display: flex; gap: 3px; align-items: flex-end; height: 18px;
}
.voice-bars span {
    width: 3px; background: var(--accent); border-radius: 2px;
    animation: bar-idle 1.5s infinite ease-in-out;
}
.voice-bars span:nth-child(1) { height: 5px; animation-delay: 0s; }
.voice-bars span:nth-child(2) { height: 9px; animation-delay: 0.15s; }
.voice-bars span:nth-child(3) { height: 13px; animation-delay: 0.3s; }
.voice-bars span:nth-child(4) { height: 9px; animation-delay: 0.45s; }
.voice-bars span:nth-child(5) { height: 5px; animation-delay: 0.6s; }
.voice-bars.active span { animation: bar-active 0.3s infinite ease-in-out alternate; }
@keyframes bar-idle { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(0.4); } }
@keyframes bar-active { 0% { transform: scaleY(0.3); } 100% { transform: scaleY(1.8); } }
.voice-label { font-family: var(--font-mono); font-size: 0.6rem; color: var(--text-muted); }

/* 3D Control Buttons */
#spline-controls {
    position: absolute;
    bottom: 24px;
    right: 24px;
    display: flex;
    gap: 8px;
    z-index: 20;
}
.ctrl-btn {
    width: 42px; height: 42px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(15px);
    border: 1px solid var(--border);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.ctrl-btn:hover {
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--accent-glow);
    transform: scale(1.1);
}

/* ── RIGHT: FLOATING CHAT UI ── */
#chat-section {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 600px;
    height: 80vh;
    display: flex;
    flex-direction: column;
    background: rgba(3, 6, 12, 0.85);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border: 1px solid rgba(64, 224, 208, 0.3);
    border-radius: var(--radius-lg);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.9), 0 0 40px rgba(64, 224, 208, 0.1);
    z-index: 1000;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}

#chat-section.active {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

/* Floating Robo Trigger */
#floating-trigger {
    position: absolute;
    bottom: 40px;
    right: 40px;
    width: 120px;
    height: 120px;
    background: radial-gradient(circle, rgba(64, 224, 208, 0.2) 0%, transparent 70%);
    border-radius: 50%;
    cursor: pointer;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    border: 1px solid rgba(64, 224, 208, 0.1);
}

#floating-trigger:hover {
    transform: scale(1.1);
    background: radial-gradient(circle, rgba(64, 224, 208, 0.3) 0%, transparent 70%);
    box-shadow: 0 0 30px rgba(64, 224, 208, 0.2);
}

#floating-trigger .trigger-label {
    position: absolute;
    top: -30px;
    background: var(--accent);
    color: #000;
    font-size: 0.6rem;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 4px;
    letter-spacing: 1px;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
}

#floating-trigger:hover .trigger-label {
    opacity: 1;
    transform: translateY(0);
}

#close-chat {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: color 0.2s;
}

#close-chat:hover {
    color: var(--error);
}

#chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(3, 6, 10, 0.5);
}
.header-tag { font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 2px; color: var(--text-muted); }
.header-topic { font-size: 0.65rem; color: var(--text-muted); }
.header-topic strong { color: var(--accent); }

/* Language Toggle */
.lang-select {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 700;
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
}
.lang-select:hover {
    border-color: var(--accent);
}
.lang-select option {
    background: var(--bg);
    color: var(--text-primary);
}

/* Temporal Ribbon */
#temporal-ribbon {
    display: flex;
    gap: 8px;
    padding: 10px 24px;
    border-bottom: 1px solid var(--border);
}
.temp-chip {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 6px 14px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
}
.temp-chip.past { background: rgba(245, 158, 11, 0.08); color: #f59e0b; border: 1px solid rgba(245, 158, 11, 0.2); }
.temp-chip.present { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(0, 229, 255, 0.2); }
.temp-chip.future { background: var(--purple-dim); color: var(--purple); border: 1px solid rgba(167, 139, 250, 0.2); }

/* Messages */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.05) transparent;
}
#chat-messages::-webkit-scrollbar { width: 5px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 10px; }

.msg-group {
    display: flex;
    gap: 12px;
    max-width: 90%;
    animation: msgSlide 0.35s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.msg-group.agent { align-self: flex-start; }
.msg-group.user { align-self: flex-end; flex-direction: row-reverse; }
@keyframes msgSlide { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.msg-avatar {
    width: 34px; height: 34px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 0.7rem; flex-shrink: 0;
}
.agent .msg-avatar { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(0,229,255,0.2); }
.user .msg-avatar { background: var(--purple-dim); color: var(--purple); border: 1px solid rgba(167,139,250,0.2); }

.msg-content { display: flex; flex-direction: column; gap: 5px; }
.msg-bubble {
    padding: 14px 18px; border-radius: 16px;
    font-size: 0.88rem; line-height: 1.6;
}
.agent .msg-bubble {
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text-primary); border-bottom-left-radius: 4px;
}
.user .msg-bubble {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff; border-bottom-right-radius: 4px;
}
.msg-meta { font-family: var(--font-mono); font-size: 0.55rem; color: var(--text-muted); padding: 0 4px; }
.user .msg-meta { text-align: right; }

.msg-bubble code { background: rgba(0,229,255,0.1); color: var(--accent); padding: 2px 7px; border-radius: 5px; font-family: var(--font-mono); font-size: 0.78rem; }
.msg-bubble strong { color: var(--accent); }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { margin: 14px 0 6px; color: var(--accent); font-size: 0.95rem; }
.msg-bubble ul, .msg-bubble ol { padding-left: 18px; margin: 6px 0; }
.msg-bubble li { margin: 3px 0; }
.msg-bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.msg-bubble p { margin: 6px 0; }

/* Typing */
#typing-indicator {
    display: none; align-items: center; gap: 10px;
    padding: 10px 24px; color: var(--accent);
    font-family: var(--font-mono); font-size: 0.65rem;
}
#typing-indicator.visible { display: flex; }
.typing-dots { display: flex; gap: 4px; }
.typing-dots span {
    width: 5px; height: 5px; background: var(--accent); border-radius: 50%;
    animation: dotPulse 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dotPulse { 0%, 80%, 100% { transform: scale(0.5); opacity: 0.3; } 40% { transform: scale(1); opacity: 1; } }

/* Input */
#input-area {
    padding: 18px 24px;
    background: rgba(3, 6, 10, 0.6);
    border-top: 1px solid var(--border);
    display: flex; gap: 10px; align-items: center;
}
#user-input {
    flex: 1;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 14px 18px;
    color: var(--text-primary); font-family: var(--font-sans); font-size: 0.88rem;
    outline: none; transition: all 0.3s ease;
}
#user-input::placeholder { color: var(--text-muted); }
#user-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
    background: var(--surface-hover);
}
#send-btn {
    width: 48px; height: 48px; border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent), #0097a7);
    border: none; color: #000; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s ease; flex-shrink: 0;
}
#send-btn:hover { transform: scale(1.05); box-shadow: 0 0 25px var(--accent-glow); }
#send-btn:active { transform: scale(0.95); }

/* Mic Button */
#mic-btn {
    width: 48px; height: 48px; border-radius: var(--radius-md);
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text-secondary); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.3s ease; flex-shrink: 0;
}
#mic-btn:hover { border-color: var(--accent); color: var(--accent); }
#mic-btn.recording {
    background: rgba(255, 50, 50, 0.15);
    border-color: #ff5252;
    color: #ff5252;
    animation: micPulse 1s infinite;
}
@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 82, 82, 0.4); }
    50% { box-shadow: 0 0 0 10px rgba(255, 82, 82, 0); }
}

/* Particle Canvas */
#particle-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 15;
}

/* Speaking glow on 3D viewport */
#character-viewport.speaking {
    box-shadow: inset 0 0 80px rgba(0, 229, 255, 0.12);
}
#character-viewport.speaking #spline-canvas {
    filter: brightness(1.15) contrast(1.05);
    transition: filter 0.5s ease;
}

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
    #chat-section { 
        top: auto; 
        bottom: 0; 
        left: 0 !important; 
        right: 0 !important;
        width: 100% !important;
        height: 75vh;
        transform: translateY(100%) !important;
        border-radius: 24px 24px 0 0;
        border: 1px solid rgba(64, 224, 208, 0.4);
        border-bottom: none;
    }

    #chat-section.active {
        transform: translateY(0) !important;
    }

    #floating-trigger {
        width: 100px;
        height: 100px;
        bottom: 20px;
        right: 20px;
    }

    #spline-canvas {
        width: 140px;
        height: 140px;
    }

    .logo { font-size: 1.6rem; letter-spacing: 3px; }
    .sub { font-size: 0.5rem; letter-spacing: 1px; }

    #character-hud {
        padding: 16px;
    }

    .hud-stats {
        gap: 8px;
    }

    .hud-stat {
        padding: 6px 12px;
    }

    .hud-stat-val { font-size: 0.9rem; }

    #spline-controls {
        top: 20px;
        right: 20px;
        bottom: auto;
        flex-direction: column;
    }

    /* Adjust chat internal spacing for mobile */
    #chat-header {
        padding: 12px 18px;
    }
    #chat-messages {
        padding: 16px;
    }
    #input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
    #user-input {
        padding: 10px 14px;
        font-size: 0.8rem;
    }
    #mic-btn, #send-btn {
        width: 44px;
        height: 44px;
    }
}
