:root {
  --fond: #eef2ff;
  --fond2: #fdf4ff;
  --carte: #ffffff;
  --texte: #1e1b4b;
  --doux: #6366f1;
  --gris: #64748b;
  --principal: #4f46e5;
  --principal-fonce: #3730a3;
  --vert: #16a34a;
  --rouge: #dc2626;
  --or: #f59e0b;
  --ombre: 0 6px 0 rgba(30, 27, 75, .12), 0 10px 24px rgba(30, 27, 75, .10);
  --rayon: 22px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #1e1b4b; --fond2: #2e1065; --carte: #312e81; --texte: #eef2ff;
    --gris: #c7d2fe; --doux: #a5b4fc;
    --ombre: 0 6px 0 rgba(0,0,0,.3), 0 10px 24px rgba(0,0,0,.3);
  }
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--texte);
  background: linear-gradient(160deg, var(--fond), var(--fond2));
  background-attachment: fixed;
  overscroll-behavior: none;
}
#app { max-width: 560px; margin: 0 auto; min-height: 100%; padding: 0 16px 24px; }
h1 { font-size: 2.2rem; margin: .2em 0; text-align: center; color: var(--principal); }
h2 { margin: .3em 0; }
.petit-texte { color: var(--gris); font-size: .9rem; margin: .2em 0; }
.sous-titre { text-align: center; font-size: 1.15rem; }

/* Barre du haut */
.barre { display: flex; align-items: center; gap: 8px; padding: 12px 0; position: sticky; top: 0; z-index: 5; }
.compteurs { display: flex; gap: 8px; flex: 1; }
.pastille { background: var(--carte); border-radius: 999px; padding: 6px 12px; box-shadow: var(--ombre); font-size: .95rem; white-space: nowrap; }
.pastille .piece { color: var(--or); }
.pastille.llm { font-size: .8rem; opacity: .85; }
.pastille.anim { animation: pop .5s; }
.btn-icone { border: 0; background: var(--carte); border-radius: 50%; width: 42px; height: 42px; font-size: 1.2rem; box-shadow: var(--ombre); cursor: pointer; }

/* Boutons */
.btn { border: 0; border-radius: 16px; padding: 14px 20px; font: inherit; font-weight: bold; font-size: 1.05rem; cursor: pointer; box-shadow: var(--ombre); transition: transform .1s; }
.btn:active { transform: translateY(3px); }
.btn.principal { background: var(--principal); color: #fff; }
.btn.secondaire { background: var(--carte); color: var(--texte); }

/* Écrans */
.ecran { display: none; animation: entree .35s ease-out; }
.ecran.actif { display: block; }
@keyframes entree { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.form-prenom { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.form-prenom input { font: inherit; font-size: 1.3rem; padding: 14px; border-radius: 16px; border: 3px solid var(--doux); text-align: center; background: var(--carte); color: var(--texte); }

/* Robot Calculo (CSS pur) */
.robot-zone { display: flex; justify-content: center; padding: 18px 0 6px; }
.robot-zone.petit { padding: 0; transform: scale(.6); transform-origin: left center; width: 72px; }
.robot { position: relative; width: 110px; height: 120px; animation: flotte 3s ease-in-out infinite; }
.robot::before { /* tête */
  content: ""; position: absolute; left: 10px; top: 18px; width: 90px; height: 70px;
  background: linear-gradient(#a5b4fc, #818cf8); border-radius: 26px; box-shadow: inset 0 -6px 0 rgba(0,0,0,.12);
}
.robot::after { /* antenne */
  content: ""; position: absolute; left: 51px; top: 0; width: 8px; height: 20px; background: #6366f1; border-radius: 4px;
  box-shadow: 0 -6px 0 4px #f472b6;
}
.robot .yeux { position: absolute; left: 26px; top: 40px; width: 58px; height: 18px; display: flex; justify-content: space-between; z-index: 1; }
.robot .yeux i { width: 18px; height: 18px; background: #1e1b4b; border-radius: 50%; animation: cligne 4s infinite; }
.robot .bouche { position: absolute; left: 40px; top: 64px; width: 30px; height: 10px; border-bottom: 4px solid #1e1b4b; border-radius: 0 0 20px 20px; z-index: 1; }
.robot .corps { position: absolute; left: 25px; top: 88px; width: 60px; height: 30px; background: #6366f1; border-radius: 10px 10px 16px 16px; }
.robot .tenue { position: absolute; z-index: 2; font-size: 38px; line-height: 1; left: 50%; transform: translateX(-50%); top: -22px; }
.robot.content { animation: saute .6s; }
.robot.content .bouche { height: 16px; }
.robot.triste .bouche { border-bottom: 0; border-top: 4px solid #1e1b4b; border-radius: 20px 20px 0 0; top: 70px; }
.robot.triste { animation: secoue .4s; }
.robot.reflechit::after { animation: clignote .6s infinite alternate; }
@keyframes flotte { 50% { transform: translateY(-6px); } }
@keyframes cligne { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
@keyframes saute { 30% { transform: translateY(-26px) rotate(-6deg); } 60% { transform: translateY(0) rotate(4deg); } }
@keyframes secoue { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes clignote { to { box-shadow: 0 -6px 0 4px #facc15; } }

/* Carte des niveaux */
.entete-carte { display: flex; align-items: center; gap: 8px; }
.entete-carte > div:last-child { flex: 1; }
.progression-globale, .chrono { height: 14px; background: rgba(99,102,241,.18); border-radius: 999px; overflow: hidden; }
#barre-globale { height: 100%; width: 0; background: linear-gradient(90deg, var(--or), #f472b6); border-radius: 999px; transition: width .8s; }
.actions-carte { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.actions-carte .btn { flex: 1; padding: 12px 10px; font-size: .95rem; min-width: 30%; }
.niveaux { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.niveau { background: var(--carte); border-radius: var(--rayon); padding: 14px; box-shadow: var(--ombre); cursor: pointer; position: relative; border: 0; text-align: left; font: inherit; color: inherit; width: 100%; animation: entree .4s both; }
.niveau .num { font-size: 1.6rem; font-weight: bold; color: var(--principal); }
.niveau .nom { font-weight: bold; }
.niveau .desc { font-size: .8rem; color: var(--gris); min-height: 2.2em; }
.niveau .mini-etoiles { margin-top: 4px; letter-spacing: 2px; }
.niveau.verrouille { opacity: .55; cursor: not-allowed; filter: grayscale(.8); }
.niveau.verrouille::after { content: "🔒"; position: absolute; right: 12px; top: 12px; font-size: 1.3rem; }
.niveaux li.large { grid-column: 1 / -1; }
.niveau { cursor: default; }
.niveau.valide { outline: 3px solid var(--vert); }
.sous-niveaux { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.sous { display: flex; justify-content: space-between; align-items: center; gap: 4px; border: 0; border-radius: 12px;
  padding: 8px 10px; font: inherit; font-size: .85rem; font-weight: bold; cursor: pointer; color: inherit;
  background: rgba(99,102,241,.12); touch-action: manipulation; }
.sous:hover { background: rgba(99,102,241,.25); }
.sous.fait { background: rgba(34,197,94,.2); }
.sous .mini-etoiles { margin: 0; letter-spacing: 0; font-size: .75rem; white-space: nowrap; }
.niveau.verrouille .sous { cursor: not-allowed; }
.niveau.boss .sous { background: rgba(255,255,255,.55); color: #1e1b4b; }
.niveau.boss { background: linear-gradient(135deg, #fde68a, #f9a8d4); color: #1e1b4b; }
.niveau.boss .desc { color: #4c1d95; }

/* Jeu */
.jeu-haut { display: flex; justify-content: space-between; align-items: baseline; }
.jeu-titre { font-weight: bold; font-size: 1.1rem; }
.progression-niveau { display: flex; gap: 6px; margin: 8px 0; }
.progression-niveau i { flex: 1; height: 10px; border-radius: 6px; background: rgba(99,102,241,.2); transition: background .3s; }
.progression-niveau i.ok { background: var(--vert); }
.progression-niveau i.ko { background: var(--rouge); }
.progression-niveau i.cours { background: var(--doux); animation: clignote2 1s infinite alternate; }
@keyframes clignote2 { to { opacity: .4; } }
#chrono-barre { height: 100%; width: 100%; background: linear-gradient(90deg, var(--vert), var(--or)); border-radius: 999px; }
#chrono-barre.urgent { background: var(--rouge); }

.scene { display: flex; align-items: center; gap: 4px; min-height: 120px; }
.scene .robot-zone { padding: 0; flex: 0 0 auto; transform: scale(.75); }
.bulle { flex: 1; background: var(--carte); border-radius: 18px; padding: 12px 14px; box-shadow: var(--ombre); position: relative; font-size: 1rem; min-height: 54px; display: flex; align-items: center; }
.bulle::before { content: ""; position: absolute; left: -10px; top: 50%; transform: translateY(-50%); border: 10px solid transparent; border-right-color: var(--carte); border-left: 0; }
.bulle.attente #bulle-texte::after { content: " …"; animation: clignote2 .6s infinite alternate; }
#bulle-texte { animation: entree .3s; }

.carte-question { background: var(--carte); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 18px; text-align: center; margin: 12px 0; position: relative; }
.carte-question.juste { animation: pop .5s; outline: 4px solid var(--vert); }
.carte-question.faux { animation: secoue .4s; outline: 4px solid var(--rouge); }
.operation { font-size: 3rem; font-weight: bold; letter-spacing: 2px; }
.saisie { font-size: 2.4rem; font-weight: bold; min-height: 1.3em; color: var(--principal); }
.saisie.correction { color: var(--rouge); }
.combo { position: absolute; top: -14px; right: 14px; background: var(--or); color: #fff; font-weight: bold; border-radius: 999px; padding: 4px 10px; animation: pop .4s; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.15); } 100% { transform: scale(1); } }

.clavier { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.clavier button, .choix button { border: 0; border-radius: 16px; background: var(--carte); color: var(--texte); font: inherit; font-size: 1.7rem; font-weight: bold; padding: 14px 0; box-shadow: var(--ombre); cursor: pointer; touch-action: manipulation; }
.clavier button:active, .choix button:active { transform: translateY(3px); box-shadow: none; }
.clavier .touche-ok { background: var(--vert); color: #fff; }
.clavier .touche-sec { background: #fecaca; color: #7f1d1d; }
.choix { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.choix button { font-size: 2rem; padding: 22px 0; }
.choix button.bon { background: var(--vert); color: #fff; }
.choix button.mauvais { background: var(--rouge); color: #fff; }

/* Résultat */
#ecran-resultat { text-align: center; padding-top: 10px; }
.grandes-etoiles { font-size: 3.4rem; letter-spacing: 8px; min-height: 1.3em; }
.grandes-etoiles span { display: inline-block; opacity: .2; filter: grayscale(1); }
.grandes-etoiles span.gagnee { animation: etoile .6s both; opacity: 1; filter: none; }
@keyframes etoile { 0% { transform: scale(0) rotate(-180deg); } 70% { transform: scale(1.4) rotate(20deg); } 100% { transform: scale(1); } }
.res-message { font-size: 1.35rem; font-weight: bold; color: var(--violet, #6c4ad6); max-width: 34rem; min-height: 3.4em; margin: 0.4rem auto 0.8rem; line-height: 1.35; }
.btn-lien { background: none; border: none; color: inherit; opacity: 0.8; font: inherit; font-size: 0.9rem; padding: 0.2rem 0; cursor: pointer; text-decoration: underline; }
.res-score { font-size: 1.3rem; font-weight: bold; }
.res-gains { font-size: 1.15rem; color: var(--or); font-weight: bold; }
.res-badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.revision { background: var(--carte); border-radius: var(--rayon); padding: 10px 14px; box-shadow: var(--ombre); margin: 12px 0; text-align: left; }
.revision:empty { display: none; }
.revision li { margin: 4px 0; }
.actions-res { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.actions-res .btn { flex: 1; }

/* Boutique & badges */
.grille-boutique, .grille-badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0 18px; }
.article, .badge { background: var(--carte); border-radius: 18px; padding: 12px 6px; text-align: center; box-shadow: var(--ombre); border: 3px solid transparent; font: inherit; color: inherit; cursor: pointer; }
.article .ico, .badge .ico { font-size: 2.2rem; display: block; }
.article .prix { font-size: .85rem; font-weight: bold; color: var(--or); }
.article.porte { border-color: var(--vert); }
.article.trop-cher { opacity: .5; }
.badge { cursor: default; }
.badge.non { opacity: .35; filter: grayscale(1); }
.badge .nom { font-size: .8rem; font-weight: bold; display: block; }
.badge .quoi { font-size: .7rem; color: var(--gris); }
.badge-gagne { background: var(--carte); border-radius: 999px; padding: 6px 12px; box-shadow: var(--ombre); animation: pop .6s; }

/* Confettis, toast */
#confettis { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
#confettis i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: tombe linear forwards; }
@keyframes tombe { to { transform: translateY(110vh) rotate(720deg); } }
.piece-vol { position: fixed; z-index: 21; color: var(--or); font-size: 1.6rem; font-weight: bold; pointer-events: none; animation: vole .9s ease-in forwards; }
@keyframes vole { to { transform: translate(var(--dx), var(--dy)) scale(.5); opacity: .2; } }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 120px); background: var(--texte); color: var(--fond); padding: 12px 18px; border-radius: 16px; font-weight: bold; transition: transform .35s; z-index: 30; max-width: 90vw; text-align: center; }
.toast.visible { transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .niveaux { grid-template-columns: repeat(2, 1fr); }
  .operation { font-size: 3.6rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* Voix de Calculo : la bouche bouge pendant qu'il « parle » ; prénom mis en valeur */
.robot.parle .bouche { animation: parle .14s infinite alternate; }
@keyframes parle { from { height: 4px; border-radius: 0 0 8px 8px; } to { height: 16px; border-radius: 0 0 20px 20px; } }
.prenom { color: var(--or, #f59e0b); text-shadow: 0 0 8px rgba(245,158,11,.6); animation: pop .5s; display: inline-block; }
.bilan-calculo { display: flex; align-items: center; justify-content: center; gap: 4px; }
.bilan-calculo .robot-zone { padding: 0; transform: scale(.65); flex: 0 0 auto; margin: -16px -18px; }
.bilan-calculo .res-message { margin: 0; text-align: left; }
