/* whale.css —— 像素鲸鱼桌宠：半隐藏交互 + 状态动效 */

.pixel-whale {
    --whale-size: 64px;
    --whale-color: #7fb8ff;
    position: fixed;
    right: 0;
    bottom: calc(88px + env(safe-area-inset-bottom));
    width: var(--whale-size);
    height: var(--whale-size);
    color: var(--whale-color);
    z-index: 120; /* 在聊天区之上，但不影响输入区/底部栏的层级判断 */
    pointer-events: auto;
    cursor: grab;
    opacity: 1;
    touch-action: none;
    transition: transform 0.35s cubic-bezier(0.22, 0.9, 0.3, 1);
    will-change: transform;
}

.pixel-whale:active { cursor: grabbing; }

/* 默认：只露出左半边，贴在右侧边缘 */
.pixel-whale.whale-docked { transform: translateX(52%); }
.pixel-whale.whale-popped { transform: translateX(0); }
.pixel-whale.whale-free { transform: none; }

.pixel-whale .whale-svg {
    width: 100%;
    height: 100%;
    display: block;
    transform-origin: 50% 80%;
    transition: transform 0.3s ease, filter 0.3s ease, opacity 0.3s ease;
}

.pixel-whale .whale-svg svg {
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
}

/* ---------------- emoji 冒泡 ---------------- */
.whale-fx {
    position: absolute;
    left: 50%;
    top: -6px;
    width: 0;
    height: 0;
    pointer-events: none;
}

.whale-emoji-bubble {
    position: absolute;
    left: -8px;
    top: 0;
    font-size: 16px;
    line-height: 1;
    opacity: 0;
    animation: whaleEmojiFloat 1.8s ease-out forwards;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.whale-emoji-bubble.slow { animation-duration: 2.8s; }

.whale-text-bubble {
    font-size: 12px;
    color: #ffb3d9;
    font-weight: 600;
    animation-duration: 2.2s;
}

@keyframes whaleEmojiFloat {
    0% { opacity: 0; transform: translateY(8px) scale(0.7); }
    25% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-30px) scale(1.05); }
}

/* ---------------- 设备状态 ---------------- */
.pixel-whale.state-idle .whale-inner { animation: whaleFloat 3s ease-in-out infinite; }

.pixel-whale.state-curious .whale-svg { animation: whaleSway 2.2s ease-in-out infinite; }

.pixel-whale.state-thinking .whale-eye { animation: whaleBlink 1.2s infinite; }
.pixel-whale.state-thinking .whale-bubble,
.pixel-whale.state-bubble .whale-bubble { animation: whaleBubble 1.6s ease-out infinite; }
.pixel-whale.state-thinking .whale-bubble:nth-of-type(2),
.pixel-whale.state-bubble .whale-bubble:nth-of-type(2) { animation-delay: 0.5s; }
.pixel-whale.state-thinking .whale-bubble:nth-of-type(3),
.pixel-whale.state-bubble .whale-bubble:nth-of-type(3) { animation-delay: 1s; }

.pixel-whale.state-drowsy .whale-svg {
    opacity: 0.6;
    animation: whaleSinkSlow 4s ease-in-out infinite;
}

.pixel-whale.state-sleeping .whale-svg {
    opacity: 0.4;
    animation: whaleSleepBreath 3.2s ease-in-out infinite;
}

/* 睡着时头顶飘 Z */
.pixel-whale.state-sleeping::after {
    content: "Z";
    position: absolute;
    top: -10px;
    right: 8px;
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.55);
    animation: whaleZFloat 2.4s ease-out infinite;
    pointer-events: none;
}

@keyframes whaleZFloat {
    0% { opacity: 0; transform: translateY(4px) scale(0.8); }
    30% { opacity: 0.9; }
    100% { opacity: 0; transform: translateY(-16px) scale(1.1); }
}

@keyframes whaleSway {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg); }
}

@keyframes whaleSinkSlow {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(4px); }
}

@keyframes whaleSleepBreath {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

/* ---------------- 情绪状态 ---------------- */

/* blush：脸红 */
.pixel-whale.state-blush .whale-svg {
    filter: hue-rotate(-20deg);
    box-shadow: 0 0 16px rgba(255, 105, 180, 0.55);
    border-radius: 18px;
}

/* happy：开心 */
.pixel-whale.state-happy .whale-svg {
    filter: brightness(1.2);
    animation: whaleBounce 0.8s ease-in-out infinite;
}

/* sad：垂头丧气 */
.pixel-whale.state-sad .whale-svg {
    filter: grayscale(0.6) saturate(0.2);
    animation: whaleSadDrop 2.6s ease-in-out infinite;
}
.pixel-whale.state-sad .whale-eye { animation: whaleSadEyes 2.6s ease-in-out infinite; }

/* surprised：慌张 */
.pixel-whale.state-surprised .whale-svg {
    transform: scale(1.1);
    animation: whaleShake 0.4s linear infinite;
}

/* angry：心疼式生气 */
.pixel-whale.state-angry .whale-svg {
    transform: scale(1.15);
    filter: hue-rotate(30deg) saturate(1.5);
}

/* excited：兴奋 */
.pixel-whale.state-excited .whale-svg {
    transform: scale(1.1);
    animation: whaleBounce 0.6s ease-in-out infinite;
}

/* panic：慌张/不安 */
.pixel-whale.state-panic .whale-svg {
    animation: whaleShake 0.32s linear infinite;
}

/* possessive：占有欲 */
.pixel-whale.state-possessive .whale-svg {
    opacity: 0.7;
    transform: rotate(-3deg);
    filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.6));
}

/* glitch：宕机/过载 */
.pixel-whale.state-glitch .whale-svg {
    transform: scaleY(0.3) scaleX(1.4);
    opacity: 0.6;
    animation: whaleGlitch 0.2s steps(2) infinite;
}

/* stubborn：委屈 */
.pixel-whale.state-stubborn .whale-svg {
    transform: translateX(10px);
    animation: whaleStubbornSway 1.6s ease-in-out infinite;
}

/* melt：融化 */
.pixel-whale.state-melt .whale-svg {
    transform: scaleY(0.5) scaleX(1.5);
    box-shadow: 0 0 18px rgba(255, 105, 180, 0.45);
    border-radius: 30px;
}

/* strict：极度严厉 */
.pixel-whale.state-strict .whale-svg {
    transform: scale(1.3);
    filter: hue-rotate(180deg) saturate(2);
    box-shadow: 0 0 22px rgba(255, 40, 40, 0.55);
    border-radius: 16px;
    animation: whaleStrictShake 0.1s linear infinite;
}

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

@keyframes whaleSadDrop {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(3px); }
}

@keyframes whaleSadEyes {
    0%, 100% { transform: scaleY(1) rotate(0deg); }
    50% { transform: scaleY(0.6) rotate(12deg); }
}

@keyframes whaleShake {
    0% { transform: scale(1.1) translateX(0); }
    25% { transform: scale(1.1) translateX(-2px); }
    50% { transform: scale(1.1) translateX(2px); }
    75% { transform: scale(1.1) translateX(-1px); }
    100% { transform: scale(1.1) translateX(0); }
}

@keyframes whaleGlitch {
    0% { transform: scaleY(0.3) scaleX(1.4) translateX(-2px); opacity: 0.45; }
    50% { transform: scaleY(0.3) scaleX(1.4) translateX(2px); opacity: 0.7; }
    100% { transform: scaleY(0.3) scaleX(1.4) translateX(-1px); opacity: 0.55; }
}

@keyframes whaleStubbornSway {
    0%, 100% { transform: translateX(10px) rotate(0deg); }
    50% { transform: translateX(10px) rotate(-4deg); }
}

@keyframes whaleStrictShake {
    0% { transform: scale(1.3) translateX(0); }
    25% { transform: scale(1.3) translateX(-1.5px); }
    50% { transform: scale(1.3) translateX(1.5px); }
    75% { transform: scale(1.3) translateX(-1px); }
    100% { transform: scale(1.3) translateX(0); }
}

/* 拖拽时不要过渡，跟手 */
.pixel-whale.whale-grabbing { transition: none; }
