/* KLEO front — palette alignée sur le chat hébergé n8n existant */
:root {
  --primary: #5b6cff;
  --primary-dark: #4a59e0;
  --secondary: #28c39a;
  --bg: #eef1fb;
  --bubble-bot-bg: #ffffff;
  --bubble-bot-border: #e6e9f5;
  --text: #1f2440;
  --muted: #7a82a8;
  --radius: 1.1rem;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: var(--app-height, 100dvh);
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- Écran de choix d'élève ---------- */
.picker {
  /* épinglé au viewport visible (suit le clavier iOS via --app-offset) */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--app-height, 100dvh);
  transform: translateY(var(--app-offset, 0px));
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  padding: 1rem;
}

.picker-card {
  background: #fff;
  border-radius: 1.5rem;
  box-shadow: 0 8px 30px rgba(31, 36, 64, 0.10);
  padding: 2rem 2.2rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  margin: auto; /* centré si petit, scrollable si grand */
}

.picker-card h1 {
  margin: 0;
  font-size: 2.2rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tagline {
  margin: 0.3rem 0 1.4rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.picker-question {
  font-weight: 600;
  margin-bottom: 0.8rem;
}

.student-list {
  display: grid;
  gap: 0.7rem;
}

.student-btn {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  padding: 0.8rem 1rem;
  border: 1px solid var(--bubble-bot-border);
  border-radius: var(--radius);
  background: #fbfcff;
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.student-btn:hover, .student-btn:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 2px 12px rgba(91, 108, 255, 0.18);
  transform: translateY(-1px);
}

.student-emoji { font-size: 1.6rem; }

.student-info { flex: 1; min-width: 0; }

.student-name { font-weight: 700; }

.student-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.student-delete {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
}
.student-delete:hover {
  background: #fff2f2;
  color: #d23c3c;
}

.new-student-btn {
  width: 100%;
  margin-bottom: 1.3rem;
  padding: 0.8rem 1rem;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(91, 108, 255, 0.3);
  transition: transform 0.1s, box-shadow 0.15s;
}
.new-student-btn:hover {
  box-shadow: 0 4px 16px rgba(91, 108, 255, 0.4);
  transform: translateY(-1px);
}

.picker-loading {
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
}

.guardian-link {
  display: inline-block;
  margin-top: 1.4rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
  border-bottom: 1px dashed var(--muted);
  padding-bottom: 1px;
}
.guardian-link:hover { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Chat ---------- */
.chat {
  /* épinglé au viewport visible : sur iOS le clavier scrolle le layout
     viewport ; on suit la zone visible via --app-offset (offsetTop) au lieu
     de laisser le composer remonter avec du vide en dessous. */
  position: fixed;
  top: 0;
  left: 0;
  transform: translateY(var(--app-offset, 0px));
  display: flex;
  flex-direction: column;
  height: var(--app-height, 100dvh);
  width: 100%;          /* pleine largeur : occupe toute la fenêtre */
  background: var(--bg);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem clamp(1rem, 2.5vw, 2.5rem);
  padding-top: calc(0.9rem + env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  flex-shrink: 0;
}

.chat-header h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.chat-header p {
  margin: 0.1rem 0 0;
  font-size: 0.85rem;
  opacity: 0.92;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.switch-student {
  color: #fff;
  text-decoration: none;
  font-size: 1.4rem;
  opacity: 0.85;
  padding: 0.3rem 0.5rem;
}
.switch-student:hover { opacity: 1; }

.header-btn {
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.12);
  border-radius: 0.7rem;
  color: #fff;
  font-size: 1.1rem;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  opacity: 0.9;
}
.header-btn:hover { opacity: 1; }
.header-btn.on {
  background: rgba(255, 255, 255, 0.3);
  border-color: #fff;
}

/* bouton écouter d'une bulle KLEO */
.msg-speak {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--bubble-bot-border);
  background: #fbfcff;
  border-radius: 0.6rem;
  padding: 0.15rem 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
  opacity: 0.75;
}
.msg-speak:hover { opacity: 1; border-color: var(--primary); }
.msg-speak:disabled { cursor: default; }
/* génération de la voix en cours : pastille qui pulse */
.msg-speak.loading { opacity: 1; border-color: var(--primary); color: var(--primary); animation: speak-pulse 1s ease-in-out infinite; }
/* lecture en cours : bouton actif */
.msg-speak.playing { opacity: 1; border-color: var(--primary); background: var(--primary); color: #fff; }
@keyframes speak-pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

/* formules KaTeX un peu plus aérées dans les bulles */
.msg .katex-display { margin: 0.45em 0; }

/* Fractions EN LIGNE (\( ... \)) : plus grandes et plus aérées.
   Retours testeurs du 15/07 — Doriane : « l'affichage de fractions très rapprochées n'est
   pas toujours ultra lisible, il faudrait écarter un tout petit peu les lignes » ; Kal :
   « augmenter la police des fractions et des calculs (prob pour les gamins avec des
   difficultés de vision et les DYS) ». C'est de l'accessibilité, pas du confort.
   La règle .katex-display ci-dessus ne couvrait PAS ce cas : les fractions du chat sont
   INLINE (front/app.js renderMath, display:false) et tombent donc dans .katex tout court.
   Une fraction empile numérateur/barre/dénominateur : elle dépasse la hauteur de ligne,
   d'où deux lignes de calcul qui se touchent. */
.msg .katex { font-size: 1.12em; }

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 1rem clamp(1rem, 2.5vw, 2.5rem);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scroll-behavior: smooth;
}

.msg {
  max-width: 85%;
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  font-size: 1rem;
  line-height: 1.75; /* 1.55 -> 1.75 : à 1.55 deux lignes de fractions se touchaient (15/07) */
  white-space: normal;
  overflow-wrap: break-word;
}

.msg.bot {
  align-self: flex-start;
  background: var(--bubble-bot-bg);
  border: 1px solid var(--bubble-bot-border);
  box-shadow: 0 2px 8px rgba(31, 36, 64, 0.06);
  border-bottom-left-radius: 0.3rem;
}

.msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 10px rgba(91, 108, 255, 0.25);
  border-bottom-right-radius: 0.3rem;
}

.msg.error {
  align-self: flex-start;
  background: #fff2f2;
  border: 1px solid #f3c2c2;
  color: #8a2f2f;
}

.msg p { margin: 0 0 0.55em; }
.msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 0.3em 0 0.55em; padding-left: 1.3em; }
.msg hr { border: none; border-top: 1px solid var(--bubble-bot-border); margin: 0.7em 0; }
.msg blockquote {
  margin: 0.3em 0;
  padding: 0.15em 0 0.15em 0.8em;
  border-left: 3px solid var(--secondary);
  color: inherit;
}
.msg pre {
  background: #f4f6ff;
  border: 1px solid var(--bubble-bot-border);
  border-radius: 0.5rem;
  padding: 0.6rem 0.8rem;
  margin: 0.3em 0 0.55em;
  font-size: 0.85rem;
  overflow-x: auto;
}

/* Boutons de réponse rapide ([choix: a | b | c]) */
.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-self: flex-start;
  max-width: 85%;
}

.choice-btn {
  padding: 0.6rem 1.1rem;
  border: 1.5px solid var(--primary);
  border-radius: 1.5rem;
  background: #fff;
  color: var(--primary);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.choice-btn:hover {
  background: var(--primary);
  color: #fff;
  transform: translateY(-1px);
}

/* Indicateur « KLEO réfléchit » */
.typing {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  padding: 0.4rem 0.2rem;
}
.typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Ardoise ---------- */
.board {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  height: 46dvh;
  background: #fff;
  border-top: 1px solid var(--bubble-bot-border);
  box-shadow: 0 -4px 16px rgba(31, 36, 64, 0.08);
}

.board-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.8rem;
  border-bottom: 1px solid var(--bubble-bot-border);
  flex-wrap: wrap;
}

.board-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.board-tools {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.tool {
  width: 42px;
  height: 42px;
  border: 1px solid var(--bubble-bot-border);
  border-radius: 0.7rem;
  background: #fbfcff;
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}

.tool:hover { border-color: var(--primary); }

.tool.active {
  border-color: var(--primary);
  background: #eef0ff;
  box-shadow: inset 0 0 0 1px var(--primary);
}

.tool.color::before {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--c);
}

.board-close { margin-left: 0.4rem; }

.board-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  /* quadrillage léger type cahier */
  background:
    linear-gradient(#f0f3fc 1px, transparent 1px),
    linear-gradient(90deg, #f0f3fc 1px, transparent 1px);
  background-size: 24px 24px;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- Zone de saisie ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.8rem clamp(1rem, 2.5vw, 2.5rem);
  padding-bottom: calc(0.8rem + env(safe-area-inset-bottom));
  background: var(--bg);
  flex-shrink: 0;
}

#input {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 1px solid var(--bubble-bot-border);
  border-radius: 0.9rem;
  padding: 0.85rem 1rem;
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  background: #fff;
  color: var(--text);
  max-height: 9rem;
  outline: none;
}

#input:focus { border-color: var(--primary); }

.send-btn {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}

.send-btn:hover:not(:disabled) { background: var(--primary-dark); }
.send-btn:active:not(:disabled) { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.45; cursor: default; }

.round-btn {
  position: relative;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border: 1px solid var(--bubble-bot-border);
  border-radius: 50%;
  background: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.round-btn:hover { border-color: var(--primary); }

.round-btn.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(91, 108, 255, 0.25);
}

.badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--secondary);
  border: 2px solid #fff;
}

.round-btn.recording {
  border-color: #d23c3c;
  background: #fff2f2;
  box-shadow: 0 0 0 3px rgba(210, 60, 60, 0.25);
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(210, 60, 60, 0.25); }
  50% { box-shadow: 0 0 0 7px rgba(210, 60, 60, 0.12); }
}

.rec-chip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0 0.7rem;
  height: 52px;
  border-radius: 0.9rem;
  background: #fff2f2;
  border: 1px solid #f3c2c2;
  color: #8a2f2f;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d23c3c;
  animation: blink 1.2s infinite;
}

.rec-chip button {
  border: none;
  background: none;
  color: #8a2f2f;
  font-size: 1rem;
  cursor: pointer;
  padding: 0.3rem;
}

/* lecteur audio du message vocal dans la bulle utilisateur */
.msg .voice-note {
  display: block;
  max-width: 230px;
  height: 38px;
  margin-bottom: 0.3rem;
}

/* vignette de l'ardoise dans la bulle utilisateur */
.msg .sketch-thumb {
  display: block;
  max-width: 240px;
  max-height: 160px;
  border-radius: 0.6rem;
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 0.5);
  margin-bottom: 0.4rem;
}

@media (max-width: 600px) {
  .msg { max-width: 92%; }
  .chat-header h1 { font-size: 1.25rem; }
  .board-title { display: none; }
  .board-toolbar { justify-content: center; }
  .tool { width: 38px; height: 38px; }
  .board { height: 42dvh; }
  .round-btn, .send-btn { width: 46px; height: 46px; }
  .rec-chip { height: 46px; padding: 0 0.5rem; }
  .composer { gap: 0.4rem; padding: 0.6rem 0.6rem calc(0.6rem + env(safe-area-inset-bottom)); }
}

/* ============ Bandeau « nouveau chapitre activé par le prof » (item 3.3) ============ */
.notif-banner {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.55rem clamp(0.8rem, 2.5vw, 1.5rem) 0;
  padding: 0.6rem 0.8rem;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(91, 108, 255, 0.12), rgba(40, 195, 154, 0.12));
  border: 1px solid rgba(91, 108, 255, 0.35);
  color: var(--text);
  font-size: 0.9rem;
  box-shadow: 0 6px 16px rgba(31, 36, 64, 0.06);
}
.notif-banner.hidden { display: none; }
.notif-banner .notif-ic { font-size: 1.15rem; line-height: 1; }
.notif-banner .notif-text { flex: 1; min-width: 0; }
.notif-banner .notif-cta {
  flex-shrink: 0;
  border: none;
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-weight: 700;
  font-size: 0.82rem;
  color: #fff;
  background: var(--primary, #5b6cff);
  cursor: pointer;
}
.notif-banner .notif-cta:hover { filter: brightness(1.05); }

/* ============ Checklist des concepts de la séance (item 1.2) ============ */
.phud-concepts {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  margin-top: 0.15rem;
}
.phud-concepts[hidden] { display: none; }
.concept {
  display: flex;
  align-items: center;
  gap: 0.42rem;
  font-size: 0.78rem;
  line-height: 1.3;
}
.concept-ic { width: 1rem; text-align: center; flex-shrink: 0; font-weight: 800; }
.concept-tx { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.concept-done { color: #128a6b; }
.concept-done .concept-ic { color: #28c39a; }
.concept-current { color: var(--text); font-weight: 700; }
.concept-current .concept-ic { color: var(--primary, #5b6cff); }
.concept-upcoming { color: var(--muted, #9aa0b4); }
.concept-warn { color: #c9740a; }
.concept-warn .concept-ic { color: #e8890c; }

/* Bouton « Terminer ma séance » (déclenche le bilan) */
.phud-end {
  align-self: flex-start;
  margin-top: 0.2rem;
  padding: 0.28rem 0.7rem;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted, #6b7189);
  background: #f4f5fb;
  border: 1px solid var(--bubble-bot-border, #e3e6f2);
  border-radius: 999px;
  cursor: pointer;
}
.phud-end:hover { background: #eceeffe0; color: var(--text); }
.phud-end[hidden] { display: none; }
.phud-end:disabled { opacity: 0.55; cursor: default; }

/* ===================== Parcours gamifié (progress HUD) ===================== */
.phud {
  flex-shrink: 0;
  background: #fff;
  border-bottom: 1px solid var(--bubble-bot-border);
  box-shadow: 0 6px 16px rgba(31, 36, 64, 0.06);
  padding: 0.55rem clamp(0.8rem, 2.5vw, 1.5rem) 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 2;
}
.phud[hidden] { display: none; }

.phud-top { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.phud-chap { min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.phud-eyebrow {
  font-size: 0.6rem; font-weight: 800; letter-spacing: 0.13em;
  text-transform: uppercase; color: var(--muted);
}
.phud-chap-name {
  font-size: 0.92rem; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw;
}
.phud-pill {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.28rem 0.62rem; border-radius: 999px;
  background: linear-gradient(135deg, rgba(91, 108, 255, 0.13), rgba(40, 195, 154, 0.13));
  border: 1px solid rgba(91, 108, 255, 0.22);
  font-size: 0.8rem; font-weight: 800; color: var(--primary-dark); white-space: nowrap;
}
.phud-pill-icon { font-size: 1rem; }

/* 3 segments = les niveaux du chapitre */
.phud-levels { display: flex; gap: 0.4rem; }
.phud-seg {
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: center; gap: 0.3rem;
  padding: 0.32rem 0.25rem; border-radius: 0.7rem;
  font-size: 0.72rem; font-weight: 700;
  background: #eef1fb; color: var(--muted);
  border: 1px solid transparent;
  transition: color 0.3s, background 0.3s, box-shadow 0.3s;
  position: relative; overflow: hidden;
}
.phud-seg .seg-ic { font-size: 0.95rem; filter: grayscale(1); opacity: 0.55; transition: filter 0.3s, opacity 0.3s; }
.phud-seg .seg-tx { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phud-seg.done { background: rgba(40, 195, 154, 0.14); color: #128a6b; }
.phud-seg.done .seg-ic { filter: none; opacity: 1; }
.phud-seg.done .seg-tx::after { content: " ✓"; font-weight: 900; }
.phud-seg.current {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff; box-shadow: 0 4px 14px rgba(91, 108, 255, 0.4);
}
.phud-seg.current .seg-ic { filter: none; opacity: 1; }
.phud-seg.current::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 35%, rgba(255, 255, 255, 0.45) 50%, transparent 65%);
  transform: translateX(-130%); animation: phud-sheen 2.8s ease-in-out infinite;
}
@keyframes phud-sheen { 0% { transform: translateX(-130%); } 55%, 100% { transform: translateX(130%); } }

/* barre de % */
.phud-prog { display: flex; align-items: center; gap: 0.55rem; }
.phud-prog-track { flex: 1; height: 9px; border-radius: 999px; background: #e6eaf6; overflow: hidden; }
.phud-fill {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative; overflow: hidden;
}
.phud-fill::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 35%, rgba(255, 255, 255, 0.55) 50%, transparent 65%);
  transform: translateX(-100%); animation: phud-fill-sheen 2.3s ease-in-out infinite;
}
@keyframes phud-fill-sheen { 0% { transform: translateX(-100%); } 55%, 100% { transform: translateX(240%); } }
.phud-fill.bump { animation: phud-bump 0.55s ease; }
@keyframes phud-bump { 50% { filter: brightness(1.3) saturate(1.25); } }
.phud-pct {
  flex-shrink: 0; font-size: 0.82rem; font-weight: 800; color: var(--primary-dark);
  font-variant-numeric: tabular-nums; min-width: 2.7em; text-align: right;
}

@media (max-width: 380px) {
  .phud-seg .seg-tx { display: none; }
  .phud-chap-name { max-width: 46vw; }
}

/* ===================== Célébration passage de niveau 🎉 ===================== */
.lvlup {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 24, 52, 0.42);
  animation: lvlup-bg 0.3s ease;
}
.lvlup.hidden { display: none; }
@keyframes lvlup-bg { from { opacity: 0; } to { opacity: 1; } }
.lvlup-confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.lvlup-card {
  position: relative;
  background: #fff; border-radius: 1.6rem;
  padding: 1.7rem 1.9rem 1.3rem; text-align: center;
  box-shadow: 0 26px 64px rgba(20, 24, 52, 0.42);
  max-width: 86%;
  animation: lvlup-pop 0.55s cubic-bezier(0.18, 1.45, 0.5, 1) both;
}
@keyframes lvlup-pop {
  0% { transform: scale(0.4) translateY(24px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
.lvlup-emoji { font-size: 3.1rem; line-height: 1; animation: lvlup-emoji 0.9s ease 0.18s both; }
@keyframes lvlup-emoji {
  0% { transform: scale(0) rotate(-22deg); } 60% { transform: scale(1.25) rotate(9deg); }
  100% { transform: scale(1) rotate(0); }
}
.lvlup-title {
  margin-top: 0.4rem; font-size: 1.75rem; font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.lvlup-sub { margin-top: 0.25rem; font-size: 1.05rem; color: var(--text); }
.lvlup-sub b { color: var(--primary-dark); }
.lvlup-hint { margin-top: 0.95rem; font-size: 0.72rem; color: var(--muted); }

/* ===================== Bilan de fin de séance 🎯 ===================== */
.bilan {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  background: rgba(20, 24, 52, 0.42);
  animation: lvlup-bg 0.3s ease;
}
.bilan.hidden { display: none; }
.bilan-card {
  position: relative;
  background: #fff; border-radius: 1.4rem;
  padding: 1.4rem 1.4rem 1.3rem;
  box-shadow: 0 26px 64px rgba(20, 24, 52, 0.42);
  width: min(680px, 94vw);
  max-height: 88vh; overflow-y: auto;
  animation: lvlup-pop 0.5s cubic-bezier(0.18, 1.45, 0.5, 1) both;
}
.bilan-close {
  position: absolute; top: 0.7rem; right: 0.7rem;
  width: 2rem; height: 2rem; border-radius: 999px;
  border: none; background: #f1f2f8; color: var(--muted, #6b7189);
  font-size: 0.95rem; cursor: pointer;
}
.bilan-close:hover { background: #e6e8f4; color: var(--text); }
.bilan-title { font-size: 1.3rem; font-weight: 800; text-align: center; }
.bilan-sub { margin: 0.2rem 0 1rem; text-align: center; color: var(--muted, #6b7189); font-size: 0.9rem; }
.bilan-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem; }
.bilan-col { background: #f7f8fc; border-radius: 0.9rem; padding: 0.7rem 0.8rem; }
.bilan-col h3 { margin: 0 0 0.5rem; font-size: 0.86rem; font-weight: 700; }
.bilan-c-acquis h3 { color: #128a6b; }
.bilan-c-warn h3 { color: #c9740a; }
.bilan-c-todo h3 { color: var(--muted, #9aa0b4); }
.bilan-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.32rem; }
.bilan-list li { font-size: 0.82rem; line-height: 1.3; color: var(--text); }
.bilan-list li.bilan-empty { color: var(--muted, #9aa0b4); }
@media (max-width: 520px) {
  .bilan-cols { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .phud-seg.current::after, .phud-fill::after { animation: none; }
  .lvlup, .lvlup-card, .lvlup-emoji { animation: none; }
}

/* ---------- Géométrie interactive (JSXGraph 2D/3D) ---------- */
.geo {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  height: 52dvh;
  background: #fff;
  border-top: 1px solid var(--bubble-bot-border);
  box-shadow: 0 -4px 16px rgba(31, 36, 64, 0.08);
}

.geo-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.8rem;
  border-bottom: 1px solid var(--bubble-bot-border);
  flex-wrap: wrap;
}

.geo-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.geo-tools {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
  margin-left: auto;
}

.geo-tool {
  min-width: 38px;
  height: 38px;
  padding: 0 0.5rem;
  border: 1px solid var(--bubble-bot-border);
  border-radius: 0.6rem;
  background: #fbfcff;
  font-size: 1.05rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}

.geo-tool:hover { border-color: var(--primary); }

.geo-tool.active {
  border-color: var(--primary);
  background: #eef0ff;
  box-shadow: inset 0 0 0 1px var(--primary);
}

.geo-mode {
  display: inline-flex;
  border: 1px solid var(--bubble-bot-border);
  border-radius: 0.6rem;
  overflow: hidden;
}

.geo-mode .geo-tool {
  border: none;
  border-radius: 0;
  height: 32px;
  font-size: 0.85rem;
  font-weight: 600;
}

.geo-mode .geo-tool + .geo-tool { border-left: 1px solid var(--bubble-bot-border); }

.geo-close { margin-left: 0.2rem; }

/* En mode 3D, les outils de tracé 2D n'ont pas de sens → on les masque. */
.geo--3d .geo-tool.draw2d { display: none; }

.geo-board {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #fff;
  touch-action: none; /* le tracé/la rotation ne déclenchent pas le scroll */
}
.geo-board > * { width: 100%; height: 100%; }

/* Puce « figure jointe » : pastille blanche lisible sur la bulle élève (indigo). */
.geo-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.4rem;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  background: #ffffff;
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(31, 36, 64, 0.18);
}

/* ---------- Vue côte à côte (géométrie à gauche, chat à droite) ---------- */
.geo-divider { display: none; } /* masquée hors de la vue scindée */

@media (min-width: 820px) {
  /* Géométrie ouverte → le chat passe en grille 2 colonnes redimensionnables :
     géométrie (gauche) | poignée | transcript + saisie (droite). */
  .chat.geo-open {
    display: grid;
    grid-template-columns: var(--geo-w, 54%) 9px minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "head head head"
      "phud phud phud"
      "geo  divi trans"
      "geo  divi comp";
  }
  .chat.geo-open > .chat-header { grid-area: head; }
  .chat.geo-open > #phud       { grid-area: phud; }
  .chat.geo-open > #transcript { grid-area: trans; min-height: 0; }
  .chat.geo-open > .composer   { grid-area: comp; }
  .chat.geo-open > #board      { grid-area: geo; } /* sécurité si ardoise ouverte */

  /* La géométrie remplit la colonne gauche (plus de drawer 52dvh). */
  .chat.geo-open > #geo {
    grid-area: geo;
    height: auto;
    min-height: 0;
    border-top: none;
    border-right: 1px solid var(--bubble-bot-border);
    box-shadow: none;
  }

  .chat.geo-open > #geo-divider {
    display: block;
    grid-area: divi;
    position: relative;
    cursor: col-resize;
    background: var(--bubble-bot-border);
    touch-action: none;
  }
  .chat.geo-open > #geo-divider::before { /* zone de saisie élargie */
    content: ""; position: absolute; top: 0; bottom: 0; left: -6px; right: -6px;
  }
  .chat.geo-open > #geo-divider::after { /* poignée visuelle */
    content: "⋮"; position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%); color: var(--muted);
    font-size: 1rem; line-height: 1;
  }
  .chat.geo-open > #geo-divider:hover { background: var(--primary); }
}
