/*
  Feuille de style de l'application d'étude, alignée sur l'interface V4
  approuvée (apps/ui-v4-preview).

  Trois contraintes non négociables, vérifiées par test/test_handwriting.py :
  - « touch-action: pan-y » sur la page d'écriture, et jamais « touch-action:
    none » : le doigt fait défiler la copie, le stylet écrit ;
  - la paume posée sur l'écran ne doit rien sélectionner (règles sur body),
    mais les champs de saisie restent sélectionnables ;
  - le canevas garde sa taille calculée par la mise en page (display:block,
    width:100%, aspect-ratio A4, height:auto) : sans dimensions non nulles, la
    page ne peut pas être redimensionnée et l'encre disparaît.

  Aucune police distante : la politique servie est default-src 'self'.
*/

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f1f4f9;
  --surface-blue: #f3f6ff;
  --border: #e4e8ef;
  --text: #152033;
  --muted: #6f7b8f;
  --accent: #3157d5;
  --accent-soft: #e9eeff;
  --accent-dark: #1f3ea6;
  --success: #2e8f6f;
  --warn: #d78a2f;
  --danger: #b74d3c;
  --shadow: 0 14px 42px rgba(25, 38, 70, .075);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "STIX Two Text", "Latin Modern Roman", "DejaVu Serif", Georgia, "Times New Roman", serif;
  /* Marquage d'indisponibilité : ces couleurs disent qu'un élément ne
     fonctionne pas, elles ne sont pas décoratives. */
  --miss: #c62828;
  --miss-soft: #fdf1f0;
  --hold: #b26a00;
  --hold-soft: #fff8ec;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  /* Une main posée sur l'écran pendant qu'on écrit ne doit rien sélectionner ni
     faire apparaître le menu « Copier » de Safari. Le défilement au doigt et la
     navigation ne sont pas concernés. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Ce qui doit rester sélectionnable : les champs de saisie, partout. */
input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* Sur un ordinateur, sélectionner un énoncé ou une correction reste utile. Sur
   une tablette, le doigt sélectionnerait par accident. */
@media (hover: hover) and (pointer: fine) {
  .rich-text,
  .math-display,
  .math-inline,
  code {
    -webkit-user-select: text;
    user-select: text;
  }
}

button, input { font: inherit; }
button { cursor: pointer; color: inherit; }
p { line-height: 1.65; }
h1, h2, h3, p { margin-top: 0; }

/* ================================================================
   Coquille : barre latérale, en-tête, zone de page
   ================================================================ */

#root { width: 100%; }

/* Les écrans de la séquence d'étude (chargement, appairage, écriture,
   correction) occupent tout l'écran : ils gardent une colonne de lecture. */
.flow-screen {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.account-landing, .account-card { min-height: calc(100dvh - 72px); padding: 24px 8px; }
.account-header { display: flex; justify-content: space-between; align-items: center; }
.account-landing main { padding-top: 20vh; }
.account-card { max-width: 460px; margin: 6vh auto; min-height: auto; padding: 32px; border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.account-card h1 { font-size: 30px; }
.account-form { display: grid; gap: 16px; margin-top: 24px; }
.account-form label { display: grid; gap: 6px; font-size: 14px; font-weight: 650; }
.account-form input { min-height: 46px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.account-form button, .account-link { min-height: 46px; padding: 10px 16px; border: 0; border-radius: 10px; color: #fff; background: var(--accent); font-weight: 700; }
.account-link { min-height: 38px; }
.account-links { display: grid; gap: 10px; margin-top: 20px; }
.account-links button { border: 0; background: transparent; color: var(--accent-dark); text-align: left; }

.app-shell { min-height: 100dvh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  padding: 28px 20px;
  border-right: 1px solid var(--border);
  background: rgba(255, 255, 255, .94);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.brand {
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px 28px;
  text-align: left;
}

.brand-mark, .avatar, .avatar-btn { display: grid; place-items: center; border-radius: 12px; font-weight: 700; }
.brand-mark { width: 38px; height: 38px; background: var(--text); color: #fff; font-family: var(--serif); font-size: 22px; }
.brand strong, .mini-profile strong { display: block; font-size: 14px; }
.brand span, .mini-profile span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }

.nav { display: grid; gap: 7px; }
.nav-item {
  border: 0;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}
.nav-item:hover { color: var(--text); background: var(--surface-soft); }
.nav-item.active { color: var(--accent-dark); background: var(--accent-soft); }
.nav-icon { width: 22px; text-align: center; font-size: 16px; }

.sidebar-footer { margin-top: auto; }
.mini-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 16px 10px 0;
  border-top: 1px solid var(--border);
}
.avatar, .avatar-btn { width: 36px; height: 36px; border: none; background: var(--text); color: #fff; }

.main { width: min(1240px, 100%); margin: 0 auto; padding: 42px clamp(24px, 4vw, 64px) 72px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 30px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 8px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .14em; }
h1 { margin-bottom: 7px; font-size: clamp(30px, 4vw, 42px); letter-spacing: -.045em; }
.subtitle { margin-bottom: 0; color: var(--muted); font-size: 14px; }
.top-actions { display: flex; gap: 10px; align-items: flex-start; }
.icon-btn { width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); }

.page { display: block; }

/* ================================================================
   Marquage d'indisponibilité
   Un bloc rouge est une fonction absente du serveur : il reste visible,
   marqué, et ses commandes désactivées. Rien ne peut le masquer.
   ================================================================ */

.blk-b, .blk-c { position: relative; }
.blk-b {
  border: 2px solid var(--miss) !important;
  border-radius: 12px;
  background-color: var(--miss-soft) !important;
  background-image: repeating-linear-gradient(135deg, rgba(198, 40, 40, .07) 0 8px, transparent 8px 16px) !important;
}
.blk-c {
  border: 2px solid var(--hold) !important;
  border-radius: 12px;
  background-color: var(--hold-soft) !important;
  background-image: repeating-linear-gradient(135deg, rgba(178, 106, 0, .07) 0 8px, transparent 8px 16px) !important;
}
.badge-b, .badge-c {
  display: block;
  margin: -2px 0 10px;
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .09em;
  color: #fff;
  text-align: center;
}
.badge-b { background: var(--miss); }
.badge-c { background: var(--hold); }
.blk-b::after, .blk-c::after {
  content: attr(data-reason);
  display: block;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed rgba(0, 0, 0, .14);
  font-size: 10px;
  line-height: 1.6;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.blk-b::after { color: #8e2019; }
.blk-c::after { color: #7d4b00; }
.blk-b [disabled], .blk-c [disabled] { opacity: .55; cursor: not-allowed; }
.blk-b button[disabled] { text-decoration: line-through; }

.blk-b.mini, .blk-c.mini {
  display: inline-block;
  margin: 6px 0 0;
  padding: 6px 8px;
  border-width: 1px !important;
  border-radius: 8px;
  vertical-align: top;
}
.blk-b.mini .badge-b, .blk-c.mini .badge-c { display: block; margin: 0 0 4px; padding: 2px 5px; font-size: 7px; letter-spacing: .06em; }
.blk-b.mini::after, .blk-c.mini::after { margin-top: 5px; padding-top: 5px; font-size: 9px; }
/* Sur le panneau bleu, le texte est blanc : dans un bloc marqué le fond
   redevient clair, donc le texte doit repasser en sombre. */
.blk-b.mini.light { background-color: rgba(255, 255, 255, .94) !important; color: var(--text); }
.math-caption .blk-b.mini { margin-top: 8px; }
.top-actions .blk-b.mini, .sidebar-footer .blk-b.mini { display: block; }
.top-actions .blk-b.mini { width: 250px; }
.blk-b.mini .nav-item { min-height: 34px; font-size: 12px; }
.mini-profile .blk-b.mini { margin-top: 5px; font-size: 11px; }
.lesson-meta .blk-b.mini, .exercise-foot .blk-b.mini { max-width: 230px; }
/* Ces blocs marqués sont eux-mêmes des rangées flex : sans passage à la ligne,
   le badge deviendrait une colonne à côté des boutons au lieu de les encadrer. */
.view-switch.blk-b, .training-path.blk-b { flex-wrap: wrap; }
.view-switch.blk-b > .badge-b, .training-path.blk-b > .badge-b,
.view-switch.blk-b::after, .training-path.blk-b::after { flex: 0 0 100%; }

/* ================================================================
   Éléments communs
   ================================================================ */

.pill {
  display: inline-flex;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .1em;
}
.pill.inverted { background: rgba(255, 255, 255, .12); color: #fff; }

.section-block { margin-top: 52px; }
.section-block.compact { margin-top: 34px; }
.section-heading, .split-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.section-heading h2, .split-heading h2 { margin-bottom: 0; font-size: 24px; letter-spacing: -.03em; }
/* Un lien reste une cible tactile : 44px de haut au minimum, sinon il est
   inatteignable au doigt sur l'iPad. */
.link-btn { border: 0; background: transparent; color: var(--accent-dark); font-size: 12px; font-weight: 600; min-height: 44px; padding: 0 4px; }
.link-btn:disabled { color: var(--muted); cursor: default; }

.primary-btn, .secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 13px;
}
.primary-btn { border: none; background: var(--text); color: #fff; }
.secondary-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.primary-btn:disabled, .secondary-btn:disabled { opacity: .5; cursor: default; }
.full { width: 100%; }

/* Boutons des écrans de la séquence d'étude : mêmes couleurs, cible plus
   grande, parce qu'on les touche avec la main qui tient le stylet. */
.primary-button, .secondary-button {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 1.02rem;
  font-weight: 600;
  text-align: center;
}
.primary-button { border: none; background: var(--text); color: #fff; }
.secondary-button { border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.primary-button:active:not(:disabled), .secondary-button:active:not(:disabled) { transform: translateY(1px); }
.primary-button:disabled, .secondary-button:disabled { opacity: .5; cursor: default; }

.link-button {
  border: none;
  background: transparent;
  color: var(--accent-dark);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 4px;
  min-height: 44px;
  cursor: pointer;
}
.link-button:disabled { color: var(--muted); cursor: default; }

.back-button {
  /* Le retour reste collé au bord gauche du contenu : étiré sur toute la
     largeur, son libellé se retrouverait centré au milieu de la page. */
  align-self: flex-start;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  min-height: 44px;
  padding: 10px 0;
  cursor: pointer;
}

.card {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.card-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 8px; }
.card-text { color: var(--muted); font-size: 0.95rem; }
.card-note { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }

.banner {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 16px;
}
.banner-error { border-left-color: var(--miss); background: var(--miss-soft); color: #8e2019; }
.banner-action { margin-top: 10px; }

.screen-header { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.screen-title { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }
.app-brand { font-size: 1.5rem; font-weight: 700; color: var(--accent-dark); text-align: center; margin-bottom: 8px; }

.row-list { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
  width: 100%;
}
.row-tappable { cursor: pointer; }
.row-tappable:active { background: var(--surface-soft); }
.row-title { font-size: 1rem; font-weight: 600; }
.row-chevron { color: var(--muted); font-size: 1.1rem; }

/* Étiquettes d'état d'une notion. Le vocabulaire est celui du serveur. */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-mastered { color: #23755a; background: #e9f7f1; border-color: #b8decf; }
.status-consolidating { color: var(--accent-dark); background: var(--accent-soft); border-color: #c7d4ff; }
.status-learning, .status-started { color: #8a5a12; background: #fff8ef; border-color: #ffe3bf; }
.status-unknown { color: var(--muted); background: var(--surface-soft); border-color: #d5dbe6; }
.status-review-due { color: #795c16; background: #fff5d9; border-color: #f0dca6; }
.status-available { color: #4d5f80; background: #fbfcff; border-color: #cdd6e6; }
.status-locked { color: #7b8497; background: var(--surface-soft); border-color: #d5dbe6; }

.dot, .status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.status-dot { width: 8px; height: 8px; }
.dot.mastered, .status-dot.mastered { background: var(--success); }
.dot.consolidating, .status-dot.consolidating { background: var(--accent); }
.dot.learning, .status-dot.learning,
.dot.started, .status-dot.started { background: var(--warn); }
.dot.review-due, .status-dot.review-due { background: #c9a227; }
.dot.available, .status-dot.available { background: #8fa1c4; }
.dot.locked, .status-dot.locked { background: #c3cad8; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; color: var(--muted); font-size: 11px; }
.legend span { display: flex; align-items: center; gap: 7px; }

.star-group { display: flex; gap: 8px; }
.star {
  width: 52px;
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
}
.star-on { border-color: #cad4ff; background: var(--accent-soft); color: var(--accent-dark); }
.star:disabled { opacity: .5; cursor: default; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(49, 87, 213, .2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================
   Accueil
   ================================================================ */

.hero-card {
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, .7fr);
  min-height: 360px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.hero-copy { padding: clamp(30px, 5vw, 54px); }
.hero-copy h2, .training-reco h2, .course-toolbar h2, .progress-hero h2 {
  margin: 24px 0 10px;
  font-size: clamp(30px, 4vw, 44px);
  letter-spacing: -.045em;
}
.hero-copy > div > p, .progress-hero-copy p { max-width: 720px; margin-bottom: 16px; color: var(--muted); }
.lesson-meta { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 28px; color: var(--muted); font-size: 13px; }

.math-panel {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 34px;
  background: radial-gradient(circle at top right, rgba(255, 255, 255, .26), transparent 28%), linear-gradient(145deg, #2f55d4, #213a8c);
  color: #fff;
}
.math-panel::before, .math-panel::after { content: ""; position: absolute; border: 1px solid rgba(255, 255, 255, .12); border-radius: 50%; }
.math-panel::before { width: 260px; height: 260px; right: -120px; top: -100px; }
.math-panel::after { width: 180px; height: 180px; left: -100px; bottom: -70px; }
.math-label { position: relative; z-index: 1; font-size: 10px; font-weight: 700; letter-spacing: .12em; opacity: .72; }
.simple-symbol {
  position: relative;
  z-index: 1;
  align-self: center;
  margin: 10px 0 12px;
  font-family: var(--serif);
  font-size: clamp(72px, 11vw, 130px);
  line-height: 1;
}
.math-caption { position: relative; z-index: 1; }
.math-caption strong { display: block; font-size: 16px; }

/* L'anneau lit sa part depuis --ring, posée par le script à partir de la
   maîtrise mesurée. Sans mesure, il n'y a pas d'anneau du tout. */
.mastery-ring {
  position: relative;
  z-index: 1;
  align-self: flex-end;
  width: 94px;
  height: 94px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(#fff 0 var(--ring, 0%), rgba(255, 255, 255, .18) var(--ring, 0%) 100%);
}
.mastery-ring::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: #2948b5; }
.mastery-ring div { position: relative; z-index: 2; text-align: center; }
.mastery-ring strong, .mastery-ring span { display: block; }
.mastery-ring strong { font-size: 19px; }
.mastery-ring span { margin-top: 2px; font-size: 8px; opacity: .8; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card { min-height: 150px; padding: 22px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface); height: auto; }
.stat-label, .stat-note { display: block; color: var(--muted); }
.stat-label { min-height: 36px; font-size: 12px; font-weight: 500; }
.stat-card strong { display: block; margin: 6px 0; font-size: 29px; letter-spacing: -.04em; }
.stat-note { font-size: 11px; }

.progress-card { margin-top: 14px; padding: 8px 24px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface); }
.progress-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, .8fr); align-items: center; gap: 32px; padding: 18px 0; }
/* Une rangée cliquable est un bouton : sans ces règles il se réduirait à son
   contenu et les rangées ne seraient plus alignées entre elles. */
.progress-row.row-tappable { width: 100%; border: 0; background: transparent; color: inherit; text-align: left; }
.progress-row.row-tappable:active { background: var(--surface-soft); }
.progress-row + .progress-row { border-top: 1px solid var(--border); }
.progress-info { display: flex; align-items: center; gap: 14px; }
.subject-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-soft); font-family: var(--serif); font-size: 20px; }
.progress-info strong, .progress-info span { display: block; }
.progress-info strong { font-size: 14px; }
.progress-info span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.progress-side { display: grid; grid-template-columns: 46px minmax(0, 1fr); align-items: center; gap: 12px; }
.progress-side > strong { font-size: 13px; }
.progress-side > strong.empty { color: var(--muted); font-weight: 500; }
.progress-track { overflow: hidden; height: 7px; border-radius: 999px; background: var(--surface-soft); }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.progress-track.dark { background: rgba(255, 255, 255, .13); }
.progress-track.dark span { background: #fff; }

.quick-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.quick-card {
  min-height: 132px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 20px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  text-align: left;
}
.quick-card:hover { box-shadow: var(--shadow); border-color: #d7ddea; }
.quick-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-soft); font-size: 18px; }
.quick-card strong { display: block; font-size: 15px; }
.quick-card p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.home-header { display: flex; flex-direction: column; gap: 4px; margin-bottom: 18px; }
.home-greeting { font-size: 1.6rem; font-weight: 700; }
.card-today { border-left: 4px solid var(--accent); }
.today-subject { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: .08em; }
.today-concept { font-size: 1.15rem; font-weight: 700; margin: 6px 0; }
.today-reason { color: var(--muted); font-size: 0.95rem; margin-bottom: 14px; }
.alternative-title { font-size: 0.9rem; color: var(--muted); margin: 22px 0 8px; }
.progress-list { display: flex; flex-direction: column; }
.progress-entry { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.progress-entry + .progress-entry { border-top: 1px solid var(--border); }
.progress-name { font-size: 0.98rem; }

/* ================================================================
   Chapitres, entraînement, bibliothèque d'exercices
   ================================================================ */

.chapter-list { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.chapter-row {
  width: 100%;
  min-height: 44px;
  border: 0;
  background: transparent;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 20px 22px;
  text-align: left;
}
.chapter-row + .chapter-row { border-top: 1px solid var(--border); }
.chapter-row:hover { background: #fafbfe; }
.chapter-row:disabled { cursor: default; }
.chapter-main, .chapter-status { display: flex; align-items: center; }
.chapter-main { gap: 15px; }
.chapter-number { color: #a4adbc; font-size: 11px; font-weight: 700; }
.chapter-main strong, .chapter-main span { display: block; }
.chapter-main strong { font-size: 14px; }
.chapter-main div span { margin-top: 4px; color: var(--muted); font-size: 10px; }
.chapter-status { gap: 11px; font-size: 12px; }

.training-reco {
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.training-copy { padding: 42px; }
.training-copy > div > p { max-width: 670px; color: var(--muted); }
.training-path { display: flex; align-items: flex-start; max-width: 660px; margin: 28px 0 30px; }
.path-step { min-width: 125px; text-align: center; color: var(--muted); }
.path-step > span {
  width: 32px;
  height: 32px;
  margin: 0 auto 9px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 11px;
  font-weight: 700;
}
.path-step strong, .path-step small { display: block; }
.path-step strong { color: var(--text); font-size: 11px; }
.path-step small { margin-top: 4px; font-size: 9px; }
.path-step.done > span { background: var(--success); color: #fff; border-color: var(--success); }
.path-step.active > span { background: var(--accent); color: #fff; border-color: var(--accent); }
.path-line { flex: 1; height: 1px; background: var(--border); margin-top: 16px; }
.path-line.done { background: var(--success); }

.reco-summary {
  padding: 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  background: linear-gradient(160deg, #f0f4ff, #e9efff);
  border-left: 1px solid #dde5ff;
}
.math-mini { font-family: var(--serif); font-size: 42px; color: var(--accent-dark); }
.reco-summary > div { padding-top: 14px; border-top: 1px solid rgba(49, 87, 213, .13); }
.reco-summary > div span, .reco-summary > div strong { display: block; }
.reco-summary > div span { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.reco-summary > div strong { margin-top: 5px; font-size: 14px; }

.training-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; }
.filter-panel { padding: 22px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface); }
.filter-group { margin-bottom: 22px; }
.filter-group > label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.select-like {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 0 12px;
  font-size: 12px;
  text-align: left;
}
.select-like.active { border-color: #cad4ff; background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; }
.star-levels { display: grid; gap: 8px; }
.star-btn {
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 0 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}
.star-btn.active { border-color: #cad4ff; background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; }
.star-btn span { font-size: 11px; color: var(--muted); }
.helper-text { margin: 10px 0 0; color: var(--muted); font-size: 10px; }

.exercise-library { display: grid; gap: 12px; }
.exercise-card { padding: 22px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface); }
.exercise-head, .exercise-foot { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.exercise-head { color: var(--muted); font-size: 10px; }
.difficulty { padding: 6px 8px; border-radius: 999px; font-weight: 700; }
.difficulty.easy { color: #23755a; background: #e9f7f1; }
.difficulty.medium { color: #795c16; background: #fff5d9; }
.difficulty.hard { color: #9a4438; background: #fff0ed; }
.exercise-card h3 { margin-bottom: 6px; font-size: 16px; }
.exercise-card p { color: var(--muted); font-size: 11px; }
.exercise-foot { margin-top: 18px; padding-top: 15px; border-top: 1px solid var(--border); color: var(--muted); font-size: 9px; }
.exercise-foot button { border: 0; background: transparent; color: var(--accent-dark); font-weight: 700; font-size: 11px; }

.mode-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.mode-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mode-card { min-height: 392px; padding: 24px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; height: auto; }
.mode-card.featured { border-color: #cad4ff; }
.mode-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mode-icon { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 14px; background: var(--surface-soft); font-family: var(--serif); font-size: 22px; }
.soft-tag { padding: 6px 8px; background: var(--surface-soft); border-radius: 999px; color: var(--muted); font-size: 9px; font-weight: 700; }
.mode-card h3 { margin: 24px 0 8px; font-size: 21px; }
.mode-card p { color: var(--muted); font-size: 12px; }
.clean-list { list-style: none; margin: 7px 0 24px; padding: 0; display: grid; gap: 9px; color: var(--muted); font-size: 11px; }
.clean-list li::before { content: "·"; margin-right: 8px; color: var(--accent); font-weight: 700; }
.mode-card .full { margin-top: auto; }

.intro-banner {
  min-height: 220px;
  border-radius: var(--radius-lg);
  padding: 38px 42px;
  display: grid;
  grid-template-columns: 1fr 300px;
  align-items: center;
  gap: 40px;
  background: linear-gradient(145deg, #162238, #253b65);
  color: #fff;
  box-shadow: var(--shadow);
}
.intro-banner h2 { margin: 0 0 10px; font-size: clamp(26px, 3vw, 36px); letter-spacing: -.04em; }
.intro-banner p { max-width: 680px; margin: 0; color: rgba(255, 255, 255, .7); }
.focus-score { padding: 24px; border: 1px solid rgba(255, 255, 255, .13); border-radius: 16px; background: rgba(255, 255, 255, .06); }
.focus-score > span, .focus-score > strong { display: block; }
.focus-score > span { color: rgba(255, 255, 255, .65); font-size: 11px; }
.focus-score > strong { margin: 8px 0 15px; font-size: 32px; }

/* ================================================================
   Cours
   ================================================================ */

/* Le titre d'un document peut être long : il garde toute la largeur et les
   matières passent en dessous, sinon le titre se coupait au milieu d'un mot. */
.course-toolbar { display: grid; gap: 14px; margin-bottom: 20px; }
.course-toolbar h2 { margin: 16px 0 6px; font-size: 35px; }
.course-toolbar p { margin: 0; color: var(--muted); font-size: 11px; }
.view-switch { display: flex; padding: 4px; background: var(--surface-soft); border-radius: 11px; }
.view-switch button { border: 0; min-height: 36px; padding: 0 13px; border-radius: 8px; background: transparent; color: var(--muted); font-size: 10px; font-weight: 600; }
.view-switch button.active { background: var(--surface); color: var(--text); }

.course-shell { display: grid; grid-template-columns: 245px minmax(0, 1fr); gap: 16px; align-items: start; }
.course-outline { border-radius: var(--radius-md); padding: 20px 14px; border: 1px solid var(--border); background: var(--surface); max-height: 78dvh; overflow-y: auto; }
.course-outline > .eyebrow { padding: 0 8px; margin-bottom: 14px; }
.outline-item {
  width: 100%;
  min-height: 44px;
  border: 0;
  background: transparent;
  padding: 11px 9px;
  border-radius: 10px;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  text-align: left;
  color: var(--muted);
}
.outline-item.active { background: var(--accent-soft); color: var(--accent-dark); }
.outline-item > span { width: 24px; height: 24px; border: 1px solid var(--border); border-radius: 50%; display: grid; place-items: center; font-size: 9px; }
.outline-item.done > span { background: var(--success); border-color: var(--success); color: #fff; }
.outline-item strong, .outline-item small { display: block; }
.outline-item strong { font-size: 10px; line-height: 1.35; }
.outline-item small { margin-top: 3px; font-size: 8px; opacity: .75; }
.outline-progress { margin-top: 16px; padding: 16px 8px 4px; border-top: 1px solid var(--border); }
.outline-progress > span, .outline-progress > strong { display: block; font-size: 9px; }
.outline-progress > span { color: var(--muted); }
.outline-progress > strong { margin: 5px 0 10px; font-size: 16px; }
/* Sommaire des pages : une pastille par page, assez grande pour le doigt. */
.page-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px; }
.page-chip {
  min-height: 44px;
  min-width: 44px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  font-size: 10px;
}
.page-chip.active { border-color: #cad4ff; background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; }

.course-content { border-radius: var(--radius-md); padding: 28px; border: 1px solid var(--border); background: var(--surface); }
.course-block + .course-block { margin-top: 28px; }
.block-label .blk-b.mini { max-width: 340px; }
.block-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .1em;
}
.paper { padding: 44px clamp(28px, 5vw, 64px); border: 1px solid #dfe3eb; border-radius: 12px; background: #fff; }
.paper-top { display: flex; justify-content: space-between; margin-bottom: 38px; color: #9aa3b2; font-size: 8px; text-transform: uppercase; letter-spacing: .08em; }
.paper h3 { margin-bottom: 20px; font-family: var(--serif); font-size: 28px; }
.paper p { color: #3f4b5f; font-family: var(--serif); font-size: 15px; line-height: 1.8; }
/* Le texte extrait d'un PDF garde ses retours à la ligne : les reproduire est
   la seule façon honnête de montrer une page dont la mise en page est perdue. */
.paper-extract {
  margin: 0;
  color: #3f4b5f;
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.course-actions { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--border); }
.theorem-box {
  margin-top: 24px;
  padding: 18px;
  border-left: 3px solid var(--accent);
  background: var(--surface-blue);
  color: #46536a;
  font-family: var(--serif);
  font-size: 13px;
  line-height: 1.7;
}

/* ================================================================
   Compétences : graphe de prérequis
   ================================================================ */

.skills-toolbar { display: grid; gap: 14px; margin-top: 24px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: inherit;
  font-size: 12px;
}
.chip.active { border-color: #cad4ff; background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; }
.chip small { color: var(--muted); font-size: 10px; }
.chip.active small { color: var(--accent-dark); }
.legend-entry { display: flex; align-items: center; gap: 7px; }
.graph-shell {
  position: relative;
  margin-top: 20px;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: linear-gradient(180deg, #fbfcff, #f8f9fd);
  overflow: auto;
}
/* Le graphe est une suite de colonnes : une notion se place après tous ses
   prérequis. Les liens sont tracés après mesure des boîtes, donc aucune
   coordonnée n'est devinée et rien ne peut sortir du cadre. */
.graph-canvas {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 34px;
  padding: 26px;
  width: max-content;
  min-width: 100%;
}
.graph-column { display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.skill-links { position: absolute; inset: 0; z-index: 1; overflow: visible; }
.skill-links path { fill: none; stroke: #ccd5ea; stroke-width: 2.5; }
.skill-links path.advised { stroke-dasharray: 5 5; stroke: #d9d2ea; }
.skill-node {
  position: relative;
  z-index: 2;
  display: block;
  width: 176px;
  min-height: 44px;
  padding: 12px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 6px 16px rgba(15, 23, 42, .05);
  text-align: left;
}
.skill-node strong, .skill-node .status-word, .skill-node small { display: block; }
.skill-node strong { font-size: 12px; line-height: 1.3; }
.skill-node .status-word { margin-top: 5px; font-size: 11px; font-weight: 800; }
.skill-node small { margin-top: 4px; font-size: 9px; color: var(--muted); line-height: 1.35; }
.skill-node.mastered { border-color: #b8decf; background: #f3fbf7; }
.skill-node.mastered .status-word { color: #23755a; }
.skill-node.consolidating { border-color: #c7d4ff; background: #eef2ff; }
.skill-node.consolidating .status-word { color: var(--accent-dark); }
.skill-node.learning { border-color: #ffe3bf; background: #fff8ef; }
.skill-node.learning .status-word { color: #8a5a12; }
.skill-node.review-due { border-color: #f0dca6; background: #fffbee; }
.skill-node.review-due .status-word { color: #795c16; }
.skill-node.available { border-color: #cdd6e6; background: #fbfcff; }
.skill-node.available .status-word { color: #4d5f80; }
.skill-node.locked { opacity: .62; }
.skill-node.locked .status-word { color: #7b8497; }
.skill-node:not(:disabled):active { box-shadow: 0 0 0 5px rgba(49, 87, 213, .14); }

.explain-panels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.mini-panel { padding: 20px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); height: auto; }
.mini-panel h3 { margin: 0 0 8px; font-size: 16px; }
.mini-panel p { margin: 0; color: var(--muted); font-size: 12px; }

/* ================================================================
   Progression
   ================================================================ */

.progress-hero { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); padding: 42px; box-shadow: var(--shadow); }
.progress-hero-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 28px; }
.mini-stat { padding: 20px; border-radius: 14px; background: var(--surface-soft); border: 1px solid var(--border); height: auto; }
.mini-stat > span, .mini-stat > strong { display: block; }
.mini-stat > span { color: var(--muted); font-size: 10px; }
.mini-stat > strong { margin-top: 8px; font-size: 26px; }
.mini-stat small { display: block; margin-top: 6px; color: var(--muted); font-size: 9px; line-height: 1.5; }

/* Les panneaux gardent leur hauteur naturelle : étirés, un bloc marqué
   deviendrait une grande zone vide. */
.dashboard-grid { display: grid; grid-template-columns: 1.35fr 1fr 1fr; gap: 14px; align-items: start; }
.dashboard-grid.lower { grid-template-columns: repeat(3, 1fr); }
/* Page Révision : les formats de séance que Nabla ne sait pas tenir
   restent visibles, côte à côte, chacun avec sa raison. */
.revision-readiness { margin-top: 16px; }
.revision-readiness > span { font-size: 11px; color: var(--muted); }
.revision-formats { margin-top: 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.revision-format { padding: 16px; border-radius: 12px; background: var(--surface-soft); display: grid; gap: 10px; align-content: start; }
.revision-format strong { font-size: 13px; }
.revision-format button { min-height: 44px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: inherit; font-size: 11px; }
.panel { padding: 22px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface); height: auto; }
.panel-head h3 { margin: 2px 0 0; font-size: 20px; letter-spacing: -.02em; }
.insight-list, .stack-list { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 12px; }
.insight-list li, .stack-list li { padding: 14px; border-radius: 12px; background: var(--surface-soft); }
.insight-list strong, .insight-list span, .stack-list strong, .stack-list span { display: block; }
.insight-list strong, .stack-list strong { font-size: 12px; }
.insight-list span, .stack-list span { margin-top: 5px; color: var(--muted); font-size: 10px; }

.mastery-table { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.table-row { display: grid; grid-template-columns: 1.2fr 1fr 120px 150px; gap: 18px; align-items: center; padding: 18px 20px; }
.table-row + .table-row { border-top: 1px solid var(--border); }
.table-head { background: #fafbfe; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.table-chapter strong, .table-chapter small { display: block; }
.table-chapter strong { font-size: 13px; }
.table-chapter small { margin-top: 5px; color: var(--muted); font-size: 10px; }
.table-progress { display: grid; grid-template-columns: 48px minmax(0, 1fr); align-items: center; gap: 12px; }
.table-progress span { font-size: 12px; font-weight: 700; }
.status-pill { display: inline-flex; justify-content: center; padding: 7px 10px; border-radius: 999px; font-size: 10px; font-weight: 700; }
.status-pill.success { background: #e9f7f1; color: #23755a; }
.status-pill.warn { background: #fff5d9; color: #795c16; }
.status-pill.mid { background: var(--accent-soft); color: var(--accent-dark); }
.status-pill.danger { background: #eef0f4; color: #5c6779; }
/* Les pastilles portent le vocabulaire du serveur, pour qu'aucune traduction
   intermédiaire ne puisse dériver. */
.status-pill.mastered { background: #e9f7f1; color: #23755a; }
.status-pill.consolidating { background: var(--accent-soft); color: var(--accent-dark); }
.status-pill.learning { background: #fff5d9; color: #795c16; }
.status-pill.review-due { background: #fffbee; color: #795c16; }
.status-pill.available { background: #eef2f8; color: #4d5f80; }
.status-pill.locked { background: #eef0f4; color: #5c6779; }
/* Une ligne de tableau cliquable est un bouton : sans largeur imposée elle se
   réduirait à son contenu et la grille se désalignerait. */
.table-row.row-tappable { width: 100%; min-height: 44px; border: 0; background: transparent; color: inherit; text-align: left; font: inherit; }
.summary-box { margin-top: 18px; padding: 18px; border-radius: 12px; background: var(--surface-soft); }
.summary-box p { color: #46536a; font-size: 12px; }

/* ================================================================
   Séquence d'étude : chargement, appairage, préparation
   ================================================================ */

.loading-screen { display: flex; flex-direction: column; align-items: center; padding-top: 48px; gap: 16px; }
.loading-text { color: var(--muted); font-size: 0.95rem; }

.pairing-screen { display: flex; flex-direction: column; align-items: center; padding-top: 24px; gap: 12px; }
.pairing-intro { color: var(--muted); font-size: 0.95rem; text-align: center; max-width: 400px; margin: 8px 0 12px; }
.pairing-form { display: flex; flex-direction: column; width: 100%; max-width: 360px; gap: 8px; }
.pairing-label { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.pairing-input {
  font-size: 1.1rem;
  padding: 14px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.pairing-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.pairing-input::placeholder { color: #a4adbc; }
.pairing-button {
  min-height: 52px;
  margin-top: 8px;
  border: none;
  border-radius: 12px;
  background: var(--text);
  color: #fff;
  font-size: 1.02rem;
  font-weight: 600;
  cursor: pointer;
}
.pairing-button:active { transform: translateY(1px); }
.pairing-button:disabled { opacity: .5; cursor: default; }
.pairing-error {
  color: #8e2019;
  background: var(--miss-soft);
  border: 1px solid var(--miss);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  max-width: 360px;
}
/* An alert with nothing to say must not paint an empty red box. */
.pairing-error:empty { display: none; }

.preparing-screen { display: flex; flex-direction: column; align-items: center; padding-top: 48px; gap: 14px; text-align: center; }
.preparing-title { font-size: 1.25rem; font-weight: 700; }
.preparing-phase { color: var(--muted); font-size: 0.95rem; }
.preparing-elapsed { color: #a4adbc; font-size: 0.85rem; }

/* ================================================================
   Énoncé et indices
   ================================================================ */

.exercise-title { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.exercise-meta { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: 0.9rem; margin: 6px 0 16px; }
.meta-stars { color: var(--accent-dark); font-weight: 700; }
.statement {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.rich-text > * + * { margin-top: 12px; }
.rich-heading { font-size: 1.05rem; font-weight: 700; }
.rich-text h5.rich-heading { font-size: 0.98rem; color: var(--muted); }
.rich-list { padding-left: 22px; }
.rich-list li { margin-top: 6px; }
.rich-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px 6px;
}
/* Une formule large défile horizontalement ; les fractions dépassent de
   quelques pixels en hauteur, d'où la marge intérieure verticale : sans elle
   le navigateur ajoute une barre de défilement verticale par-dessus la
   formule. */
.math-display { margin: 14px 0; padding: 8px 0; text-align: center; overflow-x: auto; overflow-y: hidden; }
.math-fallback {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
  color: var(--muted);
}
.katex { font-size: 1.05em; }
.katex-display { margin: 0; }
.math-inline .katex { font-size: 1em; }

.hint-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.hint {
  padding: 14px 16px 14px 44px;
  position: relative;
  border: 1px solid #dce4ff;
  border-radius: var(--radius-sm);
  background: var(--surface-blue);
  font-size: 0.98rem;
}
.hint::before {
  content: "?";
  position: absolute;
  left: 14px;
  top: 13px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}
.hint-error { color: #8e2019; font-size: 0.92rem; margin-top: 8px; }

/* ================================================================
   Copie manuscrite
   Les propriétés de structure de cette section commandent le stylet :
   ne rien y changer sans repasser par une validation sur l'iPad.
   ================================================================ */

.notebook {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Écrire à la main demande plus de largeur que lire un énoncé : la copie
     déborde de la colonne de lecture jusqu'aux bords de l'écran. */
  --notebook-bleed: max(0px, (100vw - 48px - 680px) / 2);
  margin-inline: calc(-1 * var(--notebook-bleed));
}

.notebook-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.notebook-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-button {
  min-height: 44px;
  min-width: 88px;
  padding: 10px 16px;
  font: inherit;
  font-size: 0.98rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.tool-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.tool-button.is-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.notebook-status {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.notebook-status[data-state="saved"] { color: var(--success); }
.notebook-status[data-state="failed"] { color: var(--danger); }

.notebook-notice {
  margin: 0;
  padding: 10px 12px;
  font-size: 0.94rem;
  color: #7d4b00;
  background: var(--hold-soft);
  border: 1px solid #e6c99a;
  border-radius: 8px;
}

.notebook-pages {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.notebook-page {
  position: relative;
}

.notebook-canvas {
  display: block;
  width: 100%;
  /* Format A4 : la page garde ses proportions quelle que soit la largeur. */
  aspect-ratio: 1000 / 1414;
  height: auto;
  background: #ffffff;
  border-radius: 4px;
  box-shadow: 0 2px 14px rgba(25, 38, 70, 0.12);
  /* Le doigt fait défiler la copie, le stylet écrit. */
  touch-action: pan-y;
}

.notebook-page-number {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: 0.85rem;
  color: #a4adbc;
}

.notebook-footer {
  display: flex;
  justify-content: center;
  max-width: 420px;
  margin: 0 auto;
  padding-bottom: 24px;
}
.notebook-footer .secondary-button { flex: 1; }

/* ---- rendre la copie ---- */
.notebook-submit {
  max-width: 420px;
  margin: 0 auto;
  padding-bottom: 48px;
}
.notebook-confirm-question {
  color: var(--text);
  text-align: center;
}
.notebook-confirm {
  display: flex;
  gap: 12px;
}
.notebook-confirm .primary-button,
.notebook-confirm .secondary-button {
  flex: 1;
}

/* ================================================================
   Correction
   ================================================================ */

.correction-screen { padding-bottom: 8px; }
.verdict-card { text-align: left; }
.verdict {
  display: inline-block;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 7px 14px;
  border-radius: 999px;
}
.verdict-correct { color: #23755a; background: #e9f7f1; }
.verdict-partial { color: #795c16; background: #fff5d9; }
.verdict-incorrect { color: #9a4438; background: #fff0ed; }
.verdict-uncertain { color: #4d5f80; background: var(--surface-soft); }

.score-row { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.score-label { display: flex; justify-content: space-between; font-size: 0.92rem; color: var(--muted); }
.score-value { font-weight: 700; color: var(--text); }
.score-track { height: 8px; border-radius: 999px; background: var(--surface-soft); overflow: hidden; }
.score-fill { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

.observation-list { display: flex; flex-direction: column; }
.observation + .observation { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 12px; }
.observation-labels { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.observation-category { font-size: 0.82rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.severity-blocking { color: #9a4438; font-weight: 700; }
.severity-major { color: #795c16; font-weight: 700; }
.severity-minor { color: var(--muted); }

.doubt-card { border-left: 4px solid var(--warn); }

.concept-list { display: flex; flex-direction: column; gap: 10px; }
.concept {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.concept-locked { opacity: .72; }
.concept-name { font-size: 1rem; font-weight: 600; }
.concept-reason { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }
.concept-open { border: none; background: transparent; color: var(--accent-dark); font-weight: 700; cursor: pointer; min-height: 44px; }
.concept-open:active { opacity: .7; }
.concept-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.concept-state-line { display: flex; align-items: center; gap: 10px; }
.concept-state-reason { color: var(--muted); font-size: 0.92rem; margin-top: 6px; }

/* ================================================================
   Adaptations d'écran
   ================================================================ */

@media (max-width: 1200px) {
  .mode-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid.lower { grid-template-columns: 1fr 1fr; }
  .panel.large { grid-column: 1 / -1; }
  .explain-panels { grid-template-columns: 1fr; }
}

@media (max-width: 1040px) {
  .app-shell { grid-template-columns: 82px minmax(0, 1fr); }
  .sidebar { padding-left: 12px; padding-right: 12px; }
  .brand { justify-content: center; padding-left: 0; padding-right: 0; }
  .brand > div:last-child, .nav-item > span:last-child, .mini-profile > div:last-child { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .mini-profile { justify-content: center; padding-left: 0; padding-right: 0; }
  /* La barre repliée est trop étroite pour la phrase : la marque devient un
     glyphe, la raison reste dans l'infobulle et revient en entier dès que la
     barre se déplie. Sans cela le mot « INDISPONIBLE » était tronqué. */
  .sidebar-footer .blk-b.mini::after { display: none; }
  .sidebar-footer .blk-b.mini .badge-b { font-size: 0; letter-spacing: 0; padding: 3px 0; }
  .sidebar-footer .blk-b.mini .badge-b::before { content: "⊘"; font-size: 11px; letter-spacing: 0; }
  .hero-card, .training-reco { grid-template-columns: 1fr; }
  .math-panel { min-height: 260px; }
  .reco-summary { border-left: 0; border-top: 1px solid #dde5ff; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-actions { grid-template-columns: 1fr; }
  .course-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .progress-hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .intro-banner { grid-template-columns: 1fr; }
  .training-layout { grid-template-columns: 1fr; }
  .course-shell { grid-template-columns: 1fr; }
  .table-row { grid-template-columns: 1fr; }
  .table-head { display: none; }
  .dashboard-grid, .dashboard-grid.lower { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav { grid-template-columns: repeat(3, 1fr); }
  .main { padding: 26px 18px 60px; }
  .topbar { flex-direction: column; }
  .hero-copy, .training-copy, .progress-hero { padding: 28px 22px; }
  .math-panel { padding: 24px; }
  .stats-grid, .progress-hero-stats, .mode-grid.four { grid-template-columns: 1fr; }
  .progress-card { padding: 0 18px; }
  .progress-row { grid-template-columns: 1fr; gap: 14px; }
  .intro-banner { padding: 28px 22px; }
  .course-content { padding: 18px; }
  .paper { padding: 30px 22px; }
  .course-actions { flex-direction: column-reverse; }
}
