/* ══════════════════════════════════════════════════
   余温桌宠 · 夹心酱（小邪神）
   形象走 /pet/*.webp（设计图抠出的五态位图），动效在下方 keyframes，
   这里管位置、尺寸、气泡和面板。站点 CSP style-src 'self'
   ══════════════════════════════════════════════════ */

.pet {
  position: fixed;
  z-index: 90;
  width: 124px;
  height: 96px;
  left: auto;
  right: 26px;
  bottom: 24px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

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

/* ── 舞台 ── */
.pet-stage {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: grab;
  outline: none;
  display: grid;
  place-items: center;
  transition: transform .22s ease, filter .22s ease;
  filter: drop-shadow(0 8px 14px rgba(48, 44, 40, .16));
}

.pet-stage:focus-visible {
  outline: 2px solid var(--coral, #bb634b);
  outline-offset: 3px;
  border-radius: 50%;
}

.pet-stage:hover {
  transform: translateY(-2px);
  filter: drop-shadow(0 12px 20px rgba(48, 44, 40, .22));
}

.pet-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  user-select: none;
}

/* 位图在 img 里保持比例、别被压扁；各状态素材高度不同，统一底部对齐 */
.pet-img {
  object-fit: contain;
  object-position: bottom center;
  transform-origin: bottom center;
}

/* ── 位图动画（素材是静态图，动效由 CSS 驱动） ── */
@keyframes petFloat {
  0%, 100% { transform: translateY(0) }
  50% { transform: translateY(-3px) }
}
@keyframes petBreathe {
  0%, 100% { transform: scale(1) }
  50% { transform: scale(1.02) }
}
@keyframes petShake {
  0%, 100% { transform: translate(0, 0) rotate(0) }
  25% { transform: translate(-2px, -1px) rotate(-.7deg) }
  75% { transform: translate(2px, -1px) rotate(.7deg) }
}
@keyframes petHoverLift {
  0%, 100% { transform: translateY(0) scale(1) }
  50% { transform: translateY(-4px) scale(1.06) }
}
@keyframes petJump {
  0%, 100% { transform: translateY(0) scale(1) }
  22%, 32% { transform: translateY(-11px) scale(1.04) }
  46% { transform: translateY(0) scale(1) }
}

.pet[data-state="idle"] .pet-img,
.pet[data-state="rest"] .pet-img { animation: petFloat 4s ease-in-out infinite }
.pet[data-state="reading"] .pet-img { animation: petBreathe 3.6s ease-in-out infinite }
.pet[data-state="thinking"] .pet-img { animation: petFloat 3s ease-in-out infinite }
.pet[data-state="writing"] .pet-img { animation: petFloat 2.4s ease-in-out infinite }
.pet[data-state="berserk"] .pet-img { animation: petShake .3s linear infinite }
.pet[data-state="hover"] .pet-img { animation: petHoverLift 1.6s ease-in-out infinite }
.pet[data-state="click"] .pet-img { animation: petJump 1.4s ease-in-out 1 }

@media (prefers-reduced-motion: reduce) {
  .pet-img { animation: none !important }
}

/* ── 气泡 ── */
.pet-bubble {
  position: absolute;
  right: 6px;
  bottom: calc(100% + 8px);
  max-width: 200px;
  width: max-content;
  padding: 8px 11px;
  background: #fffdf8;
  border: 1px solid #ded7cc;
  border-radius: 12px 12px 3px 12px;
  color: #302c28;
  font-size: 12.5px;
  line-height: 1.62;
  letter-spacing: .01em;
  box-shadow: 0 8px 20px rgba(48, 44, 40, .12);
  opacity: 0;
  transform: translateY(6px) scale(.96);
  transform-origin: bottom right;
  transition: opacity .22s ease, transform .22s ease;
  pointer-events: none;
}

.pet-bubble.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.pet-bubble::after {
  content: "";
  position: absolute;
  right: 14px;
  bottom: -6px;
  width: 10px;
  height: 10px;
  background: #fffdf8;
  border-right: 1px solid #ded7cc;
  border-bottom: 1px solid #ded7cc;
  transform: rotate(45deg);
  border-radius: 0 0 3px 0;
}

/* ══════════════ 面板 ══════════════ */

.pet-panel {
  position: fixed;
  z-index: 95;
  width: 344px;
  max-height: min(70vh, 520px);
  display: flex;
  flex-direction: column;
  background: #f7f3eb;
  border: 1px solid #ded7cc;
  border-radius: 16px;
  box-shadow: 0 22px 50px rgba(38, 32, 27, .22);
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px) scale(.98);
  transform-origin: bottom right;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}

.pet-panel.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.pet-panel-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 13px 14px 11px;
  border-bottom: 1px solid #e6dfd4;
  background: #fffdf8;
}

.pet-panel-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7fa88c;
  flex: none;
  box-shadow: 0 0 0 3px rgba(127, 168, 140, .18);
}

.pet[data-state="berserk"] ~ .pet-panel .pet-panel-dot {
  background: #c2543f;
  box-shadow: 0 0 0 3px rgba(194, 84, 63, .16);
}

.pet-panel-name {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .04em;
  color: #302c28;
}

.pet-panel-sub {
  font-size: 10.5px;
  color: #8b857c;
  margin-left: auto;
  letter-spacing: .04em;
}

.pet-panel-close {
  width: 24px;
  height: 24px;
  border: 1px solid #e2dbd0;
  border-radius: 50%;
  background: transparent;
  color: #6f6961;
  font-size: 13px;
  line-height: 1;
  display: grid;
  place-items: center;
  flex: none;
  margin-left: 6px;
  cursor: pointer;
}

.pet-panel-close:hover {
  border-color: #bb634b;
  color: #bb634b;
}

.pet-tabs {
  display: flex;
  gap: 2px;
  padding: 9px 12px 0;
  background: #fffdf8;
  border-bottom: 1px solid #e6dfd4;
}

.pet-tab {
  border: 0;
  background: transparent;
  padding: 7px 12px 9px;
  font-size: 11.5px;
  font-weight: 700;
  color: #9a938a;
  cursor: pointer;
  position: relative;
  letter-spacing: .04em;
}

.pet-tab.active {
  color: #302c28;
}

.pet-tab.active::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  background: #bb634b;
  border-radius: 2px;
}

.pet-body {
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1;
  min-height: 0;
}

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

/* ── 指标条 ── */
.pet-metric {
  margin-bottom: 13px;
}

.pet-metric-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 5px;
}

.pet-metric-label {
  font-size: 11px;
  color: #6f6961;
  letter-spacing: .06em;
}

.pet-metric-value {
  font-size: 11px;
  font-weight: 700;
  color: #302c28;
  font-variant-numeric: tabular-nums;
}

.pet-bar {
  height: 5px;
  border-radius: 3px;
  background: #e8e1d6;
  overflow: hidden;
}

.pet-bar-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: #bb634b;
  transition: width .5s ease;
}

.pet-bar-fill.is-cool { background: #7fa88c; }
.pet-bar-fill.is-warn { background: #d99a45; }
.pet-bar-fill.is-hot { background: #cf5f4c; }

/* ── 小标题 ── */
.pet-section-title {
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #9a938a;
  font-weight: 700;
  margin: 16px 0 8px;
}

.pet-section-title:first-child {
  margin-top: 0;
}

/* ── 渠道列表 ── */
.pet-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed #e6dfd4;
  font-size: 12px;
}

.pet-link:last-child {
  border-bottom: 0;
}

.pet-link-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7fa88c;
  flex: none;
}

.pet-link.off .pet-link-dot {
  background: #c3bcb2;
}

.pet-link-name {
  color: #302c28;
  font-weight: 600;
}

.pet-link-note {
  margin-left: auto;
  font-size: 10.5px;
  color: #9a938a;
  font-variant-numeric: tabular-nums;
}

/* ── 定时任务 ── */
.pet-job {
  padding: 8px 0;
  border-bottom: 1px dashed #e6dfd4;
}

.pet-job:last-child {
  border-bottom: 0;
}

.pet-job-name {
  font-size: 12px;
  color: #302c28;
  line-height: 1.5;
}

.pet-job-meta {
  margin-top: 3px;
  font-size: 10.5px;
  color: #9a938a;
  display: flex;
  gap: 10px;
  font-variant-numeric: tabular-nums;
}

.pet-job[data-status="error"] .pet-job-name {
  color: #c2543f;
}

/* ── 历史记录 ── */
.pet-log {
  position: relative;
  padding-left: 14px;
}

.pet-log::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: #e2dbd0;
}

.pet-log-item {
  position: relative;
  padding: 7px 0;
}

.pet-log-item::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 13px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fffdf8;
  border: 1.5px solid #c9a08e;
}

.pet-log-title {
  font-size: 12px;
  line-height: 1.55;
  color: #302c28;
}

.pet-log-meta {
  margin-top: 3px;
  font-size: 10.5px;
  color: #9a938a;
  display: flex;
  gap: 9px;
  font-variant-numeric: tabular-nums;
}

.pet-log-hash {
  font-family: ui-monospace, Menlo, monospace;
  color: #b0a89e;
}

.pet-empty {
  padding: 22px 0;
  text-align: center;
  font-size: 12px;
  color: #a8a199;
}

.pet-foot-note {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #e6dfd4;
  font-size: 10.5px;
  line-height: 1.7;
  color: #a8a199;
}

/* ── 移动端 ── */
@media (max-width: 900px) {
  .pet {
    width: 92px;
    height: 72px;
    right: 14px;
    bottom: 14px;
  }

  .pet-bubble {
    max-width: 168px;
    font-size: 12px;
  }

  .pet-panel {
    width: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
    top: auto;
    max-height: 62vh;
    transform-origin: bottom center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pet-stage,
  .pet-bubble,
  .pet-panel,
  .pet-bar-fill {
    animation: none !important;
    transition: none !important;
  }
}
/* ── 说话面板：只聊天，不干活 ── */
.pet-chat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 232px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  margin-bottom: 10px;
}

.pet-chat-row {
  display: flex;
}

.pet-chat-row.me {
  justify-content: flex-end;
}

.pet-chat-text {
  max-width: 84%;
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.58;
  word-break: break-word;
  white-space: pre-wrap;
}

.pet-chat-row.her .pet-chat-text {
  background: #efe8dc;
  color: #302c28;
  border-bottom-left-radius: 3px;
}

.pet-chat-row.me .pet-chat-text {
  background: #bb634b;
  color: #fff8f2;
  border-bottom-right-radius: 3px;
}

.pet-chat-empty {
  margin: 8px 0 0;
  font-size: 12px;
  color: #9a938a;
  text-align: center;
}

.pet-chat-form {
  display: flex;
  gap: 6px;
  align-items: center;
}

.pet-chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid #e6dfd4;
  background: #fffdf9;
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 12px;
  color: #302c28;
  font-family: inherit;
}

.pet-chat-input::placeholder {
  color: #b3aca1;
}

.pet-chat-input:focus {
  outline: none;
  border-color: #bb634b;
  box-shadow: 0 0 0 2px rgba(187, 99, 75, .12);
}

.pet-chat-send {
  border: 1px solid #bb634b;
  background: #bb634b;
  color: #fff8f2;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.pet-chat-send:active {
  transform: translateY(1px);
}

@media (max-width: 900px) {
  .pet-chat {
    height: 28vh;
  }
}

/* ── 养成 ── */
.pet-grow { padding: 4px 2px 2px; }
.pet-grow-loading { margin: 0; padding: 18px 0; text-align: center; font-size: 13px; color: #8b7b6b; }
.pet-grow-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.pet-grow-top strong { font-size: 16px; color: #3b3128; letter-spacing: .02em; }
.pet-grow-pct { font-size: 12px; color: #a08d7a; font-variant-numeric: tabular-nums; }
.pet-grow-note { margin: 4px 0 10px; font-size: 12px; color: #8b7b6b; line-height: 1.6; }
.pet-grow-bar { height: 8px; border-radius: 999px; background: #f0e6d8; overflow: hidden; }
.pet-grow-bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #e8a08a, #d9715a); transition: width .45s ease; }
.pet-grow-next { margin: 8px 0 12px; font-size: 12px; color: #8b7b6b; }
.pet-grow-stats { display: flex; flex-wrap: wrap; gap: 12px; padding: 10px 0; border-top: 1px dashed #e6d9c8; border-bottom: 1px dashed #e6d9c8; font-size: 12px; color: #8b7b6b; }
.pet-grow-stats strong { color: #3b3128; font-weight: 600; }
.pet-grow-feed { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.pet-feed-btn { display: inline-flex; align-items: center; gap: 4px; padding: 7px 14px; border-radius: 999px; border: 1px solid #d9715a; background: #d9715a; color: #fff; font-size: 13px; cursor: pointer; transition: .2s; }
.pet-feed-btn small { font-size: 11px; opacity: .85; }
.pet-feed-btn:hover:not(:disabled) { background: #c65f49; border-color: #c65f49; }
.pet-feed-btn:disabled { background: #efe4d6; border-color: #e6d9c8; color: #a89a89; cursor: default; }
.pet-grow-hint { font-size: 11px; color: #a08d7a; }
@media (max-width: 480px) {
  .pet-grow-stats { gap: 8px; font-size: 11px; }
}

/* ---------- 暗色 ---------- */
html[data-theme="dark"] .pet-bubble {
  background: #241f1a;
  border-color: #3b342c;
  color: #ece5d8;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .55);
}
html[data-theme="dark"] .pet-bubble::after {
  background: #241f1a;
  border-right-color: #3b342c;
  border-bottom-color: #3b342c;
}
