:root {
  --fond: #1c1d20;
  --fond-carte: #26282c;
  --fond-bouton: #33363b;
  --bord: #3a3d43;
  --texte: #ecedef;
  --texte-2: #a3a7ae;
  --accent: #6db567;
  --accent-texte: #0f1a0e;
  --alerte: #e07a5f;
  --courbe-blanc: #eceae4;
  --courbe-noir: #3a3c41;
  --courbe-milieu: #8b8f96;
  --fleche-meilleur: #6db567;
  --fleche-moteur: #4a8fd9;
  --case-claire: #e8ecd6;
  --case-foncee: #6f9a5b;
  --case-dernier: rgba(246, 222, 90, 0.55);
  --gouttiere: 16px;
  color-scheme: dark;
}

:root[data-echiquier="bois"] { --case-claire: #f0d9b5; --case-foncee: #b58863; }
:root[data-echiquier="bleu"] { --case-claire: #dee3e6; --case-foncee: #8ca2ad; }

@media (prefers-color-scheme: light) {
  :root {
    --fond: #f2f2ef;
    --fond-carte: #ffffff;
    --fond-bouton: #e7e7e3;
    --bord: #d9d9d4;
    --texte: #1d1e20;
    --texte-2: #63666c;
    --accent: #3f8f3a;
    --accent-texte: #ffffff;
    --courbe-noir: #4a4c51;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

html, body { margin: 0; background: var(--fond); color: var(--texte); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 20px; }
h2 { font-size: 17px; margin-bottom: 8px; }
h3 { font-size: 15px; margin: 14px 0 6px; }
p { margin: 6px 0; }
button, input { font: inherit; color: inherit; }
input[type="text"] {
  font-size: 16px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--bord); background: var(--fond); min-width: 0; flex: 1;
}

.chargement { padding: 40px var(--gouttiere); color: var(--texte-2); }
.discret { color: var(--texte-2); }
.petit-texte { font-size: 13px; }
.centre { text-align: center; }
.alerte { color: var(--alerte); }

.ecran { max-width: 1180px; margin: 0 auto; padding: 0 var(--gouttiere) 32px; }

.barre {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 0 12px; position: sticky; top: 0; z-index: 5; background: var(--fond);
}
.barre h1 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barre .titre { flex: 1; min-width: 0; }
.barre .titre h1 { font-size: 18px; }
.barre .titre .discret { font-size: 13px; }

.bouton-icone {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px; border: 0;
  background: var(--fond-bouton); text-decoration: none; font-size: 20px; cursor: pointer; flex: none;
}

.bouton {
  border: 0; border-radius: 10px; padding: 9px 14px; background: var(--fond-bouton);
  cursor: pointer; font-size: 15px; font-weight: 500; white-space: nowrap;
}
.bouton:disabled { opacity: 0.4; cursor: default; }
.bouton.principal { background: var(--accent); color: var(--accent-texte); }
.bouton.actif { outline: 2px solid var(--fleche-moteur); }
.bouton.large { display: block; width: 100%; margin: 10px 0; }

.carte {
  background: var(--fond-carte); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px;
}

/* Liste des parties */
.joueur-actif { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; font-weight: 600; }
.puces { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.puces::-webkit-scrollbar { display: none; }
.puce {
  border: 1px solid var(--bord); background: transparent; border-radius: 999px;
  padding: 5px 12px; font-size: 14px; white-space: nowrap; cursor: pointer;
}
.puce.active { background: var(--texte); color: var(--fond); border-color: var(--texte); }
.carte-partie { display: block; text-decoration: none; }
.carte-partie .ligne-1 { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.carte-partie .ligne-1 .discret { font-weight: 400; }
.carte-partie .ligne-2 { font-size: 14px; margin-top: 2px; }
.carte-partie .ligne-3 { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 14px; }
.adversaire { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.issue { margin-left: auto; font-size: 13px; padding: 2px 9px; border-radius: 999px; flex: none; }
.issue.gagnee { background: rgba(109, 181, 103, 0.2); color: #79c172; }
.issue.perdue { background: rgba(214, 65, 58, 0.18); color: #e26b64; }
.issue.nulle { background: rgba(160, 160, 160, 0.2); color: var(--texte-2); }
.pastille { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; border: 1px solid #777; }
.pastille.blanc { background: #f4f4f4; }
.pastille.noir { background: #222; }
.vide { color: var(--texte-2); text-align: center; padding: 24px 0; }

/* Écran d'analyse */
.disposition { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .disposition { grid-template-columns: minmax(0, 560px) minmax(0, 1fr); align-items: start; }
  .colonne-plateau { position: sticky; top: 70px; }
}
.joueur { display: flex; align-items: center; gap: 6px; padding: 6px 0; font-size: 15px; min-height: 36px; }
.joueur .nom { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.precision-mini { font-size: 13px; padding: 1px 7px; border-radius: 6px; background: var(--fond-bouton); }
.pendule { margin-left: auto; font-variant-numeric: tabular-nums; background: var(--fond-bouton); padding: 2px 8px; border-radius: 6px; font-size: 15px; }
.pendule.active { background: var(--texte); color: var(--fond); }

.plateau-et-barre { display: flex; gap: 6px; }
.barre-eval {
  position: relative; width: 18px; flex: none; border-radius: 4px; overflow: hidden; background: #3d3f44;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.barre-eval .remplissage { position: absolute; left: 0; right: 0; bottom: 0; background: #eeece6; transition: height 0.25s; }
.barre-eval.noirs-en-bas .remplissage { bottom: auto; top: 0; }
.barre-eval .valeur {
  position: absolute; left: 0; right: 0; top: 4px; font-size: 9px; font-weight: 700; text-align: center;
  color: #eee; writing-mode: vertical-rl; transform: rotate(180deg); letter-spacing: -0.3px;
}
.barre-eval .valeur.cote-blanc { top: auto; bottom: 4px; color: #333; }
.barre-eval.noirs-en-bas .valeur { top: auto; bottom: 4px; }
.barre-eval.noirs-en-bas .valeur.cote-blanc { top: 4px; bottom: auto; }

.echiquier { position: relative; flex: 1; aspect-ratio: 1; user-select: none; -webkit-user-select: none; touch-action: none; }
.grille { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; height: 100%; border-radius: 4px; overflow: hidden; }
.case { position: relative; }
.case.claire { background: var(--case-claire); }
.case.foncee { background: var(--case-foncee); }
.case.dernier::before, .case.selection::before { content: ""; position: absolute; inset: 0; background: var(--case-dernier); }
.case.echec::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, rgba(230, 40, 40, 0.85) 0%, rgba(230, 40, 40, 0) 70%); }
.case.cible::after { content: ""; position: absolute; left: 36%; top: 36%; width: 28%; height: 28%; border-radius: 50%; background: rgba(0, 0, 0, 0.22); }
.case.cible-prise::after { content: ""; position: absolute; inset: 4%; border-radius: 50%; border: 5px solid rgba(0, 0, 0, 0.22); }
.piece { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.coord { position: absolute; font-size: 10px; font-weight: 700; line-height: 1; pointer-events: none; }
.case.claire .coord { color: var(--case-foncee); }
.case.foncee .coord { color: var(--case-claire); }
.coord.rang { left: 3px; top: 3px; }
.coord.colonne { right: 3px; bottom: 2px; }
.badge {
  position: absolute; top: -9%; right: -9%; z-index: 3; width: 44%; height: 44%; min-width: 18px; min-height: 18px;
  border-radius: 50%; color: #fff; font-weight: 800; font-size: clamp(9px, 2.6vw, 14px);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45); letter-spacing: -0.5px;
}
.fleches { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.fantome { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 50; }
.promotion {
  position: absolute; inset: 0; z-index: 10; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 8px;
  background: rgba(0, 0, 0, 0.55); border-radius: 4px;
}
.promotion button { width: 22%; aspect-ratio: 1; border: 0; border-radius: 12px; background: var(--fond-carte); cursor: pointer; padding: 6%; }
.promotion button img { width: 100%; height: 100%; }
.promotion .annuler { width: 60%; aspect-ratio: auto; padding: 10px; }

.navigation { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 6px; margin-top: 6px; }
.navigation .bouton { font-size: 18px; padding: 8px 0; }
.navigation .bouton:last-child { font-size: 14px; padding: 8px 12px; }

.coach h2 { margin-bottom: 6px; }
.entete-coup { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.entete-coup .libelle { font-weight: 700; }
.entete-coup .coup { font-weight: 600; }
.symbole {
  display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%;
  color: #fff; font-weight: 800; font-size: 12px; letter-spacing: -0.5px; flex: none;
}
.symbole.petit { width: 18px; height: 18px; font-size: 10px; vertical-align: -3px; }
.symbole.mini { width: 14px; height: 14px; font-size: 8px; margin-right: 3px; vertical-align: 1px; }
.phrase { font-size: 16px; margin: 8px 0 10px; }
.phrase.reussi { color: var(--accent); font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.resume { margin: 6px 0 12px; padding-left: 18px; }
.resume li { margin: 4px 0; }
.progression { height: 6px; background: var(--fond-bouton); border-radius: 3px; overflow: hidden; margin: 8px 0; }
.progression div { height: 100%; background: var(--accent); transition: width 0.2s; }

.carte-courbe { padding: 10px; }
.courbe { height: 76px; border-radius: 6px; overflow: hidden; cursor: pointer; touch-action: none; }
.courbe svg { display: block; width: 100%; height: 76px; }

.precisions { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; text-align: center; gap: 8px; margin: 4px 0 10px; }
.precisions .grand { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tableau-bilan { width: 100%; border-collapse: collapse; font-size: 15px; }
.tableau-bilan td { padding: 4px 2px; }
.tableau-bilan td:nth-child(2) { text-align: left; padding-left: 12px; }
.tableau-bilan .nombre { width: 64px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

.grille-coups { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 2px 4px; font-size: 15px; }
.grille-coups .numero { color: var(--texte-2); padding: 4px 0; text-align: right; padding-right: 4px; }
.grille-coups .vide { padding: 4px 6px; text-align: left; }
.coup-liste { text-align: left; border: 0; background: transparent; padding: 4px 6px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.coup-liste.actuel { background: var(--fond-bouton); font-weight: 700; }

/* Réglages */
.ligne-formulaire { display: flex; gap: 8px; }
.choix-liste { display: grid; gap: 8px; margin-bottom: 10px; }
.choix { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.choix input { margin-top: 4px; accent-color: var(--accent); }
.credits p { font-size: 13px; }
