* { box-sizing: border-box; margin: 0; padding: 0; }
/* 禁掉移动端双击缩放(iOS Safari 忽略 user-scalable, 用 touch-action 才有效);
   复盘逐手点击时不会再误触发整页放大. 文本仍可正常选择. */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
button, .seg button, .controls button, .review-nav button,
.km, .moves ol.clickable li, #board, .modal-card { touch-action: manipulation; }
:root {
  --wood: #e9c887; --wood-dark: #d8a85a; --line: #7a5230;
  --red: #c0392b; --black: #2c3e50; --ink: #3a2a18;
  --panel: #fffdf7; --accent: #c0392b;
}
body {
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: linear-gradient(135deg, #f5efe2 0%, #e8dcc4 100%);
  color: var(--ink); min-height: 100vh; -webkit-font-smoothing: antialiased;
}
.app { max-width: 980px; margin: 0 auto; padding: 18px 14px 40px; }
.topbar { text-align: center; margin-bottom: 18px; }
.topbar h1 { font-size: 26px; letter-spacing: 2px; color: var(--ink); }
.topbar .sub { font-size: 13px; color: #8a7a5e; margin-top: 4px; }
.hidden { display: none !important; }

/* 开局设置卡 */
.setup { display: flex; justify-content: center; padding-top: 20px; }
.setup-card {
  background: var(--panel); border-radius: 16px; padding: 28px 26px;
  box-shadow: 0 8px 30px rgba(120, 90, 40, 0.18); width: 100%; max-width: 380px;
}
.setup-card h2 { font-size: 19px; margin-bottom: 18px; text-align: center; }
.setup-card label { display: block; font-size: 13px; color: #7a6a4e; margin: 14px 0 8px; }
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; padding: 10px 6px; border: 1.5px solid var(--wood-dark); background: #fff;
  border-radius: 10px; font-size: 14px; cursor: pointer; color: var(--ink);
  transition: all .15s;
}
.seg button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.primary {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  cursor: pointer; font-size: 15px; transition: filter .15s;
}
.primary:hover { filter: brightness(1.08); }
.big { width: 100%; padding: 14px; margin-top: 22px; font-size: 16px; letter-spacing: 1px; }
.hist-line { font-size: 12px; color: #9a8a6e; margin-top: 14px; text-align: center; min-height: 16px; }

/* 对局区 */
.game { display: flex; gap: 22px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.board-wrap { position: relative; }
#board {
  background: var(--wood); border-radius: 8px; box-shadow: 0 6px 24px rgba(120, 80, 30, .28);
  touch-action: none; max-width: 100%; height: auto;
}
.ai-think {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(44, 30, 16, .86); color: #fff; padding: 12px 20px; border-radius: 24px;
  font-size: 14px; display: flex; align-items: center; gap: 10px; z-index: 5;
}
.spinner {
  width: 15px; height: 15px; border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 侧栏 */
.panel { width: 270px; background: var(--panel); border-radius: 14px; padding: 16px;
  box-shadow: 0 6px 24px rgba(120, 90, 40, .14); }
.status { font-size: 16px; font-weight: 600; text-align: center; padding: 10px;
  border-radius: 8px; background: #f3ead6; margin-bottom: 12px; }
.status.red { color: var(--red); } .status.black { color: var(--black); }

/* 双方对弈钟 */
.clocks { display: flex; gap: 8px; margin-bottom: 12px; }
.clock { flex: 1; background: #f3ead6; border: 1.5px solid transparent; border-radius: 8px;
  padding: 8px 6px; text-align: center; transition: all .15s; }
.clock .ck-label { display: block; font-size: 11px; color: #8a7a5e; margin-bottom: 2px; }
.clock .ck-time { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: 1px; color: #6a5a3e; }
#clockR.active { border-color: var(--red); background: #fbeae7; }
#clockR.active .ck-time { color: var(--red); }
#clockB.active { border-color: var(--black); background: #e9edf1; }
#clockB.active .ck-time { color: var(--black); }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.controls button {
  padding: 10px 6px; border: 1.5px solid var(--wood-dark); background: #fff; border-radius: 9px;
  font-size: 13px; cursor: pointer; color: var(--ink); transition: all .15s;
}
.controls button:hover:not(:disabled) { background: #f7efdd; }
.controls button:disabled { opacity: .45; cursor: not-allowed; }
#hintBtn { border-color: #d4a017; color: #9a6b00; }
#drawBtn { border-color: #2e7d32; color: #2e7d32; }
.hint-box {
  background: #fff8e6; border: 1px solid #e8d089; border-radius: 10px; padding: 12px;
  font-size: 13px; line-height: 1.6; margin-bottom: 12px;
}
.hint-box .hb-move { font-weight: 700; color: var(--accent); font-size: 15px; }
.hint-box .hb-tip { margin-top: 8px; color: #8a6a00; border-top: 1px dashed #e0c878; padding-top: 8px; }
.moves-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.moves h3 { font-size: 13px; color: #7a6a4e; }
.review-nav { display: flex; align-items: center; gap: 6px; }
.review-nav button {
  border: 1.5px solid var(--wood-dark); background: #fff; border-radius: 7px;
  padding: 2px 9px; font-size: 13px; cursor: pointer; color: var(--ink); line-height: 1.5;
}
.review-nav button:hover:not(:disabled) { background: #f7efdd; }
.review-nav button:disabled { opacity: .4; cursor: not-allowed; }
.review-nav #rvPos { font-size: 12px; color: #8a7a5e; min-width: 48px; text-align: center; }
.moves ol { list-style: none; max-height: 280px; overflow-y: auto; font-size: 13px; }
.moves li { padding: 4px 8px; border-radius: 6px; display: flex; gap: 8px; }
.moves li:nth-child(odd) { background: #f6efdf; }
.moves ol.clickable li { cursor: pointer; }
.moves ol.clickable li:hover { background: #efe4cb; }
.moves li.active { background: #d8a85a !important; color: #fff; font-weight: 600; }
.moves li.active .ply, .moves li.active .r, .moves li.active .b { color: #fff; }
.moves li .ply { color: #aa9a7e; min-width: 26px; }
.moves li .r { color: var(--red); } .moves li .b { color: var(--black); }
.moves li .blunder-dot { margin-left: auto; color: #c0392b; font-size: 10px; }
.moves li.active .blunder-dot { color: #fff; }

/* 复盘浮窗: 无遮罩, 不挡棋盘/着法, 可拖到一边边看评估边点步骤回放 */
.modal { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.modal-card { pointer-events: auto; position: fixed; top: 72px; right: 24px;
  background: var(--panel); border-radius: 16px; padding: 24px; max-width: 400px;
  width: 92%; max-height: 82vh; overflow-y: auto;
  box-shadow: 0 14px 44px rgba(40, 28, 14, .42); border: 1px solid #e3d3a8; }
.modal-drag { cursor: move; user-select: none; touch-action: none;
  margin: -24px -24px 14px; padding: 11px 16px; background: #f1e6cd;
  border-radius: 15px 15px 0 0; font-size: 12px; color: #8a7a5e; }
.close { position: absolute; top: 8px; right: 14px; border: none; background: none;
  font-size: 24px; cursor: pointer; color: #9a8a6e; line-height: 1; z-index: 1; }
.mini { position: absolute; top: 8px; right: 42px; border: none; background: none;
  font-size: 24px; cursor: pointer; color: #9a8a6e; line-height: 1; z-index: 1; }
.modal-card.collapsed { max-height: none; overflow: visible; }
.modal-card.collapsed #reviewBody { display: none; }
.rv-head { text-align: center; margin-bottom: 16px; }
.rv-level { font-size: 22px; font-weight: 700; color: var(--accent); }
.rv-score { font-size: 40px; font-weight: 800; color: var(--ink); }
.rv-score small { font-size: 16px; color: #9a8a6e; }
.rv-summary { background: #f3ead6; border-radius: 10px; padding: 12px; font-size: 14px;
  line-height: 1.6; margin-bottom: 14px; }
.rv-sec { margin-bottom: 14px; }
.rv-sec h4 { font-size: 14px; margin-bottom: 6px; }
.rv-sec.good h4 { color: #2e7d32; } .rv-sec.bad h4 { color: #c0392b; } .rv-sec.adv h4 { color: #d4a017; }
.rv-sec.key h4 { color: #2c6fb0; }
.km-list { list-style: none; }
.km { cursor: pointer; padding: 7px 9px; border-radius: 8px; margin-bottom: 5px;
  background: #faf6ec; border-left: 3px solid #c8b88a; transition: background .15s; }
.km:hover { background: #efe4cb; }
.km.good { border-left-color: #2e7d32; } .km.bad { border-left-color: #c0392b; } .km.adv { border-left-color: #d4a017; }
.km .km-h { display: block; font-size: 13px; font-weight: 600; color: var(--accent); }
.km .km-c { display: block; font-size: 12px; color: #6a5a3e; line-height: 1.5; margin-top: 2px; }
.rv-sec ul { list-style: none; }
.rv-sec li { font-size: 13px; line-height: 1.6; padding: 4px 0 4px 18px; position: relative; }
.rv-sec li::before { content: "•"; position: absolute; left: 4px; }

@media (max-width: 640px) {
  .app { padding: 10px 8px 28px; }
  .topbar { margin-bottom: 12px; }
  .topbar h1 { font-size: 21px; letter-spacing: 1px; }
  .topbar .sub { font-size: 11px; }

  .game { gap: 14px; flex-direction: column; align-items: stretch; }
  .board-wrap { width: 100%; }
  #board { width: 100%; display: block; }
  .panel { width: 100%; max-width: 100%; }

  /* 5 个操作按钮: 手机上 3 列, 触控区更大 */
  .controls { grid-template-columns: repeat(3, 1fr); gap: 7px; }
  .controls button { padding: 13px 4px; font-size: 13px; }
  .clock .ck-time { font-size: 22px; }

  .moves ol { max-height: 200px; }

  /* 复盘窗在手机上变底部抽屉, 不挡棋盘 */
  .modal-card { top: auto; bottom: 8px; left: 8px; right: 8px; width: auto;
    max-width: none; max-height: 48vh; padding: 18px; }
  .modal-drag { margin: -18px -18px 12px; }
  .modal-card.collapsed { bottom: 8px; }
  .rv-score { font-size: 32px; } .rv-level { font-size: 19px; }

  /* 复盘中(抽屉展开): 棋盘缩小并吸顶, 与下方文字同屏, 点击棋盘可回放 */
  .app.review-open .board-wrap {
    position: sticky; top: 4px; z-index: 40;
    max-width: 56vw; margin: 0 auto;
  }
  .app.review-open #board { width: 100%; }
  /* 给底部抽屉腾出空间, 文字/着法不被遮住 */
  .app.review-open { padding-bottom: 50vh; }
}
