/* ============================================================
   ACCESSIBILITY WIDGET
   ============================================================
   Loaded after style.css so it can override.
   Five toggleable preferences, persisted via localStorage.
   ============================================================ */


/* ============================================================
   1. DARK MODE
   ============================================================ */
html.a11y-dark {
  --ink: #e8e8e3;
  --ink-soft: #c8c8c0;
  --ink-muted: #8a8a82;

  --paper: #16161a;
  --paper-warm: #232432;

  --indigo: #8b8fff;
  --indigo-deep: #6a6fd4;

  --rule: #2a2b35;
  --rule-soft: #1f2028;
}

/* Footer is already dark in default theme; in dark mode invert to lighter contrast */
/* Footer keeps its dark identity but pulls darker still in dark mode,
   and we set explicit colors instead of vars so it doesn't follow the flip */
html.a11y-dark .footer {
  background: #08080b;
  color: #e8e8e3;
}

html.a11y-dark .footer-brand,
html.a11y-dark .footer-col h4,
html.a11y-dark .footer-col p,
html.a11y-dark .footer-col a {
  color: #e8e8e3;
}

html.a11y-dark .footer-tagline {
  color: #b8b8b0;
  opacity: 1;
}

html.a11y-dark .footer-col h4 {
  color: #8a8a82;
  opacity: 1;
}

html.a11y-dark .footer-col p,
html.a11y-dark .footer-col a {
  opacity: 0.92;
}

html.a11y-dark .footer-bottom {
  border-top-color: rgba(232, 232, 227, 0.15);
  color: #8a8a82;
  opacity: 1;
}

html.a11y-dark .footer-credit a {
  color: #e8e8e3;
  border-bottom-color: rgba(232, 232, 227, 0.4);
}

html.a11y-dark .footer-credit a:hover {
  border-bottom-color: #e8e8e3;
}

html.a11y-dark .footer-bottom {
  border-top-color: rgba(232, 232, 227, 0.12);
}

html.a11y-dark .footer-credit a {
  border-bottom-color: rgba(232, 232, 227, 0.3);
}

/* Topbar transparency tweak for dark */
html.a11y-dark .topbar {
  background-color: rgba(22, 22, 26, 0.92);
}

/* Highlighter behind <strong> needs a darker warm tone in dark mode */
html.a11y-dark .intro-body strong,
html.a11y-dark .prose strong {
  background: linear-gradient(transparent 65%, rgba(139, 143, 255, 0.18) 65%);
}


/* ============================================================
   2. LARGE TEXT
   ============================================================
   122% bumps body 18px → ~22px proportionally. Because almost
   everything uses rem-equivalents (font-size in px scales via
   browser settings), we adjust the html font-size which cascades.
   ============================================================ */
html.a11y-large-text {
  font-size: 122%;
}

/* When combined with high-contrast, give a small extra bump */
html.a11y-large-text.a11y-contrast {
  font-size: 128%;
}


/* ============================================================
   3. HIGH CONTRAST
   ============================================================
   Hardens text/background contrast and removes subtle effects
   (highlighter gradients, opacity) that low-vision users miss.
   ============================================================ */
html.a11y-contrast {
  --ink: #000000;
  --ink-soft: #1a1a1a;
  --ink-muted: #2a2a2a;
  --paper: #ffffff;
  --indigo: #0000aa;
  --rule: #000000;
  --rule-soft: #555555;
}

html.a11y-contrast.a11y-dark {
  --ink: #ffffff;
  --ink-soft: #f0f0f0;
  --ink-muted: #d0d0d0;
  --paper: #000000;
  --paper-warm: #1a1a2a;
  --indigo: #ffd84d;
  --indigo-deep: #ffb800;
  --rule: #ffffff;
  --rule-soft: #888888;
}

/* Remove decorative highlighter — replace with bold underline */
html.a11y-contrast .intro-body strong,
html.a11y-contrast .prose strong {
  background: none;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

/* Remove animations and opacity in high-contrast */
html.a11y-contrast .footer-tagline,
html.a11y-contrast .footer-col h4,
html.a11y-contrast .footer-col p,
html.a11y-contrast .footer-col a,
html.a11y-contrast .footer-bottom {
  opacity: 1;
}

/* Strengthen all borders */
html.a11y-contrast .credential,
html.a11y-contrast .contact-card,
html.a11y-contrast .request-callout {
  border-width: 3px;
}

/* Stronger focus indicators */
html.a11y-contrast a:focus-visible,
html.a11y-contrast button:focus-visible {
  outline: 3px solid var(--indigo);
  outline-offset: 3px;
}


/* ============================================================
   4. REDUCED MOTION
   ============================================================
   Honors the toggle (independent of OS-level prefers-reduced-motion)
   ============================================================ */
html.a11y-no-motion *,
html.a11y-no-motion *::before,
html.a11y-no-motion *::after {
  animation-duration: 0.01ms !important;
  animation-delay: 0ms !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}


/* ============================================================
   5. UNDERLINE LINKS
   ============================================================
   Forces underlines on every meaningful link in body content,
   for users who can't perceive color contrast alone.
   ============================================================ */
html.a11y-underline a {
  text-decoration: underline !important;
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
}

/* But not the brand, hamburger, or skip-link */
html.a11y-underline .brand,
html.a11y-underline .hamburger,
html.a11y-underline .a11y-trigger,
html.a11y-underline .a11y-panel * {
  text-decoration: none !important;
}


/* ============================================================
   WIDGET — FLOATING TRIGGER BUTTON
   ============================================================ */
.a11y-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--indigo);
  color: var(--paper);
  border: 2px solid var(--paper);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18), 0 2px 4px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.15s ease;
  font-family: var(--sans);
}

.a11y-trigger:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22), 0 2px 6px rgba(0, 0, 0, 0.1);
}

.a11y-trigger:focus-visible {
  outline: 3px solid var(--indigo);
  outline-offset: 4px;
}

.a11y-trigger svg {
  width: 28px;
  height: 28px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Mobile: smaller, tucked into corner */
@media (max-width: 520px) {
  .a11y-trigger {
    width: 48px;
    height: 48px;
    bottom: 16px;
    right: 16px;
  }
  .a11y-trigger svg {
    width: 24px;
    height: 24px;
  }
}


/* ============================================================
   WIDGET — PANEL
   ============================================================ */
.a11y-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.08);
  padding: 20px;
  z-index: 1001;
  font-family: var(--sans);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

@media (max-width: 520px) {
  .a11y-panel {
    bottom: 76px;
    right: 16px;
    width: calc(100vw - 32px);
    padding: 18px;
  }
}

.a11y-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

.a11y-panel-title {
  font-family: var(--serif-display);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0;
  font-variation-settings: "opsz" 60, "SOFT" 30;
}

.a11y-panel-close {
  background: none;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.15s ease, background 0.15s ease;
}

.a11y-panel-close:hover {
  color: var(--ink);
  background: var(--rule-soft);
}

.a11y-panel-close:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

.a11y-panel-close svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
}


/* ============================================================
   WIDGET — TOGGLE ROWS
   ============================================================ */
.a11y-toggles {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.a11y-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px;
  border-bottom: 1px solid var(--rule-soft);
  cursor: pointer;
  user-select: none;
}

.a11y-toggle:last-of-type {
  border-bottom: none;
}

.a11y-toggle-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.a11y-toggle-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.005em;
}

.a11y-toggle-desc {
  font-size: 12px;
  color: var(--ink-muted);
  font-weight: 400;
}

/* Hidden checkbox — visually hidden but keyboard-accessible */
.a11y-toggle input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Custom toggle switch */
.a11y-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--rule);
  border-radius: 12px;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.a11y-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--paper);
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.a11y-toggle input:checked ~ .a11y-switch {
  background: var(--indigo);
}

.a11y-toggle input:checked ~ .a11y-switch::after {
  transform: translateX(20px);
}

.a11y-toggle input:focus-visible ~ .a11y-switch {
  outline: 2px solid var(--indigo);
  outline-offset: 3px;
}

.a11y-toggle:hover .a11y-switch {
  background: var(--ink-muted);
}

.a11y-toggle:hover input:checked ~ .a11y-switch {
  background: var(--indigo-deep);
}


/* ============================================================
   WIDGET — RESET BUTTON
   ============================================================ */
.a11y-reset {
  margin-top: 16px;
  padding: 10px 14px;
  background: none;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.a11y-reset:hover {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--rule-soft);
}

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


/* ============================================================
   WIDGET — DARK MODE OVERRIDES FOR THE WIDGET ITSELF
   ============================================================ */
html.a11y-dark .a11y-trigger {
  background: var(--indigo);
  color: var(--paper);
  border-color: var(--paper);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.2);
}

html.a11y-dark .a11y-panel {
  background: #1f2028;
  border-color: var(--rule);
}


/* ============================================================
   SKIP LINK (for keyboard users)
   ============================================================
   Hidden until focused, then jumps to the main content.
   ============================================================ */
.a11y-skip {
  position: absolute;
  top: -100px;
  left: 16px;
  background: var(--indigo);
  color: var(--paper);
  padding: 12px 20px;
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  z-index: 10000;
  transition: top 0.2s ease;
}

.a11y-skip:focus {
  top: 16px;
  color: var(--paper);
}
