/* ========== CTM ACCESSIBILITY WIDGET ========== */

/* OpenDyslexic web font — only downloaded when dyslexia mode is active */
@font-face {
  font-family: 'OpenDyslexic';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Regular.woff') format('woff');
}
@font-face {
  font-family: 'OpenDyslexic';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Bold.woff') format('woff');
}

/* Trigger Button */
#ctm-a11y-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99998;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1e293b;
  border: 3px solid #ffffff;
  outline: 2px solid #1a1a1a;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  transition: transform 0.2s, box-shadow 0.2s;
}

#ctm-a11y-trigger:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0,0,0,0.35);
  outline: 2px solid #1a1a1a;
}

#ctm-a11y-trigger:focus-visible {
  outline: 3px solid #60a5fa;
  outline-offset: 3px;
}

#ctm-a11y-trigger svg {
  width: 28px;
  height: 28px;
  fill: white;
}

/* Panel */
#ctm-a11y-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 99999;
  width: 340px;
  max-height: 80vh;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.05);
  overflow: hidden;
  display: none;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

#ctm-a11y-panel.open {
  display: flex;
  animation: ctmSlideUp 0.25s ease-out;
}

@keyframes ctmSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.ctm-a11y-header {
  background: #1e293b;
  color: white;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.ctm-a11y-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  padding: 0;
  color: white;
  line-height: 1.4;
}

.ctm-a11y-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: background 0.15s;
}

.ctm-a11y-close:hover { background: rgba(255,255,255,0.25); }
.ctm-a11y-close:focus-visible { outline: 2px solid #60a5fa; outline-offset: 2px; }

.ctm-a11y-body {
  padding: 16px;
  overflow-y: auto;
  flex-grow: 1;
}

.ctm-a11y-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ctm-a11y-btn {
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
  font-family: inherit;
  position: relative;
}

.ctm-a11y-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.ctm-a11y-btn:focus-visible {
  outline: 3px solid #60a5fa;
  outline-offset: 2px;
}

.ctm-a11y-btn.active {
  background: #eff6ff;
  border-color: #3b82f6;
}

.ctm-a11y-btn.active::after {
  content: '\2713';
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 0.7rem;
  color: #3b82f6;
  font-weight: 700;
}

.ctm-a11y-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #334155;
}

.ctm-a11y-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: #334155;
  text-align: center;
  line-height: 1.3;
}

/* Reset button */
.ctm-a11y-reset {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  background: #fee2e2;
  border: 2px solid #fca5a5;
  border-radius: 12px;
  color: #991b1b;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.ctm-a11y-reset:hover { background: #fecaca; border-color: #f87171; }
.ctm-a11y-reset:focus-visible { outline: 3px solid #60a5fa; outline-offset: 2px; }

/* ========== ACCESSIBILITY OVERRIDE CLASSES ========== */

/* High contrast */
html.ctm-high-contrast body {
  background: #000 !important;
  color: #fff !important;
}
html.ctm-high-contrast body * {
  background-color: #000 !important;
  color: #fff !important;
  border-color: #fff !important;
  box-shadow: none !important;
}
html.ctm-high-contrast a { color: #ffff00 !important; }
html.ctm-high-contrast img { filter: contrast(1.5) !important; }
/* Exclude the widget itself from high contrast */
html.ctm-high-contrast #ctm-a11y-panel,
html.ctm-high-contrast #ctm-a11y-panel * {
  background-color: revert !important;
  color: revert !important;
  border-color: revert !important;
}
html.ctm-high-contrast #ctm-a11y-trigger {
  background-color: #1e293b !important;
}

/* Bigger text */
html.ctm-big-text body { font-size: 130% !important; }
html.ctm-big-text p,
html.ctm-big-text li,
html.ctm-big-text td,
html.ctm-big-text span:not(.ctm-a11y-label):not(.ctm-a11y-icon) {
  font-size: 1.3em !important;
}

/* Text spacing */
html.ctm-text-spacing body {
  letter-spacing: 0.08em !important;
  word-spacing: 0.16em !important;
}
html.ctm-text-spacing p,
html.ctm-text-spacing li,
html.ctm-text-spacing td {
  letter-spacing: 0.08em !important;
  word-spacing: 0.16em !important;
}

/* Line height */
html.ctm-line-height body { line-height: 2.2 !important; }
html.ctm-line-height p,
html.ctm-line-height li,
html.ctm-line-height td {
  line-height: 2.2 !important;
}

/* Dyslexia friendly */
html.ctm-dyslexia body,
html.ctm-dyslexia p,
html.ctm-dyslexia li,
html.ctm-dyslexia td,
html.ctm-dyslexia h1,
html.ctm-dyslexia h2,
html.ctm-dyslexia h3,
html.ctm-dyslexia h4,
html.ctm-dyslexia span,
html.ctm-dyslexia a {
  font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif !important;
}

/* Highlight links */
html.ctm-highlight-links a {
  outline: 3px solid #ffff00 !important;
  outline-offset: 2px !important;
  background: rgba(255,255,0,0.15) !important;
  text-decoration: underline !important;
}

/* Pause animations */
html.ctm-pause-anim *,
html.ctm-pause-anim *::before,
html.ctm-pause-anim *::after {
  animation-duration: 0s !important;
  animation-delay: 0s !important;
  transition-duration: 0s !important;
  transition-delay: 0s !important;
}
html.ctm-pause-anim #ctm-a11y-panel,
html.ctm-pause-anim #ctm-a11y-panel * {
  transition-duration: revert !important;
}

/* Hide images */
html.ctm-hide-images img:not(#ctm-a11y-panel img) {
  opacity: 0 !important;
}

/* Grayscale */
html.ctm-desaturate body {
  filter: grayscale(100%) !important;
}

/* Big cursor */
html.ctm-big-cursor,
html.ctm-big-cursor * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48'%3E%3Cpath d='M4 4l16 40 6-16 16-6z' fill='%23000' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") 4 4, auto !important;
}

/* Invert colors */
html.ctm-invert body {
  filter: invert(1) hue-rotate(180deg) !important;
}
html.ctm-invert img,
html.ctm-invert video {
  filter: invert(1) hue-rotate(180deg) !important;
}
html.ctm-invert #ctm-a11y-panel {
  filter: invert(1) hue-rotate(180deg) !important;
}

/* Focus indicator enhancement */
html.ctm-focus-indicator *:focus-visible {
  outline: 4px solid #ff6600 !important;
  outline-offset: 4px !important;
}

/* Align left */
html.ctm-align-left p,
html.ctm-align-left li,
html.ctm-align-left td,
html.ctm-align-left h1,
html.ctm-align-left h2,
html.ctm-align-left h3 {
  text-align: left !important;
}
