/* ============================================
   NAKSHATRA — REDESIGNED UI
   Premium dark-mode companion interface
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Space+Grotesk:wght@300;400;500;600;700&display=swap');

/* ---- TOKENS ---- */
:root {
    --bg: #04040f;
    --surface: rgba(255,255,255,0.04);
    --surface-2: rgba(255,255,255,0.07);
    --border: rgba(255,255,255,0.08);
    --border-bright: rgba(139,92,246,0.4);

    --accent-1: #8B5CF6;   /* violet */
    --accent-2: #06B6D4;   /* cyan */
    --accent-glow: rgba(139,92,246,0.35);

    --text: #F1F0FF;
    --text-dim: rgba(241,240,255,0.45);
    --text-mid: rgba(241,240,255,0.7);

    --error: #F87171;
    --success: #34D399;

    --font-ui: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;

    --chat-drawer-height: 420px;
    --drawer-open: 1;
}

/* ---- RESET ---- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
}

/* ---- UTILITY ---- */
.hidden { display: none !important; }

/* ============================================
   BACKGROUND CANVAS (starfield)
   ============================================ */
#bg-canvas {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

/* ============================================
   ORB CANVAS
   ============================================ */
#orb-canvas {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

/* ---- Glow ring behind orb ---- */
#orb-glow-ring {
    position: fixed;
    left: 50%;
    top: 46%;
    transform: translate(-50%, -50%);
    width: 340px;
    height: 340px;
    border-radius: 50%;
    background: radial-gradient(ellipse at center,
        rgba(139,92,246,0.18) 0%,
        rgba(6,182,212,0.08) 50%,
        transparent 70%);
    z-index: 0;
    pointer-events: none;
    animation: glowPulse 4s ease-in-out infinite;
}
@keyframes glowPulse {
    0%, 100% { opacity: 0.7; transform: translate(-50%,-50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%,-50%) scale(1.06); }
}

/* ============================================
   LOGIN SCREEN
   ============================================ */
#login-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    backdrop-filter: blur(2px);
    animation: fadeIn 0.6s ease;
}

#login-card {
    width: 100%;
    max-width: 380px;
    background: rgba(10, 10, 25, 0.85);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius-xl);
    padding: 40px 36px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow:
        0 0 0 1px rgba(139,92,246,0.1),
        0 40px 80px rgba(0,0,0,0.6),
        0 0 80px rgba(139,92,246,0.12);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    animation: cardSlideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes cardSlideUp {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}
.brand-icon {
    width: 48px;
    height: 48px;
    background: rgba(139,92,246,0.15);
    border: 1px solid rgba(139,92,246,0.3);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.brand-name {
    font-family: var(--font-ui);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    background: linear-gradient(135deg, #fff 40%, #A78BFA);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.brand-tagline {
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-top: 2px;
}

.login-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-bright), transparent);
}

.login-prompt {
    font-size: 0.875rem;
    color: var(--text-mid);
    line-height: 1.5;
}

.input-wrapper {
    position: relative;
}
.input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    pointer-events: none;
}
.input-wrapper input {
    width: 100%;
    padding: 14px 16px 14px 44px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    letter-spacing: 0.1em;
}
.input-wrapper input::placeholder {
    color: var(--text-dim);
    letter-spacing: 0;
}
.input-wrapper input:focus {
    border-color: var(--accent-1);
    background: rgba(139,92,246,0.07);
    box-shadow: 0 0 0 3px rgba(139,92,246,0.15);
}

#login-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--accent-1), #6D28D9);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-family: var(--font-ui);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: 0.01em;
}
#login-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.12), transparent);
    opacity: 0;
    transition: opacity 0.2s;
}
#login-btn:hover::before { opacity: 1; }
#login-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(139,92,246,0.4); }
#login-btn:active { transform: translateY(0); }

.btn-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#login-error {
    font-size: 0.82rem;
    color: var(--error);
    text-align: center;
    min-height: 18px;
    animation: shake 0.3s ease;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

/* ============================================
   MAIN APP
   ============================================ */
#app {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    pointer-events: none;
    animation: fadeIn 0.5s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---- TOP BAR ---- */
#top-bar {
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    gap: 12px;
}

.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid rgba(52,211,153,0.2);
    border-radius: 100px;
    padding: 6px 14px;
    font-size: 0.78rem;
    color: #34D399;
    font-family: var(--font-ui);
    font-weight: 500;
    letter-spacing: 0.02em;
}
.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #34D399;
}
.status-dot.pulse {
    box-shadow: 0 0 0 0 rgba(52,211,153,0.4);
    animation: statusPulse 2.5s infinite;
}
@keyframes statusPulse {
    0% { box-shadow: 0 0 0 0 rgba(52,211,153,0.4); }
    70% { box-shadow: 0 0 0 8px rgba(52,211,153,0); }
    100% { box-shadow: 0 0 0 0 rgba(52,211,153,0); }
}

.header-name {
    font-family: var(--font-ui);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-mid);
}

.header-actions {
    display: flex;
    gap: 8px;
}
.hdr-btn {
    pointer-events: auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.hdr-btn:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border-bright);
}

/* ---- CENTER LABEL ---- */
#center-label {
    pointer-events: none;
    position: absolute;
    top: 72%;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
#state-label {
    font-family: var(--font-ui);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-mid);
    letter-spacing: 0.04em;
    transition: all 0.4s ease;
}
#state-sub {
    font-size: 0.78rem;
    color: var(--text-dim);
    letter-spacing: 0.01em;
    transition: all 0.4s ease;
}

/* ---- ORB HITBOX (invisible click target) ---- */
#orb-hitbox {
    pointer-events: auto;
    position: absolute;
    left: 50%;
    top: 46%;
    transform: translate(-50%, -50%);
    width: 220px;
    height: 220px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 20;
}

/* ============================================
   CHAT DRAWER (slides up from bottom)
   ============================================ */
#chat-drawer {
    pointer-events: auto;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(8, 8, 20, 0.92);
    backdrop-filter: blur(32px);
    -webkit-backdrop-filter: blur(32px);
    border-top: 1px solid var(--border-bright);
    border-radius: 28px 28px 0 0;
    display: flex;
    flex-direction: column;
    height: var(--chat-drawer-height);
    transform: translateY(calc(var(--chat-drawer-height) - 64px));
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 -20px 60px rgba(0,0,0,0.5), 0 -1px 0 rgba(139,92,246,0.2);
    z-index: 50;
}
#chat-drawer.open {
    transform: translateY(0);
}

#chat-drag-handle {
    padding: 12px 0 6px;
    display: flex;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
.drag-pill {
    width: 40px;
    height: 4px;
    background: var(--border-bright);
    border-radius: 100px;
    transition: background 0.2s;
}
#chat-drag-handle:hover .drag-pill { background: var(--accent-1); }

/* Messages scroll area */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(139,92,246,0.3) transparent;
}
#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(139,92,246,0.3); border-radius: 4px; }

/* Chat bubbles */
.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    animation: msgSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.msg-row.user { flex-direction: row-reverse; }

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

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    font-family: var(--font-ui);
}
.msg-row.user .msg-avatar {
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--border);
    color: var(--text-dim);
}

.msg-bubble {
    max-width: 75%;
    padding: 10px 16px;
    border-radius: 18px;
    font-size: 0.88rem;
    line-height: 1.55;
    color: var(--text);
}
.msg-row.ai .msg-bubble {
    background: rgba(139,92,246,0.12);
    border: 1px solid rgba(139,92,246,0.2);
    border-bottom-left-radius: 4px;
}
.msg-row.user .msg-bubble {
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border);
    border-bottom-right-radius: 4px;
}

/* Typing indicator */
.typing-dot-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px 16px;
}
.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-1);
    animation: typingBounce 1.2s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

/* ---- CHAT INPUT BAR ---- */
#chat-input-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px 20px;
    border-top: 1px solid var(--border);
}

#chat-input-wrap {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    padding: 0 16px;
    transition: border-color 0.2s, background 0.2s;
}
#chat-input-wrap:focus-within {
    border-color: var(--accent-1);
    background: rgba(139,92,246,0.06);
}
#chat-input {
    width: 100%;
    padding: 11px 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.9rem;
}
#chat-input::placeholder { color: var(--text-dim); }

.action-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}
.mic-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
}
.mic-btn:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border-bright);
}
.mic-btn.recording {
    background: rgba(248,113,113,0.15);
    border-color: #F87171;
    color: #F87171;
    animation: micPulse 1.5s ease infinite;
}
@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(248,113,113,0.3); }
    50% { box-shadow: 0 0 0 10px rgba(248,113,113,0); }
}
.send-btn {
    background: linear-gradient(135deg, var(--accent-1), #6D28D9);
    color: white;
}
.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(139,92,246,0.4);
}
.send-btn:active { transform: scale(0.97); }

/* ============================================
   WAVEFORM VISUALIZER
   ============================================ */
#wave-viz {
    pointer-events: none;
    position: absolute;
    left: 50%;
    top: 63%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    height: 40px;
}
#wave-viz span {
    display: block;
    width: 4px;
    border-radius: 100px;
    background: linear-gradient(to top, var(--accent-1), var(--accent-2));
    animation: waveAnim 1.2s ease-in-out infinite;
    min-height: 4px;
}
#wave-viz span:nth-child(1)  { animation-delay: 0.0s; }
#wave-viz span:nth-child(2)  { animation-delay: 0.1s; }
#wave-viz span:nth-child(3)  { animation-delay: 0.2s; }
#wave-viz span:nth-child(4)  { animation-delay: 0.1s; }
#wave-viz span:nth-child(5)  { animation-delay: 0.0s; }
#wave-viz span:nth-child(6)  { animation-delay: 0.15s; }
#wave-viz span:nth-child(7)  { animation-delay: 0.25s; }
#wave-viz span:nth-child(8)  { animation-delay: 0.15s; }
#wave-viz span:nth-child(9)  { animation-delay: 0.05s; }
#wave-viz span:nth-child(10) { animation-delay: 0.1s; }
@keyframes waveAnim {
    0%, 100% { height: 6px; opacity: 0.4; }
    50% { height: 32px; opacity: 1; }
}

/* ============================================
   STATE LABEL VARIANTS (via JS class on body)
   ============================================ */
body.state-listening #state-label { color: var(--accent-2); }
body.state-listening #orb-glow-ring { background: radial-gradient(ellipse at center, rgba(6,182,212,0.25) 0%, transparent 70%); }
body.state-thinking #state-label { color: #A78BFA; }
body.state-speaking #state-label { color: #FCD34D; }
body.state-speaking #orb-glow-ring { background: radial-gradient(ellipse at center, rgba(252,211,77,0.18) 0%, transparent 70%); }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 480px) {
    #login-card { padding: 32px 24px; }
    .brand-name { font-size: 1.3rem; }
    :root { --chat-drawer-height: 380px; }
}
