/* Styles de l'app — couleurs, polices et animations reprises de la maquette v14.
   Les couleurs sont des « variables CSS » (--bg, --accent…) : on les change
   d'un coup pour passer du thème clair au thème sombre. */

:root {
  --bg: #F5F6FA; --surface: #FFFFFF; --surface2: #ECEEF5; --line: #DADDE7;
  --text: #151824; --muted: #555B6E;
  --accent: #3949C9; --accent-ink: #FFFFFF; --accent-soft: #E3E6FA;
  --flame: #E8590C; --flame-text: #B8440A; --flame-soft: #FFE8D9;
  --ok: #1B7F4B; --ok-soft: #DDF3E6; --ko: #C62F2F; --ko-soft: #FBE1E1;
  --or: #F2B705; --or-fonce: #A87A00; --or-soft: #FFF4CC; --argent: #AEB6C2; --argent-soft: #EEF1F5;
  --bronze: #CD7F45; --bronze-soft: #F8E6D8; --medal-ink: #151824;
  /* Matières (couleurs des marches du podium) et niveaux des succès ; « -ink » = version foncée, lisible sur le fond « -soft » */
  --maths: #7C3AED; --maths-soft: #F1E8FE; --physique: #2563EB; --physique-soft: #E3EDFE; --si: #0D9488; --si-soft: #D5F5EF;
  --bronze-ink: #9A5A2A; --argent-ink: #5E6878; --or-ink: #8A6400; --legendaire: #7C3AED; --legendaire-soft: #F1E8FE;
  --ombre-carte: 0 10px 30px rgba(20, 24, 40, .10);
  color-scheme: light;
}
/* Thème sombre : automatique (réglage du téléphone) sauf si l'élève a forcé « clair » */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="clair"]) {
    --bg: #0F1118; --surface: #191C26; --surface2: #232735; --line: #30354A;
    --text: #EEF0F7; --muted: #A6ACBF;
    --accent: #8E9BFF; --accent-ink: #0F1118; --accent-soft: #262B4A;
    --flame: #FF8F4A; --flame-text: #FF9F63; --flame-soft: #3A2418;
    --ok: #5BD08F; --ok-soft: #163525; --ko: #FF7B7B; --ko-soft: #3D1C1F;
    --or: #F2C230; --or-fonce: #A87A00; --or-soft: #3A3010; --argent: #B9C1CD; --argent-soft: #2A2F3A;
    --bronze: #D98E57; --bronze-soft: #3A2618; --medal-ink: #EEF0F7;
    --maths: #C084FC; --maths-soft: #3E2B5C; --physique: #60A5FA; --physique-soft: #22375C; --si: #2DD4BF; --si-soft: #184547;
    --bronze-ink: #D98E57; --argent-ink: #B9C1CD; --or-ink: #F2C230; --legendaire: #C084FC; --legendaire-soft: #362750;
    --ombre-carte: 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="sombre"] {
  --bg: #0F1118; --surface: #191C26; --surface2: #232735; --line: #30354A;
  --text: #EEF0F7; --muted: #A6ACBF;
  --accent: #8E9BFF; --accent-ink: #0F1118; --accent-soft: #262B4A;
  --flame: #FF8F4A; --flame-text: #FF9F63; --flame-soft: #3A2418;
  --ok: #5BD08F; --ok-soft: #163525; --ko: #FF7B7B; --ko-soft: #3D1C1F;
  --or: #F2C230; --or-fonce: #A87A00; --or-soft: #3A3010; --argent: #B9C1CD; --argent-soft: #2A2F3A;
  --bronze: #D98E57; --bronze-soft: #3A2618; --medal-ink: #EEF0F7;
  --maths: #C084FC; --maths-soft: #3E2B5C; --physique: #60A5FA; --physique-soft: #22375C; --si: #2DD4BF; --si-soft: #184547;
  --bronze-ink: #D98E57; --argent-ink: #B9C1CD; --or-ink: #F2C230; --legendaire: #C084FC; --legendaire-soft: #362750;
  --ombre-carte: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button { font: inherit; }
.h { font-family: 'Space Grotesk', Inter, sans-serif; }
.muted { color: var(--muted); }
.cache { display: none !important; }

/* L'écran occupe toute la hauteur du téléphone ; sur ordinateur, colonne centrée */
#app {
  max-width: 480px; margin: 0 auto; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; overflow: hidden; background: var(--bg);
}
.defile { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
/* Dans une zone qui défile, les blocs gardent leur hauteur (sinon, quand la
   page est longue, ceux en « overflow:hidden » sont écrasés à 0). */
.defile > * { flex-shrink: 0; }

/* ---------- éléments communs ---------- */
.carte-bloc { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.etiquette { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.barre { height: 8px; border-radius: 4px; background: var(--surface2); overflow: hidden; display: flex; }
.barre > span { display: block; height: 100%; background: var(--accent); }
.barre > span.leger { opacity: .35; }
.bouton {
  border: 0; text-decoration: none; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border-radius: 16px; min-height: 56px;
  display: flex; align-items: center; justify-content: center; width: 100%;
  font-size: 17px; font-weight: 700; box-shadow: 0 4px 0 rgba(0, 0, 0, .18);
}
.bouton:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .18); }
.bouton[disabled] { opacity: .45; cursor: default; }
.bouton-texte {
  border: 0; background: none; color: var(--muted); text-decoration: none; cursor: pointer;
  min-height: 44px; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 600;
}
.retour {
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  color: var(--text); border-radius: 12px; border: 0; background: none; cursor: pointer;
}
.entete-retour { display: flex; align-items: center; gap: 8px; padding: 18px 12px 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Barre de navigation du bas */
.nav {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line); background: var(--surface);
  padding: 8px 8px calc(14px + env(safe-area-inset-bottom));
}
.nav a {
  text-decoration: none; color: var(--muted); display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 6px; min-height: 44px; font-size: 12px; font-weight: 500;
}
.nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* ---------- flamme ---------- */
/* Le dessin est dans ecrans/outils.js, l'animation (vaciller, regarder, cligner, dormir) dans ecrans/flamme_vivante.js */
@keyframes glow { 0%,100% { filter: drop-shadow(0 0 3px var(--flame)) } 50% { filter: drop-shadow(0 0 8px var(--flame)) } }
.flamme { flex: none; }
.flame-on { animation: glow 2.2s ease-in-out infinite; }
.flame-off { opacity: .8; }
/* Petites flammes du classement : immobiles, juste une lueur fixe */
.flamme-mini.flame-on { animation: none; filter: drop-shadow(0 0 2px rgba(255, 122, 61, .6)); }

/* ---------- accueil ---------- */
.accueil-entete { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 24px 20px 12px; }
.accueil-entete h1 { margin: 0; font-size: 23px; line-height: 1.2; font-weight: 700; }
.pastille-serie { display: flex; align-items: center; gap: 6px; padding: 8px 14px 8px 10px; border-radius: 999px; flex-shrink: 0; background: var(--surface2); }
.pastille-serie .h { font-size: 19px; font-weight: 700; color: var(--muted); }
.pastille-serie.allumee { background: var(--flame-soft); }
.pastille-serie.allumee .h { color: var(--flame-text); }
.accueil-corps { padding: 8px 20px 20px; display: flex; flex-direction: column; gap: 22px; }
.objectif { padding: 18px; display: flex; flex-direction: column; gap: 16px; border-radius: 20px; }
.semaine { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.semaine > div { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); font-weight: 600; }
.rond-jour { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.rond-jour.fait { background: var(--flame); }
.rond-jour.auj { border: 2px dashed var(--flame); }
.rond-jour.vide { background: var(--surface2); }
.chapitre-lien {
  text-decoration: none; color: var(--text); padding: 14px 16px; display: flex; align-items: center; gap: 14px; min-height: 44px;
}
/* Accueil : onglets (une page par matière + Favoris) et étoile des favoris */
.onglets { display: flex; background: var(--surface2); border-radius: 12px; padding: 3px; gap: 2px; }
.onglets button { flex: 1; min-width: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px; font-weight: 600; padding: 8px 10px; border-radius: 9px; cursor: pointer; min-height: 38px; }
.onglets button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.chapitre-ligne { display: flex; align-items: stretch; overflow: hidden; }
.chapitre-ligne .chapitre-lien { flex: 1; min-width: 0; padding-left: 4px; }
.etoile { flex-shrink: 0; width: 48px; border: 0; background: none; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0 0 0 6px; }
.etoile[aria-pressed="true"] { color: var(--flame); }
.etoile:active svg { transform: scale(.85); }
.texte-vide { margin: 0; font-size: 14px; line-height: 1.5; }

/* Accueil : cases de choix de la matière */
.matiere-case { display: flex; align-items: center; gap: 14px; padding: 16px; min-height: 44px; text-decoration: none; color: var(--text); }
.matiere-dessin { width: 46px; height: 46px; flex-shrink: 0; border-radius: 14px; display: flex; align-items: center; justify-content: center; background: var(--surface2); color: var(--accent); }
.matiere-case.verrouillee { color: var(--muted); }
/* Chaque matière a la couleur d'une marche du podium : Maths = 1re (violet), Physique = 2e (bleu), SI = 3e (turquoise).
   Fond doux derrière le logo, liseré à gauche, barre de maîtrise en dégradé comme les marches. */
.matiere-maths { --mat: var(--maths); --mat-soft: var(--maths-soft); --mat-degrade: linear-gradient(90deg, #A855F7, #6D28D9); }
.matiere-physique { --mat: var(--physique); --mat-soft: var(--physique-soft); --mat-degrade: linear-gradient(90deg, #3B82F6, #2563EB); }
.matiere-si { --mat: var(--si); --mat-soft: var(--si-soft); --mat-degrade: linear-gradient(90deg, #14B8A6, #0EA5E9); }
.matiere-case .matiere-dessin { background: var(--mat-soft, var(--surface2)); color: var(--mat, var(--accent)); }
.matiere-case:not(.verrouillee) { border-left: 4px solid var(--mat, var(--line)); }
.matiere-case .barre > span { background: var(--mat-degrade, var(--mat, var(--accent))); }
/* Objectif du jour : fond normal, contour violet léger, anneau en dégradé violet → bleu (1re et 2e marches du podium) */
.objectif { border-color: color-mix(in srgb, var(--maths) 40%, var(--line)); }
.objectif .etiquette { color: var(--maths); }

/* ---------- lancement ---------- */
.stats3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stats3 > div { padding: 12px; display: flex; flex-direction: column; gap: 2px; border-radius: 14px; }
.pied { padding: 16px 20px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.pied.avec-fond { border-top: 1px solid var(--line); background: var(--surface); }
.legende { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legende span { display: flex; align-items: center; gap: 6px; }
.legende i { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); display: inline-block; }

/* ---------- session recto/verso ---------- */
.session-entete { display: flex; align-items: center; gap: 10px; padding: 18px 16px 10px 8px; }
.progression { flex: 1; height: 12px; border-radius: 6px; background: var(--surface2); overflow: hidden; }
.progression > span { display: block; height: 100%; border-radius: 6px; background: var(--accent); transition: width .35s ease; }
.badge-type { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); padding: 5px 10px; border-radius: 999px; }
.badge-type.piege { color: var(--ko); background: var(--ko-soft); }
.badge-type.methode { color: var(--ok); background: var(--ok-soft); }
.zone-carte { position: relative; flex: 1; min-height: 300px; margin: 6px 0 22px; }
/* Cartes de derrière : opaques (couleur pré-mélangée avec le fond), sinon on voit le trait de celle d'en dessous au travers. */
.pile { position: absolute; left: 14px; right: 14px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); }
.pile-1 { background: color-mix(in srgb, var(--surface) 80%, var(--bg)); border-color: color-mix(in srgb, var(--line) 80%, var(--bg)); }
.pile-2 { background: color-mix(in srgb, var(--surface) 50%, var(--bg)); border-color: color-mix(in srgb, var(--line) 50%, var(--bg)); }
.scene { position: absolute; inset: 0; perspective: 1100px; touch-action: pan-y; cursor: pointer; user-select: none; -webkit-user-select: none; }
.scene.retournee { cursor: grab; } /* pan-y : on peut encore faire défiler une longue réponse */
.flipper { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .55s cubic-bezier(.3, 1.4, .5, 1); }
.scene.retournee .flipper { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 22px; padding: 22px; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); box-shadow: var(--ombre-carte); border: 1px solid var(--line); overflow: hidden;
}
.face.verso { transform: rotateY(180deg); border: 2px solid var(--accent); }
.face .texte { overflow-y: auto; min-height: 6.5em; flex-shrink: 1; } /* la question garde de la place, même avec un schéma */
.face:not(.sans-figure) .schema-dessin svg { max-height: 20vh; }
/* Sans schéma : le texte se place au milieu de la carte (marges auto en haut et en bas).
   Si le texte est trop long, les marges tombent à 0 : il reste en haut et défile. */
.face.sans-figure .ressort { display: none; }
.face.sans-figure .texte { margin-block: auto; padding-block: 4px; }
.recto-texte { margin: 0; font-size: 21px; line-height: 1.4; font-weight: 600; }
.verso-texte { margin: 0; font-size: 17px; line-height: 1.55; }
.consigne { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--muted); text-align: center; font-size: 14px; line-height: 1.45; }
.indices { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 600; }
.indices .ko { color: var(--ko); display: flex; align-items: center; gap: 4px; }
.indices .ok { color: var(--ok); display: flex; align-items: center; gap: 4px; }
@keyframes hint { 0%,100% { transform: translateX(0) } 30% { transform: translateX(-6px) } 70% { transform: translateX(6px) } }
.indices.anime { animation: hint 2.4s ease-in-out infinite; }
.tampon {
  position: absolute; top: 18px; padding: 6px 12px; border-radius: 10px; border: 3px solid;
  font-family: 'Space Grotesk', Inter, sans-serif; font-weight: 700; font-size: 18px; letter-spacing: .04em;
  text-transform: uppercase; pointer-events: none; opacity: 0;
}
.tampon.ok { right: 18px; color: var(--ok); border-color: var(--ok); background: var(--ok-soft); transform: rotate(8deg); }
.tampon.ko { left: 18px; color: var(--ko); border-color: var(--ko); background: var(--ko-soft); transform: rotate(-8deg); }
.deux-boutons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.choix {
  cursor: pointer; border-radius: 16px; min-height: 52px; display: flex; align-items: center; justify-content: center;
  gap: 8px; font-size: 15px; font-weight: 700; border: 2px solid;
}
.choix.ko { border-color: var(--ko); color: var(--ko); background: var(--ko-soft); }
.choix.ok { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.texte-math .katex { font-size: 1.05em; }
/* Formule courte : on ne la coupe pas au milieu (pas de « V = » en fin de ligne et « βs » dessous) */
.katex.insecable .katex-html { white-space: nowrap; }

/* ---------- schémas des cartes (champs figure / figure_verso) ----------
   Le dessin SVG est inséré dans la page : ses traits suivent la couleur du texte
   (currentColor), donc il s'adapte tout seul au thème sombre.
   Classes utilisables dans les dessins (voir CLAUDE.md) :
   accent (trait de couleur), accent-plein, plein (rempli couleur du texte),
   discret (trait gris), fond (rempli couleur de la carte), nom (lettres et textes ; « nom droit » = non italique). */
.schema {
  flex-shrink: 0; margin: 0; padding: 8px 8px 4px; border-radius: 14px;
  background: var(--surface2); display: flex; flex-direction: column; align-items: stretch; gap: 2px;
}
.schema-dessin { width: 100%; display: flex; justify-content: center; color: var(--text); }
.schema-dessin svg { display: block; width: 100%; height: auto; max-height: 28vh; }
.schema-attente { font-size: 13px; padding: 24px 8px; text-align: center; }
/* Loupe : dans une fine bande sous le dessin, à droite (elle ne cache plus rien du dessin) */
.loupe {
  align-self: flex-end; width: 28px; height: 28px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
}
.loupe svg { width: 15px; height: 15px; }
.correction .schema { background: var(--surface); }
.correction .schema-dessin svg { max-height: 20vh; }
.correction .explication:has(.schema) { max-height: 50vh; } /* place pour le schéma de la réponse */
/* Habillage des dessins */
.schema svg, .schema-plein svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.schema svg .accent, .schema-plein svg .accent { stroke: var(--accent); }
.schema svg .accent-plein, .schema-plein svg .accent-plein { fill: var(--accent); stroke: none; }
.schema svg .plein, .schema-plein svg .plein { fill: currentColor; stroke: none; }
.schema svg .discret, .schema-plein svg .discret { stroke: var(--muted); stroke-width: 1.4; }
.schema svg .pointille, .schema-plein svg .pointille { stroke-dasharray: 5 5; }
.schema svg .fond, .schema-plein svg .fond { fill: var(--surface2); }
.schema svg .nom, .schema-plein svg .nom {
  fill: currentColor; stroke: none; font-family: 'KaTeX_Math', 'Times New Roman', serif; font-style: italic; font-size: 17px;
}
.schema svg .nom.droit, .schema-plein svg .nom.droit { font-family: 'KaTeX_Main', 'Times New Roman', serif; font-style: normal; }
.schema svg .nom.accent-plein, .schema-plein svg .nom.accent-plein { fill: var(--accent); }
/* Plein écran */
.voile.schema-plein { flex-direction: column; align-items: center; justify-content: center; padding: 8px; overflow: hidden; }
.schema-plein-dessin {
  box-sizing: border-box; width: 100%; max-width: 900px; background: var(--surface); color: var(--text);
  border-radius: 16px; padding: 8px;
}
.schema-plein-dessin svg { display: block; width: 100%; height: auto; max-height: 85vh; }
/* Téléphone en portrait et dessin large : on le tourne d'un quart de tour pour qu'il prenne toute la hauteur.
   Sa largeur (avant rotation) = la hauteur de l'écran moins la place du bouton Fermer. */
.schema-plein.tourne .schema-plein-dessin {
  flex-shrink: 0; width: calc(100vh - 150px); width: calc(100svh - 150px); max-width: none; transform: rotate(90deg);
}
.schema-plein.tourne .schema-plein-dessin svg { max-height: calc(100vw - 32px); }
.schema-plein.tourne .schema-fermer { position: absolute; top: 12px; right: 12px; margin: 0; }
.schema-fermer {
  margin-top: 14px; width: 48px; height: 48px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: flex; align-items: center; justify-content: center;
}

/* ---------- session QCM (3b) et Vrai/Faux (3c) ---------- */
.zone-carte.libre { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; margin: 4px 0 8px; }
.question-bloc {
  flex-shrink: 0; border-radius: 22px; padding: 20px 22px; display: flex; flex-direction: column; gap: 8px;
  /* Pas d'ombre : la zone .libre défile (overflow) et coupe l'ombre en carré, ce qui assombrit les coins arrondis. */
  background: var(--surface); border: 1px solid var(--line);
}
/* QCM répondu : la question se réduit à 2 lignes pour laisser voir les 4 propositions */
.zone-carte.libre.repondue .question-bloc { padding: 12px 18px; gap: 4px; }
.zone-carte.libre.repondue .question-bloc .schema { display: none; }
.zone-carte.libre.repondue .question-bloc .recto-texte {
  font-size: 15px !important; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.zone-carte.libre.repondue .options { gap: 6px; }
.zone-carte.libre.repondue .option { min-height: 0; padding: 7px 12px; font-size: 14.5px; line-height: 1.35; }.options { display: flex; flex-direction: column; gap: 10px; padding-bottom: 4px; }
.option {
  cursor: pointer; text-align: left; width: 100%; min-height: 54px; padding: 12px 14px; border-radius: 16px;
  border: 2px solid var(--line); background: var(--surface); color: var(--text);
  display: flex; align-items: center; gap: 12px; font: inherit; font-size: 16px; line-height: 1.45;
  transition: border-color .15s, background .15s, opacity .2s;
}
.option .lettre {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--surface2); color: var(--muted);
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
}
@media (hover: hover) { .option:not(:disabled):hover { border-color: var(--accent); } }
.option:not(:disabled):active { transform: translateY(1px); }
.option:disabled { cursor: default; }
.option.bonne { border-color: var(--ok); background: var(--ok-soft); }
.option.bonne .lettre { background: var(--ok); color: var(--bg); }
.option.mauvaise { border-color: var(--ko); background: var(--ko-soft); }
.option.mauvaise .lettre { background: var(--ko); color: var(--bg); }
.option.estompee { opacity: .45; }
.choix.neutre { border-color: var(--line); color: var(--text); background: var(--surface); font-size: 17px; min-height: 60px; }
.choix.neutre:disabled { cursor: default; }
.choix.neutre.bonne { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.choix.neutre.mauvaise { border-color: var(--ko); color: var(--ko); background: var(--ko-soft); }
.choix.neutre.estompee { opacity: .45; }
@keyframes monte { 0% { transform: translateY(100%) } 100% { transform: translateY(0) } }
.correction {
  border-top: 3px solid; animation: monte .28s cubic-bezier(.2, .9, .3, 1.1) both;
  padding: 14px 20px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px;
}
.correction.ok { background: var(--ok-soft); border-color: var(--ok); }
.correction.ko { background: var(--ko-soft); border-color: var(--ko); }
.correction .titre { display: flex; align-items: center; gap: 8px; font-family: 'Space Grotesk', Inter, sans-serif; font-size: 19px; font-weight: 700; }
.correction.ok .titre { color: var(--ok); }
.correction.ko .titre { color: var(--ko); }
.correction .explication { font-size: 15px; line-height: 1.5; max-height: 32vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.correction .explication p { margin: 0; }
.correction .bouton { color: var(--bg); }
.correction.ok .bouton { background: var(--ok); }
.correction.ko .bouton { background: var(--ko); }
/* Petits téléphones : l'explication défile dans moins de place, pour laisser voir les 4 propositions */
@media (max-height: 720px) { .correction .explication { max-height: 16vh; } .correction { padding-top: 10px; gap: 8px; } }

/* ---------- fin de session ---------- */
@keyframes grow { 0% { transform: scale(.35); opacity: 0 } 45% { transform: scale(1.35); opacity: 1 } 70% { transform: scale(.92) } 100% { transform: scale(1) } }
@keyframes halo { 0% { transform: scale(.4); opacity: 0 } 40% { opacity: .55 } 100% { transform: scale(1.9); opacity: 0 } }
@keyframes burst { 0% { transform: translate(0, 0) scale(1); opacity: 1 } 100% { transform: translate(var(--tx), var(--ty)) scale(.4) rotate(var(--r)); opacity: 0 } }
@keyframes outUp { 0% { transform: translateY(0); opacity: 1 } 100% { transform: translateY(-100%); opacity: 0 } }
@keyframes inUp { 0% { transform: translateY(100%); opacity: 0 } 100% { transform: translateY(0); opacity: 1 } }
@keyframes slideIn { 0% { transform: translateY(28px); opacity: 0 } 100% { transform: translateY(0); opacity: 1 } }
.grow { animation: grow .9s cubic-bezier(.2, .9, .3, 1.2) both; transform-origin: 50% 90%; }
.halo { position: absolute; left: 50%; top: 50%; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%; background: radial-gradient(circle, var(--flame) 0%, transparent 70%); animation: halo 1.1s ease-out .35s both; }
.particule { position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; margin: -4px; border-radius: 2px; opacity: 0; animation: burst 1s cubic-bezier(.1, .7, .3, 1) .4s both; }
.compteur { position: relative; height: 62px; width: 140px; overflow: hidden; text-align: center; font-size: 58px; font-weight: 700; line-height: 62px; color: var(--flame-text); }
.compteur span { position: absolute; inset: 0; }
.compteur .ancien { animation: outUp .45s ease-in .9s both; }
.compteur .nouveau { animation: inUp .5s cubic-bezier(.2, .9, .3, 1.3) 1s both; }
.s0 { animation: slideIn .45s ease-out 1.3s both; }
.s1 { animation: slideIn .45s ease-out 1.5s both; }
.s2 { animation: slideIn .45s ease-out 1.65s both; }
.s3 { animation: slideIn .45s ease-out 1.8s both; }
.s4 { animation: slideIn .45s ease-out 1.95s both; }
.puce { width: 8px; height: 8px; border-radius: 50%; background: var(--ko); flex-shrink: 0; margin-top: 7px; }
.deux-lignes { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- profil ---------- */
.stats-profil { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 8px; }
.stats-profil > * { border-radius: 16px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.calendrier { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; text-align: center; }
.calendrier .l { font-size: 11px; font-weight: 600; color: var(--muted); padding-bottom: 2px; }
.case { height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 500; color: var(--muted); }
.case.serie { background: var(--flame); color: #FFFFFF; font-weight: 700; }
.case.revise { background: var(--flame-soft); color: var(--flame-text); font-weight: 700; }
.case.saute, .case.a_faire { background: var(--surface2); }
.case.auj { border: 2px solid var(--text); }
.mois-btn { width: 36px; height: 36px; border: 0; background: none; color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; border-radius: 10px; }
.mois-btn[disabled] { color: var(--line); cursor: default; }
.succes-grille { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.badge { border-radius: 16px; padding: 12px 8px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; background: var(--surface2); border: 1px solid transparent; opacity: .75; }
.badge .rond { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--line); color: var(--muted); }
.badge.obtenu { background: var(--surface); border-color: var(--line); opacity: 1; }
.badge.obtenu .rond { background: var(--niv-soft, var(--flame-soft)); color: var(--niv, var(--flame-text)); box-shadow: inset 0 0 0 2px var(--niv, transparent); }
/* Pas encore obtenu : reste gris, avec une barre à gauche de la couleur de son niveau (comme les lignes du classement) */
.badge:not(.obtenu) { border-left: 4px solid var(--niv, var(--line)); }
.badge.obtenu { border-color:color-mix(in srgb, var(--niv, var(--line)) 55%, var(--line)); }
/* Niveaux des succès : bronze (facile) → argent → or → légendaire (violet de la 1re marche du podium) */
.niveau-bronze { --niv: var(--bronze-ink); --niv-soft: var(--bronze-soft); }
.niveau-argent { --niv: var(--argent-ink); --niv-soft: var(--argent-soft); }
.niveau-or { --niv: var(--or-ink); --niv-soft: var(--or-soft); }
.niveau-legendaire { --niv: var(--legendaire); --niv-soft: var(--legendaire-soft); }
.reglage { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 52px; cursor: pointer; }
.reglage + .reglage { border-top: 1px solid var(--line); }
.reglage.inactif { cursor: default; opacity: .55; }
.choix-reglage { font: inherit; font-size: 14px; font-weight: 600; color: var(--text); background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; min-height: 36px; cursor: pointer; }
.sw { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.sw input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.sw .track { position: absolute; inset: 0; border-radius: 13px; background: var(--line); transition: background .2s; }
.sw .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #FFFFFF; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s; }
.sw input:checked ~ .track { background: var(--accent); }
.sw input:checked ~ .knob { transform: translateX(18px); }
.sw input:focus-visible ~ .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.sw input:disabled { cursor: default; }
.segment { display: flex; background: var(--surface2); border-radius: 10px; padding: 3px; gap: 2px; }
.segment button { border: 0; background: none; color: var(--muted); font-size: 13px; font-weight: 600; padding: 6px 10px; border-radius: 8px; cursor: pointer; min-height: 32px; }
.segment button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.bientot { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface2); padding: 3px 8px; border-radius: 999px; }
@keyframes open { from { opacity: 0; transform: translateY(-6px) } to { opacity: 1; transform: none } }
.accordeon-corps { animation: open .25s ease-out; border-top: 1px solid var(--line); padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 12px; background: var(--bg); }

/* Classement : podium (2e, 1er, 3e), groupes par catégorie, lignes d'élèves */
.etat-classement { align-self: flex-start; font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface2); padding: 3px 9px; border-radius: 999px; margin-top: 2px; }
.podium { position: relative; display: flex; align-items: flex-end; gap: 8px; padding: 18px 0 8px; }
.marche { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.medaille-zone { position: relative; display: flex; align-items: center; justify-content: center; }
.medaille {
  position: relative; z-index: 1; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: 'Space Grotesk', Inter, sans-serif; font-size: 19px; font-weight: 700;
  color: var(--lettre-avatar, var(--text)); background: var(--fond-avatar, var(--surface2)); box-shadow: 0 0 0 3px var(--bg);
}
.place1 .medaille { width: 58px; height: 58px; font-size: 23px; }
/* Le 1er : de petites flammes à visage volent autour de son avatar (animées par ecrans/flammes_premier.js) */
.place1 .medaille-zone { margin: 10px 0 14px; }
.orbite { position: absolute; inset: 0; pointer-events: none; }
.flamme-volante { position: absolute; left: 50%; top: 50%; width: 28px; height: 34px; transform-origin: 50% 70%; display: flex; filter: drop-shadow(0 0 4px rgba(255, 122, 61, .65)); }
.braise { position: absolute; left: 50%; top: 50%; border-radius: 50%; }
/* « Toi » : contour bleu autour de l'avatar */
.marche.moi .medaille { outline: 3px solid var(--accent); outline-offset: 3px; }
.place1.moi .medaille { outline-offset: 9px; }
.nom-podium { max-width: 100%; font-size: 13px; font-weight: 600; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.marche.moi .nom-podium { color: var(--accent); font-weight: 700; }
.socle {
  width: 100%; height: 92px; padding: 6px 4px; border-radius: 14px 14px 6px 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: #FFFFFF; background: linear-gradient(160deg, #14B8A6, #0EA5E9); transform-origin: 50% 100%;
  box-shadow: 0 6px 16px -8px rgba(14, 165, 233, .7);
}
/* Tons froids (bleu, violet, turquoise) : la flamme orange de la série ressort sur toutes les marches */
.place2 .socle { height: 110px; background: linear-gradient(160deg, #3B82F6, #2563EB); box-shadow: 0 6px 16px -8px rgba(37, 99, 235, .7); }
.place1 .socle { height: 130px; background: linear-gradient(160deg, #A855F7, #6D28D9); box-shadow: 0 8px 20px -8px rgba(124, 58, 237, .75); }
/* Entrée en scène : les marches montent l'une après l'autre, puis les avatars rebondissent */
.entree .socle { animation: monter .6s cubic-bezier(.3, 1.4, .5, 1) both; animation-delay: calc(var(--ordre) * .22s); }
.entree .medaille-zone, .entree .nom-podium, .entree .marche .variation, .entree .marche .signaler-pseudo { animation: rebondir .5s cubic-bezier(.3, 1.7, .5, 1) both; animation-delay: calc(var(--ordre) * .22s + .3s); }
@keyframes monter { from { transform: scaleY(0); } }
@keyframes rebondir { from { transform: scale(0); opacity: 0; } }
/* Toi sur le podium : ta flamme de série s'embrase une fois (après la montée de ta marche) */
.embrase-zone { position: relative; display: inline-flex; }
.embrase { display: inline-flex; transform-origin: 50% 80%; animation: embraser .9s cubic-bezier(.3, 1.4, .5, 1) both; animation-delay: calc(var(--ordre) * .22s + .9s); }
@keyframes embraser {
  0% { transform: scale(1); }
  35% { transform: scale(1.9); filter: drop-shadow(0 0 6px #FFC53D); }
  100% { transform: scale(1); }
}
.etincelle { position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%; box-shadow: 0 0 4px #FFD25A; opacity: 0; pointer-events: none; animation: etinceler .8s ease-out both; animation-delay: calc(var(--ordre) * .22s + 1.15s); }
@keyframes etinceler {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--x), var(--y)) scale(.4); }
}
/* Flèches : monté (vert) / descendu (rouge) depuis hier */
.variation { display: inline-flex; align-items: center; gap: 3px; padding: 3px 6px; border-radius: 999px; font-size: 12px; font-weight: 700; line-height: 1; }
.variation svg { width: 10px; height: 10px; }
.variation.monte { color: #4ADE80; background: rgba(34, 197, 94, .18); }
.variation.descend { color: #F87171; background: rgba(239, 68, 68, .18); }
.variation.stable { color: var(--muted); padding: 3px 5px; }
.titre-groupe { display: flex; align-items: center; gap: 8px; padding: 14px 2px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.titre-groupe .trait { flex: 1; height: 2px; border-radius: 1px; background: var(--line); }
.pastille-groupe { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--couleur-groupe, var(--muted)); }
.rang-bloc { width: 34px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.barre-serie { display: block; height: 4px; border-radius: 2px; background: var(--surface2); overflow: hidden; margin-top: 2px; }
.barre-serie > span { display: block; height: 100%; border-radius: 2px; background: linear-gradient(90deg, var(--flame), #FF4F8B); }
.entree .ligne-eleve { animation: glisser .45s ease-out both; animation-delay: calc(var(--i) * 70ms + .75s); }
.entree .barre-serie > span { animation: pousser .9s ease-out both; animation-delay: calc(var(--i) * 70ms + 1s); }
@keyframes glisser { from { opacity: 0; transform: translateX(40px); } }
@keyframes pousser { from { width: 0; } }
.ligne-eleve { display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 56px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--couleur-groupe, var(--line)); border-radius: 14px; }
.ligne-eleve.moi { background: var(--accent-soft); border-color: var(--accent); }
.ligne-eleve .rang { width: 22px; text-align: center; font-size: 15px; font-weight: 700; color: var(--muted); }
.ligne-eleve .avatar { width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--fond-avatar, var(--surface2)); color: var(--lettre-avatar, var(--text)); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
.ligne-eleve.moi .avatar { outline: 2px solid var(--accent); outline-offset: 2px; }
.ligne-eleve .nom { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne-eleve.moi .nom { font-weight: 700; }
.serie-eleve { display: flex; align-items: center; gap: 3px; font-family: 'Space Grotesk', Inter, sans-serif; font-size: 16px; font-weight: 700; color: var(--flame-text); }

.objectif-classement { display: flex; gap: 12px; align-items: flex-start; padding: 14px; margin-top: 4px; background: var(--surface); border: 1px solid var(--accent); border-radius: 16px; }
.objectif-icone { width: 40px; height: 40px; flex: none; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent); }
.bonnes-podium { display: flex; flex-direction: column; align-items: center; font-size: 12px; font-weight: 700; line-height: 1.15; }
.bonnes-semaine { font-size: 10px; font-weight: 500; opacity: .85; }
.titre-groupe .trait { background: var(--couleur-groupe, var(--line)); opacity: .6; }
.ligne-eleve.eteinte { background: transparent; }
.ligne-eleve.eteinte .nom, .ligne-eleve.eteinte .serie-eleve { color: var(--muted); }
.ligne-eleve.eteinte .serie-eleve svg { opacity: .6; }

/* Formulaires (rejoindre le classement) */
.formulaire { display: flex; flex-direction: column; gap: 16px; }
.champ { display: flex; flex-direction: column; gap: 6px; }
.champ > span { font-size: 14px; font-weight: 600; }
.champ input, .champ select {
  font: inherit; font-size: 16px; /* 16 px : évite le zoom automatique sur iPhone */
  color: var(--text); background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 12px 14px; min-height: 48px; width: 100%;
}
.champ select { appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat; }
.champ input:focus, .champ select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.saut-classement { text-align: center; color: var(--muted); font-size: 20px; letter-spacing: .3em; line-height: 1; padding: 2px 0 6px; }
.ma-place { margin: 6px 0 2px; font-size: 14px; text-align: center; }
.champ small { font-size: 12px; }
input.code { font-family: 'Space Grotesk', ui-monospace, monospace; letter-spacing: .08em; text-transform: uppercase; }
.erreur { margin: 0; min-height: 1.2em; font-size: 14px; color: var(--ko); }
.erreur:empty { display: none; }
.code-recup { font-size: 22px; font-weight: 700; letter-spacing: .08em; text-align: center; word-break: break-all; user-select: all; }
.code-recup.petit { font-size: 15px; text-align: left; }

/* Moins d'animations si l'élève l'a demandé dans les réglages du téléphone */
@media (prefers-reduced-motion: reduce) {
  .flame-on, .flipper, .indices.anime, .grow,
  .halo, .particule, .compteur span, .s0, .s1, .s2, .s3, .s4, .accordeon-corps, .progression > span, .correction, .option,
  .socle, .medaille-zone, .nom-podium, .variation, .embrase, .ligne-eleve, .barre-serie > span { animation: none; transition: none; }
  .orbite, .etincelle { display: none; }
  .particule, .halo, .compteur .ancien { display: none; }
}

/* Fenêtre de confirmation (quitter une session, se déconnecter) */
.voile {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-end; justify-content: center; padding: 16px;
}
.dialogue {
  width: 100%; max-width: 448px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 22px 20px calc(12px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px;
}
/* Bandeau « Installe l'app » en haut de l'accueil */
.bandeau-installation { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; border-color: var(--accent); background: var(--accent-soft); }
.bandeau-installation p { margin: 0; font-size: 14px; line-height: 1.45; }
.bandeau-boutons { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.bandeau-boutons .bouton { width: auto; min-height: 44px; padding: 0 18px; font-size: 15px; }

.dialogue h2 { margin: 0; font-size: 19px; color: var(--text); }
.dialogue p { margin: 0 0 8px; font-size: 15px; }

/* Fenêtre de signalement (erreur sur une carte, pseudo) */
.zone-signalement {
  font: inherit; font-size: 16px; /* 16 px : évite le zoom automatique sur iPhone */
  color: var(--text); background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 12px 14px; width: 100%; min-height: 96px; resize: vertical; box-sizing: border-box;
}
.zone-signalement:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
/* Petit lien discret « Signaler une erreur » (verso des cartes, correction) */
.lien-signaler {
  align-self: center; background: none; border: 0; padding: 10px 14px; min-height: 44px;
  font: inherit; font-size: 13px; color: var(--muted); text-decoration: underline; cursor: pointer;
}
.lien-signaler:hover, .lien-signaler:focus-visible { color: var(--text); }

/* Bouton « ⋯ » du classement (signaler ; plus tard aussi « Voir le profil »).
   La zone cliquable fait 44 px de haut, mais on ne voit qu'une petite pastille. */
.signaler-pseudo {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; margin: -6px -8px -6px -4px; padding: 0; background: none; border: 0;
  color: var(--muted); cursor: pointer; font-size: 14px; font-weight: 700;
}
.signaler-pseudo svg { display: block; border-radius: 999px; background: var(--surface2); transition: background .15s, color .15s; }
.signaler-pseudo:hover svg, .signaler-pseudo:focus-visible svg { background: var(--line); color: var(--text); }
.signaler-pseudo:focus-visible { outline: none; }
.signaler-pseudo:focus-visible svg { outline: 2px solid var(--accent); outline-offset: 1px; }
.signaler-pseudo.fait { color: var(--ok); cursor: default; }
/* Podium : la pastille se range juste à droite du nom, sans zone morte autour */
.nom-ligne { max-width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 2px; min-width: 0; }
.nom-ligne .signaler-pseudo { width: 32px; height: 32px; margin: -6px -4px -6px 0; }
.nom-ligne .signaler-pseudo svg { width: 24px; height: 16px; }
