/* ============== Reset & base ============== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --accent: #7c3aed;
  --bg: #f5f7fb;
  --card-bg: #fff;
  --text: #1f2937;
  --text-light: #6b7280;
  --border: #e5e7eb;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --cm1: #3b82f6;
  --cm2: #8b5cf6;
  --cm3: #ec4899;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============== Topbar ============== */
.topbar {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  padding: 18px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 36px; }
.brand h1 { font-size: 20px; font-weight: 700; }
.brand p { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.modes { display: flex; gap: 8px; }
.mode-btn {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.mode-btn:hover { background: rgba(255,255,255,0.25); }
.mode-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

main {
  flex: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 20px;
  width: 100%;
}

/* ============== Filters ============== */
.filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}
.filter-label { font-size: 13px; font-weight: 600; color: var(--text-light); margin-right: 4px; }
.chip {
  background: white;
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ============== Mode panels ============== */
.mode-panel { display: none; }
.mode-panel.active { display: block; }

/* ============== Flashcards ============== */
.card-stage {
  perspective: 1500px;
  margin-bottom: 24px;
}
.flashcard {
  width: 100%;
  height: 400px;
  cursor: pointer;
  position: relative;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute;
  inset: 0;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  backface-visibility: hidden;
}
.flashcard-face.back {
  transform: rotateY(180deg);
  background: linear-gradient(135deg, #fdfcff, #eef2ff);
  text-align: left;
}
.chapter-tag {
  position: absolute;
  top: 16px;
  left: 16px;
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.5px;
}
.chapter-tag[data-cm="CM1"] { background: var(--cm1); }
.chapter-tag[data-cm="CM2"] { background: var(--cm2); }
.chapter-tag[data-cm="CM3"] { background: var(--cm3); }
.card-text {
  font-size: 19px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-line;
  max-height: 280px;
  overflow-y: auto;
  width: 100%;
}
.flashcard-face.front .card-text { font-size: 22px; font-weight: 600; text-align: center; }
.hint {
  position: absolute;
  bottom: 14px;
  font-size: 12px;
  color: var(--text-light);
  font-style: italic;
}

/* ============== Controls ============== */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}
.controls-secondary { display: flex; justify-content: center; gap: 12px; }
.btn-control, .btn-secondary, .btn-primary {
  font-size: 14px;
  font-weight: 600;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-control {
  background: var(--card-bg);
  color: var(--primary);
  border: 1px solid var(--border);
  flex: 1;
  max-width: 180px;
}
.btn-control:hover { background: var(--primary); color: white; }
.btn-secondary {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #f9fafb; border-color: var(--primary); }
.btn-primary {
  background: var(--primary);
  color: white;
  padding: 12px 28px;
  font-size: 15px;
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.counter {
  font-size: 14px;
  color: var(--text-light);
  font-weight: 600;
  min-width: 80px;
  text-align: center;
}

/* ============== Quiz ============== */
.quiz-screen {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 36px;
  box-shadow: var(--shadow);
  text-align: center;
}
.quiz-screen.hidden { display: none; }
.quiz-screen h2 { font-size: 26px; margin-bottom: 12px; }
.quiz-desc { color: var(--text-light); margin-bottom: 24px; }
.quiz-config {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.quiz-config label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--text-light);
  text-align: left;
}
.quiz-config select {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  cursor: pointer;
  min-width: 160px;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  padding: 14px 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  font-weight: 600;
  font-size: 14px;
}
.quiz-timer.warning { animation: pulse 0.6s infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); color: #fde68a; }
}
.quiz-card {
  text-align: left;
  position: relative;
  padding-top: 16px;
}
.quiz-question {
  font-size: 18px;
  margin: 18px 0 22px;
  line-height: 1.5;
  color: var(--text);
}
.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.quiz-option {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  line-height: 1.5;
  transition: all 0.15s;
  white-space: pre-line;
  color: var(--text);
}
.quiz-option:hover:not(.disabled) { border-color: var(--primary); background: #f5f3ff; }
.quiz-option.correct { background: #ecfdf5; border-color: var(--success); color: #064e3b; }
.quiz-option.wrong { background: #fef2f2; border-color: var(--error); color: #7f1d1d; }
.quiz-option.disabled { cursor: default; opacity: 0.85; }
#btn-quiz-next { margin-top: 18px; }

.end-score { margin: 24px 0; }
.big-score { font-size: 56px; font-weight: 700; color: var(--primary); }
.end-percent { font-size: 22px; color: var(--text-light); margin-top: 4px; }
.end-buttons { display: flex; justify-content: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

.hidden { display: none !important; }

/* ============== Cas DS ============== */
.case-screen {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.case-screen.hidden { display: none; }
.case-screen h2 { font-size: 24px; margin-bottom: 10px; }

.cases-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 20px;
}
.case-card {
  background: linear-gradient(135deg, #ffffff, #f5f3ff);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.case-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}
.case-card h3 {
  font-size: 16px;
  margin: 8px 0 10px;
  line-height: 1.35;
  color: var(--text);
}
.case-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-light);
  margin-top: 12px;
}
.case-card .chapter-tag {
  position: static;
  display: inline-block;
}

.btn-back {
  background: transparent;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 0 14px 0;
}
.btn-back:hover { text-decoration: underline; }

.case-context {
  background: linear-gradient(135deg, #eef2ff, #faf5ff);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 22px;
}
.case-context .chapter-tag {
  position: static;
  display: inline-block;
  margin-bottom: 10px;
}
.case-context h3 {
  font-size: 18px;
  margin: 0 0 12px;
  line-height: 1.4;
}
.context-box {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-line;
}

.case-quiz-area .quiz-question {
  font-size: 17px;
  margin: 10px 0 18px;
}

.explanation {
  background: #ecfdf5;
  border-left: 4px solid var(--success);
  border-radius: 8px;
  padding: 14px 16px;
  margin-top: 14px;
  font-size: 14px;
  line-height: 1.55;
  color: #064e3b;
}
.explanation::before {
  content: "💡 ";
  font-weight: 700;
}
.explanation.wrong {
  background: #fef2f2;
  border-left-color: var(--error);
  color: #7f1d1d;
}
.explanation.wrong::before { content: "❌ "; }

/* ============== Mindmap mode (full page) ============== */
/* Quand le mode mindmap est actif, on casse les contraintes du <main>
   et on fait prendre toute la largeur/hauteur disponible à l'iframe. */
body.mindmap-active main {
  max-width: none !important;
  padding: 0 !important;
  margin: 0 !important;
  width: 100% !important;
}
body.mindmap-active #chapter-filters,
body.mindmap-active footer {
  display: none !important;
}
.mode-panel.mindmap-mode { padding: 0; }
.mode-panel.mindmap-mode.active {
  display: block;
  width: 100%;
  height: calc(100vh - 80px); /* 80px ≈ hauteur topbar */
}
#mindmap-frame {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: #f5f7fb;
  display: block;
}

/* ============== Footer ============== */
footer {
  text-align: center;
  padding: 18px;
  color: var(--text-light);
  font-size: 12px;
}

/* ============== Responsive ============== */
@media (max-width: 640px) {
  .topbar { flex-direction: column; gap: 14px; padding: 16px; text-align: center; }
  .brand { flex-direction: column; gap: 6px; }
  main { padding: 20px 14px; }
  .flashcard { height: 380px; }
  .flashcard-face { padding: 30px 22px; }
  .card-text { font-size: 16px; }
  .flashcard-face.front .card-text { font-size: 18px; }
  .controls { flex-direction: column; gap: 10px; }
  .btn-control { max-width: none; width: 100%; }
  .quiz-screen { padding: 22px 18px; }
}
