:root {
  --bg: #fff6e5;
  --bg2: #ffecc9;
  --ink: #2d2a4a;
  --ink-soft: #6b678f;
  --paper: #ffffff;
  --line: #ece3d2;
  --coral: #ff7a59;
  --coral-dark: #e85d3c;
  --teal: #1fa6a0;
  --sky: #dff1ff;
  --syl-a: #2463eb;
  --syl-b: #e0303a;
  --silent: #b7b3c9;
  --ok: #24b06c;
  --star: #ffc23c;
  --red-token: #ef4444;
  --blue-token: #3b82f6;
  --radius: 28px;
  --shadow: 0 10px 0 rgba(45, 42, 74, .08), 0 18px 40px rgba(45, 42, 74, .10);
  --ui: 'Fredoka', system-ui, sans-serif;
  --read: 'Andika', 'Fredoka', sans-serif;
  --cursive: 'Playwrite FR Moderne', 'Comic Sans MS', cursive;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--ui);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, #ffe2b8 0 120px, transparent 121px),
    radial-gradient(circle at 92% 95%, #ffd9cc 0 160px, transparent 161px),
    var(--bg);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
[hidden] { display: none !important; }
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; }

.screen { position: fixed; inset: 0; display: flex; }

/* ---------- Accueil ---------- */
#welcome, #goodbye { align-items: center; justify-content: center; padding: 16px; }
.welcome-card {
  background: var(--paper); border-radius: 40px; box-shadow: var(--shadow);
  padding: 36px 48px 28px; text-align: center; max-width: 560px; width: 100%;
}
.welcome-avatar { width: 220px; height: 240px; margin: -6px auto 4px; }
.welcome-avatar svg { width: 100%; height: 100%; }
.welcome-card h1 { font-size: 48px; margin: 6px 0 4px; font-weight: 700; }
.welcome-sub { font-size: 22px; color: var(--ink-soft); margin: 0 0 22px; }
.btn-giant {
  font-size: 34px; font-weight: 700; background: var(--coral); color: #fff;
  padding: 22px 48px; border-radius: 999px; box-shadow: 0 8px 0 var(--coral-dark);
  transition: transform .12s, box-shadow .12s; animation: pulse 2.2s ease-in-out infinite;
}
.btn-giant:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--coral-dark); }
.btn-giant:disabled { opacity: .6; animation: none; }
.btn-giant-icon { display: inline-block; margin-right: 8px; }
@keyframes pulse { 50% { transform: scale(1.04); } }
.checklist { list-style: none; padding: 0; margin: 22px 0 8px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.checklist li { background: var(--bg); padding: 6px 14px; border-radius: 999px; font-size: 15px; color: var(--ink-soft); }
.checklist li.ok { background: #dcf7e8; color: #157347; }
.checklist li.ko { background: #ffe1dc; color: #b42318; }
.welcome-foot { margin: 18px 0 0; font-size: 15px; display: flex; gap: 12px; justify-content: center; align-items: center; }
.link-parent { color: var(--ink-soft); }
.badge { background: #fff1c2; color: #8a5a00; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.big-emoji { font-size: 110px; animation: spin 3s ease-in-out infinite; }
@keyframes spin { 50% { transform: rotate(14deg) scale(1.1); } }
.upload-status { color: var(--ink-soft); min-height: 1.4em; }
.btn-soft {
  display: inline-block; background: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 18px; font-weight: 600; text-decoration: none; color: var(--ink);
  box-shadow: 0 4px 0 var(--line);
}
.btn-soft:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }

/* ---------- Classe ---------- */
#classroom { flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 12px 20px 6px; }
.journey { flex: 1; display: flex; align-items: center; gap: 0; min-width: 0; }
.j-step { display: flex; align-items: center; flex: 1; min-width: 0; }
.j-dot {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--paper); box-shadow: 0 3px 0 var(--line); font-size: 19px; transition: transform .3s;
}
.j-line { flex: 1; height: 6px; background: var(--line); margin: 0 4px; border-radius: 3px; }
.j-step.done .j-dot { background: #dcf7e8; }
.j-step.done .j-line { background: #9be3bd; }
.j-step.now .j-dot { background: var(--coral); color: #fff; transform: scale(1.18); box-shadow: 0 3px 0 var(--coral-dark); }
.j-step:last-child .j-line { display: none; }
.j-step:last-child { flex: none; }
.stars { display: flex; align-items: center; gap: 6px; background: var(--paper); padding: 6px 16px; border-radius: 999px; box-shadow: 0 4px 0 var(--line); font-size: 26px; font-weight: 700; }
.stars.bump { animation: bump .5s; }
@keyframes bump { 40% { transform: scale(1.3); } }
.adult-controls { display: flex; gap: 6px; opacity: .45; }
.adult-controls:hover { opacity: 1; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; background: var(--paper); font-size: 18px; box-shadow: 0 3px 0 var(--line); }

.room { flex: 1; display: flex; gap: 18px; padding: 8px 20px 20px; min-height: 0; }
.teacher-col { width: clamp(260px, 28vw, 380px); display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.avatar-wrap { flex: 1; min-height: 180px; display: flex; align-items: flex-end; justify-content: center; }
.avatar-wrap svg { width: 100%; height: 100%; max-height: 420px; overflow: visible; }
.caption {
  background: var(--paper); border-radius: 20px; padding: 10px 14px; font-size: 16px; line-height: 1.35;
  color: var(--ink-soft); min-height: 46px; max-height: 92px; overflow: hidden; box-shadow: 0 4px 0 var(--line);
  position: relative;
}
.caption::before { content: ''; position: absolute; top: -9px; left: 50%; border: 10px solid transparent; border-bottom-color: var(--paper); border-top: 0; transform: translateX(-50%); }
.caption:empty { visibility: hidden; }
.child-zone { display: flex; gap: 12px; align-items: stretch; }
.cam-wrap { position: relative; width: 46%; aspect-ratio: 4/3; border-radius: 20px; overflow: hidden; background: #2d2a4a; box-shadow: 0 4px 0 var(--line); }
.cam-wrap video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.rec-dot { position: absolute; top: 6px; left: 8px; background: #e0303a; color: #fff; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 8px; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .35; } }
.talk { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.btn-talk { position: relative; width: 92px; height: 92px; border-radius: 50%; background: var(--paper); box-shadow: 0 6px 0 var(--line); font-size: 42px; }
.btn-talk .mic-ring { position: absolute; inset: -6px; border-radius: 50%; border: 6px solid transparent; transition: border-color .2s; }
.btn-talk.listening { background: #dcf7e8; }
.btn-talk.listening .mic-ring { border-color: var(--ok); animation: ring 1.2s ease-out infinite; }
.btn-talk.call { background: var(--coral); animation: pulse 1.4s infinite; }
.btn-talk:disabled { opacity: .5; }
@keyframes ring { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.35); opacity: 0; } }
.heard { font-family: var(--read); font-size: 18px; min-height: 24px; color: var(--teal); text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-soft[disabled] { opacity: .4; }

/* ---------- Tableau ---------- */
.board {
  flex: 1; min-width: 0; background: var(--paper); border-radius: 36px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; padding: 28px; position: relative; overflow: hidden;
  background-image: radial-gradient(#f1e9d8 1.4px, transparent 1.4px); background-size: 26px 26px;
}
.board-stage { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 18px; min-height: 0; }
.board-answer { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; }
.board-answer:empty { display: none; }
.board.locked .tap { pointer-events: none; filter: saturate(.6); opacity: .75; }
.enter { animation: enter .45s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes enter { from { opacity: 0; transform: translateY(24px) scale(.94); } }
.prompt { font-size: 24px; color: var(--ink-soft); text-align: center; }
.empty-board { font-size: 90px; opacity: .25; }

/* Lettre */
.letter-row { display: flex; gap: 28px; align-items: flex-end; justify-content: center; flex-wrap: wrap; }
.letter-card { background: var(--sky); border-radius: 26px; padding: 6px 26px 2px; text-align: center; min-width: 140px; }
.letter-card .glyph { font-family: var(--read); font-size: clamp(90px, 13vw, 170px); line-height: 1.1; font-weight: 700; }
.letter-card.cursive .glyph { font-family: var(--cursive); font-weight: 400; font-size: clamp(70px, 10vw, 130px); line-height: 1.5; }
.letter-card .tag { font-size: 14px; color: var(--ink-soft); padding-bottom: 6px; }
.example { display: flex; align-items: center; gap: 16px; font-family: var(--read); font-size: 46px; }
.example .emoji { font-size: 70px; }
.example mark { background: none; color: var(--coral); font-weight: 700; }

/* Syllabes et mots */
.syl-row { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.syl-card {
  font-family: var(--read); font-size: clamp(56px, 7.5vw, 96px); font-weight: 700; background: var(--paper);
  border: 5px solid var(--line); border-radius: 26px; padding: 8px 30px 14px; min-width: 150px; text-align: center;
  box-shadow: 0 7px 0 var(--line); transition: transform .12s;
}
.syl-card:nth-child(odd) { color: var(--syl-a); }
.syl-card:nth-child(even) { color: var(--syl-b); }
.syl-card.hl { border-color: var(--star); background: #fff8df; transform: scale(1.06); }
.syl-card.tap:active, .choice:active, .num-key:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--line); }
.tap.picked { border-color: var(--teal) !important; background: #dff7f5 !important; }
.fusion { display: flex; align-items: center; gap: 18px; font-family: var(--read); font-size: 76px; font-weight: 700; }
.fusion .f-op { color: var(--ink-soft); font-size: 50px; }
.fusion .f-c { color: var(--syl-a); animation: slide-r 1.8s ease-in-out infinite alternate; }
.fusion .f-v { color: var(--syl-b); animation: slide-l 1.8s ease-in-out infinite alternate; }
@keyframes slide-r { to { transform: translateX(18px); } }
@keyframes slide-l { to { transform: translateX(-18px); } }
.word-emoji { font-size: 110px; line-height: 1; }
.word { display: flex; font-family: var(--read); font-size: clamp(70px, 10vw, 130px); font-weight: 700; gap: 2px; }
.syl { position: relative; padding: 0 4px 22px; }
.syl::after { content: ''; position: absolute; left: 8%; right: 8%; bottom: 4px; height: 18px; border: 4px solid currentColor; border-top: 0; border-radius: 0 0 50% 50% / 0 0 100% 100%; opacity: .55; }
.syl.a { color: var(--syl-a); }
.syl.b { color: var(--syl-b); }
.mute { color: var(--silent) !important; }

.sentence { display: flex; flex-wrap: wrap; gap: 10px 26px; justify-content: center; font-family: var(--read); font-size: clamp(44px, 5.6vw, 72px); font-weight: 700; max-width: 100%; }
.s-word { padding: 4px 10px; border-radius: 16px; transition: background .25s; display: flex; }
.s-word.hl { background: #fff1b8; box-shadow: 0 0 0 4px #ffe27a; }
.s-word .syl { padding-bottom: 16px; }
.s-word .syl::after { height: 12px; border-width: 3px; }
.scene { font-size: 90px; }

/* Choix */
.choices { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.choice {
  background: var(--paper); border: 5px solid var(--line); border-radius: 26px; padding: 14px 30px;
  font-family: var(--read); font-size: 46px; font-weight: 700; box-shadow: 0 7px 0 var(--line); min-width: 120px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.choice .c-emoji { font-size: 60px; line-height: 1; }
.choice.image { font-size: 18px; color: var(--ink-soft); font-family: var(--ui); font-weight: 500; }
.choice.image .c-emoji { font-size: 88px; }
.choice.letter { font-size: 80px; min-width: 140px; }

/* Maths */
.math-row { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; justify-content: center; }
.group { display: grid; grid-template-columns: repeat(5, auto); gap: 6px; padding: 12px; border-radius: 22px; background: var(--bg); font-size: 46px; line-height: 1; }
.group.b { background: #e5efff; }
.op { font-size: 70px; font-weight: 700; color: var(--ink-soft); }
.qmark { font-size: 80px; font-weight: 700; color: var(--coral); min-width: 70px; text-align: center; font-family: var(--read); }
.qmark.ans { color: var(--ok); }
.equation { font-family: var(--read); font-size: 72px; font-weight: 700; display: flex; gap: 18px; align-items: center; }
.tenframe { display: grid; grid-template-columns: repeat(5, 74px); grid-template-rows: repeat(2, 74px); border: 5px solid var(--ink); border-radius: 12px; background: var(--paper); }
.tenframe > div { border: 2.5px solid var(--ink); display: grid; place-items: center; }
.token { width: 54px; height: 54px; border-radius: 50%; animation: pop .35s cubic-bezier(.2, 1.6, .4, 1) both; }
.token.r { background: var(--red-token); box-shadow: inset 0 -6px 0 rgba(0,0,0,.18); }
.token.b { background: var(--blue-token); box-shadow: inset 0 -6px 0 rgba(0,0,0,.18); }
.token.ghost { background: none; border: 4px dashed #c9c3dc; }
@keyframes pop { from { transform: scale(0); } }
.count-grid { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; max-width: 620px; font-size: 76px; }
.count-grid span { animation: pop .4s both; }
.house { display: flex; flex-direction: column; align-items: center; }
.roof { width: 0; height: 0; border-left: 150px solid transparent; border-right: 150px solid transparent; border-bottom: 110px solid var(--coral); position: relative; }
.roof span { position: absolute; left: -40px; width: 80px; top: 34px; text-align: center; color: #fff; font-size: 64px; font-weight: 700; font-family: var(--read); }
.house-body { width: 260px; background: #fff3dc; border: 5px solid var(--coral); border-top: 0; border-radius: 0 0 14px 14px; }
.house-row { display: grid; grid-template-columns: 1fr 1fr; border-top: 3px solid #f6c8a8; }
.house-row:first-child { border-top: 0; }
.house-row div { text-align: center; font-family: var(--read); font-size: 46px; font-weight: 700; padding: 4px; }
.house-row div:first-child { border-right: 3px solid #f6c8a8; color: var(--red-token); }
.house-row div:last-child { color: var(--blue-token); }
.house-row .hole { color: var(--coral) !important; background: #ffe6dc; animation: blink 1.6s infinite; }
.numline { width: min(820px, 100%); }
.numline text { font-family: var(--read); font-size: 26px; font-weight: 700; fill: var(--ink); }
.vs { font-size: 40px; color: var(--ink-soft); }
.num-pad { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 760px; }
.num-key { width: 76px; height: 76px; border-radius: 22px; background: var(--paper); border: 4px solid var(--line); box-shadow: 0 6px 0 var(--line); font-size: 40px; font-weight: 700; font-family: var(--read); }

/* Ardoise */
.slate { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.slate-canvas-wrap { position: relative; width: min(760px, 100%); aspect-ratio: 2.1/1; border-radius: 24px; background: #2f5d50; box-shadow: inset 0 0 0 10px #8b5a2b, 0 6px 0 var(--line); overflow: hidden; }
.slate-canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.slate-btns { display: flex; gap: 14px; }
.slate-btns button { font-size: 22px; font-weight: 600; padding: 12px 24px; border-radius: 999px; box-shadow: 0 5px 0 var(--line); background: var(--paper); }
.slate-btns .done { background: var(--ok); color: #fff; box-shadow: 0 5px 0 #17824e; }

/* Pause / overlay */
.overlay { position: fixed; inset: 0; background: rgba(255, 246, 229, .94); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 20; gap: 10px; }
.overlay .ov-emoji { font-size: 150px; animation: bounce 1s ease-in-out infinite; }
.overlay .ov-title { font-size: 44px; font-weight: 700; }
.overlay .ov-timer { font-size: 80px; font-weight: 700; color: var(--coral); }
.overlay .ov-sub { font-size: 20px; color: var(--ink-soft); }
@keyframes bounce { 50% { transform: translateY(-30px) scale(1.05); } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; width: 100%; height: 100%; }
.fly-star { position: fixed; font-size: 90px; z-index: 31; pointer-events: none; transition: all 1s cubic-bezier(.5, -0.4, .6, 1); }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 14px; z-index: 50; font-size: 15px; max-width: 90vw; }

/* Avatar */
#avatar svg .head { transform-origin: 200px 300px; transform-box: view-box; }
.av-thought circle { animation: think 1.2s infinite; }
.av-thought circle:nth-child(2) { animation-delay: .2s; }
.av-thought circle:nth-child(3) { animation-delay: .4s; }
@keyframes think { 50% { transform: translateY(-6px); opacity: .5; } }
.av-ear path { animation: wave 1.2s infinite; }
.av-ear path:nth-child(2) { animation-delay: .3s; }
@keyframes wave { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }

/* Tablette en portrait */
@media (max-aspect-ratio: 1/1) {
  .room { flex-direction: column; }
  .teacher-col { width: 100%; flex-direction: row; height: 210px; flex: none; }
  .avatar-wrap { width: 170px; flex: none; min-height: 0; }
  .caption { flex: 1; max-height: none; align-self: center; }
  .caption::before { display: none; }
  .child-zone { width: 300px; flex: none; }
  .cam-wrap { width: 55%; aspect-ratio: auto; }
}
@media (max-height: 640px) {
  .syl-card { font-size: 54px; }
  .word { font-size: 80px; }
  .word-emoji { font-size: 70px; }
}
