:root {
  --bg: #fff8ec;
  --ink: #2d2a45;
  --muted: #6b6784;
  --card: #ffffff;
  --line: #ece4d3;
  --primary: #6c5ce7;
  --primary-dark: #5546d6;
  --accent: #ff9f43;
  --good: #1fa85a;
  --good-bg: #dff7e8;
  --bad: #d63c3c;
  --bad-bg: #fde4e4;
  --radius: 18px;
  --shadow: 0 4px 14px rgba(70, 60, 120, 0.1);
  font-size: 18px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  line-height: 1.45;
  min-height: 100vh;
}

h1, h2 { margin: 0 0 0.4em; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 0.6em; }
a { color: var(--primary-dark); }

.screen { max-width: 860px; margin: 0 auto; padding: 16px 16px 48px; display: flex; flex-direction: column; gap: 14px; }
.screen.narrow { max-width: 460px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card.center, .center { text-align: center; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.center { justify-content: center; }
.stack-v { display: flex; flex-direction: column; gap: 14px; }

.hint { color: var(--muted); }
.msg { min-height: 1.5em; color: var(--muted); font-weight: 600; }
.msg.error { color: var(--bad); }

/* --- Boutons ---------------------------------------------------------------- */
.btn {
  appearance: none;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  transition: transform 0.08s, background 0.15s;
}
.btn:hover { background: #f6f1ff; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--bad); border-color: #f2c4c4; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { padding: 6px 12px; min-height: 40px; font-size: 0.9rem; }
.btn.speak { background: #eef6ff; border-color: #cfe3fb; }
.btn:focus-visible, .tile:focus-visible, .key:focus-visible, .game-card:focus-visible, .list-head:focus-visible, .answer:focus-visible, .select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
button:disabled { cursor: default; }

/* --- Formulaires ---------------------------------------------------------------- */
.answer {
  font: inherit;
  font-size: 1.4rem;
  text-align: center;
  padding: 12px 14px;
  border: 3px solid var(--line);
  border-radius: 14px;
  width: 100%;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
.answer:focus { border-color: var(--primary); outline: none; }
.answer.small { font-size: 1rem; text-align: left; padding: 10px 12px; flex: 1 1 180px; }
.answer.pin { flex: 0 1 200px; }
.answer.area { font-size: 1rem; text-align: left; resize: vertical; margin-bottom: 10px; }

.select {
  font: inherit;
  padding: 12px;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
.select.small { font-size: 1rem; padding: 10px; flex: 1 1 220px; width: auto; }

.checks { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 12px; }
.check-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 2px solid var(--line); border-radius: 14px; cursor: pointer; background: #fff; }
.check-row:has(input:checked) { border-color: var(--primary); background: #f0edff; }
.check-row input { width: 1.5rem; height: 1.5rem; accent-color: var(--primary); flex: none; }
.check-name { flex: 1; font-weight: 700; }
.check-row small { color: var(--muted); }
.game-card.disabled { opacity: 0.45; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
form.card.inline-form { margin-bottom: 0; }

/* --- En-tête et accueil -------------------------------------------------------------- */
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.topbar h1 { margin: 0; }
.who { display: flex; align-items: center; gap: 10px; font-size: 1.2rem; }
.who small { display: block; color: var(--muted); font-weight: 400; }
.avatar { font-size: 2rem; line-height: 1; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 700;
  font-size: 0.95rem;
}

.streak-banner {
  background: #fff1d6;
  border: 2px solid #ffd993;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 700;
  text-align: center;
  margin: 0;
}
.streak-banner.done { background: var(--good-bg); border-color: #a9e5c1; }
.streak-banner.big { font-size: 1.3rem; animation: pop 0.6s ease both; }

.notice {
  background: #fff4e5;
  border: 2px solid #ffd7a6;
  border-radius: 14px;
  padding: 10px 14px;
  margin: 0;
}

.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.game-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-decoration: none;
  color: inherit;
  border: 3px solid transparent;
  transition: transform 0.1s, border-color 0.15s;
}
.game-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.game-card.featured { grid-column: 1 / -1; background: linear-gradient(135deg, #6c5ce7, #a29bfe); color: #fff; }
.game-card.featured small { color: #efeaff; }
.game-emoji { font-size: 2.4rem; }
.game-text { display: flex; flex-direction: column; }
.game-text small { color: var(--muted); }

/* --- Séance de jeu ------------------------------------------------------------------------ */
.game-head { display: flex; align-items: center; gap: 12px; }
.progress { flex: 1; height: 14px; background: #e9e2f9; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 999px; transition: width 0.4s; }
.counter { font-weight: 700; min-width: 3em; text-align: right; }
.game-title { text-align: center; font-size: 1.2rem; color: var(--muted); margin: 0; }

.stage {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 16px;
  min-height: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
.stage > * { max-width: 100%; }
.prompt-area { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.diff-area { min-height: 3.2rem; }
.answer-row { display: flex; gap: 10px; width: 100%; max-width: 520px; }
.answer-row .answer { flex: 1; }

.big-icon { font-size: 3.4rem; line-height: 1; }
.big-word { font-size: clamp(2rem, 9vw, 3.4rem); font-weight: 800; color: var(--primary-dark); letter-spacing: 0.03em; word-break: break-word; }
.speak-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.sentence { font-style: italic; color: var(--muted); }

.timer { width: min(320px, 80%); height: 10px; background: #e9e2f9; border-radius: 999px; overflow: hidden; }
.timer-fill { height: 100%; width: 100%; background: var(--accent); transition-property: transform; transition-timing-function: linear; transform-origin: left; }
.timer-fill.run { transform: scaleX(0); }

.diff { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.dl { min-width: 1.6em; padding: 4px 6px; border-radius: 8px; font-size: 1.6rem; font-weight: 800; }
.dl.ok { background: var(--good-bg); color: var(--good); }
.dl.bad { background: var(--bad-bg); color: var(--bad); }
.dl.miss { background: var(--bad-bg); color: var(--bad); opacity: 0.7; }

.feedback { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 30px; }
.feedback.good .praise { font-size: 1.8rem; font-weight: 800; color: var(--good); animation: pop 0.5s ease both; }
.feedback.bad .big-word { color: var(--bad); }

/* Mots mélangés / à trous */
.slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.slot, .bl {
  width: 2.3rem;
  height: 3rem;
  border: 3px dashed #cfc6ee;
  border-radius: 10px;
  background: #faf8ff;
  font: inherit;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.slot.filled { border-style: solid; border-color: var(--primary); background: #f0edff; cursor: pointer; }
.slots.good .slot { border-color: var(--good); background: var(--good-bg); }
.slots.bad { animation: shake 0.4s; }
.slots.bad .slot { border-color: var(--bad); background: var(--bad-bg); }

.tiles, .choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.tile {
  min-width: 3.2rem;
  height: 3.4rem;
  padding: 0 12px;
  border: 0;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-size: 1.7rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--primary-dark);
}
.tile:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 var(--primary-dark); }
.tile:disabled { opacity: 0.25; box-shadow: none; }
.tile.wrong { background: var(--bad); box-shadow: none; opacity: 0.5; }

.blank-word { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.bl { border: 0; background: transparent; width: auto; min-width: 1.1rem; font-size: 2.4rem; }
.bl.hole { width: 2.4rem; border: 3px dashed #cfc6ee; background: #faf8ff; }
.bl.hole.current { border-color: var(--accent); background: #fff4e5; animation: blink 1s infinite; }
.bl.hole.done { border: 3px solid var(--good); background: var(--good-bg); color: var(--good); animation: none; }

/* Attrape le bon mot */
.arcade {
  position: relative;
  width: 100%;
  height: 340px;
  overflow: hidden;
  border-radius: var(--radius);
  background: linear-gradient(#dff1ff, #f4fbff);
}
.fall {
  position: absolute;
  top: -64px;
  width: 44%;
  padding: 10px 6px;
  border: 3px solid #bcd9f5;
  border-radius: 14px;
  background: #fff;
  font: inherit;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
  animation-name: fall;
  animation-timing-function: linear;
  animation-fill-mode: both;
  word-break: break-word;
}
.fall.good { border-color: var(--good); background: var(--good-bg); animation-play-state: paused; }
.fall.wrong { border-color: var(--bad); background: var(--bad-bg); animation-play-state: paused; opacity: 0.6; }
.fall.gone { display: none; }
.arcade.calm { height: auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; padding: 12px; }
.arcade.calm .fall { position: static; width: auto; animation: none; }

/* Mots cachés */
.wsgrid { display: grid; gap: 4px; width: 100%; margin: 0 auto; }
.wscell {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 2px solid #e1d9f7;
  border-radius: 8px;
  background: #faf8ff;
  font: inherit;
  font-size: clamp(0.95rem, 4.2vw, 1.4rem);
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
}
.wscell.sel { background: var(--accent); border-color: var(--accent); color: #fff; }
.wscell.hint { border-color: var(--accent); background: #fff4e5; animation: blink 1s infinite; }
.wscell.found { background: var(--good); border-color: var(--good); color: #fff; }

/* Détective des fautes */
.sentence-line { font-size: 1.5rem; line-height: 2.3; margin: 4px 0; }
.tok { font: inherit; padding: 0 4px; margin: 0 1px; border: 0; border-bottom: 3px dashed #cfc6ee; border-radius: 6px; background: transparent; color: inherit; cursor: pointer; }
.tok:hover:not(:disabled) { background: #f0edff; }
.tok.wrong { opacity: 0.4; border-bottom-color: transparent; }
.tok-static { padding: 0 4px; }
.tok.bad-found { background: var(--bad-bg); color: var(--bad); border-bottom: 3px solid var(--bad); cursor: default; font-weight: 800; }

/* Pendu amical */
.balloons { display: flex; gap: 6px; justify-content: center; font-size: 2rem; min-height: 2.4rem; }
.balloon.popped { opacity: 0.35; font-size: 1.5rem; }
.kb { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.kb-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.tile.key-l { min-width: 2.4rem; height: 2.8rem; font-size: 1.25rem; padding: 0 6px; border-radius: 10px; }
.tile.key-l.hit { background: var(--good); box-shadow: none; opacity: 0.6; }
.tile.key-l.miss { background: var(--bad); box-shadow: none; opacity: 0.4; }
.bl.hole.lost { border: 3px solid var(--bad); background: var(--bad-bg); color: var(--bad); }

/* --- Résultats -------------------------------------------------------------------------------- */
.results { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.score { color: var(--muted); }
.stars-gained { font-size: 1.8rem; font-weight: 800; color: var(--accent); margin: 0; }
.new-badges { display: flex; flex-direction: column; align-items: center; gap: 8px; }

/* --- Progression ----------------------------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; align-items: center; }
.stat strong { font-size: 1.6rem; }
.stat span { color: var(--muted); font-size: 0.9rem; }

.stack { display: flex; height: 22px; border-radius: 999px; overflow: hidden; background: #eee; }
.seg.mastered, .dot.mastered { background: var(--good); }
.seg.learning, .dot.learning { background: var(--accent); }
.seg.fresh, .dot.fresh { background: #cfcfdc; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 14px; padding: 0; margin: 10px 0 0; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; }

.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; max-width: 420px; }
.cal-head { text-align: center; font-weight: 700; color: var(--muted); font-size: 0.85rem; }
.cal-day { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: #f3effa; font-size: 0.85rem; color: var(--muted); }
.cal-day.played { background: var(--good); color: #fff; font-weight: 800; }
.cal-day.today { outline: 3px solid var(--accent); outline-offset: 1px; }
.cal-day.future { opacity: 0.35; }

.chart { display: flex; align-items: flex-end; gap: 4px; height: 150px; padding-top: 18px; }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px; min-width: 0; }
.bar { width: 100%; background: var(--primary); border-radius: 6px 6px 0 0; }
.bar.empty { background: #e5e0f3; }
.bar-val { font-size: 0.75rem; font-weight: 700; min-height: 1em; }
.bar-label { font-size: 0.7rem; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip.word { background: #f3effa; border-color: #e1d9f7; }
.chip-x { border: 0; background: transparent; color: var(--bad); font-size: 1.1rem; font-weight: 800; cursor: pointer; padding: 0 2px; }

.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.badge { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding: 12px 8px; border-radius: 14px; background: #f4f2f8; color: var(--muted); }
.badge small { font-size: 0.78rem; }
.badge.earned { background: #fff1d6; color: var(--ink); border: 2px solid #ffd993; }
.badge-emoji { font-size: 2.2rem; }
.badge.pop { animation: pop 0.6s ease both; }

/* --- Listes et espace adulte ---------------------------------------------------------------------------- */
.lists { display: flex; flex-direction: column; gap: 12px; }
.list { padding: 0; }
.list-head { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 10px; width: 100%; padding: 16px 18px; cursor: pointer; flex-wrap: wrap; }
.list-head strong { flex: 1 1 140px; }
.tag { background: #eef6ff; border-radius: 999px; padding: 2px 10px; font-size: 0.85rem; font-weight: 700; }
.count { color: var(--muted); font-size: 0.9rem; }
.chev { color: var(--muted); }
.panel { padding: 0 18px 18px; }

.tab { text-decoration: none; padding: 8px 14px; border-radius: 12px; font-weight: 700; color: var(--ink); background: #fff; border: 2px solid var(--line); }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.child { display: flex; flex-direction: column; gap: 10px; }

.avatars { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.avatar-opt { font-size: 1.7rem; background: #fff; border: 3px solid var(--line); border-radius: 12px; padding: 2px 8px; cursor: pointer; }
.avatar-opt.on { border-color: var(--primary); background: #f0edff; }

/* --- Connexion ------------------------------------------------------------------------------------------------ */
.login { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.login > * { max-width: 100%; }
.logo { width: 76px; height: 76px; border-radius: 22px; background: var(--primary); color: #fff; font-size: 2.2rem; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.pin-dots { display: flex; gap: 14px; margin: 6px 0; }
.pin-dot { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--primary); }
.pin-dot.on { background: var(--primary); }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 10px; }
.key { height: 64px; font: inherit; font-size: 1.6rem; font-weight: 800; border: 0; border-radius: 16px; background: #f0edff; color: var(--primary-dark); cursor: pointer; box-shadow: 0 3px 0 #d9d3f5; }
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 #d9d3f5; }
.link-small { font-size: 0.9rem; color: var(--muted); }
.shake { animation: shake 0.4s; }

/* --- Notifications et animations ----------------------------------------------------------------------------------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 140%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 14px;
  font-weight: 700;
  max-width: 90vw;
  transition: transform 0.25s, opacity 0.25s;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.error { background: var(--bad); }
#toast.ok { background: var(--good); }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

@keyframes fall { from { transform: translateY(0); } to { transform: translateY(440px); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 70% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); } }
@keyframes blink { 50% { background: #ffe2b8; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media (max-width: 480px) {
  :root { font-size: 17px; }
  .keypad { grid-template-columns: repeat(3, 70px); }
  .slot { width: 2rem; height: 2.7rem; }
  .stage { padding: 16px 10px; }
}
