/* SkyCastle Press — Accessibility Stylesheet
   WCAG 2.1 AA compliant styles
   Include in every page: <link rel="stylesheet" href="/accessibility.css">
   The .a11y-* classes are toggled via accessibility.js based on user preferences
   stored in localStorage under key "scp_a11y_prefs".
*/

/* ─── Screen-reader only utility ─────────────────────────────────────── */
.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;
}
.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ─── Skip Navigation Link ────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  z-index: 99999;
  padding: 0.75rem 1.5rem;
  background: #c9a84c;
  color: #0e0e14;
  font-weight: 700;
  font-size: 1rem;
  border-radius: 0 0 6px 6px;
  text-decoration: none;
  transition: top 0.1s ease;
}
.skip-link:focus {
  top: 0;
}

/* ─── Focus Indicators (universal) ───────────────────────────────────── */
/* High-visibility focus ring for ALL interactive elements */
:focus-visible {
  outline: 3px solid #c9a84c !important;
  outline-offset: 2px !important;
  border-radius: 3px;
}
/* Remove outline for mouse-only navigation */
:focus:not(:focus-visible) {
  outline: none !important;
}

/* ─── ARIA live region ────────────────────────────────────────────────── */
#a11y-live-region {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ─── Accessibility Toolbar ───────────────────────────────────────────── */
#a11y-toolbar {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}
#a11y-toggle-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #14141e;
  border: 2px solid #c9a84c;
  color: #c9a84c;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: background 0.15s, transform 0.15s;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}
#a11y-toggle-btn:hover,
#a11y-toggle-btn:focus-visible {
  background: #c9a84c;
  color: #0e0e14;
  transform: scale(1.05);
}
#a11y-panel {
  display: none;
  background: #14141e;
  border: 1px solid rgba(201,168,76,0.4);
  border-radius: 10px;
  padding: 1.25rem;
  width: 260px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#a11y-panel.open {
  display: block;
}
#a11y-panel h3 {
  margin: 0 0 1rem 0;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #c9a84c;
  font-family: 'DM Sans', sans-serif;
}
.a11y-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  color: #eae8e4;
  font-family: 'DM Sans', sans-serif;
}
.a11y-option label {
  cursor: pointer;
}
/* Toggle switch */
.a11y-switch {
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}
.a11y-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.a11y-switch-track {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.15);
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.2s;
}
.a11y-switch input:checked + .a11y-switch-track {
  background: #c9a84c;
}
.a11y-switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.a11y-switch input:checked + .a11y-switch-track::after {
  transform: translateX(16px);
}
.a11y-switch input:focus-visible + .a11y-switch-track {
  outline: 3px solid #c9a84c;
  outline-offset: 2px;
}
#a11y-panel-footer {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: rgba(234,232,228,0.4);
  text-align: center;
  font-family: 'DM Sans', sans-serif;
}

/* ─── 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;
  }
}
/* Manual override via user preference */
body.a11y-reduced-motion *,
body.a11y-reduced-motion *::before,
body.a11y-reduced-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

/* ─── Dyslexia-Friendly Mode ──────────────────────────────────────────── */
/* Uses OpenDyslexic font loaded via CDN in accessibility.js */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/open-dyslexic-regular.woff2') format('woff2'),
       url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/open-dyslexic-regular.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/open-dyslexic-bold.woff2') format('woff2'),
       url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/open-dyslexic-bold.woff') format('woff');
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

body.a11y-dyslexia {
  font-family: 'OpenDyslexic', sans-serif !important;
  background-color: #faf7f0 !important; /* cream background */
  color: #1a1a1a !important;
}
body.a11y-dyslexia * {
  font-family: 'OpenDyslexic', sans-serif !important;
  text-align: left !important;
  letter-spacing: 0.12em !important;
  word-spacing: 0.18em !important;
  line-height: 2.0 !important;
}
body.a11y-dyslexia p,
body.a11y-dyslexia .prose-editor,
body.a11y-dyslexia [contenteditable],
body.a11y-dyslexia .chapter-content {
  max-width: 70ch !important;
}
/* Preserve coloring for interactive elements */
body.a11y-dyslexia a { color: #7b4f00 !important; }
body.a11y-dyslexia button,
body.a11y-dyslexia .btn-primary { background: #7b4f00 !important; color: #faf7f0 !important; }

/* ─── Large Print Mode ────────────────────────────────────────────────── */
body.a11y-large-print {
  font-size: 20px !important;
}
body.a11y-large-print *:not(h1):not(h2):not(h3):not(.icon):not(svg) {
  font-size: 1em !important; /* relative to 20px base */
}
body.a11y-large-print h1 { font-size: 2em !important; }
body.a11y-large-print h2 { font-size: 1.6em !important; }
body.a11y-large-print h3 { font-size: 1.35em !important; }
body.a11y-large-print p,
body.a11y-large-print li,
body.a11y-large-print [contenteditable] {
  line-height: 1.9 !important;
}
/* Enlarge controls to remain usable */
body.a11y-large-print button,
body.a11y-large-print input,
body.a11y-large-print select {
  min-height: 44px !important;
  padding: 0.5em 1em !important;
}

/* ─── High Contrast Mode ──────────────────────────────────────────────── */
body.a11y-high-contrast {
  background: #000 !important;
  color: #fff !important;
}
body.a11y-high-contrast * {
  border-color: #fff !important;
}
body.a11y-high-contrast a { color: #ffff00 !important; }
body.a11y-high-contrast button { background: #000 !important; color: #fff !important; border: 2px solid #fff !important; }
body.a11y-high-contrast .btn-primary,
body.a11y-high-contrast [class*="btn-"] {
  background: #fff !important;
  color: #000 !important;
  border: 2px solid #fff !important;
}
body.a11y-high-contrast input,
body.a11y-high-contrast textarea,
body.a11y-high-contrast select {
  background: #000 !important;
  color: #fff !important;
  border: 2px solid #fff !important;
}

/* ─── Keyboard Navigation Helpers ────────────────────────────────────── */
/* Visible focus on sidebar items */
.keyboard-focus-visible {
  outline: 3px solid #c9a84c !important;
  outline-offset: 2px !important;
}

/* Ensure minimum touch/click target 44×44px for WCAG 2.5.5 */
button,
[role="button"],
a,
input[type="checkbox"],
input[type="radio"],
select {
  min-height: 24px;
  min-width: 24px;
}

/* ─── EPUB Accessibility Export Indicators ────────────────────────────── */
.a11y-export-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.5rem;
  background: rgba(74,222,128,0.15);
  border: 1px solid rgba(74,222,128,0.4);
  border-radius: 4px;
  font-size: 0.7rem;
  color: #4ade80;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  letter-spacing: 0.03em;
}

/* ─── Accessibility validation report ────────────────────────────────── */
.a11y-report-section {
  margin-bottom: 1.5rem;
}
.a11y-report-section h4 {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(234,232,228,0.5);
  margin: 0 0 0.75rem 0;
}
.a11y-check-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-family: 'DM Sans', sans-serif;
}
.a11y-check-item.pass { background: rgba(74,222,128,0.08); border: 1px solid rgba(74,222,128,0.2); }
.a11y-check-item.fail { background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.2); }
.a11y-check-item.warn { background: rgba(251,191,36,0.08); border: 1px solid rgba(251,191,36,0.25); }
.a11y-check-icon { font-size: 1rem; flex-shrink: 0; margin-top: 0.1rem; }
.a11y-check-text strong { display: block; color: #eae8e4; margin-bottom: 0.15rem; }
.a11y-check-text span { color: rgba(234,232,228,0.6); font-size: 0.8rem; }
.a11y-check-text .fix-suggestion {
  margin-top: 0.4rem;
  padding: 0.35rem 0.6rem;
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
  font-size: 0.78rem;
  color: #c9a84c;
}
