: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: 1080px;
  margin: 0 auto;
  padding: 48px 20px 80px;
}
.home-hero {
  background: linear-gradient(135deg, var(--edu-primary) 0%, var(--edu-primary-dark) 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; }
.module-card .adapt-badge,
.adapt-badge {
  display: inline-block;
  margin-top: 10px;
  font-size: .75rem;
  font-style: normal;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}
.adapt-badge.must { background: #FEE2E2; color: #991B1B; }
.adapt-badge.core { background: #FEF3C7; color: #92400E; }
.adapt-badge.skip { background: #D1FAE5; color: #065F46; }
.module-card.is-skip { opacity: .88; }
.home-brand { margin-bottom: 16px; }
.brand-logo {
  height: 48px;
  max-width: 180px;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  padding: 4px 8px;
}
.toc-logo { display: block; height: 40px; max-width: 220px; margin: 0 0 14px; }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  min-height: 100vh;
}
.toc {
  background: #fff;
  border-right: 1px solid var(--edu-line);
  padding: 24px 18px 32px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.toc a.back { color: var(--edu-primary); text-decoration: none; font-size: .9rem; font-weight: 600; }
.toc h1 { font-size: 1.12rem; line-height: 1.35; margin: 14px 0 18px; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0 0 8px; }
.toc button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  color: var(--edu-ink);
  font: inherit;
  font-size: .95rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.toc button:hover, .toc button.active { background: var(--edu-objectif); color: var(--edu-primary-dark); }

.toc-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  border: 0;
  background: var(--edu-primary);
  color: #fff;
  font: inherit;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 0;
  width: 100%;
  cursor: pointer;
  position: sticky;
  top: 0;
  z-index: 30;
}
.toc-backdrop {
  display: none;
}

.main-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.stage {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 36px 40px 120px;
}
.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; }
figure.sheet-figure svg,
.prose svg,
figure svg {
  width: 100%;
  height: auto;
  max-width: 100%;
  display: block;
  border-radius: 12px;
  overflow: visible;
}
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%;
  overflow: hidden;
  box-sizing: border-box;
}
.quiz legend,
.exercise legend {
  display: table;
  float: left;
  width: 100%;
  max-width: 100%;
  padding: 0;
  margin: 0 0 8px;
  font-weight: 700;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-sizing: border-box;
}
.quiz legend + *,
.exercise legend + * {
  clear: both;
}
.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 span,
.exercise label span {
  flex: 1;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.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 fieldset.is-ok,
.exercise fieldset.is-ok {
  border-color: #34D399;
  background: #ECFDF5;
}
.quiz fieldset.is-ko,
.exercise fieldset.is-ko {
  border-color: #FCA5A5;
  background: #FEF2F2;
}
.quiz label.is-good span,
.exercise label.is-good span {
  color: #065F46;
  font-weight: 700;
}
.quiz label.is-bad span,
.exercise label.is-bad span {
  color: #991B1B;
  text-decoration: line-through;
}
.quiz .correction,
.exercise .correction,
.match-row .correction {
  display: none;
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.45;
  background: #FFF7ED;
  border: 1px solid #FDBA74;
  color: #9A3412;
}
.quiz .correction[hidden],
.exercise .correction[hidden],
.match-row .correction[hidden] { display: none; }
.quiz fieldset.is-ok .correction,
.quiz fieldset.is-ko .correction,
.exercise fieldset.is-ok .correction,
.exercise fieldset.is-ko .correction,
.match-row .correction {
  display: block;
}
.quiz fieldset.is-ok .correction,
.exercise fieldset.is-ok .correction {
  background: #ECFDF5;
  border-color: #6EE7B7;
  color: #065F46;
}
.correction-inline {
  display: inline-block;
  margin-left: 8px;
  color: #065F46;
  font-weight: 700;
  font-size: .9rem;
}
.tf button.is-good { background: #059669 !important; color: #fff; border-color: #059669; }
.tf button.is-bad { background: #FEE2E2 !important; color: #991B1B; border-color: #FCA5A5; }
select.is-good { background: #D1FAE5; border-color: #34D399; }
select.is-bad { background: #FEE2E2; border-color: #FCA5A5; }

.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: center;
  gap: 12px;
  padding: 14px 24px;
  background: rgba(248, 250, 252, .92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--edu-line);
  width: 100%;
}
.pager-inner {
  width: min(960px, 100%);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.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;
}

.end-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.end-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 28px 26px 22px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
}
.end-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: #D1FAE5;
  color: #065F46;
  font-size: 28px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.end-card h2 {
  margin: 0 0 10px;
  color: var(--edu-primary-dark);
  font-size: 1.35rem;
}
.end-card p {
  margin: 0 0 20px;
  color: var(--edu-ink);
  line-height: 1.5;
}
.end-ok {
  appearance: none;
  border: 0;
  background: var(--edu-primary);
  color: #fff;
  font: inherit;
  font-weight: 700;
  padding: 12px 28px;
  border-radius: 12px;
  cursor: pointer;
  min-width: 140px;
}
.end-ok:hover { background: var(--edu-primary-dark); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(280px, 320px) minmax(0, 1fr); }
  .stage { padding: 28px 24px 110px; }
}
@media (max-width: 900px) {
  .toc-toggle { display: inline-flex; }
  .layout { grid-template-columns: 1fr; }
  .toc {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(88vw, 360px);
    height: 100vh;
    z-index: 40;
    transform: translateX(-105%);
    transition: transform .22s ease;
    border-right: 1px solid var(--edu-line);
    box-shadow: none;
  }
  body.toc-open .toc {
    transform: translateX(0);
    box-shadow: 12px 0 40px rgba(15, 23, 42, .18);
  }
  body.toc-open .toc-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .42);
    z-index: 35;
  }
  .stage { padding: 20px 16px 100px; }
  .pager { padding: 12px 16px; }
  .ai-header { flex-wrap: wrap; }
}
