/* ==========================================
   pet.css（v207.0）小D · 看板娘
   全部使用全站变量（浅暗自动跟随）；禁渐变、禁 emoji；
   动效只过渡 transform/opacity，带 reduced-motion 与 data-motion=off 兜底。
   ========================================== */

/* ---------- 召唤器（DeepSeek logo 钮，独立拖动） ---------- */
#petSummon {
  position: fixed;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
  cursor: grab;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2147482900;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#petSummon:hover { transform: translateY(-3px); box-shadow: var(--shadow-card-hover); }
#petSummon:active { cursor: grabbing; }
#petSummon svg { width: 26px; height: 26px; }

/* ---------- 舞台（立绘 + 气泡 + 工具条） ---------- */
#petStage {
  position: fixed;
  width: 300px;
  z-index: 2147482890;
  user-select: none;
  -webkit-user-select: none;
}
/* 立绘：双层图交叉淡入淡出（v207.4 丝滑形态切换） */
#petCharWrap {
  width: 240px;
  margin: 0 auto;
  pointer-events: none;
  display: grid;
  animation: petBreathe 3.2s ease-in-out infinite;
  transform-origin: 50% 100%;
}
#petCharWrap img {
  grid-area: 1 / 1;
  width: 100%;
  display: block;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s ease;
  cursor: grab;
  touch-action: none;
  -webkit-user-drag: none;
  transform-origin: 50% 100%;
}
#petCharWrap img.on { opacity: 1; pointer-events: auto; }
#petCharWrap img:active { cursor: grabbing; }

/* 拍扁摸头：squash & stretch（挂在 wrap 上，双层切换不打断；origin 已显式声明） */
#petCharWrap.pet-squish { animation: petSquish 0.68s ease; }
@keyframes petSquish {
  0% { transform: scale(1, 1); }
  28% { transform: scale(1.16, 0.74); }
  55% { transform: scale(0.95, 1.07); }
  76% { transform: scale(1.05, 0.92); }
  100% { transform: scale(1, 1); }
}
@keyframes petBreathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}
/* 走路：walk 帧 + 左右晃动模拟步伐（出门 / 归来） */
#petCharWrap.pet-walk { animation: petWalkSway 0.42s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes petWalkSway {
  0%, 100% { transform: translateX(-10px) rotate(-2.5deg); }
  50% { transform: translateX(10px) rotate(2.5deg); }
}
/* 玩具（游戏机等无立绘的）用摇晃动效代替 */
#petCharWrap.pet-wiggle { animation: petWiggle 1s ease-in-out; }
@keyframes petWiggle {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(-4deg) translateY(-2px); }
  30% { transform: rotate(4deg); }
  45% { transform: rotate(-4deg) translateY(-4px); }
  60% { transform: rotate(4deg); }
  75% { transform: rotate(-3deg); }
}
#petStage.pet-enter #petCharWrap { animation: petEnter 0.5s cubic-bezier(0.2, 1.4, 0.4, 1), petBreathe 3.2s ease-in-out 0.5s infinite; }
@keyframes petEnter {
  0% { transform: translateY(30px) scale(0.3); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
/* 退场动画（关闭 / 出门走远）：与入场呼应，缩小淡出 */
#petStage.pet-exit { animation: petExit 0.42s ease forwards; pointer-events: none; }
@keyframes petExit {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(26px) scale(0.3); opacity: 0; }
}

/* 气泡（v207.1：提到头顶上方，不挡脸） */
#petBubble {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  max-width: 252px;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px 8px;
  box-shadow: var(--shadow-card);
  opacity: 0;
  pointer-events: none;
  text-align: left;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 2;
}
#petBubble.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#petBubble small {
  display: block;
  color: var(--text-faint);
  font-size: 10px;
  margin-bottom: 1px;
}
#petBubble span {
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.45;
  word-break: break-all;
}

/* 工具条：logo 左下 + 三个点右下 */
#petBar {
  width: 210px;
  margin: -6px auto 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#petBar button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-sub);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, color 0.15s ease;
}
#petBar button:hover { transform: translateY(-2px); color: var(--text-main); }
#petLogoBtn svg { width: 20px; height: 20px; }

/* 粒子层 */
#petFx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 3;
}
.pet-pt {
  position: absolute;
  bottom: 46%;
  color: var(--accent);
  animation: petPtUp 1.3s ease-out forwards;
}
.pet-pt svg { width: 14px; height: 14px; }
@keyframes petPtUp {
  0% { transform: translate(0, 0) rotate(0deg) scale(0.6); opacity: 0; }
  18% { opacity: 1; }
  100% { transform: translate(var(--drift), -110px) rotate(var(--turn)) scale(1); opacity: 0; }
}
.pet-dizzy {
  position: absolute;
  top: 6%;
  left: 50%;
  width: 120px;
  height: 40px;
  margin-left: -60px;
  animation: petDizzySpin 1.1s linear infinite;
}
.pet-dizzy span {
  position: absolute;
  color: var(--text-sub);
  animation: petStarPulse 0.9s ease-in-out infinite;
  animation-delay: var(--sd);
}
.pet-dizzy svg { width: 15px; height: 15px; }
@keyframes petDizzySpin { to { transform: rotate(360deg); } }
@keyframes petStarPulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

/* ---------- 自绘菜单（下拉/上拉） ---------- */
#petMenu {
  position: fixed;
  min-width: 138px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card-hover);
  padding: 5px;
  z-index: 2147482901;
}
#petMenu[hidden] { display: none !important; }
#petMenu { animation: petMenuIn 0.16s ease; transform-origin: 50% 0%; }
#petMenu.up { transform-origin: 50% 100%; }
@keyframes petMenuIn {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
#petMenu button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
#petMenu button:hover { background: var(--bg-hover-tint); }
#petMenu button svg { color: var(--text-sub); flex: none; }
#petMenu button small {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-faint);
  margin-top: 1px;
}

/* ---------- 概况卡 ---------- */
#petOvCard {
  position: fixed;
  width: 218px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card-hover);
  padding: 12px 14px;
  z-index: 2147482901;
}
#petOvCard[hidden] { display: none !important; }
#petOvCard { animation: poIn 0.2s ease; transform-origin: 0% 40%; }
@keyframes poIn {
  0% { transform: translateX(-8px); opacity: 0; }
  100% { transform: translateX(0); opacity: 1; }
}
.po-head {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 9px;
}
.po-head small { color: var(--accent); font-weight: 600; }
.po-x {
  flex: none;
  border: 0;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 3px;
  border-radius: 7px;
  display: flex;
}
.po-x:hover { color: var(--text-main); background: var(--bg-hover-tint); }
.po-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 7px;
}
.po-row span { flex: none; width: 42px; }
.po-row b { flex: none; font-size: 12px; color: var(--text-main); font-weight: 600; }
.po-bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-hover-tint);
  overflow: hidden;
}
.po-bar i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.3s ease;
}
.po-bar i.warn { background: #d97706; }
.po-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-sub);
}
.po-foot svg { color: var(--accent); vertical-align: -2px; }
.po-bal { color: var(--text-faint); font-size: 11px; }
.po-quota {
  margin-top: 7px;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
}

/* ---------- 聊天窗 ---------- */
#petChat {
  position: fixed;
  width: 340px;
  height: 430px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card-hover);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147482902;
  animation: pcIn 0.26s cubic-bezier(0.2, 1.2, 0.4, 1); /* 打开动画，配 pop 音效 */
  transform-origin: 80% 90%;
}
@keyframes pcIn {
  0% { transform: translateY(14px) scale(0.94); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
#petChat[hidden] { display: none !important; }
.pc-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px 9px;
  border-bottom: 1px solid var(--border);
}
.pc-title { display: flex; align-items: baseline; gap: 8px; }
.pc-title b { font-size: 14px; color: var(--text-main); }
.pc-title small { font-size: 11px; color: var(--text-faint); }
.pc-close {
  border: 0;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  display: flex;
}
.pc-close:hover { color: var(--text-main); background: var(--bg-hover-tint); }
.pc-bal {
  flex: none;
  margin: 8px 14px 0;
  padding: 6px 10px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}
.pc-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overscroll-behavior: contain;
}
.pc-msg {
  max-width: 82%;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.pc-msg.ai {
  align-self: flex-start;
  background: var(--bg-bubble);
  color: var(--text-main);
  border-bottom-left-radius: 5px;
}
.pc-msg.me {
  align-self: flex-end;
  background: var(--btn-grad);
  color: var(--bg-page);
  border-bottom-right-radius: 5px;
}
/* v208.0：等回复时这行「……」轻微呼吸，别让人以为界面卡住了 */
.pc-msg.typing { color: var(--text-faint); font-style: italic; animation: pcThink 1.2s ease-in-out infinite; }
@keyframes pcThink { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }
.pc-msg.error { color: #d97706; }
.pc-stk {
  display: block;
  width: 132px;
  margin: 4px 0 2px;
  border-radius: 8px;
}
/* 关窗确认条（小D 挽留 + 是否保留记忆） */
.pc-confirm {
  flex: none;
  margin: 8px 12px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-bubble);
}
.pc-confirm p { margin: 0 0 7px; font-size: 12.5px; color: var(--text-main); font-weight: 600; }
.pc-keep { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-sub); cursor: pointer; }
.pc-keep input { accent-color: var(--accent); }
.pc-c-btns { display: flex; gap: 8px; margin-top: 9px; }
.pc-c-btns button {
  flex: 1;
  height: 30px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 12.5px;
  cursor: pointer;
}
.pc-c-btns #pcLeave { background: var(--btn-grad); color: var(--bg-page); border-color: transparent; }
/* 附件（发图片 / 文件，只存本窗口内存） */
.pc-att-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-sub);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pc-att-btn:hover { color: var(--text-main); }
.pc-att-prev {
  flex: none;
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 8px 12px 0;
  padding: 7px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-sub);
}
.pc-att-prev[hidden] { display: none !important; }
.pc-att-prev img { width: 42px; height: 42px; object-fit: cover; border-radius: 8px; }
.pc-att-prev span { min-width: 0; word-break: break-all; }
.pc-att-prev button {
  flex: none;
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 4px;
  border-radius: 7px;
  display: flex;
}
.pc-att-prev button:hover { color: var(--text-main); background: var(--bg-hover-tint); }
.pc-att-img {
  display: block;
  max-width: 180px;
  max-height: 150px;
  border-radius: 9px;
  margin-top: 5px;
}
/* v208.0：图没附成功时的明示（以前是静默降级，用户只看到「她说看不到图」） */
.pc-att-bad {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-faint);
}
.pc-att-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--bg-hover-tint);
  font-size: 12px;
  max-width: 100%;
}
.pc-att-file span { min-width: 0; word-break: break-all; }
.pc-form {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.pc-form input {
  flex: 1;
  min-width: 0;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-main);
  padding: 0 11px;
  font-size: 13px;
  outline: none;
}
.pc-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.pc-form button {
  flex: none;
  width: 38px;
  height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--btn-grad);
  color: var(--bg-page);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* ⚠️ 必须显式写这条：上面 .pc-form button 的 display:flex 特异性高于浏览器对 [hidden]
   的 display:none，不补这一条「停止生成」钮会一直挂着。停止钮与发送钮同款，靠方块图标区分。 */
.pc-form button[hidden] { display: none; }

/* v208.0：聊天正文走 MiniMD 后的排版
   注意 .pc-msg 自带 white-space:pre-wrap，这里必须还原成 normal，
   否则 Markdown 转出的换行会再叠一次 pre-wrap 的换行，行距翻倍。 */
.pc-md { white-space: normal; }
.pc-md p { margin: 0 0 6px; }
.pc-md p:last-child { margin-bottom: 0; }
.pc-md ul, .pc-md ol { margin: 4px 0; padding-left: 18px; }
.pc-md li { margin: 2px 0; }
.pc-md strong { font-weight: 700; }
.pc-md code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: var(--bg-hover-tint);
  padding: 1px 4px;
  border-radius: 4px;
}
.pc-md pre {
  margin: 5px 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg-hover-tint);
  overflow-x: auto;
}
.pc-md pre code { background: none; padding: 0; }
.pc-md blockquote {
  margin: 4px 0;
  padding-left: 8px;
  border-left: 2px solid var(--border);
  color: var(--text-sub);
}
.pc-md hr { margin: 7px 0; border: 0; border-top: 1px solid var(--border); }
.pc-md table { border-collapse: collapse; margin: 4px 0; }
.pc-md th, .pc-md td { border: 1px solid var(--border); padding: 3px 6px; font-size: 12px; }
/* 用户气泡是深底浅字，内嵌代码块的浅色底捞不住，换成半透明白 */
.pc-msg.me .pc-md code, .pc-msg.me .pc-md pre { background: rgba(255, 255, 255, 0.18); }

/* ---------- 弹窗（商店 / 小鲸鱼） ---------- */
#petModalMask {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 2147482903;
}
#petModalMask[hidden] { display: none !important; }
/* 弹窗入场动画（v207.1） */
#petModal { animation: pmIn 0.24s cubic-bezier(0.2, 1.2, 0.4, 1); transform-origin: 50% 60%; }
@keyframes pmIn {
  0% { transform: translateY(18px) scale(0.92); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
#petModal {
  width: min(400px, 100%);
  max-height: min(560px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card-hover);
  overflow: hidden;
}
.pm-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.pm-head b { font-size: 15px; color: var(--text-main); }
.pm-close {
  border: 0;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  display: flex;
}
.pm-close:hover { color: var(--text-main); background: var(--bg-hover-tint); }
.pm-body { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 16px 16px; overscroll-behavior: contain; }
.pm-bal { font-size: 12.5px; color: var(--text-sub); margin-bottom: 10px; }
.pm-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.pm-i-info b { display: block; font-size: 13.5px; color: var(--text-main); }
.pm-i-info small { display: block; font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.pm-i-info em { display: inline-block; font-style: normal; font-size: 11px; color: var(--accent); margin-top: 3px; }
.pm-i-buy { flex: none; text-align: right; }
.pm-i-buy span { display: block; font-size: 12px; color: var(--text-sub); margin-bottom: 5px; }
.pm-i-buy button {
  border: 0;
  border-radius: 9px;
  background: var(--btn-grad);
  color: var(--bg-page);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 14px;
  cursor: pointer;
}
.pm-note { font-size: 11.5px; color: var(--text-faint); line-height: 1.6; margin-top: 12px; }
.pm-profile { display: flex; gap: 14px; align-items: flex-start; }
.pm-profile img { width: 110px; flex: none; border-radius: var(--radius-sm); }
.pm-profile p { font-size: 12.5px; color: var(--text-sub); line-height: 1.7; margin: 0 0 4px; }
.pm-profile b { color: var(--text-main); }
.pm-sub {
  font-size: 12px;
  color: var(--text-sub);
  margin: 14px 0 2px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ---------- 动效兜底 ---------- */
@media (prefers-reduced-motion: reduce) {
  #petCharWrap, #petStage.pet-enter #petCharWrap, .pet-pt, .pet-dizzy, .pet-dizzy span, #petChat,
  #petCharWrap.pet-walk, #petCharWrap.pet-wiggle, #petModal, #petMenu, #petOvCard, .pc-msg.typing { animation: none !important; }
  #petBubble, #petSummon, #petBar button { transition: none !important; }
}
html[data-motion="off"] #petCharWrap,
html[data-motion="off"] #petStage.pet-enter #petCharWrap,
html[data-motion="off"] .pet-pt,
html[data-motion="off"] .pet-dizzy,
html[data-motion="off"] .pet-dizzy span,
html[data-motion="off"] #petChat,
html[data-motion="off"] #petModal,
html[data-motion="off"] #petMenu,
html[data-motion="off"] #petOvCard,
html[data-motion="off"] .pc-msg.typing { animation: none !important; }

/* ---------- 窄屏 ---------- */
@media (max-width: 560px) {
  #petStage { display: none !important; }
  #petSummon { display: none !important; }
}
