* { box-sizing: border-box; margin: 0; padding: 0; }
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
button, .seg button, .controls button, .km, #board, .modal-card { touch-action: manipulation; }
:root {
  --wood: #e9c887; --wood-dark: #d8a85a; --line: #7a5230;
  --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; padding: 10px 16px;
}
.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; cursor: pointer;
}
.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); } }
.result-banner {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; padding: 8px 22px; border-radius: 20px;
  font-size: 16px; font-weight: 600; z-index: 6; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

.side { width: 260px; max-width: 100%; display: flex; flex-direction: column; gap: 14px; }
.status-card {
  background: var(--panel); border-radius: 14px; padding: 16px;
  box-shadow: 0 4px 18px rgba(120, 90, 40, 0.14);
}
.turn { font-size: 16px; font-weight: 600; margin-bottom: 10px; }
.meta-row { display: flex; gap: 8px; }
.km {
  flex: 1; text-align: center; font-size: 12px; padding: 6px 4px;
  background: #f3ead5; border-radius: 8px; color: #6a5a3e;
}
.hint-line { font-size: 12px; color: #1e9e5a; margin-top: 10px; min-height: 16px; }

.controls { display: flex; gap: 8px; }
.controls button {
  flex: 1; padding: 10px 4px; border: 1.5px solid var(--wood-dark); background: #fff;
  border-radius: 10px; font-size: 13px; cursor: pointer; color: var(--ink); transition: all .15s;
}
.controls button:hover { background: #f3ead5; }

.moves {
  background: var(--panel); border-radius: 14px; padding: 14px 16px;
  box-shadow: 0 4px 18px rgba(120, 90, 40, 0.14); max-height: 280px; overflow-y: auto;
}
.moves h3 { font-size: 14px; margin-bottom: 8px; color: #6a5a3e; }
.moves ol { list-style: none; font-size: 13px; }
.moves ol li { padding: 3px 2px; border-bottom: 1px dashed #e6dcc4; color: #4a3a22; }

.modal {
  position: fixed; inset: 0; background: rgba(40, 28, 14, .55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-card {
  background: var(--panel); border-radius: 16px; padding: 28px 26px; max-width: 360px;
  text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.modal-card h2 { font-size: 20px; margin-bottom: 12px; }
.modal-card p { font-size: 14px; color: #6a5a3e; margin-bottom: 20px; line-height: 1.6; }

@media (max-width: 680px) {
  .side { width: 100%; }
  .game { gap: 14px; }
}
