/* ==========================================================================
   Hermes 宠物机器人（2026-10-02）
   常驻右下角悬浮球 + 可展开大面板；形象为「冰冰」狗。
   铁律：宠物只解释/建议，绝不参与评分；危险动作必须确认。
   ========================================================================== */

.pet-ball {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(145deg, #2b3446, #1a2130);
  border: 2px solid var(--gold);
  box-shadow: 0 8px 26px rgba(0,0,0,.5);
  cursor: pointer;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
  padding: 0;
}
.pet-ball:hover { transform: translateY(-3px) scale(1.05); box-shadow: 0 12px 32px rgba(0,0,0,.6); }
.pet-ball img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pet-ball .pet-ball-emoji { font-size: 30px; line-height: 1; }
/* 有未读/待确认时的红点 */
.pet-ball .pet-badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 19px; height: 19px; border-radius: 10px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  display: none; align-items: center; justify-content: center; padding: 0 5px;
  border: 2px solid var(--bg);
}
.pet-ball.has-badge .pet-badge { display: flex; }
/* 待确认时呼吸提示 */
.pet-ball.need-confirm { border-color: var(--red); animation: petPulse 1.4s infinite; }
@keyframes petPulse {
  0%,100% { box-shadow: 0 8px 26px rgba(0,0,0,.5), 0 0 0 0 rgba(239,68,68,.5); }
  50%     { box-shadow: 0 8px 26px rgba(0,0,0,.5), 0 0 0 10px rgba(239,68,68,0); }
}

/* ---- 面板 ---- */
.pet-panel {
  position: fixed;
  right: 22px;
  bottom: 96px;
  width: 400px;
  height: 560px;
  /* 上限放宽：实际可用空间由 JS 的 limits() 精确计算并兜住，
     避免 CSS 的 max-* 把用户拖出来的尺寸又压回去 */
  max-width: 96vw;
  max-height: calc(100vh - 110px);
  min-width: 300px;
  min-height: 300px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 22px 60px rgba(0,0,0,.62);
  z-index: 91;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pet-panel[hidden] { display: none !important; }

/* ---- 自由调整大小（2026-10-02）----
   8 个方向的手柄：四边 + 四角。拖拽时由 JS 计算新宽高并落盘到 localStorage。 */
.pet-resize {
  position: absolute;
  z-index: 5;
  touch-action: none;            /* 手机上拖手柄不触发页面滚动 */
  user-select: none;
}
/* 四边 */
.pet-rs-n { top: -3px; left: 10px; right: 10px; height: 7px; cursor: ns-resize; }
.pet-rs-s { bottom: -3px; left: 10px; right: 10px; height: 7px; cursor: ns-resize; }
.pet-rs-w { left: -3px; top: 10px; bottom: 10px; width: 7px; cursor: ew-resize; }
.pet-rs-e { right: -3px; top: 10px; bottom: 10px; width: 7px; cursor: ew-resize; }
/* 四角（加大命中区） */
.pet-rs-nw { top: -3px; left: -3px; width: 15px; height: 15px; cursor: nwse-resize; }
.pet-rs-ne { top: -3px; right: -3px; width: 15px; height: 15px; cursor: nesw-resize; }
.pet-rs-sw { bottom: -3px; left: -3px; width: 15px; height: 15px; cursor: nesw-resize; }
.pet-rs-se { bottom: -3px; right: -3px; width: 15px; height: 15px; cursor: nwse-resize; }

/* 右下角画一个可见的抓取标记 */
.pet-rs-se::after {
  content: '';
  position: absolute;
  right: 4px; bottom: 4px;
  width: 9px; height: 9px;
  border-right: 2px solid var(--mut);
  border-bottom: 2px solid var(--mut);
  border-radius: 0 0 3px 0;
  opacity: .55;
}
.pet-panel:hover .pet-rs-se::after { opacity: .95; }

/* 拖拽中：禁掉过渡，避免跟手延迟 */
.pet-panel.resizing {
  user-select: none;
  transition: none !important;
}
.pet-panel.resizing * { pointer-events: none; }
.pet-panel.resizing .pet-resize { pointer-events: auto; }

/* 尺寸预设按钮（表头里） */
.pet-size-row {
  display: inline-flex; gap: 3px; margin-left: 4px;
}
.pet-size-btn {
  background: transparent; border: 1px solid var(--line); color: var(--mut);
  font-size: 10.5px; line-height: 1; padding: 3px 6px; border-radius: 6px; cursor: pointer;
}
.pet-size-btn:hover, .pet-size-btn.on { color: var(--gold); border-color: var(--gold); }

.pet-head {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent);
  flex: 0 0 auto;
}
.pet-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  border: 2px solid var(--gold); object-fit: cover; flex: 0 0 auto;
  background: var(--bg2); display: flex; align-items: center; justify-content: center;
  font-size: 21px; overflow: hidden;
}
.pet-avatar img { width: 100%; height: 100%; object-fit: cover; }
.pet-meta { flex: 1 1 auto; min-width: 0; }
.pet-name { font-size: 15px; font-weight: 700; line-height: 1.25; }
.pet-sub { font-size: 11.5px; color: var(--mut); line-height: 1.3; }
.pet-head-btns { display: flex; gap: 6px; flex: 0 0 auto; }
.pet-icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--mut);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.pet-icon-btn:hover { color: var(--gold); border-color: var(--gold); }

/* 消息区 */
.pet-body {
  flex: 1 1 auto; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: thin;
}
.pet-body::-webkit-scrollbar { width: 7px; }
.pet-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.pet-msg { max-width: 88%; font-size: 13.5px; line-height: 1.68; white-space: pre-wrap; word-break: break-word; }
.pet-msg.u {
  align-self: flex-end; background: rgba(212,167,86,.15);
  border: 1px solid rgba(212,167,86,.3); color: var(--txt);
  padding: 9px 13px; border-radius: 12px 12px 3px 12px;
}
.pet-msg.a {
  align-self: flex-start; background: var(--bg2);
  border: 1px solid var(--line); color: var(--txt);
  padding: 9px 13px; border-radius: 12px 12px 12px 3px;
}
.pet-msg.sys { align-self: center; color: var(--mut); font-size: 12px; text-align: center; }
.pet-msg.err { align-self: flex-start; background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.35); color: #fca5a5; padding: 9px 13px; border-radius: 12px; }
.pet-msg b { color: var(--gold); }

/* 工具调用提示 */
.pet-tool {
  align-self: flex-start; font-size: 11.5px; color: var(--mut);
  background: rgba(255,255,255,.03); border: 1px dashed var(--line);
  padding: 4px 10px; border-radius: 8px;
}

/* 危险动作确认卡 */
.pet-confirm {
  align-self: stretch; background: rgba(239,68,68,.09);
  border: 1px solid rgba(239,68,68,.45); border-radius: 11px;
  padding: 12px 13px; font-size: 13px;
}
.pet-confirm .pc-title { font-weight: 700; color: #fca5a5; margin-bottom: 6px; font-size: 12.5px; }
.pet-confirm .pc-sum { color: var(--txt); margin-bottom: 4px; line-height: 1.6; }
.pet-confirm .pc-args {
  font-family: monospace; font-size: 11px; color: var(--mut);
  background: rgba(0,0,0,.28); padding: 6px 8px; border-radius: 6px;
  margin: 7px 0; max-height: 110px; overflow: auto; white-space: pre-wrap;
}
.pet-confirm .pc-btns { display: flex; gap: 8px; margin-top: 9px; }
.pet-confirm button {
  padding: 7px 15px; border-radius: 8px; font-size: 13px; cursor: pointer; font-weight: 600; border: none;
}
.pet-confirm .pc-yes { background: var(--red); color: #fff; }
.pet-confirm .pc-no { background: transparent; border: 1px solid var(--line); color: var(--mut); font-weight: 400; }

/* 输入区 */
.pet-foot {
  flex: 0 0 auto; padding: 10px 12px;
  border-top: 1px solid var(--line);
  display: flex; gap: 8px; align-items: flex-end;
  background: linear-gradient(0deg, rgba(255,255,255,.02), transparent);
}
.pet-foot textarea {
  flex: 1 1 auto; resize: none; background: var(--bg2);
  border: 1px solid var(--line); color: var(--txt);
  border-radius: 10px; padding: 9px 11px; font-size: 13.5px;
  font-family: inherit; line-height: 1.5; max-height: 108px; min-height: 38px;
}
.pet-foot textarea:focus { outline: none; border-color: var(--gold); }
.pet-send {
  background: var(--gold); border: none; color: #0b0f17; font-weight: 700;
  width: 40px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 15px;
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
}
.pet-send:disabled { opacity: .45; cursor: not-allowed; }

/* 快捷提问 */
.pet-quick { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px 9px; flex: 0 0 auto; }
.pet-quick button {
  background: transparent; border: 1px solid var(--line); color: var(--mut);
  font-size: 11.5px; padding: 4px 10px; border-radius: 20px; cursor: pointer;
}
.pet-quick button:hover { color: var(--gold); border-color: var(--gold); }

/* 宠物设置面板 */
.pet-settings { padding: 14px; overflow-y: auto; flex: 1 1 auto; }
.pet-settings h4 { margin: 0 0 10px; font-size: 14px; }
.pet-settings label { display: block; font-size: 12px; color: var(--mut); margin: 11px 0 4px; }
.pet-settings input, .pet-settings select {
  width: 100%; background: var(--bg2); border: 1px solid var(--line);
  color: var(--txt); padding: 8px 10px; border-radius: 8px; font-size: 13px;
}
.pet-settings .ps-note { font-size: 11.5px; color: var(--mut); line-height: 1.6; margin-top: 6px; }
.pet-settings .ps-row { display: flex; gap: 8px; margin-top: 14px; }
.pet-settings .ps-row button {
  padding: 8px 16px; border-radius: 8px; font-size: 13px; cursor: pointer; border: none;
  background: var(--gold); color: #0b0f17; font-weight: 700;
}
.pet-settings .ps-row button.ghost { background: transparent; border: 1px solid var(--line); color: var(--mut); font-weight: 400; }
.pet-status-pill {
  display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 20px;
  border: 1px solid var(--line); color: var(--mut); margin-left: 6px;
}
.pet-status-pill.ok { color: var(--green); border-color: rgba(34,197,94,.4); }
.pet-status-pill.bad { color: var(--red); border-color: rgba(239,68,68,.4); }

/* 移动端（2026-10-02 重写：可用 + 仍可调整大小） */
@media (max-width: 760px) {
  /* 悬浮球：手指友好，不挡内容 */
  .pet-ball { right: 12px; bottom: 12px; width: 58px; height: 58px; }

  /* 面板：默认接近全屏，但可拖动调整 */
  .pet-panel {
    right: 8px; left: 8px; bottom: 8px;
    width: auto;
    max-width: none;
    height: 72vh;
    max-height: calc(100vh - 90px);
    min-width: 0; min-height: 240px;
    border-radius: 16px;
  }
  /* 手机上不设 left+right 之外的宽度限制（可拖动改高度） */
  .pet-panel { width: calc(100vw - 16px); }

  /* 手柄命中区加大，方便手指拖 */
  .pet-rs-se, .pet-rs-sw, .pet-rs-ne, .pet-rs-nw { width: 26px; height: 26px; }
  .pet-rs-n, .pet-rs-s { height: 12px; }
  .pet-rs-w, .pet-rs-e { width: 12px; }
  .pet-rs-se::after { width: 12px; height: 12px; right: 5px; bottom: 5px; }

  /* 手机隐藏预设按钮，靠拖动调整 */
  .pet-size-row { display: none; }

  /* 头部与输入区（触摸友好） */
  .pet-head { padding: 11px 12px; gap: 9px; }
  .pet-avatar { width: 38px; height: 38px; }
  .pet-name { font-size: 14.5px; }
  .pet-sub { font-size: 11.5px; }
  .pet-icon-btn { width: 34px; height: 34px; font-size: 15px; }
  .pet-body { padding: 12px; gap: 9px; }
  .pet-foot { padding: 9px 10px; gap: 7px; }
  .pet-foot textarea { font-size: 16px; }   /* 防 iOS 聚焦放大 */
  .pet-send { width: 42px; height: 42px; }
  .pet-quick { padding: 8px 10px; }
  .pet-quick button { font-size: 12px; padding: 6px 10px; min-height: 34px; }
  .pet-msg { font-size: 14px; max-width: 88%; }

  /* 走路彩蛋小一点 */
  .pet-walker { width: 62px; height: 62px; bottom: 4px; }
}

@media (max-width: 420px) {
  .pet-ball { width: 54px; height: 54px; right: 10px; bottom: 10px; }
  .pet-panel { height: 76vh; }   /* 小屏给多一点 */
  .pet-msg { font-size: 13.5px; }
}

/* 横屏矮屏 */
@media (max-height: 520px) and (orientation: landscape) {
  .pet-panel { height: calc(100vh - 30px); max-height: none; }
  .pet-body { padding: 9px; }
}
