/* Accessibility Features CSS */

/* ===========================
   DYSLEXIC FONT
   =========================== */

/* OpenDyslexic Font - Self-hosted or CDN */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/opendyslexic@3.0.0/fonts/OpenDyslexic-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/opendyslexic@3.0.0/fonts/OpenDyslexic-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

body.dyslexic-font,
body.dyslexic-font * {
  font-family: 'OpenDyslexic', -apple-system, BlinkMacSystemFont, sans-serif !important;
  letter-spacing: 0.05em;
  word-spacing: 0.1em;
  line-height: 1.8 !important;
}

/* ===========================
   REDUCE MOTION
   =========================== */

body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

body.reduce-motion .coin.flipping,
body.reduce-motion .spin-wheel.spinning,
body.reduce-motion .revealed-card {
  animation: none !important;
  transition: none !important;
}

/* Respect system preference for reduced motion */
@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;
  }
}

/* ===========================
   HIGH CONTRAST MODE
   =========================== */

body.high-contrast {
  --text-primary: #ffffff;
  --text-secondary: #e0e0e0;
  --bg-primary: #000000;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #2d2d2d;
  --bg-hover: #3d3d3d;
  --border: #ffffff;
  --accent: #00ff00;
  --success: #00ff00;
  --error: #ff0000;
  --warning: #ffff00;
  --info: #00ffff;
}

body.high-contrast * {
  border-color: currentColor !important;
  outline: 2px solid transparent;
  outline-offset: 2px;
}

body.high-contrast *:focus {
  outline: 3px solid #00ff00 !important;
  outline-offset: 2px;
}

body.high-contrast a,
body.high-contrast button {
  text-decoration: underline !important;
  font-weight: bold !important;
}

body.high-contrast img {
  filter: contrast(1.3) brightness(1.1);
}

/* ===========================
   INCREASED FONT SIZE
   =========================== */

body.large-text,
body.larger-text {
  font-size: 18px !important;
}

body.large-text .text-xs,
body.larger-text .text-xs { font-size: 14px !important; }
body.large-text .text-sm,
body.larger-text .text-sm { font-size: 16px !important; }
body.large-text .text-base,
body.larger-text .text-base { font-size: 18px !important; }
body.large-text .text-lg,
body.larger-text .text-lg { font-size: 22px !important; }
body.large-text .text-xl,
body.larger-text .text-xl { font-size: 26px !important; }
body.large-text .text-2xl,
body.larger-text .text-2xl { font-size: 30px !important; }
body.large-text .text-3xl,
body.larger-text .text-3xl { font-size: 36px !important; }
body.large-text .text-4xl,
body.larger-text .text-4xl { font-size: 42px !important; }

body.extra-large-text {
  font-size: 20px !important;
}

body.extra-large-text .text-xs { font-size: 16px !important; }
body.extra-large-text .text-sm { font-size: 18px !important; }
body.extra-large-text .text-base { font-size: 20px !important; }
body.extra-large-text .text-lg { font-size: 24px !important; }
body.extra-large-text .text-xl { font-size: 28px !important; }
body.extra-large-text .text-2xl { font-size: 34px !important; }
body.extra-large-text .text-3xl { font-size: 40px !important; }
body.extra-large-text .text-4xl { font-size: 48px !important; }

/* ===========================
   INCREASED SPACING
   =========================== */

body.increased-spacing {
  line-height: 1.8 !important;
}

body.increased-spacing p,
body.increased-spacing li {
  margin-bottom: 1.2em !important;
}

body.increased-spacing button,
body.increased-spacing input,
body.increased-spacing select,
body.increased-spacing textarea {
  padding: 1em 1.5em !important;
  min-height: 48px !important;
}

/* ===========================
   FOCUS INDICATORS
   =========================== */

body.enhanced-focus *:focus {
  outline: 4px solid var(--accent) !important;
  outline-offset: 3px !important;
  box-shadow: 0 0 0 6px rgba(139, 92, 246, 0.3) !important;
}

body.enhanced-focus button:focus,
body.enhanced-focus a:focus {
  background-color: var(--accent) !important;
  color: white !important;
}

/* ===========================
   KEYBOARD NAVIGATION
   =========================== */

body.keyboard-nav *:focus {
  outline: 3px solid #4f46e5 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.2) !important;
}

body.keyboard-nav button:focus,
body.keyboard-nav a:focus,
body.keyboard-nav input:focus,
body.keyboard-nav select:focus,
body.keyboard-nav textarea:focus {
  outline: 3px solid #4f46e5 !important;
  outline-offset: 2px !important;
}

body.keyboard-nav :focus-visible {
  outline: 3px solid #4f46e5 !important;
  outline-offset: 2px !important;
}

/* ===========================
   LINK HIGHLIGHTING
   =========================== */

body.underline-links a {
  text-decoration: underline !important;
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
}

body.underline-links a:hover {
  text-decoration-thickness: 3px !important;
}

/* ===========================
   GRAYSCALE MODE
   =========================== */

body.grayscale {
  filter: grayscale(100%);
}

body.grayscale * {
  filter: grayscale(100%);
}

/* ===========================
   COLOR BLIND MODES
   =========================== */

/* Protanopia (Red-Blind) */
body.protanopia {
  filter: url('#protanopia-filter');
}

/* Deuteranopia (Green-Blind) */
body.deuteranopia {
  filter: url('#deuteranopia-filter');
}

/* Tritanopia (Blue-Blind) */
body.tritanopia {
  filter: url('#tritanopia-filter');
}

/* Alternative: Use adjusted color schemes */
body.protanopia,
body.deuteranopia {
  --success: #0088ff;
  --error: #ffaa00;
  --warning: #ff00ff;
}

body.tritanopia {
  --success: #ff0066;
  --info: #ff6600;
}

/* ===========================
   READING MODE
   =========================== */

body.reading-mode {
  background: #f5f1e8 !important;
  color: #2b2b2b !important;
}

body.reading-mode * {
  background: transparent !important;
  color: inherit !important;
}

body.reading-mode main,
body.reading-mode article {
  max-width: 800px !important;
  margin: 0 auto !important;
  padding: 3em !important;
  font-size: 18px !important;
  line-height: 1.8 !important;
  font-family: Georgia, 'Times New Roman', serif !important;
}

/* ===========================
   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-width: 0;
}

.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ===========================
   SKIP TO CONTENT
   =========================== */

.skip-to-content {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  z-index: var(--z-tooltip);
  font-weight: bold;
}

.skip-to-content:focus {
  top: 0;
}

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

.a11y-widget {
  position: fixed;
  bottom: var(--space-4);
  left: var(--space-4);
  z-index: 9998;
}

.a11y-toggle-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: var(--transition-fast);
}

.a11y-toggle-btn:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-xl);
}

.a11y-toggle-btn:focus {
  outline: 3px solid white;
  outline-offset: 3px;
}

.a11y-panel {
  position: absolute;
  bottom: 70px;
  left: 0;
  width: 320px;
  max-height: 600px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--space-5);
  display: none;
  border: 2px solid var(--border);
}

.a11y-panel.active {
  display: block;
  animation: slideUp 0.3s ease;
}

.a11y-panel h3 {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  margin-bottom: var(--space-4);
  color: var(--text-primary);
}

.a11y-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  transition: var(--transition-fast);
}

.a11y-option:hover {
  background: var(--bg-hover);
}

.a11y-option label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
}

.a11y-option input[type="checkbox"],
.a11y-option input[type="radio"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.a11y-divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-4) 0;
}

.a11y-reset {
  width: 100%;
  padding: var(--space-3);
  background: var(--error);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-weight: var(--font-bold);
  cursor: pointer;
  margin-top: var(--space-4);
  transition: var(--transition-fast);
}

.a11y-reset:hover {
  background: var(--error-dark);
  transform: translateY(-2px);
}

@media (max-width: 768px) {
  .a11y-widget {
    bottom: var(--space-3);
    right: var(--space-3);
  }
  
  .a11y-toggle-btn {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
  
  .a11y-panel {
    width: calc(100vw - 32px);
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    bottom: 60px;
  }
}
