/* ============================================================
   Welcome Mascot - Animations
   Mascot idle, entrance, head swap, emotion transitions
   ============================================================ */

/* ─── Mascot Breathing (always-on default) ─── */
.mascot-center {
    animation: mascot-float 4s ease-in-out infinite;
    transform-origin: center bottom;
}

/* ─── Mascot Entrance (one-shot, removed by JS after animationend) ─── */
.mascot-center.entering {
    animation: mascot-entrance 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes mascot-entrance {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.3) translateY(30px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) translateY(0);
    }
}

/* ─── Idle Breathing ─── */
/* Body-only breathing (no translate — body is not centered via transform) */
.mascot-body-svg.idle {
    animation: mascot-body-breathe 3s ease-in-out infinite;
}

@keyframes mascot-body-breathe {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(1.02); }
}

/* Center-level breathing (includes translate for centering) */
@keyframes mascot-breathe {
    0%, 100% { transform: translate(-50%, -50%) scaleY(1); }
    50% { transform: translate(-50%, -50%) scaleY(1.02); }
}

/* ─── Idle Blink ─── */
/* Blinking is handled via JS SVG src swap (head-forward-blink.svg)
   because head SVGs are loaded as <img>, not inline SVG.
   See HeadTracker.js startBlinking() / doBlink() */

/* ─── Head Position Swap ─── */
.mascot-head-svg {
    transition: opacity 0.15s ease;
}

.mascot-head-svg.swapping {
    opacity: 0;
}

/* ─── Emotion Fade In/Out ─── */
.mascot-emotion-svg {
    transition: opacity 0.4s ease;
}

.mascot-emotion-svg.active {
    opacity: 1;
}

/* ─── Wave Animation (greeting) ─── */
.mascot-body-svg.waving .arm-wave {
    animation: mascot-wave 0.8s ease-in-out 3;
    transform-origin: 50% 50%;
}

@keyframes mascot-wave {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(15deg); }
    75% { transform: rotate(-10deg); }
}

/* ─── Bounce (excited reaction) ─── */
.mascot-center.bounce {
    animation: mascot-bounce 0.5s ease;
}

@keyframes mascot-bounce {
    0%, 100% { transform: translate(-50%, -50%) translateY(0); }
    30% { transform: translate(-50%, -50%) translateY(-15px); }
    60% { transform: translate(-50%, -50%) translateY(-5px); }
}

/* ─── Nod (acknowledgment) ─── */
.mascot-head-svg.nodding {
    animation: mascot-nod 0.4s ease 2;
}

@keyframes mascot-nod {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(5px); }
}

/* ─── Subtle Breathe (idle on homepage) ─── */
.mascot-center.floating {
    animation: mascot-float 4s ease-in-out infinite;
    transform-origin: center bottom;
}

@keyframes mascot-float {
    0%, 100% { transform: translate(-50%, -50%) scaleY(1); }
    50% { transform: translate(-50%, -50%) scaleY(1.015); }
}

/* ─── Tail Animation (breathing + direction sync) ─── */
/* Driven entirely by TailAnimator.js via requestAnimationFrame.
   Breathing: synced to the 4s mascot-float/mascot-breathe CSS cycle.
   Direction: follows head/ear position (left → tail up-left, right → tail down-right).
   No CSS transition needed — rAF provides frame-level smooth updates. */
.mascot-tail-svg svg image {
    transform-origin: 524px 974px;
}

/* ─── Scarf Wave (idle) ─── */
/* Pivot at neck attachment: canvas (500, 646) → viewBox-relative 55.4%, 12.7% */
.mascot-scarf-svg {
    animation: scarf-wave 3.5s ease-in-out infinite;
    transform-origin: 55.4% 12.7%;
}

@keyframes scarf-wave {
    0%, 100% { transform: rotate(0deg); }
    40% { transform: rotate(2deg); }
    75% { transform: rotate(-1.5deg); }
}

/* ─── Attention Grab (after idle timeout) ─── */
.mascot-center.attention {
    animation: mascot-attention 0.6s ease;
}

@keyframes mascot-attention {
    0%, 100% { transform: translate(-50%, -50%) rotate(0deg); }
    20% { transform: translate(-50%, -50%) rotate(-5deg); }
    40% { transform: translate(-50%, -50%) rotate(5deg); }
    60% { transform: translate(-50%, -50%) rotate(-3deg); }
    80% { transform: translate(-50%, -50%) rotate(3deg); }
}

/* ─── Speech Bubble Entrance ─── */
/* NOTE: JS sets inline transform (translateY) for positioning.
   Animations must NOT override transform — use opacity only. */
.speech-bubble.animate-in {
    animation: mascot-speech-enter 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes mascot-speech-enter {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ─── Speech Bubble Exit ─── */
.speech-bubble.animate-out {
    animation: mascot-speech-exit 0.3s ease forwards;
}

@keyframes mascot-speech-exit {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* ─── Sparkle Effect ─── */
.mascot-sparkle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #FFD700;
    border-radius: 50%;
    pointer-events: none;
    animation: mascot-sparkle 1s ease forwards;
}

@keyframes mascot-sparkle {
    0% { opacity: 1; transform: scale(0) translateY(0); }
    50% { opacity: 1; transform: scale(1) translateY(-20px); }
    100% { opacity: 0; transform: scale(0.5) translateY(-40px); }
}

/* ─── Reduced Motion ─── */
@media (prefers-reduced-motion: reduce) {
    .mascot-center,
    .mascot-body-svg,
    .mascot-head-svg,
    .mascot-tail-svg,
    .mascot-tail-svg svg image,
    .mascot-scarf-svg,
    .mascot-emotion-svg,
    .speech-bubble,
    .octagon-button,
    .mascot-sparkle {
        animation: none !important;
        transition-duration: 0.001ms !important;
    }
    
    /* Still allow opacity transitions for state changes */
    .mascot-emotion-svg {
        transition: opacity 0.1s ease;
    }
    
    /* Remove entrance delays */
    .octagon-button {
        opacity: 1 !important;
        animation-delay: 0s !important;
    }
}

/* ─── Sleep Mode: floating z-Z-Z above the head ─── */
.mascot-sleep-overlay {
    position: absolute;
    top: -55%;
    left: 45%;
    width: 60px;
    height: 60px;
    pointer-events: none;
    z-index: 10;
}

/* Corner collapsed: sleep overlay closer to the small head circle */
.mascot-corner-puppet:not(.mascot-corner-expanded) .mascot-sleep-overlay {
    top: -20%;
    left: 50%;
}

.sleep-z {
    position: absolute;
    font-family: var(--mascot-font, 'Poppins', sans-serif);
    font-weight: 700;
    color: var(--mascot-primary, #4a90d9);
    opacity: 0;
    text-shadow: 0 1px 4px rgba(74, 144, 217, 0.3);
}

/* First z — smallest, starts bottom-left, drifts up-right */
.sleep-z.z1 {
    font-size: 14px;
    bottom: 0;
    left: 5px;
    animation: sleep-float-1 2.4s ease-in-out infinite;
}

/* Second Z — medium, starts middle */
.sleep-z.z2 {
    font-size: 20px;
    bottom: 10px;
    left: 20px;
    animation: sleep-float-2 2.4s ease-in-out 0.6s infinite;
}

/* Third Z — largest, starts higher-right */
.sleep-z.z3 {
    font-size: 28px;
    bottom: 20px;
    left: 35px;
    animation: sleep-float-3 2.4s ease-in-out 1.2s infinite;
}

@keyframes sleep-float-1 {
    0% {
        opacity: 0;
        transform: translate(0, 0) scale(0.5) rotate(-10deg);
    }
    15% {
        opacity: 0.8;
    }
    50% {
        opacity: 1;
        transform: translate(8px, -18px) scale(1) rotate(5deg);
    }
    85% {
        opacity: 0.4;
    }
    100% {
        opacity: 0;
        transform: translate(16px, -36px) scale(0.6) rotate(15deg);
    }
}

@keyframes sleep-float-2 {
    0% {
        opacity: 0;
        transform: translate(0, 0) scale(0.5) rotate(5deg);
    }
    15% {
        opacity: 0.8;
    }
    50% {
        opacity: 1;
        transform: translate(6px, -20px) scale(1.1) rotate(-8deg);
    }
    85% {
        opacity: 0.4;
    }
    100% {
        opacity: 0;
        transform: translate(12px, -40px) scale(0.7) rotate(10deg);
    }
}

@keyframes sleep-float-3 {
    0% {
        opacity: 0;
        transform: translate(0, 0) scale(0.6) rotate(-5deg);
    }
    15% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
        transform: translate(4px, -22px) scale(1.15) rotate(8deg);
    }
    85% {
        opacity: 0.3;
    }
    100% {
        opacity: 0;
        transform: translate(10px, -44px) scale(0.7) rotate(-12deg);
    }
}
