/* =========================================================
   DSH 桌宠 · 多皮肤通用样式
   - 默认为大肥鱼正方形比例
   - 若皮肤带 aspect ratio(如 Kun Like 192×208),通过 --pet-ratio 覆盖
   ========================================================= */

.dsh-pet {
  --pet-size: 120px;            /* 桌宠显示高度 */
  --pet-ratio: 1 / 1;           /* 宽/高,默认 1:1,可被 JS 覆盖 */
  --pet-accent: #5ecbff;        /* 主题色(对应气泡/面板描边投影,按皮肤换) */
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
  height: var(--pet-size);
  width: calc(var(--pet-size) * var(--pet-ratio));
  user-select: none;
  touch-action: none;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.18));
  transition: transform 0.15s ease;
}
.dsh-pet.is-dragging { transition: none; }
.dsh-pet:hover        { transform: scale(1.03); }

/* 桌宠预览卡(个人中心里用) */
.pet-skins {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.pet-skin-card {
  position: relative;
  border: 1.5px solid var(--border-subtle, #e6e6e6);
  background: var(--surface-card, #fff);
  border-radius: 16px;
  padding: 14px 14px 12px;
  cursor: pointer;
  transition: all .2s cubic-bezier(.2,.9,.3,1);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.pet-skin-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.06);
  border-color: color-mix(in srgb, var(--pet-accent, #5ecbff) 35%, var(--border-subtle, #e6e6e6));
}
.pet-skin-card[data-active="1"] {
  border-color: var(--card-accent, var(--pet-accent, #5ecbff));
  background: var(--surface-card, #fff);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--card-accent, var(--pet-accent,#5ecbff)) 14%, transparent),
              0 0 0 3px color-mix(in srgb, var(--card-accent, var(--pet-accent,#5ecbff)) 12%, transparent);
}
.pet-skin-card__badge {
  position: absolute;
  top: 8px; right: 8px;
  width: 22px; height: 22px; border-radius: 999px;
  background: var(--card-accent, var(--pet-accent, #5ecbff));
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  box-shadow: 0 1px 3px color-mix(in srgb, var(--card-accent, var(--pet-accent,#5ecbff)) 30%, transparent);
}
.pet-skin-card__preview {
  height: 130px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
  background: transparent;
  border-radius: 12px;
  overflow: hidden;
  /* sprite 切帧参数(由 JS 在 style 里注入) */
  --preview-cols: 1;
  --preview-rows: 1;
  --preview-cell-col: 0;
  --preview-cell-row: 0;
  --preview-ratio: 1;
}
.pet-skin-card__preview img {
  max-width: 80%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
  filter: drop-shadow(0 6px 16px color-mix(in srgb, var(--card-accent, var(--pet-accent,#5ecbff)) 28%, transparent));
}
/* spritesheet 预览:容器 130 高 × aspect-ratio=ratio;背景就是 sheet;position 精准切到某一格 */
.pet-skin-card__preview[data-spritesheet="1"] img {
  display: none;
}
.pet-skin-card__preview[data-spritesheet="1"] {
  background-image: var(--preview-sheet, none);
  background-repeat: no-repeat;
  background-size: calc(100% * var(--preview-cols)) calc(100% * var(--preview-cols) * var(--preview-rows) / var(--preview-ratio));
  --x: calc(100% * var(--preview-cell-col) / max(1, calc(var(--preview-cols) - 1)));
  background-position-x: var(--x);
  /* y:先算"缩了 cols 倍后容器高度 vs 单格宽高比得到的实际显示高 vs 整体显示图高"的 row 偏移 */
  background-position-y: calc(100% * var(--preview-cell-row) / max(1, calc(var(--preview-rows) - 1)));
  height: 130px;
  aspect-ratio: var(--preview-ratio);
  margin-inline: auto;
  width: auto;
}
@media (max-width: 480px) {
  .pet-skin-card__preview[data-spritesheet="1"] {
    height: 120px;
  }
}
.pet-skin-card__name {
  font-size: 15px; font-weight: 600;
  color: var(--text, #111);
  margin-bottom: 2px;
}
.pet-skin-card__desc {
  font-size: 12.5px;
  color: var(--bs-secondary-color, #6a737d);
  line-height: 1.5;
}
.pet-skin-card__active {
  position: absolute;
  left: 14px; bottom: -1px;
  font-size: 11px;
  color: var(--card-accent, var(--pet-accent, #5ecbff));
  font-weight: 600;
  background: var(--surface-card, #fff);
  padding: 0 6px;
  transform: translateY(50%);
}

/* ---------- 鱼本体 (PNG 多帧) ---------- */
.dsh-pet__body {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
  pointer-events: auto;
  cursor: grab;
}
.dsh-pet.is-dragging .dsh-pet__body { cursor: grabbing; }

/* ---------- motion:呼吸 / 思考 / 工作 / 等待 / 跳动 / 摇头 / 晕眩 ---------- */
@keyframes pet-breathe { 0%,100%{ transform: translateY(0) scale(1,1);} 50%{ transform: translateY(-3px) scale(1.02, 0.98);} }
@keyframes pet-think   { 0%,100%{ transform: translate(0,0) rotate(-2deg);} 50%{ transform: translate(1px,-2px) rotate(2deg);} }
@keyframes pet-work    { 0%,100%{ transform: translateX(0) rotate(0);} 25%{ transform: translateX(-2px) rotate(-2deg);} 75%{ transform: translateX(2px) rotate(2deg);} }
@keyframes pet-wait    { 0%,100%{ transform: translateY(0);} 50%{ transform: translateY(-2px);} }
@keyframes pet-bounce  { 0%  { transform: translateY(0) scale(1,1);}
                        30% { transform: translateY(-16px) scale(1.08,0.92);}
                        55% { transform: translateY(0) scale(0.96,1.05);}
                        75% { transform: translateY(-4px) scale(1.02,0.98);}
                        100%{ transform: translateY(0) scale(1,1);} }
@keyframes pet-shake   { 0%,100%{ transform: translateX(0) rotate(0);} 20%{transform:translateX(-4px) rotate(-3deg);} 40%{transform:translateX(4px) rotate(3deg);} 60%{transform:translateX(-3px) rotate(-2deg);} 80%{transform:translateX(3px) rotate(2deg);} }
@keyframes pet-dizzy   { 0%{ transform: rotate(0);} 25%{transform: rotate(-6deg);} 50%{transform: rotate(6deg);} 75%{transform: rotate(-3deg);} 100%{ transform: rotate(0);} }

.dsh-pet[data-motion="breathe"] .dsh-pet__body { animation: pet-breathe 2.6s ease-in-out infinite; transform-origin: 50% 90%; }
.dsh-pet[data-motion="think"]   .dsh-pet__body { animation: pet-think   1.1s ease-in-out infinite; transform-origin: 50% 85%; }
.dsh-pet[data-motion="work"]    .dsh-pet__body { animation: pet-work    0.55s ease-in-out infinite; transform-origin: 50% 90%; }
.dsh-pet[data-motion="wait"]    .dsh-pet__body { animation: pet-wait    1.3s ease-in-out infinite; transform-origin: 50% 90%; }
.dsh-pet[data-motion="bounce"]  .dsh-pet__body { animation: pet-bounce  0.9s cubic-bezier(.5,1.6,.4,1) 2; transform-origin: 50% 100%; }
.dsh-pet[data-motion="shake"]   .dsh-pet__body { animation: pet-shake   0.5s ease-in-out infinite; }
.dsh-pet[data-motion="dizzy"]   .dsh-pet__body { animation: pet-dizzy   1.2s ease-in-out infinite; transform-origin: 50% 50%; }

/* ---------- 状态角标(左下角小灯) ---------- */
.dsh-pet__status {
  position: absolute;
  left: 4px;
  bottom: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #8fd46f;
  box-shadow: 0 0 0 3px rgba(143,212,111,0.25);
  transition: all 0.25s;
  z-index: 1;
}

/* =========================================================
   气泡(消息提示)美化:
   - 玻璃拟态毛玻璃背景 + 1px 渐变边框
   - 鱼尾造型连接(双层伪元素拼圆角弧形尾巴,不是尖角三角)
   - 弹性进场:从小鱼嘴边"啵"地弹出来
   - 右上角 × 关闭按钮
   - 可调参数集中在 .dsh-pet 变量上,方便你后续调参
   ========================================================= */
.dsh-pet {
  --bubble-w: 340px;              /* 气泡最大宽(宽比高大) */
  --bubble-min-w: 260px;          /* 气泡最小宽 — 关键:防止瘦成一条竖条 */
  --bubble-py: 12px;              /* 气泡上下内边距 */
  --bubble-px: 18px;              /* 气泡左右内边距 */
  --bubble-radius: 18px 6px 18px 18px; /* 右上收窄一个小尖,模拟鱼尾嘴型 */
  --bubble-gap: 14px;             /* 气泡和鱼之间的水平距离 */
  --bubble-attach-bottom: 36px;   /* 气泡底部对齐鱼嘴(≈中下位置) */
  --bubble-tail-w: 22px;          /* 鱼尾连接宽度 */
  --bubble-tail-h: 16px;          /* 鱼尾连接高度 */
}

.dsh-pet__bubble-msg {
  position: absolute;
  right: calc(100% + var(--bubble-gap));
  bottom: var(--bubble-attach-bottom);
  /* 宽度三连: fit-content 自适应内容 + min 不瘦 + max 不胖 */
  width: fit-content;
  min-width: var(--bubble-min-w);
  max-width: var(--bubble-w);
  /* 右上角关闭按钮占 24px,所以 padding-right 大一点,不压字 */
  padding: var(--bubble-py) 30px var(--bubble-py) calc(var(--bubble-px) + 2px);
  color: var(--text, #15171a);
  font-size: 14px;
  line-height: 1.6;
  border-radius: var(--bubble-radius);
  /* 中文不要每个字都断行,只在标点/空格处断(防止瘦长竖排) */
  word-break: normal;
  overflow-wrap: anywhere;
  line-break: loose;
  /* 玻璃拟态 */
  background:
    linear-gradient(135deg,
      color-mix(in srgb, var(--pet-accent, #5ecbff) 10%, var(--surface-card, #fff)) 0%,
      var(--surface-card, #fff) 100%);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  /* 渐变描边 */
  border: 1px solid color-mix(in srgb, var(--pet-accent, #5ecbff) 35%, var(--border-subtle, #e6e6e6));
  box-shadow:
    0 1px 0 rgba(255,255,255,0.6) inset,
    0 -1px 0 color-mix(in srgb, var(--pet-accent, #5ecbff) 18%, transparent) inset,
    0 10px 28px rgba(94, 203, 255, 0.18),
    0 6px 14px rgba(0, 0, 0, 0.08);
  transform-origin: calc(100% + var(--bubble-tail-w)) calc(100% - var(--bubble-tail-h));
  transform: translateX(12px) scale(0.6) rotate(-6deg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

/* 双层伪元素做鱼尾连接(外层大蓝边 + 内层白填充同背景) */
.dsh-pet__bubble-msg::before {
  content: "";
  position: absolute;
  right: calc(var(--bubble-tail-w) * -1);
  bottom: 8px;
  width: var(--bubble-tail-w);
  height: var(--bubble-tail-h);
  background:
    radial-gradient(ellipse at left 50%,
      color-mix(in srgb, var(--pet-accent, #5ecbff) 14%, var(--surface-card, #fff)) 0%,
      var(--surface-card, #fff) 75%);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-top: 1px solid color-mix(in srgb, var(--pet-accent, #5ecbff) 30%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--pet-accent, #5ecbff) 30%, transparent);
  border-right: 1px solid color-mix(in srgb, var(--pet-accent, #5ecbff) 30%, transparent);
  clip-path: path("M 0 0 Q " + (parseInt(getComputedStyleStyleVar(/*fallback*/).replace('px','')) || 22)/2 + " " + (parseInt(getComputedStyleStyleVar(/*fallback*/).replace('px','')) || 16)/2 + " " + (parseInt(getComputedStyleStyleVar(/*fallback*/).replace('px','')) || 22) + " " + (parseInt(getComputedStyleStyleVar(/*fallback*/).replace('px','')) || 16) + " T 0 " + (parseInt(getComputedStyleStyleVar(/*fallback*/).replace('px','')) || 16) + " Z");
  border-radius: 0 12px 18px 0;
  pointer-events: none;
}
/* 因为 CSS 原生变量无法在 clip-path 里直接做字符串拼接 + 数值运算,用 --bubble-tail-w/h 重算 */
.dsh-pet__bubble-msg::before {
  right: calc(var(--bubble-tail-w) * -1);
  bottom: 10px;
  width: var(--bubble-tail-w);
  height: var(--bubble-tail-h);
  /* 贝塞尔鱼尾:从 (0,0) 控制点 (宽/3,高*1.1) 终点 (宽,高),再画一条 (0,高) 回来 */
  clip-path: polygon(
    0 0,
    55% 12%,
    100% 50%,
    55% 88%,
    0 100%
  );
  border-radius: 0 50% 50% 0 / 0 70% 70% 0;
  /* 用 mask 切掉鱼尾和主气泡的交叠,避免重叠 */
  -webkit-mask-image: linear-gradient(to right, #000 60%, transparent 100%);
  mask-image: linear-gradient(to right, #000 60%, transparent 100%);
}

/* 关闭气泡的小 × */
.dsh-pet__bubble-close {
  position: absolute;
  top: 6px; right: 8px;
  width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  color: var(--bs-secondary-color, #6a737d);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: all .15s ease;
  padding: 0;
}
.dsh-pet__bubble-close:hover {
  background: color-mix(in srgb, var(--pet-accent, #5ecbff) 18%, transparent);
  color: var(--bs-body-color, #1c2a38);
  transform: rotate(90deg);
}

/* 气泡前缀小鱼图标 */
.dsh-pet__bubble-prefix {
  display: inline-block;
  margin-right: 6px;
  vertical-align: -2px;
  font-size: 15px;
  filter: drop-shadow(0 1px 0 rgba(94,203,255,0.35));
}

/* 出场动画 */
.dsh-pet.has-msg .dsh-pet__bubble-msg {
  opacity: 1;
  pointer-events: auto;
  animation: bubble-pop-in 0.38s cubic-bezier(.2,1.4,.4,1) both;
}
@keyframes bubble-pop-in {
  0%   { transform: translateX(12px) scale(0.55) rotate(-8deg); opacity: 0; }
  55%  { transform: translateX(-2px) scale(1.05) rotate(1.5deg); opacity: 1; }
  78%  { transform: translateX(0) scale(0.97) rotate(-0.5deg); }
  100% { transform: translateX(0) scale(1) rotate(0); opacity: 1; }
}
/* 退场:当 has-msg 移除时 fade-out,不再弹 */
.dsh-pet__bubble-msg:not([class*="has-msg"]) {
  animation: none;
}

/* 快捷面板同步也美化(气泡/面板统一玻璃拟态家族)
   注意:下面原有的 .dsh-pet__panel 位置/结构规则在后面,不重写,仅在已有规则前面叠加纯视觉属性,
   因为 CSS 后面的相同属性会覆盖前面,所以用 [data-enhanced=1] 锚定,保证视觉增强优先。 */
.dsh-pet .dsh-pet__panel {
  background:
    linear-gradient(160deg,
      color-mix(in srgb, var(--pet-accent, #5ecbff) 8%, var(--surface-card, #fff)) 0%,
      var(--surface-card, #fff) 100%);
  -webkit-backdrop-filter: blur(14px) saturate(1.25);
  backdrop-filter: blur(14px) saturate(1.25);
  border: 1px solid color-mix(in srgb, var(--pet-accent, #5ecbff) 28%, var(--border-subtle, #e6e6e6));
  box-shadow:
    0 1px 0 rgba(255,255,255,0.6) inset,
    0 12px 30px rgba(94, 203, 255, 0.16),
    0 8px 16px rgba(0,0,0,0.08);
  border-radius: 16px 4px 16px 16px; /* 右上角收一个小尖,呼应气泡 */
}

/* ---------- 快捷操作面板(点击鱼身弹出) ---------- */
.dsh-pet__panel {
  position: absolute;
  right: calc(100% + 14px);
  bottom: 0;
  min-width: 200px;
  padding: 10px 6px;
  background: var(--surface-card, #fff);
  border: 1px solid var(--border-subtle, #e6e6e6);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.1);
  opacity: 0;
  transform: translateX(8px) scale(0.96);
  pointer-events: none;
  transition: all 0.2s cubic-bezier(.2,.8,.2,1);
  z-index: 1;
  overflow: hidden;
}
.dsh-pet.panel-open .dsh-pet__panel {
  opacity: 1;
  transform: translateX(0) scale(1);
  pointer-events: auto;
}
.dsh-pet__panel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--text, #111);
  cursor: pointer;
  transition: background 0.15s;
}
.dsh-pet__panel-item:hover  { background: var(--surface-hover, #f3f4f6); }
.dsh-pet__panel-item.danger { color: #e5484d; }
.dsh-pet__panel-sep { height: 1px; background: var(--border-subtle, #e6e6e6); margin: 4px 10px; }
.dsh-pet__panel-item svg { flex: 0 0 16px; }

/* 双击隐藏态 */
.dsh-pet.is-hidden { display: none; }

/* 移动端适配:缩至 96px,面板改为左侧贴边弹出 */
@media (max-width: 640px) {
  .dsh-pet { --pet-size: 96px; right: 14px; bottom: 14px; }
  .dsh-pet__bubble-msg { max-width: 220px; font-size: 12px; }
}
