:root {
  --light: #f0d9b5;
  --dark: #b58863;
  --board-size: min(88vw, 560px);
  --cell: calc(var(--board-size) / 8);
  --accent: #2e7d32;
  --accent-soft: #66bb6a;
  --sel: #f7ec5e;
  --check: #e74c3c;
  --bg: #faf7f2;
  --panel: #ffffff;
  --ink: #2b2b2b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", Segoe UI, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

.topbar {
  text-align: center;
  padding: 18px 12px 6px;
}
.topbar h1 { margin: 0; font-size: 1.7rem; }
.subtitle { margin: 4px 0 0; color: #8a7a66; font-size: .95rem; }

/* Tabs */
.tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 14px 12px;
  flex-wrap: wrap;
}
.tab {
  border: none;
  background: #ece3d6;
  color: #5b4a35;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 1rem;
  cursor: pointer;
  transition: all .15s;
}
.tab:hover { background: #e0d3bf; }
.tab.active { background: var(--dark); color: #fff; }

/* Layout */
.layout {
  display: flex;
  gap: 28px;
  justify-content: center;
  align-items: flex-start;
  padding: 8px 16px 48px;
  flex-wrap: wrap;
}

/* Board */
.board-area { display: flex; flex-direction: column; align-items: center; }
.board-wrap {
  position: relative;
  padding-left: 22px;
  padding-bottom: 22px;
}
.board {
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 3px solid var(--dark);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.72);
  line-height: 1;
  cursor: pointer;
  user-select: none;
}
.cell.light { background: var(--light); }
.cell.dark  { background: var(--dark); }
.piece { pointer-events: none; }
.piece.white { color: #fff; text-shadow: 0 0 2px #000, 0 1px 2px rgba(0,0,0,.6); }
.piece.black { color: #2b2b2b; text-shadow: 0 0 1px #000; }

/* highlights */
.cell.selected { box-shadow: inset 0 0 0 4px var(--sel); }
.cell.move-dot::after {
  content: "";
  position: absolute;
  width: 28%; height: 28%;
  border-radius: 50%;
  background: rgba(46,125,50,.55);
}
.cell.capture-ring::before {
  content: "";
  position: absolute;
  inset: 8%;
  border: 5px solid rgba(46,125,50,.6);
  border-radius: 50%;
}
.cell.last-move { box-shadow: inset 0 0 0 4px rgba(102,187,106,.7); }
.cell.in-check { background: var(--check) !important; }

/* coords */
.coords { position: absolute; color: #8a7a66; font-size: .7rem; font-weight: 600; }
.coords.ranks {
  left: 0; top: 0;
  height: var(--board-size);
  display: flex; flex-direction: column;
  justify-content: space-around;
  width: 18px; text-align: center;
}
.coords.files {
  left: 22px; bottom: 0;
  width: var(--board-size);
  display: flex; justify-content: space-around;
  height: 18px;
}

.turn-banner {
  margin-top: 14px;
  padding: 8px 20px;
  background: var(--panel);
  border-radius: 8px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.turn-banner.win { background: var(--accent); color: #fff; }

/* Panel */
.panel {
  width: min(92vw, 380px);
  background: var(--panel);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 18px rgba(0,0,0,.08);
}
.panel h2 { margin-top: 0; }
.hint { color: #7a6a55; font-size: .9rem; }
.hidden { display: none; }

.piece-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.piece-btn {
  flex: 1 1 30%;
  border: 2px solid #e6dccb;
  background: #fbf6ee;
  border-radius: 10px;
  padding: 10px 4px;
  cursor: pointer;
  text-align: center;
  transition: all .15s;
}
.piece-btn:hover { border-color: var(--dark); }
.piece-btn.active { border-color: var(--accent); background: #eaf6ea; }
.piece-btn .glyph { font-size: 2rem; line-height: 1; display: block; }
.piece-btn .label { font-size: .82rem; color: #5b4a35; }

.detail-card {
  background: #fbf6ee;
  border-radius: 10px;
  padding: 14px 16px;
  border: 1px solid #ece3d6;
}
.detail-card h3 { margin: 0 0 6px; }
.detail-card .value { color: var(--accent); font-weight: 700; }

.rules-list .rule {
  background: #fbf6ee;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 10px;
  border: 1px solid #ece3d6;
}
.rules-list .rule h3 { margin: 0 0 4px; font-size: 1rem; }
.rules-list .rule p { margin: 0; font-size: .9rem; color: #5b4a35; }

/* controls */
.controls { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.switch-row { display: flex; align-items: center; gap: 8px; font-size: .92rem; cursor: pointer; }
.btn {
  border: none;
  background: var(--dark);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .95rem;
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: #ece3d6; color: #5b4a35; }

.status-box {
  background: #eaf6ea;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  min-height: 44px;
  font-size: .92rem;
}
.status-box.warn { background: #fdeaea; }

.captured { font-size: 1.4rem; margin-bottom: 12px; min-height: 28px; }
.captured > div { font-size: .85rem; color: #7a6a55; margin-bottom: 4px; }
.captured span { font-size: 1.5rem; }

.move-log {
  max-height: 220px;
  overflow-y: auto;
  margin: 0;
  padding-left: 28px;
  font-size: .9rem;
}
.move-log li { margin-bottom: 2px; }

@media (max-width: 900px) {
  .layout { gap: 20px; }
}
