/* ============================================================
   Kultivate Accessibility Widget
   Design-matched to Kultivate theme
   ============================================================ */

/* ── Floating trigger button ─────────────────────────────── */
#a11y-trigger {
  position: fixed;
  bottom: 28px;
  left: 28px;
  z-index: 99998;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--sage, #6b8c7a);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  transition: background .2s, transform .2s;
  outline: none;
}
#a11y-trigger:hover,
#a11y-trigger:focus-visible {
  background: var(--sage-dark, #4f6b58);
  transform: scale(1.08);
}
#a11y-trigger svg {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}
/* Tooltip */
#a11y-trigger::after {
  content: 'Accessibility';
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--sage-dark, #4f6b58);
  color: #fff;
  font-size: .72rem;
  letter-spacing: .06em;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s;
  font-family: 'DM Sans', sans-serif;
}
#a11y-trigger:hover::after,
#a11y-trigger:focus-visible::after {
  opacity: 1;
}

/* ── Panel ───────────────────────────────────────────────── */
#a11y-panel {
  position: fixed;
  bottom: 90px;
  left: 28px;
  z-index: 99999;
  width: 340px;
  max-height: calc(100vh - 120px);
  background: var(--warm-white, #faf8f5);
  border: 1px solid var(--border, #ddd6cc);
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,.14);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'DM Sans', sans-serif;
  /* hidden state */
  opacity: 0;
  transform: translateY(12px) scale(.97);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
#a11y-panel.a11y-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* Panel header */
#a11y-panel-header {
  background: var(--sage, #6b8c7a);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#a11y-panel-header h2 {
  font-size: .85rem;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin: 0;
  color: #fff;
  line-height: 1;
}
#a11y-close {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  transition: background .15s;
  flex-shrink: 0;
}
#a11y-close:hover { background: rgba(255,255,255,.3); }

/* Reset strip */
#a11y-reset-strip {
  padding: 10px 16px;
  background: var(--cream, #f5f0e8);
  border-bottom: 1px solid var(--border, #ddd6cc);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#a11y-reset-strip span {
  font-size: .72rem;
  color: var(--text-light, #8a7e72);
  letter-spacing: .04em;
}
#a11y-reset-btn {
  font-size: .72rem;
  color: var(--sage, #6b8c7a);
  background: none;
  border: 1px solid var(--sage, #6b8c7a);
  border-radius: 20px;
  padding: 3px 12px;
  cursor: pointer;
  letter-spacing: .04em;
  transition: background .15s, color .15s;
}
#a11y-reset-btn:hover {
  background: var(--sage, #6b8c7a);
  color: #fff;
}

/* Grid of buttons */
#a11y-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
  flex: 1;
}
#a11y-grid::-webkit-scrollbar { width: 4px; }
#a11y-grid::-webkit-scrollbar-track { background: transparent; }
#a11y-grid::-webkit-scrollbar-thumb { background: var(--border, #ddd6cc); border-radius: 4px; }

/* Individual feature button */
.a11y-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 6px 12px;
  background: #fff;
  border: 1.5px solid var(--border, #ddd6cc);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
  text-align: center;
  position: relative;
}
.a11y-btn:hover {
  border-color: var(--sage, #6b8c7a);
  background: var(--cream, #f5f0e8);
}
.a11y-btn.active {
  background: var(--sage, #6b8c7a);
  border-color: var(--sage, #6b8c7a);
  color: #fff;
}
.a11y-btn .a11y-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.a11y-btn .a11y-icon svg {
  width: 26px;
  height: 26px;
}
.a11y-btn.active .a11y-icon svg {
  stroke: #fff;
  fill: #fff;
}
.a11y-btn .a11y-label {
  font-size: .67rem;
  font-weight: 500;
  letter-spacing: .03em;
  color: var(--text, #2d2a26);
  line-height: 1.25;
}
.a11y-btn.active .a11y-label {
  color: #fff;
}

/* Step buttons (bigger text / line height / saturation) */
.a11y-btn.step-active {
  border-color: var(--sage, #6b8c7a);
}
.a11y-step-badge {
  position: absolute;
  top: 6px;
  right: 7px;
  background: var(--sage, #6b8c7a);
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  border-radius: 20px;
  padding: 1px 5px;
  line-height: 1.4;
  display: none;
}
.a11y-btn.step-active .a11y-step-badge { display: block; }

/* Page structure overlay */
#a11y-structure-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 99997;
  background: rgba(107,140,122,.06);
  pointer-events: none;
}
#a11y-structure-overlay.active { display: block; }

/* ── Active feature classes ──────────────────────────────── */

/* 1. Screen Reader — spoken focus announcements (JS handles, no CSS needed) */

/* 2. Contrast + */
html.a11y-contrast {
  filter: contrast(160%) !important;
}

/* 3. Smart Contrast */
html.a11y-smart-contrast {
  filter: invert(1) hue-rotate(180deg) !important;
}
html.a11y-smart-contrast img,
html.a11y-smart-contrast video,
html.a11y-smart-contrast iframe,
html.a11y-smart-contrast [style*="background-image"] {
  filter: invert(1) hue-rotate(180deg);
}

/* 4. Highlight Links */
html.a11y-highlight-links a {
  outline: 2px solid #2a7a4f !important;
  outline-offset: 2px !important;
  background: rgba(42,122,79,.08) !important;
  border-radius: 2px;
  text-decoration: underline !important;
}

/* 5. Bigger Text — 3 steps */
html.a11y-text-1 { font-size: 110% !important; }
html.a11y-text-2 { font-size: 120% !important; }
html.a11y-text-3 { font-size: 135% !important; }

/* 6. Text Spacing */
html.a11y-text-spacing * {
  letter-spacing: .12em !important;
  word-spacing: .2em !important;
}

/* 7. Pause Animations */
html.a11y-pause-animations *,
html.a11y-pause-animations *::before,
html.a11y-pause-animations *::after {
  animation-play-state: paused !important;
  transition-duration: 0s !important;
}

/* 8. Hide Images */
html.a11y-hide-images img { visibility: hidden !important; }
html.a11y-hide-images [style*="background-image"] { background-image: none !important; }

/* 9. Dyslexia Friendly */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/fonts/OpenDyslexic-Regular.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/fonts/OpenDyslexic-Bold.otf') format('opentype');
  font-weight: 700;
  font-style: normal;
}
html.a11y-dyslexia,
html.a11y-dyslexia body,
html.a11y-dyslexia p,
html.a11y-dyslexia h1,
html.a11y-dyslexia h2,
html.a11y-dyslexia h3,
html.a11y-dyslexia h4,
html.a11y-dyslexia li,
html.a11y-dyslexia a,
html.a11y-dyslexia span,
html.a11y-dyslexia div,
html.a11y-dyslexia button {
  font-family: 'OpenDyslexic', sans-serif !important;
  line-height: 1.8 !important;
  word-spacing: .16em !important;
}

/* 10. Cursor */
html.a11y-cursor,
html.a11y-cursor * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' stroke='%23fff' stroke-width='1' d='M4 0 L4 20 L8 16 L12 24 L14 22 L10 14 L16 14 Z'/%3E%3C/svg%3E") 0 0, auto !important;
}

/* 11. Tooltips — JS injects, styled here */
.a11y-tooltip-bubble {
  position: fixed;
  z-index: 999999;
  background: var(--sage-dark, #4f6b58);
  color: #fff;
  font-size: .75rem;
  padding: 6px 12px;
  border-radius: 6px;
  pointer-events: none;
  max-width: 240px;
  line-height: 1.45;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  font-family: 'DM Sans', sans-serif;
  transition: opacity .12s;
}
.a11y-tooltip-bubble::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--sage-dark, #4f6b58);
}

/* 12. Page Structure — heading outlines (JS injects labels) */
html.a11y-structure h1,
html.a11y-structure h2,
html.a11y-structure h3,
html.a11y-structure h4,
html.a11y-structure h5,
html.a11y-structure h6 {
  outline: 2px dashed var(--sage, #6b8c7a) !important;
  outline-offset: 3px;
  position: relative;
}
.a11y-heading-tag {
  position: absolute;
  top: -10px;
  left: 0;
  background: var(--sage, #6b8c7a);
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  letter-spacing: .06em;
  pointer-events: none;
  z-index: 99;
}

/* 13. Line Height — 3 steps */
html.a11y-lh-1 * { line-height: 1.9 !important; }
html.a11y-lh-2 * { line-height: 2.3 !important; }
html.a11y-lh-3 * { line-height: 2.8 !important; }

/* 14. Text Align */
html.a11y-text-align p,
html.a11y-text-align li,
html.a11y-text-align div,
html.a11y-text-align span {
  text-align: left !important;
}

/* 15. Dictionary — highlight on hover in dictionary mode */
html.a11y-dictionary-mode .a11y-word-wrap {
  cursor: help;
  border-bottom: 1px dotted var(--sage, #6b8c7a);
}
#a11y-dict-popup {
  position: fixed;
  z-index: 999999;
  background: var(--warm-white, #faf8f5);
  border: 1.5px solid var(--sage, #6b8c7a);
  border-radius: 10px;
  padding: 14px 16px;
  max-width: 280px;
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
  font-family: 'DM Sans', sans-serif;
  display: none;
}
#a11y-dict-popup.visible { display: block; }
#a11y-dict-popup strong {
  display: block;
  font-size: .9rem;
  color: var(--sage-dark, #4f6b58);
  margin-bottom: 6px;
  text-transform: capitalize;
}
#a11y-dict-popup p {
  font-size: .8rem;
  color: var(--text, #2d2a26);
  line-height: 1.6;
  margin: 0;
}
#a11y-dict-close {
  position: absolute;
  top: 8px; right: 10px;
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-light, #8a7e72);
  line-height: 1;
}

/* 16. Saturation — 3 steps */
html.a11y-sat-0 { filter: saturate(0) !important; }
html.a11y-sat-2 { filter: saturate(2) !important; }
html.a11y-sat-3 { filter: saturate(3) !important; }

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width: 400px) {
  #a11y-panel {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: 80px;
  }
  #a11y-trigger {
    left: 16px;
    bottom: 20px;
  }
}
