/* Pipwatch themes (Rj 2026-10-23: "dark mode, not so dark mode and light mode option").
   Light = the Scoreboard tokens in index.html (paper and ink) - nothing here touches it.
   Dim   = warm charcoal paper, softer contrast, the scoreboard block stays the darkest thing on screen.
   Dark  = true dark for night: near-black paper, raised cards, the scoreboard block a raised panel.
   Only TOKENS change, so every screen, chart and the Desk's lightweight-charts (desk.js reads the tokens
   when it draws) follow. The theme is set on <html data-theme> by the inline script in <head> before the
   first paint (localStorage "theme"), then by settings.js / the saved per-user preference.
   Every pair was checked for WCAG AA (4.5:1 text) - ink / ink-2 / ink-3 on card, paper, paper-2;
   up / down / warn / option on card and on their soft fills; board-ink / board-dim / up / down on the
   board; card text on the primary button - and the review gate runs its contrast pass in each theme. */

:root[data-theme="dim"]{
  color-scheme:dark;
  --paper:oklch(0.285 0.012 70);
  --paper-2:oklch(0.255 0.012 70);
  --card:oklch(0.325 0.012 70);
  --rule:oklch(0.4 0.012 70);
  --rule-2:oklch(0.47 0.012 70);
  --ink:oklch(0.93 0.012 85);
  --ink-2:oklch(0.83 0.012 85);
  --ink-3:oklch(0.76 0.012 85);
  --hi:oklch(0.88 0.16 103);
  --hi-ink:oklch(0.2 0.04 103);
  --hi-track:oklch(0.2 0.04 103 / .18);
  --board:oklch(0.215 0.01 70);
  --board-ink:oklch(0.95 0.01 90);
  --board-dim:oklch(0.74 0.012 90);
  --board-rule:oklch(0.34 0.012 70);
  --up-on-board:oklch(0.8 0.16 150);
  --down-on-board:oklch(0.74 0.17 27);
  --up-wash:oklch(0.8 0.13 150 / .16);
  --down-wash:oklch(0.78 0.13 27 / .18);
  --accent-2:oklch(0.86 0.012 85);
  --on-accent-line:oklch(1 0 0 / .16);
  --on-accent-fill:oklch(1 0 0 / .1);
  --up:oklch(0.8 0.13 150);
  --down:oklch(0.78 0.13 27);
  --up-soft:oklch(0.37 0.05 150);
  --down-soft:oklch(0.37 0.05 27);
  --warn:oklch(0.83 0.12 80);
  --warn-soft:oklch(0.38 0.05 85);
  --option:oklch(0.8 0.1 300);
  --option-soft:oklch(0.38 0.05 300);
  --spy:oklch(0.72 0.012 70);
  --cash:oklch(0.76 0.08 195);
  --sea:oklch(0.3 0.012 70);
  --land:oklch(0.42 0.012 70);
  --night:oklch(0 0 0 / .25);
  --shadow:oklch(0 0 0 / .32);
  --scrim:oklch(0 0 0 / .55);
  --focus:oklch(0.78 0.13 265);
  --lt-sticky-shadow:oklch(0 0 0 / .25);
  --lt-fade:linear-gradient(90deg, oklch(0.325 0.012 70 / 0), var(--card));
}

:root[data-theme="dark"]{
  color-scheme:dark;
  --paper:oklch(0.165 0.006 70);
  --paper-2:oklch(0.135 0.006 70);
  --card:oklch(0.205 0.006 70);
  --rule:oklch(0.3 0.008 70);
  --rule-2:oklch(0.38 0.008 70);
  --ink:oklch(0.95 0.008 85);
  --ink-2:oklch(0.82 0.008 85);
  --ink-3:oklch(0.72 0.008 85);
  --hi:oklch(0.88 0.16 103);
  --hi-ink:oklch(0.2 0.04 103);
  --hi-track:oklch(0.2 0.04 103 / .18);
  --board:oklch(0.255 0.008 70);
  --board-ink:oklch(0.96 0.01 90);
  --board-dim:oklch(0.76 0.012 90);
  --board-rule:oklch(0.36 0.008 70);
  --up-on-board:oklch(0.8 0.16 150);
  --down-on-board:oklch(0.74 0.17 27);
  --up-wash:oklch(0.78 0.14 150 / .14);
  --down-wash:oklch(0.74 0.15 27 / .16);
  --accent-2:oklch(0.85 0.008 85);
  --on-accent-line:oklch(1 0 0 / .14);
  --on-accent-fill:oklch(1 0 0 / .08);
  --up:oklch(0.78 0.14 150);
  --down:oklch(0.74 0.15 27);
  --up-soft:oklch(0.3 0.05 150);
  --down-soft:oklch(0.3 0.06 27);
  --warn:oklch(0.82 0.12 80);
  --warn-soft:oklch(0.31 0.05 85);
  --option:oklch(0.78 0.11 300);
  --option-soft:oklch(0.31 0.05 300);
  --spy:oklch(0.7 0.008 70);
  --cash:oklch(0.74 0.08 195);
  --sea:oklch(0.2 0.006 70);
  --land:oklch(0.32 0.008 70);
  --night:oklch(0 0 0 / .3);
  --shadow:oklch(0 0 0 / .45);
  --scrim:oklch(0 0 0 / .6);
  --focus:oklch(0.76 0.13 265);
  --lt-sticky-shadow:oklch(0 0 0 / .35);
  --lt-fade:linear-gradient(90deg, oklch(0.205 0.006 70 / 0), var(--card));
}

/* The scoreboard-black accent is also used as TEXT and as small fills next to text in a few light-theme
   rules. On a dark page that black would vanish, so those few rules read ink instead. */
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .linkbtn{color:var(--ink)}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .input:focus-visible{border-color:var(--focus)}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .toggle input:checked{background:var(--up)}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .meter i,
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .legend i{background:var(--ink-2)}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .facts li::before{box-shadow:inset 0 0 0 2px var(--ink-3)}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) img.invert-dark{filter:invert(1) hue-rotate(180deg)}

/* Theme changes fade instead of snapping (not on first paint: the class is added after load). */
@media (prefers-reduced-motion:no-preference){
  html.theme-anim, html.theme-anim *{transition:background-color .25s ease, border-color .25s ease, color .2s ease !important}
}

/* Light: "only light" so Chrome's automatic dark mode (Android "darken websites") never repaints the light
   theme - that repaint is what turned the Desk green-on-yellow / cream chips on Rj's phone (2026-10-23). */
:root[data-theme="light"]{color-scheme:only light}

/* Light-only treatments that do not survive a dark page (Rj's phone screenshot, 2026-10-23 "Color issues"):
   1. the highlighter strip under the Desk's "since start" figure -> an underline in the highlighter colour;
   2. selected chips / timeframes / the pending pill: ink fill with board-ink text (light on light in a dark
      theme) -> ink fill with card text, the count in card too;
   3. chart area fills in the highlighter yellow (muddy olive on black) -> the positive / negative token at a
      low opacity; the lines already use ink / up / down tokens;
   4. the checklist tick: a highlighter tick on an ink box -> a card tick on the positive token. */
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .dsk-kpis div:first-child dd:first-of-type{
  background:none;text-decoration:underline;text-decoration-color:var(--hi);text-decoration-thickness:3px;
  text-underline-offset:5px;text-decoration-skip-ink:none}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .dsk-fchip[aria-pressed="true"],
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .dsk-tf[aria-pressed="true"],
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .dsk-pill[data-s="pending"]{color:var(--card)}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .dsk-fchip[aria-pressed="true"] .num{color:var(--card);font-weight:700}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .dsk-curve__fill{fill:var(--up);opacity:.18}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .dsk-curve[data-tone="down"] .dsk-curve__fill{fill:var(--down);opacity:.2}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .tr-plot .ar-eq{fill:var(--up);opacity:.16}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .dsk-steps li[data-ok="yes"] .dsk-steps__m{background:var(--up);border-color:var(--up)}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .dsk-steps li[data-ok="yes"] .dsk-steps__m::after{border-color:var(--card)}

/* Up / down figures sitting ON a highlighter surface (an open round tile, the approvals banner, ...):
   light green / red on yellow vanish on a dark page, so they take dark versions of the same hues there. */
:root[data-theme="dim"], :root[data-theme="dark"]{--up-on-hi:oklch(0.42 0.12 150);--down-on-hi:oklch(0.45 0.18 27)}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .sb-tile.open.is-down .val{color:var(--down-on-hi)}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) :is(.sb-tile.open, .ap-banner, .mc-paper, .dsk-be, .dsk-pill[data-s="running"], .tr-st.pending, .ict-flag.is-on, .ict-band.is-now, .navsheet a[aria-current="page"]) .up{color:var(--up-on-hi)}
:is(:root[data-theme="dim"], :root[data-theme="dark"]) :is(.sb-tile.open, .ap-banner, .mc-paper, .dsk-be, .dsk-pill[data-s="running"], .tr-st.pending, .ict-flag.is-on, .ict-band.is-now, .navsheet a[aria-current="page"]) .down{color:var(--down-on-hi)}
/* The board's sound / vibration picker: ink buttons with board-dim captions (light theme) -> scoreboard
   buttons in dim / dark, where ink is the light colour. */
:is(:root[data-theme="dim"], :root[data-theme="dark"]) .sb-fx button:not(.hi){background:var(--board);color:var(--board-ink)}
