:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --text: #22201c;
  --muted: #6b665d;
  --border: #e0dbd0;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --light-sq: #ebd9b4;
  --dark-sq: #b18762;
  --hl: rgba(255, 214, 64, 0.55);
  --sel: rgba(47, 111, 79, 0.55);
  --bar: #2f6f4f;
  --bar-bg: #ece7dc;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --card: #262421;
    --text: #ece8e1;
    --muted: #a39d92;
    --border: #3a3733;
    --accent: #5fb38a;
    --accent-ink: #10231a;
    --light-sq: #d9c39b;
    --dark-sq: #9c7552;
    --bar: #5fb38a;
    --bar-bg: #34312d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header { max-width: 1100px; margin: 0 auto; padding: 24px 16px 8px; }
h1 { margin: 0 0 4px; font-size: 1.7rem; }
.sub { margin: 0; color: var(--muted); max-width: 70ch; }
h2 { margin: 0 0 12px; font-size: 1rem; }
h3 { margin: 18px 0 8px; font-size: .9rem; color: var(--muted); font-weight: 600; }
a { color: var(--accent); }

main {
  max-width: 1100px; margin: 0 auto; padding: 16px;
  display: grid; gap: 24px;
  grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
  align-items: start;
}
@media (max-width: 900px) { main { grid-template-columns: minmax(0, 1fr); } }

button {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

/* ---------- board ---------- */
.mode-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.board-wrap { position: relative; width: 100%; aspect-ratio: 1; touch-action: none; user-select: none; }
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  width: 100%; height: 100%; border-radius: 6px; overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.last::before, .sq.from::before { content: ""; position: absolute; inset: 0; background: var(--hl); }
.sq.from::before { background: var(--sel); }
.sq.target::after {
  content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%;
  background: rgba(0,0,0,.22);
}
.sq.target.occupied::after { width: 88%; height: 88%; background: none; border: 5px solid rgba(0,0,0,.22); }
.coord { position: absolute; font-size: 11px; font-weight: 600; opacity: .75; pointer-events: none; }
.coord.file { right: 3px; bottom: 1px; }
.coord.rank { left: 3px; top: 1px; }
.sq.light .coord { color: var(--dark-sq); }
.sq.dark .coord { color: var(--light-sq); }

.piece {
  position: relative; z-index: 1;
  font-size: min(9vw, 54px); line-height: 1; cursor: grab;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", "Arial Unicode MS", serif;
}
.piece.w { color: #fff; text-shadow: 0 0 1px #000, 0 0 1px #000, 0 0 2px #000, 0 1px 1px #000; }
.piece.b { color: #111; text-shadow: 0 0 1px #fff4, 0 1px 1px #0006; }
.ghost { position: fixed; pointer-events: none; z-index: 1000; transform: translate(-50%, -55%); }

.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }

.palette { display: flex; gap: 4px; justify-content: center; padding: 6px 0; flex-wrap: wrap; }
.palette .pal {
  width: 46px; height: 46px; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 2px solid transparent; background: var(--card); cursor: pointer;
  touch-action: none;
}
.palette .pal .piece { font-size: 34px; }
.palette .pal.selected { border-color: var(--accent); }
.palette .pal.eraser { font-size: 20px; color: var(--muted); }
body.mode-play .palette { visibility: hidden; height: 0; padding: 0; }

.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 10px; min-height: 1.3em; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- side panel ---------- */
.side-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.label { min-width: 110px; color: var(--muted); font-size: .9rem; }
.castling label { font-size: .88rem; white-space: nowrap; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; border-left: 0; }
.seg button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.fen-box { display: flex; gap: 6px; flex: 1; min-width: 0; }
.fen-box input {
  flex: 1; min-width: 0; font: 12px ui-monospace, Menlo, Consolas, monospace;
  padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
input[type=range] { flex: 1; min-width: 120px; accent-color: var(--accent); }
input[type=number] {
  width: 76px; font: inherit; padding: 5px 6px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); color: var(--text);
}
.small { font-size: .85rem; color: var(--muted); }

.status { color: var(--muted); }
.status.error { color: #c0392b; }
.headline { display: flex; flex-direction: column; gap: 2px; }
.hl-label { color: var(--muted); }
.hl-move { font-size: 2.6rem; font-weight: 700; line-height: 1.15; }
.hl-prob { color: var(--muted); font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.move-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.move-list li {
  display: grid; grid-template-columns: 64px 1fr 52px; align-items: center; gap: 10px;
  padding: 3px 6px; border-radius: 6px; cursor: pointer;
}
.move-list li:hover { background: var(--bar-bg); }
.move-list .san { font-weight: 600; }
.move-list .bar { height: 10px; background: var(--bar-bg); border-radius: 5px; overflow: hidden; }
.move-list .bar > div { height: 100%; background: var(--bar); border-radius: 5px; }
.move-list .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }

.winbar { height: 14px; border-radius: 7px; overflow: hidden; background: #333; border: 1px solid var(--border); }
.winbar > div { height: 100%; background: #f5f5f5; transition: width .3s; }
.winbar-labels { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-top: 4px; }

.about p { color: var(--muted); font-size: .9rem; }
.about summary { cursor: pointer; font-weight: 600; }

footer { max-width: 1100px; margin: 0 auto; padding: 16px; color: var(--muted); font-size: .8rem; }
