/* ============================================================
   ACCESSIBILITY - the controls in the Accessibility dialog and
   the html.a11y-* classes they switch on. Loaded last so these
   rules win. js/services/a11y-settings.js decides the classes.
   ============================================================ */

/* ---- Floating button ---- */
/* Fixed in the bottom-left corner so it's always reachable. */
.a11y-fab {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 90;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: var(--maroon-900);
  color: var(--cream);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-pop);
}

.a11y-fab:hover {
  background: var(--maroon-700);
}

/* ---- Controls inside the dialog ---- */
.a11y-sub {
  margin: 20px 0 8px;
  font-size: 14px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* Small banner shown when the OS itself already requests reduced motion. */
.a11y-os-note {
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: var(--radius-s);
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
}

.a11y-os-note[hidden] {
  display: none;
}

/* Vertical list of switch rows, framed as a single card. */
.a11y-controls {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--surface);
  margin-bottom: 14px;
}

/* Each switch row: label on the left, control on the right.
   Clicking the whole row toggles the checkbox (label wraps input). */
.a11y-switch,
.a11y-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  cursor: pointer;
}

/* Hairline separator between stacked rows (but not before the first). */
.a11y-controls > * + * {
  border-top: 1px solid var(--line);
}

/* Label text stacks title + description on separate lines. */
.a11y-switch span,
.a11y-row > span:first-child {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.a11y-switch small,
.a11y-row small {
  color: var(--ink-soft);
  font-size: 12.5px;
}

/* Switch look for the native checkbox (keeps keyboard + screen reader behaviour) */
/* We restyle the real <input> with appearance:none rather than using a fake
   element, so it stays focusable, togglable with Space, and announced correctly. */
.a11y-switch input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--line);
  border: 1.5px solid var(--ink-soft);
  position: relative;
  cursor: pointer;
  transition: background .2s ease;
}

/* The "thumb" — a pseudo-element circle positioned inside the track. */
.a11y-switch input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform .2s ease;
}

/* Checked state: track turns gold, thumb slides right. */
.a11y-switch input[type="checkbox"]:checked {
  background: var(--gold);
  border-color: var(--gold);
}

.a11y-switch input[type="checkbox"]:checked::after {
  transform: translateX(18px);
  background: var(--maroon-950);
}

/* A− / A+ pair for changing text size. */
.a11y-stepper {
  display: flex;
  gap: 8px;
}

.a11y-stepper button {
  min-width: 44px;
  height: 36px;
  border-radius: var(--radius-s);
  border: 1.5px solid var(--ink-soft);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* Greyed out when the text size hits the min or max step. */
.a11y-stepper button:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.a11y-reset {
  margin-bottom: 16px;
}

/* ---- Pause animations ---- */
/* Kill every animation/transition on the page, including pseudo-elements
   and smooth scrolling. !important is required to override component rules. */
html.a11y-no-motion *,
html.a11y-no-motion *::before,
html.a11y-no-motion *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

/* ---- Text size (scales the whole page) ---- */
/* Using zoom rather than rem-scaling so existing px-based sizes scale too. */
html.a11y-text-1 body { zoom: 1.12; }
html.a11y-text-2 body { zoom: 1.25; }
html.a11y-text-3 body { zoom: 1.5; }

/* ---- High contrast ---- */
/* Light mode: pure black text, pure white surfaces, darker gold for contrast. */
html.a11y-contrast {
  --ink: #000;
  --ink-soft: #1a1a1a;
  --line: #000;
  --paper-bg: #fff;
  --surface: #fff;
  --gold: #8a5a00;
}

/* Dark mode overrides — invert to pure white on black. */
html.a11y-contrast[data-theme="dark"] {
  --ink: #fff;
  --ink-soft: #fff;
  --line: #fff;
  --paper-bg: #000;
  --surface: #000;
  --gold: #ffd84a;
  --dark-accent: #ffd84a;
}

/* Thicker borders on card-like elements so their edges are clearly visible. */
html.a11y-contrast .paper-card,
html.a11y-contrast .modal,
html.a11y-contrast .detail-modal,
html.a11y-contrast .filter-chip,
html.a11y-contrast .pill {
  border: 2px solid var(--ink);
}

/* Links need an underline in high-contrast mode — colour alone isn't enough. */
html.a11y-contrast a {
  text-decoration: underline;
}

/* ---- Easy-read font ---- */
/* :where() keeps specificity at 0, so component styles can still override
   individual elements if needed; !important is only on font-family. */
html.a11y-font body,
html.a11y-font body :where(h1, h2, h3, h4, h5, h6, p, li, a, button, input, select, textarea, label, span, small, strong, div) {
  font-family: Verdana, Tahoma, "Trebuchet MS", sans-serif !important;
  letter-spacing: .02em;
}

/* ---- Wider spacing ---- */
html.a11y-spacing body {
  line-height: 1.8;
  word-spacing: .16em;
  letter-spacing: .04em;
}

/* Force the wider line-height through nested elements too
   (component rules may set their own tighter value). */
html.a11y-spacing body :where(p, li, h1, h2, h3, h4, span) {
  line-height: 1.8 !important;
}

/* ---- Underlined links ---- */
html.a11y-links a {
  text-decoration: underline !important;
  text-underline-offset: 3px;
}

/* ---- Strong keyboard focus ---- */
/* Yellow outline + black halo so it stays visible on any background.
   :focus-visible keeps the ring off for mouse users. */
html.a11y-focus :focus-visible {
  outline: 4px solid #ffbf00 !important;
  outline-offset: 3px !important;
  box-shadow: 0 0 0 7px #000 !important;
}

/* ---- Reading guide ---- */
/* Semi-transparent horizontal band that follows the pointer.
   pointer-events:none so it never blocks clicks underneath. */
.a11y-guide {
  position: fixed;
  left: 0;
  right: 0;
  height: 2.6em;
  transform: translateY(-50%);
  background: rgba(255, 224, 0, .2);
  border-top: 2px solid rgba(0, 0, 0, .65);
  border-bottom: 2px solid rgba(0, 0, 0, .65);
  pointer-events: none;
  z-index: 130;
}

/* ---- Buttons row and collapsible settings section ---- */
/* Two equal buttons side by side; one per row on narrow screens. */
.a11y-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 22px;
}

.a11y-actions .btn {
  width: 100%;
  margin: 0;
  padding: 13px 16px;
  white-space: nowrap;
}

/* Stack the two action buttons on small screens. */
@media (max-width: 480px) {
  .a11y-actions {
    grid-template-columns: 1fr;
  }
}

/* Explicit rules so [hidden] wins against .display:flex above. */
.a11y-settings[hidden] {
  display: none;
}

.a11y-list[hidden],
.a11y-modal .modal-hint[hidden] {
  display: none;
}
