:root {
  --edu-primary: #4F46E5;
  --edu-primary-dark: #3730A3;
  --edu-ink: #0F172A;
  --edu-muted: #64748B;
  --edu-line: #E2E8F0;
  --edu-bg: #F8FAFC;
  --edu-card: #FFFFFF;
  --edu-objectif: #EEF2FF;
  --edu-objectif-fg: #3730A3;
  --edu-astuce: #FEF3C7;
  --edu-astuce-fg: #92400E;
  --edu-exemple: #ECFDF5;
  --edu-exemple-fg: #065F46;
  --edu-retenir: #F1F5F9;
  --edu-retenir-fg: #0F172A;
  --edu-ok: #059669;
  --edu-ko: #DC2626;
  --edu-radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body.player {
  font-family: "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  background: var(--edu-bg);
  color: var(--edu-ink);
  line-height: 1.55;
  min-height: 100vh;
}

.player-preview {
  font-family: "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  background: var(--edu-bg);
  color: var(--edu-ink);
  line-height: 1.55;
  padding: 8px 4px 16px;
  max-width: 760px;
  overflow-x: hidden;
}

.home {
  max-width: 920px;
  margin: 0 auto;
  padding: 48px 20px 80px;
}
.home-hero {
  background: linear-gradient(135deg, #4F46E5 0%, #06B6D4 100%);
  color: #fff;
  border-radius: 24px;
  padding: 40px 36px;
  margin-bottom: 28px;
}
.home-hero h1 { margin: 0 0 10px; font-size: clamp(1.6rem, 3vw, 2.2rem); }
.home-hero p { margin: 0; opacity: .92; }
.module-grid { display: grid; gap: 14px; }
.module-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--edu-card);
  border: 1px solid var(--edu-line);
  border-radius: var(--edu-radius);
  padding: 18px 20px;
  box-shadow: 0 10px 24px -12px rgba(15, 23, 42, .12);
}
.module-card:hover { border-color: #C7D2FE; }
.module-card strong { color: var(--edu-primary); }
.module-card span { color: var(--edu-muted); font-size: .9rem; }

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}
.toc {
  background: #fff;
  border-right: 1px solid var(--edu-line);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.toc a.back { color: var(--edu-primary); text-decoration: none; font-size: .85rem; }
.toc h1 { font-size: 1.05rem; margin: 12px 0 16px; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0 0 6px; }
.toc button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--edu-ink);
  font: inherit;
}
.toc button:hover, .toc button.active { background: var(--edu-objectif); color: var(--edu-primary-dark); }

.stage { padding: 28px 32px 100px; max-width: 860px; }
.lesson-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 18px;
}
.lesson-head .kicker {
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: .75rem;
  font-weight: 700;
  color: var(--edu-primary);
  margin: 0 0 6px;
}
.lesson-head h2 { margin: 0; font-size: 1.7rem; }
.listen-lesson {
  flex-shrink: 0;
  border: 0;
  border-radius: 999px;
  background: #4F46E5;
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: .9rem;
  padding: 10px 16px;
  cursor: pointer;
}
.listen-lesson:hover { background: #3730A3; }
.listen-lesson.is-playing { background: #B45309; }

.callout {
  border-radius: 14px;
  padding: 14px 16px;
  margin: 0 0 16px;
}
.callout-objectif { background: var(--edu-objectif); color: var(--edu-objectif-fg); }
.callout-astuce { background: var(--edu-astuce); color: var(--edu-astuce-fg); }
.callout-exemple { background: var(--edu-exemple); color: var(--edu-exemple-fg); }
.callout-retenir { background: var(--edu-retenir); color: var(--edu-retenir-fg); }
.callout::before {
  display: block;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 6px;
  opacity: .8;
}
.callout-objectif::before { content: "Objectif"; }
.callout-astuce::before { content: "Astuce"; }
.callout-exemple::before { content: "Cas concret"; }
.callout-retenir::before { content: "À retenir"; }

.prose { margin: 0 0 16px; }
.prose img, figure img {
  max-width: 100%;
  height: auto;
  border-radius: 14px;
  display: block;
}
figure { margin: 0 0 18px; }
figcaption { color: var(--edu-muted); font-size: .85rem; margin-top: 8px; }

.exercise {
  background: #fff;
  border: 1px solid var(--edu-line);
  border-radius: 16px;
  padding: 18px;
  margin: 0 0 18px;
}
.exercise h3 { margin: 0 0 12px; font-size: 1rem; color: var(--edu-primary-dark); }
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.flip {
  min-height: 140px;
  border-radius: 14px;
  background: var(--edu-objectif);
  color: var(--edu-primary-dark);
  padding: 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  border: 0;
  font: inherit;
  text-align: left;
}
.flip img { width: 100%; border-radius: 10px; }
.flip .back { display: none; }
.flip.is-back { background: #ECFDF5; color: #065F46; }
.flip.is-back .front { display: none; }
.flip.is-back .back { display: block; }

.tf { display: flex; gap: 10px; flex-wrap: wrap; }
.tf button, .quiz button, .pager button, .exercise button[data-check] {
  background: var(--edu-primary);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
}
.tf button.alt, .pager button.ghost { background: #fff; color: var(--edu-ink); border: 1px solid var(--edu-line); }
.feedback { margin-top: 10px; font-weight: 700; }
.feedback.ok { color: var(--edu-ok); }
.feedback.ko { color: var(--edu-ko); }
.score-banner {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #EEF2FF;
  color: #3730A3;
  font-weight: 800;
  font-size: 1.05rem;
}
.livrable textarea {
  width: 100%;
  min-height: 120px;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--edu-line);
  border-radius: 12px;
  margin: 8px 0;
}
.livrable input[type="file"] { margin: 8px 0 12px; }
.criteres { margin: 0 0 12px; padding-left: 18px; color: var(--edu-muted); }

.blank {
  border: 0;
  border-bottom: 2px solid var(--edu-primary);
  min-width: 4.5rem;
  padding: 2px 6px;
  font: inherit;
  background: #EEF2FF;
}
.match-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: center;
  margin: 0 0 10px;
}
.match-row select {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--edu-line);
}
.order-list { padding-left: 0; list-style: none; }
.order-list li { margin: 0 0 8px; }
.quiz fieldset,
.exercise fieldset {
  border: 1px solid var(--edu-line);
  border-radius: 12px;
  margin: 0 0 12px;
  padding: 12px 14px;
  background: #fff;
  display: grid;
  gap: 2px;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.quiz legend,
.exercise legend {
  display: block;
  float: none;
  width: 100%;
  max-width: 100%;
  padding: 0;
  margin: 0 0 8px;
  font-weight: 700;
}
.quiz label,
.exercise label {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 8px 0;
  cursor: pointer;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.quiz label input[type="radio"],
.exercise label input[type="radio"],
.quiz input[type="radio"],
.exercise input[type="radio"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  max-width: 18px;
  margin: 3px 0 0;
  padding: 0;
  flex: 0 0 18px;
  accent-color: var(--edu-primary);
}
.quiz label span,
.exercise label span {
  flex: 1;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

.pager button:disabled { opacity: .45; cursor: default; }

.xp-hud {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #4F46E5 0%, #06B6D4 100%);
  color: #fff;
  font-weight: 700;
}
.xp-hud span { font-size: .85rem; opacity: .95; }

.callout-mission::before { content: "Mission"; }
.callout-contexte::before { content: "Situation"; }
.callout-defi::before { content: "Défi"; }

.pager {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 32px;
  background: rgba(248, 250, 252, .92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--edu-line);
}
.lesson[hidden] { display: none !important; }

.ai-assistant-card {
  background: linear-gradient(135deg, #FFFFFF 0%, #F8FAFC 100%);
  border-radius: 20px;
  border: 1px solid #E2E8F0;
  padding: 22px;
  margin: 0 0 22px;
  box-shadow: 0 10px 30px -5px rgba(79, 70, 229, 0.08);
}
.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.ai-avatar-wrapper {
  display: flex;
  align-items: center;
  gap: 14px;
}
.ai-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366F1 0%, #A855F7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 22px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  flex-shrink: 0;
}
.ai-avatar-wrapper strong {
  display: block;
  font-size: 15px;
  color: var(--edu-ink);
}
.ai-sub {
  font-size: 12px;
  color: var(--edu-muted);
  font-weight: 500;
}
.ai-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #ECFDF5;
  color: #047857;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.ai-pulse {
  width: 9px;
  height: 9px;
  background: #10B981;
  border-radius: 50%;
  animation: pulse-ring 1.5s infinite;
}
@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}
.ai-chat-stream {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 48px;
  max-height: 240px;
  overflow-y: auto;
  padding: 12px;
  background: #F1F5F9;
  border-radius: 14px;
}
.chat-bubble-ai {
  align-self: flex-start;
  background: #FFFFFF;
  color: var(--edu-ink);
  padding: 14px 18px;
  border-radius: 18px 18px 18px 4px;
  font-size: 14px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.03);
  max-width: 85%;
}
.chat-bubble-user {
  align-self: flex-end;
  background: var(--edu-primary);
  color: white;
  padding: 14px 18px;
  border-radius: 18px 18px 4px 18px;
  font-size: 14px;
  max-width: 85%;
}
.ai-input-bar {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  background: #FFFFFF;
  border: 1px solid var(--edu-line);
  border-radius: 30px;
  padding: 6px 8px 6px 20px;
  align-items: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.02);
}
.ai-input-bar input {
  border: none;
  outline: none;
  margin: 0;
  padding: 8px 0;
  font-size: 14px;
  background: transparent;
  flex: 1;
  min-width: 0;
  width: auto;
  font-family: inherit;
}
.ai-btn-mic {
  background: linear-gradient(135deg, #F59E0B, #EF4444);
  color: white;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.ai-btn-send {
  background: var(--edu-primary);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
body.tutor-page {
  background: #fff;
  min-height: auto;
  padding: 8px;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .toc { height: auto; position: relative; border-right: 0; border-bottom: 1px solid var(--edu-line); }
  .stage { padding: 20px 16px 90px; }
  .ai-header { flex-wrap: wrap; }
}
