/* Human-like chess bot: page styles. Colours are tokens; dark mode follows the system setting. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --line: #e1e0d9;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #d03b3b;
  --square-light: #eeeed2;
  --square-dark: #769656;
  --last-move: rgba(255, 255, 51, 0.48);
  --selected: rgba(255, 255, 51, 0.62);
  --target-dot: rgba(0, 0, 0, 0.16);
  --drop-ring: rgba(255, 255, 255, 0.75);
  --premove: rgba(20, 30, 85, 0.5);
  --premove-dot: rgba(20, 30, 85, 0.3);
  --check: radial-gradient(circle, rgba(255, 30, 30, 0.95) 0%, rgba(231, 0, 0, 0.6) 30%, rgba(169, 0, 0, 0) 72%);
  --bar: #2a78d6;
  --radius: 10px;
  --board-size: min(92vw, 560px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-muted: #898781;
    --line: #2c2c2a;
    --accent: #3987e5;
    --bar: #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --line: #2c2c2a;
  --accent: #3987e5;
  --bar: #3987e5;
}

* { box-sizing: border-box; }
/* Elements with display rules (the promotion overlay, banners) must still disappear when hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.topbar { padding: 18px 16px 4px; max-width: 1040px; margin: 0 auto; }
.topbar h1 { font-size: 1.35rem; margin: 0; }
.nav { display: flex; gap: 4px; margin-bottom: 8px; }
.nav a { color: var(--ink-2); text-decoration: none; padding: 4px 10px; border-radius: 6px; }
.nav a:hover { background: var(--surface); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--surface); border: 1px solid var(--line); }
.tagline { margin: 2px 0 0; color: var(--ink-2); }

.layout {
  display: grid;
  grid-template-columns: var(--board-size) minmax(260px, 1fr);
  gap: 24px;
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 16px 32px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; justify-items: center; }
  .side-column { width: 100%; max-width: var(--board-size); }
}

/* ---------------------------------------------------------------- board */

.board-column { width: var(--board-size); }
.board-wrap { position: relative; width: var(--board-size); aspect-ratio: 1; }
.board {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18), 0 12px 32px rgba(0, 0, 0, 0.18);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.board { position: relative; }
.board .shapes { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.square { position: relative; display: flex; align-items: center; justify-content: center; }
.square.light { background: var(--square-light); }
.square.dark { background: var(--square-dark); }
/* Highlights sit between the square colour and the piece (::before), move targets above it (::after). */
.square.last-move::before, .square.selected::before, .square.in-check::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
}
.square.last-move::before { background: var(--last-move); }
.square.selected::before { background: var(--selected); }
.square.premove::before { content: ""; position: absolute; inset: 0; pointer-events: none; background: var(--premove); }
.board.premoving .square.selected::before { background: var(--premove); }
.board.premoving .square.target::after { background: var(--premove-dot); }
.board.premoving .square.target.occupied::after {
  background: radial-gradient(circle closest-side, transparent 0 80%, var(--premove-dot) 82% 100%, transparent 101%);
}
.square.in-check::before { background: var(--check); }
.square.hint-from::after, .square.hint-to::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 4px var(--accent);
}
.square.hint-to::after { background: color-mix(in srgb, var(--accent) 25%, transparent); }
/* Where the selected piece can go: a dot on an empty square, a ring round a piece it can take. */
.square.target::after {
  content: ""; position: absolute; width: 32%; height: 32%; border-radius: 50%; z-index: 2;
  background: var(--target-dot); pointer-events: none;
}
.square.target.occupied::after {
  width: 100%; height: 100%; border-radius: 0;
  background: radial-gradient(circle closest-side, transparent 0 80%, var(--target-dot) 82% 100%, transparent 101%);
}
.square.target { cursor: pointer; }
@media (hover: hover) {
  .square.target:hover::after { width: 100%; height: 100%; border-radius: 0; background: var(--target-dot); }
}
.square.drop-over::after { box-shadow: inset 0 0 0 0.6cqw var(--drop-ring); }
.coord { position: absolute; font-size: 2.3cqw; font-weight: 600; line-height: 1; pointer-events: none; z-index: 1; }
.coord.rank { top: 0.5cqw; left: 0.6cqw; }
.coord.file { bottom: 0.5cqw; right: 0.7cqw; }
.square.light .coord { color: var(--square-dark); }
.square.dark .coord { color: var(--square-light); }

.piece {
  width: 100%;
  height: 100%;
  background: center / 100% 100% no-repeat;
  cursor: grab;
  position: relative;
  z-index: 1;
}
.piece[data-piece="wk"] { background-image: url("../pieces/wK.svg"); }
.piece[data-piece="wq"] { background-image: url("../pieces/wQ.svg"); }
.piece[data-piece="wr"] { background-image: url("../pieces/wR.svg"); }
.piece[data-piece="wb"] { background-image: url("../pieces/wB.svg"); }
.piece[data-piece="wn"] { background-image: url("../pieces/wN.svg"); }
.piece[data-piece="wp"] { background-image: url("../pieces/wP.svg"); }
.piece[data-piece="bk"] { background-image: url("../pieces/bK.svg"); }
.piece[data-piece="bq"] { background-image: url("../pieces/bQ.svg"); }
.piece[data-piece="br"] { background-image: url("../pieces/bR.svg"); }
.piece[data-piece="bb"] { background-image: url("../pieces/bB.svg"); }
.piece[data-piece="bn"] { background-image: url("../pieces/bN.svg"); }
.piece[data-piece="bp"] { background-image: url("../pieces/bP.svg"); }
.board:not(.locked) .square.occupied:hover .piece { filter: brightness(1.06); }
.piece.dragging { opacity: 0.3; }
.drag-ghost { position: fixed; pointer-events: none; z-index: 50; transform: translate(-50%, -50%) scale(1.08);
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.35)); cursor: grabbing; }
.board.locked .piece { cursor: default; }

.promotion {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.35); z-index: 10;
}
.promotion .choices { display: flex; gap: 6px; background: var(--surface); padding: 10px; border-radius: var(--radius); }
.promotion button { width: 64px; height: 64px; padding: 4px; border: 1px solid var(--line); border-radius: 8px;
  background-color: var(--surface); background-origin: content-box; background-size: contain; cursor: pointer; }
.promotion button:hover { background-color: var(--line); }

.result-banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 9;
  background: var(--surface); color: var(--ink); border-radius: var(--radius); padding: 16px 22px;
  text-align: center; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3); min-width: 60%;
}
.result-banner h2 { margin: 0 0 4px; font-size: 1.3rem; }
.result-banner p { margin: 0 0 12px; color: var(--ink-2); }
.result-banner .actions { justify-content: center; }

.player-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 2px; min-height: 44px; }
.player-name { font-weight: 600; }
.clock {
  font-variant-numeric: tabular-nums; font-size: 1.35rem; padding: 2px 10px; border-radius: 6px;
  background: var(--surface); border: 1px solid var(--line); min-width: 84px; text-align: right;
}
.clock.running { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.clock.low { color: var(--danger); }
.clock.running.low { background: var(--danger); color: #ffffff; border-color: var(--danger); }
.status { margin: 4px 2px 0; color: var(--ink-2); min-height: 1.45em; }
.keys { margin: 6px 2px 0; }
kbd { font: 0.85em ui-monospace, monospace; padding: 0 5px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface); }

/* ---------------------------------------------------------------- side panels */

.side-column { display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.panel h2 { font-size: 1rem; margin: 0 0 10px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; border: 0; padding: 0; }
.field > span, .field legend { color: var(--ink-2); font-size: 0.9rem; padding: 0; }
.field output { color: var(--ink); font-weight: 600; margin-left: 4px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
select { font: inherit; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--page); color: var(--ink); }

.segmented { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 6px 0; cursor: pointer; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

button {
  font: inherit; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--page); color: var(--ink); cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--ink-muted); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); width: 100%; font-weight: 600; }
button.danger { color: var(--danger); }
button.danger[data-confirm="yes"] { background: var(--danger); color: #ffffff; border-color: var(--danger); }
.button-link {
  display: inline-block; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--page); color: var(--ink); text-decoration: none;
}
.button-link:hover { border-color: var(--ink-muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.move-list {
  list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto;
  display: grid; grid-template-columns: 2.6em 1fr 1fr; font-variant-numeric: tabular-nums;
}
.move-list li { display: contents; }
.move-list .num { color: var(--ink-muted); padding: 2px 0; }
.move-list .san { padding: 2px 6px; border-radius: 4px; }
.move-list .san.latest { background: var(--line); font-weight: 600; }

.hint { color: var(--ink-2); margin: -4px 0 10px; font-size: 0.9rem; }
.candidates { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.candidate { display: grid; grid-template-columns: 7.5em 1fr 3.2em; gap: 8px; align-items: center; }
.candidate .san { font-weight: 600; white-space: nowrap; }
.candidate.played .san::after { content: " \2190 played"; font-weight: 400; color: var(--ink-muted); font-size: 0.8rem; }
/* Spans are inline by default and would ignore width: the bars must be blocks. */
.candidate .track { display: block; height: 10px; background: var(--line); border-radius: 0 4px 4px 0; }
.candidate .fill { display: block; height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.candidate .pct { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* Hints (step 17) */
.badge { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; margin-left: 6px;
  border: 1px solid var(--line); color: var(--ink-2); vertical-align: 2px; }
.hint-text { margin: 4px 0 8px; line-height: 1.5; }

/* Adaptive difficulty (step 18) */
.adaptive-result { font-weight: 600; }
fieldset.field .hint { margin: 6px 0 0; }
