/*
 * Panneau d'accessibilité, et les états qu'il applique à <html>.
 *
 * LE PANNEAU reprend la COMPOSITION du module cookies du parent (fenêtre de
 * préférences et pastille de rappel) — en-tête à pastille d'icône teintée et
 * croix, interrupteurs 42 × 24, boutons, rayon 12 px, ombre douce — mais avec
 * les COULEURS DU SITE, et toujours en clair. Le bandeau cookies suit les mêmes
 * règles (cookies.css), pour que les deux fenêtres restent identiques.
 *
 * Décidé après revue (1er octobre 2026) : le passage automatique en sombre et
 * les gris génériques du module faisaient deux îlots noirs, hors charte, sur un
 * site entièrement clair. Couleurs retenues :
 *
 *   — texte --ink, texte secondaire --ink-3 (5.8:1 sur le blanc) ;
 *   — séparateurs décoratifs --line-soft ;
 *   — bordures des contrôles (tailles, bouton secondaire) et piste éteinte de
 *     l'interrupteur --ink-3 : 5.8:1, au-dessus du 3:1 des composants
 *     d'interface. Les #e5e7eb du module ne donnaient que 1.24:1 ;
 *   — accent --navy ; liseré de focus terra (5.3:1 sur le blanc).
 *
 * Les états appliqués à <html> n'ont pas changé :
 *
 *   — « Police dyslexie » retirée — elle ne faisait rien — et remplacée par
 *     « Espacement du texte renforcé », qui applique le critère WCAG 1.4.12 ;
 *   — « Contraste élevé » est une PALETTE ALTERNATIVE, pas un filter: contrast() ;
 *   — le panneau reste disponible sur téléphone, là où la maquette le masquait.
 */

/* ==========================================================================
   Jetons — la composition du module cookies, les couleurs du site
   ========================================================================== */

.a11y {
  --a11y-bg: var(--paper);
  --a11y-fg: var(--ink);
  --a11y-muted: var(--ink-3);
  --a11y-accent: var(--navy);
  --a11y-accent-fg: #ffffff;
  --a11y-border: var(--line-soft);
  --a11y-control: var(--ink-3);
  --a11y-track: var(--ink-3);
  --a11y-radius: 12px;
  --a11y-shadow: 0 16px 48px -16px rgba(15, 23, 42, 0.35);
}

/*
 * Voile transparent : il n'assombrit rien — on doit voir la page changer pendant
 * qu'on règle — mais il capte le clic hors de la fenêtre pour la fermer. La
 * fenêtre est ainsi modale à la souris comme elle l'est au clavier et pour le
 * lecteur d'écran (aria-modal).
 */
.a11y-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100001;
  background: transparent;
}

.a11y-backdrop[hidden] { display: none; }

/* ==========================================================================
   Pastille d'ouverture — la pastille de rappel des cookies, coin opposé
   ========================================================================== */

.a11y-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 89;
  width: 48px;
  height: 48px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 6px 20px -6px rgba(0, 0, 0, 0.4);
  opacity: 0.9;
  transition: opacity .15s ease, transform .15s ease;
}

.a11y-toggle:hover,
.a11y-toggle[aria-expanded="true"] { opacity: 1; transform: scale(1.06); }

/*
 * La pastille flotte sur toutes les surfaces, pied de page marine compris, où
 * le terra seul ne fait que 2,4:1 : un halo blanc dans l'écart garde le liseré
 * lisible partout (RGAA 10.7).
 */
.a11y-toggle:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  box-shadow: 0 0 0 3px #fff, 0 6px 20px -6px rgba(0, 0, 0, 0.4);
  opacity: 1;
}

.a11y-toggle svg { width: 24px; height: 24px; }

/* ==========================================================================
   Fenêtre
   ========================================================================== */

/*
 * Posée au-dessus de sa pastille, sans voile : on doit voir la page changer
 * pendant qu'on règle. Au-dessus du bandeau cookies (z-index 99999) quand on
 * l'ouvre explicitement.
 */
.a11y {
  position: fixed;
  right: 16px;
  bottom: 76px;
  z-index: 100002;
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--a11y-bg);
  color: var(--a11y-fg);
  border: 1px solid var(--a11y-border);
  border-radius: var(--a11y-radius);
  box-shadow: var(--a11y-shadow);
  font-family: var(--sans);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
}

.a11y.open { opacity: 1; transform: none; }

/* hidden doit l'emporter sur le display: flex. */
.a11y[hidden] { display: none; }

.a11y * { box-sizing: border-box; }

/* --------------------------------------------------------------------------
   En-tête
   -------------------------------------------------------------------------- */

.a11y-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--a11y-border);
}

.a11y-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
  color: var(--a11y-fg);
}

.a11y-title:focus { outline: none; }

/* L'icône du titre, sans pastille teintée : comme le bandeau cookies (cookies.css). */
.a11y-icon {
  flex: none;
  display: inline-flex;
  color: var(--a11y-accent);
}

.a11y-icon svg { width: 26px; height: 26px; }

.a11y-close {
  flex: none;
  display: grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  margin: -10px -12px -10px 0;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--a11y-muted);
  font-size: 1.625rem;
  line-height: 1;
  cursor: pointer;
}

.a11y-close:hover { color: var(--a11y-fg); }

/* --------------------------------------------------------------------------
   Corps
   -------------------------------------------------------------------------- */

.a11y-body {
  padding: 18px 22px;
  overflow-y: auto;
}

.a11y-intro {
  margin: 0 0 18px;
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--a11y-fg);
}

/* De vrais fieldset, dont la bordure est retirée. */
.a11y-group {
  margin: 0 0 20px;
  padding: 0;
  border: none;
}

/* Libellé de groupe : celui des rubriques « À propos » du module cookies. */
.a11y-legend {
  margin-bottom: 8px;
  padding: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--a11y-muted);
}

/* --------------------------------------------------------------------------
   Taille du texte — quatre boutons radio habillés en boutons du module
   -------------------------------------------------------------------------- */

.a11y-sizes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.a11y-size {
  position: relative;
  display: grid;
  place-items: center;
  min-height: var(--touch);
  padding: 8px 4px;
  border: 1px solid var(--a11y-control);
  border-radius: calc(var(--a11y-radius) - 4px);
  background: transparent;
  color: var(--a11y-fg);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.a11y-size:hover { background: var(--bg-alt); }

.a11y-size.is-active {
  background: var(--a11y-accent);
  border-color: var(--a11y-accent);
  color: var(--a11y-accent-fg);
}

.a11y-size:nth-child(1) { font-size: 0.8125rem; }
.a11y-size:nth-child(2) { font-size: 0.9375rem; }
.a11y-size:nth-child(3) { font-size: 1.125rem; }
.a11y-size:nth-child(4) { font-size: 1.3125rem; }

/* Le bouton radio reste dans l'arbre d'accessibilité, mais invisible. */
.a11y-size input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Le focus vit sur l'input masqué : on le remonte sur le bouton visible, au
   clavier seulement — :focus-within l'affichait aussi après un clic. */
.a11y-size:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Interrupteurs — ceux des catégories de cookies
   -------------------------------------------------------------------------- */

.a11y-option {
  padding: 14px 0;
  border-bottom: 1px solid var(--a11y-border);
}

.a11y-option:first-of-type { padding-top: 6px; }
.a11y-option:last-child { border-bottom: none; padding-bottom: 0; }

.a11y-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--touch);
  margin: -10px 0;
  cursor: pointer;
}

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

.a11y-switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--a11y-track);
  transition: background .15s ease;
}

.a11y-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform .15s ease;
}

.a11y-switch-input:checked + .a11y-switch-track { background: var(--a11y-accent); }
.a11y-switch-input:checked + .a11y-switch-track .a11y-switch-thumb { transform: translateX(18px); }

.a11y-switch-input:focus-visible + .a11y-switch-track {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.a11y-switch-label {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--a11y-fg);
}

.a11y-option-desc {
  margin: 8px 0 0 54px;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--a11y-muted);
}

/* --------------------------------------------------------------------------
   Note et pied
   -------------------------------------------------------------------------- */

.a11y-note {
  margin: 4px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--a11y-border);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--a11y-muted);
}

.a11y-note a {
  color: var(--a11y-fg);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.a11y-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 16px 22px;
  border-top: 1px solid var(--a11y-border);
}

/* Les boutons du module : 14 px gras, rayon 8 px. */
.a11y-btn {
  appearance: none;
  min-height: var(--touch);
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: calc(var(--a11y-radius) - 4px);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: filter .15s ease, background .15s ease;
}

.a11y-btn--primary {
  background: var(--a11y-accent);
  border-color: var(--a11y-accent);
  color: var(--a11y-accent-fg);
}

.a11y-btn--primary:hover { filter: brightness(1.08); }

.a11y-btn--ghost {
  background: transparent;
  border-color: var(--a11y-control);
  color: var(--a11y-fg);
}

.a11y-btn--ghost:hover { background: var(--bg-alt); }

.a11y-btn:focus-visible,
.a11y-close:focus-visible,
.a11y-note a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ==========================================================================
   États appliqués à <html>
   ========================================================================== */

/*
 * Espacement renforcé — les quatre valeurs du critère WCAG 1.4.12.
 * !important est ici légitime : il s'agit de passer outre les réglages du thème,
 * c'est l'objet même de la préférence.
 */
html.a11y-spacing body,
html.a11y-spacing p,
html.a11y-spacing li,
html.a11y-spacing dd,
html.a11y-spacing dt,
html.a11y-spacing td,
html.a11y-spacing th,
html.a11y-spacing figcaption {
  line-height: 1.5 !important;
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
}

html.a11y-spacing p { margin-bottom: 2em !important; }

/* Les titres gardent un interligne serré : 1.5 sur un titre de 52 px le
   disloquerait, et le critère ne vise que le texte courant. */
html.a11y-spacing h1,
html.a11y-spacing h2,
html.a11y-spacing h3 {
  letter-spacing: 0.02em !important;
  word-spacing: 0.16em !important;
}

/* Soulignement de tous les liens. */
html.a11y-underline a {
  text-decoration: underline !important;
  text-underline-offset: 2px;
}

/* Les liens qui sont des boutons ou des cartes ne se soulignent pas : le trait
   traverserait l'objet sans rien signaler d'utile. */
html.a11y-underline .cta-btn,
html.a11y-underline .btn-primary,
html.a11y-underline .section-link,
html.a11y-underline .assoc-link,
html.a11y-underline .qa-card,
html.a11y-underline .contact-actions a,
html.a11y-underline .pp-actions a,
html.a11y-underline .map-foot .route,
html.a11y-underline .footer-fb,
html.a11y-underline .docs-years a,
html.a11y-underline .error-nav a,
html.a11y-underline .page-numbers {
  text-decoration: none !important;
}

/* Animations réduites — même effet que la préférence système, à la demande. */
html.a11y-reduce-motion,
html.a11y-reduce-motion * {
  animation-duration: .01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .01ms !important;
  scroll-behavior: auto !important;
}

/* ==========================================================================
   Contraste élevé — palette alternative
   ==========================================================================

   Chaque valeur a été mesurée sur le fond blanc :

     --ink    #0b1424  18.4:1
     --ink-2  #1e2a44  14.3:1
     --ink-3  #2f3b54  11.2:1
     --navy   #0d2350  15.3:1
     --terra  #a8151d   7.5:1 avec du blanc

   Les bordures décoratives passent à --ink-3 : dans ce mode, tout élément
   perceptible doit l'être franchement.

   « html:root.a11y-contrast » vaut 0,0,3 : la palette passe devant les ponts
   « html:root » de tokens.css comme devant le « :root » de base. */

html:root.a11y-contrast {
  --bg: #ffffff;
  --bg-alt: #eef1f6;
  --paper: #ffffff;
  --ink: #0b1424;
  --ink-2: #1e2a44;
  --ink-3: #2f3b54;
  --line: #2f3b54;
  --line-soft: #2f3b54;
  --navy: #0d2350;
  --navy-2: #0d2350;
  --terra: #a8151d;
  --green: #14532d;
  --gold: #7a5c12;

  /* Les modules du parent suivent, par l'indirection des ponts. */
  --color-primary: var(--navy);
  --color-accent: var(--terra);
  --color-dark: var(--ink);
  --color-text: var(--ink);
  --color-text-muted: var(--ink-3);
}

/* Les fonds translucides posés sur des photos deviennent opaques : une
   transparence ne garantit aucun ratio. */
html.a11y-contrast .village-images figcaption,
html.a11y-contrast .vf-image figcaption {
  background: var(--ink);
}

html.a11y-contrast .hero-image::after {
  background: linear-gradient(90deg, rgba(11, 20, 36, 0.95) 0%, rgba(11, 20, 36, 0.8) 45%, rgba(11, 20, 36, 0.55) 100%);
}

/* Le blanc translucide du footer et de la section associations passe au plein. */
html.a11y-contrast .footer-col h2,
html.a11y-contrast .footer-brand p,
html.a11y-contrast .footer-meta,
html.a11y-contrast .footer-bottom,
html.a11y-contrast .associations .section-eyebrow,
html.a11y-contrast .contact-card .eyebrow,
html.a11y-contrast .contact-item .label,
html.a11y-contrast .pp-banner .pp-eyebrow,
html.a11y-contrast .pp-banner .pp-body span {
  color: #ffffff;
}

html.a11y-contrast .footer-col a,
html.a11y-contrast .assoc-link,
html.a11y-contrast .contact-actions .outlined {
  color: #ffffff;
  border-color: #ffffff;
}

/* Le panneau suit la palette renforcée ; ses séparateurs deviennent francs. */
html.a11y-contrast .a11y { --a11y-border: var(--ink-3); }

/* Second ton des titres : l'opacité .55 reste grise dans ce mode. Le contraste
   élevé la neutralise, le ton reste porté par la graisse. */
html.a11y-contrast .section-head h2 .ton2,
html.a11y-contrast .section-head h3 .ton2,
html.a11y-contrast .texte-seul-body h2 .ton2,
html.a11y-contrast .texte-seul-body h3 .ton2,
html.a11y-contrast .village-body h2 .ton2,
html.a11y-contrast .error-404 h1 .ton2 {
  opacity: 1;
  color: var(--ink-2);
}

/* ==========================================================================
   Sous 640 px — le point de rupture du module cookies
   ========================================================================== */

@media (max-width: 640px) {
  .a11y {
    right: 10px;
    left: 10px;
    bottom: 72px;
    width: auto;
    max-height: calc(100vh - 92px);
    max-height: calc(100dvh - 92px);
  }

  .a11y-footer .a11y-btn { flex: 1 1 auto; }
}

/*
 * Écran bas — téléphone couché, ou zoom à 400 % d'un écran de bureau : en-tête et
 * pied fixes ne laissaient que 36 px de corps visible. La fenêtre entière défile
 * alors d'un bloc.
 */
@media (max-height: 560px) {
  .a11y { display: block; overflow-y: auto; bottom: 68px; max-height: calc(100vh - 80px); }
  .a11y-body { overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  .a11y,
  .a11y-toggle,
  .a11y-size,
  .a11y-btn,
  .a11y-switch-track,
  .a11y-switch-thumb { transition: none; }
}
