/**
 * A11yToolkit — panneau d'accessibilité autonome (profils + réglages)
 * Version 2.0.0
 *
 * 1. Police très lisible
 * 2. Variables (à surcharger par site : `.a11y2 { --a11y2-accent: … }` ou option `theme`)
 * 3. Panneau
 * 4. Effets appliqués à la page
 */

/* ============================================
   1. POLICE TRÈS LISIBLE — Atkinson Hyperlegible (Braille Institute, SIL OFL 1.1)
   Téléchargée seulement quand le réglage est actif.
   ============================================ */
@font-face {
  font-family: 'A11y2 Hyperlegible';
  src: url('fonts/atkinson-hyperlegible-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'A11y2 Hyperlegible';
  src: url('fonts/atkinson-hyperlegible-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ============================================
   2. VARIABLES
   ============================================ */
.a11y2 {
  --a11y2-accent: #ffb800;
  --a11y2-on-accent: #000;
  --a11y2-strong: #111;
  --a11y2-on-strong: #fff;
  --a11y2-bg: #fff;
  --a11y2-fg: #151515;
  --a11y2-muted: #595959;
  --a11y2-soft: #f3f3f1;
  --a11y2-line: #e2e2de;
  --a11y2-switch-off: #8a8a8a;
  --a11y2-radius: 16px;
  --a11y2-font: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --a11y2-z: 100000;
}

/* ============================================
   3. PANNEAU
   ============================================ */

/* Réinitialisation locale : le panneau ne subit ni le CSS du site ni ses propres réglages */
.a11y2,
.a11y2 * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--a11y2-font) !important;
  font-style: normal !important;
  letter-spacing: normal !important;
  word-spacing: normal !important;
  text-align: left;
  text-transform: none;
  line-height: 1.35 !important;
  text-decoration: none !important;
  cursor: auto;
}

.a11y2 button,
.a11y2 select,
.a11y2 label {
  cursor: pointer;
}

.a11y2 button,
.a11y2 select {
  appearance: none;
  -webkit-appearance: none;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
}

.a11y2 svg {
  display: block;
  flex-shrink: 0;
}

.a11y2 :focus-visible {
  outline: 3px solid var(--a11y2-strong) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 6px var(--a11y2-accent) !important;
}

.a11y2 [hidden] {
  display: none !important;
}

.a11y2-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- Bouton flottant (sites sans bouton propre) --- */
.a11y2-fab {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: var(--a11y2-z);
  width: 52px;
  height: 52px;
  border-radius: 50% !important;
  display: grid;
  place-items: center;
  background: var(--a11y2-strong) !important;
  color: var(--a11y2-on-strong) !important;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.a11y2--bottom-right .a11y2-fab {
  left: auto;
  right: 16px;
}

/* Pastille sur le déclencheur quand un réglage est actif */
.a11y2-has-settings {
  position: relative;
}

.a11y2-has-settings::after {
  content: '';
  position: absolute;
  top: -2px;
  right: -2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--a11y2-accent, #ffb800);
  border: 2px solid #000;
  pointer-events: none;
}

/* --- Fenêtre --- */
.a11y2-dialog {
  position: fixed;
  z-index: var(--a11y2-z);
  left: var(--a11y2-left, 16px);
  bottom: var(--a11y2-bottom, 80px);
  width: min(400px, calc(100vw - 16px));
  max-height: min(var(--a11y2-max-h, 640px), calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  background: var(--a11y2-bg);
  color: var(--a11y2-fg);
  border-radius: var(--a11y2-radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.08);
  font-size: 15px;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.a11y2--bottom-right .a11y2-dialog {
  left: auto;
  right: 16px;
}

.a11y2-dialog--in {
  opacity: 1;
  transform: none;
}

/* En-tête */
.a11y2-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 4px 20px;
}

.a11y2-head-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--a11y2-accent);
  color: var(--a11y2-on-accent);
}

.a11y2-title {
  flex: 1;
  font-size: 19px !important;
  font-weight: 700;
  color: var(--a11y2-fg);
}

/* Le titre reçoit le focus à l'ouverture (point de départ de la lecture) : rien à signaler visuellement */
.a11y2 .a11y2-title:focus,
.a11y2 .a11y2-title:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

.a11y2-icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--a11y2-fg);
}

.a11y2-icon-btn:hover {
  background: var(--a11y2-soft);
}

.a11y2-intro {
  padding: 4px 20px 14px;
  font-size: 13.5px !important;
  color: var(--a11y2-muted);
}

/* Onglets */
.a11y2-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0 16px 12px;
  padding: 4px;
  border-radius: 999px;
  background: var(--a11y2-soft);
}

.a11y2-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 14px !important;
  font-weight: 600;
  color: var(--a11y2-fg);
}

.a11y2-tab[aria-selected="true"] {
  background: var(--a11y2-strong);
  color: var(--a11y2-on-strong);
}

/* Corps défilant */
.a11y2-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px 8px;
}

.a11y2-pane:focus {
  outline: none;
}

/* Catégorie (menu déroulant) */
.a11y2-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 4px 10px;
}

.a11y2-field-label {
  font-size: 14px !important;
  font-weight: 600;
}

.a11y2-select-wrap {
  position: relative;
  flex: 0 1 210px;
}

.a11y2-select {
  width: 100%;
  min-height: 42px;
  padding: 0 38px 0 14px !important;
  border-radius: 10px;
  background: var(--a11y2-soft) !important;
  border: 1px solid var(--a11y2-line) !important;
  font-size: 14px !important;
  font-weight: 600;
}

.a11y2-select-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

/* Lignes (profils et interrupteurs) */
.a11y2-profiles {
  list-style: none;
}

.a11y2-profile + .a11y2-profile {
  border-top: 1px solid var(--a11y2-line);
}

.a11y2-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 10px 6px !important;
  border-radius: 10px;
  color: var(--a11y2-fg);
}

.a11y2-row:hover {
  background: var(--a11y2-soft) !important;
}

.a11y2-row--profile {
  min-height: 64px;
}

.a11y2-row-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--a11y2-soft);
  color: var(--a11y2-fg);
  flex-shrink: 0;
}

.a11y2-row[aria-checked="true"] .a11y2-row-icon {
  background: var(--a11y2-accent);
  color: var(--a11y2-on-accent);
}

.a11y2-row-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.a11y2-row-name {
  font-size: 15px !important;
  font-weight: 600;
}

.a11y2-row-desc {
  font-size: 12.5px !important;
  color: var(--a11y2-muted);
}

/* Interrupteur : état lisible sans la couleur (position + coche) */
.a11y2-switch {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--a11y2-switch-off);
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.a11y2-switch::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}

[aria-checked="true"] > .a11y2-switch {
  background: var(--a11y2-strong);
}

[aria-checked="true"] > .a11y2-switch::before {
  transform: translateX(20px);
  background: var(--a11y2-accent);
}

[aria-checked="true"] > .a11y2-switch::after {
  content: '';
  position: absolute;
  top: 8px;
  left: 29px;
  width: 4px;
  height: 8px;
  border: solid var(--a11y2-on-accent);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Choix en pastilles (boutons radio natifs) */
.a11y2-radios {
  border: 0;
  padding: 10px 6px 12px !important;
}

.a11y2-radios-legend {
  font-size: 15px !important;
  font-weight: 600;
  padding: 0 0 8px !important;
}

.a11y2-subchoice {
  padding: 0 6px 12px 60px !important;
}

.a11y2-subchoice .a11y2-radios-legend {
  font-size: 12.5px !important;
  font-weight: 500;
  color: var(--a11y2-muted);
}

.a11y2-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.a11y2-chip {
  position: relative;
}

.a11y2-chip input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.a11y2-chip label {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px !important;
  border-radius: 999px;
  border: 1.5px solid var(--a11y2-line);
  background: var(--a11y2-bg);
  font-size: 13.5px !important;
  font-weight: 500;
}

.a11y2-chip label:hover {
  border-color: var(--a11y2-strong);
}

.a11y2-chip input:checked + label {
  background: var(--a11y2-strong);
  border-color: var(--a11y2-strong);
  color: var(--a11y2-on-strong);
  font-weight: 600;
}

.a11y2-chip input:focus-visible + label {
  outline: 3px solid var(--a11y2-strong);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--a11y2-accent);
}

/* Rubriques de réglages */
.a11y2-section {
  padding: 4px 0 8px;
}

.a11y2-section + .a11y2-section {
  border-top: 1px solid var(--a11y2-line);
}

.a11y2-section-title {
  padding: 12px 6px 4px !important;
  font-size: 12px !important;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em !important;
  color: var(--a11y2-muted);
}

/* Réglages gradués : − valeur + */
.a11y2-stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 6px !important;
}

.a11y2-stepper-label {
  font-size: 15px !important;
  font-weight: 600;
}

.a11y2-stepper-ctrl {
  display: flex;
  align-items: center;
  border-radius: 999px;
  background: var(--a11y2-soft);
  padding: 3px !important;
}

.a11y2-step {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--a11y2-bg) !important;
  box-shadow: 0 0 0 1px var(--a11y2-line);
}

.a11y2-step:hover:not(:disabled) {
  background: var(--a11y2-strong) !important;
  color: var(--a11y2-on-strong);
}

.a11y2-step:disabled {
  opacity: 0.35;
  cursor: default;
}

.a11y2-stepper-value {
  min-width: 66px;
  text-align: center;
  font-size: 14px !important;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.a11y2-hint {
  padding: 10px 6px 6px !important;
  font-size: 12.5px !important;
  color: var(--a11y2-muted);
}

/* Pied */
.a11y2-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px 14px 20px;
  border-top: 1px solid var(--a11y2-line);
}

.a11y2-count {
  font-size: 13px !important;
  color: var(--a11y2-muted);
}

.a11y2-reset {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px !important;
  border-radius: 999px;
  background: var(--a11y2-accent) !important;
  color: var(--a11y2-on-accent) !important;
  font-size: 14px !important;
  font-weight: 700;
}

.a11y2-reset:disabled {
  background: var(--a11y2-soft) !important;
  color: var(--a11y2-muted) !important;
  cursor: default;
}

/* Mobile : panneau en bas d'écran, pleine largeur */
@media (max-width: 600px) {
  .a11y2-dialog,
  .a11y2--bottom-right .a11y2-dialog {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 88vh;
    max-height: 88dvh;
    border-radius: var(--a11y2-radius) var(--a11y2-radius) 0 0;
  }

  .a11y2-foot {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .a11y2-dialog,
  .a11y2-switch,
  .a11y2-switch::before {
    transition: none;
  }
}

/* ============================================
   4. EFFETS APPLIQUÉS À LA PAGE
   Le panneau est toujours exclu : :not(.a11y2, .a11y2 *)
   ============================================ */

/* --- Texte --- */
html.a11y2-lineHeight-1 body *:not(.a11y2, .a11y2 *) { line-height: 1.6 !important; }
html.a11y2-lineHeight-2 body *:not(.a11y2, .a11y2 *) { line-height: 1.9 !important; }
html.a11y2-lineHeight-3 body *:not(.a11y2, .a11y2 *) { line-height: 2.2 !important; }

html.a11y2-letterSpacing-1 body *:not(.a11y2, .a11y2 *) { letter-spacing: 0.06em !important; }
html.a11y2-letterSpacing-2 body *:not(.a11y2, .a11y2 *) { letter-spacing: 0.12em !important; }
html.a11y2-letterSpacing-3 body *:not(.a11y2, .a11y2 *) { letter-spacing: 0.18em !important; }

html.a11y2-wordSpacing-1 body *:not(.a11y2, .a11y2 *) { word-spacing: 0.12em !important; }
html.a11y2-wordSpacing-2 body *:not(.a11y2, .a11y2 *) { word-spacing: 0.24em !important; }
html.a11y2-wordSpacing-3 body *:not(.a11y2, .a11y2 *) { word-spacing: 0.36em !important; }

html.a11y2-font body *:not(.a11y2, .a11y2 *) {
  font-family: 'A11y2 Hyperlegible', Verdana, Arial, sans-serif !important;
}

html.a11y2-noitalic body *:not(.a11y2, .a11y2 *) {
  font-style: normal !important;
}

/* Texte courant seulement : un titre court centré reste lisible */
html.a11y2-left body :is(p, li, dd, dt, blockquote, figcaption, td, th):not(.a11y2 *) {
  text-align: left !important;
}

/* --- Apparence : sombre --- */
html.a11y2-dark,
html.a11y2-dark body {
  background-color: #121212 !important;
}

html.a11y2-dark body *:not(.a11y2, .a11y2 *) {
  color: #ececec !important;
  border-color: #444 !important;
  text-shadow: none !important;
  box-shadow: none !important;
}

html.a11y2-dark .a11y2-bg {
  background-color: #1d1d1d !important;
}

html.a11y2-dark .a11y2-bg-line {
  background-color: #ececec !important;
}

html.a11y2-dark body a:not(.a11y2 *),
html.a11y2-dark body a:not(.a11y2 *) * {
  color: #ffd966 !important;
}

/* --- Apparence : contraste élevé --- */
html.a11y2-contrast,
html.a11y2-contrast body {
  background-color: #000 !important;
}

html.a11y2-contrast body *:not(.a11y2, .a11y2 *) {
  color: #fff !important;
  border-color: #fff !important;
  text-shadow: none !important;
  box-shadow: none !important;
}

html.a11y2-contrast .a11y2-bg {
  background-color: #000 !important;
  background-image: none !important;
}

html.a11y2-contrast .a11y2-bg-line {
  background-color: #fff !important;
}

html.a11y2-contrast body :is(button, input, select, textarea):not(.a11y2 *) {
  border: 2px solid #fff !important;
}

html.a11y2-contrast body a:not(.a11y2 *),
html.a11y2-contrast body a:not(.a11y2 *) * {
  color: #ffff00 !important;
}

html.a11y2-contrast body a:not(.a11y2 *) {
  text-decoration: underline !important;
}

/* --- Liens et focus --- */
html.a11y2-links body a:not(.a11y2 *) {
  text-decoration: underline !important;
  text-decoration-thickness: 2px !important;
  text-underline-offset: 0.18em !important;
}

html.a11y2-linkspace body a:not(.a11y2 *) {
  margin-inline: 0.18em !important;
  padding-block: 0.2em !important;
}

html.a11y2-linkspace body :is(nav, footer) :is(li):not(.a11y2 *) {
  margin-block: 0.25em !important;
}

html.a11y2-focus *:focus-visible,
html.a11y2-focus *:focus {
  outline: 3px solid #000 !important;
  outline-offset: 3px !important;
  box-shadow: 0 0 0 6px #ffd400 !important;
}

/* --- Grand curseur (flèche 48 px ; jaune sur les éléments cliquables) --- */
html.a11y2-cursor,
html.a11y2-cursor body,
html.a11y2-cursor body * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'%3E%3Cpath d='M4.5 2.5l14.5 11-6.3 1.1 3.8 6.9-2.9 1.5-3.8-7-5.3 4.3z' fill='%23000' stroke='%23fff' stroke-width='1.3' stroke-linejoin='round'/%3E%3C/svg%3E") 5 3, auto !important;
}

html.a11y2-cursor body :is(a, button, label, select, summary, [role="button"], [role="switch"], [role="tab"]),
html.a11y2-cursor body :is(a, button, label, select, summary, [role="button"], [role="switch"], [role="tab"]) * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'%3E%3Cpath d='M4.5 2.5l14.5 11-6.3 1.1 3.8 6.9-2.9 1.5-3.8-7-5.3 4.3z' fill='%23ffd400' stroke='%23000' stroke-width='1.3' stroke-linejoin='round'/%3E%3C/svg%3E") 5 3, pointer !important;
}

/* --- Arrêter les animations --- */
html.a11y2-motion *,
html.a11y2-motion *::before,
html.a11y2-motion *::after {
  animation-duration: 0.001ms !important;
  animation-delay: 0s !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  transition-delay: 0s !important;
  scroll-behavior: auto !important;
}

/* --- Guides de lecture --- */
.a11y2-guide {
  position: fixed;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: calc(var(--a11y2-z, 100000) - 1);
}

.a11y2-guide[hidden] {
  display: none !important;
}

.a11y2-defs {
  width: 0;
  height: 0;
  overflow: hidden;
}

.a11y2-ruler {
  top: 50%;
  height: 44px;
  background: rgba(255, 212, 0, 0.22);
  border-top: 3px solid #000;
  border-bottom: 3px solid #000;
  box-shadow: 0 0 0 1px #fff;
}

.a11y2-mask {
  background: rgba(0, 0, 0, 0.62);
}

.a11y2-mask--top {
  top: 0;
  height: 40vh;
}

.a11y2-mask--bottom {
  top: 60vh;
  bottom: 0;
}
