/* =============================================================================
   pet.css — 桌面宠物（像素柴犬 + 对话气泡 + 状态 HUD）
   结构由 modules/pet.js 生成：
   .pet > .pet__stage > (.pet__bubble + canvas.pet__canvas + .pet__hud + .pet__actions)
   ============================================================================= */

.pet {
  position: fixed;
  left: 0;
  bottom: 14px;
  z-index: 60; /* 低于搜索面板(200)，高于页面内容 */
  pointer-events: none;
  will-change: transform;
}
.pet[hidden] { display: none; }

/* 手机端滑动时整体藏起来（scrollAwayHide），停下淡回；
   过渡走 .pet 上已有的 opacity 规则。pointer-events 一并关掉，
   藏着的狗不许吞背后内容的点击。
   放在 is-farm-panel 之前：农场面板打开时的完全隐身优先级更高。 */
.pet.is-away { opacity: 0; pointer-events: none; }

/* 农场页打开商店 / 选种面板时，桌宠让开。
   想靠 z-index 解决是行不通的：`.site-main` 自己是一个 z-index:5 的层叠上下文，
   HUD（含抽屉）全被封在里面，而桌宠挂在 body 上、原本是 60 ——
   它永远压在抽屉之上（截图里商店右半边那只柴犬就是它）。
   所以不调层级，改为「有面板打开就淡出」，面板关掉再回来。 */
body.is-farm-panel .pet,
body.is-farm-panel .pet-show {
  opacity: 0;
  pointer-events: none;
}

/* 观影页播放器打开时同理：弹窗要盖住一切，狗不许趴在进度条上。 */
body.is-watch-open .pet,
body.is-watch-open .pet-show {
  opacity: 0;
  pointer-events: none;
}

/* 游戏页：桌宠退场。
   棋盘 / 翻牌 / 反应区都在页面下半部分，桌宠固定悬浮，正好压在操作区上——
   玩到一半被一只柴犬挡住点击，是纯粹的负体验。body[data-game] 由 play.js 维护。 */
body[data-game="1"] .pet {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.pet { transition: opacity var(--d-base) var(--ease-out); }

/* ⚠️ 舞台自己必须是 none。
   它的盒子包含「收起状态的 HUD 与按钮」——那两块是 opacity:0 但仍然占位的，
   舞台一旦 auto，这块 172×273 的透明区域就会吞掉点击：
   农场右下角的「商店 / 缩放 / 返回」正好在它下面，点下去命中的是 .pet__stage，
   商店打不开。可见的部分（小狗、气泡）自己声明 auto 就够了。 */
.pet__stage {
  position: relative;
  pointer-events: none;
  width: max-content;
}

/* ---------------------------------------------------------------- 像素画布 */
.pet__canvas {
  pointer-events: auto;  /* 舞台是 none，小狗自己要能点能拖 */
  display: block;
  margin: 0 auto; /* 在 HUD 面板上方居中 */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: grab;            /* 可以拖着走 */
  touch-action: none;      /* 拖拽自己接管，别让浏览器去滚页面 */
  user-select: none;
  -webkit-user-select: none;
  transform-origin: bottom center;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
  transition: filter var(--d-fast) var(--ease-out);
}
.pet__canvas:hover { filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.45)); }

/* ---------------------------------------------------------------- 对话气泡 */
.pet__bubble {
  pointer-events: auto;    /* 舞台 none，气泡要能点（点它换一条提示） */
  position: absolute;
  bottom: calc(100% + 8px);
  right: calc(-4px + var(--bub-shift, 0px));
  width: max-content;
  max-width: 210px;
  padding: 9px 13px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-hi);
  background: color-mix(in srgb, var(--bg-1) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow-2);
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.6;
  cursor: pointer;
  /* opacity:0 不妨碍命中测试，藏着的气泡会白白挡住背后内容的点击；
     只有可见时才接收事件（可见时点击 = 换一条） */
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px) scale(0.94);
  transform-origin: bottom right;
  transition: opacity var(--d-base) var(--ease-out), transform var(--d-base) var(--ease-spring);
}
.pet__bubble.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
/* 小狗靠左时：气泡改为左对齐，避免溢出屏幕左侧 */
.pet__bubble.is-flipped {
  right: auto;
  left: calc(-4px + var(--bub-shift, 0px));
  transform-origin: bottom left;
}
.pet__bubble.is-flipped::after {
  right: auto;
  left: 20px;
}
/* 气泡小尾巴，指向小狗 */
.pet__bubble::after {
  content: '';
  position: absolute;
  right: 20px;
  bottom: -5px;
  width: 9px;
  height: 9px;
  background: color-mix(in srgb, var(--bg-1) 88%, transparent);
  border-right: 1px solid var(--border-hi);
  border-bottom: 1px solid var(--border-hi);
  transform: rotate(45deg);
}

/* ---------------------------------------------------------------- 动效 */
@keyframes pet-jump {
  0%   { transform: translateY(0) scaleY(1); }
  30%  { transform: translateY(-16px) scaleY(1.06); }
  55%  { transform: translateY(0) scaleY(0.92); }
  75%  { transform: translateY(-4px) scaleY(1.02); }
  100% { transform: translateY(0) scaleY(1); }
}
.pet.is-jump .pet__stage { animation: pet-jump 0.52s var(--ease-out); }

@keyframes pet-pop {
  0%   { transform: scale(0.4) rotate(-8deg); opacity: 0.2; }
  60%  { transform: scale(1.12) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}
.pet.is-pop .pet__stage { animation: pet-pop 0.42s var(--ease-spring); }

/* 睡着：整体极轻微地上下浮动，像呼吸；只动 transform，不产生新合成层 */
@keyframes pet-breathe {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(1px); }
}
.pet.is-asleep .pet__stage { animation: pet-breathe 3.6s ease-in-out infinite; }

/* 头顶飘出来的 Z */
.pet__zzz {
  position: absolute;
  top: -8px;
  right: 4px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--d-base) var(--ease-out);
}
.pet.is-asleep .pet__zzz { opacity: 1; }
.pet__zzz span {
  font-size: var(--text-2xs);
  font-weight: 700;
  line-height: 1;
  color: var(--text-dim);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  animation: zzz-float 3.2s ease-in-out infinite;
}
.pet__zzz span:nth-child(2) { font-size: var(--text-sm); animation-delay: 0.55s; }
.pet__zzz span:nth-child(3) { font-size: var(--text-base); animation-delay: 1.1s; }
@keyframes zzz-float {
  0%   { opacity: 0; transform: translate(0, 5px) scale(0.7); }
  30%  { opacity: 1; }
  100% { opacity: 0; transform: translate(7px, -18px) scale(1.05); }
}

/* ---------------------------------------------------------------- 状态 HUD */
/* 面板（HUD + 三个按钮）默认收起：进页面亮几秒、点宠物再亮，其余时间只留一只狗 */
.pet__hud,
.pet__actions {
  transition: opacity var(--d-base) var(--ease-out), transform var(--d-base) var(--ease-out);
}
.pet:not(.is-panel) .pet__hud,
.pet:not(.is-panel) .pet__actions {
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
}
/* 面板展开时把点击收回来：pointer-events 是继承的，舞台现在是 none，
   不写这一条的话 喂食/玩耍/睡觉 三个按钮全都点不动。 */
.pet.is-panel .pet__hud,
.pet.is-panel .pet__actions {
  pointer-events: auto;
}

.pet__hud {
  width: 172px;
  margin-top: 7px;
  padding: 7px 10px 8px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-hi);
  background: color-mix(in srgb, var(--bg-1) 88%, transparent);
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  box-shadow: var(--shadow-2);
  font-size: var(--text-3xs);
  color: var(--text-dim);
  animation: hud-in var(--d-base) var(--ease-spring);
}
@keyframes hud-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.pet__hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
  font-size: var(--text-2xs);
  color: var(--text);
}
.pet__hud-mood { display: inline-flex; align-items: center; gap: 5px; }
.pet__hud-face { font-size: var(--text-xs); line-height: 1; }
.pet__hud-breed {
  color: var(--text-mute);
  font-size: var(--text-3xs);
  letter-spacing: 0.04em;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pet__hud-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 4px;
}
.pet__hud-key { flex: none; width: 26px; }
.pet__hud-num {
  flex: none;
  width: 22px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-mute);
}
.pet__bar {
  position: relative;
  flex: 1;
  height: 5px;
  border-radius: var(--r-xs);
  background: color-mix(in srgb, var(--text) 14%, transparent);
  overflow: hidden;
}
.pet__bar > i {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: var(--r-xs);
  transition: width var(--d-base) var(--ease-out), background var(--d-base) var(--ease-out);
}
.pet__bar--hunger > i { background: #f5a623; }
.pet__bar--happy > i  { background: #f06ba8; }
.pet__bar--energy > i { background: #3fb6f0; }
/* 低于 25 变警示色 */
.pet__bar.is-low > i { background: var(--bad); }

/* ---------------------------------------------------------------- 互动按钮 */
.pet__actions {
  display: flex;
  gap: 5px;
  margin-top: 6px;
}
.pet__act {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 5px 0 4px;
  border-radius: var(--r-xs);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-1) 82%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-dim);
  font-size: var(--text-3xs);
  cursor: pointer;
  transition: color var(--d-fast) var(--ease-out), border-color var(--d-fast) var(--ease-out),
    transform var(--d-fast) var(--ease-spring), background var(--d-fast) var(--ease-out);
}
.pet__act svg { width: 13px; height: 13px; }
.pet__act:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-hi);
  transform: translateY(-1px);
}
.pet__act:active:not(:disabled) { transform: translateY(0) scale(0.94); }
.pet__act:disabled { opacity: 0.42; cursor: default; }

/* ---------------------------------------------------------------- 小屏 */
@media (max-width: 640px) {
  .pet { bottom: 10px; }
  .pet__bubble { max-width: 172px; font-size: var(--text-xs); padding: 8px 11px; }
  /* 手机端整体缩一档（画布由 pet.js 的 pxFor 决定），HUD 也跟着收窄 */
  .pet__hud { width: 124px; padding: 6px 8px; }
  .pet__hud-top { font-size: var(--text-3xs); }
  .pet__hud-row { font-size: var(--text-3xs); }
  .pet__hud-num { display: none; }
  .pet__act span { display: none; }
  .pet__act { padding: 7px 0; }
}

/* ---------------------------------------------------------------- 减少动效 */
@media (prefers-reduced-motion: reduce) {
  .pet__bubble { transition: opacity 0.01s; transform: none; }
  .pet.is-jump .pet__stage,
  .pet.is-pop .pet__stage,
  .pet.is-asleep .pet__stage { animation: none; }
  .pet__zzz span { animation: none; opacity: 1; }
}

/* ---------------------------------------------------------------- 显隐与拖拽
   桌宠会压住页面内容，所以必须能自己挪开、也能彻底收起：
     ① 拖着走 —— 在 .pet__canvas 上按住拖（cursor: grab）；
     ② 面板上的 × —— 收起；
     ③ 收起之后右下角出现「唤回」按钮，再点回来。
   隐藏状态存在 localStorage(chweb:pet-hidden)，位置和摆放也记在
   chweb:pet-pos —— 刷新、换页都按上次的来。 */
.pet__hide {
  margin-left: auto;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border-hi, rgba(255, 255, 255, 0.18));
  border-radius: var(--r-sm, 8px);
  background: transparent;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  flex: none;
}
.pet__hide:hover { opacity: 1; background: rgba(255, 255, 255, 0.1); }
.pet__hide svg { width: 11px; height: 11px; }

/* 唤回按钮：藏起来之后唯一的入口，固定右下角，和宠物原来的角落一致 */
.pet-show {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border: 1px solid var(--border-hi, rgba(255, 255, 255, 0.18));
  border-radius: var(--r-sm, 10px);
  background: color-mix(in srgb, var(--bg-1, #14161d) 82%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow-2, 0 6px 18px rgba(0, 0, 0, 0.28));
  color: var(--text, #eef1f7);
  font-size: var(--text-2xs, 11px);
  cursor: pointer;
}
.pet-show[hidden] { display: none; }
.pet-show:hover { background: color-mix(in srgb, var(--bg-1, #14161d) 96%, transparent); }
.pet-show svg { width: 14px; height: 14px; }
@media (max-width: 640px) {
  .pet-show { right: 10px; bottom: 10px; padding: 6px 9px; }
  .pet-show span { display: none; }
}
