/* ============================================================
   实时聊天 + 手绘小丑表情浮层（右下角条带；DOM 挂 body，跨屏常驻）
   z-index：FAB 900（高于对局 UI / pixi-fx 250，低于 info-overlay 1500、tooltip 1000）
            panel 1400（低于 info-overlay，说明弹窗在其上合理）；均 < rotate-overlay 2000
   ============================================================ */

/* —— 折叠 FAB —— */
.chat-fab {
  position: fixed;
  right: calc(var(--sa-right, 0px) + 12px);
  bottom: calc(var(--sa-bottom, 0px) + 12px);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  z-index: 900;
  padding: 8px;
  cursor: pointer;
  color: var(--accent-gold);
  background: var(--bg-panel-deep);
  border: 2px solid var(--accent-gold-border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45), 0 0 14px var(--accent-gold-glow);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: transform 0.15s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), 0 0 20px var(--accent-gold-glow); }
.chat-fab:active { transform: scale(0.94); }
.chat-fab svg { width: 100%; height: 100%; display: block; }
/* 拖拽到自定义位置后覆盖默认 right/bottom 定位 */
.chat-fab.chat-fab-custom-pos {
  right: auto;
  bottom: auto;
  touch-action: none; /* 拖拽模式下禁止浏览器手势 */
}

/* 对局/商店仍固定在安全区内；不能用负 bottom 把按钮推到屏幕外。 */
body.in-game .chat-fab {
  width: 44px; height: 44px; padding: 6px;
  bottom: calc(var(--sa-bottom, 0px) + 12px);
}
/* 自定义位置时不覆盖用户拖拽位置 */
body.in-game .chat-fab.chat-fab-custom-pos {
  bottom: auto;
}
body.in-game .chat-panel {
  bottom: calc(var(--sa-bottom, 0px) + 64px);
}

.chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #e0454a;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  line-height: 18px;
  text-align: center;
  border: 1.5px solid var(--bg-panel-deep);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.chat-badge[hidden] { display: none; }

/* —— 展开面板（默认隐藏，.open 显示）—— */
.chat-panel {
  position: fixed;
  right: calc(var(--sa-right, 0px) + 12px);
  bottom: calc(var(--sa-bottom, 0px) + 72px);
  width: 300px;
  max-width: calc(100vw - 24px);
  max-height: min(64vh, 460px);
  z-index: 1400;
  display: none;
  flex-direction: column;
  background: var(--bg-panel-deep);
  border: 1.5px solid var(--accent-gold-border);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 24px var(--accent-gold-glow);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  overflow: hidden;
}
.chat-panel.open { display: flex; }

.chat-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--border-panel);
}
.chat-title { font-size: 14px; font-weight: 800; color: var(--accent-gold); letter-spacing: 1px; }
.chat-close {
  width: 26px; height: 26px;
  border: none; border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  font-size: 20px; line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}
.chat-close:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }

/* —— 消息列表 —— */
.chat-msgs {
  flex: 1 1 auto;
  min-height: 80px;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msgs::-webkit-scrollbar { width: 6px; }
.chat-msgs::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.18); border-radius: 3px; }

.chat-msg { display: flex; flex-direction: column; max-width: 82%; }
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-msg.theirs { align-self: flex-start; align-items: flex-start; }
.chat-name { font-size: 10px; color: var(--text-primary); opacity: 0.55; margin: 0 4px 2px; }

.chat-bubble {
  padding: 7px 11px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-primary);
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}
.chat-msg.theirs .chat-bubble {
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--border-panel);
  border-bottom-left-radius: 4px;
}
.chat-msg.mine .chat-bubble {
  background: var(--accent-gold-bg);
  border: 1px solid var(--accent-gold-border);
  border-bottom-right-radius: 4px;
}
/* 表情气泡：透明背景、放大 SVG */
.chat-bubble-sticker {
  background: transparent !important;
  border: none !important;
  padding: 2px !important;
  color: var(--accent-gold);
}
.chat-bubble-sticker .chat-sticker-art { width: 56px; height: 56px; display: block; }

/* —— 表情快捷栏 —— */
.chat-stickers {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 10px;
  border-top: 1px solid var(--border-panel);
  background: rgba(0, 0, 0, 0.18);
}
.chat-sticker {
  width: 36px; height: 36px;
  padding: 3px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}
.chat-sticker:hover { background: rgba(255, 255, 255, 0.08); border-color: var(--accent-gold-border); transform: translateY(-1px); }
.chat-sticker:active { transform: scale(0.9); }
.chat-sticker .chat-sticker-art { width: 100%; height: 100%; display: block; }

/* —— 输入行 —— */
.chat-input-row {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 8px 10px calc(8px + max(0px, var(--sa-bottom) * 0));
  border-top: 1px solid var(--border-panel);
}
.chat-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border-panel);
  border-radius: 8px;
  outline: none;
}
.chat-input:focus { border-color: var(--accent-gold-border); }
.chat-send-btn {
  flex: 0 0 auto;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 800;
  color: #1a1208;
  background: var(--accent-gold);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.chat-send-btn:hover { filter: brightness(1.08); }
.chat-send-btn:active { transform: scale(0.96); }

/* —— 移动端横屏：限高、靠右、不遮中央出牌区；软键盘弹出时 dvh 收缩面板自然上移 —— */
@media (max-height: 500px) and (orientation: landscape) {
  .chat-fab { width: 44px; height: 44px; padding: 6px; right: calc(var(--sa-right, 0px) + 8px); bottom: calc(var(--sa-bottom, 0px) + 8px); }
  .chat-panel {
    width: min(300px, 80vw);
    right: calc(var(--sa-right, 0px) + 8px);
    bottom: calc(var(--sa-bottom, 0px) + 60px);
    max-height: calc(100dvh - max(16px, var(--sa-top)) - max(16px, var(--sa-bottom)) - 60px);
  }
  .chat-bubble-sticker .chat-sticker-art { width: 46px; height: 46px; }
}
