/* =========================================================================
   AF2PVision — Accessibilité : panneau, lecture vocale, thèmes
   Les thèmes ne redéfinissent QUE les rôles (--surface-*, --text-*…) :
   les couleurs fixes (blanc sur sarcelle, encre sur or) restent lisibles.
   ========================================================================= */

/* ---- Lien d'évitement : caché puis visible au focus (géré par .screen-reader-text) ---- */
.af-skip-link { z-index: 100001; }

/* ---- Panneau de réglages (non modal : se ferme par Échap, clic extérieur, ✕) ---- */
.af-a11y-panel {
  position: fixed;
  /* Juste sous l'en-tête collant (bouton « Accessibilité »). */
  top: calc(var(--af-header-h, 80px) + 8px);
  right: 16px;
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100vh - var(--af-header-h, 80px) - 24px);
  overflow: auto;
  background: var(--surface-card);
  color: var(--text);
  border: 3px solid var(--text);
  border-radius: var(--r-carte);
  padding: 24px;
  box-shadow: var(--ombre-panel);
  z-index: 9500;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.af-a11y-panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.af-a11y-panel h2 { margin: 0; font-size: 1.3125rem; }
.af-a11y-close {
  width: 48px; height: 48px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--text); background: var(--surface-card);
  border-radius: var(--r-sm); color: var(--text);
  cursor: pointer;
}
.af-a11y-group { display: flex; flex-direction: column; gap: 8px; }
.af-a11y-group > .af-a11y-label { font-size: 1.125rem; font-weight: var(--fw-bold); }
.af-a11y-choices { display: flex; gap: 8px; }
.af-a11y-choices button {
  flex: 1;
  min-height: 48px;
  font-family: var(--font-base);
  font-size: 1.0625rem;
  font-weight: var(--fw-bold);
  border: 2px solid var(--text-brand);
  background: var(--surface-card);
  color: var(--text-brand);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.af-a11y-choices button[data-af-value="100"] { font-size: 1rem; }
.af-a11y-choices button[data-af-value="112"] { font-size: 1.25rem; }
.af-a11y-choices button[data-af-value="125"] { font-size: 1.5rem; }
/* État choisi : fond plein + coche (repère non lié à la seule couleur). */
.af-a11y-choices button[aria-pressed="true"] {
  background: var(--c-sarcelle);
  border-color: var(--c-sarcelle);
  color: var(--c-fix-blanc);
  text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px;
}
.af-a11y-reset {
  min-height: 48px;
  font-family: var(--font-base); font-size: 1.0625rem; font-weight: var(--fw-bold);
  border: 2px solid var(--text-muted); background: var(--surface-card); color: var(--text);
  border-radius: var(--r-sm); cursor: pointer;
}
/* Explication du mode « Lecture » (question de la cliente : « que veut dire lecture ? »). */
.af-a11y-help { margin: 2px 0 0; font-size: var(--fs-small); line-height: 1.45; color: var(--text-muted); }
/* Bouton « Écouter la page » dans le panneau : pleine largeur. */
.af-a11y-tts { width: 100%; }
.af-tts__label { display: inline; }

/* Onde du bouton « Écouter » de l'en-tête pendant la lecture (layout.css). */
@keyframes af-tts-pulse {
  0%   { transform: scale(0.7); opacity: 0.7; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* =========================================================================
   LECTEUR DE LECTURE VOCALE (assets/js/tts.js)
   ========================================================================= */
.af-tts-player {
  position: fixed; z-index: 9450;
  left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(980px, calc(100% - 24px));
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 20px;
  padding: 12px 16px 12px 22px;
  background: var(--surface-ink); color: var(--on-ink);
  border: 3px solid var(--c-or); border-radius: 20px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.af-tts-player[hidden] { display: none; }
body.af-cookie-open .af-tts-player { bottom: calc(16px + var(--af-cookie-h, 0px)); }
/* Réserve en bas de page : le lecteur ne masque jamais la fin du pied de page. */
body.af-tts-on .af-footer { padding-bottom: calc(var(--af-tts-h, 200px) + 32px); }
/* Pendant la lecture : le focus clavier défile au-dessus du lecteur (WCAG 2.4.11). */
html.af-tts-active { scroll-padding-bottom: calc(var(--af-tts-h, 200px) + 16px); scroll-behavior: auto; }
.af-tts-player__info {
  margin: 0; min-width: 0; flex: 1 1 260px;
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 14px;
  font-size: var(--fs-small); line-height: 1.35; color: var(--on-ink-muted);
}
.af-tts-player__status { font-weight: var(--fw-bold); color: var(--on-ink); }
.af-tts-player__pos { font-variant-numeric: tabular-nums; }
.af-tts-player__hint { flex-basis: 100%; }
@media (hover: none), (max-width: 899px) { .af-tts-player__hint { display: none; } }
/* Onde animée : lecture en cours (figée en pause et si mouvement réduit). */
.af-tts-player__wave { display: inline-flex; align-items: flex-end; gap: 3px; height: 18px; }
.af-tts-player__wave span { width: 4px; height: 100%; border-radius: 2px; background: var(--c-or); animation: af-tts-bars 1s ease-in-out infinite; }
.af-tts-player__wave span:nth-child(2) { animation-delay: -0.3s; }
.af-tts-player__wave span:nth-child(3) { animation-delay: -0.6s; }
@keyframes af-tts-bars { 0%, 100% { transform: scaleY(0.35); } 50% { transform: scaleY(1); } }
.af-tts-player--paused .af-tts-player__wave span { animation: none; transform: scaleY(0.35); }
@media (prefers-reduced-motion: reduce) { .af-tts-player__wave span { animation: none; } }

.af-tts-player__controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.af-tts-player__btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 52px; min-height: 52px; padding: 8px 14px;
  font-family: var(--font-base); font-size: var(--fs-small); font-weight: var(--fw-bold);
  color: var(--on-ink); background: transparent;
  border: 2px solid var(--on-ink-muted); border-radius: 14px; cursor: pointer;
  transition: background-color var(--t-rapide);
}
.af-tts-player__btn:hover:not([aria-disabled="true"]) { background: rgba(255, 255, 255, 0.12); }
/* Bout de liste : bouton atténué mais focusable (aria-disabled, pas disabled). */
.af-tts-player__btn[aria-disabled="true"] { opacity: 0.45; cursor: default; }
.af-tts-player__btn .af-ico { flex: none; }
.af-tts-player__btn--main { min-width: 150px; background: var(--c-or); color: var(--c-fix-encre); border-color: var(--c-or); }
.af-tts-player__btn--main:hover { background: var(--c-or-hover); }
/* Icône du bouton principal selon l'état (pause pendant la lecture, lecture en pause). */
.af-tts-player__btn--main .af-ico--play { display: none; }
.af-tts-player--paused .af-tts-player__btn--main .af-ico--play { display: inline-block; }
.af-tts-player--paused .af-tts-player__btn--main .af-ico--pause { display: none; }
@media (max-width: 639px) {
  .af-tts-player { bottom: 8px; width: calc(100% - 16px); padding: 10px 12px; border-radius: 16px; }
  /* Bouton principal sur toute la largeur, les quatre autres en dessous :
     tient à 320 px, même avec le texte agrandi. */
  .af-tts-player__controls {
    width: 100%; display: grid; gap: 6px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-areas: "main main main main" "prev next rate stop";
  }
  .af-tts-player__btn { min-width: 0; min-height: 48px; padding: 6px; }
  .af-tts-player__btn--main { grid-area: main; min-width: 0; }
  .af-tts-player__btn[data-tts-cmd="prev"] { grid-area: prev; }
  .af-tts-player__btn[data-tts-cmd="next"] { grid-area: next; }
  .af-tts-player__btn--rate { grid-area: rate; }
  .af-tts-player__btn--stop { grid-area: stop; }
  /* Choix de la voix présent : cinq boutons sous le bouton principal
     (sans :has(), le bouton se place simplement sur une ligne de plus). */
  .af-tts-player__controls:has(.af-tts-player__btn--voice:not([hidden])) {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-template-areas: "main main main main main" "prev next rate voice stop";
  }
  .af-tts-player__controls:has(.af-tts-player__btn--voice:not([hidden])) .af-tts-player__btn--voice { grid-area: voice; }
  /* Libellés « Vitesse : … », « Voix : … » et « Arrêter » réduits à l'icône (noms accessibles conservés). */
  .af-tts-player__btn--rate > span, .af-tts-player__btn--voice > span, .af-tts-player__btn--stop > span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
  }
}

/* Paragraphe en cours de lecture : cadre de la couleur du texte (toujours
   contrasté, quel que soit le fond ou le mode) et halo doré AUTOUR du bloc —
   jamais de fond sous le texte, qui en réduirait le contraste (AAA). */
.af-tts-current {
  outline: 3px solid currentColor; outline-offset: 6px; border-radius: 4px;
  box-shadow: 0 0 0 12px rgba(245, 183, 0, 0.35);
  scroll-margin: 120px 0 140px;
}
body.af-tts-on .af-tts-item { cursor: pointer; }
body.af-tts-on .af-tts-item:not(.af-tts-current):hover { outline: 2px dashed currentColor; outline-offset: 6px; }

/* Bouton « Écouter la sélection » (sous le texte sélectionné). */
.af-tts-sel {
  position: fixed; z-index: 9460; left: 0; top: 0;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 8px 16px;
  font-family: var(--font-base); font-size: var(--fs-small); font-weight: var(--fw-bold);
  background: var(--c-sarcelle); color: var(--c-fix-blanc);
  border: 3px solid var(--c-fix-blanc); border-radius: var(--r-pill);
  box-shadow: var(--ombre-flottant); cursor: pointer;
}
.af-tts-sel[hidden] { display: none; }
.af-tts-sel:hover { background: var(--c-sarcelle-dark); }

/* Bouton « Écouter » de chaque section de l'accueil : discret, contour de la
   couleur du texte de la section (lisible sur crème, blanc, sarcelle…). */
.af-tts-section {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: var(--sp-5); min-height: var(--cible-min); padding: 6px 16px 6px 12px;
  font-family: var(--font-base); font-size: var(--fs-small); font-weight: var(--fw-bold);
  color: var(--text-brand); background: transparent;
  border: 2px solid currentColor; border-radius: var(--r-pill); cursor: pointer;
  transition: background-color var(--t-rapide);
}
.af-tts-section:hover { background: var(--surface-soft); }
.bg-sarcelle .af-tts-section, .af-chiffres .af-tts-section { color: var(--on-brand); }
.bg-sarcelle .af-tts-section:hover, .af-chiffres .af-tts-section:hover { background: rgba(255, 255, 255, 0.12); }
.af-tts-section.af-tts--playing { background: var(--c-or); color: var(--c-fix-encre); border-color: var(--c-or); }
/* Titre suivi directement du bouton (sections sans bloc .af-heading). */
h2 + .af-tts-section { margin: 0 0 var(--sp-5); }

/* Téléphone à l'horizontale (peu de hauteur) : lecteur sur une seule ligne,
   sans la ligne d'état, pour ne pas couvrir l'écran. */
@media (max-height: 500px) and (orientation: landscape) {
  .af-tts-player { bottom: 6px; padding: 6px 10px; }
  .af-tts-player__info { display: none; }
  .af-tts-player__controls {
    display: flex; flex-wrap: nowrap; width: 100%; justify-content: center; gap: 6px;
  }
  .af-tts-player__btn { min-height: 44px; }
  /* Libellés « Vitesse : … », « Voix : … » et « Arrêter » réduits à l'icône
     (noms accessibles conservés) : le lecteur reste sur une ligne basse. */
  .af-tts-player__btn--rate > span, .af-tts-player__btn--voice > span, .af-tts-player__btn--stop > span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
  }
}

@media (forced-colors: active) {
  .af-tts-player, .af-tts-sel, .af-tts-section, .af-tts-player__btn { border: 2px solid ButtonText; }
  .af-tts-current { outline: 3px solid Highlight; box-shadow: none; }
  /* Barres du bouton « Menu » (dessinées en fond) : couleur système imposée. */
  .af-burger .af-burger__bars span { background: ButtonText; forced-color-adjust: none; }
  .af-hbtn[aria-pressed="true"], .af-hbtn[aria-expanded="true"] { outline: 3px solid Highlight; outline-offset: 2px; }
}

/* =========================================================================
   THÈME SOMBRE  (contrastes vérifiés : texte 16:1, liens 10:1, étiquettes 10:1)
   ========================================================================= */
html.af-theme-dark {
  color-scheme: dark;
  --surface-page:    #0F1717;
  --surface-card:    #16211F;
  --surface-warm:    #241F10;
  --surface-soft:    #12312F;
  --surface-brand:   #0B3D3D;
  --surface-brand-2: #072B2B;
  --surface-ink:     #0A1010;
  --text:            #F4F1E8;
  --text-muted:      #C9D3D0;
  --text-brand:      #7FD4D4;
  --text-label:      #F2C94C;
  --link:            #7FD4D4;
  --link-hover:      #A9E6E6;
  --border:          #34423F;
  --border-soft:     #2A3633;
  --border-strong:   #C9D3D0;
  --decor-1:         #1F4A47;
  --c-erreur:        #FFB4A8;
  --focus-c:         #F5B700;   /* trait or, très visible sur sombre */
  --focus-halo:      #0A0F0F;   /* halo sombre autour (contraste sur éléments clairs) */
  --ombre-carte:     none;
}
/* « Accessibilité » (aplat sarcelle) : contour clair, bien détaché du fond sombre. */
html.af-theme-dark .af-a11y-toggle.af-hbtn { border-color: var(--text-brand); }
html.af-theme-dark .af-hero__media::after { opacity: 0.8; }
html.af-theme-dark img { filter: brightness(0.92); }

/* =========================================================================
   MODE LECTURE  (fond papier, interlignage plus généreux, sans ombres)
   ========================================================================= */
html.af-theme-reading {
  --surface-page: #F7F1E1;
  --surface-card: #FBF6EA;
  --surface-warm: #F3E9CE;
  --ombre-carte:  none;
  --ombre-bouton: none;
  /* Teintes un peu plus soutenues : AAA conservé sur le fond papier. */
  --text-brand:   #03504F;
  --link:         #03504F;
  --text-label:   #5A4000;
}
html.af-theme-reading body { line-height: 1.8; }

/* Encarts chaleureux (crème-jaune) en thème clair : liens et étiquettes
   légèrement assombris pour rester au niveau AAA (7:1) sur ce fond. */
html:not(.af-theme-dark) :is(.af-toc__tip, .af-billet, .af-soutenir, .af-soutien-bloc--don, .af-tip, .af-tag) {
  --link:       #03504F;
  --text-brand: #03504F;
  --text-label: #5A4000;
}

/* =========================================================================
   CONTRASTE RENFORCÉ  (AAA : supprime les gris doux, traits plus épais)
   ========================================================================= */
html.af-contrast-high {
  --surface-page: #FFFFFF;
  --text-muted:   var(--text);
  --border:       #5C6B6B;
  --border-strong:#000000;
  --link:         #023F3F;
  --text-brand:   #023F3F;
  --focus-w:      4px;
}
html.af-contrast-high a { text-decoration: underline; }
/* Titres de cartes, sommaire « Sur cette page », liste des fiches, étiquettes :
   pas de soulignement permanent (il gênait la lecture des titres — retour de
   la cliente du 16/11/2026). Ce ne sont pas des liens dans un texte (WCAG
   1.4.1) et ils sont repérables autrement : flèche « Lire la suite » et cadre
   épais des cartes, chevron des fiches, cadre et filet du sommaire.
   Soulignement au survol et au focus. Les liens des textes restent soulignés. */
html.af-contrast-high :is(.af-card__more, .af-toc a, .af-fiches-box li a, a.af-tag) { text-decoration: none; }
html.af-contrast-high :is(.af-toc a, .af-fiches-box li a):is(:hover, :focus-visible) { text-decoration: underline; text-decoration-thickness: 2px; }
html.af-contrast-high .af-card--linked:is(:hover, :focus-within) .af-card__title { text-decoration-thickness: 2px; }
html.af-contrast-high .af-card,
html.af-contrast-high .af-form,
html.af-contrast-high .af-toc { border-width: 2px; }
/* Combinaison sombre + contraste renforcé : blanc pur sur noir profond. */
html.af-contrast-high.af-theme-dark {
  --surface-page:  #000000;
  --surface-card:  #0A0A0A;
  --surface-warm:  #1A1505;
  --surface-soft:  #06201F;
  --text:          #FFFFFF;
  --text-muted:    #FFFFFF;
  --text-brand:    #9FEFEF;
  --link:          #9FEFEF;
  --border:        #8A9A9A;
  --border-strong: #FFFFFF;
}

/* Respecte aussi la préférence système de contraste élevé */
@media (prefers-contrast: more) {
  :root { --text-muted: var(--text); --border-strong: #000000; }
}
/* Mode contraste forcé Windows : les bordures remplacent les aplats. */
@media (forced-colors: active) {
  .af-btn, .af-cta, .af-header__support, .af-hbtn, .af-filter { border: 2px solid ButtonText; }
  .af-card, .af-form, .af-toc, .af-verbatim, .af-chiffre-card { border: 1px solid CanvasText; }
}
