/* RelayWriters accessibility upgrade.
   Loaded site-wide via base.html + portal index.html. Pairs with a11y.js. */

/* ─── Skip-to-main-content link ───────────────────────────────────────── */
.a11y-skip {
  position: absolute;
  top: -48px;
  left: 0;
  padding: 10px 14px;
  background: var(--accent, #d4a84c);
  color: #0a0a0d;
  text-decoration: none;
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  z-index: 10000;
  transition: top 180ms ease;
  border: 0;
}
.a11y-skip:focus { top: 0; }

/* ─── Visible focus indicators (keyboard nav only) ────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent, #d4a84c);
  outline-offset: 3px;
  border-radius: 2px;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--accent, #d4a84c);
  outline-offset: 3px;
}

/* ─── Site-wide reduced-motion respect ────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ─── Text-size body classes (set by toolbar) ─────────────────────────── */
body.a11y-size-lg { font-size: 19px; }
body.a11y-size-xl { font-size: 22px; }
body.a11y-size-lg .prose,
body.a11y-size-lg article p { font-size: 1.18em; }
body.a11y-size-xl .prose,
body.a11y-size-xl article p { font-size: 1.32em; }

/* ─── Light theme (inverse of the dark editorial palette) ─────────────── */
body.a11y-light {
  --bg: #f5efe6;
  --bg-2: #efe7d8;
  --bg-3: #e6dccb;
  --fg: #1a1a1d;
  --fg-dim: #5a5a60;
  --accent: #9a4a1f;
  --accent-2: #c8472a;
  --hairline: rgba(26, 26, 29, 0.12);
}
body.a11y-light { background: var(--bg) !important; color: var(--fg); }

/* ─── High-contrast mode (WCAG AAA targets) ───────────────────────────── */
body.a11y-contrast {
  --fg: #ffffff;
  --fg-dim: #e0e0e0;
  --bg: #000000;
  --bg-2: #0d0d0d;
  --bg-3: #1a1a1a;
  --accent: #ffd700;
  --hairline: rgba(255, 255, 255, 0.5);
}
body.a11y-contrast.a11y-light {
  --fg: #000000;
  --fg-dim: #2a2a2a;
  --bg: #ffffff;
  --bg-2: #f5f5f5;
  --bg-3: #e8e8e8;
  --accent: #6a2b07;
  --hairline: rgba(0, 0, 0, 0.5);
}
body.a11y-contrast { background: var(--bg) !important; color: var(--fg) !important; }
body.a11y-contrast a { text-decoration: underline; }

/* ─── OpenDyslexic font (loaded from CDN, applied via class) ───────────── */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Regular.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
body.a11y-dyslexic,
body.a11y-dyslexic *:not(code):not(pre) {
  font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif !important;
  letter-spacing: 0.02em !important;
  word-spacing: 0.05em !important;
}

/* ─── Toolbar UI ───────────────────────────────────────────────────────── */
.a11y-toolbar {
  position: fixed;
  bottom: 88px;
  right: 22px;
  z-index: 9999;
  font-family: 'DM Mono', ui-monospace, monospace;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  align-items: flex-end;
}
.a11y-trigger {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(232, 227, 214, 0.25);
  background: rgba(15, 15, 20, 0.85);
  color: var(--accent, #d4a84c);
  font-size: 18px;
  font-weight: 700;
  font-family: serif;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 180ms ease;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.a11y-trigger:hover { background: rgba(15, 15, 20, 0.95); transform: scale(1.04); }
.a11y-trigger:focus-visible { outline-offset: 4px; }
.a11y-panel {
  display: none;
  background: rgba(15, 15, 20, 0.96);
  border: 1px solid rgba(232, 227, 214, 0.18);
  border-radius: 10px;
  padding: 12px;
  flex-direction: column;
  gap: 6px;
  min-width: 240px;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  color: rgba(232, 227, 214, 0.92);
}
.a11y-toolbar.is-open .a11y-panel { display: flex; }
.a11y-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
}
.a11y-row-label {
  flex: 1;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(232, 227, 214, 0.55);
}
.a11y-toolbar button:not(.a11y-trigger):not(.a11y-reset) {
  background: transparent;
  border: 1px solid rgba(232, 227, 214, 0.22);
  color: rgba(232, 227, 214, 0.92);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  min-width: 32px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 150ms ease;
}
.a11y-toolbar button:not(.a11y-trigger):not(.a11y-reset):hover {
  background: rgba(232, 227, 214, 0.06);
}
.a11y-toolbar button.is-active {
  background: rgba(212, 168, 76, 0.18);
  border-color: rgba(212, 168, 76, 0.65);
  color: #f0e0b0;
}
.a11y-reset {
  margin-top: 4px;
  background: transparent;
  border: 0;
  color: rgba(232, 227, 214, 0.4);
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: center;
  padding: 6px;
}
.a11y-reset:hover { color: rgba(232, 227, 214, 0.7); }

/* Hide toolbar in print */
@media print { .a11y-toolbar, .a11y-skip { display: none !important; } }


/* ─── Light-theme readability — force --fg on common text elements ───── */
body.a11y-light h1, body.a11y-light h2, body.a11y-light h3,
body.a11y-light h4, body.a11y-light h5, body.a11y-light h6,
body.a11y-light p, body.a11y-light span, body.a11y-light li,
body.a11y-light blockquote, body.a11y-light figcaption,
body.a11y-light .prose, body.a11y-light .prose *,
body.a11y-light article, body.a11y-light article *,
body.a11y-light label, body.a11y-light input, body.a11y-light textarea {
  color: var(--fg) !important;
}
body.a11y-light a { color: var(--accent) !important; }
body.a11y-light em { color: var(--accent-2, var(--accent)) !important; }
/* preserve sigil/SVG accent colour */
body.a11y-light .sigil, body.a11y-light .sigil * { color: var(--accent) !important; }
/* a11y panel itself stays dark — better contrast on the floating control */
body.a11y-light .a11y-panel, body.a11y-light .a11y-panel * { color: rgba(232,227,214,0.92) !important; }
body.a11y-light .a11y-trigger { color: var(--accent) !important; }

/* ─── Light mode: aggressive override (var(--fg) wasn't enough because       */
/* theme rooms re-override --fg per scope). Hard-code dark text everywhere   */
/* except sigils, SVGs, the a11y panel itself, and rooms with image bgs.    */
body.a11y-light,
body.a11y-light h1, body.a11y-light h2, body.a11y-light h3,
body.a11y-light h4, body.a11y-light h5, body.a11y-light h6,
body.a11y-light p, body.a11y-light span, body.a11y-light li,
body.a11y-light blockquote, body.a11y-light figcaption,
body.a11y-light label, body.a11y-light strong, body.a11y-light dt,
body.a11y-light dd, body.a11y-light td, body.a11y-light th,
body.a11y-light caption, body.a11y-light small,
body.a11y-light .prose, body.a11y-light .prose *,
body.a11y-light article, body.a11y-light article *,
body.a11y-light .wordmark, body.a11y-light .wordmark *,
body.a11y-light .room, body.a11y-light .lbl, body.a11y-light .room-accent,
body.a11y-light .open-line, body.a11y-light .open-line *,
body.a11y-light .open-meta, body.a11y-light .open-meta *,
body.a11y-light .tagline, body.a11y-light .tagline *,
body.a11y-light .deck, body.a11y-light .lede,
body.a11y-light nav, body.a11y-light nav *,
body.a11y-light .foot-slim, body.a11y-light .foot-slim *,
body.a11y-light footer, body.a11y-light footer * {
  color: #1a1a1d !important;
}
body.a11y-light a { color: #9a4a1f !important; }
body.a11y-light a:hover { color: #c8472a !important; }
body.a11y-light em, body.a11y-light .accent, body.a11y-light .sep { color: #9a4a1f !important; }
body.a11y-light input, body.a11y-light textarea, body.a11y-light select {
  background: #ffffff !important;
  color: #1a1a1d !important;
  border-color: rgba(26,26,29,0.25) !important;
}
  color: #1a1a1d !important;
  border-color: rgba(26,26,29,0.25) !important;
}
/* Don't tint the sigil — keep accent ink */
body.a11y-light .sigil, body.a11y-light .sigil *,
body.a11y-light .f-sigil, body.a11y-light .f-sigil * { color: #9a4a1f !important; }
/* a11y panel (floating) keeps its own dark contrast — overrides above lock it */
body.a11y-light .a11y-toolbar, body.a11y-light .a11y-toolbar * {
  color: rgba(232,227,214,0.92) !important;
}
body.a11y-light .a11y-trigger { color: #d4a84c !important; }

/* ─── Light mode buttons: force readable contrast regardless of theme bg ─ */
body.a11y-light button:not(.a11y-trigger):not(.a11y-toolbar button),
body.a11y-light .btn,
body.a11y-light .cta,
body.a11y-light input[type="submit"],
body.a11y-light input[type="button"] {
  background: #ffffff !important;
  background-color: #ffffff !important;
  color: #1a1a1d !important;
  border: 1px solid #1a1a1d !important;
}
body.a11y-light button:not(.a11y-trigger):not(.a11y-toolbar button):hover,
body.a11y-light .btn:hover,
body.a11y-light .cta:hover {
  background: #9a4a1f !important;
  background-color: #9a4a1f !important;
  color: #ffffff !important;
  border-color: #9a4a1f !important;
}
body.a11y-light a.btn, body.a11y-light a.cta,
body.a11y-light a[class*="-btn"], body.a11y-light a[class*="-cta"] {
  background: #ffffff !important;
  color: #1a1a1d !important;
  border: 1px solid #1a1a1d !important;
  text-decoration: none !important;
}

/* ─── Accent swatches ─── */
.a11y-row-accents { flex-wrap: wrap; }
.a11y-swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.a11y-swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(232, 227, 214, 0.25) !important;
  padding: 0 !important;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
}
.a11y-swatch:hover { transform: scale(1.12); border-color: rgba(232,227,214,0.6) !important; }
.a11y-swatch.is-active {
  border: 2px solid #fff !important;
  box-shadow: 0 0 0 2px rgba(232, 227, 214, 0.4);
}

/* ─── Accent colour classes — set at body scope so per-theme [data-theme]
   selectors on the portal can still override them via CSS source order ─── */
body.a11y-accent-gold   { --accent: #d4a84c; --accent-2: #e6c070; --accent-rgb: 212, 168, 76;  }
body.a11y-accent-ember  { --accent: #c8472a; --accent-2: #e0633f; --accent-rgb: 200, 71, 42;   }
body.a11y-accent-rose   { --accent: #c47585; --accent-2: #d99baa; --accent-rgb: 196, 117, 133; }
body.a11y-accent-sage   { --accent: #7a9a6e; --accent-2: #95b08a; --accent-rgb: 122, 154, 110; }
body.a11y-accent-teal   { --accent: #4a8a92; --accent-2: #6da6af; --accent-rgb: 74, 138, 146;  }
body.a11y-accent-cobalt { --accent: #4866a0; --accent-2: #6884b8; --accent-rgb: 72, 102, 160;  }
body.a11y-accent-plum   { --accent: #8a4d8a; --accent-2: #a76aa7; --accent-rgb: 138, 77, 138;  }
body.a11y-accent-steel  { --accent: #6c7c92; --accent-2: #8898ad; --accent-rgb: 108, 124, 146; }
