/* ==========================================================
   La salle d'entraînement : le style des leçons (Physics-for-kids/lesson.css,
   Mathematics/multiples/lcm.html). Inter pour le texte, Source Serif 4 pour les
   titres, les grands nombres et les équations ; filets fins, couleurs atténuées,
   boutons plats, sans émojis ni décorations. La page ne lie plus maths.css :
   tout son style est ici. maths.js lui donne toujours la langue.
   ========================================================== */
:root {
  --ink: #1a2232; --muted: #5d6779; --line: #dde3ec; --bg: #eef1f5; --paper: #ffffff; --soft: #f5f7fa;
  --accent: #2552a3; --ok: #1f7a55; --bad: #b3362b; --warn: #b4531f;
  --font: "Inter", "Segoe UI", system-ui, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}
[hidden] { display: none !important; }
html[lang="en"] [lang="fr"], html[lang="fr"] [lang="en"] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: clamp(16px, 1.3vw, 17.5px); line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); font-weight: 600; }
b { font-weight: 650; }
button, input, select { font: inherit; color: inherit; }

.app {
  max-width: 1060px; margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) clamp(12px, 3vw, 28px) max(28px, env(safe-area-inset-bottom));
}

/* En-tête : le lien de retour et les réglages, puis le titre. */
.top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 12px; }
.back { color: var(--muted); text-decoration: none; font-size: 15px; font-weight: 500; }
.back:hover, .back:focus-visible { color: var(--ink); text-decoration: underline; }
.tools { display: flex; gap: 8px; align-items: center; margin-left: auto; }
/* Le bandeau du titre : sombre, sur l'illustration de la salle (hero.jpg), comme la première
   diapositive des leçons. Les onglets des matières y sont des pastilles. */
.hero {
  position: relative; isolation: isolate; margin: 14px 0 20px; padding: clamp(22px, 3.4vw, 40px);
  color: #f3f5f9; background: #0a0f1d url(hero.jpg?v=1) no-repeat 100% 50% / cover;
  border: 1px solid #1c2337; border-radius: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 14px 34px -12px rgba(16, 24, 40, .25);
}
.hero::before {
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit;
  background: linear-gradient(90deg, rgba(8, 12, 24, .96) 0%, rgba(8, 12, 24, .9) 42%, rgba(8, 12, 24, .3) 68%, rgba(8, 12, 24, .04) 100%);
}
.kicker { margin: 0 0 10px; font-size: 13px; font-weight: 650; letter-spacing: .12em; text-transform: uppercase; color: #9fb6e6; }
h1 { margin: 0; max-width: 12em; font-family: var(--serif); font-size: clamp(36px, 5.4vw, 60px); line-height: 1.02; font-weight: 600; letter-spacing: -.015em; color: #fff; }
.hero .sub { margin: 12px 0 22px; max-width: 30em; font-family: var(--serif); font-style: italic; font-size: clamp(18px, 2vw, 22px); line-height: 1.35; color: #f0c27a; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; max-width: 640px; }
.tabs:empty { display: none; }
.chip {
  display: inline-flex; align-items: baseline; gap: 8px; padding: 7px 14px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .28); border-radius: 999px; background: rgba(255, 255, 255, .07);
  color: #f3f5f9; font-size: 15px; font-weight: 600; transition: background .12s;
}
.chip:hover { background: rgba(255, 255, 255, .16); }
.chip small { font-size: 12px; font-weight: 500; color: #b9c3d3; }
.chip[aria-pressed="true"] { background: #fff; border-color: #fff; color: var(--ink); }
.chip[aria-pressed="true"] small { color: var(--muted); }
.chip:focus-visible { outline: 2px solid #f0c27a; outline-offset: 2px; }
/* Pendant les exercices et dans Mes progrès, le bandeau se réduit au titre. */
body:is([data-view="practice"], [data-view="progress"]) .hero { padding: 14px 22px; margin-bottom: 14px; }
body:is([data-view="practice"], [data-view="progress"]) .hero :is(.kicker, .sub) { display: none; }
body:is([data-view="practice"], [data-view="progress"]) h1 { max-width: none; font-size: clamp(22px, 2.6vw, 28px); }

/* Boutons plats, filet fin. */
.chunky {
  border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink);
  padding: 6px 14px; font-size: .95em; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: .45em;
  transition: border-color .12s, background .12s; touch-action: manipulation;
}
.chunky:hover:not(:disabled) { border-color: #b8c3d4; background: var(--soft); }
.chunky:disabled { opacity: .45; cursor: default; }
.chunky:focus-visible, .num-input:focus-visible, ul.skills a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chunky.go { background: var(--ink); color: #fff; border-color: var(--ink); }
.chunky.go:hover:not(:disabled) { background: #2a3550; border-color: #2a3550; }
.lang { min-width: 46px; justify-content: center; }
.prof { max-width: 11em; padding: 6px 10px; }
#newProfile { min-width: 38px; justify-content: center; padding: 6px 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.center { justify-content: center; }
.muted { color: var(--muted); }

/* Les cartes blanches. */
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
  padding: clamp(16px, 2.6vw, 28px); margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 12px 28px -16px rgba(16, 24, 40, .14);
}
.card h2 { margin: 0 0 10px; font-family: var(--serif); font-size: clamp(22px, 2.4vw, 28px); line-height: 1.2; font-weight: 600; letter-spacing: -.005em; }
.card h3 { margin: 16px 0 6px; font-size: 1em; font-weight: 650; }
.card p { margin: 6px 0; }

/* Le retour au catalogue, au-dessus d'une question ou de Mes progrès. */
.subjects { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

/* Le catalogue : un thème par carte, ses compétences en liste. */
.topic-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; margin-bottom: 8px; }
.topic-head h2 { margin: 0; display: flex; align-items: baseline; gap: 12px; }
.letter {
  flex: none; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #fff; font: 650 15px/1 var(--font); transform: translateY(-3px);
}
.lesson-link { font-weight: 600; text-decoration: none; white-space: nowrap; }
.lesson-link::after { content: " →"; }
.lesson-link:hover, .lesson-link:focus-visible { text-decoration: underline; }
ul.skills { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); column-gap: 24px; }
ul.skills li { border-bottom: 1px solid var(--line); }
ul.skills a { display: flex; align-items: center; gap: 12px; padding: 8px 8px; border-radius: 6px; color: var(--ink); text-decoration: none; font-weight: 500; }
ul.skills a:hover { background: var(--soft); }
.sk-code { flex: none; min-width: 2.4em; font-size: .85em; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.name { flex: 1; min-width: 0; }
/* Le score d'une compétence : une pastille teintée selon le niveau ; ✓ une fois maîtrisée. */
.badge { flex: none; min-width: 2.7em; padding: 1px 8px; text-align: center; font-size: .82em; font-weight: 650; line-height: 1.6; border-radius: 999px; font-variant-numeric: tabular-nums; }
.badge.none { border: 1px dashed #c7cfdb; min-height: 1.6em; }
.badge.s0 { background: #fbeceb; color: var(--bad); }
.badge.s1 { background: #fbf1e2; color: #8f520f; }
.badge.s2 { background: #e4f1ea; color: var(--ok); }
.badge.done { background: var(--ok); color: #fff; }
.pbar { flex: 0 0 90px; height: 6px; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); overflow: hidden; }
.pbar span { display: block; height: 100%; background: var(--accent); }

/* S'exercer : la question à gauche, le score à droite. */
.practice { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 0 18px; align-items: start; }
.skill-head { margin: 0 0 14px !important; font-size: 13px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: var(--accent); }
.skill-head .sk-code { min-width: 0; font-size: inherit; color: inherit; }
.skill-head .sk-code::after { content: " ·"; }
.prompt { font-size: 1.3em; font-weight: 500; line-height: 1.5; }
.prompt b { font-weight: 700; }
.prompt .hint { margin: 8px 0 0 !important; font-size: .72em; font-weight: 400; color: var(--muted); }
.eq { display: inline-flex; align-items: center; flex-wrap: wrap; gap: .25em; font-family: var(--serif); font-size: clamp(30px, 5.5vw, 42px); font-weight: 600; font-variant-numeric: tabular-nums; }
.blank { display: inline-grid; place-items: center; min-width: 1.4em; height: 1.2em; padding: 0 .15em; font-family: var(--font); font-size: .85em; color: var(--bad); border: 2px dashed var(--bad); border-radius: 8px; }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1.12; }
.frac > span { padding: 0 .15em; }
.frac > span:first-child { border-bottom: 2px solid currentColor; }
.frac .blank { height: 1.1em; margin: 2px 0; }
.visual { margin: 16px 0 4px; text-align: center; overflow-x: auto; }
.visual .vis { max-width: 100%; height: auto; }
pre.code { display: inline-block; margin: 0; padding: 12px 18px; max-width: 100%; overflow-x: auto; text-align: left; background: var(--ink); color: #e8edf5; border-radius: 10px; font: 16px/1.5 var(--mono); }
pre.code code { font: inherit; }

#ansForm { margin-top: 18px; }
.num-input {
  width: 4.2em; height: 1.9em; text-align: center;
  font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums;
  background: #fff; border: 1px solid #b8c3d4; border-radius: 8px;
  -moz-appearance: textfield; appearance: textfield;
}
.num-input:focus { border-color: var(--accent); }
.num-input::-webkit-outer-spin-button, .num-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num-input:disabled { background: var(--soft); }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; }
.choice { justify-content: flex-start; text-align: left; font-size: 1.05em; font-weight: 500; padding: 9px 14px; }
.choice kbd { flex: none; display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; font: 600 12px var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 5px; }
.choice.picked { background: #eef3fb; border-color: var(--accent); }
.unit { font-size: 22px; font-weight: 600; }
.pair-in label { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.pair-in .num-input { font-size: 24px; width: 4em; }
.frac-in { display: flex; flex-direction: column; align-items: center; gap: 6px; width: max-content; margin: 0 auto 12px; }
.frac-in .fr-bar { width: 100%; min-width: 5em; border-top: 2px solid var(--ink); }
.frac-in .num-input { font-size: 24px; width: 3.6em; }

/* Après une réponse. */
.flash { margin: 14px 0 0 !important; text-align: center; font-weight: 650; font-size: 1.15em; }
.flash.good { color: var(--ok); }
.flash.info { color: var(--muted); font-size: 1em; font-weight: 500; }
.good { color: var(--ok); }
.bad { color: var(--bad); }
.hl { padding: 0 .35em; border-radius: 5px; background: #fbf1d6; font-weight: 650; white-space: nowrap; }
.wrongbox { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.big-msg { margin: 0 0 4px !important; font-family: var(--serif); font-size: 1.5em; font-weight: 600; line-height: 1.2; }
.wrongbox h3 { margin: 16px 0 6px; font-size: 13px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.explain { padding: 12px 16px; background: var(--soft); border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; }
.explain ol { margin: 4px 0; padding-left: 1.2em; }
.explain p { margin: 6px 0; }
.wrongbox .row { margin-top: 16px; gap: 16px; }
.mastered { margin-top: 10px; text-align: center; }
.mastered .big-msg { font-size: 2em; color: var(--ok); }
.mastered .row { margin-top: 16px; }

/* Le score, à droite de la question. */
.side { position: sticky; top: 12px; padding: 14px 18px; }
.stat { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.stat span { font-size: .92em; font-weight: 500; color: var(--muted); }
.stat b { font-size: 1.45em; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat.score { flex-wrap: wrap; border-bottom: 0; }
.stat.score b { font-family: var(--serif); font-size: 2.6em; line-height: 1; }
.meter { position: relative; flex-basis: 100%; height: 8px; margin-top: 10px; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.meter i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: .35; }
.zone { display: block; flex-basis: 100%; margin-top: 6px; font-size: .88em; font-weight: 600; color: var(--muted); }
.zone.z_challenge { color: var(--warn); }
.zone.z_master { color: var(--ok); }
.side .lesson-link { display: inline-block; margin-top: 12px; }
.sync-side { display: block; margin-top: 8px; font-size: .85em; color: var(--muted); }

/* Mes progrès. */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { padding: 12px 14px; text-align: center; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; }
.tile b { display: block; font-family: var(--serif); font-size: 2em; font-weight: 600; line-height: 1.15; }
.tile span { font-size: .88em; font-weight: 500; color: var(--muted); }

/* Le suivi sur plusieurs appareils. */
.sync-code { margin: 10px 0 !important; padding: 8px 12px; text-align: center; font: 600 clamp(22px, 5vw, 32px) var(--mono); letter-spacing: .08em; background: var(--soft); border: 1px dashed #b8c3d4; border-radius: 10px; user-select: all; }
.sync-have { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.sync-have label { font-weight: 600; }
.code-input { width: 12em; height: auto; padding: 6px 10px; font: 600 18px var(--mono); text-transform: uppercase; letter-spacing: .05em; }

footer { margin-top: 28px; font-size: 14px; color: var(--muted); }
footer p { margin: 0; }

@media (max-width: 760px) {
  .practice { grid-template-columns: 1fr; }
  /* Sur un téléphone, le score tient sur une bande au-dessus de la question. */
  .side { order: -1; position: static; display: grid; grid-template-columns: auto auto 1fr; gap: 0 16px; align-items: start; padding: 10px 14px; margin-bottom: 12px; }
  .side .stat { display: block; padding: 0; border: 0; }
  .side .stat span { display: block; font-size: 12px; }
  .side .stat b, .side .stat.score b { font-size: 22px; }
  .side .meter { height: 6px; margin-top: 4px; }
  .side .zone { font-size: 12px; margin-top: 2px; }
  .side .lesson-link { display: none !important; }
  .prompt { font-size: 1.18em; }
}
@media (max-width: 760px) {
  /* Sur un téléphone, l'illustration en haut du bandeau, le texte dessous. */
  .hero { background-size: 200% auto; background-position: 100% 0; padding-top: 40vw; }
  .hero::before { background: linear-gradient(180deg, rgba(8, 12, 24, .05) 0%, rgba(8, 12, 24, .85) 38vw, rgba(8, 12, 24, .97) 100%); }
  body:is([data-view="practice"], [data-view="progress"]) .hero { background-size: cover; background-position: 100% 50%; padding: 12px 16px; }
  body:is([data-view="practice"], [data-view="progress"]) .hero::before { background: linear-gradient(90deg, rgba(8, 12, 24, .96) 0%, rgba(8, 12, 24, .88) 55%, rgba(8, 12, 24, .2) 100%); }
}
@media (max-width: 520px) {
  /* Les matières sur deux colonnes, le compte sous le nom. */
  .tabs { display: grid; grid-template-columns: 1fr 1fr; }
  .chip { flex-direction: column; align-items: flex-start; gap: 0; border-radius: 12px; padding: 6px 12px; }
}
@media (prefers-reduced-motion: reduce) { .chunky, .chip { transition: none; } .meter span { transition: none; } }
