/* Leçon interactive. Grands boutons en relief, retour immédiat, couleurs
   franches : le geste doit être évident pour un enfant de douze ans. */

.lecon {
  --l-vert: var(--vert, #2e7d4f);
  --l-vert-relief: #1f5c3a;
  --l-pousse: var(--pousse, #43a047);
  --l-juste-fond: #dff3e4;
  --l-faux: var(--alerte, #b3402e);
  --l-faux-fond: #fbe4df;
  --l-soleil: var(--soleil, #f2b233);
  --l-encre: var(--encre, #1b2b22);
  --l-doux: var(--encre-douce, #5b6b62);
  --l-ligne: #e2e8e4;
  --l-relief: #cfd8d2;
  --l-surface: #fff;
  color: var(--l-encre);
  font-family: var(--police, inherit);
  position: relative;
}

.lecon__puces { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; padding: 0; }
.lecon__puces span {
  background: var(--menthe, #e6f1ea); color: var(--l-vert);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 700;
}

/* --- Barre du haut ----------------------------------------------------------- */
.lecon__barre { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.lecon__progres { flex: 1; height: 16px; background: var(--l-ligne); border-radius: 999px; overflow: hidden; }
.lecon__progres > span {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: var(--l-pousse);
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, .35);
  transition: width .45s cubic-bezier(.3, 1.4, .6, 1);
}
.lecon__coeurs { display: inline-flex; align-items: center; gap: 4px; color: #e5484d; font-weight: 800; font-size: 18px; }
.lecon__coeurs b { color: #e5484d; }
.lecon__son { border: 0; background: none; font-size: 20px; cursor: pointer; padding: 4px; border-radius: 8px; }

/* --- Étapes ------------------------------------------------------------------ */
.lecon__etapes { list-style: none; margin: 0; padding: 0; }
.lecon:not(.lecon--active) .lecon__etape { padding: 24px 0; border-bottom: 1px solid var(--l-ligne); }
.lecon--active .lecon__etape { animation: lecon-entree .35s ease both; }
.lecon__etape h2 { font-size: clamp(22px, 3.2vw, 28px); line-height: 1.25; margin: 0 0 18px; text-wrap: balance; outline: none; }
.lecon__etape p { font-size: 17px; line-height: 1.6; margin: 0 0 12px; }
.lecon__consigne { color: var(--l-doux); font-size: 14px !important; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px !important; }

.lecon__etape--carte { background: var(--menthe, #e6f1ea); border-radius: 20px; padding: 28px !important; }
.lecon__etape--carte strong { color: var(--l-vert); }

.lecon__video { width: 100%; aspect-ratio: 16 / 9; border-radius: 16px; background: #0f1a14; display: block; margin-bottom: 16px; }
.lecon__figure { margin: 0 0 18px; text-align: center; }
.lecon__figure img { max-height: 260px; width: auto; border-radius: 12px; }

/* --- Boutons en relief ------------------------------------------------------- */
.lecon__choix,
.lecon__puce,
.lecon__action,
.lecon__recommencer {
  font: inherit; cursor: pointer; border-radius: 16px;
  transition: transform .08s ease, box-shadow .08s ease, background .15s ease, border-color .15s ease;
}

.lecon__options { display: grid; gap: 12px; }
.lecon__choix {
  display: flex; align-items: center; gap: 14px; text-align: start;
  background: var(--l-surface); color: var(--l-encre);
  border: 2px solid var(--l-ligne); box-shadow: 0 4px 0 var(--l-relief);
  padding: 16px 18px; font-size: 17px; font-weight: 600;
}
.lecon__choix kbd {
  flex-shrink: 0; display: grid; place-items: center; width: 30px; height: 30px;
  border: 2px solid var(--l-ligne); border-radius: 8px; font: inherit; font-size: 14px; color: var(--l-doux);
}
.lecon:not(.lecon--active) .lecon__choix kbd { display: none; }
.lecon__choix:hover:not(:disabled) { background: #f6faf7; }
.lecon__choix:active:not(:disabled),
.lecon__puce:active:not(:disabled),
.lecon__action:active:not(:disabled),
.lecon__recommencer:active { transform: translateY(4px); box-shadow: 0 0 0 transparent; }
.lecon__choix[aria-pressed="true"] { border-color: var(--l-pousse); background: var(--l-juste-fond); box-shadow: 0 4px 0 var(--l-pousse); }
.lecon__choix[aria-pressed="true"] kbd { border-color: var(--l-pousse); color: var(--l-vert); }
.lecon__choix.est-juste { border-color: var(--l-pousse); background: var(--l-juste-fond); box-shadow: 0 4px 0 var(--l-pousse); color: var(--l-vert-relief); }
.lecon__choix.est-faux { border-color: var(--l-faux); background: var(--l-faux-fond); box-shadow: 0 4px 0 var(--l-faux); color: var(--l-faux); animation: lecon-secousse .35s ease; }
.lecon__choix.est-faux kbd { border-color: var(--l-faux); color: var(--l-faux); }
.lecon__choix.est-juste kbd { border-color: var(--l-pousse); color: var(--l-vert); }
.lecon__choix:disabled { cursor: default; }

.lecon__nombre { display: flex; align-items: center; gap: 12px; }
.lecon__nombre input {
  width: min(220px, 100%); font: inherit; font-size: 26px; font-weight: 700; text-align: center;
  border: 2px solid var(--l-ligne); border-bottom-width: 5px; border-radius: 16px; padding: 12px 14px; background: var(--l-surface);
}
.lecon__nombre input:focus { border-color: var(--l-pousse); outline: none; }
.lecon__nombre span { font-size: 22px; font-weight: 700; color: var(--l-doux); }
.lecon__etape--juste .lecon__nombre input { border-color: var(--l-pousse); background: var(--l-juste-fond); }
.lecon__etape--faux .lecon__nombre input { border-color: var(--l-faux); background: var(--l-faux-fond); animation: lecon-secousse .35s ease; }

.lecon__reponse {
  min-height: 64px; display: flex; flex-direction: column; gap: 10px;
  border-bottom: 2px dashed var(--l-relief); padding: 6px 0 16px; margin-bottom: 18px;
}
.lecon:not(.lecon--active) .lecon__reponse { display: none; }
.lecon__banque { display: flex; flex-wrap: wrap; gap: 10px; }
.lecon__reponse .lecon__puce { width: 100%; }
.lecon__puce {
  background: var(--l-surface); color: var(--l-encre); text-align: start;
  border: 2px solid var(--l-ligne); box-shadow: 0 4px 0 var(--l-relief);
  padding: 12px 16px; font-size: 16px; font-weight: 600;
}
.lecon__etape--juste .lecon__reponse .lecon__puce { border-color: var(--l-pousse); background: var(--l-juste-fond); }
.lecon__etape--faux .lecon__reponse .lecon__puce { border-color: var(--l-faux); background: var(--l-faux-fond); }

.lecon__solution { margin-top: 16px; }
.lecon__solution summary { cursor: pointer; font-weight: 700; color: var(--l-vert); }
.lecon--active .lecon__solution { display: none; }

/* --- Pied : verdict et bouton principal ---------------------------------------- */
.lecon__pied {
  position: sticky; bottom: 0; z-index: 2;
  margin: 28px -40px -40px; padding: 18px 40px 22px;
  background: var(--l-surface); border-top: 2px solid var(--l-ligne);
  border-radius: 0 0 var(--r-carte, 16px) var(--r-carte, 16px);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 24px;
  transition: background .2s ease;
}
.lecon:not(.lecon--active) .lecon__pied { display: none; }
.lecon--juste .lecon__pied { background: var(--l-juste-fond); border-top-color: transparent; }
.lecon--faux .lecon__pied { background: var(--l-faux-fond); border-top-color: transparent; }
.lecon__verdict { flex: 1 1 280px; animation: lecon-monte .25s ease both; }
.lecon__verdict strong { display: block; font-size: 22px; }
.lecon__verdict p { margin: 4px 0 0; font-size: 15px; line-height: 1.5; }
.lecon--juste .lecon__verdict { color: var(--l-vert-relief); }
.lecon--faux .lecon__verdict { color: var(--l-faux); }

.lecon__action,
.lecon__recommencer {
  margin-inline-start: auto; min-width: 180px;
  background: var(--l-vert); color: #fff; border: 0;
  box-shadow: 0 4px 0 var(--l-vert-relief);
  padding: 15px 28px; font-size: 16px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
}
.lecon--faux .lecon__action { background: var(--l-faux); box-shadow: 0 4px 0 #7d2a1e; }
.lecon__action:disabled { background: var(--l-ligne); color: #8b968f; box-shadow: 0 4px 0 var(--l-relief); cursor: not-allowed; }

/* --- Fin de leçon ---------------------------------------------------------------- */
.lecon__fin { text-align: center; padding: 20px 0 8px; position: relative; overflow: hidden; }
.lecon__fin h2 { font-size: clamp(28px, 4vw, 38px); color: var(--l-vert); margin: 8px 0 10px; outline: none; }
.lecon__fin-texte { color: var(--l-doux); max-width: 46ch; margin: 0 auto 26px; }
.lecon__stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 0 0 28px; }
.lecon__stat { --c: var(--l-vert); border: 2px solid var(--c); border-radius: 16px; overflow: hidden; }
.lecon__stat dt { background: var(--c); color: #fff; padding: 6px; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.lecon__stat dd { margin: 0; padding: 12px 6px; font-size: 24px; font-weight: 800; color: var(--l-encre); font-variant-numeric: tabular-nums; }
.lecon__stat--xp { --c: #9a6208; }
.lecon__stat--serie { --c: #b0500f; }
.lecon__stat--temps { --c: #2f6aa8; }
.lecon__fin-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 16px 24px; }
.lecon__fin-actions .lecon__recommencer { margin: 0; }
.lecon__lien { color: var(--l-vert); font-weight: 700; }

.lecon__confettis { position: absolute; inset: 0; pointer-events: none; }
.lecon__confettis i { position: absolute; top: -12px; width: 10px; height: 14px; border-radius: 3px; opacity: 0; }
.lecon__confettis i:nth-child(4n+1) { background: var(--l-pousse); }
.lecon__confettis i:nth-child(4n+2) { background: var(--l-soleil); }
.lecon__confettis i:nth-child(4n+3) { background: #3d7fc4; }
.lecon__confettis i:nth-child(4n) { background: #e5484d; }
.lecon__fin--fete .lecon__confettis i { animation: lecon-confetti 1.6s cubic-bezier(.2, .6, .4, 1) forwards; }

.lecon__confettis i:nth-child(1) { left: 43%; animation-delay: 0.09s; --x: -10px; --r: 229deg; }
.lecon__confettis i:nth-child(2) { left: 11%; animation-delay: 0.34s; --x: -48px; --r: 554deg; }
.lecon__confettis i:nth-child(3) { left: 76%; animation-delay: 0.03s; --x: 56px; --r: 699deg; }
.lecon__confettis i:nth-child(4) { left: 29%; animation-delay: 0.02s; --x: -49px; --r: 624deg; }
.lecon__confettis i:nth-child(5) { left: 55%; animation-delay: 0.04s; --x: -30px; --r: 272deg; }
.lecon__confettis i:nth-child(6) { left: 72%; animation-delay: 0.27s; --x: -53px; --r: 306deg; }
.lecon__confettis i:nth-child(7) { left: 30%; animation-delay: 0.4s; --x: 20px; --r: 243deg; }
.lecon__confettis i:nth-child(8) { left: 75%; animation-delay: 0.37s; --x: -10px; --r: 230deg; }
.lecon__confettis i:nth-child(9) { left: 30%; animation-delay: 0.02s; --x: 11px; --r: 316deg; }
.lecon__confettis i:nth-child(10) { left: 39%; animation-delay: 0.26s; --x: -42px; --r: 300deg; }
.lecon__confettis i:nth-child(11) { left: 75%; animation-delay: 0.19s; --x: 11px; --r: 365deg; }
.lecon__confettis i:nth-child(12) { left: 15%; animation-delay: 0.37s; --x: 13px; --r: 372deg; }
.lecon__confettis i:nth-child(13) { left: 49%; animation-delay: 0.06s; --x: 10px; --r: 244deg; }
.lecon__confettis i:nth-child(14) { left: 74%; animation-delay: 0.03s; --x: 19px; --r: 390deg; }
.lecon__confettis i:nth-child(15) { left: 65%; animation-delay: 0.34s; --x: -6px; --r: 501deg; }
.lecon__confettis i:nth-child(16) { left: 61%; animation-delay: 0.37s; --x: 58px; --r: 644deg; }
.lecon__confettis i:nth-child(17) { left: 48%; animation-delay: 0.19s; --x: -29px; --r: 364deg; }
.lecon__confettis i:nth-child(18) { left: 91%; animation-delay: 0.15s; --x: -50px; --r: 487deg; }
.lecon__confettis i:nth-child(19) { left: 69%; animation-delay: 0.31s; --x: 52px; --r: 531deg; }
.lecon__confettis i:nth-child(20) { left: 95%; animation-delay: 0.28s; --x: -24px; --r: 254deg; }
.lecon__confettis i:nth-child(21) { left: 17%; animation-delay: 0.32s; --x: -7px; --r: 348deg; }
.lecon__confettis i:nth-child(22) { left: 45%; animation-delay: 0.09s; --x: 59px; --r: 680deg; }
.lecon__confettis i:nth-child(23) { left: 55%; animation-delay: 0.02s; --x: 25px; --r: 259deg; }
.lecon__confettis i:nth-child(24) { left: 73%; animation-delay: 0.36s; --x: 41px; --r: 501deg; }

@keyframes lecon-confetti { 0% { opacity: 1; transform: translate(0, 0) rotate(0); } 100% { opacity: 0; transform: translate(var(--x), 420px) rotate(var(--r)); } }
/* Formules : isolées de gauche à droite, même au milieu d'un texte arabe. */
.lecon__maths { direction: ltr; unicode-bidi: isolate; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lecon[dir="rtl"] { font-family: var(--police-arabe, "Noto Sans Arabic", system-ui, sans-serif); }
.lecon[dir="rtl"] .lecon__consigne { letter-spacing: 0; text-transform: none; }
.lecon--active[dir="rtl"] .lecon__etape { animation-name: lecon-entree-rtl; }
@keyframes lecon-entree-rtl { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }

@keyframes lecon-entree { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes lecon-monte { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes lecon-secousse { 0%, 100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.lecon button:focus-visible, .lecon input:focus-visible, .lecon summary:focus-visible { outline: 3px solid var(--l-soleil); outline-offset: 3px; }

@media (max-width: 640px) {
  /* Le thème garde 40 px autour du contenu à toutes les tailles : sur un
     téléphone, la leçon en perdrait le quart de sa largeur. */
  .contenu:has(> .lecon) { padding: 20px 16px; }
  .lecon__pied { margin: 24px -16px -20px; padding: 14px 16px 18px; }
  .lecon__etape--carte { padding: 20px !important; }
  .lecon__figure img { max-height: none; width: 100%; }
  .lecon__action, .lecon__recommencer { width: 100%; }
  .lecon__stats { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .lecon *, .lecon *::before { animation: none !important; transition: none !important; }
}
