:root {
  --paper: #f5f1e8;
  --card: #ffffff;
  --ink: #24211c;
  --ink-2: #6b6459;
  --ink-3: #9a9288;
  --line: #e4ddd0;
  --red: #b3352c;
  --red-soft: #fdeceb;
  --black-p: #2b2b2b;
  --blue: #1f6feb;
  --blue-soft: #eaf2fe;
  --wood: #e9cfa0;
  --wood-2: #dcbb85;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--wood); color: var(--red);
  display: flex; align-items: center; justify-content: center;
  font-family: "STKaiti", "KaiTi", "Songti SC", serif;
  font-size: 22px; font-weight: 700;
  border: 2px solid #a9762f;
  flex: 0 0 auto;
}
.topbar h1 { font-size: 17px; letter-spacing: .5px; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--ink-3); }

.me-box { display: flex; align-items: center; gap: 10px; }
button.ghost {
  background: transparent; border: 1px solid var(--line);
  color: var(--ink); border-radius: 9px;
  padding: 6px 12px; font-size: 13px; cursor: pointer;
  font-family: inherit; transition: .15s;
}
button.ghost:hover { background: #faf7f1; border-color: #d5ccbb; }
.pencil { color: var(--ink-3); font-size: 11px; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.on { background: #36a852; box-shadow: 0 0 0 3px #e2f4e7; }
.dot.off { background: #cc6a5f; box-shadow: 0 0 0 3px #fbe9e6; }

/* ---------- 布局 ---------- */
main { padding: 22px; max-width: 1180px; margin: 0 auto; }
.view.hide { display: none; }

/* ---------- 大厅 ---------- */
.lobby-head { margin-bottom: 18px; }
.lobby-head h2 { font-size: 19px; margin-bottom: 6px; }
.lobby-head p { margin: 0; color: var(--ink-2); font-size: 13.5px; }

.room-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.room-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  cursor: pointer;
  transition: .18s;
}
.room-card:hover { border-color: #cbbf9f; transform: translateY(-2px); box-shadow: 0 6px 18px rgba(90,70,40,.08); }
.rc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.rc-head h3 { font-size: 16px; }
.pill {
  font-size: 11.5px; padding: 3px 9px; border-radius: 20px;
  background: #f0ece2; color: var(--ink-2);
}
.pill.live { background: var(--red-soft); color: var(--red); }
.pill.done { background: var(--blue-soft); color: var(--blue); }

.rc-seats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.rc-seat {
  border-radius: 9px; padding: 8px 10px; font-size: 12.5px;
  background: #faf8f3; border: 1px solid var(--line);
  display: flex; align-items: center; gap: 7px; min-width: 0;
}
.rc-seat .tag {
  width: 20px; height: 20px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-family: "STKaiti","KaiTi",serif; font-weight: 700;
  background: var(--wood); border: 1.5px solid #a9762f;
}
.rc-seat.red .tag { color: var(--red); }
.rc-seat.black .tag { color: var(--black-p); }
.rc-seat .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.rc-seat .nm.empty { color: var(--ink-3); }
.rc-foot { display: flex; gap: 14px; font-size: 12px; color: var(--ink-3); }
.rc-foot b { color: var(--ink-2); font-weight: 500; }

.tips {
  margin-top: 26px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 20px;
}
.tips h3 { font-size: 14px; margin-bottom: 8px; }
.tips ol { margin: 0; padding-left: 20px; color: var(--ink-2); font-size: 13px; line-height: 1.9; }
.tips b { color: var(--ink); font-weight: 600; }

/* ---------- 棋室 ---------- */
.room-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}
@media (max-width: 900px) {
  .room-grid { grid-template-columns: minmax(0, 1fr); }
}

.board-panel { min-width: 0; }
.board-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.board-head h2 { font-size: 17px; }
.bh-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.view-tag {
  font-size: 11.5px; padding: 3px 9px; border-radius: 20px; white-space: nowrap;
  background: #f0ece2; color: var(--ink-2);
}
.view-tag.black-side { background: #ececec; color: var(--black-p); }
.view-tag.red-side { background: var(--red-soft); color: var(--red); }

.board-shell {
  position: relative;
  display: inline-block;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid #d8c8a6;
  box-shadow: 0 4px 16px rgba(110,85,45,.12);
  background: var(--wood);
  max-width: 100%;
}
#board { display: block; max-width: 100%; height: auto; touch-action: manipulation; }

.result-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(36,33,28,.62);
  color: #fff; font-size: 26px; font-weight: 600; letter-spacing: 2px;
  backdrop-filter: blur(1.5px);
}
.result-overlay.hide { display: none; }

.banner {
  margin-top: 12px; padding: 10px 16px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line);
  font-size: 13.5px; color: var(--ink-2);
  display: flex; align-items: center; gap: 8px;
}
.banner.turn-mine { background: var(--red-soft); border-color: #f0c9c6; color: var(--red); font-weight: 600; }
.banner.warn { background: #fff6e8; border-color: #f0dcbb; color: #96651c; }

/* ---------- 侧栏 ---------- */
.side-panel { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card-title { font-size: 13px; color: var(--ink-2); margin-bottom: 10px; font-weight: 600; letter-spacing: .3px; }
.muted { color: var(--ink-3); font-weight: 400; }

.seat-list { display: flex; flex-direction: column; gap: 8px; }
.seat {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; cursor: pointer; background: #faf8f3;
  transition: .15s; min-width: 0;
}
.seat:hover { border-color: #cbbf9f; background: #fff; }
.seat.mine { border-color: var(--blue); background: var(--blue-soft); }
.seat.battle { border-left: 3px solid #d9cdb4; }
.seat.battle.red { border-left-color: var(--red); }
.seat.battle.black { border-left-color: var(--black-p); }
.seat .ico {
  width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-family: "STKaiti","KaiTi",serif; font-weight: 700;
  background: var(--wood); border: 1.5px solid #a9762f; color: var(--red);
}
.seat.battle.black .ico { color: var(--black-p); }
.seat.spec .ico { background: #f0ece2; border-color: #cdc3ac; color: var(--ink-2); font-size: 12px; font-family: inherit; }
.seat .info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.seat .role { font-size: 11px; color: var(--ink-3); }
.seat .who { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .who .empty { color: var(--ink-3); }
.seat .badge { font-size: 10.5px; padding: 2px 6px; border-radius: 6px; background: #eee9dd; color: var(--ink-2); flex: 0 0 auto; }
.seat .badge.me { background: var(--blue); color: #fff; }
.seat .badge.off { background: #f2e6e3; color: #a05a4f; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  border: none; border-radius: 9px; padding: 9px 14px;
  font-size: 13px; font-family: inherit; cursor: pointer; transition: .15s;
  background: #efeade; color: var(--ink);
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--red); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.wide { width: 100%; justify-content: center; }

.moves { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; font-size: 13px; }
.moves li {
  display: grid; grid-template-columns: 34px 1fr 1fr; gap: 6px;
  padding: 4px 6px; border-radius: 6px; align-items: center;
}
.moves li:nth-child(odd) { background: #faf8f3; }
.moves li .no { color: var(--ink-3); font-size: 12px; }
.moves li .mv.red-c { color: var(--red); }
.moves li .mv.black-c { color: var(--black-p); }
.moves .none { color: var(--ink-3); display: block; padding: 4px 6px; }

/* ---------- toast ---------- */
.toasts {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 60; align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(36,33,28,.92); color: #fff;
  padding: 9px 18px; border-radius: 10px; font-size: 13px;
  animation: pop .2s ease;
}
.toast.error { background: rgba(179,53,44,.95); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 悔棋确认弹窗 ---------- */
.dialog-backdrop {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(36,33,28,.38);
}
.dialog-backdrop.hide { display: none; }
.dialog-card {
  width: min(360px, 100%); background: var(--card); border-radius: var(--radius);
  padding: 22px; border: 1px solid var(--line); box-shadow: 0 16px 48px rgba(36,33,28,.24);
}
.dialog-card h3 { font-size: 17px; }
.dialog-card p { margin: 10px 0 18px; color: var(--ink-2); font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
