:root {
  color-scheme: dark light;
  --bg: #1e1e1e;
  --fg: #e8e8e8;
  --card-bg: #2a2a2a;
  --accent: #4caf50;
  --error: #e57373;
  --info: #64b5f6;
}

html {
  /* Empeche le "font boosting" automatique des navigateurs mobiles (Android Chrome surtout) --
     sans ca, les navigateurs agrandissent le texte dans les colonnes etroites pour la
     lisibilite, ce qui fait deborder toute la mise en page (symptome : tout parait "zoome",
     le plateau coupe sur le cote). */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  background: var(--bg);
  color: var(--fg);
}

h1 { font-size: 1.4rem; margin: 0.5rem 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid #444;
}

nav a { color: var(--fg); text-decoration: none; font-weight: bold; font-size: 1rem; }

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 0.85rem;
}

.card {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 0.85rem;
  font-size: 0.95rem;
}

/* Distingue une position jamais vue d'une revision espacee due (J+1/J+3/J+7) -- voir
   web/app.py:_INTERVAL_LABELS. display:table + margin:auto centre le badge sans deborder
   sur toute la largeur comme display:block le ferait. */
.badge {
  display: table;
  margin: 0.4rem auto 0.6rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: bold;
  text-align: center;
}
.badge-new { background: rgba(76, 175, 80, 0.18); color: var(--accent); }
.badge-due { background: rgba(100, 181, 246, 0.18); color: var(--info); }

.color-label { font-weight: bold; text-align: center; margin: 0.5rem 0 0; font-size: 1rem; }
.board { text-align: center; margin: 0.75rem 0; }

.capture-tray {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 20px;
  margin: 0.15rem 0;
  opacity: 0.85;
}
.capture-tray svg { width: 18px; height: 18px; }
.material-plus { font-size: 0.75rem; font-weight: bold; margin-left: 0.3rem; opacity: 0.9; }
#move-status, #scan-status { text-align: center; font-size: 0.85rem; opacity: 0.8; margin: 0.4rem 0; }

#scan-legend { text-align: center; font-size: 0.85rem; opacity: 0.85; margin: 0.4rem 0; }
.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin: 0 0.2rem 0 0.6rem;
  vertical-align: middle;
}
.legend-swatch.legend-correct { background: var(--accent); }
.legend-swatch.legend-missed { background: var(--error); }

.chessboard {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border: 2px solid #333;
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.square svg { width: 82%; height: 82%; pointer-events: none; }

.square.light { background: #eeeed2; }
.square.dark { background: #769656; }
.square.lastmove { box-shadow: inset 0 0 0 3px rgba(255, 193, 7, 0.85); }
.square.selected { box-shadow: inset 0 0 0 3px var(--accent); }
.square.legal-target::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(76, 175, 80, 0.65);
}
.square.scan-marked { box-shadow: inset 0 0 0 3px var(--error); }
.square.scan-marked::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(229, 115, 115, 0.7);
}

.chessboard[data-mode] .square { cursor: pointer; }

/* Suite qui punit (review_result.html), un plateau par demi-coup au lieu d'une ligne de SAN
   concatenee -- defile horizontalement sur mobile plutot que de forcer 8 plateaux de 420px a la
   suite (voir punishing_pv_boards, replay/session.py). */
.pv-steps {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  padding: 0.5rem 0 0.15rem;
  margin: 0.5rem 0;
  -webkit-overflow-scrolling: touch;
}
.pv-step { flex: 0 0 auto; width: 130px; text-align: center; }
.pv-step-label { font-size: 0.8rem; font-weight: bold; margin: 0 0 0.25rem; opacity: 0.9; }
.pv-step .board { margin: 0; }
.pv-step .chessboard { max-width: 130px; border-width: 1px; }

/* Texte "Menace : ..." (played_pv[1] est une capture/echec, voir PvMenace) -- au-dessus de
   .pv-steps, avant que la sequence ne se joue. La case elle-meme est marquee sur le 1er plateau
   via le point rouge de coin deja utilise pour "case oubliee" au balayage (scan-missed). */
.pv-menace { font-size: 0.9rem; margin: 0.4rem 0; }

/* Solde materiel par demi-coup (PvStep.material_delta), sous chaque plateau de .pv-steps -- un
   deficit qui revient a 0 en fin de suite (echange nul en materiel) est un signal important en
   soi : la position est pire pour des raisons positionnelles, pas seulement materielles. */
.pv-step-material { font-size: 0.75rem; margin: 0.2rem 0 0; opacity: 0.9; }
.pv-step-material.material-down { color: var(--error); }
.pv-step-material.material-up { color: var(--accent); }
.pv-step-material.material-even { opacity: 0.6; }

/* Page resultat, premier plateau : badge de coin plutot qu'un rond centre (le rond centre des
   classes .legal-target/.scan-marked recouvrirait la piece, or ces cases-la ont presque toujours
   une piece dessus une fois le coup joue). */
.square.scan-correct::after,
.square.scan-missed::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
}
.square.scan-correct::after { background: var(--accent); }
.square.scan-missed::after { background: var(--error); }

form { display: flex; flex-direction: column; gap: 0.75rem; margin: 1rem 0; }

label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }

input, button {
  min-height: 44px;
  font-size: 16px;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid #555;
  background: #333;
  color: var(--fg);
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  font-weight: bold;
  cursor: pointer;
}

.link-button {
  background: none;
  border: none;
  color: var(--fg);
  text-decoration: underline;
  min-height: auto;
  font-size: 0.9rem;
  padding: 0;
}

.big-button {
  display: block;
  text-align: center;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: bold;
  padding: 1rem;
  border-radius: 8px;
  margin: 1rem 0;
}

.success { color: var(--accent); }
.error { color: var(--error); }

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f5f5;
    --fg: #1a1a1a;
    --card-bg: #ffffff;
  }
  input, button { background: #fff; color: var(--fg); }
}
