/* =========================================================
   VIVI — VISUAL SYSTEM
========================================================= */
#vivisystem-bot {
    --vivi-size: 66px;
    position: fixed;
    left: 0;
    top: 0;
    width: var(--vivi-size);
    height: var(--vivi-size);
    z-index: 9999;
    user-select: none;
    -webkit-user-select: none;
    cursor: grab;
    touch-action: none;
    will-change: transform;
    transform: translate3d(-200px, -200px, 0);
    filter:
        drop-shadow(
            0 10px 20px rgba(170,120,245,.28)
        );
}
/* =========================================================
   HEAD
========================================================= */
#vivisystem-bot .vivi-head {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background:
        radial-gradient(
            circle at 29% 20%,
            rgba(255,255,255,.76),
            transparent 24%
        ),
        radial-gradient(
            circle at 72% 80%,
            rgba(80,40,130,.17),
            transparent 52%
        ),
        linear-gradient(
            145deg,
            #f2e2ff 0%,
            #c99cf5 48%,
            #8955c2 100%
        );
    border:
        1px solid rgba(255,255,255,.58);
    box-shadow:
        inset 0 2px 7px rgba(255,255,255,.5),
        inset 0 -10px 20px rgba(50,20,90,.18),
        0 10px 25px rgba(90,45,150,.25);
    transform-origin: center bottom;
    will-change: transform;
}
/* =========================================================
   FACE
========================================================= */
#vivisystem-bot .vivi-face {
    position: absolute;
    inset: 0;
}
/* =========================================================
   EYES
========================================================= */
#vivisystem-bot .vivi-eye {
    position: absolute;
    top: 20%;
    width: 8px;
    height: 23px;
    border-radius: 999px;
    background:
        linear-gradient(
            180deg,
            #29143b,
            #0e0715
        );
    overflow: hidden;
    will-change:
        transform,
        width,
        height;
    transition:
        width .18s ease,
        height .18s ease,
        border-radius .18s ease;
}
#vivisystem-bot .vivi-eye.left {
    left: 30%;
}
#vivisystem-bot .vivi-eye.right {
    right: 30%;
}
/* =========================================================
   PUPILS
   Always clipped by the black eye.
========================================================= */
#vivisystem-bot .vivi-pupil {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 4px;
    height: 7px;
    border-radius: 50%;
    background:
        radial-gradient(
            circle at 30% 25%,
            #fff,
            rgba(255,255,255,.9) 45%,
            rgba(255,255,255,.55)
        );
    transform:
        translate(-50%,-50%);
}
#vivisystem-bot .vivi-pupil::after {
    content: "";
    position: absolute;
    width: 2px;
    height: 2px;
    left: 1px;
    top: 1px;
    border-radius: 50%;
    background: #fff;
}
/* =========================================================
   MOUTH
========================================================= */
#vivisystem-bot .vivi-mouth {
    position: absolute;
    left: 50%;
    top: 67%;
    width: 14px;
    height: 6px;
    transform:
        translateX(-50%)
        scaleY(.35);
    transform-origin: center center;
    border-radius: 0 0 999px 999px;
    background:
        #21102e;
    opacity: 0;
    transition:
        opacity .15s ease,
        width .15s ease,
        height .15s ease,
        transform .15s ease,
        border-radius .15s ease;
}
/* =========================================================
   ACTUAL TALKING
   The mouth expands and contracts vertically,
   opening and closing.
========================================================= */
#vivisystem-bot.vivi-talking .vivi-mouth {
    opacity: 1;
    animation:
        viviMouthTalk
        .13s
        ease-in-out
        infinite alternate;
}
@keyframes viviMouthTalk {
    0% {
        height: 3px;
        width: 8px;
        transform:
            translateX(-50%)
            scaleY(.35);
        border-radius:
            999px;
    }
    100% {
        height: 12px;
        width: 15px;
        transform:
            translateX(-50%)
            scaleY(1);
        border-radius:
            50%;
    }
}
/* =========================================================
   CHEEKS
========================================================= */
#vivisystem-bot .vivi-cheek {
    position: absolute;
    top: 65%;
    width: 10px;
    height: 5px;
    border-radius: 50%;
    background:
        rgba(255,160,220,.4);
    opacity: .3;
}
#vivisystem-bot .vivi-cheek.left {
    left: 15%;
}
#vivisystem-bot .vivi-cheek.right {
    right: 15%;
}
/* =========================================================
   EXPRESSIONS
========================================================= */
#vivisystem-bot[data-expression="happy"] .vivi-mouth {
    opacity: 1;
    width: 17px;
    height: 7px;
    transform:
        translateX(-50%)
        scaleY(1);
}
#vivisystem-bot[data-expression="joy"] .vivi-mouth {
    opacity: 1;
    width: 18px;
    height: 10px;
    border-radius:
        0 0 999px 999px;
}
#vivisystem-bot[data-expression="joy"] .vivi-cheek {
    opacity: .9;
}
#vivisystem-bot[data-expression="excited"] .vivi-mouth {
    opacity: 1;
    width: 18px;
    height: 11px;
    border-radius: 5px 5px 999px 999px;
}
#vivisystem-bot[data-expression="surprised"] .vivi-eye {
    width: 10px;
    height: 27px;
}
#vivisystem-bot[data-expression="surprised"] .vivi-mouth {
    opacity: 1;
    width: 9px;
    height: 10px;
    border-radius: 50%;
}
#vivisystem-bot[data-expression="sad"] .vivi-eye.left {
    transform:
        rotate(-12deg);
}
#vivisystem-bot[data-expression="sad"] .vivi-eye.right {
    transform:
        rotate(12deg);
}
#vivisystem-bot[data-expression="sad"] .vivi-mouth {
    opacity: .8;
    transform:
        translateX(-50%)
        rotate(180deg);
}
#vivisystem-bot[data-expression="angry"] .vivi-eye.left {
    transform:
        rotate(17deg);
}
#vivisystem-bot[data-expression="angry"] .vivi-eye.right {
    transform:
        rotate(-17deg);
}
#vivisystem-bot[data-expression="confused"] .vivi-eye.left {
    transform:
        translateY(-4px)
        rotate(-5deg);
}
#vivisystem-bot[data-expression="confused"] .vivi-eye.right {
    transform:
        translateY(3px)
        rotate(5deg);
}
#vivisystem-bot[data-expression="suspicious"] .vivi-eye {
    width: 14px;
    height: 7px;
}
#vivisystem-bot[data-expression="deadpan"] .vivi-eye {
    width: 14px;
    height: 4px;
}
#vivisystem-bot[data-expression="deadpan"] .vivi-mouth {
    opacity: .7;
    width: 11px;
    height: 2px;
    border-radius: 0;
}
#vivisystem-bot[data-expression="shy"] .vivi-cheek {
    opacity: 1;
}
#vivisystem-bot[data-expression="sleepy"] .vivi-eye {
    width: 13px;
    height: 4px;
}
#vivisystem-bot[data-expression="sleepy"] .vivi-mouth {
    opacity: .35;
}
#vivisystem-bot[data-expression="blink"] .vivi-eye {
    width: 13px;
    height: 2px;
}
/* =========================================================
   DAZED
========================================================= */
#vivisystem-bot[data-expression="dazed"] .vivi-eye {
    width: 15px;
    height: 15px;
    border-radius: 50%;
}
#vivisystem-bot[data-expression="dazed"] .vivi-pupil {
    display: none;
}
#vivisystem-bot[data-expression="dazed"] .vivi-eye::after {
    content: "↻";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color:
        rgba(255,255,255,.9);
    animation:
        viviEyeSpin
        .65s
        linear
        infinite;
}
@keyframes viviEyeSpin {
    to {
        transform:
            rotate(360deg);
    }
}
/* =========================================================
   MUSH
========================================================= */
#vivisystem-bot.vivi-mush .vivi-head {
    animation:
        viviMush
        .9s
        cubic-bezier(.2,.8,.2,1)
        forwards;
}
@keyframes viviMush {
    0% {
        transform:
            scale(1);
    }
    35% {
        transform:
            scaleX(1.2)
            scaleY(.75);
    }
    65% {
        transform:
            scaleX(1.45)
            scaleY(.42)
            translateY(19px);
    }
    100% {
        transform:
            scaleX(1.42)
            scaleY(.4)
            translateY(20px);
    }
}
#vivisystem-bot.vivi-mush .vivi-mouth {
    opacity: .6;
    width: 18px;
    height: 2px;
}
/* =========================================================
   NORMAL SQUISH
========================================================= */
#vivisystem-bot.vivi-squish .vivi-head {
    animation:
        viviSquish
        .55s
        cubic-bezier(.2,.8,.2,1);
}
@keyframes viviSquish {
    0% {
        transform: scale(1);
    }
    30% {
        transform:
            scaleX(1.18)
            scaleY(.82);
    }
    65% {
        transform:
            scaleX(.94)
            scaleY(1.06);
    }
    100% {
        transform: scale(1);
    }
}
/* =========================================================
   BOUNCE
========================================================= */
#vivisystem-bot.vivi-bounce .vivi-head {
    animation:
        viviBounce
        .7s
        cubic-bezier(.2,.8,.2,1);
}
@keyframes viviBounce {
    0% {
        transform:
            translateY(0)
            scale(1);
    }
    30% {
        transform:
            translateY(-14px)
            scaleX(.94)
            scaleY(1.06);
    }
    55% {
        transform:
            translateY(2px)
            scaleX(1.1)
            scaleY(.9);
    }
    100% {
        transform:
            translateY(0)
            scale(1);
    }
}
/* =========================================================
   HOP
========================================================= */
#vivisystem-bot.vivi-hop {
    animation:
        viviHop
        .65s
        cubic-bezier(.2,.8,.2,1);
}
@keyframes viviHop {
    0% {
        translate:
            0 0;
    }
    40% {
        translate:
            0 -20px;
    }
    70% {
        translate:
            0 2px;
    }
    100% {
        translate:
            0 0;
    }
}
/* =========================================================
   SPIN
========================================================= */
#vivisystem-bot.vivi-spin {
    filter: drop-shadow(0 10px 22px rgba(185,140,255,.38)) drop-shadow(0 0 12px rgba(126,208,255,.18));
}
#vivisystem-bot.vivi-spin .vivi-head {
    animation: viviSpin .82s cubic-bezier(.2,.8,.25,1) both;
    transform-origin: center center;
}
@keyframes viviSpin {
    0% { transform: rotate(0deg) scale(1); }
    34% { transform: rotate(145deg) scale(1.045); }
    69% { transform: rotate(305deg) scale(1.025); }
    100% { transform: rotate(360deg) scale(1); }
}
/* =========================================================
   WIND
========================================================= */
#vivisystem-bot .vivi-wind {
    position: absolute;
    left: -24px;
    height: 3px;
    border-radius: 999px;
    background:
        rgba(255,255,255,.85);
    opacity: 0;
    pointer-events: none;
}
#vivisystem-bot .vivi-wind.w1 {
    top: 32%;
    width: 13px;
}
#vivisystem-bot .vivi-wind.w2 {
    top: 50%;
    width: 22px;
}
#vivisystem-bot .vivi-wind.w3 {
    top: 69%;
    width: 10px;
}
#vivisystem-bot.vivi-wind .vivi-wind {
    animation:
        viviWind
        .7s
        ease-out
        forwards;
}
@keyframes viviWind {
    0% {
        opacity: 0;
        transform:
            translateX(20px)
            scaleX(.2);
    }
    20% {
        opacity: .9;
    }
    100% {
        opacity: 0;
        transform:
            translateX(-45px)
            scaleX(1.4);
    }
}
/* =========================================================
   GIFT
========================================================= */
#vivisystem-bot .vivi-gift {
    position: absolute;
    left: 50%;
    top: 100%;
    width: 27px;
    height: 23px;
    transform:
        translateX(-50%)
        scale(.2);
    opacity: 0;
    border-radius: 4px;
    background:
        linear-gradient(
            90deg,
            transparent 42%,
            white 42%,
            white 58%,
            transparent 58%
        ),
        #c79af3;
    border:
        1px solid
        rgba(255,255,255,.65);
}
#vivisystem-bot.vivi-gift .vivi-gift {
    animation:
        viviGift
        1.15s
        cubic-bezier(.2,.8,.2,1)
        forwards;
}
@keyframes viviGift {
    0% {
        opacity: 0;
        transform:
            translateX(-50%)
            scale(.2)
            translateY(10px);
    }
    30% {
        opacity: 1;
        transform:
            translateX(-50%)
            scale(1)
            translateY(0);
    }
    60% {
        transform:
            translateX(-50%)
            scale(1.15)
            translateY(-3px);
    }
    100% {
        opacity: 0;
        transform:
            translateX(-50%)
            scale(.7)
            translateY(-18px);
    }
}
/* =========================================================
   SKATEBOARD
========================================================= */
#vivisystem-bot .vivi-skateboard {
    position: absolute;
    left: 50%;
    top: 100%;
    width: 44px;
    height: 7px;
    transform:
        translateX(-50%);
    border-radius:
        999px;
    background:
        linear-gradient(
            90deg,
            #8150b4,
            #d7b9ff,
            #8150b4
        );
    opacity: 0;
}
#vivisystem-bot .vivi-skateboard::before,
#vivisystem-bot .vivi-skateboard::after {
    content: "";
    position: absolute;
    bottom: -6px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background:
        #24132f;
}
#vivisystem-bot .vivi-skateboard::before {
    left: 4px;
}
#vivisystem-bot .vivi-skateboard::after {
    right: 4px;
}
#vivisystem-bot.vivi-skate .vivi-skateboard {
    opacity: 1;
    animation:
        viviSkateboard
        2.4s
        ease-in-out
        forwards;
}
@keyframes viviSkateboard {
    0% {
        transform:
            translateX(-50%)
            rotate(-2deg);
    }
    30% {
        transform:
            translateX(-50%)
            rotate(3deg);
    }
    60% {
        transform:
            translateX(-50%)
            rotate(-2deg);
    }
    78% {
        transform:
            translateX(-50%)
            translateY(5px)
            rotate(17deg);
    }
    100% {
        transform:
            translateX(-50%)
            translateY(20px)
            rotate(55deg);
        opacity: 0;
    }
}
/* =========================================================
   WAVE
========================================================= */
#vivisystem-bot .vivi-wave {
    position: absolute;
    left: 50%;
    top: 100%;
    width: 80px;
    height: 18px;
    transform:
        translateX(-50%);
    border-radius:
        50%;
    background:
        radial-gradient(
            ellipse,
            rgba(120,220,255,.8),
            rgba(80,170,255,.35) 55%,
            transparent 70%
        );
    opacity: 0;
}
#vivisystem-bot.vivi-surf .vivi-wave {
    opacity: 1;
    animation:
        viviWave
        2.7s
        ease-in-out
        forwards;
}
@keyframes viviWave {
    0% {
        transform:
            translateX(-50%)
            scaleX(.55);
    }
    50% {
        transform:
            translateX(-50%)
            scaleX(1.2);
    }
    100% {
        transform:
            translateX(-50%)
            scaleX(.65);
        opacity: 0;
    }
}
/* =========================================================
   DRAWING (subtle lean / focus)
========================================================= */
#vivisystem-bot.vivi-drawing .vivi-head {
    animation:
        viviDrawLean
        2.8s
        ease-in-out;
}
@keyframes viviDrawLean {
    0%, 100% {
        transform:
            rotate(0deg);
    }
    25% {
        transform:
            rotate(-4deg)
            translateY(1px);
    }
    55% {
        transform:
            rotate(5deg)
            translateY(2px);
    }
    80% {
        transform:
            rotate(-2deg);
    }
}
/* =========================================================
   STATUS BUBBLE
========================================================= */
#vivisystem-bot .vivi-status {
    position: absolute;
    left: 50%;
    bottom:
        calc(100% + 12px);
    transform:
        translateX(-50%)
        translateY(8px)
        scale(.95);
    width: max-content;
    max-width:
        min(300px, 76vw);
    padding:
        9px 13px;
    border-radius:
        14px;
    background:
        rgba(250,246,255,.97);
    color:
        #29133d;
    border:
        1px solid
        rgba(185,140,255,.42);
    box-shadow:
        0 10px 28px
        rgba(60,25,100,.2);
    font:
        500 12px/1.45
        inherit;
    opacity: 0;
    pointer-events: none;
    transition:
        opacity .22s ease,
        transform .22s ease;
}
#vivisystem-bot .vivi-status.show {
    opacity: 1;
    transform:
        translateX(-50%)
        translateY(0)
        scale(1);
}
/* =========================================================
   HELP DIALOG (basic, so it works out of the box)
========================================================= */
#vivi-help-dialog {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(.96);
    width: min(340px, 90vw);
    padding: 22px 24px 18px;
    border-radius: 18px;
    background: rgba(250,246,255,.98);
    color: #29133d;
    border: 1px solid rgba(185,140,255,.45);
    box-shadow: 0 18px 50px rgba(60,25,100,.28);
    z-index: 10010;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease, transform .22s ease;
    font: 500 14px/1.5 inherit;
}
#vivi-help-dialog.show {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}
#vivi-help-dialog h3 {
    margin: 0 0 10px;
    font-size: 1.15rem;
}
#vivi-help-dialog p {
    margin: 0 0 12px;
    opacity: .9;
}
#vivi-help-dialog button {
    margin-top: 6px;
    padding: 8px 16px;
    border-radius: 999px;
    border: none;
    background: linear-gradient(135deg, #c99af5, #8955c2);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}
/* =========================================================
   MOBILE
========================================================= */
@media (max-width:600px) {
    #vivisystem-bot {
        --vivi-size:
            54px;
    }
    #vivisystem-bot .vivi-eye {
        width:
            6px;
        height:
            19px;
    }
    #vivisystem-bot .vivi-eye.left {
        left:
            29%;
    }
    #vivisystem-bot .vivi-eye.right {
        right:
            29%;
    }
}


/* Shape-only sparkle flecks for the dizzy/recovery animation. */
.vivi-dizzy-star {
  border-radius: 2px;
  background: radial-gradient(circle at 50% 50%, #fff 0 8%, #f3eaff 30%, #c69cff 70%, rgba(151,108,227,.12) 100%);
  clip-path: polygon(50% 0, 62% 37%, 100% 50%, 62% 63%, 50% 100%, 38% 63%, 0 50%, 38% 37%);
  filter: drop-shadow(0 0 5px rgba(230,207,255,.95)) drop-shadow(0 0 12px rgba(166,122,247,.55));
  will-change: transform, opacity;
}


/* Small facial reactions keep Vivi expressive without interrupting his movement. */
#vivisystem-bot .vivi-face { transform-origin: 50% 50%; }
#vivisystem-bot.vivi-expression-pop .vivi-face {
    animation: viviFacePop .34s cubic-bezier(.18,.82,.22,1);
}
@keyframes viviFacePop {
    0% { transform: scale(1); }
    42% { transform: scale(1.07) translateY(-1px); }
    100% { transform: scale(1); }
}
#vivisystem-bot[data-expression="neutral"] .vivi-mouth {
    opacity: .42; width: 9px; height: 2px; border-radius: 999px;
    transform: translateX(-50%) scaleY(1);
}
#vivisystem-bot[data-expression="curious"] .vivi-eye.left {
    transform: translateY(-2px) rotate(-4deg);
}
#vivisystem-bot[data-expression="curious"] .vivi-eye.right {
    transform: translateY(1px) rotate(3deg);
}
#vivisystem-bot[data-expression="curious"] .vivi-mouth {
    opacity: .9; width: 6px; height: 6px; border-radius: 50%;
}
#vivisystem-bot[data-expression="excited"] .vivi-cheek,
#vivisystem-bot[data-expression="shy"] .vivi-cheek {
    opacity: .85; transform: scale(1.12);
}
#vivisystem-bot[data-expression="shy"] .vivi-mouth {
    opacity: .8; width: 8px; height: 4px; border-radius: 0 0 999px 999px;
}
#vivisystem-bot[data-expression="confused"] .vivi-mouth {
    opacity: .85; width: 8px; height: 5px; border-radius: 50%;
}
#vivisystem-bot[data-expression="surprised"] .vivi-cheek { opacity: .48; }
#vivisystem-bot:focus-visible {
    outline: 2px solid rgba(190,153,255,.9);
    outline-offset: 6px;
    border-radius: 50%;
}

/* Dedicated mobile pages keep the companion in chat, not floating over content. */
body[data-vivi-chat-only] #vivisystem-bot,
body[data-vivi-chat-only] #vivi-tools-menu,
body[data-vivi-chat-only] #vivi-edge-peek {
    display: none !important;
}
@media(prefers-reduced-motion:reduce) {
    #vivisystem-bot.vivi-expression-pop .vivi-face { animation:none !important; }
    #vivisystem-bot.vivi-spin .vivi-head { animation:none !important; }
}


/* Coordinated face acting for Vivi's existing physical actions. The head keeps
   its own silhouette while the eyes and mouth add a small readable reaction. */
#vivisystem-bot.vivi-bounce .vivi-face { animation:viviFaceBounce .7s cubic-bezier(.2,.8,.2,1); }
@keyframes viviFaceBounce {
  0%,100% { transform:translateY(0) rotate(0) scale(1); }
  34% { transform:translateY(-1px) rotate(-3deg) scale(1.035); }
  58% { transform:translateY(1px) rotate(2deg) scale(.98); }
}
#vivisystem-bot.vivi-hop .vivi-face { animation:viviFaceHop .65s cubic-bezier(.2,.8,.2,1); }
@keyframes viviFaceHop {
  0%,100% { transform:rotate(0) scale(1); }
  35% { transform:rotate(-5deg) scale(1.035); }
  72% { transform:rotate(3deg) scale(.985); }
}
#vivisystem-bot.vivi-squish .vivi-face { animation:viviFaceSquish .55s cubic-bezier(.2,.8,.2,1); }
@keyframes viviFaceSquish {
  0%,100% { transform:scale(1); }
  30% { transform:scaleX(1.08) scaleY(.88) translateY(1px); }
  65% { transform:scaleX(.96) scaleY(1.06) translateY(-1px); }
}
#vivisystem-bot.vivi-wind .vivi-face { animation:viviFaceWind .7s ease-out; }
@keyframes viviFaceWind {
  0%,100% { transform:translateX(0) rotate(0); }
  28% { transform:translateX(2px) rotate(5deg); }
  62% { transform:translateX(-1px) rotate(-3deg); }
}
#vivisystem-bot.vivi-gift .vivi-face { animation:viviFaceGift 1.15s cubic-bezier(.18,.82,.22,1); }
@keyframes viviFaceGift {
  0%,100% { transform:translateY(0) scale(1); }
  24% { transform:translateY(-2px) scale(1.035); }
  52% { transform:translateY(1px) scale(.99); }
  76% { transform:translateY(-1px) scale(1.02); }
}
#vivisystem-bot.vivi-skate .vivi-face { animation:viviFaceSkate 2.4s ease-in-out; }
@keyframes viviFaceSkate {
  0%,100% { transform:rotate(0); }
  28% { transform:rotate(-4deg) translateY(1px); }
  58% { transform:rotate(4deg) translateY(-1px); }
  82% { transform:rotate(-2deg); }
}
#vivisystem-bot.vivi-drawing .vivi-face { animation:viviFaceFocus 2.8s ease-in-out; }
@keyframes viviFaceFocus {
  0%,100% { transform:rotate(0) translateY(0); }
  25% { transform:rotate(-3deg) translateY(1px); }
  55% { transform:rotate(3deg) translateY(2px); }
  82% { transform:rotate(-1deg); }
}
@media(prefers-reduced-motion:reduce) {
  #vivisystem-bot.vivi-bounce .vivi-face,
  #vivisystem-bot.vivi-hop .vivi-face,
  #vivisystem-bot.vivi-squish .vivi-face,
  #vivisystem-bot.vivi-wind .vivi-face,
  #vivisystem-bot.vivi-gift .vivi-face,
  #vivisystem-bot.vivi-skate .vivi-face,
  #vivisystem-bot.vivi-drawing .vivi-face { animation:none !important; }
}
