:root {
  --bg: #14161a;
  --panel: #1d2027;
  --panel-2: #262a33;
  --line: #333844;
  --text: #e8eaee;
  --muted: #9aa1ae;
  --light: #ebd9b6;
  --dark: #9c7a54;
  --sel: #f2c14e;
  --last: #d7c04a;
  --check: #e2564a;
  --accent: #6f9ceb;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 800px at 20% -10%, #1e222b, var(--bg));
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px;
}

.app {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}

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

.board-area {
  --size: min(76vh, 88vw, 640px);
  display: flex;
  gap: 10px;
  align-items: center;
}
.board-column { display: flex; flex-direction: column; gap: 8px; }

.board-wrap { position: relative; }

.board {
  width: var(--size);
  height: var(--size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  touch-action: none;
  user-select: none;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sq.light { background: var(--light); }
.sq.dark  { background: var(--dark); }

.sq .coord {
  position: absolute;
  font-size: calc(var(--size, 640px) / 64);
  font-weight: 700;
  opacity: .55;
  pointer-events: none;
}
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }
.sq.light .coord { color: var(--dark); }
.sq.dark  .coord { color: var(--light); }

.sq.last::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--last);
  opacity: .38;
}
.sq.sel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sel);
  opacity: .5;
}
.sq.check::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: radial-gradient(circle, var(--check) 18%, rgba(226, 86, 74, .6) 46%, transparent 72%);
}

.piece {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--size, 640px) / 8 * 0.78);
  line-height: 1;
  cursor: default;
  text-shadow: 0 2px 2px rgba(0, 0, 0, .3);
}
.piece.img {
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  text-shadow: none;
  -webkit-text-stroke: 0;
}
.piece.w { color: #fbfbf9; -webkit-text-stroke: calc(var(--size, 640px) / 640) #2a2f38; }
.piece.b { color: #2c3038; -webkit-text-stroke: calc(var(--size, 640px) / 900) #e9e6df; }
.piece.draggable { cursor: grab; }
.piece.dragging { opacity: .28; }

.commentary {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--panel-2);
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}
.commentary[hidden] { display: none; }
.commentary p { margin: 0 0 6px; color: var(--text); }
.commentary a { color: var(--accent); font-size: 11px; text-decoration: none; }
.commentary a:hover { text-decoration: underline; }

.opening-name {
  margin: 0 0 8px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
}
.opening-name.out { color: var(--muted); }

.opening-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.opening-list .line {
  display: flex;
  align-items: baseline;
  gap: 7px;
  width: 100%;
  padding: 4px 7px;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.opening-list .line:hover:not(:disabled) { background: #313745; border-color: var(--line); }
.opening-list .line:disabled { opacity: .5; cursor: default; }
.opening-list .line b {
  color: #6f9ceb;                  /* the colour it previews in on the board */
  min-width: 42px;
  font-variant-numeric: tabular-nums;
}
.opening-list .line span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opening-list .line i { font-style: normal; font-size: 11px; opacity: .6; }

/* the engine's suggested move */
.arrow {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  color: #4fd1a5;
}
.arrow[hidden] { display: none; }
#arrow-line, #threat-line, #book-line { fill: none; stroke-linejoin: round; }
#arrow-line { stroke: #4fd1a5; stroke-width: 1.5; stroke-linecap: round; opacity: .9; }
#threat-line { stroke: #e2564a; stroke-width: 1.3; stroke-linecap: round; opacity: .85; }
#book-line { stroke: #6f9ceb; stroke-width: 1.5; stroke-linecap: round; opacity: .95; }
#arrow-line[hidden], #threat-line[hidden], #book-line[hidden] { display: none; }

.sq.threat-square::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #e2564a;
  opacity: .22;
}
.sq.book-square::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #6f9ceb;
  opacity: .34;
}

.sq.best-from::after, .sq.best-to::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #4fd1a5;
  opacity: .3;
}
.piece.preview {
  position: absolute;
  inset: 4%;
  z-index: 2;
  opacity: .5;
}

/* movement-pattern view */
.pips {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 5%;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-end;
  gap: 2px;
  pointer-events: none;
}
.pips i {
  width: calc(var(--size, 640px) / 8 * .125);
  height: calc(var(--size, 640px) / 8 * .125);
  display: block;
  opacity: .62;
}
.pips i.w { border-radius: 50%; box-shadow: 0 0 0 1px rgba(20, 22, 26, .6); }
.pips i.b {                              /* diamond reads as clearly not-a-circle */
  border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(245, 245, 245, .75);
  transform: rotate(45deg) scale(.92);
}
.pips i.legal { opacity: 1; }
.pips i.w.legal { transform: scale(1.3); }
.pips i.b.legal { transform: rotate(45deg) scale(1.2); }

/* squares both sides bear on */
.hatch {
  position: absolute;
  inset: 0;
  z-index: 1;
  /* Deliberately faint: in a middlegame most squares are contested, so this has to
     read as texture rather than compete with the pieces. */
  background: repeating-linear-gradient(45deg,
    rgba(255, 255, 255, .16) 0 2px, rgba(20, 22, 26, .10) 2px 7px);
}

.seg { display: flex; width: 100%; }
.seg button {
  flex: 1;
  padding: 5px 6px;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; border-left: none; }
.seg button.on { background: var(--accent); color: #10131a; border-color: transparent; font-weight: 600; }

#pat-side {
  width: 100%;
  padding: 5px 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
}
#pat-side:disabled { opacity: .45; }

.btn.tiny {
  flex: none;
  width: 100%;
  padding: 5px 8px;
  font-size: 12px;
}

.legend-chips { display: flex; flex-wrap: wrap; gap: 6px 10px; width: 100%; }
.legend .chip.shape i.shape-w {
  background: #cfd4dc; border-radius: 50%; box-shadow: 0 0 0 1px rgba(20, 22, 26, .6);
}
.legend .chip.shape i.shape-b {
  background: #4a505c; border-radius: 1px; box-shadow: 0 0 0 1px rgba(245, 245, 245, .75);
  transform: rotate(45deg) scale(.9);
}
.legend .chip.shape i.shape-x {
  background: repeating-linear-gradient(45deg,
    rgba(255, 255, 255, .55) 0 2px, rgba(20, 22, 26, .5) 2px 4px);
  border-radius: 2px;
}
.pat {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: .34;
}
.pat-focus {
  position: absolute;
  inset: 0;
  z-index: 4;
  border: 3px dashed;              /* hovered: provisional */
  border-radius: 2px;
  pointer-events: none;
}
.pat-focus.pinned { border-style: solid; }   /* right-clicked: stays put */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 10px;
  background: var(--panel-2);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
}
.legend[hidden] { display: none; }
.legend-help { width: 100%; margin: 0 0 2px; line-height: 1.45; }
.legend .chip { display: inline-flex; align-items: center; gap: 5px; }
.legend .chip i {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  display: inline-block;
}

.btn.toggle.on {
  background: var(--accent);
  color: #10131a;
  border-color: transparent;
  font-weight: 600;
}

/* move hints */
.hint-dot, .hint-ring {
  position: absolute;
  z-index: 3;
  pointer-events: none;
}
.hint-dot {
  width: 30%; height: 30%;
  border-radius: 50%;
  background: rgba(20, 22, 26, .32);
}
.hint-ring {
  inset: 4%;
  border-radius: 50%;
  border: 6px solid rgba(20, 22, 26, .3);
}
.sq.target { cursor: pointer; }

#ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .5));
}
#ghost.w { color: #fbfbf9; -webkit-text-stroke: 1px #2a2f38; }
#ghost.b { color: #2c3038; -webkit-text-stroke: .7px #e9e6df; }
#ghost.img { background-size: contain; background-repeat: no-repeat; background-position: center; }

/* ---------- eval bar ---------- */

.evalbar {
  position: relative;
  width: 26px;
  height: var(--size);
  border-radius: 4px;
  overflow: hidden;
  background: #21242b;                 /* Black's share of the bar */
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  flex: none;
}
.eval-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;                           /* White grows from the bottom */
  height: 50%;
  background: #f1efe9;
  transition: height .35s cubic-bezier(.4, 0, .2, 1);
}
.evalbar.flip .eval-fill { bottom: auto; top: 0; }
.evalbar::after {                      /* the even mark */
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  border-top: 1px dashed rgba(128, 128, 128, .55);
}
.eval-num {
  position: absolute;
  left: 0; right: 0;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.2px;
  z-index: 2;
  pointer-events: none;
}
.eval-num.bottom { bottom: 3px; }
.eval-num.top { top: 3px; }
.eval-num.on-white { color: #2c3038; }
.eval-num.on-black { color: #e9e6df; }
.evalbar.decided .eval-fill { transition-duration: .5s; }
.evalbar.offline { opacity: .35; }
.evalbar.offline .eval-fill { background: #6d727c; }

.engine .best-move { color: #4fd1a5; font-weight: 600; }  /* matches its arrow */

.engine {
  margin: -6px 0 0;
  font-size: 12px;
  color: var(--muted);
  min-height: 16px;
}

/* ---------- players ---------- */

.player {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  min-height: 26px;
}
.player .dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #0006;
}
.player.black .dot { background: #2b2b2b; border-color: #0009; }
.player.turn .name { color: var(--sel); }
.player .captured {
  font-size: 19px;
  line-height: 1;
  letter-spacing: -4px;
  color: var(--muted);
  opacity: .85;
}
.player .edge { font-size: 13px; color: var(--muted); font-weight: 700; }

/* ---------- panel ---------- */

.panel {
  width: 280px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel h1 { margin: 0; font-size: 20px; letter-spacing: .5px; }
.status { margin: 0; color: var(--muted); min-height: 22px; }
.status.check { color: var(--check); font-weight: 600; }
.status.done  { color: var(--sel); font-weight: 600; }

.moves {
  height: 300px;
  overflow-y: auto;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 6px;
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  align-content: start;
  gap: 2px;
  font-variant-numeric: tabular-nums;
  scrollbar-width: thin;
}
.moves .num { color: var(--muted); text-align: right; padding: 2px 6px 2px 0; font-size: 13px; }
.moves .san {
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.moves .san:hover { background: #ffffff12; }
.moves .san.active { background: var(--accent); color: #10131a; font-weight: 600; }
.moves .empty { grid-column: 1 / -1; color: var(--muted); padding: 6px; font-size: 13px; }

.controls { display: flex; gap: 6px; }
.btn {
  flex: 1;
  padding: 8px 6px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: #313745; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: #10131a; border-color: transparent; font-weight: 600; }

.opts summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.opts[open] summary { margin-bottom: 8px; }

.opt {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}
.opt span { display: block; margin-bottom: 3px; }
.opt b { color: var(--text); font-variant-numeric: tabular-nums; }
.opt input[type="range"] { width: 100%; accent-color: var(--accent); }
.opt input[type="range"]:disabled { opacity: .4; }
.opt.check { display: flex; align-items: center; gap: 7px; }
.opt.check input { accent-color: var(--accent); margin: 0; }
.opt.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.opt select {
  flex: 1;
  padding: 5px 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
}
.fen input {
  width: 100%;
  margin: 8px 0 6px;
  padding: 7px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: 12px ui-monospace, Menlo, Consolas, monospace;
}
.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); min-height: 16px; }

/* ---------- overlays ---------- */

.promo[hidden], .over[hidden] { display: none; }

/* The promotion picker must be answered, so it blocks the board. */
.promo {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 14, 18, .72);
  border-radius: 6px;
}
.promo-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 20px;
  text-align: center;
  box-shadow: 0 12px 40px #0008;
}
.promo-card p { margin: 0 0 10px; color: var(--muted); }
.promo-choices { display: flex; gap: 8px; }
.promo-choices button {
  width: 62px; height: 62px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  padding: 6px;
}
.promo-choices button:hover { background: #3a4152; border-color: var(--accent); }
.promo-choices button span { font-size: 44px; line-height: 1; }
.promo-choices button span.img { display: block; width: 100%; height: 100%; }
.promo-choices button span.w { color: #fbfbf9; -webkit-text-stroke: 1px #2a2f38; }
.promo-choices button span.b { color: #2c3038; -webkit-text-stroke: .7px #e9e6df; }

/* The result banner is only news, so it stays out of the way: a strip at the top
   of the board, click-through everywhere except the card, closed with x or Esc. */
.over {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12px;
  pointer-events: none;
  border-radius: 6px;
}
.over-card {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 14px;
  background: rgba(29, 32, 39, .97);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.over-msg h2 { margin: 0; font-size: 15px; }
.over-msg p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }
.over-card .btn { width: auto; flex: none; padding: 6px 12px; font-size: 13px; }
.over-close {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.over-close:hover { background: #313745; color: var(--text); }

@media (max-width: 900px) {
  body { padding: 12px; }
  .board-area { --size: min(76vh, 84vw, 640px); }
  .panel { width: min(92vw, 640px); }
  .moves { height: 160px; }
}
