/* ==========================================================================
   PyPrépa — « le cahier de l'élève »
   Clair : papier Seyès, encre bleue, marge rouge, surligneur fluo.
   Sombre : tableau noir à la craie.
   ========================================================================== */
:root {
  --paper: #f6f8fc;
  --card: #ffffff;
  --card-2: #f3f6fb;
  --text: #1d2433;
  --muted: #5f6b80;
  --ink: #1f3fa8;          /* stylo bille bleu */
  --ink-soft: #e3e9fb;
  --red: #d6455d;          /* marge / stylo rouge */
  --red-soft: #fde8ec;
  --green: #1f8a4c;        /* stylo vert de correction */
  --green-soft: #e2f5ea;
  --fluo: #f7e94b;         /* surligneur */
  --fluo-soft: #fdf8c7;
  --accent: #0e8fa3;
  --orange: #e07a1f;
  --violet: #7b4bd1;
  --line: #cdd6e4;
  --grid: #dbe7f7;
  --grid-strong: #b9cdea;
  --shadow: 0 1px 0 rgba(31, 63, 168, .06), 0 6px 18px -10px rgba(29, 36, 51, .25);
  --radius-s: 8px;
  --radius: 14px;
  --font-ui: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-title: "Bricolage Grotesque", "Atkinson Hyperlegible", system-ui, sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --font-hand: "Caveat", "Segoe Print", cursive;
  --nav-h: 64px;
  --side-w: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #18241f; --card: #1f2e28; --card-2: #24362f; --text: #e7eee9; --muted: #9db0a6;
    --ink: #9ec1ff; --ink-soft: #24365a; --red: #ff8a95; --red-soft: #45242a; --green: #6fdc9c; --green-soft: #1f3d2c;
    --fluo: #f1e05a; --fluo-soft: #3d3a1c; --accent: #5fd0e0; --orange: #ffb067; --violet: #c3a6ff;
    --line: #34493f; --grid: #22332c; --grid-strong: #2b4037;
    --shadow: 0 1px 0 rgba(0,0,0,.2), 0 8px 22px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #18241f; --card: #1f2e28; --card-2: #24362f; --text: #e7eee9; --muted: #9db0a6;
  --ink: #9ec1ff; --ink-soft: #24365a; --red: #ff8a95; --red-soft: #45242a; --green: #6fdc9c; --green-soft: #1f3d2c;
  --fluo: #f1e05a; --fluo-soft: #3d3a1c; --accent: #5fd0e0; --orange: #ffb067; --violet: #c3a6ff;
  --line: #34493f; --grid: #22332c; --grid-strong: #2b4037;
  --shadow: 0 1px 0 rgba(0,0,0,.2), 0 8px 22px -12px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.55;
  color: var(--text);
  background-color: var(--paper);
  /* quadrillage Seyès : lignes fines tous les 8px, fortes tous les 32px */
  background-image:
    linear-gradient(to right, var(--grid-strong) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-strong) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px, 32px 32px, 8px 8px;
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
}
img, svg, video { max-width: 100%; }
a { color: var(--ink); text-underline-offset: 3px; }
code, pre, kbd { font-family: var(--font-code); font-size: .9em; }
:not(pre) > code { background: var(--ink-soft); color: var(--ink); padding: .05em .35em; border-radius: 5px; }
h1, h2, h3 { font-family: var(--font-title); line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); font-weight: 800; }
h2 { font-size: 1.45rem; font-weight: 700; }
h3 { font-size: 1.15rem; font-weight: 700; }
p { margin: 0 0 .8em; }
:focus-visible { outline: 3px solid var(--fluo); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hand { font-family: var(--font-hand); font-size: 1.35em; line-height: 1.1; }
.muted { color: var(--muted); }
.fluo { background: linear-gradient(transparent 55%, var(--fluo) 55%, var(--fluo) 90%, transparent 90%); padding: 0 .1em; }
:root[data-theme="dark"] .fluo, :root:not([data-theme="light"]) .fluo { color: inherit; }

/* ---------- Coquille ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--card); border-right: 2px solid var(--red);
  padding: 18px 14px 24px; display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; text-decoration: none; color: var(--text); }
.brand-mark { width: 40px; height: 40px; flex: none; }
.brand-name { font-family: var(--font-title); font-weight: 800; font-size: 1.25rem; line-height: 1; }
.brand-sub { font-family: var(--font-hand); color: var(--red); font-size: 1.05rem; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-weight: 600;
}
.nav-link .ico { width: 22px; text-align: center; font-size: 1.1rem; }
.nav-link:hover { background: var(--card-2); }
.nav-link.active { background: var(--ink-soft); color: var(--ink); }
.side-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px dashed var(--line); font-size: .9rem; }

.main { min-width: 0; padding: 28px clamp(14px, 4vw, 48px) 120px; }
.page { max-width: 860px; margin: 0 auto; }
.page.wide { max-width: 1100px; }

.topbar, .bottomnav { display: none; }

@media (max-width: 900px) {
  .shell { display: block; }
  .side { display: none; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30;
    background: var(--card); border-bottom: 2px solid var(--red); padding: 8px 16px;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .topbar .brand { padding: 0; }
  .topbar .brand-mark { width: 32px; height: 32px; }
  .topbar .brand-sub { display: none; }
  .topbar .spacer { flex: 1; }
  .bottomnav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--card); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: var(--nav-h); text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 700;
  }
  .bottomnav a .ico { font-size: 1.3rem; }
  .bottomnav a.active { color: var(--ink); }
  .bottomnav a.active .ico { transform: translateY(-1px); }
  .main { padding: 16px 16px calc(var(--nav-h) + 40px); }
  body { font-size: 16px; }
}

/* ---------- Feuilles (cartes) ---------- */
.sheet {
  position: relative; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px 22px 22px 34px; margin-bottom: 18px; border: 1px solid var(--line);
}
.sheet::before { /* marge rouge du cahier */
  content: ""; position: absolute; left: 18px; top: 0; bottom: 0; width: 2px; background: var(--red); opacity: .55;
}
.sheet.plain { padding-left: 22px; }
.sheet.plain::before { display: none; }
@media (max-width: 600px) { .sheet { padding: 16px 14px 16px 24px; } .sheet::before { left: 11px; } .sheet.plain { padding-left: 14px; } }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px;
  padding: 8px 16px; border-radius: 10px; border: 2px solid var(--ink); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; line-height: 1.1;
  transition: transform .08s ease, background .15s ease;
}
.btn:hover { background: var(--ink-soft); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: var(--card); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.green { border-color: var(--green); color: var(--green); }
.btn.green.primary { background: var(--green); color: var(--card); }
.btn.red { border-color: var(--red); color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: .9rem; border-width: 1.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { min-width: 42px; padding: 6px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  background: var(--card-2); border: 1px solid var(--line); font-size: .85rem; font-weight: 700; white-space: nowrap;
}
.chip.xp { background: var(--fluo-soft); border-color: var(--fluo); color: var(--text); }
.chip.ok { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.chip.ko { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.chip.ink { background: var(--ink-soft); border-color: var(--ink); color: var(--ink); }
.stars { color: var(--orange); letter-spacing: 1px; font-size: .9rem; }

/* Picto « pas adapté au mobile » */
.nomobile {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  border: 1.5px solid var(--red); color: var(--red); font-size: .78rem; font-weight: 700; background: var(--red-soft);
}
.nomobile svg { width: 15px; height: 15px; }
.nomobile-banner {
  display: none; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 10px; margin-bottom: 12px;
  border: 1.5px dashed var(--red); background: var(--red-soft); color: var(--text);
}
@media (max-width: 760px) { .nomobile-banner { display: flex; } }

/* ---------- Accueil ---------- */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: center; }
.hero h1 { margin-bottom: .2em; }
.hero .hand { color: var(--red); font-size: 1.6rem; }
.mascot { width: 120px; height: 120px; }
@media (max-width: 600px) { .hero { grid-template-columns: 1fr; } .mascot { width: 84px; height: 84px; position: absolute; right: 10px; top: 6px; } .hero-text { padding-right: 70px; } }
.level-bar { height: 14px; background: var(--card-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.level-bar > span { display: block; height: 100%; background: repeating-linear-gradient(-45deg, var(--fluo) 0 10px, #f2dc2a 10px 20px); border-radius: 999px; transition: width .6s ease; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 600px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--card-2); border-radius: 12px; padding: 10px 12px; border: 1px solid var(--line); }
.stat b { display: block; font-family: var(--font-title); font-size: 1.5rem; line-height: 1.1; }
.stat span { font-size: .85rem; color: var(--muted); }

/* Carte de chapitre = onglet de classeur */
.ch-card {
  position: relative; display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 16px 14px;
  box-shadow: var(--shadow); overflow: hidden; min-height: 150px;
}
.ch-card::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--ch, var(--ink)); }
.ch-card:hover { border-color: var(--ch, var(--ink)); }
.ch-num { font-family: var(--font-hand); font-size: 1.3rem; color: var(--ch, var(--ink)); line-height: 1; }
.ch-title { font-family: var(--font-title); font-weight: 700; font-size: 1.08rem; line-height: 1.2; }
.ch-emoji { position: absolute; right: 12px; top: 10px; font-size: 1.6rem; }
.ch-meta { margin-top: auto; display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: .85rem; color: var(--muted); }
.progress-mini { height: 6px; background: var(--card-2); border-radius: 99px; overflow: hidden; flex: 1; }
.progress-mini > span { display: block; height: 100%; background: var(--green); }
.level-title { margin: 26px 0 10px; display: flex; align-items: baseline; gap: 10px; }
.level-title .hand { color: var(--red); }

/* ---------- Chapitre ---------- */
.ch-head { display: flex; gap: 14px; align-items: flex-start; }
.ch-head .big-emoji { font-size: 2.6rem; line-height: 1; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 14px 0 18px; border-bottom: 2px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 9px 14px; border: none; background: none; font: inherit; font-weight: 700; color: var(--muted);
  cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; text-decoration: none;
}
.tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.toc { display: flex; flex-wrap: wrap; gap: 6px; }
.toc a { font-size: .9rem; }
.objectives li::marker { content: "☐  "; color: var(--ink); }
.objectives li.done::marker { content: "☑  "; color: var(--green); }
.section-title { display: flex; align-items: baseline; gap: 10px; }
.section-title .n { font-family: var(--font-hand); color: var(--red); font-size: 1.5rem; }

.callout { border-radius: 10px; padding: 12px 14px 12px 46px; margin: 12px 0; position: relative; border: 1.5px solid; }
.callout::before { position: absolute; left: 12px; top: 10px; font-size: 1.2rem; }
.callout > :last-child { margin-bottom: 0; }
.callout .lbl { font-family: var(--font-hand); font-size: 1.3rem; display: block; line-height: 1; margin-bottom: 4px; }
.callout.tip { border-color: var(--green); background: var(--green-soft); } .callout.tip::before { content: "💡"; } .callout.tip .lbl { color: var(--green); }
.callout.warn { border-color: var(--red); background: var(--red-soft); } .callout.warn::before { content: "⚠️"; } .callout.warn .lbl { color: var(--red); }
.callout.jury { border-color: var(--violet); background: color-mix(in srgb, var(--violet) 10%, var(--card)); } .callout.jury::before { content: "⚖️"; } .callout.jury .lbl { color: var(--violet); }
.callout.analogy { border-color: var(--orange); background: color-mix(in srgb, var(--orange) 9%, var(--card)); border-style: dashed; } .callout.analogy::before { content: "🧠"; } .callout.analogy .lbl { color: var(--orange); }
.callout.def { border-color: var(--ink); background: var(--ink-soft); } .callout.def::before { content: "📌"; } .callout.def .lbl { color: var(--ink); }
.steps-list { counter-reset: st; list-style: none; padding: 0; }
.steps-list li { counter-increment: st; position: relative; padding-left: 44px; margin-bottom: 10px; }
.steps-list li::before { content: counter(st); position: absolute; left: 0; top: 0; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--ink); color: var(--ink); display: grid; place-items: center; font-weight: 800; }
table.tbl { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: .95rem; }
.tbl-wrap { overflow-x: auto; }
table.tbl th, table.tbl td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
table.tbl th { background: var(--card-2); }

/* ---------- Code ---------- */
.codebox { border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; margin: 12px 0; background: var(--card); }
.codebox-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; background: var(--card-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.codebox-head .title { font-weight: 700; font-size: .9rem; margin-right: auto; color: var(--muted); }
.codebox pre.static { margin: 0; padding: 12px 14px; overflow-x: auto; font-size: .88rem; line-height: 1.5; }
.CodeMirror { height: auto; min-height: 60px; font-family: var(--font-code); font-size: 14px; line-height: 1.5; background: var(--card); color: var(--text); }
.CodeMirror-scroll { max-height: 520px; }
.CodeMirror-gutters { background: var(--card-2); border-right: 1px solid var(--line); }
.CodeMirror-linenumber { color: var(--muted); }
.CodeMirror-cursor { border-left: 2px solid var(--ink); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: var(--ink-soft) !important; }
.cm-s-cahier .cm-keyword { color: var(--violet); font-weight: 700; }
.cm-s-cahier .cm-def { color: var(--ink); font-weight: 700; }
.cm-s-cahier .cm-builtin { color: var(--accent); }
.cm-s-cahier .cm-string { color: var(--green); }
.cm-s-cahier .cm-number { color: var(--orange); }
.cm-s-cahier .cm-comment { color: var(--muted); font-style: italic; }
.cm-s-cahier .cm-operator { color: var(--red); }
.cm-s-cahier .cm-variable-2 { color: var(--ink); }
.cm-line-active { background: var(--fluo-soft) !important; }
.cm-line-error { background: var(--red-soft) !important; }
textarea.code-fallback { width: 100%; min-height: 160px; border: none; padding: 12px; font-family: var(--font-code); font-size: 14px; background: var(--card); color: var(--text); resize: vertical; tab-size: 4; }

.console { margin: 0; padding: 10px 14px; background: #10192e; color: #e4ecff; font-family: var(--font-code); font-size: .85rem; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; border-top: 1px solid var(--line); }
.console:empty { display: none; }
.console .err { color: #ff9aa8; }
.console .info { color: #9fb3d9; font-style: italic; }
.figs { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; background: #fff; border-top: 1px solid var(--line); }
.figs:empty { display: none; }
.figs img { max-width: 100%; height: auto; border-radius: 6px; }
.inputs-zone { padding: 6px 12px; border-top: 1px dashed var(--line); font-size: .85rem; }
.inputs-zone textarea { width: 100%; min-height: 40px; font-family: var(--font-code); background: var(--card-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; }

/* Pas à pas */
.tracer { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 0; border-top: 1px solid var(--line); }
@media (max-width: 760px) { .tracer { grid-template-columns: 1fr; } }
.tracer-code { margin: 0; padding: 8px 0; font-family: var(--font-code); font-size: .85rem; overflow-x: auto; background: var(--card); }
.tracer-code div { padding: 0 12px 0 0; white-space: pre; display: flex; }
.tracer-code div .ln { display: inline-block; width: 36px; text-align: right; padding-right: 10px; color: var(--muted); flex: none; }
.tracer-code div.cur { background: var(--fluo-soft); box-shadow: inset 4px 0 0 var(--orange); }
.tracer-code div.prev { background: color-mix(in srgb, var(--green) 9%, transparent); }
.tracer-state { padding: 10px 12px; background: var(--card-2); border-left: 1px solid var(--line); font-size: .85rem; min-width: 0; }
.frame { border: 1.5px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--card); }
.frame.top { border-color: var(--ink); }
.frame h4 { margin: 0; padding: 4px 8px; font-size: .8rem; border-bottom: 1px solid var(--line); font-family: var(--font-code); color: var(--ink); }
.frame table { width: 100%; border-collapse: collapse; font-family: var(--font-code); font-size: .8rem; }
.frame td { padding: 3px 8px; border-bottom: 1px dashed var(--line); vertical-align: top; word-break: break-all; }
.frame td:first-child { color: var(--violet); width: 35%; font-weight: 700; }
.frame tr.changed td { background: var(--fluo-soft); }
.tracer-out { font-family: var(--font-code); background: #10192e; color: #e4ecff; padding: 6px 8px; border-radius: 6px; white-space: pre-wrap; max-height: 140px; overflow: auto; font-size: .8rem; min-height: 1.6em; }
.tracer-bar { display: flex; gap: 6px; align-items: center; padding: 8px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.tracer-bar input[type=range] { flex: 1; min-width: 120px; accent-color: var(--ink); }

/* ---------- Exercices ---------- */
.ex-list { display: grid; gap: 8px; }
.ex-item {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); text-decoration: none; color: var(--text);
}
.ex-item:hover { border-color: var(--ink); }
.ex-item .st { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; border: 2px solid var(--line); font-size: .95rem; }
.ex-item.done .st { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.ex-item.tried .st { border-color: var(--orange); color: var(--orange); }
.ex-item .t { font-weight: 700; line-height: 1.25; }
.ex-item .tp { font-size: .8rem; color: var(--muted); }
.ex-type { font-size: .78rem; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: var(--card-2); border: 1px solid var(--line); }

.ex-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.ex-statement { margin-bottom: 12px; }
.choices { display: grid; gap: 8px; margin: 12px 0; }
.choice {
  display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 11px 14px; border-radius: 10px; border: 2px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; cursor: pointer; min-height: 48px;
}
.choice .key { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-weight: 800; font-size: .85rem; }
.choice.sel { border-color: var(--ink); background: var(--ink-soft); }
.choice.sel .key { border-color: var(--ink); background: var(--ink); color: var(--card); }
.choice.good { border-color: var(--green); background: var(--green-soft); }
.choice.bad { border-color: var(--red); background: var(--red-soft); }
.choice:disabled { cursor: default; }

.feedback { margin-top: 14px; border-radius: 12px; padding: 12px 14px; border: 2px solid; position: relative; }
.feedback.ok { border-color: var(--green); background: var(--green-soft); }
.feedback.ko { border-color: var(--red); background: var(--red-soft); }
.feedback.info { border-color: var(--ink); background: var(--ink-soft); }
.feedback .verdict { font-family: var(--font-hand); font-size: 1.7rem; line-height: 1; display: block; margin-bottom: 6px; }
.feedback.ok .verdict { color: var(--green); }
.feedback.ko .verdict { color: var(--red); }
.explain { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 12px; }
.explain h4 { margin: 0 0 6px; font-family: var(--font-hand); font-size: 1.4rem; color: var(--red); font-weight: 400; }

.tests { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.tests li { padding: 8px 10px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); font-size: .88rem; }
.tests li.ok { border-left: 5px solid var(--green); }
.tests li.ko { border-left: 5px solid var(--red); }
.tests code { white-space: pre-wrap; }

.hints { margin-top: 10px; }
.hint { padding: 8px 12px; border-left: 4px solid var(--orange); background: color-mix(in srgb, var(--orange) 8%, var(--card)); border-radius: 0 8px 8px 0; margin-top: 8px; }

/* Banque de termes / trous */
.bank { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; border: 2px dashed var(--line); border-radius: 12px; min-height: 54px; background: var(--card-2); }
.term {
  font-family: var(--font-code); font-size: .9rem; padding: 6px 12px; border-radius: 8px; border: 2px solid var(--ink);
  background: var(--card); color: var(--ink); cursor: pointer; min-height: 38px; user-select: none; touch-action: manipulation;
}
.term.used { opacity: .3; pointer-events: none; }
.term.picked { background: var(--ink); color: var(--card); }
.holes-code { font-family: var(--font-code); font-size: .9rem; background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px; white-space: pre-wrap; overflow-x: auto; line-height: 2.2; }
.hole {
  display: inline-block; min-width: 64px; min-height: 30px; padding: 0 8px; line-height: 26px; vertical-align: middle;
  border: 2px dashed var(--orange); border-radius: 7px; background: var(--fluo-soft); color: var(--text); cursor: pointer; text-align: center;
}
.hole.filled { border-style: solid; border-color: var(--ink); background: var(--ink-soft); color: var(--ink); }
.hole.focus { box-shadow: 0 0 0 3px var(--fluo); }
.hole.good { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.hole.bad { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.terms-help { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; font-size: .85rem; }
.terms-help code { cursor: help; }

/* Parsons */
.parsons { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 6px; }
.parsons li {
  display: flex; align-items: center; gap: 6px; border: 1.5px solid var(--line); border-radius: 9px; background: var(--card);
  padding: 4px 6px 4px 10px; font-family: var(--font-code); font-size: .88rem; white-space: pre; overflow-x: auto; touch-action: none;
}
.parsons li .code { flex: 1; cursor: grab; padding: 6px 0; }
.parsons li.dragging { opacity: .6; border-color: var(--ink); background: var(--ink-soft); }
.parsons li.good { border-color: var(--green); }
.parsons li.bad { border-color: var(--red); }
.parsons .mv { flex: none; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--card-2); color: var(--text); cursor: pointer; font-size: .9rem; }

/* Blockly */
.blockly-wrap { height: 460px; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; }
@media (max-width: 760px) { .blockly-wrap { height: 380px; } }
.blockly-code { font-family: var(--font-code); font-size: .82rem; white-space: pre; background: var(--card-2); padding: 10px; border-radius: 10px; overflow-x: auto; margin: 8px 0; }

/* SQL */
.sql-tables { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin: 10px 0; }
.sql-table { border: 1.5px solid var(--line); border-radius: 10px; overflow: auto; background: var(--card); max-height: 260px; }
.sql-table h5 { margin: 0; padding: 6px 10px; font-family: var(--font-code); background: var(--card-2); border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.sql-table table, .result-table { border-collapse: collapse; width: 100%; font-size: .82rem; font-family: var(--font-code); }
.sql-table td, .sql-table th, .result-table td, .result-table th { border-bottom: 1px solid var(--line); padding: 3px 8px; text-align: left; white-space: nowrap; }
.result-wrap { overflow: auto; max-height: 300px; border-top: 1px solid var(--line); background: var(--card); }

/* Rédaction */
textarea.redac { width: 100%; min-height: 140px; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px; font: inherit; background: var(--card); color: var(--text);
  background-image: linear-gradient(to bottom, transparent 27px, var(--grid-strong) 27px, var(--grid-strong) 28px); background-size: 100% 28px; line-height: 28px; }
.criteria label { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; }
.criteria input { width: 20px; height: 20px; accent-color: var(--green); flex: none; margin-top: 3px; }

/* ---------- Animations (classes partagées) ---------- */
.anim { margin: 14px 0; border: 1.5px solid var(--line); border-radius: 14px; background: var(--card); overflow: hidden; }
.anim-head { padding: 7px 12px; background: var(--card-2); border-bottom: 1px solid var(--line); font-weight: 700; font-size: .9rem; display: flex; gap: 8px; align-items: center; }
.anim-head .hand { color: var(--red); font-size: 1.25rem; margin-left: auto; font-weight: 400; }
.anim-body { padding: 12px; }
.anim-caption { padding: 0 12px 10px; font-size: .88rem; color: var(--muted); }
.anim-controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; }
.anim-btn {
  min-height: 38px; min-width: 40px; padding: 4px 12px; border-radius: 9px; border: 1.5px solid var(--ink); background: var(--card);
  color: var(--ink); font: inherit; font-weight: 700; cursor: pointer;
}
.anim-btn:hover { background: var(--ink-soft); }
.anim-btn.primary { background: var(--ink); color: var(--card); }
.anim-btn:disabled { opacity: .45; cursor: not-allowed; }
.anim-speed { min-height: 38px; border-radius: 9px; border: 1.5px solid var(--line); background: var(--card); color: var(--text); font: inherit; padding: 0 6px; }
.anim-count { font-size: .82rem; color: var(--muted); margin-left: auto; }
.anim-msg { min-height: 2.6em; margin-top: 10px; padding: 8px 12px; border-radius: 9px; background: var(--fluo-soft); border-left: 4px solid var(--fluo); font-size: .93rem; }
.anim-msg:empty { display: none; }
.anim-slider { display: flex; align-items: center; gap: 8px; font-size: .9rem; flex-wrap: wrap; }
.anim-slider input { flex: 1; min-width: 120px; accent-color: var(--ink); min-height: 30px; }
.anim-slider-val { font-family: var(--font-code); font-weight: 700; min-width: 2.5em; color: var(--ink); }
.anim-missing { color: var(--muted); font-style: italic; padding: 12px; margin: 0; }

/* ---------- Révision / flashcards ---------- */
.flashcard { perspective: 1200px; height: 280px; cursor: pointer; margin: 10px 0 14px; }
.flashcard-inner { position: relative; width: 100%; height: 100%; transition: transform .5s; transform-style: preserve-3d; }
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 16px; border: 1.5px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; text-align: center; overflow: auto;
  background-color: var(--card);
  background-image: linear-gradient(to bottom, transparent 31px, var(--grid) 31px, var(--grid) 32px); background-size: 100% 32px;
}
.flashcard-face.back { transform: rotateY(180deg); }
.flashcard-face .term-big { font-family: var(--font-code); font-size: clamp(1.3rem, 5vw, 2rem); font-weight: 700; color: var(--ink); }
.flashcard-face .from { position: absolute; top: 10px; left: 14px; font-size: .8rem; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .flashcard-inner { transition: none; } }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate .btn { flex-direction: column; gap: 0; font-size: .9rem; }
.rate .btn small { font-weight: 400; font-size: .72rem; opacity: .8; }

/* ---------- Examens ---------- */
.exam-bar {
  position: sticky; top: 0; z-index: 20; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 14px;
  background: var(--card); border: 1.5px solid var(--ink); border-radius: 12px; margin-bottom: 14px; box-shadow: var(--shadow);
}
@media (max-width: 900px) { .exam-bar { top: 52px; } }
.timer { font-family: var(--font-code); font-weight: 800; font-size: 1.2rem; color: var(--ink); }
.timer.low { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .timer.low { animation: none; } }
.score-big { font-family: var(--font-hand); font-size: 4.5rem; line-height: 1; color: var(--red); }
.score-big small { font-size: 2rem; }
.exam-item { border-top: 1px dashed var(--line); padding-top: 14px; margin-top: 14px; }
.pts { font-family: var(--font-hand); color: var(--red); font-size: 1.3rem; }

/* ---------- Badges ---------- */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.badge { text-align: center; padding: 12px 8px; border-radius: 12px; border: 1.5px dashed var(--line); background: var(--card); }
.badge .b-ico { font-size: 2rem; display: block; filter: grayscale(1); opacity: .45; }
.badge.got { border-style: solid; border-color: var(--fluo); background: var(--fluo-soft); }
.badge.got .b-ico { filter: none; opacity: 1; }
.badge .b-name { font-weight: 700; font-size: .85rem; display: block; }
.badge .b-desc { font-size: .75rem; color: var(--muted); }

/* ---------- Lexique ---------- */
.lex-search { width: 100%; min-height: 46px; padding: 8px 14px; border-radius: 12px; border: 2px solid var(--line); font: inherit; background: var(--card); color: var(--text); }
.lex-search:focus { border-color: var(--ink); outline: none; }
.lex-item { padding: 10px 0; border-bottom: 1px dashed var(--line); }
.lex-item dt { font-family: var(--font-code); font-weight: 700; color: var(--ink); }
.lex-item dd { margin: 2px 0 0; }
.lex-item pre { margin: 6px 0 0; background: var(--card-2); padding: 6px 10px; border-radius: 8px; font-size: .82rem; overflow-x: auto; }

/* ---------- Ressources ---------- */
.res-item { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); text-decoration: none; color: var(--text); }
.res-item .ri { font-size: 1.5rem; }
.res-item:hover { border-color: var(--ink); }
video.res-video { width: 100%; border-radius: 12px; background: #000; max-height: 70vh; }

/* ---------- Toasts / confettis / modale ---------- */
.toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
@media (min-width: 901px) { .toasts { bottom: 24px; } }
.toast { pointer-events: auto; background: var(--card); border: 2px solid var(--ink); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: center; animation: toastin .25s ease; }
.toast.xp { border-color: var(--fluo); background: var(--fluo-soft); }
.toast.badge-t { border-color: var(--violet); }
@keyframes toastin { from { transform: translateY(10px); opacity: 0; } }
.update-banner { position: fixed; z-index: 120; top: 10px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--card); padding: 8px 10px 8px 16px; border-radius: 999px; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); font-weight: 700; max-width: calc(100vw - 20px); }
.update-banner .btn { min-height: 32px; background: var(--fluo); color: #1d2433; border-color: var(--fluo); }
.update-banner { white-space: nowrap; font-size: .92rem; }
@media (max-width: 900px) { .update-banner { top: auto; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); font-size: .85rem; } }
.nomobile-banner .nomobile { padding: 4px; border-radius: 50%; flex: none; }
.nomobile-banner .nomobile svg { width: 26px; height: 26px; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 110; }
.modal-back { position: fixed; inset: 0; background: rgba(10, 16, 30, .45); z-index: 90; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--card); border-radius: 16px; padding: 20px; max-width: 520px; width: 100%; box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }

.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.empty .hand { font-size: 1.8rem; color: var(--ink); display: block; }
.kbd-hint { font-size: .8rem; color: var(--muted); }
.loader { display: inline-block; width: 16px; height: 16px; border: 2.5px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.pystatus { font-size: .8rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); display: inline-block; }
.dot.ready { background: var(--green); } .dot.loading { background: var(--orange); } .dot.error { background: var(--red); }

input[type=text], input[type=password], select.field, textarea.field {
  min-height: 42px; padding: 6px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card); color: var(--text); font: inherit;
}
.form-row { display: grid; gap: 4px; margin-bottom: 10px; }
.form-row label { font-weight: 700; font-size: .9rem; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 0; }
.switch input { width: 22px; height: 22px; accent-color: var(--ink); }

.mascot-bubble { display: flex; gap: 10px; align-items: flex-start; }
.mascot-bubble svg { width: 52px; height: 52px; flex: none; }
.bubble { background: var(--card); border: 1.5px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 8px 12px; font-family: var(--font-hand); font-size: 1.3rem; line-height: 1.2; color: var(--ink); }

.annex-card h3 { display: flex; gap: 8px; align-items: center; }
.annex-card ul { padding-left: 1.2em; }
.annex-card li { margin-bottom: 6px; }

@media print {
  .side, .topbar, .bottomnav, .toasts, .btn { display: none !important; }
  body { background: #fff; }
  .shell { display: block; }
}
