/* ========================================
   VOICE MODE - Immersive Audio Experience
   ========================================

   When a user clicks "Listen", the UI transforms:
   1. Dimension Shift - Everything dims, non-active messages blur
   2. Liquid Glass - Active message becomes translucent with soft edges
   3. Avatar Aura - Persona avatar glows and pulses with audio
   4. Breathing - The environment subtly scales with amplitude
*/

/* CSS Variables for voice mode (set by JS) */
:root {
    --voice-color-rgb: 0, 212, 255;  /* Default: Cyan (Wit) */
    --pulse-speed: 1s;
    --gradient-opacity: 0.7;
}

/* ========================================
   DIMENSION SHIFT
   ======================================== */

/* No full-screen overlay - we darken individual elements instead */

/* Blur and dim non-active messages */
body.voice-mode .message:not(.voice-active) {
    filter: blur(8px) brightness(0.3);
    opacity: 0.4;
    transform: scale(0.98);
    transition: all 0.4s ease;
}

/* Dim the sidebar during voice mode */
body.voice-mode .sidebar {
    filter: blur(4px) brightness(0.5);
    pointer-events: none;
    transition: all 0.4s ease;
}

/* Dim the input section */
body.voice-mode .input-section {
    filter: blur(4px) brightness(0.5);
    pointer-events: none;
    transition: all 0.4s ease;
}

/* Dim the top bar */
body.voice-mode .top-bar {
    filter: blur(2px) brightness(0.5);
    pointer-events: none;
    transition: all 0.4s ease;
}

/* Dim the thread header (persona avatar at top) */
body.voice-mode .thread-header {
    filter: blur(2px) brightness(0.5);
    pointer-events: none;
    transition: all 0.4s ease;
    z-index: 10 !important;  /* Force below voice mode elements */
    position: relative;  /* Ensure z-index applies */
}

/* ========================================
   ACTIVE MESSAGE - Float Forward
   ======================================== */

.message.voice-active {
    position: relative;
    z-index: 250;  /* Above floating avatar (200) */
    isolation: isolate;
    /* No transform - prevents jitter */
    transition: all 0.4s ease;
}

/* Ensure the entire AI content is visible */
.message.voice-active .ai-content {
    position: relative;
    z-index: 251;  /* Above floating avatar (200) */
}

/* ========================================
   LIQUID GLASS BUBBLE
   ======================================== */

.message.voice-active .message-response {
    background: linear-gradient(
        135deg,
        rgba(var(--voice-color-rgb), 0.15) 0%,
        rgba(var(--voice-color-rgb), 0.05) 50%,
        rgba(255, 255, 255, 0.08) 100%
    ) !important;
    backdrop-filter: blur(20px) saturate(1.2);
    -webkit-backdrop-filter: blur(20px) saturate(1.2);
    border: 1px solid rgba(var(--voice-color-rgb), 0.3) !important;
    border-radius: 24px !important;
    box-shadow:
        0 8px 32px rgba(var(--voice-color-rgb), 0.2),
        0 0 60px rgba(var(--voice-color-rgb), 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.15),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
    animation: liquidGlass 0.5s ease-out;
}

@keyframes liquidGlass {
    0% {
        border-radius: 4px 18px 18px 18px !important;
        transform: scale(0.98);
        box-shadow:
            0 4px 16px rgba(var(--voice-color-rgb), 0.1),
            0 0 20px rgba(var(--voice-color-rgb), 0.05);
    }
    50% {
        border-radius: 28px !important;
        transform: scale(1.01);
    }
    100% {
        border-radius: 24px !important;
        transform: scale(1);
        box-shadow:
            0 8px 32px rgba(var(--voice-color-rgb), 0.2),
            0 0 60px rgba(var(--voice-color-rgb), 0.1),
            inset 0 1px 0 rgba(255, 255, 255, 0.15);
    }
}

/* ========================================
   AVATAR GLOW (No transforms - prevents jitter)
   ======================================== */

.message.voice-active .ai-avatar {
    /* No transform - prevents jitter */
    z-index: 252;  /* Above floating avatar (200) */
}

.message.voice-active .ai-avatar img {
    border-radius: 50%;
    box-shadow:
        0 0 20px rgba(var(--voice-color-rgb), 0.6),
        0 0 40px rgba(var(--voice-color-rgb), 0.4);
    animation: avatarGlow var(--pulse-speed) ease-in-out infinite;
}

/* Glow-only animation (no transform to prevent jitter) */
@keyframes avatarGlow {
    0%, 100% {
        box-shadow:
            0 0 20px rgba(var(--voice-color-rgb), 0.6),
            0 0 40px rgba(var(--voice-color-rgb), 0.4);
    }
    50% {
        box-shadow:
            0 0 30px rgba(var(--voice-color-rgb), 0.8),
            0 0 60px rgba(var(--voice-color-rgb), 0.5),
            0 0 80px rgba(var(--voice-color-rgb), 0.3);
    }
}

/* Glow ring removed - was causing unwanted ellipse effect */

/* Persona name tag glow */
.message.voice-active .persona-name-tag {
    color: rgba(var(--voice-color-rgb), 1);
    text-shadow: 0 0 10px rgba(var(--voice-color-rgb), 0.5);
    transition: all 0.3s ease;
}

/* ========================================
   BREATHING ENVIRONMENT (Disabled - causes visual noise)
   ======================================== */

/* Breathing disabled for cleaner experience */

/* ========================================
   EXIT HINT
   ======================================== */

body.voice-mode::after {
    content: 'Click Stop or tap anywhere to exit';
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.4);
    font-size: 13px;
    font-weight: 400;
    letter-spacing: 0.5px;
    z-index: 102;
    opacity: 0;
    animation: fadeInHint 0.5s ease 2s forwards;
    pointer-events: none;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

@keyframes fadeInHint {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ========================================
   LISTEN BUTTON - VOICE MODE STATE
   ======================================== */

/* When voice mode is active, style the listen button on active message */
.message.voice-active .inline-action-btn.listen.playing {
    color: rgba(var(--voice-color-rgb), 1);
    background: rgba(var(--voice-color-rgb), 0.15);
    border-color: rgba(var(--voice-color-rgb), 0.3);
    box-shadow: 0 0 20px rgba(var(--voice-color-rgb), 0.2);
    transform: scale(1.1);
    /* Pulse animation removed */
}

.message.voice-active .inline-action-btn.listen.playing:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
    animation: none;
}

/* ========================================
   EXIT ANIMATION
   ======================================== */

/* Exit transitions handled by individual element transitions */

/* ========================================
   MOBILE ADJUSTMENTS
   ======================================== */

@media (max-width: 768px) {
    /* No transforms on mobile either */

    body.voice-mode::after {
        bottom: 80px; /* Above mobile input */
        font-size: 12px;
    }

    /* Reduce blur on mobile for performance */
    body.voice-mode .message:not(.voice-active) {
        filter: blur(4px) brightness(0.4);
    }

    /* Smaller floating avatar on mobile */
    .voice-floating-avatar {
        width: 120px;
        height: 120px;
        top: 80px;
    }

    .voice-floating-avatar img[src$=".svg"] {
        padding: 18px;
    }
}

/* ========================================
   ACCESSIBILITY: REDUCED MOTION
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    /* Disable all voice mode animations */
    .message.voice-active .ai-avatar img {
        animation: none !important;
    }

    .message.voice-active .message-response {
        animation: none !important;
    }

    .message.voice-active,
    .message.voice-active .message-response,
    .message.voice-active .ai-avatar,
    body.voice-mode .message:not(.voice-active),
    body.voice-mode .sidebar,
    body.voice-mode .input-section {
        transition-duration: 0.01ms !important;
    }

    body.voice-mode::after {
        animation: none;
        opacity: 1;
    }
}

/* ========================================
   FLOATING PERSONA AVATAR
   ======================================== */

.voice-floating-avatar {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    width: 160px;
    height: 160px;
    pointer-events: none;
    /* Entrance animation to prevent jumping */
    opacity: 0;
    animation: avatarEnter 0.3s ease-out forwards;
}

@keyframes avatarEnter {
    from {
        opacity: 0;
        transform: translateX(-50%) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
}

.voice-floating-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid rgba(255, 255, 255, 0.3);
    box-shadow:
        0 0 40px rgba(var(--voice-color-rgb), 0.4),
        0 8px 32px rgba(0, 0, 0, 0.5);
}

/* Handle SVG fallback avatars */
.voice-floating-avatar img[src$=".svg"] {
    object-fit: contain;
    padding: 24px;
    background: rgba(var(--voice-color-rgb), 0.15);
    border-radius: 50%;
}

/* Desktop: center relative to main content area (account for 280px sidebar) */
@media (min-width: 769px) {
    .voice-floating-avatar {
        left: calc(50% + 140px);  /* Shift right by half sidebar width */
    }

    /* Reset when sidebar is collapsed */
    body:has(.sidebar.collapsed) .voice-floating-avatar {
        left: 50%;
    }
}

/* ========================================
   PERSONA-SPECIFIC COLOR PRESETS
   ======================================== */

/* These can be set via JS: VoiceMode.enter(el, 'friend') */

/* Wit (default) - Cyan */
/* --voice-color-rgb: 0, 212, 255 */

/* Friend personas - Purple */
body.voice-mode[data-persona-type="friend"] {
    --voice-color-rgb: 168, 85, 247;
}

/* Utility personas - Green */
body.voice-mode[data-persona-type="utility"] {
    --voice-color-rgb: 34, 197, 94;
}

/* System personas - Gold */
body.voice-mode[data-persona-type="system"] {
    --voice-color-rgb: 251, 191, 36;
}

/* ========================================
   WORD HIGHLIGHTING DURING TTS
   ======================================== */

.voice-word {
    transition: background-color 0.15s ease, color 0.15s ease;
    display: inline;
}

.voice-word.active {
    background-color: rgba(var(--voice-color-rgb), 0.5);
    color: white;
    border-radius: 3px;
    padding: 1px 3px;
    margin: 0 -1px;
    box-shadow: 0 0 8px rgba(var(--voice-color-rgb), 0.3);
}

.voice-word.spoken {
    color: rgba(255, 255, 255, 0.5);
}

/* Reduced motion: disable word highlight transitions */
@media (prefers-reduced-motion: reduce) {
    .voice-word {
        transition: none !important;
    }
}
