/* Dark theme. Switched by <html data-theme="dark"> (public/theme.js: light / dark / as the system).
   The light theme is styles.css plus the original colours kept as var() fallbacks: every fixed UI colour
   was rewritten by tools/theme/codemod.js into var(--th-<role>, <light colour>), and the --th- tokens are
   defined only here. Only on screen: print and PDF always use the light colours.
   Contrast (WCAG AA, 4.5:1 for text) is checked by tests/theme-dark.test.js. */
@media screen {
  :root[data-theme=dark] {
    color-scheme: dark;
    /* shared tokens of styles.css */
    --bg: #0f1218; --panel: #181c24; --line: #2f3642; --text: #e6e9ef; --muted: #9aa3b2;
    --accent: #5b5ef0; --accent-soft: #272a52; --sel: #60a5fa; --danger: #dc2626;
    --field-line: #6b7587;
    --st-todo: #94a3b8; --st-doing: #60a5fa; --st-done: #4ade80;
    /* neutral roles */
    --th-surface: #181c24; --th-surface-2: #1e232c; --th-hover: #262c37; --th-hover-2: #2f3642;
    --th-glass: rgba(24, 28, 36, .95); --th-line: #2f3642; --th-line-strong: #465062;
    --th-text: #e6e9ef; --th-text-2: #c5ccd6; --th-muted: #9aa3b2; --th-accent-text: #a5b4fc;
    /* tinted roles: background / border / text of the same hue */
    --th-red-bg: #3b1d22; --th-red-line: #7f2d35; --th-red-text: #fca5a5;
    --th-amber-bg: #352a10; --th-amber-line: #6f5518; --th-amber-text: #fcd34d;
    --th-green-bg: #13301f; --th-green-line: #22683f; --th-green-text: #86efac;
    --th-blue-bg: #172b47; --th-blue-line: #2d528a; --th-blue-text: #93c5fd;
    --th-violet-bg: #272a52; --th-violet-line: #43458f; --th-violet-text: #c4b5fd;
    --th-teal-bg: #0f2f2d; --th-teal-line: #1f5f59; --th-teal-text: #5eead4;
    --th-pink-bg: #3a1b34; --th-pink-line: #7a2f6b; --th-pink-text: #f9a8d4;
  }

  /* Light islands: content that is drawn light on purpose (the diagram canvas below, previews of exports,
     printouts and the portal) gets the light tokens back; "initial" makes every var() use its light fallback */
  :root[data-theme=dark] :is(svg.canvas, .th-light, .th-invert, svg[font-family^="Segoe UI"], .pitem > svg) {
    color-scheme: light;
    --bg: #f6f7f9; --panel: #fff; --line: #e3e6eb; --text: #1f2430; --muted: #6b7280;
    --accent: #4f46e5; --accent-soft: #eef2ff; --sel: #3b82f6; --danger: #dc2626;
    --field-line: #858e9c;
    --st-todo: #64748b; --st-doing: #2563eb; --st-done: #16a34a;
    --th-surface: initial; --th-surface-2: initial; --th-hover: initial; --th-hover-2: initial;
    --th-glass: initial; --th-line: initial; --th-line-strong: initial;
    --th-text: initial; --th-text-2: initial; --th-muted: initial; --th-accent-text: initial;
    --th-red-bg: initial; --th-red-line: initial; --th-red-text: initial;
    --th-amber-bg: initial; --th-amber-line: initial; --th-amber-text: initial;
    --th-green-bg: initial; --th-green-line: initial; --th-green-text: initial;
    --th-blue-bg: initial; --th-blue-line: initial; --th-blue-text: initial;
    --th-violet-bg: initial; --th-violet-line: initial; --th-violet-text: initial;
    --th-teal-bg: initial; --th-teal-line: initial; --th-teal-text: initial;
    --th-pink-bg: initial; --th-pink-line: initial; --th-pink-text: initial;
  }
  :root[data-theme=dark] .th-light { color: var(--text); }

  /* Diagrams: the drawing stays the light one (the same as export, print, PDF and portal) and is shown
     inverted in lightness only (hue-rotate brings the hues back): white shapes turn dark grey, black lines
     and texts light, status and element colours keep their hue. Pictures are turned back to their colours. */
  :root[data-theme=dark] :is(svg.canvas, .th-invert) { filter: invert(.88) hue-rotate(180deg); }
  :root[data-theme=dark] :is(svg.canvas, .th-invert) :is(image, img, video, .th-keep) { filter: invert(1) hue-rotate(180deg); }
  /* the same for diagram pictures outside the editor (Docs blocks, embeds, version compare, Gantt and
     roadmap pictures: every SVG of the diagram renderers carries font-family="Segoe UI…") and the palette */
  :root[data-theme=dark] svg[font-family^="Segoe UI"]:not(svg.canvas svg, .th-invert svg) {
    filter: invert(.88) hue-rotate(180deg); color-scheme: light;
  }
  :root[data-theme=dark] svg[font-family^="Segoe UI"]:not(svg.canvas svg, .th-invert svg) image { filter: invert(1) hue-rotate(180deg); }
  :root[data-theme=dark] :is(.pgrid, .pgroup) .pitem > svg { filter: invert(.88) hue-rotate(180deg); }
  :root[data-theme=dark] .editor-host { background: #1f1f1f; }

  /* Native look of the remaining fixed colours */
  :root[data-theme=dark] ::selection { background: #3b4a7a; color: #fff; }
  :root[data-theme=dark] input::placeholder, :root[data-theme=dark] textarea::placeholder { color: #7d8697; }
  :root[data-theme=dark] img.th-dim { opacity: .9; }
}
