/* Style inspiré d'une esthétique « app SaaS » : fond gris clair, bleu marine profond,
   cartes blanches très arrondies, pastilles grises, boutons flèche ronds. */

/* Poppins (licence SIL OFL 1.1, voir polices/OFL-Poppins.txt), sous-ensemble latin,
   hébergée avec l'application pour fonctionner hors ligne. */
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("polices/poppins-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("polices/poppins-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("polices/poppins-latin-600-normal.woff2") format("woff2");
}

:root {
  --fond: #f0f0f2;
  --surface: #ffffff;
  --surface-douce: #f5f5f7;
  --texte: #0b1020;
  --texte-doux: #6f7280;
  --bordure: #e4e4ea;
  --marine: #020e46;
  --marine-clair: #1b2a78;
  --sur-marine: #ffffff;
  --accent: #3b5bfd; /* couleur de remplissage au survol des boutons marine */
  --puce: #ececf0;
  --oubli: #c0362c;
  --difficile: #a5670a;
  --facile: #1f7a45;
  --rayon: 20px;
  --rayon-petit: 12px;
  --ombre: 0 1px 2px rgba(2, 14, 70, 0.04), 0 8px 24px rgba(2, 14, 70, 0.06);
  --halo: inset 0 0 12px rgba(255, 255, 255, 0.35);
  --marge: clamp(16px, 4.5vw, 28px);
  --police: "Poppins", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}

/* Thème sombre : uniquement sur choix de l'utilisateur (bouton de l'accueil).
   Gris anthracite plutôt que bleu nuit, avec le bleu réservé aux éléments d'action. */
:root[data-theme="sombre"] {
  --fond: #111318;
  --surface: #1b1e25;
  --surface-douce: #22262e;
  --texte: #eceef3;
  --texte-doux: #a2a7b3;
  --bordure: #2c313b;
  --marine: #4a63e6;
  --marine-clair: #7b8ff0;
  --accent: #2b3fb8;
  --puce: #2a2e37;
  --oubli: #f2a19b;
  --difficile: #f0c170;
  --facile: #8fd4a2;
  --ombre: 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* L'attribut hidden doit toujours l'emporter sur les display définis plus bas. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: var(--police);
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

svg { width: 1em; height: 1em; display: block; }

#app {
  max-width: 680px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(var(--marge), env(safe-area-inset-top)) var(--marge) 0;
}

.chargement { text-align: center; color: var(--texte-doux); margin-top: 30vh; }

.ecran {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--marge));
}

/* ---------- Éléments communs ---------- */

.puces { display: flex; flex-wrap: wrap; gap: 6px; }
.puce {
  display: inline-block;
  background: var(--puce);
  color: var(--texte-doux);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.fleche {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--marine);
  color: var(--sur-marine);
  font-size: 1.1rem;
  box-shadow: var(--halo);
}

.bouton-rond {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--bordure);
  background: var(--surface);
  color: var(--texte);
  font-size: 1.15rem;
  cursor: pointer;
}

.bouton {
  display: block;
  width: 100%;
  min-height: 56px;
  border: none;
  border-radius: var(--rayon-petit);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}

.bouton-principal {
  background: var(--marine);
  color: var(--sur-marine);
  box-shadow: var(--halo), 0 6px 18px rgba(2, 14, 70, 0.25);
}

.bouton:focus-visible, .bouton-rond:focus-visible, .lien:focus-visible,
.tuile:focus-visible, .ligne:focus-visible {
  outline: 3px solid var(--marine-clair);
  outline-offset: 3px;
}

.lien {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
  padding: 8px;
}

.intro { color: var(--texte-doux); margin: 0 0 1.25rem; }
.accueil .intro { font-size: 0.9rem; margin-bottom: 1rem; }

.barre {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--texte-doux);
  font-size: 0.9rem;
}
.barre-titre { font-size: 1.35rem; font-weight: 500; color: var(--texte); margin: 0; }

/* ---------- Accueil ---------- */

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.logo { display: flex; align-items: center; gap: 10px; }
.logo-tuile {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--rayon-petit);
  background: var(--marine);
  color: var(--sur-marine);
  font-size: 1.35rem;
  box-shadow: var(--halo);
}
.logo-texte { display: flex; flex-direction: column; line-height: 1.15; }
.logo-texte strong { font-weight: 600; font-size: 1.05rem; }
.logo-texte small { color: var(--marine-clair); font-size: 0.75rem; }

.hero {
  font-size: clamp(1.7rem, 7vw, 2.4rem);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0 0 0.75rem;
}

.hero-tuile {
  display: inline-grid;
  place-items: center;
  width: 1.15em;
  height: 1.15em;
  vertical-align: -0.18em;
  border-radius: 0.28em;
  background: var(--marine);
  color: var(--sur-marine);
  font-size: 0.85em;
  box-shadow: var(--halo), 0 8px 20px rgba(2, 14, 70, 0.3);
}
.hero-tuile svg { width: 0.6em; height: 0.6em; }
.hero-tuile.grande { font-size: 3rem; margin: 0 auto 1rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 1.75rem;
}
.stat {
  background: var(--surface);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 14px 8px;
  text-align: center;
}
.stat-nombre { display: block; font-size: 1.7rem; font-weight: 600; color: var(--marine); }
.stat-libelle { color: var(--texte-doux); font-size: 0.8rem; }
[data-theme="sombre"] .stat-nombre { color: var(--texte); }
[data-theme="sombre"] .tuile-sombre { background: radial-gradient(120% 90% at 100% 0%, #3046c4 0%, #1d2a8a 65%); }

.titre-section { font-size: 1.1rem; font-weight: 500; margin: 0 0 0.75rem; }

/* Indicateurs clés de l'Insee (haut de l'accueil) : carrousel, 3 cartes visibles.
   .chiffres = la fenêtre, qui défile horizontalement (barre masquée) ; .chiffres-piste = deux fois la série
   de cartes. Le défilement automatique et la boucle sont faits en JS (brancherDefilement), ce qui laisse
   défiler à la main : glisser à la souris ou au doigt, pavé tactile, flèches. */
.chiffres-insee { position: relative; margin-bottom: 1.25rem; }
.chiffres-entete { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 0.75rem; }
.chiffres-entete .titre-section { margin: 0; }
.chiffres-fleches { display: flex; gap: 6px; }
.bouton-mini { width: 34px; height: 34px; }
.bouton-mini svg { width: 16px; height: 16px; }
.chiffres {
  --ecart-chiffres: 8px;
  container-type: inline-size;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  cursor: grab;
  /* place pour l'ombre et la levée au survol, sinon coupées */
  padding: 6px 0 10px;
  margin: -6px 0 -10px;
}
.chiffres::-webkit-scrollbar { display: none; }
.chiffres.en-glisse { cursor: grabbing; user-select: none; }
.chiffres.en-glisse .chiffre { pointer-events: none; }
.chiffres-piste {
  display: flex;
  gap: var(--ecart-chiffres);
  /* l'écart après la dernière carte rend la piste exactement double (boucle sans saut) */
  padding-right: var(--ecart-chiffres);
  width: max-content;
}
.chiffres-piste > .chiffre { flex: 0 0 calc((100cqw - 2 * var(--ecart-chiffres)) / 3); }
.chiffre {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--surface);
  border-radius: var(--rayon-petit, 12px);
  box-shadow: var(--ombre);
  padding: 10px 12px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.chiffre-nom { color: var(--texte-doux); font-size: 0.75rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chiffre-valeur { font-size: 1.4rem; font-weight: 600; color: var(--marine); line-height: 1.25; white-space: nowrap; }
[data-theme="sombre"] .chiffre-valeur { color: var(--texte); }
.chiffre-periode { color: var(--texte-doux); font-size: 0.72rem; }
/* Téléphone : cartes étroites, le nom passe sur deux lignes (hauteur réservée pour aligner les valeurs). */
@media (max-width: 559px) {
  .chiffre { padding: 8px 10px; }
  .chiffre-nom { white-space: normal; line-height: 1.2; min-height: 2.4em; font-size: 0.7rem; }
  .chiffre-valeur { font-size: 1.2rem; }
}

/* Encart au survol d'un indicateur, placé en JS sous la carte : titre, petit graphique de l'historique
   (barres pour une évolution, courbe pour un niveau), puis « Lecture : … » et la source, comme dans
   une publication de l'Insee. Fond clair pour bien lire le graphique. */
.lecture {
  --serie: #3b5bfd;
  position: absolute;
  z-index: 5;
  width: min(340px, 100%);
  padding: 12px 14px 10px;
  border-radius: var(--rayon-petit, 12px);
  background: var(--surface);
  color: var(--texte);
  border: 1px solid var(--bordure);
  font-size: 0.78rem;
  line-height: 1.45;
  box-shadow: var(--ombre-haute, 0 12px 30px rgba(2, 14, 70, 0.2));
  pointer-events: none;
  animation: lecture-entree 0.2s ease both;
}
.lecture::before {
  content: "";
  position: absolute;
  top: -7px;
  left: calc(var(--fleche, 50%) - 6px);
  width: 12px;
  height: 12px;
  background: inherit;
  border-left: 1px solid var(--bordure);
  border-top: 1px solid var(--bordure);
  transform: rotate(45deg);
  border-radius: 2px 0 0 0;
}
.lecture p { margin: 0; }
.lecture[hidden] { display: none; }
[data-theme="sombre"] .lecture { --serie: #7b8ff0; background: var(--surface-douce); }
.lecture-titre { font-weight: 600; font-size: 0.78rem; margin-bottom: 4px !important; }
.lecture-texte { margin-top: 6px !important; }
.lecture-source { color: var(--texte-doux); font-size: 0.7rem; margin-top: 4px !important; }

/* Graphique de l'encart : marques fines, grille et axes discrets, texte en couleur d'encre. */
.graphique { display: block; overflow: visible; width: 100%; height: auto; aspect-ratio: 296 / 128; }
.graphique-grille { stroke: var(--bordure); stroke-width: 1; }
.graphique-zero { stroke: var(--texte-doux); stroke-width: 1; stroke-dasharray: 3 3; }
.graphique-axe { fill: var(--texte-doux); font-size: 9.5px; font-family: inherit; }
.graphique-valeur { fill: var(--texte); font-size: 10.5px; font-weight: 600; font-family: inherit; }
.graphique-ligne { fill: none; stroke: var(--serie); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.graphique-point { fill: var(--serie); stroke: var(--surface); stroke-width: 2; }
[data-theme="sombre"] .graphique-point { stroke: var(--surface-douce); }
.graphique-marque { fill: var(--serie); opacity: 0.45; }
.graphique-dernier { opacity: 1; }@keyframes lecture-entree { from { opacity: 0; translate: 0 -4px; } }

/* Accueil compact : compteurs de cartes sur une ligne, pour laisser la place aux indicateurs. */
.stats-compactes { gap: 8px; margin-bottom: 1.5rem; }
.stats-compactes .stat {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  border-radius: var(--rayon-petit, 12px);
}
.stats-compactes .stat-nombre { display: inline; font-size: 1.15rem; }
.stats-compactes .stat-libelle { font-size: 0.75rem; }
.chiffre-badge {
  display: inline-block;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--puce);
  font-size: 0.72rem;
  color: var(--texte-doux);
}
.chiffres-source { color: var(--texte-doux); font-size: 0.78rem; margin: 0.6rem 0 0; }
.chiffre:focus-visible { outline: 2px solid var(--marine); outline-offset: 2px; }

.bento {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.tuile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  min-height: 150px;
  padding: 18px 18px 64px;
  text-align: left;
  font: inherit;
  color: var(--texte);
  background: var(--surface);
  border: none;
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  cursor: pointer;
}
.tuile:disabled { cursor: default; opacity: 0.6; }
.tuile .fleche { position: absolute; right: 16px; bottom: 16px; }
.tuile-icone {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--rayon-petit);
  background: var(--puce);
  color: var(--marine);
  font-size: 1.15rem;
  margin-bottom: 4px;
}
.tuile-titre { font-weight: 600; font-size: 1.05rem; }
.tuile-texte { color: var(--texte-doux); font-size: 0.88rem; }

.tuile-sombre {
  background: radial-gradient(120% 90% at 100% 0%, #1b2a78 0%, var(--marine) 60%);
  color: var(--sur-marine);
  box-shadow: var(--halo), 0 10px 28px rgba(2, 14, 70, 0.3);
}
.tuile-sombre .tuile-texte { color: rgba(255, 255, 255, 0.78); }
.tuile-sombre .tuile-icone { background: rgba(255, 255, 255, 0.12); color: var(--sur-marine); }
.tuile-sombre .puce { background: rgba(255, 255, 255, 0.14); color: var(--sur-marine); }
.tuile-sombre .fleche { background: var(--sur-marine); color: var(--marine); }

/* Téléphone : les petites tuiles deviennent des lignes compactes, flèche à droite. */
@media (max-width: 559px) {
  .tuile:not(.tuile-large) {
    min-height: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 14px;
    row-gap: 2px;
    align-items: center;
    padding: 14px 66px 14px 14px;
  }
  .tuile:not(.tuile-large) .tuile-icone { grid-row: span 2; margin: 0; }
  /* Centrage vertical sans transform, pour laisser transform libre à l'animation de survol. */
  .tuile:not(.tuile-large) .fleche { top: 0; bottom: 0; margin: auto 0; }
}

@media (min-width: 560px) {
  .bento { grid-template-columns: repeat(3, 1fr); }
  .tuile-large { grid-column: span 3; }
}

.pied {
  margin-top: auto;
  padding: 2rem 0 max(1rem, env(safe-area-inset-bottom));
  color: var(--texte-doux);
  font-size: 0.78rem;
  text-align: center;
}
.pied p { margin: 0.3rem 0; }
.avertissement { font-weight: 600; }

/* ---------- Listes (thèmes, chapitres) ---------- */

.liste .barre { margin-bottom: 1rem; }
.lignes { display: grid; gap: 10px; padding-bottom: 2rem; }

.ligne {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px;
  text-align: left;
  font: inherit;
  color: var(--texte);
  background: var(--surface);
  border: none;
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  cursor: pointer;
}
.ligne:disabled { cursor: default; opacity: 0.55; box-shadow: none; }
.ligne:disabled .fleche { background: var(--puce); color: var(--texte-doux); box-shadow: none; }
.ligne-corps { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ligne-titre { font-weight: 600; }
.ligne-texte { color: var(--texte-doux); font-size: 0.85rem; }
.ligne-texte:empty { display: none; }

.jauge { display: block; height: 6px; border-radius: 999px; background: var(--puce); overflow: hidden; }
.jauge-remplie { display: block; height: 100%; width: 0; background: var(--marine); border-radius: inherit; }

/* ---------- Révision ---------- */

.compteur { margin-left: auto; }

.carte {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  margin: 16px 0;
  padding: calc(var(--marge) + 4px);
  background: var(--surface);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  min-height: 45dvh;
  cursor: pointer;
}
.carte .puces { order: -1; }

.question { font-size: 1.35rem; font-weight: 500; line-height: 1.3; margin: 0; }

.reponse {
  padding-top: 14px;
  border-top: 1px solid var(--bordure);
  font-size: 1.05rem;
}
.reponse p { margin: 0; }

.actions-bas {
  position: sticky;
  bottom: 0;
  padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--fond) 25%);
}

.notes, .modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.modes { grid-template-columns: 1fr 1fr 1.3fr; }

.note, .mode {
  background: var(--surface);
  color: var(--texte);
  box-shadow: var(--ombre);
  font-size: 0.95rem;
  padding: 6px 4px;
}
.note { border: 2px solid currentColor; }
.note small, .mode small { display: block; font-weight: 400; font-size: 0.72rem; opacity: 0.8; }
.note-oubli { color: var(--oubli); }
.note-difficile { color: var(--difficile); }
.note-facile { color: var(--facile); }
.mode.bouton-principal { background: var(--marine); color: var(--sur-marine); box-shadow: var(--halo), 0 6px 18px rgba(2, 14, 70, 0.25); }
.mode:disabled { opacity: 0.4; cursor: not-allowed; }

.choix { display: grid; gap: 8px; }

/* Avec des propositions, la carte se réduit pour laisser la place aux réponses. */
.avec-propositions .carte { flex: none; min-height: 0; }
.avec-propositions .reponse { border-top: none; padding-top: 0; }

.proposition {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  font-weight: 400;
  font-size: 0.95rem;
  padding: 12px 14px;
  min-height: 52px;
  background: var(--surface);
  color: var(--texte);
  border: 2px solid transparent;
  box-shadow: var(--ombre);
}
.proposition .numero {
  flex: none;
  width: 1.7em;
  height: 1.7em;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--puce);
  color: var(--texte-doux);
}
.proposition:disabled { cursor: default; opacity: 0.55; }
.proposition.juste { border-color: var(--facile); opacity: 1; }
.proposition.faux { border-color: var(--oubli); opacity: 1; }
.proposition.juste .numero { background: var(--facile); color: var(--surface); }
.proposition.faux .numero { background: var(--oubli); color: var(--surface); }

[data-action="continuer"] { margin-top: 8px; }

.resultat { font-weight: 600; margin: 0 0 0.4rem; }
.resultat-juste { color: var(--facile); }
.resultat-faux { color: var(--oubli); }

/* ---------- Fin ---------- */

.fin { justify-content: center; text-align: center; }
.fin h2 { font-weight: 500; font-size: 1.6rem; margin: 0 0 0.5rem; }
.fin .actions-bas { position: static; background: none; }

/* ---------- Fiche d'un thème ou d'un chapitre ---------- */

.fiche .barre { margin-bottom: 1rem; }
.fiche .intro { margin-bottom: 0.75rem; }
.fiche > .puces { margin-bottom: 1.25rem; }
.fiche-aide { color: var(--texte-doux); font-size: 0.85rem; margin: -0.75rem 0 1.25rem; }
.fiche-sections { display: grid; gap: 1.75rem; padding-bottom: 1rem; }
.fiche-section { display: grid; gap: 10px; }
.fiche-section .titre-section { margin-bottom: 2px; }

.fiche-carte {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--rayon-petit);
  box-shadow: var(--ombre);
}
.fiche-question { margin: 0; font-weight: 600; line-height: 1.35; }
.fiche-reponse { margin: 0; line-height: 1.45; transition: filter 0.3s ease, opacity 0.3s ease; }

.fiche-etat {
  justify-self: start;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--puce);
  color: var(--texte-doux);
}
.etat-a-revoir { color: var(--oubli); background: color-mix(in srgb, var(--oubli) 14%, transparent); }
.etat-en-cours { color: var(--difficile); background: color-mix(in srgb, var(--difficile) 14%, transparent); }
.etat-maitrisee { color: var(--facile); background: color-mix(in srgb, var(--facile) 14%, transparent); }

/* Onglet « Questions » : réponses floutées, une touche les révèle. */
.fiche-questions .fiche-carte { cursor: pointer; }
.fiche-questions .fiche-carte:not(.revelee) .fiche-reponse,
.fiche-questions .fiche-carte:not(.revelee) .fiche-illustration {
  filter: blur(6px);
  opacity: 0.6;
  user-select: none;
}

/* Illustration d'une définition (exemple concret), écrite en vert, sous la réponse. */
.illustration {
  margin: 0.6rem 0 0;
  padding: 8px 12px;
  border-left: 3px solid var(--facile);
  border-radius: 0 8px 8px 0;
  background: color-mix(in srgb, var(--facile) 8%, transparent);
  color: var(--facile);
  font-size: 0.92em;
  line-height: 1.45;
}
.illustration[hidden] { display: none; }
.illustration-libelle { font-weight: 600; }
.fiche-illustration { margin-top: 0.4rem; transition: filter 0.3s ease, opacity 0.3s ease; }

/* Onglet « Fiche de révision » : la fiche rédigée, lisible comme une fiche papier. */
.fiche-synthese { display: grid; gap: 1.25rem; padding-bottom: 1rem; }
.fiche-bloc {
  display: grid;
  gap: 1rem;
  padding: 18px 18px 20px;
  background: var(--surface);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
}
.fiche-bloc-titre { margin: 0; font-size: 1.15rem; font-weight: 600; }
.fiche-resume {
  margin: 0;
  padding: 12px 14px;
  border-left: 4px solid var(--marine);
  background: var(--surface-douce);
  border-radius: 0 var(--rayon-petit) var(--rayon-petit) 0;
  line-height: 1.5;
}
/* Cours rédigé : lecture continue, paragraphes aérés. */
.fiche-partie { display: grid; gap: 0.6rem; }
.fiche-partie-titre { margin: 0.4rem 0 0; font-size: 1.05rem; font-weight: 600; color: var(--marine); }
.fiche-paragraphe { margin: 0; line-height: 1.65; }
.fiche-paragraphe strong { font-weight: 600; }

/* Encadré final « À retenir » : les points essentiels pour la relecture rapide. */
.fiche-retenir {
  display: grid;
  gap: 1rem;
  margin-top: 0.5rem;
  padding: 16px;
  border-radius: var(--rayon-petit);
  background: var(--surface-douce);
  border: 1px solid var(--bordure);
}
.fiche-retenir-titre { margin: 0; font-size: 1.05rem; font-weight: 600; }

/* Formules LaTeX (KaTeX) : même couleur que le texte, taille alignée sur Poppins. */
.formule .katex { font-size: 1.08em; color: inherit; }
.proposition-texte { min-width: 0; }
/* Dans les questions et les propositions, formules un peu plus grandes pour que les fractions restent lisibles. */
.question .katex,
.proposition .katex,
.reponse .katex { font-size: 1.18em; }

/* Tableau des formules : notion à gauche, formule à droite ; défilement horizontal si trop large. */
.fiche-table-conteneur { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.fiche-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--rayon-petit);
  overflow: hidden;
  font-size: 0.95rem;
}
.fiche-table th,
.fiche-table td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--bordure);
}
.fiche-table tr:last-child th,
.fiche-table tr:last-child td { border-bottom: none; }
.fiche-table th { width: 38%; font-weight: 600; color: var(--texte); }
.fiche-table td { color: var(--marine); }
.fiche-table td .katex { font-size: 1.12em; }

.fiche-rubrique { display: grid; gap: 8px; }
.fiche-rubrique-titre {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--marine-clair);
}
.fiche-liste { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.fiche-item {
  line-height: 1.45;
  padding-left: 14px;
  position: relative;
}
.fiche-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.6em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--marine-clair);
}
.fiche-terme { font-weight: 600; }
.fiche-terme + .fiche-def::before { content: " : "; }
/* Formules : terme et résultat mis en valeur. */
.rubrique-formules .fiche-terme,
.rubrique-chiffres .fiche-terme,
.rubrique-dates .fiche-terme { color: var(--marine); }
.rubrique-pieges .fiche-item::before { background: var(--oubli); }

/* La fiche peut être longue : le bouton du quiz reste collé en bas, même sur ordinateur. */
.fiche .actions-bas { position: sticky; bottom: 0; }

.segments-petits { margin-bottom: 1.25rem; }
.segments-petits .segment { font-size: 0.95rem; min-height: 42px; }

/* ---------- Sélecteur de matière (accueil) ---------- */

/* Bien visible : toute la largeur, trois boutons égaux, gros texte. */
.segments {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  padding: 6px;
  margin: 0 0 1.5rem;
  background: var(--surface);
  border: 2px solid var(--bordure);
  border-radius: 999px;
  box-shadow: var(--ombre);
}
.segment {
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 600;
  font-size: 1.05rem;
  min-height: 48px;
  padding: 10px 16px;
  border-radius: 999px;
  color: var(--texte-doux);
  cursor: pointer;
  transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}
.segment[aria-pressed="true"] { box-shadow: var(--halo), 0 6px 18px rgba(2, 14, 70, 0.25); }
.segment[aria-pressed="true"] { background: var(--marine); color: var(--sur-marine); }
.segment:focus-visible { outline: 3px solid var(--marine-clair); outline-offset: 2px; }
@media (hover: hover) {
  .segment[aria-pressed="false"]:hover { color: var(--texte); background: var(--surface-douce); }
}

/* ---------- Animations ---------- */

/* Règles de fluidité :
   - on n'anime que transform et opacity, que le navigateur calcule sans redessiner la page ;
   - les ombres renforcées sont pré-dessinées dans un ::after dont seule l'opacité varie ;
   - les animations d'entrée ne figent pas l'élément (fill-mode « backwards ») :
     sinon leur état final bloque le déplacement au survol. */

:root {
  --ease-doux: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-ressort: cubic-bezier(0.34, 1.56, 0.64, 1);
  /* Survol : démarrage et arrivée progressifs (pas de départ brusque). */
  --ease-survol: cubic-bezier(0.45, 0, 0.25, 1);
  --duree-survol: 0.6s;
  --ombre-haute: 0 4px 10px rgba(2, 14, 70, 0.06), 0 20px 40px rgba(2, 14, 70, 0.12);
}

.tuile, .ligne, .stat, .chiffre, .mode, .note, .proposition, .bouton, .bouton-rond, .fleche, .tuile-icone {
  transition:
    translate 0.4s ease,
    transform var(--duree-survol) var(--ease-survol),
    opacity var(--duree-survol) var(--ease-survol),
    color 0.3s ease,
    border-color 0.4s ease;
}

.tuile, .ligne, .stat, .chiffre { position: relative; isolation: isolate; }
.tuile::after, .ligne::after, .stat::after, .chiffre::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  box-shadow: var(--ombre-haute);
  opacity: 0;
  transition: opacity var(--duree-survol) var(--ease-survol);
  pointer-events: none;
}

/* Changement de couleur des boutons au survol : une couche de couleur apparaît en fondu
   derrière le contenu (::before, isolation + z-index -1), pendant que le texte change de couleur.
   --remplissage : couleur de fond au survol ; --sur-remplissage : couleur du texte par-dessus. */
/* :where() = spécificité nulle, pour que les couleurs par variante (principal, notes) l'emportent. */
:where(.bouton:not(.proposition), .bouton-rond, .fleche) {
  --remplissage: var(--marine);
  --sur-remplissage: var(--sur-marine);
}
.bouton:not(.proposition), .bouton-rond, .fleche {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}
.bouton:not(.proposition)::before, .bouton-rond::before, .fleche::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--remplissage);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.bouton-principal, .fleche { --remplissage: var(--accent); }
.tuile-sombre .fleche { --remplissage: var(--accent); --sur-remplissage: var(--sur-marine); }
.note-oubli { --remplissage: var(--oubli); --sur-remplissage: var(--surface); }
.note-difficile { --remplissage: var(--difficile); --sur-remplissage: var(--surface); }
.note-facile { --remplissage: var(--facile); --sur-remplissage: var(--surface); }
.note { border-color: var(--remplissage); } /* sinon la bordure (currentColor) changerait avec le texte */

/* Survol : seulement sur les appareils avec une souris (pas d'effet « collé » au doigt).
   Levée façon Coffelo : la carte monte de 5 px en 0,4 s ; la flèche, survolée elle-même,
   monte encore de 5 px. On utilise « translate » (indépendant de transform) pour que la
   levée se cumule avec l'enfoncement au clic (transform: scale). */
@media (hover: hover) {
  .tuile:not(:disabled):hover, .ligne:not(:disabled):hover, .stat:hover, .chiffre:hover { translate: 0 -5px; }
  .tuile:not(:disabled):hover::after, .ligne:not(:disabled):hover::after, .stat:hover::after, .chiffre:hover::after { opacity: 1; }
  .tuile:not(:disabled):hover .tuile-icone { transform: rotate(-4deg) scale(1.04); }
  .fleche:hover { translate: 0 -5px; }

  .bouton:not(.proposition):not(:disabled):hover, .bouton-rond:hover,
  .tuile:not(:disabled):hover .fleche, .ligne:not(:disabled):hover .fleche { color: var(--sur-remplissage); }
  .bouton:not(.proposition):not(:disabled):hover::before, .bouton-rond:hover::before,
  .tuile:not(:disabled):hover .fleche::before, .ligne:not(:disabled):hover .fleche::before { opacity: 1; }

  .proposition:not(:disabled):hover { border-color: var(--marine-clair); transform: translateX(2px); }
}

/* Appui (tous appareils) : enfoncement rapide, puis retour en douceur. */
.bouton:active:not(:disabled), .bouton-rond:active, .ligne:active:not(:disabled), .tuile:active:not(:disabled) {
  transform: scale(0.97);
  transition-duration: 0.12s;
}

@keyframes entree {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
}
@keyframes apparition { from { opacity: 0; transform: translateY(8px); } }
@keyframes fondu { from { opacity: 0; } }
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.045); }
  100% { transform: scale(1); }
}
@keyframes secousse {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

/* Changement d'écran : fondu enchaîné. */
.ecran { animation: fondu 0.35s var(--ease-doux) backwards; }

.carte.entree { animation: entree 0.5s var(--ease-doux) backwards; }
.reponse:not([hidden]), .notes:not([hidden]), [data-action="continuer"]:not([hidden]) {
  animation: apparition 0.4s var(--ease-doux) backwards;
}
.choix:not([hidden]) .proposition { animation: apparition 0.45s var(--ease-doux) backwards; }
.choix .proposition:nth-child(2) { animation-delay: 0.05s; }
.choix .proposition:nth-child(3) { animation-delay: 0.1s; }
.choix .proposition:nth-child(4) { animation-delay: 0.15s; }
.choix:not([hidden]) .proposition.juste { animation: pop 0.5s var(--ease-ressort); }
.choix:not([hidden]) .proposition.faux { animation: secousse 0.45s ease; }

/* Accueil et listes : apparition en cascade. */
.accueil .stat, .accueil .tuile, .lignes .ligne { animation: entree 0.6s var(--ease-doux) backwards; }
.accueil .stat:nth-child(2) { animation-delay: 0.05s; }
.accueil .stat:nth-child(3) { animation-delay: 0.1s; }
.accueil .tuile:nth-child(1) { animation-delay: 0.12s; }
.accueil .tuile:nth-child(2) { animation-delay: 0.18s; }
.accueil .tuile:nth-child(3) { animation-delay: 0.24s; }
.accueil .tuile:nth-child(4) { animation-delay: 0.3s; }
.lignes .ligne:nth-child(2) { animation-delay: 0.04s; }
.lignes .ligne:nth-child(3) { animation-delay: 0.08s; }
.lignes .ligne:nth-child(4) { animation-delay: 0.12s; }
.lignes .ligne:nth-child(5) { animation-delay: 0.16s; }
.lignes .ligne:nth-child(n+6) { animation-delay: 0.2s; }

/* ---------- Pop-ups (toasts) ---------- */

.toasts {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}

@keyframes toast-entree {
  0% { opacity: 0; transform: translateY(-16px) scale(0.85); }
  60% { opacity: 1; transform: translateY(2px) scale(1.04); }
  100% { opacity: 1; transform: none; }
}
@keyframes toast-sortie { to { opacity: 0; transform: translateY(-10px) scale(0.95); } }

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 10px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--texte);
  font-weight: 500;
  font-size: 0.95rem;
  box-shadow: 0 10px 30px rgba(2, 14, 70, 0.2);
  animation: toast-entree 0.38s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
.toast.sortie { animation: toast-sortie 0.25s ease forwards; }
.toast-icone {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 1rem;
  color: #fff;
  background: var(--facile);
}
.toast-info .toast-icone { background: var(--texte-doux); }
.toast-serie .toast-icone { background: linear-gradient(135deg, #ff9a3c, #ff4e50); }
.toast-serie { background: var(--marine); color: var(--sur-marine); box-shadow: var(--halo), 0 10px 30px rgba(2, 14, 70, 0.35); }

/* ---------- Fin de série ---------- */

@keyframes fin-pop {
  0% { opacity: 0; transform: scale(0.6) rotate(-8deg); }
  60% { opacity: 1; transform: scale(1.12) rotate(3deg); }
  100% { transform: none; }
}
.fin .hero-tuile { animation: fin-pop 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.2) both; }
.fin h2, .fin p, .fin .puces { animation: entree 0.45s ease both; }
.fin h2 { animation-delay: 0.15s; }
.fin .fin-message { animation-delay: 0.25s; }
.fin .puces { animation-delay: 0.35s; justify-content: center; margin: 1rem 0; }
.fin [data-bilan] { animation-delay: 0.3s; color: var(--texte-doux); }
.fin-message { font-size: 1.1rem; font-weight: 500; margin: 0 0 0.3rem; }

.confettis { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
@keyframes chute {
  0% { transform: translate3d(0, -10vh, 0) rotate(0); opacity: 1; }
  100% { transform: translate3d(var(--derive), 105vh, 0) rotate(var(--rotation)); opacity: 0.9; }
}
.confetti {
  position: absolute;
  top: 0;
  left: var(--x);
  width: 8px;
  height: 14px;
  border-radius: 2px;
  background: var(--couleur);
  animation: chute var(--duree) cubic-bezier(0.25, 0.6, 0.4, 1) var(--delai) both;
}

/* Réglage système « réduire les animations » : on coupe les animations automatiques
   (apparition des écrans, cascades, confettis, secousse…). Choix assumé : les effets de
   survol (montée de 5 px, remplissage des boutons) restent actifs, car ils sont légers
   et ne se déclenchent que sous la souris. Les transitions ne sont donc pas coupées. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
  }
  .confettis { display: none; }
}

/* ---------- Grands écrans ---------- */

/* Ordinateur et tablette : pas de pleine hauteur. La carte prend la hauteur de son contenu
   et les boutons restent juste dessous, au lieu d'être collés en bas de l'écran. */
@media (min-width: 700px) {
  html, body { font-size: 18px; }
  #app { padding-top: max(40px, env(safe-area-inset-top)); }
  .ecran { min-height: 0; }
  .revision .carte { flex: none; min-height: 240px; margin: 20px 0 8px; }
  .actions-bas { position: static; background: none; padding-bottom: 40px; }
  .fin { min-height: 60vh; }
  .pied { margin-top: 2rem; }
}

/* ---------- Document à lire (cartes « note de lecture ») ---------- */
/* Couleurs des séries : palette validée (daltonisme, contraste), une version par thème. */
:root { --serie-1: #2a78d6; --serie-2: #eb6834; }
[data-theme="sombre"] { --serie-1: #3987e5; --serie-2: #d95926; }
.document-zone { margin-top: 0.9rem; }
.document-zone[hidden] { display: none; }
.document {
  margin: 0;
  padding: 12px 14px 10px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon-petit, 12px);
  background: var(--surface);
}
.document-titre { font-weight: 600; font-size: 0.88rem; line-height: 1.35; }
.document-unite { font-weight: 400; color: var(--texte-doux); font-size: 0.8rem; }
.document-graphique { display: block; width: 100%; height: auto; margin-top: 6px; overflow: visible; }
.document-notes { margin: 4px 0 0; color: var(--texte-doux); font-size: 0.72rem; line-height: 1.4; }
.doc-grille { stroke: var(--bordure); stroke-width: 1; }
.doc-zero { stroke: var(--texte-doux); stroke-width: 1.2; }
.doc-axe { fill: var(--texte-doux); font-size: 12px; font-family: inherit; }
.doc-legende { fill: var(--texte); font-size: 12.5px; font-family: inherit; }
.doc-valeur { fill: var(--texte); font-size: 12px; font-family: inherit; }
.doc-valeur-forte { font-weight: 700; font-size: 13px; }
.doc-ligne { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.doc-point { stroke: var(--surface); stroke-width: 2; }
.doc-attenue { opacity: 0.4; }
.fiche-carte .document { margin: 0.5rem 0; }
/* Tableau d'un document (annexes des annales) : défile horizontalement sur petit écran. */
.document-tableau-conteneur { overflow-x: auto; max-width: 100%; margin-top: 8px; -webkit-overflow-scrolling: touch; }
/* Le tableau défile dans son cadre au lieu d'élargir la carte (les parents flex/grid doivent pouvoir rétrécir). */
.document, .document-zone, .fiche-carte, .carte { min-width: 0; }
.document-tableau { min-width: 420px; }
.document-tableau { border-collapse: collapse; width: 100%; font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.document-tableau th, .document-tableau td { padding: 4px 6px; border-bottom: 1px solid var(--bordure); }
.document-tableau thead th { font-weight: 600; text-align: right; vertical-align: bottom; line-height: 1.2; }
.document-tableau tbody th { font-weight: 400; text-align: left; }
.document-tableau td { text-align: right; white-space: nowrap; }
.document-tableau .ligne-grasse th, .document-tableau .ligne-grasse td { font-weight: 700; }
.document-tableau .ligne-titre-tableau th { font-weight: 700; padding-top: 8px; }
.document-tableau .cellule-surlignee { background: color-mix(in srgb, var(--serie-1) 22%, transparent); outline: 2px solid var(--serie-1); outline-offset: -2px; font-weight: 700; }