/* ==========================================================================
   Emergency Car Keys — Accessibility widget, skip links, focus states,
   and light/dark/high-contrast theme system.
   Loaded after styles.css so these rules can override site tokens.
   The site is dark-by-default; this file adds a light alternative and
   a high-contrast mode on top of the existing custom-property system.
   ========================================================================== */

/* ---------- Light theme: re-map the existing design tokens ---------- */
:root[data-theme="light"] {
  --bg-0: #ffffff;
  --bg-1: #f5f5f7;
  --bg-2: #ececef;
  --card: #ffffff;
  --card-hover: #f7f7f9;
  --border: rgba(0, 0, 0, 0.09);
  --border-strong: rgba(0, 0, 0, 0.18);
  --text-primary: #1d1d1f;
  --text-secondary: rgba(29, 29, 31, 0.68);
  --text-tertiary: rgba(29, 29, 31, 0.5);
}
/* A handful of surfaces use hardcoded white-on-dark overlays rather than
   the tokens above; override those specifically for light mode. */
:root[data-theme="light"] .site-header { background: rgba(255, 255, 255, 0.78); }
:root[data-theme="light"] .site-nav { background: rgba(0, 0, 0, 0.05); }
:root[data-theme="light"] .site-nav a:hover { background: rgba(0, 0, 0, 0.07); }
:root[data-theme="light"] .btn-outline { background: rgba(0, 0, 0, 0.04); }
:root[data-theme="light"] .btn-ghost { background: rgba(0, 0, 0, 0.05); }
:root[data-theme="light"] .btn-ghost:hover { background: rgba(0, 0, 0, 0.09); }
:root[data-theme="light"] .chip { background: rgba(0, 0, 0, 0.04); }
:root[data-theme="light"] .float-badge { background: rgba(255, 255, 255, 0.88); }

/* Fix: .eyebrow-light uses var(--blue-light) (#29c1ff), the dark-theme cyan accent,
   which the light-theme remap above intentionally leaves untouched since --blue-light
   is also used for several icon/decorative accents that stay legitimate in light mode
   (chip icons, feature icons, step numbers, etc.). As TEXT on the light theme's white
   background, though, it measures 2.06:1 (verified live via axe-core). Override just
   this one text usage to the theme's darker --blue (#0071e3), which clears contrast
   comfortably (4.70:1) without touching the shared token's other, still-correct uses. */
:root[data-theme="light"] .eyebrow-light { color: var(--blue); }

/* Fix: --text-tertiary in the light-theme remap above is rgba(29,29,31,0.5) — measured
   live via axe-core at 3.27:1 against white (#a11y-footer, #year), under the 4.5:1
   minimum. Raise the opacity to 0.65 (5.24:1), keeping it lighter than
   --text-secondary's 0.68 so the two tiers stay visually distinct. */
:root[data-theme="light"] { --text-tertiary: rgba(29, 29, 31, 0.65); }

/* ---------- High-contrast mode (WCAG AA/AAA target): black / white / yellow ---------- */
html.a11y-contrast-high {
  --bg-0: #000000;
  --bg-1: #000000;
  --bg-2: #000000;
  --card: #000000;
  --card-hover: #0d0d0d;
  --border: #ffffff;
  --border-strong: #ffffff;
  --text-primary: #ffffff;
  --text-secondary: #f2f2f2;
  --text-tertiary: #e0e0e0;
  --blue: #66b3ff;
  --blue-light: #7fe6ff;
  --shadow-soft: none;
  --shadow-lift: none;
}
html.a11y-contrast-high * { text-shadow: none !important; box-shadow: none !important; }
html.a11y-contrast-high body { background: #000 !important; }
html.a11y-contrast-high a { color: #ffd400 !important; text-decoration: underline !important; }
html.a11y-contrast-high .btn, html.a11y-contrast-high .btn-outline, html.a11y-contrast-high .btn-ghost {
  border: 2px solid #fff !important;
}
html.a11y-contrast-high .card, html.a11y-contrast-high .feature-card,
html.a11y-contrast-high .why-card, html.a11y-contrast-high .faq-item,
html.a11y-contrast-high .choice-card {
  border: 2px solid #fff !important;
}

/* Fix: the blanket "html.a11y-contrast-high a { color: #ffd400 !important; }" rule
   above (specificity 0,1,2) beats .a11y-skip-link's own "color: #fff !important"
   (specificity 0,1,0) — both are !important, so the higher-specificity selector wins
   regardless of source order. Result: in high-contrast mode the skip link renders as
   yellow (#ffd400) text on its #0071e3 blue background, measuring 3.28:1 — under the
   4.5:1 minimum for its 14px/700 text (too small to qualify as "large text"). Axe-core
   never flags this because the skip link is only visible on keyboard focus and axe's
   automated scan doesn't exercise focus-only elements. Re-assert white at higher
   specificity to restore the link's own contrast-safe design (4.70:1 verified live). */
html.a11y-contrast-high .a11y-skip-link { color: #fff !important; }

/* ---------- Baseline WCAG fixes (always on, not gated by the menu) ---------- */
.about-copy p a, .choice-card p a, .feature-card p a, .faq-item p a {
  text-decoration: underline;
  text-underline-offset: 2px;
}
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible, summary:focus-visible {
  outline: 3px solid #29c1ff;
  outline-offset: 2px;
  border-radius: 4px;
}
:root[data-theme="light"] a:focus-visible, :root[data-theme="light"] button:focus-visible,
:root[data-theme="light"] summary:focus-visible {
  outline-color: #0071e3;
}

/* ---------- Skip links ---------- */
#a11y-skip-links { position: relative; z-index: 10000; }
.a11y-skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  background: #0071e3;
  color: #fff !important;
  padding: 12px 18px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none !important;
  transition: top 0.15s ease;
  z-index: 10000;
}
.a11y-skip-link:nth-of-type(2) { left: 220px; }
.a11y-skip-link:nth-of-type(3) { left: 420px; }
.a11y-skip-link:focus { top: 12px; outline: 3px solid #fff; outline-offset: 2px; }

/* ---------- Quick theme toggle ---------- */
.a11y-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.2s ease;
  flex-shrink: 0;
}
:root[data-theme="light"] .a11y-theme-toggle { background: rgba(0, 0, 0, 0.05); }
.a11y-theme-toggle:hover { background: rgba(255, 255, 255, 0.16); }
:root[data-theme="light"] .a11y-theme-toggle:hover { background: rgba(0, 0, 0, 0.1); }
.a11y-theme-toggle-standalone { position: absolute; top: 14px; right: 24px; z-index: 50; }

/* ---------- Floating accessibility launcher ---------- */
.a11y-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #0071e3 0%, #29c1ff 100%);
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 113, 227, 0.45);
  cursor: pointer;
}
.a11y-launcher:hover { transform: translateY(-2px); }
.a11y-launcher-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 640px) {
  .a11y-launcher { left: 50%; right: auto; transform: translateX(-50%); bottom: 18px; }
  .a11y-launcher:hover { transform: translateX(-50%) translateY(-2px); }
}

/* ---------- Overlay + dialog panel ---------- */
.a11y-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 9999; }
.a11y-dialog {
  position: fixed;
  right: 24px;
  bottom: 92px;
  z-index: 10000;
  width: min(380px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 120px));
  overflow-y: auto;
  background: var(--card);
  color: var(--text-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  border: 1px solid var(--border);
}
@media (max-width: 640px) {
  .a11y-dialog { left: 16px; right: 16px; bottom: 84px; width: auto; }
}
.a11y-dialog-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--card);
}
.a11y-dialog-header h2 { font-size: 17px; margin: 0; color: var(--text-primary); }
.a11y-close {
  border: none; background: rgba(255, 255, 255, 0.08); color: var(--text-primary);
  width: 32px; height: 32px; border-radius: 999px; font-size: 20px; line-height: 1; cursor: pointer;
}
.a11y-dialog-body { padding: 18px 20px 24px; }
.a11y-group { margin-bottom: 22px; }
.a11y-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-tertiary); margin: 0 0 10px; }
.a11y-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.a11y-btn {
  border: 1px solid var(--border-strong); background: rgba(255, 255, 255, 0.05); color: var(--text-primary);
  border-radius: 8px; padding: 8px 12px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.a11y-btn:hover { border-color: var(--blue-light); }
.a11y-btn-text { font-weight: 500; }
.a11y-btn-reset { width: 100%; justify-content: center; display: flex; }
.a11y-value { min-width: 52px; text-align: center; font-weight: 700; }
.a11y-radio, .a11y-checkbox {
  display: flex; align-items: center; gap: 8px; font-size: 14px;
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); cursor: pointer;
}
.a11y-checkbox { margin-bottom: 8px; }
.a11y-note { font-size: 12px; color: var(--text-tertiary); margin: 6px 0 0; }
.a11y-disclaimer { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 4px; }
.a11y-disclaimer a { color: var(--blue-light); text-decoration: underline; }
.a11y-actions { margin-top: 4px; }

/* ---------- Text size / line spacing tokens ---------- */
html.a11y-text-110 body { font-size: 1.1em; }
html.a11y-text-125 body { font-size: 1.25em; }
html.a11y-text-150 body { font-size: 1.5em; }
html.a11y-text-175 body { font-size: 1.75em; }
html.a11y-text-200 body { font-size: 2em; }
html.a11y-line-plus20 body { line-height: 1.85; }
html.a11y-line-plus40 body { line-height: 2.15; }

/* ---------- Highlight links ---------- */
html.a11y-highlight-links a:not(.btn):not(.btn-outline):not(.btn-ghost) {
  background: rgba(255, 214, 0, 0.28);
  padding: 0 2px;
  border-radius: 3px;
}

/* ---------- Dyslexia-friendly font ---------- */
html.a11y-dyslexia-font body, html.a11y-dyslexia-font input, html.a11y-dyslexia-font select, html.a11y-dyslexia-font textarea {
  font-family: 'Atkinson Hyperlegible', -apple-system, system-ui, sans-serif !important;
}

/* ---------- Reading guide ---------- */
#a11y-reading-guide-bar {
  position: fixed; left: 0; right: 0; height: 44px;
  background: rgba(255, 214, 0, 0.2);
  border-top: 2px solid rgba(255, 180, 0, 0.85);
  border-bottom: 2px solid rgba(255, 180, 0, 0.85);
  pointer-events: none;
  z-index: 9997;
}

/* ---------- Big cursor ---------- */
html.a11y-big-cursor, html.a11y-big-cursor * {
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24"><path d="M4 2l14 8-6 2 4 7-3 1.6-4-7-4.5 4.4z" fill="white" stroke="black" stroke-width="1.2"/></svg>') 4 4, auto !important;
}

/* ---------- Enhanced always-visible focus ring ---------- */
html.a11y-focus-ring a:focus, html.a11y-focus-ring button:focus,
html.a11y-focus-ring input:focus, html.a11y-focus-ring select:focus,
html.a11y-focus-ring textarea:focus, html.a11y-focus-ring [tabindex]:focus,
html.a11y-focus-ring summary:focus {
  outline: 4px solid #ffd400 !important;
  outline-offset: 3px !important;
}

/* ---------- Reduce motion ---------- */
html.a11y-reduce-motion *, html.a11y-reduce-motion *::before, html.a11y-reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}
html.a11y-reduce-motion .reveal { opacity: 1 !important; transform: none !important; }
