/* ==========================================================================
   Algèbre² — Feuille de style
   Palette sobre (13-14 ans : moderne, pas enfantine), fond « papier quadrillé ».
   ========================================================================== */
:root {
  --bg: #f4f5fb;
  --grid: rgba(67, 56, 202, .055);
  --surface: #ffffff;
  --surface-2: #f8f9fe;
  --ink: #1b1d3a;
  --ink-2: #4b4f72;
  --muted: #7b7f9e;
  --line: #e3e5f2;
  --primary: #4338ca;
  --primary-2: #6366f1;
  --primary-soft: #eef0ff;
  --accent: #f97316;
  --ok: #059669; --ok-soft: #e7f8f1;
  --mid: #d97706; --mid-soft: #fff6e6;
  --ko: #dc2626; --ko-soft: #fdeeee;
  --m1: #2563eb; --m2: #7c3aed; --m3: #0891b2; --m4: #db2777; --m5: #ea580c;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(27, 29, 58, .06), 0 6px 24px rgba(27, 29, 58, .06);
  --shadow-lg: 0 10px 40px rgba(67, 56, 202, .16);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --fig-stroke: #312e81; --fig-fill: #eef0ff;
  --taille: 16px; --espacement: normal;
  --white: #ffffff;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0e0f1d; --grid: rgba(128, 128, 255, .06);
  --surface: #171930; --surface-2: #21243f; --white: #1d2040;
  --ink: #eceefe; --ink-2: #c3c7e8; --muted: #a3a8cc; --line: #2c3054;
  --primary: #8080ff; --primary-2: #a5a5ff; --primary-soft: #272a5c;
  --ok: #3dd68c; --ok-soft: #133a29; --mid: #fbbf24; --mid-soft: #3a2f12; --ko: #ff6b70; --ko-soft: #46202a;
  --m1: #60a5fa; --m2: #a78bfa; --m3: #22d3ee; --m4: #f472b6; --m5: #fb923c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  --fig-stroke: #a5b4fc; --fig-fill: #23265a;
  color-scheme: dark;
}
[data-lecture="on"] { --taille: 19px; --espacement: .04em; }
[data-lecture="on"] body { line-height: 1.75; word-spacing: .12em; }
html { font-size: var(--taille); }
body { letter-spacing: var(--espacement); }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px; min-height: 100vh; display: flex; flex-direction: column; line-height: 1.5;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: clamp(1.5rem, 2.6vw, 2.1rem); }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: .4rem 0; }
code { background: var(--primary-soft); padding: .05rem .35rem; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 700; color: var(--mc, var(--primary)); margin: 0 0 .25rem; }
button { font: inherit; }

/* ---------- En-tête ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem clamp(1rem, 3vw, 2rem); background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .7rem; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
  display: flex; align-items: center; justify-content: center; font-family: Georgia, "Times New Roman", serif; font-size: 1.35rem; box-shadow: var(--shadow-lg);
}
.logo sup { font-size: .7rem; margin-left: 1px; font-style: normal; align-self: flex-start; margin-top: 7px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-size: 1.05rem; }
.brand-text small { color: var(--muted); font-size: .78rem; }
.top-right { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; justify-content: flex-end; }
.badge { display: inline-flex; align-items: center; gap: .45rem; background: var(--primary-soft); color: var(--primary); font-weight: 600; padding: .3rem .75rem; border-radius: 999px; font-size: .88rem; }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.topnav { display: flex; gap: .25rem; }

main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); outline: none; }
.footer { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: center; padding: 1rem; font-size: .8rem; color: var(--muted); }
.teacher-link { color: var(--muted); margin-left: 1rem; text-decoration: none; border-bottom: 1px dotted var(--muted); }
.teacher-link:hover { color: var(--primary); }
.sync { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.btn-icone { display: inline-grid; place-items: center; min-width: 38px; height: 38px; padding: 0 .5rem; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; color: var(--ink); }
.btn-icone:hover { background: var(--surface-2); }
.btn-icone[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }
.saut { position: absolute; left: -999px; top: 0; background: var(--primary); color: #fff; padding: .5em 1em; z-index: 99; }
.saut:focus { left: 1rem; }
.aide { font-size: .85rem; color: var(--muted); margin: -.2rem 0 .9rem; }
.aide b { color: var(--primary); font-family: ui-monospace, Menlo, Consolas, monospace; }
.nip-titre { background: var(--primary-soft); border-radius: 12px; padding: .7rem .9rem; }
.nip-input { letter-spacing: .5em; font-size: 1.4rem !important; text-align: center; }
.actions.spread { justify-content: space-between; }
.anciens-codes { margin-top: 1rem; border-top: 1px dashed var(--line); padding-top: .8rem; }
.puce-code { display: inline-flex; margin: .2rem .3rem .2rem 0; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.puce-code button { border: 0; background: none; padding: .35rem .7rem; cursor: pointer; font-weight: 600; color: var(--ink); }
.puce-code .retirer { color: var(--muted); padding: .35rem .55rem; border-left: 1px solid var(--line); }
.badge { font-family: ui-monospace, Menlo, Consolas, monospace; }

/* ---------- Composants ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: clamp(1rem, 2.5vw, 1.6rem); margin-bottom: 1.2rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid transparent; border-radius: 12px;
  padding: .65rem 1.15rem; font-weight: 650; cursor: pointer; transition: transform .08s, background .15s, box-shadow .15s; color: var(--ink); background: var(--surface);
  min-height: 44px; /* cible tactile confortable (iPad) */
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .choice:focus-visible, .k:focus-visible, .module-card:focus-visible, .chip input:focus-visible + span { outline: 3px solid var(--primary-2); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(67, 56, 202, .3); }
.btn-primary:hover { background: #3730a3; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: var(--surface); border-color: #cfd2e6; }
.btn-lg { padding: .85rem 1.4rem; font-size: 1.05rem; width: 100%; }
.btn-sm { padding: .3rem .7rem; min-height: 34px; font-size: .85rem; border-radius: 9px; }
.btn[disabled] { opacity: .6; cursor: wait; }
.danger { color: var(--ko); }
.link { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0 .2rem; text-decoration: underline; font-size: .85rem; }
.back { margin-bottom: 1rem; }
.pill { display: inline-block; background: var(--mc, var(--primary)); color: #fff; font-size: .75rem; font-weight: 700; padding: .12rem .55rem; border-radius: 999px; }
.tag { display: inline-block; padding: .3rem .7rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: .88rem; font-weight: 600; }
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.mid { background: var(--mid-soft); color: var(--mid); border-color: transparent; }
.tag.ko { background: var(--ko-soft); color: var(--ko); border-color: transparent; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; font-weight: 600; font-size: .92rem; flex: 1; }
.field em { font-weight: 400; color: var(--muted); }
.field small { font-weight: 400; color: var(--muted); font-size: .8rem; line-height: 1.35; }
.field-row { display: flex; gap: .8rem; flex-wrap: wrap; }
input, select { font: inherit; color: var(--ink); }
.field input, .field select, .filters input, .filters select, .form-inline input, .form-inline select {
  border: 1.5px solid var(--line); border-radius: 11px; padding: .65rem .8rem; font-size: 1rem; background: var(--surface-2); min-height: 44px;
}
.field input:focus, .field select:focus, .filters select:focus, .form-inline input:focus { border-color: var(--primary-2); outline: none; background: var(--surface); box-shadow: 0 0 0 4px var(--primary-soft); }
.form-error { color: var(--ko); font-weight: 600; min-height: 1.2em; font-size: .9rem; }
.privacy { font-size: .82rem; color: var(--muted); text-align: center; margin-top: .9rem; }
.mode-local { font-size: .82rem; background: var(--mid-soft); color: var(--mid); padding: .5rem .7rem; border-radius: 10px; }

/* ---------- Connexion ---------- */
.login-wrap { display: grid; grid-template-columns: 1.1fr 1fr; gap: clamp(1rem, 4vw, 3rem); align-items: center; min-height: 70vh; }
.login-hero h1 { font-size: clamp(1.9rem, 4.2vw, 3rem); background: linear-gradient(120deg, var(--primary), var(--m4)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-hero p { font-size: 1.1rem; color: var(--ink-2); max-width: 32ch; }
.hero-list { list-style: none; padding: 0; margin: 1.4rem 0 0; display: grid; gap: .6rem; }
.hero-list li { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .65rem .9rem; box-shadow: var(--shadow); }
.hero-list b { color: var(--primary); }
.login-card { max-width: 460px; width: 100%; justify-self: end; }
.login-card.narrow { margin: 2rem auto; justify-self: center; max-width: 380px; }

/* ---------- Accueil ---------- */
.home-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.home-kpis, .kpis { display: flex; gap: .6rem; flex-wrap: wrap; }
.kpis { margin-bottom: 1.2rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: .55rem .9rem; display: flex; flex-direction: column; min-width: 96px; box-shadow: var(--shadow); }
.kpi b { font-size: 1.25rem; }
.kpi span { font-size: .78rem; color: var(--muted); }
.kpi.big { flex: 1; min-width: 140px; padding: .9rem 1rem; }
.kpi.big b { font-size: 1.6rem; color: var(--primary); }
.modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.module-card {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1rem; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s, border-color .15s; position: relative; overflow: hidden; color: var(--ink);
}
.module-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--mc); }
.module-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--mc); }
.module-num { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; font-weight: 800; font-size: 1.25rem; color: #fff; background: var(--mc, var(--primary)); }
.module-num.sm { width: 28px; height: 28px; font-size: .9rem; border-radius: 8px; display: inline-grid; margin-right: .5rem; vertical-align: middle; }
.module-body { display: flex; flex-direction: column; }
.module-body small { color: var(--muted); }
.module-stat { font-weight: 700; font-size: .9rem; color: var(--ink-2); display: flex; align-items: center; gap: .4rem; }
.module-stat em { font-style: normal; font-size: .75rem; background: var(--primary-soft); color: var(--primary); padding: .15rem .5rem; border-radius: 999px; }
.mini-bar { display: inline-block; width: 52px; height: 7px; border-radius: 9px; background: var(--line); overflow: hidden; }
.mini-bar span { display: block; height: 100%; background: var(--mc, var(--primary)); border-radius: 9px; }
.module-card.mixte { --mc: var(--accent); background: linear-gradient(120deg, var(--surface), color-mix(in srgb, var(--accent) 10%, var(--surface))); }
.module-card.mixte .module-num { background: linear-gradient(135deg, var(--accent), var(--m4)); }

/* ---------- Configuration ---------- */
.setup-card { max-width: 760px; margin: 0 auto; border-top: 5px solid var(--mc); }
.chips { border: 0; padding: 0; margin: 1.1rem 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.chips legend { font-weight: 700; margin-bottom: .5rem; padding: 0; width: 100%; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-flex; align-items: center; gap: .4rem; padding: .55rem .95rem; border: 1.5px solid var(--line); border-radius: 999px; background: var(--surface-2); font-weight: 600; font-size: .92rem; transition: all .12s; min-height: 42px; }
.chip input:checked + span { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.chip em { font-style: normal; font-size: .72rem; padding: .05rem .4rem; border-radius: 999px; background: var(--line); color: var(--ink-2); }
.chip em.good { background: var(--ok-soft); color: var(--ok); }
.chip em.weak { background: var(--ko-soft); color: var(--ko); }

/* ---------- Série ---------- */
.drill { max-width: 820px; margin: 0 auto; }
.drill-top { display: flex; align-items: center; gap: .8rem; margin-bottom: .6rem; flex-wrap: wrap; }
.drill-title { flex: 1; font-weight: 650; color: var(--ink-2); font-size: .95rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.diff { color: var(--mc); letter-spacing: 1px; font-size: .75rem; }
.drill-count { font-size: .95rem; color: var(--muted); }
.drill-count b { color: var(--ink); font-size: 1.15rem; }
.streak { font-weight: 800; padding: .3rem .7rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); transition: all .2s; }
.streak.hot { background: color-mix(in srgb, var(--accent) 15%, var(--surface)); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); transform: scale(1.05); }
.progress { height: 8px; border-radius: 9px; background: var(--line); overflow: hidden; margin-bottom: 1.1rem; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--mc), var(--primary-2)); border-radius: 9px; transition: width .4s ease; }
.qcard { border-top: 5px solid var(--mc); animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.qprompt { font-size: 1.12rem; font-weight: 600; margin-bottom: .6rem; }
.qprompt .enonce { display: block; margin-top: .4rem; font-weight: 500; font-size: 1.15rem; color: var(--primary); background: var(--primary-soft); padding: .6rem .9rem; border-radius: 12px; }
.qtex { font-size: 1.45rem; text-align: center; padding: .9rem .5rem 1rem; overflow-x: auto; overflow-y: hidden; }
.qtex .katex-display { margin: 0; }
.qfig { display: flex; justify-content: center; margin: .3rem 0 1rem; }
.figure { width: 100%; max-width: 420px; height: auto; }
.fig-shape { fill: var(--fig-fill); stroke: var(--fig-stroke); stroke-width: 2.5; stroke-linejoin: round; }
.fig-label { font-size: 15px; font-weight: 700; fill: var(--ink); font-family: var(--font); }
.fig-caption { font-size: 13px; fill: var(--ink-2); font-family: var(--font); font-weight: 600; }
.fig-strong { font-size: 15px; fill: var(--primary); font-weight: 800; }
.fig-dash { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 5; }
.fig-thin { fill: none; stroke: var(--fig-stroke); stroke-width: 1.5; }
.fig-tick { stroke: var(--fig-stroke); stroke-width: 2; }

.input-row { display: flex; gap: .6rem; align-items: stretch; }
.input-prefix { display: grid; place-items: center; font-size: 1.25rem; padding: 0 .3rem; }
.answer-input {
  flex: 1; min-width: 0; font-size: 1.35rem; padding: .7rem .9rem; border: 2px solid var(--line); border-radius: 13px; background: var(--surface-2);
  font-family: "Cambria Math", Cambria, Georgia, serif; letter-spacing: .02em;
}
.answer-input:focus { outline: none; border-color: var(--primary-2); background: var(--white); box-shadow: 0 0 0 4px var(--primary-soft); }
.answer-input.ok { border-color: var(--ok); background: var(--ok-soft); }
.answer-input.ko { border-color: var(--ko); background: var(--ko-soft); }
.preview { min-height: 2rem; padding: .35rem .2rem; font-size: 1.1rem; }
.preview .muted { font-size: .85rem; margin-right: .3rem; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.mathkb { display: flex; flex-direction: column; gap: .4rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: .5rem; margin-top: .3rem; transition: opacity .2s; }
.mathkb.dim { opacity: .35; pointer-events: none; }
.krow { display: flex; flex-wrap: wrap; gap: .35rem; }
.krow .k { flex: 1 0 40px; }
.kgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .35rem; }
.mathkb-number .kgrid, .mathkb-int .kgrid { grid-template-columns: repeat(4, 1fr); max-width: 420px; }
.kgrid .k { min-height: 46px; }
.k-vide { visibility: hidden; pointer-events: none; }
.k { min-height: 44px; border: 1px solid var(--line); background: var(--white); border-radius: 10px; font-size: 1.1rem; font-weight: 600; cursor: pointer; color: var(--ink); touch-action: manipulation; }
.k:hover { border-color: var(--primary-2); }
.k:active { background: var(--primary-soft); }
.k-var { font-family: Georgia, serif; font-style: italic; font-size: 1.25rem; color: var(--primary); background: var(--primary-soft); }
.k-op { color: var(--ink-2); }
.k-del { background: var(--ko-soft); color: var(--ko); }
.k-nav { color: var(--muted); }
.kb-toggle { margin-top: .4rem; }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .6rem; margin: .4rem 0 .6rem; }
.choice {
  display: flex; align-items: center; gap: .7rem; text-align: left; padding: .85rem 1rem; border: 2px solid var(--line); border-radius: 13px;
  background: var(--white); cursor: pointer; font-size: 1.1rem; font-weight: 600; min-height: 56px; color: var(--ink); transition: all .12s;
}
.choice:hover:not([disabled]) { border-color: var(--primary-2); transform: translateY(-1px); }
.choice-key { width: 28px; height: 28px; flex: none; border-radius: 8px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-size: .85rem; font-weight: 800; }
.choices.multi .choice-key { border: 2px solid var(--line); background: var(--white); }
.choice.selected { border-color: var(--primary); background: var(--primary-soft); }
.choices.multi .choice.selected .choice-key { background: var(--primary); border-color: var(--primary); }
.choices.multi .choice.selected .choice-key::after { content: "✓"; color: #fff; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.wrong { border-color: var(--ko); background: var(--ko-soft); opacity: .8; }
.choice[disabled] { cursor: default; }
.actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: .8rem; }

.feedback:empty { display: none; }
.feedback { margin-top: 1rem; border-radius: 14px; padding: .9rem 1.1rem; animation: rise .2s ease; }
.fb-title { font-weight: 800; font-size: 1.1rem; margin: 0 0 .3rem; }
.fb-ok { background: var(--ok-soft); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); }
.fb-ok .fb-title { color: var(--ok); }
.fb-retry { background: var(--mid-soft); border: 1px solid color-mix(in srgb, var(--mid) 35%, transparent); }
.fb-retry .fb-title { color: #b45309; }
.fb-ko { background: var(--surface); border: 2px solid color-mix(in srgb, var(--ko) 40%, transparent); }
.fb-ko .fb-title { color: var(--ko); }
.fb-invalid { background: var(--surface-2); border: 1px dashed #cfd2e6; color: var(--ink-2); }
.fb-note { font-size: .9rem; color: var(--ink-2); background: color-mix(in srgb, var(--surface) 70%, transparent); padding: .35rem .6rem; border-radius: 8px; }
.steps-box { margin-top: .6rem; }
.steps-box summary { cursor: pointer; font-weight: 700; color: var(--primary); }
.steps-head { font-weight: 700; color: var(--ink-2); margin: .4rem 0; }
.steps { list-style: none; counter-reset: st; padding: 0; margin: .5rem 0 0; display: grid; gap: .5rem; }
.steps li { counter-increment: st; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: .55rem .8rem .55rem 2.6rem; position: relative; }
.steps li::before { content: counter(st); position: absolute; left: .7rem; top: .6rem; width: 1.4rem; height: 1.4rem; border-radius: 50%; background: var(--primary); color: #fff; font-size: .78rem; font-weight: 800; display: grid; place-items: center; }
.steps li.final { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 35%, transparent); }
.step-label { font-weight: 650; font-size: .92rem; color: var(--ink-2); }
.step-tex { font-size: 1.12rem; overflow-x: auto; overflow-y: hidden; padding: .1rem 0; }
.step-tex .katex-display { margin: .25rem 0; text-align: left; }
.step-tex .katex-display > .katex { text-align: left; }
.step-note { font-size: .84rem; color: var(--muted); }

/* ---------- Bilan ---------- */
.summary { max-width: 860px; margin: 0 auto; }
.summary-card { display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap; }
.score-ring { --p: 0; width: 130px; height: 130px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--line) 0); }
.score-ring span { width: 100px; height: 100px; border-radius: 50%; background: var(--white); display: flex; align-items: center; justify-content: center; gap: 2px; font-size: 2rem; font-weight: 800; color: var(--primary); }
.score-ring small { font-size: .9rem; }
.summary-stats { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.summary-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.review { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.review li { display: grid; grid-template-columns: 32px 1fr auto; gap: .8rem; align-items: center; padding: .55rem .7rem; border-radius: 11px; background: var(--surface-2); }
.review li.ko { background: var(--ko-soft); }
.rv-icon { font-weight: 800; text-align: center; }
.review li.ok .rv-icon { color: var(--ok); }
.review li.ko .rv-icon { color: var(--ko); }
.rv-q { display: flex; flex-direction: column; overflow-x: auto; }
.rv-text { display: block; }
.rv-q small { color: var(--muted); }
.rv-a { font-weight: 600; }

/* ---------- Tableaux de bord ---------- */
.dash-grid, .t-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.dash-mod { border-top: 4px solid var(--mc); margin: 0; }
.tbl-wrap { overflow-x: auto; }
.tbl-wrap.tall { max-height: 420px; overflow-y: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .5rem .5rem; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; }
.tbl td { padding: .5rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl.small td { font-size: .8rem; }
.tbl tr.untried td { color: var(--muted); }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover td { background: var(--primary-soft); }
.rate { display: inline-block; font-weight: 700; padding: .05rem .5rem; border-radius: 999px; background: var(--surface-2); }
.rate.good { background: var(--ok-soft); color: var(--ok); }
.rate.mid { background: var(--mid-soft); color: var(--mid); }
.rate.weak { background: var(--ko-soft); color: var(--ko); }
.weak-tag { display: inline-block; font-style: normal; font-size: .72rem; background: var(--ko-soft); color: var(--ko); padding: .08rem .45rem; border-radius: 999px; margin: 1px 0; }
.history { list-style: none; padding: 0; margin: .6rem 0 0; display: grid; gap: .25rem; max-height: 280px; overflow-y: auto; }
.history li { display: grid; grid-template-columns: 24px 1fr auto; gap: .5rem; font-size: .9rem; padding: .25rem .4rem; border-radius: 8px; }
.history li.ok span:first-child { color: var(--ok); font-weight: 800; }
.history li.ko span:first-child { color: var(--ko); font-weight: 800; }

/* Enseignant */
.teacher-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.teacher-actions { display: flex; gap: .5rem; }
.tabs { display: flex; gap: .3rem; border-bottom: 2px solid var(--line); margin-bottom: 1.2rem; }
.tabs button { background: none; border: 0; padding: .7rem 1rem; font-weight: 700; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs button.active { color: var(--primary); border-color: var(--primary); }
.filters { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; font-size: .8rem; font-weight: 700; color: var(--ink-2); gap: .25rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .6rem; margin-bottom: .6rem; }
.heatmap td.heat { text-align: center; font-weight: 700; color: #fff; background: hsl(calc(var(--r) * 1.2) 62% 42%); border: 2px solid var(--surface); border-radius: 8px; }
.heatmap td.none { color: var(--muted); background: var(--surface-2); text-align: center; }
.hard { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.hard li { display: grid; grid-template-columns: 1fr 60px 48px; gap: .6rem; align-items: center; font-size: .9rem; }
.hard .mini-bar span { background: var(--ko); }
.form-inline { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }
.form-inline h2 { width: 100%; }
.form-inline label { display: flex; flex-direction: column; font-size: .82rem; font-weight: 700; gap: .25rem; }
.form-inline p { width: 100%; }
.code { font-size: 1rem; font-weight: 800; letter-spacing: .12em; }
.actions-cell { display: flex; flex-wrap: wrap; gap: .3rem; }
.loading { text-align: center; color: var(--muted); }

/* Notifications */
#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: grid; gap: .5rem; z-index: 100; width: min(92vw, 460px); }
.toast { background: #1b1d3a; color: #fff; padding: .75rem 1rem; border-radius: 12px; box-shadow: var(--shadow-lg); font-weight: 600; transition: opacity .4s, transform .4s; }
.toast-ok { background: var(--ok); }
.toast-err { background: var(--ko); }
.toast-warn { background: #b45309; }
.toast.out { opacity: 0; transform: translateY(10px); }

/* KaTeX : couleurs dans les démarches */
.katex { font-size: 1.08em; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .login-wrap { grid-template-columns: 1fr; min-height: auto; }
  .login-card { justify-self: stretch; max-width: none; }
  .login-hero p { max-width: none; }
  .brand-text small { display: none; }
  .topnav .btn { padding: .3rem .5rem; }
}
@media (max-width: 560px) {
  .input-row { flex-wrap: wrap; }
  .input-row .btn { width: 100%; }
  .qtex { font-size: 1.2rem; }
  .drill-title { order: 3; width: 100%; flex: none; }
  .review li { grid-template-columns: 26px 1fr; }
  .rv-a { grid-column: 2; }
  #navDash { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print { .topbar, .footer, .mathkb, .actions { display: none; } body { background: var(--white); } }

/* Espace enseignant : confirmations en deux clics, champs en ligne */
.btn.arme { background: var(--ko); color: #fff; border-color: var(--ko); }
.inline-input { border: 1px solid transparent; background: transparent; border-radius: 8px; padding: .3rem .4rem; font: inherit; color: var(--ink); width: 100%; min-width: 180px; }
.inline-input:hover, .inline-input:focus { border-color: var(--line); background: var(--surface-2); outline: none; }
.switch { display: inline-flex; align-items: center; gap: .35rem; cursor: pointer; font-size: .85rem; }
.mini-form { display: flex; gap: .3rem; }
.mini-form input { width: 90px; border: 1px solid var(--line); border-radius: 8px; padding: .3rem .5rem; background: var(--surface-2); color: var(--ink); }
.tbl th { background: var(--surface); }

/* ---------- Récompenses : XP, niveaux, badges, confettis ---------- */
.entete-stats { display: flex; gap: .35rem; }
.pastille { display: inline-flex; align-items: center; gap: .3em; padding: .25em .7em; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: .85rem; white-space: nowrap; }
.niveau-carte { display: flex; gap: 1rem; align-items: center; padding: 1rem 1.2rem; }
.niveau-badge { width: 58px; height: 58px; flex: none; border-radius: 16px; display: grid; place-items: center; background: linear-gradient(135deg, #f59e0b, var(--accent)); color: #fff; font-size: .9rem; line-height: 1; text-align: center; }
.niveau-badge b { display: block; font-size: 1.4rem; }
.niveau-info { flex: 1; display: flex; flex-direction: column; gap: .3rem; }
.niveau-ligne { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.jauge-xp { display: block; height: 10px; border-radius: 9px; background: var(--line); overflow: hidden; }
.jauge-xp span { display: block; height: 100%; border-radius: 9px; background: linear-gradient(90deg, #f59e0b, var(--accent)); transition: width .6s ease; }
.niveau-mini { display: grid; gap: .3rem; margin-top: .7rem; max-width: 360px; }
.titre-section { margin: 1.6rem 0 .7rem; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.badge-carte { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .15rem; padding: .8rem .5rem; border-radius: 12px; background: var(--surface); border: 1px dashed var(--line); opacity: .6; }
.badge-carte span { font-size: 1.6rem; filter: grayscale(1); }
.badge-carte b { font-size: .85rem; }
.badge-carte small { font-size: .72rem; color: var(--muted); line-height: 1.3; }
.badge-carte.obtenu { opacity: 1; border-style: solid; border-color: color-mix(in srgb, #f59e0b 50%, var(--line)); background: color-mix(in srgb, #f59e0b 8%, var(--surface)); }
.badge-carte.obtenu span { filter: none; }
.badge-carte.nouveau { animation: pop .6s ease; }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
.xp-gain { font-size: .78rem; background: color-mix(in srgb, #f59e0b 18%, var(--surface)); color: #b45309; padding: .1em .6em; border-radius: 99px; margin-left: .3rem; vertical-align: middle; }
[data-theme="dark"] .xp-gain { color: #fbbf24; }
.tag.xp { background: color-mix(in srgb, #f59e0b 15%, var(--surface)); color: #b45309; border-color: transparent; }
[data-theme="dark"] .tag.xp { color: #fbbf24; }
.note-interrompue { font-size: .85rem; background: var(--mid-soft); color: var(--mid); padding: .5rem .7rem; border-radius: 10px; margin-top: .6rem; }
.toast-trophee { background: linear-gradient(120deg, #b45309, #f97316); }
.toast-icone { font-size: 1.3rem; vertical-align: middle; margin-right: .3rem; }
.confettis { position: fixed; left: 50%; top: 45%; width: 0; height: 0; pointer-events: none; z-index: 99; }
.confettis i { position: absolute; width: 9px; height: 14px; border-radius: 2px; animation: confetti 1.4s cubic-bezier(.2, .7, .4, 1) forwards; }
@keyframes confetti { to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; } }
@media (max-width: 820px) { .entete-stats { display: none; } }

/* Bandeau de mise à jour */
.bandeau-maj { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; justify-content: center; gap: .8rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: linear-gradient(90deg, var(--primary), #7c3aed); color: #fff; font-weight: 600; font-size: .95rem; }
.bandeau-maj .btn { background: #fff; color: #3730a3; min-height: 34px; }
.muted-inv { opacity: .85; font-weight: 400; }
.compteur { display: inline-grid; place-items: center; min-width: 1.4em; height: 1.4em; padding: 0 .35em; border-radius: 999px; background: var(--accent); color: #fff; font-size: .75rem; margin-left: .25rem; }
.demandes { border-top: 4px solid var(--accent); }

/* ---------- Cellulaire : en-tête compact et non collant (ne cache plus la question) ---------- */
@media (max-width: 640px) {
  .topbar { position: static; padding: .45rem .7rem; gap: .35rem; }
  .logo { width: 32px; height: 32px; font-size: 1.05rem; border-radius: 10px; }
  .brand-text b { font-size: .95rem; }
  .top-right { gap: .3rem; }
  .badge { font-size: .74rem; padding: .2rem .55rem; }
  .btn-icone { min-width: 34px; height: 34px; }
  .topnav .btn { min-height: 32px; font-size: .78rem; padding: .2rem .5rem; }
  main { padding: .7rem; }
  .card { padding: .9rem; border-radius: 14px; }
  .qprompt { font-size: 1.02rem; }
  .qtex { font-size: 1.15rem; padding: .5rem .2rem .7rem; }
  .answer-input { font-size: 1.2rem; padding: .55rem .7rem; }
  .k { font-size: 1.05rem; }
  .kgrid .k { min-height: 48px; }
  .footer { font-size: .72rem; padding: .7rem; }
  .drill-top { gap: .5rem; }
}

/* Rétroaction constructive */
.intention { font-size: .88rem; color: var(--ink-2); margin: -.6rem 0 .9rem; }
.fb-diag { background: color-mix(in srgb, var(--surface) 75%, transparent); border-left: 4px solid var(--primary-2); padding: .45rem .7rem; border-radius: 8px; font-weight: 500; }
.fb-proc { font-size: .9rem; font-weight: 600; color: var(--ink-2); }
.prochaine { border-left: 5px solid var(--accent); }
.prochaine.reussite { border-left-color: var(--ok); }
.pe-texte { font-weight: 700; font-size: 1.05rem; }
#etapeBox .steps { margin-top: .5rem; }
.hard.erreurs li { grid-template-columns: 1fr 60px 64px; align-items: start; padding: .3rem 0; border-bottom: 1px dashed var(--line); }
