/* =========================================================
   La Proportionnalité - CM2
   Palette ludique, gros boutons, contraste élevé, responsive
   ========================================================= */

:root {
  --violet:   #6c5ce7;
  --violet-d: #5341d6;
  --bleu:     #0984e3;
  --vert:     #00b894;
  --vert-d:   #00997b;
  --rouge:    #e74c3c;
  --orange:   #ff9f43;
  --jaune:    #ffd32a;
  --rose:     #fd79a8;
  --encre:    #2d3436;
  --gris:     #636e72;
  --gris-cl:  #dfe6e9;
  --fond:     #f4f3ff;
  --carte:    #ffffff;
  --ombre:    0 10px 30px rgba(108, 92, 231, .18);
  --ombre-sm: 0 4px 14px rgba(45, 52, 54, .12);
  --radius:   22px;
  --radius-sm:14px;
  --font: 'Trebuchet MS', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--encre);
  background:
    radial-gradient(1200px 600px at 10% -10%, #e7e3ff 0%, transparent 60%),
    radial-gradient(1000px 500px at 110% 10%, #d6f5ec 0%, transparent 55%),
    var(--fond);
  min-height: 100%;
  font-size: 18px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ---------- Confettis ---------- */
#confetti-canvas {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 9999;
}

/* ---------- Barre supérieure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 12px;
  padding: 10px clamp(12px, 3vw, 28px);
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--gris-cl);
}
.topbar-progress { flex: 1; display: flex; align-items: center; gap: 10px; }
.topbar-progress-bar {
  flex: 1; height: 14px; border-radius: 999px;
  background: var(--gris-cl); overflow: hidden;
}
.topbar-progress-bar span {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--vert), var(--bleu));
  border-radius: 999px; transition: width .5s ease;
}
.topbar-progress-label { font-weight: 700; color: var(--gris); font-size: .9rem; min-width: 40px; }
.topbar-stats { display: flex; align-items: center; gap: 8px; }
.chip {
  background: var(--fond); border: 2px solid var(--gris-cl);
  padding: 5px 12px; border-radius: 999px; font-weight: 700; font-size: .95rem;
  white-space: nowrap;
}
.chip-score { color: var(--orange); }
.chip-stars { color: var(--violet); }
.icon-btn {
  font-size: 1.3rem; background: var(--carte); border: 2px solid var(--gris-cl);
  width: 44px; height: 44px; border-radius: 14px; cursor: pointer;
  display: grid; place-items: center; transition: transform .15s, background .15s;
}
.icon-btn:hover { transform: translateY(-2px); background: var(--fond); }
.icon-btn:active { transform: scale(.92); }

/* ---------- Layout écrans ---------- */
#app { max-width: 1100px; margin: 0 auto; padding: clamp(14px, 3vw, 30px); }
.screen { display: none; animation: fade .35s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.screen-title { font-size: clamp(1.5rem, 4vw, 2.2rem); text-align: center; color: var(--violet-d); }
.screen-intro { text-align: center; color: var(--gris); margin: 6px 0 22px; }
.block-title { margin: 26px 0 12px; color: var(--violet-d); font-size: 1.2rem; }

/* ---------- Boutons ---------- */
.btn {
  font-family: var(--font); font-weight: 800; font-size: 1.05rem;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  padding: 14px 22px; color: #fff; transition: transform .15s, box-shadow .15s, filter .15s;
  box-shadow: var(--ombre-sm); display: inline-flex; align-items: center; gap: 8px;
  justify-content: center; min-height: 52px;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn:active { transform: translateY(0) scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary   { background: linear-gradient(135deg, var(--violet), var(--bleu)); }
.btn-secondary { background: linear-gradient(135deg, var(--orange), var(--rose)); }
.btn-accent    { background: linear-gradient(135deg, var(--vert), var(--bleu)); }
.btn-success   { background: linear-gradient(135deg, var(--vert), var(--vert-d)); }
.btn-ghost     { background: transparent; color: var(--gris); box-shadow: none; border: 2px solid var(--gris-cl); }
.btn-ghost:hover { background: var(--carte); }
.btn-hint      { background: linear-gradient(135deg, var(--jaune), var(--orange)); color: var(--encre); }
.btn-xl { font-size: 1.4rem; padding: 18px 40px; border-radius: var(--radius); min-height: 64px; }
.btn-block { width: 100%; }
.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(108,92,231,.45); } 50% { box-shadow: 0 0 0 16px rgba(108,92,231,0); } }

/* ---------- Accueil ---------- */
.home-hero {
  text-align: center; padding: clamp(20px, 6vh, 60px) 16px;
  position: relative; min-height: 86vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.home-title { font-size: clamp(2rem, 7vw, 3.4rem); color: var(--violet-d); line-height: 1.1; }
.badge-cm2 {
  background: var(--jaune); color: var(--encre); font-size: .45em;
  padding: 4px 14px; border-radius: 999px; vertical-align: middle;
  box-shadow: var(--ombre-sm); display: inline-block;
}
.home-subtitle { font-size: clamp(1rem, 3vw, 1.3rem); color: var(--gris); max-width: 540px; }
.mascot-lg { font-size: clamp(3.5rem, 14vw, 6rem); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-14px) rotate(3deg); } }
.home-progress { width: min(420px, 90%); }
.home-progress-track { height: 18px; border-radius: 999px; background: var(--gris-cl); overflow: hidden; }
.home-progress-track span { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--vert), var(--jaune)); transition: width .6s; }
.home-progress-text { margin-top: 8px; color: var(--gris); font-weight: 700; }
.floating-shapes { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.floating-shapes span {
  position: absolute; font-size: clamp(1.6rem, 4vw, 2.6rem); opacity: .55;
  animation: float 9s ease-in-out infinite;
}
.floating-shapes span:nth-child(1){ left: 8%;  top: 18%; animation-delay: 0s; }
.floating-shapes span:nth-child(2){ left: 84%; top: 22%; animation-delay: 1.2s; }
.floating-shapes span:nth-child(3){ left: 14%; top: 70%; animation-delay: 2.1s; }
.floating-shapes span:nth-child(4){ left: 78%; top: 66%; animation-delay: .6s; }
.floating-shapes span:nth-child(5){ left: 46%; top: 12%; animation-delay: 1.7s; }
.floating-shapes span:nth-child(6){ left: 52%; top: 80%; animation-delay: 2.6s; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-22px); } }

/* ---------- Grille des modules ---------- */
.module-grid {
  display: grid; gap: 18px;
  grid-template-columns: 1fr;
}
.module-card {
  background: var(--carte); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--ombre); cursor: pointer; position: relative; overflow: hidden;
  border: 3px solid transparent; transition: transform .18s, border-color .18s;
  display: flex; align-items: center; gap: 16px; text-align: left;
}
.module-card:hover { transform: translateY(-4px); border-color: var(--violet); }
.module-card .m-emoji { font-size: 2.6rem; flex-shrink: 0; }
.module-card .m-info { flex: 1; }
.module-card h3 { font-size: 1.15rem; color: var(--violet-d); }
.module-card p { color: var(--gris); font-size: .95rem; }
.module-card .m-bar { height: 10px; border-radius: 999px; background: var(--gris-cl); margin-top: 8px; overflow: hidden; }
.module-card .m-bar span { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--vert), var(--bleu)); transition: width .5s; }
.module-card .m-check { font-size: 1.6rem; }
.module-card.done { border-color: var(--vert); }
.module-card.locked { opacity: .55; filter: grayscale(.5); }
.hub-footer { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-top: 26px; }

/* ---------- Écran de module ---------- */
.module-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.module-title-h { font-size: clamp(1.2rem, 4vw, 1.7rem); color: var(--violet-d); text-align: center; flex: 1; }
.module-step { font-weight: 800; color: var(--gris); background: var(--carte); padding: 6px 12px; border-radius: 999px; box-shadow: var(--ombre-sm); }
.btn-back { white-space: nowrap; }
.step-track { height: 12px; border-radius: 999px; background: var(--gris-cl); overflow: hidden; margin-bottom: 22px; }
.step-track span { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--violet), var(--rose)); transition: width .4s; }

.module-body { background: var(--carte); border-radius: var(--radius); padding: clamp(18px, 4vw, 34px); box-shadow: var(--ombre); }
.q-lesson { font-size: 1.05rem; color: var(--encre); }
.q-lesson .lead { font-size: 1.2rem; font-weight: 700; color: var(--violet-d); margin-bottom: 10px; }
.q-question { font-size: clamp(1.2rem, 3.5vw, 1.5rem); font-weight: 800; text-align: center; margin: 6px 0 20px; color: var(--encre); }
.q-context { text-align: center; color: var(--gris); margin-bottom: 14px; }
.q-emoji-big { font-size: 3rem; text-align: center; display: block; margin-bottom: 6px; }

/* Tableaux de proportionnalité */
.prop-table-wrap { overflow-x: auto; margin: 14px 0 20px; }
table.prop {
  border-collapse: separate; border-spacing: 0; margin: 0 auto;
  border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--ombre-sm);
  min-width: min(520px, 100%);
}
table.prop th, table.prop td {
  padding: 14px 18px; text-align: center; font-size: 1.25rem; font-weight: 800;
  border: 2px solid #fff; min-width: 64px;
}
table.prop th { background: var(--violet); color: #fff; }
table.prop tr:nth-child(1) td { background: #eef0ff; color: var(--violet-d); }
table.prop tr:nth-child(2) td { background: #e6fbf4; color: var(--vert-d); }
table.prop td.reveal { animation: pop .4s ease; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
table.prop td.coef-hl { outline: 3px dashed var(--orange); outline-offset: -4px; }
.coef-note { text-align: center; color: var(--orange); font-weight: 800; margin: 6px 0 0; }

/* Champ de saisie réponse */
.answer-input {
  font-family: var(--font); font-size: 1.6rem; font-weight: 800; text-align: center;
  width: 130px; padding: 10px; border: 3px solid var(--violet); border-radius: 14px;
  color: var(--violet-d); background: #fff;
}
.answer-input:focus { outline: none; border-color: var(--bleu); box-shadow: 0 0 0 4px rgba(9,132,227,.18); }
.answer-cell { display: inline-flex; align-items: center; gap: 10px; }
.answer-unit { font-size: 1.3rem; font-weight: 800; color: var(--gris); }
.input-row { display: flex; flex-direction: column; align-items: center; gap: 16px; margin: 10px 0; }

/* Choix Oui/Non, Proportionnel/Non */
.choice-row { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin: 8px 0; }
.choice-btn {
  flex: 1 1 180px; max-width: 260px; font-size: 1.2rem; padding: 20px; border-radius: var(--radius);
  border: 3px solid var(--gris-cl); background: #fff; cursor: pointer; font-weight: 800; color: var(--encre);
  transition: transform .15s, border-color .15s, background .15s;
}
.choice-btn:hover { transform: translateY(-3px); border-color: var(--violet); }
.choice-btn.correct { background: #e6fbf4; border-color: var(--vert); }
.choice-btn.wrong   { background: #ffecea; border-color: var(--rouge); }

/* Boutons d'action sous l'exercice */
.action-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 22px; }

/* Explication / feedback inline */
.explain {
  margin-top: 18px; border-radius: var(--radius-sm); padding: 16px 18px;
  font-size: 1rem; line-height: 1.6; animation: fade .3s ease;
}
.explain.ok  { background: #e6fbf4; border: 2px solid var(--vert); color: var(--vert-d); }
.explain.no  { background: #fff4e6; border: 2px solid var(--orange); color: #b5651d; }
.explain h4 { margin-bottom: 6px; font-size: 1.1rem; }
.explain .step { margin: 4px 0; padding-left: 4px; }
.explain code { background: rgba(0,0,0,.06); padding: 2px 8px; border-radius: 8px; font-size: 1.05em; font-weight: 800; }

/* Difficulté / niveaux */
.level-pills { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }
.level-pill {
  border: 2px solid var(--gris-cl); background: #fff; padding: 8px 16px; border-radius: 999px;
  cursor: pointer; font-weight: 800; color: var(--gris); transition: all .15s;
}
.level-pill.active { background: var(--violet); color: #fff; border-color: var(--violet); }

/* ---------- Indice / mascotte ---------- */
.helper-row { display: flex; align-items: flex-start; gap: 14px; margin-top: 18px; flex-wrap: wrap; }
.mascot { font-size: 2.2rem; }
.mascot-bubble {
  display: flex; align-items: center; gap: 12px; background: #fff;
  border: 3px solid var(--jaune); border-radius: var(--radius); padding: 12px 18px;
  box-shadow: var(--ombre-sm); animation: pop .3s ease; flex: 1; min-width: 220px;
}
.mascot-bubble p { font-weight: 700; color: var(--encre); }

/* ---------- Timer mini-défi ---------- */
.timer-bar { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 14px; }
.timer-pill { font-size: 1.4rem; font-weight: 900; color: var(--rouge); background: #ffecea; padding: 8px 18px; border-radius: 999px; }

/* ---------- Tableau de bord ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.stat-card { background: var(--carte); border-radius: var(--radius); padding: 18px; text-align: center; box-shadow: var(--ombre-sm); }
.stat-ico { font-size: 2rem; }
.stat-num { font-size: 1.8rem; font-weight: 900; color: var(--violet-d); }
.stat-lbl { color: var(--gris); font-size: .9rem; font-weight: 700; }

.bar-chart { display: flex; align-items: flex-end; gap: 14px; height: 200px; background: var(--carte); border-radius: var(--radius); padding: 18px; box-shadow: var(--ombre-sm); }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-fill { width: 100%; max-width: 60px; border-radius: 10px 10px 0 0; background: linear-gradient(180deg, var(--violet), var(--bleu)); transition: height .6s ease; min-height: 4px; }
.bar-val { font-weight: 800; color: var(--violet-d); font-size: .9rem; }
.bar-lbl { font-size: 1.4rem; }

.badge-shelf { display: flex; gap: 16px; flex-wrap: wrap; }
.badge-item { background: var(--carte); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--ombre-sm); width: 150px; border: 3px solid var(--gris-cl); }
.badge-item.earned { border-color: var(--jaune); background: linear-gradient(180deg, #fffbe6, #fff); }
.badge-item .b-ico { font-size: 2.4rem; filter: grayscale(1); opacity: .4; }
.badge-item.earned .b-ico { filter: none; opacity: 1; animation: bob 2.5s ease-in-out infinite; }
.badge-item .b-name { font-weight: 800; margin-top: 6px; }
.badge-item .b-cond { font-size: .8rem; color: var(--gris); }

/* ---------- Écran final ---------- */
.final-card { background: var(--carte); border-radius: var(--radius); padding: clamp(24px, 6vw, 48px); box-shadow: var(--ombre); text-align: center; max-width: 640px; margin: 20px auto; }
.final-title { font-size: clamp(1.8rem, 6vw, 2.6rem); color: var(--vert-d); }
.final-sub { color: var(--gris); margin: 6px 0 22px; font-size: 1.1rem; }
.final-stats { display: flex; justify-content: center; gap: 26px; flex-wrap: wrap; margin-bottom: 18px; }
.final-stats div { display: flex; flex-direction: column; }
.final-stats b { font-size: 2rem; color: var(--violet-d); }
.final-stats span { color: var(--gris); font-weight: 700; }
.final-badge { display: inline-block; background: var(--jaune); color: var(--encre); font-weight: 900; padding: 10px 22px; border-radius: 999px; margin-bottom: 22px; box-shadow: var(--ombre-sm); }
.final-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--encre); color: #fff; padding: 14px 26px; border-radius: 999px;
  font-weight: 800; font-size: 1.1rem; box-shadow: var(--ombre); z-index: 9998; opacity: 0;
  transition: opacity .3s, transform .3s; pointer-events: none; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: linear-gradient(135deg, var(--vert), var(--vert-d)); }
.toast.no { background: linear-gradient(135deg, var(--orange), var(--rouge)); }

.hidden { display: none !important; }
.wave { display: inline-block; animation: wave 1.6s ease-in-out infinite; transform-origin: 70% 70%; }
@keyframes wave { 0%,60%,100% { transform: rotate(0); } 20% { transform: rotate(18deg); } 40% { transform: rotate(-8deg); } }

/* shake pour mauvaise réponse */
.shake { animation: shake .4s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }

/* ===================== RESPONSIVE ===================== */
/* Tablette : 2 colonnes */
@media (min-width: 600px) {
  .module-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-cards { grid-template-columns: repeat(3, 1fr); }
}
/* Ordinateur : mise en page étendue */
@media (min-width: 980px) {
  body { font-size: 19px; }
  .module-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-cards { grid-template-columns: repeat(6, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
