:root {
  --navy: #10243f;
  --accent: #0e7490;
  --fuchsia: #b5267a;
  --orange: #e76f00;
  --orange-bg: #fff4e8;
  --blue: #1f4e9c;
  --blue-bg: #eef3fb;
  --bg: #f4f8f8;
  --card: #ffffff;
  --ink: #14243a;
  --muted: #5b6b7a;
  --line: #d8e0e4;
  --good: #1b7f3b;
  --good-bg: #e7f6ec;
  --bad: #c62828;
  --bad-bg: #fdecec;
  --mid: #2e7d6b;
  --rep: #c62828;
  --rap-prop: #1565c0;
  --rap-defi: #2e7d6b;
  --rap-meth: #7b3f9e;
  --rap-rem: #5b6b7a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  font-size: 16.5px;
}
a { color: var(--accent); }
code { background: #eef2f4; padding: 0 4px; border-radius: 4px; font-size: .92em; }
.rep { color: var(--rep); }

/* ---------------------------------------------------------------- en-tête */
.top {
  background: linear-gradient(135deg, #10243f 0%, #0e7490 55%, #2a9d8f 100%);
  color: #fff;
}
.top-inner { max-width: 980px; margin: auto; padding: 18px 16px 20px; }
.crumbs { font-size: .85rem; opacity: .85; margin-bottom: 10px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.crumbs a { color: #fff; text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sp { flex: 1; }
.titlerow { display: flex; align-items: center; gap: 14px; }
.fnum {
  flex: none; width: 58px; height: 58px; border-radius: 50%;
  background: var(--fuchsia); color: #fff; font-weight: 800; font-size: 1.25rem;
  display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.titlerow h1 { margin: 0; font-size: clamp(1.35rem, 4vw, 2rem); line-height: 1.15; }
.titlerow .eyebrow { font-size: .75rem; letter-spacing: 2px; text-transform: uppercase; opacity: .75; }

/* barre de progression collante */
.bar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(255,255,255,.96); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.bar-inner { max-width: 980px; margin: auto; padding: 8px 16px; display: flex; gap: 10px 16px; align-items: center; flex-wrap: wrap; }
.score { flex: 1 1 260px; min-width: 0; }
#score-text { font-size: .88rem; color: var(--muted); }
#score-bar { height: 8px; background: #e6ecef; border-radius: 4px; overflow: hidden; display: flex; margin-top: 4px; }
#score-bar span { display: block; height: 100%; transition: width .3s; }
.b-ok1 { background: var(--good); } .b-ok { background: #6cbf8a; } .b-ko { background: #e57373; }
.bilan { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#nom { width: 11em; }
#nom.need { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
#bilan-msg { font-size: .8rem; color: var(--muted); width: 100%; text-align: right; }
#bilan-msg:empty { display: none; }

/* ---------------------------------------------------------------- contenu */
main { max-width: 980px; margin: auto; padding: 16px 16px 60px; }
.notice { font-size: .85rem; color: var(--muted); margin: 0 0 14px; }

.rappels { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 16px; margin-bottom: 22px; }
.rappels > summary { cursor: pointer; font-weight: 700; color: var(--blue); padding: 10px 0; font-size: 1.05rem; }
.rap { border-left: 4px solid var(--rap-prop); padding: 6px 12px; margin: 10px 0 14px; background: #f7f9fc; border-radius: 0 8px 8px 0; }
.rap.definition { border-color: var(--rap-defi); }
.rap.methode { border-color: var(--rap-meth); }
.rap.theoreme { border-color: var(--rap-prop); }
.rap.remarque { border-color: var(--rap-rem); background: #fafafa; }
.raptitle { margin-bottom: 4px; }
.raptitle b { color: var(--rap-prop); margin-right: 4px; }
.rap.definition .raptitle b { color: var(--rap-defi); }
.rap.methode .raptitle b { color: var(--rap-meth); }
.rap.remarque .raptitle b { color: var(--rap-rem); }
.rapbody ul, .corr ul, .stem ul { margin: 4px 0; padding-left: 1.3em; }

.sec h2 {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  margin: 28px 0 8px; padding: 8px 14px; border-radius: 8px; font-size: 1.25rem;
}
.sec-qcm h2 { background: var(--orange-bg); color: var(--orange); }
.sec-exo h2 { background: var(--blue-bg); color: var(--blue); }
.count { font-size: .82rem; font-weight: 500; color: var(--muted); }
.consigne { color: var(--muted); font-size: .92rem; margin: 0 0 12px; }
.consigne p { margin: 0 0 6px; }
.aide summary { cursor: pointer; color: var(--accent); }
.aide ul { margin: 6px 0; padding-left: 1.3em; }

/* ---------------------------------------------------------------- questions */
.q {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin: 12px 0; scroll-margin-top: 70px;
  border-left: 5px solid var(--line);
}
.q.qcm { border-left-color: #f3b37a; }
.q.exo { border-left-color: #9db5dd; }
.q[data-status="ok1"], .q[data-status="ok"] { border-left-color: var(--good); }
.q[data-status="ko"] { border-left-color: var(--bad); }
.qhead { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.qnum { font-weight: 800; font-family: ui-sans-serif, system-ui, sans-serif; }
.qcm .qnum { color: var(--orange); }
.exo .qnum { color: var(--blue); }
.qtitle { font-style: italic; color: var(--muted); font-size: .92rem; flex: 1; }
.badge { font-size: .75rem; padding: 2px 9px; border-radius: 999px; background: #eef2f4; color: var(--muted); white-space: nowrap; }
.badge.ok1 { background: var(--good-bg); color: var(--good); font-weight: 600; }
.badge.ok { background: #eef8f1; color: var(--mid); }
.badge.ko { background: var(--bad-bg); color: var(--bad); }
.stem { margin-bottom: 8px; }
.center { text-align: center; margin: 8px 0; }
img.fig { max-width: 100%; height: auto; background: #fff; border-radius: 6px; }
table.tab { border-collapse: collapse; margin: 6px auto; }
table.tab td { border: 1px solid #9aa7b0; padding: 3px 10px; text-align: center; }
table.tab tr:first-child td { background: #f1f5f7; }

.opts { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.opts > .opt { flex: 1 1 auto; max-width: 100%; }
.opts.long { flex-direction: column; }
/* QCM : 4 colonnes égales, sinon une ligne, sinon 2 × 2, sinon une par ligne (choix fait par app.js) */
.qcmopts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.qcmopts.row { display: flex; flex-wrap: nowrap; }
.qcmopts.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.qcmopts.c1, .qcmopts.long { grid-template-columns: minmax(0, 1fr); }
.qcmopts.measure { display: flex; flex-wrap: nowrap; visibility: hidden; }
.qcmopts.measure > .opt { flex: none; max-width: none; }
.opts.chips > .opt { flex: 0 0 auto; }
@media (max-width: 640px) {
  body { font-size: 16px; }
  .q { padding: 12px; }
  #nom { flex: 1; min-width: 8em; }
}
.opt > span:last-child { min-width: 0; }
mjx-container[display="true"] { max-width: 100%; }
mjx-container { overflow: visible !important; }
.corr, .stem, .rapbody, .ptext { overflow-wrap: anywhere; }
.opt {
  font: inherit; color: inherit; text-align: left; cursor: pointer;
  background: #fbfcfd; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 8px 10px; display: flex; align-items: center; gap: 8px; min-height: 44px;
  transition: border-color .15s, background .15s;
}
.opt:hover:not(:disabled) { border-color: var(--accent); background: #f1f8fa; }
.opt:disabled { cursor: default; }
.opt.sel { border-color: var(--accent); background: #e3f3f6; box-shadow: inset 0 0 0 1px var(--accent); }
.opt.good { border-color: var(--good); background: var(--good-bg); }
.opt.bad { border-color: var(--bad); background: var(--bad-bg); }
.opt:disabled:not(.good):not(.bad):not(.sel) { opacity: .6; }
.lettre {
  flex: none; display: inline-grid; place-items: center; width: 1.6em; height: 1.6em;
  border: 1.5px solid currentColor; border-radius: 50%; font-size: .85em; font-weight: 600;
}
.corr .lettre { width: 1.4em; height: 1.4em; }

.fb { margin-top: 8px; font-size: .93rem; min-height: 0; }
.fb:empty { display: none; }
.fb.yes { color: var(--good); font-weight: 600; }
.fb.no { color: var(--bad); }

.corr { margin-top: 10px; padding: 10px 14px; background: #fbf8f2; border: 1px dashed #e0cfa9; border-radius: 10px; }
.corrtitle { font-weight: 700; color: #8a5a00; font-size: .85rem; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.corr ol { margin: 4px 0; padding-left: 1.4em; list-style: lower-alpha; }

/* champs de réponse */
.parts { display: flex; flex-direction: column; gap: 8px; }
.part { display: flex; flex-direction: column; gap: 6px; }
.part + .part { border-top: 1px dotted var(--line); padding-top: 8px; }
.ptext { display: flex; gap: 6px; }
.plabel { font-weight: 700; color: var(--blue); }
.field { padding: 4px 8px; border-radius: 8px; border: 1.5px solid transparent; }
.field.good { background: var(--good-bg); border-color: #a7dcb7; }
.field.bad { background: var(--bad-bg); border-color: #f2b8b8; }
.frow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pre, .post { white-space: normal; }
.note { font-size: .8rem; color: var(--muted); }
.inp {
  font: inherit; font-size: 1rem; padding: 6px 9px; border: 1.5px solid #b9c6ce; border-radius: 8px;
  background: #fff; color: var(--ink); max-width: 100%;
}
.inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px #cdeaf0; }
.inp:disabled { background: transparent; border-style: dashed; color: var(--ink); }
.ta { width: 100%; resize: vertical; }
select.inp { padding: 6px 4px; }
.pow { display: inline-flex; align-items: flex-start; }
.pow .expo { font-size: .85rem; padding: 3px 6px; margin-top: -12px; margin-left: 2px; }
.prevrow { min-height: 0; padding-left: 4px; color: var(--muted); font-size: .95rem; }
.preview:empty { display: none; }
.preview::before { content: "Lu : "; font-size: .8rem; }

.cmp { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 1.1rem; }
.cmpslot { min-width: 2em; text-align: center; border-bottom: 2px solid var(--accent); }
.cmpbtns { display: inline-flex; gap: 6px; margin-left: 8px; }
.opt.sign { min-width: 46px; justify-content: center; }
.opt.chip { min-width: 60px; justify-content: center; }
.opt.chip.used { opacity: .35; }
.ordline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.ordslot { min-width: 56px; min-height: 40px; padding: 4px 8px; border: 1.5px solid var(--accent); border-radius: 8px; display: inline-grid; place-items: center; background: #fff; }
.ordslot.empty { border-style: dashed; color: var(--muted); }
.mini { font: inherit; font-size: .82rem; background: none; border: none; color: var(--accent); cursor: pointer; text-decoration: underline; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn {
  font: inherit; font-size: .93rem; cursor: pointer; border-radius: 9px; padding: 7px 14px;
  border: 1.5px solid var(--accent); background: #fff; color: var(--accent); font-weight: 600;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #0b5f76; }
.btn.ghost { border-color: #b9c6ce; color: var(--muted); font-weight: 500; }
.btn.good { border-color: var(--good); color: var(--good); }
.btn.bad { border-color: var(--bad); color: var(--bad); }
.btn.dl { background: var(--fuchsia); border-color: var(--fuchsia); color: #fff; }
.btn.dl:hover { background: #951f64; }
.btn[hidden] { display: none; }

.foot-nav { max-width: 980px; margin: 0 auto; padding: 0 16px 40px; display: flex; justify-content: space-between; gap: 10px; }
.foot-nav a { text-decoration: none; font-weight: 600; }
.foot-nav a[hidden] { visibility: hidden; display: inline; }
.err { color: var(--bad); }

/* ---------------------------------------------------------------- accueil */
.hero { text-align: center; padding: 42px 16px 36px; position: relative; overflow: hidden; }
.hero h1 { margin: 6px 0; font-size: clamp(1.8rem, 5vw, 2.8rem); }
.hero h1 em { font-style: normal; color: #ffc9e6; }
.hero p { margin: 6px auto 0; max-width: 640px; opacity: .88; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.card {
  display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(16,36,63,.1); border-color: var(--accent); }
.card .fnum { width: 52px; height: 52px; font-size: 1.1rem; }
.card h3 { margin: 0 0 2px; font-size: 1.05rem; }
.card .meta { font-size: .82rem; color: var(--muted); }
.howto { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 6px 18px; margin: 22px 0; }
.howto h2 { font-size: 1.05rem; color: var(--accent); }
.howto li { margin: 3px 0; }

@media print {
  .bar, .crumbs, .actions, .foot-nav { display: none; }
  .q { break-inside: avoid; }
}
