/* ============================================================
   accessibility.css — Full Accessibility Module Styles
   ============================================================ */

/* ---- CSS Variables (Root defaults) ---- */
:root {
  --a11y-font-scale: 1;
  --a11y-line-height: 1.6;
  --a11y-letter-spacing: 0em;
  --a11y-text-align: left;

  --a11y-panel-bg: #ffffff;
  --a11y-panel-text: #1a1a2e;
  --a11y-panel-border: #e2e8f0;
  --a11y-accent: #2563eb;
  --a11y-switch-off: #cbd5e1;
  --a11y-switch-on: #2563eb;
  --a11y-panel-width: 340px;
  --a11y-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

/* ============================================================
   SKIP LINKS
   ============================================================ */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--color-accent, #2563eb);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 0 0 8px 8px;
  font-weight: 700;
  font-size: 0.95rem;
  z-index: 99999;
  text-decoration: none;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* ============================================================
   SCREEN READER ONLY
   ============================================================ */
/* .sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0) !important;
  white-space: nowrap !important;
  border: 0 !important;
} */
.sr-only {
  text-align: left;
  display: block;
  color: #fff;
  margin-bottom: 5px;
}

/* ============================================================
   ACCESSIBILITY WIDGET BUTTON
   ============================================================ */

/**
 * Lock the widget + panel to a fixed 16px base.
 * Because we scale the page by changing html { font-size },
 * rem units inside the panel would also grow. We counter this
 * by explicitly resetting font-size to 16px on the containers
 * and using px values for all internal sizes.
 */
#accessibility-widget,
#a11y-panel {
  font-size: 16px !important;
}

#accessibility-widget {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

#a11y-toggle-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-accent, #2563eb);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(37, 99, 235, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  letter-spacing: 0.01em;
}

#a11y-toggle-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(37, 99, 235, 0.5);
}

#a11y-toggle-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

/* ============================================================
   ACCESSIBILITY PANEL
   ============================================================ */
#a11y-panel {
  position: fixed;
  bottom: 5.5rem;
  right: 2rem;
  width: var(--a11y-panel-width);
  max-height: 80vh;
  background: var(--a11y-panel-bg);
  color: var(--a11y-panel-text);
  border-radius: 16px;
  box-shadow: var(--a11y-shadow);
  border: 1px solid var(--a11y-panel-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9998;
  transform: translateY(20px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

#a11y-panel.panel-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* Panel Header */
.a11y-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem 0.9rem;
  border-bottom: 1px solid var(--a11y-panel-border);
  background: var(--a11y-panel-bg);
  position: sticky;
  top: 0;
  z-index: 1;
}

.a11y-panel-header h2 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  color: var(--a11y-panel-text);
}

#a11y-close-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--a11y-panel-text);
  padding: 0.3rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: background 0.15s;
}

#a11y-close-btn:hover {
  background: rgba(0, 0, 0, 0.07);
}

#a11y-close-btn:focus-visible {
  outline: 3px solid var(--a11y-accent);
  outline-offset: 2px;
}

/* Panel Body */
.a11y-panel-body {
  overflow-y: auto;
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.a11y-panel-body section {
  margin-bottom: 0.75rem;
}

/* Reset Button */
.a11y-reset-all {
  width: 100%;
  background: transparent;
  border: 1.5px solid var(--a11y-panel-border);
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--a11y-panel-text);
  cursor: pointer;
  margin-bottom: 0.75rem;
  transition: background 0.15s, border-color 0.15s;
}

.a11y-reset-all:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: #94a3b8;
}

.a11y-reset-all:focus-visible {
  outline: 3px solid var(--a11y-accent);
  outline-offset: 2px;
}

/* Section Title */
.a11y-section-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
  margin: 0.5rem 0 0.6rem;
}

/* Single Control Row */
.a11y-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--a11y-panel-border);
}

.a11y-control:last-child {
  border-bottom: none;
}

.a11y-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--a11y-panel-text);
  cursor: default;
}

/* ============================================================
   TOGGLE SWITCH
   ============================================================ */
.a11y-switch {
  position: relative;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.a11y-switch:focus-visible {
  outline: 3px solid var(--a11y-accent);
  outline-offset: 3px;
  border-radius: 50px;
}

.switch-track {
  width: 44px;
  height: 24px;
  background: var(--a11y-switch-off);
  border-radius: 50px;
  position: relative;
  transition: background 0.25s ease;
  display: block;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.25s ease;
}

.a11y-switch[aria-checked="true"] .switch-track {
  background: var(--a11y-switch-on);
}

.a11y-switch[aria-checked="true"] .switch-thumb {
  transform: translateX(20px);
}

.switch-status {
  display: none;
}

/* ============================================================
   STEPPERS (Font Size, Line Height, Letter Spacing)
   ============================================================ */
.a11y-stepper-control .a11y-stepper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stepper-btn {
  background: var(--a11y-panel-border);
  border: none;
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--a11y-panel-text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.stepper-btn:hover {
  background: #94a3b8;
  color: #fff;
}

.stepper-btn:focus-visible {
  outline: 3px solid var(--a11y-accent);
  outline-offset: 2px;
}

#font-size-display,
#line-height-display,
#letter-spacing-display {
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 54px;
  text-align: center;
  color: var(--a11y-panel-text);
}

/* ============================================================
   TEXT ALIGN BUTTONS
   ============================================================ */
.a11y-btn-group {
  display: flex;
  gap: 0.3rem;
}

.align-btn {
  background: transparent;
  border: 1.5px solid var(--a11y-panel-border);
  border-radius: 6px;
  width: 32px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--a11y-panel-text);
  transition: background 0.15s, border-color 0.15s;
}

.align-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.align-btn[aria-pressed="true"],
.align-btn.active {
  background: var(--a11y-accent);
  border-color: var(--a11y-accent);
  color: #fff;
}

.align-btn:focus-visible {
  outline: 3px solid var(--a11y-accent);
  outline-offset: 2px;
}

/* ============================================================
   PANEL FOOTER
   ============================================================ */
.a11y-panel-footer {
  padding: 0.65rem 1.25rem;
  border-top: 1px solid var(--a11y-panel-border);
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: #94a3b8;
  letter-spacing: 0.04em;
  background: var(--a11y-panel-bg);
}

/* ============================================================
   READING MASK OVERLAY
   ============================================================ */
#reading-mask-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9000;
  background: transparent;
}

#reading-mask-overlay.mask-active {
  display: block;
}

/* Top and bottom dark strips — the gap between is the reading strip */
#reading-mask-overlay::before,
#reading-mask-overlay::after {
  content: '';
  position: fixed;
  left: 0;
  width: 100%;
  background: rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

#reading-mask-overlay::before {
  top: 0;
  height: var(--mask-top, 0px);
}

#reading-mask-overlay::after {
  top: calc(var(--mask-top, 0px) + var(--mask-height, 80px));
  height: 100vh;
}

/* ============================================================
   BODY CLASS — FEATURE TOGGLES
   ============================================================ */

/* ---- Readable Font ---- */
body.readable-font,
body.readable-font * {
  font-family: 'Georgia', 'Times New Roman', serif !important;
}

/* ---- Dyslexia Font ---- */
body.dyslexia-font,
body.dyslexia-font * {
  font-family: 'OpenDyslexic', 'Comic Sans MS', cursive !important;
}

/* ---- Font Scale ---- */
body {
  font-size: calc(1rem * var(--a11y-font-scale));
}

/* ---- Line Height ---- */
body {
  line-height: var(--a11y-line-height);
}

/* ---- Letter Spacing ---- */
body p,
body li,
body span,
body a,
body label,
body input,
body textarea {
  letter-spacing: var(--a11y-letter-spacing);
}

/* ---- Text Align ---- */
body.text-align-left p,
body.text-align-left li {
  text-align: left;
}

body.text-align-center p,
body.text-align-center li {
  text-align: center;
}

body.text-align-right p,
body.text-align-right li {
  text-align: right;
}

/* ---- High Contrast (WCAG) ---- */
body.high-contrast {
  background-color: #000000 !important;
  color: #ffffff !important;
}

body.high-contrast * {
  background-color: #000000 !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}

body.high-contrast a {
  color: #ffff00 !important;
  text-decoration: underline !important;
}

body.high-contrast button,
body.high-contrast .btn {
  background-color: #ffffff !important;
  color: #000000 !important;
  border: 2px solid #ffffff !important;
}

body.high-contrast img {
  filter: invert(1) !important;
}

body.high-contrast #a11y-panel,
body.high-contrast #a11y-toggle-btn {
  background-color: #1a1a1a !important;
  border-color: #ffffff !important;
}

/* ---- Greyscale ---- */
body.greyscale #page-wrapper {
  filter: grayscale(100%);
}

/* ---- Hide Images ---- */
body.hide-images img,
body.hide-images video,
body.hide-images svg:not(.keep-svg),
body.hide-images figure {
  visibility: hidden !important;
}

/* ---- Pause Animations ---- */
body.pause-animations *,
body.pause-animations *::before,
body.pause-animations *::after {
  animation-play-state: paused !important;
  transition-duration: 0s !important;
  transition-delay: 0s !important;
}

/* ---- Dark Mode ---- */
body.dark-mode {
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-text: #f1f5f9;
  --color-text-muted: #94a3b8;
  --color-border: #334155;
  background-color: #0f172a;
  color: #f1f5f9;
}

body.dark-mode header#site-header {
  background: #1e293b;
  border-bottom-color: #334155;
}

body.dark-mode footer#site-footer {
  background: #1e293b;
  border-top-color: #334155;
}

body.dark-mode .card {
  background: #1e293b;
  border-color: #334155;
}

body.dark-mode .bg-alt {
  background: #162032;
}

body.dark-mode #a11y-panel {
  --a11y-panel-bg: #1e293b;
  --a11y-panel-text: #f1f5f9;
  --a11y-panel-border: #334155;
  background: #1e293b !important;
  color: #f1f5f9 !important;
}

body.dark-mode input,
body.dark-mode textarea {
  background: #0f172a;
  color: #f1f5f9;
  border-color: #334155;
}

/* ---- Highlight Links ---- */
body.highlight-links a {
  background-color: #fef08a !important;
  color: #000 !important;
  text-decoration: underline !important;
  outline: 2px solid #f59e0b !important;
  border-radius: 3px;
  padding: 0 2px;
}

/* ---- Outline Focus ---- */
body.outline-focus *:focus,
body.outline-focus *:focus-visible {
  outline: 3px solid #f59e0b !important;
  outline-offset: 4px !important;
  border-radius: 4px;
}

/* ---- Page Structure ---- */
body.page-structure header[role="banner"],
body.page-structure nav,
body.page-structure main[id],
body.page-structure section,
body.page-structure footer[role="contentinfo"],
body.page-structure aside {
  outline: 2px solid #7c3aed !important;
  position: relative;
}

body.page-structure header[role="banner"]::before {
  content: 'HEADER';
}

body.page-structure nav::before {
  content: 'NAV';
}

body.page-structure main[id]::before {
  content: 'MAIN';
}

body.page-structure section::before {
  content: 'SECTION';
}

body.page-structure footer[role="contentinfo"]::before {
  content: 'FOOTER';
}

body.page-structure header[role="banner"]::before,
body.page-structure nav::before,
body.page-structure main[id]::before,
body.page-structure section::before,
body.page-structure footer[role="contentinfo"]::before {
  position: absolute;
  top: 0;
  left: 0;
  background: #7c3aed;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  letter-spacing: 0.08em;
  z-index: 100;
  pointer-events: none;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 480px) {
  #a11y-panel {
    width: calc(100vw - 2rem);
    right: 1rem;
    bottom: 5rem;
  }

  #accessibility-widget {
    right: 1rem;
    bottom: 1rem;
  }
}


/* Isolate widget from all body-level feature changes */
#accessibility-widget,
#accessibility-widget *,
#a11y-panel,
#a11y-panel * {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
  line-height: 1.5 !important;
  letter-spacing: 0 !important;
  text-align: left !important;
  filter: none !important;
  animation-play-state: running !important;
  transition-duration: unset !important;
  transition-delay: unset !important;
}

/* Block high-contrast from overriding panel */
body.high-contrast #accessibility-widget,
body.high-contrast #accessibility-widget *,
body.high-contrast #a11y-panel,
body.high-contrast #a11y-panel * {
  background-color: unset !important;
  color: unset !important;
  border-color: unset !important;
}

body.high-contrast #a11y-panel {
  background: var(--a11y-panel-bg) !important;
  color: var(--a11y-panel-text) !important;
}

body.high-contrast #a11y-toggle-btn {
  background: var(--color-accent, #2563eb) !important;
  color: #fff !important;
}

/* Block greyscale from widget */
body.greyscale #accessibility-widget {
  filter: none !important;
}

/* Block hide-images from affecting widget SVGs */
body.hide-images #accessibility-widget svg,
body.hide-images #a11y-panel svg {
  visibility: visible !important;
}

/* Block text-align from affecting panel */
body.text-align-left #a11y-panel p,
body.text-align-center #a11y-panel p,
body.text-align-right #a11y-panel p,
body.text-align-left #a11y-panel li,
body.text-align-center #a11y-panel li,
body.text-align-right #a11y-panel li {
  text-align: left !important;
}

/* Block readable/dyslexia fonts */
body.readable-font #accessibility-widget,
body.readable-font #accessibility-widget *,
body.dyslexia-font #accessibility-widget,
body.dyslexia-font #accessibility-widget * {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
}