/* Accessibility Widget CSS */
:root {
  --a11y-primary: #2563eb;
  --a11y-bg: white;
  --a11y-text: black;
  --a11y-border: #e5e7eb;
  --a11y-shadow: rgba(0, 0, 0, 0.1);
  --a11y-success: #10b981;
  --a11y-radius: 8px;
  --a11y-transition: all 0.3s ease;
  --a11y-z-index: 9999;
  
  /* Viewport scaling variable */
  --a11y-vw-scale: 1;
  
  /* High contrast mode variables */
  --a11y-contrast-bg: var(--a11y-bg);
  --a11y-contrast-link: var(--a11y-primary);
}

@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/ttf/OpenDyslexic-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

/* Base Widget Styles */
.a11y-widget {
  pointer-events: auto !important;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: var(--a11y-z-index);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--a11y-text);
  --a11y-z-index: 9999;
}

.a11y-widget.open {
  --a11y-z-index: 999999999999;
}

/* FAB Button */
.a11y-fab {
  position: relative;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background-color: var(--a11y-text);
  color: var(--a11y-bg);
  border: 2px solid var(--a11y-text);
  cursor: pointer;
  box-shadow: 0 4px 8px var(--a11y-shadow);
  transition: var(--a11y-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: calc(var(--a11y-z-index) + 1);
}

.a11y-fab:focus {
  outline: 2px solid white;
  outline-offset: 2px;
}

.a11y-fab-icon,
.a11y-fab-close {
  position: absolute;
  transition: var(--a11y-transition);
}

.a11y-fab-close {
  opacity: 0;
  transform: scale(0.5);
}

.a11y-widget.open .a11y-fab-icon {
  opacity: 0;
  transform: scale(0.5);
}

.a11y-widget.open .a11y-fab-close {
  opacity: 1;
  transform: scale(1);
}

/* Tooltip */
.a11y-tooltip {
  position: absolute;
  top: 50%;
  right: calc(100% + 0.75rem);
  transform: translateY(-50%);
  background-color: #333;
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 1rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: var(--a11y-transition);
}


.a11y-fab:hover .a11y-tooltip {
  opacity: 1;
}

/* Panel */
.a11y-panel {
  position: absolute;
  bottom: calc(100% + 1rem);
  right: 0;
  width: 24rem;
  max-width: calc(100vw - 3rem);
  background-color: var(--a11y-bg);
  border-radius: var(--a11y-radius);
  box-shadow: 0 8px 16px var(--a11y-shadow);
  opacity: 0;
  transform: translateY(1rem);
  pointer-events: none;
  transition: var(--a11y-transition);
  overflow: hidden;
  max-height: calc(100vh - 6rem - 16px);
  overflow-y: auto;
  z-index: var(--a11y-z-index);
}

.a11y-panel[data-state="closed"] {
  display: none;
}

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

.a11y-widget.open .a11y-panel[data-state="closed"] {
  display: block;
}

/* Sections */
.a11y-section {
  padding: 2rem;
  border-bottom: 1px solid #eaeaea;
}

.a11y-section:last-child {
  border-bottom: none;
}

.a11y-section h2 {
  margin: 0 0 1rem;
  font-size: 1.2rem;
  font-weight: 600;
}

.a11y-section h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
}

/* Options */
.a11y-option {
  margin-bottom: 1rem;
}

.a11y-option:last-child {
  margin-bottom: 0;
}

.a11y-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.a11y-label-text {
  font-weight: 500;
}

.a11y-description {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: #666;
}

/* Switch */
.a11y-switch {
  position: relative;
  width: 2.5rem;
  height: 1.25rem;
  margin-left: 1rem;
}

.a11y-switch-input {
  opacity: 0;
  width: 0;
  height: 0;
}

.a11y-switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--a11y-bg);
  border: 1px solid var(--a11y-text);
  border-radius: 1.25rem;
  transition: var(--a11y-transition);
}

.a11y-switch-slider:before {
  position: absolute;
  content: "";
  height: 0.875rem;
  width: 0.875rem;
  left: 0.125rem;
  bottom: 0.125rem;
  background-color: var(--a11y-text);
  border: 1px solid var(--a11y-text);
  border-radius: 50%;
  transition: var(--a11y-transition);
}

.a11y-switch-input:checked + .a11y-switch-slider {
  background-color: var(--a11y-bg);
  border-color: var(--a11y-text);
}

.a11y-switch-input:checked + .a11y-switch-slider:before {
  transform: translateX(1.25rem);
  background-color: var(--a11y-text);
  border-color: var(--a11y-text);
}

.a11y-switch-input:focus + .a11y-switch-slider {
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

/* Range Control */
.a11y-range-control {
  display: flex;
  align-items: center;
  margin-left: 1rem;
}

.a11y-btn {
  height: 1.75rem;
  width: 1.75rem;
  padding: 0;
  border-radius: 4px;
  border: 1px solid var(--a11y-border);
  background-color: var(--a11y-bg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  transition: var(--a11y-transition);
}

.a11y-btn:hover {
  background-color: #f5f5f5;
}

.a11y-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

#text-size-reset {
  margin: 0 0.25rem;
  font-size: 0.75rem;
  width: auto;
  padding: 0 0.25rem;
}

/* Contrast Buttons */
.a11y-contrast-options {
  margin-top: 1rem;
}

.a11y-contrast-options.hidden {
  display: none;
}

.a11y-contrast-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.a11y-contrast-btn {
  aspect-ratio: 1/1;
  border-radius: 4px;
  border: 1px solid var(--a11y-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  transition: var(--a11y-transition);
}

.a11y-contrast-btn span {
  font-size: 1rem;
}

.a11y-contrast-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.a11y-contrast-btn[aria-pressed="true"] {
  transform: scale(1.1);
  box-shadow: 0 0 0 2px var(--a11y-primary);
}

/* Applied Classes */
body.a11y-readable-font,
body.a11y-readable-font * {
  letter-spacing: 0.05em !important;
  word-spacing: 0.1em !important;
  line-height: 1.8 !important;
}

body.a11y-dyslexic-font,
body.a11y-dyslexic-font * {
  font-family: 'OpenDyslexic', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
}

body.a11y-readable-font:not(.a11y-dyslexic-font),
body.a11y-readable-font:not(.a11y-dyslexic-font) * {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
}

body.a11y-underline-links a {
  text-decoration: underline !important;
}

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

body.a11y-reduce-animations video,
body.a11y-reduce-animations [autoplay] {
  display: none !important;
}

body.a11y-calm-mode > *:not(.a11y-widget) {
  filter: saturate(65%) !important;
}

/* High Contrast Mode */
body.a11y-high-contrast {
  --a11y-contrast-bg: var(--a11y-bg);
  --a11y-contrast-link: var(--a11y-primary);
}

body.a11y-high-contrast > *:not(.a11y-widget) {
  filter: contrast(120%) !important;
}

body.a11y-high-contrast *:not(.a11y-contrast-btn):not(.a11y-contrast-btn *):not(svg):not(img):not(.no-high-contrast):not(.no-high-contrast *) {
  background-color: var(--a11y-contrast-bg) !important;
  color: var(--a11y-text) !important;
}

/* Handle pseudo-elements in high contrast mode */
body.a11y-high-contrast *:not(.a11y-contrast-btn):not(.a11y-contrast-btn *):not(.no-high-contrast):not(.no-high-contrast *)::before,
body.a11y-high-contrast *:not(.a11y-contrast-btn):not(.a11y-contrast-btn *):not(.no-high-contrast):not(.no-high-contrast *)::after {
  color: var(--a11y-text) !important;
  background-color: var(--a11y-contrast-bg) !important;
}

/* SVG handling in high contrast mode */
body.a11y-high-contrast svg:not(.no-high-contrast):not(.a11y-widget svg) {
  fill: var(--a11y-text) !important;
  stroke: var(--a11y-text) !important;
}

body.a11y-high-contrast svg path:not(.no-high-contrast),
body.a11y-high-contrast svg rect:not(.no-high-contrast),
body.a11y-high-contrast svg circle:not(.no-high-contrast),
body.a11y-high-contrast svg line:not(.no-high-contrast),
body.a11y-high-contrast svg polygon:not(.no-high-contrast),
body.a11y-high-contrast svg polyline:not(.no-high-contrast) {
  fill: var(--a11y-text) !important;
  stroke: var(--a11y-text) !important;
}

body.a11y-high-contrast input:not(.no-high-contrast):not(.no-high-contrast *),
body.a11y-high-contrast a:not(.a11y-contrast-btn):not(.a11y-contrast-btn *):not(.no-high-contrast):not(.no-high-contrast *) {
  border: solid 2px var(--a11y-text) !important;
}

body.a11y-high-contrast ::placeholder {
  color: var(--a11y-text) !important;
}

body.a11y-high-contrast a:not(.a11y-contrast-btn):not(.a11y-contrast-btn *):not(.no-high-contrast):not(.no-high-contrast *) {
  color: var(--a11y-contrast-link) !important;
}

/* Contrast Button Styling via Data Attributes */
.a11y-contrast-btn[data-bg="#FCED1F"][data-text="#1500FF"] {
  background-color: #FCED1F;
  color: #1500FF;
}

.a11y-contrast-btn[data-bg="#FCED1F"][data-text="black"] {
  background-color: #FCED1F;
  color: black;
}

.a11y-contrast-btn[data-bg="black"][data-text="#FCED1F"] {
  background-color: black;
  color: #FCED1F;
}

.a11y-contrast-btn[data-bg="black"][data-text="white"] {
  background-color: black;
  color: white;
}

.a11y-contrast-btn[data-bg="#1500FF"][data-text="#FCED1F"] {
  background-color: #1500FF;
  color: #FCED1F;
}

.a11y-contrast-btn[data-bg="#1500FF"][data-text="white"] {
  background-color: #1500FF;
  color: white;
}

.a11y-contrast-btn[data-bg="white"][data-text="#1500FF"] {
  background-color: white;
  color: #1500FF;
}

.a11y-contrast-btn[data-bg="white"][data-text="black"] {
  background-color: white;
  color: black;
}

/* Contrast Theme Variables */
body.a11y-contrast-yellow-blue {
  --a11y-contrast-bg: #FCED1F;
  --a11y-text: #1500FF;
  --a11y-contrast-link: #1500FF;
}

body.a11y-contrast-yellow-black {
  --a11y-contrast-bg: #FCED1F;
  --a11y-text: black;
  --a11y-contrast-link: black;
}

body.a11y-contrast-black-yellow {
  --a11y-contrast-bg: black;
  --a11y-text: #FCED1F;
  --a11y-contrast-link: #FCED1F;
}

body.a11y-contrast-black-white {
  --a11y-contrast-bg: black;
  --a11y-text: white;
  --a11y-contrast-link: white;
}

body.a11y-contrast-blue-yellow {
  --a11y-contrast-bg: #1500FF;
  --a11y-text: #FCED1F;
  --a11y-contrast-link: #FCED1F;
}

body.a11y-contrast-blue-white {
  --a11y-contrast-bg: #1500FF;
  --a11y-text: white;
  --a11y-contrast-link: white;
}

body.a11y-contrast-white-blue {
  --a11y-contrast-bg: white;
  --a11y-text: #1500FF;
  --a11y-contrast-link: #1500FF;
}

body.a11y-contrast-white-black {
  --a11y-contrast-bg: white;
  --a11y-text: black;
  --a11y-contrast-link: black;
}

/* Viewport-based font size adjustments */
body.a11y-vw-scale * {
  font-size: calc(var(--a11y-vw-scale) * 1vw) !important;
}