/* ============================================================
   洄州異聞錄 · 桌寵「大肥魚」
   可愛女僕導遊 · 懸浮於所有層之上（z-index 600）
   ============================================================ */

#pet-root {
  position: fixed;
  z-index: 600;
  user-select: none;
  -webkit-user-select: none;
  font-family: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
}

/* ---------------- 桌寵本體 ---------------- */
.pet-body {
  position: relative;
  width: 92px;
  height: 116px;
  cursor: grab;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .55));
  animation: petBob 3.8s ease-in-out infinite;
  transform-origin: 50% 100%;
}
.pet-body:active { cursor: grabbing; }
.pet-body svg { width: 100%; height: 100%; display: block; }

/* 漂浮 */
@keyframes petBob {
  0%, 100% { transform: translateY(0) rotate(-1.2deg); }
  50%      { transform: translateY(-7px) rotate(1.2deg); }
}

/* 雙馬尾輕晃 */
.tail { transform-origin: 50% 6%; animation: tailSway 3.8s ease-in-out infinite; }
.tail.r { animation-delay: -.4s; }
@keyframes tailSway {
  0%, 100% { transform: rotate(0deg); }
  50%      { transform: rotate(3.4deg); }
}

/* 眨眼 */
.eyelid { opacity: 0; animation: petBlink 4.7s infinite; }
.eyelid.r { animation-delay: 2.35s; }
@keyframes petBlink {
  0%, 90%, 100% { opacity: 0; }
  93%, 95%      { opacity: 1; }
}

/* 提示小紅點 */
.pet-badge {
  position: absolute;
  top: 2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  box-sizing: border-box;
  border-radius: 10px;
  background: #c0402f;
  color: #f5f1e6;
  font-size: 13px;
  line-height: 20px;
  text-align: center;
  font-weight: bold;
  box-shadow: 0 0 8px rgba(192, 64, 47, .8);
  animation: badgePulse 1.6s ease-in-out infinite;
}
@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.15); }
}

/* ---------------- 氣泡 ---------------- */
.pet-bubble {
  position: absolute;
  bottom: 128px;
  left: 50%;
  transform: translateX(-50%);
  width: 240px;
  max-height: 200px;
  overflow: auto;
  background: rgba(13, 15, 19, .96);
  color: #e7dcc0;
  border: 1px solid rgba(226, 164, 79, .55);
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 13.5px;
  line-height: 1.7;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
  cursor: pointer;
}
.pet-bubble::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: rgba(226, 164, 79, .55);
  border-bottom: none;
}
.pet-bubble[hidden] { display: none; }

/* ---------------- 聊天面板 ---------------- */
.pet-chat {
  position: absolute;
  bottom: 132px;
  right: 0;
  width: 320px;
  max-width: 88vw;
  background: rgba(10, 12, 15, .97);
  border: 1px solid rgba(226, 164, 79, .5);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .72);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: #e7dcc0;
}
.pet-chat[hidden] { display: none; }

.pet-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 11px;
  border-bottom: 1px solid rgba(226, 164, 79, .28);
  background: rgba(226, 164, 79, .08);
}
.pc-title { font-size: 14px; letter-spacing: 1px; color: #f0d9a6; }
.pc-title small { color: #9a8b6f; font-size: 11px; margin-left: 4px; }
.pc-actions { display: flex; gap: 4px; }

.pc-btn {
  background: transparent;
  color: #e7dcc0;
  border: 1px solid rgba(203, 185, 143, .4);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.pc-btn:hover { background: rgba(226, 164, 79, .2); color: #f0d9a6; }
.pc-btn:active { transform: translateY(1px); }

.pet-msgs {
  flex: 1;
  min-height: 150px;
  max-height: 300px;
  overflow-y: auto;
  padding: 11px 11px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pet-msgs::-webkit-scrollbar { width: 6px; }
.pet-msgs::-webkit-scrollbar-thumb { background: rgba(203, 185, 143, .3); border-radius: 3px; }

.msg { max-width: 88%; padding: 7px 10px; border-radius: 10px; font-size: 13.5px; line-height: 1.6; word-break: break-word; }
.msg .who { display: block; font-size: 10.5px; opacity: .6; margin-bottom: 2px; letter-spacing: 1px; }
.msg.assist { align-self: flex-start; background: rgba(226, 164, 79, .12); border: 1px solid rgba(226, 164, 79, .25); }
.msg.user   { align-self: flex-end; background: rgba(78, 109, 95, .28); border: 1px solid rgba(78, 109, 95, .45); }
.msg.err    { align-self: flex-start; background: rgba(192, 64, 47, .16); border: 1px solid rgba(192, 64, 47, .5); }
.msg.typing { color: #b7a887; }

/* 打字光標 */
.caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: #e2a44f;
  margin-left: 1px;
  vertical-align: -2px;
  animation: caretBlink .7s steps(1) infinite;
}
@keyframes caretBlink { 50% { opacity: 0; } }

/* ---------------- 設置 ---------------- */
.pet-settings {
  padding: 10px 11px;
  border-bottom: 1px solid rgba(203, 185, 143, .22);
  background: rgba(0, 0, 0, .25);
}
.pet-settings[hidden] { display: none; }
.ps-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ps-row label { font-size: 12px; color: #b7a887; width: 52px; flex-shrink: 0; }
.ps-row input {
  flex: 1;
  background: rgba(0, 0, 0, .4);
  border: 1px solid rgba(203, 185, 143, .35);
  border-radius: 7px;
  color: #f0d9a6;
  padding: 6px 9px;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
}
.ps-row input:focus { border-color: rgba(226, 164, 79, .7); }
.ps-btns { justify-content: flex-end; margin-bottom: 0; }
.ps-note { font-size: 11px; line-height: 1.6; color: #8a7d63; }

/* ---------------- 輸入 ---------------- */
.pet-input {
  display: flex;
  gap: 6px;
  padding: 9px 11px;
  border-top: 1px solid rgba(203, 185, 143, .22);
}
.pet-input input {
  flex: 1;
  background: rgba(0, 0, 0, .4);
  border: 1px solid rgba(203, 185, 143, .35);
  border-radius: 8px;
  color: #f0d9a6;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.pet-input input:focus { border-color: rgba(226, 164, 79, .7); }
.pet-input input::placeholder { color: #6d6350; }

@media (max-width: 480px) {
  .pet-chat { width: 260px; }
  .pet-bubble { width: 200px; }
}
