.page-pet {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 45;
  width: fit-content;
  pointer-events: none;
  will-change: left, top;
}

.page-pet.is-hidden {
  display: none;
}

.page-pet-character {
  position: relative;
  display: block;
  width: fit-content;
  height: var(--page-pet-height, 260px);
  padding: 0;
  line-height: 0;
  cursor: grab;
  touch-action: none;
  background: transparent;
  border: 0;
  outline: none;
  pointer-events: auto;
  transform-origin: 50% 100%;
}

.page-pet-character:active {
  cursor: grabbing;
}

.page-pet-character:focus-visible {
  filter: drop-shadow(0 0 0.55rem rgba(210, 85, 135, 0.42));
}

.page-pet-breather {
  display: block;
  height: 100%;
  transform-origin: 50% 100%;
  animation: page-pet-breathe 3.4s ease-in-out infinite;
}

.page-pet-image {
  display: block;
  width: auto;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
  filter:
    drop-shadow(0 12px 13px rgba(103, 67, 82, 0.14))
    drop-shadow(0 3px 4px rgba(255, 255, 255, 0.45));
  transform-origin: 50% 100%;
  transition: opacity 140ms ease, transform 180ms ease;
}

.page-pet-shadow {
  position: absolute;
  bottom: -3px;
  left: 50%;
  width: 54%;
  height: 12px;
  background: radial-gradient(ellipse, rgba(105, 70, 86, 0.2), transparent 70%);
  border-radius: 50%;
  filter: blur(1.5px);
  pointer-events: none;
  transform: translateX(-50%);
}

.page-pet.is-facing-left .page-pet-image {
  transform: scaleX(-1);
}

.page-pet.is-walking .page-pet-breather {
  animation: page-pet-walk 0.46s ease-in-out infinite;
}

.page-pet.is-sleeping .page-pet-breather {
  animation-duration: 5.2s;
}

.page-pet.is-sleeping .page-pet-image {
  opacity: 0.8;
  transform: scaleY(0.97);
}

.page-pet-character.is-jumping {
  animation: page-pet-jump 560ms cubic-bezier(0.22, 0.8, 0.32, 1);
}

.page-pet-character.is-squashing {
  animation: page-pet-squash 560ms ease-in-out;
}

.page-pet-character.is-shaking {
  animation: page-pet-shake 520ms ease-in-out;
}

.page-pet-character.is-tapping {
  animation: page-pet-tap 360ms cubic-bezier(0.22, 0.8, 0.32, 1);
}

.page-pet-bubble {
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  z-index: 2;
  min-width: 120px;
  max-width: 230px;
  padding: 10px 14px;
  color: #5f4650;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 172, 199, 0.86);
  border-radius: 15px;
  box-shadow: 0 9px 28px rgba(126, 65, 89, 0.15);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 12px;
  line-height: 1.55;
  text-align: center;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px) scale(0.96);
  transition:
    opacity 180ms ease,
    transform 220ms ease;
}

.page-pet-bubble::after {
  position: absolute;
  bottom: -8px;
  left: 50%;
  width: 14px;
  height: 14px;
  content: "";
  background: #fff;
  border-right: 1px solid rgba(255, 172, 199, 0.86);
  border-bottom: 1px solid rgba(255, 172, 199, 0.86);
  transform: translateX(-50%) rotate(45deg);
}

.page-pet-bubble.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.page-pet-zzz {
  position: absolute;
  top: 9%;
  right: -8px;
  z-index: 3;
  display: flex;
  gap: 1px;
  align-items: flex-end;
  color: #b36d8a;
  font-family: Georgia, serif;
  font-size: 18px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 240ms ease, transform 240ms ease;
}

.page-pet-zzz span:nth-child(2) {
  margin-bottom: 10px;
  font-size: 14px;
}

.page-pet-zzz span:nth-child(3) {
  margin-bottom: 20px;
  font-size: 10px;
}

.page-pet.is-sleeping .page-pet-zzz {
  opacity: 1;
  transform: translateY(0);
  animation: page-pet-zzz-float 2.2s ease-in-out infinite;
}

.page-pet-menu {
  position: fixed;
  z-index: 190;
  display: grid;
  min-width: 156px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(255, 182, 193, 0.9);
  border-radius: 12px;
  box-shadow: 0 14px 38px rgba(99, 53, 72, 0.18);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
}

.page-pet-menu[hidden] {
  display: none;
}

.page-pet-menu button {
  padding: 8px 16px;
  color: #66525a;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}

.page-pet-menu button:hover,
.page-pet-menu button:focus-visible {
  color: #c24f78;
  background: #ffe4ec;
  outline: none;
}

.page-pet-menu-separator {
  height: 1px;
  margin: 5px 8px;
  background: rgba(226, 158, 182, 0.24);
}

.page-pet-restore {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 46;
  padding: 9px 14px;
  color: #8d4e68;
  background: rgba(255, 249, 252, 0.96);
  border: 1px solid rgba(211, 112, 150, 0.28);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(120, 63, 86, 0.15);
  cursor: pointer;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 12px;
}

.page-pet-size-dialog {
  width: min(360px, calc(100vw - 32px));
  padding: 24px;
  color: #604653;
  background:
    radial-gradient(circle at 90% 0%, rgba(255, 211, 226, 0.5), transparent 35%),
    #fffafc;
  border: 1px solid rgba(219, 132, 165, 0.34);
  border-radius: 24px;
  box-shadow: 0 24px 70px rgba(91, 46, 65, 0.2);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
}

.page-pet-size-dialog::backdrop {
  background: rgba(91, 63, 74, 0.18);
  backdrop-filter: blur(2px);
}

.page-pet-size-head {
  display: flex;
  gap: 13px;
  align-items: center;
}

.page-pet-size-head > span {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #bd5a80;
  background: rgba(255, 238, 245, 0.9);
  border-radius: 14px;
}

.page-pet-size-head small {
  color: #b4778d;
  font-size: 9px;
  letter-spacing: 0.16em;
}

.page-pet-size-head h3 {
  margin: 3px 0 0;
  font-family: var(--serif, Georgia, serif);
  font-size: 21px;
  font-weight: 500;
}

.page-pet-size-label {
  display: block;
  margin: 22px 0 10px;
  color: #876b77;
  font-size: 12px;
}

.page-pet-size-range {
  width: 100%;
  accent-color: #c85c86;
}

.page-pet-size-actions {
  display: flex;
  gap: 9px;
  justify-content: flex-end;
  margin-top: 22px;
}

.page-pet-size-actions button {
  min-width: 74px;
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}

.page-pet-size-cancel {
  color: #8a747e;
  background: #fff;
  border: 1px solid rgba(192, 138, 158, 0.28);
}

.page-pet-size-confirm {
  color: #fff;
  background: linear-gradient(135deg, #d46c92, #b7587c);
  border: 0;
}

html[data-theme="dark"] .page-pet-bubble {
  color: #f1e5eb;
  background: rgba(43, 32, 41, 0.97);
  border-color: rgba(220, 139, 171, 0.42);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

html[data-theme="dark"] .page-pet-bubble::after {
  background: #2b2029;
  border-color: rgba(220, 139, 171, 0.42);
}

html[data-theme="dark"] .page-pet-menu {
  background: rgba(40, 30, 39, 0.98);
  border-color: rgba(216, 141, 170, 0.36);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.34);
}

html[data-theme="dark"] .page-pet-menu button {
  color: #e7d3dc;
}

html[data-theme="dark"] .page-pet-menu button:hover,
html[data-theme="dark"] .page-pet-menu button:focus-visible {
  color: #fff;
  background: rgba(135, 70, 94, 0.48);
}

html[data-theme="dark"] .page-pet-restore,
html[data-theme="dark"] .page-pet-size-dialog {
  color: #eedce5;
  background:
    radial-gradient(circle at 90% 0%, rgba(117, 61, 83, 0.3), transparent 35%),
    #241b23;
  border-color: rgba(220, 141, 171, 0.28);
}

html[data-theme="dark"] .page-pet-size-head small,
html[data-theme="dark"] .page-pet-size-label {
  color: #c1a5b2;
}

html[data-theme="dark"] .page-pet-size-cancel {
  color: #dbc6d0;
  background: rgba(54, 41, 51, 0.9);
  border-color: rgba(218, 141, 171, 0.24);
}

@keyframes page-pet-breathe {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  50% {
    transform: translateY(-2px) scale(1.008, 0.994);
  }
}

@keyframes page-pet-walk {
  0%,
  100% {
    transform: translateY(0) rotate(-0.8deg);
  }

  50% {
    transform: translateY(-5px) rotate(0.8deg);
  }
}

@keyframes page-pet-jump {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  36% {
    transform: translateY(-30px) scale(1.025, 0.975);
  }

  62% {
    transform: translateY(-22px) scale(0.99, 1.01);
  }
}

@keyframes page-pet-tap {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  36% {
    transform: translateY(-10px) scale(1.01, 0.98);
  }

  68% {
    transform: translateY(-4px) scale(0.995, 1.005);
  }
}

@keyframes page-pet-squash {
  0%,
  100% {
    transform: scale(1);
  }

  35% {
    transform: scale(1.07, 0.86) translateY(5px);
  }

  68% {
    transform: scale(0.96, 1.05) translateY(-3px);
  }
}

@keyframes page-pet-shake {
  0%,
  100% {
    transform: translateX(0) rotate(0);
  }

  20% {
    transform: translateX(-5px) rotate(-2deg);
  }

  40% {
    transform: translateX(5px) rotate(2deg);
  }

  60% {
    transform: translateX(-4px) rotate(-1.5deg);
  }

  80% {
    transform: translateX(4px) rotate(1.5deg);
  }
}

@keyframes page-pet-zzz-float {
  0%,
  100% {
    transform: translateY(2px);
  }

  50% {
    transform: translateY(-5px);
  }
}

@media (max-width: 680px) {
  .page-pet-bubble {
    max-width: 185px;
    padding: 8px 11px;
    font-size: 11px;
  }

  .page-pet-restore {
    right: 12px;
    bottom: 12px;
  }

  .page-pet-size-dialog {
    padding: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .page-pet-breather,
  .page-pet.is-walking .page-pet-breather,
  .page-pet.is-sleeping .page-pet-zzz {
    animation: none;
  }

  .page-pet-character.is-jumping,
  .page-pet-character.is-squashing,
  .page-pet-character.is-shaking,
  .page-pet-character.is-tapping {
    animation-duration: 1ms;
  }
}
