/* ══════════════════════════════════════════════════════════
   五子棋 · 联机对弈   样式表
   配色：深色为主（木枰 + 暖色高光），light 主题用 data-theme 切换
   ══════════════════════════════════════════════════════════ */

:root {
  --bg: #10151b;
  --bg-2: #151c24;
  --panel: #1a222c;
  --panel-2: #202a35;
  --line: #2b3744;
  --line-soft: #232e3a;
  --text: #e8edf2;
  --text-2: #9aa8b6;
  --text-3: #6b7a89;
  --accent: #d9a05b;
  --accent-2: #e8b878;
  --accent-ink: #241a0d;
  --ok: #5fbf8f;
  --warn: #e8b878;
  --danger: #e0705f;
  --wood: #c8934f;
  --wood-2: #b9823f;
  --shadow: 0 12px 32px rgba(0, 0, 0, .42);
  --radius: 14px;
  --radius-sm: 9px;
}

[data-theme="light"] {
  --bg: #f3eee6;
  --bg-2: #ebe4d9;
  --panel: #fffdf9;
  --panel-2: #f7f2e9;
  --line: #e0d6c6;
  --line-soft: #ece4d6;
  --text: #23201b;
  --text-2: #6d6459;
  --text-3: #9a9084;
  --accent: #b4793a;
  --accent-2: #c98f4c;
  /* ★ 主按钮文字用深墨色，不用白。
     亮色主题的按钮底是橙金渐变（#c98f4c → #b4793a），白字压上去对比度只有 2.69，
     低于 WCAG 对按钮文字 3.0 的门槛，小字会发虚。深墨色是 6.12 / 4.67，两端都过。
     和深色主题保持同一个墨色，观感也更统一。 */
  --accent-ink: #241a0d;
  --ok: #2f8f62;
  --warn: #b4793a;
  --danger: #c0523f;
  --shadow: 0 12px 30px rgba(90, 70, 40, .16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1100px 620px at 50% -220px, rgba(217, 160, 91, .10), transparent 62%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }

/* ─────────── 顶部栏 ─────────── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  height: 58px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 30px; display: block; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-text {
  font-size: 17px; font-weight: 700; letter-spacing: .5px;
}
.brand-text em {
  font-style: normal; margin-left: 7px; font-size: 11px; font-weight: 600;
  color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  padding: 1px 6px; border-radius: 99px; vertical-align: 2px;
  letter-spacing: .6px;
}
.topbar-right { display: flex; align-items: center; gap: 6px; }

.net-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--text-3);
  padding: 4px 10px 4px 8px; border-radius: 99px;
  background: var(--panel); border: 1px solid var(--line-soft);
  margin-right: 4px;
}
.net-status i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 18%, transparent);
  transition: background .3s;
}
.net-status.on i { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.net-status.off i { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent); }
.net-status.on { color: var(--text-2); }

.icon-btn {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  color: var(--text-2);
  transition: background .18s, color .18s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; fill: currentColor; }

/* ─────────── 通用 ─────────── */
.view { max-width: 1180px; margin: 0 auto; padding: 26px 20px 48px; }
.view[hidden] { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 42px; padding: 0 18px;
  border-radius: 10px;
  font-weight: 600; font-size: 14.5px;
  border: 1px solid transparent;
  transition: transform .12s, background .18s, border-color .18s, opacity .18s;
  user-select: none;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; fill: currentColor; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 26%, transparent);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-ghost {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text-2);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--text-3); }
.btn-ghost.danger:hover:not(:disabled) { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, transparent); }
.btn-lg { height: 50px; font-size: 16px; width: 100%; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.link-btn { color: var(--accent); font-size: 13px; text-align: left; }
.link-btn:hover { text-decoration: underline; }

/* ─────────── 大厅 ─────────── */
.hero { text-align: center; padding: 26px 0 30px; }
.hero h1 {
  margin: 0 0 8px; font-size: 34px; letter-spacing: 1px; font-weight: 800;
  background: linear-gradient(180deg, var(--text), color-mix(in srgb, var(--text) 62%, var(--accent)));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub { margin: 0; color: var(--text-2); font-size: 14.5px; }
.hero-stats {
  margin-top: 14px; display: inline-flex; gap: 18px;
  font-size: 12.5px; color: var(--text-3);
}
.hero-stats b { color: var(--accent); font-size: 15px; margin-right: 3px; }

.lobby-grid {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 18px;
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.panel h2 {
  margin: 0 0 18px; font-size: 15px; font-weight: 700;
  letter-spacing: .8px; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.panel h2::before {
  content: ''; width: 3px; height: 14px; border-radius: 2px;
  background: var(--accent);
}

.field { margin-bottom: 16px; }
.field > label {
  display: block; font-size: 12.5px; color: var(--text-2);
  margin-bottom: 7px; font-weight: 600; letter-spacing: .3px;
}
.field .hint { color: var(--text-3); font-weight: 400; }

input[type="text"], input[type="password"] {
  width: 100%; height: 42px;
  padding: 0 13px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
input[type="text"]:focus, input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
input::placeholder { color: var(--text-3); }

/* 尺寸选择 */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg button {
  padding: 10px 6px; border-radius: 10px;
  background: var(--bg-2);
  border: 1.5px solid var(--line);
  color: var(--text-2);
  text-align: center;
  transition: all .16s;
  line-height: 1.35;
}
.seg button b { display: block; font-size: 14px; font-weight: 700; }
.seg button small { display: block; font-size: 11px; color: var(--text-3); }
.seg button:hover { border-color: var(--text-3); }
.seg button.on {
  background: color-mix(in srgb, var(--accent) 13%, var(--bg-2));
  border-color: var(--accent);
  color: var(--text);
}
.seg button.on small { color: color-mix(in srgb, var(--accent) 78%, var(--text-2)); }
.seg-sm { grid-template-columns: repeat(4, 1fr); }
.seg-sm button { padding: 8px 4px; font-size: 12.5px; }

/* 单选行 */
.radio-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.radio {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 10px 12px; border-radius: 10px;
  background: var(--bg-2); border: 1.5px solid var(--line);
  cursor: pointer; transition: all .16s;
}
.radio:hover { border-color: var(--text-3); }
.radio input { margin: 3px 0 0; accent-color: var(--accent); }
.radio span b { display: block; font-size: 13.5px; font-weight: 600; }
.radio span small { display: block; font-size: 11px; color: var(--text-3); line-height: 1.45; }
.radio:has(input:checked) {
  background: color-mix(in srgb, var(--accent) 11%, var(--bg-2));
  border-color: var(--accent);
}

.check {
  display: flex; gap: 9px; align-items: flex-start;
  font-size: 12.5px; color: var(--text-2);
  margin-bottom: 10px; cursor: pointer;
}
.check input { margin: 3px 0 0; accent-color: var(--accent); }

/* 高级设置 */
.adv { margin: 4px 0 18px; border-top: 1px dashed var(--line); padding-top: 12px; }
.adv summary {
  font-size: 12.5px; color: var(--text-3); cursor: pointer;
  list-style: none; user-select: none; margin-bottom: 2px;
}
.adv summary::-webkit-details-marker { display: none; }
.adv summary::before { content: '▸ '; color: var(--accent); }
.adv[open] summary::before { content: '▾ '; }
.adv summary:hover { color: var(--text-2); }
.adv-body { padding-top: 14px; }

/* 房间号输入 */
.code-input { display: flex; gap: 8px; }
.code-char {
  flex: 1; min-width: 0; height: 54px;
  background: var(--bg-2);
  border: 1.5px solid var(--line);
  border-radius: 11px;
  text-align: center;
  font-size: 22px; font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 1px;
  text-transform: uppercase;
  outline: none;
  transition: all .16s;
}
.code-char:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
.code-char.filled { color: var(--accent); }

.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0 16px; color: var(--text-3); font-size: 12px;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line-soft);
}
.sub-h { margin: 0 0 10px; font-size: 12.5px; color: var(--text-2); font-weight: 600; }

/* 房间列表 */
.room-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; max-height: 330px; overflow-y: auto; }
.room-list .empty {
  padding: 24px 12px; text-align: center;
  color: var(--text-3); font-size: 13px;
  border: 1px dashed var(--line); border-radius: 10px;
}
.room-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 13px;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  transition: all .16s;
  text-align: left; width: 100%;
}
.room-item:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--bg-2));
}
.ri-main { flex: 1; min-width: 0; }
.ri-top { display: flex; align-items: center; gap: 7px; }
.ri-code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 14px; font-weight: 700; color: var(--accent); letter-spacing: 1px;
}
.ri-size {
  font-size: 10.5px; padding: 1px 6px; border-radius: 99px;
  background: var(--panel-2); color: var(--text-2); border: 1px solid var(--line);
}
.ri-lock { font-size: 11px; color: var(--warn); }
.ri-sub {
  font-size: 12px; color: var(--text-3); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ri-state {
  font-size: 11px; padding: 3px 9px; border-radius: 99px; font-weight: 600;
  white-space: nowrap;
}
.ri-state.waiting { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.ri-state.playing { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.ri-state.full { background: var(--panel-2); color: var(--text-3); }

.lobby-foot {
  margin-top: 26px; text-align: center;
  font-size: 12.5px; color: var(--text-3);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}

/* ─────────── 对局页 ─────────── */
.view-game { max-width: 1240px; padding-top: 18px; }
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 20px;
  align-items: start;
}

.board-panel {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.board-head {
  display: flex; align-items: center; gap: 10px;
  padding: 0 2px 12px;
  flex-wrap: wrap;
}
.board-head .back { margin-left: -6px; }
.room-tag {
  display: flex; align-items: center; gap: 8px;
  position: relative;
}
.room-label { font-size: 11.5px; color: var(--text-3); }
.room-code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 16px; font-weight: 700; letter-spacing: 2.5px;
  color: var(--accent);
  padding: 3px 9px; border-radius: 7px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  transition: all .16s;
}
.room-code:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.copy-hint {
  position: absolute; left: 100%; top: 50%; transform: translateY(-50%);
  margin-left: 8px; font-size: 11.5px; color: var(--ok);
  opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap;
}
.copy-hint.show { opacity: 1; }
.board-meta { margin-left: auto; font-size: 12px; color: var(--text-3); display: flex; gap: 5px; align-items: center; }
.board-meta .dot { color: var(--line); }

.board-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 0 10px;
  /* 关键：允许子元素在窄屏下收缩，而不是把容器顶出去 */
  min-width: 0;
  width: 100%;
}
.board-wrap {
  position: relative;
  /* 用这两条约束而不是 max-width + aspect-ratio：
     在小屏上 aspect-ratio 会与 min-content 打架，导致 canvas 被拉成非正方形 */
  width: min(100%, 78vh, 700px);
  height: auto;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #8d5f30;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.18), 0 8px 26px rgba(0,0,0,.3);
}
#board {
  display: block;
  /* canvas 的像素尺寸由 JS 设置，CSS 尺寸必须严格等于它，
     否则会被拉伸变形（这就是"对不齐"的根因） */
  width: 100% !important;
  height: 100% !important;
  touch-action: manipulation;
}

.board-overlay.waiting {
  background: linear-gradient(180deg, rgba(10,14,18,.16), rgba(10,14,18,.40));
  backdrop-filter: none;
}
.board-overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(10, 14, 18, .58);
  z-index: 5;
  animation: fadeIn .22s ease;
}
.board-overlay[hidden] { display: none; }
/* 结算/等待浮层的内容必须有自己的底板：
   棋盘是深色木纹、棋子是黑的，文字直接压上去（尤其"连成五子"落在胜线上）
   会看不清，按钮也会和棋子糊在一起。 */
.ov-inner {
  text-align: center; padding: 22px 26px; max-width: 88%;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.ov-title { font-size: 20px; font-weight: 700; margin-bottom: 7px; }
.ov-text { font-size: 13px; color: var(--text-2); line-height: 1.65; margin-bottom: 16px; }
.ov-text b { color: var(--accent); font-family: ui-monospace, Menlo, monospace; letter-spacing: 2px; }
.ov-actions { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; }

.thinking {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 7px;
  padding: 6px 13px; border-radius: 99px;
  background: rgba(16, 21, 27, .82);
  border: 1px solid var(--line);
  font-size: 12px; color: var(--text-2);
  backdrop-filter: blur(6px);
  /* 浮标压在最下面一行交叉点上会挡棋子，也不该吞掉点击 */
  pointer-events: none;
}
.thinking[hidden] { display: none; }
.thinking i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.1s infinite;
}
@keyframes pulse { 0%,100% { opacity: .25; } 50% { opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.board-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 4px 2px 0;
}
.turn-bar {
  display: flex; align-items: center; gap: 9px;
  font-size: 13.5px; color: var(--text-2);
}
.turn-text { font-weight: 600; }
.turn-timer {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12.5px; color: var(--text-3);
  padding: 1px 7px; border-radius: 6px; background: var(--panel-2);
}
.turn-timer[hidden] { display: none; }
.turn-timer.low { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }

.stone-dot {
  width: 15px; height: 15px; border-radius: 50%; display: inline-block; flex: none;
}
.stone-dot.black { background: radial-gradient(circle at 32% 28%, #5a6472, #14191f 62%); box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.stone-dot.white { background: radial-gradient(circle at 32% 28%, #ffffff, #d8d3c8 68%); box-shadow: 0 1px 3px rgba(0,0,0,.35), inset 0 0 0 1px rgba(0,0,0,.12); }
.stone-dot.turn { animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-2.5px); } }

.actions { display: flex; gap: 8px; }

/* 侧栏 */
.side {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  height: calc(100vh - 110px);
  min-height: 460px;
  position: sticky; top: 74px;
}

.players { padding: 14px 14px 10px; border-bottom: 1px solid var(--line-soft); }
.player {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 9px;
  border: 1.5px solid transparent;
  transition: all .2s;
}
.player.active {
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  border-color: color-mix(in srgb, var(--accent) 34%, transparent);
}
.player .stone-dot { width: 20px; height: 20px; }
.p-info { flex: 1; min-width: 0; }
.p-name {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.p-sub { font-size: 11.5px; color: var(--text-3); }
.p-sub.online { color: var(--ok); }
.p-sub.offline { color: var(--danger); }
.p-badge {
  font-size: 10px; padding: 1px 7px; border-radius: 99px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.p-badge[hidden] { display: none; }
.vs {
  text-align: center; font-size: 10.5px; color: var(--text-3);
  letter-spacing: 2px; padding: 3px 0;
}

.side-tabs { display: flex; border-bottom: 1px solid var(--line-soft); }
.tab {
  flex: 1; padding: 10px 0; font-size: 13px; color: var(--text-3);
  border-bottom: 2px solid transparent; transition: all .16s;
}
.tab:hover { color: var(--text-2); }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-body { flex: 1; min-height: 0; display: flex; }
.pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pane[hidden] { display: none; }

.chat-list {
  flex: 1; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 9px;
}
.chat-empty { color: var(--text-3); font-size: 12.5px; text-align: center; margin-top: 22px; }
.chat-msg { font-size: 13px; line-height: 1.5; }
.chat-msg .cm-head { font-size: 11.5px; color: var(--text-3); margin-bottom: 2px; }
.chat-msg .cm-head b { color: var(--text-2); font-weight: 600; }
.chat-msg.mine .cm-head b { color: var(--accent); }
.chat-msg .cm-body {
  display: inline-block;
  padding: 6px 10px; border-radius: 9px;
  background: var(--panel-2);
  word-break: break-word; max-width: 100%;
}
.chat-msg.mine { text-align: right; }
.chat-msg.mine .cm-body {
  background: color-mix(in srgb, var(--accent) 18%, var(--panel-2));
  text-align: left;
}
.chat-msg.sys { text-align: center; font-size: 11.5px; color: var(--text-3); }

.chat-input {
  display: flex; gap: 7px; padding: 10px 12px;
  border-top: 1px solid var(--line-soft);
}
.chat-input input {
  flex: 1; height: 36px; border-radius: 8px;
}
.chat-input .btn { width: 40px; padding: 0; }

.log-list {
  flex: 1; overflow-y: auto; padding: 10px 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.9;
  color: var(--text-2);
}
.log-row { display: flex; gap: 10px; padding: 1px 0; }
.log-row .ln { color: var(--text-3); width: 26px; text-align: right; flex: none; }
.log-row .lc { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; }
.log-row .lc.black { background: #2b323c; box-shadow: inset 0 0 0 1px #4a5462; }
.log-row .lc.white { background: #ddd8cd; }
.log-row .coord { color: var(--text); letter-spacing: .5px; }
.log-empty { color: var(--text-3); text-align: center; margin-top: 22px; font-size: 12.5px; }

/* ─────────── 弹窗 ─────────── */
.modal-mask {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(8, 11, 15, .62);
  backdrop-filter: blur(4px);
  /* 用 flex + margin:auto 居中，而不是 grid + place-items:center：
     grid 居中时超高的弹窗会同时向上下溢出，顶部那段滚不到（scrollHeight 不增长），
     矮屏下按钮就被顶到屏幕外且无法滚动。 */
  display: flex;
  align-items: center; justify-content: center;
  animation: fadeIn .16s ease;
  padding: 20px;
  overflow-y: auto;
}
.modal-mask[hidden] { display: none; }
.modal {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .5);
  animation: popIn .2s cubic-bezier(.2, .9, .3, 1.2);
  /* 内容比视口高时自身滚动，保证按钮永远够得着 */
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  /* flex 容器里用 auto 外边距居中，超高时上下都可滚动 */
  margin: auto;
}
@keyframes popIn { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h3 { margin: 0 0 10px; font-size: 17px; }
.modal p { margin: 0 0 20px; font-size: 13.5px; color: var(--text-2); line-height: 1.7; }
.modal-actions { display: flex; gap: 9px; justify-content: flex-end; }
.modal-actions .btn { min-width: 84px; }

/* ─────────── Toast ─────────── */
/* 放在顶栏下方居中：底部中间是「悔棋/和棋/认输」和回合提示，
   提示条压上去会挡住刚要用到的按钮（截图里三条提示直接盖住了整排按钮）。 */
.toast-stack {
  position: fixed; left: 50%; top: 68px; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none; align-items: center;
}
.toast {
  padding: 9px 17px; border-radius: 99px;
  background: rgba(26, 34, 44, .96);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .38);
  animation: toastIn .22s ease;
  white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}
.toast.err { border-color: color-mix(in srgb, var(--danger) 50%, transparent); color: #ffb4a6; }
.toast.ok { border-color: color-mix(in srgb, var(--ok) 50%, transparent); color: #a8e8c6; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ─────────── 响应式 ─────────── */
@media (max-width: 900px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; }
  .side { height: auto; min-height: 0; position: static; }
  .chat-list { max-height: 240px; }
  .log-list { max-height: 240px; }
  .board-wrap { max-width: min(92vw, 560px); }
  .hero h1 { font-size: 27px; }
  .view { padding: 18px 14px 40px; }
}

@media (max-width: 520px) {
  .topbar { padding: 0 14px; height: 52px; }
  .brand-text em { display: none; }
  .seg button small { display: none; }
  .radio-row { grid-template-columns: 1fr; }
  .board-head { gap: 6px; }
  .board-meta { width: 100%; margin-left: 0; padding-left: 2px; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}

/* ══════════════════════════════════════════════════════
   手表 / 极窄屏（Apple Watch、Wear OS、小屏横置）
   特征：宽度普遍 320~400px，高度可能更小，无鼠标悬停
   ══════════════════════════════════════════════════════ */
@media (max-width: 420px) {
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 13px; line-height: 1.5; }

  .topbar { height: 42px; padding: 0 8px; }
  .brand-mark { width: 22px; height: 22px; }
  .brand-text { font-size: 14px; }
  .brand-text em { display: none; }
  .net-status { font-size: 11px; padding: 2px 7px 2px 6px; margin-right: 0; }
  .net-status span { display: none; }
  .icon-btn { width: 28px; height: 28px; }
  .icon-btn svg { width: 16px; height: 16px; }

  .view { padding: 10px 8px 24px; }

  /* 大厅：单列、紧凑 */
  .hero { padding: 10px 0 14px; }
  .hero h1 { font-size: 20px; margin-bottom: 4px; }
  .hero-sub { font-size: 12px; }
  .hero-stats { margin-top: 8px; gap: 12px; font-size: 11px; }
  .panel { padding: 12px; border-radius: 12px; }
  .panel h2 { font-size: 13px; margin-bottom: 10px; }
  .field { margin-bottom: 10px; }
  .field > label { font-size: 11.5px; margin-bottom: 5px; }
  input[type="text"] { height: 36px; font-size: 14px; padding: 0 10px; }
  .btn { height: 36px; font-size: 13px; padding: 0 12px; border-radius: 9px; }
  .btn-lg { height: 42px; font-size: 14px; }

  .seg { gap: 5px; }
  .seg button { padding: 7px 3px; border-radius: 8px; }
  .seg button b { font-size: 12px; }
  .seg-sm button { font-size: 11.5px; padding: 6px 2px; }

  .code-input { gap: 4px; }
  .code-char { height: 42px; font-size: 18px; border-radius: 9px; }

  .room-list { max-height: 180px; }
  .room-item { padding: 8px 10px; gap: 8px; }
  .ri-code { font-size: 13px; }
  .ri-sub { font-size: 11px; }
  .ri-state { font-size: 10px; padding: 2px 7px; }

  /* 对局：棋盘吃满宽度，信息区压到棋盘下方 */
  .view-game { padding: 6px 6px 16px; }
  .game-layout { gap: 8px; }
  .board-panel { padding: 8px; border-radius: 12px; }

  .board-head { padding-bottom: 6px; gap: 5px; }
  .board-head .back { margin-left: -4px; }
  .room-label { display: none; }
  .room-code { font-size: 13px; letter-spacing: 1.5px; padding: 2px 6px; }
  .board-meta { font-size: 10.5px; gap: 3px; width: 100%; margin-left: 0; }

  .board-stage { padding: 2px 0 4px; }
  /* 手表上不能只按宽度吃满 —— 那样棋盘会把底部操作区顶出屏幕。
     约束思路：棋盘边长 = min(可用宽度, 可用高度)。
     高度里扣掉的是：顶栏 42 + 房间头约 46 + 状态与操作栏约 44 + 内边距。 */
  .board-wrap {
    width: min(100%, calc(100dvh - 190px));
    height: auto;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    margin: 0 auto;
  }

  .board-foot { gap: 6px; padding-top: 4px; }
  .turn-bar { font-size: 12px; gap: 6px; }
  .stone-dot { width: 12px; height: 12px; }
  .turn-timer { font-size: 11px; padding: 0 5px; }
  .actions { gap: 5px; }
  .actions .btn { height: 30px; font-size: 12px; padding: 0 9px; border-radius: 7px; }

  /* 侧栏：玩家条横排、聊天区限高 */
  .side { border-radius: 12px; }
  .players { padding: 8px 8px 6px; }
  .player { padding: 5px 6px; gap: 7px; border-radius: 7px; }
  .player .stone-dot { width: 14px; height: 14px; }
  .p-name { font-size: 12.5px; }
  .p-sub { font-size: 10.5px; }
  .vs { display: none; }
  .side-tabs .tab { padding: 7px 0; font-size: 12px; }
  .chat-list { max-height: 150px; padding: 8px; gap: 6px; }
  .chat-msg { font-size: 12px; }
  .chat-msg .cm-body { padding: 4px 8px; border-radius: 7px; }
  .chat-input { padding: 6px 8px; gap: 5px; }
  .chat-input input { height: 30px; font-size: 12px; }
  .chat-input .btn { width: 32px; height: 30px; }

  /* 弹窗与提示：留足边距，竖排按钮更好点 */
  .modal { padding: 16px; border-radius: 12px; }
  .modal h3 { font-size: 15px; }
  .modal p { font-size: 12.5px; margin-bottom: 14px; }
  .modal-actions { flex-direction: column-reverse; gap: 6px; }
  .modal-actions .btn { width: 100%; height: 38px; }

  .board-overlay .ov-title { font-size: 16px; }
  .board-overlay .ov-text { font-size: 11.5px; }
  .board-overlay .ov-inner { padding: 10px; }
  .thinking { font-size: 10.5px; padding: 4px 9px; bottom: 6px; }

  .toast { font-size: 12px; padding: 7px 13px; }
  .toast-stack { top: 52px; }
}

/* 手表且屏幕极矮（横置或圆形小表盘） */
@media (max-height: 420px) and (max-width: 560px) {
  .topbar { height: 36px; }
  .view { padding: 6px 6px 12px; }
  .hero { display: none; }
  .board-stage { padding: 0; }
  .chat-list, .log-list { max-height: 110px; }
  .lobby-foot { display: none; }
}
