/* =====================================================================
   Lalek Learn – système de design
   « Stylo et surligneur » : encre bleue de stylo-bille sur papier blanc,
   stylo rouge pour les erreurs, surligneur jaune en signature (logo, chiffre
   du jour, réussite). Atkinson Hyperlegible Next pour lire les questions sans
   ambiguïté (1/l/I, 0/O), Bricolage Grotesque pour les titres et les chiffres.
   ===================================================================== */

@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  src: url('../fonts/atkinson-next.woff') format('woff');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  src: url('../fonts/atkinson-next-italic.woff') format('woff');
  font-weight: 200 800;
  font-style: italic;
  font-display: swap;
}
/* Chiffres de l'interface : ceux de Bricolage (zéro sans barre). Les questions gardent Atkinson pur. */
@font-face {
  font-family: 'LL Chiffres';
  src: url('../fonts/bricolage-digits.woff') format('woff');
  font-weight: 300 800;
  unicode-range: U+0030-0039;
  font-display: swap;
}
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('../fonts/bricolage.woff') format('woff');
  font-weight: 500 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #F5F6F8;
  --bg-elev: #FAFBFC;
  --surface: #FFFFFF;
  --surface-2: #F7F8FA;
  --surface-3: #EDEFF4;
  --ink: #121A2E;
  --text: #283048;
  --muted: #5D667D;
  --faint: #97A0B3;
  --line: #E3E6ED;
  --line-strong: #CDD2DD;
  --brand: #2446D8;
  --brand-strong: #172F9E;
  --brand-soft: #E8EDFD;
  --brand-tint: #F3F6FF;
  --on-brand: #FFFFFF;
  --hl: #FFE04B;
  --hl-soft: #FFF5BF;
  --hl-ink: #4A3D00;
  --eosin: #CF3F7A;
  --eosin-soft: #FCEAF2;
  --good: #128A5D;
  --good-soft: #E2F4EC;
  --good-line: #9ED8BE;
  --bad: #D1352D;
  --bad-soft: #FDEBE9;
  --bad-line: #F2B2AD;
  --warn: #A86500;
  --warn-soft: #FFF2DB;
  --warn-line: #EBCB8E;
  /* Rampe de maîtrise (séquentielle, une teinte : clair → foncé) */
  --m-new: #DDE1EA;
  --m-learning: #B9C6F6;
  --m-consolidating: #6F89EC;
  --m-mastered: #1D3AC0;
  --m-weak: #E5776D;
  --hero-bg: #2446D8;

  --nav-bg: rgba(245, 246, 248, 0.8);
  --bar-bg: rgba(255, 255, 255, 0.82);
  --scrim: rgba(12, 18, 40, 0.36);
  --shadow-1: 0 1px 2px rgba(18, 26, 46, 0.05), 0 0 0 1px rgba(18, 26, 46, 0.04);
  --shadow-2: 0 2px 6px rgba(18, 26, 46, 0.06), 0 12px 32px -8px rgba(18, 26, 46, 0.14);
  --shadow-3: 0 24px 64px -12px rgba(18, 26, 46, 0.3), 0 0 0 1px rgba(18, 26, 46, 0.05);

  --font-ui: 'LL Chiffres', 'Atkinson Hyperlegible Next', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-read: 'Atkinson Hyperlegible Next', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-display: 'Bricolage Grotesque', 'Atkinson Hyperlegible Next', -apple-system, system-ui, sans-serif;

  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --gutter: 20px;
  --tabbar-h: 58px;
  --navbar-h: 48px;
  --sidebar-w: 268px;
  --content-max: 760px;
  --stem-size: 20px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-1: 140ms;
  --dur-2: 240ms;
  --dur-3: 420ms;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0B0F1A;
    --bg-elev: #0F1420;
    --surface: #151B29;
    --surface-2: #1A2132;
    --surface-3: #232B3F;
    --ink: #F2F4F8;
    --text: #D4D9E4;
    --muted: #98A1B5;
    --faint: #677089;
    --line: #242C3E;
    --line-strong: #343E56;
    --brand: #7F9CFF;
    --brand-strong: #B8C8FF;
    --brand-soft: #1C2752;
    --brand-tint: #151D3A;
    --on-brand: #0B0F1A;
    --hl: #FFE04B;
    --hl-soft: #3A3313;
    --hl-ink: #1A1500;
    --eosin: #F07CA9;
    --eosin-soft: #3A1B2B;
    --good: #3FC98E;
    --good-soft: #10302A;
    --good-line: #23674D;
    --bad: #FF7B70;
    --bad-soft: #3A1A1C;
    --bad-line: #7C3833;
    --warn: #F2B54F;
    --warn-soft: #352914;
    --warn-line: #6E5422;
    --m-new: #263049;
    --m-learning: #34509E;
    --m-consolidating: #6584F2;
    --m-mastered: #B4C5FF;
    --m-weak: #E9776C;
    --hero-bg: #172A8C;
    --nav-bg: rgba(11, 15, 26, 0.76);
    --bar-bg: rgba(21, 27, 41, 0.8);
    --scrim: rgba(0, 0, 0, 0.56);
    --shadow-1: 0 0 0 1px rgba(255, 255, 255, 0.05);
    --shadow-2: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 16px 40px -10px rgba(0, 0, 0, 0.6);
    --shadow-3: 0 0 0 1px rgba(255, 255, 255, 0.07), 0 28px 72px -12px rgba(0, 0, 0, 0.75);
    color-scheme: dark;
}
}
:root[data-theme='dark'] {
  --bg: #0B0F1A;
  --bg-elev: #0F1420;
  --surface: #151B29;
  --surface-2: #1A2132;
  --surface-3: #232B3F;
  --ink: #F2F4F8;
  --text: #D4D9E4;
  --muted: #98A1B5;
  --faint: #677089;
  --line: #242C3E;
  --line-strong: #343E56;
  --brand: #7F9CFF;
  --brand-strong: #B8C8FF;
  --brand-soft: #1C2752;
  --brand-tint: #151D3A;
  --on-brand: #0B0F1A;
  --hl: #FFE04B;
  --hl-soft: #3A3313;
  --hl-ink: #1A1500;
  --eosin: #F07CA9;
  --eosin-soft: #3A1B2B;
  --good: #3FC98E;
  --good-soft: #10302A;
  --good-line: #23674D;
  --bad: #FF7B70;
  --bad-soft: #3A1A1C;
  --bad-line: #7C3833;
  --warn: #F2B54F;
  --warn-soft: #352914;
  --warn-line: #6E5422;
  --m-new: #263049;
  --m-learning: #34509E;
  --m-consolidating: #6584F2;
  --m-mastered: #B4C5FF;
  --m-weak: #E9776C;
  --hero-bg: #172A8C;
  --nav-bg: rgba(11, 15, 26, 0.76);
  --bar-bg: rgba(21, 27, 41, 0.8);
  --scrim: rgba(0, 0, 0, 0.56);
  --shadow-1: 0 0 0 1px rgba(255, 255, 255, 0.05);
  --shadow-2: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 16px 40px -10px rgba(0, 0, 0, 0.6);
  --shadow-3: 0 0 0 1px rgba(255, 255, 255, 0.07), 0 28px 72px -12px rgba(0, 0, 0, 0.75);
  color-scheme: dark;
}

:root[data-text='s'] { --stem-size: 18px; }
:root[data-text='l'] { --stem-size: 23px; }

@media (min-width: 700px) {
  :root { --gutter: 32px; --stem-size: 22px; }
  :root[data-text='s'] { --stem-size: 19px; }
  :root[data-text='l'] { --stem-size: 26px; }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
  background: var(--bg);
}
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  font-feature-settings: 'ss01', 'cv11';
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; -webkit-user-select: none; user-select: none; }
a { color: var(--brand); text-decoration: none; }
img, svg { display: block; }
h1, h2, h3, h4, p { margin: 0; }
::selection { background: var(--brand-soft); }
:focus { outline: none; }
:focus-visible { outline: 2.5px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.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; }

/* ---------- Coque de l'application ---------- */
.app { min-height: 100vh; min-height: 100dvh; display: flex; }
.sidebar { display: none; }
.main { flex: 1; min-width: 0; position: relative; }
.stage { position: relative; min-height: 100vh; min-height: 100dvh; }
.view {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(var(--safe-t) + var(--navbar-h)) calc(var(--gutter) + var(--safe-r)) calc(var(--tabbar-h) + var(--safe-b) + 40px) calc(var(--gutter) + var(--safe-l));
  background: var(--bg);
}
.view.no-tabbar { padding-bottom: calc(var(--safe-b) + 40px); }
.view-inner { max-width: var(--content-max); margin: 0 auto; }
.view-inner.wide { max-width: 1120px; }
.view.leaving { position: fixed; left: 0; right: 0; bottom: auto; pointer-events: none; z-index: 1; will-change: transform; }

/* Barre de navigation (titre compact qui apparaît au défilement) */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  padding-top: var(--safe-t);
  height: calc(var(--safe-t) + var(--navbar-h));
  display: flex;
  align-items: stretch;
  pointer-events: none;
}
.navbar-inner {
  position: relative;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(88px, 1fr) auto minmax(88px, 1fr);
  align-items: center;
  padding: 0 calc(8px + var(--safe-r)) 0 calc(8px + var(--safe-l));
  pointer-events: auto;
}
.navbar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(1.8) blur(20px);
  backdrop-filter: saturate(1.8) blur(20px);
  border-bottom: 0.5px solid var(--line);
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease-out);
}
.navbar.scrolled::before, .navbar.solid::before { opacity: 1; }
.navbar-title {
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
  text-align: center;
}
.navbar.scrolled .navbar-title, .navbar.always-title .navbar-title { opacity: 1; transform: none; }
.navbar-left, .navbar-right { display: flex; align-items: center; gap: 2px; min-width: 0; }
.navbar-right { justify-content: flex-end; }
.nav-btn {
  height: 40px;
  min-width: 40px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 999px;
  color: var(--brand);
  font-weight: 550;
  font-size: 16px;
  transition: background var(--dur-1), transform var(--dur-1) var(--ease-out);
}
.nav-btn:active { background: var(--brand-soft); transform: scale(0.94); }
.nav-btn.back { padding-left: 4px; }
.nav-btn svg { width: 24px; height: 24px; flex: none; }
.nav-btn.back span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 36vw; }
.navbar-left .nav-btn { min-width: 0; }

/* Grand titre */
.large-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 36px;
  line-height: 1.08;
  letter-spacing: -0.015em;
  color: var(--ink);

  margin: 10px 0 6px;
  text-wrap: balance;
}
.large-sub { color: var(--muted); font-size: 15px; margin-bottom: 22px; }
@media (min-width: 700px) {
  .large-title { font-size: 44px; margin-top: 18px; }
}

/* Barre d'onglets (iPhone, iPad portrait) */
.tabbar {
  position: fixed;
  z-index: 40;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 6px calc(8px + var(--safe-r)) calc(var(--safe-b) + 4px) calc(8px + var(--safe-l));
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(1.8) blur(22px);
  backdrop-filter: saturate(1.8) blur(22px);
  border-top: 0.5px solid var(--line);
  display: flex;
  justify-content: space-around;
  transition: transform var(--dur-3) var(--ease-out), opacity var(--dur-2);
}
.tabbar.hidden { transform: translateY(110%); opacity: 0; pointer-events: none; }
.tab {
  flex: 1;
  max-width: 120px;
  height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: 14px;
  transition: color var(--dur-2);
}
.tab svg { width: 25px; height: 25px; transition: transform var(--dur-2) var(--ease-out); }
.tab:active svg { transform: scale(0.86); }
.tab.active { color: var(--brand); }
.tab.create .tab-orb {
  width: 44px;
  height: 32px;
  border-radius: 12px;
  background: var(--brand);
  color: var(--on-brand);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px -6px var(--brand);
}
.tab.create svg { width: 22px; height: 22px; }
.tab.create span:last-child { display: none; }

/* Barre latérale (iPad paysage, ordinateur) */
@media (min-width: 1000px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: calc(var(--sidebar-w) + var(--safe-l));
    padding: calc(var(--safe-t) + 22px) 14px calc(var(--safe-b) + 18px) calc(14px + var(--safe-l));
    background: var(--bg-elev);
    border-right: 0.5px solid var(--line);
    z-index: 35;
  }
  .main { margin-left: calc(var(--sidebar-w) + var(--safe-l)); }
  .navbar { left: calc(var(--sidebar-w) + var(--safe-l)); }
  .tabbar { display: none; }
  .view { padding-bottom: calc(var(--safe-b) + 56px); padding-left: 40px; padding-right: calc(40px + var(--safe-r)); }
  .view.leaving { left: calc(var(--sidebar-w) + var(--safe-l)); }
  .toast-host { left: calc(var(--sidebar-w) + var(--safe-l)) !important; }
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 10px 22px; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-name { font-family: var(--font-display); font-size: 22px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; }
.brand-name span { font-weight: 500; color: var(--brand); }
.side-group { margin-bottom: 18px; }
.side-label { font-size: 12px; color: var(--faint); font-weight: 600; padding: 0 12px 6px; }
.side-link {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  color: var(--text);
  font-weight: 550;
  font-size: 15.5px;
  width: 100%;
  text-align: left;
  transition: background var(--dur-1);
}
.side-link svg { width: 21px; height: 21px; color: var(--muted); }
.side-link:hover { background: var(--surface-3); }
.side-link.active { background: var(--brand-soft); color: var(--brand-strong); }
.side-link.active svg { color: var(--brand); }
.side-link .count { margin-left: auto; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.side-cta {
  margin: 4px 0 22px;
  height: 46px;
  border-radius: 14px;
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 22px -10px var(--brand);
  transition: transform var(--dur-1) var(--ease-out), filter var(--dur-1);
}
.side-cta:active { transform: scale(0.97); }
.side-cta svg { width: 20px; height: 20px; }
.side-foot { margin-top: auto; padding: 10px 12px; border-radius: 14px; display: flex; align-items: center; gap: 10px; color: inherit; transition: background var(--dur-2); }
.side-foot:hover { background: var(--surface-3); }
.side-avatar { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: var(--on-brand); font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.side-who { min-width: 0; display: grid; gap: 1px; }
.side-who b { font-size: 14.5px; color: var(--ink); font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-sync { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.sync-dot.auth { background: var(--bad); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.sync-dot.ok { background: var(--good); }
.sync-dot.syncing { background: var(--brand); animation: pulse 1.2s var(--ease-in-out) infinite; }
.sync-dot.error { background: var(--bad); }
.sync-dot.offline { background: var(--warn); }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- Typographie ---------- */
.h-section {
  font-size: 20px;
  font-weight: 650;
  color: var(--ink);
  letter-spacing: -0.01em;
  margin: 34px 0 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.h-section .link { font-size: 15px; font-weight: 550; }
.h-section:first-child { margin-top: 8px; }
.serif { font-family: var(--font-display); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.lead { font-size: 17px; color: var(--muted); line-height: 1.5; }

/* ---------- Boutons ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 14px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.005em;
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-1) var(--ease-out), background var(--dur-2), opacity var(--dur-2), box-shadow var(--dur-2);
  white-space: nowrap;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { --btn-bg: var(--brand); --btn-fg: var(--on-brand); box-shadow: 0 10px 24px -12px var(--brand), inset 0 1px 0 rgba(255, 255, 255, 0.12); }
.btn.tinted { --btn-bg: var(--brand-soft); --btn-fg: var(--brand-strong); box-shadow: none; }
.btn.plain { --btn-bg: transparent; --btn-fg: var(--brand); box-shadow: none; padding: 0 12px; }
.btn.danger { --btn-bg: var(--bad-soft); --btn-fg: var(--bad); box-shadow: none; }
.btn.good { --btn-bg: var(--good); --btn-fg: #fff; box-shadow: none; }
.btn.block { width: 100%; }
.btn.lg { min-height: 56px; font-size: 17px; border-radius: 16px; }
.btn.sm { min-height: 38px; padding: 0 14px; font-size: 14.5px; border-radius: 11px; }
.btn.icon { padding: 0; width: 44px; min-height: 44px; border-radius: 13px; }
.btn.icon.sm { width: 38px; min-height: 38px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row.end { justify-content: flex-end; }
.btn-row > .btn { flex: 1 1 auto; }
.btn .spinner { width: 18px; height: 18px; border-width: 2px; }

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
  opacity: 0.8;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Listes groupées (style réglages iOS) ---------- */
.group {
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.group + .group { margin-top: 14px; }
.group-title { font-size: 13.5px; color: var(--muted); font-weight: 550; margin: 26px 4px 8px; }
.group-foot { font-size: 13px; color: var(--muted); margin: 8px 4px 0; line-height: 1.45; }
.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 54px;
  padding: 10px 16px;
  width: 100%;
  text-align: left;
  background: transparent;
  transition: background var(--dur-1);
}
.row + .row::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 16px;
  border-top: 0.5px solid var(--line);
}
.row.has-icon + .row::before, .row.has-icon + .row.has-icon::before { left: 58px; }
button.row:active, a.row:active { background: var(--surface-3); }
.row-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--brand-soft);
  color: var(--brand);
}
.row-icon svg { width: 18px; height: 18px; }
.row-icon.eosin { background: var(--eosin-soft); color: var(--eosin); }
.row-icon.good { background: var(--good-soft); color: var(--good); }
.row-icon.bad { background: var(--bad-soft); color: var(--bad); }
.row-icon.warn { background: var(--warn-soft); color: var(--warn); }
.row-icon.neutral { background: var(--surface-3); color: var(--muted); }
.row-main { flex: 1; min-width: 0; }
.row-title { color: var(--ink); font-weight: 550; font-size: 16px; line-height: 1.3; }
.row-sub { color: var(--muted); font-size: 13.5px; line-height: 1.35; margin-top: 2px; }
.row-value { color: var(--muted); font-size: 15px; text-align: right; flex: none; max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-chevron { color: var(--faint); width: 18px; height: 18px; flex: none; }
.row.danger .row-title { color: var(--bad); }
.row.disabled { opacity: 0.5; pointer-events: none; }

/* ---------- Champs ---------- */
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 14px; font-weight: 600; color: var(--ink); margin: 0 2px 7px; }
.field-hint { font-size: 13px; color: var(--muted); margin: 6px 2px 0; line-height: 1.4; }
.input, .textarea, .select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  transition: border-color var(--dur-2), box-shadow var(--dur-2), background var(--dur-2);
  -webkit-appearance: none;
  appearance: none;
}
.textarea { resize: none; overflow: hidden; min-height: 52px; display: block; }
.textarea.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13.5px; line-height: 1.55; overflow: auto; resize: vertical; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.select { padding-right: 40px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-inline { display: flex; align-items: center; gap: 10px; }

/* Interrupteur */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch-track { position: absolute; inset: 0; border-radius: 999px; background: var(--line-strong); transition: background var(--dur-2) var(--ease-out); }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); transition: transform var(--dur-2) var(--ease-out), width var(--dur-1); }
.switch input:checked ~ .switch-track { background: var(--good); }
.switch input:checked ~ .switch-thumb { transform: translateX(20px); }
.switch input:active ~ .switch-thumb { width: 31px; }
.switch input:checked:active ~ .switch-thumb { transform: translateX(16px); }
.switch input:focus-visible ~ .switch-track { outline: 2.5px solid var(--brand); outline-offset: 2px; }

/* Contrôle segmenté */
.segmented {
  position: relative;
  display: flex;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-3);
  isolation: isolate;
}
.segmented button {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 9px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--muted);
  transition: color var(--dur-2);
  white-space: nowrap;
}
.segmented button.active { color: var(--ink); }
.segmented .seg-pill {
  position: absolute;
  z-index: 0;
  top: 3px;
  bottom: 3px;
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(25, 28, 60, 0.12), 0 0 0 0.5px rgba(25, 28, 60, 0.06);
  transition: transform var(--dur-3) var(--ease-out), width var(--dur-3) var(--ease-out);
}

/* Puces */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 550;
  transition: background var(--dur-2), border-color var(--dur-2), color var(--dur-2), transform var(--dur-1) var(--ease-out);
}
.chip:active { transform: scale(0.96); }
.chip svg { width: 16px; height: 16px; }
.chip.on { background: var(--brand-soft); border-color: transparent; color: var(--brand-strong); }
.chip .chip-n { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 500; }
.chip.on .chip-n { color: var(--brand); }

/* Pas à pas numérique */
.stepper { display: inline-flex; align-items: center; background: var(--surface-3); border-radius: 12px; padding: 3px; }
.stepper button { width: 40px; height: 36px; border-radius: 9px; display: grid; place-items: center; color: var(--ink); transition: background var(--dur-1); }
.stepper button:active { background: var(--surface); }
.stepper button svg { width: 18px; height: 18px; }
.stepper input { width: 52px; text-align: center; border: 0; background: transparent; font-weight: 650; font-size: 16px; font-variant-numeric: tabular-nums; color: var(--ink); -moz-appearance: textfield; appearance: textfield; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--muted);
  white-space: nowrap;
}
.badge svg { width: 13px; height: 13px; }
.badge.brand { background: var(--brand-soft); color: var(--brand-strong); }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.eosin { background: var(--eosin-soft); color: var(--eosin); }
.badge.outline { background: transparent; border: 1px solid var(--line-strong); }

/* ---------- Cartes ---------- */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: 20px;
}
.card.pad-lg { padding: 24px; }
.card-press { transition: transform var(--dur-2) var(--ease-out), box-shadow var(--dur-2); width: 100%; text-align: left; display: block; }
.card-press:active { transform: scale(0.985); }

/* ---------- Barre de maîtrise ---------- */
.mbar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; gap: 2px; background: transparent; }
.mbar > span { display: block; height: 100%; min-width: 0; transition: flex-grow var(--dur-3) var(--ease-out); }
.mbar > span:first-child { border-radius: 999px 0 0 999px; }
.mbar > span:last-child { border-radius: 0 999px 999px 0; }
.mbar > span:only-child { border-radius: 999px; }
.mbar.lg { height: 12px; }
.m-mastered { background: var(--m-mastered); }
.m-consolidating { background: var(--m-consolidating); }
.m-learning { background: var(--m-learning); }
.m-weak { background: var(--m-weak); }
.m-new { background: var(--m-new); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Toasts ---------- */
.toast-host {
  position: fixed;
  z-index: 100;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 16px;
}
.toast-host.no-tabbar { bottom: calc(var(--safe-b) + 20px); }
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 460px;
  min-height: 48px;
  padding: 10px 12px 10px 16px;
  border-radius: 16px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 550;
  font-size: 15px;
  box-shadow: var(--shadow-3);
}
.toast svg { width: 20px; height: 20px; flex: none; }
.toast .toast-action { color: var(--brand-soft); font-weight: 650; padding: 6px 8px; border-radius: 9px; margin-left: 4px; }
:root[data-theme='dark'] .toast .toast-action { color: var(--brand); }
.toast.good svg { color: #6ee0aa; }
.toast.bad svg { color: #ff9b91; }

/* ---------- Feuilles modales ---------- */
.sheet-host { position: fixed; inset: 0; z-index: 80; display: flex; align-items: flex-end; justify-content: center; }
.sheet-scrim { position: absolute; inset: 0; background: var(--scrim); }
.sheet {
  position: relative;
  width: 100%;
  max-height: calc(100dvh - var(--safe-t) - 24px);
  background: var(--bg-elev);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: var(--safe-b);
}
.sheet-grab { padding: 8px 0 2px; display: flex; justify-content: center; touch-action: none; cursor: grab; }
.sheet-grab::before { content: ''; width: 38px; height: 5px; border-radius: 999px; background: var(--line-strong); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 12px 6px 20px; min-height: 52px; touch-action: none; }
.sheet-title { font-size: 18px; font-weight: 650; color: var(--ink); }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 20px 22px; overscroll-behavior: contain; }
.sheet-foot { padding: 12px 20px calc(14px); border-top: 0.5px solid var(--line); background: var(--bg-elev); }
@media (min-width: 700px) {
  .sheet-host { align-items: center; padding: 24px; }
  .sheet { max-width: 560px; border-radius: var(--r-xl); max-height: min(86dvh, 860px); padding-bottom: 0; }
  .sheet.wide { max-width: 760px; }
  .sheet-grab { display: none; }
  .sheet-head { padding-top: 12px; }
}
.dialog-text { color: var(--muted); font-size: 15.5px; line-height: 1.5; margin-bottom: 18px; }

/* ---------- Visionneuse d'image ---------- */
.lightbox { position: fixed; inset: 0; z-index: 120; background: rgba(8, 9, 22, 0.94); touch-action: none; overflow: hidden; }
.lightbox img { position: absolute; top: 50%; left: 50%; max-width: 96vw; max-height: 86vh; transform-origin: center; will-change: transform; border-radius: 6px; background: #fff; }
.lightbox-close { position: absolute; top: calc(var(--safe-t) + 12px); right: calc(var(--safe-r) + 12px); width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, 0.14); color: #fff; display: grid; place-items: center; z-index: 2; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.lightbox-close svg { width: 22px; height: 22px; }
.lightbox-hint { position: absolute; bottom: calc(var(--safe-b) + 18px); left: 0; right: 0; text-align: center; color: rgba(255, 255, 255, 0.6); font-size: 13px; }

/* ---------- Texte riche ---------- */
.rt { overflow-wrap: anywhere; }
.rt p + p, .rt p + ul, .rt ul + p, .rt p + .rt-table, .rt .rt-table + p, .rt p + ol, .rt ol + p { margin-top: 0.7em; }
.rt ul, .rt ol { margin: 0.4em 0; padding-left: 1.3em; }
.rt li + li { margin-top: 0.2em; }
.rt sub, .rt sup { font-size: 0.72em; line-height: 0; }
.rt code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 0.88em; background: var(--surface-3); padding: 0.1em 0.35em; border-radius: 5px; }
.rt strong { font-weight: 650; color: var(--ink); }
.rt-table { overflow-x: auto; margin: 0.8em 0; border-radius: 12px; border: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
.rt-table table { border-collapse: collapse; width: 100%; font-family: var(--font-ui); font-size: 0.78em; font-variant-numeric: tabular-nums; }
.rt-table th, .rt-table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.rt-table th { background: var(--surface-2); font-weight: 650; color: var(--ink); }
.rt-table tr:last-child td { border-bottom: 0; }
.rt-math { margin: 0.7em 0; overflow-x: auto; }
.rt .katex { font-size: 1.04em; }
.rt .katex-display { margin: 0.4em 0; }
.math-raw { color: var(--brand-strong); }

/* ---------- Images dans les questions ---------- */
.figs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.fig {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-1);
  cursor: zoom-in;
  max-width: 100%;
  transition: transform var(--dur-2) var(--ease-out);
}
.fig:active { transform: scale(0.985); }
.fig img { max-width: 100%; max-height: 340px; width: auto; height: auto; object-fit: contain; margin: 0 auto; }
.fig.thumb img { max-height: 120px; }
.fig .fig-zoom { position: absolute; right: 8px; bottom: 8px; width: 30px; height: 30px; border-radius: 9px; background: rgba(25, 28, 60, 0.6); color: #fff; display: grid; place-items: center; opacity: 0.9; }
.fig .fig-zoom svg { width: 16px; height: 16px; }
.fig-pending {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1.5px dashed var(--line-strong);
  color: var(--muted);
  font-size: 14px;
  background: var(--surface-2);
}
.fig-pending svg { width: 20px; height: 20px; flex: none; color: var(--faint); }

/* ---------- États vides ---------- */
.empty { text-align: center; padding: 48px 20px; }
.empty-art { width: 120px; height: 120px; margin: 0 auto 14px; }
.empty h3 { font-family: var(--font-display); font-size: 24px; font-weight: 500; color: var(--ink); margin-bottom: 8px; }
.empty p { color: var(--muted); max-width: 360px; margin: 0 auto 22px; }

/* ---------- Divers ---------- */
.stack > * + * { margin-top: 12px; }
.stack-lg > * + * { margin-top: 20px; }
.hstack { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.divider { height: 0.5px; background: var(--line); margin: 18px 0; }
.kbd { font-family: ui-monospace, monospace; font-size: 12px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line-strong); color: var(--muted); }
.notice {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--brand-tint);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.45;
}
.notice svg { width: 20px; height: 20px; flex: none; color: var(--brand); margin-top: 1px; }
.notice.warn { background: var(--warn-soft); }
.notice.warn svg { color: var(--warn); }
.notice.bad { background: var(--bad-soft); }
.notice.bad svg { color: var(--bad); }
.notice.good { background: var(--good-soft); }
.notice.good svg { color: var(--good); }
.notice b { color: var(--ink); }
.disclosure { display: flex; align-items: center; gap: 8px; color: var(--brand); font-weight: 600; font-size: 15px; padding: 10px 2px; }
.disclosure svg { width: 18px; height: 18px; transition: transform var(--dur-2) var(--ease-out); }
.disclosure[aria-expanded='true'] svg { transform: rotate(90deg); }
.collapse { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
:root[data-motion='reduced'] *, :root[data-motion='reduced'] *::before, :root[data-motion='reduced'] *::after {
  transition-duration: 0.01ms !important;
  animation-duration: 0.01ms !important;
}

/* Bouton en cours : roue superposée, dimensions inchangées */
.btn-spinner { display: none; position: absolute; left: 50%; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%; border: 2.4px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; }
.btn.busy > :not(.btn-spinner) { visibility: hidden; }
.btn.busy > .btn-spinner { display: block; }
.btn.busy:disabled { opacity: 1; }

/* Aucune largeur de page au-delà de l'écran, même pendant une transition :
   sinon le navigateur mobile « dézoome » une fraction de seconde et tout saute. */
html, body { overflow-x: clip; }
@supports not (overflow: clip) { html, body { overflow-x: hidden; } }
.stage, .main { overflow-x: clip; }
.fig img { opacity: 0; transition: opacity 0.32s var(--ease-out); }
.fig img.loaded { opacity: 1; }
/* Ordinateur : la place de la barre de défilement reste réservée (ouvrir une feuille ne décale rien) */
@media (pointer: fine) { html { scrollbar-gutter: stable; } }
