/* Palette et mise en page reprises de server/seconddegre/styles.css à
   l'identique : ivoire/navy/orange, polices Fraunces (titres) + Inter
   (corps) — la palette du site, comme les mini-applis Première récentes. */
:root {
  --ivory: #ffffff;
  --ivory-soft: #f4f6f9;
  --card: #ffffff;
  --ink: #002b5c;
  --ink-soft: #5a6b7b;
  --border: #e2e8f0;
  --shadow: 0 6px 20px rgba(0, 43, 92, 0.08);
  --shadow-lg: 0 14px 36px rgba(0, 43, 92, 0.16);
  --radius: 14px;
  --green: #16a34a;
  --red: #dc2626;

  --theme: #002b5c;
  --theme-soft: #eaf3fb;
  --blue: #0073cf;
  --accent: #ff6a13;
  --accent-600: #e85d08;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--ivory);
  color: var(--ink);
}
h2 {
  font-family: "Fraunces", Georgia, serif;
  color: var(--ink);
  font-weight: 700;
  margin: 0 0 6px;
}
.muted { color: var(--ink-soft); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 24px;
  background: var(--ink);
  color: #fff;
}
.topbar h1 { font-size: 1.2rem; margin: 0; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back-link { color: #fff; opacity: 0.85; text-decoration: none; font-size: 0.9rem; font-weight: 600; flex: none; white-space: nowrap; }
.back-link:hover { opacity: 1; text-decoration: underline; }
.topbar nav { display: flex; gap: 8px; flex: none; }
.nav-btn {
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.35); color: #fff;
  padding: 8px 16px; border-radius: 999px; cursor: pointer; font-size: 0.88rem; font-weight: 700; white-space: nowrap;
}
.nav-btn:hover { background: rgba(255,255,255,0.22); }

@media (max-width: 640px) {
  .topbar { padding: 12px 14px; gap: 6px; }
  .topbar h1 { font-size: 1.02rem; }
  .back-link span.back-label { display: none; }
  .nav-btn { padding: 7px 10px; font-size: 0.78rem; }
}
@media (max-width: 420px) {
  .topbar h1 svg { display: none; }
}

#app { max-width: 900px; margin: 0 auto; padding: 26px 16px 60px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; margin-top: 16px; }
.card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; background: var(--card);
  cursor: pointer; transition: box-shadow .15s, transform .15s, border-color .15s;
}
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-3px); border-color: var(--theme); }
.card h3 { margin: 0 0 6px; font-size: 1.02rem; color: var(--ink); }
.card p { margin: 0; font-size: 0.85rem; color: var(--ink-soft); }

.section-title {
  margin-top: 28px; padding-bottom: 6px; font-size: 0.95rem; color: var(--ink);
  font-weight: 800; text-transform: uppercase; letter-spacing: .5px; border-bottom: 2px solid var(--border);
}

.badge { display: inline-block; background: var(--theme-soft); color: var(--theme); border-radius: 999px; padding: 4px 12px; font-size: 0.8rem; font-weight: 700; }

/* ── Compositeur (chips par paragraphe) ──────────────────────────────── */
.chapter-block { margin-top: 14px; }
.chapter-head { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--theme); padding: 8px 0; }
.chapter-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; background: var(--theme-soft); color: var(--theme);
  font-weight: 800; font-size: 0.8rem; flex: none;
}
.paragraphe-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 6px; }
.paragraphe-chip {
  border: 1.5px solid var(--border); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 18px; font-size: 0.88rem; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: all .12s ease;
}
.paragraphe-chip:hover { border-color: var(--theme); }
.paragraphe-chip.is-selected { background: var(--theme); border-color: var(--theme); color: #fff; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  border: 1.5px solid var(--border); background: var(--card); color: var(--ink);
  padding: 7px 16px; border-radius: 999px; font-size: 0.88rem; font-weight: 700; cursor: pointer; font-family: inherit;
}
.chip.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }

.roadmap {
  margin-top: 24px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.roadmap-title { font-weight: 800; font-size: 0.85rem; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-soft); margin-bottom: 8px; }
.roadmap-body { display: flex; flex-wrap: wrap; gap: 6px; }
.roadmap-pill { background: var(--theme-soft); color: var(--theme); font-weight: 700; font-size: 0.82rem; padding: 5px 12px; border-radius: 999px; }

/* ── Rappel de cours ─────────────────────────────────────────────────── */
.rappel-card {
  background: var(--theme-soft); border: 1px solid var(--theme); border-radius: var(--radius);
  padding: 22px; margin-top: 14px;
}
.rappel-tag { font-weight: 800; font-size: 0.82rem; text-transform: uppercase; letter-spacing: .3px; color: var(--theme); margin-bottom: 10px; }
.rappel-body p { margin: 0 0 10px; line-height: 1.65; }
.rappel-body strong { color: var(--theme); }
.revoir-rappel-btn {
  background: none; border: none; color: var(--blue); text-decoration: underline; cursor: pointer;
  font-size: 0.85rem; font-family: inherit; padding: 0; margin-bottom: 10px;
}

/* ── Question ─────────────────────────────────────────────────────────── */
.top-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.top-actions-left { display: flex; align-items: center; gap: 14px; }
.link-btn { background: none; border: none; color: var(--blue); text-decoration: underline; cursor: pointer; font-size: 0.9rem; padding: 0; font-weight: 600; font-family: inherit; flex: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 999px;
  border: 1.5px solid var(--border); background: var(--card); color: var(--theme); cursor: pointer; padding: 0; flex: none;
}
.icon-btn:hover { border-color: var(--theme); }

.progress-bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.progress-bar-fill { height: 100%; background: var(--theme); transition: width .2s; }

.quiz-card { background: var(--card); border: 1px solid var(--border); border-top: 4px solid var(--theme); border-radius: var(--radius); padding: 24px; margin-top: 20px; box-shadow: var(--shadow); }
.prompt { font-size: 1.15rem; margin-bottom: 16px; line-height: 1.6; font-weight: 600; }
.katex { color: inherit; }
.svg-wrap { display: flex; justify-content: center; margin-bottom: 16px; max-width: 100%; overflow-x: auto; }
.svg-wrap svg { max-width: 100%; height: auto; }

/* Tableau "division posée" (facteurs premiers) — la barre verticale sépare
   le dividende du diviseur, comme sur une feuille de cours. */
.decomp-table { border-collapse: collapse; margin: 0 auto; font-size: 1.05rem; font-weight: 700; color: var(--ink); }
.decomp-table th { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; color: var(--ink-soft); padding: 4px 18px 8px; }
.decomp-table td { padding: 5px 18px; text-align: center; }
.decomp-table td:first-child, .decomp-table th:first-child { border-right: 2px solid var(--ink); }

/* ── QCM (choix multiples) ──────────────────────────────────────────── */
.choices { display: grid; gap: 10px; }
.choice-btn {
  text-align: left; border: 1.5px solid var(--border); background: var(--ivory-soft); color: var(--ink);
  padding: 12px 16px; border-radius: 12px; font-size: 1rem; font-family: inherit; cursor: pointer; transition: all .12s;
}
.choice-btn:hover:not(:disabled) { border-color: var(--theme); }
.choice-btn:disabled { cursor: default; }
.choice-btn.choice-correct { background: #e3f3e6; border-color: var(--green); color: var(--green); font-weight: 700; }
.choice-btn.choice-wrong { background: #fbe7e5; border-color: var(--red); color: var(--red); }

.answer-row { display: flex; gap: 10px; }
.answer-row input {
  flex: 1; padding: 12px 14px; font-size: 1.1rem; border: 2px solid var(--border); border-radius: 10px; font-family: inherit;
}
.answer-row input:focus { outline: none; border-color: var(--theme); }
.answer-row button, .primary-btn {
  background: var(--accent); color: #fff; border: none; padding: 12px 22px; border-radius: 999px;
  font-size: 1.05rem; font-weight: 700; cursor: pointer; font-family: inherit; transition: background .15s ease, transform .05s ease;
}
.answer-row button:hover, .primary-btn:hover { background: var(--accent-600); }
.answer-row button:active, .primary-btn:active { transform: translateY(1px); }
.primary-btn:disabled { opacity: .4; cursor: not-allowed; }

.feedback { margin-top: 16px; padding: 14px 16px; border-radius: 10px; font-size: 1.05rem; font-weight: 600; }
.feedback.correct { background: #e3f3e6; color: var(--green); }
.feedback.incorrect { background: #fbe7e5; color: var(--red); }
.feedback-expl { margin-top: 6px; font-weight: 500; font-size: 0.9rem; opacity: 0.9; }

.result-summary { text-align: center; }
.result-score { font-size: 2.4rem; font-weight: 800; color: var(--theme); margin: 12px 0; }
.result-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.result-table th, .result-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.result-table th { color: var(--ink-soft); }

/* ── Accueil "Préparation au contrôle" (cartes de test) ─────────────────── */
.defi-carte {
  background: var(--card); border: 1px solid var(--border); border-top: 4px solid var(--accent);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); text-align: center;
}
.defi-carte-icone {
  display: inline-flex; align-items: center; justify-content: center; width: 46px; height: 46px;
  border-radius: 50%; background: var(--theme-soft); color: var(--theme); margin-bottom: 10px;
}
.defi-carte h3 { margin: 0 0 10px; color: var(--ink); }
.defi-carte-classement { font-size: 0.82rem; line-height: 1.6; text-align: left; min-height: 44px; }
.defi-classement-titre { display: block; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.defi-classement-liste { margin: 0 0 6px; padding-left: 20px; }
.defi-classement-liste li { margin-bottom: 2px; }

/* ── Chrono par question (mode défi) ─────────────────────────────────────── */
.timer-row { display: flex; justify-content: flex-end; margin-bottom: 4px; font-size: 0.85rem; color: var(--ink-soft); }
.timer-row strong { color: var(--theme); font-variant-numeric: tabular-nums; }
.timer-bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
.timer-bar-fill { height: 100%; background: var(--theme); transition: width 1s linear; }
.timer-bar-fill--urgent { background: var(--red); }
.choice-btn.choice-pending { opacity: 0.6; }

/* ── Écran "Prépare-toi !" (confirmation avant un test chronométré) ─────── */
.rappel-defi { text-align: center; }
.rappel-defi-question { font-size: 1.3rem; font-weight: 800; color: var(--ink); margin: 6px 0 4px; }
.rappel-defi-consigne { font-size: 1rem; margin-bottom: 16px; color: var(--ink-soft); }
.rappel-defi-liste { text-align: left; background: var(--ivory-soft); border-radius: 10px; padding: 14px 18px; margin-bottom: 14px; }
.rappel-defi-liste ul { margin: 0; padding-left: 20px; }
.rappel-defi-liste li { margin-bottom: 4px; }
#prepChrono { font-variant-numeric: tabular-nums; font-weight: 700; }

/* ── Confettis (bonne réponse en mode défi) ──────────────────────────────── */
.confetti-conteneur { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 300; }
.confetti-morceau {
  position: absolute; top: 100%; width: 9px; height: 9px; border-radius: 2px;
  animation: confetti-envol var(--duree, 1.2s) ease-out var(--delai, 0s) forwards;
}
@keyframes confetti-envol {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--decalage, 0), -110vh) rotate(540deg); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .confetti-conteneur { display: none; }
}

/* ── Rapport de fin de défi (double score, faiblesses) ───────────────────── */
.defi-sous-scores { display: flex; justify-content: center; gap: 24px; margin: 10px 0 6px; flex-wrap: wrap; }
.defi-sous-scores > div { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.85rem; color: var(--ink-soft); }
.defi-sous-scores strong { font-size: 1.15rem; color: var(--theme); }
.defi-rapport { text-align: left; background: var(--theme-soft); border-radius: 10px; padding: 16px 18px; margin-top: 16px; }
.defi-rapport-titre { font-weight: 800; color: var(--theme); margin: 0 0 8px; }
.defi-rapport ul { margin: 0 0 12px; padding-left: 20px; }
.defi-rapport li { margin-bottom: 4px; }

/* ── Calculatrice flottante (copie de server/seconddegre/, pour vérifier
     un calcul intermédiaire) ────────────────────────────────────────── */
.calc-overlay { position: fixed; inset: 0; background: rgba(0, 43, 92, 0.45); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; }
.calc-card { width: min(320px, 100%); background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.calc-head { display: flex; align-items: center; justify-content: space-between; font-weight: 800; color: var(--ink); margin-bottom: 10px; }
.calc-close { background: none; border: none; color: var(--ink-soft); cursor: pointer; padding: 4px; display: flex; }
.calc-display { background: var(--ivory-soft); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; text-align: right; font-size: 1.6rem; font-weight: 700; color: var(--ink); margin-bottom: 10px; overflow-x: auto; white-space: nowrap; }
.calc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.calc-grid button { min-height: 46px; border-radius: 10px; border: 1px solid var(--border); background: var(--ivory-soft); color: var(--ink); font-size: 1.05rem; font-weight: 700; cursor: pointer; font-family: inherit; }
.calc-grid button:active { background: var(--theme-soft); }
.calc-grid button[data-op], .calc-grid button[data-act="sqrt"], .calc-grid button[data-act="pow"] { background: var(--theme-soft); color: var(--theme); }
.calc-zero { grid-column: span 2; }
.calc-eq { background: var(--accent) !important; color: #fff !important; border-color: var(--accent) !important; }

@media (max-width: 640px) {
  #app { padding: 18px 12px 44px; }
  .quiz-card, .rappel-card { padding: 16px; }
  .prompt { font-size: 1.05rem; }
  .answer-row { flex-direction: column; }
  .answer-row button { width: 100%; }
}
@media (max-width: 360px) {
  .calc-card { padding: 12px; }
  .calc-grid button { min-height: 42px; font-size: 0.98rem; }
}

/* ══════════ Terminale — limites & suites : habillage façon Maths0 ══════════ */
:root { --accent-light: #ffc78a; }
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; flex: 1; min-width: 0; overflow: hidden; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: #fff; color: var(--ink); font-weight: 800; font-size: 0.8rem;
}
.brand-text { font-family: "Fraunces", Georgia, serif; font-weight: 700; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text em { font-style: normal; opacity: 0.9; font-weight: 600; color: var(--accent-light); }
@media (max-width: 640px) { .brand-text { font-size: 1rem; } }
@media (max-width: 480px) { .brand-text em { display: none; } }
.footer { text-align: center; padding: 18px; color: var(--ink-soft); font-size: 0.82rem; }

/* Écran 1 (prénom) et écran 2 (double vérification stylo) */
.entree-card {
  max-width: 520px; margin: 10px auto 0; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 24px; text-align: center;
}
.entree-badge {
  width: 54px; height: 54px; margin: 0 auto 10px; border-radius: 16px; display: flex; align-items: center; justify-content: center;
  background: var(--theme-soft); color: var(--theme);
}
.entree-label { display: block; margin: 20px 0 8px; font-weight: 800; font-size: 1.05rem; color: var(--ink); }
.entree-input {
  width: 100%; max-width: 320px; padding: 12px 14px; font-size: 1.1rem; font-family: inherit; text-align: center;
  border: 2px solid var(--border); border-radius: 12px; color: var(--ink);
}
.entree-input:focus { outline: none; border-color: var(--accent); }
.entree-materiel { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin: 18px 0 6px; }
.entree-materiel span {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 12px;
  background: var(--ivory-soft); font-weight: 700; color: var(--ink);
}
.entree-go { width: 100%; margin-top: 16px; font-size: 1.05rem; }
.entree-go:disabled { opacity: 0.45; cursor: not-allowed; }
.verif-card { text-align: left; }
.verif-alerte {
  display: flex; flex-direction: column; gap: 4px; margin: 10px 0 16px; padding: 14px 16px; border-radius: 12px;
  background: #fff4ec; border-left: 4px solid var(--accent); color: var(--ink);
}
.verif-alerte strong { font-size: 1.08rem; }
.verif-check {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 2px solid var(--border);
  border-radius: 12px; cursor: pointer; font-weight: 700; color: var(--ink);
}
.verif-check:has(input:checked) { border-color: var(--green); background: #effaf3; }
.verif-check input { width: 22px; height: 22px; accent-color: var(--green); flex: none; }
.rappel-defi-liste summary { cursor: pointer; font-weight: 700; color: var(--ink); }
.rappel-defi-liste ul { margin-top: 8px; }

/* Étapes déjà rédigées (limites guidées, démonstration par récurrence) */
.svg-wrap > .etapes { width: 100%; }
.etapes {
  text-align: left; background: var(--ivory-soft); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 16px; overflow-x: auto;
}
.etapes-titre { margin: 0 0 6px; font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-soft); }
.etapes ol { margin: 0; padding-left: 22px; }
.etapes li { margin: 6px 0; line-height: 1.7; }
.etape-trou { color: var(--accent-600); font-weight: 700; }
.etape-trou-marque {
  display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; margin-right: 6px;
}
/* Formules longues : défilement dans le bouton plutôt qu'un débordement de page */
.choice-btn, .prompt, .feedback-expl { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
