:root {
  --bg1: #f3f8ff;
  --bg2: #dde9fb;
  --ink: #2a2150;
  --muted: #6d6690;
  --card: #ffffff;
  --coral: #ff6b4a;
  --purple: #8b5cf6;
  --teal: #14b8a6;
  --pink: #ff5fa2;
  --sun: #ffc233;
  --ok: #16a34a;
  --ko: #e11d48;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(42, 33, 80, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'Quicksand', system-ui, sans-serif;
  font-weight: 500;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2)) fixed;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
h1, h2, strong, .btn, .chip { font-family: 'Baloo 2', 'Quicksand', sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }

.screen { max-width: 760px; margin: 0 auto; padding: 20px 16px 40px; }
.lead { text-align: center; color: var(--muted); font-size: 1.15rem; font-weight: 700; margin: 6px 0 16px; }

.logo { text-align: center; font-size: 2.6rem; font-weight: 800; margin: 8px 0 0; color: var(--coral); }
.logo span { color: var(--purple); }

/* Boutons */
.btn {
  border: 0; border-radius: 16px; padding: 12px 22px; font-weight: 800; font-size: 1.1rem;
  background: var(--coral); color: #fff; box-shadow: 0 5px 0 #d94a2c; transition: transform .08s, box-shadow .08s;
}
.btn.big { width: 100%; font-size: 1.3rem; padding: 14px; }
.btn.alt { background: var(--purple); box-shadow: 0 5px 0 #6d3fd6; }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #d94a2c; }
.link { background: none; border: 0; color: var(--muted); font-weight: 700; padding: 8px; text-decoration: underline; }

.chip {
  border: 3px solid transparent; background: #fff; border-radius: 999px; padding: 6px 16px; font-size: 1.15rem; font-weight: 800;
  box-shadow: var(--shadow); min-width: 52px;
}
.chip.on { background: var(--sun); border-color: var(--ink); }
.pick { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }

/* Profils */
.profiles { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin-bottom: 20px; }
.profile-wrap { display: flex; flex-direction: column; align-items: center; }
.profile {
  display: flex; flex-direction: column; align-items: center; gap: 2px; width: 150px; padding: 14px;
  border: 0; border-radius: var(--radius); background: #fff; box-shadow: var(--shadow);
}
.profile:active { transform: translateY(3px); }
.profile strong { font-size: 1.3rem; }
.profile small { color: var(--muted); font-weight: 700; }
.avatar { font-size: 3rem; line-height: 1.1; }
.avatar.sm { font-size: 1.8rem; }
.del { font-size: .8rem; }
.new h2 { margin: 0 0 8px; text-align: center; }
.new label { display: block; font-weight: 700; }
.new input {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 1.2rem; padding: 10px 14px;
  border-radius: 14px; border: 3px solid #e4defa; color: var(--ink);
}
.new input:focus { outline: none; border-color: var(--purple); }
.new .btn { margin-top: 10px; }

/* Accueil */
.top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.who { display: flex; align-items: center; gap: 8px; background: #fff; border: 0; border-radius: 999px; padding: 6px 16px 6px 8px; box-shadow: var(--shadow); font-weight: 800; font-size: 1.15rem; }
.total { background: var(--sun); border-radius: 999px; padding: 8px 16px; font-weight: 800; font-size: 1.2rem; box-shadow: var(--shadow); }
.levels { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-top: 14px; }
.cat {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 18px 12px; border: 0;
  border-radius: var(--radius); color: #fff; text-align: center; transition: transform .1s;
}
.cat:active { transform: translateY(4px); }
.cat .icon { font-size: 2.6rem; }
.cat strong { font-size: 1.35rem; }
.cat small { opacity: .95; font-weight: 700; }
.cat .stars { font-size: 1.5rem; letter-spacing: 3px; margin-top: 4px; color: #fff7c2; text-shadow: 0 2px 0 rgba(0,0,0,.15); }
.coral { background: var(--coral); box-shadow: 0 6px 0 #d94a2c; }
.purple { background: var(--purple); box-shadow: 0 6px 0 #6d3fd6; }
.teal { background: var(--teal); box-shadow: 0 6px 0 #0d8f82; }
.pink { background: var(--pink); box-shadow: 0 6px 0 #d63d85; }
.sun { background: #f5a800; box-shadow: 0 6px 0 #c28400; }
.blue { background: #3b82f6; box-shadow: 0 6px 0 #2563c4; }
.green { background: #5aa51f; box-shadow: 0 6px 0 #3f7a12; }
.indigo { background: #4f46e5; box-shadow: 0 6px 0 #3a33b8; }

/* Exercice */
.count { font-weight: 800; font-size: 1.2rem; background: #fff; padding: 6px 14px; border-radius: 999px; box-shadow: var(--shadow); }
.progress { height: 14px; background: #fff; border-radius: 99px; margin: 14px 0; overflow: hidden; box-shadow: inset 0 2px 0 rgba(0,0,0,.08); }
.progress i { display: block; height: 100%; background: var(--teal); border-radius: 99px; transition: width .3s; }
.q { border-top: 10px solid var(--coral); }
.q.purple { border-top-color: var(--purple); }
.q.teal { border-top-color: var(--teal); }
.q.pink { border-top-color: var(--pink); }
.q.sun { border-top-color: var(--sun); }
.q.coral { border-top-color: var(--coral); }
.q.blue { border-top-color: #3b82f6; }
.q.green { border-top-color: #5aa51f; }
.q.indigo { border-top-color: #4f46e5; }
.q { background: #fff; }
.prompt { margin: 0 0 8px; text-align: center; font-weight: 700; font-size: 1.2rem; }
.visual { display: flex; justify-content: center; margin: 14px 0; }
.expr { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 2.6rem; text-align: center; }
.story { font-size: 1.3rem; line-height: 1.5; margin: 0; font-weight: 700; }

.posed { font-family: 'Courier New', ui-monospace, monospace; font-weight: 700; font-size: 2.2rem; display: inline-block; text-align: right; min-width: 180px; }
.posed .l { white-space: pre; line-height: 1.3; position: relative; padding-left: 1.4em; }
.posed .sym { position: absolute; left: 0; color: var(--coral); }
.posed .bar { border-top: 4px solid var(--ink); margin-top: 6px; }

.divi { display: inline-grid; grid-template-columns: auto auto; font-family: 'Courier New', ui-monospace, monospace; font-weight: 700; font-size: 2.2rem; }
.divi .dividend { padding: 4px 16px 4px 4px; border-right: 4px solid var(--ink); }
.divi .divisor { padding: 4px 4px 4px 16px; border-bottom: 4px solid var(--ink); align-self: start; }

.numline { width: 100%; max-width: 640px; color: var(--ink); }
.numline .tl { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 22px; fill: currentColor; }
.numline .arrow line { stroke: var(--coral); }
.numline .arrow polygon { fill: var(--coral); }

.fields { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin-bottom: 14px; }
.field { font-weight: 800; text-align: center; font-family: 'Baloo 2', sans-serif; }
.field .row { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 4px; }
.field em { font-style: normal; font-size: 1.6rem; font-weight: 800; }
.field input {
  width: 9.5em; max-width: 100%; font: inherit; font-size: 1.8rem; font-weight: 800; text-align: center; padding: 10px;
  border-radius: 16px; border: 4px solid #d9d2f3; color: var(--ink); background: #fbfaff;
}
.field input:focus { outline: none; border-color: var(--purple); background: #fff; }
.field input.ok { border-color: var(--ok); background: #e8f9ee; }
.field input.ko { border-color: var(--ko); background: #ffe9ee; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

#feedback { margin-top: 14px; text-align: center; font-size: 1.15rem; }
#feedback.good strong { color: var(--ok); font-size: 1.6rem; }
#feedback.bad strong { color: var(--ko); font-size: 1.4rem; }
#feedback p { margin: 4px 0 0; background: #fff6d6; border-radius: 14px; padding: 10px 14px; font-weight: 700; }

/* Résultat */
.result .card { text-align: center; margin-top: 40px; }
.trophy { font-size: 5rem; }
.result h2 { font-size: 3rem; margin: 0; }
.big-stars { font-size: 3rem; letter-spacing: 6px; color: #f5a800; }
.new-best { color: var(--purple); font-weight: 800; font-size: 1.3rem; }
.actions { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 10; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }

/* En-têtes et écran de niveaux */
.grade { display: flex; align-items: center; gap: 6px; font-weight: 800; color: var(--muted); }
.grade select { font: inherit; font-weight: 800; padding: 6px 10px; border-radius: 12px; border: 3px solid #e4defa; background: #fff; color: var(--ink); }
.hint-line { margin: 10px 0 0; font-weight: 700; color: var(--muted); }
.form-error { min-height: 1.4em; margin: 8px 0 0; color: var(--ko); font-weight: 800; text-align: center; }
.title { text-align: center; font-size: 2rem; margin: 6px 0 0; }
.catpill { display: block; width: max-content; max-width: 100%; margin: 12px auto 6px; padding: 8px 20px; border-radius: 999px; color: #fff; font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.15rem; }
.levels { display: flex; flex-direction: column; gap: 12px; }
.lvl {
  display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: 'name desc stars' 'name meta stars';
  align-items: center; column-gap: 14px; row-gap: 4px; text-align: left; border: 0; border-radius: var(--radius);
  padding: 14px 18px; color: #fff; transition: transform .1s;
}
.lvl:active { transform: translateY(4px); }
.lv-name { grid-area: name; font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.6rem; min-width: 64px; text-align: center; background: rgba(255,255,255,.22); border-radius: 14px; padding: 4px 10px; }
.lv-desc { grid-area: desc; font-weight: 800; font-size: 1.1rem; }
.lv-meta { grid-area: meta; display: flex; flex-wrap: wrap; gap: 6px; }
.lv-stars { grid-area: stars; font-size: 1.5rem; letter-spacing: 2px; color: #fff7c2; text-shadow: 0 2px 0 rgba(0,0,0,.15); }
.badge { background: rgba(0,0,0,.25); border-radius: 999px; padding: 2px 10px; font-size: .85rem; font-weight: 800; }
.badge.me { background: #fff; color: var(--ink); }
.lv0 { background: #14b8a6; box-shadow: 0 6px 0 #0d8f82; }
.lv1 { background: #3b82f6; box-shadow: 0 6px 0 #2563c4; }
.lv2 { background: #8b5cf6; box-shadow: 0 6px 0 #6d3fd6; }
.lv3 { background: #f5a800; box-shadow: 0 6px 0 #c28400; }
.lv4 { background: #ff5fa2; box-shadow: 0 6px 0 #d63d85; }
.lvl.custom { background: #fff; color: var(--ink); border: 3px dashed var(--purple); box-shadow: none; }
.lvl.custom .lv-name { background: #efe9ff; }
.lvl.custom .badge { background: #efe9ff; color: var(--ink); }
.qtop { flex-wrap: wrap; }
.level-tag { background: var(--sun); border-radius: 999px; padding: 6px 14px; font-weight: 800; font-family: 'Baloo 2', sans-serif; box-shadow: var(--shadow); }
.pts { font-weight: 800; font-size: 1.3rem; color: #c28400; margin: 0; }

/* Calcul posé guidé */
.gtools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 10px; }
.chipbtn { border: 0; background: #f1edff; color: var(--ink); border-radius: 999px; padding: 8px 14px; font-weight: 800; font-size: .95rem; }
.chipbtn:active { transform: translateY(2px); }
.gsteps { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }
.gsteps span { padding: 4px 14px; border-radius: 999px; background: #f1edff; color: var(--muted); font-weight: 800; font-size: .95rem; }
.gsteps span.on { background: var(--purple); color: #fff; }
.gridwrap { display: flex; justify-content: center; margin: 6px 0 12px; }
.ggrid { --cs: clamp(34px, 10vw, 58px); display: inline-flex; flex-direction: column; font-family: 'Baloo 2', sans-serif; font-weight: 800; color: var(--ink); padding: 6px; border-radius: 16px; background: #faf8ff; }
.grow { display: flex; }
.gc { position: relative; width: var(--cs); height: var(--cs); display: flex; align-items: center; justify-content: center; font-size: calc(var(--cs) * 0.66); border-radius: 8px; }
.gc.op { color: var(--coral); }
.gc.comma { width: calc(var(--cs) * 0.32); align-items: flex-end; padding-bottom: calc(var(--cs) * 0.08); }
.gc.act { background: #fff0cc; }
.gc.carry { height: calc(var(--cs) * 0.62); font-size: calc(var(--cs) * 0.42); color: var(--coral); }
.gc.res { color: var(--purple); }
.gc.target { outline: 3px dashed var(--coral); outline-offset: -3px; background: #fff; }
.gc sup { position: absolute; top: 2px; left: 4px; font-size: calc(var(--cs) * 0.34); color: var(--coral); line-height: 1; }
.grow.last .gc:not(.op) { border-bottom: 4px solid var(--ink); border-radius: 0; }
.grow.last .gc.act { border-radius: 8px 8px 0 0; }
.gmsg { background: #f1edff; border-radius: 16px; padding: 12px 16px; font-weight: 700; font-size: 1.08rem; line-height: 1.45; margin-bottom: 12px; }
.gmsg.bad { background: #ffe9ee; }
.gmsg.good { background: #e8f9ee; }
.ghint { margin-top: 8px; background: #fff6d6; border-radius: 12px; padding: 8px 12px; }
.keypad { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.keypad button { border: 3px solid #cfc4f7; background: #fff; border-radius: 14px; padding: 10px 0; font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.5rem; color: var(--purple); box-shadow: 0 3px 0 #cfc4f7; }
.keypad button:active { transform: translateY(3px); box-shadow: none; }
.keypad button:disabled, .hintbtn:disabled { opacity: .4; }
.gactions { display: flex; gap: 10px; }
.gactions .btn.big { flex: 1; background: #16a34a; box-shadow: 0 5px 0 #0f7a36; }
.gactions .btn.big.next { background: var(--coral); box-shadow: 0 5px 0 #d94a2c; }
.hintbtn { border: 0; border-radius: 16px; padding: 0 18px; background: #fff0cc; color: #8a5a00; font-weight: 800; font-size: 1.05rem; box-shadow: 0 5px 0 #e8c76a; }
.method { margin-top: 16px; background: #f1edff; border-radius: 16px; padding: 12px 18px; }
.method h3 { margin: 0 0 6px; font-family: 'Baloo 2', sans-serif; color: var(--purple); }
.method ol { margin: 0; padding-left: 22px; line-height: 1.5; font-weight: 600; }

@media (min-width: 700px) {
  .posed { font-size: 2.8rem; }
  .divi { font-size: 2.8rem; }
  .expr { font-size: 3.4rem; }
  .story { font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Multiplication en saisie libre */
.ggrid.free .gc.edit { background: #fff; box-shadow: inset 0 0 0 1.5px #e7e1fb; cursor: pointer; }
.ggrid.free .gc.edit.carry { box-shadow: inset 0 0 0 1.5px #ffd9cf; background: #fff8f5; }
.ggrid.free .gc.edit.sel { outline: 3px dashed var(--coral); outline-offset: -3px; background: #fff7e6; }
.ggrid.free .gc.rowok { background: #e8f9ee; box-shadow: inset 0 0 0 1.5px #86d6a2; }
.ggrid.free .gc.rowko { background: #ffe9ee; box-shadow: inset 0 0 0 1.5px #f3a3b5; }
.ggrid.free .gc.edit:not(.carry) { color: var(--purple); }
.mark { width: calc(var(--cs) * 0.7); display: flex; align-items: center; justify-content: center; font-size: calc(var(--cs) * 0.5); font-weight: 800; }
.mark.ok { color: var(--ok); }
.mark.ko { color: var(--ko); }

.modebar { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 14px; font-weight: 800; color: var(--muted); }
.modebar .chip { font-size: 1rem; padding: 4px 14px; }

/* Mode immédiat : retenue qui monte */
.gridwrap { position: relative; }
.flyer {
  position: absolute; z-index: 5; pointer-events: none; display: flex; align-items: center; justify-content: center;
  font-family: 'Baloo 2', sans-serif; font-weight: 800; color: var(--coral); text-shadow: 0 3px 8px rgba(255, 107, 74, .35);
  transition: transform .8s cubic-bezier(.3, .7, .25, 1); will-change: transform;
}
.gc.pop { animation: pop .5s ease-out; }
@keyframes pop { 0% { transform: scale(.3); background: #ffd9cf; } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }
.gc.typed { color: var(--purple); }
.gc.res.rowko { color: var(--ko); background: #ffe9ee; }
.tip { margin-top: 6px; font-weight: 600; font-size: .95rem; color: var(--muted); }
.gactions #gok[hidden] { display: none; }
.gc.two { font-size: calc(var(--cs) * 0.46); letter-spacing: -1px; }

/* Clavier : 10 chiffres + effacer sur une seule ligne (2 lignes seulement sur très petit écran) */
.keypad button { padding: 10px 0; font-size: 1.4rem; min-width: 0; }
@media (max-width: 559px) {
  .keypad { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
}

/* Réussite */
.keypad[hidden], .hintbtn[hidden] { display: none; }
.gc.win, .field input.win { animation: win .75s cubic-bezier(.3, .7, .3, 1) both; color: var(--ok) !important; background: #e8f9ee !important; }
@keyframes win {
  0% { transform: translateY(0) scale(1); box-shadow: 0 0 0 0 rgba(22, 163, 74, .6); }
  35% { transform: translateY(-20px) scale(1.4); box-shadow: 0 0 0 12px rgba(22, 163, 74, 0); }
  65% { transform: translateY(0) scale(.94); }
  100% { transform: translateY(0) scale(1); box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}
.ring { position: fixed; z-index: 19; width: 44px; height: 44px; border-radius: 50%; border: 5px solid #34d399; pointer-events: none; }
.confetto { position: fixed; z-index: 20; pointer-events: none; will-change: transform, opacity; }
.gmsg.good { animation: msgpop .6s cubic-bezier(.3, 1.5, .5, 1); }
.gmsg.good::before {
  content: '\2713'; display: inline-grid; place-items: center; vertical-align: middle; margin-right: 10px; width: 1.9em; height: 1.9em; border-radius: 50%;
  background: var(--ok); color: #fff; font-weight: 800; animation: pop .6s ease-out .2s both;
}
@keyframes msgpop { 0% { transform: translateY(14px) scale(.92); opacity: 0; } 100% { transform: translateY(0) scale(1); opacity: 1; } }
.btn.next.attn { animation: attn 1.1s ease-in-out 1.2s 3; }
@keyframes attn { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.035); } }
@media (prefers-reduced-motion: reduce) { .btn.next.attn, .gmsg.good::before { animation: none !important; } }

/* Points gagnés */
.pts-badge { display: inline-block; margin-left: 6px; padding: 2px 14px; border-radius: 999px; background: #ffe9a6; color: #7a4d00; font-weight: 800; animation: pop .6s ease-out .3s both; white-space: nowrap; }
.pts-float { position: fixed; z-index: 21; pointer-events: none; font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 2.6rem; color: #f59e0b; text-shadow: 0 3px 0 rgba(122, 77, 0, .25), 0 0 18px rgba(255, 255, 255, .9); }
.count.bump, .total.bump { animation: bump .6s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); background: #ffe9a6; } 100% { transform: scale(1); } }
.lv-stars.pts { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.2rem; letter-spacing: 0; color: #fff; }
.chipbtn:disabled { opacity: .4; }

/* Écran de niveaux : une ligne centrée par niveau */
.lvl { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px; text-align: center; }
.lv-name { min-width: 0; background: none; padding: 0; font-size: 1.5rem; }
.lv-desc { background: rgba(0, 0, 0, .22); border-radius: 999px; padding: 3px 14px; font-size: .95rem; }
.lvl .badge.pts { background: #1b1740; color: #ffd24d; padding: 3px 12px; }
.lvl .badge.me { background: #fff; color: var(--ink); }
.lvl .lv-stars { margin-left: 4px; }
.lv-bars { display: inline-flex; align-items: flex-end; gap: 3px; height: 24px; }
.lv-bars i { display: block; width: 6px; border-radius: 2px; background: #fff; opacity: .35; }
.lv-bars i:nth-child(1) { height: 7px; } .lv-bars i:nth-child(2) { height: 11px; } .lv-bars i:nth-child(3) { height: 15px; }
.lv-bars i:nth-child(4) { height: 20px; } .lv-bars i:nth-child(5) { height: 24px; }
.lv-bars i.on { opacity: 1; }
.lv-bars.pen { font-size: 1.3rem; height: auto; }
.lvl.custom .lv-desc { background: #efe9ff; }
.lvl.custom .badge.pts { background: #1b1740; color: #ffd24d; }

.lvl { position: relative; }
.lvl .badge.me { position: absolute; top: -9px; left: 18px; font-size: .75rem; padding: 1px 12px; box-shadow: 0 2px 0 rgba(0, 0, 0, .15); }
.lv-stars.pts { font-size: 1rem; background: rgba(255, 255, 255, .25); border-radius: 999px; padding: 2px 12px; }
.lvl .badge.pts { font-size: .9rem; }
.lvl.custom .lv-name { background: none; }

/* Écran de niveaux : contenus alignés en colonnes (barres | nom | description | points | étoiles) */
.lvl { display: grid; grid-template-columns: 44px 130px 1fr auto auto; align-items: center; column-gap: 14px; justify-items: start; text-align: left; padding: 14px 20px; }
.lv-bars { justify-self: center; }
.lv-bars.pen { width: 44px; text-align: center; }
.lv-name { justify-self: start; }
.lv-desc { justify-self: start; }
.lvl .badge.pts { justify-self: end; }
.lv-stars { justify-self: end; margin-left: 0 !important; white-space: nowrap; }
@media (max-width: 640px) {
  .lvl { grid-template-columns: 44px 1fr auto; row-gap: 6px; }
  .lv-bars { grid-column: 1; grid-row: 1 / span 2; }
  .lv-name { grid-column: 2; grid-row: 1; }
  .lvl .badge.pts { grid-column: 3; grid-row: 1; }
  .lv-desc { grid-column: 2 / -1; grid-row: 2; }
  .lv-stars { grid-column: 2 / -1; grid-row: 3; justify-self: start; }
}
/* Neutralise les anciennes zones de grille (première version de l'écran de niveaux) */
.lvl { grid-template-areas: none; }
.lvl .lv-bars, .lvl .lv-name, .lvl .lv-desc, .lvl .lv-meta, .lvl .lv-stars, .lvl .badge { grid-area: auto; }
.lvl .lv-name { min-width: 0; white-space: nowrap; }
.lvl .lv-desc { white-space: normal; }
/* Petit écran (téléphone) : nom + points sur la 1re ligne, description dessous */
@media (max-width: 640px) {
  .lvl { grid-template-columns: 44px 1fr auto; row-gap: 6px; }
  .lvl .lv-bars { grid-column: 1; grid-row: 1 / span 2; }
  .lvl .lv-name { grid-column: 2; grid-row: 1; }
  .lvl .badge.pts { grid-column: 3; grid-row: 1; }
  .lvl .lv-desc { grid-column: 2 / -1; grid-row: 2; }
  .lvl .lv-stars { grid-column: 2 / -1; grid-row: 3; justify-self: start; }
}
@media (max-width: 640px) {
  .lvl { grid-template-columns: 44px 1fr auto; row-gap: 6px; }
  .lvl .lv-bars { grid-column: 1; grid-row: 1 / span 3; }
  .lvl .lv-name { grid-column: 2 / -1; grid-row: 1; }
  .lvl .lv-desc { grid-column: 2 / -1; grid-row: 2; }
  .lvl .badge.pts { grid-column: 2; grid-row: 3; justify-self: start; }
  .lvl .lv-stars { grid-column: 3; grid-row: 3; justify-self: end; }
}
.lvl .badge.pts { white-space: nowrap; }
/* Icône de difficulté (3 barres) : boîte = hauteur de la plus grande barre, centrée sur la ligne du nom */
.lvl .lv-bars { height: 16px; align-self: center; align-items: flex-end; }
.lv-bars i:nth-child(1) { height: 6px; } .lv-bars i:nth-child(2) { height: 11px; } .lv-bars i:nth-child(3) { height: 16px; }
.lv-bars.pen { height: auto; }
@media (max-width: 640px) {
  .lvl .lv-bars { grid-row: 1; }
}
/* Téléphone : points en haut à droite (même ligne que le nom), description dessous, étoiles en bas */
@media (max-width: 640px) {
  .lvl { grid-template-columns: 44px 1fr auto; row-gap: 6px; }
  .lvl .lv-bars { grid-column: 1; grid-row: 1; }
  .lvl .lv-name { grid-column: 2; grid-row: 1; }
  .lvl .badge.pts { grid-column: 3; grid-row: 1; justify-self: end; }
  .lvl .lv-desc { grid-column: 2 / -1; grid-row: 2; }
  .lvl .lv-stars { grid-column: 2 / -1; grid-row: 3; justify-self: start; }
  .badge .per { display: none; }
}
@media (max-width: 640px) {
  .modebar { flex-wrap: wrap; row-gap: 6px; }
  .modebar span { flex-basis: 100%; text-align: center; }
  .modebar .chip { white-space: nowrap; font-size: .95rem; padding: 4px 12px; min-width: 0; }
}

/* Bandeau du haut : navigation + nom + points, séparé du corps de page */
.appbar { position: sticky; top: 0; z-index: 30; background: rgba(255, 255, 255, .94); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-bottom: 3px solid #ece6fb; box-shadow: 0 6px 16px rgba(42, 33, 80, .08); }
.appbar-in { max-width: 760px; margin: 0 auto; padding: 8px 16px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; min-height: 56px; }
.ab-l { justify-self: start; display: flex; align-items: center; }
.ab-c { justify-self: center; }
.ab-r { justify-self: end; display: flex; align-items: center; gap: 8px; }
.appbar .link { padding: 6px 4px; }
.appbar .who { box-shadow: none; background: #f4f0ff; padding: 3px 14px 3px 6px; font-size: 1rem; }
.appbar .who.static { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; font-weight: 800; }
.appbar .who .avatar.sm { font-size: 1.5rem; }
.appbar .total, .appbar .count, .appbar .level-tag { box-shadow: none; font-size: 1rem; padding: 6px 14px; }
.brand { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.3rem; color: var(--coral); }
.brand b { color: var(--purple); }
.screen { padding-top: 18px; }
@media (max-width: 480px) {
  .who-name { display: none; }
  .appbar .who { padding: 3px 8px 3px 6px; }
  .appbar-in { padding: 6px 10px; gap: 6px; }
}

/* Choix du type de saisie, dans la page de l'exercice */
.seg { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; margin-bottom: 8px; font-weight: 800; color: var(--muted); }
.chipbtn.on { background: var(--purple); color: #fff; }
.seg .chipbtn { white-space: nowrap; }
@media (max-width: 480px) {
  .seg span { display: none; }
  .seg, .gtools { gap: 6px; margin-bottom: 6px; }
  .chipbtn { font-size: .85rem; padding: 6px 10px; }
}

/* Choix du type de saisie : en bas de page, sous « La méthode » */
.seg.bottom { margin: 14px 0 0; padding-top: 12px; border-top: 2px dashed #e4defa; }
@media (max-width: 480px) { .seg.bottom span { display: inline; } }

/* Carte qui englobe le contenu des écrans d'accueil et de choix du niveau (comme dans un exercice) */
.card.page { padding: 18px 20px 22px; }
.card.page > .lead:first-child { margin-top: 2px; }
.card.page .catpill { margin-top: 2px; }
@media (max-width: 480px) { .card.page { padding: 14px 12px 18px; } }
@media (max-width: 480px) {
  .lvl { padding: 12px 12px; column-gap: 8px; grid-template-columns: 34px 1fr auto; }
  .lv-bars.pen { width: 34px; }
  .lvl .lv-name { font-size: 1.35rem; }
}

/* Ligne d'outils dans la carte : niveau à gauche, petits boutons à droite */
.ctools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.ctools .level-tag { box-shadow: none; padding: 4px 14px; font-size: .95rem; }
.ctools .gtools { margin: 0; justify-content: flex-end; flex: 1; gap: 6px; }
.gtools .chipbtn { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; padding: 4px 10px; }
.chipbtn .lv-bars { height: 11px; gap: 2px; }
.chipbtn .lv-bars i { width: 3.5px; background: currentColor; opacity: 1; border-radius: 1px; }
.chipbtn .lv-bars i:nth-child(1) { height: 4px; } .chipbtn .lv-bars i:nth-child(2) { height: 8px; } .chipbtn .lv-bars i:nth-child(3) { height: 11px; }
@media (max-width: 480px) {
  .gtools .chipbtn { font-size: .72rem; padding: 4px 8px; }
  .ctools .level-tag { font-size: .85rem; padding: 3px 12px; }
}

@media (max-width: 480px) {
  .ctools .gtools { flex: 1 1 100%; flex-wrap: nowrap; }
  .gtools .chipbtn .long { display: none; }
  .gtools .chipbtn { white-space: nowrap; }
  .ctools { margin-bottom: 8px; row-gap: 6px; }
}

/* Boutons à gauche, niveau à droite */
.ctools .gtools { justify-content: flex-start; flex: 0 1 auto; }
.ctools .level-tag { margin-left: auto; }

/* Grille quadrillée derrière le calcul (papier à carreaux) */
.ggrid { padding: 0; background: #fff; border: 1.5px solid #d6cdf0; border-radius: 12px; overflow: hidden; }
.ggrid .gc, .ggrid .mark { border-right: 1px solid #e4def6; border-bottom: 1px solid #e4def6; border-radius: 0; }
.ggrid .grow > :last-child { border-right: 0; }
.ggrid .grow:last-child > * { border-bottom: 0; }
.ggrid .grow.last .gc:not(.op) { border-bottom: 4px solid var(--ink); }
.ggrid .grow.last .gc.act { border-radius: 0; }
.ggrid.free .gc.edit { box-shadow: none; }
.ggrid.free .gc.edit.carry { background: #fff8f5; }
.ggrid .gc.act { background: #fff0cc; }
.ggrid .gc.op { background: #faf8ff; }

/* Plus d'espace entre la ligne de boutons et le calcul */
.ctools { margin-bottom: 26px; }
@media (max-width: 480px) { .ctools { margin-bottom: 18px; } }

/* Ligne de retenue : fine, de hauteur uniforme (toutes ses cases), intégrée à la grille */
.ggrid .grow.crow .gc, .ggrid .grow.crow .mark { height: calc(var(--cs) * 0.5); min-height: 0; }
.ggrid .grow.crow .gc.carry { font-size: calc(var(--cs) * 0.34); background: #fff4ef; color: var(--coral); line-height: 1; }
.ggrid .grow.crow .gc.target, .ggrid .grow.crow .gc.sel { outline-width: 2px; outline-offset: -2px; }

/* Retenue : un petit carré centré dans la cellule (la cellule garde la grille, sans fond plein) */
.ggrid .grow.crow .gc, .ggrid .grow.crow .mark { height: calc(var(--cs) * 0.56); }
.ggrid .grow.crow .gc.carry, .ggrid.free .grow.crow .gc.edit.carry { background: transparent; position: relative; z-index: 0; font-size: calc(var(--cs) * 0.3); box-shadow: none; }
.ggrid .grow.crow .gc.carry.act { background: #fff0cc; }
.ggrid .grow.crow .gc.carry::before {
  content: ''; position: absolute; z-index: -1; width: calc(var(--cs) * 0.4); height: calc(var(--cs) * 0.4);
  border: 1.5px solid #ffb9a3; border-radius: 5px; background: #fff3ee;
}
.ggrid .grow.crow .gc.carry.target, .ggrid .grow.crow .gc.carry.sel { outline: none; background: transparent; }
.ggrid .grow.crow .gc.carry.act.target, .ggrid .grow.crow .gc.carry.act.sel { background: #fff0cc; }
.ggrid .grow.crow .gc.carry.target::before, .ggrid .grow.crow .gc.carry.sel::before { border: 2px dashed var(--coral); background: #fff; }

/* « La méthode » sous le choix du type de saisie */
.seg.bottom + .method { margin-top: 12px; }

/* Explication du type de saisie : sous les choix, tout en bas */
.seg-help { margin: 8px 0 0; padding: 10px 14px; border-radius: 12px; background: #faf8ff; border: 1.5px solid #ece6fb; color: var(--muted); font-weight: 700; font-size: .95rem; line-height: 1.45; text-align: center; }

/* Colonne de gauche qui apparaît quand l'enfant saisit sa réponse */
.gc.newcol { animation: colin .55s cubic-bezier(.3, 1.4, .5, 1) both; transform-origin: right center; }
@keyframes colin { 0% { opacity: 0; transform: scaleX(.1); } 100% { opacity: 1; transform: scaleX(1); } }

/* Nouvelle colonne : elle s'ouvre progressivement, la grille se recentre en douceur */
.gc.newcol { animation: colgrow .55s cubic-bezier(.25, .9, .35, 1) both; overflow: hidden; transform: none; transform-origin: left center; }
@keyframes colgrow { 0% { width: 0; min-width: 0; opacity: 0; } 60% { opacity: 1; } 100% { width: var(--cs); opacity: 1; } }

/* Ligne du bas de la grille : 2× plus basse que la ligne des retenues */
.ggrid .grow.brow .gc, .ggrid .grow.brow .mark { height: calc(var(--cs) * 0.28); min-height: 0; }

/* Touche « effacer » : poubelle dessinée (indépendante de la police), couleur distincte des chiffres */
.keypad button svg { display: block; width: 1.6rem; height: 1.6rem; margin: 0 auto; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.keypad button[data-k="del"] { color: var(--coral); border-color: #ffd3c6; box-shadow: 0 3px 0 #ffd3c6; }
.keypad button[data-k="del"]:active { box-shadow: none; }

/* Indice : dans son propre encadré, sous la zone de message */
.ghintbox { margin: -4px 0 12px; padding: 10px 14px; border-radius: 14px; background: #fff6d6; border: 1.5px solid #f3df9a; color: #5a4300; font-weight: 700; line-height: 1.45; animation: msgpop .35s ease-out; }
.ghintbox::before { content: '💡 '; }
.ghintbox[hidden] { display: none; }

/* Bilan */
button.total { border: 0; color: inherit; cursor: pointer; }
.rp-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.rp-head .title, .rp-head .lead { margin: 0; }
.rp-sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0 18px; }
.rp-sum div { background: #fff6e8; border-radius: 16px; padding: 10px 6px; text-align: center; display: flex; flex-direction: column; }
.rp-sum b { font-family: 'Baloo 2', sans-serif; font-size: 1.6rem; line-height: 1.1; }
.rp-sum span { font-size: .8rem; color: var(--muted); font-weight: 700; }
.rp-h { margin: 18px 0 8px; font-family: 'Baloo 2', sans-serif; }
.rp-game { border: 2px solid #f0e6dc; border-radius: 16px; padding: 10px 12px; margin-bottom: 10px; }
.rp-gt { font-weight: 800; margin-bottom: 6px; }
.rp-row { display: grid; grid-template-columns: 78px 1fr auto auto; align-items: center; gap: 10px; padding: 4px 0; }
.rp-lv { font-weight: 700; }
.rp-bar { height: 12px; border-radius: 99px; background: #ffd9d2; overflow: hidden; }
.rp-bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.rp-n { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.rp-n b { color: var(--ink); }
.rp-st { color: var(--sun); letter-spacing: 1px; }
.rp-reset { text-align: center; margin-top: 20px; }
@media (max-width: 560px) {
  .rp-row { grid-template-columns: 70px 1fr auto; }
  .rp-row .rp-st { grid-column: 2 / 4; }
}
.rp .rp-game { background: #fffaf3; box-shadow: none; color: var(--ink); }

.rp .rp-game { background: #fffaf3; border: 2px solid #f0e6dc; box-shadow: none; border-radius: 16px; }
.rp-bar { background: #eee6dc; }
.rp-bar i { background: #6fc49a; }
.rp-st { color: #e0a82e; }

/* Liste dépliable du bilan : une ligne = grille alignée, le détail s'ouvre dessous */
@media (max-width: 560px) {
}

.rp-head .title { flex: 1; min-width: 0; }
.rp-pts { margin-left: auto; align-self: flex-start; background: var(--sun); border-radius: 999px; padding: 6px 14px; font-weight: 800; white-space: nowrap; }
.rp-head .title { text-align: left; }
.rp-head { align-items: center; } .rp-head .title { margin: 0; line-height: 1.1; } .rp-head .rp-pts { align-self: center; }

/* Propositions pour « Par jeu et par niveau » */
.vlabel { margin: 16px 0 8px; font-weight: 800; color: var(--purple); font-size: .85rem; }
.vleg { font-weight: 600; color: var(--muted); margin-left: 8px; }
.vleg i, .vb-dots i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #6fc49a; margin: 0 2px 0 6px; vertical-align: middle; }
.vleg i.ko, .vb-dots i.ko { background: #f0a35c; }
.vb-dots i { margin: 0 3px 0 0; width: 12px; height: 12px; }
/* A */
/* B */
.vb-game { border-bottom: 1px solid #f0e6dc; padding: 8px 0; }
.vb-t { font-weight: 800; margin-bottom: 4px; }
.vb-lv { display: grid; grid-template-columns: 84px 1fr auto; align-items: center; gap: 8px; padding: 3px 0; font-size: .9rem; }
.vb-n { font-weight: 700; color: var(--muted); }
.vb-dots em { color: var(--muted); }
/* C */
.vc-game { background: #fffaf3; border: 2px solid #f0e6dc; border-radius: 14px; padding: 4px 12px; margin-bottom: 8px; }
.vc-game summary { cursor: pointer; display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; font-weight: 800; }
.vc-s { font-weight: 600; color: var(--muted); font-size: .85rem; }
.vc-game[open] { padding-bottom: 8px; }

/* Bilan : tuiles sur toute la largeur */


/* Formulaire « Choisis tes nombres » : plus d'air */
#cf { display: flex; flex-direction: column; gap: 20px; padding: 28px 24px; }
#cf .hint-line { margin: 0; }
#cf label { display: flex; flex-direction: column; gap: 8px; }
#cf .form-error { margin: 0; min-height: 1.2em; }
#cf .btn { margin-top: 6px; }

/* Niveaux : mêmes couleurs que les pastilles F / M / D du bilan */
.lv0 { background: #6fc49a; box-shadow: 0 6px 0 #4ea37b; }
.lv1 { background: #f6d58e; box-shadow: 0 6px 0 #d4b062; }
.lv3 { background: #f0a35c; box-shadow: 0 6px 0 #c9803a; }
.lvl.lv0, .lvl.lv1, .lvl.lv3 { color: var(--ink); }
.lvl.lv0 .lv-bars i, .lvl.lv1 .lv-bars i, .lvl.lv3 .lv-bars i { background: var(--ink); opacity: .22; }
.lvl.lv0 .lv-bars i.on, .lvl.lv1 .lv-bars i.on, .lvl.lv3 .lv-bars i.on { opacity: .85; }
.lvl.lv0 .lv-desc, .lvl.lv1 .lv-desc, .lvl.lv3 .lv-desc { background: rgba(255, 255, 255, .45); }
.lvl.lv0 .lv-stars, .lvl.lv1 .lv-stars, .lvl.lv3 .lv-stars { color: #b8791a; }

/* Palette des niveaux : dégradé de bleu (clair → moyen → soutenu) */
.lv0 { background: #c3e4fa; box-shadow: 0 6px 0 #97c3e3; }
.lv1 { background: #82c1f1; box-shadow: 0 6px 0 #589fd2; }
.lv3 { background: #4f9fe6; box-shadow: 0 6px 0 #2f78bf; }
.lvl.lv0 .lv-stars, .lvl.lv1 .lv-stars, .lvl.lv3 .lv-stars { color: #1c3f78; text-shadow: none; }

/* Mode Perso : carte pleine, jaune soleil (hors dégradé bleu), séparée des niveaux */
.levels .lvl.custom { margin-top: 18px; }
.lvl.custom {
  background: #ffd166; color: var(--ink); border: 0; box-shadow: 0 6px 0 #d9a93a;
}
.lvl.custom .lv-name { background: none; color: var(--ink); }
.lvl.custom .lv-desc { background: rgba(255, 255, 255, .5); color: var(--ink); }
.lvl.custom .lv-bars.pen { font-size: 1.6rem; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .15)); }
.lvl.custom .badge.pts { background: #1b1740; color: #ffd24d; }

/* Points des cartes de niveau : pastille blanche douce, même style partout (y compris Perso) */
.lvl .badge.pts, .lvl.custom .badge.pts {
  background: rgba(255, 255, 255, .85); color: var(--ink);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .12);
}
.lvl .badge.pts .per { font-weight: 700; opacity: .7; }

/* ===== Écran « Choisis ton niveau » : finitions ===== */
.card.page > .title { font-size: 1.9rem; line-height: 1.1; margin: 10px 0 0; }
.card.page > .lead { margin: 4px 0 18px; font-size: 1.05rem; }
.levels { gap: 14px; }
.levels .lvl { min-height: 74px; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .12s, box-shadow .12s, filter .12s; }
.levels .lvl .lv-name { font-size: 1.5rem; line-height: 1; }
.levels .lvl .lv-desc { font-size: 1.02rem; line-height: 1.25; }

/* Niveaux bleus : nom lisible, sans pastille translucide */
.levels .lvl.lv0 .lv-name, .levels .lvl.lv1 .lv-name, .levels .lvl.lv3 .lv-name { background: none; padding: 0; }

/* Étoiles : gagnées en doré, restantes en creux */
.lv-stars b, .lv-stars em { font-style: normal; font-weight: 400; }
.lvl .lv-stars { font-size: 1.35rem; letter-spacing: 1px; }
.lvl.lv0 .lv-stars b, .lvl.lv1 .lv-stars b, .lvl.lv3 .lv-stars b { color: #f5a800; text-shadow: 0 1px 0 rgba(255, 255, 255, .6), 0 -1px 0 rgba(120, 70, 0, .35); }
.lvl.lv0 .lv-stars em, .lvl.lv1 .lv-stars em, .lvl.lv3 .lv-stars em { color: rgba(42, 33, 80, .18); }

/* Survol (souris) et clavier */
@media (hover: hover) {
  .levels .lvl:hover { transform: translateY(-2px); filter: brightness(1.04); }
  .levels .lvl:hover:active { transform: translateY(4px); }
}
.levels .lvl:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* Perso : un peu plus discret en hauteur, avec un trait de séparation */
.levels .lvl.custom { min-height: 64px; }
.levels .lvl.custom .lv-name { font-size: 1.35rem; }

@media (max-width: 480px) {
  .card.page > .title { font-size: 1.6rem; }
  .levels { gap: 12px; }
  .levels .lvl { min-height: 0; }
}

/* ===== Cartes de niveau : nom + description empilés, points à droite (d'après capture) ===== */
.levels { gap: 20px; }
.levels .lvl.custom { margin-top: 14px; }
.levels .lvl {
  grid-template-columns: 48px 1fr auto; grid-template-rows: auto auto;
  column-gap: 14px; row-gap: 6px; padding: 14px 18px; align-items: center;
}
.levels .lvl .lv-bars { grid-column: 1; grid-row: 1 / span 2; justify-self: center; }
.levels .lvl .lv-name { grid-column: 2; grid-row: 1; align-self: end; }
.levels .lvl .lv-desc { grid-column: 2; grid-row: 2; align-self: start; justify-self: start; font-size: .95rem; padding: 2px 12px; border-radius: 999px; }
.levels .lvl .badge.pts { grid-column: 3; grid-row: 1 / span 2; align-self: center; justify-self: end; }
.levels .lvl .lv-stars { grid-column: 3; grid-row: 2; justify-self: end; }
.levels .lvl .lv-stars ~ .badge.pts, .levels .lvl:has(.lv-stars) .badge.pts { grid-row: 1; }
.levels .lvl .lv-desc { background: rgba(255, 255, 255, .5); }
.levels .lvl.custom .lv-desc { background: rgba(255, 255, 255, .5); }
@media (max-width: 480px) {
  .levels { gap: 18px; }
  .levels .lvl { grid-template-columns: 34px 1fr auto; padding: 12px 12px; column-gap: 10px; }
  .levels .lvl .lv-desc { font-size: .9rem; }
}

/* ===== Carte des écrans d'accueil / niveaux : ombre douce, voile de la couleur du jeu, en-tête aéré ===== */
.card.q.page {
  --cat: var(--coral);
  border-radius: 26px;
  box-shadow: 0 1px 2px rgba(42, 33, 80, .06), 0 12px 32px rgba(42, 33, 80, .14);
  background: #fff; border: 1px solid #e6e1f5;
  padding: 28px 22px 26px;
}
.card.q.page.coral { --cat: #ff6b4a; }
.card.q.page.purple { --cat: #8b5cf6; }
.card.q.page.teal { --cat: #14b8a6; }
.card.q.page.pink { --cat: #ff5fa2; }
.card.q.page.sun { --cat: #ffc233; }
.card.q.page.blue { --cat: #3b82f6; }
.card.q.page.green { --cat: #5aa51f; }
.card.q.page.indigo { --cat: #4f46e5; }
.card.q.page .catpill { margin: 0 auto 18px; padding: 9px 24px; box-shadow: 0 5px 0 rgba(0, 0, 0, .18), 0 10px 18px rgba(0, 0, 0, .10); }
.card.page > .title { margin: 6px 0 0; }
.card.page > .lead { margin: 8px 0 26px; }
@media (max-width: 480px) { .card.q.page { padding: 22px 14px 22px; } .card.page > .lead { margin-bottom: 22px; } }

/* Perso : plus petit que les trois niveaux */
.levels .lvl.custom {
  min-height: 0; padding: 8px 14px; row-gap: 2px; width: 100%; margin: 14px 0 0;
  box-shadow: 0 4px 0 #d9a93a;
}
.levels .lvl.custom .lv-name { font-size: 1.15rem; }
.levels .lvl.custom .lv-desc { font-size: .82rem; padding: 1px 10px; }
.levels .lvl.custom .lv-bars.pen { font-size: 1.25rem; }
.levels .lvl.custom .badge.pts { font-size: .8rem; padding: 2px 10px; }
@media (max-width: 480px) { .levels .lvl.custom { width: 100%; padding: 8px 12px; } }

/* Pastille du jeu : petite, en haut à droite de la carte */
.card.q.page .catpill {
  margin: 0 0 4px auto; padding: 4px 14px; font-size: .9rem;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .16);
}
.card.q.page { padding-top: 18px; }
@media (max-width: 480px) { .card.q.page { padding-top: 14px; } .card.q.page .catpill { font-size: .82rem; padding: 3px 12px; } }

/* Perso : retour à la hauteur compacte, mais bien séparé de Difficile */
.levels .lvl.custom { padding: 8px 14px; row-gap: 2px; min-height: 0; margin-top: 32px; }
@media (max-width: 480px) { .levels .lvl.custom { padding: 8px 12px; margin-top: 28px; } }

/* Perso : mêmes colonnes que les niveaux (icône et badge alignés) */
.levels .lvl.custom { padding-left: 18px; padding-right: 18px; }
.levels .lvl.custom .lv-bars.pen { width: 100%; justify-self: stretch; text-align: center; font-size: 1.25rem; line-height: 1; }
.levels .lvl.custom .badge.pts { font-size: .9rem; padding: 3px 12px; }
.levels .lvl .badge.pts { min-width: 7.5em; text-align: center; box-sizing: border-box; }
@media (max-width: 480px) { .levels .lvl.custom { padding-left: 12px; padding-right: 12px; } .levels .lvl .badge.pts { min-width: 0; } }

/* Alignements (d'après capture) */
.levels .lvl.custom .lv-bars.pen { display: flex; justify-content: center; align-items: center; height: auto; }
.levels .lvl .badge.pts { min-width: 8.6em; }
@media (max-width: 480px) { .levels .lvl .badge.pts { min-width: 0; } }

/* Perso : un peu plus d'espace entre le nom et la description */
.levels .lvl.custom { row-gap: 6px; }

/* Mobile : points en haut à droite face au nom, description dessous sur toute la largeur */
@media (max-width: 560px) {
  .levels .lvl { grid-template-rows: auto auto auto; }
  .levels .lvl .badge.pts { grid-column: 3; grid-row: 1; align-self: center; min-width: 0; }
  .levels .lvl .lv-desc { grid-column: 2 / -1; grid-row: 2; justify-self: start; }
  .levels .lvl .lv-stars { grid-column: 2 / -1; grid-row: 3; justify-self: start; }
  .levels .lvl .lv-bars { grid-row: 1 / span 2; }
  .levels .lvl:has(.lv-stars) .lv-bars { grid-row: 1 / span 3; }
  .levels .lvl .lv-name { align-self: center; }
}

/* Bilan : disposition « mobile » partout — la date au-dessus, puis jeu · niveau, résultat et flèche */

/* Soustraction : retenue écrite dans la case du chiffre (petit carré en haut à gauche) */
.ggrid.sub .gc:not(.op):not(.comma) { box-sizing: border-box; padding-left: calc(var(--cs) * 0.14); }
.ret {
  position: absolute; bottom: 2px; left: 2px; z-index: 1; box-sizing: border-box; display: flex; align-items: center; justify-content: center;
  width: calc(var(--cs) * 0.36); height: calc(var(--cs) * 0.36); padding: 0;
  border: 1.5px solid #ffb9a3; border-radius: 5px; background: #fff3ee; color: var(--coral);
  font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: calc(var(--cs) * 0.27); line-height: 1; cursor: pointer;
}
.ret::after { content: ''; position: absolute; inset: -5px; } /* zone de toucher plus grande */
.ret.bret { border-color: #a9c6f7; background: #eef4ff; color: #2f6fd6; }
.ret.target, .ret.sel { border: 2px dashed var(--coral); background: #fff; }
.ret.pop { animation: pop .5s ease-out; }
.ggrid:not(.free) .ret.bret { cursor: default; }

/* Retenue en bas de la case : au-dessus du trait épais de la dernière ligne */
.grow.last .gc .ret { bottom: 6px; }

/* Fenêtre de confirmation */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(42, 33, 80, .45); animation: modalbg .15s ease-out; }
.modal-box { width: min(380px, 100%); background: #fff; border-radius: 22px; padding: 24px 22px 20px; text-align: center; box-shadow: 0 20px 50px rgba(42, 33, 80, .35); animation: modalin .18s ease-out; }
.modal-box h3 { margin: 0 0 6px; font-family: 'Baloo 2', sans-serif; font-size: 1.5rem; line-height: 1.15; }
.modal-box p { margin: 0 0 18px; color: var(--muted); font-weight: 700; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; margin: 0; padding: 12px 10px; font-size: 1.05rem; }
.modal-actions .btn.danger { background: var(--ko); box-shadow: 0 5px 0 #b8334f; }
@keyframes modalbg { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalin { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }

/* Barre d'un exercice : le logo remplace « Quitter » (toucher = quitter) */
.brandbtn { border: 0; background: none; padding: 4px 6px; cursor: pointer; line-height: 1; border-radius: 10px; }
.brandbtn:active { transform: translateY(1px); }
.brandbtn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
@media (max-width: 480px) { .brandbtn { font-size: 1.1rem; } }
.brandbtn { display: inline-flex; align-items: center; gap: 2px; }
.brandbtn .arr { width: 1.05em; height: 1.05em; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); margin-right: 1px; }

/* Bilan : un problème est lisible comme une histoire, pas comme un calcul */

/* Bilan : même typographie pour les calculs et les problèmes */

/* La méthode : plus d'espace entre les étapes */
.method li + li { margin-top: 10px; }

/* La méthode : texte un peu plus petit */
.method h3 { font-size: 1.05rem; }
.method ol { font-size: .88rem; line-height: 1.45; }

/* Type de saisie : tout en bas, bien séparé de la méthode, libellé à gauche, choix retenu discret */
.seg.bottom { margin-top: 44px; justify-content: flex-start; gap: 8px; }
.seg.bottom > span { flex: 0 0 100%; text-align: left; font-size: .9rem; }
.seg .chipbtn.on { background: #e9e2ff; color: var(--purple); box-shadow: inset 0 0 0 2px #cbb9fb; }
.seg-help { text-align: left; }
@media (max-width: 480px) { .seg.bottom { margin-top: 36px; } }

/* Légende dans « La méthode » : mêmes petits carrés que dans la grille */
.ret-key { display: inline-flex; align-items: center; justify-content: center; width: 1.35em; height: 1.35em; vertical-align: middle; position: relative; top: -0.04em; margin: 0 2px; box-sizing: border-box; border-radius: 5px; border: 1.5px solid #ffb9a3; background: #fff3ee; color: var(--coral); font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: .8em; line-height: 1; }
.ret-key.bret { border-color: #a9c6f7; background: #eef4ff; color: #2f6fd6; }

/* Zone de focus : pointillés arrondis, décollés des traits de la grille (la grille elle-même reste carrée) */
.gc.target:not(.carry), .ggrid.free .gc.edit.sel:not(.carry) { outline: none; }
.gc.target:not(.carry)::after, .ggrid.free .gc.edit.sel:not(.carry)::after {
  content: ''; position: absolute; inset: 3px; box-sizing: border-box; pointer-events: none;
  border: 2.5px dashed var(--coral); border-radius: 10px;
}
@media (max-width: 480px) { .gc.target:not(.carry)::after, .ggrid.free .gc.edit.sel:not(.carry)::after { inset: 3px; } }

/* Félicitation d'une étape assistée : zone à part, sous la grille, qui reste jusqu'à la validation suivante */
.okline { min-height: 2rem; display: flex; align-items: center; justify-content: center; margin: -4px 0 6px; }
.okpill { background: #e8f9ee; color: #166534; font-weight: 800; font-size: .95rem; border-radius: 999px; padding: 3px 14px; box-shadow: inset 0 0 0 1.5px #b7e8c9; animation: okin .22s ease-out; }
@keyframes okin { from { opacity: 0; transform: translateY(-4px) scale(.96); } to { opacity: 1; transform: none; } }

/* Zéros de décalage de la multiplication : bleus, pour bien voir le décalage */
.ggrid .gc.shift, .ggrid.free .gc.edit.shift:not(.carry) { color: #2f6fd6; background: #eaf2ff; }
.shift-key { display: inline-flex; align-items: center; justify-content: center; width: 1.35em; height: 1.35em; vertical-align: middle; position: relative; top: -0.04em; margin: 0 2px; border-radius: 5px; background: #eaf2ff; color: #2f6fd6; font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: .85em; line-height: 1; }
.okpill.shift { background: #eaf2ff; color: #2f6fd6; box-shadow: inset 0 0 0 1.5px #b9d3fb; }
.okpill { max-width: 100%; text-align: center; line-height: 1.3; border-radius: 16px; padding: 5px 14px; }

/* Message de fin : texte à gauche, points gagnés alignés à droite */
.gmsg.good { display: flex; align-items: center; gap: 10px; }
.gmsg.good::before { flex: none; margin-right: 0; }
.gmsg.good .gtxt { flex: 1; min-width: 0; }
.gmsg.good .pts-badge { flex: none; margin-left: auto; }

/* Multiplication : retenues empilées, une couleur par ligne (chiffre du multiplicateur) ; les anciennes sont barrées */
.ggrid .grow.crow .gc.carry.rc0, .ggrid .gc.dcol0 { color: #16a34a; }
.ggrid .grow.crow .gc.carry.rc1, .ggrid .gc.dcol1 { color: #e11d48; }
.ggrid .grow.crow .gc.carry.rc2, .ggrid .gc.dcol2 { color: #4f46e5; }
.ggrid .grow.crow .gc.carry.rc3, .ggrid .gc.dcol3 { color: #b45309; }
.ggrid .grow.crow .gc.carry.rc0::before { border-color: #a7e3bd; background: #effbf3; }
.ggrid .grow.crow .gc.carry.rc1::before { border-color: #f6b1c0; background: #fff0f3; }
.ggrid .grow.crow .gc.carry.rc2::before { border-color: #b9b5f3; background: #f1f0ff; }
.ggrid .grow.crow .gc.carry.rc3::before { border-color: #efcf9b; background: #fff7e8; }
.ggrid .grow.crow .gc.carry.struck { text-decoration: line-through; text-decoration-thickness: 2px; }
.ggrid .grow.crow .gc.carry.struck::before { opacity: .55; }
.flyer { text-shadow: 0 3px 8px rgba(0, 0, 0, .18); }
.ret.struck { text-decoration: line-through; text-decoration-thickness: 2px; }
.ret.struck { opacity: .65; }

/* Logo de l'en-tête : l'icône de l'app devant le nom */
.brand { display: inline-flex; align-items: center; gap: 8px; line-height: 1; }
.brand-mark { width: 1.75em; height: 1.75em; flex: none; display: block; border-radius: 22%; box-shadow: 0 2px 0 rgba(42, 33, 80, .12); }
.brandbtn { gap: 8px; }
.brandbtn .arr { margin-right: 0; }
@media (max-width: 480px) { .brand { gap: 6px; } .brand-mark { width: 1.6em; height: 1.6em; } }

/* ===== Accueil : cartes calmes (fond blanc, pastille de couleur douce, ombre légère) ===== */
.grid-title { margin: 20px 4px 8px; font-family: 'Baloo 2', sans-serif; font-size: .8rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.card.page > .lead + .grid-title { margin-top: 12px; }
.grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 0; }
.cat {
  --cat: var(--coral);
  flex-direction: row; justify-content: flex-start; align-items: center; gap: 14px; text-align: left;
  padding: 12px 14px; color: var(--ink); background: #fff; border: 1px solid #e6e1f5; border-radius: 20px;
  box-shadow: 0 1px 2px rgba(42, 33, 80, .05), 0 6px 16px rgba(42, 33, 80, .07);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.cat.coral { --cat: #ff6b4a; } .cat.pink { --cat: #ff5fa2; } .cat.purple { --cat: #8b5cf6; } .cat.blue { --cat: #3b82f6; }
.cat.sun { --cat: #f5a800; } .cat.teal { --cat: #14b8a6; } .cat.green { --cat: #5aa51f; } .cat.indigo { --cat: #4f46e5; }
.cat.coral, .cat.pink, .cat.purple, .cat.blue, .cat.sun, .cat.teal, .cat.green, .cat.indigo { background: #fff; box-shadow: 0 1px 2px rgba(42, 33, 80, .05), 0 6px 16px rgba(42, 33, 80, .07); }
.cat .icon { flex: none; display: grid; place-items: center; width: 54px; height: 54px; border-radius: 16px; font-size: 1.8rem; background: color-mix(in srgb, var(--cat) 16%, #fff); }
.cat .txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.cat strong { font-size: 1.1rem; line-height: 1.2; }
.cat small { opacity: 1; color: var(--muted); font-weight: 700; font-size: .9rem; }
.cat .chev { flex: none; width: 1.1rem; height: 1.1rem; fill: none; stroke: #b8b0d6; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; transition: transform .12s, stroke .12s; }
@media (hover: hover) {
  .cat:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--cat) 45%, #fff); box-shadow: 0 2px 4px rgba(42, 33, 80, .06), 0 10px 22px rgba(42, 33, 80, .10); }
  .cat:hover .chev { transform: translateX(2px); stroke: var(--cat); }
}
.cat:active { transform: translateY(1px); box-shadow: 0 1px 2px rgba(42, 33, 80, .05); }
.cat:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
@media (max-width: 480px) { .grid { grid-template-columns: 1fr; gap: 10px; } .cat .icon { width: 48px; height: 48px; font-size: 1.6rem; } }

/* ===== Choix du niveau : même style calme que l'accueil (fond blanc, couleur du jeu en accent, plus de bleus/jaune) ===== */
.levels { gap: 14px; }
.levels .lvl:is(.lv0, .lv1, .lv3), .levels .lvl.custom {
  --tint: 14%;
  background: #fff; color: var(--ink); border: 1px solid #e6e1f5; border-radius: 20px;
  box-shadow: 0 1px 2px rgba(42, 33, 80, .05), 0 6px 16px rgba(42, 33, 80, .07);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.levels .lvl.lv1 { --tint: 26%; }
.levels .lvl.lv3 { --tint: 40%; }
@media (hover: hover) {
  .levels .lvl:is(.lv0, .lv1, .lv3):hover, .levels .lvl.custom:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--cat, var(--coral)) 45%, #fff); box-shadow: 0 2px 4px rgba(42, 33, 80, .06), 0 10px 22px rgba(42, 33, 80, .10); }
}
.levels .lvl:is(.lv0, .lv1, .lv3):active, .levels .lvl.custom:active { transform: translateY(1px); box-shadow: 0 1px 2px rgba(42, 33, 80, .05); }

/* Pastille de gauche : les barres de niveau, de plus en plus teintées */
.levels .lvl:is(.lv0, .lv1, .lv3) .lv-bars {
  width: 46px; height: 46px; justify-self: center; align-self: center; display: flex; align-items: flex-end; justify-content: center; gap: 4px; padding-bottom: 11px; box-sizing: border-box;
  border-radius: 14px; background: color-mix(in srgb, var(--cat, var(--coral)) var(--tint), #fff);
}
.levels .lvl:is(.lv0, .lv1, .lv3) .lv-bars i { width: 6px; background: var(--cat, var(--coral)); opacity: .28; border-radius: 3px; }
.levels .lvl:is(.lv0, .lv1, .lv3) .lv-bars i.on { opacity: 1; }
.levels .lvl:is(.lv0, .lv1, .lv3) .lv-bars i:nth-child(1) { height: 9px; }
.levels .lvl:is(.lv0, .lv1, .lv3) .lv-bars i:nth-child(2) { height: 15px; }
.levels .lvl:is(.lv0, .lv1, .lv3) .lv-bars i:nth-child(3) { height: 21px; }

/* Textes */
.levels .lvl .lv-name, .levels .lvl.custom .lv-name { color: var(--ink); background: none; }
.levels .lvl .lv-desc, .levels .lvl.custom .lv-desc { background: none; padding: 0; color: var(--muted); font-weight: 700; font-size: .95rem; }

/* Points et étoiles */
.levels .lvl .badge.pts, .levels .lvl.custom .badge.pts { background: color-mix(in srgb, var(--cat, var(--coral)) 14%, #fff); color: var(--ink); box-shadow: none; }
.levels .lvl:is(.lv0, .lv1, .lv3) .lv-stars b { color: #f5a800; text-shadow: none; }
.levels .lvl:is(.lv0, .lv1, .lv3) .lv-stars em { color: #e3dff2; text-shadow: none; }

/* Perso : même carte, trait pointillé de la couleur du jeu pour montrer qu'elle est libre */
.levels .lvl.custom { border: 2px dashed color-mix(in srgb, var(--cat, var(--coral)) 50%, #fff); box-shadow: none; }
.levels .lvl.custom .lv-bars.pen { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 14px; background: color-mix(in srgb, var(--cat, var(--coral)) 14%, #fff); font-size: 1.35rem; padding: 0; }
@media (max-width: 480px) { .levels .lvl:is(.lv0, .lv1, .lv3) .lv-bars, .levels .lvl.custom .lv-bars.pen { width: 40px; height: 40px; padding-bottom: 9px; } .levels .lvl.custom .lv-bars.pen { padding-bottom: 0; } }

/* Pastille du jeu (en haut à droite de la carte) : teinte douce de la couleur du jeu, texte foncé, plus d'aplat vif */
.card.q.page .catpill {
  background: color-mix(in srgb, var(--cat, var(--coral)) 14%, #fff);
  color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--cat, var(--coral)) 32%, #fff);
  box-shadow: none;
  font-weight: 800;
}

/* Logo de l'en-tête : bleu foncé, comme l'icône */
.brand { color: #1e3a8a; }
.brand b { color: #3b82f6; }
.card.page > .title + .grid-title { margin-top: 30px; }
@media (max-width: 480px) { .card.page > .title + .grid-title { margin-top: 24px; } }

/* Icônes des jeux (accueil) : fond blanc, seulement le contour en couleur */
.cat .icon { background: #fff; border: 2px solid var(--cat); }

/* Nom de l'app : une ligne sur ordinateur, deux lignes courtes sur téléphone */
.brand-text { white-space: nowrap; }
@media (max-width: 480px) { .brand-text { white-space: normal; line-height: 1.05; font-size: .95rem; max-width: 7.6em; text-align: left; } }

/* Logo de l'en-tête : la maison seule (sans fond), nom sur deux lignes */
.brand-mark { width: 2.2em; height: 2.2em; border-radius: 0; box-shadow: none; }
.brand-text { white-space: nowrap; line-height: 1.05; font-size: .86em; text-align: left; max-width: none; }
@media (max-width: 480px) { .brand-mark { width: 2em; height: 2em; } .brand-text { white-space: nowrap; font-size: .8em; max-width: none; } }

/* Accueil : la place de la flèche de retour est conservée (invisible) pour que le logo ne bouge pas d'un écran à l'autre */
.brandbtn.static { cursor: default; }
.brandbtn.static .arr { visibility: hidden; }

/* Pictogrammes des jeux (SVG, couleur du jeu) */
.gi { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.gi .f { fill: currentColor; fill-opacity: .16; }
.cat .icon .gi { width: 30px; height: 30px; stroke-width: 2; }
.catpill .gi { width: 1.2em; height: 1.2em; margin-right: 2px; }
.count .gi { width: 1.1em; height: 1.1em; }
.gi { stroke-width: 1.6; }
.cat .icon .gi { stroke-width: 1.6; }
.gi .f { fill: none; }
.gi .in { opacity: .45; }
.gi .f { fill: currentColor; fill-opacity: .14; stroke: none; }
/* Pictogrammes sur grille de 48 : trait fin régulier, sans remplissage */
.gi, .cat .icon .gi { stroke-width: 2.6; }
.gi .f, .gi .in { fill: none; opacity: 1; }

/* Accueil : plus d'air avant le groupe « Autres jeux » */
.grid + .grid-title { margin-top: 54px; }
@media (max-width: 480px) { .grid + .grid-title { margin-top: 44px; } }
.card.page > .lead + .grid-title { margin-top: 46px; }
@media (max-width: 480px) { .card.page > .lead + .grid-title { margin-top: 36px; } }

/* Écran « Qui joue ? » : la maison et le nom de l'app, en bleu */
.logo { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 14px 0 4px; font-size: 2.2rem; line-height: 1.05; color: #1e3a8a; }
.logo span { color: #3b82f6; }
.logo .logo-text { color: #1e3a8a; text-align: center; }
.logo .logo-text span { color: #3b82f6; }
.logo-mark { width: 96px; height: 96px; display: block; }
@media (max-width: 480px) { .logo { font-size: 1.9rem; } .logo-mark { width: 80px; height: 80px; } }

/* Écran « Qui joue ? » : la maison à gauche, le nom à droite */
.logo { flex-direction: row; justify-content: center; gap: 14px; font-size: 2rem; }
.logo .logo-text { text-align: left; }
.logo-mark { width: 84px; height: 84px; flex: none; }
@media (max-width: 480px) { .logo { gap: 10px; font-size: 1.6rem; } .logo-mark { width: 64px; height: 64px; } }

/* Écran « Qui joue ? » : le titre en grand, avec de l'air avant et après */
.who-title { font-size: 2.3rem; line-height: 1.1; margin: 40px 0 28px; }
@media (max-width: 480px) { .who-title { font-size: 1.9rem; margin: 30px 0 22px; } }

/* ===== Bilan : « Par jeu et par niveau » — cartes de jeu (cercle à gauche, réussite par niveau à droite) ===== */
.pj-nav { display: flex; gap: 8px; margin: 0 0 12px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.pj-nav::-webkit-scrollbar { display: none; }
.pj-go { flex: none; width: 48px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: #fff; border: 1.5px solid #f0e6dc; padding: 0; transition: background .15s, border-color .15s; }
.pj-go .gi { width: 24px; height: 24px; }
.pj-go.on { background: #fbeedb; border: 2px solid var(--g); }
.pj-go:focus-visible, .pj-track:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.pj { min-width: 0; max-width: 100%; }
.pj-track { position: relative; display: flex; gap: 8px; width: 100%; max-width: 100%; min-width: 0; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scroll-padding-inline: 6%; touch-action: pan-x pan-y; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding: 2px 6% 8px; border-radius: 22px; }
.pj-track::-webkit-scrollbar { display: none; }
.pj-card { flex: 0 0 min(88%, 440px); min-width: 0; scroll-snap-align: center; scroll-snap-stop: always; background: #fffaf3; border: 1.5px solid #f0e6dc; border-radius: 20px; overflow: hidden; }
.pj-card header { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #fbeedb; }
.pj-ico { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; background: #fff; border: 1.5px solid #f0e6dc; }
.pj-ico .gi { width: 21px; height: 21px; }
.pj-ttl { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.pj-ttl strong { font-size: .98rem; }
.pj-ttl small { color: var(--muted); font-weight: 700; font-size: .8rem; }
.pj-body { display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 14px; padding: 14px; }
.pj-ring { --p: 0; position: relative; width: 74px; height: 74px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--c, #6fc49a) calc(var(--p) * 1%), #eee6dc 0); }
.pj-ring::before { content: ''; position: absolute; inset: 9px; border-radius: 50%; background: #fffaf3; }
.pj-ring b { position: relative; font-size: 1rem; }
.pj-lv { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.pj-lv li { display: grid; grid-template-columns: 1fr 3em; column-gap: 8px; row-gap: 3px; align-items: center; }
.pj-l { font-weight: 800; font-size: .82rem; }
.pj-n { grid-column: 2; grid-row: 1; justify-self: end; font-style: normal; font-weight: 700; font-size: .72rem; color: var(--muted); white-space: nowrap; }
.pj-bar { grid-column: 1; grid-row: 2; height: 10px; border-radius: 99px; background: #eee6dc; overflow: hidden; }
.pj-bar i { display: block; height: 100%; min-width: 0; border-radius: 99px; background: var(--c, #6fc49a); }
.pj-pct { grid-column: 2; grid-row: 2; justify-self: end; font-size: .85rem; }
.pj-lv li.off .pj-l, .pj-lv li.off .pj-n, .pj-lv li.off .pj-pct { color: #a9a3b8; font-weight: 600; }
.pj-lv li.off .pj-n { grid-column: 2; }
.pj-dots { display: flex; justify-content: center; gap: 8px; margin: 4px 0 2px; }
.pj-dots i { width: 8px; height: 8px; border-radius: 99px; background: #d9d3c8; transition: width .2s, background .2s; }
.pj-dots i.on { width: 22px; background: #6fc49a; }
/* Grand écran : grille de deux colonnes, sans défilement ni raccourcis */
/* Dès 700 px : deux cartes par ligne, plus de défilement ni de raccourcis (écran tactile compris). */
@media (min-width: 700px) {
  .pj-track { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; scroll-snap-type: none; padding: 0; }
  .pj-card { flex: none; }
  .pj-nav, .pj-dots { display: none; }
}
@media (prefers-reduced-motion: reduce) { .pj-dots i, .pj-go { transition: none; } }

.pj-track { cursor: grab; } .pj-track:active { cursor: grabbing; }
@media (min-width: 700px) { .pj-track, .pj-track:active { cursor: auto; } }

/* Bilan sur téléphone : on récupère la largeur perdue en marges (écran, carte blanche, liste des jeux) */
.total { white-space: nowrap; }
@media (max-width: 699px) {
  .rpscreen { padding-left: 6px; padding-right: 6px; }
  .card.page.rp { padding: 12px 6px 16px; border-radius: 22px; }
  .rp .rp-pts { display: none; } /* les points sont déjà dans l'en-tête de l'appli */
  .rp .rp-head { gap: 10px; }
  .rp .rp-sum { gap: 6px; }
  .rp-h { margin-left: 4px; margin-right: 4px; }
  /* Cartes de jeu : la carte affichée prend presque toute la largeur, seul un petit bord des voisines dépasse */
  .pj-nav { padding-left: 4px; padding-right: 4px; }
  .pj-track { margin-inline: -6px; padding-inline: 18px; scroll-padding-inline: 18px; }
  .pj-card { flex: 0 0 min(100%, 520px); }
  .pj-card header { padding: 9px 11px; }
  .pj-body { grid-template-columns: 68px 1fr; gap: 12px; padding: 12px 12px; }
  .pj-ring { width: 68px; height: 68px; }
  .pj-ring::before { inset: 8px; }
  .pj-ring b { font-size: .95rem; }
}

/* Bilan sur téléphone : la carte occupe toute la largeur, sans fond de page visible autour */
@media (max-width: 699px) {
  .rpscreen { padding: 0 0 24px; }
  .card.page.rp { border-radius: 0 0 22px 22px; border-left: 0; border-right: 0; border-top: 0; box-shadow: none; padding: 18px 20px 24px; min-height: calc(100dvh - 66px); }
  .pj-track { margin-inline: -20px; }
  .pj-nav { padding-left: 2px; padding-right: 2px; }
  .rp-h { margin-left: 2px; margin-right: 2px; }
}

/* ===== Écrans étroits (moins de 700 px) : plus de marge autour de .screen, les cartes vont de bord à bord, sur tous les écrans ===== */
@media (max-width: 699px) {
  .screen { padding: 0 0 24px; }
  .screen > .card { border-radius: 0 0 22px 22px; border-left: 0; border-right: 0; box-shadow: none; }
  .screen > .card.page { border-top: 0; }
  .screen > .card:only-of-type { min-height: calc(100dvh - 66px); }
  /* ce qui n'est pas une carte (profils, barre de progression, titres…) garde un peu d'air sur les côtés */
  .screen > :not(.card) { margin-left: 14px; margin-right: 14px; }
  .screen > .logo { margin-top: 18px; }
}

/* Les cartes « page » (accueil, niveaux) ont une règle plus précise : on l'égale pour retirer aussi leur arrondi du haut, leur bordure et leur ombre */
@media (max-width: 699px) {
  .screen > .card.q.page { border-radius: 0 0 22px 22px; border-left: 0; border-right: 0; border-top: 0; box-shadow: none; }
}

/* Slider des jeux : pas de sélection de texte en glissant (au doigt ou à la souris) */
@media (max-width: 699px) {
  .pj-track, .pj-track * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
  .pj-track svg { pointer-events: none; }
}

/* Couleur de la réussite (anneau et barres) : vert ≥ 70 %, orange en dessous, rouge à 40 % et moins */
.pj-ring.t-mid, .pj-bar i.t-mid { --c: #f2a65a; }
.pj-ring.t-bad, .pj-bar i.t-bad { --c: #e4605f; }

/* Bilan : plus d'air au-dessus des titres « Par jeu et par niveau » et « Derniers exercices » */
.rp .rp-h { margin-top: 56px; }
@media (max-width: 699px) { .rp .rp-h { margin-top: 50px; } }

/* ===== Bilan : derniers exercices, regroupés par jour ===== */
.rl-day + .rl-day { margin-top: 48px; }
.rl-dayh { margin: 0 0 2px; font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #9a95b5; }
.rl-list { list-style: none; margin: 0; padding: 0; }
.rl-row { border-bottom: 1.3px solid #eceaf5; }
.rl-btn { display: grid; grid-template-columns: 44px 38px minmax(0, 1fr) auto 18px; align-items: center; gap: 12px; width: 100%; padding: 11px 0; background: none; border: 0; text-align: left; color: inherit; font: inherit; cursor: pointer; }
.rl-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 10px; }
.rl-time { font-size: .74rem; font-weight: 700; color: #9a95b5; font-variant-numeric: tabular-nums; }
.rl-ico { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: #fff; border: 1.5px solid #f0e6dc; }
.rl-ico .gi { width: 21px; height: 21px; }
.rl-txt { display: flex; flex-direction: column; gap: 3px; min-width: 0; line-height: 1.2; }
.rl-txt strong { font-size: .95rem; }
.rl-lv { display: inline-flex; align-items: center; gap: 4px; font-size: .66rem; font-weight: 700; color: #7d86a8; }
.rl-bars { width: 9px; height: 9px; fill: #9aa6c9; }
.rl-res { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.rl-pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 99px; font-size: .74rem; font-weight: 700; white-space: nowrap; }
.rl-pill svg { width: 12px; height: 12px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rl-pill.ok { background: #e4f6ea; color: #2f7a4d; }
.rl-pill.err { background: #fdeedd; color: #a24a1f; }
.rl-pill.hint { background: #fcf3d6; color: #8a6a1f; }
.rl-chev { width: 18px; height: 18px; fill: none; stroke: #9a95b5; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
.rl-btn[aria-expanded="true"] .rl-chev { transform: rotate(180deg); }
@media (max-width: 480px) { .rl-btn { grid-template-columns: 36px 38px minmax(0, 1fr) auto 16px; gap: 10px; } }
@media (prefers-reduced-motion: reduce) { .rl-chev { transition: none; } }

/* ===== Ligne dépliée : fond gris-bleu léger, haut droit (il s'aligne sur le trait de séparation), bas arrondi ===== */
.rl-dayh { margin-left: 8px; }
.rl-btn { padding: 11px 8px; }
.rl-row.open { background: #f4f7fd; border-radius: 0 0 14px 14px; border-bottom-color: transparent; }
.rl-btn[aria-expanded="true"] .rl-chev { stroke: #1e3a8a; }
.rl-more { --off: 114px; padding: 0 12px 14px var(--off); }
.rl-more[hidden] { display: none; }
.rl-kind { display: block; font-size: .62rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #9a95b5; }
.rl-calc { margin: 3px 0 10px; font-size: 1rem; font-weight: 700; color: var(--ink); }
.rl-calc.muted { font-size: .85rem; font-weight: 600; color: var(--muted); }
.rl-story { margin: 4px 0 10px; font-size: .9rem; font-weight: 500; line-height: 1.5; color: var(--ink); }
.rl-redo { display: inline-flex; align-items: center; gap: 6px; padding: 0; background: none; border: 0; color: #1e3a8a; font: inherit; font-size: .85rem; font-weight: 700; text-decoration: underline; text-decoration-color: rgba(30, 58, 138, .35); text-underline-offset: 4px; cursor: pointer; }
.rl-redo svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rl-redo:hover { text-decoration-color: #1e3a8a; }
.rl-redo:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; border-radius: 6px; }
@media (max-width: 480px) { .rl-more { --off: 102px; padding-right: 8px; } }

/* Détail déplié : une zone blanche dans la zone gris-bleu, avec de l'espace vertical (calcul, énoncé de problème…) */
.rl-more { --off: 0px; padding: 2px 8px 14px; }
.rl-box { display: flex; flex-direction: column; gap: 10px; padding: 20px 18px 16px; background: #fff; border: 1px solid #e3eaf7; border-radius: 12px; }
.rl-box .rl-kind { margin: 0; }
.rl-box .rl-calc { margin: 0; font-size: 1.1rem; line-height: 1.4; }
.rl-box .rl-story { margin: 0; line-height: 1.6; }
.rl-actions { margin-top: 8px; padding-top: 14px; border-top: 1px solid #eef1f8; }
@media (max-width: 480px) { .rl-more { padding: 2px 6px 12px; } .rl-box { padding: 18px 16px 14px; } }
/* Étiquette « Calcul » / « Problème » : plus lisible */
.rl-box .rl-kind { font-size: .74rem; letter-spacing: .07em; color: #5b6590; }

/* Pagination des derniers exercices */
.rp .rp-h { scroll-margin-top: 84px; }
.rl-pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 26px; }
.rl-pg { padding: 9px 16px; border-radius: 99px; background: #fff; border: 1.5px solid #f0e6dc; color: #1e3a8a; font: inherit; font-size: .84rem; font-weight: 700; cursor: pointer; white-space: nowrap; }
.rl-pg:hover:not(:disabled) { border-color: #c9d3ea; background: #f4f7fd; }
.rl-pg:disabled { opacity: .35; cursor: default; }
.rl-pg:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.rl-pgnum { text-align: center; font-size: .8rem; font-weight: 700; color: var(--muted); }

/* ===== Division posée : grille (dividende | diviseur, quotient sous le diviseur), étapes, aides ===== */
.ggrid.div { --cs: clamp(26px, 8.2vw, 52px); }
.ggrid.div .gc.bar { border-left: 3px solid var(--ink); }
.ggrid.div .gc.dvl, .ggrid.div .gc.ul { border-bottom: 3px solid var(--ink); }
.ggrid.div .gc.hl { background: #fff0cc; }
.ggrid.div .gc.hl-down { background: #ffe0b0; color: #c2610a; }
.ggrid.div .gc.down { color: var(--coral); }
.dsteps { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 0 0 12px; }
.dsteps span { padding: 4px 11px; border-radius: 99px; background: #eef1f8; color: #8f97b8; font-size: .72rem; font-weight: 800; }
.dsteps span.past { background: #e4f6ea; color: #2f7a4d; }
.dsteps span.on { background: #1e3a8a; color: #fff; }
.gactions { flex-wrap: wrap; }
.gactions .btn.big.abaisse { background: #f59e0b; box-shadow: 0 5px 0 #c27d08; }
.gactions .btn.alt { flex: 1 1 100%; padding: 12px 14px; font-size: 1rem; }
.hintbtn.table { background: #eef1f8; color: #3a4a7a; box-shadow: 0 5px 0 #cfd6ea; }
.hintbtn.table[hidden], .gactions .btn.alt[hidden] { display: none; }
/* fenêtres d'aide */
.modal-box.sheet h3 { text-align: left; }
.modal-box.panel { width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; text-align: left; padding: 16px 16px 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.panel-head h3 { margin: 0; font-size: 1.25rem; }
.panel-body .g { margin: 0; }

/* Table du diviseur : deux colonnes de cinq lignes « 3 × 54 = 162 » */
.mtab { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; margin: 10px 0 16px; }
.mtab ul { list-style: none; margin: 0; padding: 0; }
.mt { display: grid; grid-template-columns: 1fr auto auto; align-items: baseline; gap: 8px; padding: 11px 4px; border-bottom: 1.3px solid #eceaf5; font-variant-numeric: tabular-nums; font-size: 1rem; }
.mtab ul li:last-child { border-bottom: 0; }
.mt span { font-weight: 700; color: var(--ink); text-align: right; }
.mt i { font-style: normal; color: var(--muted); font-weight: 700; }
.mt b { min-width: 3ch; text-align: left; color: #3b4fd6; font-size: 1.1rem; }
@media (max-width: 380px) { .mtab { gap: 0 10px; } .mt { gap: 5px; font-size: .92rem; } }

/* Table du diviseur : multiplicateur en gras et plus grand, colonne de gauche calée à gauche */
.mt { grid-template-columns: 7.2ch auto 1fr; padding: 11px 0; }
.mt span { text-align: left; font-weight: 600; }
.mt span strong { font-size: 1.2rem; font-weight: 800; }
@media (max-width: 380px) { .mt { grid-template-columns: 6.6ch auto 1fr; } }
/* Table du diviseur : le « = » colle au nombre de la table, le résultat suit juste après */
.mt, .mt { display: flex; align-items: baseline; gap: 0; }
.mt span { flex: none; }
.mt i { margin: 0 0 0 .12em; }
.mt b { min-width: 0; margin-left: .4em; }
/* Table du diviseur : retrait à gauche de chaque ligne (plus aéré) */
.mt { padding: 11px 0 11px 20px; }
@media (max-width: 380px) { .mt { padding-left: 12px; } }
/* Table du diviseur : lignes alignées à droite (résultats alignés sur leur bord droit) */
.mt { justify-content: flex-end; padding: 11px 8px 11px 0; }
.mt b { min-width: 3.4ch; text-align: right; }
@media (max-width: 380px) { .mt { padding-right: 4px; } }

/* Division : une seule zone en pointillé sur les cases où s'écrit le produit ou le reste (un seul nombre) */
.ggrid.div .gc.zone::after { content: ''; position: absolute; inset: 3px; z-index: 1; box-sizing: border-box; pointer-events: none; border: 2.5px dashed var(--coral); }
.ggrid.div .gc.zone.zs::after { border-radius: 10px; }
.ggrid.div .gc.zone.zl::after { right: -2px; border-right: 0; border-radius: 10px 0 0 10px; }
.ggrid.div .gc.zone.zm::after { left: -2px; right: -2px; border-left: 0; border-right: 0; border-radius: 0; }
.ggrid.div .gc.zone.zr::after { left: -2px; border-left: 0; border-radius: 0 10px 10px 0; }



/* Mode Perso : la saisie des nombres se déplie juste sous la carte « Perso » */
.levels .lvl.custom[aria-expanded="true"] { border-bottom-style: solid; border-bottom-color: transparent; border-bottom-left-radius: 0; border-bottom-right-radius: 0; background: color-mix(in srgb, var(--cat, var(--coral)) 8%, #fff); }
.custom-panel { margin-top: -14px; padding: 18px 18px 20px; background: #fff; border: 2px dashed color-mix(in srgb, var(--cat, var(--coral)) 50%, #fff); border-top: 0; border-radius: 0 0 20px 20px; }
.custom-panel[hidden] { display: none; }
.custom-panel #cf { padding: 0; gap: 16px; }
.custom-panel #cf .form-error { min-height: 0; }
.custom-panel #cf .form-error:empty { display: none; }
@media (prefers-reduced-motion: no-preference) { .custom-panel:not([hidden]) { animation: cpin .2s ease-out; } }
@keyframes cpin { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Jeux pas encore disponibles : grisés et non cliquables */
.cat.soon { cursor: not-allowed; filter: grayscale(1); opacity: .55; box-shadow: none; background: #f4f5f9; }
.cat.soon .icon { background: #fff; border-color: #c9cdd9; }
.cat.soon .icon .gi { color: #9aa0b4 !important; }
.cat.soon:hover, .cat.soon:active { transform: none; box-shadow: none; border-color: #e6e1f5; }
.soon-tag { flex: none; padding: 3px 10px; border-radius: 99px; background: #e4e7f0; color: #5b6590; font-size: .72rem; font-weight: 800; white-space: nowrap; }
