/*
 * Colour schemes. The page takes one of them from data-scheme on <html>, which js/scheme.js
 * sets: "dark" (the first and default) and "light", which the switch offers. "contrast"
 * (dark, with the strongest differences) is kept for a page that sets it; no switch offers
 * it. The visitor's choice, or else the device setting, picks the scheme.
 *
 * Everything below is "red green blue", so a page can add its own opacity:
 *   rgb(var(--white) / 0.1)
 * Names are kept from the Tailwind palette the pages were written with: "white" is the
 * main text colour and the tint of lines, "page" is the page background, and slate-N and
 * gray-N are the greys. In the light scheme the greys are swapped end to end, so a page
 * that says text-slate-300 gets a dark grey there. "on-accent" is text on a coloured
 * button and does not change.
 *
 * "--a-N" and "--a2-N" are the accent colours as the page uses them. In the light scheme
 * the pale accents are the dark ones, so accent text can be read on a pale page.
 */
:root, :root[data-scheme="dark"] {
    color-scheme: dark;
    --page: 11 18 32;
    --raised: 21 27 40;
    --raised2: 15 26 46;
    --deep: 10 10 35;
    --deep2: 18 18 67;
    --card: 13 13 42;
    --white: 255 255 255;
    --black: 0 0 0;
    --on-accent: 255 255 255;
    --faint: 124 138 160;
    --hair: 0.16;
    --hair2: 0.32;
    --control-line: 0.42;
    --slate-50: 248 250 252;
    --slate-100: 241 245 249;
    --slate-200: 226 232 240;
    --slate-300: 203 213 225;
    --slate-400: 148 163 184;
    --slate-500: 100 116 139;
    --slate-600: 71 85 105;
    --slate-700: 51 65 85;
    --slate-800: 30 41 59;
    --slate-900: 15 23 42;
    --slate-950: 2 6 23;
    --gray-50: 249 250 251;
    --gray-100: 243 244 246;
    --gray-200: 229 231 235;
    --gray-300: 209 213 219;
    --gray-400: 156 163 175;
    --gray-500: 107 114 128;
    --gray-600: 75 85 99;
    --gray-700: 55 65 81;
    --gray-800: 31 41 55;
    --gray-900: 17 24 39;
    --gray-950: 3 7 18;
    --ok-fg: 134 239 172;
    --ok-line: 21 128 61;
    --ok-fill: 20 83 45;
    --warn-fg: 253 230 138;
    --warn-line: 161 98 7;
    --warn-fill: 113 63 18;
    --bad-fg: 254 202 202;
    --bad-line: 185 28 28;
    --bad-fill: 127 29 29;
    /* the tables of links */
    --lk-bg0: 17 17 17;
    --lk-bg1: 26 26 26;
    --lk-bg2: 34 34 34;
    --lk-line: 51 51 51;
    --lk-line2: 85 85 85;
    --lk-muted: 170 170 170;
    --lk-faint: 119 119 119;
    --lk-teal: 69 229 195;
    --lk-red: 229 69 69;
    --lk-on-teal: 0 0 0;
    --a-50: var(--accent-50);
    --a-100: var(--accent-100);
    --a-200: var(--accent-200);
    --a-300: var(--accent-300);
    --a-400: var(--accent-400);
    --a-500: var(--accent-500);
    --a-600: var(--accent-600);
    --a-700: var(--accent-700);
    --a-800: var(--accent-800);
    --a-900: var(--accent-900);
    --a-950: var(--accent-950);
    --a2-50: var(--accent2-50);
    --a2-100: var(--accent2-100);
    --a2-200: var(--accent2-200);
    --a2-300: var(--accent2-300);
    --a2-400: var(--accent2-400);
    --a2-500: var(--accent2-500);
    --a2-600: var(--accent2-600);
    --a2-700: var(--accent2-700);
    --a2-800: var(--accent2-800);
    --a2-900: var(--accent2-900);
    --a2-950: var(--accent2-950);
}
:root[data-scheme="light"] {
    color-scheme: light;
    --page: 248 250 252;
    --raised: 255 255 255;
    --raised2: 241 245 249;
    --deep: 238 242 255;
    --deep2: 224 231 255;
    --card: 255 255 255;
    --white: 15 23 42;
    --black: 255 255 255;
    --on-accent: 255 255 255;
    --faint: 71 85 105;
    --hair: 0.22;
    --hair2: 0.42;
    --control-line: 0.55;
    --slate-50: 2 6 23;
    --slate-100: 15 23 42;
    --slate-200: 30 41 59;
    --slate-300: 51 65 85;
    --slate-400: 71 85 105;
    --slate-500: 100 116 139;
    --slate-600: 148 163 184;
    --slate-700: 203 213 225;
    --slate-800: 226 232 240;
    --slate-900: 241 245 249;
    --slate-950: 248 250 252;
    --gray-50: 3 7 18;
    --gray-100: 17 24 39;
    --gray-200: 31 41 55;
    --gray-300: 55 65 81;
    --gray-400: 75 85 99;
    --gray-500: 107 114 128;
    --gray-600: 156 163 175;
    --gray-700: 209 213 219;
    --gray-800: 229 231 235;
    --gray-900: 243 244 246;
    --gray-950: 249 250 251;
    --ok-fg: 21 128 61;
    --ok-line: 22 163 74;
    --ok-fill: 220 252 231;
    --warn-fg: 133 77 14;
    --warn-line: 202 138 4;
    --warn-fill: 254 249 195;
    --bad-fg: 185 28 28;
    --bad-line: 220 38 38;
    --bad-fill: 254 226 226;
    --lk-bg0: 255 255 255;
    --lk-bg1: 241 245 249;
    --lk-bg2: 226 232 240;
    --lk-line: 203 213 225;
    --lk-line2: 148 163 184;
    --lk-muted: 71 85 105;
    --lk-faint: 80 94 115;
    --lk-teal: 13 124 102;
    --lk-red: 185 28 28;
    --lk-on-teal: 255 255 255;
    --a-50: var(--accent-950);
    --a-100: var(--accent-900);
    --a-200: var(--accent-800);
    --a-300: var(--accent-700);
    --a-400: var(--accent-600);
    --a-500: var(--accent-500);
    --a-600: var(--accent-600);
    --a-700: var(--accent-700);
    --a-800: var(--accent-800);
    --a-900: var(--accent-900);
    --a-950: var(--accent-950);
    --a2-50: var(--accent2-950);
    --a2-100: var(--accent2-900);
    --a2-200: var(--accent2-800);
    --a2-300: var(--accent2-700);
    --a2-400: var(--accent2-600);
    --a2-500: var(--accent2-500);
    --a2-600: var(--accent2-600);
    --a2-700: var(--accent2-700);
    --a2-800: var(--accent2-800);
    --a2-900: var(--accent2-900);
    --a2-950: var(--accent2-950);
}
:root[data-scheme="contrast"] {
    color-scheme: dark;
    --page: 0 0 0;
    --raised: 20 20 20;
    --raised2: 20 20 20;
    --deep: 0 0 0;
    --deep2: 20 20 20;
    --card: 20 20 20;
    --white: 255 255 255;
    --black: 0 0 0;
    --on-accent: 255 255 255;
    --faint: 190 190 190;
    --hair: 0.6;
    --hair2: 0.85;
    --control-line: 0.9;
    --slate-50: 255 255 255;
    --slate-100: 255 255 255;
    --slate-200: 255 255 255;
    --slate-300: 242 242 242;
    --slate-400: 224 224 224;
    --slate-500: 190 190 190;
    --slate-600: 150 150 150;
    --slate-700: 118 118 118;
    --slate-800: 38 38 38;
    --slate-900: 20 20 20;
    --slate-950: 0 0 0;
    --gray-50: 255 255 255;
    --gray-100: 255 255 255;
    --gray-200: 255 255 255;
    --gray-300: 242 242 242;
    --gray-400: 224 224 224;
    --gray-500: 190 190 190;
    --gray-600: 150 150 150;
    --gray-700: 118 118 118;
    --gray-800: 38 38 38;
    --gray-900: 20 20 20;
    --gray-950: 0 0 0;
    --ok-fg: 134 239 172;
    --ok-line: 134 239 172;
    --ok-fill: 0 60 20;
    --warn-fg: 253 230 138;
    --warn-line: 253 230 138;
    --warn-fill: 70 40 0;
    --bad-fg: 254 202 202;
    --bad-line: 254 202 202;
    --bad-fill: 90 0 0;
    --lk-bg0: 0 0 0;
    --lk-bg1: 20 20 20;
    --lk-bg2: 38 38 38;
    --lk-line: 150 150 150;
    --lk-line2: 190 190 190;
    --lk-muted: 224 224 224;
    --lk-faint: 190 190 190;
    --lk-teal: 94 234 212;
    --lk-red: 255 140 140;
    --lk-on-teal: 0 0 0;
    --a-50: var(--accent-50);
    --a-100: var(--accent-100);
    --a-200: var(--accent-100);
    --a-300: var(--accent-100);
    --a-400: var(--accent-200);
    --a-500: var(--accent-500);
    --a-600: var(--accent-600);
    --a-700: var(--accent-700);
    --a-800: var(--accent-800);
    --a-900: var(--accent-900);
    --a-950: var(--accent-950);
    --a2-50: var(--accent2-50);
    --a2-100: var(--accent2-100);
    --a2-200: var(--accent2-100);
    --a2-300: var(--accent2-100);
    --a2-400: var(--accent2-200);
    --a2-500: var(--accent2-500);
    --a2-600: var(--accent2-600);
    --a2-700: var(--accent2-700);
    --a2-800: var(--accent2-800);
    --a2-900: var(--accent2-900);
    --a2-950: var(--accent2-950);
}

/* Status colours that the pages write as Tailwind classes, for the light and contrast schemes. */
:root[data-scheme="light"] .text-red-400 { color: rgb(var(--bad-fg)); }
:root[data-scheme="light"] .text-green-400 { color: rgb(var(--ok-fg)); }
:root[data-scheme="light"] .text-yellow-100,
:root[data-scheme="light"] .text-yellow-200,
:root[data-scheme="light"] .text-yellow-400 { color: rgb(var(--warn-fg)); }
:root[data-scheme="light"] .text-purple-400 { color: rgb(107 33 168); }
:root[data-scheme="light"] [class*="bg-yellow-900"] { background-color: rgb(var(--warn-fill)); }
:root[data-scheme="light"] .border-yellow-600,
:root[data-scheme="light"] .border-yellow-700 { border-color: rgb(var(--warn-line)); }
:root[data-scheme="light"] .bg-emerald-400 { background-color: rgb(22 163 74); }

/* Lines that the pages write as border-white/10 must show in the contrast scheme. */
:root[data-scheme="contrast"] [class*="border-white/"] { border-color: rgb(255 255 255 / 0.6); }
:root[data-scheme="contrast"] [class*="bg-white/"] { background-color: rgb(255 255 255 / 0.12); }
:root[data-scheme="contrast"] a { text-decoration: underline; }

/* The switch that picks the scheme: four icon buttons (templates/layout.html). */
.scheme-switch { display: inline-flex; gap: 0.15rem; padding: 0.15rem; border-radius: 0.6rem;
    border: 1px solid rgb(var(--white) / var(--hair2)); }
.scheme-switch button { display: inline-flex; align-items: center; justify-content: center; width: 1.75rem;
    height: 1.75rem; padding: 0; border: 0; border-radius: 0.45rem; background: transparent;
    color: rgb(var(--slate-400)); cursor: pointer; }
.scheme-switch button:hover { color: rgb(var(--white)); background: rgb(var(--white) / 0.08); }
.scheme-switch button[aria-pressed="true"] { color: rgb(var(--white)); background: rgb(var(--white) / 0.16); }
.scheme-switch button:focus-visible { outline: 2px solid rgb(var(--a-400)); outline-offset: 1px; }
.scheme-switch svg { width: 1rem; height: 1rem; }

/*
 * More difference between a control and what is behind it, and links that can be found.
 * The pages were written with faint Tailwind borders (white at 10 or 15 percent, gray-600
 * and gray-700, which the light scheme turns pale); these take their strength from the
 * scheme's tokens instead. ":root" in front makes them win over the utility classes.
 */
:root .border-white\/10,
:root .border-white\/15,
:root .border-white\/20 { border-color: rgb(var(--white) / var(--hair2)); }
:root .border-gray-600,
:root .border-gray-700,
:root .border-slate-600,
:root .border-slate-700 { border-color: rgb(var(--white) / var(--control-line)); }
:root input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]):not(.border-0),
:root select,
:root textarea { border-width: 1px; border-style: solid; border-color: rgb(var(--white) / var(--control-line)); }
:root input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]):focus,
:root select:focus,
:root textarea:focus { border-color: rgb(var(--a-400)); }
/* links in the footer and in running text */
:root footer a { color: rgb(var(--a-300)); text-decoration: underline; text-underline-offset: 3px; }
:root footer a:hover { color: rgb(var(--white)); }
