:root {
  --bg: #16161a;
  --panel: #1e1e24;
  --panel-raised: #26262e;
  --border: #33333d;
  --text: #e8e8ec;
  --text-dim: #9a9aa8;
  --accent: #6c8cff;

  --brilliant: #22d3c5;
  --decisive: #9d7bff;
  --best: #7bb3ff;
  --excellent: #67d391;
  --good: #a3a3b2;
  --inaccuracy: #f2c14e;
  --mistake: #f08c3c;
  --missed-win: #e86ba0;
  --blunder: #e5484d;

  --radius: 10px;
  --gap: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: var(--gap);
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 {
  margin: 0 0 4px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(360px, 1fr) minmax(260px, 320px);
  gap: var(--gap);
  align-items: start;
  max-width: 1500px;
  margin: 0 auto;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.panel-moves {
  max-height: calc(100vh - 2 * var(--gap));
  overflow-y: auto;
}

/* Champs et actions */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-inline {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.field-check {
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
}

.field-check input {
  margin-top: 2px;
  accent-color: var(--accent);
}

.field-check small {
  display: block;
  color: var(--text-dim);
  font-size: 11px;
}

.field-label {
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

textarea,
select {
  padding: 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  resize: vertical;
}

textarea:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.actions {
  display: flex;
  gap: 8px;
}

button {
  padding: 9px 14px;
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

button:hover:not(:disabled) {
  background: #30303a;
  border-color: #45454f;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.primary {
  flex: 1;
  background: var(--accent);
  border-color: var(--accent);
  color: #0f1020;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: #7f9bff;
  border-color: #7f9bff;
}

.status {
  margin: 0;
  padding: 9px 11px;
  background: var(--bg);
  border-left: 3px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-dim);
}

.status[data-tone='busy'] {
  border-left-color: var(--accent);
  color: var(--text);
}

.status[data-tone='error'] {
  border-left-color: var(--blunder);
  color: #ffb3b5;
}

/* En-têtes de partie */

.game-headers {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  min-height: 22px;
}

.player {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.player::before {
  content: '';
  width: 9px;
  height: 9px;
  border: 1px solid var(--border);
  border-radius: 2px;
  align-self: center;
}

.player.is-white::before {
  background: #f0f0f0;
}

.player.is-black::before {
  background: #101014;
}

.player-name {
  font-weight: 600;
}

.player-elo,
.game-context {
  color: var(--text-dim);
  font-size: 13px;
}

.game-result {
  padding: 1px 7px;
  background: var(--panel-raised);
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 13px;
}

.game-context {
  flex-basis: 100%;
  margin: 0;
}

/* Échiquier */

.board-column {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

/* La barre d'évaluation s'aligne sur l'échiquier seul, pas sur les zones de
   captures qui l'encadrent. */
.board-area {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.board {
  flex: 1;
  min-width: 0;
  aspect-ratio: 1;
}

/* Le badge déborde un peu du coin de la case, comme sur Chess.com : il ne
   doit pas être coupé par l'échiquier. */
.board.cg-wrap {
  overflow: visible;
}

.board-move-badge {
  position: absolute;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  margin: 0;
  padding: 0;
  border: 2px solid #16161a;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.06em;
  white-space: nowrap;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

/* `display: flex` ci-dessus gagne sur la feuille UA de `[hidden]`. Sans
   cette règle, la pastille du dernier coup reste visible au départ. */
.board-move-badge[hidden] {
  display: none;
}

.board-move-badge.is-brilliant { background: var(--brilliant); color: #fff; }
.board-move-badge.is-decisive { background: var(--decisive); color: #fff; }
.board-move-badge.is-best {
  background: var(--best);
  color: #fff;
}

.board-move-badge.is-excellent {
  background: var(--excellent);
  color: #fff;
}

.board-move-badge svg {
  display: block;
  width: 0.92rem;
  height: 0.92rem;
}

.board-move-badge.is-good {
  background: var(--good);
  color: #1a1a22;
  font-size: 1.15rem;
}

/* Fond clair : le symbole reste sombre, comme dans la légende. */
.board-move-badge.is-inaccuracy {
  background: var(--inaccuracy);
  color: #101014;
}

.board-move-badge.is-mistake { background: var(--mistake); color: #fff; }
.board-move-badge.is-missed-win { background: var(--missed-win); color: #fff; }
.board-move-badge.is-blunder { background: var(--blunder); color: #fff; }

/* Deux caractères dans le même disque : on resserre plutôt que d’agrandir. */
.board-move-badge.is-brilliant,
.board-move-badge.is-inaccuracy,
.board-move-badge.is-blunder {
  font-size: 0.62rem;
  letter-spacing: -0.12em;
}

/* Les cases du dernier coup prennent la couleur du jugement, pas le vert
   générique de Chessground : on voit d'emblée si le coup est une gaffe. */
.board.is-brilliant cg-board square.last-move { background-color: color-mix(in srgb, var(--brilliant) 42%, transparent); }
.board.is-decisive cg-board square.last-move { background-color: color-mix(in srgb, var(--decisive) 42%, transparent); }
.board.is-best cg-board square.last-move { background-color: color-mix(in srgb, var(--best) 42%, transparent); }
.board.is-excellent cg-board square.last-move { background-color: color-mix(in srgb, var(--excellent) 42%, transparent); }
.board.is-good cg-board square.last-move { background-color: color-mix(in srgb, var(--good) 38%, transparent); }
.board.is-inaccuracy cg-board square.last-move { background-color: color-mix(in srgb, var(--inaccuracy) 45%, transparent); }
.board.is-mistake cg-board square.last-move { background-color: color-mix(in srgb, var(--mistake) 45%, transparent); }
.board.is-missed-win cg-board square.last-move { background-color: color-mix(in srgb, var(--missed-win) 45%, transparent); }
.board.is-blunder cg-board square.last-move { background-color: color-mix(in srgb, var(--blunder) 48%, transparent); }

.evalbar {
  position: relative;
  flex: 0 0 26px;
  border-radius: 6px;
  overflow: hidden;
  background: #101014;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column-reverse;
}

/* Retournée avec l'échiquier : le camp affiché en bas garde sa part en bas. */
.evalbar.is-flipped {
  flex-direction: column;
}

.evalbar-fill {
  width: 100%;
  background: #f2f2f4;
  transition: height 260ms ease;
}

.evalbar-caption {
  position: absolute;
  inset-inline: 0;
  bottom: 4px;
  text-align: center;
  font-family: ui-monospace, monospace;
  font-size: 10px;
  font-weight: 600;
  color: #101014;
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.95);
}

.evalbar.is-flipped .evalbar-caption {
  bottom: auto;
  top: 4px;
}

.evalbar.is-unknown .evalbar-fill {
  background: #4a4a56;
}

.evalbar.is-unknown .evalbar-caption {
  color: var(--text-dim);
  text-shadow: none;
}

/* Décalées de la largeur de la barre d'évaluation et de son écart, pour
   s'aligner sur le bord de l'échiquier et non sur celui de la barre. */
.captures {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1px;
  min-height: 22px;
  padding-left: 38px;
  font-size: 19px;
  line-height: 1;
}

.material-balance {
  margin-left: 6px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: ui-monospace, monospace;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.controls button {
  min-width: 46px;
  font-size: 15px;
}

/* Variante explorée */

/* L'échiquier montre alors une position qui n'a pas été jouée : le liseré est
   ce qui empêche de confondre la proposition du moteur avec la partie. */
.board.is-exploring {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.variation {
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel);
}

.variation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.variation-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.variation-close {
  padding: 2px 8px;
  font-size: 12px;
}

.variation-moves {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.variation-step {
  padding: 2px 7px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  color: var(--text);
}

.variation-step.is-start {
  color: var(--text-dim);
}

.variation-step:hover {
  background: var(--panel-raised);
}

.variation-step.is-current {
  background: var(--panel-raised);
  border-color: var(--accent);
}

.variation-note {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

/* Une réserve sur ce que le moteur a démontré doit se voir. */
.variation-note.is-reserved {
  color: var(--inaccuracy);
}

/* Graphe d'évaluation */

.evalgraph {
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #101014;
  cursor: pointer;
  overflow: hidden;
}

.evalgraph-svg {
  display: block;
  width: 100%;
  height: 96px;
}

/* La part des Blancs, comme sur la barre d'évaluation : même surface claire,
   même signification. */
.evalgraph-area {
  fill: #e8e8ec;
  fill-opacity: 0.82;
}

.evalgraph-curve {
  fill: none;
  stroke: #ffffff;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.evalgraph-midline {
  stroke: var(--text-dim);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  stroke-opacity: 0.5;
  vector-effect: non-scaling-stroke;
}

.evalgraph-marker rect {
  fill: currentcolor;
  stroke: #101014;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.evalgraph-cursor {
  stroke: var(--accent);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

/* Liste des coups */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin: 0 0 4px;
  padding: 0 0 10px;
  border-bottom: 1px solid var(--border);
  list-style: none;
  font-size: 11px;
  color: var(--text-dim);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legend-symbol {
  font-family: ui-monospace, monospace;
  font-weight: 700;
}

.move-rows {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.move-row {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  gap: 3px;
  align-items: center;
}

.move-number {
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
  font-size: 12px;
  text-align: right;
  padding-right: 4px;
}

.move {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 5px;
  padding: 4px 7px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  text-align: left;
}

.move:hover:not(:disabled) {
  background: var(--panel-raised);
  border-color: transparent;
}

.move.is-current {
  background: var(--panel-raised);
  border-color: var(--accent);
}

.move.is-unanalysed .move-san {
  color: var(--text-dim);
  font-style: italic;
}

.move-badge {
  font-size: 11px;
  font-weight: 700;
}

/* Labels : la couleur porte le sens, le symbole le redit */

.is-brilliant { color: var(--brilliant); }
.is-decisive { color: var(--decisive); }
.is-best { color: var(--best); }
.is-excellent { color: var(--excellent); }
.is-good { color: var(--good); }
.is-inaccuracy { color: var(--inaccuracy); }
.is-mistake { color: var(--mistake); }
.is-missed-win { color: var(--missed-win); }
.is-blunder { color: var(--blunder); }

/* Le pastille de l'échiquier réutilise ces classes. Sans surcharge, le
   symbole prendrait la couleur du label — jaune sur jaune pour une
   imprécision, invisible. */
.board-move-badge.is-brilliant,
.board-move-badge.is-decisive,
.board-move-badge.is-best,
.board-move-badge.is-excellent,
.board-move-badge.is-mistake,
.board-move-badge.is-missed-win,
.board-move-badge.is-blunder {
  color: #fff;
}

.board-move-badge.is-inaccuracy,
.board-move-badge.is-good {
  color: #101014;
}

.move.is-brilliant .move-san,
.move.is-decisive .move-san,
.move.is-best .move-san,
.move.is-excellent .move-san,
.move.is-inaccuracy .move-san,
.move.is-mistake .move-san,
.move.is-missed-win .move-san,
.move.is-blunder .move-san {
  color: inherit;
}

/* Un coup brillant est rare : il mérite d'être repérable sans être cherché. */
.move.is-brilliant {
  background: color-mix(in srgb, var(--brilliant) 14%, transparent);
}

.move.is-brilliant .move-badge,
.move.is-decisive .move-badge {
  font-weight: 700;
}

.move.is-good .move-san {
  color: var(--text);
}

/* Rapport */

.report {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.report-partial {
  margin: 0;
  color: var(--inaccuracy);
  font-size: 12px;
}

.accuracy-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.accuracy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px;
  background: var(--bg);
  border-radius: 8px;
  text-align: center;
}

.accuracy strong {
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}

.accuracy span {
  color: var(--text-dim);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.label-counts {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.label-counts th,
.label-counts td {
  padding: 3px 6px;
  text-align: left;
  font-weight: 400;
}

.label-counts thead th {
  color: var(--text-dim);
  font-size: 11px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.label-counts tbody th {
  color: inherit;
}

.label-counts td {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .panel-moves {
    max-height: 360px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
