/* ==========================================================================
   Calcul Express — styles du jeu de maths
   Toutes les classes commencent par « math- » (ou sont sous .game-maths).
   ========================================================================== */
.math-off { display: none !important; }
.math-hint { margin: 0; font-size: 15px; line-height: 1.3; color: var(--ink-soft); }

/* ==================== Écran de réglages ==================== */
.math-setup { display: grid; gap: 14px; padding-block: 2px 0; }
.math-setup__head { display: flex; align-items: flex-end; min-height: 80px; }
.math-setup__head .owl-box { width: 72px; }
.math-setup__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 430px), 1fr));
  gap: 16px;
  align-items: start;
}
.math-panel { display: grid; gap: 14px; align-content: start; }
.math-panel__title { font-size: clamp(22px, 1vw + 16px, 30px); }
.math-field { display: grid; gap: 8px; }
.game-maths .chips { gap: 10px; }
.game-maths .math-chip { min-height: 56px; min-width: 56px; }
.math-chip--all { padding-inline: 18px; }
.math-chip--ex { text-align: left; border-radius: 18px; padding: 6px 16px 7px; line-height: 1.1; }
.math-chip__sym { display: inline-block; min-width: 1em; font-size: 1.3em; line-height: .8; vertical-align: -.08em; }
.math-chip--ex small { display: block; margin-top: 2px; font-family: var(--font-body); font-weight: 700; font-size: 14px; opacity: .8; }
.math-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.math-tile {
  appearance: none;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  min-height: 76px;
  padding: 10px 14px;
  text-align: left;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s, background .12s;
}
.math-tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.math-tile[aria-pressed="true"] { background: var(--sun); }
.math-tile__emoji { font-size: 34px; line-height: 1; }
.math-tile__txt { display: grid; gap: 2px; min-width: 0; }
.math-tile__txt b { font-family: var(--font-display); font-weight: 800; font-size: 21px; line-height: 1.05; }
.math-tile__txt span { font-size: 15px; line-height: 1.2; color: var(--ink-soft); }
.math-voice { border-bottom: 0; padding-block: 4px 0; cursor: pointer; }
/* L'interrupteur du socle fait 44 px de haut : on agrandit sa zone de toucher (et toute la ligne est cliquable). */
.math-voice .switch::before { content: ""; position: absolute; inset: -10px -8px; }

.math-go {
  position: sticky;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  padding: 20px 0 2px;
  background: linear-gradient(180deg, rgba(196,239,255,0) 0, var(--sky-2) 20px);
}
.math-go__hint {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 18px;
  line-height: 1.15;
  color: var(--ink-soft);
}
.math-go__hint.is-err { color: var(--tomato); }
.math-go__btn { flex: 0 0 auto; }
.math-go__btn.is-dim { filter: grayscale(.6) opacity(.7); }

/* iPad en paysage : tout l'écran de réglages tient sans défiler.
   Plume descend à côté du bouton « C'est parti ! » (sa bulle y affiche aussi les erreurs),
   et les panneaux sont un peu plus serrés. */
@media (min-aspect-ratio: 5/4) and (min-width: 760px) {
  .math-setup {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "grid grid" "head go";
    align-items: end;
    gap: 10px 16px;
  }
  .math-setup__grid { grid-area: grid; align-self: start; }
  .math-setup__head { grid-area: head; min-height: 0; padding-bottom: 2px; }
  .math-setup__head .bubble { margin-bottom: 16px; max-width: 30ch; }
  .math-go { grid-area: go; padding-top: 10px; }
  .math-panel { gap: 10px; padding-block: 14px 16px; }
  .math-tile { min-height: 64px; padding-block: 6px; }
}

/* ==================== Partie : grille ==================== */
.math-game {
  --track-w: 84px;
  position: relative;
  display: grid;
  grid-template-columns: var(--track-w) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "hud hud" "track main" "track side";
  gap: 12px;
  min-height: 0;
  padding-bottom: 4px;
}
.math-game--balloons { grid-template-rows: auto minmax(0, 1fr) minmax(0, 1.05fr); }
@media (min-aspect-ratio: 5/4) and (min-width: 760px) {
  .math-game,
  .math-game--balloons {
    --track-w: 92px;
    grid-template-columns: var(--track-w) minmax(0, 1fr) minmax(330px, 34%);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "track hud hud" "track main side";
  }
}

/* ---------- Barre du haut ---------- */
.math-hud { grid-area: hud; display: flex; align-items: center; gap: 10px; min-width: 0; }
.math-hud .pill { min-height: 52px; font-size: 22px; padding: 4px 14px; font-variant-numeric: tabular-nums; }
.math-hud__score b { font-family: var(--font-display); }
.math-hud__pts { font-size: .8em; color: var(--ink-soft); }
.math-hud__time {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 56px;
  padding: 2px 14px;
  border: var(--stroke) solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 4px 0 var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 32px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.math-hud__ico { font-size: 26px; }
.math-hud__time.is-warn { background: var(--tomato); color: var(--paper); text-shadow: 0 2px 0 rgba(35,26,74,.35); animation: mathPulse .5s ease-in-out infinite alternate; }
@keyframes mathPulse { from { transform: scale(1); } to { transform: scale(1.06); } }
.math-hud__free { flex: 1; font-family: var(--font-display); font-weight: 800; font-size: 20px; color: var(--ink-soft); }

/* Mèche : la corde se consume, l'étincelle avance vers la gauche */
.math-fuse {
  --f: 1;
  position: relative;
  flex: 1;
  min-width: 50px;
  height: 26px;
  border: var(--stroke) solid var(--ink);
  border-radius: 999px;
  background: repeating-linear-gradient(-45deg, #f3e2bf 0 8px, #e9d2a4 8px 16px);
  box-shadow: 0 4px 0 var(--ink);
}
.math-fuse__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--f) * 100%);
  border-radius: 999px;
  background: linear-gradient(90deg, var(--sun-deep), var(--sun));
}
.math-fuse.is-low .math-fuse__fill { background: linear-gradient(90deg, var(--tomato), var(--sun-deep)); }
.math-fuse__spark {
  position: absolute;
  right: -16px;
  top: 50%;
  width: 32px;
  height: 32px;
  margin-top: -16px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 16%, var(--sun) 28%, var(--sun-deep) 46%, rgba(255,94,87,.0) 70%);
  animation: mathSpark .16s ease-in-out infinite alternate;
}
@keyframes mathSpark { from { transform: scale(.8) rotate(0); } to { transform: scale(1.2) rotate(30deg); } }

/* ---------- Piste de la fusée ---------- */
.math-track {
  --rk-w: calc(var(--track-w) * .6);
  --rk: calc(var(--rk-w) * 1.5625);
  --ground: 20px;
  grid-area: track;
  position: relative;
  min-height: 0;
  border: var(--stroke) solid var(--ink);
  border-radius: calc(var(--track-w) / 2);
  overflow: hidden;
  background: linear-gradient(180deg, #2b2370 0%, #5145c2 26%, #4ca7ee 62%, #8fdcff 86%, #c4efff 100%);
  box-shadow: 0 5px 0 var(--ink);
}
.math-track__sky {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(2px 2px at 30% 6%, #fff 99%, transparent),
    radial-gradient(2px 2px at 70% 12%, #fff 99%, transparent),
    radial-gradient(1.5px 1.5px at 45% 20%, #fff 99%, transparent),
    radial-gradient(2px 2px at 20% 28%, #fff 99%, transparent),
    radial-gradient(1.5px 1.5px at 80% 34%, #fff 99%, transparent),
    radial-gradient(14px 8px at 25% 78%, rgba(255,255,255,.9) 98%, transparent),
    radial-gradient(18px 9px at 72% 66%, rgba(255,255,255,.85) 98%, transparent);
}
.math-track__ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--ground);
  background: var(--grass);
  border-top: 3px solid var(--ink);
}
.math-mark {
  --pos: calc(var(--ground) + var(--m) * (100% - var(--rk) - var(--ground) - 6px) + var(--rk) * .45);
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--pos);
  height: 0;
  border-top: 3px dashed rgba(255,255,255,.65);
}
.math-mark .star { position: absolute; left: 50%; top: 0; font-size: calc(var(--track-w) * .38); transform: translate(-50%, -50%); }
.math-mark .star.is-in { animation: mathStarIn .5s cubic-bezier(.3,1.6,.6,1) both; }
@keyframes mathStarIn { 0% { transform: translate(-50%, -50%) scale(0) rotate(-40deg); } 100% { transform: translate(-50%, -50%) scale(1); } }
.math-mark.is-on { border-top-color: var(--sun); }
.math-rocket {
  position: absolute;
  z-index: 2;
  left: 50%;
  width: var(--rk-w);
  margin-left: calc(var(--rk-w) / -2);
  bottom: calc(var(--ground) + var(--p, 0) * (100% - var(--rk) - var(--ground) - 6px));
  transition: bottom .6s cubic-bezier(.3,1.35,.5,1);
}
.math-rocket svg { display: block; width: 100%; height: auto; overflow: visible; }
.math-rocket__flame { transform-origin: 32px 79px; animation: mathFlame .12s ease-in-out infinite alternate; }
@keyframes mathFlame { from { transform: scaleY(.8); } to { transform: scaleY(1.12); } }
.math-rocket.is-boost svg { animation: mathBoost .55s ease; }
@keyframes mathBoost { 0% { transform: none; } 30% { transform: translateY(-6px) scale(1.08, .94); } 100% { transform: none; } }
.math-rocket.is-boost .math-rocket__flame { animation: mathFlameBig .55s ease; }
@keyframes mathFlameBig { 0% { transform: scaleY(1); } 30% { transform: scaleY(1.8); } 100% { transform: scaleY(1); } }
.math-rocket.is-wobble svg { animation: mathWobble .45s ease; }
@keyframes mathWobble { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-12deg); } 60% { transform: rotate(9deg); } }
.math-rocket.is-ignite svg { animation: mathRumble .09s linear infinite; }
@keyframes mathRumble { 0% { transform: translate(0, 0); } 33% { transform: translate(-1.5px, 1px); } 66% { transform: translate(1.5px, -1px); } 100% { transform: translate(0, 0); } }
.math-rocket.is-launch { bottom: 115% !important; transition: bottom 1.1s cubic-bezier(.55,0,.85,.35); }
.math-game.is-paused .math-rocket__flame,
.math-game.is-paused .math-fuse__spark,
.math-game.is-paused .math-hud__time { animation-play-state: paused; }

/* ---------- Feuille Séyès ---------- */
.math-main { grid-area: main; position: relative; display: flex; min-width: 0; min-height: 0; }
.math-sheet {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 40px 14px 52px calc(var(--margin) + 14px);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--ink);
  container-type: inline-size;
}
.math-sheet__title {
  position: absolute;
  top: 8px;
  left: calc(var(--margin) + 14px);
  font-weight: 700;
  font-size: 18px;
  color: var(--ink-soft);
  text-decoration: underline 2px var(--seyes-margin);
  text-underline-offset: 4px;
}
.math-sheet__n {
  position: absolute;
  left: 0;
  top: 50%;
  width: var(--margin);
  transform: translateY(-50%);
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  color: var(--seyes-margin);
}
.math-q {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  column-gap: .32em;
  row-gap: .1em;
  max-width: 100%;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(40px, calc(165cqi / var(--len, 9)), 132px);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.math-q__g { display: inline-flex; align-items: center; gap: .32em; white-space: nowrap; }
.math-q__o { color: var(--grape-deep); }
.math-q__w { font-size: .62em; }
.math-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5em;
  min-height: 1.12em;
  padding: 0 .16em;
  border: max(3px, .055em) dashed var(--ink);
  border-radius: .2em;
  background: rgba(255,255,255,.88);
  color: var(--ocean);
  line-height: 1;
}
.math-box.is-empty::after { content: ""; width: max(3px, .05em); height: .72em; border-radius: 2px; background: var(--ocean); animation: mathCaret 1s steps(1) infinite; }
@keyframes mathCaret { 50% { opacity: 0; } }
.math-box.is-ask { color: var(--grape); border-style: solid; }
.math-box.is-good { background: var(--grass); color: var(--paper); border-style: solid; text-shadow: 0 .04em 0 rgba(35,26,74,.35); animation: mathBoxPop .3s ease; }
.math-box.is-fix { background: #eafff0; color: var(--ok); border-style: solid; border-color: var(--ok); animation: mathBoxPop .3s ease; }
.math-box.is-nudge { animation: mathNudge .3s ease; }
@keyframes mathBoxPop { 0% { transform: scale(.9); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes mathNudge { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-6px); } 70% { transform: translateX(6px); } }
.math-sheet.is-good { animation: mathGood .5s ease; }
@keyframes mathGood {
  0% { box-shadow: 0 6px 0 var(--ink), 0 0 0 0 rgba(63,194,107,0); }
  35% { box-shadow: 0 6px 0 var(--ink), 0 0 0 12px rgba(63,194,107,.6); }
  100% { box-shadow: 0 6px 0 var(--ink), 0 0 0 0 rgba(63,194,107,0); }
}
.math-sheet.is-bad { animation: mathShake .42s ease; }
@keyframes mathShake { 0%, 100% { transform: translateX(0); } 18% { transform: translateX(-11px); } 38% { transform: translateX(9px); } 58% { transform: translateX(-6px); } 78% { transform: translateX(3px); } }
.math-note {
  position: absolute;
  left: calc(var(--margin) + 10px);
  right: 96px;
  bottom: 12px;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(18px, 1vw + 12px, 26px);
  line-height: 1.15;
  min-height: 1.2em;
}
.math-note s { color: var(--tomato); text-decoration-thickness: 3px; }
.math-note b { color: var(--ok); }
.math-streak {
  position: absolute;
  top: 8px;
  right: 10px;
  padding: 2px 12px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--sun);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  box-shadow: 0 3px 0 var(--ink);
  opacity: 0;
  transform: scale(.6);
  transition: opacity .15s, transform .15s;
  white-space: nowrap;
}
.math-streak.is-on { opacity: 1; transform: none; }
.math-streak.is-bump { animation: mathBump .3s ease; }
@keyframes mathBump { 0% { transform: scale(1); } 50% { transform: scale(1.22) rotate(-4deg); } 100% { transform: scale(1); } }
.math-fx { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.math-float {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(28px, 2vw + 16px, 46px);
  line-height: 1;
  color: var(--sun);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--ink);
  white-space: nowrap;
  animation: mathFloat .95s ease-out forwards;
}
@keyframes mathFloat {
  0% { opacity: 0; transform: translate(-50%, 0) scale(.6); }
  20% { opacity: 1; transform: translate(-50%, -34px) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -120px) scale(1); }
}
.math-flash {
  position: absolute;
  left: 50%;
  top: 22%;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(30px, 4vw + 10px, 60px);
  color: var(--sun);
  -webkit-text-stroke: 2.5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink);
  white-space: nowrap;
  animation: mathFlash 1.05s ease forwards;
}
@keyframes mathFlash {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(.4) rotate(-8deg); }
  25% { opacity: 1; transform: translate(-50%, 0) scale(1.1) rotate(-3deg); }
  75% { opacity: 1; transform: translate(-50%, -6px) scale(1) rotate(-3deg); }
  100% { opacity: 0; transform: translate(-50%, -24px) scale(.95) rotate(-3deg); }
}
.math-owl { position: absolute; right: 8px; bottom: 6px; z-index: 4; pointer-events: none; }
.math-owl .owl-wrap { display: block; }
.math-owl .owl-box { width: 76px; }
.math-owl .bubble {
  position: absolute;
  right: calc(100% + 12px);
  bottom: 34px;
  margin: 0;
  max-width: none;
  white-space: nowrap;
  font-size: 19px;
  padding: 6px 12px;
}
.math-owl .bubble::after { left: auto; right: -13px; bottom: 9px; width: 18px; height: 18px; transform: rotate(225deg) skew(10deg, 10deg); }

/* ---------- Pavé numérique ---------- */
.math-pad {
  --key-h: clamp(62px, 8vh, 96px);
  grid-area: side;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: var(--key-h);
  gap: 10px;
  justify-self: center;
  align-self: end;
  width: min(100%, 540px);
}
@media (min-aspect-ratio: 5/4) and (min-width: 760px) {
  .math-pad { --key-h: auto; grid-template-rows: repeat(4, minmax(64px, 1fr)); grid-auto-rows: auto; height: min(100%, 470px); align-self: center; width: 100%; }
}
.math-key {
  appearance: none;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 62px;
  padding: 0;
  border: var(--stroke) solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--ink);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(30px, 1.6vw + 18px, 46px);
  line-height: 1;
  cursor: pointer;
  transition: transform .05s, box-shadow .05s, background .08s;
}
.math-key.is-down { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); background: var(--sun); }
.math-key--del { grid-column: 4; grid-row: 1; background: var(--peach); }
.math-key--ok { grid-column: 4; grid-row: 2 / span 3; background: var(--grass); color: var(--paper); text-shadow: 0 2px 0 rgba(35,26,74,.35); }
.math-key--ok.is-down { background: #2fa85a; }
.math-key--zero { grid-column: 1 / span 3; }
.math-pad--dec .math-key--zero { grid-column: 2 / span 2; }
.math-key--comma { background: var(--sky-2); }

/* ---------- Ciel à ballons ---------- */
.math-sky {
  --bw: 80px;
  grid-area: side;
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--ink);
  background:
    radial-gradient(46px 18px at 18% 22%, rgba(255,255,255,.9) 98%, transparent),
    radial-gradient(34px 22px at 22% 18%, rgba(255,255,255,.9) 98%, transparent),
    radial-gradient(60px 20px at 78% 58%, rgba(255,255,255,.8) 98%, transparent),
    radial-gradient(40px 24px at 74% 54%, rgba(255,255,255,.8) 98%, transparent),
    linear-gradient(180deg, #7fd3fa 0%, #c9f0ff 100%);
}
.math-balloon {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--bw);
  height: calc(var(--bw) * 1.66);
  padding: 0;
  border: 0;
  background: none;
  appearance: none;
  cursor: pointer;
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
}
.math-balloon__body {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--bw);
  height: calc(var(--bw) * 1.18);
  display: grid;
  place-items: center;
  border: var(--stroke) solid var(--ink);
  border-radius: 50% 50% 47% 47% / 56% 56% 44% 44%;
  background: radial-gradient(circle at 32% 26%, rgba(255,255,255,.8) 0 8%, rgba(255,255,255,0) 9%), var(--c);
  box-shadow: inset -7px -9px 0 rgba(35,26,74,.15);
}
.math-balloon__body::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  z-index: -1;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  border: 3px solid var(--ink);
  border-radius: 3px;
  background: var(--c);
  transform: rotate(45deg);
}
.math-balloon__num {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--fs, 30px);
  line-height: 1;
  color: var(--paper);
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--ink);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.math-balloon__string {
  position: absolute;
  left: 50%;
  top: calc(var(--bw) * 1.18 + 2px);
  width: 16px;
  height: calc(var(--bw) * .46);
  margin-left: -8px;
}
.math-balloon__string svg { display: block; width: 100%; height: 100%; }
.math-balloon.is-pop .math-balloon__body { animation: mathPopB .24s ease-out forwards; }
.math-balloon.is-pop .math-balloon__string { opacity: 0; transition: opacity .2s; }
@keyframes mathPopB { 0% { transform: scale(1); } 45% { transform: scale(1.3); opacity: 1; } 100% { transform: scale(1.55); opacity: 0; } }
.math-balloon.is-deflate .math-balloon__body { animation: mathDeflate .9s ease-in forwards; }
@keyframes mathDeflate {
  0% { transform: none; }
  20% { transform: scale(.92, 1.06) rotate(-9deg); }
  45% { transform: scale(.78) rotate(11deg); }
  70% { transform: scale(.62) rotate(-7deg); filter: grayscale(.6); }
  100% { transform: translateY(30px) scale(.5); filter: grayscale(.85); opacity: .6; }
}
.math-balloon.is-answer .math-balloon__body { animation: mathGlow .45s ease-in-out infinite alternate; }
@keyframes mathGlow {
  from { box-shadow: inset -7px -9px 0 rgba(35,26,74,.15), 0 0 0 0 var(--sun); }
  to { box-shadow: inset -7px -9px 0 rgba(35,26,74,.15), 0 0 0 9px var(--sun); }
}
.math-balloon.is-idle { opacity: .55; transition: opacity .2s; }
.math-balloon.is-gone { opacity: 0; transition: opacity .3s; }
.math-burst { position: absolute; left: 50%; top: calc(var(--bw) * .55); width: 0; height: 0; pointer-events: none; }
.math-burst i {
  position: absolute;
  left: -6px;
  top: -6px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--c);
  transform: rotate(var(--a)) translateY(0);
  animation: mathShard .45s ease-out forwards;
}
@keyframes mathShard { to { transform: rotate(var(--a)) translateY(calc(var(--bw) * -.95)) scale(.4); opacity: 0; } }

/* ---------- Superpositions : compte à rebours, pause, fin ---------- */
.math-over {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: rgba(196,239,255,.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.math-over--end { background: rgba(196,239,255,.35); }
.math-cd {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(120px, 16vw + 40px, 240px);
  line-height: 1;
  color: var(--sun);
  -webkit-text-stroke: 5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 10px 0 var(--ink);
  text-align: center;
  animation: mathCd .62s cubic-bezier(.2,1.5,.5,1) both;
}
.math-cd--go { color: var(--grass); font-size: clamp(64px, 8vw + 30px, 150px); }
.math-cd--end { color: var(--tomato); font-size: clamp(46px, 5vw + 24px, 104px); -webkit-text-stroke-width: 4px; padding-inline: 12px; }
@keyframes mathCd { 0% { transform: scale(.3) rotate(-12deg); opacity: 0; } 60% { transform: scale(1.12) rotate(3deg); opacity: 1; } 100% { transform: scale(1) rotate(0); } }
.math-pause { display: grid; gap: 10px; justify-items: center; text-align: center; max-width: 420px; }
.math-pause__t { font-family: var(--font-display); font-weight: 800; font-size: 44px; line-height: 1; }
.math-pause p { margin: 0; font-size: 20px; }

/* ---------- Téléphone ---------- */
@media (max-width: 560px) {
  .math-setup__head { min-height: 0; }
  .math-tiles { grid-template-columns: 1fr; }
  .math-tile { min-height: 64px; }
  .math-go { flex-wrap: wrap; }
  .math-go__hint { flex-basis: 100%; font-size: 15px; }
  .math-go__btn { width: 100%; }
  .math-game { --track-w: 48px; gap: 8px; }
  .math-track { --ground: 14px; border-width: 3px; }
  .math-hud { gap: 7px; }
  .math-hud .pill { min-height: 46px; font-size: 18px; padding: 2px 10px; }
  .math-hud__pts { display: none; }
  .math-hud__time { min-height: 48px; padding: 2px 10px; font-size: 24px; border-width: 3px; }
  .math-hud__ico { display: none; }
  .math-fuse { height: 20px; border-width: 3px; }
  .math-fuse__spark { width: 26px; height: 26px; margin-top: -13px; right: -13px; }
  .math-sheet { --margin: 32px; padding: 34px 8px 50px calc(var(--margin) + 8px); }
  .math-sheet__title { font-size: 15px; top: 6px; left: calc(var(--margin) + 8px); }
  .math-sheet__n { font-size: 17px; }
  .math-streak { font-size: 16px; padding: 1px 9px; top: 6px; right: 6px; }
  .math-note { right: 58px; bottom: 10px; font-size: 18px; }
  .math-owl .owl-box { width: 50px; }
  .math-owl .bubble { font-size: 16px; bottom: 22px; }
  .math-key { border-width: 3px; border-radius: 15px; box-shadow: 0 4px 0 var(--ink); }
  .math-pad { gap: 8px; }
}
@media (max-height: 560px) {
  .math-sheet__title { display: none; }
}

/* ==================== Espace parents ==================== */
.math-ps { display: grid; gap: 14px; }
.math-ps__block { display: grid; gap: 6px; }
.math-ps__title { font-family: var(--font-display); font-weight: 800; font-size: 18px; }
.math-grid { border-collapse: separate; border-spacing: 2px; font-family: var(--font-display); font-weight: 800; font-size: 13px; font-variant-numeric: tabular-nums; }
.math-grid th { min-width: 26px; height: 24px; color: var(--ink-soft); font-size: 13px; text-align: center; }
.math-grid__corner { color: var(--grape-deep) !important; font-size: 16px !important; }
.math-grid__c { min-width: 28px; height: 26px; padding: 0 2px; text-align: center; border-radius: 6px; border: 2px solid rgba(35,26,74,.2); }
.math-grid__c.is-good { background: #9fe6b4; border-color: var(--ok); }
.math-grid__c.is-mid { background: #ffd89a; border-color: var(--sun-deep); }
.math-grid__c.is-bad { background: #ffb3ad; border-color: var(--tomato); }
.math-grid__c.is-new { background: #eeecf5; color: #a29dbc; }
.math-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 15px; }
.math-legend__i { display: inline-flex; align-items: center; gap: 6px; }
.math-legend__i i { display: inline-block; width: 18px; height: 18px; min-width: 0; padding: 0; }
.math-ps__miss { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.math-ps__miss li { padding: 3px 10px; border: 2px solid var(--ink); border-radius: 12px; background: #fff1ef; font-family: var(--font-display); font-weight: 800; font-size: 17px; white-space: nowrap; }
.math-ps__miss li.is-good { background: #eafff0; }
.math-ps__err { color: var(--tomato); font-size: 14px; }
