/*
 * usenet-hierarchies: a text-mode newsreader.  Dark mode is a phosphor
 * terminal, light mode the same newsreader printed on paper.
 *
 * Each colour is light-dark(<light>, <dark>).  The mode follows the system
 * setting (color-scheme: light dark), unless the visitor picks one with the
 * switch, which sets data-theme on <html> (see index.py).
 *
 * Only system monospace fonts are used (no web fonts, no external requests).
 * Headings borrow the "## " of control.ctl entries, the footer sits under
 * the "-- " signature separator, and <details> sections fold like threads.
 */

:root {
  color-scheme: light dark;
  /*                      light (paper)  dark (phosphor) */
  --bg:           light-dark(#fafadc, #070b07);   /* Julien's original cream */
  --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);   /* blue */
  --link-visited: light-dark(#6b3fa0, #b39dff);   /* violet-blue */
  --quote:        light-dark(#0e6b68, #7fd3d0);   /* quoted text */
  --key:          light-dark(#7a2f9a, #e0b0ff);
  --panel:        light-dark(#f0f0cc, #0d140d);
  --scanline:     light-dark(transparent, rgba(255, 255, 255, 0.018));
  --glow:         light-dark(transparent, rgba(184, 240, 176, 0.35));
}

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

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

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

body {
  margin: 0 auto;
  padding: 1.5rem 2ch 3rem;
  max-width: 104ch;
  font-family: "IBM Plex Mono", "DejaVu Sans Mono", "Menlo", "Consolas",
    "Liberation Mono", "Courier New", monospace;
  font-size: 15px;
  line-height: 1.45;
  text-align: left;
  /* Long URLs (the Big 8 example in the footer) must not widen the page. */
  overflow-wrap: anywhere;
  color: var(--fg);
  background-color: var(--bg);
  /* Faint CRT scan lines and phosphor glow (dark mode only). */
  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;
}

/* Links: blue, underlined like a terminal hyperlink; inverse on hover. */
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;
}

a,
strong {
  font-weight: bold;
}

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

em {
  font-style: normal;
  color: var(--fg-bright);
}

/* Title bar of the newsreader, in inverse video, with a blinking cursor. */
h1 {
  margin: 0 0 1rem;
  padding: 0.25rem 1ch;
  font-size: 1em;
  font-weight: bold;
  color: var(--bg);
  background-color: var(--fg);
  text-shadow: none;
}

h1::before {
  content: "usenet-hierarchies :: ";
  font-weight: normal;
}

h1::after {
  content: "\2588";       /* full block */
  margin-left: 0.5ch;
  font-weight: normal;
  animation: cursor 1.1s steps(1) infinite;
}

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

/* Command bar under the title. */
.navigation {
  margin: 0 0 1.5rem;
  padding: 0.4rem 1ch;
  text-align: left;
  color: var(--fg-dim);
  border-top: 1px dashed var(--rule);
  border-bottom: 1px dashed var(--rule);
}

.navigation::before {
  content: "Go to: ";
  color: var(--fg-dim);
}

/* Section headings, as in control.ctl: "## Hierarchy FR". */
h2 {
  margin: 2.2rem 0 0.8rem;
  padding: 0;
  font-size: 1em;
  font-weight: bold;
  color: var(--fg-bright);
  border: 0;
}

h2::before {
  content: "## ";
  color: var(--fg-dim);
}

p {
  margin: 1em 0;
}

/* Lists: one item per line, with a terminal bullet. */
ul {
  margin: 0.5rem 0 1rem;
  padding-left: 0;
  list-style: none;
}

li {
  position: relative;
  margin: 0.15em 0;
  padding-left: 3ch;
}

li::before {
  content: "*";
  position: absolute;
  left: 1ch;
  color: var(--fg-dim);
}

li p {
  margin: 0;
}

dl {
  margin: 1rem 0;
}

dt {
  margin-top: 1em;
  font-weight: bold;
  color: var(--fg-bright);
}

dd {
  margin: 0.2em 0 0 3ch;
}

/* Preformatted blocks: control files, keys, logs, newsgroups. */
pre,
code {
  font-family: inherit;
  font-size: 1em;
}

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

/* "# ..." comments read like quoted text. */
pre.comment {
  color: var(--quote);
  border-left: 2px solid var(--quote);
}

pre.key {
  color: var(--key);
}

pre.newsgroups {
  /* Long lists: keep them scannable. */
  max-height: 32em;
  overflow-y: auto;
}

code {
  display: block;
  color: var(--fg);
  background-color: var(--panel);
  border: 1px dashed var(--rule);
  overflow: auto;
}

/* Collapsible sections fold like threads: [+] closed, [-] open. */
details {
  margin: 0.4rem 0;
}

summary {
  cursor: pointer;
  list-style: none;
  color: var(--fg-dim);
}

summary::-webkit-details-marker {
  display: none;
}

summary::before {
  content: "[+] ";
  color: var(--link);
}

details[open] > summary::before {
  content: "[-] ";
}

summary:hover,
summary:focus-visible {
  color: var(--fg-bright);
  outline: none;
}

/* The footer is a signature: "-- " on a line of its own. */
hr {
  margin: 3rem 0 0;
  border: 0;
  height: auto;
  color: var(--fg-dim);
}

hr::before {
  content: "-- ";
  white-space: pre;
}

hr ~ p {
  color: var(--fg-dim);
}

hr ~ p em {
  color: var(--fg-dim);
}

.bottom {
  margin: 2rem 0 0;
  text-align: left;
}

.bottom a::before {
  content: "[ ";
}

.bottom a::after {
  content: " ]";
}

.intro {
  margin: 1em 0 0;
  font-weight: bold;
  clear: both;
}

input.formulaire,
textarea,
select {
  font-family: inherit;
  color: inherit;
  background-color: var(--panel);
  border: 1px solid var(--rule);
}

/* Light/dark switch, on its own line above the command bar.  Hidden in the
   HTML until its script runs, so it never shows without JavaScript. */
.theme-bar {
  margin: 0 0 0.5rem;
}

.theme-bar[hidden] {
  display: none;
}

.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;
}

@media (prefers-reduced-motion: reduce) {
  h1::after {
    animation: none;
  }
}

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

/* Paper does not glow. */
@media print {
  :root,
  :root[data-theme] {
    color-scheme: light;
    --bg: #fff;
    --fg: #000;
    --fg-bright: #000;
    --fg-dim: #444;
    --rule: #999;
    --link: #000;
    --link-visited: #000;
    --quote: #333;
    --key: #000;
    --panel: #fff;
  }

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

  h1 {
    color: #000;
    background: none;
    border-bottom: 2px solid #000;
  }

  h1::after,
  .theme-switch {
    display: none;
  }
}
