/* Palette Maths0 = palette du site principal (blanc / navy / orange clair),
   comme la bannière d'accueil — demande explicite de l'utilisateur, à la
   place d'une teinte distincte par chapitre. Une seule palette pour tous
   les chapitres : `[data-theme]` reste posé dans le HTML (cf.
   content/content.json > chapitres[].color) mais ne change plus rien ici,
   pour ne pas avoir à toucher le contenu si l'un ou l'autre revient. */
: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;
  /* Orangé clair utilisé sur fond navy (bannière d'accueil du site,
     `.home-banner-note a`) — demande explicite de l'utilisateur pour le
     bandeau sombre de Maths0, distinct de l'orange vif des boutons. */
  --accent-light: #ffc78a;
}

* { 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: 14px;
  padding: 16px 24px;
  background: var(--ink);
  color: #fff;
}
.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; }
.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.85rem;
}
.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.85; font-weight: 600; color: var(--accent-light); }
.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: 8px; }
  .back-link span.back-label { display: none; }
  .brand-text { font-size: 1rem; }
  .nav-btn { padding: 7px 10px; font-size: 0.76rem; }
}
@media (max-width: 360px) {
  /* Sous 360px, même deux libellés courts ("Composer"/"Progression") ne
     tiennent plus à côté du monogramme + "← " : le monogramme porte seul
     la marque (cf. apps/web, même geste sur le header du site). */
  .brand-text { display: none; }
}

#app { max-width: 880px; margin: 0 auto; padding: 26px 16px 60px; }
.footer { text-align: center; padding: 18px; color: var(--ink-soft); font-size: 0.82rem; }

.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);
}

/* ── Compositeur ─────────────────────────────────────────────────────── */
.chapter-block { margin-top: 14px; }
.chapter-head {
  display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--theme);
  padding: 8px 0;
}
.chapter-head--soon { color: var(--ink-soft); }
.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;
}
.soon-badge { margin-left: auto; font-size: 0.75rem; font-weight: 700; color: var(--ink-soft); background: var(--ivory-soft); padding: 3px 10px; border-radius: 999px; }
.chapter-avg { margin-left: auto; font-weight: 800; color: var(--theme); }

.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; }

.primary-btn {
  background: var(--accent); color: #fff; border: none; padding: 12px 22px; border-radius: 999px;
  font-size: 1rem; font-weight: 700; cursor: pointer; font-family: inherit; transition: background .15s;
}
.primary-btn:hover { background: var(--accent-600); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.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; }

/* ── 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 ol { margin: 0 0 10px; padding-left: 22px; line-height: 1.65; }
.rappel-body strong { color: var(--theme); }
.rappel-table { width: 100%; border-collapse: collapse; margin: 4px 0 14px; background: var(--card); border-radius: 10px; overflow: hidden; }
.rappel-table th, .rappel-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 0.92rem; text-align: center; }
.rappel-table th:first-child, .rappel-table td:first-child { text-align: left; }
.rappel-table th { background: var(--theme); color: #fff; font-weight: 700; }
.rappel-table tr:last-child td { border-bottom: none; }

/* ── 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; }
.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); }

/* ── Calculatrice ─────────────────────────────────────────────────────── */
.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; }
.calc-combi { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; }
.calc-combi-title { font-weight: 800; font-size: 0.82rem; text-transform: uppercase; letter-spacing: .3px; color: var(--ink-soft); margin-bottom: 8px; }
.calc-combi-row { display: flex; gap: 10px; margin-bottom: 10px; }
.calc-combi-row label { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; color: var(--ink-soft); font-weight: 700; }
.calc-combi-row input {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 1rem;
  font-family: inherit; color: var(--ink); width: 100%;
}
.calc-combi-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.calc-combi-btns button {
  flex: 1; min-height: 40px; border-radius: 999px; border: 1.5px solid var(--theme); background: #fff;
  color: var(--theme); font-weight: 700; cursor: pointer; font-family: inherit;
}
.calc-combi-result { margin-top: 10px; font-weight: 700; color: var(--ink); min-height: 1.2em; word-break: break-word; }

@media (max-width: 360px) {
  .calc-card { padding: 12px; }
  .calc-grid button { min-height: 42px; font-size: 0.98rem; }
}
.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; box-shadow: var(--shadow); }
.quiz-card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
/* Petit rappel visuel de la marque sur chaque question, en haut à droite —
   demande de l'utilisateur. Le vrai logo du site (`LOGO_KHOUBAIB` dans
   app.js, copie du SVG d'apps/web/components/Header.tsx), pas le monogramme
   « M0 » du topbar de cette appli. Posé comme DERNIER élément de
   `.quiz-card-head` : `justify-content: space-between` le pousse tout à
   droite et décale « Revoir le rappel » vers le centre, sans chevauchement. */
.quiz-card-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 8px; flex: none; overflow: hidden;
}
.quiz-card-logo svg { width: 100%; height: 100%; display: block; }
.badge { display: inline-block; background: var(--theme-soft); color: var(--theme); border-radius: 999px; padding: 4px 12px; font-size: 0.8rem; font-weight: 700; }

.prompt { font-size: 1.15rem; margin-bottom: 16px; line-height: 1.6; font-weight: 600; }

/* Courbe à lire (renderFigure dans app.js) : repère orthonormé quadrillé. */
.fig-courbe { margin: 0 auto 18px; max-width: 400px; }
.fig-courbe svg { width: 100%; height: auto; display: block; background: #fff; border: 1px solid var(--border); border-radius: 14px; }
.fig-grid { stroke: #e6ebf2; stroke-width: 1; }
.fig-axe { stroke: #334155; stroke-width: 1.4; }
.fig-arrow { fill: #334155; }
.fig-tick { font: 500 11px Inter, system-ui, sans-serif; fill: #475569; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.fig-axis-name { font: italic 600 13px Georgia, serif; fill: #334155; }
.fig-curve { fill: none; stroke: var(--theme); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.fig-curve.c2 { stroke: #e8590c; }
.fig-guide { stroke: #e8590c; stroke-width: 1.3; stroke-dasharray: 4 3; }
.fig-pt { fill: #e8590c; stroke: #fff; stroke-width: 1.6; }
.fig-lab { font: 700 12px Inter, system-ui, sans-serif; fill: #0f172a; paint-order: stroke; stroke: #fff; stroke-width: 3.5px; }
.fig-name { font: italic 700 15px Georgia, serif; fill: var(--theme); paint-order: stroke; stroke: #fff; stroke-width: 3.5px; }
.fig-name.c2 { fill: #e8590c; }
.katex { color: inherit; }

.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); }

.feedback { margin-top: 16px; padding: 12px 16px; border-radius: 12px; font-size: 0.98rem; 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: 8px 0; }
.result-table { width: 100%; border-collapse: collapse; margin-top: 16px; text-align: left; }
.result-table th, .result-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.result-table th { color: var(--ink-soft); font-weight: 700; }

@media (max-width: 640px) {
  #app { padding: 18px 12px 44px; }
  .quiz-card, .rappel-card { padding: 16px; }
  .prompt { font-size: 1.05rem; }
}
