:root {
  --fond: #12141c; --carte: #1b1f2b; --carte2: #242938; --trait: #2f3547;
  --texte: #e9ebf2; --doux: #9aa1b5; --accent: #7c8cff; --accent-texte: #0d1020;
  --case-claire: #e6e9f0; --case-sombre: #6f86a8;
  --brillant: #1fb8a8; --tresbon: #4c8dde; --meilleur: #6bbf3b; --excellent: #8fc65a; --bon: #8aa38a;
  --theorique: #b08b62; --imprecision: #e8c33a; --erreur: #ee9335; --manque: #ee6b62; --gaffe: #d93a3a; --force: #8a90a3;
  color-scheme: dark;
}
:root[data-theme="clair"] {
  --fond: #f2f3f7; --carte: #ffffff; --carte2: #eceef4; --trait: #d6d9e3;
  --texte: #1a1d29; --doux: #5d6478; --accent: #4353d6; --accent-texte: #ffffff;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--fond); color: var(--texte); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); margin: 0 0 .3em; }
h2 { font-size: 1.05rem; margin: 0 0 .7em; }
.petit { font-size: .85rem; color: var(--doux); margin: .5em 0 0; }

.barre { display: flex; align-items: center; justify-content: space-between; padding: .6rem 1rem; border-bottom: 1px solid var(--trait); }
.logo { display: flex; align-items: center; gap: .5rem; color: var(--texte); text-decoration: none; font-weight: 700; font-size: 1.2rem; letter-spacing: .02em; }
.barre-droite { display: flex; gap: .5rem; }

.bouton { font: inherit; color: var(--texte); background: var(--carte2); border: 1px solid var(--trait); border-radius: 8px; padding: .5rem .9rem; cursor: pointer; }
.bouton:hover { border-color: var(--accent); }
.bouton:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible, .partie:focus-visible, .coup:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.bouton.principal { background: var(--accent); color: var(--accent-texte); border-color: var(--accent); font-weight: 600; }
.bouton.discret { background: transparent; }
input, textarea, select { font: inherit; color: var(--texte); background: var(--fond); border: 1px solid var(--trait); border-radius: 8px; padding: .55rem .7rem; }
textarea { width: 100%; resize: vertical; margin: .7rem 0; font-family: ui-monospace, monospace; font-size: .9rem; }

#accueil { max-width: 720px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.hero { text-align: center; padding: 1.5rem 0 1rem; }
.sous-titre { color: var(--doux); margin: 0 0 1.2rem; }
.ligne-saisie { display: flex; gap: .5rem; }
.ligne-saisie input { flex: 1; min-width: 0; }
.carte { background: var(--carte); border: 1px solid var(--trait); border-radius: 12px; padding: 1rem; margin-top: 1rem; }
summary { cursor: pointer; font-weight: 600; }
.message { margin: .8rem 0 0; padding: .6rem .8rem; border-radius: 8px; background: var(--carte2); border-left: 4px solid var(--erreur); text-align: left; }
.message.info { border-left-color: var(--accent); }
.pied { color: var(--doux); font-size: .82rem; margin-top: 2rem; }

.liste-parties { list-style: none; margin: .8rem 0 0; padding: 0; display: grid; gap: .4rem; }
.partie { width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: .7rem; align-items: center; text-align: left; font: inherit; color: var(--texte); background: var(--carte2); border: 1px solid var(--trait); border-radius: 8px; padding: .5rem .7rem; cursor: pointer; }
.partie:hover { border-color: var(--accent); }
.pastille { width: 1.6rem; height: 1.6rem; border-radius: 6px; display: grid; place-items: center; font-weight: 700; font-size: .8rem; color: #fff; }
.pastille.gagne { background: var(--meilleur); } .pastille.perdu { background: var(--gaffe); } .pastille.nul { background: var(--force); }
.partie-info { font-size: .82rem; color: var(--doux); }
.partie-date { font-size: .82rem; color: var(--doux); white-space: nowrap; }

/* ---------- Revue ---------- */
#revue { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 420px); gap: 1.2rem; max-width: 1250px; margin: 0 auto; padding: 1rem; align-items: start; }
.zone-plateau { --cote: min(100%, calc(100vh - 215px)); max-width: 820px; width: 100%; margin: 0 auto; position: sticky; top: .5rem; }
.joueur { display: flex; align-items: center; gap: .5rem; padding: .35rem 0 .35rem 34px; min-height: 2rem; font-weight: 600; }
.joueur .pion { width: .9rem; height: .9rem; border-radius: 3px; border: 1px solid var(--doux); }
.joueur .pion.w { background: #fff; } .joueur .pion.b { background: #222; }
.joueur .elo { color: var(--doux); font-weight: 400; }
.joueur .score { margin-left: auto; color: var(--doux); font-weight: 400; }
.plateau-ligne { display: flex; gap: 8px; width: var(--cote); min-width: 240px; margin: 0 auto; }
.jauge { position: relative; flex: 0 0 26px; border-radius: 6px; overflow: hidden; background: #2b2d33; border: 1px solid var(--trait); }
.jauge-blanc { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: #f4f5f8; transition: height .35s ease; }
.jauge.retournee .jauge-blanc { bottom: auto; top: 0; }
.jauge-texte { position: absolute; left: 0; right: 0; text-align: center; font-size: .62rem; font-weight: 700; padding: 3px 0; }
.jauge-texte.pour-blancs { bottom: 0; color: #222; } .jauge-texte.pour-noirs { top: 0; color: #eee; }
.jauge.retournee .jauge-texte.pour-blancs { bottom: auto; top: 0; } .jauge.retournee .jauge-texte.pour-noirs { top: auto; bottom: 0; }
.plateau-cadre { position: relative; flex: 1; aspect-ratio: 1; border-radius: 6px; overflow: hidden; }
.plateau { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; height: 100%; user-select: none; }
.case { position: relative; background: var(--case-claire); }
.case.sombre { background: var(--case-sombre); }
.case img { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }
.case .coord { position: absolute; font-size: clamp(.5rem, 1.3vw, .72rem); font-weight: 700; color: var(--case-sombre); z-index: 1; }
.case.sombre .coord { color: var(--case-claire); }
.coord.rang { top: 2px; left: 3px; } .coord.colonne { bottom: 1px; right: 3px; }
.case.marque::before { content: ""; position: absolute; inset: 0; background: var(--teinte, #f6e27a); opacity: .55; }
.badge { position: absolute; top: -6%; right: -6%; width: 42%; height: 42%; border-radius: 50%; z-index: 3; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: clamp(.55rem, 1.6vw, .95rem); background: var(--teinte); box-shadow: 0 1px 4px rgba(0,0,0,.45); border: 2px solid rgba(255,255,255,.85); }
.case.bord-haut .badge { top: 2%; } .case.bord-droit .badge { right: 2%; }
.fleches { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.fleches line { stroke: var(--meilleur); stroke-width: .17; stroke-linecap: round; opacity: .9; }
.fleches polygon { fill: var(--meilleur); opacity: .9; }
.navigation { display: flex; gap: .4rem; justify-content: center; padding: .7rem 0 0 34px; }
.navigation .bouton { flex: 1; max-width: 5rem; font-size: 1.3rem; line-height: 1; padding: .45rem; }

.panneau .carte:first-child { margin-top: 0; }
.progres { height: 10px; background: var(--carte2); border-radius: 5px; overflow: hidden; }
.progres-barre { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
#btnAnnuler { margin-top: .7rem; }

.detail { min-height: 5.6rem; }
.detail-titre { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; }
.signe { flex: 0 0 auto; width: 1.7rem; height: 1.7rem; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 800; font-size: .8rem; background: var(--teinte); }
.signe.mini { width: 1.2rem; height: 1.2rem; font-size: .6rem; }
.detail-note { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; background: var(--carte2); border-radius: 6px; padding: .1rem .45rem; font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.actions .bouton { flex: 1; white-space: nowrap; }
.resume .niveau { font-weight: 700; font-variant-numeric: tabular-nums; }
.detail p { margin: .5rem 0 0; color: var(--doux); }
.detail strong { color: var(--texte); }

.graphique { position: relative; height: 90px; border-radius: 6px; overflow: hidden; background: #2b2d33; cursor: pointer; touch-action: none; }
#graphSvg { position: absolute; inset: 0; width: 100%; height: 100%; }
#graphSvg .aire { fill: #f4f5f8; }
#graphSvg .milieu { stroke: #8a90a3; stroke-width: .6; vector-effect: non-scaling-stroke; }
.graph-point { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--teinte); border: 1px solid rgba(0,0,0,.4); pointer-events: none; }
.graph-curseur { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--accent); pointer-events: none; }

.resume { display: grid; grid-template-columns: 1fr auto 1fr; gap: .3rem .8rem; align-items: center; }
.resume .nom { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resume .droite { text-align: right; }
.resume .gauche { text-align: left; }
.resume .centre { text-align: center; color: var(--doux); font-size: .85rem; display: flex; align-items: center; gap: .4rem; justify-content: center; }
.resume .precision { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.resume .nombre { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--teinte); }
.resume .nombre.zero { color: var(--doux); font-weight: 400; opacity: .6; }
.resume .separateur { grid-column: 1 / -1; border-top: 1px solid var(--trait); margin: .3rem 0; }

.coups { max-height: 300px; overflow-y: auto; display: grid; grid-template-columns: 2.4rem 1fr 1fr; gap: 2px 4px; align-items: center; font-variant-numeric: tabular-nums; }
.coups .numero { color: var(--doux); font-size: .85rem; }
.coup { display: flex; align-items: center; gap: .35rem; font: inherit; color: var(--texte); background: transparent; border: 0; border-radius: 6px; padding: .2rem .4rem; cursor: pointer; text-align: left; }
.coup:hover { background: var(--carte2); }
.coup.actif { background: var(--accent); color: var(--accent-texte); font-weight: 700; }
.outils { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.outils label { display: flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--doux); }

.t-brillant { --teinte: var(--brillant); } .t-tresbon { --teinte: var(--tresbon); } .t-meilleur { --teinte: var(--meilleur); }
.t-excellent { --teinte: var(--excellent); } .t-bon { --teinte: var(--bon); } .t-theorique { --teinte: var(--theorique); }
.t-imprecision { --teinte: var(--imprecision); } .t-erreur { --teinte: var(--erreur); } .t-manque { --teinte: var(--manque); }
.t-gaffe { --teinte: var(--gaffe); } .t-force { --teinte: var(--force); }

@media (max-width: 900px) {
  #revue { grid-template-columns: 1fr; padding: .5rem; }
  .zone-plateau { --cote: 100%; position: static; }
  .joueur, .navigation { padding-left: 0; }
  .jauge { flex-basis: 18px; }
  .ligne-saisie { flex-wrap: wrap; }
  .ligne-saisie input { flex-basis: 100%; }
  .ligne-saisie .bouton { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
