/* ================= 基础 ================= */
:root {
  --bg: #14130f;
  --bg-2: #191813;
  --panel: #1f1e1a;
  --panel-2: #262520;
  --panel-3: #2f2d27;
  --line: #34322b;
  --line-2: #403d34;
  --text: #f2f0e8;
  --muted: #a5a094;
  --muted-2: #7d786c;
  --accent: #81b64c;
  --accent-dim: #6b9a3e;
  --wood: #b58863;
  --cream: #f0d9b5;
  --danger: #cb4a43;
  --info: #5b9bd5;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --serif: "Songti SC", "Noto Serif SC", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  background-image:
    radial-gradient(900px 500px at 15% -10%, rgba(129, 182, 76, 0.10), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(181, 136, 99, 0.10), transparent 55%);
  background-attachment: fixed;
}

.hidden { display: none !important; }
.grow { flex: 1; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
::selection { background: rgba(129, 182, 76, 0.35); }

/* ================= 通用按钮 / 表单 ================= */
.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-3);
  transition: background .15s, transform .08s, border-color .15s, opacity .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #14200b; }
.btn-primary:hover { background: #8fc457; }
.btn-primary:disabled:hover { background: var(--accent); }
.btn-ghost { background: var(--panel-2); border-color: var(--line-2); color: var(--text); }
.btn-ghost:hover { background: var(--panel-3); border-color: #4d4a40; }
.btn-danger { background: rgba(203, 74, 67, .14); color: #e9857f; border-color: rgba(203, 74, 67, .35); }
.btn-danger:hover { background: rgba(203, 74, 67, .24); }
.btn-lg { padding: 14px 20px; font-size: 15px; width: 100%; border-radius: 11px; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--muted); font-size: 17px; line-height: 1;
  display: grid; place-items: center;
}
.icon-btn:hover { color: var(--text); background: var(--panel-3); }
.link-btn {
  background: none; border: 0; color: var(--muted); font-size: 12.5px; padding: 2px 0;
  border-bottom: 1px dashed var(--line-2);
}
.link-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ================= 首页 ================= */
.home-wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 56px;
}
.home-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 9px; }
.brand-mark { width: 30px; height: 30px; flex: none; display: block; line-height: 0; }
.brand-mark svg { width: 30px; height: 30px; display: block; }
.brand-text {
  font-family: var(--serif); font-size: 24px; letter-spacing: 3px; font-weight: 700;
}
.brand.small .brand-mark, .brand.small .brand-mark svg { width: 24px; height: 24px; }
.brand.small .brand-text { font-size: 18px; letter-spacing: 2px; }
.home-sub { color: var(--muted-2); font-size: 13px; letter-spacing: 1.5px; margin: 0; }

.hero { margin: 44px 0 30px; max-width: 720px; }
.hero h1 {
  font-family: var(--serif);
  font-size: clamp(28px, 4.6vw, 44px);
  line-height: 1.28; margin: 0 0 14px; letter-spacing: .5px; font-weight: 700;
}
.hero p { color: var(--muted); font-size: 15px; line-height: 1.75; margin: 0; }

/* 棋种选择 */
.picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 26px; }
.game-tile {
  position: relative; text-align: left; padding: 16px 14px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); transition: border-color .15s, background .15s, transform .12s;
  display: flex; flex-direction: column; gap: 4px; overflow: hidden;
}
.game-tile:hover { border-color: var(--line-2); background: var(--panel-2); transform: translateY(-1px); }
.game-tile.on { border-color: var(--accent); background: linear-gradient(180deg, rgba(129,182,76,.12), rgba(129,182,76,.03)); }
.game-tile.on::after {
  content: ""; position: absolute; inset: 0; border-radius: var(--radius);
  box-shadow: inset 0 0 0 1px rgba(129, 182, 76, .35); pointer-events: none;
}
.tile-icon { position: relative; width: 40px; height: 26px; display: block; margin-bottom: 6px; }
.tile-icon.stones { display: flex; align-items: center; gap: 3px; }
.tile-icon .st {
  width: 17px; height: 17px; border-radius: 50%; display: block; flex: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.55);
}
.tile-icon.two .st { width: 20px; height: 20px; }
.tile-icon .st.b { background: radial-gradient(circle at 34% 28%, #63635f, #0d0d0c 72%); }
.tile-icon .st.w { background: radial-gradient(circle at 34% 28%, #fff, #d5d1c6 74%); }
.tile-icon.disc {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 36% 30%, #fdf3dc, #e0c99e);
  border: 1.5px solid #b98b57; color: #b3311f; font-family: "KaiTi", "STKaiti", var(--serif);
  font-size: 15px; font-weight: 700;
}
.tile-icon.glyph {
  font-size: 26px; line-height: 26px; height: 26px; color: var(--text); font-family: var(--serif);
  display: grid; place-items: center; width: 34px;
}
.tile-name { font-size: 15px; font-weight: 700; letter-spacing: .5px; }
.tile-desc { font-size: 11.5px; color: var(--muted-2); letter-spacing: .3px; }

/* 创建 / 加入 */
.start-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; align-items: start; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 16px; font-size: 15px; font-weight: 700; letter-spacing: 1px; color: var(--muted); }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 12px; color: var(--muted-2); margin-bottom: 7px; letter-spacing: .6px; }
.field input {
  width: 100%; padding: 12px 13px; border-radius: 10px; border: 1px solid var(--line-2);
  background: #14130f; color: var(--text); font-size: 15px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(129,182,76,.14); }
.code-input {
  font-family: var(--mono); font-size: 22px !important; letter-spacing: 6px; text-transform: uppercase;
  text-align: center; font-weight: 700;
}

.settings { display: grid; gap: 12px; margin-bottom: 18px; }
.setting-row { display: flex; align-items: center; gap: 12px; }
.setting-row[hidden] { display: none; }
.setting-label { font-size: 12px; color: var(--muted-2); width: 34px; flex: none; letter-spacing: .6px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  border: 1px solid var(--line-2); background: transparent; color: var(--muted);
  padding: 6px 10px; border-radius: 8px; font-size: 12.5px; transition: all .13s;
}
.seg button:hover { color: var(--text); border-color: #4d4a40; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: #14200b; font-weight: 700; }
.seg button[hidden] { display: none; }

.hint { font-size: 12px; color: var(--muted-2); line-height: 1.7; margin: 12px 0 0; }
.divider { position: relative; text-align: center; margin: 20px 0 4px; }
.divider::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--line); }
.divider span { position: relative; background: var(--panel); padding: 0 10px; font-size: 11.5px; color: var(--muted-2); }
.join-result { font-size: 13px; color: var(--danger); margin-top: 10px; min-height: 18px; }
.join-result.ok { color: var(--accent); }

.home-foot { margin-top: 34px; text-align: center; color: var(--muted-2); font-size: 12px; letter-spacing: .8px; }

/* ================= 对局页 ================= */
.screen-room { min-height: 100dvh; display: flex; flex-direction: column; }
.room-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  background: rgba(20, 19, 15, .86); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.room-head-left, .room-head-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.room-game {
  font-size: 13px; color: var(--muted); padding-left: 12px; border-left: 1px solid var(--line-2);
  letter-spacing: .8px; white-space: nowrap;
}
.code-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 9px;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text);
}
.code-chip:hover { border-color: var(--accent); }
.code-chip-label { font-size: 11px; color: var(--muted-2); letter-spacing: .5px; }
.code-chip-value { font-family: var(--mono); font-size: 15px; font-weight: 700; letter-spacing: 2.5px; color: var(--accent); }
.code-chip svg { color: var(--muted-2); }

.game-layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 336px;
  gap: 22px; padding: 20px 22px 32px; max-width: 1180px; width: 100%; margin: 0 auto; align-items: start;
}

.board-area { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

/* 棋手卡 */
.pcard {
  display: flex; align-items: center; gap: 11px; padding: 9px 13px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  transition: border-color .2s, background .2s;
}
.pcard.active { border-color: rgba(129,182,76,.6); background: rgba(129,182,76,.07); }
.pcard-avatar {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--panel-3); color: var(--text); font-family: var(--serif); font-size: 17px; font-weight: 700; flex: none;
  border: 1px solid var(--line-2);
}
.pcard-main { min-width: 0; flex: 1; }
.pcard-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard-sub { font-size: 11.5px; color: var(--muted-2); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.pcard-clock {
  font-family: var(--mono); font-size: 17px; font-variant-numeric: tabular-nums;
  padding: 3px 9px; border-radius: 7px; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line-2);
}
.pcard-clock.low { color: #f08a84; }
.pcard-clock.running { color: var(--text); background: #3a3830; border-color: #4d4a40; }
.dot-conn { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; }
.dot-conn.off { background: var(--danger); }

/* 棋盘 */
.board-wrap {
  position: relative; width: 100%; aspect-ratio: 1 / 1; max-height: min(72dvh, 640px);
  border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
  background: #1a1914; margin: 0 auto;
  touch-action: manipulation;
}
.board-wrap canvas { display: block; width: 100%; height: 100%; }
.board-veil {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(12, 11, 8, .74); backdrop-filter: blur(3px); padding: 18px; z-index: 6;
}
.veil-inner { width: 100%; max-width: 320px; text-align: center; }
.wait-box { display: grid; gap: 12px; justify-items: center; }
.wait-title { font-size: 12.5px; color: var(--muted); letter-spacing: 2px; }
.wait-code {
  font-family: var(--mono); font-size: clamp(30px, 8vw, 44px); font-weight: 700; letter-spacing: 10px;
  color: var(--accent); padding: 10px 16px 10px 26px; border-radius: 12px;
  background: rgba(129, 182, 76, .10); border: 1px dashed rgba(129, 182, 76, .5);
}
.wait-tip { font-size: 13px; color: var(--muted); line-height: 1.7; margin: 0; }
.wait-link { font-size: 11.5px; color: var(--muted-2); word-break: break-all; max-width: 100%; }
.wait-dots { display: flex; gap: 5px; margin-top: 4px; }
.wait-dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted-2); display: block;
  animation: bounce 1.2s infinite ease-in-out;
}
.wait-dots i:nth-child(2) { animation-delay: .15s; }
.wait-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

.result-box { display: grid; gap: 8px; justify-items: center; }
.result-title { font-family: var(--serif); font-size: clamp(22px, 5vw, 30px); font-weight: 700; letter-spacing: 2px; }
.result-title.win { color: var(--accent); }
.result-title.lose { color: #e9857f; }
.result-title.draw { color: var(--muted); }
.result-sub { font-size: 13px; color: var(--muted); }
.result-actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; justify-content: center; }

/* 升变选择 */
.promo {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(12, 11, 8, .6); z-index: 8;
}
.promo-inner {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line-2); box-shadow: var(--shadow);
}
.promo-label { font-size: 12px; color: var(--muted); margin-right: 4px; }
.promo-btn {
  width: 46px; height: 46px; border-radius: 9px; font-size: 26px; line-height: 1;
  background: #f0d9b5; color: #1b1a15; border: 1px solid #b58863;
}
.promo-btn:hover { background: #fff; }

/* 状态条 */
.status-bar {
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted);
  padding: 2px 4px; min-height: 20px;
}
.turn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted-2); flex: none; }
.turn-dot.black { background: #111; box-shadow: 0 0 0 1px #555; }
.turn-dot.white { background: #f4f1e8; }
.turn-dot.red { background: #c0392b; }
.turn-dot.live { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.spectator-tag {
  font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--panel-3);
  color: var(--muted); border: 1px solid var(--line-2);
}

/* 侧栏 */
.side {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden; min-height: 320px;
  max-height: calc(100dvh - 120px); position: sticky; top: 76px;
}
.side-tabs { display: flex; border-bottom: 1px solid var(--line); }
.side-tabs button {
  flex: 1; padding: 12px; background: none; border: 0; color: var(--muted-2);
  font-size: 13px; font-weight: 600; letter-spacing: 1px; position: relative;
}
.side-tabs button.on { color: var(--text); }
.side-tabs button.on::after {
  content: ""; position: absolute; left: 22%; right: 22%; bottom: 0; height: 2px;
  background: var(--accent); border-radius: 2px;
}
.tab-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.moves-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px 8px; border-bottom: 1px solid var(--line);
}
.moves-count { font-size: 12px; color: var(--muted-2); letter-spacing: .5px; }
.moves-list {
  flex: 1; overflow-y: auto; padding: 6px 8px 10px; min-height: 120px;
  max-height: 340px; scrollbar-width: thin;
}
.moves-list::-webkit-scrollbar, .chat-list::-webkit-scrollbar { width: 8px; }
.moves-list::-webkit-scrollbar-thumb, .chat-list::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 8px; }
.move-row { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 4px; align-items: center; }
.move-row .no { color: var(--muted-2); font-size: 11.5px; text-align: right; padding-right: 6px; font-family: var(--mono); }
.move-cell {
  font-size: 13.5px; padding: 4px 8px; border-radius: 6px; color: var(--text);
  font-family: var(--mono); letter-spacing: .3px;
}
.move-cell:last-child { grid-column: auto; }
.move-cell.cur { background: rgba(129,182,76,.16); color: #cbe3ab; }
.move-cell.empty { color: transparent; }
.empty-note { color: var(--muted-2); font-size: 12.5px; text-align: center; padding: 26px 0; }

.go-score {
  border-top: 1px solid var(--line); padding: 10px 14px; font-size: 12.5px; color: var(--muted);
  display: grid; gap: 6px;
}
.go-score b { color: var(--text); font-family: var(--mono); }
.go-score-btns { display: flex; gap: 6px; margin-top: 4px; }

.chat-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 380px; }
.chat-msg { font-size: 13px; line-height: 1.5; word-break: break-word; }
.chat-msg .who { color: var(--accent); font-weight: 600; margin-right: 5px; }
.chat-msg.mine .who { color: #cbe3ab; }
.chat-msg.system { color: var(--muted-2); font-size: 12px; font-style: normal; text-align: center; padding: 2px 0; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input {
  flex: 1; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line-2);
  background: #14130f; color: var(--text); font-size: 13px; outline: none; min-width: 0;
}
.chat-form input:focus { border-color: var(--accent); }

.actions { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.actions .btn { flex: 1; min-width: 84px; }
.side-note { padding: 0 12px 12px; font-size: 11.5px; color: var(--muted-2); line-height: 1.6; }

/* Toast */
.toast-wrap {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; align-items: center;
}
.toast {
  background: #2c2a24; color: var(--text); border: 1px solid var(--line-2);
  padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow);
  animation: toastIn .18s ease-out; max-width: 86vw; text-align: center;
}
.toast.good { border-color: rgba(129,182,76,.5); }
.toast.bad { border-color: rgba(203,74,67,.6); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ================= 响应式 ================= */
@media (max-width: 980px) {
  .game-layout { grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 14px 12px 28px; }
  .side { position: static; max-height: none; min-height: auto; }
  .tab-panel { flex: none; }
  .board-wrap { max-height: none; max-width: 100% !important; }
  .moves-list { max-height: 200px; }
  .chat-list { max-height: 240px; }
  .picker { grid-template-columns: repeat(2, 1fr); }
  .start-grid { grid-template-columns: 1fr; }
  .hero { margin: 28px 0 22px; }
  .home-wrap { padding: 20px 16px 40px; }
  .room-head { padding: 10px 12px; }
  .btn-copy-link, #btn-copy-link { display: none; }
}
@media (max-width: 560px) {
  .room-game { display: none; }
  .code-chip-label { display: none; }
  .card { padding: 18px; }
  .pcard-clock { font-size: 15px; padding: 2px 7px; }
  .board-wrap { border-radius: 10px; }
  .actions .btn { min-width: 0; }
}
