/* ============================================================
   ACCESSIBILITY WIDGET — Premium Design v7
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --a11y-font-scale: 1;
  --a11y-line-height: 1.5;
  --a11y-letter-space: 0;
}

/* ---------- Root Scaling ---------- */
html { font-size: calc(16px * var(--a11y-font-scale)); }
html body {
  line-height: var(--a11y-line-height);
  letter-spacing: calc(var(--a11y-letter-space) * 1em);
}

/* ============================================================
   A11Y STATE CLASSES
   ============================================================ */

/* Contrast */
html.a11y__contrast { filter: contrast(1.2) saturate(1.08); }

/* Grayscale */
html.a11y__gray { filter: grayscale(1); }

/* Contrast + Gray together */
html.a11y__contrast.a11y__gray { filter: contrast(1.2) saturate(1.08) grayscale(1); }

/* Underline Links */
html.a11y__underline a,
html.a11y__underline a:visited {
  text-decoration: underline !important;
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
}

/* Big Cursor */
html.a11y__cursor,
html.a11y__cursor * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48'%3E%3Ccircle cx='18' cy='18' r='14' fill='%23000' fill-opacity='.12'/%3E%3Ccircle cx='18' cy='18' r='8' fill='%23000'/%3E%3Ccircle cx='18' cy='18' r='4' fill='%23fff'/%3E%3C/svg%3E") 18 18, auto !important;
}

/* Reduce Motion */
html.a11y__reduceMotion *,
html.a11y__reduceMotion *::before,
html.a11y__reduceMotion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

/* Focus Ring */
html.a11y__focusRing :focus-visible {
  outline: 3px solid rgba(59, 130, 246, .85) !important;
  outline-offset: 3px !important;
  border-radius: 8px;
}

/* Hide Images */
html.a11y__hideImages img,
html.a11y__hideImages picture,
html.a11y__hideImages video,
html.a11y__hideImages svg:not(#a11yFab svg) {
  opacity: 0.08 !important;
}

/* Reading Guide — horizontal bar that follows cursor */
html.a11y__readGuide #a11yReadGuide {
  display: block !important;
}

/* ============================================================
   FAB BUTTON (Floating Action Button)
   ============================================================ */

#a11yFab {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 99998;

  width: 52px;
  height: 52px;
  border-radius: 16px;
  border: none;

  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 50%, #1d4ed8 100%);
  color: #fff;
  box-shadow:
    0 8px 32px rgba(37, 99, 235, .45),
    0 2px 8px rgba(0, 0, 0, .12),
    inset 0 1px 0 rgba(255, 255, 255, .25);

  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), box-shadow .22s ease;
  animation: a11yFabPulse 3s ease-in-out infinite;
}

#a11yFab:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow:
    0 14px 44px rgba(37, 99, 235, .55),
    0 4px 16px rgba(0, 0, 0, .16),
    inset 0 1px 0 rgba(255, 255, 255, .30);
}

#a11yFab:active {
  transform: scale(.95);
  animation: none;
}

#a11yFab svg {
  width: 26px;
  height: 26px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .25));
}

/* Badge showing active count */
#a11yBadge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(239, 68, 68, .4);
  border: 2px solid #fff;
}
#a11yBadge.show { display: inline-flex; }

@keyframes a11yFabPulse {
  0%, 100% { box-shadow: 0 8px 32px rgba(37,99,235,.45), 0 2px 8px rgba(0,0,0,.12); }
  50% { box-shadow: 0 8px 32px rgba(37,99,235,.25), 0 2px 8px rgba(0,0,0,.08); }
}

/* ============================================================
   BACKDROP
   ============================================================ */

#a11yBackdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99998;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}

/* ============================================================
   PANEL
   ============================================================ */

#a11yBar {
  position: fixed;
  top: 78px;
  right: 18px;
  z-index: 99999;

  width: min(420px, calc(100vw - 48px));
  direction: rtl;

  background: rgba(255, 255, 255, .96);
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 24px;
  box-shadow:
    0 24px 80px rgba(0, 0, 0, .18),
    0 0 0 1px rgba(255, 255, 255, .8) inset;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);

  padding: 18px;
  transform-origin: top right;

  /* Opening animation */
  opacity: 1;
  transform: scale(1) translateY(0);
  transition: opacity .25s cubic-bezier(.4,0,.2,1), transform .25s cubic-bezier(.34,1.56,.64,1);
}

#a11yBar[hidden] {
  display: none !important;
}

/* ============================================================
   HEADER
   ============================================================ */

#a11yHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px 14px;
  border-bottom: 1px solid rgba(0, 0, 0, .06);
  margin-bottom: 14px;
}

#a11yTitle {
  font-weight: 900;
  font-size: 16px;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 8px;
}

#a11yTitle::before {
  content: "♿";
  font-size: 20px;
}

#a11yTitle small {
  font-weight: 600;
  opacity: .5;
  font-size: 11px;
}

#a11yClose {
  border: none;
  background: rgba(15, 23, 42, .06);
  border-radius: 12px;
  height: 36px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
  font-size: 13px;
  color: #334155;
  transition: background .15s ease, transform .1s ease;
}
#a11yClose:hover { background: rgba(15, 23, 42, .10); }
#a11yClose:active { transform: scale(.96); }

/* ============================================================
   COUNTER PILLS (Font Size, Line Height, Letter Spacing)
   ============================================================ */

#a11yRow, .a11yRow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
}

.a11yPill {
  flex: 1;
  min-width: 110px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  border: 1px solid rgba(0, 0, 0, .06);
  background: rgba(15, 23, 42, .03);
  transition: border-color .15s ease, background .15s ease;
}

.a11yCounterBtn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, .08);
  background: #fff;
  cursor: pointer;
  font-weight: 900;
  font-size: 16px;
  color: #334155;
  display: grid;
  place-items: center;
  transition: background .12s ease, transform .1s ease, box-shadow .12s ease;
}
.a11yCounterBtn:hover {
  background: #eff6ff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, .12);
}
.a11yCounterBtn:active { transform: scale(.92); }

.a11yValue {
  flex: 1;
  text-align: center;
  font-weight: 800;
  font-size: 12px;
  color: #475569;
  white-space: nowrap;
}

/* ============================================================
   TOGGLE TILES
   ============================================================ */

.a11yTile {
  min-width: calc(50% - 4px);
  flex: 1;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, .06);
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .04);
  cursor: pointer;
  user-select: none;
  font-weight: 700;
  font-size: 13px;
  color: #334155;
  transition: all .18s ease;
}

.a11yTile:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .08);
  border-color: rgba(59, 130, 246, .15);
}

.a11yTile:active { transform: translateY(0) scale(.97); }

.a11yTile[aria-pressed="true"] {
  background: linear-gradient(135deg, rgba(59, 130, 246, .12), rgba(56, 189, 248, .08));
  border-color: rgba(59, 130, 246, .35);
  color: #1d4ed8;
  box-shadow: 0 4px 16px rgba(37, 99, 235, .12);
}

.a11yTile span:first-child {
  font-size: 18px;
  flex-shrink: 0;
}

/* ============================================================
   RESET BUTTON
   ============================================================ */

#a11yReset {
  width: 100%;
  height: 44px;
  margin-top: 6px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid rgba(239, 68, 68, .15);
  background: rgba(239, 68, 68, .06);
  color: #dc2626;
  cursor: pointer;
  font-weight: 800;
  font-size: 13px;
  transition: background .15s ease, transform .1s ease;
}
#a11yReset:hover { background: rgba(239, 68, 68, .12); }
#a11yReset:active { transform: scale(.97); }

/* ============================================================
   READING GUIDE
   ============================================================ */

#a11yReadGuide {
  position: fixed;
  left: 0;
  right: 0;
  height: 8px;
  z-index: 99997;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(59,130,246,.35) 20%, rgba(56,189,248,.45) 50%, rgba(59,130,246,.35) 80%, transparent);
  border-radius: 999px;
  box-shadow: 0 0 20px rgba(59,130,246,.3);
  display: none;
  transition: top .05s linear;
}

/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 640px) {
  #a11yFab {
    top: 12px;
    right: 12px;
    width: 46px;
    height: 46px;
  }
  #a11yFab svg { width: 20px; height: 20px; }

  #a11yBar {
    top: 66px;
    left: 12px;
    right: 12px;
    width: auto;
    padding: 14px;
    border-radius: 20px;
  }

  .a11yTile {
    min-width: calc(50% - 4px);
    height: 46px;
    font-size: 12px;
  }

  .a11yPill { min-width: 100%; }
}

@media (max-width: 380px) {
  .a11yTile { min-width: 100%; }
}

/* ============================================================
   DARK MODE
   ============================================================ */

html[data-theme="dark"] #a11yFab {
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 50%, #1e3a8a 100%);
  box-shadow:
    0 8px 32px rgba(37, 99, 235, .35),
    0 2px 8px rgba(0, 0, 0, .3),
    inset 0 1px 0 rgba(255, 255, 255, .15);
}

html[data-theme="dark"] #a11yBadge {
  border-color: #0f172a;
}

html[data-theme="dark"] #a11yBackdrop {
  background: rgba(0, 0, 0, .55);
}

html[data-theme="dark"] #a11yBar {
  background: rgba(15, 23, 42, .96);
  border-color: rgba(148, 163, 184, .15);
  box-shadow:
    0 24px 80px rgba(0, 0, 0, .55),
    0 0 0 1px rgba(148, 163, 184, .08) inset;
}

html[data-theme="dark"] #a11yHeader {
  border-bottom-color: rgba(148, 163, 184, .12);
}

html[data-theme="dark"] #a11yTitle { color: #e2e8f0; }
html[data-theme="dark"] #a11yTitle small { color: #94a3b8; }

html[data-theme="dark"] #a11yClose {
  background: rgba(148, 163, 184, .10);
  color: #cbd5e1;
}
html[data-theme="dark"] #a11yClose:hover { background: rgba(148, 163, 184, .18); }

html[data-theme="dark"] .a11yPill {
  background: rgba(148, 163, 184, .06);
  border-color: rgba(148, 163, 184, .12);
}

html[data-theme="dark"] .a11yCounterBtn {
  background: rgba(30, 41, 59, .8);
  border-color: rgba(148, 163, 184, .18);
  color: #e2e8f0;
}
html[data-theme="dark"] .a11yCounterBtn:hover {
  background: rgba(37, 99, 235, .18);
  box-shadow: 0 4px 12px rgba(37, 99, 235, .15);
}

html[data-theme="dark"] .a11yValue { color: #94a3b8; }

html[data-theme="dark"] .a11yTile {
  background: rgba(30, 41, 59, .6);
  border-color: rgba(148, 163, 184, .12);
  color: #cbd5e1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
}
html[data-theme="dark"] .a11yTile:hover {
  border-color: rgba(56, 189, 248, .2);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}

html[data-theme="dark"] .a11yTile[aria-pressed="true"] {
  background: linear-gradient(135deg, rgba(37, 99, 235, .22), rgba(56, 189, 248, .12));
  border-color: rgba(56, 189, 248, .35);
  color: #93c5fd;
  box-shadow: 0 4px 16px rgba(37, 99, 235, .2);
}

html[data-theme="dark"] #a11yReset {
  background: rgba(239, 68, 68, .10);
  border-color: rgba(239, 68, 68, .20);
  color: #fca5a5;
}
html[data-theme="dark"] #a11yReset:hover { background: rgba(239, 68, 68, .18); }

/* Dark mode cursor */
html[data-theme="dark"].a11y__cursor,
html[data-theme="dark"].a11y__cursor * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48'%3E%3Ccircle cx='18' cy='18' r='14' fill='%23fff' fill-opacity='.15'/%3E%3Ccircle cx='18' cy='18' r='8' fill='%23fff'/%3E%3Ccircle cx='18' cy='18' r='4' fill='%23000'/%3E%3C/svg%3E") 18 18, auto !important;
}

html[data-theme="dark"] #a11yReadGuide {
  background: linear-gradient(90deg, transparent, rgba(56,189,248,.35) 20%, rgba(96,165,250,.5) 50%, rgba(56,189,248,.35) 80%, transparent);
  box-shadow: 0 0 24px rgba(56,189,248,.35);
}
