/* ===== 中国象棋 — 传统木纹风格 ===== */

:root {
  /* 由 JS 按窗口大小实时写入 */
  --cell: 60px;
  --margin: 38px;
  --piece: 53px;
  --board-w: 556px;
  --board-h: 616px;

  --ink: #4a2f18;
  --red-ink: #b1352a;
  --black-ink: #23201d;
  --wood-dark: #6b4423;

  --bg-1: #241c15;
  --bg-2: #38291c;
  --panel: rgba(255, 250, 240, 0.055);
  --panel-line: rgba(232, 200, 150, 0.16);
  --text: #f0e4d2;
  --text-dim: #b09d84;
  --gold: #e2b552;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #4a3524 0%, transparent 60%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 18px clamp(14px, 3vw, 36px) 26px;
  gap: 16px;
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-family: "Kaiti SC", "STKaiti", KaiTi, "楷体", serif;
  font-size: clamp(22px, 2.4vw, 30px);
  font-weight: 600;
  letter-spacing: 0.22em;
  color: var(--gold);
  text-shadow: 0 2px 12px rgba(226, 181, 82, 0.28);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.field {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-dim);
}

select, .btn, .icon-btn {
  font-family: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, transform 0.1s;
}

select:hover, .btn:hover, .icon-btn:hover {
  background: rgba(255, 250, 240, 0.11);
  border-color: rgba(232, 200, 150, 0.34);
}

.btn:active { transform: translateY(1px); }

.btn:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(190, 60, 46, 0.24);
  border-color: rgba(220, 90, 74, 0.5);
}

.icon-btn { padding: 7px 10px; font-size: 15px; line-height: 1; }
.icon-btn[aria-pressed="false"] { opacity: 0.45; }

/* ---------- 主体布局 ---------- */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: clamp(16px, 2.5vw, 34px);
  align-items: flex-start;
  justify-content: center;
}

.board-area { flex: 0 0 auto; min-width: 0; max-width: 100%; }

.sidebar {
  flex: 0 0 300px;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: stretch;
  /* 与棋盘等高封顶：否则棋谱一长，侧栏会把整页撑出滚动条，
     棋谱面板也不会在自己内部滚动 */
  max-height: var(--board-h);
}

/* 翻转棋盘时，侧栏上下两个玩家面板也要跟着对调，
   面板的上下关系才和棋盘上双方的位置对得上 */
#panelBlack { order: 1; }
.status     { order: 2; }
.side-panel { order: 3; }
#panelRed   { order: 4; }
.controls   { order: 5; }
#btnOffline { order: 6; }
.hint       { order: 7; }
.sidebar.flipped #panelBlack { order: 4; }
.sidebar.flipped #panelRed   { order: 1; }

/* ---------- 棋盘 ---------- */

.board-wrap {
  position: relative;
  width: var(--board-w);
  height: var(--board-h);
  max-width: 100%;
  max-width: 100%;
  border-radius: 10px;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.55),
    0 3px 10px rgba(0, 0, 0, 0.4),
    inset 0 0 0 1px rgba(90, 55, 25, 0.5);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.board-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  display: block;
}

.layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ---------- 棋子 ---------- */

.piece {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--piece);
  height: var(--piece);
  margin-left: calc(var(--piece) / -2);
  margin-top: calc(var(--piece) / -2);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: "Kaiti SC", "STKaiti", KaiTi, "楷体", "Songti SC", serif;
  font-size: calc(var(--piece) * 0.6);
  font-weight: 700;
  line-height: 1;
  will-change: transform;
  transition: transform 0.24s var(--ease), filter 0.16s, opacity 0.2s;

  /* 木质圆饼：外圈渐变 + 立体投影 */
  background:
    radial-gradient(circle at 34% 28%, #fdf3dc 0%, #f0dcb3 38%, #ddbe8a 70%, #c9a271 100%);
  box-shadow:
    0 3px 5px rgba(0, 0, 0, 0.42),
    0 1px 2px rgba(0, 0, 0, 0.3),
    inset 0 -2px 4px rgba(140, 96, 48, 0.4),
    inset 0 2px 3px rgba(255, 255, 255, 0.7);
}

/* 内圈刻线 */
.piece::before {
  content: "";
  position: absolute;
  inset: calc(var(--piece) * 0.085);
  border-radius: 50%;
  border: calc(var(--piece) * 0.032) solid currentColor;
  opacity: 0.85;
}

.piece span {
  position: relative;
  transform: translateY(2%);
}

.piece.red { color: var(--red-ink); }
.piece.black { color: var(--black-ink); }

.piece.movable:hover {
  filter: brightness(1.07);
}

/* 选中：金色光环 + 上浮 */
.piece.selected {
  box-shadow:
    0 0 0 4px rgba(240, 194, 90, 1),
    0 0 22px 6px rgba(226, 181, 82, 0.7),
    0 7px 12px rgba(0, 0, 0, 0.45),
    inset 0 -2px 4px rgba(140, 96, 48, 0.4),
    inset 0 2px 3px rgba(255, 255, 255, 0.7);
  z-index: 6;
}

/* 被将军的将/帅 */
.piece.in-check {
  animation: check-pulse 0.85s ease-in-out infinite;
  z-index: 5;
}

@keyframes check-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(226, 74, 58, 0.9), 0 0 12px 2px rgba(226, 74, 58, 0.5), 0 3px 5px rgba(0,0,0,0.42); }
  50%      { box-shadow: 0 0 0 5px rgba(226, 74, 58, 0.95), 0 0 26px 8px rgba(226, 74, 58, 0.75), 0 3px 5px rgba(0,0,0,0.42); }
}

/* 被吃：缩小淡出 */
.piece.captured {
  opacity: 0;
  z-index: 1;
  transition: transform 0.3s ease-in, opacity 0.3s ease-in;
}

/* 无效点击时抖一下 */
.piece.shake { animation: shake 0.32s; }

@keyframes shake {
  0%, 100% { margin-left: calc(var(--piece) / -2); }
  20% { margin-left: calc(var(--piece) / -2 - 5px); }
  50% { margin-left: calc(var(--piece) / -2 + 5px); }
  80% { margin-left: calc(var(--piece) / -2 - 3px); }
}

/* 回看历史时关闭全部动画 */
.no-anim .piece { transition: none !important; }

/* ---------- 标记层 ---------- */

.marker {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

/* 可走的空位：半透明圆点 */
.marker.dot {
  width: calc(var(--cell) * 0.28);
  height: calc(var(--cell) * 0.28);
  margin-left: calc(var(--cell) * -0.14);
  margin-top: calc(var(--cell) * -0.14);
  /* left/top 由 JS 写入 */
  border-radius: 50%;
  background: rgba(60, 130, 70, 0.55);
  box-shadow: 0 0 8px rgba(60, 130, 70, 0.5);
  animation: pop-in 0.18s var(--ease) backwards;
}

/* 可吃的目标：套在敌方棋子外面的一圈红光（必须比棋子大，否则会被棋子完全盖住） */
.marker.ring {
  width: calc(var(--cell) * 1.08);
  height: calc(var(--cell) * 1.08);
  margin-left: calc(var(--cell) * -0.54);
  margin-top: calc(var(--cell) * -0.54);
  border-radius: 50%;
  border: calc(var(--cell) * 0.055) solid rgba(206, 48, 36, 0.92);
  box-shadow: 0 0 14px rgba(206, 48, 36, 0.6), inset 0 0 12px rgba(206, 48, 36, 0.35);
  animation: pop-in 0.18s var(--ease) backwards;
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.4); }
}

/* 上一步的起点/终点：露在棋子外面的四个金色角标 */
.marker.last {
  width: calc(var(--cell) * 1.04);
  height: calc(var(--cell) * 1.04);
  margin-left: calc(var(--cell) * -0.52);
  margin-top: calc(var(--cell) * -0.52);
  border: calc(var(--cell) * 0.042) solid rgba(232, 176, 64, 0.95);
  border-radius: 4px;
  opacity: 1;
  filter: drop-shadow(0 0 3px rgba(232, 176, 64, 0.45));
  -webkit-mask:
    linear-gradient(#000 0 0) top left    / 30% 30% no-repeat,
    linear-gradient(#000 0 0) top right   / 30% 30% no-repeat,
    linear-gradient(#000 0 0) bottom left / 30% 30% no-repeat,
    linear-gradient(#000 0 0) bottom right/ 30% 30% no-repeat;
          mask:
    linear-gradient(#000 0 0) top left    / 30% 30% no-repeat,
    linear-gradient(#000 0 0) top right   / 30% 30% no-repeat,
    linear-gradient(#000 0 0) bottom left / 30% 30% no-repeat,
    linear-gradient(#000 0 0) bottom right/ 30% 30% no-repeat;
}

/* ---------- 侧栏面板 ---------- */

.player-panel {
  flex: 0 0 auto;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  padding: 11px 13px;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.player-panel.active {
  border-color: rgba(226, 181, 82, 0.55);
  background: rgba(226, 181, 82, 0.09);
  box-shadow: 0 0 0 1px rgba(226, 181, 82, 0.16), 0 4px 18px rgba(226, 181, 82, 0.09);
}

.player-head {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
}

.player-name { font-weight: 600; letter-spacing: 0.06em; }

.side-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.5);
}
.side-dot.red { background: #c8402f; }
.side-dot.black { background: #2b2723; border: 1px solid #6d6459; }

.clock {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 16px;
  color: var(--text-dim);
  transition: color 0.2s;
}
.player-panel.active .clock { color: var(--text); }
.clock.urgent { color: #ff7a68; animation: blink 1s steps(2, end) infinite; }

@keyframes blink { 50% { opacity: 0.35; } }

.captured {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 8px;
  min-height: 22px;
}
.captured:empty::after {
  content: "暂无战果";
  font-size: 11px;
  color: rgba(176, 157, 132, 0.5);
}

.cap {
  width: 21px;
  height: 21px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: "Kaiti SC", "STKaiti", KaiTi, serif;
  font-size: 13px;
  font-weight: 700;
  background: linear-gradient(160deg, #f3e2c0, #d5b384);
  box-shadow: 0 1px 2px rgba(0,0,0,0.35);
  animation: pop-in-cap 0.28s var(--ease) backwards;
}
.cap.red { color: var(--red-ink); }
.cap.black { color: var(--black-ink); }

@keyframes pop-in-cap { from { opacity: 0; transform: scale(0.3); } }

/* ---------- 状态条 ---------- */

.status {
  flex: 0 0 auto;
  text-align: center;
  padding: 11px 12px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.05em;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  transition: all 0.2s;
}
.status.check {
  background: rgba(200, 52, 40, 0.18);
  border-color: rgba(226, 74, 58, 0.55);
  color: #ffb3a6;
}
.status.over {
  background: rgba(226, 181, 82, 0.16);
  border-color: rgba(226, 181, 82, 0.5);
  color: var(--gold);
}
.status.review {
  background: rgba(90, 130, 200, 0.16);
  border-color: rgba(120, 160, 220, 0.5);
  color: #b6cdf2;
}

/* ---------- 棋谱 ---------- */

.side-panel {
  flex: 1 1 0;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  overflow: hidden;
}

.moves-head {
  display: grid;
  grid-template-columns: 44px 1fr 1fr;
  padding: 8px 12px;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--panel-line);
  background: rgba(0, 0, 0, 0.14);
}

.moves-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(226, 181, 82, 0.3) transparent;
}
.moves-scroll::-webkit-scrollbar { width: 7px; }
.moves-scroll::-webkit-scrollbar-thumb {
  background: rgba(226, 181, 82, 0.28);
  border-radius: 4px;
}

.move-row {
  display: grid;
  grid-template-columns: 44px 1fr 1fr;
  padding: 1px 12px;
  font-size: 13.5px;
  align-items: center;
}
.move-row:nth-child(odd) { background: rgba(255, 255, 255, 0.022); }
.move-no { color: var(--text-dim); font-size: 12px; }

.ply {
  padding: 4px 7px;
  border-radius: 6px;
  cursor: pointer;
  font-family: "Kaiti SC", "STKaiti", KaiTi, serif;
  font-size: 14.5px;
  letter-spacing: 0.04em;
  transition: background 0.13s, color 0.13s;
}
.ply:hover { background: rgba(255, 255, 255, 0.1); }
.ply.red { color: #f0a396; }
.ply.black { color: #cfe0ef; }
.ply.current {
  background: rgba(226, 181, 82, 0.24);
  box-shadow: inset 0 0 0 1px rgba(226, 181, 82, 0.5);
}
.ply.empty { cursor: default; }
.ply.empty:hover { background: none; }

.moves:empty::after {
  content: "尚未落子";
  display: block;
  text-align: center;
  padding: 26px 0;
  font-size: 12.5px;
  color: rgba(176, 157, 132, 0.55);
}

.back-live {
  border: none;
  border-top: 1px solid var(--panel-line);
  background: rgba(120, 160, 220, 0.16);
  color: #b6cdf2;
  padding: 9px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.back-live:hover { background: rgba(120, 160, 220, 0.26); }

/* ---------- 控制区 ---------- */

.controls {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.controls .btn { padding: 10px 6px; font-size: 13.5px; }

.hint {
  flex: 0 0 auto;
  margin: 0;
  text-align: center;
  font-size: 11px;
  color: rgba(176, 157, 132, 0.65);
  line-height: 1.7;
}
kbd {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 4px;
  padding: 1px 4px;
}

/* ---------- 对话框 ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 8, 5, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: grid;
  place-items: center;
  z-index: 50;
  animation: fade-in 0.2s;
}
.modal-backdrop.hidden { display: none; }

@keyframes fade-in { from { opacity: 0; } }

.modal {
  width: min(370px, 88vw);
  background: linear-gradient(165deg, #3c2c1e, #2a1f16);
  border: 1px solid rgba(226, 181, 82, 0.32);
  border-radius: 16px;
  padding: 26px 26px 20px;
  text-align: center;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.65);
  animation: rise 0.26s var(--ease);
}

@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(0.96); } }

.modal-icon { font-size: 40px; line-height: 1; margin-bottom: 8px; }
.modal-icon:empty { display: none; }

.modal h2 {
  margin: 0 0 8px;
  font-family: "Kaiti SC", "STKaiti", KaiTi, serif;
  font-size: 24px;
  letter-spacing: 0.1em;
  color: var(--gold);
}
.modal p { margin: 0 0 20px; font-size: 14px; color: var(--text-dim); line-height: 1.6; }

.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions .btn { min-width: 92px; padding: 10px 16px; }
.modal-actions .btn.primary {
  background: rgba(226, 181, 82, 0.9);
  border-color: rgba(226, 181, 82, 0.9);
  color: #2a1f16;
  font-weight: 600;
}
.modal-actions .btn.primary:hover { background: var(--gold); }

.hidden { display: none !important; }

/* ---------- 窄屏 ---------- */

@media (max-width: 900px) {
  .main { flex-direction: column; align-items: center; }
  .sidebar { flex: 1 1 auto; width: var(--board-w); max-width: 100%; max-height: none; }
  .side-panel { min-height: 150px; max-height: 260px; }
}

/* ═══════════════ 联机相关 ═══════════════ */

/* ---------- 移动端触摸 ---------- */

body {
  -webkit-touch-callout: none;              /* 长按不弹系统菜单 */
  -webkit-tap-highlight-color: transparent; /* 点击不闪蓝框 */
  overscroll-behavior: none;                /* 不触发下拉刷新 */
}

.app {
  padding-top: max(18px, env(safe-area-inset-top));
  padding-bottom: max(26px, env(safe-area-inset-bottom));
}

@media (pointer: coarse) {
  .btn, .icon-btn, select { min-height: 44px; }   /* 手指够得着 */
  .tab { min-height: 42px; }
  .ply { padding: 7px 8px; }
}

/* ---------- 开场页 ---------- */

.lobby {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background:
    radial-gradient(1200px 700px at 50% -10%, #4a3524 0%, transparent 60%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
}

.lobby-card { width: min(430px, 100%); }

.lobby-title {
  margin: 0 0 6px;
  text-align: center;
  font-family: "Kaiti SC", "STKaiti", KaiTi, "楷体", serif;
  font-size: clamp(30px, 8vw, 40px);
  font-weight: 600;
  letter-spacing: 0.26em;
  text-indent: 0.26em;
  color: var(--gold);
  text-shadow: 0 2px 16px rgba(226, 181, 82, 0.3);
}

.lobby-sub {
  margin: 0 0 22px;
  text-align: center;
  font-size: 13.5px;
  color: var(--text-dim);
}

.lobby-btn {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  padding: 15px 18px;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, transform 0.1s;
}
.lobby-btn:hover { background: rgba(255, 250, 240, 0.1); border-color: rgba(232, 200, 150, 0.34); }
.lobby-btn:active { transform: translateY(1px); }
.lobby-btn.primary {
  background: rgba(226, 181, 82, 0.16);
  border-color: rgba(226, 181, 82, 0.5);
}
.lobby-btn.primary:hover { background: rgba(226, 181, 82, 0.24); }
.lobby-btn[disabled] { opacity: 0.5; cursor: default; }

.lobby-btn-main { display: block; font-size: 16px; font-weight: 600; letter-spacing: 0.05em; }
.lobby-btn-sub { display: block; margin-top: 3px; font-size: 12px; color: var(--text-dim); }

.lobby-join { display: flex; gap: 8px; margin-bottom: 16px; }
.lobby-join input {
  flex: 1;
  min-width: 0;
  padding: 13px 16px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 18px;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
  color: var(--text);
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
}
.lobby-join input::placeholder { letter-spacing: 0.1em; font-size: 14px; color: rgba(176, 157, 132, 0.5); }
.lobby-join input:focus { outline: none; border-color: rgba(226, 181, 82, 0.5); }
.lobby-join .btn { padding: 0 20px; }

.lobby-options { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

.lobby-note {
  margin: 16px 0 0;
  min-height: 18px;
  text-align: center;
  font-size: 12.5px;
  line-height: 1.6;
  color: #ff9c8c;
}
.lobby-note.info { color: var(--text-dim); }

/* ---------- 房间栏与连接状态 ---------- */

.room-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 8px 5px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: #7d7166;
  transition: background 0.2s;
}
.conn-dot[data-status="online"]     { background: #4caf72; box-shadow: 0 0 7px rgba(76, 175, 114, 0.85); }
.conn-dot[data-status="connecting"] { background: var(--gold); animation: blink 1s steps(2, end) infinite; }
.conn-dot[data-status="offline"]    { background: #d9503f; animation: blink 1s steps(2, end) infinite; }

.room-code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--gold);
}

#btnCopyLink { padding: 6px 11px; font-size: 12px; }

/* ---------- 座位标记 ---------- */

.seat-tag {
  padding: 1px 7px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--gold);
  background: rgba(226, 181, 82, 0.2);
  border: 1px solid rgba(226, 181, 82, 0.42);
  border-radius: 999px;
}
.player-panel.away .player-name { opacity: 0.5; }
.player-panel.away::after {
  content: "已离线";
  float: right;
  font-size: 10.5px;
  color: #ffab9c;
}

/* ---------- 标签页 ---------- */

.tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.14);
  border-bottom: 1px solid var(--panel-line);
}

.tab {
  flex: 1;
  position: relative;
  padding: 9px 4px;
  font-family: inherit;
  font-size: 12.5px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s, box-shadow 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--gold); box-shadow: inset 0 -2px 0 var(--gold); }

.badge {
  display: inline-block;
  min-width: 16px;
  margin-left: 5px;
  padding: 0 4px;
  font-size: 10px;
  line-height: 16px;
  color: #2a1f16;
  background: var(--gold);
  border-radius: 999px;
}

.tab-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---------- 聊天 ---------- */

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(226, 181, 82, 0.3) transparent;
}
.chat-scroll::-webkit-scrollbar { width: 7px; }
.chat-scroll::-webkit-scrollbar-thumb { background: rgba(226, 181, 82, 0.28); border-radius: 4px; }

.chat-scroll:empty::after {
  content: "还没有消息";
  margin: auto;
  font-size: 12.5px;
  color: rgba(176, 157, 132, 0.5);
}

.chat-msg {
  max-width: 86%;
  padding: 7px 11px;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 12px;
  word-break: break-word;
  animation: pop-in-cap 0.2s var(--ease) backwards;
}
.chat-msg.me   { align-self: flex-end;   background: rgba(226, 181, 82, 0.2); border: 1px solid rgba(226, 181, 82, 0.28); }
.chat-msg.them { align-self: flex-start; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--panel-line); }

.chat-form { display: flex; gap: 7px; padding: 8px; border-top: 1px solid var(--panel-line); }
.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--panel-line);
  border-radius: 9px;
}
.chat-form input:focus { outline: none; border-color: rgba(226, 181, 82, 0.45); }
.chat-form .btn { padding: 9px 14px; }

/* ---------- 次要文字按钮 ---------- */

.link-btn {
  flex: 0 0 auto;
  padding: 3px;
  font-family: inherit;
  font-size: 11.5px;
  color: var(--text-dim);
  background: none;
  border: none;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-btn:hover { color: var(--gold); }

/* ---------- 浮动提示 ---------- */

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 70;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  max-width: min(420px, 90vw);
  padding: 10px 18px;
  font-size: 13px;
  text-align: center;
  color: var(--text);
  background: rgba(32, 22, 14, 0.96);
  border: 1px solid rgba(226, 181, 82, 0.35);
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s var(--ease);
}
.toast.leaving { animation: toast-out 0.3s ease-in forwards; }

@keyframes toast-in  { from { opacity: 0; transform: translateY(14px); } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(10px); } }

/* ---------- 对话框里的额外内容（着法码等） ---------- */

.modal-body { margin: 0 0 18px; text-align: left; }
.modal-body:empty { display: none; }

.code-label { margin: 0 0 6px; font-size: 12px; color: var(--text-dim); }
.code-row { display: flex; gap: 8px; margin-bottom: 14px; }
.code-row:last-child { margin-bottom: 0; }

.code-box {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 15px;
  letter-spacing: 0.12em;
  text-align: center;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--panel-line);
  border-radius: 9px;
}
.code-box:focus { outline: none; border-color: rgba(226, 181, 82, 0.5); }
textarea.code-box {
  text-align: left;
  letter-spacing: 0;
  font-size: 12.5px;
  line-height: 1.6;
  min-height: 72px;
  resize: vertical;
}

/* ---------- 窄屏补充 ---------- */

@media (max-width: 900px) {
  .topbar { gap: 10px; }
  .room-bar { order: 3; width: 100%; justify-content: center; }
  .controls { grid-template-columns: repeat(2, 1fr); }
}
