/* ========================================================
   A11Y — Accessibility toolbar (load last, after components).
   Driven by the html[data-a11y-*] attributes toggled by
   modules/a11y.js; preferences are re-applied before first
   paint by the inline head script in base.html.
   ======================================================== */

/* ─── 1. Text size steps ────────────────────────────────
   The whole app is built on rem, so scaling the root font
   size scales every heading, paragraph and control. */
html[data-a11y-font="large"]  { font-size: 112.5%; } /* ~18px base */
html[data-a11y-font="xlarge"] { font-size: 125%; }   /* ~20px base */

/* ─── 2. High contrast ──────────────────────────────────
   Overrides the theme tokens for whichever theme is active
   (this file loads after variables.css, so it wins ties). */
html[data-a11y-contrast="on"] {
  --bg: #ffffff;
  --bg-alt: #f2f2f2;
  --surface: #ffffff;
  --surface-2: #f2f2f2;
  --border: #000000;
  --fg: #000000;
  --muted: #1a1a1a;
  --primary: #003b8f;
  --primary-dark: #002a66;
  --primary-foreground: #ffffff;
  --primary-hover: #002a66;
}

html[data-theme="dark"][data-a11y-contrast="on"] {
  --bg: #000000;
  --bg-alt: #0a0a0a;
  --surface: #000000;
  --surface-2: #111111;
  --border: #ffffff;
  --fg: #ffffff;
  --muted: #e6e6e6;
  --primary: #9ecbff;
  --primary-dark: #cfe4ff;
  --primary-foreground: #000000;
  --primary-hover: #cfe4ff;
  --accent: #9ecbff;
  --accent-foreground: #000000;
  --accent-hover: #cfe4ff;
}

/* Links are unmistakable in high-contrast mode */
html[data-a11y-contrast="on"] a {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

/* Stronger, offset focus ring */
html[data-a11y-contrast="on"] :focus-visible {
  outline: 3px solid var(--fg);
  outline-offset: 2px;
}

/* ─── 3. Reduce motion ──────────────────────────────────
   Mirrors prefers-reduced-motion, but user-toggled: every
   transition/animation snaps; slideshows still swap images,
   carousels still advance — just without easing. */
html[data-a11y-motion="on"],
html[data-a11y-motion="on"] *,
html[data-a11y-motion="on"] *::before,
html[data-a11y-motion="on"] *::after {
  animation-duration: 0.01ms !important;
  animation-delay: 0s !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  transition-delay: 0s !important;
  scroll-behavior: auto !important;
}

/* ─── 4. Floating toolbar ───────────────────────────────
   Bottom-left, stacked above the 44px back-to-top button
   (1.5rem gutter + 2.75rem button + 0.5rem gap = 4.75rem).
   Donate FAB is bottom-right — no collision either side. */
.a11y-fab {
  position: fixed;
  left: 1.5rem;
  bottom: 4.75rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-full);
  background-color: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.18s ease, background-color 0.18s ease;
}
.a11y-fab:hover {
  background-color: var(--surface-2);
  transform: translateY(-2px);
}
.a11y-fab svg { width: 22px; height: 22px; }

.a11y-panel {
  position: fixed;
  left: 1.5rem;
  bottom: calc(4.75rem + 44px + 0.5rem);
  width: min(17rem, calc(100vw - 3rem));
  background-color: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--r-lg, 0.75rem);
  box-shadow: var(--shadow-xl, 0 20px 40px rgba(0, 0, 0, 0.25));
  padding: 1rem;
  z-index: 1001;
}
.a11y-panel[hidden] { display: none; }

.a11y-panel-title {
  font-size: var(--text-small, 0.875rem);
  font-weight: 700;
  letter-spacing: var(--tracking-wide, 0.04em);
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.a11y-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.625rem;
}

.a11y-row-label {
  font-size: var(--text-small, 0.875rem);
  font-weight: 600;
}

.a11y-group {
  display: flex;
  gap: 0.375rem;
}

.a11y-btn {
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0.25rem 0.5rem;
  font-size: var(--text-small, 0.875rem);
  font-weight: 700;
  color: var(--fg);
  background-color: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md, 0.5rem);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.a11y-btn:hover:not(:disabled) {
  background-color: var(--primary);
  color: var(--primary-foreground, #fff);
}
.a11y-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.a11y-btn[aria-pressed="true"] {
  background-color: var(--primary);
  color: var(--primary-foreground, #fff);
  border-color: var(--primary);
}

.a11y-reset {
  width: 100%;
  margin-top: 0.25rem;
  background-color: transparent;
}
.a11y-reset:hover:not(:disabled) {
  background-color: var(--primary);
  color: var(--primary-foreground, #fff);
}

/* Keep the toolbar usable on narrow screens */
@media (max-width: 480px) {
  .a11y-fab { left: 1rem; bottom: 4.5rem; }

/* ─── 5. Skip link (blind & keyboard users) ───────────────
   First tabbable element after <body>; visually hidden
   until focused, then drops over the ticker/navbar so a
   screen-reader or keyboard user can jump straight past
   them to #main-content. */
.skip-link {
  position: fixed;
  top: -100%;
  left: 1.5rem;
  z-index: 2000;
  padding: 0.75rem 1.25rem;
  background-color: var(--primary);
  color: var(--primary-foreground, #fff);
  font-size: var(--text-small, 0.875rem);
  font-weight: 700;
  text-decoration: none;
  border-radius: var(--r-md, 0.5rem);
  box-shadow: var(--shadow-lg, 0 10px 25px rgba(0, 0, 0, 0.2));
  transition: top 0.18s ease;
}
.skip-link:focus {
  top: 1.5rem;
}
@media (max-width: 480px) {
  .skip-link { left: 1rem; }
}
  .a11y-panel { left: 1rem; bottom: calc(4.5rem + 44px + 0.5rem); }
}