/* 页面宠物：团子小黑
   fixed 定位 + pointer-events:none，不参与布局、不挡点击。
   雪碧条：12 帧 × 100×100（pet-cat-v2.png / pet-cat-v2@2x.png，白底已按 238 阈值硬键扣除，alpha 只有 0/255）。 */

.pet {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 40;
  pointer-events: none;
  user-select: none;
  contain: layout style;   /* 不能带 paint：思考框要溢出到猫头顶之外 */
  will-change: transform;
  transform: translate3d(-999px, -999px, 0);
  opacity: 1;              /* 不做淡入：无头截图/停掉动画的环境里别让它看不见 */
}

.pet.is-ready {
  opacity: 1;
}

.pet__sprite {
  display: block;
  width: 100px;
  height: 100px;
  background-image: url("../img/pet-cat-v2.png");
  background-repeat: no-repeat;
  background-size: 1200px 100px;   /* 12 帧，整张条的 CSS 尺寸 */
  background-position: 0 0;
  /* 深色区块上给一圈极淡的亮边，不然黑猫会糊进背景 */
  filter: drop-shadow(0 0 1.5px rgba(250, 246, 228, 0.55));
  /* 只有猫本体接指针：可拖拽，但不会挡住页面其它区域的点击 */
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  -webkit-user-drag: none;
  transition: filter 0.2s ease;
}

.pet.is-dragging .pet__sprite {
  cursor: grabbing;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35))
          drop-shadow(0 0 2px rgba(250, 246, 228, 0.75));
}

/* 高分屏换 2 倍图，CSS 尺寸仍是 1200×100 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .pet__sprite {
    background-image: url("../img/pet-cat-v2@2x.png");
  }
}

.pet--flip .pet__sprite {
  transform: scaleX(-1);
}

/* ---------- 停顿时的思考框 ---------- */

@font-face {
  font-family: "Xiaohei Hand";
  src: url("../fonts/xiaohei-hand.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

.pet__bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 16px);
  transform: translateX(calc(-50% + var(--nudge, 0px))) rotate(-1.1deg);
  transform-origin: 50% 100%;
  width: max-content;
  min-width: 74px;
  padding: 9px 13px 8px;
  /* 手写便签感：四角半径不相等，边线略粗 */
  border-radius: 15px 11px 16px 10px / 12px 17px 11px 15px;
  border: 1.6px solid rgba(38, 32, 25, 0.62);
  background: #fffdf2;
  color: #23241f;
  font: 400 15px/1.4 "Xiaohei Hand", "ZCOOL KuaiLe", "PingFang SC", cursive;
  letter-spacing: 0.6px;
  white-space: nowrap;
  box-shadow: 0 9px 22px rgba(0, 0, 0, 0.34), inset 0 0 0 1px rgba(255, 255, 255, 0.7);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 2;
}

.pet__bubble.is-on {
  opacity: 1;
  visibility: visible;
}

/* 打字机光标 */
.pet__caret {
  display: inline-block;
  width: 2px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: rgba(35, 36, 31, 0.85);
  border-radius: 1px;
  animation: pet-caret 0.9s steps(1, end) infinite;
}

.pet__bubble.is-done .pet__caret {
  animation: none;
  opacity: 0.28;
}

@keyframes pet-caret {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* 思考框的两个小气泡尾巴，指向猫头 */
.pet__bubble::before,
.pet__bubble::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: #fffdf2;
  border: 1.4px solid rgba(38, 32, 25, 0.5);
}

.pet__bubble::before {
  left: 19px;
  bottom: -9px;
  width: 9px;
  height: 9px;
}

.pet__bubble::after {
  left: 12px;
  bottom: -17px;
  width: 5px;
  height: 5px;
}

/* 贴近屏幕上沿时，气泡改到猫下面 */
.pet--bubble-below .pet__bubble {
  bottom: auto;
  top: calc(100% + 14px);
  transform-origin: 50% 0;
  border-radius: 11px 16px 10px 15px / 17px 12px 15px 11px;
}

.pet--bubble-below .pet__bubble::before {
  bottom: auto;
  top: -10px;
}

.pet--bubble-below .pet__bubble::after {
  bottom: auto;
  top: -20px;
}

@media (max-width: 820px) {
  .pet__sprite {
    width: 72px;
    height: 72px;
    background-size: 864px 72px;
  }

  .pet__bubble {
    font-size: 13.5px;
    padding: 7px 11px 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pet {
    display: none !important;
  }
}
