:root {
  --fond: #f6f5f1; --texte: #1d1d1b; --doux: #6b6b66; --ligne: #e2e0d9; --carte: #fff;
  --accent: #3b5bdb; --vert: #2f9e44; --rouge: #d9485f; --jaune: #e8a317;
}
@media (prefers-color-scheme: dark) {
  :root { --fond: #161615; --texte: #ecebe6; --doux: #9c9a92; --ligne: #2e2d2a; --carte: #1f1f1d; --accent: #748ffc; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--fond); color: var(--texte); font: 15px/1.5 system-ui, -apple-system, sans-serif; }
header { display: flex; align-items: center; gap: 24px; padding: 14px 24px; border-bottom: 1px solid var(--ligne); }
h1 { font-size: 18px; margin: 0; }
nav { display: flex; gap: 4px; }
nav button { border: 0; background: none; color: var(--doux); padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; }
nav button.actif { background: var(--carte); color: var(--texte); font-weight: 600; box-shadow: 0 0 0 1px var(--ligne); }
main { display: grid; grid-template-columns: minmax(320px, 560px) minmax(300px, 1fr); gap: 28px; padding: 24px; max-width: 1200px; margin: 0 auto; }
#plateau { width: 100%; aspect-ratio: 1; }
#sous-plateau { margin-top: 10px; color: var(--doux); font-size: 13px; min-height: 20px; }
aside section { display: flex; flex-direction: column; gap: 14px; }
.carte { background: var(--carte); border: 1px solid var(--ligne); border-radius: 10px; padding: 14px 16px; }
.carte p { margin: 0 0 8px; } .carte p:last-child { margin-bottom: 0; }
.filtres { display: flex; gap: 14px; flex-wrap: wrap; }
.filtres label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--doux); }
select, input, textarea { font: inherit; color: var(--texte); background: var(--carte); border: 1px solid var(--ligne); border-radius: 8px; padding: 6px 8px; }
input[type=number] { width: 90px; }
textarea { width: 100%; resize: vertical; margin-bottom: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
button { font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--ligne); background: var(--carte); color: var(--texte); }
button.principal { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button:disabled { opacity: .45; cursor: default; }
.choix { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.choix button.choisi { background: var(--accent); color: #fff; border-color: var(--accent); }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--ligne); color: var(--texte); margin-right: 4px; }
.titre { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.ok, .ko, .neutre { border-radius: 10px; padding: 14px 16px; border: 1px solid; }
.ok { border-color: var(--vert); background: color-mix(in srgb, var(--vert) 10%, transparent); }
.ko { border-color: var(--rouge); background: color-mix(in srgb, var(--rouge) 10%, transparent); }
.neutre { border-color: var(--jaune); background: color-mix(in srgb, var(--jaune) 10%, transparent); }
.ligne-pv { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.doux { color: var(--doux); font-size: 13px; }
.pendule { font: 600 44px/1 ui-monospace, Menlo, monospace; text-align: center; padding: 12px; border-radius: 10px; background: var(--carte); border: 1px solid var(--ligne); }
.pendule.court { color: var(--rouge); }
.chiffres { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.chiffre { font-size: 26px; font-weight: 700; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--ligne); font-size: 14px; }
th { color: var(--doux); font-weight: 600; font-size: 13px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.barre { display: inline-block; width: 100px; height: 8px; background: var(--ligne); border-radius: 4px; vertical-align: middle; }
.barre > span { display: block; height: 100%; border-radius: 4px; background: var(--vert); }
a { color: var(--accent); }
@media (max-width: 860px) { main { grid-template-columns: 1fr; } }
[hidden] { display: none !important; }
.coup-pv { padding: 2px 6px; margin: 1px 0; border: 0; background: none; border-radius: 6px; font: inherit; }
.coup-pv:hover { background: var(--ligne); }
.coup-pv.courant { background: var(--accent); color: #fff; }
.nav-ligne { display: flex; gap: 6px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.nav-ligne button { padding: 4px 12px; }
.explications { margin: 4px 0 8px; padding-left: 20px; }
.explications li { margin-bottom: 2px; }
.explication { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--ligne); }
.journal { max-height: 380px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.entree { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--ligne); }
.entree p { margin: 0 0 4px; }
.entree.moteur { background: color-mix(in srgb, var(--ligne) 40%, transparent); }
.badge.bon { background: color-mix(in srgb, var(--vert) 25%, transparent); }
.badge.mauvais { background: color-mix(in srgb, var(--rouge) 25%, transparent); }
#erreur { position: sticky; top: 0; z-index: 10; background: var(--rouge); color: #fff; padding: 10px 24px; cursor: pointer; font-weight: 600; }
/* Colonne de gauche fixe pendant le défilement ; en mode fiche, l'échiquier rétrécit pour laisser la place au cadre */
#zone-plateau { position: sticky; top: 12px; align-self: start; }
body[data-onglet=ouvertures] #plateau { width: min(100%, calc(100vh - 420px)); min-width: 300px; }
.visionneuse { margin-top: 10px; max-height: 340px; overflow-y: auto; }
.section-ouv summary { cursor: pointer; list-style: none; }
.section-ouv summary::-webkit-details-marker { display: none; }
.section-ouv summary::before { content: '▸ '; color: var(--doux); }
.section-ouv[open] summary::before { content: '▾ '; }
.section-ouv ul { padding-left: 20px; }
.lignes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.btn-ligne { padding: 5px 10px; font-size: 13px; }
.btn-ligne.ligne { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.btn-ligne.piege { border-color: var(--rouge); color: var(--rouge); }
@media (max-width: 860px) { #zone-plateau { position: static; } }
/* Onglet Ouvertures : 3 colonnes (règles d'or | échiquier | fiches) */
body[data-onglet=ouvertures] main { grid-template-columns: minmax(220px, 300px) minmax(320px, 1fr) minmax(340px, 1fr); max-width: 1600px; }
#ouv-gauche { position: sticky; top: 12px; align-self: start; max-height: calc(100vh - 24px); overflow-y: auto; }
#ouv-gauche ul { padding-left: 18px; font-size: 14px; }
#ouv-gauche li { margin-bottom: 6px; }
body[data-onglet=ouvertures] #plateau { width: min(100%, calc(100vh - 420px)); margin: 0 auto; }
@media (max-width: 1100px) { body[data-onglet=ouvertures] main { grid-template-columns: minmax(320px, 1fr) minmax(340px, 1fr); }
  #ouv-gauche { grid-column: 1 / -1; position: static; max-height: none; } }
@media (max-width: 860px) { body[data-onglet=ouvertures] main { grid-template-columns: 1fr; } }
body[data-onglet=ouvertures] #sous-plateau { display: none; }
/* Menu à deux niveaux des ouvertures */
#ouv-menu .niveau1 { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
#ouv-menu .groupe { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#ouv-menu .groupe .doux { min-width: 110px; }
#ouv-menu .niveau1 button.choisi { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
#ouv-menu .niveau2 { padding: 8px; background: var(--carte); border: 1px solid var(--ligne); border-radius: 10px; }
#ouv-menu .niveau2 button { font-size: 13px; padding: 5px 10px; }
.btn-ligne.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-ligne.habitude { border-color: var(--jaune); }
.coup-pv.commun { opacity: .6; }
/* Page Partie */
#barre-eval { position: relative; height: 18px; background: #333; border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
#barre-blanche { height: 100%; width: 50%; background: #f2f2ee; transition: width .4s; }
#barre-texte { position: absolute; top: 1px; left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 700; color: var(--texte); background: var(--carte); padding: 0 8px; border-radius: 4px; line-height: 16px; }
.case { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--doux); margin: 8px 0; }
.deux-plans { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.badge.cat-meilleur, .badge.cat-excellent { background: color-mix(in srgb, var(--vert) 30%, transparent); }
.badge.cat-bon { background: color-mix(in srgb, var(--vert) 15%, transparent); }
.badge.cat-imprecision { background: color-mix(in srgb, var(--jaune) 30%, transparent); }
.badge.cat-erreur { background: color-mix(in srgb, var(--rouge) 25%, transparent); }
.badge.cat-gaffe { background: var(--rouge); color: #fff; }
.coup-pv.cat-imprecision { color: var(--jaune); font-weight: 600; }
.coup-pv.cat-erreur { color: var(--rouge); font-weight: 600; }
.coup-pv.cat-gaffe { color: #fff; background: var(--rouge); }
.coup-pv.cat-meilleur { color: var(--vert); }
/* Onglet Partie : 3 colonnes (mode et statistiques | échiquier | analyse) */
body[data-onglet=partie] main { grid-template-columns: minmax(260px, 340px) minmax(320px, 1fr) minmax(340px, 1fr); max-width: 1700px; }
#partie-gauche { position: sticky; top: 12px; align-self: start; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 24px); overflow-y: auto; }
#partie-gauche .filtres { flex-direction: column; }
#partie-gauche select, #partie-gauche input { width: 100%; }
body[data-onglet=partie] #plateau { width: min(100%, calc(100vh - 200px)); margin: 0 auto; }
#pendules { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.pendule-p { flex: 1; font: 600 22px/1 ui-monospace, Menlo, monospace; padding: 6px 10px; border-radius: 8px; background: var(--carte); border: 1px solid var(--ligne); text-align: center; }
.pendule-p.actif { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.pendule-p.court { color: var(--rouge); }
@media (max-width: 1150px) { body[data-onglet=partie] main { grid-template-columns: minmax(320px, 1fr) minmax(340px, 1fr); }
  #partie-gauche { grid-column: 1 / -1; position: static; max-height: none; } }
@media (max-width: 860px) { body[data-onglet=partie] main { grid-template-columns: 1fr; } }
.badge.cat-brillant { background: #1c7ed6; color: #fff; }
.badge.cat-tres_bon { background: #3b5bdb; color: #fff; }
.coup-pv.cat-brillant { color: #fff; background: #1c7ed6; }
.coup-pv.cat-tres_bon { color: #3b5bdb; font-weight: 700; }
.tableau-bilan td.num { min-width: 40px; }
#partie-gauche input[type=checkbox] { width: auto; }
#partie-gauche .case { align-items: flex-start; }
.stat-camp { padding: 8px 0; border-bottom: 1px solid var(--ligne); }
.stat-camp:last-of-type { border-bottom: 0; }
.stat-chiffres { display: flex; gap: 14px; margin: 4px 0; }
.stat-chiffres span { display: flex; flex-direction: column; }
.stat-chiffres b { font-size: 18px; }
.stat-chiffres small { color: var(--doux); font-size: 11px; }
.coup-pv.courant { color: #fff !important; background: var(--accent) !important; }

/* Connexion par clé */
#compte { margin-left: auto; color: var(--doux); display: flex; align-items: center; gap: 8px; }
button.lien { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
#connexion { display: flex; justify-content: center; padding-top: 12vh; }
#connexion[hidden] { display: none; }
#connexion-form { width: min(420px, 92vw); display: flex; flex-direction: column; gap: 12px; }
#connexion-form h2 { margin: 0; }
#connexion-form input { font: 600 18px/1.4 ui-monospace, monospace; letter-spacing: 1px; padding: 10px 12px; text-align: center; }
#connexion-erreur { min-height: 1.5em; margin: 0; color: var(--rouge); }
main[hidden], nav[hidden], #compte[hidden] { display: none; }

/* Profil */
#onglet-profil .carte { margin-bottom: 16px; }
#onglet-profil h3 { margin: 4px 0 8px; }
.profil-classe { margin: 8px 0; }
.profil-classe strong { display: block; margin-bottom: 2px; }
label.case { display: inline-flex; align-items: center; gap: 6px; margin: 2px 18px 2px 0; }
label.case input { width: auto; }
#profil-barre .barre { display: block; width: 100%; }

/* Bilan */
#onglet-bilan h3 { margin: 22px 0 6px; }
#onglet-bilan td.bon { color: var(--vert); font-weight: 600; }
#onglet-bilan td.faible { color: var(--rouge); font-weight: 600; }
.barre.rouge > span { background: var(--rouge); }
.priorites li { margin-bottom: 8px; }
.grille-gaffes { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.grille-gaffes figure { margin: 0; }
.grille-gaffes svg { width: 100%; height: auto; display: block; }
.grille-gaffes figcaption { font-size: 13px; margin-top: 6px; }
.deux { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.deux h4 { margin: 4px 0; }
body[data-onglet=bilan] main { grid-template-columns: minmax(0, 1fr); max-width: 1100px; }
