/**
 * High Contrast Theme — WCAG AAA target.
 *
 * Maximum readability for users with low vision. Every foreground/background
 * pair meets 7:1 contrast ratio (AAA Normal Text). Black/white primary palette
 * with saturated status colors that maintain AAA on both backgrounds.
 *
 * Typography: Atkinson Hyperlegible (body + headings) + Cascadia Code (mono)
 * Both fonts designed specifically for low-vision readability.
 */

/* ─── Light Mode (default) ────────────���─────────────────────────── */
:root {
  color-scheme: light;

  --sonde-color-primary: #000000;
  --sonde-color-secondary: #00524a;
  --sonde-color-bg: #ffffff;
  --sonde-color-surface: #ffffff;
  --sonde-color-text: #000000;
  --sonde-color-text-muted: #333333;
  --sonde-color-text-heading: #000000;
  --sonde-color-border: #000000;
  --sonde-color-border-subtle: #666666;
  --sonde-color-accent: #00524a;
  --sonde-color-accent-dim: #00524a22;

  /* Status colors: all ≥ 7:1 on white */
  --sonde-color-pass: #006838;
  --sonde-color-fail: #b30000;
  --sonde-color-partial: #7a4f00;
  --sonde-color-na: #444444;
  --sonde-color-info: #003d99;
  --sonde-color-warning: #7a4f00;
  --sonde-color-error: #b30000;
  --sonde-color-critical: #8b0028;

  --sonde-color-table-header-bg: #000000;
  --sonde-color-table-header-text: #ffffff;

  /* High contrast brand mark: match the Daylight themes-page HC sample. */
  --sonde-daylight-mark-sun-stop-0: #000000;
  --sonde-daylight-mark-sun-stop-1: #000000;
  --sonde-daylight-mark-sun-stop-2: #000000;
  --sonde-daylight-mark-crater: transparent;
  --sonde-daylight-mark-probe: #ffffff;
  --sonde-daylight-mark-solid-display: none;
  --sonde-daylight-mark-line-display: block;


  --sonde-font-body: 'Atkinson Hyperlegible', 'Verdana', system-ui, sans-serif;
  --sonde-font-heading: 'Atkinson Hyperlegible', 'Verdana', system-ui, sans-serif;
  --sonde-font-mono: 'Cascadia Code', 'Consolas', ui-monospace, monospace;
  --sonde-font-display: 'Atkinson Hyperlegible', 'Verdana', system-ui, sans-serif;
  --sonde-font-size-base: 18px;
  --sonde-line-height: 1.7;

  /* Wider spacing for readability */
  --sonde-radius-sm: 2px;
  --sonde-radius-md: 4px;
  --sonde-radius-lg: 8px;

  /* Elevated surface + stronger border tiers — HC collapses tiers into
   * the base palette; elevation comes from borders, not fills. */
  --sonde-color-surface-elevated: #ffffff;
  --sonde-color-border-strong: #000000;

  /* Visualization primitives — HC avoids low-alpha overlays; solid
   * blacks where possible, 25%+ alpha where an overlay is unavoidable. */
  --sonde-viz-grid-overlay: rgba(0, 0, 0, 0);
  --sonde-viz-glow: rgba(0, 0, 0, 0);
  --sonde-viz-label-bg: rgba(255, 255, 255, 0.95);
  --sonde-viz-node-faded: rgba(0, 0, 0, 0.3);
  --sonde-viz-edge: #000000;
  --sonde-viz-code-bg: #f0f0f0;

  /* Code block surfaces */
  --sonde-code-bg: #ffffff;
  --sonde-code-text: #000000;
  --sonde-code-line-num: #595959;
  --sonde-code-gutter-bg: #f0f0f0;
  --sonde-code-highlight-bg: #ffff99;

  /* Syntax highlighting — maximally-distinct AAA palette on white */
  --sonde-syntax-keyword: #0000cc;
  --sonde-syntax-type: #006600;
  --sonde-syntax-string: #a31515;
  --sonde-syntax-number: #098658;
  --sonde-syntax-comment: #595959;
  --sonde-syntax-function: #795e26;
  --sonde-syntax-variable: #001080;
  --sonde-syntax-constant: #0000cc;
  --sonde-syntax-property: #001080;
  --sonde-syntax-punctuation: #000000;
  --sonde-syntax-tag: #800000;
  --sonde-syntax-default: #000000;
  --sonde-color-sidebar: #ffffff;

  /* Diff viewer */
  --sonde-color-diff-bg: #ffffff;
  --sonde-color-diff-add-bg: #e8f5e9;
  --sonde-color-diff-add-text: #006838;
  --sonde-color-diff-add-gutter: #d2ead5;
  --sonde-color-diff-remove-bg: #fff0f0;
  --sonde-color-diff-remove-text: #b30000;
  --sonde-color-diff-remove-gutter: #ffd6d6;
  --sonde-color-diff-unchanged-gutter: #f0f0f0;
}

/* ���── Dark Mode — explicit via data-mode="dark" ────────────────── */
:root[data-mode="dark"], [data-theme="dark"] {
  color-scheme: dark;
  --sonde-color-primary: #ffffff;
  --sonde-color-secondary: #5eead4;
  --sonde-color-bg: #000000;
  --sonde-color-surface: #111111;
  --sonde-color-sidebar: #000000;
  --sonde-color-text: #ffffff;
  --sonde-color-text-muted: #cccccc;
  --sonde-color-text-heading: #ffffff;
  --sonde-color-border: #ffffff;
  --sonde-color-border-subtle: #999999;
  --sonde-color-accent: #5eead4;
  --sonde-color-accent-dim: rgba(94, 234, 212, 0.22);

  /* Status colors: all ≥ 7:1 on black */
  --sonde-color-pass: #4ade80;
  --sonde-color-fail: #fca5a5;
  --sonde-color-partial: #fde047;
  --sonde-color-na: #bbbbbb;
  --sonde-color-info: #93c5fd;
  --sonde-color-warning: #fde047;
  --sonde-color-error: #fca5a5;
  --sonde-color-critical: #fda4af;

  --sonde-color-table-header-bg: #ffffff;
  --sonde-color-table-header-text: #000000;

  /* Keep the HC brand mark active under explicit dark mode. */
  --sonde-daylight-mark-sun-stop-0: #000000;
  --sonde-daylight-mark-sun-stop-1: #000000;
  --sonde-daylight-mark-sun-stop-2: #000000;
  --sonde-daylight-mark-crater: transparent;
  --sonde-daylight-mark-probe: #ffffff;
  --sonde-daylight-mark-solid-display: none;
  --sonde-daylight-mark-line-display: block;


  /* Code block surfaces — dark */
  --sonde-code-bg: #000000;
  --sonde-code-text: #ffffff;
  --sonde-code-line-num: #aaaaaa;
  --sonde-code-gutter-bg: #111111;
  --sonde-code-highlight-bg: #003300;

  /* Syntax highlighting — maximally-distinct AAA palette on black */
  --sonde-syntax-keyword: #93c5fd;
  --sonde-syntax-type: #4ade80;
  --sonde-syntax-string: #fca5a5;
  --sonde-syntax-number: #5eead4;
  --sonde-syntax-comment: #aaaaaa;
  --sonde-syntax-function: #fde047;
  --sonde-syntax-variable: #ffffff;
  --sonde-syntax-constant: #93c5fd;
  --sonde-syntax-property: #ffffff;
  --sonde-syntax-punctuation: #ffffff;
  --sonde-syntax-tag: #fda4af;
  --sonde-syntax-default: #ffffff;

  /* Diff viewer */
  --sonde-color-diff-bg: #000000;
  --sonde-color-diff-add-bg: #052e16;
  --sonde-color-diff-add-text: #4ade80;
  --sonde-color-diff-add-gutter: #0a3d20;
  --sonde-color-diff-remove-bg: #330707;
  --sonde-color-diff-remove-text: #fca5a5;
  --sonde-color-diff-remove-gutter: #4a1010;
  --sonde-color-diff-unchanged-gutter: #111111;

  /* Elevated surface + stronger border tiers */
  --sonde-color-surface-elevated: #222222;
  --sonde-color-border-strong: #ffffff;

  /* Visualization primitives */
  --sonde-viz-grid-overlay: rgba(255, 255, 255, 0);
  --sonde-viz-glow: rgba(255, 255, 255, 0);
  --sonde-viz-label-bg: rgba(0, 0, 0, 0.95);
  --sonde-viz-node-faded: rgba(255, 255, 255, 0.3);
  --sonde-viz-edge: #ffffff;
  --sonde-viz-code-bg: #222222;
}

/* ─── Dark Mode — automatic via OS preference ───────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    color-scheme: dark;
    --sonde-color-primary: #ffffff;
    --sonde-color-secondary: #5eead4;
    --sonde-color-bg: #000000;
    --sonde-color-surface: #111111;
    --sonde-color-sidebar: #000000;
    --sonde-color-text: #ffffff;
    --sonde-color-text-muted: #cccccc;
    --sonde-color-text-heading: #ffffff;
    --sonde-color-border: #ffffff;
    --sonde-color-border-subtle: #999999;
    --sonde-color-accent: #5eead4;
    --sonde-color-accent-dim: rgba(94, 234, 212, 0.22);

    --sonde-color-pass: #4ade80;
    --sonde-color-fail: #fca5a5;
    --sonde-color-partial: #fde047;
    --sonde-color-na: #bbbbbb;
    --sonde-color-info: #93c5fd;
    --sonde-color-warning: #fde047;
    --sonde-color-error: #fca5a5;
    --sonde-color-critical: #fda4af;

    --sonde-color-table-header-bg: #ffffff;
    --sonde-color-table-header-text: #000000;

    /* Keep the HC brand mark active under OS dark mode. */
    --sonde-daylight-mark-sun-stop-0: #000000;
    --sonde-daylight-mark-sun-stop-1: #000000;
    --sonde-daylight-mark-sun-stop-2: #000000;
    --sonde-daylight-mark-crater: transparent;
    --sonde-daylight-mark-probe: #ffffff;
    --sonde-daylight-mark-solid-display: none;
    --sonde-daylight-mark-line-display: block;


    /* Code block surfaces — dark */
    --sonde-code-bg: #000000;
    --sonde-code-text: #ffffff;
    --sonde-code-line-num: #aaaaaa;
    --sonde-code-gutter-bg: #111111;
    --sonde-code-highlight-bg: #003300;

    /* Syntax highlighting — maximally-distinct AAA palette on black */
    --sonde-syntax-keyword: #93c5fd;
    --sonde-syntax-type: #4ade80;
    --sonde-syntax-string: #fca5a5;
    --sonde-syntax-number: #5eead4;
    --sonde-syntax-comment: #aaaaaa;
    --sonde-syntax-function: #fde047;
    --sonde-syntax-variable: #ffffff;
    --sonde-syntax-constant: #93c5fd;
    --sonde-syntax-property: #ffffff;
    --sonde-syntax-punctuation: #ffffff;
    --sonde-syntax-tag: #fda4af;
    --sonde-syntax-default: #ffffff;

    /* Diff viewer */
    --sonde-color-diff-bg: #000000;
    --sonde-color-diff-add-bg: #052e16;
    --sonde-color-diff-add-text: #4ade80;
    --sonde-color-diff-add-gutter: #0a3d20;
    --sonde-color-diff-remove-bg: #330707;
    --sonde-color-diff-remove-text: #fca5a5;
    --sonde-color-diff-remove-gutter: #4a1010;
    --sonde-color-diff-unchanged-gutter: #111111;

    /* Elevated surface + stronger border tiers */
    --sonde-color-surface-elevated: #222222;
    --sonde-color-border-strong: #ffffff;

    /* Visualization primitives */
    --sonde-viz-grid-overlay: rgba(255, 255, 255, 0);
    --sonde-viz-glow: rgba(255, 255, 255, 0);
    --sonde-viz-label-bg: rgba(0, 0, 0, 0.95);
    --sonde-viz-node-faded: rgba(255, 255, 255, 0.3);
    --sonde-viz-edge: #ffffff;
    --sonde-viz-code-bg: #222222;
  }
}

/* ─── High Contrast (reinforced — this IS the high-contrast theme) ─ */
@media (prefers-contrast: more) {
  :root {
    --sonde-color-text: #000000;
    --sonde-color-text-muted: #222222;
    --sonde-color-text-heading: #000000;
    --sonde-color-border: #000000;
    --sonde-color-border-subtle: #444444;
  }

  :root[data-mode="dark"], [data-theme="dark"] {
    --sonde-color-text: #ffffff;
    --sonde-color-text-muted: #ffffff;
    --sonde-color-text-heading: #ffffff;
    --sonde-color-border: #ffffff;
    --sonde-color-border-subtle: #ffffff;
  }
}

/* ─── Reduced Motion ───────────���────────────────────────────────── */
/* Reduced-motion block inherited from tokens.css. */

/* ─── Print ─────────────────────────────────────────────────────── */
@media print {
  :root {
    --sonde-color-bg: #ffffff;
    --sonde-color-surface: #ffffff;
    --sonde-color-surface-elevated: #ffffff;
    --sonde-color-text: #000000;
    --sonde-color-text-muted: #222222;
    --sonde-color-text-heading: #000000;
    --sonde-color-border: #000000;
    --sonde-color-border-subtle: #666666;
    --sonde-shadow-sm: none;
    --sonde-shadow-md: none;
    --sonde-shadow-lg: none;
  }
  body, .sonde-exhibit, .scribe-shell__main {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .site-nav, .settings-dropdown, footer, .sonde-nav, .sonde-controls,
  .scribe-leaderboard-pagination, .leaderboard-pagination, [data-print="hide"] {
    display: none !important;
  }
  details, details:not([open]) { display: block; }
  details > summary { display: none; }
  details > * { display: revert; }
  pre, code, .exhibit-code-block {
    break-inside: avoid;
    page-break-inside: avoid;
    orphans: 4;
    widows: 4;
  }
  section, .vpat-section, tr { break-inside: avoid; }
  h1, h2, h3, h4, h5, h6 {
    break-after: avoid;
    page-break-after: avoid;
  }
  thead { display: table-header-group; }
  /* Modern PDF readers preserve clickable hyperlinks; legacy
   * "URL (URL)" expansion removed to avoid duplicate output. */
  th.sortable::after, th[data-sort-key]::after {
    content: "";
    display: none;
  }
  tr[data-filtered="true"] { display: none; }
  body[data-scribe-print-rows="all"] tr[data-filtered="true"] { display: table-row; }
}

/* ─── Forced Colors (Windows High Contrast) ─────────────────────── */
@media (forced-colors: active) {
  :root {
    --sonde-color-primary: LinkText;
    --sonde-color-text: CanvasText;
    --sonde-color-bg: Canvas;
    --sonde-color-surface: Canvas;
    --sonde-color-border: CanvasText;
    --sonde-color-accent: Highlight;
  }
}
