/*
 * diablo-theme.css: the /hierarchies/ newsreader look for the Diablo feeder
 * statistics in /diablo/.
 *
 * Those pages are written by feeder-stats.pl (HTML 4, colours in bgcolor= and
 * <font color=> attributes).  They are not edited: Apache adds a <link> to
 * this file and a <script> for diablo-theme.js to their <head> as they are
 * served (mod_substitute, see usenet.conf), so every page, old or new, gets
 * the look.  Author CSS always wins over those presentational attributes.
 *
 * Each colour is light-dark(<light>, <dark>), as in /hierarchies/style.css;
 * the light/dark choice ("theme" in localStorage) is shared with it.
 */

:root {
  color-scheme: light dark;
  /*                      light (paper)  dark (phosphor) */
  --bg:           light-dark(#fafadc, #070b07);
  --fg:           light-dark(#1c2a1a, #b8f0b0);
  --fg-bright:    light-dark(#000000, #e8ffe4);
  --fg-dim:       light-dark(#56664f, #7fae78);
  --rule:         light-dark(#c4c08e, #2f5a2c);
  --link:         light-dark(#0b4fb3, #6ab0ff);
  --link-visited: light-dark(#6b3fa0, #b39dff);
  --panel:        light-dark(#f0f0cc, #0d140d);
  --head:         light-dark(#e2e0b4, #15261a);
  --scanline:     light-dark(transparent, rgba(255, 255, 255, 0.018));
  --glow:         light-dark(transparent, rgba(184, 240, 176, 0.35));

  /* Size colours of feeder-stats.pl: GB red, MB blue, KB green. */
  --size-gb:      light-dark(#a8140f, #ff8a7a);
  --size-mb:      light-dark(#1a2fa8, #9cc0ff);
  --size-kb:      light-dark(#2a5c14, #9fe08f);

  /* Outgoing queue fill levels (legend and rows), lowest to highest. */
  --q20:          light-dark(#d6efcf, #12301a);
  --q35:          light-dark(#a9d9a0, #1d4a22);
  --q50:          light-dark(#bcd5f0, #14324c);
  --q65:          light-dark(#f2eda6, #44420f);
  --q80:          light-dark(#f5c788, #5a380a);
  --q95:          light-dark(#f2ada4, #601818);
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

html {
  background-color: var(--bg);
}

body {
  margin: 0;
  padding: 1.5rem 2ch 3rem;
  font-family: "IBM Plex Mono", "DejaVu Sans Mono", "Menlo", "Consolas",
    "Liberation Mono", "Courier New", monospace;
  font-size: 15px;   /* as / and /hierarchies/ */
  line-height: 1.45;
  color: var(--fg);
  background-color: var(--bg);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--scanline) 0,
    var(--scanline) 1px,
    transparent 1px,
    transparent 3px
  );
  text-shadow: 0 0 1px var(--glow);
}

::selection {
  color: var(--bg);
  background-color: var(--fg);
  text-shadow: none;
}

tt,
pre {
  font-family: inherit;
  font-size: 1em;
}

a:link {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:visited {
  color: var(--link-visited);
}

a:hover,
a:focus-visible,
a:active {
  color: var(--bg);
  background-color: var(--link);
  text-decoration: none;
  text-shadow: none;
  outline: none;
}

b,
strong {
  color: var(--fg-bright);
}

/* Title: the first table (logo + "DIABLO statistics for ..."), as the
   inverse-video title bar of the newsreader.  feeder-stats.pl writes it as
   <table border="0">, so it also matches the statistics tables'
   table[border] rules below: its size, line height and border are reset
   here, so the bar matches the title bars of / and /hierarchies/. */
body > table:first-of-type {
  display: table;   /* not the phone layout's scrolling block (below) */
  width: 100%;
  margin: 0 0 1rem;
  font-size: 1em;
  line-height: 1.45;
  border: 0;
  border-collapse: collapse;
  color: var(--bg);
  background-color: var(--fg);
  text-shadow: none;
}

body > table:first-of-type td {
  padding: 0.25rem 1ch;
  white-space: normal;
  border: 0;
  vertical-align: middle;
}

body > table:first-of-type td:first-child {
  width: 1px;
}

/* logo.gif is the BWH logo drawn at 2x (100x100, see www/logo/): shown at
   50x50, with its pixels kept square. */
/* The logo link holds a space before the image; line-height 0 keeps it
   from adding to the bar's height (58px, as on /). */
body > table:first-of-type td:first-child a {
  display: block;
  line-height: 0;
  text-decoration: none;
}

body > table:first-of-type td:first-child a:hover,
body > table:first-of-type td:first-child a:focus-visible {
  background: none;
  outline: 2px solid var(--bg);
  outline-offset: 2px;
}

body > table:first-of-type img {
  display: block;
  width: 50px;
  height: 50px;
  image-rendering: pixelated;
}

body > table:first-of-type h3 {
  margin: 0;
  font-size: 1em;
  color: var(--bg);
}

body > table:first-of-type h3::after {
  content: "\2588";
  margin-left: 0.5ch;
  font-weight: normal;
  animation: cursor 1.1s steps(1) infinite;
}

body > table:first-of-type i {
  font-style: normal;
}

body > table:first-of-type a:link,
body > table:first-of-type a:visited {
  color: var(--bg);
}

body > table:first-of-type a:hover,
body > table:first-of-type a:focus-visible {
  color: var(--fg);
  background-color: var(--bg);
}

@keyframes cursor {
  50% {
    opacity: 0;
  }
}

/* Light/dark switch and command bar, added by diablo-theme.js. */
.theme-bar {
  margin: 0 0 0.5rem;
}

.theme-switch {
  margin: 0;
  padding: 0;
  font: inherit;
  font-weight: bold;
  color: var(--link);
  background: none;
  border: 0;
  cursor: pointer;
  text-shadow: inherit;
}

.theme-switch::before {
  content: "[ ";
  color: var(--fg-dim);
}

.theme-switch::after {
  content: " ]";
  color: var(--fg-dim);
}

.theme-switch:hover,
.theme-switch:focus-visible {
  color: var(--bg);
  background-color: var(--link);
  text-shadow: none;
  outline: none;
}

.navigation {
  margin: 0 0 1.5rem;
  padding: 0.4rem 1ch;
  color: var(--fg-dim);
  border-top: 1px dashed var(--rule);
  border-bottom: 1px dashed var(--rule);
}

.navigation::before {
  content: "Go to: ";
}

.navigation a {
  font-weight: bold;
}

/* Section headings, as in control.ctl: "## 1. Summary of ...". */
body > h3 {
  margin: 1.5rem 0 0.8rem;
  font-size: 1em;
  text-align: left;
  color: var(--fg-bright);
}

body > h3::before {
  content: "## ";
  color: var(--fg-dim);
}

hr {
  height: 0;
  margin: 1.5rem 0;
  border: 0;
  border-top: 1px dashed var(--rule);
}

/* Table of contents and system status. */
ol {
  margin: 0.5rem 0 1rem;
  padding-left: 4ch;
}

ol li::marker {
  color: var(--fg-dim);
}

pre {
  margin: 0.4rem 0 0.8rem;
  padding: 0.6rem 1.5ch;
  overflow-x: auto;
  background-color: var(--panel);
  border: 1px dashed var(--rule);
}

/* Statistics tables. */
table[border] {
  border-collapse: collapse;
  font-size: 13px;
  border: 1px solid var(--rule);
}

table[border] th,
table[border] td {
  padding: 0.15rem 0.8ch;
  white-space: nowrap;
  border: 1px solid var(--rule);
}

table[border] th {
  color: var(--fg-bright);
  background-color: var(--head);
}

tr[bgcolor="#C5C5C5"] {
  background-color: var(--panel);
}

tr[bgcolor="#DFDFDF"] {
  background-color: var(--bg);
}

font[color="#C01010"] {
  color: var(--size-gb);
}

font[color="#1020A0"] {
  color: var(--size-mb);
}

font[color="#255510"] {
  color: var(--size-kb);
}

td[bgcolor="lightgreen"] {
  background-color: var(--q20);
}

td[bgcolor="green"] {
  background-color: var(--q35);
}

td[bgcolor="lightblue"] {
  background-color: var(--q50);
}

td[bgcolor="lightyellow"] {
  background-color: var(--q65);
}

td[bgcolor="orange"] {
  background-color: var(--q80);
}

td[bgcolor="red"] {
  background-color: var(--q95);
}

/* Graphs: white PNGs from GD.  On paper they are multiplied into the cream;
   on the terminal they are inverted, with the hues turned back so the feed
   colours keep their meaning. */
img[alt="Graph"] {
  display: block;
  max-width: 100%;
  height: auto;
  mix-blend-mode: multiply;
}

:root[data-theme="dark"] img[alt="Graph"] {
  mix-blend-mode: normal;
  filter: invert(0.92) hue-rotate(180deg);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) img[alt="Graph"] {
    mix-blend-mode: normal;
    filter: invert(0.92) hue-rotate(180deg);
  }
}

table[align="center"] {
  margin: 0.5rem auto;
}

table[align="center"] td {
  padding: 0;
}

@media (prefers-reduced-motion: reduce) {
  body > table:first-of-type h3::after {
    animation: none;
  }
}

@media (max-width: 600px) {
  body {
    font-size: 13px;
    padding: 1rem 1ch 2rem;
  }

  /* Wide statistics tables scroll inside their own box instead of pushing
     the page sideways (the pages get a viewport <meta> from Apache). */
  table[border] {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    font-size: 12px;
  }
}

/* Paper does not glow. */
@media print {
  :root,
  :root[data-theme] {
    color-scheme: light;
  }

  body {
    background-image: none;
    text-shadow: none;
  }

  img[alt="Graph"] {
    filter: none !important;
    mix-blend-mode: normal !important;
  }

  body > table:first-of-type h3::after,
  .theme-bar,
  .navigation {
    display: none;
  }
}
