/* ==========================================================================
   Accessibility: skip link, focus rings, the user-selectable options (classes
   on <html>, set by a11y-init.js) and the accessibility panel.
   Ported from the Observatory website so both sites offer the same options.
   ========================================================================== */

/* ── Baseline ─────────────────────────────────────────────────────────── */

.a11y-skip {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100000;
  padding: 12px 20px;
  background: #fff;
  color: #4e165d;
  font-weight: 700;
  border-radius: 8px;
  border: 3px solid #4e165d;
  text-decoration: none;
  transform: translateY(-200%);
}
.a11y-skip:focus { transform: translateY(0); }
.a11y-skip[hidden] { display: none; }

[tabindex="-1"]:focus { outline: none; }

/* Visible keyboard focus on light and dark surfaces: blue ring with a white halo */
:where(a, button, input, select, textarea, summary, [tabindex], [role="button"]):focus-visible {
  outline: 3px solid #0b57d0;
  outline-offset: 2px;
  box-shadow: 0 0 0 2px #fff;
}

/* ── User options ─────────────────────────────────────────────────────── */

/* Text spacing: the WCAG 1.4.12 values */
html.a11y-spacing body *:not(#a11y-root):not(#a11y-root *):not(i):not(svg *) {
  line-height: 1.5 !important;
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
}
html.a11y-spacing body p { margin-bottom: 2em !important; }

/* Dyslexia-friendly font (Atkinson Hyperlegible, loaded when first chosen) */
html.a11y-dyslexia body,
html.a11y-dyslexia body *:not(i):not(.fa):not(.fas):not(.far):not(.fab):not(.fa-solid):not(.fa-regular):not(.fa-brands) {
  font-family: "Atkinson Hyperlegible", "Verdana", "Arial", sans-serif !important;
}

html.a11y-align body *:not(#a11y-root):not(#a11y-root *) { text-align: left !important; }

html.a11y-motion { scroll-behavior: auto !important; }
html.a11y-motion *, html.a11y-motion *::before, html.a11y-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  animation-delay: 0s !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

html.a11y-links a:not(#a11y-root a) {
  text-decoration: underline !important;
  text-decoration-thickness: 2px !important;
  text-underline-offset: 3px !important;
  background: #fff3a3 !important;
  color: #1a0a52 !important;
  outline: 2px solid #1a0a52;
  outline-offset: 1px;
}

html.a11y-focus :focus {
  outline: 4px solid #0b57d0 !important;
  outline-offset: 3px !important;
  box-shadow: 0 0 0 3px #fff, 0 0 0 7px #000 !important;
}

html.a11y-cursor, html.a11y-cursor * {
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'><path d='M4 2l16 9-7 2-3 7z' fill='black' stroke='white' stroke-width='1.5'/></svg>") 4 2, auto !important;
}
html.a11y-cursor a, html.a11y-cursor button, html.a11y-cursor [role="button"], html.a11y-cursor input, html.a11y-cursor label {
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'><path d='M4 2l16 9-7 2-3 7z' fill='%23702283' stroke='white' stroke-width='1.5'/></svg>") 4 2, pointer !important;
}

/* Hide images (charts are drawn on <canvas> and stay) */
html.a11y-noimg img, html.a11y-noimg picture, html.a11y-noimg video { display: none !important; }

/* Dark theme: the page is inverted; pictures and charts are flipped back so they keep
   their own colours. Charts draw light text for this theme themselves (chart-a11y.js). */
html.a11y-contrast-dark img,
html.a11y-contrast-dark video,
html.a11y-contrast-dark picture,
html.a11y-contrast-dark canvas,
html.a11y-contrast-dark iframe {
  filter: invert(1) hue-rotate(180deg);
}

/* High contrast, dark: white on black, yellow links */
html.a11y-contrast-hc-dark body *:not(#a11y-root):not(#a11y-root *) {
  background-color: #000 !important;
  background-image: none !important;
  color: #fff !important;
  border-color: #fff !important;
  box-shadow: none !important;
  text-shadow: none !important;
}
html.a11y-contrast-hc-dark body { background: #000 !important; }
html.a11y-contrast-hc-dark a:not(#a11y-root a), html.a11y-contrast-hc-dark a * { color: #ffff00 !important; text-decoration: underline !important; }
html.a11y-contrast-hc-dark button:not(#a11y-root button) { border: 2px solid #ffff00 !important; }
html.a11y-contrast-hc-dark svg:not(#a11y-root svg), html.a11y-contrast-hc-dark i { color: #fff !important; fill: currentColor; }
/* Charts (canvas) draw their own colours; chart-a11y.js switches them to white or black ink */

/* High contrast, light: black on white, blue links */
html.a11y-contrast-hc-light body *:not(#a11y-root):not(#a11y-root *) {
  background-color: #fff !important;
  background-image: none !important;
  color: #000 !important;
  border-color: #000 !important;
  box-shadow: none !important;
  text-shadow: none !important;
}
html.a11y-contrast-hc-light body { background: #fff !important; }
html.a11y-contrast-hc-light a:not(#a11y-root a), html.a11y-contrast-hc-light a * { color: #0000cc !important; text-decoration: underline !important; }
html.a11y-contrast-hc-light button:not(#a11y-root button) { border: 2px solid #000 !important; }

/* Reading ruler */
#a11y-ruler {
  position: fixed;
  left: 0;
  width: 100%;
  height: 3.2rem;
  top: 40%;
  z-index: 99990;
  pointer-events: none;
  border-top: 3px solid #ffd400;
  border-bottom: 3px solid #ffd400;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.5);
}
#a11y-ruler[hidden] { display: none; }

/* ── The panel ────────────────────────────────────────────────────────── */

#a11y-root, #a11y-root * { box-sizing: border-box; }
#a11y-root {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  letter-spacing: normal;
  word-spacing: normal;
}

/* Bottom right, above the sign-up prompt that appears in the corner */
.a11y-fab {
  position: fixed;
  right: 20px;
  bottom: 92px;
  z-index: 9990;            /* below the cookie notice (9998) */
  width: 52px;
  height: 52px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 3px solid #fff;
  background: #4e165d;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}
.a11y-fab:hover { transform: scale(1.06); background: #702283; }
.a11y-fab svg { width: 30px; height: 30px; fill: currentColor; }

.a11y-panel {
  position: fixed;
  right: 20px;
  bottom: 156px;
  z-index: 9991;
  width: 400px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 180px);
  max-height: calc(100dvh - 180px);
  display: flex;
  flex-direction: column;
  background: #fff;
  color: #1e293b;
  border-radius: 18px;
  border: 1px solid #d9cce2;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
  overflow: hidden;
  overflow: clip;   /* the box itself never scrolls; only .a11y-body does */
  overscroll-behavior: contain;
}
.a11y-panel[hidden] { display: none; }

.a11y-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, #4a0f6a, #702283);
  color: #fff;
  flex-shrink: 0;
}
.a11y-head h2 { margin: 0; font-size: 18px; font-weight: 700; color: #fff; }
.a11y-close {
  width: 40px; height: 40px;
  border: 0; border-radius: 10px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff; font-size: 24px; line-height: 1; cursor: pointer;
}
.a11y-close:hover { background: rgba(255, 255, 255, 0.3); }

.a11y-body { padding: 8px 18px 6px; overflow-y: auto; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }
.a11y-group { border: 0; padding: 14px 0; margin: 0; border-bottom: 1px solid #ece4f1; min-width: 0; }
.a11y-group:last-of-type { border-bottom: 0; }
.a11y-group legend { float: left; width: 100%; }
.a11y-group legend + * { clear: both; }
.a11y-group legend, .a11y-group-title {
  padding: 0; margin: 0 0 10px;
  font-size: 12px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: #702283;
}

.a11y-seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.a11y-seg-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.a11y-seg label { position: relative; display: block; min-width: 0; }
.a11y-seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.a11y-seg span {
  position: relative;
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 44px; padding: 8px 6px;
  border: 2px solid #d9cce2; border-radius: 10px;
  font-size: 14px; font-weight: 600; background: #fff; color: #1e293b;
}
.a11y-seg input:checked + span { border-color: #702283; background: #f3e8ff; color: #4a0f6a; }
.a11y-seg-4 span { padding-left: 2px; padding-right: 2px; font-size: 13px; }
.a11y-seg input:checked + span::after { content: "\2713"; position: absolute; top: 1px; right: 4px; font-size: 11px; font-weight: 800; color: #702283; }
.a11y-seg input:focus-visible + span { outline: 3px solid #0b57d0; outline-offset: 2px; }

.a11y-switch {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: relative; min-height: 44px; padding: 6px 0; cursor: pointer; font-size: 15px; font-weight: 500;
}
.a11y-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.a11y-track {
  position: relative; flex-shrink: 0; width: 46px; height: 26px; border-radius: 99px;
  background: #6b7280; transition: background 0.15s;
}
.a11y-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform 0.15s;
}
.a11y-switch input:checked + .a11y-track { background: #702283; }
.a11y-switch input:checked + .a11y-track::after { transform: translateX(20px); }
.a11y-switch input:focus-visible + .a11y-track { outline: 3px solid #0b57d0; outline-offset: 2px; }

.a11y-foot { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid #ece4f1; background: #faf7fc; flex-shrink: 0; }
.a11y-btn {
  flex: 1; min-height: 44px; padding: 10px 14px; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer;
  border: 2px solid #702283; background: #fff; color: #4a0f6a;
}
.a11y-btn:hover { background: #f3e8ff; }
.a11y-note { margin: 0; padding: 0 18px 12px; font-size: 12px; color: #475569; background: #faf7fc; flex-shrink: 0; }

@media (max-width: 768px) {
  .a11y-fab { right: 12px; bottom: 84px; width: 46px; height: 46px; border-width: 2px; }
  .a11y-fab svg { width: 27px; height: 27px; }
  .a11y-panel {
    left: 8px; right: 8px; bottom: 8px;
    width: auto; max-width: none;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }
}

@media (prefers-reduced-motion: reduce) { .a11y-fab, .a11y-track, .a11y-track::after { transition: none; } }

/* Print: the panel and ruler are screen-only */
@media print { #a11y-root, .a11y-skip { display: none !important; } }
