/* Accessibility preferences: the floating button, its panel, and the modes the options turn on
   (classes on <html>, set by a11y.js). Shared by every page. The CSP allows no inline styles.
   Recolouring uses plain CSS, never filter/transform on an ancestor: those would turn the
   page into the containing block of the fixed button. */

/* --a11y-mark and the high-contrast colours live in tokens.css. */

.a11y-btn {
  position: fixed;
  inset-inline-start: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 60;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid var(--color-ink);
  border-radius: 50%;
  background: var(--color-paper);
  color: var(--color-ink);
  cursor: pointer;
}
.a11y-btn svg { width: 26px; height: 26px; fill: currentColor; }
.a11y-btn:focus-visible, .a11y-panel button:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 3px; }

.a11y-panel {
  position: fixed;
  inset-inline-start: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 60;
  width: min(320px, calc(100% - 32px));
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  padding: var(--space-lg);
  background: var(--color-paper);
  color: var(--color-ink);
  border: 1px solid var(--color-stroke);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-float);
  font-size: 0.95rem;
  line-height: 1.5;
}
.a11y-panel[hidden] { display: none; }
.a11y-hint { margin: 0 0 var(--space-xs); font-size: 0.85rem; }
.a11y-panel h2 { margin: 0 0 var(--space-xs); font-size: 1.1rem; }
.a11y-panel button { font: inherit; color: inherit; cursor: pointer; }

.a11y-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  width: 100%;
  min-height: 44px;
  padding: var(--space-2xs) 0;
  border: 0;
  background: none;
  text-align: start;
}
/* px, not rem: the font-size modes change the root size, and the thumb offsets are fixed.
   The thumb is anchored with a physical `left` so translateX is right in RTL. */
.a11y-track {
  position: relative;
  flex: none;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: var(--color-muted);
}
.a11y-track::after {
  content: "";
  position: absolute;
  left: 0;
  top: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-paper-3);
  transform: translateX(3px);
  transition: transform var(--dur-short) var(--ease-in-out);
}
.a11y-switch[aria-checked="true"] .a11y-track { background: var(--color-focus); }
.a11y-switch[aria-checked="true"] .a11y-track::after { transform: translateX(23px); }

.a11y-font { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-xs); margin: var(--space-xs) 0 var(--space-2xs); }
.a11y-font button, .a11y-actions button {
  min-height: 44px;
  border: 1px solid var(--color-ink);
  border-radius: 999px;
  background: transparent;
}
.a11y-font button[aria-pressed="true"] { background: var(--color-ink); color: var(--color-paper); }
.a11y-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-xs); margin-top: var(--space-sm); }
.a11y-statement { display: block; white-space: nowrap; margin-top: var(--space-sm); color: inherit; text-underline-offset: 3px; }

/* Modes ------------------------------------------------------------------------------ */
html.a11y-keyboard *:focus,
html.a11y-keyboard *:focus-visible {
  outline: 3px solid var(--a11y-mark) !important;
  outline-offset: 3px !important;
}

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

html.a11y-contrast { --a11y-mark: var(--a11y-hc-mark); background-color: var(--a11y-hc-paper) !important; }
html.a11y-contrast body,
html.a11y-contrast body *:not(img):not(video):not(picture):not(svg) {
  background-color: var(--a11y-hc-paper) !important;
  color: var(--a11y-hc-ink) !important;
  background-image: none !important;
}
html.a11y-contrast a { color: var(--a11y-hc-link) !important; }
html.a11y-contrast input, html.a11y-contrast textarea,
html.a11y-contrast select, html.a11y-contrast button { border: 1px solid var(--a11y-hc-ink) !important; }
html.a11y-contrast ::placeholder { color: var(--a11y-hc-placeholder) !important; opacity: 1; }
html.a11y-contrast .grain { display: none !important; }
/* The panel stays readable in its own mode; state is the thumb position and aria-checked. */
html.a11y-contrast .a11y-track { background-color: var(--a11y-hc-paper) !important; box-shadow: 0 0 0 1px var(--a11y-hc-ink); }
html.a11y-contrast .a11y-track::after { background-color: var(--a11y-hc-ink) !important; }
html.a11y-contrast .a11y-font button[aria-pressed="true"] { background-color: var(--a11y-hc-ink) !important; color: var(--a11y-hc-paper) !important; }

html.a11y-font-lg { font-size: 115%; }
html.a11y-font-sm { font-size: 88%; }

html.a11y-readable body *:not(i):not(svg):not(code):not(pre):not([class*="icon"]) {
  font-family: var(--font-readable) !important;
  letter-spacing: 0.015em;
}

html.a11y-spacing body *:not(svg):not(code):not(pre) { line-height: 1.9 !important; }

/* A large arrow cursor (data: images are allowed by the CSP's img-src). */
html.a11y-cursor, html.a11y-cursor body * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24'%3E%3Cpath d='M3 2l16 9-7 2 4 8-3 1-4-8-5 5z' fill='%23000' stroke='%23fff' stroke-width='1.5'/%3E%3C/svg%3E") 3 2, auto !important;
}

html.a11y-headings h1, html.a11y-headings h2,
html.a11y-headings h3, html.a11y-headings h4 {
  outline: 2px dashed var(--a11y-mark) !important;
  outline-offset: 6px;
}

html.a11y-links a,
html.a11y-links button {
  outline: 2px solid var(--a11y-link-ring) !important;
  text-decoration: underline !important;
}

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