/* Wallaby des maths — fond blanc, Andika en graisse normale, traits fins,
   grandes zones à toucher (même charte que NumérationCM et Problèmes). */

@font-face{
  font-family:'Andika';
  src:url('polices/andika-400.woff2') format('woff2');
  font-weight:400; font-style:normal; font-display:swap;
}
@font-face{
  font-family:'Andika';
  src:url('polices/andika-700.woff2') format('woff2');
  font-weight:700; font-style:normal; font-display:swap;
}

:root{
  --fond:#ffffff;
  --surface:#f5f6f8;
  --trait:#dfe3e8;
  --texte:#1d1f23;
  --doux:#646a73;
  --ok:#1b7f45;   --ok-fond:#e6f4ec;
  --err:#c23b2e;  --err-fond:#fbecea;
  --info:#8a5300; --info-fond:#fdf3e1;
  --accent:#2f7d32; --accent-fond:#eaf5ea;      /* le vert de la clairière */
  --action:#e8590c; --action-fonce:#cf4d08;     /* l'orange du wallaby */
  --rayon:16px;
  --ombre:0 1px 2px rgba(20,24,32,.05), 0 6px 20px rgba(20,24,32,.07);
  --police:'Andika', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

*,*::before,*::after{ box-sizing:border-box; }
html{ -webkit-text-size-adjust:100%; }
body{
  margin:0; min-height:100vh;
  background:var(--fond); color:var(--texte);
  font-family:var(--police); font-weight:400; font-size:18px; line-height:1.45;
  -webkit-tap-highlight-color:transparent;
}
button, input{ font:inherit; color:inherit; }
button{ cursor:pointer; }
[hidden]{ display:none !important; }
h1, h2{ font-weight:400; margin:0; }
.doux{ color:var(--doux); }

/* ---------- Boutons ---------- */
.bouton{
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  min-height:52px; padding:0 22px; border-radius:26px;
  border:1.5px solid var(--trait); background:var(--fond); font-size:1.1rem;
  transition:background .15s, border-color .15s, filter .15s;
}
.bouton svg{ width:22px; height:22px; }
.bouton:hover{ background:var(--surface); }
.bouton.principal{ border-color:var(--action); background:var(--action); color:#fff; padding:0 34px; font-size:1.2rem; }
.bouton.principal:hover{ background:var(--action-fonce); border-color:var(--action-fonce); }
.bouton:disabled{ opacity:.4; cursor:default; }
.bouton:focus-visible, .pastille:focus-visible, .rond:focus-visible, .choix button:focus-visible,
.segments button:focus-visible, input:focus-visible{ outline:3px solid var(--accent); outline-offset:2px; }
.bouton .reste{ color:var(--doux); font-size:.95rem; }
.pastille{
  min-height:44px; padding:0 18px; border:0; border-radius:22px;
  background:var(--accent-fond); color:var(--accent); font-size:1.05rem;
}
.pastille:hover{ filter:brightness(.96); }
.rond{
  flex:none; width:48px; height:48px; border:0; border-radius:50%;
  background:var(--surface); color:var(--doux);
  display:inline-flex; align-items:center; justify-content:center;
}
.rond svg{ width:26px; height:26px; }
.rond:hover, .rond.actif{ background:var(--accent-fond); color:var(--accent); }
.actions{ display:flex; flex-wrap:wrap; justify-content:flex-end; gap:12px; margin-top:22px; }

/* ---------- Accueil ---------- */
.accueil{ min-height:100vh; display:flex; flex-direction:column; box-shadow:inset 0 6px 0 var(--accent); }
.accueil-corps{
  flex:1; display:grid; grid-template-columns:minmax(0, 400px) minmax(0, 520px);
  gap:44px; align-items:center; justify-content:center; padding:28px 24px 12px;
}
.affiche{ width:100%; height:auto; border-radius:28px; box-shadow:var(--ombre); }
.carte{ background:var(--fond); border:1px solid var(--trait); border-radius:var(--rayon); box-shadow:var(--ombre); padding:26px 28px; }
.carte h1{ font-size:2rem; line-height:1.2; }
.accroche{ margin:6px 0 18px; color:var(--doux); }
.resume{ margin:0 0 16px; padding:10px 14px; border-radius:12px; background:var(--accent-fond); color:var(--accent); }
.champ{ display:grid; grid-template-columns:110px minmax(0,1fr); align-items:center; gap:12px; margin-top:12px; }
.champ > span{ color:var(--doux); }
.champ input{
  width:100%; min-height:50px; padding:0 16px; font-size:1.2rem;
  border:1.5px solid var(--trait); border-radius:12px; background:var(--fond);
}
.segments{ display:flex; flex-wrap:wrap; gap:6px; }
.segments button{
  flex:1 1 auto; min-height:46px; padding:0 14px; white-space:nowrap;
  border:1.5px solid var(--trait); border-radius:12px; background:var(--fond);
}
.segments button:hover{ background:var(--surface); }
.segments button.actif{ border-color:var(--accent); background:var(--accent-fond); color:var(--accent); font-weight:700; }
.pied{ padding:10px 20px 14px; text-align:center; color:var(--doux); font-size:.8rem; }
.pied a{ color:inherit; }
@media (max-width:860px){
  .accueil-corps{ grid-template-columns:minmax(0, 520px); gap:18px; padding-top:22px; }
  .affiche{ width:150px; justify-self:center; border-radius:20px; }
}
@media (max-width:480px){
  .champ{ grid-template-columns:1fr; gap:4px; }
  .carte{ padding:20px 18px; }
  .actions{ justify-content:stretch; }
  .actions .bouton{ flex:1; }
}

/* ---------- Partie : bandeau ---------- */
.jeu{ min-height:100vh; display:flex; flex-direction:column; }
.barre{
  display:grid; grid-template-columns:1fr auto 1fr; align-items:center; gap:12px;
  min-height:68px; padding:10px 16px; box-shadow:inset 0 6px 0 var(--accent);
}
.barre .pastille{ justify-self:start; }
.compteurs{ justify-self:end; display:flex; align-items:center; gap:10px; }
.chrono, .score{
  display:inline-flex; align-items:center; gap:8px; min-height:44px; padding:0 16px;
  border-radius:22px; background:var(--surface); font-size:1.1rem; white-space:nowrap;
}
.chrono i{ width:20px; height:20px; border-radius:50%; background:conic-gradient(var(--accent) var(--part, 100%), var(--trait) 0); }
.chrono b, .score b{ font-weight:700; font-variant-numeric:tabular-nums; }
.chrono.presse{ background:var(--err-fond); color:var(--err); }
.chrono.presse i{ background:conic-gradient(var(--err) var(--part, 100%), #f1cbc6 0); }

/* La piste : six pierres, le wallaby sur celle du niveau en cours */
.piste{ list-style:none; margin:0; padding:0; display:flex; align-items:center; }
.piste li{
  position:relative; width:34px; height:34px; margin-left:18px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  background:var(--surface); color:var(--doux); font-size:.95rem;
}
.piste li:first-child{ margin-left:0; }
.piste li + li::before{ content:''; position:absolute; right:100%; top:50%; width:18px; height:3px; margin-top:-1.5px; background:var(--surface); }
.piste li.fait{ background:var(--accent-fond); color:var(--accent); }
.piste li.fait + li::before{ background:var(--accent-fond); }
.piste li.actuel{
  width:48px; height:48px; color:transparent;
  background:#fff url('logo_wallaby.jpg') 36% 46% / 330% no-repeat;
  box-shadow:0 0 0 3px var(--accent);
}
.piste li.actuel.saut{ animation:saut .6s ease; }
@keyframes saut{ 0%{ transform:translateY(0); } 40%{ transform:translateY(-12px) scale(1.08); } 100%{ transform:translateY(0); } }
.piste li.actuel .serie{ position:absolute; left:0; right:0; top:100%; margin-top:5px; display:flex; justify-content:center; gap:4px; }
.piste .serie i{ width:8px; height:8px; border-radius:50%; background:var(--trait); }
.piste .serie i.plein{ background:var(--accent); }

/* ---------- Partie : problème ---------- */
.probleme{
  flex:1; width:100%; max-width:1060px; margin:0 auto; padding:14px 24px 20px;
  display:flex; flex-direction:column; gap:14px;
}
.etiquette{ margin:0; color:var(--doux); font-size:1rem; display:flex; align-items:center; gap:10px; }
.rappel{ padding:2px 12px; border-radius:14px; background:var(--info-fond); color:var(--info); }
.enonce{ display:flex; align-items:flex-start; gap:14px; }
.enonce p{ flex:1; margin:0; font-size:clamp(1.3rem, 2.3vw, 1.85rem); line-height:1.45; }
.milieu{ flex:1; display:grid; gap:20px; align-content:center; }
.probleme.avec-figure .milieu{ grid-template-columns:minmax(0, 1fr) minmax(0, 1fr); align-items:center; }
.figure{ display:flex; justify-content:center; align-items:center; min-width:0; }
.figure svg{ display:block; width:auto; max-width:100%; height:min(38vh, 300px); }
.figure svg.fig-monnaie{ width:min(100%, 460px); height:auto; }
.figure svg.fig-rectangle{ height:min(30vh, 230px); }
.figure svg.fig-droite, .figure svg.fig-bande{ width:min(100%, 520px); height:auto; }
.figure svg.fig-quadrillage, .figure svg.fig-grille{ height:min(32vh, 240px); }
.figure svg.fig-balance{ height:min(34vh, 250px); }
.fig-calendrier{ border-collapse:collapse; font-size:clamp(1rem, 1.6vw, 1.25rem); }
.fig-calendrier caption{ padding-bottom:6px; font-size:1.15em; }
.fig-calendrier th, .fig-calendrier td{ width:2.5em; height:2em; text-align:center; border:1.5px solid var(--trait); font-weight:400; }
.fig-calendrier th{ background:var(--accent-fond); color:var(--accent); }
.fig-calendrier td:empty{ background:var(--surface); }
.fig-calendrier td.marque{ background:var(--action); color:#fff; font-weight:700; }
.fig-picto{ display:grid; gap:8px; font-size:clamp(1.05rem, 1.7vw, 1.3rem); }
.fig-picto div{ display:grid; grid-template-columns:5.5em 1fr; align-items:center; gap:10px; padding-bottom:8px; border-bottom:1.5px solid var(--trait); }
.fig-picto .jetons{ display:flex; gap:6px; min-height:30px; }
.fig-picto i{ display:inline-block; width:30px; height:30px; border-radius:50%; background:#3b82c4; vertical-align:middle; }
.fig-picto i.demi{ width:15px; border-radius:15px 0 0 15px; }
.fig-picto p{ margin:4px 0 0; color:var(--doux); }
.fig-picto p i{ width:22px; height:22px; }
.fig-tableau{ border-collapse:collapse; font-size:clamp(1.05rem, 1.7vw, 1.35rem); }
.fig-tableau th, .fig-tableau td{ border:1.5px solid var(--trait); padding:8px 18px; text-align:center; font-weight:400; }
.fig-tableau thead th{ background:var(--accent-fond); color:var(--accent); }
.fig-tableau tbody th{ background:var(--surface); text-align:left; }
.fig-suite{ display:flex; flex-wrap:wrap; justify-content:center; gap:12px; font-size:clamp(1.6rem, 3.4vw, 2.6rem); }
.fig-suite span{ min-width:1.9em; padding:6px 12px; text-align:center; border-radius:14px; background:var(--surface); }
.fig-suite .inconnu{ background:var(--fond); color:var(--action); box-shadow:inset 0 0 0 2.5px var(--action); }

.choix{ display:grid; grid-template-columns:1fr 1fr; gap:14px; }
.choix button{
  display:flex; align-items:center; gap:14px; min-height:76px; padding:10px 18px;
  border:2px solid var(--trait); border-radius:var(--rayon); background:var(--fond);
  font-size:clamp(1.2rem, 2vw, 1.6rem); text-align:left;
  transition:border-color .15s, background .15s, opacity .2s;
}
.choix button .lettre{
  flex:none; width:36px; height:36px; border-radius:50%; background:var(--surface); color:var(--doux);
  display:flex; align-items:center; justify-content:center; font-size:1.05rem;
}
.choix button:hover:not(:disabled){ border-color:#b9c0c9; }
.choix button.choisi{ border-color:var(--accent); background:var(--accent-fond); }
.choix button.choisi .lettre{ background:var(--accent); color:#fff; }
.choix button:disabled{ cursor:default; }
.choix button.retire{ opacity:.3; border-style:dashed; }
.choix.corrige button{ opacity:.45; }
.choix.corrige button.juste{ opacity:1; border-color:var(--ok); background:var(--ok-fond); }
.choix.corrige button.juste .lettre{ background:var(--ok); color:#fff; }
.choix.corrige button.faux{ opacity:1; border-color:var(--err); background:var(--err-fond); }
.choix.corrige button.faux .lettre{ background:var(--err); color:#fff; }

.message{ padding:12px 18px; border-radius:var(--rayon); font-size:clamp(1.05rem, 1.6vw, 1.25rem); }
.message.ok{ background:var(--ok-fond); color:var(--ok); text-align:center; font-size:clamp(1.2rem, 2vw, 1.5rem); }
.message.err{ background:var(--err-fond); }
.message.err b{ color:var(--err); }
.message.info{ background:var(--info-fond); color:var(--info); }
.message p{ margin:0; }
.message p + p{ margin-top:4px; }
.message .cadeau{ margin-top:8px; color:var(--info); }
.actions-jeu{ display:flex; flex-wrap:wrap; align-items:center; gap:12px; }
.actions-jeu .principal{ margin-left:auto; min-width:190px; }

/* Fraction en écriture superposée */
.frac{ display:inline-grid; grid-template-rows:auto auto auto; justify-items:center; vertical-align:middle; line-height:1.05; margin:0 .14em; font-size:.92em; }
.frac > span:nth-child(2){ width:100%; min-width:1.1em; height:.08em; min-height:2px; background:currentColor; border-radius:2px; margin:.08em 0; }

@media (max-width:820px), (orientation:portrait){
  .probleme.avec-figure .milieu{ grid-template-columns:1fr; }
  .figure svg{ height:min(28vh, 240px); }
}
@media (max-width:640px){
  .barre{ grid-template-columns:auto 1fr; padding:8px 10px 14px; row-gap:6px; }
  .piste{ grid-column:1 / -1; grid-row:2; justify-content:center; padding-bottom:12px; }
  .probleme{ padding:8px 14px 14px; gap:10px; }
  .choix{ gap:10px; }
  .choix button{ min-height:64px; padding:8px 12px; gap:10px; }
  .actions-jeu{ flex-wrap:wrap; }
  .actions-jeu .bouton{ padding:0 16px; }
  .actions-jeu .principal{ min-width:0; flex:1; }
}
@media (max-width:420px){ .choix{ grid-template-columns:1fr; } }

/* ---------- Calculatrice (aménagements) ---------- */
.note-reglage{ margin:8px 0 0 122px; color:var(--doux); font-size:.9rem; }
.calc{
  position:fixed; right:16px; bottom:84px; z-index:40; width:264px; padding:12px;
  border:1px solid var(--trait); border-radius:18px; background:var(--fond); box-shadow:0 12px 40px rgba(20,24,32,.22);
}
.calc-tete{ display:flex; align-items:center; justify-content:space-between; min-height:30px; color:var(--doux); font-size:.95rem; }
.calc-tete button{ width:34px; height:34px; border:0; border-radius:50%; background:transparent; color:var(--doux); font-size:1.5rem; line-height:1; }
.calc-tete button:hover{ background:var(--surface); }
.calc-ecran{
  margin:4px 0 10px; padding:6px 12px; border-radius:12px; background:var(--surface);
  text-align:right; font-size:2rem; line-height:1.3; font-variant-numeric:tabular-nums; overflow:hidden;
}
.calc-touches{ display:grid; grid-template-columns:repeat(4, 1fr); gap:7px; }
.calc-touches button{
  min-height:50px; border:0; border-radius:12px; background:var(--surface); font-size:1.4rem;
  box-shadow:0 2px 0 #d5d9df;
}
.calc-touches button:active{ transform:translateY(2px); box-shadow:none; }
.calc-touches .op{ background:var(--accent-fond); color:var(--accent); box-shadow:0 2px 0 #cfe3d0; }
.calc-touches .outil{ color:var(--doux); }
.calc-touches .egal{ grid-column:span 2; background:var(--action); color:#fff; box-shadow:0 2px 0 var(--action-fonce); }
/* Calculatrice ouverte sur un écran large : le problème se serre à gauche, rien n'est caché */
@media (min-width:900px){
  body.calc-ouverte .probleme{ margin:0 296px 0 0; max-width:none; width:auto; }
}
@media (max-width:480px){
  .note-reglage{ margin-left:0; }
  .calc{ left:8px; right:8px; bottom:8px; width:auto; }
  .piste li{ margin-left:8px; width:30px; height:30px; }
  .piste li + li::before{ width:8px; }
  .piste li.actuel{ width:42px; height:42px; }
}

/* ---------- Bilan ---------- */
.bilan{ min-height:100vh; padding:28px 18px; box-shadow:inset 0 6px 0 var(--accent); }
.carte.large{ max-width:860px; margin:0 auto; }
.bilan-tete{ display:flex; align-items:center; gap:18px; }
.bilan-tete img{ width:84px; height:84px; border-radius:18px; }
.bilan-tete p{ margin:2px 0 0; }
.chiffres{ display:grid; grid-template-columns:repeat(auto-fit, minmax(150px, 1fr)); gap:12px; margin:22px 0 6px; }
.chiffres div{ padding:14px 10px; border-radius:14px; background:var(--surface); text-align:center; }
.chiffres b{ display:block; font-size:2.2rem; line-height:1.15; color:var(--accent); font-weight:700; }
.chiffres span{ color:var(--doux); font-size:.95rem; }
.bilan h2{ margin:22px 0 10px; font-size:1.25rem; }
.domaines{ display:grid; grid-template-columns:auto 1fr auto; gap:8px 14px; align-items:center; }
.domaines .jauge{ height:12px; border-radius:6px; background:var(--surface); overflow:hidden; }
.domaines .jauge i{ display:block; height:100%; border-radius:6px; background:var(--accent); }
.revoir{ margin:0; padding-left:1.4em; }
.revoir li{ margin-bottom:10px; }
.revoir .reponse{ color:var(--ok); }
@media (max-width:640px){ .chiffres{ grid-template-columns:1fr 1fr; } }
.serie-defis{ display:inline-flex; align-items:center; gap:6px; min-height:44px; padding:0 16px; border-radius:22px; background:var(--info-fond); color:var(--info); font-size:1.1rem; white-space:nowrap; }
.serie-defis b{ font-weight:700; }
.panneau.defi p{ font-size:1.15rem; text-align:left; margin:12px 0 0; }
.panneau.defi img{ width:96px; height:96px; border-radius:20px; }

/* ---------- Fenêtres ---------- */
.voile{
  position:fixed; inset:0; z-index:50; display:flex; align-items:center; justify-content:center;
  padding:16px; background:rgba(20,24,32,.45);
}
.panneau{
  position:relative; width:100%; max-width:min(92vw, 640px); max-height:94vh; overflow:auto;
  padding:26px 28px; border-radius:20px; background:var(--fond); box-shadow:0 20px 60px rgba(20,24,32,.3); text-align:center;
}
.panneau.petit{ max-width:460px; }
.panneau h2{ font-size:1.7rem; }
.panneau .actions{ justify-content:center; }
.fermer{ position:absolute; top:10px; right:12px; width:44px; height:44px; border:0; border-radius:50%; background:transparent; color:var(--doux); font-size:1.9rem; line-height:1; }
.fermer:hover{ background:var(--surface); }
.qr-code{ width:min(64vh, 100%); margin:12px auto 0; }
.qr-code svg{ display:block; width:100%; height:auto; }
.qr-adresse{ margin:10px 0 0; font-size:.8rem; color:var(--doux); word-break:break-all; }

.confettis{ position:fixed; inset:0; width:100%; height:100%; pointer-events:none; z-index:60; }

/* ---------- Impression du bilan ---------- */
@media print{
  body{ font-size:12pt; }
  .accueil, .jeu, .voile, .bilan .actions{ display:none !important; }
  .bilan{ padding:0; box-shadow:none; min-height:0; }
  .carte{ border:0; box-shadow:none; padding:0; }
  .chiffres div, .domaines .jauge{ border:1px solid #bbb; }
  .revoir li{ break-inside:avoid; }
}
