/* wtpp-user-contrast-prefs.css  (added v3.7.807)
 *
 * Support for two operating-system accessibility preferences the platform did not
 * previously honour: prefers-contrast and forced-colors.
 *
 * WHY THESE AND NOT A WIDGET
 *   Reviewing an accessibility overlay product raised the question of what genuine
 *   gaps it was papering over. Two of its panel controls mapped to real user needs
 *   that the operating system already exposes as a preference: "High Contrast" and,
 *   implicitly, Windows High Contrast Mode. The right answer to a user who has
 *   already told their OS they need higher contrast is to honour that setting, not
 *   to ask them to set it a second time in a floating panel. The platform already
 *   honours prefers-reduced-motion and prefers-color-scheme; these two complete the
 *   set.
 *
 * 1. prefers-contrast: more
 *    Set by "Increase contrast" on macOS/iOS and by contrast themes on Windows.
 *    Rather than inventing a third palette, this darkens ink tokens and lightens
 *    paper tokens so existing contrast ratios increase without changing hue
 *    relationships. Hue relationships matter here because the colour-blind-safety
 *    work (see tools/check_color_accessibility.py) is tuned to the current hue
 *    families, and shifting hues under a contrast preference could reintroduce a
 *    confusable pair for a user who has both needs.
 *
 * 2. forced-colors: active
 *    Windows High Contrast Mode. The browser replaces author colours with a small
 *    user-chosen system palette. Two things break without explicit handling:
 *
 *      a) SVG figures. Fills and strokes set via CSS custom properties are NOT
 *         automatically remapped, so a figure can render as invisible shapes on a
 *         same-coloured background. This matters more here than on most sites
 *         because the platform's analytical figures are SVG, and a figure that
 *         vanishes takes its argument with it. Handled by mapping figure strokes
 *         and text to CanvasText and backgrounds to Canvas.
 *
 *      b) Elements that convey state through background colour alone. The platform
 *         already avoids colour as a sole signal per WCAG 1.4.1, so the dash
 *         patterns and text labels survive forced-colors intact. This block only
 *         needs to ensure borders remain visible, since a border that was carrying
 *         visual separation can otherwise disappear.
 *
 * WHAT THIS FILE DOES NOT DO
 *   It does not add user-facing toggles. Browsers and operating systems already
 *   provide text scaling, zoom, and reader modes, and reimplementing them in-page
 *   produces a worse version that competes with the real one.
 *
 * TESTING
 *   Chrome DevTools: Rendering panel > "Emulate CSS media feature
 *   prefers-contrast" and "Emulate CSS media feature forced-colors".
 *   Windows: Settings > Accessibility > Contrast themes.
 *   macOS: System Settings > Accessibility > Display > Increase contrast.
 */

@media (prefers-contrast: more) {
  :root {
    /* Ink tokens darkened toward black; paper tokens lightened toward white.
       Hue families are preserved deliberately (see header note). */
    --ink-11: #000000;
    --ink-11x: #000000;
    --ink-15: #0d0b09;
    --ink-15x: #0d0b09;
    --ink-17: #14110e;
    --ink-29: #241f19;
    --paper-99: #ffffff;
    --paper-98: #ffffff;
    --paper-89: #f4f1e8;
    --paper-83: #ebe8e0;
    --tone-69: #6b6459;
    --tone-76: #7a7366;
    --tone-54: #4a4640;
    --tone-45: #3d3830;
    /* Chromatic tokens darkened for contrast against light paper while keeping
       red and blue distinguishable from each other and from ink. */
    --flag-red: #8f1a29;
    --flag-blue: #2a2950;
    --navy-30: #23293a;
    --danger-26: #5c1d2a;
  }

  /* Borders carry more of the visual structure when contrast is raised. */
  .site-header,
  .site-footer,
  section,
  figure,
  table {
    border-color: var(--ink-17);
  }

  /* Focus indication must remain unmistakable at higher contrast. */
  a:focus-visible,
  button:focus-visible,
  [tabindex]:focus-visible {
    outline: 3px solid var(--ink-11);
    outline-offset: 2px;
  }
}

@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root {
    --ink-11: #ffffff;
    --ink-11x: #ffffff;
    --ink-17: #f4f2ee;
    --ink-29: #e4e0d8;
    --paper-99: #000000;
    --paper-98: #000000;
    --paper-89: #14120f;
    --paper-83: #1c1a16;
    --flag-red: #ff8a97;
    --flag-blue: #a9a8e0;
  }
}

@media (forced-colors: active) {
  /* Let the system palette drive text and surfaces. */
  :root {
    --ink-11: CanvasText;
    --ink-11x: CanvasText;
    --ink-15: CanvasText;
    --ink-15x: CanvasText;
    --ink-17: CanvasText;
    --ink-29: CanvasText;
    --tone-45: CanvasText;
    --tone-54: CanvasText;
    --tone-69: GrayText;
    --tone-76: GrayText;
    --paper-99: Canvas;
    --paper-98: Canvas;
    --paper-89: Canvas;
    --paper-83: Canvas;
    --surface-card: Canvas;
    --flag-red: CanvasText;
    --flag-blue: CanvasText;
  }

  /* SVG figures: without this, custom-property fills are not remapped and a
     figure can render invisible. Series remain distinguishable because they are
     differentiated by dash pattern and direct labels, not by colour. */
  svg text {
    fill: CanvasText;
  }
  svg [stroke]:not([stroke="none"]) {
    stroke: CanvasText;
  }
  svg [fill]:not([fill="none"]):not(text) {
    fill: Canvas;
    stroke: CanvasText;
  }

  /* Keep structural borders present when author backgrounds are discarded. */
  .site-header,
  .site-footer,
  section,
  figure,
  table,
  th,
  td {
    border-color: CanvasText;
  }

  /* Focus must survive the palette swap. */
  a:focus-visible,
  button:focus-visible,
  [tabindex]:focus-visible {
    outline: 3px solid Highlight;
    outline-offset: 2px;
  }

  /* Links keep the system link colour rather than an author colour. */
  a {
    color: LinkText;
  }
}
