/* =========================================================
   Calcul mental — feuille de style
   Charte ProjetV : minimaliste noir & blanc, sobre.
   Le thème sombre ne fait que redéfinir les variables.
   ========================================================= */

/* ---------- 1. Variables : thème clair (charte ProjetV) ---------- */
:root {
  --primary: #000000;
  --primary-light: #333333;
  --accent: #3b82f6;
  --bg-body: linear-gradient(135deg, #f5f5f5 0%, #ffffff 100%);
  --bg-container: #ffffff;
  --text-primary: #000000;
  --text-secondary: #666666;
  --text-inverse: #ffffff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gray-200: #e5e5e5;
  --gray-400: #a3a3a3;
  --shadow: 0 10px 40px rgba(0,0,0,0.08);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);

  /* Variables complémentaires (lisibilité du feedback) */
  --success-bg: rgba(16, 185, 129, 0.10);
  --danger-bg: rgba(239, 68, 68, 0.08);
  --success-text: #047857;
  --danger-text: #b91c1c;
  --danger-hover: #dc2626;

  /* Graphiques (couleurs vérifiées : contraste et daltonisme) */
  --chart-series: #3b82f6;              /* série mise en avant */
  --chart-muted: #8a8a8a;               /* série de fond (valeurs brutes) */
  --chart-track: rgba(59, 130, 246, 0.16); /* fond des jauges */
  --chart-grid: #ececec;
  --chart-axis: #d4d4d4;
  --chart-crosshair: #a3a3a3;
  --chart-band: rgba(0, 0, 0, 0.04);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --speed: 0.2s;

  color-scheme: light;
}

/* ---------- 2. Variables : thème sombre ---------- */
[data-theme="dark"] {
  --primary: #ffffff;
  --primary-light: #d4d4d4;
  --accent: #60a5fa;
  --bg-body: linear-gradient(135deg, #0f0f0f 0%, #151515 100%);
  --bg-container: #1a1a1a;
  --text-primary: #ffffff;
  --text-secondary: #a3a3a3;
  --text-inverse: #000000;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gray-200: #2a2a2a;
  --gray-400: #6b6b6b;
  --shadow: 0 10px 40px rgba(0,0,0,0.45);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.30);

  --success-bg: rgba(16, 185, 129, 0.14);
  --danger-bg: rgba(239, 68, 68, 0.14);
  --success-text: #34d399;
  --danger-text: #f87171;

  --chart-series: #4a8ef7;
  --chart-muted: #6b6b6b;
  --chart-track: rgba(74, 142, 247, 0.22);
  --chart-grid: #262626;
  --chart-axis: #3a3a3a;
  --chart-crosshair: #6b6b6b;
  --chart-band: rgba(255, 255, 255, 0.05);

  color-scheme: dark;
}

/* ---------- 3. Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-container);
  background-image: var(--bg-body);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  transition: color var(--speed) ease;
}

h1, h2, h3, p, figure {
  margin: 0;
}

[tabindex="-1"]:focus {
  outline: none;
}

kbd {
  font-family: inherit;
  font-size: 0.85em;
  font-weight: 600;
  padding: 0.1em 0.45em;
  border: 1px solid var(--gray-200);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-container);
}

/* Masqué visuellement, mais lu par les lecteurs d'écran et focalisable */
.visually-hidden {
  position: absolute !important;
  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;
  top: -100px;
  left: 1rem;
  z-index: 100;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--text-inverse);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 0.5rem;
}

/* ---------- 4. En-tête ---------- */
.site-header {
  height: 10vh;
  min-height: 60px;
  background: var(--bg-container);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 1200px;
  height: 100%;
  margin: 0 auto;
  padding: 0 2rem;
}

.site-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0.45rem 0.9rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--speed) ease, color var(--speed) ease;
}

.theme-toggle:hover {
  border-color: var(--primary);
  color: var(--text-primary);
}

.theme-icon {
  display: inline-flex;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Onglets Jouer / Profil */
.site-nav {
  display: flex;
  gap: 0.25rem;
}

.nav-link {
  min-height: 40px;
  padding: 0.45rem 0.75rem;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--speed) ease, border-color var(--speed) ease;
}

.nav-link:hover {
  color: var(--text-primary);
}

.nav-link[aria-current="page"] {
  border-bottom-color: var(--primary);
  color: var(--text-primary);
}

.nav-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- 5. Mise en page ---------- */
.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 2.5rem 2rem 4rem;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ---------- 6. Cartes, titres, libellés ---------- */
.card {
  background: var(--bg-container);
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 2.5rem 2rem;
  transition: border-color var(--speed) ease, background-color var(--speed) ease;
}

.card-title {
  margin: 0 0 1.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--gray-200);
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
}

.label,
.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
}

.field {
  min-width: 0;
  margin: 0 0 1.75rem;
  padding: 0;
  border: 0;
}

.field > legend.label {
  display: block;
  padding: 0 0 0.75rem;
}

.field-label {
  display: block;
}

.hint {
  margin-top: 0.625rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.hint.is-error {
  color: var(--danger-text);
  font-weight: 600;
}

.hint:empty {
  display: none;
}

.empty {
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

/* ---------- 7. Pastilles sélectionnables (vrais inputs masqués) ---------- */
.chips {
  --cols: 3;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 0.625rem;
}

.chips-2 { --cols: 2; }
.chips-3 { --cols: 3; }
.chips-4 { --cols: 4; }

.chip {
  position: relative;
  display: block;
  cursor: pointer;
}

.chip-face {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-height: 48px;
  height: 100%;
  padding: 0.625rem 0.75rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
  hyphens: auto;
  overflow-wrap: break-word;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chip-face--stacked {
  flex-direction: column;
  gap: 0.125rem;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}

.chip-symbol {
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.1;
}

.chip:hover .chip-face {
  border-color: var(--primary);
  color: var(--text-primary);
}

.chip input:checked + .chip-face {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-inverse);
}

.chip input:focus-visible + .chip-face {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- 8. Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.8rem 1.5rem;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--speed) ease, border-color var(--speed) ease,
    color var(--speed) ease, transform 0.15s ease;
}

.btn:focus-visible,
.btn-ghost:focus-visible,
.theme-toggle:focus-visible,
.skip-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-inverse);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-light);
  border-color: var(--primary-light);
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: transparent;
  border-color: var(--gray-200);
  color: var(--text-secondary);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Bouton discret (abandon) */
.btn-ghost {
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  cursor: pointer;
  transition: color var(--speed) ease;
}

.btn-ghost:hover {
  color: var(--danger-text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- 9. Champs ---------- */
.input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: var(--bg-container);
  color: var(--text-primary);
  font: inherit;
  transition: border-color var(--speed) ease;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ---------- 10. Accueil ---------- */
.home-record {
  margin-bottom: 1.25rem;
  padding-top: 1.25rem;
  border-top: 2px solid var(--gray-200);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ---------- 10 bis. Aide dépliable (point d'interrogation) ----------
   Fermée : un rond « ? » de 30 px. Ouverte : la bulle s'élargit sur
   toute la largeur du réglage, puis le panneau se déroule. Elle passe
   par-dessus le contenu (position absolue) : rien ne bouge en dessous. */
.field-help {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 30px;
  margin-top: 0.75rem;
  padding-left: 42px; /* place réservée au « ? » */
}

.field-help .hint {
  margin-top: 0;
}

.help {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  width: 30px;
  overflow: hidden;
  border: 2px solid var(--gray-200);
  border-radius: 15px;
  background: var(--bg-container);
  /* Fermeture : le panneau se replie d'abord, puis la bulle redevient un rond */
  transition: width 0.25s ease 0.2s, border-radius 0.25s ease 0.2s,
    border-color 0.2s ease, box-shadow 0.2s ease;
}

.help.is-open {
  z-index: 6;
  width: 100%;
  border-color: var(--primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  /* Ouverture : la bulle s'élargit d'abord, puis le panneau se déroule */
  transition: width 0.25s ease, border-radius 0.25s ease,
    border-color 0.2s ease, box-shadow 0.2s ease;
}

.help-toggle {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: padding 0.25s ease 0.2s;
}

/* Une fois ouverte, le « ? » se décolle du bord en même temps que la bulle s'élargit */
.help.is-open .help-toggle {
  padding: 0.375rem 0.5rem;
  transition: padding 0.25s ease;
}

.help-toggle:focus {
  outline: none;
}

/* Anneau de focus clavier dessiné à l'intérieur (la bulle coupe ce qui dépasse) */
.help-toggle:focus-visible .help-icon {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.help-icon {
  display: flex;
  flex: 0 0 26px;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.help:hover .help-icon,
.help.is-open .help-icon {
  background: var(--primary);
  color: var(--text-inverse);
}

.help-title {
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.help.is-open .help-title {
  color: var(--text-primary);
  opacity: 1;
  transition: opacity 0.2s ease 0.1s;
}

/* Hauteur animée de 0 à « auto » grâce à grid-template-rows */
.help-panel {
  display: grid;
  grid-template-rows: 0fr;
  visibility: hidden;
  transition: grid-template-rows 0.25s ease, visibility 0s linear 0.25s;
}

.help.is-open .help-panel {
  grid-template-rows: 1fr;
  visibility: visible;
  transition: grid-template-rows 0.3s ease 0.2s, visibility 0s linear 0s;
}

.help-panel-inner {
  min-height: 0;
  overflow: hidden;
}

.help-list {
  display: grid;
  gap: 0.625rem;
  margin: 0;
  padding: 0.375rem 1rem 1rem 2.75rem; /* aligné sous le titre */
}

/* Barème de rapidité : deux colonnes */
.help-list--cols {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1.25rem;
}

.help-item dt {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text-primary);
}

.help-item dd {
  margin: 0.125rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

/* Un exemple de calcul ne se coupe jamais en fin de ligne */
.help .math {
  white-space: nowrap;
}

.help-note {
  margin: -0.25rem 1rem 1rem 2.75rem;
  padding-top: 0.625rem;
  border-top: 1px solid var(--gray-200);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ---------- 11. Écran de jeu ---------- */
.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
  margin: 0;
}

.stat {
  display: flex;
  flex-direction: column;
  min-width: 88px;
  padding: 0.5rem 0.875rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: var(--bg-container);
}

.stat-label {
  font-size: 0.6875rem;
}

.stat-value {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.lives {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 1.6875rem;
}

.life {
  width: 12px;
  height: 12px;
  border: 2px solid var(--primary);
  border-radius: 50%;
  background: var(--primary);
  transition: background-color var(--speed) ease, border-color var(--speed) ease;
}

.life.is-lost {
  background: transparent;
  border-color: var(--gray-400);
}

.game-card {
  container-type: inline-size; /* permet d'adapter la taille du calcul à la carte */
  padding: 2rem 2rem 2.25rem;
  text-align: center;
}

.game-card.is-correct {
  border-color: var(--success);
  background-image: linear-gradient(var(--success-bg), var(--success-bg));
}

.game-card.is-wrong {
  border-color: var(--danger);
  background-image: linear-gradient(var(--danger-bg), var(--danger-bg));
}

/* Calcul affiché en très grand. --chars (posé par app.js) = longueur du calcul
   avec sa réponse : la taille est choisie pour que tout tienne sur une ligne. */
.question {
  margin-bottom: 2rem;
  font-size: clamp(2rem, 8vw, 4rem); /* repli sans container queries */
  font-size: clamp(1.75rem, calc(100cqi / (var(--chars, 12) * 0.62)), 5rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.question-answer {
  color: var(--text-secondary);
}

.game-card.is-correct .question-answer {
  color: var(--success-text);
}

.game-card.is-wrong .question-answer {
  color: var(--danger-text);
}

/* Saisie de la réponse */
.answer-form {
  max-width: 440px;
  margin: 0 auto;
}

.answer-row {
  display: flex;
  gap: 0.75rem;
}

.answer-input {
  flex: 1;
  min-width: 0;
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.answer-input.is-correct {
  border-color: var(--success);
}

.answer-input.is-wrong {
  border-color: var(--danger);
}

.btn-sign {
  flex: 0 0 auto;
  width: 60px;
  padding: 0;
  font-size: 1.5rem;
}

.btn-submit {
  flex: 0 0 auto;
}

.feedback {
  min-height: 1.5em;
  margin-top: 1.25rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.feedback.is-correct {
  color: var(--success-text);
}

.feedback.is-wrong {
  color: var(--danger-text);
}

.game-hint {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-align: center;
}

/* ---------- 12. Résultats ---------- */
.results-card {
  text-align: center;
}

.record-badge {
  display: inline-block;
  margin-bottom: 1.25rem;
  padding: 0.375rem 0.875rem;
  border-radius: 999px;
  background: var(--primary);
  color: var(--text-inverse);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.results-score {
  font-size: clamp(3rem, 12vw, 5rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}

.results-total {
  font-size: 0.5em;
  font-weight: 700;
  color: var(--text-secondary);
}

.results-caption {
  margin-top: 0.5rem;
  color: var(--text-secondary);
}

.results-config {
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.results-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 2rem 0 0;
}

.results-stat {
  min-width: 0;
  padding: 1rem 0.75rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
}

/* Grands chiffres isolés : chiffres proportionnels (pas tabular-nums) */
.results-stat dd {
  margin: 0.25rem 0 0;
  font-size: 1.5rem;
  font-weight: 700;
  white-space: nowrap;
}

/* Tableau des questions ratées */
.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.table th {
  padding: 0 0.75rem 0.75rem;
  border-bottom: 2px solid var(--gray-200);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  text-align: left;
}

.table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--gray-200);
  font-weight: 600;
}

.table tr:last-child td {
  border-bottom: 0;
}

.table th:first-child,
.table td:first-child {
  padding-left: 0;
}

.table .is-wrong {
  color: var(--danger-text);
}

.table .is-right {
  color: var(--success-text);
}

/* ---------- 13. Historique & records ---------- */
.list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--gray-200);
}

.list-item:first-child {
  padding-top: 0;
}

.list-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.list-main {
  min-width: 0;
}

.list-title {
  font-size: 0.9375rem;
  font-weight: 600;
}

.list-meta {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.list-score {
  flex: 0 0 auto;
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- 13 bis. Profil ---------- */
.page-title {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin-top: 0.25rem;
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

.profile-content,
.profile-body {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.profile-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.25rem;
}

/* Filtres : une seule ligne au-dessus de tout ce qu'ils filtrent */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
}

.filter {
  position: relative;
  display: flex;
  flex: 0 1 220px;
  flex-direction: column;
  gap: 0.375rem;
  min-width: 0;
}

.filter-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
}

/* Petite flèche de la liste déroulante, dessinée en CSS */
.filter::after {
  content: '';
  position: absolute;
  right: 1rem;
  bottom: 21px;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
  transform: rotate(45deg);
  pointer-events: none;
}

.select {
  width: 100%;
  min-height: 48px;
  padding: 0.625rem 2.5rem 0.625rem 1rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: var(--bg-container);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--speed) ease;
}

.select:hover {
  border-color: var(--primary);
}

.select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Tuiles de chiffres clés (chiffres proportionnels) */
.kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0;
}

.kpi {
  min-width: 0;
  padding: 1rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
}

.kpi-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
}

.kpi-value {
  margin: 0.25rem 0 0;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
}

.kpi-detail,
.kpi-delta {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.kpi-delta {
  font-weight: 600;
  white-space: nowrap;
}

.kpi-delta.is-good {
  color: var(--success-text);
}

.kpi-delta.is-bad {
  color: var(--danger-text);
}

.kpi-delta-icon {
  font-size: 0.75em;
}

.kpi-compare {
  margin-top: 1rem;
}

/* En-tête de graphique : explication + légende */
.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  margin-bottom: 1.5rem;
}

.chart-intro {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.chart-intro:empty {
  display: none;
}

.chart-intro + .chart,
.chart-intro + .tier-list {
  margin-top: 1.25rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

/* La clé de légende reprend la marque : un trait pour une courbe */
.legend-key,
.chart-key {
  flex: 0 0 auto;
  width: 16px;
  height: 2px;
  border-radius: 1px;
}

.legend-key--raw,
.chart-key--raw {
  background: var(--chart-muted);
}

.legend-key--avg,
.chart-key--avg {
  background: var(--chart-series);
}

.chart-figure + .chart-figure {
  margin-top: 1.75rem;
}

.chart-caption {
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.chart-caption-note {
  margin-left: 0.375rem;
  font-weight: 400;
  color: var(--text-secondary);
}

/* ---------- 13 ter. Graphiques SVG (charts.js) ---------- */
.chart {
  position: relative;
  width: 100%;
  border-radius: 4px;
  touch-action: pan-y; /* glisser horizontalement parcourt le graphique */
  -webkit-tap-highlight-color: transparent;
}

.chart:focus {
  outline: none;
}

.chart:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.chart-svg {
  display: block;
}

.chart-grid,
.chart-axis,
.chart-crosshair {
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.chart-grid {
  stroke: var(--chart-grid);
}

.chart-axis {
  stroke: var(--chart-axis);
}

.chart-crosshair {
  stroke: var(--chart-crosshair);
}

.chart-tick {
  fill: var(--text-secondary);
  font-family: var(--font);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-end-label {
  fill: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line--raw {
  stroke: var(--chart-muted);
}

.chart-line--avg {
  stroke: var(--chart-series);
}

/* Anneau de 2 px couleur du fond autour des points */
.chart-dot {
  stroke: var(--bg-container);
  stroke-width: 2;
}

.chart-dot--raw {
  fill: var(--chart-muted);
}

.chart-dot--avg {
  fill: var(--chart-series);
}

.chart-bar {
  fill: var(--chart-series);
  transition: opacity 0.15s ease;
}

.chart.is-hovering .chart-bar:not(.is-active) {
  opacity: 0.45;
}

.chart-band {
  fill: var(--chart-band);
}

.chart-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  width: max-content;
  max-width: 240px;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: var(--bg-container);
  box-shadow: var(--shadow);
  font-size: 0.8125rem;
  line-height: 1.4;
  pointer-events: none;
}

.chart-tooltip-title {
  font-weight: 600;
}

.chart-tooltip-sub {
  margin-top: 0.125rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.chart-tooltip-rows {
  display: grid;
  gap: 0.25rem;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
}

.chart-tooltip-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-tooltip-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip-label {
  color: var(--text-secondary);
}

/* Vue tableau des graphiques */
.table-view {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--gray-200);
}

.table-view summary {
  width: max-content;
  max-width: 100%;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.table-view summary:hover {
  color: var(--text-primary);
}

.table-view summary:focus {
  outline: none;
}

.table-view summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.table-view[open] summary {
  margin-bottom: 1rem;
}

.table-scroll {
  max-height: 360px;
  overflow: auto;
}

.table--compact th,
.table--compact td {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  font-size: 0.8125rem;
  white-space: nowrap;
}

.table--compact thead th {
  position: sticky;
  top: 0;
  background: var(--bg-container);
}

.table .is-text {
  font-weight: 400;
}

/* Libellés longs : retour à la ligne pour que toutes les colonnes tiennent */
.table--compact .is-text {
  min-width: 9rem;
  white-space: normal;
}

/* Tableau par opération, avec jauge de réussite */
.table tbody th {
  padding: 0.75rem 0.75rem 0.75rem 0;
  border-bottom: 1px solid var(--gray-200);
  font-size: 0.9375rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-primary);
  white-space: nowrap;
}

.table tbody tr:last-child th {
  border-bottom: 0;
}

/* Filet de sécurité sur très petit écran : le tableau défile dans sa carte */
.table-wrap {
  overflow-x: auto;
}

.ops-symbol {
  display: inline-block;
  width: 1.25rem;
  font-weight: 700;
}

.ops-rate {
  min-width: 6.5rem;
}

.meter {
  display: block;
  height: 6px;
  margin-top: 0.375rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--chart-track);
}

.meter-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--chart-series);
}

/* Répartition par palier du barème */
.tier-list {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tier-list + .hint {
  margin-top: 1rem;
}

.tier-row {
  display: grid;
  grid-template-columns: 9.5rem minmax(0, 1fr) 6rem;
  align-items: center;
  gap: 1rem;
}

.tier-name {
  display: flex;
  flex-direction: column;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
}

.tier-limit {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-secondary);
}

.tier-track {
  display: block;
  height: 14px;
  border-left: 1px solid var(--chart-axis);
}

/* Barre de 14 px, arrondie au bout, carrée sur la ligne de base */
.tier-bar {
  display: block;
  min-width: 2px;
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--chart-series);
}

.tier-value {
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.tier-share {
  margin-left: 0.5rem;
  font-weight: 400;
  color: var(--text-secondary);
}

/* ---------- 14. Boîte de dialogue ---------- */
.dialog {
  width: min(440px, calc(100% - 2rem));
  padding: 2rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--bg-container);
  color: var(--text-primary);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.dialog .card-title {
  margin-bottom: 1rem;
}

.dialog-message {
  color: var(--text-secondary);
}

.dialog-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.75rem;
}

.dialog-actions .btn {
  flex: 1;
}

/* ---------- 15. Tests (tests.html) ---------- */
.test-summary {
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.test-summary.is-correct {
  border-color: var(--success);
  color: var(--success-text);
  background: var(--success-bg);
}

.test-summary.is-wrong {
  border-color: var(--danger);
  color: var(--danger-text);
  background: var(--danger-bg);
}

.test-failures {
  margin: 1.5rem 0 0;
  padding-left: 1.25rem;
  color: var(--danger-text);
  font-size: 0.875rem;
}

/* ---------- 16. Responsive ---------- */
@media (max-width: 900px) {
  .header-inner {
    padding: 0 1.5rem;
  }

  .container {
    padding: 2rem 1.5rem 3rem;
  }

  .chips-4 { --cols: 2; }

  .results-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .header-inner {
    padding: 0 1rem;
  }

  .site-title {
    font-size: 1.125rem;
  }

  .header-actions {
    gap: 0.5rem;
  }

  .nav-link {
    padding: 0.45rem 0.5rem;
  }

  /* Bouton thème : icône seule (le texte reste lu par les lecteurs d'écran) */
  .theme-toggle {
    padding: 0.45rem 0.6rem;
  }

  .theme-toggle-text {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .container {
    padding: 1.25rem 1rem 2.5rem;
  }

  .screen {
    gap: 1rem;
  }

  .card {
    padding: 1.75rem 1.25rem;
  }

  .card-title {
    margin-bottom: 1.25rem;
  }

  .field {
    margin-bottom: 1.5rem;
  }

  .help-list {
    padding: 0.5rem 0.875rem 0.875rem;
  }

  .help-note {
    margin: -0.125rem 0.875rem 0.875rem;
  }

  .help-list--cols {
    grid-template-columns: 1fr;
  }

  /* Profil */
  .page-title {
    font-size: 1.5rem;
  }

  .profile-content,
  .profile-body {
    gap: 1rem;
  }

  .filter {
    flex: 1 1 0;
  }

  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .kpi {
    padding: 0.75rem;
  }

  .kpi-value {
    font-size: 1.25rem;
  }

  .ops-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .ops-rate {
    min-width: 3.75rem;
  }

  .ops-table th,
  .ops-table td {
    padding-left: 0.375rem;
    padding-right: 0.375rem;
    font-size: 0.8125rem;
  }

  .ops-table thead th {
    font-size: 0.625rem;
    letter-spacing: 0.3px;
  }

  .tier-row {
    grid-template-columns: 6.25rem minmax(0, 1fr) 5.25rem;
    gap: 0.625rem;
  }

  .tier-share {
    margin-left: 0.375rem;
  }

  /* Jeu */
  .stats {
    flex: 1 1 100%;
    flex-wrap: nowrap;
  }

  .stat {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.5rem 0.625rem;
  }

  .stat-label {
    font-size: 0.625rem;
    letter-spacing: 0.5px;
  }

  .game-topbar .btn-ghost {
    margin-left: auto;
  }

  .game-card {
    padding: 1.5rem 1.25rem 1.75rem;
  }

  .question {
    margin-bottom: 1.5rem;
  }

  .answer-row {
    flex-wrap: wrap;
  }

  /* Ligne 1 : [±] [réponse] — ligne 2 : Valider pleine largeur */
  .answer-input {
    flex: 1 1 0;
    font-size: 2rem;
  }

  .btn-sign {
    flex: 0 0 64px;
  }

  .btn-submit {
    flex: 1 1 100%;
  }

  .game-hint {
    display: none;
  }

  /* Résultats */
  .results-stats {
    grid-template-columns: 1fr;
  }

  .results-stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
  }

  .results-stat dd {
    margin: 0;
    font-size: 1.25rem;
  }

  .table td,
  .table th {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .list-item {
    align-items: flex-start;
  }

  .dialog {
    padding: 1.5rem 1.25rem;
  }
}

/* ---------- 17. Mouvements réduits ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }

  .btn-primary:hover:not(:disabled) {
    transform: none;
  }
}
