html.a11y--readable-font,
html.a11y--readable-font body,
html.a11y--readable-font input,
html.a11y--readable-font textarea,
html.a11y--readable-font select,
html.a11y--readable-font button {
  font-family: var(--a11y-readable-font, 'Atkinson Hyperlegible', 'OpenDyslexic',
    system-ui, -apple-system, Segoe UI, Roboto, Arial, 'Noto Sans', sans-serif) !important;
}

:root {
  /* Tweak per project */
  --a11y-accent: #24355c;
  --a11y-focus-color: var(--a11y-accent);
  --a11y-panel-width: 22rem;
  --a11y-scroll-margin: 4rem;         /* header height for focus-no-obscure */
  --a11y-ruler-height: 2.75rem;       /* reading ruler window thickness */
  --a11y-text-scale: 1;               /* used by .a11y--scaled */
  --a11y-readable-font: 'Atkinson Hyperlegible', system-ui, -apple-system, Segoe UI, Roboto, Arial, 'Noto Sans', sans-serif;
}

/* Screen-reader-only utility */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,1px,1px); white-space: nowrap; border: 0;
}

/* Skip link helper (optional: render via {% skip_to_content_link %}) */
.a11y-skip-link { position:absolute; left:-9999px; top:auto; width:1px; height:1px; overflow:hidden; }
.a11y-skip-link:focus {
  left: 1rem; top: 1rem; width:auto; height:auto; padding:.5rem .75rem;
  background:#000; color:#fff; z-index:10000;
}

/* Launcher button */
.a11y-root { position: fixed; inset: auto 1rem 1rem auto; z-index: 10000; }
.a11y-btn {
  border: 2px solid var(--a11y-accent); background: #fff; color: #000;
  border-radius: .75rem; padding: .5rem .75rem; font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.a11y-btn:focus-visible {
  outline: 2px solid transparent;
  /* Two-ring focus: white inner + dark outer (meets 2.4.11 on most BGs) */
  box-shadow: 0 0 0 2px #fff, 0 0 0 5px #0a0a0a;
}

/* Panel */
.a11y-panel {
  position: fixed; right: 1rem; bottom: 3.5rem; width: var(--a11y-panel-width);
  max-width: calc(100vw - 2rem); background: #fff; color: #111;
  border: 2px solid var(--a11y-accent); border-radius: 1rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.a11y-panel__header { display:flex; align-items:center; justify-content:space-between; padding:.75rem 1rem; border-bottom:1px solid #eee; }
.a11y-close { border:none; background:transparent; font-size:1.5rem; line-height:1; cursor:pointer; }
.a11y-panel__content { padding: 1rem; }
.a11y-toggle { display:block; margin:.25rem 0; font-size: .95rem; }
.a11y-toggle input { margin-right: .5rem; }
.a11y-actions { margin-top: .75rem; display:flex; gap:.5rem; }
.a11y-flex { display:flex; gap:.5rem; flex-wrap: wrap; margin-bottom:.5rem; }
.a11y-secondary { border:1px solid #999; background:#f7f7f7; padding:.5rem .75rem; border-radius:.5rem; cursor:pointer; }
.a11y-hint { font-size: .85rem; color:#555; margin-top:.5rem; }

/* Fix frameworks that hide native checkboxes (e.g., MDBootstrap) */
.a11y-panel input[type="checkbox"]{
  position: static !important; opacity: 1 !important; pointer-events: auto !important;
  appearance: auto !important; -webkit-appearance: checkbox !important;
}

/* Stronger focus ring (WCAG 2.4.11 Focus Appearance min) */
.a11y--focus-strong :focus-visible {
  outline: 2px solid transparent !important;
  box-shadow: 0 0 0 2px #fff, 0 0 0 5px #0a0a0a !important;
  outline-offset: 2px !important;
}

/* Font & size toggles */
.a11y--text-lg { font-size: 115%; }
.a11y--scaled { font-size: calc(100% * var(--a11y-text-scale, 1)); }
.a11y--text-spacing { line-height: 1.8 !important; letter-spacing: 0.12em !important; word-spacing: 0.16em !important; }
.a11y--readable-font {
  font-family: var(--a11y-readable-font, 'OpenDyslexic', 'Atkinson Hyperlegible',
    system-ui, -apple-system, Segoe UI, Roboto, Arial, 'Noto Sans', sans-serif) !important;
}
.a11y--left-align p { text-align: left !important; hyphens: auto; }

/* Contrast & color modes */
.a11y--high-contrast, .a11y--high-contrast body { background: #fff !important; color:#000 !important; }
.a11y--high-contrast a { color:#000 !important; text-decoration: underline !important; }
.a11y--dark, .a11y--dark body { background: #000 !important; color:#fff !important; }
.a11y--dark a { color:#fff !important; text-decoration: underline !important; }
.a11y--grayscale { filter: grayscale(100%) contrast(1.1); }

/* Links */
.a11y--underline-links a { text-decoration: underline !important; }
.a11y--highlight-links a { background: rgba(255, 115, 7, 0.2) !important; padding: 0 .1em; border-radius: .2em; }
.a11y--show-link-urls a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .85em; word-break: break-all; }

/* Motion & autoplay */
.a11y--stop-animations *, .a11y--stop-animations *::before, .a11y--stop-animations *::after {
  animation: none !important; transition: none !important; scroll-behavior: auto !important;
}

/* Hit target size (2.5.8 Minimum) */
.a11y--big-targets a,
.a11y--big-targets button,
.a11y--big-targets input[type="button"],
.a11y--big-targets input[type="submit"],
.a11y--big-targets label,
.a11y--big-targets .btn {
  min-height: 24px; min-width: 24px;
}

/* Focus not obscured (2.4.12) */
.a11y--focus-no-obscure :focus { scroll-margin-top: var(--a11y-scroll-margin); }

/* Reading ruler overlay (JS toggles .a11y--ruler) */
#a11y-ruler{
  position: fixed; left: 0; right: 0; height: var(--a11y-ruler-height, 2.75rem);
  top: var(--a11y-ruler-top, 40%); pointer-events: none; z-index: 100000; display: none;
  box-shadow: 0 -100vh 0 0 rgba(0,0,0,.6), 0 100vh 0 0 rgba(0,0,0,.6);
}
html.a11y--ruler #a11y-ruler{ display:block; }

/* Reader mode (hides peripheral UI; style main for readability) */
.a11y--reader body > header,
.a11y--reader nav,
.a11y--reader aside,
.a11y--reader footer,
.a11y--reader [role="banner"],
.a11y--reader [role="navigation"],
.a11y--reader [role="complementary"],
.a11y--reader .sidebar,
.a11y--reader .hero,
.a11y--reader .advertisement { display: none !important; }
.a11y--reader main { max-width: 70ch; margin: 2rem auto; font-size: 115%; }

/* Respect user OS pref by default */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

html.a11y--focus-strong :where(a, button, input, textarea, select, details, summary, [tabindex]):focus-visible,
html.a11y--focus-strong :where(a, button, input, textarea, select, details, summary, [tabindex]):focus {
  outline: 2px solid transparent !important;
  box-shadow: 0 0 0 2px #fff, 0 0 0 5px #0a0a0a !important;
  outline-offset: 2px !important;
}

html.a11y--big-targets :where(button, input[type="button"], input[type="submit"], input[type="reset"], label, [role="button"], a.btn, a.button) {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; min-height: 24px; /* WCAG 2.5.8 */
}

/* optionally include your design-system classes */
html.a11y--big-targets :where(.btn, .button, .nav-link, .pagination a){
  min-height: 24px;
}

html.a11y--show-link-urls body a[href^="https://"]::after,
html.a11y--show-link-urls body a[href^="http://"]::after {
  content: " (" attr(href) ")";
  font-size: .85em;
  word-break: break-all;
}

.a11y-panel{
  right: 1rem; bottom: 3.5rem; width: 20rem;  /* a bit narrower */
  max-width: calc(100vw - 2rem);
  max-height: calc(100vh - 2rem);
  overflow: auto;
}

/* Small screens: stretch near full width and lower margins */
@media (max-width: 480px){
  .a11y-panel{
    right: .5rem; left: .5rem; bottom: .5rem; width: auto;
    max-height: calc(100vh - 1rem);
  }
}