:root {
  --bg: #f4f1ea;
  --fg: #1f1d1a;
  --muted: #6b665d;
  --panel: #ffffff;
  --line: #ddd6c8;
  --light: #ecdcb9;
  --dark: #a9794f;
  --accent: #2f6f4f;
  --hi: rgba(240, 200, 60, .55);
  --sel: rgba(47, 111, 79, .55);
  --check: rgba(200, 40, 40, .6);
  --err: #b3261e;
  --ok: #2f6f4f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15140f; --fg: #ece7dc; --muted: #9a9384; --panel: #1f1d17; --line: #34312a;
    --light: #c9b48e; --dark: #7d5a3c; --accent: #6fbf8f; --err: #ff8a80; --ok: #7fd3a0;
  }
}
:root[data-theme="dark"] {
  --bg: #15140f; --fg: #ece7dc; --muted: #9a9384; --panel: #1f1d17; --line: #34312a;
  --light: #c9b48e; --dark: #7d5a3c; --accent: #6fbf8f; --err: #ff8a80; --ok: #7fd3a0;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh; min-height: 100dvh;
}
header { padding: 12px 16px 4px; text-align: center; }
h1 { margin: 0; font-size: 1.35rem; letter-spacing: .01em; }
h1 .vs { font-weight: 400; color: var(--muted); font-size: .95rem; margin-left: .4em; }
.status { margin: 4px 0 0; font-weight: 600; min-height: 1.45em; }
.status.live { color: var(--accent); }

main {
  display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; align-items: flex-start;
  padding: 8px 16px 24px;
}
.board-wrap { flex: 0 0 auto; }
.board {
  /* fits the screen: as large as width and height allow */
  --size: min(calc(100vw - 32px), calc(100dvh - 120px), 720px);
  width: var(--size); height: var(--size);
  min-width: 240px; min-height: 240px;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border: 2px solid var(--dark); border-radius: 4px; overflow: hidden;
  container-type: size; user-select: none; touch-action: manipulation;
}
.sq {
  position: relative; display: flex; align-items: center; justify-content: center;
  font-size: 10cqw; line-height: 1; cursor: pointer;
}
.sq.l { background: var(--light); }
.sq.d { background: var(--dark); }
.sq.hi::before, .sq.sel::before, .sq.chk::before { content: ""; position: absolute; inset: 0; }
.sq.hi::before { background: var(--hi); }
.sq.sel::before { background: var(--sel); }
.sq.chk::before { background: radial-gradient(circle, var(--check) 30%, transparent 75%); }
.pc { position: relative; font-family: "DejaVu Sans", "Segoe UI Symbol", "Noto Sans Symbols 2", serif; }
.pc.w { color: #fff; text-shadow: 0 0 1px #000, 0 0 1px #000, 0 1px 2px rgba(0,0,0,.6); }
.pc.b { color: #111; text-shadow: 0 0 1px rgba(255,255,255,.5); }
.coord { position: absolute; font-size: 2.2cqw; font-weight: 600; opacity: .75; pointer-events: none; }
.coord.f { right: 3%; bottom: 2%; }
.coord.r { left: 4%; top: 3%; }
.sq.l .coord { color: var(--dark); }
.sq.d .coord { color: var(--light); }

.panel {
  flex: 1 1 260px; max-width: 420px; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px;
}
.panel h2 { font-size: .95rem; margin: 18px 0 6px; }
.muted { color: var(--muted); font-weight: 400; }
.vote label { font-weight: 600; display: block; margin-bottom: 6px; }
.vote .row { display: flex; gap: 8px; }
.vote input {
  flex: 1; min-width: 0; padding: 9px 10px; font: inherit; font-family: ui-monospace, monospace;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg);
}
.vote button {
  padding: 9px 16px; font: inherit; font-weight: 600; border: 0; border-radius: 6px;
  background: var(--accent); color: var(--bg); cursor: pointer;
}
.vote button:disabled, .vote input:disabled { opacity: .5; cursor: not-allowed; }
.msg { min-height: 1.45em; margin: 6px 0 0; font-weight: 600; }
.msg.err { color: var(--err); }
.msg.ok { color: var(--ok); }
.hint { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }

.tally { list-style: none; margin: 0; padding: 0; }
.tally li { display: grid; grid-template-columns: 4.5em 1fr 2.5em; gap: 8px; align-items: center; padding: 2px 0; }
.tally .san { font-family: ui-monospace, monospace; font-weight: 600; }
.tally .bar { height: 8px; background: var(--accent); border-radius: 4px; opacity: .8; }
.tally .n { text-align: right; font-variant-numeric: tabular-nums; }
.tally li.mine .san::after { content: " ✓"; color: var(--accent); }
.tally .empty { display: block; color: var(--muted); }

.history {
  margin: 0; padding: 0 0 0 2.2em; max-height: 9.5em; overflow-y: auto;
  font-family: ui-monospace, monospace; font-size: .9rem;
}
.history li { padding: 0 0 0 .3em; }
.history li span { display: inline-block; min-width: 5.5em; }

.watch { margin: 0; font-weight: 600; }
[hidden] { display: none !important; }
.nav { margin: 2px 0 0; font-size: .9rem; }
.nav a, .archive a, .panel a { color: var(--accent); }

.archive { display: block; max-width: 900px; margin: 0 auto; overflow-x: auto; }
.games { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.games th, .games td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.games th { font-size: .85rem; color: var(--muted); font-weight: 600; }
.games .num { text-align: right; font-variant-numeric: tabular-nums; }
.games .res { font-family: ui-monospace, monospace; font-weight: 600; }
.games .res .muted { font-family: inherit; font-weight: 400; font-size: .85rem; }
.games tr.live td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.badge { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--accent); color: var(--bg);
  font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; vertical-align: 1px; }

.replay-ctl { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 10px; }
.replay-ctl button { font: inherit; font-size: 1.1rem; min-width: 44px; min-height: 40px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--panel); color: var(--fg); cursor: pointer; }
.replay-ctl button:disabled { opacity: .4; cursor: default; }
.ply { min-width: 8em; text-align: center; font-family: ui-monospace, monospace; font-weight: 600; }
.history.clickable { max-height: 18em; }
.history .mv { font: inherit; background: none; border: 0; color: var(--fg); padding: 1px 4px; min-width: 5.5em;
  text-align: left; border-radius: 4px; cursor: pointer; }
.history .mv:hover { background: var(--line); }
.history .mv.cur { background: var(--accent); color: var(--bg); }

.api { margin-top: 18px; color: var(--muted); }
.api summary { cursor: pointer; font-weight: 600; color: var(--fg); }
.api pre { overflow-x: auto; font-size: .8rem; background: var(--bg); padding: 8px; border-radius: 6px; }
.api a { color: var(--accent); }
