/* ==========================================================================
   Ability Beyond Vision — shared accessibility layer
   Include on EVERY page of the platform, before any page-specific CSS:
     <link rel="stylesheet" href="/assets/a11y.css">
     <script src="/assets/a11y.js" defer></script>
   Targets WCAG 2.2 level AA.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Colour schemes
   Every pairing below is checked against WCAG 1.4.3 (4.5:1 body text,
   3:1 large text) and 1.4.11 (3:1 for UI components and focus indicators).
   -------------------------------------------------------------------------- */

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

:root {
  --bg: #ffffff;
  --fg: #1a1a1a;          /* 16.9:1 on white */
  --muted: #45494d;       /* 9.1:1  on white */
  --accent: #00457a;      /* 9.5:1  on white */
  --on-accent: #ffffff;
  --surface: #f2f4f6;
  --rule: #6b7075;        /* 4.6:1  on white — passes non-text contrast */
  --focus: #b8003a;
  --logo-panel: #000000;

  --text-scale: 1;
  --zoom: 1;
}

/* Follow the operating system when the user has not chosen a scheme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #101418;
    --fg: #f2f2f2;        /* 15.9:1 */
    --muted: #c8ced4;     /* 10.4:1 */
    --accent: #7fc4ff;    /* 9.2:1  */
    --on-accent: #101418;
    --surface: #1b2128;
    --rule: #79828b;      /* 4.7:1  */
    --focus: #ffb000;
    --logo-panel: #000000;
  }
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #45494d;
  --accent: #00457a;
  --on-accent: #ffffff;
  --surface: #f2f4f6;
  --rule: #6b7075;
  --focus: #b8003a;
  --logo-panel: #000000;
}

:root[data-theme="dark"] {
  --bg: #101418;
  --fg: #f2f2f2;
  --muted: #c8ced4;
  --accent: #7fc4ff;
  --on-accent: #101418;
  --surface: #1b2128;
  --rule: #79828b;
  --focus: #ffb000;
  --logo-panel: #000000;
}

/* Maximum contrast: pure black and white, 21:1 throughout. */
:root[data-theme="contrast"] {
  --bg: #000000;
  --fg: #ffffff;
  --muted: #ffffff;
  --accent: #ffffff;
  --on-accent: #000000;
  --surface: #000000;
  --rule: #ffffff;
  --focus: #ffff00;
  --logo-panel: #000000;
}

/* Yellow on black — widely preferred by people with low vision. 19.6:1 */
:root[data-theme="yellow"] {
  --bg: #000000;
  --fg: #ffd400;
  --muted: #ffd400;
  --accent: #ffd400;
  --on-accent: #000000;
  --surface: #141414;
  --rule: #ffd400;
  --focus: #ffffff;
  --logo-panel: #000000;
}

/* --------------------------------------------------------------------------
   2. Text size and zoom
   Scale is applied at the root so every rem-based measurement follows,
   satisfying 1.4.4 (resize to 200%) without a separate layout.
   -------------------------------------------------------------------------- */

html {
  font-size: calc(18px * var(--text-scale));
  zoom: var(--zoom);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: Arial, Helvetica, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.6;
}

/* 1.4.12 Text spacing — never clip content when users override spacing. */
p, li, dd, dt, h1, h2, h3 {
  overflow-wrap: break-word;
}

/* --------------------------------------------------------------------------
   3. Focus, targets and motion
   -------------------------------------------------------------------------- */

:where(a, button, input, select, textarea, summary):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* 2.4.11 Focus not obscured — nothing here is sticky, but guard anyway. */
:where(a, button, input, select, textarea, summary) {
  scroll-margin-top: 4rem;
}

/* 2.5.8 Target size — 44px comfortably exceeds the 24px minimum. */
.a11y-bar button,
.a11y-bar input[type="range"] {
  min-height: 44px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* --------------------------------------------------------------------------
   4. Skip link
   -------------------------------------------------------------------------- */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: var(--on-accent);
  padding: 0.75rem 1.25rem;
  font-weight: bold;
}
.skip-link:focus { left: 0; }

/* --------------------------------------------------------------------------
   5. The accessibility toolbar
   Deliberately in the normal document flow, not fixed or floating, so it
   can never cover focused content (2.4.11) or trap a magnifier user.
   -------------------------------------------------------------------------- */

.a11y-bar {
  background: var(--surface);
  border-bottom: 2px solid var(--rule);
  color: var(--fg);
}

.a11y-bar__inner {
  max-width: 60rem;
  margin: 0 auto;
  padding: 0.5rem 1rem;
}

.a11y-bar__toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  color: var(--fg);
  border: 2px solid var(--rule);
  border-radius: 0.25rem;
  padding: 0.5rem 1rem;
  font: inherit;
  font-weight: bold;
  cursor: pointer;
  max-width: 100%;
  text-align: left;
  flex-wrap: wrap;
  overflow-wrap: break-word;
}

/* Option buttons must also wrap rather than push the layout wide. */
.a11y-options button,
.a11y-bar__reset {
  max-width: 100%;
  overflow-wrap: break-word;
}

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

.a11y-bar__panel {
  padding: 1rem 0 0.5rem;
}

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

.a11y-group {
  border: 2px solid var(--rule);
  border-radius: 0.25rem;
  padding: 0.75rem 1rem 1rem;
  margin: 0 0 1rem;
}

.a11y-group legend {
  font-weight: bold;
  padding: 0 0.4rem;
}

.a11y-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.a11y-options button {
  background: var(--bg);
  color: var(--fg);
  border: 2px solid var(--rule);
  border-radius: 0.25rem;
  padding: 0.5rem 1rem;
  font: inherit;
  cursor: pointer;
}

.a11y-options button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  font-weight: bold;
}

.a11y-slider {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Widths are intentionally in px, not rem: the slider must not grow with
   the text-size setting, or the toolbar overflows at large sizes (1.4.10). */
.a11y-slider input[type="range"] {
  flex: 1 1 160px;
  min-width: 0;
  max-width: 100%;
  accent-color: var(--accent);
}

.a11y-slider output {
  font-weight: bold;
  min-width: 4ch;
}

.a11y-group,
.a11y-bar__inner {
  max-width: 100%;
}

.a11y-bar__reset {
  background: var(--bg);
  color: var(--fg);
  border: 2px solid var(--rule);
  border-radius: 0.25rem;
  padding: 0.5rem 1rem;
  font: inherit;
  cursor: pointer;
}

/* Screen-reader-only helper. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* If scripting is unavailable the toolbar is hidden rather than broken;
   the page itself remains fully usable and the OS theme still applies. */
.no-js .a11y-bar { display: none; }
