/* gloop.live accessibility layer (a11y pass). Loaded after every other
   stylesheet; pairs with js/a11y.js. Default look is unchanged: everything
   here is focus rings, screen-reader helpers, reduced motion, or opt-in
   modes switched on from the Accessibility panel (html[data-a11y-*] / .a11y-*). */

/* ---------- screen-reader-only helper ---------- */
.a11y-sr {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

/* ---------- 2. focus: one high-contrast ring for every interactive element ---------- */
:is(a[href], button, input, select, textarea, summary, [tabindex]:not([tabindex="-1"]), [role="button"]):focus-visible {
  outline: 3px solid var(--a11y-focus, #ffffff) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 6px rgba(0, 0, 0, 0.85) !important;
}
/* programmatically focused containers (tabindex=-1, e.g. the help panel whose
   gloop.css rule removes the outline) still get a ring when keyboard-focused */
[tabindex="-1"]:focus-visible {
  outline: 2px dashed var(--a11y-focus, #ffffff) !important;
  outline-offset: -4px !important;
}
.dock { scroll-padding-inline: 1rem; }

/* ---------- 4. reduced motion (system setting unless overridden in the panel) ---------- */
@media (prefers-reduced-motion: reduce) {
  html:not(.a11y-rm-off) *, html:not(.a11y-rm-off) *::before, html:not(.a11y-rm-off) *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
}
html.a11y-rm-on *, html.a11y-rm-on *::before, html.a11y-rm-on *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  animation-delay: 0s !important;
  transition-duration: 0.01ms !important;
  transition-delay: 0s !important;
  scroll-behavior: auto !important;
}

/* photosensitivity: no full-screen flashes (world.js also damps the in-scene flash) */
html.a11y-noflash .bolt-flash { opacity: 0 !important; display: none !important; }
html.a11y-noflash .evolve-flash { display: none !important; }

/* ---------- settings button + panel ---------- */
.a11y-open {
  position: absolute;
  top: 0.7rem;
  left: 0.8rem;
  z-index: 3;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--ink, #ece6da);
  background: var(--glass, rgba(12, 16, 22, 0.62));
  border: 1px solid var(--line, rgba(236, 230, 218, 0.1));
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  cursor: pointer;
  opacity: 0.85;
}
.a11y-open svg { width: 1rem; height: 1rem; display: block; }
.a11y-open:hover, .a11y-open[aria-expanded="true"] { opacity: 1; border-color: rgba(255, 255, 255, 0.6); }
html.no-webgl .a11y-open { top: auto; bottom: 0.7rem; }
@media (max-width: 900px) and (pointer: coarse), (max-width: 560px) {
  .a11y-open { width: 44px; height: 44px; }
  .a11y-open svg { width: 1.3rem; height: 1.3rem; }
}

.a11y-panel {
  position: fixed;
  top: 3.6rem;
  left: 0.8rem;
  z-index: 45;
  width: min(340px, calc(100vw - 1.6rem));
  max-height: calc(100vh - 4.6rem);
  overflow: auto;
  padding: 0.9rem 1rem 1rem;
  border-radius: 12px;
  background: #0c1016;
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  color: #f2efe8;
  font-family: var(--font, system-ui, sans-serif);
  font-size: 0.9rem;
  line-height: 1.45;
}
.a11y-panel[hidden] { display: none; }
.a11y-panel header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.4rem; }
.a11y-panel h2 { margin: 0; font-size: 1rem; font-weight: 600; color: #ffffff; }
.a11y-panel fieldset { margin: 0.6rem 0 0; padding: 0.5rem 0.7rem 0.6rem; border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 8px; }
.a11y-panel legend { padding: 0 0.3rem; font-weight: 600; color: #ffffff; }
.a11y-row { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; margin: 0.35rem 0; }
.a11y-row.is-check { justify-content: flex-start; }
.a11y-panel select, .a11y-panel button {
  font: inherit;
  font-size: 0.85rem;
  color: #ffffff;
  background: #1b222c;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 6px;
  padding: 0.25rem 0.45rem;
}
.a11y-panel button { cursor: pointer; }
.a11y-panel button:hover { background: #26303c; }
.a11y-panel input[type="checkbox"] { flex: none; width: 1.05rem; height: 1.05rem; margin: 0; accent-color: #b9f5b4; }
.a11y-note { margin: 0.2rem 0 0; font-size: 0.78rem; color: #c9ced6; }
.a11y-foot { display: flex; justify-content: flex-end; margin-top: 0.8rem; }

/* ---------- captions / subtitles ---------- */
.a11y-captions {
  position: absolute;
  top: 3rem; /* below the toast / corner buttons row */
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  width: max-content;
  max-width: min(640px, calc(100% - 9rem));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  pointer-events: none;
  text-align: center;
}
html:not(.a11y-cap-on) .a11y-captions {
  /* captions off: still announced to screen readers, just not drawn */
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; transform: none;
}
.a11y-captions p {
  margin: 0;
  padding: 0.25em 0.7em 0.3em;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.8);
  color: #ffffff;
  font-family: var(--font, system-ui, sans-serif);
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 2px #000;
}
.a11y-captions p.is-cue { color: #ffe27a; font-style: normal; }
.a11y-captions p.is-alert { color: #ffffff; border-left: 4px solid #ffb000; }
html.a11y-cap-s .a11y-captions p { font-size: 0.85rem; }
html.a11y-cap-l .a11y-captions p { font-size: 1.4rem; }
@media (max-width: 600px) {
  .a11y-captions { max-width: calc(100% - 7.5rem); }
}

/* ---------- text cues for colour-coded state ---------- */
.a11y-val { font-style: normal; font-size: 0.95em; color: var(--ink, #ece6da); min-width: 2.2em; }
html:not(.a11y-cues) .a11y-val { display: none; }
.a11y-feel { margin-left: 0.35rem; }
html.a11y-cues .a11y-feel {
  position: static !important; width: auto; height: auto; margin: 0 0 0 0.4rem; overflow: visible;
  clip: auto; clip-path: none; white-space: nowrap;
  padding: 0.05rem 0.4rem; border-radius: 999px; border: 1px solid currentColor;
  font-size: 0.9em; letter-spacing: 0.08em; color: var(--ink, #ece6da);
}
html.a11y-cues .a11y-feel[data-feel="hurt"] { border-style: dashed; }
html.a11y-cues .a11y-feel[data-feel="afraid"] { border-width: 2px; }
@media (max-width: 600px) { html.a11y-cues .a11y-feel { font-size: 0.8em; padding: 0 0.3rem; margin-left: 0.25rem; } }

/* ---------- A. colour-blind modes (canvas via SVG colour matrix, HUD via vars) ---------- */
html[data-a11y-cb="deuteranopia"] #body { filter: url(#a11y-cb-deuteranopia); }
html[data-a11y-cb="protanopia"] #body { filter: url(#a11y-cb-protanopia); }
html[data-a11y-cb="tritanopia"] #body { filter: url(#a11y-cb-tritanopia); }
html[data-a11y-cb="high-contrast"] #body { filter: contrast(1.35) saturate(1.3) brightness(1.08); }
/* Okabe-Ito palette: distinguishable for protan / deutan / tritan viewers */
html[data-a11y-cb="deuteranopia"], html[data-a11y-cb="protanopia"], html[data-a11y-cb="tritanopia"] {
  --glow: #56b4e9;
  --hot: #e69f00;
  --a11y-focus: #ffffff;
}
html:is([data-a11y-cb="deuteranopia"], [data-a11y-cb="protanopia"], [data-a11y-cb="tritanopia"]) .needs [data-k="hunger"] i::after { background: #e69f00; color: rgba(230, 159, 0, 0.5); }
html:is([data-a11y-cb="deuteranopia"], [data-a11y-cb="protanopia"], [data-a11y-cb="tritanopia"]) .needs [data-k="warmth"] i::after { background: #56b4e9; color: rgba(86, 180, 233, 0.5); }
html:is([data-a11y-cb="deuteranopia"], [data-a11y-cb="protanopia"], [data-a11y-cb="tritanopia"]) .needs [data-k="hp"] i::after { background: #d55e00; color: rgba(213, 94, 0, 0.5); }
html:is([data-a11y-cb="deuteranopia"], [data-a11y-cb="protanopia"], [data-a11y-cb="tritanopia"]) .needs [data-k="fear"] i::after { background: #cc79a7; color: rgba(204, 121, 167, 0.5); }
html:is([data-a11y-cb="deuteranopia"], [data-a11y-cb="protanopia"], [data-a11y-cb="tritanopia"]) .skills [data-k] i::after { background: #f0e442; color: rgba(240, 228, 66, 0.45); }
html:is([data-a11y-cb="deuteranopia"], [data-a11y-cb="protanopia"], [data-a11y-cb="tritanopia"]) body[data-feel="hurt"] .mark b { color: #ffffff; }
html:is([data-a11y-cb="deuteranopia"], [data-a11y-cb="protanopia"], [data-a11y-cb="tritanopia"]) body[data-feel="afraid"] .mark b { color: #e69f00; }

/* high contrast: opaque black panels, white text and borders */
html[data-a11y-cb="high-contrast"] {
  --ink: #ffffff;
  --mute: #e8e8e8;
  --line: rgba(255, 255, 255, 0.7);
  --glow: #9dff8f;
  --hot: #ffd24a;
  --glass: #000000;
  --glass-hi: #000000;
  --a11y-focus: #ffd24a;
}
html[data-a11y-cb="high-contrast"] body { background: #000; }
html[data-a11y-cb="high-contrast"] :is(.topbar, .dock, .needs, .pack, .thoughts) {
  background: #000 !important;
  -webkit-backdrop-filter: none; backdrop-filter: none;
  border-color: #ffffff;
}
html[data-a11y-cb="high-contrast"] .thoughts p { opacity: 1; color: #ffffff; }
html[data-a11y-cb="high-contrast"] .thoughts p:last-child { color: var(--glow); }
html[data-a11y-cb="high-contrast"] :is(.acts button, .zoom button, .gk-hint, .gk-close, .a11y-open) {
  background: #000 !important; color: #ffffff; border: 2px solid #ffffff; opacity: 1;
}
html[data-a11y-cb="high-contrast"] .acts #act-reset { color: #ffffff; }
html[data-a11y-cb="high-contrast"] .hint { color: #ffffff; }
html[data-a11y-cb="high-contrast"] .needs i { background: #333; box-shadow: inset 0 0 0 1px #fff; }
html[data-a11y-cb="high-contrast"] .needs [data-k="hunger"] i::after { background: #ffd24a; }
html[data-a11y-cb="high-contrast"] .needs [data-k="warmth"] i::after { background: #6cc6ff; }
html[data-a11y-cb="high-contrast"] .needs [data-k="hp"] i::after { background: #ff6b6b; }
html[data-a11y-cb="high-contrast"] .needs [data-k="fear"] i::after { background: #e3a6ff; }
html[data-a11y-cb="high-contrast"] .skills [data-k] i::after { background: #9dff8f; }

/* ---------- C. dyslexia-friendly text: more spacing, no italics, no all-caps ---------- */
html.a11y-dys body { letter-spacing: 0.05em; word-spacing: 0.14em; }
html.a11y-dys :is(.mark, .vitals, .needs, .pack, .speed, .zoom, .acts button, .hint, .thoughts, .gk-panel, .a11y-panel, .a11y-captions, .gk-body h3, .gk-panel h2) {
  text-transform: none !important;
  letter-spacing: 0.05em !important;
  word-spacing: 0.14em;
}
html.a11y-dys .thoughts, html.a11y-dys .a11y-captions p, html.a11y-dys .a11y-panel { line-height: 1.75; }
html.a11y-dys *, html.a11y-dys *::before, html.a11y-dys *::after { font-style: normal !important; }

/* intro title-card lightning (intro.js/intro.css) also honours the panel toggles */
html.a11y-noflash .intro-flash, html.a11y-rm-on .intro-flash { display: none !important; }
html.a11y-rm-on .evolve-flash { animation: none !important; opacity: 0.35; }
