:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1f2a44;
  --muted: #667085;
  --line: #e3e1db;
  --accent: #6b3fa0;
  --accent-soft: #efe8f7;
  --ok: #1d7a4a;
  --ok-soft: #e4f3ea;
  --bad: #b42318;
  --bad-soft: #fbe9e7;
  --warn: #9a6200;
  --warn-soft: #fdf1dc;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c;
    --surface: #1d2029;
    --text: #e8e9ee;
    --muted: #9aa0ad;
    --line: #2d313d;
    --accent: #b392e0;
    --accent-soft: #2b2340;
    --ok: #5fcf91;
    --ok-soft: #173326;
    --bad: #f08f84;
    --bad-soft: #3a1f1c;
    --warn: #f0c060;
    --warn-soft: #3a2f17;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
main { max-width: 720px; margin: 0 auto; padding: 24px 16px 96px; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }

.brand { color: var(--accent); font-weight: 700; letter-spacing: .08em; font-size: .8rem; text-transform: uppercase; margin-bottom: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

label { display: block; font-weight: 600; margin: 14px 0 6px; }
input[type="text"], input[type="password"], input[type="number"], textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
textarea { min-height: 140px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .btn {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.secondary, .btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.ghost { background: transparent; color: var(--muted); padding: 8px 10px; }
button:disabled { opacity: .5; cursor: default; }
.full { width: 100%; margin-top: 18px; }

.error { color: var(--bad); background: var(--bad-soft); border-radius: 10px; padding: 10px 12px; margin-top: 14px; }
.notice { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; margin: 12px 0; }

/* Barre d'épreuve */
.examBar {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.examBar .inner { max-width: 720px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.15rem; }
.timer.low { color: var(--bad); }
.progress { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.saveState { font-size: .8rem; color: var(--muted); min-width: 80px; text-align: right; }

.q { scroll-margin-top: 70px; }
.q .num { color: var(--accent); font-weight: 700; margin-right: 6px; }
.q .qtext { font-weight: 600; margin-bottom: 12px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin: 8px 0; cursor: pointer; font-weight: 400;
}
.opt input { margin-top: 4px; accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.opt .letter { font-weight: 700; color: var(--muted); }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* Résultats */
.score { font-size: 3rem; font-weight: 800; line-height: 1; }
.score small { font-size: 1.2rem; color: var(--muted); font-weight: 600; }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.tag { display: inline-block; font-size: .78rem; font-weight: 700; border-radius: 999px; padding: 2px 10px; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.neutral { background: var(--accent-soft); color: var(--accent); }
.given { white-space: pre-wrap; background: var(--bg); border-radius: 10px; padding: 12px; border: 1px solid var(--line); }
.expected { font-size: .9rem; color: var(--muted); margin-top: 10px; }

/* Admin */
.wide { max-width: 1100px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row > * { flex: none; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 1.6rem; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; margin: 0; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tableWrap { overflow-x: auto; }
.grade { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.grade button { background: transparent; color: var(--text); border-radius: 0; padding: 6px 12px; font-weight: 600; }
.grade button.on { background: var(--accent); color: #fff; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.openBlock { margin: 12px 0; padding-top: 12px; border-top: 1px dashed var(--line); }

/* Alertes de sortie */
.feed { list-style: none; margin: 12px 0 0; padding: 0; max-height: 260px; overflow-y: auto; }
.feed li { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }
.feed time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; flex: none; }
.feed .left b { color: var(--bad); }
.toasts { position: fixed; right: 16px; bottom: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 20; pointer-events: none; }
.toast { background: var(--bad); color: #fff; font-weight: 600; padding: 12px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 420px; }
