/* ── Base ── */
:root {
  --bg: #faf6f0;
  --card: #ffffff;
  --border: #eadfd2;
  --text: #2c1810;
  --muted: #6b5d54;
  --primary: #8b5a3c;
  --primary-dark: #6b4329;
  --accent: #d4a574;
  --success: #4caf50;
  --success-bg: #e8f5e9;
  --error: #e76f51;
  --error-bg: #fdeee8;
  --shadow: 0 4px 14px rgba(60, 30, 10, 0.08);
  --shadow-lg: 0 10px 30px rgba(60, 30, 10, 0.14);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse at top, #fff4e3 0%, var(--bg) 60%),
    var(--bg);
  min-height: 100vh;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

h1, h2 {
  color: var(--text);
  margin: 0 0 12px;
  line-height: 1.2;
}

h1 { font-size: 2.2rem; }
h2 { font-size: 1.25rem; }

p { margin: 0 0 12px; }

.hidden { display: none !important; }

/* ── Hero (écran d'accueil) ── */
.hero {
  text-align: center;
  padding: 24px 8px 8px;
}

.hero-emoji {
  font-size: 4rem;
  line-height: 1;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 8px rgba(139, 90, 60, 0.25));
}

.subtitle {
  color: var(--muted);
  font-size: 1.05rem;
  margin-bottom: 4px;
}

.tagline {
  color: var(--primary);
  font-weight: 500;
  font-size: 1rem;
}

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 16px;
}

/* ── Card ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card h2 { margin-bottom: 14px; }

/* ── Liste de thèmes ── */
.theme-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}

.section-label {
  margin-top: 8px;
  margin-bottom: 10px;
  font-size: 1.05rem;
}

.count-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.count-list .theme-chip {
  min-width: 64px;
  padding: 10px 18px;
}

/* ── Mode selector ── */
.mode-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
@media (min-width: 560px) {
  .mode-list { grid-template-columns: repeat(4, 1fr); }
}

.mode-chip {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 14px 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  line-height: 1.2;
}
.mode-chip:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.mode-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.mode-chip .mode-emoji {
  font-size: 1.6rem;
  filter: grayscale(0);
}
.mode-chip .mode-sub {
  font-size: 0.72rem;
  font-weight: 500;
  opacity: 0.8;
}

/* ── Study mode ── */
.study-header {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 12px;
}

.btn.small { padding: 8px 16px; font-size: 0.85rem; }

#study-article h1 {
  font-size: 1.9rem;
  margin-bottom: 6px;
}

#study-article .lesson-intro {
  color: var(--muted);
  font-size: 1rem;
  font-style: italic;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.lesson-section {
  margin-bottom: 22px;
}

.lesson-section h3 {
  font-size: 1.05rem;
  color: var(--primary-dark);
  margin: 0 0 10px;
  font-weight: 700;
}

.lesson-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.lesson-section li {
  padding: 8px 10px 8px 28px;
  position: relative;
  line-height: 1.55;
  color: var(--text);
  border-left: 2px solid var(--border);
  margin-left: 4px;
  transition: border-color 0.15s;
}

.lesson-section li:hover {
  border-left-color: var(--accent);
}

.lesson-section li::before {
  content: "•";
  position: absolute;
  left: 10px;
  color: var(--primary);
  font-weight: 700;
}

.lesson-section strong {
  color: var(--primary-dark);
  font-weight: 700;
}

/* TOC */
.toc-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.toc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  transition: all 0.15s;
}
.toc-item:hover {
  border-color: var(--accent);
  background: #fff;
  transform: translateX(2px);
}
.toc-item .toc-emoji { font-size: 1.4rem; }

/* ── Flashcards ── */
.flashcard-wrap {
  perspective: 1200px;
  margin: 20px 0 24px;
}

.flashcard {
  position: relative;
  min-height: 360px;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}

.flashcard.flipped { transform: rotateY(180deg); }

.flashcard-inner {
  position: relative;
  transform-style: preserve-3d;
}

.card-face {
  position: absolute;
  inset: 0;
  min-height: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 22px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-face.back {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, #fff4e3 0%, #fff 100%);
}

.card-label {
  display: inline-block;
  align-self: flex-start;
  background: var(--primary);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 16px;
}
.card-label.ok { background: var(--success); }

.card-text {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
  flex: 1;
  display: flex;
  align-items: center;
  margin: 0 0 20px;
}

.card-answer {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--success);
  margin: 0 0 12px;
  line-height: 1.35;
}

.card-explanation {
  font-size: 0.98rem;
  color: var(--muted);
  line-height: 1.55;
  flex: 1;
  margin: 0 0 20px;
}

.card-face .btn { align-self: stretch; }

/* Hide count-wrap in study mode */
#count-wrap.hidden { display: none; }

/* ── Images dans les fiches ── */
.lesson-figure {
  margin: 8px 0 16px;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.lesson-figure img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 80vh;
  object-fit: contain;
  background: #fff;
}

.lesson-figure figcaption {
  padding: 10px 14px;
  font-size: 0.88rem;
  color: var(--muted);
  font-style: italic;
  text-align: center;
  border-top: 1px solid var(--border);
}

/* ── Mode QCM ── */
.mcq-hint {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0 0 14px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 10px;
  border-left: 3px solid var(--accent);
}

.mcq-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.mcq-choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 14px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  transition: all 0.15s;
  line-height: 1.4;
}
.mcq-choice:hover:not(.locked) {
  border-color: var(--accent);
  background: #fff;
  transform: translateX(2px);
}
.mcq-choice.selected {
  border-color: var(--primary);
  background: #fff4e3;
}
.mcq-choice.locked { cursor: default; }

.mcq-choice input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  accent-color: var(--primary);
  cursor: pointer;
  margin-top: 1px;
}
.mcq-choice.locked input[type="checkbox"] { cursor: default; }

.mcq-choice.correct {
  border-color: var(--success);
  background: var(--success-bg);
  color: #1b5e20;
}
.mcq-choice.wrong {
  border-color: var(--error);
  background: var(--error-bg);
  color: #8a2a1a;
}
.mcq-choice.missed {
  border-color: #f0a84e;
  background: #fff4e3;
  color: #7a5414;
  border-style: dashed;
}

.mcq-choice .mcq-marker {
  margin-left: auto;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}
.mcq-choice.correct .mcq-marker { background: var(--success); color: #fff; }
.mcq-choice.wrong .mcq-marker { background: var(--error); color: #fff; }
.mcq-choice.missed .mcq-marker { background: #f0a84e; color: #fff; }

.btn-block { display: block; width: 100%; }

.mcq-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 8px 0 14px;
  padding: 0;
}
.mcq-legend span::before {
  content: "●";
  margin-right: 5px;
}
.mcq-legend .ok::before { color: var(--success); }
.mcq-legend .ko::before { color: var(--error); }
.mcq-legend .mi::before { color: #f0a84e; }

/* ── Image optionnelle sur une question ── */
.question-image {
  margin: 0 0 16px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
}
.question-image img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 340px;
  object-fit: contain;
}
.question-image.hidden { display: none; }

.theme-chip {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  text-align: center;
}

.theme-chip:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.theme-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.theme-chip .count {
  opacity: 0.7;
  font-size: 0.8rem;
  margin-left: 4px;
}

/* ── Boutons ── */
.btn {
  display: inline-block;
  padding: 14px 24px;
  border-radius: 999px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(139, 90, 60, 0.3);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(139, 90, 60, 0.4);
}

.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--border);
}

.btn-ghost:hover { background: var(--bg); border-color: var(--primary); }

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

/* ── Quiz ── */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 500;
}

.theme-tag {
  background: #fff4e3;
  color: var(--primary-dark);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.stats { display: flex; gap: 10px; }

.stat {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}

.streak { color: #e76f51; }
.score  { color: var(--primary); }

.progress {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 18px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  transition: width 0.3s ease;
}

.question-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.question-card h2 {
  font-size: 1.2rem;
  margin-bottom: 18px;
  line-height: 1.35;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  text-align: left;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: all 0.15s;
}

.choice:hover:not(:disabled) {
  border-color: var(--accent);
  background: #fff;
  transform: translateX(2px);
}

.choice:disabled { cursor: default; }

.choice .bullet {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--muted);
  flex-shrink: 0;
}

.choice.correct {
  border-color: var(--success);
  background: var(--success-bg);
  color: #1b5e20;
}
.choice.correct .bullet {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.choice.wrong {
  border-color: var(--error);
  background: var(--error-bg);
  color: #8a2a1a;
}
.choice.wrong .bullet {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}

.choice.dim { opacity: 0.55; }

/* ── Feedback ── */
.feedback {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.feedback-status {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.feedback-status.ok { color: var(--success); }
.feedback-status.ko { color: var(--error); }

.explanation {
  color: var(--muted);
  margin-bottom: 14px;
  line-height: 1.55;
}

.feedback .btn { width: 100%; }

/* ── Fin ── */
.end-hero { text-align: center; padding: 24px 8px 8px; }

.final-score {
  text-align: center;
  padding: 16px 0 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.score-big {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 4px;
}

.score-pct {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 10px;
}

.score-streak { color: var(--muted); font-size: 0.95rem; }

.theme-recap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theme-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.theme-row:last-child { border: none; }

.theme-name { font-weight: 600; flex-shrink: 0; min-width: 110px; }

.theme-bar-wrap {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.theme-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  border-radius: 999px;
}

.theme-score {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  min-width: 48px;
  text-align: right;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  h1 { font-size: 1.8rem; }
  .hero-emoji { font-size: 3.2rem; }
  .card { padding: 16px; }
  .question-card { padding: 18px; }
  .btn { padding: 13px 22px; font-size: 0.95rem; }
  .theme-list { grid-template-columns: repeat(2, 1fr); }
  .theme-name { min-width: 90px; font-size: 0.9rem; }
}
