/* Accessibility Panel Styles */
.accessibility-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  right: -400px;
  width: 400px;
  max-width: 90vw;
  max-height: 100vh;
  background: white;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
  transition: 0.3s ease;
  overflow-y: auto;
  z-index: 10000;
  font-family:  sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', 'Liberation Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  /* Exclude from body filters */
  filter: none !important;
}

.accessibility-panel.open {
  right: 0;
}

.panel-header {
  background: var(--primary-color);
  color: white;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 1;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: var(--font-bold);
}

.close-button {
  background: none;
  border: none;
  color: white;
  font-size: 32px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: transform 0.2s ease;
}

.close-button:hover {
  transform: scale(1.1);
}

.panel-content {
  padding: 20px;
}


.control-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  gap: 15px;
}

.control-label {
  font-size: 1.2rem;
  color: var(--gray-dark);
  font-weight: var(--font-medium);
  flex: 1;
}

/* Toggle Switch */
.toggle-switch {
  width: 50px;
  height: 26px;
  background: var(--extra-light-gray);
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  transition: background 0.3s ease;
  flex-shrink: 0;
}

.toggle-switch.active {
  background: var(--primary-color);
}

.toggle-slider {
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  right: 2px;
  transition: transform 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch.active .toggle-slider {
  transform: translateX(-24px);
}

/* Button Group */
.button-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.control-button {
  padding: 8px 16px;
  border: 1px solid var(--extra-light-gray);
  background: white;
  color: var(--gray-dark);
  border-radius: var(--radius-2, 4px);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: var(--font-medium);
  transition: all 0.2s ease;
  font-family: inherit;
}

.control-button:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.control-button.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Select */
.a11y-select {
  padding: 8px 12px;
  border: 1px solid var(--extra-light-gray);
  border-radius: var(--radius-2, 4px);
  width: 100%;
  font-size: 0.9rem;
  font-family: inherit;
  background: white;
  color: var(--gray-dark);
  cursor: pointer;
}

.a11y-select:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Color Picker Group */
.color-picker-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.color-picker {
  width: 50px;
  height: 40px;
  border: 1px solid var(--extra-light-gray);
  border-radius: var(--radius-2, 4px);
  cursor: pointer;
  padding: 0;
}

.color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker::-webkit-color-swatch {
  border: none;
  border-radius: var(--radius-2, 4px);
}

/* Reset Button */
.reset-button {
  width: 100%;
  padding: 12px;
  background: var(--secondary-color);
  color: white;
  border: none;
  border-radius: var(--radius-2, 4px);
  font-size: 1rem;
  font-weight: var(--font-bold);
  cursor: pointer;
  transition: background 0.2s ease;
  margin-top: 20px;
  font-family: inherit;
}

.reset-button:hover {
  background: hsl(from var(--secondary-color) h s 50%);
}

/* Table of Contents Overlay */
.a11y-overlay-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10001;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  /* Exclude from body filters */
  filter: none !important;
}

.a11y-overlay-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.a11y-toc-overlay {
  position: fixed;
  top: 50%;
  right: 50%;
  transform: translate(50%, -50%);
  background: white;
  padding: 30px;
  border-radius: var(--radius-3, 8px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 10002;
  max-width: 500px;
  width: 90%;
  max-height: 70vh;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  /* Exclude from body filters - will be handled by specific rules */
}

.a11y-toc-overlay.show {
  opacity: 1;
  visibility: visible;
}

.a11y-toc-overlay h3 {
  margin: 0 0 20px 0;
  color: var(--primary-color);
  font-size: 1.3rem;
  font-weight: var(--font-bold);
}

.a11y-toc-overlay ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.a11y-toc-overlay ul li {
  margin-bottom: 10px;
}

.a11y-toc-overlay ul li a {
  color: var(--gray-dark);
  text-decoration: none;
  font-size: 1rem;
  display: block;
  padding: 8px;
  border-radius: var(--radius-2, 4px);
  transition: background 0.2s ease;
}

.a11y-toc-overlay ul li a:hover {
  background: var(--extra-light-gray);
  color: var(--primary-color);
}

/* Accessibility Feature Classes */
body.cognitive-mode {
  font-family: 'Arial', sans-serif;
}

body.screen-reader * {
  cursor: pointer;
}

body.highlight-links a {
  background: yellow;
  padding: 2px 4px;
}

body.large-text {
  /* Font size is handled by JavaScript, this class is just for toggle state */
}

body.word-spacing * {
  word-spacing: 0.2em;
}

body.no-animations *,
body.no-animations *::before,
body.no-animations *::after {
  animation-duration: 0s !important;
  animation-delay: 0s !important;
  transition-duration: 0s !important;
  transition-delay: 0s !important;
  animation-play-state: paused !important;
}

/* Keep panel transitions working even when animations are disabled */
body.no-animations .accessibility-panel {
  transition: right 0.3s ease, left 0.3s ease !important;
}

[dir="rtl"] body.no-animations .accessibility-panel {
  transition: right 0.3s ease, left 0.3s ease !important;
}

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

body.letter-spacing * {
  letter-spacing: 0.1em;
}

body.line-height * {
  line-height: 1.8;
}

body.hide-images img {
  display: none;
}

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

body.invert-colors {
  filter: invert(1);
}

/* Exclude panel and button from invert filter - apply reverse invert */
body.invert-colors .accessibility-panel,
body.invert-colors .a11y-toc-overlay,
body.invert-colors .a11y-action {
  filter: invert(1) !important;
}

body.dark-contrast {
  background: #000 !important;
  color: #fff !important;
}

body.dark-contrast a {
  color: #4fc3f7 !important;
}

body.dark-contrast .accessibility-panel {
  background: #1a1a1a !important;
  color: #fff !important;
}

body.dark-contrast .accessibility-panel .panel-header {
  background: var(--primary-color) !important;
}

body.dark-contrast .accessibility-panel .section-title {
  color: var(--primary-color) !important;
}

body.dark-contrast .accessibility-panel .control-label {
  color: #fff !important;
}

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

/* Exclude panel and button from monochrome filter - apply reverse grayscale */
body.monochrome .accessibility-panel,
body.monochrome .a11y-toc-overlay,
body.monochrome .a11y-action {
  filter: grayscale(0%) !important;
}

body.readable-font {
  font-family: 'Arial', 'Helvetica', sans-serif !important;
}

body.text-left {
  text-align: left;
  direction: ltr;
}

body.text-center {
  text-align: center;
}

body.text-right {
  text-align: right;
  direction: rtl;
}

/* Screen Reader Only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* RTL Support */
[dir="rtl"] .accessibility-panel {
  right: auto;
  left: -400px;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
}

[dir="rtl"] .accessibility-panel.open {
  left: 0;
  right: auto;
}

[dir="rtl"] .toggle-switch.active .toggle-slider {
  transform: translateX(24px);
}

[dir="rtl"] .toggle-slider {
  right: auto;
  left: 2px;
}

/* Responsive */
@media (max-width: 768px) {
  .accessibility-panel {
    width: 100%;
    max-width: 100%;
  }

  [dir="rtl"] .accessibility-panel {
    left: -100%;
  }

  .accessibility-panel.open {
    right: 0;
  }

  [dir="rtl"] .accessibility-panel.open {
    left: 0;
  }
}
