/* 小 SPU 悬浮宠物 —— 样式层
   所有尺寸都基于 --pet-w / --pet-h，由 spu-pet.js 根据屏幕宽度写入。 */

/* 宠物层不建立独立层叠上下文（不用 fixed），这样宠物能和页面里的景点图层交错：
   景点图层的 z-index 高于宠物时，宠物就躲到它后面去。层级约定见 web/ui-preview.css。 */
.spu-pet-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.spu-pet {
  z-index: 20;
  --pet-w: 84px;
  --pet-h: 90px;
  position: absolute;
  left: 0;
  top: 0;
  width: var(--pet-w);
  height: var(--pet-h);
  will-change: transform;
  transition: opacity 0.35s ease;
}
.spu-pet { transform-origin: 50% 100%; }
.spu-pet.is-gone { opacity: 0; visibility: hidden; }
.spu-pet[data-mode="calm"] .spu-fin { animation: none; }
.spu-pet .spu-m--open {
  transform-box: fill-box;
  transform-origin: center;
  transform: scaleY(var(--spu-mouth-scale, 1));
}
.spu-pet-caret-mirror {
  position: fixed;
  left: -10000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  margin: 0;
  min-height: 0;
  height: auto;
  overflow: hidden;
}

/* 水面 / 卡片边缘裁切：.is-sunk 时只显示边缘线以上的部分 */
.spu-pet__clip { position: absolute; inset: 0; }
.spu-pet__body,
.spu-pet__spin { position: absolute; inset: 0; }
.spu-pet__body { transform-origin: 50% 100%; will-change: transform; }
.spu-pet__spin { transform-origin: 50% 58%; }
.spu-pet__spin svg { display: block; width: 100%; height: 100%; overflow: visible; }

.spu-pet__shadow {
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -5px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(30, 58, 55, 0.24), rgba(30, 58, 55, 0));
  transform-origin: 50% 50%;
}

.spu-pet__hit {
  position: absolute;
  left: 16%;
  right: 16%;
  top: 8%;
  bottom: 2%;
  padding: 0;
  border: 0;
  border-radius: 50% 50% 46% 46%;
  background: transparent;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.spu-pet__hit:focus { outline: none; }
.spu-pet__hit:focus-visible { box-shadow: 0 0 0 3px rgba(44, 102, 80, 0.45); }
.spu-pet.is-dragging .spu-pet__hit { cursor: grabbing; }
.spu-pet[data-mode="hidden"] .spu-pet__hit { pointer-events: none; }

/* ---------- 表情：按 data-* 切换部件 ---------- */
.spu-e, .spu-m { display: none; }
.spu-pet[data-eyes="open"]   .spu-e--open,
.spu-pet[data-eyes="happy"]  .spu-e--happy,
.spu-pet[data-eyes="closed"] .spu-e--closed,
.spu-pet[data-eyes="dizzy"]  .spu-e--dizzy { display: inline; }

.spu-pet[data-mouth="smile"] .spu-m--smile,
.spu-pet[data-mouth="grin"]  .spu-m--grin,
.spu-pet[data-mouth="open"]  .spu-m--open,
.spu-pet[data-mouth="o"]     .spu-m--o,
.spu-pet[data-mouth="flat"]  .spu-m--flat,
.spu-pet[data-mouth="wavy"]  .spu-m--wavy,
.spu-pet[data-mouth="yawn"]  .spu-m--yawn,
.spu-pet[data-mouth="drool"] .spu-m--drool { display: inline; }

.spu-eye-ball {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.09s ease-out;
}
.spu-pet[data-big] .spu-eye-ball { transform: scale(1.16); }
.spu-pet.is-blink .spu-eye-ball { transform: scaleY(0.1); }

.spu-brow {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.25s ease;
}
.spu-pet[data-brows="sad"] .spu-brow--l { transform: translateY(-1px) rotate(-18deg); }
.spu-pet[data-brows="sad"] .spu-brow--r { transform: translateY(-1px) rotate(18deg); }
.spu-pet[data-brows="confused"] .spu-brow--l { transform: translateY(-3px) rotate(-10deg); }
.spu-pet[data-brows="confused"] .spu-brow--r { transform: translateY(1px) rotate(8deg); }

.spu-face-cheeks ellipse { opacity: 0.5; transition: opacity 0.3s ease; }
.spu-pet[data-blush] .spu-face-cheeks ellipse { opacity: 0.95; }

/* ---------- 鳍：休息 / 走路 / 扑腾 / 挥手 ---------- */
.spu-fin { transition: transform 0.2s ease; }
.spu-fin--l { transform-origin: 26px 85px; }
.spu-fin--r { transform-origin: 94px 85px; }

.spu-pet[data-fins="rest"] .spu-fin--l { animation: spu-fin-rest-l 3.4s ease-in-out infinite; }
.spu-pet[data-fins="rest"] .spu-fin--r { animation: spu-fin-rest-r 3.4s ease-in-out infinite 0.4s; }
.spu-pet[data-fins="walk"] .spu-fin--l { animation: spu-fin-flap-l 0.36s ease-in-out infinite alternate; }
.spu-pet[data-fins="walk"] .spu-fin--r { animation: spu-fin-flap-r 0.36s ease-in-out infinite alternate-reverse; }
.spu-pet[data-fins="flap"] .spu-fin--l { animation: spu-fin-flap-l 0.14s linear infinite alternate; }
.spu-pet[data-fins="flap"] .spu-fin--r { animation: spu-fin-flap-r 0.14s linear infinite alternate; }
.spu-pet[data-fins="wave"] .spu-fin--l { animation: spu-fin-rest-l 3.4s ease-in-out infinite; }
.spu-pet[data-fins="wave"] .spu-fin--r { animation: spu-fin-wave 0.32s ease-in-out infinite alternate; }

@keyframes spu-fin-rest-l { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(7deg); } }
@keyframes spu-fin-rest-r { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(-7deg); } }
@keyframes spu-fin-flap-l { from { transform: rotate(-16deg); } to { transform: rotate(18deg); } }
@keyframes spu-fin-flap-r { from { transform: rotate(16deg); } to { transform: rotate(-18deg); } }
@keyframes spu-fin-wave { from { transform: rotate(-58deg); } to { transform: rotate(-24deg); } }

/* ---------- 气泡 ---------- */
.spu-pet__bubble {
  --bx: 0px;
  --by: 0px;
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  padding: 7px 12px;
  border-radius: 14px;
  background: #fff;
  color: #1e3a37;
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
  box-shadow: 0 0 0 1px rgba(44, 102, 80, 0.14), 0 8px 20px rgba(30, 58, 55, 0.12);
  opacity: 0;
  transform: translate(calc(-50% + var(--bx)), calc(var(--by) + 6px)) scale(0.9);
  transform-origin: 50% 100%;
  transition: opacity 0.16s ease, transform 0.26s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.spu-pet__bubble.is-show {
  opacity: 1;
  transform: translate(calc(-50% + var(--bx)), var(--by)) scale(1);
}
.spu-pet__bubble::after {
  content: "";
  position: absolute;
  left: calc(50% - var(--bx) - 6px);
  bottom: -5px;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 0 0 4px 0;
  transform: rotate(45deg);
  box-shadow: 1px 1px 0 rgba(44, 102, 80, 0.14);
}
/* 头顶空间不够时，气泡挪到身侧 */
.spu-pet__bubble.is-side {
  left: 100%;
  bottom: 52%;
  transform: translate(4px, var(--by)) scale(0.9);
  transform-origin: 0 50%;
}
.spu-pet__bubble.is-side.is-show { transform: translate(4px, var(--by)) scale(1); }
.spu-pet__bubble.is-side::after { left: -4px; bottom: 10px; border-radius: 0 0 0 4px; box-shadow: -1px 1px 0 rgba(44, 102, 80, 0.14); }
.spu-pet__bubble.is-side.is-left { left: auto; right: 100%; transform: translate(-4px, var(--by)) scale(1); transform-origin: 100% 50%; }
.spu-pet__bubble.is-side.is-left::after { left: auto; right: -4px; border-radius: 0 4px 0 0; box-shadow: 1px -1px 0 rgba(44, 102, 80, 0.14); }

.spu-pet__dots { display: none; gap: 4px; padding: 3px 2px; }
.spu-pet__bubble.is-thinking .spu-pet__text { display: none; }
.spu-pet__bubble.is-thinking .spu-pet__dots { display: inline-flex; }
.spu-pet__dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7fb4e6;
  animation: spu-dot 1.1s ease-in-out infinite;
}
.spu-pet__dots i:nth-child(2) { animation-delay: 0.15s; }
.spu-pet__dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes spu-dot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.45; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---------- 特效：爱心、星星、Zzz、音符、水花 ---------- */
.spu-pet__fx { position: absolute; left: 50%; top: 16%; width: 0; height: 0; }
.spu-pet__ground { position: absolute; left: 50%; bottom: 0; width: 0; height: 0; }

.spu-fx {
  position: absolute;
  left: -9px;
  top: -9px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  animation: spu-fx-float var(--d, 1.4s) cubic-bezier(0.2, 0.7, 0.3, 1) both;
}
.spu-fx svg { width: 100%; height: 100%; display: block; }
.spu-fx--z { font-size: 15px; color: #6d8fbf; }
.spu-fx--question, .spu-fx--bang { font-size: 22px; color: #2c6650; }
.spu-fx--note { font-size: 17px; color: #4c97e0; }
.spu-fx--star { width: 14px; height: 14px; }

@keyframes spu-fx-float {
  0% { opacity: 0; transform: translate(var(--x0), 0) scale(0.4); }
  18% { opacity: 1; transform: translate(var(--x0), -8px) scale(1); }
  100% { opacity: 0; transform: translate(var(--x1), var(--y1)) scale(0.85) rotate(var(--r, 0deg)); }
}

.spu-fx--ripple {
  left: -30px;
  top: -6px;
  width: 60px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(110, 178, 232, 0.75);
  animation: spu-ripple 0.9s ease-out both;
}
@keyframes spu-ripple { from { opacity: 1; transform: scale(0.4); } to { opacity: 0; transform: scale(1.7); } }

.spu-fx--drop {
  left: -3px;
  top: -3px;
  width: 6px;
  height: 7px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: #9fd2f6;
  animation: spu-drop 0.7s cubic-bezier(0.3, 0.6, 0.6, 1) both;
}
@keyframes spu-drop {
  0% { opacity: 1; transform: translate(0, 0); }
  50% { opacity: 1; transform: translate(calc(var(--x1) * 0.6), var(--y1)); }
  100% { opacity: 0; transform: translate(var(--x1), 4px); }
}

@media (prefers-reduced-motion: reduce) {
  .spu-pet *, .spu-pet *::after { animation: none !important; transition: none !important; }
  .spu-fx { display: none; }
}

/* 图片动作：显示素材时身体隐藏，图片贴在宠物的位置上（不接收点击） */
.spu-pet.is-sprite .spu-pet__body { opacity: 0; }
.spu-pet__sprite { position: absolute; left: 50%; bottom: 0; width: 130%; max-width: none; transform: translateX(-50%); pointer-events: none; z-index: 2; animation: spu-sprite-in 0.22s ease-out both; }
.spu-pet__sprite.is-dive { width: 96%; }
@keyframes spu-sprite-in { from { opacity: 0; transform: translate(-50%, 12px) scale(0.92); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }

