/* =========================================================================
   DUEL DE PLUMES — feuille de style
   -------------------------------------------------------------------------
   Direction visuelle : "salle d'armes littéraire" — encre profonde, cire à
   cacher, or des étoiles. Le nom du projet ("duel" + "plumes") est pris au
   pied de la lettre : traits de plume tendus comme des lames, gouttes
   d'encre, sceau de cire. On évite délibérément le cliché "IA générique"
   (fond crème + serif + terracotta, ou noir + un seul accent néon) : ici le
   fond est un bleu-encre profond, l'accent est un rouge de cire chaud, et
   les étoiles/récompenses vivent dans un or distinct.
   ========================================================================= */

/* ---- Polices ---- */
:root {
  --font-display: 'Fraunces', Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --font-body: 'Figtree', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Space Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;

  /* ---- Couleurs — famille "encre" (fonds) ---- */
  --ink-950: #0e1322;
  --ink-900: #161d33;
  --ink-800: #202a48;
  --ink-700: #2c3860;
  --ink-600: #3c4a7a;

  /* ---- famille "parchemin" (texte clair / papier) ---- */
  --parchment: #f4ead6;
  --parchment-dim: #c9bfa8;
  --parchment-faint: #8b8ba0;

  /* ---- accents nommés ---- */
  --sceau: #d1483f;        /* rouge cire — actions principales, duel */
  --sceau-dark: #a8352e;
  --sceau-glow: rgba(209, 72, 63, 0.35);
  --plume-gold: #e3ad46;   /* or — étoiles, récompenses, série */
  --plume-gold-dim: #8a6a2e;
  --encre-vert: #5f9e78;   /* vert d'encre — succès / correct */
  --encre-bleu: #7b98d1;   /* bleu d'encre — info / secondaire */

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --ease-out: cubic-bezier(.16,.84,.44,1);
  --ease-spring: cubic-bezier(.34,1.56,.64,1);

  color-scheme: dark;
}

/* ---- Reset minimal ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink-950);
  color: var(--parchment);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, p, figure, blockquote { margin: 0; }
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--encre-bleu); }
ul { list-style: none; margin: 0; padding: 0; }
svg { display: block; }

/* Fond ambiant : léger dégradé radial pour donner de la profondeur à l'encre,
   plus une texture de "papier"/grain très subtile en overlay fixe. */
body {
  background-image:
    radial-gradient(ellipse 900px 500px at 15% -5%, rgba(123, 152, 209, 0.10), transparent 60%),
    radial-gradient(ellipse 700px 500px at 100% 10%, rgba(227, 173, 70, 0.06), transparent 55%);
  background-attachment: fixed;
}

:focus { outline: none; }
:focus-visible {
  outline: 2.5px solid var(--plume-gold);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---- Icônes ---- */
.icon { width: 1.25em; height: 1.25em; flex-shrink: 0; }
.icon-stroke { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-fill { fill: currentColor; stroke: none; }

/* =========================================================================
   Coquille de l'app
   ========================================================================= */
#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  position: relative;
}

/* ---- Barre supérieure ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4) var(--space-3);
}
.brand { display: flex; align-items: center; gap: var(--space-2); }
.brand__mark { width: 34px; height: 34px; }
.brand__word {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.02;
  letter-spacing: -0.01em;
}
.brand__word b { color: var(--plume-gold); font-weight: 900; }

.stat-row { display: flex; gap: var(--space-2); flex-wrap: wrap; justify-content: flex-end; }
.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}
.stat-chip .icon { width: 15px; height: 15px; }
.stat-chip--flame { color: var(--plume-gold); }
.stat-chip--flame .icon { color: #f0803c; }
.stat-chip--stars { color: var(--parchment); }
.stat-chip--stars .icon { color: var(--plume-gold); }
.stat-chip--trophy { color: var(--parchment-dim); }
.stat-chip--trophy .icon { color: var(--encre-bleu); }

.skeleton-chip {
  width: 64px; height: 26px; border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--ink-800) 25%, var(--ink-700) 37%, var(--ink-800) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.greeting {
  padding: 0 var(--space-4) var(--space-2);
}
.greeting h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.7rem;
  letter-spacing: -0.01em;
}
.greeting__rivalry {
  margin-top: var(--space-2);
  font-size: 0.86rem;
  font-style: italic;
  color: var(--parchment-faint);
}
.greeting__rivalry strong { color: var(--plume-gold); font-style: normal; }

/* Trait de plume — élément signature, utilisé comme séparateur/soulignement */
.plume-stroke {
  width: 72px;
  height: 10px;
  margin-top: var(--space-2);
  color: var(--sceau);
  overflow: visible;
}
.plume-stroke path {
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 90;
  stroke-dashoffset: 90;
  animation: draw-stroke .7s var(--ease-out) forwards;
}
@keyframes draw-stroke { to { stroke-dashoffset: 0; } }

/* ---- Vue principale ---- */
.view {
  flex: 1;
  padding: 0 var(--space-4) var(--space-6);
  animation: view-in .35s var(--ease-out);
}
@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Barre d'onglets (bas sur mobile, pastille sous l'entête sur grand écran) ---- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(0deg, var(--ink-950) 60%, rgba(14,19,34,0));
  z-index: 20;
}
.tabbar__inner {
  display: flex;
  gap: 4px;
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--radius-pill);
  padding: 4px;
  width: 100%;
  max-width: 420px;
}
.tabbar__btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--parchment-dim);
  transition: background .2s var(--ease-out), color .2s var(--ease-out);
}
.tabbar__btn .icon { width: 17px; height: 17px; }
.tabbar__btn.is-active {
  background: var(--sceau);
  color: var(--parchment);
}

/* =========================================================================
   Carte des chapitres
   ========================================================================= */
.matiere-group { margin-top: var(--space-7, 40px); }
.matiere-group:first-of-type { margin-top: var(--space-5); }
.matiere-group__head {
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--ink-700);
  margin-bottom: var(--space-2);
}
.matiere-group__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--plume-gold);
}

.objet-group { margin-top: var(--space-6); }
.objet-group__head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.objet-group__eyebrow {
  font-family: var(--font-display);
  font-weight: 700;
  font-style: italic;
  font-size: 1.05rem;
  color: var(--parchment);
}
.objet-group__rule {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--ink-600), transparent);
}

.chapter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

.chapter-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  text-align: left;
  width: 100%;
  padding: var(--space-4);
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--radius-md);
  transition: transform .18s var(--ease-out), border-color .18s var(--ease-out), background .18s var(--ease-out);
}
.chapter-card:hover, .chapter-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--ink-600);
  background: #232d4f;
}
.chapter-card:active { transform: translateY(0px) scale(.99); }

.chapter-card--recommended {
  border-color: var(--plume-gold-dim);
  box-shadow: 0 0 0 1px rgba(227,173,70,0.25), 0 0 24px -6px rgba(227,173,70,0.35);
}

.chapter-card__badge {
  position: absolute;
  top: -10px;
  left: var(--space-4);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--plume-gold);
  color: var(--ink-950);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.chapter-card__badge .icon { width: 11px; height: 11px; }

.chapter-card--locked {
  opacity: 0.55;
  cursor: default;
}
.chapter-card--locked:hover, .chapter-card--locked:focus-visible {
  transform: none;
  border-color: var(--ink-700);
  background: var(--ink-800);
}
.chapter-card__badge--locked {
  background: var(--ink-600);
  color: var(--parchment);
}

.chapter-card__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.25;
  color: var(--parchment);
  padding-right: 20px;
}
.chapter-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.chapter-card__attempts {
  font-size: 0.78rem;
  color: var(--parchment-faint);
}
.chapter-card__replay {
  font-size: 0.78rem;
  color: var(--encre-bleu);
  font-style: italic;
}

/* ---- Étoiles ---- */
.star-row { display: inline-flex; gap: 3px; }
.star-row .icon { width: 18px; height: 18px; }
.star--filled { color: var(--plume-gold); }
.star--empty { color: var(--ink-600); }

/* =========================================================================
   Boutons
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  border-radius: var(--radius-pill);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.01em;
  transition: transform .15s var(--ease-spring), filter .15s var(--ease-out), opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn--primary {
  background: var(--sceau);
  color: var(--parchment);
  box-shadow: 0 6px 18px -6px var(--sceau-glow);
}
.btn--primary:hover { filter: brightness(1.08); }
.btn--secondary {
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  color: var(--parchment);
}
.btn--secondary:hover { background: var(--ink-700); }
.btn--ghost {
  background: transparent;
  color: var(--parchment-dim);
  padding: 10px 14px;
}
.btn--ghost:hover { color: var(--parchment); }
.btn--block { width: 100%; }
.btn-row { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-5); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: var(--radius-pill);
  color: var(--parchment-dim);
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
}
.icon-btn:hover { color: var(--parchment); }

/* =========================================================================
   Vue "Progrès"
   ========================================================================= */
.progress-block { margin-top: var(--space-5); }
.progress-block__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}
.progress-block__title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 700;
  font-size: 1.05rem;
}
.progress-block__frac {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--parchment-dim);
}
.progress-bar {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  overflow: hidden;
  margin-bottom: var(--space-3);
}
.progress-bar__fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--sceau), var(--plume-gold));
  transition: width .6s var(--ease-out);
}
.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 10px 4px;
  border-bottom: 1px solid var(--ink-800);
}
.progress-row:last-child { border-bottom: none; }
.progress-row__title { font-size: 0.92rem; color: var(--parchment); }
.progress-row__attempts { font-size: 0.72rem; color: var(--parchment-faint); display: block; margin-top: 2px; }
.progress-row__right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.progress-row .star-row .icon { width: 14px; height: 14px; }

/* =========================================================================
   Vue "Intro de chapitre"
   ========================================================================= */
.intro-eyebrow {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--encre-bleu);
  margin-bottom: var(--space-2);
}
.intro-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.6rem;
  line-height: 1.15;
  margin-bottom: var(--space-3);
}
.timed-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  background: var(--ink-800);
  border: 1px solid var(--sceau-dark);
  color: var(--sceau);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: var(--space-4);
}
.timed-badge .icon { width: 14px; height: 14px; }

.intro-text {
  font-size: 0.98rem;
  color: var(--parchment-dim);
  line-height: 1.6;
  margin-bottom: var(--space-5);
}

.source-card {
  padding: var(--space-4);
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-left: 3px solid var(--plume-gold);
  border-radius: var(--radius-sm) var(--radius-md) var(--radius-md) var(--radius-sm);
  margin-bottom: var(--space-6);
}
.source-card__meta {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--parchment-faint);
  margin-bottom: var(--space-2);
}
.source-card__meta b { color: var(--plume-gold); font-weight: 700; }
.source-card__excerpt {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--parchment);
}

/* Positionnement uniquement : texte de référence gardé visible pendant
   toute la séquence de questions (voir renderExerciseShell). Réutilise
   .source-card / .source-card__meta / .source-card__excerpt telles quelles. */
.source-panel { margin-bottom: var(--space-6); }
.source-panel .source-card { margin-bottom: var(--space-2); }
.source-panel--collapsed .source-card__excerpt { display: none; }
.source-panel__toggle {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--plume-gold);
  cursor: pointer;
  text-decoration: underline;
}
.source-panel__toggle:hover { color: var(--parchment-dim); }

/* =========================================================================
   Session d'exercice
   ========================================================================= */
.exercise-topstrip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) 0 var(--space-3);
  position: sticky;
  top: 0;
  background: var(--ink-950);
  z-index: 10;
}
.timer {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--parchment);
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 auto;
}
.timer .icon { width: 18px; height: 18px; color: var(--encre-bleu); }
.timer.is-low { color: var(--sceau); }
.timer.is-low .icon { color: var(--sceau); }
@media (prefers-reduced-motion: no-preference) {
  .timer.is-low { animation: timer-pulse 1s ease-in-out infinite; }
}
@keyframes timer-pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

.dot-progress { display: flex; gap: 6px; justify-content: center; margin-bottom: var(--space-5); flex-wrap: wrap; }
.dot-progress__dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--ink-700);
  border: none;
  transition: all .2s var(--ease-out);
}
.dot-progress__dot.is-answered { background: var(--encre-vert); }
.dot-progress__dot.is-current { width: 22px; border-radius: var(--radius-pill); background: var(--plume-gold); }

/* Zone protégée par l'anti-triche (sélection désactivée, filigrane, etc.) */
.exercise-guard {
  position: relative;
  isolation: isolate;
}

.exercise-card {
  position: relative;
  padding: var(--space-5) var(--space-4);
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.exercise-card__eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--parchment-faint);
  margin-bottom: var(--space-3);
}
.exercise-card__question {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.2rem;
  line-height: 1.4;
  margin-bottom: var(--space-5);
  user-select: none;
}

/* Filigrane anti-capture — deux couches indépendantes (texture + texte) pour
   qu'une seule suppression de règle CSS dans l'inspecteur ne l'efface pas
   entièrement. Dissuasif, pas une protection réelle (voir js/anticheat.js). */
.watermark-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  mix-blend-mode: overlay;
  opacity: 0.85;
  background-image: repeating-linear-gradient(
    -22deg,
    rgba(244,234,214,0.05) 0px, rgba(244,234,214,0.05) 1px,
    transparent 1px, transparent 68px
  );
}
.watermark-text {
  position: absolute;
  inset: -20% -10%;
  pointer-events: none;
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  align-content: space-around;
  justify-content: space-around;
  transform: rotate(-22deg);
  opacity: 0.1;
  color: var(--parchment);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.watermark-text span { padding: 14px 22px; }

/* ---- Choix QCM ---- */
.choice-list { display: flex; flex-direction: column; gap: var(--space-2); }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--ink-700);
  background: var(--ink-900);
  transition: border-color .15s, background .15s;
}
.choice:hover { border-color: var(--ink-600); }
.choice input { accent-color: var(--sceau); width: 18px; height: 18px; flex-shrink: 0; }
.choice__label { font-size: 0.96rem; line-height: 1.35; }
.choice:has(input:checked) {
  border-color: var(--sceau);
  background: rgba(209,72,63,0.1);
}

/* ---- Texte à trous ---- */
.blank-text { font-size: 1.02rem; line-height: 2.2; color: var(--parchment); user-select: none; }
.blank-input {
  display: inline-block;
  min-width: 90px;
  max-width: 220px;
  padding: 2px 8px;
  margin: 0 3px;
  border: none;
  border-bottom: 2px solid var(--encre-bleu);
  background: rgba(123,152,209,0.08);
  border-radius: 4px 4px 0 0;
  color: var(--plume-gold);
  font-weight: 700;
  font-family: var(--font-body);
  text-align: center;
  user-select: text;
}
.blank-input:focus { border-bottom-color: var(--plume-gold); background: rgba(227,173,70,0.1); }

/* ---- Texte libre ---- */
.free-textarea {
  width: 100%;
  min-height: 160px;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--ink-700);
  background: var(--ink-900);
  resize: vertical;
  line-height: 1.6;
  font-size: 0.98rem;
}
.free-textarea:focus { border-color: var(--encre-bleu); }
.word-counter {
  margin-top: var(--space-2);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--parchment-faint);
}
.word-counter.is-met { color: var(--encre-vert); }

.exercise-nav {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-5);
}
.exercise-nav .btn--secondary { flex: 0 0 auto; }
.exercise-nav .btn--primary { flex: 1; }

/* ---- Bannière sortie d'onglet détectée ---- */
.tabswitch-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  font-size: 0.84rem;
  color: var(--parchment-dim);
  animation: banner-in .3s var(--ease-out);
}
.tabswitch-banner .icon { width: 17px; height: 17px; color: var(--encre-bleu); flex-shrink: 0; margin-top: 1px; }
@keyframes banner-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* =========================================================================
   Résultats
   ========================================================================= */
.results-hero { text-align: center; padding: var(--space-6) 0 var(--space-5); position: relative; }
.results-stars { display: flex; justify-content: center; gap: 8px; margin-bottom: var(--space-4); }
.results-stars .icon { width: 40px; height: 40px; }
.results-stars .star--filled {
  transform: scale(0);
  animation: star-pop .5s var(--ease-spring) forwards;
  animation-delay: var(--delay, 0s);
}
@media (prefers-reduced-motion: reduce) {
  .results-stars .star--filled { transform: none; animation: none; }
}
@keyframes star-pop {
  0% { transform: scale(0) rotate(-25deg); }
  60% { transform: scale(1.25) rotate(8deg); }
  100% { transform: scale(1) rotate(0deg); }
}
.results-headline {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  margin-bottom: var(--space-2);
}
.results-best { font-size: 0.88rem; color: var(--parchment-faint); }
.results-streak {
  margin-top: var(--space-3);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--plume-gold);
}

.feedback-list { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-5); }
.feedback-item {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
}
.feedback-item__icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.feedback-item__icon .icon { width: 13px; height: 13px; }
.feedback-item--correct .feedback-item__icon { background: rgba(95,158,120,0.2); color: var(--encre-vert); }
.feedback-item--incorrect .feedback-item__icon { background: rgba(209,72,63,0.2); color: var(--sceau); }
.feedback-item--neutral .feedback-item__icon { background: rgba(123,152,209,0.2); color: var(--encre-bleu); }
.feedback-item__body { flex: 1; }
.feedback-item__q { display: block; font-size: 0.82rem; color: var(--parchment-dim); margin-bottom: 4px; }
.feedback-item__note { display: block; font-size: 0.86rem; color: var(--parchment); line-height: 1.4; }
.feedback-item__answer { display: block; font-size: 0.86rem; font-weight: 700; color: var(--plume-gold); margin-bottom: 4px; }

/* ---- Confettis (5/5 uniquement) ---- */
.confetti-piece {
  position: absolute;
  top: -10px;
  left: var(--x, 50%);
  width: 7px; height: 12px;
  background: var(--c, var(--plume-gold));
  border-radius: 2px;
  opacity: 0;
  animation: confetti-fall 1.8s ease-in forwards;
  animation-delay: var(--delay, 0s);
}
@keyframes confetti-fall {
  0% { opacity: 1; transform: translateY(0) rotate(0deg); }
  100% { opacity: 0; transform: translateY(220px) rotate(var(--rot, 220deg)); }
}
@media (prefers-reduced-motion: reduce) {
  .confetti-piece { display: none; }
}

/* =========================================================================
   États divers
   ========================================================================= */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--parchment-faint);
}
.ink-dots { display: flex; gap: 8px; }
.ink-dots span {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--plume-gold);
  animation: ink-pulse 1.1s ease-in-out infinite;
}
.ink-dots span:nth-child(2) { animation-delay: .15s; }
.ink-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes ink-pulse { 0%,80%,100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

.empty-state, .error-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--parchment-faint);
}
.error-state .btn { margin-top: var(--space-4); }

/* =========================================================================
   Toast générique (temps écoulé, etc.)
   ========================================================================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  color: var(--parchment);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 50;
  animation: banner-in .25s var(--ease-out);
  box-shadow: 0 8px 24px -8px rgba(0,0,0,0.5);
}

/* =========================================================================
   Repères de progression pulsés (chapitre recommandé mis en avant au retour
   sur la carte après un résultat)
   ========================================================================= */
@media (prefers-reduced-motion: no-preference) {
  .chapter-card.is-highlighted { animation: highlight-pulse 1.6s var(--ease-out); }
}
@keyframes highlight-pulse {
  0% { box-shadow: 0 0 0 0 rgba(227,173,70,0.6); }
  60% { box-shadow: 0 0 0 14px rgba(227,173,70,0); }
  100% { box-shadow: 0 0 0 0 rgba(227,173,70,0); }
}

/* =========================================================================
   Responsive — tablette / bureau
   ========================================================================= */
@media (min-width: 700px) {
  #app { padding-bottom: var(--space-6); }
  .tabbar {
    position: static;
    background: none;
    padding: 0 var(--space-4) var(--space-3);
    justify-content: flex-start;
  }
  .tabbar__inner { max-width: 260px; }
  .view { padding: 0 var(--space-5) var(--space-7); }
  .greeting h1 { font-size: 2rem; }
  .chapter-grid { grid-template-columns: 1fr 1fr; }
  .exercise-card { padding: var(--space-6); }
  .results-stars .icon { width: 48px; height: 48px; }
}

@media (min-width: 960px) {
  #app { max-width: 800px; }
  .chapter-grid { grid-template-columns: 1fr 1fr 1fr; }
}

/* iOS Safari : evite le zoom auto au focus d'un champ (exige font-size >= 16px) - ajoute 19/08/2026 */
input, select, textarea { font-size: 16px !important; }

/* Widget progression hebdo — home */
.weekly-widget {
  margin-top: 20px;
}

.weekly-streak-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 6px;
}

.weekly-chart {
  display: flex;
  align-items: stretch;
  gap: 10px;
  height: 140px;
  margin: 18px 0 14px;
}

.weekly-chart__col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.weekly-chart__value {
  font-family: "Space Mono", monospace;
  font-size: 12px;
  color: var(--parchment-dim);
}

.weekly-chart__track {
  width: 100%;
  max-width: 30px;
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--ink-800);
  border-radius: 12px;
  overflow: hidden;
}

.weekly-chart__bar {
  display: block;
  width: 100%;
  background: linear-gradient(180deg, var(--plume-gold, #e3ad46), var(--sceau, #d1483f));
  border-radius: 12px 12px 6px 6px;
  min-height: 0;
  opacity: 0.9;
  transition: height 0.4s ease;
}

.weekly-chart__col.is-current .weekly-chart__track {
  background: rgba(209, 72, 63, 0.12);
}

.weekly-chart__col.is-current .weekly-chart__bar {
  background: var(--sceau, #d1483f);
  opacity: 1;
}

.weekly-chart__label {
  font-size: 11px;
  font-family: "Figtree", sans-serif;
  color: var(--parchment-dim);
  white-space: nowrap;
}

.weekly-chart__col.is-current .weekly-chart__label {
  color: var(--sceau, #d1483f);
  font-weight: 700;
}

.weekly-totals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.weekly-total {
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: 14px;
  padding: 12px 10px;
  text-align: center;
}

.weekly-total__label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--parchment-dim);
  margin-bottom: 6px;
}

.weekly-total__value {
  font-family: "Space Mono", monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--parchment);
}

.weekly-widget__hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--parchment-dim);
}

/* =========================================================================
   FICHE — carte mentale affichée avant le QCM (chapter-intro).
   Tout est affiché en permanence (pas de plier/déplier), navigation par
   pincer-zoomer. En portrait mobile, un écran invite à tourner le
   téléphone (largeur nécessaire pour que les branches respirent).
   ========================================================================= */
.fiche-container { margin: 20px 0; }

.fiche-rotate-gate {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  gap: 16px;
  background: var(--ink-900);
  border: 1px solid var(--ink-700);
  border-radius: var(--radius-lg);
}
.fiche-rotate-gate__icon {
  width: 56px; height: 56px;
  color: var(--plume-gold);
  animation: ficheRotateHint 1.8s ease-in-out infinite;
}
@keyframes ficheRotateHint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}
.fiche-rotate-gate h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  margin: 0;
}
.fiche-rotate-gate p {
  color: var(--parchment-dim);
  font-size: .88rem;
  max-width: 280px;
  line-height: 1.5;
  margin: 0;
}
.fiche-rotate-gate__bypass {
  background: none;
  border: none;
  color: var(--parchment-faint);
  font-size: .78rem;
  text-decoration: underline;
  cursor: pointer;
  margin-top: 4px;
  font-family: var(--font-body);
}
@media (orientation: portrait) and (max-width: 820px) {
  .fiche-rotate-gate { display: flex; }
  .fiche-map-wrap { display: none; }
  .fiche-container.force-show .fiche-rotate-gate { display: none; }
  .fiche-container.force-show .fiche-map-wrap { display: block; }
}

.fiche-map {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto auto;
  column-gap: 60px;
  row-gap: 44px;
  align-items: center;
  justify-items: stretch;
  padding: 10px 0;
}

/* Le hub occupe sa propre ligne de grille : jamais de chevauchement possible
   avec les branches, quelle que soit la longueur de leur contenu. */
.fiche-hub {
  position: relative;
  z-index: 2;
  grid-column: 1 / -1;
  grid-row: 2;
  justify-self: center;
  width: 220px;
  padding: 20px 18px 16px;
  text-align: center;
  background:
    radial-gradient(120% 140% at 50% -10%, rgba(209,72,63,.2), transparent 60%),
    var(--ink-900);
  border: 1.5px solid var(--sceau-dark);
  border-radius: 999px / 44%;
  box-shadow: 0 0 0 1px rgba(209,72,63,.14), 0 20px 50px -20px rgba(0,0,0,.7);
}

/* Rayons : un petit trait par branche, ancré à son coin interieur, plutot
   qu un unique overlay qui suppose une position fixe du hub (fragile des
   que le contenu d une branche est plus long que prevu). */
.fiche-branch__stub { position: absolute; width: 70px; height: 50px; pointer-events: none; z-index: 0; }
.fiche-branch__stub path { fill: none; stroke-width: 2.4; stroke-linecap: round; opacity: .9; }
.fiche-branch--tl .fiche-branch__stub { right: -50px; bottom: -40px; }
.fiche-branch--tr .fiche-branch__stub { left: -50px; bottom: -40px; }
.fiche-branch--bl .fiche-branch__stub { right: -50px; top: -40px; }
.fiche-branch--br .fiche-branch__stub { left: -50px; top: -40px; }
.fiche-hub__matiere {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--sceau);
  margin-bottom: 8px;
}
.fiche-hub h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.28rem;
  line-height: 1.18;
}
.fiche-hub__icon { width: 70px; height: 50px; margin: 10px auto 0; }
.fiche-hub__icon svg { width: 100%; height: 100%; display: block; }

.fiche-branch {
  position: relative;
  z-index: 1;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--branch-color);
  background: var(--ink-900);
  overflow: hidden;
  width: 320px;
}
.fiche-branch--tl { grid-column: 1; grid-row: 1; justify-self: end; align-self: end; }
.fiche-branch--tr { grid-column: 2; grid-row: 1; justify-self: start; align-self: end; }
.fiche-branch--bl { grid-column: 1; grid-row: 3; justify-self: end; align-self: start; }
.fiche-branch--br { grid-column: 2; grid-row: 3; justify-self: start; align-self: start; }

.fiche-branch__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  background: color-mix(in srgb, var(--branch-color) 14%, var(--ink-900));
}
.fiche-branch__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--branch-color); flex-shrink: 0; }
.fiche-branch__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.08rem;
  color: var(--branch-color);
  flex: 1;
  line-height: 1.2;
}
.fiche-branch__body { padding: 16px 16px 14px; }
.fiche-branch__body .fiche-diagram { max-width: 220px; margin: 0 auto 14px; }

.fiche-diagram {
  padding: 12px 8px 10px;
  background: var(--ink-950);
  border: 1px solid var(--ink-800);
  border-radius: var(--radius-sm);
  text-align: center;
}
.fiche-diagram-svg { width: 100%; height: auto; display: block; margin: 0 auto; }
.fiche-diagram-svg text { font-family: var(--font-mono); font-size: 13px; font-style: italic; }
.fiche-diagram-caption { margin-top: 8px; font-size: .76rem; color: var(--parchment-faint); font-style: italic; }

.fiche-item { padding: 8px 0; border-top: 1px solid var(--ink-800); }
.fiche-item:first-of-type { border-top: none; padding-top: 0; }
.fiche-item__label { font-weight: 700; font-size: .94rem; color: var(--parchment); margin-bottom: 2px; }
.fiche-item__detail { font-size: .88rem; color: var(--parchment-dim); line-height: 1.4; }
.fiche-item__detail .fmath {
  font-family: var(--font-mono); font-size: .82rem; background: var(--ink-800);
  padding: 1px 6px; border-radius: 5px; color: var(--parchment);
}
.fiche-item__example {
  margin-top: 4px; font-size: .82rem; font-style: italic; color: var(--parchment-faint);
  padding-left: 9px; border-left: 2px solid var(--ink-700);
}
