/* ------------------------------------------------------------------ *
 * Tokens — design system « Repère » v0.1.0 (assets/design-tokens.json)
 * Les composants n'utilisent que les rôles ; le thème est un changement
 * de correspondance. pt (mobile) → px (web), 1 pt = 1 px.
 * ------------------------------------------------------------------ */
:root {
  --canvas: #F7F7F5;
  --surface: #FFFFFF;
  --surface-pressed: #F2F1EF;
  --exam: #FFFFFF;
  --text-primary: #1C1B19;
  --text-secondary: #57534E;
  --text-tertiary: #726C66; /* UX/UI 29/10 : le défaut est la CLASSE, pas l'instance. #78716C échouait sur canvas (4,47) ET stone-100 (4,25) ET primary-pale (4,24) ; #767069 corrigeait le canvas mais échouait encore sur stone-100 (4,33) et primary-pale (4,32). #726C66 est le plus petit assombrissement qui passe sur les QUATRE surfaces : 4,83 / 5,18 / 4,59 / 4,58. */
  --text-on-primary: #FFFFFF;
  --link: #4338CA;
  --border-interactive: #8A8580;
  --border-subtle: #E7E5E4;
  --action-primary-bg: #4338CA;
  --action-primary-bg-pressed: #3730A3;
  --action-secondary-border: #4338CA;
  --action-selected-bg: #E0E7FF;
  --primary: #4338CA;
  --primary-dark: #3730A3;
  --primary-light: #E0E7FF;
  --primary-pale: #EEF0FF;
  --primary-soft: #E0E7FF;
  --success-strong: #15803D;
  --success-soft: #ECFDF3;
  --success-on-soft: #14532D;
  --error-strong: #B42318;
  --error-soft: #FEF1F0;
  --error-on-soft: #7A1A12;
  --warning-strong: #92400E;
  --warning-soft: #FFF4D6;
  --warning-on-soft: #5C3A00;
  --info-strong: #1D4ED8;
  --info-soft: #EAF1FF;
  --info-on-soft: #1E3A8A;
  --saffron: #F5A524;
  --saffron-ink: #3B2A00;
  --saffron-soft: #FFF4D6;
  --stone-100: #F2F1EF;
  --stone-200: #E7E5E4;
  --stone-300: #D6D3D1;
  --stone-500: #726C66; /* même correction que --text-tertiary ; le jeton source du design system porte encore #78716C */
  --focus-ring: #4338CA;
  --shadow-1: 0 1px 3px rgba(28,27,25,.08);
  --shadow-2: 0 -2px 12px rgba(28,27,25,.10);
  --shadow-3: 0 -8px 24px rgba(28,27,25,.16);
  --veil: rgba(28,27,25,.40);
  --theme-1: #4338CA;
  --theme-2: #0E7490;
  --theme-3: #7C3AED;
  --theme-4: #B45309;
  --theme-5: #BE185D;
}
html[data-appearance="dark"] {
  --canvas: #121110;
  --surface: #1F1E1C;
  --surface-pressed: #2A2926;
  --exam: #1F1E1C;
  --text-primary: #F2F1EF;
  --text-secondary: #B8B3AD;
  --text-tertiary: #948F89; /* le défaut est la CLASSE, pas le thème : #8C8781 échouait sur stone-100 (4,09) et primary-pale (4,25) du sombre. #948F89 est le plus petit éclaircissement qui passe sur les quatre : 5,88 / 5,19 / 4,54 / 4,72. */
  --text-on-primary: #121110;
  --link: #A5B4FC;
  --border-interactive: #8C8781;
  --border-subtle: #34322F;
  --action-primary-bg: #A5B4FC;
  --action-primary-bg-pressed: #C7D2FE;
  --action-secondary-border: #A5B4FC;
  --action-selected-bg: #2E2A66;
  --primary: #A5B4FC;
  --primary-dark: #C7D2FE;
  --primary-light: #2E2A66;
  --primary-pale: #23214A;
  --primary-soft: #2E2A66;
  --success-strong: #4ADE80;
  --success-soft: #0F2A1A;
  --success-on-soft: #86EFAC;
  --error-strong: #FCA5A5;
  --error-soft: #3A1512;
  --error-on-soft: #FECACA;
  --warning-strong: #FCD34D;
  --warning-soft: #33270A;
  --warning-on-soft: #FDE68A;
  --info-strong: #93C5FD;
  --info-soft: #13213F;
  --info-on-soft: #BFDBFE;
  --saffron: #F5A524;
  --saffron-ink: #121110;
  --saffron-soft: #33270A;
  --stone-100: #2A2926;
  --stone-200: #34322F;
  --stone-300: #454340;
  --stone-500: #948F89; /* même correction que --text-tertiary */
  --focus-ring: #A5B4FC;
  --shadow-1: 0 1px 3px rgba(0,0,0,.5);
  --shadow-2: 0 -2px 12px rgba(0,0,0,.5);
  --shadow-3: 0 -8px 24px rgba(0,0,0,.6);
  --veil: rgba(0,0,0,.55);
}

/* ---------------------------- base ---------------------------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--canvas);
  color: var(--text-primary);
  font-family: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 24px;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* Colonne téléphone : sur ordinateur l'app garde la forme d'un téléphone.
   La colonne a la hauteur de la fenêtre ; c'est la zone de lecture qui défile,
   pas la page — sinon la barre d'onglets chevauche le contenu. */
#root { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.phone {
  flex: 1; min-height: 0;
  width: 100%; max-width: 640px;
  margin: 0 auto;
  background: var(--canvas);
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Bandeau d'aperçu (dev only — n'existe pas dans le build réel). */
.devbar {
  background: var(--warning-soft);
  color: var(--warning-on-soft);
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 16px;
  font-size: 13px;
  line-height: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.devbar strong { font-weight: 600; }
.devbar button {
  background: transparent; border: 1px solid currentColor; border-radius: 999px;
  padding: 2px 10px; font-size: 12px; cursor: pointer;
}
.devbar button[aria-pressed="true"] { background: var(--warning-on-soft); color: var(--warning-soft); }

/* ---------------------------- type ---------------------------- */
.t-display { font-size: 34px; line-height: 42px; font-weight: 700; letter-spacing: -.5px; }
.t-h1 { font-size: 28px; line-height: 36px; font-weight: 700; letter-spacing: -.3px; margin: 0; }
.t-h2 { font-size: 22px; line-height: 30px; font-weight: 700; margin: 0; }
.t-h3 { font-size: 20px; line-height: 28px; font-weight: 600; margin: 0; }
.t-h4 { font-size: 18px; line-height: 26px; font-weight: 600; margin: 0; }
.t-h5 { font-size: 16px; line-height: 24px; font-weight: 600; margin: 0; }
.t-question { font-size: 20px; line-height: 30px; font-weight: 500; margin: 0; }
.t-option { font-size: 18px; line-height: 26px; font-weight: 500; }
.t-body-lg { font-size: 18px; line-height: 28px; margin: 0; }
.t-body { font-size: 16px; line-height: 24px; margin: 0; }
.t-body-sm { font-size: 14px; line-height: 20px; margin: 0; }
.t-caption { font-size: 13px; line-height: 18px; font-weight: 500; letter-spacing: .1px; }
.t-label { font-size: 14px; line-height: 20px; font-weight: 600; letter-spacing: .1px; }
.t-button { font-size: 17px; line-height: 24px; font-weight: 600; }
.t-timer { font-family: "Atkinson Hyperlegible Mono", ui-monospace, SFMono-Regular, monospace; font-size: 20px; line-height: 24px; font-weight: 500; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-secondary); }
.tertiary { color: var(--text-tertiary); }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------------------------- layout ---------------------------- */
.screen { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.scroll { flex: 1; overflow-y: auto; padding: 20px; }
.scroll.tight { padding: 20px 20px 12px; }
.actionbar {
  flex: 0 0 auto; background: var(--canvas);
  border-top: 1px solid var(--border-subtle);
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow-2);
}
.actionbar.plain { border-top: none; box-shadow: none; background: transparent; }
.stack { display: flex; flex-direction: column; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.gap-4 { gap: 16px; } .gap-6 { gap: 24px; } .gap-8 { gap: 32px; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.gap-2 { gap: 8px; } .row.gap-3 { gap: 12px; }

/* ---------------------------- header ---------------------------- */
.appbar {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 8px 12px;
  background: var(--canvas); position: sticky; top: 0; z-index: 5;
}
.appbar .title { flex: 1; text-align: center; }
.iconbtn {
  width: 44px; height: 44px; border-radius: 999px; border: none; background: transparent;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; cursor: pointer; color: var(--text-secondary);
}
.iconbtn:hover { background: var(--surface-pressed); }
.progressbar { height: 6px; background: var(--stone-200); border-radius: 999px; overflow: hidden; }
.progressbar > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width 240ms cubic-bezier(0,0,.2,1); }

/* ---------------------------- cards ---------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border-subtle);
  border-radius: 16px; padding: 20px;
}
.card.hero { background: var(--primary-light); border-color: transparent; box-shadow: var(--shadow-1); }
.card.done { background: var(--surface); border: 1px solid var(--success-strong); }
.card.tappable { cursor: pointer; text-align: left; width: 100%; }
.card.tappable:hover { background: var(--surface-pressed); }
.card.recommended { border: 2px solid var(--saffron); background: var(--saffron-soft); }

/* ---------------------------- buttons ---------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 12px; cursor: pointer; border: 1.5px solid transparent;
  padding: 0 24px; min-height: 56px; width: 100%;
  background: var(--action-primary-bg); color: var(--text-on-primary);
  font-size: 17px; line-height: 24px; font-weight: 600;
  transition: background 120ms, transform 120ms;
}
.btn:hover { background: var(--action-primary-bg-pressed); }
.btn:active { transform: scale(.98); }
.btn.secondary { background: transparent; color: var(--link); border-color: var(--action-secondary-border); }
.btn.secondary:hover { background: var(--primary-pale); }
.btn.tertiary { background: transparent; color: var(--link); border: none; min-height: 48px; padding: 0 12px; }
.btn.tertiary:hover { background: var(--primary-pale); text-decoration: underline; }
.btn.destructive { background: var(--error-strong); color: #fff; }
.btn.destructive-quiet { background: transparent; color: var(--error-strong); border: none; min-height: 48px; }
.btn.m { min-height: 48px; font-size: 15px; }
.btn.s { min-height: 44px; font-size: 14px; padding: 0 16px; width: auto; }
.btn:disabled { background: var(--stone-200); color: var(--stone-500); cursor: not-allowed; border-color: transparent; }
.btn:disabled:hover { background: var(--stone-200); }
.btn:disabled:active { transform: none; }

/* ---------------------------- badges ---------------------------- */
.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 24px; padding: 0 8px; border-radius: 8px;
  background: var(--stone-100); color: var(--text-secondary);
  font-size: 13px; line-height: 18px; font-weight: 500;
}
.badge .dot { width: 8px; height: 8px; border-radius: 999px; }
.badge.review { background: var(--primary-pale); color: var(--primary); }
.badge.recommended { background: var(--saffron); color: var(--saffron-ink); }
.badge.demo { background: var(--warning-soft); color: var(--warning-on-soft); }

/* Contrôle de réglage (pastille de niveau) — délibérément PAS un badge :
   une commande qui a la forme d'un statut se lit comme un statut. Cible 48,
   bord subtil, chevron après le texte (les tuiles enseignent déjà « Continuer → »). */
.chip-control {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 48px; min-width: 48px; padding: 8px 12px;
  /* `--border-subtle` ne fait que 1,26:1 sur surface — sous le 3:1 qu'exige la
     frontière d'un contrôle (WCAG 1.4.11). `--border-interactive` #8A8580 :
     3,65:1 sur blanc, 3,41:1 sur le canvas. Trouvaille UX/UI, mesurée. */
  border: 1px solid var(--border-interactive); border-radius: 999px;
  background: var(--surface); color: var(--text-primary);
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip-control:hover { background: var(--surface-pressed); }

/* ---------------------------- banners ---------------------------- */
.banner { display: flex; gap: 8px; border-radius: 12px; padding: 12px 16px; font-size: 14px; line-height: 20px; }
.banner.info { background: var(--info-soft); color: var(--info-on-soft); }
.banner.warning { background: var(--warning-soft); color: var(--warning-on-soft); }
.banner.neutral { background: var(--stone-100); color: var(--text-secondary); }

/* ---------------------------- options ---------------------------- */
.options { display: flex; flex-direction: column; gap: 12px; }
.option {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left;
  min-height: 64px; padding: 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border-interactive);
  cursor: pointer; transition: background 120ms, border-color 120ms;
}
.option:hover { background: var(--primary-pale); }
.option .letter {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 999px;
  border: 1.5px solid var(--border-interactive); color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
}
.option .otext { flex: 1; }
.option .ostate { font-size: 13px; line-height: 18px; font-weight: 500; margin-top: 4px; display: block; }
.option.chosen-correct { background: var(--success-soft); border: 2px solid var(--success-strong); }
.option.chosen-correct .letter { background: var(--success-strong); border-color: var(--success-strong); color: #fff; }
.option.chosen-correct .ostate { color: var(--success-on-soft); }
.option.chosen-incorrect { background: var(--error-soft); border: 2px solid var(--error-strong); }
.option.chosen-incorrect .letter { background: var(--error-strong); border-color: var(--error-strong); color: #fff; }
.option.chosen-incorrect .ostate { color: var(--error-on-soft); }
.option.correct-not-chosen { background: var(--success-soft); border: 2px dashed var(--success-strong); }
.option.correct-not-chosen .letter { background: var(--success-strong); border-color: var(--success-strong); color: #fff; }
.option.correct-not-chosen .ostate { color: var(--success-on-soft); }
.option.inert { background: var(--surface); border: 1px solid var(--border-subtle); cursor: default; }
.option.inert .letter { color: var(--text-tertiary); }
.option.inert:hover { background: var(--surface); }
.option.selected { background: var(--action-selected-bg); border: 2px solid var(--primary); }
.option.selected .letter { background: var(--primary); border-color: var(--primary); color: var(--text-on-primary); }

/* ---------------------------- tiles (thèmes) ---------------------------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border-subtle);
  border-radius: 16px; padding: 16px; cursor: pointer; text-align: left;
  min-height: 96px;
}
.tile:hover { background: var(--surface-pressed); }
.tile.wide { grid-column: 1 / -1; }
.tile.recommended { border: 2px solid var(--saffron); background: var(--saffron-soft); }
.tile .tname { font-size: 18px; line-height: 26px; font-weight: 600; }
.tile .tstate { margin-top: auto; color: var(--link); font-size: 14px; font-weight: 600; }

/* ---------------------------- ring ---------------------------- */
.ring { flex: 0 0 auto; position: relative; width: 56px; height: 56px; }
.ring svg { transform: rotate(-90deg); }
.ring .val { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 600; }

/* ---------------------------- sheets & dialogs ---------------------------- */
.veil { position: fixed; inset: 0; background: var(--veil); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet {
  background: var(--surface); width: 100%; max-width: 640px;
  border-radius: 24px 24px 0 0; padding: 24px;
  box-shadow: var(--shadow-3); max-height: 90dvh; overflow-y: auto;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}
.sheet .handle { width: 36px; height: 5px; border-radius: 999px; background: var(--stone-300); margin: 0 auto 16px; }
.dialog {
  background: var(--surface); border-radius: 16px; padding: 24px;
  width: min(100% - 48px, 420px); box-shadow: var(--shadow-3); margin: auto;
}
.veil.center { align-items: center; }

/* ---------------------------- exam grid ---------------------------- */
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.gcell {
  position: relative; aspect-ratio: 1 / 1; border-radius: 8px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border-interactive);
  color: var(--text-primary); font-weight: 600; font-size: 15px;
}
.gcell.answered { background: var(--primary); border-color: var(--primary); color: var(--text-on-primary); }
.gcell.current { outline: 2px solid var(--text-primary); outline-offset: 2px; }
.gcell .flag { position: absolute; top: 2px; right: 4px; font-size: 11px; color: var(--saffron); }
.gcell.answered .flag { color: var(--saffron-soft); }

/* ---------------------------- misc ---------------------------- */
.timerchip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; }
.timerchip.warn { background: var(--warning-soft); color: var(--warning-on-soft); }
.timerchip.danger { background: var(--error-soft); color: var(--error-on-soft); }
.thmline { display: flex; align-items: center; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border-subtle); }
.thmline:last-child { border-bottom: none; }
.thmline .dot { width: 8px; height: 8px; border-radius: 999px; flex: 0 0 auto; }
.thmline .n { margin-left: auto; font-variant-numeric: tabular-nums; }
.verdict-win { background: linear-gradient(135deg, #4338CA, #6D5DF5); color: #fff; border-radius: 16px; padding: 24px; }
.verdict-win .t-h1, .verdict-win .t-display { color: #fff; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 8px; top: 8px; z-index: 99; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
