:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --text: #1d1c1a;
  --muted: #6d6a63;
  --line: #e2ded5;
  --accent: #b5562b;
  --accent-soft: #f1d9cc;
  --good: #3f7d4e;
  --light-sq: #ece3d0;
  --dark-sq: #a98a68;
  --sel: rgba(181, 86, 43, 0.45);
  --last: rgba(214, 178, 64, 0.45);
  --check: rgba(200, 40, 30, 0.55);
  --dot: rgba(30, 28, 26, 0.28);
  --arrow: rgba(181, 86, 43, 0.6);
  --white-piece: #fbfaf7;
  --black-piece: #23211f;
  --piece-edge: #23211f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514;
    --panel: #1f1e1c;
    --text: #ece9e2;
    --muted: #9c978d;
    --line: #34322e;
    --accent: #e0845a;
    --accent-soft: #4a2f22;
    --good: #7cbf8b;
    --light-sq: #b9ab92;
    --dark-sq: #7a6047;
    --dot: rgba(20, 18, 16, 0.4);
    --arrow: rgba(224, 132, 90, 0.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161514;
  --panel: #1f1e1c;
  --text: #ece9e2;
  --muted: #9c978d;
  --line: #34322e;
  --accent: #e0845a;
  --accent-soft: #4a2f22;
  --good: #7cbf8b;
  --light-sq: #b9ab92;
  --dark-sq: #7a6047;
  --dot: rgba(20, 18, 16, 0.4);
  --arrow: rgba(224, 132, 90, 0.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header { max-width: 1120px; margin: 0 auto; padding: 20px 16px 4px; }
h1 { margin: 0; font-size: 26px; letter-spacing: -0.01em; }
.tagline { margin: 4px 0 0; color: var(--muted); max-width: 60ch; }
.fly-pick { margin: 8px 0 0; color: var(--muted); font-size: 0.9em; }
.fly-pick strong { color: var(--text); }
main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 16px 32px;
  display: grid;
  grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) { main { grid-template-columns: minmax(0, 1fr); } }

/* --- board side --- */
.player { display: flex; justify-content: space-between; align-items: center; padding: 6px 2px; }
.who { font-weight: 600; }
.clock {
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  padding: 2px 10px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.clock.running { background: var(--accent); border-color: var(--accent); color: #fff; }
.clock.low.running { background: #c0392b; border-color: #c0392b; }
.board-wrap { position: relative; width: 100%; aspect-ratio: 1; }
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}
.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.sel::before, .sq.check::before { content: ""; position: absolute; inset: 0; }
.sq.last::before { background: var(--last); }
.sq.sel::before { background: var(--sel); }
.sq.check::before { background: radial-gradient(circle, var(--check) 30%, transparent 75%); }
.sq.target::after {
  content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: var(--dot);
}
.sq.target.capture::after { width: 88%; height: 88%; background: none; border: 5px solid var(--dot); }
.coord { position: absolute; font-size: 10px; font-weight: 600; opacity: 0.7; 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(9.4vw, 52px);
  line-height: 1;
  font-family: "DejaVu Sans", "Segoe UI Symbol", "Noto Sans Symbols 2", sans-serif;
  cursor: grab;
  pointer-events: none;
}
.piece.w { color: var(--white-piece); -webkit-text-stroke: 1.2px var(--piece-edge); paint-order: stroke fill; }
.piece.b { color: var(--black-piece); -webkit-text-stroke: 0.6px var(--black-piece); }
.piece.dragging { position: fixed; z-index: 10; transform: translate(-50%, -50%); }
.piece.ghost { opacity: 0.3; }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.arrows line { stroke: var(--arrow); stroke-width: 0.16; stroke-linecap: round; }
.arrows marker path { fill: var(--arrow); }
.promo {
  position: absolute; z-index: 20; display: flex; gap: 4px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.promo[hidden] { display: none; }
.promo button { font-size: 40px; width: 60px; height: 60px; padding: 0; }
.overlay {
  position: absolute; inset: 0; z-index: 15; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.35); border-radius: 4px;
}
.overlay[hidden] { display: none; }
.overlay-box {
  background: var(--panel); border-radius: 10px; padding: 18px 20px; max-width: 90%; width: 320px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.overlay-box p { margin: 0 0 12px; }
fieldset { border: none; padding: 0; margin: 0 0 12px; }
legend { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
fieldset label { margin-right: 12px; }
button, select {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 14px; cursor: pointer;
}
button[type="submit"] { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; }
button:disabled { opacity: 0.45; cursor: default; }
.controls { display: flex; gap: 8px; margin: 8px 0; }
.moves {
  margin: 0; padding: 8px 10px; list-style: none; display: flex; flex-wrap: wrap; gap: 2px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-height: 40px;
  font-variant-numeric: tabular-nums;
}
.moves li .n { color: var(--muted); margin-right: 4px; }

/* --- brain side --- */
.brain { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.brain-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
h2 { margin: 0; font-size: 18px; }
h3 { margin: 18px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.mode {
  font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--line); color: var(--muted);
  white-space: nowrap;
}
.mode.search { background: var(--accent); color: #fff; }
.mode.watch { background: var(--accent-soft); color: var(--text); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
@media (max-width: 480px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.stat .label { display: block; font-size: 12px; color: var(--muted); }
.stat .value { display: block; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.stat .sub { display: block; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.trace { width: 100%; height: 90px; display: block; border: 1px solid var(--line); border-radius: 8px; }
.regions { display: grid; grid-template-columns: max-content minmax(0, 1fr) 7ch; gap: 4px 10px; align-items: center; font-size: 13px; }
.regions .bar { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.regions .bar div { height: 100%; background: var(--accent); width: 0; transition: width 0.15s; }
.regions .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.commit-track { position: relative; height: 12px; background: var(--line); border-radius: 6px; overflow: hidden; }
.commit-fill { position: absolute; top: 0; bottom: 0; left: 50%; background: var(--accent); transition: all 0.1s; }
.commit-threshold { position: absolute; top: 0; bottom: 0; left: 75%; width: 2px; background: var(--text); }
.commit-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sniffing { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.candidates { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.candidates li { display: grid; grid-template-columns: 6ch minmax(0, 1fr) 7ch; gap: 10px; align-items: center; font-variant-numeric: tabular-nums; }
.candidates .san { font-weight: 600; }
.candidates .bar { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.candidates .bar div { height: 100%; background: var(--accent); transition: width 0.15s; }
.candidates li:first-child .bar div { background: var(--good); }
.candidates .score { text-align: right; color: var(--muted); font-size: 13px; }
.facts p { margin: 10px 0 0; font-size: 14px; }
.about { margin-top: 16px; font-size: 14px; color: var(--muted); }
.about summary { cursor: pointer; color: var(--text); }
.credit { font-size: 12px; }

/* --- play / watch --- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs label {
  margin: 0; padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font-size: 14px;
}
.tabs label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.tabs label:has(input:disabled) { opacity: 0.45; cursor: default; }
.tabs input { display: none; }
#newgame[data-mode="play"] .watch-only, #newgame[data-mode="watch"] .play-only { display: none; }
.elo, .live-elo { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.elo input, .live-elo input { flex: 1; min-width: 0; accent-color: var(--accent); }
.elo output, .live-elo output { font-weight: 600; min-width: 4ch; text-align: right; }
.live-elo { margin: 4px 0 8px; font-size: 14px; }
.live-elo[hidden] { display: none; }
.live-elo label { white-space: nowrap; color: var(--muted); }
.note { font-size: 13px; color: var(--muted); }
.no-elo { display: none !important; }
.live-note { margin: -4px 0 8px; }
#live-elo[hidden] + .live-note { display: none; }

/* --- the 3D neuron cloud (always on a dark "scope" background) --- */
.brain-kind { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.kind { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--text); }
.kind.scrambled { background: #c0392b; color: #fff; }
.cloud-card { position: relative; margin-top: 12px; background: #050505; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; }
.cloud { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.cloud:active { cursor: grabbing; }
.cloud-status, .cloud-hint { position: absolute; font-size: 11px; letter-spacing: 0.06em; color: #9c978d; pointer-events: none; }
.cloud-status { top: 10px; right: 12px; text-transform: uppercase; }
.cloud-hint { bottom: 8px; right: 12px; }
.cloud-legend { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 6px; font-size: 12px; }
.cloud-legend li { display: flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); cursor: pointer; color: var(--text); user-select: none; }
.cloud-legend li.off { opacity: 0.4; }
.cloud-legend .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.cloud-legend .dot.ring { background: transparent; border: 2.5px solid; box-sizing: border-box; }
.additions { margin: 4px 0 10px; display: grid; gap: 4px; font-size: 13px; }
.additions .addition { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; align-items: start; }
.additions .addition .about { grid-column: 2; color: var(--muted); font-size: 12px; }
.additions .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; margin-left: 4px; }
.cloud-legend .n { color: var(--muted); font-variant-numeric: tabular-nums; }
