:root {
  --ink: #1d2433; --muted: #6b7385; --line: #e3e7ee; --bg: #f5f7fa; --card: #fff;
  --accent: #1f5fbf; --accent-soft: #e8f0fc;
  --good: #2e9d5b; --mid: #e0a526; --low: #e07a26; --bad: #d64545; --na: #c9ced8;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 1.2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .8rem; }
.wrap { max-width: 920px; margin: 0 auto; padding: 0 20px 60px; }
.wrap.wide { max-width: 1400px; }
.wrap.narrow { max-width: 560px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 20px 22px; margin: 0 0 18px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.err { color: var(--bad); font-weight: 600; }
.r { text-align: right; }

/* formulaires */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 10px; }
input[type=text], input[type=password], input:not([type]) {
  display: block; width: 100%; margin-top: 4px; padding: 9px 11px; font: inherit; border: 1px solid #cfd5df; border-radius: 7px; background: #fff;
}
input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 14px; padding: 10px 14px 4px; }
legend { font-weight: 700; padding: 0 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn { font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 7px; border: 1px solid #cfd5df; background: #fff; color: var(--ink); cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); border-color: #efc4c4; }
form.inline { display: inline; }

/* tableaux */
.tbl { width: 100%; border-collapse: collapse; background: #fff; font-size: .93rem; }
.tbl th, .tbl td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { background: #f0f3f8; font-weight: 600; font-size: .85rem; }
.tbl.compact td { padding: 4px 8px; }
.tbl tr.ok td { background: #f1faf4; }
.tbl tr.mid td { background: #fdf8ea; }
.tbl tr.ko td { background: #fdf1f1; }

/* ---------- élève ---------- */
body.eleve #exo, body.eleve .enonce, body.eleve .q, body.eleve .scenario { -webkit-user-select: none; user-select: none; }
body.eleve input { -webkit-user-select: text; user-select: text; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; gap: 18px; align-items: center; justify-content: space-between; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.save { font-size: .82rem; padding: 3px 10px; border-radius: 20px; background: #eef1f5; color: var(--muted); }
.save.ok { background: #e7f6ec; color: var(--good); }
.save.pending { background: #fdf5e2; color: #9a6b00; }
.save.err { background: #fde9e9; color: var(--bad); }
.hint { background: var(--accent-soft); color: #234; border-radius: 8px; padding: 10px 14px; margin-bottom: 18px; font-size: .9rem; }
.enonce p { margin: .5rem 0; }
.enonce .tbl { margin-top: 12px; }
.scenario { border-left: 4px solid var(--accent); background: #fff; padding: 12px 16px; margin: 26px 0 14px; border-radius: 0 8px 8px 0; }
.q { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin: 0 0 12px; }
.qh { display: flex; gap: 10px; margin-bottom: 10px; }
.qn { flex: none; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 0 8px; height: 1.6em; line-height: 1.6em; font-size: .85rem; }
.ans { display: flex; align-items: center; gap: 8px; max-width: 280px; }
.ans input { margin: 0; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.unit { color: var(--muted); font-weight: 600; white-space: nowrap; }
.opts { display: grid; gap: 6px; }
.opt { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.opt:hover { border-color: var(--accent); }
.opt input { margin-top: 4px; }
.opt:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.letter { font-weight: 700; color: var(--accent); min-width: 1em; }
.submit { text-align: center; margin-top: 28px; }
.submit .btn { font-size: 1.05rem; padding: 11px 26px; }
.score { font-size: 1.1rem; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .25s; background: #222a38; color: #fff; padding: 10px 18px; border-radius: 8px; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- formateur ---------- */
.topbar.prof nav { display: flex; gap: 6px; flex-wrap: wrap; }
.topbar.prof nav a { padding: 5px 10px; border-radius: 6px; }
.topbar.prof nav a.on { background: var(--accent-soft); font-weight: 600; }
.urlbox { margin: 18px 0; font-size: 1.05rem; background: #fff; border: 1px dashed var(--accent); border-radius: 8px; padding: 10px 16px; }
.urlbox strong { font-size: 1.25rem; color: var(--accent); user-select: all; }
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; color: var(--muted); font-size: .85rem; }
.kpi span { display: block; font-size: 1.9rem; font-weight: 700; color: var(--ink); line-height: 1.2; }
.controls { display: flex; flex-wrap: wrap; gap: 14px 28px; align-items: center; }
.controls .right { margin-left: auto; display: flex; gap: 14px; align-items: center; }
.chk { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; margin: 0; }
.tag { display: inline-block; font-size: .78rem; font-weight: 600; padding: 1px 8px; border-radius: 20px; background: #eef1f5; color: var(--muted); }
.tag.good { background: #e7f6ec; color: var(--good); }
.tag.bad { background: #fde9e9; color: var(--bad); }
.sechead { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 10px; }
.filters a { font-size: .85rem; padding: 3px 8px; border-radius: 6px; color: var(--muted); }
.filters a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.filters .sep { color: var(--line); }
.bar { position: relative; height: 22px; background: #eef1f5; border-radius: 5px; overflow: hidden; }
.bar span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; }
.bar em { position: absolute; left: 8px; top: 0; line-height: 22px; font-style: normal; font-weight: 700; font-size: .85rem; color: #1d2433; }
.good { background: var(--good); } .mid { background: var(--mid); } .low { background: var(--low); } .bad { background: var(--bad); } .na { background: var(--na); }
.good-t { color: var(--good) !important; } .mid-t { color: #b58100 !important; } .low-t { color: var(--low) !important; } .bad-t { color: var(--bad) !important; } .na-t { color: var(--muted) !important; }
.tbl.diff td { vertical-align: middle; }
.scroll { overflow-x: auto; }
.tbl.heat th, .tbl.heat td { padding: 5px 6px; font-size: .82rem; white-space: nowrap; }
.tbl.heat th a { color: var(--ink); }
.tbl.heat td.nm { min-width: 220px; white-space: normal; }
.cell { width: 26px; min-width: 26px; }
td.cell { border: 2px solid #fff !important; border-radius: 4px; }
.cell.g { background: var(--good); } .cell.m { background: var(--mid); } .cell.b { background: var(--bad); } .cell.e { background: #e4e7ec; }
.legend { font-size: .82rem; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.legend .cell { display: inline-block; height: 14px; width: 14px; min-width: 14px; border-radius: 3px; }
td.warn { color: var(--bad); font-weight: 700; }
.dist { display: grid; gap: 8px; margin-bottom: 20px; }
.drow { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(120px, 1fr) 90px; gap: 14px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.dval { text-align: right; font-weight: 600; }
.corrige .tbl { font-size: .88rem; }
td.qn { font-weight: 700; color: var(--accent); width: 50px; }

@media (max-width: 760px) { .kpis { grid-template-columns: repeat(2, 1fr); } .row2 { grid-template-columns: 1fr; } .drow { grid-template-columns: 1fr; } }
@media print {
  .topbar, .urlbox, .controls { display: none; }
  body { background: #fff; }
  .card { break-inside: avoid; border: none; padding: 0; }
  .corrige { break-inside: avoid; page-break-inside: avoid; margin-bottom: 20px; }
}

/* ---------- mode guidé ---------- */
.q { scroll-margin-top: 70px; }
.rules { background: var(--accent-soft); border-radius: 8px; padding: 12px 16px; margin: 0 0 16px; font-size: .92rem; }
.rules ul { margin: 6px 0 0; padding-left: 20px; }
.progress { display: flex; align-items: center; gap: 12px; font-size: .88rem; color: var(--muted); }
.pbar { width: 140px; height: 8px; background: #e4e7ec; border-radius: 6px; overflow: hidden; display: inline-block; }
.pbar i { display: block; height: 100%; background: var(--accent); }
.q.active { border: 2px solid var(--accent); box-shadow: 0 4px 18px rgba(31, 95, 191, .10); }
.q.done { padding: 12px 18px; }
.q.done .qh { margin-bottom: 6px; align-items: flex-start; }
.q.done .qt { flex: 1; }
.q.done.st-ok { border-left: 5px solid var(--good); }
.q.done.st-mid { border-left: 5px solid var(--mid); }
.q.done.st-ko { border-left: 5px solid var(--bad); }
.badge { flex: none; font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 20px; white-space: nowrap; }
.q.done.st-ok .badge { background: #e7f6ec; color: var(--good); }
.q.done.st-mid .badge { background: #fdf5e2; color: #9a6b00; }
.q.done.st-ko .badge { background: #fde9e9; color: var(--bad); }
.given { font-size: .9rem; color: var(--muted); margin-left: 44px; }
.solution { margin: 8px 0 0 44px; font-size: .92rem; background: #f6f8fb; border-radius: 6px; padding: 8px 12px; }
.solution span, .hintbox span { display: block; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 2px; }
.wrong { color: var(--bad); font-weight: 600; margin: 0 0 10px; }
.hintbox { background: #fff8e6; border: 1px solid #f3dfa6; border-radius: 8px; padding: 9px 13px; margin: 0 0 10px; font-size: .93rem; }
.hintbox span { color: #9a6b00; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.cell.h1 { background: #8fcf9f; } .cell.h2 { background: var(--mid); }
.tag.mode { background: var(--accent-soft); color: var(--accent); }
.tbl.diff td:last-child a { white-space: nowrap; }
.prevlabel { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 6px; }
details.panel { background: #fff; border: 1px solid var(--line); border-radius: 10px; margin: 0 0 14px; }
details.panel > summary { cursor: pointer; padding: 11px 18px; font-weight: 600; color: var(--accent); list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before { content: '▸'; display: inline-block; width: 1.1em; transition: transform .15s; }
details.panel[open] > summary::before { transform: rotate(90deg); }
details.panel[open] > summary { border-bottom: 1px solid var(--line); }
details.panel > .card, details.panel > .scenario, details.panel > .q { margin: 12px 14px; }
details.panel > .card { border: none; padding: 6px 4px; }
.q.active { margin-top: 14px; }
.recap { margin-top: 14px; padding: 16px 18px; }
.recap h2 { font-size: 1rem; margin-bottom: 8px; }
.recap .tbl td { font-size: .9rem; vertical-align: middle; }
.recap tr.grp th { background: #f0f3f8; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.recap td.val { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dot { font-size: .75rem; font-weight: 700; padding: 1px 7px; border-radius: 20px; white-space: nowrap; }
.dot.ok { color: var(--good); background: #e7f6ec; }
.dot.ko { color: var(--bad); background: #fde9e9; }
/* mode guidé : tableau des mots clés limité à 4 lignes visibles (défilement interne) */
body.eleve .kwscroll { max-height: 190px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 12px; }
body.eleve .kwscroll .tbl { margin: 0; }
body.eleve .kwscroll thead th { position: sticky; top: 0; z-index: 1; }
body.eleve #exo:not(.guided) .kwscroll { max-height: none; }
details.panel.data .enonce p { margin: .35rem 0; font-size: .93rem; }
details.panel.prevq .q.done { margin: 10px 14px; }
