.mascot {
    --shift: 0px;
    --look-x: 0;
    --look-y: 0;
    position: relative;
    user-select: none;
}

.mascot-figure {
    position: relative;
    translate: 0 var(--shift);
    transition: translate 0.6s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.mascot-look {
    transform: perspective(900px) rotateY(calc(var(--look-x) * 16deg)) rotateX(calc(var(--look-y) * -8deg));
    transition: transform 0.5s var(--ease);
}

.mascot-pose {
    position: relative;
    transform-origin: 50% 95%;
    filter: drop-shadow(0 10px 14px rgb(23 32 56 / 22%));
    animation: breathe 3.6s ease-in-out infinite;
}

.mascot-layer {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
}

.mascot-layer:not(.is-body) {
    position: absolute;
    inset: 0;
}

.is-pointer {
    transform-origin: 14.1% 45.8%;
    rotate: var(--arm, 0deg);
    transition: rotate 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
    animation: sway 3.2s ease-in-out infinite;
}

.is-blink {
    opacity: 0;
    animation: blink 5.2s steps(1) infinite var(--blink-delay, 0s);
}

.is-happy {
    opacity: 0;
    transition: opacity 0.1s;
}

/* Moods */

.mascot[data-mood="point"] { --arm: -22deg; }
.mascot[data-mood="watch"] { --arm: -12deg; }
.mascot[data-mood="think"] { --arm: 14deg; }
.mascot[data-mood="happy"],
.mascot[data-mood="cheer"] { --arm: 26deg; }
.mascot[data-mood="sad"],
.mascot[data-mood="shy"] { --arm: -42deg; }
.mascot[data-mood="shy"] .is-blink { animation: none; opacity: 1; }
.mascot[data-mood="shy"] .mascot-pose { animation: lean 2.4s ease-in-out infinite reverse; }

.mascot[data-mood="watch"] .mascot-pose { animation: lean 2.4s ease-in-out infinite; }
.mascot[data-mood="think"] .mascot-pose { animation: ponder 1.6s ease-in-out infinite alternate; }
.mascot[data-mood="happy"] .mascot-pose { animation: hop 0.8s cubic-bezier(0.3, 1.5, 0.6, 1); }
.mascot[data-mood="cheer"] .mascot-pose { animation: hop 0.9s cubic-bezier(0.3, 1.5, 0.6, 1) infinite; }
.mascot[data-mood="sad"] .mascot-pose { animation: slump 0.9s ease-out forwards; }

.mascot[data-mood="point"] .is-pointer { animation: tap 0.9s ease-in-out infinite; }
.mascot[data-mood="happy"] .is-pointer,
.mascot[data-mood="cheer"] .is-pointer { animation: wave 0.5s ease-in-out infinite alternate; }
.mascot[data-mood="sad"] .is-pointer,
.mascot[data-mood="think"] .is-pointer { animation: none; }

.mascot:is([data-mood="happy"], [data-mood="cheer"]) .is-happy { opacity: 1; }
.mascot:is([data-mood="happy"], [data-mood="cheer"]) .is-blink { animation: none; }
.mascot[data-mood="think"] .is-blink { animation: blink 1.6s steps(1) infinite; }

.mascot[data-talking]:is([data-mood="idle"], [data-mood="point"], [data-mood="watch"]) .mascot-pose {
    animation: chatter 0.36s ease-in-out infinite alternate;
}

.mascot[data-talking]:is([data-mood="idle"], [data-mood="point"]) .is-pointer {
    animation: tap 0.6s ease-in-out infinite;
}

/* Sparkles when happy, a sweat drop when sad */

.mascot-figure::before,
.mascot-figure::after {
    content: "";
    position: absolute;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
}

.mascot:is([data-mood="happy"], [data-mood="cheer"]) .mascot-figure::before,
.mascot:is([data-mood="happy"], [data-mood="cheer"]) .mascot-figure::after {
    top: 6%;
    width: 18%;
    aspect-ratio: 1;
    background: var(--gold);
    clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
    animation: sparkle 0.9s ease-out;
}

.mascot:is([data-mood="happy"], [data-mood="cheer"]) .mascot-figure::before { left: 2%; }
.mascot:is([data-mood="happy"], [data-mood="cheer"]) .mascot-figure::after { right: 4%; top: 14%; width: 12%; background: var(--accent-2); animation-delay: 0.12s; }
.mascot[data-mood="cheer"] .mascot-figure::before,
.mascot[data-mood="cheer"] .mascot-figure::after { animation-iteration-count: infinite; }

.mascot[data-mood="sad"] .mascot-figure::after {
    top: 10%;
    right: 26%;
    width: 7%;
    aspect-ratio: 0.75;
    border-radius: 50% 0 50% 50%;
    background: linear-gradient(135deg, #bfe9ff, #5cc8ff);
    rotate: -45deg;
    animation: sweat 1.4s ease-in 0.3s forwards;
}

/* Speech bubble: above the mascot by default; .bubble-left / .bubble-right on an ancestor put it beside. */

.mascot-bubble {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    z-index: 2;
    width: max-content;
    max-width: min(250px, 70vw);
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.45;
    text-align: left;
    box-shadow: var(--shadow);
    translate: -50% 0;
    cursor: pointer;
}

.mascot-bubble::after {
    content: "";
    position: absolute;
    top: calc(100% - 7px);
    left: calc(50% - 7px);
    width: 13px;
    height: 13px;
    border: 2px solid var(--border);
    border-top: 0;
    border-left: 0;
    background: var(--surface);
    rotate: 45deg;
}

.bubble-left .mascot-bubble,
.bubble-right .mascot-bubble {
    top: 8%;
    bottom: auto;
    translate: none;
}

.bubble-left .mascot-bubble {
    left: auto;
    right: calc(100% + 12px);
}

.bubble-right .mascot-bubble {
    left: calc(100% + 12px);
}

.bubble-left .mascot-bubble::after,
.bubble-right .mascot-bubble::after {
    top: 14px;
}

.bubble-left .mascot-bubble::after {
    left: calc(100% - 7px);
    rotate: -45deg;
}

.bubble-right .mascot-bubble::after {
    left: -8px;
    rotate: 135deg;
}

.mascot-pending {
    color: transparent;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

@keyframes breathe {
    50% { transform: translateY(-4px) scale(1.012, 0.994); }
}

@keyframes chatter {
    to { transform: translateY(-3px) rotate(-1.2deg); }
}

@keyframes lean {
    50% { transform: translateX(-6px) rotate(-3deg); }
}

@keyframes ponder {
    from { transform: rotate(2deg); }
    to { transform: rotate(5deg) translateY(2px); }
}

@keyframes hop {
    25% { transform: translateY(-26px) scale(0.95, 1.06); }
    50% { transform: translateY(0) scale(1.06, 0.94); }
    70% { transform: translateY(-7px); }
}

@keyframes slump {
    20% { transform: translateX(-5px) rotate(-3deg); }
    40% { transform: translateX(5px) rotate(2deg); }
    to { transform: translateY(6px) rotate(-2deg) scale(1, 0.98); }
}

@keyframes sway {
    50% { transform: rotate(-6deg); }
}

@keyframes tap {
    30% { transform: rotate(-9deg); }
    45% { transform: rotate(2deg); }
}

@keyframes wave {
    to { transform: rotate(-18deg); }
}

@keyframes blink {
    0%, 95% { opacity: 0; }
    96%, 99% { opacity: 1; }
}

@keyframes sparkle {
    0% { opacity: 0; scale: 0.2; rotate: 0deg; }
    40% { opacity: 1; scale: 1.1; }
    100% { opacity: 0; scale: 0.6; rotate: 90deg; translate: 0 -12px; }
}

@keyframes sweat {
    0% { opacity: 0; translate: 0 0; }
    20% { opacity: 1; }
    100% { opacity: 0; translate: 0 24px; }
}
