/* 军棋在线 — 扁平简洁风格 */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #2b323c;
  --muted: #7a828e;
  --accent: #2f9e63;
  --accent-dk: #23814f;
  --red: #d0483f;
  --red-dk: #b53830;
  --blue: #3b7bbf;
  --blue-dk: #2f64a0;
  --gold: #c9962e;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}
#app { max-width: 1180px; margin: 0 auto; padding: 18px 16px 40px; }
.hidden { display: none !important; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 10px 22px; position: sticky; top: 0; z-index: 5;
}
#topbar .logo { font-weight: 700; font-size: 17px; }
#topbar .logo-link { cursor: pointer; }
#topbar .logo-link:hover { color: var(--accent); }
#topbar-info { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13.5px; flex-wrap: wrap; justify-content: flex-end; }
#topbar-info b { color: var(--text); }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 15.5px; }

button, .btn {
  appearance: none; border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 7px; padding: 7px 14px; font-size: 14px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover { background: #f2f4f6; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dk); }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.danger:hover { background: var(--red-dk); }
button.ghost { border-color: transparent; background: transparent; color: var(--accent); padding: 4px 8px; }
button.small { padding: 3px 10px; font-size: 13px; border-radius: 6px; }

input, select, textarea {
  border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd9c9; border-color: var(--accent); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }
.error-text { color: var(--red); font-size: 13.5px; }
.ok-text { color: var(--accent); }

/* 徽标 */
.badge {
  display: inline-block; padding: 1px 9px; border-radius: 20px; font-size: 12.5px;
  border: 1px solid var(--border); color: var(--muted); background: #fafbfc;
  white-space: nowrap; flex: none;
}
.badge.team0 { color: var(--red); border-color: #ecc7c3; background: #fbf1f0; }
.badge.team1 { color: var(--blue); border-color: #c4d6ea; background: #f0f5fb; }
.badge.gold { color: var(--gold); border-color: #e7d5ac; background: #fbf6ea; }
.badge.level { color: #8a6a1c; border-color: #e7d5ac; background: #fbf3dd; font-weight: 600; }

/* 用户名 + 等级（点用户名看个人卡片） */
.user-chip { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.user-link { cursor: pointer; border-bottom: 1px dashed var(--accent); }
.user-link:hover { color: var(--accent); }

/* 设置网格 */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 24px; align-items: center; }
.settings-grid label.row { cursor: pointer; }

/* 建房 / 房间设置的表单卡片 */
.room-form .field { display: block; margin: 0; }
.room-form .field > span { display: block; margin-bottom: 4px; font-size: 13px; }
.room-form .field input { width: 100%; }
.form-grid2 { display: grid; grid-template-columns: 3fr 2fr; gap: 12px; margin-top: 4px; }
.form-section-title { margin: 16px 0 2px; font-size: 12.5px; letter-spacing: .04em; }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid #eef0f3; }
.form-row:last-of-type { border-bottom: none; }
.form-label { display: flex; flex-direction: column; gap: 1px; }
.form-label .muted { font-size: 12.5px; }
.form-control { display: flex; align-items: center; gap: 8px; flex: none; }
.inline-control { display: inline-flex; align-items: center; gap: 6px; }
.inline-control input[type=password] { width: 150px; }
.modal-actions { justify-content: flex-end; margin-top: 14px; }
.mode-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode-chip { padding: 8px 4px; line-height: 1.3; }
.mode-chip b { display: block; font-size: 14.5px; }
.mode-chip span { font-size: 12.5px; }
.mode-chip.on { border-color: var(--accent); background: #f3faf6; box-shadow: 0 0 0 1px var(--accent) inset; }
/* 安卓式滑动开关 */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: #c5cad3; border-radius: 22px; transition: background .15s; }
.switch i::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch.disabled { opacity: .5; cursor: default; }

/* 登录 */
.auth-wrap { max-width: 380px; margin: 8vh auto; }
.auth-tabs { display: flex; margin-bottom: 16px; border-bottom: 2px solid var(--border); }
.auth-tabs button { border: none; background: none; border-radius: 0; padding: 9px 4px; margin-right: 22px; font-size: 15.5px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.auth-tabs button.on { color: var(--text); font-weight: 700; border-bottom-color: var(--accent); }
.auth-wrap .field { margin-bottom: 12px; }
.auth-wrap label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.auth-wrap input { width: 100%; }
.auth-wrap button[type=submit] { width: 100%; margin-top: 4px; padding: 10px; }

/* 模式选择卡 */
.mode-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.mode-card { border: 2px solid var(--border); border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.mode-card.on { border-color: var(--accent); background: #f3faf6; }
.mode-card b { display: block; font-size: 15px; }
.mode-card span { font-size: 12.5px; color: var(--muted); }
.mode-card .mode-tag { float: right; }

/* 房间列表 */
table.rooms { width: 100%; border-collapse: collapse; font-size: 14px; }
table.rooms th { text-align: left; color: var(--muted); font-weight: 500; font-size: 13px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.rooms td { padding: 9px 8px; border-bottom: 1px solid #eef0f3; }

/* 座位 */
.seat {
  background: #fafbfc; border: 2px solid var(--border); border-radius: 10px;
  padding: 10px 12px; min-width: 150px; min-height: 74px;
}
.seat.t0 { border-color: #ecc7c3; } .seat.t1 { border-color: #c4d6ea; }
.seat .seat-name { font-weight: 700; }
.seat .seat-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.seat.ready { box-shadow: 0 0 0 2px #cfe9db inset; }
.seat.turn { box-shadow: 0 0 0 3px var(--gold); }
.seat.dead { opacity: .5; }
.seat-empty { color: var(--muted); display: flex; align-items: center; justify-content: center; height: 74px; }

.seats-ring { position: relative; height: 480px; max-width: 640px; margin: 0 auto; }
.seat-abs { position: absolute; transform: translate(-50%, -50%); }
.seats-cross { display: grid; grid-template-columns: repeat(3, 180px); grid-template-rows: repeat(3, auto); gap: 14px; justify-content: center; align-items: center; }
.seats-row2 { display: flex; gap: 16px; justify-content: center; margin: 14px 0; }

/* 棋盘 */
.board-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 8px; }
.board-wrap.my-turn { border-color: var(--gold); box-shadow: 0 0 0 3px #f3e3bd; }
svg.board { width: 100%; height: auto; display: block; user-select: none; }
svg.board text { font-family: "PingFang SC", "Microsoft YaHei", sans-serif; pointer-events: none; }
svg.board .cell-hit { cursor: pointer; }

/* 聊天 */
.chat-box { display: flex; flex-direction: column; gap: 6px; }
.chat-msgs { height: 150px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; background: #fafbfc; }
.chat-msgs .sys { color: var(--muted); }
.chat-msgs b { margin-right: 6px; }
.chat-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.phrase-list { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.phrase-list button.emoji { font-size: 16px; padding: 2px 8px; line-height: 1.4; }

/* 编辑器 */
.editor-grid { display: grid; grid-template-columns: minmax(340px, 1fr) 330px; gap: 16px; align-items: start; }
.tray { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tray-piece {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 4px; text-align: center;
  cursor: pointer; background: #fff; font-size: 13px;
}
.tray-piece.on { border-color: var(--accent); background: #f3faf6; }
.tray-piece.empty { opacity: .35; cursor: not-allowed; }
.tray-piece b { display: block; font-size: 14.5px; }
.err-list { list-style: none; margin: 6px 0; padding: 0; color: var(--red); font-size: 13px; }

/* 对局页 */
.game-grid { display: grid; grid-template-columns: minmax(420px, 1fr) 330px; gap: 16px; align-items: start; }
.player-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; padding: 5px 8px; border-radius: 7px; font-size: 14px; } /* 徽标多的时候换行，不把字挤成竖排 */
.player-row.turn { background: #fbf6ea; box-shadow: 0 0 0 1.5px var(--gold); }
.player-row.dead { opacity: .5; text-decoration: line-through; }
.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.dot.t0 { background: var(--red); } .dot.t1 { background: var(--blue); }
.grave-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; border: 1px solid var(--border); border-radius: 5px; padding: 0 6px; background: #fafbfc; color: var(--muted); }
/* 玩家的编号：和棋谱里的编号一致（先手 1 号），底色是他的棋子颜色 */
.pnum { flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.pname { font-weight: 600; white-space: nowrap; }
.player-row .user-chip { flex-wrap: nowrap; white-space: nowrap; }
.claim-btn { margin-left: auto; flex: none; white-space: nowrap; } /* 掉线满时限才变成红色的"断线判负"；没到时间是灰的 */
/* 战损：自己的按座位一行；其他玩家的是自己记的标记 */
.loss-title { margin: 10px 0 4px; font-size: 13px; font-weight: 700; }
.loss-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; padding: 5px 0; border-bottom: 1px dashed #eef0f3; font-size: 13px; }
.loss-row:last-child { border-bottom: none; }
.loss-who { flex: none; font-weight: 700; }
.loss-dead { flex: none; font-size: 12px; }
.chip.own { color: #3d4650; border-color: #cfd5dc; background: #fff; }
.chip.mark { color: #8a6a1c; border-color: #e7d5ac; background: #fbf6ea; cursor: pointer; }
.chip.mark:hover { background: #f3e3bd; }
.loss-add { flex: none; }
.loss-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.loss-pick { display: flex; gap: 2px; }
.loss-pick .small { flex: 1; min-width: 0; }
.loss-pick.on .small { border-color: var(--gold); background: #fbf6ea; }
.loss-pick .loss-minus { flex: none; width: 30px; }
/* 机器人行棋速度：三个小按钮选一个 */
.speed-picker { display: inline-flex; gap: 6px; }
.speed-chip { padding: 4px 14px; font-size: 13.5px; border-radius: 6px; }
.speed-chip.on { border-color: var(--accent); background: #f3faf6; box-shadow: 0 0 0 1px var(--accent) inset; font-weight: 700; }
.log-list { list-style: none; margin: 0; padding: 0; font-size: 13px; max-height: 260px; overflow-y: auto; }
.log-list li { padding: 3px 0; border-bottom: 1px dashed #eef0f3; }
.turn-banner { text-align: center; padding: 8px; font-size: 15px; font-weight: 700; border-radius: 8px; background: #fafbfc; border: 1px solid var(--border); margin-bottom: 10px; }
.turn-banner.mine { background: #fbf6ea; border-color: var(--gold); color: #8a6a1c; }
/* 每步限时倒计时 */
.clock { text-align: center; font-size: 14px; color: var(--muted); margin: -4px 0 10px; }
.clock:empty { display: none; }
.clock.warn { color: var(--red); font-weight: 700; }

/* 提和：棋盘上方的提示条（别人提和等我回应 / 我提的还在等谁） */
.draw-box { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; padding: 8px 12px; border-radius: 10px; background: #fff7e0; border: 1px solid var(--gold); font-weight: 600; }
.draw-box:empty { display: none; }

/* 大厅顶部：我所在的房间 / 对局中还留着座位 */
.lobby-banner { border-color: var(--gold); background: #fbf6ea; }
.lobby-banner p, .lobby-banner span { margin: 0; }
.my-room { border-color: var(--accent); background: #f3faf6; }
.my-room p { margin: 6px 0 0; }
/* 房间里站着的人看到的提示（还没有入座 / 房间已开） */
.room-open { border-style: dashed; }
.room-open h3 { margin-top: 0; }
/* 回放里的棋谱说明 */
.record-head { border-bottom: 1px dashed var(--border); padding-bottom: 6px; margin-bottom: 6px; font-size: 13px; line-height: 1.6; word-break: break-all; }
.record-help { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); }
.record-help summary { cursor: pointer; }
.record-help ul { margin: 4px 0 0; padding-left: 18px; line-height: 1.5; }
code { background: #f2f4f6; border-radius: 4px; padding: 0 4px; font-family: Consolas, "Courier New", monospace; }

/* 回放播放器 */
.replay-view { display: grid; grid-template-columns: minmax(420px, 1fr) 340px; gap: 16px; align-items: start; }
.replay-side { display: flex; flex-direction: column; gap: 10px; }
.replay-ctrl button { min-width: 46px; }
.replay-cursor { text-align: center; font-weight: 700; padding: 6px 8px; border-radius: 8px; background: #fafbfc; border: 1px solid var(--border); }
.move-list-wrap { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.move-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 400px; overflow-y: auto; font-size: 13px; }
.move-list li { display: flex; gap: 10px; padding: 4px 6px; border-radius: 6px; cursor: pointer; line-height: 1.45; }
.move-list li:hover { background: #f2f4f6; }
.move-list li.cur { background: #fbf6ea; font-weight: 600; }
.move-list li.skip { display: none; } /* 四国出局者的棋子移出棋盘：不单独占一行 */
.move-list .n { flex: none; min-width: 36px; padding-left: 6px; color: var(--muted); font-weight: 400; }
/* 对局页的棋谱：点一步回看当时的局面。连上之前的着法只有文字（没有局面快照），显示得淡一些、不能点 */
.live-moves { max-height: 230px; }
.move-list li.nosnap { opacity: .55; cursor: default; }
.move-list li.nosnap:hover { background: none; }
/* 回看时棋盘上方的那一条：在看第几手、怎么回去 */
.browse-bar { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; margin: 6px 0; padding: 5px 8px; font-size: 13px; color: #8a6a1c; background: #fbf6ea; border: 1px solid var(--gold); border-radius: 8px; }
/* 回放文件里不运行脚本时显示的文字棋谱 */
.record-text { padding-left: 30px; line-height: 1.7; font-size: 14px; }
.replay-meta > div { margin-bottom: 4px; }
.replay-meta table { max-width: 460px; }

/* 管理后台 */
.bug-text { white-space: pre-wrap; word-break: break-word; background: #fafbfc; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-family: inherit; font-size: 14px; margin: 8px 0; }
.code { background: #2b323c; color: #fff; padding: 8px 12px; border-radius: 8px; display: inline-block; }

/* 弹层 & 提示 */
#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #2b323c; color: #fff; border-radius: 8px; padding: 9px 18px; font-size: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,.18); animation: pop .18s ease-out; max-width: 80vw;
}
.toast.battle { background: #3d2f16; border: 1px solid var(--gold); font-size: 15px; }
.toast.err { background: var(--red-dk); }
.toast.turn { background: var(--accent-dk); border: 1px solid #9fd9bb; font-size: 15px; padding: 11px 22px; }
.toast.turn.clickable { cursor: pointer; }
/* 部署了新版本后，一直没刷新的页面在底部提示（正在下棋时等这局结束再出现）。点一下就刷新 */
#update-bar { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 60; cursor: pointer; white-space: nowrap;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; padding: 9px 18px; border-radius: 20px; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
#update-bar:hover { background: var(--accent-dk); }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
#modal-root:not(:empty) { position: fixed; inset: 0; background: rgba(30,36,44,.45); z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal { background: #fff; border-radius: 12px; padding: 20px 22px; max-width: 560px; width: min(92vw, 560px); max-height: 86vh; overflow-y: auto; }
.modal h3 { margin-top: 0; }

/* 管理后台 */
.stat-row { display: flex; gap: 28px; flex-wrap: wrap; margin-bottom: 14px; }
.stat b { display: block; font-size: 22px; line-height: 1.25; }
.stat .muted { font-size: 13px; }
.invite-new { margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; background: #f3faf6; border: 1px solid var(--accent); }
.invite-new b { font-size: 18px; letter-spacing: .04em; }

@media (max-width: 900px) {
  .editor-grid, .game-grid, .replay-view, .settings-grid { grid-template-columns: 1fr; }
  .mode-cards { grid-template-columns: 1fr; }
  .seats-cross { grid-template-columns: repeat(3, minmax(110px, 150px)); }
}
