:root {
  --current-body-font: var(--font-primary);
  --current-heading-font: var(--font-heading);
}

/* Polices d'accessibilité */
[data-accessibility-font="opendyslexic"] {
  --current-body-font: "OpenDyslexic", Arial, sans-serif;
  --current-heading-font: "OpenDyslexic", Arial, sans-serif;
}

[data-accessibility-font="atkinson"] {
  --current-body-font: "Atkinson Hyperlegible", Arial, sans-serif;
  --current-heading-font: "Atkinson Hyperlegible", Arial, sans-serif;
}

[data-accessibility-font="lexend"] {
  --current-body-font: "Lexend", Arial, sans-serif;
  --current-heading-font: "Lexend", Arial, sans-serif;
}

/* Force l'application globale - écrase les styles scoped */
[data-accessibility-font] * {
  font-family: var(--current-body-font) !important;
}

[data-accessibility-font] h1,
[data-accessibility-font] h2,
[data-accessibility-font] h3,
[data-accessibility-font] h4,
[data-accessibility-font] h5,
[data-accessibility-font] h6 {
  font-family: var(--current-heading-font) !important;
}

/* Ciblage spécifique des classes problématiques */
[data-accessibility-font] .collection-title,
[data-accessibility-font] .article-title,
[data-accessibility-font] .nav-link,
[data-accessibility-font] .nav-button,
[data-accessibility-font] .submenu-link,
[data-accessibility-font] .menu-title,
[data-accessibility-font] .section-title {
  font-family: var(--current-heading-font) !important;
}

[data-accessibility-font] .collection-description,
[data-accessibility-font] .article-excerpt,
[data-accessibility-font] .article-content,
[data-accessibility-font] .breadcrumb-link {
  font-family: var(--current-body-font) !important;
}

/* Espacement amélioré pour OpenDyslexic */
[data-accessibility-font="opendyslexic"] {
  letter-spacing: 0.05em;
  word-spacing: 0.1em;
  line-height: 1.6;
}

[data-accessibility-font="opendyslexic"] .article-content {
  line-height: 1.8;
}

/* Rendu plus net pour Atkinson */
[data-accessibility-font="atkinson"] {
  font-feature-settings: "kern", "liga";
  text-rendering: optimizeLegibility;
}

/* Optimisation pour Lexend */
[data-accessibility-font="lexend"] {
  letter-spacing: 0.02em;
  line-height: 1.5;
}
/* ========================================
   RESET CSS MODERNE
   ======================================== */

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

* {
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  /* Amélioration pour les petits écrans */
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: var(--accessibility-font, var(--font-primary));
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition:
    background-color 0.3s ease,
    color 0.3s ease;
  /* Amélioration de la lisibilité */
  word-spacing: 0.05em;
  hanging-punctuation: first last;
}

/* ========================================
   ÉLÉMENTS MÉDIA
   ======================================== */

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Images responsives avec lazy loading */
img {
  font-style: italic;
  background-repeat: no-repeat;
  background-size: cover;
  shape-margin: 0.75rem;
}

/* ========================================
   ÉLÉMENTS DE FORMULAIRE
   ======================================== */

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* Amélioration des champs de formulaire */
input:not([type="submit"]):not([type="button"]):not([type="reset"]),
textarea,
select {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  padding: 0.75rem;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
  width: 100%;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ========================================
   TYPOGRAPHIE AMÉLIORÉE
   ======================================== */

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
  /* Amélioration pour les longues URLs et mots */
  word-break: break-word;
  hyphens: auto;
}

/* Hiérarchie typographique claire */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-heading);
  line-height: 1.3;
  font-weight: 400;
  color: var(--text-primary);
  /* Espacement vertical amélioré */
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

/* Première heading sans marge top */
h1:first-child,
h2:first-child,
h3:first-child,
h4:first-child,
h5:first-child,
h6:first-child {
  margin-top: 0;
}

/* Tailles responsives améliorées */
h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 800;
}

h2 {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  font-weight: 400;
}

h3 {
  font-size: clamp(1.25rem, 3vw, 2rem);
  font-weight: 600;
}

h4 {
  font-size: clamp(1.125rem, 2.5vw, 1.5rem);
  font-weight: 600;
}

h5 {
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 500;
}

h6 {
  font-size: clamp(0.875rem, 1.5vw, 1.125rem);
  font-weight: 500;
}

/* Paragraphes optimisés pour la lecture */
p {
  line-height: 1.7;
  margin-bottom: 1.25rem;
  max-width: 70ch; /* Largeur optimale pour la lisibilité */
}

/* Amélioration des listes */
ul,
ol {
  margin-bottom: 1.25rem;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

/* Listes sans puces pour la navigation */
nav ul {
  list-style: none;
  padding-left: 0;
}

/* ========================================
   LIENS AMÉLIORÉS
   ======================================== */

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition:
    color 0.2s ease,
    text-decoration 0.2s ease;
  /* Amélioration de la zone de clic */
  padding: 0.125rem 0.25rem;
  margin: -0.125rem -0.25rem;
  border-radius: 0.25rem;
}

a:hover {
  color: var(--accent-secondary);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.25em;
}

a:focus {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: 0.25rem;
  text-decoration: none;
}

/* Liens externes */
a[href^="http"]:not([href*="votre-domaine.com"])::after {
  content: " ↗";
  font-size: 0.875em;
  opacity: 0.7;
}

/* ========================================
   BOUTONS SYSTÈME
   ======================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.5rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 1rem;
  line-height: 1;
  min-height: 44px; /* Accessibilité tactile */
  min-width: 44px;
}

.btn-primary {
  background: var(--accent-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-secondary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow-strong);
}

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

.btn-secondary {
  background: transparent;
  color: var(--accent-primary);
  border: 2px solid var(--accent-primary);
}

.btn-secondary:hover {
  background: var(--accent-primary);
  color: white;
}

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-ghost:hover {
  background: var(--bg-secondary);
  border-color: var(--accent-primary);
}

/* Boutons désactivés */
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

/* ========================================
   ACCESSIBILITÉ AVANCÉE
   ======================================== */

/* Screen reader only */
.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;
}

/* Focus visible polyfill */
.js-focus-visible :focus:not(.focus-visible) {
  outline: none;
}

/* Skip to content link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--accent-primary);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  border-radius: 0 0 4px 4px;
  z-index: 1000;
  font-weight: 600;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
}

/* Amélioration du focus visible */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Focus pour le contenu principal */
main:focus {
  outline: none;
}

/* ========================================
   ANIMATIONS RESPECTUEUSES
   ======================================== */

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* Classes d'animation */
.animate-fade-in {
  animation: fadeIn 0.5s ease;
}

.animate-fade-in-up {
  animation: fadeInUp 0.6s ease;
}

.animate-slide-in-left {
  animation: slideInLeft 0.5s ease;
}

.animate-pulse {
  animation: pulse 2s infinite;
}

/* ========================================
   CLASSES UTILITAIRES ÉTENDUES
   ======================================== */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.container-sm {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 1rem;
}
.container-md {
  max-width: 768px;
  margin: 0 auto;
  padding: 0 1rem;
}
.container-lg {
  max-width: 1024px;
  margin: 0 auto;
  padding: 0 1rem;
}
.container-xl {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Alignement de texte */
.text-center {
  text-align: center;
}
.text-left {
  text-align: left;
}
.text-right {
  text-align: right;
}
.text-justify {
  text-align: justify;
}

/* Espacement vertical */
.space-y-1 > * + * {
  margin-top: 0.25rem;
}
.space-y-2 > * + * {
  margin-top: 0.5rem;
}
.space-y-3 > * + * {
  margin-top: 0.75rem;
}
.space-y-4 > * + * {
  margin-top: 1rem;
}
.space-y-6 > * + * {
  margin-top: 1.5rem;
}
.space-y-8 > * + * {
  margin-top: 2rem;
}

/* Marges */
.mb-0 {
  margin-bottom: 0;
}
.mb-1 {
  margin-bottom: 0.25rem;
}
.mb-2 {
  margin-bottom: 0.5rem;
}
.mb-3 {
  margin-bottom: 0.75rem;
}
.mb-4 {
  margin-bottom: 1rem;
}
.mb-6 {
  margin-bottom: 1.5rem;
}
.mb-8 {
  margin-bottom: 2rem;
}

.mt-0 {
  margin-top: 0;
}
.mt-1 {
  margin-top: 0.25rem;
}
.mt-2 {
  margin-top: 0.5rem;
}
.mt-3 {
  margin-top: 0.75rem;
}
.mt-4 {
  margin-top: 1rem;
}
.mt-6 {
  margin-top: 1.5rem;
}
.mt-8 {
  margin-top: 2rem;
}

/* Padding */
.p-0 {
  padding: 0;
}
.p-1 {
  padding: 0.25rem;
}
.p-2 {
  padding: 0.5rem;
}
.p-3 {
  padding: 0.75rem;
}
.p-4 {
  padding: 1rem;
}
.p-6 {
  padding: 1.5rem;
}
.p-8 {
  padding: 2rem;
}

/* Border radius */
.rounded {
  border-radius: 0.375rem;
}
.rounded-lg {
  border-radius: 0.5rem;
}
.rounded-xl {
  border-radius: 0.75rem;
}
.rounded-2xl {
  border-radius: 1rem;
}
.rounded-full {
  border-radius: 9999px;
}

/* Ombres */
.shadow-sm {
  box-shadow: 0 1px 2px 0 var(--shadow-light);
}
.shadow {
  box-shadow: 0 1px 3px 0 var(--shadow);
}
.shadow-lg {
  box-shadow: 0 10px 15px -3px var(--shadow-strong);
}
.shadow-xl {
  box-shadow: 0 20px 25px -5px var(--shadow-strong);
}

/* Visibilité */
.hidden {
  display: none;
}
.invisible {
  visibility: hidden;
}
.visible {
  visibility: visible;
}

/* ========================================
   RESPONSIVE ET ACCESSIBILITÉ
   ======================================== */

@media (max-width: 640px) {
  .container {
    padding: 0 0.75rem;
  }

  /* Amélioration tactile sur mobile */
  button,
  .btn,
  a {
    min-height: 44px;
    min-width: 44px;
  }

  /* Espacement amélioré sur mobile */
  p {
    margin-bottom: 1.5rem;
  }
}

/* Respect des préférences utilisateur */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .animate-fade-in,
  .animate-fade-in-up,
  .animate-slide-in-left,
  .animate-pulse {
    animation: none;
  }
}

/* Mode haut contraste */
@media (prefers-contrast: high) {
  .btn {
    border: 2px solid currentColor;
  }

  a:hover {
    text-decoration: underline;
    text-decoration-thickness: 3px;
  }
}

/* ========================================
   STYLES D'IMPRESSION
   ======================================== */

@media print {
  .no-print {
    display: none !important;
  }

  body {
    background: white !important;
    color: black !important;
    font-size: 12pt;
    line-height: 1.5;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    break-after: avoid;
    color: black !important;
  }

  a {
    color: black !important;
    text-decoration: underline !important;
  }

  /* Afficher les URLs des liens */
  a[href^="http"]:after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }

  .btn {
    border: 1px solid black !important;
    background: white !important;
    color: black !important;
  }
}
