/* ══════════════════════════════════════════════════════════════
   Accessibility Widget — Universal Component
   Drop into any dark-themed site. Override CSS custom properties
   in your own stylesheet to match your design.
   ══════════════════════════════════════════════════════════════ */

/* ── Default palette (dark) ─────────────────────────────────── */
:root,
[data-a11y-theme="dark"] {
  --a11y-bg: #0a0e1a;
  --a11y-bg-card: rgba(15, 12, 30, 0.85);
  --a11y-text: #e2e8f0;
  --a11y-text-dim: rgba(226, 232, 240, 0.55);
  --a11y-accent: #7eb8ff;
  --a11y-border: rgba(126, 184, 255, 0.15);
  --a11y-link: #7eb8ff;
}

/* ── Light theme ────────────────────────────────────────────── */
[data-a11y-theme="light"] {
  --a11y-bg: #f5f3ee;
  --a11y-bg-card: rgba(255, 255, 255, 0.9);
  --a11y-text: #1a1a2e;
  --a11y-text-dim: rgba(26, 26, 46, 0.6);
  --a11y-accent: #2563eb;
  --a11y-border: rgba(37, 99, 235, 0.2);
  --a11y-link: #1d4ed8;
}

/* ── Apply theme to page ────────────────────────────────────── */
[data-a11y-theme="light"] body {
  background: var(--a11y-bg) !important;
  color: var(--a11y-text) !important;
}

[data-a11y-theme="light"] a {
  color: var(--a11y-link);
}

/* ── Override common dark-theme CSS variables ──────────────── */
[data-a11y-theme="light"] {
  --text: #1a1a2e !important;
  --text-dim: rgba(26, 26, 46, 0.7) !important;
  --text-muted: rgba(26, 26, 46, 0.5) !important;
  --bg-deep: #f5f3ee !important;
  --bg-card: rgba(255, 255, 255, 0.9) !important;
  --bg-card-hover: rgba(255, 255, 255, 0.95) !important;
  --border: rgba(0, 0, 0, 0.1) !important;
  --gold: #8B6914 !important;
  --gold-bright: #7a5c10 !important;
  --gold-dim: rgba(139, 105, 20, 0.15) !important;
  --astro-silver: #4a5568 !important;
  --numer-purple: #6b46c1 !important;
  --fire-red: #c53030 !important;
  --fire-orange: #c05621 !important;
  --celtic-green: #276749 !important;
  --hindu-saffron: #b7791f !important;
}

/* Override any hardcoded light-on-dark rgba text colors */
[data-a11y-theme="light"] [style*="rgba(240"],
[data-a11y-theme="light"] [style*="rgba(255"],
[data-a11y-theme="light"] [style*="rgba(226"] {
  color: rgba(26, 26, 46, 0.8) !important;
}

/* ── Font size: large (+25%) ────────────────────────────────── */
[data-a11y-font="large"] body {
  font-size: 125% !important;
}
[data-a11y-font="large"] p,
[data-a11y-font="large"] li,
[data-a11y-font="large"] td,
[data-a11y-font="large"] th,
[data-a11y-font="large"] span,
[data-a11y-font="large"] div,
[data-a11y-font="large"] label,
[data-a11y-font="large"] a {
  font-size: 125% !important;
}
[data-a11y-font="large"] h1 { font-size: 2.2rem !important; }
[data-a11y-font="large"] h2 { font-size: 1.8rem !important; }
[data-a11y-font="large"] h3 { font-size: 1.5rem !important; }
[data-a11y-font="large"] h4 { font-size: 1.25rem !important; }

/* ── Font size: extra large (+50%) ──────────────────────────── */
[data-a11y-font="xl"] body {
  font-size: 150% !important;
  line-height: 1.8 !important;
  letter-spacing: 0.01em !important;
}
[data-a11y-font="xl"] p,
[data-a11y-font="xl"] li,
[data-a11y-font="xl"] td,
[data-a11y-font="xl"] th,
[data-a11y-font="xl"] span,
[data-a11y-font="xl"] div,
[data-a11y-font="xl"] label,
[data-a11y-font="xl"] a {
  font-size: 150% !important;
  line-height: 1.8 !important;
}
[data-a11y-font="xl"] h1 { font-size: 2.8rem !important; }
[data-a11y-font="xl"] h2 { font-size: 2.2rem !important; }
[data-a11y-font="xl"] h3 { font-size: 1.8rem !important; }
[data-a11y-font="xl"] h4 { font-size: 1.5rem !important; }

/* XL hides decorative / non-essential elements */
[data-a11y-font="xl"] .starfield,
[data-a11y-font="xl"] .particles,
[data-a11y-font="xl"] .decorative,
[data-a11y-font="xl"] [data-decorative],
[data-a11y-font="xl"] canvas.bg-animation {
  display: none !important;
}

/* Reduce motion for XL as well */
[data-a11y-font="xl"] * {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

/* ── Prevent widget itself from being scaled ────────────────── */
[data-a11y-font="large"] .a11y-toggle,
[data-a11y-font="large"] .a11y-panel,
[data-a11y-font="large"] .a11y-panel *,
[data-a11y-font="xl"] .a11y-toggle,
[data-a11y-font="xl"] .a11y-panel,
[data-a11y-font="xl"] .a11y-panel * {
  font-size: revert !important;
  line-height: revert !important;
  letter-spacing: revert !important;
}

/* ── Widget toggle button ───────────────────────────────────── */
.a11y-toggle {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 99998;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(20, 18, 30, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: rgba(255, 255, 255, 0.45);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  padding: 0;
  opacity: 0.5;
}

.a11y-toggle:hover {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(20, 18, 30, 0.85);
  color: rgba(255, 255, 255, 0.9);
  transform: scale(1.08);
}

.a11y-toggle:focus-visible {
  outline: 2px solid var(--a11y-accent, #7eb8ff);
  outline-offset: 2px;
}

/* Light theme adjustments for the toggle */
[data-a11y-theme="light"] .a11y-toggle {
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(0, 0, 0, 0.1);
  color: rgba(0, 0, 0, 0.4);
}
[data-a11y-theme="light"] .a11y-toggle:hover {
  background: rgba(255, 255, 255, 0.95);
  color: rgba(0, 0, 0, 0.8);
  border-color: rgba(0, 0, 0, 0.2);
}

/* ── Widget panel ───────────────────────────────────────────── */
.a11y-panel {
  position: fixed;
  bottom: 60px;
  left: 16px;
  z-index: 99999;
  width: 232px;
  background: rgba(16, 14, 28, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  color: #e2e8f0;
  transform: translateY(8px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* Light theme panel */
[data-a11y-theme="light"] .a11y-panel {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.08);
  color: #1a1a2e;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* ── Panel header ───────────────────────────────────────────── */
.a11y-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

[data-a11y-theme="light"] .a11y-panel-header {
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

.a11y-panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.5);
}

[data-a11y-theme="light"] .a11y-panel-title {
  color: rgba(0, 0, 0, 0.4);
}

.a11y-panel-close {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.4);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
  line-height: 1;
}

.a11y-panel-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.8);
}

[data-a11y-theme="light"] .a11y-panel-close {
  background: rgba(0, 0, 0, 0.04);
  color: rgba(0, 0, 0, 0.3);
}
[data-a11y-theme="light"] .a11y-panel-close:hover {
  background: rgba(0, 0, 0, 0.08);
  color: rgba(0, 0, 0, 0.7);
}

/* ── Section label ──────────────────────────────────────────── */
.a11y-section-label {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.35);
  margin-bottom: 8px;
}

[data-a11y-theme="light"] .a11y-section-label {
  color: rgba(0, 0, 0, 0.35);
}

/* ── Pill group (shared for theme + font) ───────────────────── */
.a11y-pills {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 3px;
}

[data-a11y-theme="light"] .a11y-pills {
  background: rgba(0, 0, 0, 0.04);
}

.a11y-pill {
  flex: 1;
  padding: 6px 4px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  line-height: 1.2;
}

.a11y-pill:hover {
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.06);
}

.a11y-pill.active {
  background: rgba(126, 184, 255, 0.15);
  color: #7eb8ff;
  font-weight: 600;
}

/* Light theme pills */
[data-a11y-theme="light"] .a11y-pill {
  color: rgba(0, 0, 0, 0.4);
}
[data-a11y-theme="light"] .a11y-pill:hover {
  color: rgba(0, 0, 0, 0.7);
  background: rgba(0, 0, 0, 0.05);
}
[data-a11y-theme="light"] .a11y-pill.active {
  background: rgba(37, 99, 235, 0.12);
  color: #2563eb;
}

/* ── Font size pill icons ───────────────────────────────────── */
.a11y-pill-icon {
  display: block;
  font-size: 13px;
  margin-bottom: 1px;
}

.a11y-pill-icon.medium { font-size: 15px; }
.a11y-pill-icon.large  { font-size: 18px; }

/* ── Last section has no bottom margin ──────────────────────── */
.a11y-pills:last-child {
  margin-bottom: 0;
}

/* ── Focus styles for keyboard navigation ───────────────────── */
.a11y-pill:focus-visible,
.a11y-panel-close:focus-visible {
  outline: 2px solid var(--a11y-accent, #7eb8ff);
  outline-offset: 1px;
}
