/* ============================================================
   ACCESSIBILITY TOOLBAR
   ============================================================ */

/* ── Toolbar container — fixed top-right ─────────── */
#a11y-toolbar {
  position: fixed;
  top: 88px;
  right: 160px;
  z-index: 10000;
  font-family: 'DM Sans', sans-serif;
}

/* ── Toggle button ──────────────────────────────── */
#a11y-toolbar-toggle {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
  transition: background 0.2s, transform 0.15s;
}
#a11y-toolbar-toggle:hover {
  background: #145f55;
  transform: scale(1.06);
}
#a11y-toolbar-toggle:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
}

/* ── Panel (dropdown below toggle) ──────────────── */
#a11y-toolbar-panel {
  position: absolute;
  top: 48px;
  right: 0;
  width: 270px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  padding: 0 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#a11y-toolbar-panel[hidden] {
  display: none;
}

/* ── Panel header (title + close) ───────────────── */
.a11y-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
}

.a11y-panel-heading {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
  outline: none;
}

.a11y-close-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--mid);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.a11y-close-btn:hover {
  background: #f0f0f0;
  color: var(--ink);
}
.a11y-close-btn:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
}

/* ── Section ────────────────────────────────────── */
.a11y-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.a11y-section-toggle {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.a11y-section-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--mid);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Font size controls ─────────────────────────── */
.a11y-fontsize-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.a11y-fontsize-label {
  flex: 1;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
}

/* ── Buttons ────────────────────────────────────── */
.a11y-btn {
  border: 1px solid rgba(27,122,110,0.25);
  background: var(--teal-bg);
  color: var(--teal);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}
.a11y-btn:hover {
  background: var(--teal);
  color: #fff;
}
.a11y-btn:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
}
.a11y-btn-sm { font-size: 0.78rem; }
.a11y-btn-lg { font-size: 0.95rem; }

/* ── Contrast buttons ───────────────────────────── */
.a11y-contrast-controls {
  display: flex;
  gap: 6px;
}
.a11y-contrast-btn {
  flex: 1;
  text-align: center;
  padding: 6px 8px;
  font-size: 0.8rem;
}
.a11y-contrast-btn[aria-pressed="true"] {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

/* ── Switch toggle ──────────────────────────────── */
.a11y-switch {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
}
.a11y-switch:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
  border-radius: 14px;
}
.a11y-switch-track {
  display: block;
  width: 40px;
  height: 22px;
  border-radius: 14px;
  background: #ccc;
  position: relative;
  transition: background 0.2s;
}
.a11y-switch[aria-checked="true"] .a11y-switch-track {
  background: var(--teal);
}
.a11y-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.a11y-switch[aria-checked="true"] .a11y-switch-thumb {
  transform: translateX(18px);
}

/* ── Reset button ───────────────────────────────── */
.a11y-reset-btn {
  width: 100%;
  margin-top: 4px;
  background: transparent;
  border: 1px solid rgba(0,0,0,0.12);
  color: var(--mid);
  font-size: 0.8rem;
  font-weight: 500;
}
.a11y-reset-btn:hover {
  background: #f5f5f5;
  color: var(--ink);
}

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

/* ── Mobile ─────────────────────────────────────── */
@media (max-width: 900px) {
  #a11y-toolbar {
    right: auto;
    left: 16px;
    top: 20px;
  }
  #a11y-toolbar-panel {
    width: calc(100vw - 32px);
    left: 0;
    right: auto;
  }
  #a11y-toolbar-toggle {
    width: 34px;
    height: 34px;
  }
}

/* ============================================================
   ACCESSIBILITY MODE STYLES
   Applied by JS via classes on <html>
   ============================================================ */

/* ── Dyslexia font ──────────────────────────────── */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Regular.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Bold.woff') format('woff');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

html.a11y-dyslexia,
html.a11y-dyslexia body,
html.a11y-dyslexia h1,
html.a11y-dyslexia h2,
html.a11y-dyslexia h3,
html.a11y-dyslexia h4,
html.a11y-dyslexia h5,
html.a11y-dyslexia p,
html.a11y-dyslexia a,
html.a11y-dyslexia li,
html.a11y-dyslexia td,
html.a11y-dyslexia th,
html.a11y-dyslexia span,
html.a11y-dyslexia button,
html.a11y-dyslexia input,
html.a11y-dyslexia textarea,
html.a11y-dyslexia select,
html.a11y-dyslexia label {
  font-family: 'OpenDyslexic', sans-serif !important;
  letter-spacing: 0.05em;
  word-spacing: 0.12em;
  line-height: 1.8;
}

/* ── High contrast: light ───────────────────────── */
html.a11y-contrast-light {
  --cream: #ffffff;
  --ink: #000000;
  --mid: #222222;
  --teal: #005f56;
  --teal-lt: #007a6e;
  --teal-bg: #d4f5f0;
  --blue: #002a4a;
  --blue-lt: #004b8d;
  --orange: #c24500;
  --orange-lt: #d46a00;
}
html.a11y-contrast-light body {
  background: #ffffff;
  color: #000000;
}
html.a11y-contrast-light nav {
  background: rgba(255,255,255,0.98);
  border-bottom: 2px solid #000;
}
html.a11y-contrast-light .pillar,
html.a11y-contrast-light .badge,
html.a11y-contrast-light .prog-card,
html.a11y-contrast-light .article-card {
  border: 2px solid #000;
}
html.a11y-contrast-light a {
  text-decoration: underline;
}

/* ── High contrast: dark ────────────────────────── */
html.a11y-contrast-dark {
  --cream: #121212;
  --ink: #f0f0f0;
  --mid: #cccccc;
  --teal: #2dd4bf;
  --teal-lt: #5eead4;
  --teal-bg: #1a2e2b;
  --blue: #93c5fd;
  --blue-lt: #bfdbfe;
  --orange: #fb923c;
  --orange-lt: #fdba74;
}
html.a11y-contrast-dark body {
  background: #121212;
  color: #f0f0f0;
}
html.a11y-contrast-dark nav {
  background: rgba(18,18,18,0.98);
  border-bottom: 1px solid rgba(255,255,255,0.2);
}
html.a11y-contrast-dark .nav-links a {
  color: #ccc;
}
html.a11y-contrast-dark .nav-links a:hover {
  color: #5eead4;
}
html.a11y-contrast-dark .logo-text {
  color: #f0f0f0;
}
html.a11y-contrast-dark .pillar,
html.a11y-contrast-dark .badge,
html.a11y-contrast-dark .prog-card,
html.a11y-contrast-dark .article-card,
html.a11y-contrast-dark .info-banner {
  background: #1e1e1e;
  border: 1px solid rgba(255,255,255,0.15);
  color: #f0f0f0;
}
html.a11y-contrast-dark footer {
  background: #0a0a0a;
}
html.a11y-contrast-dark .hero-card-main {
  background: #1a3d38;
}
html.a11y-contrast-dark input,
html.a11y-contrast-dark textarea,
html.a11y-contrast-dark select {
  background: #1e1e1e;
  color: #f0f0f0;
  border-color: rgba(255,255,255,0.3);
}
html.a11y-contrast-dark .data-table th {
  background: #1a2e2b;
}
html.a11y-contrast-dark .data-table td {
  background: #1e1e1e;
  color: #f0f0f0;
}
html.a11y-contrast-dark .page-hero {
  background: #1a1a1a;
}
html.a11y-contrast-dark #a11y-toolbar-panel {
  background: #1e1e1e;
  color: #f0f0f0;
}
html.a11y-contrast-dark .a11y-panel-heading {
  color: #f0f0f0;
}
html.a11y-contrast-dark .a11y-close-btn {
  color: #aaa;
}
html.a11y-contrast-dark .a11y-close-btn:hover {
  background: #333;
  color: #f0f0f0;
}
html.a11y-contrast-dark .a11y-section-label {
  color: #aaa;
}
html.a11y-contrast-dark .a11y-fontsize-label {
  color: #f0f0f0;
}
html.a11y-contrast-dark .a11y-btn {
  background: #2a2a2a;
  border-color: rgba(255,255,255,0.2);
  color: #5eead4;
}
html.a11y-contrast-dark .a11y-btn:hover {
  background: #5eead4;
  color: #121212;
}
html.a11y-contrast-dark .a11y-reset-btn {
  color: #aaa;
  border-color: rgba(255,255,255,0.15);
}
html.a11y-contrast-dark .a11y-reset-btn:hover {
  background: #2a2a2a;
  color: #f0f0f0;
}
html.a11y-contrast-dark .nav-hamburger {
  color: #f0f0f0;
}
html.a11y-contrast-dark .card {
  background: #1e1e1e;
  border: 1px solid rgba(255,255,255,0.15);
  color: #f0f0f0;
}

/* ── Reduced motion (toolbar toggle) ───────────── */
html.a11y-reduced-motion,
html.a11y-reduced-motion *,
html.a11y-reduced-motion *::before,
html.a11y-reduced-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}
html.a11y-reduced-motion .marquee-inner {
  animation: none !important;
}

/* ── Reduced motion (OS preference) ────────────── */
/* ── Dark mode (OS preference, applied when no user override) ── */
@media (prefers-color-scheme: dark) {
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) {
    --cream: #121212;
    --ink: #f0f0f0;
    --mid: #cccccc;
    --teal: #2dd4bf;
    --teal-lt: #5eead4;
    --teal-bg: #1a2e2b;
    --blue: #93c5fd;
    --blue-lt: #bfdbfe;
    --orange: #fb923c;
    --orange-lt: #fdba74;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) body {
    background: #121212;
    color: #f0f0f0;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) nav {
    background: rgba(18,18,18,0.98);
    border-bottom: 1px solid rgba(255,255,255,0.2);
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .nav-links a {
    color: #ccc;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .nav-links a:hover {
    color: #5eead4;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .logo-text {
    color: #f0f0f0;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .pillar,
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .badge,
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .prog-card,
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .article-card,
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .info-banner {
    background: #1e1e1e;
    border: 1px solid rgba(255,255,255,0.15);
    color: #f0f0f0;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) footer {
    background: #0a0a0a;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .hero-card-main {
    background: #1a3d38;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) input,
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) textarea,
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) select {
    background: #1e1e1e;
    color: #f0f0f0;
    border-color: rgba(255,255,255,0.3);
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .data-table th {
    background: #1a2e2b;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .data-table td {
    background: #1e1e1e;
    color: #f0f0f0;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .page-hero {
    background: #1a1a1a;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) #a11y-toolbar-panel {
    background: #1e1e1e;
    color: #f0f0f0;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .a11y-panel-heading {
    color: #f0f0f0;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .a11y-close-btn {
    color: #aaa;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .a11y-section-label {
    color: #aaa;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .a11y-fontsize-label {
    color: #f0f0f0;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .a11y-btn {
    background: #2a2a2a;
    border-color: rgba(255,255,255,0.2);
    color: #5eead4;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .nav-hamburger {
    color: #f0f0f0;
  }
  html:not(.a11y-contrast-light):not(.a11y-contrast-dark) .card {
    background: #1e1e1e;
    border: 1px solid rgba(255,255,255,0.15);
    color: #f0f0f0;
  }
}

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