/* ============================================
 * 辉夜姬虚拟宠物（kaguya-pet）
 * 方案：静态立绘 + CSS GPU 呼吸动画（合成器渲染，无帧切换撕裂）
 * 交互：点击卖萌 · 拖拽物理（落地弹跳 + 蹦跳回位）
 * 风格：粉色马卡龙 · 星星 · 白底胶囊气泡
 * ============================================ */

/* 外层容器：定位 / 拖拽 / 点击 / 物理动画（transform 挂外层，呼吸挂内层，互不冲突） */
#kaguya-pet {
    position: fixed;
    right: 14px;
    bottom: 8px;
    z-index: 9996;
    width: 192px;
    height: 208px;               /* 1:1 原尺寸 */
    cursor: grab;
    touch-action: none;          /* 触摸拖拽不被页面滚动接管 */
    -webkit-user-select: none;
    user-select: none;
    filter: drop-shadow(0 8px 16px rgba(255, 173, 208, 0.45));
    transition: transform 0.25s ease, filter 0.25s ease, left 0.3s ease, top 0.3s ease;
    pointer-events: auto;
}

#kaguya-pet:hover {
    transform: translateY(-5px) scale(1.04);
    filter: drop-shadow(0 12px 22px rgba(255, 160, 200, 0.6));
}

/* 拖拽中：禁用 hover 位移，即时跟随鼠标 */
#kaguya-pet.dragging {
    transition: none !important;
    cursor: grabbing;
    z-index: 9999;
    filter: drop-shadow(0 14px 24px rgba(255, 160, 200, 0.6));
}

#kaguya-pet.dragging:hover {
    transform: none;
}

/* 点击弹跳 */
#kaguya-pet.bounce {
    animation: kaguyaPetBounce 0.55s ease;
}

@keyframes kaguyaPetBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    18%      { transform: translateY(-22px) scale(1.06, 0.94); }
    38%      { transform: translateY(0) scale(0.96, 1.05); }
    55%      { transform: translateY(-12px) scale(1.03, 0.97); }
    72%      { transform: translateY(0) scale(0.98, 1.02); }
}

/* 拖拽松手后的落地弹跳（不高，两次小弹） */
#kaguya-pet.bounce-land {
    animation: kaguyaLandBounce 0.9s ease;
}

@keyframes kaguyaLandBounce {
    0%   { transform: translateY(0) scale(1); }
    15%  { transform: translateY(-26px) scale(1.04, 0.96); }
    35%  { transform: translateY(0) scale(0.96, 1.04); }
    50%  { transform: translateY(-13px) scale(1.02, 0.98); }
    68%  { transform: translateY(0) scale(0.99, 1.01); }
    82%  { transform: translateY(-5px); }
    100% { transform: translateY(0) scale(1); }
}

/* 蹦跳回位时的一小跳 */
#kaguya-pet.hop {
    animation: kaguyaHop 0.3s ease-in-out;
}

@keyframes kaguyaHop {
    0%   { transform: translateY(0); }
    40%  { transform: translateY(-22px); }
    75%  { transform: translateY(2px); }
    100% { transform: translateY(0); }
}

/* 内层立绘：GPU 呼吸动画（transform / opacity 由合成器渲染，全程平滑） */
#kaguya-pet img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    -webkit-user-drag: none;     /* 防止图片原生拖拽 */
    transform-origin: 50% 92%;   /* 以脚底为轴，起伏更自然 */
    animation: kaguyaBreathe 3.4s ease-in-out infinite;
    will-change: transform;
}

@keyframes kaguyaBreathe {
    0%, 100% { transform: translateY(0) scale(1) rotate(0deg); }
    25%      { transform: translateY(-1.5px) scale(1.008, 1.012) rotate(0.15deg); }
    50%      { transform: translateY(-3.5px) scale(1.016, 1.024) rotate(0.35deg); }
    75%      { transform: translateY(-1.5px) scale(1.008, 1.012) rotate(0.15deg); }
}

/* 脸朝左（向右蹦跳回位时水平翻转，呼吸动画保持） */
#kaguya-pet img.facing-left {
    animation: kaguyaBreatheFlip 3.4s ease-in-out infinite;
}

@keyframes kaguyaBreatheFlip {
    0%, 100% { transform: scaleX(-1) translateY(0) scale(1) rotate(0deg); }
    25%      { transform: scaleX(-1) translateY(-1.5px) scale(1.008, 1.012) rotate(0.15deg); }
    50%      { transform: scaleX(-1) translateY(-3.5px) scale(1.016, 1.024) rotate(0.35deg); }
    75%      { transform: scaleX(-1) translateY(-1.5px) scale(1.008, 1.012) rotate(0.15deg); }
}

/* 台词气泡：白底胶囊 + 星星 + 空心爱心（跟随宠物定位） */
#kaguya-pet-bubble {
    position: absolute;
    right: 218px;                /* 宠物左侧：气泡右缘 = 宠物 div 左缘再向左 26px */
    bottom: 86px;
    z-index: 9998;
    width: 250px;                /* 固定宽度：定位点超出容器导致 shrink-to-fit 失效，需显式给宽 */
    max-width: 250px;
    text-align: center;
    background: rgb(255 255 255 / 95%);
    color: #b06a8a;
    font-size: 13px;
    line-height: 1.6;
    padding: 10px 34px;
    border-radius: 999px;
    border: 1.5px solid #ffd3e3;
    box-shadow: 0 8px 22px rgb(255 173 208 / 35%), 0 2px 6px rgb(255 173 208 / 18%);
    opacity: 0;
    transform: translateY(10px) scale(0.92);
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.28s ease;
    white-space: normal;         /* 长台词自动换行，避免超出气泡 */
    word-break: break-word;
    overflow-wrap: anywhere;
}

#kaguya-pet-bubble.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* 气泡装饰：左星星 右空心爱心 */
#kaguya-pet-bubble::before {
    content: "✦";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #ffd76a;
    font-size: 12px;
}

#kaguya-pet-bubble::after {
    content: "♡";
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #ff9ecb;
    font-size: 13px;
}

/* 小尾巴（指向宠物） */
#kaguya-pet-bubble .pet-tail {
    position: absolute;
    right: -9px;
    bottom: 18px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #ffd3e3;
}

/* 移动端缩小，避免遮挡内容 */
@media screen and (max-width: 767px) {
    #kaguya-pet {
        width: 108px;
        height: 117px;
        right: 8px;
        bottom: 6px;
    }
    #kaguya-pet-bubble {
        right: 122px;
        bottom: 62px;
        font-size: 12px;
        padding: 8px 30px;
        width: 210px;
        max-width: 210px;
    }
}
