/* ============ 基础 ============ */
:root {
  --bg: #14171e;
  --bg-soft: #1c2029;
  --card: #232836;
  --card-hi: #2b3142;
  --line: #333a4d;
  --text: #e8e6e1;
  --text-dim: #9aa0ae;
  --accent: #c9a45c;
  --accent-deep: #a9805a;
  --red: #c94f42;
  --green: #58b368;
  --danger: #d9534f;
  --radius: 16px;
  --wood1: #d8b98a;
  --wood2: #c9a875;
  --line-wood: #9a7b52;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: radial-gradient(120% 100% at 50% 0%, #1d222e 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input {
  font-family: inherit; color: var(--text);
  background: var(--bg-soft); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 13px 14px; font-size: 16px; outline: none; width: 100%;
}
input:focus { border-color: var(--accent); }

/* ============ 首页 ============ */
.screen { min-height: 100%; }
#home {
  display: flex; align-items: center; justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  min-height: 100dvh;
}
.home-card {
  width: 100%; max-width: 380px; text-align: center;
  background: linear-gradient(160deg, var(--card) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line); border-radius: 24px;
  padding: 36px 26px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.logo-piece {
  width: 84px; height: 84px; margin: 0 auto 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #f4e3bd, var(--wood1) 55%, #b9915e);
  border: 3px solid var(--accent-deep);
  box-shadow: inset 0 0 0 5px rgba(168,52,42,.0), 0 8px 24px rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 700; color: #a8342a;
  font-family: "STKaiti", "KaiTi", serif;
  position: relative;
}
.logo-piece::after {
  content: ""; position: absolute; inset: 5px; border-radius: 50%;
  border: 2px solid rgba(168,52,42,.75);
}
.home-card h1 { font-size: 30px; letter-spacing: 6px; font-weight: 700; }
.home-card .sub { color: var(--text-dim); font-size: 13px; margin: 8px 0 26px; letter-spacing: 1px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.btn {
  background: var(--card-hi); border: 1px solid var(--line);
  border-radius: 12px; padding: 13px; font-size: 16px; font-weight: 600;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(135deg, #c9a45c, #b2884a);
  color: #20180c; border: none; box-shadow: 0 6px 18px rgba(201,164,92,.25);
}
.btn.danger { background: var(--danger); color: #fff; border: none; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-dim); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; text-align: center; letter-spacing: 6px; font-weight: 700; text-transform: uppercase; font-size: 18px; }
.join-row .btn { width: 86px; }
.tiny { color: var(--text-dim); font-size: 12px; margin-top: 18px; }
.ai-btn { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 14px; color: var(--accent); border-color: rgba(201,164,92,.45); }
.ai-btn svg { width: 20px; height: 20px; }
.ai-title { font-size: 18px; font-weight: 700; margin-bottom: 18px; }
.ai-opts { display: flex; flex-direction: column; gap: 10px; }
.ai-opt { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-radius: 12px; background: var(--bg-soft); border: 1.5px solid var(--line); font-size: 15px; transition: transform .08s ease; }
.ai-opt:active { transform: scale(.97); }
.ai-opt b { font-size: 16px; }
.ai-opt span { color: var(--text-dim); font-size: 12px; }

/* ============ 对局页 ============ */
#game {
  display: flex; flex-direction: column;
  height: 100dvh; height: 100svh;
  padding: calc(env(safe-area-inset-top) + 6px) 10px calc(env(safe-area-inset-bottom) + 8px);
  gap: 8px; max-width: 560px; margin: 0 auto;
}
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 2px 2px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  background: var(--card); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 21px; height: 21px; color: var(--text-dim); }
.code-chip {
  flex: 1; height: 40px; border-radius: 12px;
  background: var(--card); border: 1px dashed var(--accent-deep);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 17px; font-weight: 800; letter-spacing: 5px;
}
.code-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); letter-spacing: 0; }
.code-chip .dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.code-chip .share-ic { width: 16px; height: 16px; color: var(--accent); letter-spacing: 0; }

.player-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 8px 12px; min-height: 58px;
}
.player-bar.me { border-color: rgba(201,164,92,.35); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; font-family: "STKaiti","KaiTi",serif;
}
.avatar.red { background: radial-gradient(circle at 32% 28%, #f4e3bd, var(--wood1)); color: #a8342a; border: 2px solid var(--accent-deep); }
.avatar.black { background: radial-gradient(circle at 32% 28%, #6a7080, #3c4252); color: #e8e6e1; border: 2px solid #23283a; }
.pinfo { flex: 1; min-width: 0; }
.pname { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pstatus { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.turn-flag {
  font-size: 11px; padding: 4px 9px; border-radius: 999px; flex: none;
  background: var(--card-hi); color: var(--text-dim); border: 1px solid var(--line);
  opacity: 0; transition: opacity .2s;
}
.turn-flag.on {
  opacity: 1; color: #20180c; background: var(--accent); border-color: var(--accent);
  font-weight: 700; animation: pulse 1.6s ease infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(201,164,92,.15); } }

/* ============ 棋盘 ============ */
.board-wrap { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#board {
  display: block; border-radius: 14px;
  box-shadow: 0 16px 44px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.4);
  touch-action: manipulation;
}

/* 回放条 */
.preview-bar {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(20,23,30,.88); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 8px;
}
.preview-bar span { font-size: 12px; color: var(--accent); min-width: 74px; text-align: center; }
.mini-btn {
  min-width: 34px; height: 30px; padding: 0 10px; border-radius: 999px;
  background: var(--card-hi); border: 1px solid var(--line);
  color: var(--text); font-size: 15px; display: inline-flex; align-items: center; justify-content: center;
}
.mini-btn.ok { color: var(--green); border-color: rgba(88,179,104,.4); font-weight: 700; }
.mini-btn.no { color: var(--danger); border-color: rgba(217,83,79,.4); font-weight: 700; }

/* 将军闪字 */
.check-flash {
  position: absolute; top: 42%; left: 50%; transform: translate(-50%,-50%);
  font-size: 44px; font-weight: 900; color: var(--red); letter-spacing: 8px;
  text-shadow: 0 2px 14px rgba(0,0,0,.6);
  opacity: 0; pointer-events: none;
}
.check-flash.show { animation: checkPop 1.1s ease forwards; }
@keyframes checkPop {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(1.8); }
  18% { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-58%) scale(1.05); }
}

/* ============ 操作区 ============ */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(201,164,92,.12); border: 1px solid rgba(201,164,92,.4);
  border-radius: 12px; padding: 9px 12px; font-size: 14px;
}
.banner-btns { display: flex; gap: 8px; }
.actions { display: flex; gap: 8px; }
.act {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: 13px;
  padding: 9px 2px 8px; font-size: 12px; color: var(--text);
  transition: transform .08s ease;
}
.act:active { transform: scale(.94); }
.act svg { width: 21px; height: 21px; color: var(--accent); }
.act:disabled { opacity: .38; }

/* 棋谱 */
.movelist {
  background: var(--card); border: 1px solid var(--line); border-radius: 13px;
  max-height: 150px; display: flex; flex-direction: column; overflow: hidden;
}
.movelist-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; font-size: 13px; color: var(--text-dim); border-bottom: 1px solid var(--line);
}
.move-chips { overflow-y: auto; padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; }
.move-chips .chip {
  font-size: 12.5px; padding: 4px 8px; border-radius: 8px;
  background: var(--bg-soft); border: 1px solid var(--line); white-space: nowrap;
}
.move-chips .chip b { color: var(--text-dim); font-weight: 400; margin-right: 3px; font-size: 11px; }
.move-chips .chip.last { border-color: var(--accent); color: var(--accent); }

.viewer-tip { text-align: center; font-size: 12px; color: var(--text-dim); padding: 4px 0; }

/* ============ 弹窗 ============ */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10,12,16,.72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  width: 100%; max-width: 330px; text-align: center;
  background: linear-gradient(160deg, var(--card), var(--bg-soft));
  border: 1px solid var(--line); border-radius: 22px; padding: 30px 24px 22px;
  box-shadow: 0 24px 70px rgba(0,0,0,.6);
  animation: rise .25s ease;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.result-big {
  font-size: 64px; font-weight: 900; margin-bottom: 8px;
  font-family: "STKaiti","KaiTi",serif; color: var(--accent);
}
.result-big.win { color: var(--green); }
.result-big.lose { color: var(--danger); }
.result-sub { color: var(--text-dim); font-size: 15px; margin-bottom: 24px; }
.result-btns { display: flex; flex-direction: column; gap: 10px; }
.confirm-text { font-size: 17px; line-height: 1.6; margin-bottom: 22px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px);
  transform: translateX(-50%); z-index: 60;
  background: rgba(28,32,41,.95); border: 1px solid var(--line);
  color: var(--text); font-size: 14px; border-radius: 999px; padding: 10px 20px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); white-space: nowrap;
  animation: rise .2s ease;
}

/* 桌面端适配：保持居中，限制宽度 */
@media (min-width: 700px) {
  #game { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
