/* ========== CTM ACCESSIBILITY WIDGET ==========
   California Technical Media Corp.
   Branded for CTM dark red / dark design system.
   ============================================== */

/* Atkinson Hyperlegible — designed for low vision and dyslexia accessibility */
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400;1,700&display=swap');

/* ── Trigger button ─────────────────────────────────────────────────────── */
#ctm-a11y-trigger {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 99998;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1A1A1A;
  border: 3px solid #9B1B1B;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(26, 26, 26, 0.4);
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
  padding: 0;
}

#ctm-a11y-trigger:hover {
  transform: scale(1.08);
  background: #2a2a2a;
  box-shadow: 0 6px 28px rgba(26, 26, 26, 0.55);
}

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

#ctm-a11y-trigger svg {
  width: 26px;
  height: 26px;
  fill: #ffffff;
}

/* ── Panel ──────────────────────────────────────────────────────────────── */
#ctm-a11y-panel {
  position: fixed;
  bottom: 96px;
  right: 28px;
  z-index: 99999;
  width: 340px;
  max-height: 80vh;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 16px 56px rgba(26, 26, 26, 0.22), 0 0 0 1px rgba(26, 26, 26, 0.07);
  overflow: hidden;
  display: none;
  flex-direction: column;
  font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

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

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

/* ── Panel header ───────────────────────────────────────────────────────── */
.ctm-a11y-header {
  background: #1A1A1A;
  color: #ffffff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 3px solid #9B1B1B;
}

.ctm-a11y-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  padding: 0;
  color: #ffffff;
  line-height: 1.4;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.ctm-a11y-close {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #ffffff;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  transition: background 0.15s;
  flex-shrink: 0;
}

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

/* ── Panel body ─────────────────────────────────────────────────────────── */
.ctm-a11y-body {
  padding: 14px;
  overflow-y: auto;
  flex-grow: 1;
}

/* ── Feature grid ───────────────────────────────────────────────────────── */
.ctm-a11y-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

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

.ctm-a11y-btn:hover {
  background: #f1f3f7;
  border-color: #9ca3af;
}

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

/* Active state — CTM red accent */
.ctm-a11y-btn.active {
  background: #fdf5f5;
  border-color: #9B1B1B;
}

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

.ctm-a11y-icon {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  color: #1A1A1A;
  line-height: 1;
}

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

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

.ctm-a11y-reset:hover { background: #ffe4e6; border-color: #f87171; }
.ctm-a11y-reset:focus-visible { outline: 3px solid #9B1B1B; outline-offset: 2px; }

/* ========== ACCESSIBILITY MODE OVERRIDES ================================= */

/* 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; }
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: #1A1A1A !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 font — Atkinson Hyperlegible */
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: 'Atkinson Hyperlegible', Arial, sans-serif !important;
}

/* Highlight links */
html.ctm-highlight-links a {
  outline: 3px solid #9B1B1B !important;
  outline-offset: 2px !important;
  background: rgba(155, 27, 27, 0.08) !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::before {
  content: '';
  position: fixed;
  inset: 0;
  backdrop-filter: grayscale(100%);
  -webkit-backdrop-filter: grayscale(100%);
  pointer-events: none;
  z-index: 99997;
}

/* 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 #9B1B1B !important;
  outline-offset: 4px !important;
}

/* Align left */
html.ctm-align-left * {
  text-align: left !important;
}

/* Readable width — applied via JS to exclude the widget */

/* ── Mobile adjustments ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #ctm-a11y-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 90px;
    max-height: 70vh;
  }
  #ctm-a11y-trigger {
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
  }
  #ctm-a11y-trigger svg {
    width: 22px;
    height: 22px;
  }
}
