/*
 * Accessibility toolbar — styles.
 * Settings are applied as data attributes on <html> by a11y-toolbar.js.
 * Page overrides skip the toolbar itself via :not(.a11y-tb, .a11y-tb *).
 * Text size is applied by the script (inline sizes), not here.
 * Sizes are in px, not rem: the public site sets html to 10px, the course leaves it at 16px.
 * The button sits bottom-left because the back-to-top button is bottom-right.
 */

/* Text size: no animation while sizes are measured and set. */
html[data-a11y-sizing] * { transition: none !important; }

/* ---------- Page overrides ---------- */

/* Readable font */
html[data-a11y-font="on"] body :not(.a11y-tb, .a11y-tb *) {
  font-family: "Atkinson Hyperlegible", Verdana, Arial, sans-serif !important;
}

/* Text spacing (WCAG 1.4.12 values) */
html[data-a11y-spacing="on"] body :not(.a11y-tb, .a11y-tb *) {
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
}

/* Line spacing */
html[data-a11y-line="on"] body :not(.a11y-tb, .a11y-tb *) {
  line-height: 2 !important;
}

/* Dark mode */
html[data-a11y-contrast="dark"] body,
html[data-a11y-contrast="dark"] body :not(.a11y-tb, .a11y-tb *) {
  background-color: #121212 !important;
  color: #f1f1f1 !important;
  border-color: #5a5a5a !important;
}
html[data-a11y-contrast="dark"] body a:not(.a11y-tb *) {
  color: #9cc3ff !important;
}
html[data-a11y-contrast="dark"] body :is(button, input, select, textarea):not(.a11y-tb *) {
  background-color: #1f1f1f !important;
  border: 2px solid #9a9a9a !important;
}

/* High contrast */
html[data-a11y-contrast="high"] body,
html[data-a11y-contrast="high"] body :not(.a11y-tb, .a11y-tb *) {
  background-color: #000 !important;
  color: #fff !important;
  border-color: #fff !important;
}
html[data-a11y-contrast="high"] body a:not(.a11y-tb *) {
  color: #ffeb3b !important;
  text-decoration: underline !important;
}
html[data-a11y-contrast="high"] body :is(button, input, select, textarea):not(.a11y-tb *) {
  border: 2px solid #fff !important;
}
html[data-a11y-contrast="high"] body :focus-visible:not(.a11y-tb *) {
  outline: 3px solid #ffeb3b !important;
  outline-offset: 2px !important;
}

/* Highlight links and buttons */
html[data-a11y-links="on"] body :is(a[href], button, input[type="submit"], input[type="image"]):not(.a11y-tb *) {
  outline: 3px dashed #1a4fbf !important;
  outline-offset: 2px !important;
  text-decoration: underline !important;
}
html[data-a11y-links="on"][data-a11y-contrast="high"] body :is(a[href], button, input[type="submit"], input[type="image"]):not(.a11y-tb *) {
  outline-color: #ffeb3b !important;
}

/* Big cursor */
html[data-a11y-cursor="on"],
html[data-a11y-cursor="on"] * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'%3E%3Cpath d='M4 2l15 11.5-6.6.9 3.9 7.4-2.9 1.5-3.9-7.5L4 20.5z' fill='%23000' stroke='%23fff' stroke-width='1.4' stroke-linejoin='round'/%3E%3C/svg%3E") 4 2, auto !important;
}

/* Reading guide bar */
.a11y-guide {
  position: fixed;
  left: 0;
  right: 0;
  height: 44px;
  background: rgba(255, 221, 0, 0.18);
  border-top: 3px solid #1a4fbf;
  border-bottom: 3px solid #1a4fbf;
  pointer-events: none;
  z-index: 2147483000;
  display: none;
}
html[data-a11y-guide="on"] .a11y-guide {
  display: block;
}

/* Block currently being read aloud.
   Selector weight matches the contrast overrides above so the highlight still wins in dark/high mode. */
html body .a11y-reading:not(.a11y-tb, .a11y-tb *) {
  background-color: #fff3a0 !important;
  color: #000 !important;
  outline: 3px solid #1a4fbf !important;
  outline-offset: 2px;
  border-radius: 2px;
}
html body .a11y-reading:not(.a11y-tb, .a11y-tb *) * {
  background-color: transparent !important;
  color: #000 !important;
}

/* ---------- Toolbar UI ---------- */

.a11y-tb {
  --tb-blue: #1a4fbf;
  --tb-blue-dark: #123a8f;
  --tb-text: #1c1c1c;
  --tb-muted: #555;
  --tb-bg: #fff;
  --tb-tile: #f2f5fb;
  --tb-line: #c9d3e6;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  letter-spacing: normal;
  word-spacing: normal;
  color: var(--tb-text);
}

.a11y-tb *,
.a11y-tb *::before,
.a11y-tb *::after {
  box-sizing: border-box;
}

.a11y-tb button,
.a11y-tb select {
  font: inherit;
  color: inherit;
}

.a11y-tb :focus-visible {
  outline: 3px solid #ff9f1a;
  outline-offset: 2px;
}

.a11y-tb .a11y-tb__launcher {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--tb-blue);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 2147483001;
}
.a11y-tb .a11y-tb__launcher:hover {
  background: var(--tb-blue-dark);
}
.a11y-tb__launcher svg {
  width: 32px;
  height: 32px;
}

.a11y-tb__panel {
  position: fixed;
  left: 16px;
  bottom: calc(16px + 68px);
  width: min(368px, calc(100vw - 32px));
  max-height: calc(100vh - 16px - 84px);
  overflow-y: auto;
  background: var(--tb-bg);
  border: 1px solid var(--tb-line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  z-index: 2147483001;
}
.a11y-tb__panel[hidden] {
  display: none;
}

.a11y-tb__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: var(--tb-blue);
  color: #fff;
  border-radius: 11px 11px 0 0;
  position: sticky;
  top: 0;
}
/* Site headings and paragraphs set their own fonts; keep the toolbar's. */
.a11y-tb h2, .a11y-tb h3, .a11y-tb p {
  font-family: inherit !important;
  line-height: 1.4 !important;
}
.a11y-tb__title {
  margin: 0;
  color: #fff !important;
  font-family: inherit !important;
  font-size: 16.8px !important;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: normal;
  text-transform: none;
}
.a11y-tb__close {
  background: transparent;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 6px;
  color: #fff !important;
  padding: 3.2px 9.6px;
  cursor: pointer;
}

.a11y-tb__body {
  padding: 16px;
  display: grid;
  gap: 16px;
}

.a11y-tb__section-title {
  margin: 0 0 8px;
  font-size: 12.8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tb-muted);
}

.a11y-tb__row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.a11y-tb__btn {
  background: var(--tb-tile);
  border: 2px solid var(--tb-line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  min-height: 44px;
}
.a11y-tb__btn:hover {
  border-color: var(--tb-blue);
}
.a11y-tb__btn--primary {
  background: var(--tb-blue);
  border-color: var(--tb-blue);
  color: #fff !important;
  font-weight: 700;
}
.a11y-tb__btn--primary:hover {
  background: var(--tb-blue-dark);
}
.a11y-tb__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.a11y-tb__size-value {
  min-width: 56px;
  text-align: center;
  font-weight: 700;
}

.a11y-tb__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.a11y-tb__tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5.6px;
  min-height: 80px;
  padding: 9.6px 6.4px;
  background: var(--tb-tile);
  border: 2px solid var(--tb-line);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  font-size: 14.4px;
}
.a11y-tb__tile:hover {
  border-color: var(--tb-blue);
}
.a11y-tb__tile svg {
  width: 25.6px;
  height: 25.6px;
}
.a11y-tb__tile[aria-pressed="true"],
.a11y-tb__tile[data-active="true"] {
  background: var(--tb-blue);
  border-color: var(--tb-blue);
  color: #fff !important;
}
.a11y-tb__tile-state {
  font-size: 12px;
  font-weight: 700;
}

.a11y-tb__select {
  min-height: 44px;
  border: 2px solid var(--tb-line);
  border-radius: 8px;
  padding: 6.4px;
  background: #fff;
}

.a11y-tb__note {
  margin: 6.4px 0 0;
  font-size: 12.8px;
  color: var(--tb-muted);
}

.a11y-tb__foot {
  padding: 0 16px 16px;
}
.a11y-tb__foot .a11y-tb__btn {
  width: 100%;
}
.a11y-tb__help {
  display: block;
  margin-top: 12px;
  text-align: center;
  color: var(--tb-blue) !important;
  font-weight: 400;
  text-decoration: underline;
}

.a11y-tb__sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .a11y-tb__panel {
    animation: a11y-tb-in 0.15s ease-out;
  }
  @keyframes a11y-tb-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }
}
