/* Palette inspirée de chess.com : fond sombre, boutons verts, échiquier vert et crème */
:root {
  --bg: #312e2b; --card: #262421; --ink: #e8e6e3; --muted: #989795; --line: #3c3a37;
  --accent: #81b64c; --accent-fonce: #45753c; --accent-soft: #3a4a2a;
  --danger: #e06666; --danger-soft: #4a2a28; --warn: #f7c045; --warn-soft: #4a3f22; --ok: #9fcf6c; --ok-soft: #33432a;
  --barre: #262421; --survol: #3c3a37; --choisi: #4b4847; --fort: #ffffff;
  --case-claire: #ebecd0; --case-foncee: #739552; --case-dernier: rgba(245, 246, 130, .55);
  --gaffe: #ca3431; --erreur: #e58f2a; --imprecision: #f7c045; --meilleur: #81b64c; --bon: #95b776; --livre: #a88865;
  --gagne: #81b64c; --perdu: #ca3431; --nul: #989795;
  --radius: 8px; --shadow: 0 1px 3px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 4px; color: var(--fort); }
h2 { font-size: 15px; margin: 20px 0 8px; color: var(--fort); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); min-height: 1em; }
[hidden] { display: none !important; }

.btn { border: 0; background: var(--survol); color: var(--ink); border-radius: 6px; padding: 8px 14px;
  box-shadow: 0 3px 0 #1f1e1c; font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: var(--choisi); }
.btn.primary { background: var(--accent); box-shadow: 0 3px 0 var(--accent-fonce); color: #fff; }
.btn.primary:hover { background: #a3d160; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input { font: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px; background: #1f1e1c; color: var(--ink); width: 100%; }
input:focus { outline: 2px solid var(--accent-fonce); border-color: var(--accent); }

.top { position: sticky; top: 0; z-index: 20; background: var(--barre); color: var(--fort); display: flex;
  align-items: center; gap: 14px; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); box-shadow: 0 1px 0 #1a1917; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--fort); font-weight: 700; }
.logo-img { width: 28px; height: 28px; }
.tabs { display: flex; gap: 2px; }
.tabs a { color: var(--muted); padding: 7px 12px; border-radius: 6px; font-weight: 600; }
.tabs a.on, .tabs a:hover { background: var(--survol); color: var(--fort); }

main { max-width: 1100px; margin: 0 auto; padding: 14px 16px 60px; }
.carte { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }

/* connexion / choix du joueur */
.centre { min-height: 80vh; display: grid; place-items: center; }
.centre .carte { width: 100%; max-width: 380px; display: grid; gap: 12px; text-align: center; padding: 26px; }
.centre .logo-img { width: 56px; height: 56px; margin: 0 auto; }

/* liste des parties */
.barre { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.barre .titre { flex: 1 1 200px; }
.puces { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.puce { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 4px 12px; font-size: 13px; cursor: pointer; color: var(--ink); }
.puce.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.liste { display: grid; gap: 8px; }
.partie { display: grid; grid-template-columns: 6px 1fr auto; gap: 12px; align-items: center; background: var(--card);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px 10px 0; color: var(--ink); overflow: hidden; }
.partie:hover { background: #2b2926; }
.partie .bande { align-self: stretch; border-radius: 0 4px 4px 0; }
.partie.gagne .bande { background: var(--gagne); } .partie.perdu .bande { background: var(--perdu); } .partie.nul .bande { background: var(--nul); }
.partie .ligne1 { font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; color: var(--fort); }
.partie .ligne2 { font-size: 13px; color: var(--muted); }
.pion { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid #5d5b58; }
.pion.b { background: #fff; } .pion.n { background: #1f1e1c; }
.badge { font-size: 12px; border-radius: 99px; padding: 2px 9px; background: var(--survol); color: var(--ink); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.ko { background: var(--danger-soft); color: var(--danger); }
.badge.attente { background: var(--warn-soft); color: var(--warn); }
.droite { display: grid; gap: 4px; justify-items: end; }

/* partie analysée */
.analyse { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .analyse { grid-template-columns: 1fr; } }
.joueur-ligne { display: flex; justify-content: space-between; align-items: center; padding: 4px 2px; font-size: 14px; gap: 8px; }
.joueur-ligne b { font-weight: 600; color: var(--fort); }
.zone-plateau { display: grid; grid-template-columns: 18px 1fr; gap: 6px; }
.barre-eval { position: relative; border-radius: 4px; overflow: hidden; background: #403d39; }
.barre-eval .blanc { position: absolute; left: 0; right: 0; bottom: 0; background: #fff; transition: height .25s; }
.barre-eval .chiffre { position: absolute; left: 0; right: 0; font-size: 9px; text-align: center; font-weight: 700; z-index: 1; }
.plateau { position: relative; aspect-ratio: 1; width: 100%; display: grid; grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr); border-radius: 4px; overflow: visible; touch-action: pan-y; user-select: none; box-shadow: var(--shadow); }
.case { position: relative; }
.case.c { background: var(--case-claire); } .case.f { background: var(--case-foncee); }
.case.dernier::after { content: ""; position: absolute; inset: 0; background: var(--case-dernier); }
.case img { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; }
.case .coord { position: absolute; font-size: 10px; font-weight: 700; z-index: 2; }
.case .coord.rang { top: 2px; left: 3px; } .case .coord.col { bottom: 1px; right: 3px; }
.case.c .coord { color: var(--case-foncee); } .case.f .coord { color: var(--case-claire); }
.case .marque { position: absolute; top: -2px; right: -2px; z-index: 3; width: 42%; height: 42%; max-width: 26px; max-height: 26px;
  border-radius: 50%; color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.fleches { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.nav { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 10px; }
.nav .btn { font-size: 18px; padding: 8px 4px; }
.nav .btn.decisif { font-size: 14px; letter-spacing: -3px; background: var(--accent); box-shadow: 0 3px 0 var(--accent-fonce); color: #fff; }
.nav .btn.decisif:disabled { background: var(--survol); box-shadow: 0 3px 0 #1f1e1c; }
.aide-nav { text-align: center; margin-top: 8px; }

/* bulle explicative posée sur l'échiquier */
.bulle { position: absolute; z-index: 6; background: #fff; color: #262421; border-radius: 8px; padding: 8px 26px 8px 10px;
  font-size: 13px; line-height: 1.35; box-shadow: 0 4px 14px rgba(0,0,0,.45); cursor: default; }
.bulle::after { content: ""; position: absolute; left: var(--pointe); margin-left: -7px; border: 7px solid transparent; }
.bulle.dessus::after { top: 100%; border-top-color: #fff; }
.bulle.dessous::after { bottom: 100%; border-bottom-color: #fff; }
.bulle .b-titre { font-weight: 800; margin-bottom: 3px; }
.bulle .t-imprecision { color: #b88a10; }
.bulle .b-conseil { margin-top: 4px; color: #45753c; }
.bulle .b-situation { margin-top: 4px; padding-top: 4px; border-top: 1px solid #e4e2df; color: #5d5b58; font-weight: 600; }
.bulle .b-fermer { position: absolute; top: 2px; right: 4px; border: 0; background: none; font-size: 18px; line-height: 1;
  color: #8b8987; cursor: pointer; padding: 2px 4px; }

.graphe { margin-top: 10px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; }
.graphe svg { width: 100%; height: 90px; display: block; cursor: pointer; }

.panneau { display: grid; gap: 12px; }
.precisions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.precisions .carte { text-align: center; padding: 10px; }
.precisions .gros { font-size: 26px; font-weight: 700; color: var(--fort); }
.compte { display: flex; justify-content: center; gap: 10px; font-size: 12px; margin-top: 4px; flex-wrap: wrap; }
.coup-actuel { min-height: 92px; }
.coup-actuel .titre { font-weight: 700; font-size: 16px; display: flex; gap: 8px; align-items: center; color: var(--fort); }
.coup-actuel p { margin: 6px 0 0; }
.pastille { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 99px;
  color: #fff; font-size: 12px; font-weight: 800; }
.k-gaffe { background: var(--gaffe); } .k-erreur { background: var(--erreur); } .k-imprecision { background: var(--imprecision); }
.k-meilleur { background: var(--meilleur); } .k-bon { background: var(--bon); } .k-livre { background: var(--livre); }
.t-gaffe { color: var(--gaffe); } .t-erreur { color: var(--erreur); } .t-imprecision { color: var(--imprecision); } .t-meilleur { color: var(--meilleur); }

.coups { max-height: 340px; overflow: auto; display: grid; grid-template-columns: 34px 1fr 1fr; font-size: 14px; }
.coups .num { color: var(--muted); padding: 3px 0; }
.coups .cp { padding: 3px 6px; border-radius: 4px; cursor: pointer; display: flex; justify-content: space-between; gap: 4px; }
.coups .cp:hover { background: var(--survol); }
.coups .cp.on { background: var(--choisi); color: var(--fort); font-weight: 700; }
.coups .cp .h { color: var(--muted); font-size: 11px; font-weight: 400; }
.moments { display: grid; gap: 6px; }
.moment { display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px;
  cursor: pointer; background: #2b2926; font: inherit; color: inherit; text-align: left; }
.moment:hover { background: var(--survol); }
.progression { height: 10px; border-radius: 99px; background: var(--survol); overflow: hidden; margin: 10px 0 4px; }
.progression div { height: 100%; background: var(--accent); transition: width .4s; }

/* bilan */
.grille { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.chiffres { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.chiffres .carte { text-align: center; }
.chiffres .gros { font-size: 24px; font-weight: 700; color: var(--fort); }
.barres { display: grid; gap: 6px; }
.barre-res { display: grid; grid-template-columns: minmax(90px, 1.2fr) 2fr 44px; gap: 8px; align-items: center; font-size: 13px; }
.barre-res .nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empile { display: flex; height: 14px; border-radius: 99px; overflow: hidden; background: var(--line); }
.empile .g { background: var(--gagne); } .empile .n { background: var(--nul); } .empile .p { background: var(--perdu); }
.legende { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.legende i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.conseil { background: var(--warn-soft); color: #f3e3b5; border-radius: var(--radius); padding: 10px 12px; font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--fort); color: #262421;
  padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.4); font-weight: 600; }
