/* =====================================================
   Accessibility — skip link, visible focus, the
   preference toolbar, and user-preference overrides.
   Loaded on every page via BaseLayout + HomeLayout.
   Tokens (--ink, --paper, --clay, --rule, --gold) are
   defined in styles.css and home.css :root.
   ===================================================== */

/* ---------- Skip to main content ---------- */
.skip-link {
  position: fixed;
  top: -120px;
  left: 12px;
  z-index: 2000;
  padding: 12px 18px;
  background: var(--ink, #121A14);
  color: var(--paper, #F5F1E6);
  border-radius: 0 0 6px 6px;
  font-family: var(--sans, sans-serif);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: top .15s ease;
}
.skip-link:focus {
  top: 0;
  outline: 3px solid var(--gold, #A88649);
  outline-offset: 2px;
}

/* ---------- Global visible focus indicator ---------- */
:focus-visible {
  outline: 3px solid var(--clay, #284A38);
  outline-offset: 2px;
  border-radius: 2px;
}
/* Programmatic focus targets (e.g. <main tabindex="-1">) get no ring. */
[tabindex="-1"]:focus { outline: none; }

/* ---------- Conditions nav: keyboard / touch toggle ---------- */
.nav-item.a11y-open > .nav-dropdown {
  opacity: 1 !important;
  visibility: visible !important;
  transform: translateY(0) !important;
}

/* =====================================================
   User-preference overrides (set via data-* on <html>)
   ===================================================== */

/* ---- Text size ---- */
html[data-a11y-font="large"]  { --a11y-scale: 1.15; }
html[data-a11y-font="larger"] { --a11y-scale: 1.30; }
html[data-a11y-font] body { font-size: calc(16px * var(--a11y-scale, 1)); }
html[data-a11y-font] .lede { font-size: calc(21px * var(--a11y-scale, 1)); }
html[data-a11y-font] .prose p,
html[data-a11y-font] .prose li,
html[data-a11y-font] p,
html[data-a11y-font] li { font-size: calc(16px * var(--a11y-scale, 1)); }

/* ---- High contrast ---- */
html[data-a11y-contrast="high"] {
  --cream: #ffffff;
  --paper: #ffffff;
  --bone:  #ffffff;
  --ink:   #000000;
  --ink-2: #1a1a1a;
  --ink-3: #333333;
  --clay:  #0b3d1f;
  --clay-deep: #062914;
  --rule:  rgba(0, 0, 0, 0.55);
}
html[data-a11y-contrast="high"] body { background: #ffffff; color: #000000; }
/* Paper-grain overlay lowers contrast — hide it. */
html[data-a11y-contrast="high"] body::before { display: none !important; }
html[data-a11y-contrast="high"] a { color: #0b3d1f; }
html[data-a11y-contrast="high"] .btn-primary,
html[data-a11y-contrast="high"] .nav-cta { background: #000000; color: #ffffff; }

/* ---- Highlight links ---- */
html[data-a11y-links="on"] a {
  text-decoration: underline !important;
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
}
html[data-a11y-links="on"] a:not(.btn):not(.nav-cta):not(.brand) {
  background: rgba(168, 134, 73, 0.16);
  box-shadow: 0 0 0 2px rgba(168, 134, 73, 0.16);
  border-radius: 2px;
}

/* ---- Readable line spacing (mirrors WCAG 1.4.12 metrics) ---- */
html[data-a11y-spacing="loose"] p,
html[data-a11y-spacing="loose"] li {
  line-height: 2 !important;
  letter-spacing: 0.02em;
  word-spacing: 0.16em;
}
html[data-a11y-spacing="loose"] p { margin-bottom: 1.5em; }

/* ---- Reduce motion (toggle + system preference) ---- */
html[data-a11y-motion="reduce"] *,
html[data-a11y-motion="reduce"] *::before,
html[data-a11y-motion="reduce"] *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
  scroll-behavior: auto !important;
}
html[data-a11y-motion="reduce"] .reveal { opacity: 1 !important; transform: none !important; }

@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1 !important; transform: none !important; }
}

/* =====================================================
   Preference toolbar UI
   ===================================================== */
.a11y-trigger {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 1500;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--paper, #F5F1E6);
  background: var(--clay, #284A38);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 22px -8px rgba(18, 26, 20, 0.5);
  transition: transform .2s, background .2s;
}
.a11y-trigger:hover { background: var(--clay-deep, #143025); transform: translateY(-2px); }
.a11y-trigger svg { width: 26px; height: 26px; display: block; }

.a11y-panel {
  position: fixed;
  left: 18px;
  bottom: 82px;
  z-index: 1500;
  width: 300px;
  max-width: calc(100vw - 36px);
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  background: var(--paper, #F5F1E6);
  color: var(--ink, #121A14);
  border: 1px solid var(--rule, rgba(18, 26, 20, 0.12));
  border-radius: 12px;
  box-shadow: 0 26px 60px -20px rgba(18, 26, 20, 0.45);
  padding: 18px;
  font-family: var(--sans, sans-serif);
  display: none;
}
.a11y-panel[data-open="true"] { display: block; }

.a11y-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.a11y-panel-head h2 {
  font-family: var(--sans, sans-serif);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0;
  color: var(--ink, #121A14);
}
.a11y-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-2, #3D4A41);
  padding: 0 4px;
}
.a11y-close:hover { color: var(--ink, #121A14); }

.a11y-group { margin-bottom: 14px; }
.a11y-label {
  display: block;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-3, #818A80);
  margin-bottom: 8px;
}
.a11y-btnrow { display: flex; gap: 8px; }

.a11y-panel button[data-a11y-action] {
  font-family: var(--sans, sans-serif);
  font-size: 14px;
  border: 1px solid var(--rule, rgba(18, 26, 20, 0.2));
  background: var(--cream, #ECE8DD);
  color: var(--ink, #121A14);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.a11y-btnrow button[data-a11y-action] { flex: 1; }
.a11y-toggle {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
}
.a11y-panel button[data-a11y-action]:hover { border-color: var(--clay, #284A38); }
.a11y-panel button[data-a11y-action][aria-pressed="true"] {
  background: var(--clay, #284A38);
  border-color: var(--clay, #284A38);
  color: #ffffff;
}

.a11y-reset {
  width: 100%;
  margin-top: 4px;
  text-align: center;
}

.a11y-note {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-3, #818A80);
  margin: 14px 0 0;
}
.a11y-note a { color: var(--clay, #284A38); text-decoration: underline; text-underline-offset: 2px; }

/* Toolbar respects reduce-motion the same as the rest of the page. */
html[data-a11y-motion="reduce"] .a11y-trigger { transition: none; }
