:root {
  --bg: #f5f3ee; --ink: #1c1b19; --muted: #5f5c55; --line: #d8d4ca; --panel: #fcfbf8;
  --accent: #1f5f8b; --accent-ink: #fff; --chip: #ebe8df;
  --light: #e6dcc6; --dark: #94795a; --sel: #d9b63c; --last: rgba(217, 182, 60, .45); --hint: rgba(20, 20, 20, .32);
  --warn: #9a3412;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214; --ink: #eceae5; --muted: #a5a29a; --line: #2e3034; --panel: #191b1e;
    --accent: #7cb9e8; --accent-ink: #0c1a24; --chip: #25282c;
    --light: #8b8473; --dark: #55503f; --sel: #c4a42f; --last: rgba(196, 164, 47, .4); --hint: rgba(255, 255, 255, .35);
    --warn: #fdba74;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
code { font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; font-size: .92em; }
.wrap { max-width: 1020px; margin: 0 auto; padding: 0 16px; }
.top { padding-top: 26px; padding-bottom: 14px; }
h1 { font-size: clamp(32px, 6vw, 46px); line-height: 1.05; margin: 0 0 8px; letter-spacing: -.02em; }
h2 { font-size: 18px; margin: 24px 0 8px; }
.lede { max-width: 70ch; margin: 0; }

.game { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 24px; align-items: start; }
.board-col { position: relative; }
.board { display: grid; grid-template-columns: repeat(8, 1fr); width: 100%; aspect-ratio: 1; border-radius: 4px; overflow: hidden; box-shadow: 0 0 0 1px var(--line); user-select: none; touch-action: manipulation; }
.sq { position: relative; border: 0; padding: 0; margin: 0; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: clamp(30px, 8.6vw, 54px); line-height: 1; cursor: pointer; font-family: "Segoe UI Symbol", "Noto Sans Symbols2", "Noto Sans Symbols", "Apple Symbols", "DejaVu Sans", sans-serif; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: var(--last); }
.sq.selected::before { content: ""; position: absolute; inset: 0; background: var(--sel); }
.sq.check::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, rgba(220, 38, 38, .85), rgba(220, 38, 38, 0) 72%); }
.sq.target::after { content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: var(--hint); }
.sq.target.occupied::after { width: 88%; height: 88%; background: none; border: 5px solid var(--hint); box-sizing: border-box; }
.sq:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 2; }
.piece { position: relative; z-index: 1; pointer-events: none; }
.piece.w { color: #fff; -webkit-text-stroke: 1.5px #1b1b1b; paint-order: stroke fill; }
.piece.b { color: #1b1b1b; -webkit-text-stroke: 1px #f1efe9; paint-order: stroke fill; }
.coord { position: absolute; font: 600 10px/1 system-ui, sans-serif; opacity: .75; z-index: 1; pointer-events: none; }
.coord.file { right: 3px; bottom: 3px; }
.coord.rank { left: 3px; top: 3px; }
.sq.light .coord { color: #5b4a33; }
.sq.dark .coord { color: #f2ead9; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
button { font: inherit; color: inherit; }
.controls button { background: var(--chip); border: 1px solid var(--line); border-radius: 4px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.controls button:disabled { opacity: .5; cursor: default; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.promotion { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 5; display: flex; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); }
.promotion[hidden] { display: none; }
.promotion button { width: 56px; height: 56px; font-size: 36px; line-height: 1; background: var(--light); border: 1px solid var(--line); border-radius: 4px; cursor: pointer; font-family: "Segoe UI Symbol", "Noto Sans Symbols2", "Apple Symbols", "DejaVu Sans", sans-serif; }

.side-col { min-width: 0; }
.status { margin: 0; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 4px; font-weight: 600; min-height: 46px; }
.status.waiting { border-left-color: #d9a400; }
.status.error { border-left-color: var(--warn); color: var(--warn); }
.engine-note { margin: 6px 0 0; font-size: 14px; color: var(--muted); min-height: 1.4em; }
.stats { margin: 0; border-top: 1px solid var(--line); }
.stats div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.fine { font-size: 13.5px; color: var(--muted); margin: 8px 0 0; }
.moves { margin: 0; padding: 0 0 0 30px; max-height: 180px; overflow-y: auto; font-variant-numeric: tabular-nums; font-size: 15px; columns: 1; }
.moves li { padding: 1px 0; }
.moves span { display: inline-block; min-width: 62px; }

.prose { max-width: 760px; padding-bottom: 44px; margin-top: 16px; }
.prose h2 { font-size: 20px; margin-top: 28px; }
.prose ul { padding-left: 20px; }
.prose li { margin-bottom: 6px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
caption { text-align: left; color: var(--muted); margin-bottom: 6px; font-size: 13.5px; }
th, td { text-align: left; padding: 7px 10px 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-weight: 600; }
tbody th { font-weight: 400; }

@media (max-width: 800px) {
  .game { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .side-col { order: 0; }
}
@media (max-width: 420px) {
  .coord { font-size: 8px; }
  .sq.target.occupied::after { border-width: 3px; }
  .promotion button { width: 50px; height: 50px; font-size: 32px; }
}
