/* ==========================================================================
   Accessibility Widget - Main Stylesheet
   A floating accessibility menu widget with BEM naming, CSS custom properties,
   RTL support, responsive layout, and reduced-motion compliance.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS Custom Properties (Design Tokens)
   -------------------------------------------------------------------------- */

.a11y-widget {
  --a11y-primary: #1a73e8;
  --a11y-primary-hover: #1557b0;
  --a11y-bg: #ffffff;
  --a11y-bg-dark: #1e1e1e;
  --a11y-text: #333333;
  --a11y-text-dark: #f0f0f0;
  --a11y-border: #e0e0e0;
  --a11y-active-bg: #e8f0fe;
  --a11y-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  --a11y-radius: 12px;
  --a11y-toggle-size: 48px;
  --a11y-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    sans-serif;
}

/* --------------------------------------------------------------------------
   2. Root Container (.a11y-widget)
   -------------------------------------------------------------------------- */

.a11y-widget {
  position: fixed;
  right: calc(20px + env(safe-area-inset-right, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 999999;
  font-family: var(--a11y-font-family);
  font-size: 14px;
  line-height: 1.5;
  color: var(--a11y-text);
  direction: ltr;
  text-align: left;
  box-sizing: border-box;
}

.a11y-widget *,
.a11y-widget *::before,
.a11y-widget *::after {
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   3. Toggle Button (.a11y-widget__toggle)
   -------------------------------------------------------------------------- */

.a11y-widget__toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--a11y-toggle-size);
  height: var(--a11y-toggle-size);
  padding: 0;
  border: none;
  border-radius: 50%;
  background-color: #ffffff;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}

.a11y-widget__toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.28);
}

.a11y-widget__toggle:active {
  transform: scale(0.96);
}

.a11y-widget__toggle:focus-visible {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 2px;
}

.a11y-widget__toggle img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  border-radius: 50%;
}

/* --------------------------------------------------------------------------
   4. Panel (.a11y-widget__panel)
   -------------------------------------------------------------------------- */

.a11y-widget__panel {
  position: absolute;
  bottom: calc(var(--a11y-toggle-size) + 12px);
  right: 0;
  width: 320px;
  max-height: 86vh;
  background-color: var(--a11y-bg);
  border-radius: var(--a11y-radius);
  box-shadow: var(--a11y-shadow);
  border: 1px solid var(--a11y-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}

.a11y-widget--open .a11y-widget__panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* --------------------------------------------------------------------------
   5. Panel Header (.a11y-widget__header)
   -------------------------------------------------------------------------- */

.a11y-widget__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 14px;
  border-bottom: 1px solid var(--a11y-border);
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   6. Title (.a11y-widget__title)
   -------------------------------------------------------------------------- */

.a11y-widget__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--a11y-text);
  margin: 0;
  line-height: 1.3;
}

/* --------------------------------------------------------------------------
   7. Close Button (.a11y-widget__close)
   -------------------------------------------------------------------------- */

.a11y-widget__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--a11y-text);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.a11y-widget__close:hover {
  background-color: rgba(0, 0, 0, 0.06);
  color: #c62828;
}

.a11y-widget__close:focus-visible {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 2px;
}

.a11y-widget__close svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   8. Content Area (.a11y-widget__content)
   -------------------------------------------------------------------------- */

.a11y-widget__content {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 12px;
  overscroll-behavior: contain;
}

/* Custom scrollbar for the content area */
.a11y-widget__content::-webkit-scrollbar {
  width: 6px;
}

.a11y-widget__content::-webkit-scrollbar-track {
  background: transparent;
}

.a11y-widget__content::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.a11y-widget__content::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.25);
}

/* --------------------------------------------------------------------------
   9. Section (.a11y-widget__section)
   -------------------------------------------------------------------------- */

.a11y-widget__section {
  margin-bottom: 12px;
}

.a11y-widget__section:last-child {
  margin-bottom: 0;
}

/* --------------------------------------------------------------------------
   10. Section Title (.a11y-widget__section-title)
   -------------------------------------------------------------------------- */

.a11y-widget__section-title {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #777777;
  margin: 0 0 1px 0;
  padding: 0 10px;
}

/* --------------------------------------------------------------------------
   11. Language Select (.a11y-widget__lang-select)
   -------------------------------------------------------------------------- */

.a11y-widget__lang-select {
  width: 100%;
  padding: 3px 8px;
  font-size: 13px;
  font-family: var(--a11y-font-family);
  color: var(--a11y-text);
  background-color: var(--a11y-bg);
  border: 1px solid var(--a11y-border);
  border-radius: 5px;
  cursor: pointer;
  appearance: auto;
}

.a11y-widget__lang-select:focus {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 1px;
}

/* Language section: tighter title-to-select and section-to-section gaps */
.a11y-widget__section:has(.a11y-widget__lang-select) .a11y-widget__section-title {
  margin-bottom: 0px;
}

.a11y-widget__section:has(.a11y-widget__lang-select) {
  margin-bottom: 6px;
}

/* --------------------------------------------------------------------------
   12. Menu Item (.a11y-widget__item)
   -------------------------------------------------------------------------- */

.a11y-widget__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  border-radius: 8px;
  margin-bottom: 1px;
  cursor: pointer;
  border: 2px solid transparent;
  background: transparent;
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  color: var(--a11y-text);
  text-align: left;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.a11y-widget__item:last-child {
  margin-bottom: 0;
}

.a11y-widget__item:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

.a11y-widget__item:focus-visible {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   12. Active Item (.a11y-widget__item--active)
   -------------------------------------------------------------------------- */

.a11y-widget__item--active {
  background-color: var(--a11y-active-bg);
  border-left: 3px solid var(--a11y-primary);
}

.a11y-widget__item--active:hover {
  background-color: #dce8fd;
}

/* --------------------------------------------------------------------------
   13. Item Icon (.a11y-widget__item-icon)
   -------------------------------------------------------------------------- */

.a11y-widget__item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: var(--a11y-primary);
}

.a11y-widget__item-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* --------------------------------------------------------------------------
   14. Item Label (.a11y-widget__item-label)
   -------------------------------------------------------------------------- */

.a11y-widget__item-label {
  flex: 1 1 auto;
  font-size: 14px;
  line-height: 1.4;
  color: var(--a11y-text);
  user-select: none;
}

/* --------------------------------------------------------------------------
   15. Toggle Switch (.a11y-widget__item-toggle)
   -------------------------------------------------------------------------- */

.a11y-widget__item-toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
  border-radius: 10px;
  background-color: #cccccc;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: background-color 0.2s ease;
  appearance: none;
  -webkit-appearance: none;
}

.a11y-widget__item-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

/* Toggle ON state */
.a11y-widget__item--active .a11y-widget__item-toggle,
[aria-checked='true'] .a11y-widget__item-toggle {
  background-color: var(--a11y-primary);
}

.a11y-widget__item--active .a11y-widget__item-toggle::after,
[aria-checked='true'] .a11y-widget__item-toggle::after {
  transform: translateX(16px);
}

.a11y-widget__item-toggle:focus-visible {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 2px;
}

.a11y-widget__item-toggle:hover {
  opacity: 0.85;
}

/* --------------------------------------------------------------------------
   16. Font Size Controls (.a11y-widget__font-controls)
   -------------------------------------------------------------------------- */

.a11y-widget__font-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   17. Font Size Button (.a11y-widget__font-btn)
   -------------------------------------------------------------------------- */

.a11y-widget__font-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--a11y-border);
  border-radius: 50%;
  background-color: var(--a11y-bg);
  color: var(--a11y-text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    color 0.15s ease;
}

.a11y-widget__font-btn:hover {
  background-color: var(--a11y-primary);
  border-color: var(--a11y-primary);
  color: #ffffff;
}

.a11y-widget__font-btn:active {
  transform: scale(0.92);
}

.a11y-widget__font-btn:focus-visible {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 2px;
}

.a11y-widget__font-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.a11y-widget__font-btn:disabled:hover {
  background-color: var(--a11y-bg);
  border-color: var(--a11y-border);
  color: var(--a11y-text);
}

/* --------------------------------------------------------------------------
   18. Footer (.a11y-widget__footer)
   -------------------------------------------------------------------------- */

.a11y-widget__footer {
  padding: 2px 12px;
  border-top: 1px solid var(--a11y-border);
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   19. Disclaimer (.a11y-widget__disclaimer)
   -------------------------------------------------------------------------- */

.a11y-widget__disclaimer {
  font-size: 11px;
  line-height: 1.5;
  color: #888888;
  margin: 0 0 2px 0;
}

/* --------------------------------------------------------------------------
   20. Zoom Lock Warning (.a11y-widget__zoom-warn)
   -------------------------------------------------------------------------- */

.a11y-widget__zoom-warn {
  margin: 0 0 8px 0;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  color: #7a5200;
  background-color: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
}

/* --------------------------------------------------------------------------
   21. Reset Button (.a11y-widget__reset)
   -------------------------------------------------------------------------- */

.a11y-widget__reset {
  display: inline-block;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--a11y-primary);
  font-size: 13px;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  transition: color 0.15s ease;
}

.a11y-widget__reset:hover {
  color: var(--a11y-primary-hover);
}

.a11y-widget__reset:focus-visible {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   21. Accessibility Statement Link (.a11y-widget__statement-link)
   -------------------------------------------------------------------------- */

.a11y-widget__statement-link {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--a11y-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.a11y-widget__statement-link:hover {
  color: var(--a11y-primary-hover);
}

.a11y-widget__statement-link:focus-visible {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

body.a11y-dark-mode .a11y-widget__statement-link {
  color: #6db3f2;
}

/* --------------------------------------------------------------------------
   21b. Attribution Link (.a11y-widget__attribution)
   -------------------------------------------------------------------------- */

.a11y-widget__attribution {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: #aaaaaa;
  text-decoration: none;
  text-align: center;
  transition: color 0.15s ease;
}

.a11y-widget__attribution:hover {
  color: #777777;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.a11y-widget__attribution:focus-visible {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

body.a11y-dark-mode .a11y-widget__attribution {
  color: #666666;
}

body.a11y-dark-mode .a11y-widget__attribution:hover {
  color: #999999;
}

body.a11y-high-contrast .a11y-widget__attribution {
  color: #000000;
}

/* --------------------------------------------------------------------------
   22. Quick Start Presets (.a11y-widget__quick-start)
   -------------------------------------------------------------------------- */

.a11y-widget__quick-start {
  border-bottom: 1px solid var(--a11y-border);
  padding: 2px 12px 4px;
}

.a11y-widget__quick-start-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #666666;
  margin-bottom: 4px;
}

.a11y-widget__quick-start-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.a11y-widget__preset-btn {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 9px;
  border-radius: 13px;
  border: 1px solid var(--a11y-primary);
  background: transparent;
  color: var(--a11y-primary);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}

.a11y-widget__preset-btn:hover {
  background-color: var(--a11y-active-bg);
}

.a11y-widget__preset-btn:focus-visible {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 2px;
}

/* Dark mode overrides */
body.a11y-dark-mode .a11y-widget__quick-start {
  border-color: #444444;
}

body.a11y-dark-mode .a11y-widget__quick-start-title {
  color: #aaaaaa;
}

body.a11y-dark-mode .a11y-widget__preset-btn {
  border-color: var(--a11y-primary);
  color: var(--a11y-primary);
}

body.a11y-dark-mode .a11y-widget__preset-btn:hover {
  background-color: rgba(26, 115, 232, 0.2);
}

/* --------------------------------------------------------------------------
   23. Profiles / Presets Section (.a11y-widget__profiles)
   -------------------------------------------------------------------------- */

.a11y-widget__profiles {
  border-top: 1px solid var(--a11y-border);
  padding: 1px 0 1px;
}

.a11y-widget__profiles-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #666666;
  padding: 0px 12px 1px;
}

.a11y-widget__profiles-save {
  display: flex;
  gap: 6px;
  padding: 0 12px 1px;
}

.a11y-widget__profiles-input {
  flex: 1;
  min-width: 0;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--a11y-border);
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  color: var(--a11y-text);
  background-color: var(--a11y-bg);
  outline: none;
}

.a11y-widget__profiles-input:focus {
  border-color: var(--a11y-primary);
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.15);
}

.a11y-widget__profiles-save-btn {
  flex-shrink: 0;
  height: 26px;
  padding: 0 10px;
  background-color: var(--a11y-primary);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s;
}

.a11y-widget__profiles-save-btn:hover {
  background-color: var(--a11y-primary-hover);
}

.a11y-widget__profiles-save-btn:focus-visible {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 2px;
}

.a11y-widget__profiles-list {
  min-height: 0;
}

.a11y-widget__profiles-empty {
  font-size: 12px;
  color: #888888;
  padding: 0 12px 1px;
  margin: 0;
  font-style: italic;
}

.a11y-widget__profiles-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 12px;
}

.a11y-widget__profiles-item-name {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.a11y-widget__profiles-item-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.a11y-widget__profiles-load-btn,
.a11y-widget__profiles-delete-btn {
  height: 20px;
  padding: 0 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid;
  background-color: transparent;
  transition: background-color 0.1s;
}

.a11y-widget__profiles-load-btn {
  border-color: var(--a11y-primary);
  color: var(--a11y-primary);
}

.a11y-widget__profiles-load-btn:hover {
  background-color: var(--a11y-active-bg);
}

.a11y-widget__profiles-delete-btn {
  border-color: #d93025;
  color: #d93025;
}

.a11y-widget__profiles-delete-btn:hover {
  background-color: rgba(217, 48, 37, 0.08);
}

.a11y-widget__profiles-load-btn:focus-visible,
.a11y-widget__profiles-delete-btn:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* Dark mode overrides */
body.a11y-dark-mode .a11y-widget__profiles {
  border-color: #444444;
}

body.a11y-dark-mode .a11y-widget__profiles-title {
  color: #aaaaaa;
}

body.a11y-dark-mode .a11y-widget__profiles-input {
  background-color: #2a2a2a;
  border-color: #555555;
  color: var(--a11y-text-dark);
}

body.a11y-dark-mode .a11y-widget__profiles-empty {
  color: #666666;
}

/* --------------------------------------------------------------------------
   23. Position Switcher (.a11y-widget__position)
   -------------------------------------------------------------------------- */

.a11y-widget__position {
  border-top: 1px solid var(--a11y-border);
  padding: 1px 0 3px;
}

.a11y-widget__position-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: #666666;
  letter-spacing: 0.05em;
  padding: 2px 12px 4px;
}

.a11y-widget__position-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 0 12px;
}

.a11y-widget__position-btn {
  height: 24px;
  padding: 0 6px;
  border: 1px solid var(--a11y-border);
  border-radius: 4px;
  background: transparent;
  color: var(--a11y-text);
  font-size: 11px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.a11y-widget__position-btn:hover {
  background-color: var(--a11y-active-bg);
  border-color: var(--a11y-primary);
}

.a11y-widget__position-btn--active {
  background-color: var(--a11y-active-bg);
  border-color: var(--a11y-primary);
  color: var(--a11y-primary);
  font-weight: 600;
}

.a11y-widget__position-btn:focus-visible {
  outline: 2px solid var(--a11y-primary);
  outline-offset: 2px;
}

/* Dark mode overrides */
body.a11y-dark-mode .a11y-widget__position {
  border-color: #444444;
}

body.a11y-dark-mode .a11y-widget__position-title {
  color: #aaaaaa;
}

body.a11y-dark-mode .a11y-widget__position-btn {
  border-color: #555555;
  color: var(--a11y-text-dark);
}

body.a11y-dark-mode .a11y-widget__position-btn--active {
  background-color: rgba(26, 115, 232, 0.2);
  border-color: var(--a11y-primary);
  color: #7baaf7;
}

/* ==========================================================================
   MODIFIERS
   ========================================================================== */

/* --------------------------------------------------------------------------
   Position Modifiers ([data-position])
   Default position (bottom-right) is handled by the base .a11y-widget rule.
   -------------------------------------------------------------------------- */

.a11y-widget[data-position="bottom-left"] {
  right: auto;
  left: calc(20px + env(safe-area-inset-left, 0px));
}

.a11y-widget[data-position="bottom-left"] .a11y-widget__panel {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

.a11y-widget[data-position="top-right"] {
  bottom: auto;
  top: calc(20px + env(safe-area-inset-top, 0px));
}

.a11y-widget[data-position="top-right"] .a11y-widget__panel {
  bottom: auto;
  top: calc(var(--a11y-toggle-size) + 12px);
  transform-origin: top right;
  transform: translateY(-12px) scale(0.96);
}

.a11y-widget--open[data-position="top-right"] .a11y-widget__panel {
  transform: translateY(0) scale(1);
}

.a11y-widget[data-position="top-left"] {
  right: auto;
  left: calc(20px + env(safe-area-inset-left, 0px));
  bottom: auto;
  top: calc(20px + env(safe-area-inset-top, 0px));
}

.a11y-widget[data-position="top-left"] .a11y-widget__panel {
  right: auto;
  left: 0;
  bottom: auto;
  top: calc(var(--a11y-toggle-size) + 12px);
  transform-origin: top left;
  transform: translateY(-12px) scale(0.96);
}

.a11y-widget--open[data-position="top-left"] .a11y-widget__panel {
  transform: translateY(0) scale(1);
}

/* --------------------------------------------------------------------------
   RTL Modifier (.a11y-widget--rtl)
   -------------------------------------------------------------------------- */

.a11y-widget--rtl {
  right: auto;
  left: calc(20px + env(safe-area-inset-left, 0px));
  direction: rtl;
  text-align: right;
}

.a11y-widget--rtl .a11y-widget__panel {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

.a11y-widget--rtl .a11y-widget__item {
  text-align: right;
  flex-direction: row-reverse;
}

.a11y-widget--rtl .a11y-widget__item--active {
  border-left: 3px solid transparent;
  border-right: 3px solid var(--a11y-primary);
}

.a11y-widget--rtl .a11y-widget__header {
  flex-direction: row-reverse;
}

.a11y-widget--rtl .a11y-widget__font-controls {
  flex-direction: row-reverse;
}

/* The position grid must always render in LTR column order (left column = left
   side of the page, right column = right side) regardless of the widget language
   direction. Without this, direction:rtl inherited from the widget root would
   visually mirror the 2×2 grid so that right-column buttons move the widget to
   the LEFT of the page instead of the right. */
.a11y-widget--rtl .a11y-widget__position-grid {
  direction: ltr;
}

/* RTL + explicit right-side position choice
 *
 * The generic .a11y-widget--rtl rule ships the widget to the LEFT edge because
 * RTL scripts (Hebrew, Arabic, …) naturally begin from the right/end of a line,
 * so the default floating position mirrors to the left. But when the user
 * *explicitly* picks a right-side corner via the position switcher those choices
 * must take precedence: right means right, left means left, regardless of text
 * direction.
 *
 * Specificity: .a11y-widget--rtl[data-position] (0,2,0) beats
 *              .a11y-widget--rtl              (0,1,0)
 * so these rules safely override only the positional properties while all
 * other RTL layout rules (text direction, flex-direction, item borders, …)
 * remain in effect.
 */
.a11y-widget--rtl[data-position="bottom-right"],
.a11y-widget--rtl[data-position="top-right"] {
  right: calc(20px + env(safe-area-inset-right, 0px));
  left: auto;
}

.a11y-widget--rtl[data-position="bottom-right"] .a11y-widget__panel,
.a11y-widget--rtl[data-position="top-right"] .a11y-widget__panel {
  right: 0;
  left: auto;
}

.a11y-widget--rtl[data-position="bottom-right"] .a11y-widget__panel {
  transform-origin: bottom right;
}

.a11y-widget--rtl[data-position="top-right"] .a11y-widget__panel {
  transform-origin: top right;
}

/* ==========================================================================
   ACCESSIBILITY FEATURE CLASSES (applied to <body>)
   ========================================================================== */

/* --------------------------------------------------------------------------
   Sensory Friendly Mode
   Applies reduced brightness and saturation to calm visual intensity, and
   disables animations/transitions for users with sensory processing needs.
   Widget itself is excluded.
   -------------------------------------------------------------------------- */

body.a11y-sensory-friendly > *:not(.a11y-widget) {
  filter: brightness(0.85) saturate(0.7) !important;
}

body.a11y-sensory-friendly *:not(.a11y-widget):not(.a11y-widget *) {
  animation: none !important;
  animation-duration: 0.001ms !important;
  transition-duration: 0.001ms !important;
}

/* --------------------------------------------------------------------------
   Reduced Transparency
   Removes backdrop-filter/frosted-glass effects that can trigger
   vestibular disorders and impair readability for some users.
   -------------------------------------------------------------------------- */

body.a11y-reduced-transparency *:not(.a11y-widget):not(.a11y-widget *) {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* --------------------------------------------------------------------------
   Readable Font Mode
   Replaces brand/decorative fonts with a clean, generic sans-serif for
   improved legibility for users with cognitive or reading differences.
   Widget is excluded.
   -------------------------------------------------------------------------- */

body.a11y-readable-font *:not(.a11y-widget):not(.a11y-widget *) {
  font-family: Arial, Helvetica, sans-serif !important;
}

/* --------------------------------------------------------------------------
   Saturation Control
   Reduces colour saturation level by level; level 5 = full greyscale.
   Applied to direct children of body, excluding the widget.
   -------------------------------------------------------------------------- */

body.a11y-saturation-1 > *:not(.a11y-widget) { filter: saturate(80%) !important; }
body.a11y-saturation-2 > *:not(.a11y-widget) { filter: saturate(60%) !important; }
body.a11y-saturation-3 > *:not(.a11y-widget) { filter: saturate(40%) !important; }
body.a11y-saturation-4 > *:not(.a11y-widget) { filter: saturate(20%) !important; }
body.a11y-saturation-5 > *:not(.a11y-widget) { filter: saturate(0%) !important; }

/* --------------------------------------------------------------------------
   Brightness Control
   Reduces screen brightness level by level; helps with light sensitivity.
   Applied to direct children of body, excluding the widget.
   -------------------------------------------------------------------------- */

body.a11y-brightness-1 > *:not(.a11y-widget) { filter: brightness(90%) !important; }
body.a11y-brightness-2 > *:not(.a11y-widget) { filter: brightness(80%) !important; }
body.a11y-brightness-3 > *:not(.a11y-widget) { filter: brightness(70%) !important; }
body.a11y-brightness-4 > *:not(.a11y-widget) { filter: brightness(60%) !important; }
body.a11y-brightness-5 > *:not(.a11y-widget) { filter: brightness(50%) !important; }

/* --------------------------------------------------------------------------
   Suppress Notifications
   Hides common chat widgets, cookie banners, and toast notifications via
   CSS only — no DOM mutation, fully reversible on feature deactivation.
   -------------------------------------------------------------------------- */

body.a11y-suppress-notifications [id*="intercom"],
body.a11y-suppress-notifications [id*="drift"],
body.a11y-suppress-notifications [id*="crisp"],
body.a11y-suppress-notifications [id*="hubspot"],
body.a11y-suppress-notifications [id*="freshchat"],
body.a11y-suppress-notifications [id*="zendesk"],
body.a11y-suppress-notifications [class*="chat-widget"],
body.a11y-suppress-notifications [class*="chat-launcher"],
body.a11y-suppress-notifications [class*="cookie-banner"],
body.a11y-suppress-notifications [class*="cookie-notice"],
body.a11y-suppress-notifications [class*="cookie-consent"],
body.a11y-suppress-notifications [class*="toast-container"],
body.a11y-suppress-notifications [class*="notification-banner"],
body.a11y-suppress-notifications [class*="popup-banner"] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Highlight on Hover
   Highlights text elements on hover to help users track their reading
   position on the page. Pure CSS — no DOM mutations.
   -------------------------------------------------------------------------- */

body.a11y-highlight-hover p:hover,
body.a11y-highlight-hover li:hover,
body.a11y-highlight-hover h1:hover,
body.a11y-highlight-hover h2:hover,
body.a11y-highlight-hover h3:hover,
body.a11y-highlight-hover h4:hover,
body.a11y-highlight-hover h5:hover,
body.a11y-highlight-hover h6:hover,
body.a11y-highlight-hover blockquote:hover,
body.a11y-highlight-hover td:hover {
  background-color: rgba(255, 240, 100, 0.35) !important;
  outline: 2px solid rgba(220, 180, 0, 0.5) !important;
  border-radius: 2px;
}

/* F-210: click-to-pin highlight — persists until another element is clicked */
body.a11y-highlight-hover .a11y-highlight-pinned {
  background-color: rgba(255, 220, 50, 0.5) !important;
  outline: 2px solid rgba(180, 140, 0, 0.8) !important;
  border-radius: 2px;
}

/* --------------------------------------------------------------------------
   High Contrast Mode
   -------------------------------------------------------------------------- */

/*
 * Force white backgrounds and black text on every page element.
 * Targeting all elements (not just specific tag names) ensures that
 * coloured cards, section headers, and custom components are also
 * overridden — a previous approach only changed body and named tags,
 * leaving site-specific background-colors untouched.
 */
body.a11y-high-contrast *:not(.a11y-widget):not(.a11y-widget *) {
  background-color: #ffffff !important;
  color: #000000 !important;
  border-color: #000000 !important;
  box-shadow: none !important;
  text-shadow: none !important;
}

/* Images / video: keep natural rendering, add a clear border */
body.a11y-high-contrast img:not(.a11y-widget img),
body.a11y-high-contrast video:not(.a11y-widget video) {
  background-color: transparent !important;
  border: 2px solid #000000 !important;
}

/* Links clearly distinguishable */
body.a11y-high-contrast a:not(.a11y-widget a) {
  color: #0000ee !important;
  text-decoration: underline !important;
}

/* Buttons: inverted (black/white) for maximum affordance */
body.a11y-high-contrast button:not(.a11y-widget button) {
  background-color: #000000 !important;
  color: #ffffff !important;
  border: 2px solid #000000 !important;
}

/* Form controls */
body.a11y-high-contrast input:not(.a11y-widget input),
body.a11y-high-contrast select:not(.a11y-widget select),
body.a11y-high-contrast textarea:not(.a11y-widget textarea) {
  background-color: #ffffff !important;
  color: #000000 !important;
  border: 2px solid #000000 !important;
}

/* --------------------------------------------------------------------------
   Dark Mode
   -------------------------------------------------------------------------- */

body.a11y-dark-mode {
  background-color: #1e1e1e !important;
  color: #f0f0f0 !important;
}

/*
 * Force dark background and light text on every page element.
 * The previous approach only changed named elements' color but never
 * overrode background-color on cards/sections/containers — those stayed
 * white, making dark-mode text invisible against a white background.
 */
body.a11y-dark-mode *:not(.a11y-widget):not(.a11y-widget *) {
  background-color: #1e1e1e !important;
  color: #f0f0f0 !important;
  border-color: #444444 !important;
}

/* Links remain distinguishable */
body.a11y-dark-mode a:not(.a11y-widget a) {
  color: #6db3f2 !important;
}

/* Media: keep natural rendering, just dim slightly */
body.a11y-dark-mode img:not(.a11y-widget img),
body.a11y-dark-mode video:not(.a11y-widget video) {
  background-color: transparent !important;
  opacity: 0.85;
}

/* Dark mode styling for the widget panel itself */
body.a11y-dark-mode .a11y-widget__panel {
  background-color: var(--a11y-bg-dark);
  border-color: #444444;
}

body.a11y-dark-mode .a11y-widget__title,
body.a11y-dark-mode .a11y-widget__item-label,
body.a11y-dark-mode .a11y-widget__close {
  color: var(--a11y-text-dark);
}

body.a11y-dark-mode .a11y-widget__header,
body.a11y-dark-mode .a11y-widget__footer {
  border-color: #444444;
}

body.a11y-dark-mode .a11y-widget__item:hover {
  background-color: rgba(255, 255, 255, 0.06);
}

body.a11y-dark-mode .a11y-widget__item--active {
  background-color: rgba(26, 115, 232, 0.15);
}

body.a11y-dark-mode .a11y-widget__item--active:hover {
  background-color: rgba(26, 115, 232, 0.22);
}

body.a11y-dark-mode .a11y-widget__section-title {
  color: #aaaaaa;
}

body.a11y-dark-mode .a11y-widget__disclaimer {
  color: #999999;
}

body.a11y-dark-mode .a11y-widget__font-btn {
  background-color: #2a2a2a;
  border-color: #555555;
  color: var(--a11y-text-dark);
}

body.a11y-dark-mode .a11y-widget__font-btn:hover {
  background-color: var(--a11y-primary);
  border-color: var(--a11y-primary);
  color: #ffffff;
}

body.a11y-dark-mode .a11y-widget__content::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.2);
}

body.a11y-dark-mode .a11y-widget__close:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

/* --------------------------------------------------------------------------
   Dyslexia-Friendly Font
   -------------------------------------------------------------------------- */

body.a11y-dyslexia-font,
body.a11y-dyslexia-font *:not(.a11y-widget):not(.a11y-widget *) {
  font-family: 'OpenDyslexic', 'Comic Sans MS', 'Comic Sans', cursive !important;
}

/* --------------------------------------------------------------------------
   Underline Links
   -------------------------------------------------------------------------- */

body.a11y-underline-links a:not(.a11y-widget a) {
  text-decoration: underline !important;
  text-underline-offset: 3px !important;
  text-decoration-thickness: 2px !important;
}

body.a11y-underline-links a:not(.a11y-widget a):not([class]) {
  color: #1a0dab !important;
}

body.a11y-underline-links.a11y-dark-mode a:not(.a11y-widget a):not([class]) {
  color: #8ab4f8 !important;
}

/* --------------------------------------------------------------------------
   Focus Outline
   -------------------------------------------------------------------------- */

body.a11y-focus-outline a:focus,
body.a11y-focus-outline button:focus,
body.a11y-focus-outline input:focus,
body.a11y-focus-outline select:focus,
body.a11y-focus-outline textarea:focus,
body.a11y-focus-outline [tabindex]:focus,
body.a11y-focus-outline [role='button']:focus,
body.a11y-focus-outline [role='link']:focus,
body.a11y-focus-outline [role='menuitem']:focus,
body.a11y-focus-outline [role='menuitemcheckbox']:focus,
body.a11y-focus-outline summary:focus {
  outline: 3px solid #ff6600 !important;
  outline-offset: 2px !important;
}

/* --------------------------------------------------------------------------
   Hide Images
   -------------------------------------------------------------------------- */

body.a11y-hide-images img:not(.a11y-widget img):not(.a11y-widget__item-icon img),
body.a11y-hide-images svg:not(.a11y-widget svg):not(.a11y-widget__item-icon svg),
body.a11y-hide-images picture:not(.a11y-widget picture),
body.a11y-hide-images video:not(.a11y-widget video) {
  display: none !important;
}

body.a11y-hide-images [style*='background-image']:not(.a11y-widget [style*='background-image']) {
  background-image: none !important;
}

/* --------------------------------------------------------------------------
   Text Spacing
   -------------------------------------------------------------------------- */

body.a11y-text-spacing *:not(.a11y-widget):not(.a11y-widget *) {
  line-height: 1.8 !important;
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
}

body.a11y-text-spacing p:not(.a11y-widget p),
body.a11y-text-spacing li:not(.a11y-widget li),
body.a11y-text-spacing dd:not(.a11y-widget dd) {
  margin-bottom: 1.2em !important;
}

/* --------------------------------------------------------------------------
   Pause Animations
   -------------------------------------------------------------------------- */

body.a11y-pause-animations *:not(.a11y-widget):not(.a11y-widget *) {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

body.a11y-pause-animations *:not(.a11y-widget):not(.a11y-widget *)::before,
body.a11y-pause-animations *:not(.a11y-widget):not(.a11y-widget *)::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}

/* --------------------------------------------------------------------------
   Large Cursor
   -------------------------------------------------------------------------- */

body.a11y-large-cursor,
body.a11y-large-cursor *:not(.a11y-widget):not(.a11y-widget *) {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M4 4l7 24 3.5-10L25 15z' fill='black' stroke='white' stroke-width='1.5'/%3E%3C/svg%3E") 4 4, auto !important;
}

body.a11y-large-cursor a:not(.a11y-widget a),
body.a11y-large-cursor button:not(.a11y-widget button),
body.a11y-large-cursor [role="button"]:not(.a11y-widget [role="button"]),
body.a11y-large-cursor input:not(.a11y-widget input),
body.a11y-large-cursor select:not(.a11y-widget select),
body.a11y-large-cursor textarea:not(.a11y-widget textarea),
body.a11y-large-cursor label:not(.a11y-widget label),
body.a11y-large-cursor summary:not(.a11y-widget summary) {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M10 2C10 2 10 22 10 22L14 18L18 26L22 24L18 16L24 16Z' fill='black' stroke='white' stroke-width='1.5'/%3E%3C/svg%3E") 10 2, pointer !important;
}

/* --------------------------------------------------------------------------
   Highlight Headings
   -------------------------------------------------------------------------- */

body.a11y-highlight-headings h1:not(.a11y-widget h1),
body.a11y-highlight-headings h2:not(.a11y-widget h2),
body.a11y-highlight-headings h3:not(.a11y-widget h3),
body.a11y-highlight-headings h4:not(.a11y-widget h4),
body.a11y-highlight-headings h5:not(.a11y-widget h5),
body.a11y-highlight-headings h6:not(.a11y-widget h6) {
  outline: 2px solid #1a73e8 !important;
  outline-offset: 4px !important;
  padding: 4px 8px !important;
  background-color: rgba(26, 115, 232, 0.08) !important;
  border-radius: 3px !important;
}

/* --------------------------------------------------------------------------
   Invert Colors
   -------------------------------------------------------------------------- */

/*
 * Apply the invert filter to every direct child of body EXCEPT the widget
 * and the reading-guide bar (both use position:fixed).
 *
 * Why not filter body itself?  Applying `filter` to an element creates a new
 * CSS stacking context, which traps all descendant `position:fixed` elements
 * inside it.  The widget (and reading guide bar) then scroll with the page
 * instead of staying fixed, and can disappear off-screen.
 *
 * By targeting only `body > *:not(.a11y-widget):not(.a11y-reading-guide-bar)`
 * we invert the page content while keeping the widget completely outside the
 * filtered stacking context so `position:fixed` continues to work correctly.
 */
body.a11y-invert-colors {
  background-color: #000000 !important;
}

body.a11y-invert-colors > *:not(.a11y-widget):not(.a11y-reading-guide-bar) {
  filter: invert(1) hue-rotate(180deg) !important;
}

/* Re-invert images/media so they keep their natural appearance */
body.a11y-invert-colors > *:not(.a11y-widget):not(.a11y-reading-guide-bar) img,
body.a11y-invert-colors > *:not(.a11y-widget):not(.a11y-reading-guide-bar) video,
body.a11y-invert-colors > *:not(.a11y-widget):not(.a11y-reading-guide-bar) picture,
body.a11y-invert-colors > *:not(.a11y-widget):not(.a11y-reading-guide-bar) canvas {
  filter: invert(1) hue-rotate(180deg) !important;
}

/* --------------------------------------------------------------------------
   Reading Guide
   -------------------------------------------------------------------------- */

.a11y-reading-guide-bar {
  position: fixed;
  left: 0;
  right: 0;
  height: 12px;
  background-color: rgba(26, 115, 232, 0.3);
  border-top: 2px solid rgba(26, 115, 232, 0.6);
  border-bottom: 2px solid rgba(26, 115, 232, 0.6);
  pointer-events: none;
  z-index: 999998;
  transition: top 0.05s linear;
}

/* --------------------------------------------------------------------------
   Text-to-Speech active highlight
   -------------------------------------------------------------------------- */

.a11y-tts-speaking {
  outline: 2px solid #1a73e8 !important;
  outline-offset: 2px !important;
  background-color: rgba(26, 115, 232, 0.08) !important;
}

/* Word-level highlight spans injected during TTS playback (F-204) */
.a11y-tts-word {
  display: inline;
}
.a11y-tts-word-active {
  background-color: rgba(26, 115, 232, 0.35) !important;
  border-radius: 2px;
}

/* --------------------------------------------------------------------------
   Font Size Scaling (body.a11y-font-1 through body.a11y-font-5)
   -------------------------------------------------------------------------- */

html.a11y-font-1 { font-size: 112.5% !important; }
html.a11y-font-2 { font-size: 125%   !important; }
html.a11y-font-3 { font-size: 137.5% !important; }
html.a11y-font-4 { font-size: 150%   !important; }
html.a11y-font-5 { font-size: 175%   !important; }

/*
 * Re-anchor body to the scaled html font-size (1em = html's new size).
 * This ensures content using em/% units also scales, even on sites that
 * hard-code body { font-size: Npx }.
 */
html.a11y-font-1 body,
html.a11y-font-2 body,
html.a11y-font-3 body,
html.a11y-font-4 body,
html.a11y-font-5 body {
  font-size: 1em !important;
}

/* ==========================================================================
   GRANULAR TYPOGRAPHY CONTROLS
   Line Height, Letter Spacing, Word Spacing (levels 1–5)
   Applied to <body> and scoped away from the widget itself.
   ========================================================================== */

/* Line Height */
body.a11y-line-height-1 *:not(.a11y-widget):not(.a11y-widget *) { line-height: 1.4 !important; }
body.a11y-line-height-2 *:not(.a11y-widget):not(.a11y-widget *) { line-height: 1.6 !important; }
body.a11y-line-height-3 *:not(.a11y-widget):not(.a11y-widget *) { line-height: 1.8 !important; }
body.a11y-line-height-4 *:not(.a11y-widget):not(.a11y-widget *) { line-height: 2.0 !important; }
body.a11y-line-height-5 *:not(.a11y-widget):not(.a11y-widget *) { line-height: 2.4 !important; }

/* Letter Spacing */
body.a11y-letter-spacing-1 *:not(.a11y-widget):not(.a11y-widget *) { letter-spacing: 0.05em !important; }
body.a11y-letter-spacing-2 *:not(.a11y-widget):not(.a11y-widget *) { letter-spacing: 0.10em !important; }
body.a11y-letter-spacing-3 *:not(.a11y-widget):not(.a11y-widget *) { letter-spacing: 0.15em !important; }
body.a11y-letter-spacing-4 *:not(.a11y-widget):not(.a11y-widget *) { letter-spacing: 0.20em !important; }
body.a11y-letter-spacing-5 *:not(.a11y-widget):not(.a11y-widget *) { letter-spacing: 0.25em !important; }

/* Word Spacing */
body.a11y-word-spacing-1 *:not(.a11y-widget):not(.a11y-widget *) { word-spacing: 0.10em !important; }
body.a11y-word-spacing-2 *:not(.a11y-widget):not(.a11y-widget *) { word-spacing: 0.20em !important; }
body.a11y-word-spacing-3 *:not(.a11y-widget):not(.a11y-widget *) { word-spacing: 0.30em !important; }
body.a11y-word-spacing-4 *:not(.a11y-widget):not(.a11y-widget *) { word-spacing: 0.40em !important; }
body.a11y-word-spacing-5 *:not(.a11y-widget):not(.a11y-widget *) { word-spacing: 0.50em !important; }

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

@media (max-width: 480px) {
  .a11y-widget__panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 70vh;
    border-radius: var(--a11y-radius) var(--a11y-radius) 0 0;
    transform: translateY(100%);
    transform-origin: bottom center;
  }

  .a11y-widget--open .a11y-widget__panel {
    transform: translateY(0);
  }

  /* RTL on mobile: panel positioning is the same (full-width) */
  .a11y-widget--rtl .a11y-widget__panel {
    left: 0;
    right: 0;
  }
}

/* ==========================================================================
   REDUCED MOTION
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .a11y-widget__toggle,
  .a11y-widget__panel,
  .a11y-widget__item,
  .a11y-widget__item-toggle,
  .a11y-widget__item-toggle::after,
  .a11y-widget__close,
  .a11y-widget__font-btn,
  .a11y-widget__reset {
    transition: none !important;
    animation: none !important;
  }

  .a11y-widget__toggle:hover {
    transform: none;
  }

  .a11y-widget__toggle:active {
    transform: none;
  }

  .a11y-widget__font-btn:active {
    transform: none;
  }
}

/* ==========================================================================
   HIGH-CONTRAST MODE - WIDGET PANEL ADAPTATION
   When high contrast is on, ensure the widget panel remains legible.
   ========================================================================== */

body.a11y-high-contrast .a11y-widget__panel {
  border: 2px solid #000000;
}

body.a11y-high-contrast .a11y-widget__header {
  border-bottom: 2px solid #000000;
}

body.a11y-high-contrast .a11y-widget__footer {
  border-top: 2px solid #000000;
}

body.a11y-high-contrast .a11y-widget__item {
  border: 1px solid #000000;
}

body.a11y-high-contrast .a11y-widget__item--active {
  border-left: 3px solid var(--a11y-primary);
}

/* ==========================================================================
   PRINT STYLES
   Hide the widget entirely when printing.
   ========================================================================== */

@media print {
  .a11y-widget {
    display: none !important;
  }
}

/* ==========================================================================
   COLOR BLINDNESS SIMULATION FILTERS
   Each class applies the matching SVG feColorMatrix filter to the host
   page content, excluding the widget itself.
   ========================================================================== */

body.a11y-deuteranopia > *:not(.a11y-widget):not(.a11y-reading-guide-bar) {
  filter: url(#a11y-filter-deuteranopia) !important;
}

body.a11y-protanopia > *:not(.a11y-widget):not(.a11y-reading-guide-bar) {
  filter: url(#a11y-filter-protanopia) !important;
}

body.a11y-tritanopia > *:not(.a11y-widget):not(.a11y-reading-guide-bar) {
  filter: url(#a11y-filter-tritanopia) !important;
}

/* ==========================================================================
   FOCUS MODE
   Dims sidebar / auxiliary content so the main text area stands out.
   Targets common landmark and layout elements outside the widget itself.
   ========================================================================== */

body.a11y-focus-mode aside:not(.a11y-widget):not(.a11y-widget *),
body.a11y-focus-mode header:not(.a11y-widget):not(.a11y-widget *),
body.a11y-focus-mode footer:not(.a11y-widget):not(.a11y-widget *),
body.a11y-focus-mode nav:not(.a11y-widget):not(.a11y-widget *),
body.a11y-focus-mode [role="complementary"]:not(.a11y-widget):not(.a11y-widget *),
body.a11y-focus-mode [role="banner"]:not(.a11y-widget):not(.a11y-widget *),
body.a11y-focus-mode [role="contentinfo"]:not(.a11y-widget):not(.a11y-widget *),
body.a11y-focus-mode [role="navigation"]:not(.a11y-widget):not(.a11y-widget *) {
  opacity: 0.08;
  transition: opacity 0.2s ease;
}

body.a11y-focus-mode aside:not(.a11y-widget):not(.a11y-widget *):hover,
body.a11y-focus-mode header:not(.a11y-widget):not(.a11y-widget *):hover,
body.a11y-focus-mode footer:not(.a11y-widget):not(.a11y-widget *):hover,
body.a11y-focus-mode nav:not(.a11y-widget):not(.a11y-widget *):hover,
body.a11y-focus-mode [role="complementary"]:not(.a11y-widget):not(.a11y-widget *):hover,
body.a11y-focus-mode [role="banner"]:not(.a11y-widget):not(.a11y-widget *):hover,
body.a11y-focus-mode [role="contentinfo"]:not(.a11y-widget):not(.a11y-widget *):hover,
body.a11y-focus-mode [role="navigation"]:not(.a11y-widget):not(.a11y-widget *):hover {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   TTS Controls
   -------------------------------------------------------------------------- */

.a11y-widget__tts-controls {
  padding: 8px 16px;
  border-top: 1px solid var(--a11y-border);
  background: var(--a11y-bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.a11y-widget__tts-controls[hidden] {
  display: none;
}

.a11y-widget__tts-pause {
  width: 100%;
  padding: 8px 12px;
  background: var(--a11y-primary, #2563eb);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

.a11y-widget__tts-speed {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

.a11y-widget__tts-rate {
  font-weight: 600;
  min-width: 40px;
  text-align: center;
}

.a11y-widget__tts-slower,
.a11y-widget__tts-faster {
  padding: 4px 10px;
  background: var(--a11y-item-bg);
  border: 1px solid var(--a11y-border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--a11y-text);
}

/* --------------------------------------------------------------------------
   Dev Mode Audit
   -------------------------------------------------------------------------- */

.a11y-dev-violation {
  outline: 3px solid #dc2626 !important;
  outline-offset: 2px !important;
}

.a11y-widget__dev-badge {
  display: inline-block;
  background: #dc2626;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 4px;
  vertical-align: middle;
  border: none;
  cursor: pointer;
}
.a11y-widget__dev-badge:focus {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

.a11y-widget__dev-audit-list {
  max-height: 160px;
  overflow-y: auto;
  background: #1f1f1f;
  border: 1px solid #dc2626;
  border-radius: 4px;
  margin-top: 4px;
  padding: 4px 0;
  font-size: 0.7rem;
  font-family: monospace;
}
.a11y-widget__dev-audit-item {
  padding: 2px 8px;
  color: #fca5a5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.a11y-widget__dev-audit-item:first-child {
  color: #86efac;
}

/* --------------------------------------------------------------------------
   First-visit tooltip (.a11y-widget__tooltip)
   -------------------------------------------------------------------------- */

.a11y-widget__tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: #1a1a1a;
  color: #ffffff;
  font-size: 13px;
  line-height: 1.4;
  padding: 8px 12px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  z-index: 10001;
  /* Arrow */
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}

.a11y-widget__tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  right: 14px;
  border: 6px solid transparent;
  border-top-color: #1a1a1a;
}

.a11y-widget__tooltip--animated {
  transition: opacity 0.2s ease;
}

.a11y-widget__tooltip--visible {
  opacity: 1;
}

/* Screen-reader live region (visually hidden)
   -------------------------------------------------------------------------- */

.a11y-widget__announce {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
