/* ============================================================
   楚河汉界 · 中国象棋 — 样式
   美学：中式木质棋盘 + 米色宣纸，朱砂红勾勒；暖色调，克制留白。
   ============================================================ */

:root {
  /* 纸张 / 背景 */
  --paper: #f6f0e3;
  --paper-2: #efe6d2;
  --paper-3: #e7dcc4;
  --card: #fcf8ef;
  --line: #d8c9a8;

  /* 木质棋盘 */
  --wood: #d9aa63;
  --wood-2: #c8944e;
  --wood-3: #b07f3c;
  --wood-line: #5f3f1d;
  --wood-glow: rgba(90, 55, 20, 0.18);

  /* 墨色与语义色 */
  --ink: #3a2a18;
  --ink-soft: #6b5a41;
  --ink-faint: #96856a;
  --red: #9c241c;
  --red-strong: #7c1c15;
  --black: #26201a;
  --gold: #b98a3e;
  --green: #3e7d4f;
  --danger: #9c241c;

  /* 尺寸 */
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(90, 62, 20, 0.10);
  --shadow-sm: 0 3px 12px rgba(90, 62, 20, 0.10);

  --font-display: "Kaiti SC", "STKaiti", "KaiTi", "FangSong", "STFangsong", serif;
  --font-body: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 50% -200px, rgba(185, 138, 62, 0.16), transparent 70%),
    repeating-linear-gradient(0deg, rgba(120, 90, 40, 0.020) 0 1px, transparent 1px 3px),
    var(--paper);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.02em;
}

/* ---------- 顶部 ---------- */
.topbar {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(252, 248, 239, 0.94), rgba(246, 240, 227, 0.9));
  backdrop-filter: blur(4px);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #c0392b, var(--red-strong));
  color: #fdf6ec;
  font-family: var(--font-display);
  font-size: 24px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(255, 244, 224, 0.55), var(--shadow-sm);
}
.brand-text h1 {
  font-size: 22px;
  color: var(--red-strong);
  line-height: 1.1;
}
.brand-sub {
  font-size: 12px;
  color: var(--ink-faint);
  letter-spacing: 0.12em;
}
.topbar-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--ink-soft);
}
.conn-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #c9a86a;
  display: inline-block;
}
.conn-dot.on { background: #3e8e5a; box-shadow: 0 0 0 3px rgba(62, 142, 90, 0.18); }
.conn-dot.off { background: #b2433a; box-shadow: 0 0 0 3px rgba(178, 67, 58, 0.16); }

/* ---------- 布局 ---------- */
.view {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}
#lobbyView {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}
#gameView {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 960px) {
  #lobbyView, #gameView { grid-template-columns: 1fr; }
  .online-panel { order: 2; }
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 19px; color: var(--red-strong); }
.panel-head h3 { font-size: 16px; color: var(--ink); }

.lobby-panel { min-height: 420px; }
.online-panel { position: sticky; top: 80px; }

/* ---------- 按钮 ---------- */
.btn {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
  min-height: 40px;
}
.btn:hover:not(:disabled) { background: var(--paper-3); border-color: #c3b192; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active:not(:disabled) { transform: translateY(0); box-shadow: none; }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, #b33a2e, var(--red-strong));
  border-color: #6f160f;
  color: #fdf3e4;
}
.btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, #c14133, #8c231b); border-color: #6f160f; }
.btn-ghost { background: transparent; }
.btn-small { padding: 6px 12px; font-size: 13px; min-height: 34px; }
.btn-block { width: 100%; }

/* ---------- 创建房间 ---------- */
.create-form {
  padding: 14px 16px;
  border-bottom: 1px dashed var(--line);
  background: var(--paper-2);
}
.create-form label { font-size: 13px; color: var(--ink-soft); display: block; margin-bottom: 8px; }
.create-row { display: flex; gap: 8px; flex-wrap: wrap; }
#roomNameInput { flex: 1; min-width: 160px; }

/* ---------- 输入框 ---------- */
input[type="text"] {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fffdf6;
  color: var(--ink);
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(185, 138, 62, 0.18);
}

/* ---------- 房间列表 ---------- */
.room-list { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.room-card {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffdf6;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.room-card:hover { box-shadow: var(--shadow-sm); border-color: #c3b192; }
.room-info { min-width: 0; }
.room-name { font-family: var(--font-display); font-size: 17px; color: var(--ink); }
.room-seats { font-size: 13px; color: var(--ink-soft); margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.seat { padding: 3px 8px; border-radius: 999px; background: var(--paper-2); color: var(--ink-soft); }
.seat.filled-red { background: rgba(156, 36, 28, 0.10); color: var(--red-strong); }
.seat.filled-black { background: rgba(38, 32, 26, 0.08); color: var(--black); }
.seat.idle { color: var(--ink-faint); }
.room-status {
  font-size: 12px; color: var(--ink-faint);
  display: inline-flex; align-items: center; gap: 5px;
}
.room-status.live { color: var(--green); }
.room-status.ended { color: var(--ink-faint); }
.spectator-count { font-size: 12px; color: var(--ink-faint); }

/* ---------- 在线列表 ---------- */
.online-list { list-style: none; margin: 0; padding: 12px 14px; max-height: 60vh; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.online-list li {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; padding: 5px 8px; border-radius: 8px;
}
.online-list li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #5aa273; flex: none; }
.online-list .me { background: rgba(185, 138, 62, 0.12); }
.badge {
  background: var(--paper-2); color: var(--ink-soft);
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
}

/* ---------- 对局布局 ---------- */
.game-stage { display: flex; justify-content: center; }
.board-wrap {
  max-width: 660px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.board {
  width: 100%;
  aspect-ratio: 9 / 10;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 22px 50px rgba(90, 62, 20, 0.28), inset 0 0 0 1px rgba(255, 244, 224, 0.25);
  background: var(--wood);
  touch-action: manipulation;
}
.board svg { display: block; width: 100%; height: 100%; }
.board-status {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--red-strong);
  text-align: center;
  min-height: 28px;
}

.game-side { display: flex; flex-direction: column; gap: 14px; }
.side-card { padding: 0; overflow: hidden; }
.side-card.grow { display: flex; flex-direction: column; min-height: 220px; }
.room-title-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.game-room-name { font-size: 18px; color: var(--red-strong); word-break: break-all; }

.players { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.player {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-radius: var(--radius-sm); background: var(--paper-2);
}
.piece-dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.piece-dot.red { background: radial-gradient(circle at 35% 30%, #d4523f, #9c241c); border-color: #6f160f; }
.piece-dot.black { background: radial-gradient(circle at 35% 30%, #54483a, #26201a); border-color: #100d09; }
.player-name { flex: 1; font-size: 14px; color: var(--ink); }
.turn-tag {
  font-size: 12px; color: var(--red-strong); background: rgba(156, 36, 28, 0.10);
  padding: 3px 8px; border-radius: 999px; font-style: normal;
}

.action-row { display: flex; gap: 8px; padding: 0 16px 14px; flex-wrap: wrap; }

/* ---------- 行棋日志 ---------- */
.move-log {
  list-style: none; margin: 0; padding: 12px 16px;
  max-height: 240px; overflow: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.move-log li {
  font-size: 13px; color: var(--ink-soft);
  padding: 4px 6px; border-radius: 6px;
  display: flex; gap: 8px; align-items: baseline;
}
.move-log li:nth-child(even) { background: rgba(120, 90, 40, 0.04); }
.move-log .mv-n { color: var(--ink-faint); font-size: 11px; flex: none; width: 30px; text-align: right; }
.move-log .mv-text { flex: 1; }
.move-log .mv-text.red { color: var(--red-strong); }
.move-log .check { color: var(--red-strong); font-weight: 600; }

/* ---------- 观战 / 聊天 ---------- */
.spectators { padding: 10px 16px 2px; font-size: 12px; color: var(--ink-faint); min-height: 20px; }
.chat-log {
  padding: 8px 16px; max-height: 180px; overflow: auto;
  display: flex; flex-direction: column; gap: 6px;
}
.chat-msg { font-size: 13px; }
.chat-msg .who { color: var(--ink-faint); font-size: 12px; }
.chat-msg.me .who { color: var(--gold); }
.chat-form { display: flex; gap: 8px; padding: 8px 16px 14px; }
.chat-form input { flex: 1; min-width: 0; }

/* ---------- 弹窗 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(58, 42, 24, 0.38);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(420px, 100%);
  padding: 28px 24px;
  text-align: center;
}
.modal-mark {
  width: 58px; height: 58px; margin: 0 auto 12px;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #c0392b, var(--red-strong));
  color: #fdf6ec; font-family: var(--font-display); font-size: 32px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 3px rgba(255, 244, 224, 0.55), var(--shadow);
}
.modal h2 { font-size: 24px; color: var(--red-strong); }
.modal-sub { font-size: 13px; color: var(--ink-soft); margin: 8px 0 18px; line-height: 1.7; }
.modal form { display: flex; flex-direction: column; gap: 10px; }
.modal-foot { font-size: 12px; color: var(--danger); min-height: 16px; }

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: var(--ink); color: #f6f0e3;
  padding: 11px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow);
  z-index: 60; max-width: 80vw; text-align: center;
}
.toast[hidden] { display: none; }

/* ---------- 通用 ---------- */
.empty-hint {
  color: var(--ink-faint); font-size: 14px; text-align: center;
  padding: 40px 0;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; clip-path: inset(50%);
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}