/* ============================================================
   10-pet.css —— 右下角捏捏角色
   功能：
   1. 角色缩放动画（点击 / 拖拽 / 呼吸）
   2. 气泡框：上下 × 左右 四种方向自适应
   3. 设置面板：上下 × 左右 四种方向自适应
   4. 移动端适配
   ============================================================ */

/* ---------- 角色容器 ---------- */
#petWidget {
    --pet-size: 96px;
    position: fixed;
    right: 24px;
    bottom: 110px;
    z-index: 9998;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    display: inline-block;
    line-height: 0;
}

/* ---------- sprite 容器：承担水平镜像 ---------- */
.pet-sprite {
    width: var(--pet-size);
    height: var(--pet-size);
    display: block;
    transform: scaleX(1);
    transition: transform 0.3s ease;
    position: relative;
}
.pet-sprite.flipped {
    transform: scaleX(-1);
}

/* ---------- 角色图片 ---------- */
.pet-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    transform-origin: center bottom;
    transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1),
                filter 0.12s ease;
    will-change: transform;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
}

/* 按下：捏扁 */
#petWidget.pet-pressed .pet-img {
    transform: scale(0.88);
    filter: brightness(1.08) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.12));
    transition: transform 0.08s ease-out, filter 0.08s ease-out;
    animation: none;
}

/* 回弹：稍微过冲 */
#petWidget.pet-bounce .pet-img {
    transform: scale(1.08);
    transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: none;
}

/* 稳定：回到原始 + 呼吸动画 */
#petWidget.pet-idle .pet-img {
    transform: scale(1);
    transition: transform 0.12s ease-out;
    animation: petBreath 3.2s ease-in-out infinite;
}

/* 拖拽中：稍微放大并提高阴影 */
#petWidget.pet-dragging .pet-img {
    transform: scale(1.05);
    filter: brightness(1.05) drop-shadow(0 8px 16px rgba(0, 0, 0, 0.22));
    transition: transform 0.15s ease, filter 0.15s ease;
    animation: none;
}

@keyframes petBreath {
    0%, 100% { transform: scale(1) translateY(0); }
    50%      { transform: scale(1.02) translateY(-2px); }
}

/* ---------- 设置按钮（角色右上角） ---------- */
.pet-settings-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #d0d7de;
    color: #666;
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    transition: transform 0.2s ease, background 0.2s ease;
    z-index: 3;
}
.pet-settings-btn:hover {
    background: #f0f7f4;
    color: #3f7e6b;
    transform: scale(1.1) rotate(45deg);
}

/* ============================================================
   设置面板：基础样式 + 四种方向
   ============================================================ */
.pet-settings-panel {
    position: absolute;
    width: 200px;
    max-width: calc(100vw - 40px);
    background: #fff;
    border: 1px solid #e8ecf0;
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
    font-size: 0.85rem;
    color: #333;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px) scale(0.96);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    pointer-events: none;
    z-index: 2;
    box-sizing: border-box;
}
.pet-settings-panel.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* 默认（右半侧 + 底部）：面板在角色上方，靠右对齐 */
.pet-settings-panel {
    right: 0;
    left: auto;
    bottom: calc(100% + 10px);
    top: auto;
    transform-origin: bottom right;
}

/* 左半侧 + 底部：面板在角色上方，靠左对齐 */
#petWidget.left-side .pet-settings-panel {
    right: auto;
    left: 0;
    bottom: calc(100% + 10px);
    top: auto;
    transform-origin: bottom left;
}

/* 右半侧 + 顶部：面板在角色下方，靠右对齐 */
#petWidget.top-side .pet-settings-panel {
    right: 0;
    left: auto;
    bottom: auto;
    top: calc(100% + 10px);
    transform-origin: top right;
    transform: translateY(-6px) scale(0.96);
}
#petWidget.top-side .pet-settings-panel.show {
    transform: translateY(0) scale(1);
}

/* 左半侧 + 顶部：面板在角色下方，靠左对齐 */
#petWidget.top-side.left-side .pet-settings-panel {
    right: auto;
    left: 0;
    bottom: auto;
    top: calc(100% + 10px);
    transform-origin: top left;
    transform: translateY(-6px) scale(0.96);
}
#petWidget.top-side.left-side .pet-settings-panel.show {
    transform: translateY(0) scale(1);
}

.pet-settings-title {
    font-weight: 600;
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 8px;
}
.pet-size-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}
.pet-size-options button {
    padding: 6px 0;
    border-radius: 8px;
    border: 1px solid #d0d7de;
    background: #f8fafc;
    color: #444;
    font-size: 0.78rem;
    cursor: pointer;
    transition: 0.2s;
}
.pet-size-options button:hover {
    background: #eef2f6;
}
.pet-size-options button.active {
    background: #3f7e6b;
    color: #fff;
    border-color: #3f7e6b;
}
.pet-reset-pos {
    width: 100%;
    padding: 7px 0;
    border-radius: 30px;
    border: none;
    background: #eef2f6;
    color: #3f7e6b;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}
.pet-reset-pos:hover {
    background: #dce2ea;
}

/* ============================================================
   气泡框：基础样式 + 四种方向
   ============================================================ */
#petBubble {
    position: absolute;
    width: 240px;
    max-width: calc(100vw - 60px);
    background: #ffffff;
    border: 1px solid #e8ecf0;
    border-radius: 14px;
    padding: 12px 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    font-size: 0.86rem;
    color: #333;
    line-height: 1.6;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px) scale(0.96);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    pointer-events: none;
    z-index: 1;
    box-sizing: border-box;
}
#petBubble.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* 默认（右半侧 + 底部）：气泡在角色上方，靠右对齐，三角在右下 */
#petBubble {
    right: 0;
    left: auto;
    bottom: calc(100% + 12px);
    top: auto;
    transform-origin: bottom right;
}
#petBubble::after {
    content: '';
    position: absolute;
    bottom: -7px;
    right: 22px;
    left: auto;
    top: auto;
    width: 12px;
    height: 12px;
    background: #ffffff;
    border-right: 1px solid #e8ecf0;
    border-bottom: 1px solid #e8ecf0;
    border-left: none;
    border-top: none;
    transform: rotate(45deg);
    border-radius: 0 0 2px 0;
}

/* 左半侧 + 底部：气泡在角色上方，靠左对齐，三角在左下 */
#petWidget.left-side #petBubble {
    right: auto;
    left: 0;
    bottom: calc(100% + 12px);
    top: auto;
    transform-origin: bottom left;
}
#petWidget.left-side #petBubble::after {
    right: auto;
    left: 22px;
    bottom: -7px;
    top: auto;
    border-right: none;
    border-bottom: none;
    border-left: 1px solid #e8ecf0;
    border-top: 1px solid #e8ecf0;
    border-radius: 2px 0 0 0;
}

/* 右半侧 + 顶部：气泡在角色下方，靠右对齐，三角在右上 */
#petWidget.top-side #petBubble {
    right: 0;
    left: auto;
    bottom: auto;
    top: calc(100% + 12px);
    transform-origin: top right;
    transform: translateY(-6px) scale(0.96);
}
#petWidget.top-side #petBubble.show {
    transform: translateY(0) scale(1);
}
#petWidget.top-side #petBubble::after {
    bottom: auto;
    top: -7px;
    right: 22px;
    left: auto;
    border-right: 1px solid #e8ecf0;
    border-top: 1px solid #e8ecf0;
    border-bottom: none;
    border-left: none;
    border-radius: 0 2px 0 0;
    transform: rotate(45deg);
}

/* 左半侧 + 顶部：气泡在角色下方，靠左对齐，三角在左上 */
#petWidget.top-side.left-side #petBubble {
    right: auto;
    left: 0;
    bottom: auto;
    top: calc(100% + 12px);
    transform-origin: top left;
    transform: translateY(-6px) scale(0.96);
}
#petWidget.top-side.left-side #petBubble.show {
    transform: translateY(0) scale(1);
}
#petWidget.top-side.left-side #petBubble::after {
    right: auto;
    left: 22px;
    bottom: auto;
    top: -7px;
    border-left: 1px solid #e8ecf0;
    border-top: 1px solid #e8ecf0;
    border-right: none;
    border-bottom: none;
    border-radius: 2px 0 0 0;
    transform: rotate(45deg);
}

/* 气泡内文本 */
#petBubble .pet-text {
    margin: 0 0 8px 0;
    color: #1a2a3a;
    font-weight: 500;
}

/* 气泡内动作按钮 */
#petBubble .pet-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eef2f6;
}
#petBubble .pet-action-btn {
    flex: 1;
    background: #3f7e6b;
    color: #fff;
    border: none;
    border-radius: 30px;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.12s ease;
    white-space: nowrap;
}
#petBubble .pet-action-btn:hover { background: #2f5b50; }
#petBubble .pet-action-btn:active { transform: scale(0.95); }
#petBubble .pet-action-btn.secondary {
    background: #eef2f6;
    color: #3f7e6b;
}
#petBubble .pet-action-btn.secondary:hover { background: #dce2ea; }

/* ============================================================
   移动端适配
   ============================================================ */
@media (max-width: 768px) {
    #petWidget {
        right: 14px;
        bottom: 96px;
    }
    #petBubble {
        width: 200px;
        max-width: calc(100vw - 32px);
        font-size: 0.82rem;
        padding: 10px 12px;
    }
    .pet-settings-panel {
        width: 180px;
        max-width: calc(100vw - 32px);
    }
}

@media (max-width: 380px) {
    #petBubble {
        max-width: calc(100vw - 24px);
        font-size: 0.78rem;
    }
    .pet-settings-panel {
        max-width: calc(100vw - 24px);
    }
}