:root {
  --rouge: #8b1a1a;
  --fond: #f6f5f2;
  --carte: #ffffff;
  --texte: #222;
  --gris: #6b6b6b;
  --vert: #2e7d32;
  --orange: #ef6c00;
  --erreur: #c62828;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fond);
  color: var(--texte);
  font-size: 17px;
  line-height: 1.45;
}
header {
  background: var(--rouge);
  color: white;
  padding: 0.6rem 1rem calc(0.4rem + env(safe-area-inset-top));
  position: sticky;
  top: 0;
}
header h1 { font-size: 1.1rem; margin: 0 0 0.4rem; }
nav { display: flex; gap: 0.4rem; }
nav button {
  flex: 1;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.95rem;
}
nav button.actif { background: white; color: var(--rouge); font-weight: 600; }
main { max-width: 760px; margin: 0 auto; padding: 1rem; }
.vue { background: var(--carte); border-radius: 10px; padding: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
h2 { font-size: 1.2rem; margin: 0.5rem 0 1rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.3rem; color: var(--rouge); }
label { display: block; margin: 0.6rem 0; }
select, textarea { width: 100%; font-size: 1rem; padding: 0.5rem; border: 1px solid #ccc; border-radius: 6px; font-family: inherit; }
fieldset { border: 1px solid #ddd; border-radius: 6px; margin: 0.8rem 0; }
fieldset label { display: inline-block; margin: 0.3rem 0.8rem 0.3rem 0; }
button, .bouton {
  font-size: 1rem;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  border: 1px solid #bbb;
  background: #eee;
  cursor: pointer;
  display: inline-block;
  margin: 0.3rem 0;
}
button.principal { background: var(--rouge); color: white; border: none; width: 100%; padding: 0.8rem; font-weight: 600; }
button.danger { color: var(--erreur); border-color: var(--erreur); background: white; }
.info { color: var(--gris); font-size: 0.9rem; }
.chemin { color: var(--gris); font-size: 0.85rem; margin: 0 0 0.2rem; }
.meta { font-size: 0.8rem; color: var(--gris); margin: 0; }
#zone-choix button.choix {
  display: block;
  width: 100%;
  text-align: left;
  background: white;
  margin: 0.4rem 0;
}
#zone-choix button.choix.selection { border: 2px solid var(--rouge); }
#zone-choix button.choix.juste { background: #e8f5e9; border-color: var(--vert); }
#zone-choix button.choix.faux { background: #ffebee; border-color: var(--erreur); }
#verdict { font-weight: 600; font-size: 1.05rem; }
#verdict.su { color: var(--vert); }
#verdict.partiel { color: var(--orange); }
#verdict.rate { color: var(--erreur); }
#r-points li { margin: 0.4rem 0; }
.citation { display: block; color: var(--gris); font-size: 0.85rem; font-style: italic; }
#auto-eval { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-top: 1rem; }
#auto-eval p { width: 100%; margin: 0; }
button.note { flex: 1; color: white; border: none; font-weight: 600; }
button.note.su { background: var(--vert); }
button.note.partiel { background: var(--orange); }
button.note.rate { background: var(--erreur); }
details { margin-top: 1.2rem; font-size: 0.9rem; }
.bas { margin-top: 1rem; color: var(--gris); font-size: 0.9rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
td, th { padding: 0.35rem; border-bottom: 1px solid #eee; text-align: right; }
td:first-child, th:first-child { text-align: left; }
.barre { height: 6px; border-radius: 3px; background: #eee; overflow: hidden; display: flex; margin-top: 3px; }
.barre span { display: block; height: 100%; }

/* ---------- Schémas ---------- */
.schema { position: relative; display: block; width: 100%; user-select: none; }
.schema.edition { touch-action: none; }  /* tracer au doigt seulement dans l'éditeur */
.schema img { display: block; width: 100%; height: auto; }
.cache {
  position: absolute; background: #fff; border: 2px solid var(--rouge); border-radius: 4px;
  color: var(--rouge); font-weight: 800; font-size: clamp(1rem, 4.5vw, 1.4rem); min-width: 1.8em; min-height: 1.6em;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.cache.juste { border-color: var(--vert); color: var(--vert); background: #e8f5e9; font-weight: 500; }
.cache.faux { border-color: var(--erreur); color: var(--erreur); background: #ffebee; font-weight: 500; }
.cache.revele { line-height: 1; text-align: left; padding: 0 4px; overflow: visible; z-index: 2;
  white-space: nowrap; min-width: 0; min-height: 0; width: max-content; justify-content: flex-start;
  box-shadow: 0 1px 3px rgba(0,0,0,0.35); }
#schema-reponses li { margin: 0.4rem 0; }
#schema-reponses li::marker { font-weight: 800; font-size: 1.2rem; color: var(--rouge); }
#schema-reponses input { width: 100%; font-size: 1.1rem; padding: 0.5rem; border: 1px solid #ccc; border-radius: 6px; }
#schema-reponses .corr { display: block; font-size: 1.15rem; font-weight: 700; margin-top: 0.25rem;
  word-break: normal; overflow-wrap: normal; hyphens: none; }
#schema-reponses li.ok .corr { color: var(--vert); }
#schema-reponses li.ko .corr { color: var(--erreur); }
#schema-reponses li.ko input { text-decoration: line-through; color: var(--gris); }
#schema-reponses li.ok input { border-color: var(--vert); }
#schema-reponses li { transition: background .3s; border-radius: 6px; }
#schema-reponses li.flash { background: #fff3c4; }
.cache.juste, .cache.faux { color: white; font-weight: 800; cursor: pointer; }
.cache.juste { background: var(--vert); border-color: var(--vert); }
.cache.faux { background: var(--erreur); border-color: var(--erreur); }
.edition .zone {
  position: absolute; border: 2px solid #1565c0; background: rgba(21,101,192,0.12);
  font-size: 0.65rem; color: #0d47a1; overflow: hidden; cursor: pointer;
}
.edition .zone.vide { border-style: dashed; border-color: #999; }
.edition .zone.sel { border-color: var(--rouge); background: rgba(139,26,26,0.15); }
.edition .trace { position: absolute; border: 2px dashed var(--rouge); pointer-events: none; }
.ligne-edition { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.ligne-edition select, .ligne-edition button { flex: 1; min-width: 8rem; }
input[type=text] { width: 100%; font-size: 1rem; padding: 0.4rem; border: 1px solid #ccc; border-radius: 6px; }
label.case { display: flex; gap: 0.5rem; align-items: center; }

/* ---------- Choix de la partie : cartes dépliables ---------- */
.arbre { display: flex; flex-direction: column; gap: 0.45rem; }
.carte {
  display: flex; align-items: center; gap: 0.7rem; padding: 0.7rem 0.8rem;
  background: white; border: 1px solid #e3e0da; border-radius: 12px; cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05); transition: border-color .15s, background .15s;
}
.carte:hover { border-color: #cbb; }
.carte.choisie { border: 2px solid var(--rouge); background: #fbf3f3; }
.carte.niv-1 { background: linear-gradient(135deg, #8b1a1a, #b23b2e); color: white; border: none; }
.carte.niv-1 .sous { color: rgba(255,255,255,0.85); }
.carte.niv-1.choisie { outline: 3px solid #f2c94c; }
.carte.niv1 { margin-left: 1.2rem; }
.carte.niv2 { margin-left: 2.4rem; }
.carte.niv3 { margin-left: 3.6rem; }
.carte.niv1, .carte.niv2, .carte.niv3 { padding: 0.5rem 0.7rem; border-radius: 10px; }
.badge {
  flex: none; width: 2.4rem; height: 2.4rem; border-radius: 50%; background: var(--rouge); color: white;
  font-weight: 800; font-size: 1.1rem; display: flex; align-items: center; justify-content: center;
}
.corps { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.titre { font-weight: 600; line-height: 1.25; }
.niv1 .titre, .niv2 .titre, .niv3 .titre { font-weight: 500; font-size: 0.95rem; }
.sous { font-size: 0.8rem; color: var(--gris); }
.carte .barre { margin-top: 0.3rem; }
.fleche {
  flex: none; width: 2.4rem; height: 2.4rem; margin: 0; padding: 0; border-radius: 50%;
  border: none; background: #f1ede8; font-size: 1.5rem; line-height: 1; color: var(--rouge);
  transition: transform .2s;
}
.fleche.ouverte { transform: rotate(90deg); }
fieldset { border: none; padding: 0; margin: 1.2rem 0 0.5rem; }
fieldset legend { font-weight: 600; margin-bottom: 0.4rem; }
.puces { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.puces label { margin: 0; }
.puces input { display: none; }
.puces label { padding: 0.4rem 0.8rem; border-radius: 999px; border: 1px solid #ccc; background: white; cursor: pointer; font-size: 0.9rem; }
.puces label:has(input:checked) { background: var(--rouge); color: white; border-color: var(--rouge); }
.barre-depart {
  position: sticky; bottom: 0; background: var(--carte); padding: 0.7rem 0 0.2rem;
  display: flex; gap: 0.8rem; align-items: center; border-top: 1px solid #eee; margin-top: 1rem;
}
.barre-depart p { flex: 1; margin: 0; }
.barre-depart button.principal { width: auto; flex: none; padding: 0.8rem 1.6rem; border-radius: 999px; }

/* ---------- Progression ---------- */
#prog-resume { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.4rem; margin-bottom: 1rem; }
.tuile { background: #f6f3ef; border-radius: 12px; padding: 0.6rem 0.2rem; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.2rem; font-size: 0.8rem; color: var(--gris); }
.tuile b { font-size: 1.4rem; color: var(--texte); }
.tuile.c-su b { color: var(--vert); } .tuile.c-partiel b { color: var(--orange); } .tuile.c-rate b { color: var(--erreur); }
.c-su { color: var(--vert); } .c-partiel { color: var(--orange); } .c-rate { color: var(--erreur); }
.sous b { font-weight: 600; }
.anneau {
  flex: none; width: 2.6rem; height: 2.6rem; border-radius: 50%; display: grid; place-items: center;
  font-size: 0.72rem; font-weight: 700; color: var(--texte);
  background: radial-gradient(closest-side, white 74%, transparent 75%),
              conic-gradient(var(--vert) calc(var(--p) * 1%), #e6e1db 0);
}
.anneau.grand { width: 3.2rem; height: 3.2rem; font-size: 0.85rem; }
#prog-faibles { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: 0.4rem; }
#prog-faibles li { display: flex; align-items: center; gap: 0.6rem; background: #fff5f3;
  border: 1px solid #f0d4cf; border-radius: 10px; padding: 0.5rem 0.7rem; }
#prog-faibles li .titre { flex: 1; font-size: 0.92rem; }
#prog-faibles li .sous { font-size: 0.78rem; color: var(--erreur); white-space: nowrap; }
#prog-faibles li button { margin: 0; padding: 0.35rem 0.8rem; border-radius: 999px; background: var(--rouge);
  color: white; border: none; font-size: 0.85rem; }
@media (max-width: 420px) { #prog-resume { grid-template-columns: repeat(3, 1fr); } }

/* Quiz schéma : schéma et réponses côte à côte sur grand écran, empilés sur téléphone */
#zone-schema { display: grid; gap: 1rem; }
@media (min-width: 760px) {
  main { max-width: 1100px; }
  #zone-schema { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
  #zone-schema .reponses { position: sticky; top: 6rem; }
}
#schema-corriger { position: sticky; bottom: 0.5rem; }
.cache.revele.deux-lignes { white-space: normal; word-break: normal; overflow-wrap: normal; line-height: 1.05; padding: 1px 3px; }
.aide { background: #fff8e1; border: 1px solid #f3d27a; border-radius: 10px; padding: 0.7rem 0.9rem; margin-bottom: 1rem; }
.aide ol { margin: 0.4rem 0 0; padding-left: 1.2rem; }
