/* ── Skyler AI — animated voice-first agent (draggable cartoon) ───────────── */

#skylerAiAgent {
    position: fixed;
    top: 50%;
    left: 50%;            /* JS recenters precisely on open; this is a fallback */
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    user-select: none;
    color: #e8eaed;
    font-family: inherit;
    animation: skylerAiPop 0.3s cubic-bezier(0.18, 0.9, 0.32, 1.2);
}

@keyframes skylerAiPop {
    from { opacity: 0; transform: translateY(16px) scale(0.85); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

#skylerAiAgent.dragging { transition: none; }
#skylerAiAgent.dragging .sai-character { cursor: grabbing; }

/* ── The character (photo avatar) ───────────────────────────────────────── */
.sai-character {
    /* --sai-react: 0..1 live audio loudness, set by the lip-sync engine in JS */
    --sai-react: 0;
    position: relative;
    width: 112px;
    height: 112px;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: skylerBob 3.6s ease-in-out infinite;
}

@keyframes skylerBob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}

/* Circular frame around the photo. Scales subtly with the AI's live loudness so
   the avatar visibly "reacts" while speaking (a flat photo can't lip-sync a mouth). */
.sai-photo-wrap {
    position: relative;
    z-index: 2;
    width: 104px;
    height: 104px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(0, 0, 0, 0.15);
    background: #1b2a4d;
    transform: scale(calc(1 + var(--sai-react) * 0.05));
    transition: transform 0.06s linear, box-shadow 0.2s ease;
}

/* Zoomed crop focusing on the character's face. The source is a SQUARE card with
   branding text across the bottom, so object-position can't crop it — we enlarge
   the image and position it to show only the face. Tune these two knobs:
     width  → zoom level   |   top → vertical framing (more negative = look lower) */
.sai-photo {
    position: absolute;
    width: 172%;
    height: auto;
    left: 50%;
    top: -4%;
    transform: translateX(-50%);
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;       /* clicks/drags go to the character, not the img */
}

/* Glowing aura behind the photo — reflects AI state + live loudness. Centered
   with margin:auto so the state keyframes can scale() without breaking centering. */
.sai-aura {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 116px;
    height: 116px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(47, 128, 237, 0.5) 0%, rgba(47, 128, 237, 0) 70%);
    opacity: 0.6;
    z-index: 1;
}

@keyframes skylerAuraPulse {
    0%, 100% { transform: scale(0.92); opacity: 0.55; }
    50%      { transform: scale(1.18); opacity: 0.95; }
}

/* ── State: SPEAKING — bright blue aura. While lip-sync is active the aura is
   driven by live loudness instead of the canned pulse. ───────────────────── */
#skylerAiAgent.speaking .sai-aura {
    background: radial-gradient(circle, rgba(47, 128, 237, 0.75) 0%, rgba(47, 128, 237, 0) 70%);
    animation: skylerAuraPulse 0.9s ease-in-out infinite;
}
#skylerAiAgent.speaking .sai-photo-wrap {
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.45), 0 0 0 3px rgba(90, 160, 236, 0.55);
}
#skylerAiAgent.lipsync .sai-aura {
    animation: none;
    transform: scale(calc(0.92 + var(--sai-react) * 0.3));
    opacity: calc(0.45 + var(--sai-react) * 0.5);
    transition: transform 0.06s linear, opacity 0.06s linear;
}

/* ── State: LISTENING — warm green glow ─────────────────────────────────── */
#skylerAiAgent.listening .sai-aura {
    background: radial-gradient(circle, rgba(46, 204, 113, 0.6) 0%, rgba(46, 204, 113, 0) 70%);
    animation: skylerAuraPulse 1.4s ease-in-out infinite;
}
#skylerAiAgent.listening .sai-photo-wrap {
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.45), 0 0 0 3px rgba(46, 204, 113, 0.6);
}

/* ── State: THINKING — slow amber shimmer ───────────────────────────────── */
#skylerAiAgent.thinking .sai-aura {
    background: radial-gradient(circle, rgba(241, 196, 15, 0.5) 0%, rgba(241, 196, 15, 0) 70%);
    animation: skylerAuraPulse 1.8s ease-in-out infinite;
}

/* ── Status line ────────────────────────────────────────────────────────── */
.sai-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(20, 22, 28, 0.6);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 4px 11px;
    border-radius: 999px;
    white-space: nowrap;
}

.skyler-ai-dot {
    width: 8px;
    height: 8px;
    background: #2ecc71;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.8);
    animation: skylerPulse 2s ease-in-out infinite;
    flex-shrink: 0;
}
@keyframes skylerPulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.35; }
}

/* Speaking dots tucked into the status pill */
#skylerAiSpeakingIndicator {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 2px;
}
.sai-speaking-dot {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: #5aa0ec;
    animation: skylerDot 1.1s ease-in-out infinite;
    flex-shrink: 0;
}
.sai-speaking-dot:nth-child(2) { animation-delay: 0.18s; }
.sai-speaking-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes skylerDot {
    0%, 100% { transform: translateY(0);    opacity: 0.45; }
    50%      { transform: translateY(-4px); opacity: 1; }
}

/* ── Caption (latest AI line, auto-fades) ───────────────────────────────── */
.sai-caption {
    max-width: 230px;
    background: rgba(20, 22, 28, 0.78);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    border-bottom-right-radius: 4px;
    padding: 9px 13px;
    font-size: 12.5px;
    line-height: 1.5;
    color: #eef1f5;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transform: translateY(6px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    max-height: 0;
    overflow: hidden;
    margin-bottom: -8px;
}
.sai-caption.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    max-height: 160px;
    margin-bottom: 0;
}

/* ── Control dock ───────────────────────────────────────────────────────── */
.sai-dock {
    display: flex;
    gap: 6px;
    padding: 5px 7px;
    background: rgba(20, 22, 28, 0.6);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    backdrop-filter: blur(14px) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.4);
    opacity: 0.55;
    transition: opacity 0.2s ease;
}
/* Fully opaque on hover, while dragging, or whenever the live host is on; stays
   touchable (semi-visible) at rest so mobile users can reach the controls. */
#skylerAiAgent:hover .sai-dock,
#skylerAiAgent.dragging .sai-dock,
#skylerAiAgent.live .sai-dock {
    opacity: 1;
}

.sai-dock-btn {
    background: rgba(255, 255, 255, 0.07);
    color: #cfe0f5;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    width: 34px;
    height: 34px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: background 0.2s, color 0.2s, transform 0.15s;
}
.sai-dock-btn:hover { background: rgba(255, 255, 255, 0.16); color: #fff; transform: translateY(-1px); }
.sai-dock-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.sai-dock-btn.activeControl {
    background: linear-gradient(135deg, #2f80ed, #2563eb);
    color: #fff;
    border-color: transparent;
    width: auto;
    padding: 0 11px;
    border-radius: 999px;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
}

/* Labeled pill buttons (Start / Stop / Hide) — replace the bare icon buttons. */
.sai-dock-btn.sai-text-btn {
    width: auto;
    min-width: 64px;
    height: 32px;
    padding: 0 13px;
    border-radius: 999px;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.2px;
}
.sai-dock-btn.sai-text-btn i { font-size: 11px; }
.sai-dock-btn.sai-start {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: #fff;
    border-color: transparent;
}
.sai-dock-btn.sai-start:hover { background: linear-gradient(135deg, #2ad36a, #18b14e); color: #fff; }
.sai-dock-btn.sai-stop {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    border-color: transparent;
}
.sai-dock-btn.sai-stop:hover { background: linear-gradient(135deg, #f15a5a, #e22d2d); color: #fff; }
.sai-dock-btn.sai-hide {
    background: rgba(255, 255, 255, 0.08);
    color: #cfe0f5;
}

/* Mic listening state */
#skylerAiMic.listening {
    background: #e74c3c;
    color: #fff;
    border-color: #e74c3c;
    animation: skylerMicPulse 1.2s ease-in-out infinite;
}
@keyframes skylerMicPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.5); }
    50%      { box-shadow: 0 0 0 6px rgba(231, 76, 60, 0); }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    .sai-character,
    .sai-aura,
    #skylerAiAgent.speaking .sai-aura,
    #skylerAiAgent.listening .sai-aura,
    #skylerAiAgent.thinking .sai-aura {
        animation: none !important;
    }
}

/* ── End Skyler AI agent ──────────────────────────────────────────────────── */
