/* ===========================================================
   小挂件 · 挂件本体样式（可被任意页面引用）
   演示页排版见 pet/demo.css
   =========================================================== */

.pet-widget,
.pet-widget * { box-sizing: border-box; }

.pet-widget {
  --pet-size: clamp(108px, 13vw, 152px);
  --pet-rose: #ff6f91;
  --pet-wine: #7a2b42;
  --pet-font: "ZCOOL KuaiLe", "YouYuan", "幼圆", "PingFang SC", sans-serif;
  --pet-font-sans: "LXGW WenKai", "YouYuan", "幼圆", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ---------- 挂件本体 ---------- */

.pet-widget {
  position: fixed;
  left: 0;
  top: 0;
  /* 在内容与顶栏之上，但在灯箱（200）与提示（300）之下 */
  z-index: 160;
  width: var(--pet-size);
  height: var(--pet-size);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.pet-widget.is-dragging { cursor: grabbing; }

/* 挂件本体：没有相框，像桌宠一样直接站在页面上 */
.pet-plate {
  position: absolute;
  inset: 0;
  animation: petBob 3.4s ease-in-out infinite;
}

.pet-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  /* 用投影代替白色底座 */
  filter: drop-shadow(0 10px 10px rgba(180, 80, 110, 0.26));
  transition: opacity 0.18s ease, filter 0.3s ease;
  /* 往左跑的时候翻个面 */
  transform: scaleX(var(--pet-face, 1));
}

.pet-act { opacity: 0; }

.pet-plate.is-acting .pet-act { opacity: 1; }
.pet-plate.is-acting .pet-idle { opacity: 0; }

.pet-widget.is-face-left { --pet-face: -1; }

.pet-widget:hover .pet-img {
  filter: drop-shadow(0 13px 14px rgba(180, 80, 110, 0.34));
}

.pet-widget.is-pressed .pet-plate { animation-play-state: paused; }

.pet-widget.is-dragging .pet-plate { animation-play-state: paused; }

.pet-widget.is-dragging .pet-img {
  filter: drop-shadow(0 18px 20px rgba(180, 80, 110, 0.4));
}

.pet-widget:focus-visible {
  outline: 2px dashed rgba(255, 111, 145, 0.75);
  outline-offset: 6px;
  border-radius: 50%;
}

/* 气泡 */

.pet-bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 2px);
  transform: translateX(-50%) translateY(4px) scale(0.82);
  transform-origin: 50% 100%;
  padding: 7px 13px;
  border-radius: 14px;
  background: #fff;
  color: var(--pet-wine);
  font-family: var(--pet-font);
  font-size: 13px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  box-shadow: 0 12px 24px -12px rgba(160, 70, 100, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.28s cubic-bezier(0.2, 0.8, 0.3, 1.25);
}

.pet-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 2px;
  background: #fff;
  transform: rotate(45deg);
}

.pet-bubble.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

/* 挂件贴近屏幕顶部时，气泡翻到下方 */
.pet-bubble.is-below {
  bottom: auto;
  top: calc(100% + 2px);
  transform-origin: 50% 0;
}

.pet-bubble.is-below::after {
  bottom: auto;
  top: -4px;
}

@keyframes petBob {
  0%, 100% { transform: translateY(0) rotate(-1.4deg); }
  50% { transform: translateY(-7px) rotate(1.4deg); }
}

/* ---------- 右键对话面板 ---------- */

.pet-chat {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  width: 236px;
  padding: 9px 11px 11px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 20px 44px -20px rgba(160, 70, 100, 0.6);
  font-family: var(--pet-font-sans);
  color: var(--pet-wine);
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(6px) scale(0.94);
  transform-origin: 50% 100%;
  transition: opacity 0.2s ease, transform 0.26s cubic-bezier(0.2, 0.8, 0.3, 1.2),
    visibility 0.2s;
}

.pet-chat.is-on {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0) scale(1);
}

/* 挂件贴近屏幕顶部时，面板翻到下方 */
.pet-chat.is-below {
  bottom: auto;
  top: calc(100% + 8px);
  transform-origin: 50% 0;
}

.pet-chat,
.pet-chat * { cursor: auto; }

.pet-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px 7px;
  font-family: var(--pet-font);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  color: var(--pet-rose);
}

.pet-chat-close {
  border: 0;
  padding: 0 2px;
  background: none;
  color: #d49bb0;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.pet-chat-close:hover { color: var(--pet-rose); }

.pet-chat-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 146px;
  overflow-y: auto;
  padding: 2px 1px;
  scrollbar-width: thin;
}

.pet-chat-line {
  max-width: 86%;
  margin: 0;
  padding: 6px 9px;
  border-radius: 11px;
  font-size: 12.5px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  word-break: break-word;
  animation: petLineIn 0.22s ease both;
}

.pet-chat-line.is-pet {
  align-self: flex-start;
  background: #fff6ea;
  border: 1px solid rgba(201, 162, 39, 0.18);
  border-bottom-left-radius: 4px;
}

.pet-chat-line.is-me {
  align-self: flex-end;
  background: #ffe6ee;
  border-bottom-right-radius: 4px;
}

@keyframes petLineIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.pet-chat-form {
  display: flex;
  gap: 6px;
  margin-top: 9px;
}

.pet-chat-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid rgba(255, 111, 145, 0.28);
  border-radius: 999px;
  background: #fffafc;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--pet-wine);
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.pet-chat-input:focus {
  border-color: rgba(255, 111, 145, 0.62);
  box-shadow: 0 0 0 3px rgba(255, 111, 145, 0.12);
}

.pet-chat-send {
  flex: 0 0 auto;
  padding: 0 13px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(160deg, #ff9db4, #e8567a);
  color: #fff;
  font-family: var(--pet-font);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.pet-chat-send:active { transform: scale(0.96); }

@media (prefers-reduced-motion: reduce) {
  .pet-plate { animation: none; }
}

@media (max-width: 520px) {
  .demo { padding-top: 48px; }
}
