:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e3e6ef;
  --text: #1c2033;
  --muted: #646a82;
  --primary: #4f46e5;
  --primary-ink: #ffffff;
  --primary-soft: #eef0ff;
  --ok: #059669;
  --ok-soft: #e7f7f0;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fff6e5;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 4px 16px rgba(20, 24, 50, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1220;
    --surface: #171b2e;
    --surface-2: #1e2339;
    --border: #2a3050;
    --text: #e7e9f3;
    --muted: #9aa0ba;
    --primary: #818cf8;
    --primary-ink: #0f1220;
    --primary-soft: #232849;
    --ok: #34d399;
    --ok-soft: #12302a;
    --bad: #f87171;
    --bad-soft: #3a1c22;
    --warn: #fbbf24;
    --warn-soft: #362b12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 6px; }
pre { background: var(--surface-2); padding: 12px 14px; border-radius: 10px; overflow-x: auto; white-space: pre; }
pre code { background: none; padding: 0; }
img { max-width: 100%; }

/* ---------- mise en page */
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 16px; padding: 10px 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand img { width: 30px; height: 30px; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { padding: 7px 12px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.user-chip { color: var(--muted); font-size: .9rem; white-space: nowrap; }
main.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .user-chip { margin-left: auto; }
  main.container { padding-top: 16px; }
}

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid.subjects { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.row.gap { gap: 10px; }
.row.between { justify-content: space-between; gap: 10px; }
.stack > * + * { margin-top: 12px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.section { margin-top: 28px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 2.4rem; margin-bottom: 6px; }

/* ---------- formulaires */
label { display: block; font-weight: 500; font-size: .92rem; }
label > input, label > textarea, label > select { margin-top: 5px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
}
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
textarea { resize: vertical; min-height: 80px; }
input[type="radio"], input[type="checkbox"] { width: auto; accent-color: var(--primary); }
input[type="color"] { padding: 2px; height: 40px; width: 64px; }
.hint { font-size: .82rem; color: var(--muted); font-weight: 400; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .94rem; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 5px 10px; font-size: .85rem; border-radius: 8px; }
.btn.big { padding: 13px 22px; font-size: 1.05rem; }
.icon-btn { padding: 6px 9px; }

.alert { padding: 10px 14px; border-radius: 10px; background: var(--primary-soft); }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- authentification */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 420px; margin: 40px auto; }
.brand-lg { display: flex; align-items: center; gap: 12px; font-size: 1.4rem; font-weight: 700; margin-bottom: 18px; }

/* ---------- tableau de bord */
.tile { padding: 16px 18px; }
.tile .value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.tile .label { color: var(--muted); font-size: .88rem; margin-top: 4px; }
.hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 60%, #06b6d4)); color: #fff; border: 0; }
.hero h2 { margin: 0 0 4px; }
.hero p { margin: 0; opacity: .92; }
.hero .btn { background: #fff; color: #312e81; border-color: #fff; }
.subject-card { cursor: pointer; position: relative; overflow: hidden; padding-top: 22px; transition: transform .1s, box-shadow .15s; }
.subject-card:hover { transform: translateY(-2px); }
.subject-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; background: var(--c, var(--primary)); }
.subject-card h3 { margin-bottom: 4px; }
.subject-card .desc { color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.7em; }
.meter { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; display: flex; }
.meter > span { display: block; height: 100%; }
.counts { display: flex; gap: 12px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-top: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--c, var(--primary)); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .82rem; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 90px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.bars .bar span { display: block; border-radius: 4px 4px 0 0; min-height: 2px; }
.bars-labels { display: flex; gap: 6px; font-size: .7rem; color: var(--muted); margin-top: 4px; }
.bars-labels span { flex: 1; text-align: center; }

/* ---------- questions */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.new { background: var(--primary-soft); color: var(--primary); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.q-item { display: grid; grid-template-columns: 1fr auto; gap: 12px; }
.q-item + .q-item { margin-top: 12px; }
.q-item .q-text { font-weight: 600; margin-bottom: 8px; white-space: pre-wrap; }
.q-item .thumb { width: 96px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.choices-mini { list-style: none; padding: 0; margin: 0 0 6px; font-size: .9rem; }
.choices-mini li { padding: 2px 0 2px 24px; position: relative; color: var(--muted); }
.choices-mini li::before { content: "○"; position: absolute; left: 4px; }
.choices-mini li.correct { color: var(--ok); font-weight: 600; }
.choices-mini li.correct::before { content: "✔"; }
.q-actions { display: flex; gap: 4px; align-items: flex-start; }
.explain { font-size: .88rem; color: var(--muted); white-space: pre-wrap; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type="search"] { flex: 1; min-width: 200px; }

.choice-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.choice-row + .choice-row { margin-top: 8px; }
.choice-row input[type="radio"] { width: 20px; height: 20px; }
.img-preview { max-height: 180px; border-radius: 10px; border: 1px solid var(--border); display: block; }

/* ---------- quiz */
.quiz { max-width: 720px; margin: 0 auto; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0 20px; }
.progress > span { display: block; height: 100%; background: var(--primary); transition: width .3s; }
.quiz-card { padding: 24px; }
.quiz-card .subject-tag { font-size: .82rem; font-weight: 600; color: var(--c, var(--primary)); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.quiz-card .prompt { font-size: 1.25rem; font-weight: 650; margin-bottom: 16px; white-space: pre-wrap; }
.quiz-card .illustration { max-height: 320px; border-radius: 12px; margin: 0 auto 18px; display: block; border: 1px solid var(--border); }
.answers { display: grid; gap: 10px; }
.answer {
  text-align: left; font: inherit; font-size: 1rem; padding: 14px 16px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--border); background: var(--surface); color: var(--text); display: flex; gap: 12px; align-items: flex-start;
  transition: border-color .15s, background .15s;
}
.answer:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.answer .letter { font-weight: 700; color: var(--muted); min-width: 1.4em; }
.answer:disabled { cursor: default; }
.answer.correct { border-color: var(--ok); background: var(--ok-soft); }
.answer.correct .letter { color: var(--ok); }
.answer.wrong { border-color: var(--bad); background: var(--bad-soft); }
.answer.wrong .letter { color: var(--bad); }
.answer.dim { opacity: .6; }
.feedback { margin-top: 18px; padding: 14px 16px; border-radius: 12px; }
.feedback.ok { background: var(--ok-soft); }
.feedback.bad { background: var(--bad-soft); }
.feedback strong { display: block; margin-bottom: 4px; }
.feedback.ok strong { color: var(--ok); }
.feedback.bad strong { color: var(--bad); }
.score-big { font-size: 3rem; font-weight: 800; color: var(--primary); line-height: 1; }
.result-list { list-style: none; padding: 0; margin: 16px 0 0; text-align: left; }
.result-list li { padding: 8px 0; border-top: 1px solid var(--border); display: flex; gap: 10px; }

/* ---------- tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }

/* ---------- fenêtres modales, notifications */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 25, .5); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 50; overflow-y: auto; }
.modal { width: 100%; max-width: 640px; background: var(--surface); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3); padding: 22px; }
.modal h2 { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 20px; }
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); animation: pop .2s ease-out; }
.toast.error { background: var(--bad); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.copy-field { display: flex; gap: 8px; }
.copy-field input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88rem; }
.doc h2 { margin-top: 28px; }
.doc h3 { margin-top: 20px; }
.doc .endpoint { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88rem; }
.method { display: inline-block; min-width: 58px; font-weight: 700; font-size: .78rem; }
.method.get { color: var(--ok); } .method.post { color: var(--primary); } .method.patch, .method.put { color: var(--warn); } .method.delete { color: var(--bad); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > .card { margin-top: 6px; }
details.menu .btn { justify-content: flex-start; width: 100%; }
.grid > .card + .card { margin-top: 0; }
@media (max-width: 720px) {
  .nav { flex-wrap: wrap; overflow: visible; }
  .nav a { padding: 6px 9px; font-size: .92rem; }
}
