/* ============================================================
   Accessibility Widget — styles
   ============================================================ */

:root {
  --a11y-primary: #1a56db;
  --a11y-primary-dark: #1442ab;
  --a11y-bg: #ffffff;
  --a11y-panel-bg: #f5f6f8;
  --a11y-text: #1f2430;
  --a11y-muted: #6b7280;
  --a11y-border: #e5e7eb;
  --a11y-radius: 12px;
  --a11y-shadow: 0 12px 32px rgba(20, 30, 60, 0.18);
  --a11y-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --a11y-z: 2147483000;
}

#a11y-widget,
#a11y-widget * {
  box-sizing: border-box;
  font-family: var(--a11y-font);
}

/* ---------- Toggle button ---------- */
#a11y-toggle {
  position: fixed;
  bottom: 24px;
  inset-inline-end: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--a11y-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--a11y-shadow);
  z-index: var(--a11y-z);
  transition: transform 0.15s ease, background 0.15s ease;
}
#a11y-toggle:hover { background: var(--a11y-primary-dark); }
#a11y-toggle:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
#a11y-toggle svg { width: 26px; height: 26px; }

/* ---------- Panel ---------- */
#a11y-panel {
  position: fixed;
  top: 0;
  inset-inline-end: 0;
  height: 100%;
  width: 340px;
  max-width: 92vw;
  background: var(--a11y-panel-bg);
  color: var(--a11y-text);
  box-shadow: var(--a11y-shadow);
  z-index: calc(var(--a11y-z) - 1);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
#a11y-panel[data-open="true"] { transform: translateX(0); }
#a11y-panel[hidden] { display: none; }

#a11y-header {
  background: var(--a11y-primary);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
}
#a11y-title { font-size: 15px; font-weight: 600; }
#a11y-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
#a11y-close:hover { background: rgba(255, 255, 255, 0.15); }
#a11y-close:focus-visible { outline: 2px solid #fff; }

.a11y-body {
  overflow-y: auto;
  padding: 14px 16px 6px;
  flex: 1 1 auto;
}
.a11y-section { margin-bottom: 16px; }
.a11y-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--a11y-muted);
  margin: 0 0 10px;
}

/* ---------- Profiles ---------- */
.a11y-profiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.a11y-profile-btn,
.a11y-tool-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--a11y-bg);
  border: 1px solid var(--a11y-border);
  border-radius: var(--a11y-radius);
  padding: 12px 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--a11y-text);
  cursor: pointer;
  text-align: start;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.a11y-profile-btn .a11y-icon,
.a11y-tool-btn .a11y-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  color: var(--a11y-primary);
}
.a11y-profile-btn:hover,
.a11y-tool-btn:hover { border-color: var(--a11y-primary); }
.a11y-profile-btn:focus-visible,
.a11y-tool-btn:focus-visible { outline: 2px solid var(--a11y-primary); outline-offset: 1px; }

.a11y-profile-btn[aria-pressed="true"] {
  background: var(--a11y-primary);
  border-color: var(--a11y-primary);
  color: #fff;
}
.a11y-profile-btn[aria-pressed="true"] .a11y-icon { color: #fff; }

.a11y-tool-btn { flex-direction: column; align-items: flex-start; gap: 8px; }
.a11y-tool-btn[aria-pressed="true"] {
  border-color: var(--a11y-primary);
  color: var(--a11y-primary);
  background: #eef4ff;
}

.a11y-tools-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

/* ---------- Oversized switch row ---------- */
.a11y-oversized-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--a11y-bg);
  border: 1px solid var(--a11y-border);
  border-radius: var(--a11y-radius);
  padding: 10px 14px;
}
.a11y-oversized-label { font-size: 13px; font-weight: 600; }

.a11y-switch { position: relative; width: 40px; height: 22px; display: inline-block; }
.a11y-switch input { opacity: 0; width: 0; height: 0; }
.a11y-switch-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.a11y-switch-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.a11y-switch input:checked + .a11y-switch-slider { background: var(--a11y-primary); }
.a11y-switch input:checked + .a11y-switch-slider::before { transform: translateX(18px); }
.a11y-switch input:focus-visible + .a11y-switch-slider { outline: 2px solid var(--a11y-primary); outline-offset: 2px; }

/* ---------- Footer ---------- */
#a11y-footer {
  flex: 0 0 auto;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--a11y-border);
}
#a11y-reset {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--a11y-border);
  background: var(--a11y-bg);
  color: var(--a11y-text);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
#a11y-reset:hover { border-color: var(--a11y-primary); color: var(--a11y-primary); }

#a11y-live-region {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ============================================================
   FEATURE EFFECTS
   Applied to <html> via classes toggled by accessibility-widget.js
   ============================================================ */

/* Bigger text (stepped) */
html.a11y-font-1 { font-size: 112% !important; }
html.a11y-font-2 { font-size: 125% !important; }
html.a11y-font-3 { font-size: 140% !important; }

/* Line height (stepped) */
html.a11y-lh-1 body, html.a11y-lh-1 body * { line-height: 1.6 !important; }
html.a11y-lh-2 body, html.a11y-lh-2 body * { line-height: 2 !important; }
html.a11y-lh-3 body, html.a11y-lh-3 body * { line-height: 2.4 !important; }

/* Text spacing (letter/word spacing, stepped) */
html.a11y-spacing-1 body, html.a11y-spacing-1 body * { letter-spacing: 0.5px !important; word-spacing: 2px !important; }
html.a11y-spacing-2 body, html.a11y-spacing-2 body * { letter-spacing: 1px !important; word-spacing: 4px !important; }
html.a11y-spacing-3 body, html.a11y-spacing-3 body * { letter-spacing: 1.5px !important; word-spacing: 6px !important; }

/* Text align (stepped: left / center / right cycle handled in JS) */
html.a11y-align-left body * { text-align: left !important; }
html.a11y-align-center body * { text-align: center !important; }
html.a11y-align-right body * { text-align: right !important; }

/* Dyslexia friendly font */
html.a11y-dyslexia-font body,
html.a11y-dyslexia-font body * {
  font-family: "OpenDyslexic", "Comic Sans MS", Verdana, sans-serif !important;
  letter-spacing: 0.5px !important;
}

/* Contrast modes */
html.a11y-contrast-dark body { background: #0b0e14 !important; color: #f5f5f5 !important; }
html.a11y-contrast-dark body * { background-color: transparent !important; border-color: #333 !important; }
html.a11y-contrast-dark img, html.a11y-contrast-dark video { filter: brightness(0.85); }

html.a11y-contrast-light body { background: #ffffff !important; color: #000000 !important; }
html.a11y-contrast-light body * { background-color: #ffffff !important; color: #000000 !important; }

html.a11y-contrast-high body { filter: contrast(1.5) !important; }

/* Saturation */
html.a11y-saturation-low body { filter: saturate(0.5); }
html.a11y-saturation-high body { filter: saturate(2); }
html.a11y-saturation-0 body { filter: grayscale(1); }

/* Highlight links */
html.a11y-highlight-links a {
  outline: 2px solid #ff9800 !important;
  background: #fff3cd !important;
  color: #7a4a00 !important;
  text-decoration: underline !important;
}

/* Hide images */
html.a11y-hide-images img,
html.a11y-hide-images svg:not(#a11y-widget svg),
html.a11y-hide-images picture,
html.a11y-hide-images video,
html.a11y-hide-images [style*="background-image"] {
  visibility: hidden !important;
}

/* Pause animations */
html.a11y-pause-anim *,
html.a11y-pause-anim *::before,
html.a11y-pause-anim *::after {
  animation-play-state: paused !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

/* Big cursor */
html.a11y-cursor-big,
html.a11y-cursor-big * {
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24"><path d="M5 3l14 8-6 1-2 6-6-15z" fill="black" stroke="white" stroke-width="1.5"/></svg>') 4 4, auto !important;
}

/* Reading guide / tooltips emphasis */
html.a11y-tooltips [title] {
  position: relative;
  border-bottom: 1px dotted var(--a11y-primary);
}

/* Page structure outline (helps see heading hierarchy) */
html.a11y-structure h1 { outline: 2px solid #dc2626 !important; }
html.a11y-structure h2 { outline: 2px solid #ea580c !important; }
html.a11y-structure h3 { outline: 2px solid #ca8a04 !important; }
html.a11y-structure h4,
html.a11y-structure h5,
html.a11y-structure h6 { outline: 2px solid #16a34a !important; }

/* ---------- Blind Accessibility Mode ----------
   Keyboard-navigation focused: strong, consistent focus rings so
   sighted-but-testing users (and low-vision keyboard users) can always
   see where focus is. Independent of the Screen Reader feature below —
   this class carries no speech behavior, only visual/focus behavior. */
html.a11y-blind-mode *:focus,
html.a11y-blind-mode *:focus-visible {
  outline: 3px solid #f59e0b !important;
  outline-offset: 3px !important;
  border-radius: 2px;
}
/* Make the current heading target (via Up/Down arrow nav) obvious too */
html.a11y-blind-mode h1:focus,
html.a11y-blind-mode h2:focus,
html.a11y-blind-mode h3:focus,
html.a11y-blind-mode h4:focus,
html.a11y-blind-mode h5:focus,
html.a11y-blind-mode h6:focus {
  background: #fff7e6 !important;
}

/* Reading focus for screen-reader "currently speaking" node */
.a11y-reading-active {
  outline: 3px solid #f59e0b !important;
  outline-offset: 2px;
  /* background: #fffbea !important; */
}

/* Screen reader control bar (play/pause/stop/speed) */
#a11y-reader-bar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: calc(var(--a11y-z) - 1);
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1f2430;
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: var(--a11y-shadow);
  font-family: var(--a11y-font);
}
#a11y-reader-bar button {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
}
#a11y-reader-bar button:hover { background: rgba(255, 255, 255, 0.15); }
#a11y-reader-bar button:focus-visible { outline: 2px solid #93c5fd; }
.a11y-reader-speed {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #cbd5e1;
}
.a11y-reader-speed select {
  background: #2d3342;
  color: #fff;
  border: 1px solid #444b5c;
  border-radius: 6px;
  padding: 2px 4px;
  font-size: 12px;
}
@media (max-width: 480px) {
  #a11y-reader-bar { left: 12px; right: 12px; transform: none; width: auto; justify-content: center; flex-wrap: wrap; }
}

/* Dictionary popup */
#a11y-dict-popup {
  position: fixed;
  z-index: calc(var(--a11y-z) + 1);
  max-width: 280px;
  background: #fff;
  color: #1f2430;
  border-radius: 10px;
  box-shadow: var(--a11y-shadow);
  padding: 12px 14px;
  font-size: 13px;
  font-family: var(--a11y-font);
  border: 1px solid var(--a11y-border);
}
#a11y-dict-popup h3 { margin: 0 0 4px; font-size: 14px; }
#a11y-dict-popup p { margin: 0 0 4px; }
#a11y-dict-popup button {
  margin-top: 6px;
  border: none;
  background: var(--a11y-primary);
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

/* Oversized widget mode */
html.a11y-oversized #a11y-panel { width: 420px; }
html.a11y-oversized .a11y-profile-btn,
html.a11y-oversized .a11y-tool-btn { font-size: 14.5px; padding: 16px 12px; }
html.a11y-oversized .a11y-icon { width: 26px; height: 26px; }
html.a11y-oversized #a11y-toggle { width: 68px; height: 68px; }
html.a11y-oversized #a11y-toggle svg { width: 32px; height: 32px; }

@media (max-width: 480px) {
  #a11y-panel { width: 100vw; }
}

@media (prefers-reduced-motion: reduce) {
  #a11y-toggle, #a11y-panel { transition: none; }
}