/* Key changes made:
   1. Reduced panel width from 600px to 420px for laptops
   2. Reduced max-height from 1010px to 500px
   3. Fixed mobile toggle button visibility by removing problematic transform
   4. Made panel positioning more responsive
*/

@import url("https://cdn.jsdelivr.net/npm/opendyslexic@3.0.0/OpenDyslexic-Regular.woff2");

@font-face {
  font-family: "OpenDyslexic";
  src: url("https://cdn.jsdelivr.net/npm/opendyslexic@3.0.0/OpenDyslexic-Regular.woff2")
    format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "OpenDyslexic";
  src: url("https://cdn.jsdelivr.net/npm/opendyslexic@3.0.0/OpenDyslexic-Bold.woff2")
    format("woff2");
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

.accessibility-toolbar {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 99999;
}

.accessibility-toggle {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0073aa 0%, #005a87 100%);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 28px;
  box-shadow: 0 8px 24px rgba(0, 115, 170, 0.4);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.accessibility-toggle::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.accessibility-toggle:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 12px 32px rgba(0, 115, 170, 0.5);
}

.accessibility-toggle:hover::before {
  opacity: 1;
}

.accessibility-toggle:focus {
  outline: 3px solid #ff3300;
  outline-offset: 3px;
}

.accessibility-toggle:active {
  transform: translateY(-1px) scale(1.02);
}

.accessibility-panel {
  position: absolute;
  bottom: 85px;
  right: 0;
  width: 420px; /* Reduced from 600px */
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 
              0 0 0 1px rgba(255, 255, 255, 0.5);
  overflow: hidden;
  animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.accessibility-header {
  background: linear-gradient(135deg, #0073aa 0%, #005a87 100%);
  color: white;
  padding: 18px 20px; /* Reduced from 20px 24px */
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  overflow: hidden;
}

.accessibility-header::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  animation: headerGlow 3s ease-in-out infinite;
}

@keyframes headerGlow {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(-10px, -10px); }
}

.accessibility-header h3 {
  margin: 0;
  font-size: 17px !important; /* Reduced from 18px */
  letter-spacing: 0.3px;
  position: relative;
  z-index: 1;
}

.accessibility-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 26px; /* Reduced from 28px */
  cursor: pointer;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 8px;
  transition: all 0.2s ease;
  position: relative;
  z-index: 1;
}

.accessibility-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}

.accessibility-content {
  padding: 20px; /* Reduced from 24px */
  max-height: 500px; /* Reduced from 1010px */
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #0073aa #f0f0f0;
}

.accessibility-content::-webkit-scrollbar {
  width: 6px;
}

.accessibility-content::-webkit-scrollbar-track {
  background: #f0f0f0;
  border-radius: 10px;
}

.accessibility-content::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #0073aa 0%, #005a87 100%);
  border-radius: 10px;
}

.accessibility-group {
  margin-bottom: 18px; /* Reduced from 24px */
  padding: 14px; /* Reduced from 18px */
  background: #f8f9fa;
  border-radius: 12px;
  border: 1px solid #e9ecef;
  transition: background 0.2s ease;
}

.accessibility-group:hover {
  background: #f1f3f5;
}

.accessibility-group h4 {
  margin: 0 0 12px 0; /* Reduced from 14px */
  font-size: 14px !important; /* Reduced from 15px */
  color: #495057;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.accessibility-group h4::before {
  content: '';
  width: 4px;
  height: 16px; /* Reduced from 18px */
  background: linear-gradient(135deg, #0073aa 0%, #005a87 100%);
  border-radius: 2px;
}

.accessibility-buttons {
  display: flex;
  gap: 8px; /* Reduced from 10px */
  flex-wrap: wrap;
}

.accessibility-btn {
  flex: 1;
  min-width: 80px; /* Reduced from 90px */
  padding: 12px 14px; /* Reduced from 14px 16px */
  border: 2px solid transparent;
  background: white;
  color: #495057;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px; /* Reduced from 14px */
  font-weight: 600;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  position: relative;
  overflow: hidden;
}

.accessibility-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(0, 115, 170, 0.1);
  transform: translate(-50%, -50%);
  transition: width 0.4s ease, height 0.4s ease;
}

.accessibility-btn:hover::before {
  width: 300px;
  height: 300px;
}

.accessibility-btn:hover {
  border-color: #0073aa;
  color: #0073aa;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 115, 170, 0.25);
}

.accessibility-btn:focus {
  outline: 3px solid #ff3300;
  outline-offset: 2px;
}

.accessibility-btn.active {
  background: linear-gradient(135deg, #0073aa 0%, #005a87 100%);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 15px rgba(0, 115, 170, 0.4);
}

.accessibility-btn i {
  margin-right: 6px;
  position: relative;
  z-index: 1;
}

.accessibility-btn span {
  position: relative;
  z-index: 1;
}

.reset-btn {
  width: 100%;
  background: linear-gradient(135deg, #1e88e5 0%, #1565c0 100%);
  border: none;
  color: white;
  font-size: 14px; /* Reduced from 15px */
  padding: 14px; /* Reduced from 16px */
  box-shadow: 0 4px 15px rgba(30, 136, 229, 0.3);
}

.reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(30, 136, 229, 0.4);
  color: white;
}

.accessibility-toggle-group {
  display: flex;
  align-items: center;
  gap: 12px; /* Reduced from 14px */
  font-size: 13px; /* Reduced from 14px */
  font-weight: 600;
  margin-bottom: 12px; /* Reduced from 14px */
  padding: 10px; /* Reduced from 12px */
  background: white;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.accessibility-toggle-group:hover {
  background: #f8f9fa;
}

.accessibility-switch {
  position: relative;
  display: inline-block;
  width: 54px;
  height: 28px;
  flex-shrink: 0;
}

.accessibility-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #e0e0e0 0%, #d0d0d0 100%);
  transition: 0.3s;
  border-radius: 28px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background: white;
  transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

input:checked + .slider {
  background: linear-gradient(135deg, #0073aa 0%, #005a87 100%);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2), 
              0 0 12px rgba(0, 115, 170, 0.4);
}

input:checked + .slider:before {
  transform: translateX(26px);
}

input:focus + .slider {
  box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.3);
}

.accessibility-btn:disabled,
.accessibility-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #e0e0e0 !important;
  color: #999 !important;
  border-color: #ccc !important;
}

.accessibility-btn:disabled:hover,
.accessibility-btn.disabled:hover {
  transform: none !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
}

body {
  --text-zoom: 1;
}

body.zoom-level-1 { --text-zoom: 1.05; }
body.zoom-level-2 { --text-zoom: 1.1; }
body.zoom-level-3 { --text-zoom: 1.15; }
body.zoom-level-4 { --text-zoom: 1.2; }
body.zoom-level-5 { --text-zoom: 1.25; }
body.zoom-level-6 { --text-zoom: 1.3; }
body.zoom-level-7 { --text-zoom: 1.35; }
body.zoom-level-8 { --text-zoom: 1.4; }

/* Zoom styles - more specific selectors */
body[class*="zoom-level-"] *:not(.accessibility-toolbar):not(.accessibility-toolbar *) {
  font-size: calc(1em * var(--text-zoom)) !important;
}

/* Additional specific selectors for commonly missed elements */
body[class*="zoom-level-"] p:not(.accessibility-toolbar p),
body[class*="zoom-level-"] li:not(.accessibility-toolbar li),
body[class*="zoom-level-"] span:not(.accessibility-toolbar span),
body[class*="zoom-level-"] a:not(.accessibility-toolbar a),
body[class*="zoom-level-"] div:not(.accessibility-toolbar div),
body[class*="zoom-level-"] h1:not(.accessibility-toolbar h1),
body[class*="zoom-level-"] h2:not(.accessibility-toolbar h2),
body[class*="zoom-level-"] h3:not(.accessibility-toolbar h3),
body[class*="zoom-level-"] h4:not(.accessibility-toolbar h4),
body[class*="zoom-level-"] h5:not(.accessibility-toolbar h5),
body[class*="zoom-level-"] h6:not(.accessibility-toolbar h6),
body[class*="zoom-level-"] label:not(.accessibility-toolbar label),
body[class*="zoom-level-"] button:not(.accessibility-toolbar button),
body[class*="zoom-level-"] input:not(.accessibility-toolbar input),
body[class*="zoom-level-"] textarea:not(.accessibility-toolbar textarea),
body[class*="zoom-level-"] td:not(.accessibility-toolbar td),
body[class*="zoom-level-"] th:not(.accessibility-toolbar th) {
  font-size: calc(1em * var(--text-zoom)) !important;
}

body.high-contrast {
  background: #000 !important;
}

body.high-contrast *:not(.accessibility-toolbar):not(.accessibility-toolbar *) {
  background-color: #000 !important;
  color: #fff !important;
  border-color: #fff !important;
}

body.high-contrast a:not(.accessibility-toolbar a) {
  color: #ff3300 !important;
  font-weight: bold !important;
}

body.high-contrast img:not(.accessibility-toolbar img) {
  filter: contrast(1.5) brightness(0.9);
}

body.high-contrast button:not(.accessibility-toolbar button),
body.high-contrast input:not(.accessibility-toolbar input) {
  background: #333 !important;
  color: #fff !important;
  border: 2px solid #fff !important;
}

body.dyslexia-mode {
  background: #fdf8e8 !important;
}

body.dyslexia-mode *:not(.accessibility-toolbar):not(.accessibility-toolbar *):not(img):not(svg):not(i) {
  font-family: "OpenDyslexic", "Comic Sans MS", Arial, sans-serif !important;
}

body.dyslexia-mode *:not(.accessibility-toolbar):not(.accessibility-toolbar *) {
  line-height: 1.8 !important;
  letter-spacing: 0.05em !important;
  word-spacing: 0.16em !important;
}

body.dyslexia-mode p:not(.accessibility-toolbar p),
body.dyslexia-mode li:not(.accessibility-toolbar li),
body.dyslexia-mode div:not(.accessibility-toolbar div) {
  color: #2a2a2a !important;
}

body.dyslexia-mode a:hover:not(.accessibility-toolbar a) {
  background-color: #fff9c4 !important;
  color: #003d82 !important;
  border-radius: 3px !important;
}

body.dyslexia-mode *:not(.accessibility-toolbar *),
body.dyslexia-mode *:not(.accessibility-toolbar *)::before,
body.dyslexia-mode *:not(.accessibility-toolbar *)::after {
  animation: none !important;
  transition: none !important;
}

body.dyslexia-mode {
  scroll-behavior: auto !important;
}

body.keyboard-navigation *:focus:not(.accessibility-toolbar *) {
  outline: 4px solid #ff3300 !important;
  outline-offset: 3px !important;
  z-index: 9999;
  position: relative;
}

body.highlight-links a:not(.accessibility-toolbar a) {
  background: #ffff00 !important;
  color: #000 !important;
  padding: 2px 4px !important;
  border-radius: 3px !important;
  font-weight: 600 !important;
  text-decoration: none !important;
}

body.highlight-links a:hover:not(.accessibility-toolbar a) {
  background: #ffff00 !important;
}

body.text-spacing *:not(.accessibility-toolbar *) {
  line-height: 2 !important;
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
}

body.text-spacing p:not(.accessibility-toolbar p),
body.text-spacing li:not(.accessibility-toolbar li) {
  margin-bottom: 1.5em !important;
}

body.light-contrast {
  background-color: #fafafa !important;
  color: #1a1a1a !important;
}

body.light-contrast *:not(.accessibility-toolbar):not(.accessibility-toolbar *) {
  background-color: transparent !important;
  color: inherit !important;
  border-color: #d0d0d0 !important;
}

body.light-contrast a:not(.accessibility-toolbar a) {
  color: #0b5ed7 !important;
  text-decoration: underline !important;
  font-weight: 500 !important;
}

body.light-contrast a:hover:not(.accessibility-toolbar a) {
  color: #084298 !important;
}

body.light-contrast h1, body.light-contrast h2, 
body.light-contrast h3, body.light-contrast h4, 
body.light-contrast h5, body.light-contrast h6 {
  color: #111 !important;
  font-weight: 600 !important;
}

body.light-contrast button:not(.accessibility-toolbar button),
body.light-contrast input:not(.accessibility-toolbar input),
body.light-contrast select:not(.accessibility-toolbar select),
body.light-contrast textarea:not(.accessibility-toolbar textarea) {
  background-color: #f1f1f1 !important;
  color: #111 !important;
  border: 1.5px solid #bbb !important;
}

body.light-contrast section,
body.light-contrast article,
body.light-contrast .card {
  background-color: #ffffff !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
}

body.reading-guide-active #reading-guide-line {
  display: block !important;
}

#reading-guide-line {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(90deg, transparent 0%, #ff6b6b 50%, transparent 100%);
  pointer-events: none;
  z-index: 99998;
  transition: top 0.05s ease-out;
}

body.reading-mask-active #reading-mask-overlay {
  display: block !important;
}

#reading-mask-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 99997;
}

#reading-mask-top,
#reading-mask-bottom {
  position: absolute;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  transition: all 0.1s ease-out;
}

#reading-mask-top { top: 0; }
#reading-mask-bottom { bottom: 0; }

.reading-mask-highlight {
  position: absolute;
  left: 0;
  right: 0;
  background: transparent;
  border-top: 2px solid rgba(255, 107, 107, 0.8);
  border-bottom: 2px solid rgba(255, 107, 107, 0.8);
  box-shadow: inset 0 0 20px rgba(255, 107, 107, 0.1);
  pointer-events: none;
}

body.dyslexia-mode #reading-guide-line {
  background: linear-gradient(90deg, transparent 0%, #0064c8 50%, transparent 100%);
  box-shadow: 0 0 10px rgba(0, 100, 200, 0.5);
}

body.dyslexia-mode #reading-mask-top,
body.dyslexia-mode #reading-mask-bottom {
  background: rgba(253, 248, 232, 0.85);
}

body.dyslexia-mode .reading-mask-highlight {
  border-color: rgba(0, 100, 200, 0.8);
  box-shadow: inset 0 0 20px rgba(0, 100, 200, 0.1);
}

body.high-contrast #reading-guide-line {
  background: linear-gradient(90deg, transparent 0%, #ff3300 50%, transparent 100%);
  box-shadow: 0 0 15px rgba(255, 17, 0, 0.7);
}

body.high-contrast #reading-mask-top,
body.high-contrast #reading-mask-bottom {
  background: rgba(0, 0, 0, 0.9);
}

@media (max-width: 768px) {
  .accessibility-panel {
    width: 90vw;
    max-width: 360px;
    bottom: 80px;
    left: 0;
    right: auto;
    transform: none;
    margin-left: 15px;
  }

  .accessibility-toolbar {
    bottom: 15px;
    left: 15px;
    right: auto;
    transform: none;
  }

  .accessibility-toggle {
    width: 60px;
    height: 60px;
    font-size: 24px;
  }

  .accessibility-content {
    max-height: 400px; /* Reduced for mobile */
    padding: 16px;
  }

  .accessibility-group {
    padding: 12px;
    margin-bottom: 14px;
  }
  
  .accessibility-btn {
    min-width: 70px;
    padding: 10px 12px;
    font-size: 12px;
  }

  .accessibility-header {
    padding: 14px 16px;
  }

  .accessibility-header h3 {
    font-size: 15px !important;
  }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
  .accessibility-panel {
    width: 380px;
  }
}