/* 7earth: a newspaper set on a character grid.

   Every box is a whole number of character cells: 1ch wide, one line (--lh) tall.
   Margins and paddings are multiples of --lh vertically and of 1ch horizontally,
   rules are drawn inside a line instead of between lines, so nothing pushes the text off the grid.
   .x2 and .x3 set text at double and triple size: each letter then takes 2x2 or 3x3 cells.

   Themes set the font and the colours (data-theme on <html>). The colours come from the CVF palettes. */

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../fonts/ibm-plex-mono-normal-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../fonts/ibm-plex-mono-normal-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(../fonts/ibm-plex-mono-normal-bold-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(../fonts/ibm-plex-mono-normal-bold-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url(../fonts/ibm-plex-mono-italic-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url(../fonts/ibm-plex-mono-italic-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: italic;
  font-weight: 700;
  font-display: swap;
  src: url(../fonts/ibm-plex-mono-italic-bold-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: italic;
  font-weight: 700;
  font-display: swap;
  src: url(../fonts/ibm-plex-mono-italic-bold-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}


/* ---- tokens ------------------------------------------------------------ */

:root {
  --font: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace;
  --fs: 16px;
  --lh: 1.25rem;
  --page: 64ch;
  --hair: 1px;
  /* The server sets these per page: black and white, or the means of the end colours of a palette
     (CVF16.01 on the CVF pages, GRAYSCALE16 on the grey one); the shadow is the middle colour of CVF03.01. */
  --paper-dark: #000000;
  --paper-light: #FFFFFF;
  --plate-shadow: #C700EF;
}

/* paper: black ink on light paper, the CVF06 colours for accents */
:root, [data-theme="paper"] {
  --bg: var(--paper-light);
  --fg: #000000;
  --muted: #776139;
  --rule: #000000;
  --link: #000ABD;
  --link-hover: #AF0500;
  --kicker: #AF0500;
  --c1: #000ABD;
  --c2: #1694CA;
  --c3: #776139;
  --c4: #AF0500;
  --c5: #FFAA00;
  --plate-ink: #000000;
  --mark: #FFAA00;
  color-scheme: light;
}
/* dark: the browser's choice unless the reader chose light (data-mode, set from the "mode" cookie), or the reader's choice */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --bg: var(--paper-dark);
    --fg: #FFFFFF;
    --muted: #7C7579;
    --rule: #7C7579;
    --link: #7196FF;
    --link-hover: #FFAA00;
    --kicker: #F15E6B;
    --c1: #FFAA00;
    --c2: #1694CA;
    --c3: #7196FF;
    --c4: #F15E6B;
    --c5: #95B1D5;
    --plate-ink: #FFFFFF;
    --mark: #776139;
    color-scheme: dark;
  }
}
:root[data-mode="dark"] {
  --bg: var(--paper-dark);
  --fg: #FFFFFF;
  --muted: #7C7579;
  --rule: #7C7579;
  --link: #7196FF;
  --link-hover: #FFAA00;
  --kicker: #F15E6B;
  --c1: #FFAA00;
  --c2: #1694CA;
  --c3: #7196FF;
  --c4: #F15E6B;
  --c5: #95B1D5;
  --plate-ink: #FFFFFF;
  --mark: #776139;
  color-scheme: dark;
}

/* A new theme is a block like this one, with its own font (add its @font-face above):
[data-theme="example"] { --font: "Some Mono", monospace; --link: #...; ... } */

/* ---- base -------------------------------------------------------------- */

* { box-sizing: border-box; }

html {
  font-family: var(--font);
  font-size: var(--fs);
  line-height: var(--lh);
  background: var(--bg);
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  font-kerning: none;
  font-variant-ligatures: none;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0 auto;
  padding: var(--lh) 2ch;
  max-width: calc(var(--page) + 4ch);
  background: var(--bg);
}
body.frontpage { --page: 98ch; }
body.archive { --page: 98ch; }

h1, h2, h3, h4, h5, h6, p, ul, ol, pre, figure, blockquote, table, dl {
  margin: 0 0 var(--lh);
  font-size: 1rem;
  line-height: var(--lh);
}
h1, h2, h3, h4, h5, h6 { font-weight: 700; }

.x2 { font-size: 2rem; line-height: calc(2 * var(--lh)); font-weight: 700; }
.x3 { font-size: 3rem; line-height: calc(3 * var(--lh)); font-weight: 700; }
.x2 + *, .x3 + * { margin-top: 0; }
.c1 { color: var(--c1); } .c2 { color: var(--c2); } .c3 { color: var(--c3); }
.c4 { color: var(--c4); } .c5 { color: var(--c5); } .muted { color: var(--muted); }
.center { text-align: center; }

/* Links are told by their colour alone, as on the old site; hovering changes only the colour. */
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }
h1 a, h2 a, h3 a, h4 a { color: inherit; }
h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover { color: var(--link-hover); }

strong { font-weight: 700; }
em { font-style: italic; }
code { font-family: inherit; color: var(--c2); }

ul, ol { padding: 0; }
ul { list-style: none; }
ul > li { padding-left: 3ch; text-indent: -3ch; }
ul > li::before { content: "-  "; color: var(--muted); }
ol { list-style: none; counter-reset: ol; }
ol > li { counter-increment: ol; padding-left: 4ch; text-indent: -4ch; }
ol > li::before { content: counter(ol) ". "; display: inline-block; width: 4ch; text-indent: 0; color: var(--muted); }

blockquote { padding-left: 3ch; position: relative; font-style: italic; }
blockquote::before { content: "\2502"; position: absolute; left: 0; color: var(--muted); }
blockquote p { margin: 0; }
blockquote footer { font-style: normal; color: var(--muted); text-align: right; }

pre { white-space: pre; overflow-x: auto; }
pre code { color: inherit; }

figure img, p img { display: block; max-width: 100%; height: auto; }

/* A rule takes one whole line and draws its hairline in the middle. */
hr {
  border: 0;
  height: var(--lh);
  margin: 0 0 var(--lh);
  background: linear-gradient(var(--rule), var(--rule)) 0 50% / 100% var(--hair) no-repeat;
}
hr.thick { background-size: 100% 3px; }

/* ---- tables: borders as shadows, so a row is exactly one line ------------ */

.table { overflow-x: auto; margin: 0 0 var(--lh); }
.table table { margin: 0; }
table { border-collapse: collapse; }
th, td { padding: 0 1ch; text-align: left; vertical-align: top; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 0; }
th { font-weight: 700; box-shadow: inset 0 calc(-1 * var(--hair)) var(--rule); }
td.ar, th.ar { text-align: right; }
td.ac, th.ac { text-align: center; }
tbody tr:hover td { background: color-mix(in srgb, var(--mark) 25%, transparent); }

/* A colour swatch: two cells of solid colour, whatever glyphs the font has. */
.sw {
  display: inline-block;
  width: 2ch;
  height: var(--lh);
  vertical-align: top;
  overflow: hidden;
  line-height: var(--lh);
}
td .sw:first-child { margin-left: 0; }

/* ---- top bar (article pages) -------------------------------------------- */

.top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 2ch;
  padding-bottom: var(--lh);
  margin-bottom: var(--lh);
  background: linear-gradient(var(--rule), var(--rule)) 0 calc(100% - var(--lh) / 2) / 100% 3px no-repeat;
}
.top .brand { font-weight: 700; color: var(--fg); text-decoration: none; }
.top .brand::before { content: "\2588\2588 "; color: var(--plate-shadow); }
.top nav { display: flex; flex-wrap: wrap; gap: 0 2ch; }

/* ---- story head ----------------------------------------------------------- */

.kicker { text-transform: uppercase; color: var(--kicker); margin-bottom: 0; }
.deck { font-style: italic; }
.byline { color: var(--muted); }
.story-head { margin-bottom: 0; }
.story-head .byline {
  padding-bottom: var(--lh);
  background: linear-gradient(var(--rule), var(--rule)) 0 calc(100% - var(--lh) / 2) / 100% var(--hair) no-repeat;
}
/* In a story the title is h1, so the source's ## is h3 and ### is h4. */
.story h2, .story h3 { text-transform: uppercase; color: var(--c1); }
.story h3.x2, .story h3.x3 { text-transform: none; }
.story h4 { color: var(--c2); }
.story h5 { font-style: italic; }
/* The archive: entries apart, the date over a big title. */
.archive .story h4.x2 { color: var(--fg); margin-bottom: 0; }
.archive .story hr { margin-bottom: 0; }
.archive .story .deck { margin-bottom: var(--lh); }

/* ---- front page ------------------------------------------------------------- */

/* The top line: the old version on the left, the topics in the middle, the about page on the right. */
.ears {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 3ch;
  text-transform: uppercase;
}
/* MODERN DARK ISSUE / MODERN LIGHT ISSUE: the word shown is the mode in use, and links to the other one. */
.is-dark { display: none; }
:root[data-mode="dark"] .is-dark { display: inline; }
:root[data-mode="dark"] .is-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) .is-dark { display: inline; }
  :root:not([data-mode="light"]) .is-light { display: none; }
}

.plate { text-align: center; margin: var(--lh) 0; line-height: 0; }
.nameplate {
  display: inline-block;
  width: min(calc(var(--cols) * 1ch), 100%);
  height: auto;
}
.nameplate .ink { fill: var(--plate-ink); }
.nameplate .shadow { fill: var(--plate-shadow); }

.motto { text-align: center; font-style: italic; color: var(--muted); }

/* Three lines: a double rule, the date line, a double rule. */
.dateline {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 2ch;
  padding: var(--lh) 0;
  margin-bottom: var(--lh);
  text-transform: uppercase;
  --d: linear-gradient(var(--rule), var(--rule));
  background:
    var(--d) 0 calc(var(--lh) / 2 - 3px) / 100% var(--hair) no-repeat,
    var(--d) 0 calc(var(--lh) / 2 + 1px) / 100% var(--hair) no-repeat,
    var(--d) 0 calc(100% - var(--lh) / 2 - 2px) / 100% var(--hair) no-repeat,
    var(--d) 0 calc(100% - var(--lh) / 2 + 2px) / 100% var(--hair) no-repeat;
}

main.front { display: grid; grid-template-columns: minmax(0, 1fr); }
/* The initial fills two lines: its top meets the top of the capitals of the first line, its foot the baseline
   of the second (IBM Plex Mono: capitals 0.698 em, ascent 1.025 em, descent 0.275 em, advance 0.6 em).
   It stands in the middle of a box of 3 cells by 2 lines, so the text beside it stays on the grid. */
.lead .cols > p:first-child::first-letter {
  float: left;
  /* Browsers ignore a width on ::first-letter: the glyph is 2.8 x 0.6 = 1.68rem, padded to 3 cells of 0.6rem. */
  padding: 0 0.06rem;
  height: calc(2 * var(--lh));
  margin-right: 0.6rem;
  font-size: 2.8rem;
  line-height: 2.4rem;
  font-weight: 700;
  font-style: italic;
  text-align: center;
  color: var(--c1);
}
.lead .more, .teaser .more { text-align: right; }
.teaser { padding-top: var(--lh); background: linear-gradient(var(--rule), var(--rule)) 0 calc(var(--lh) / 2) / 100% var(--hair) no-repeat; }
.teaser .deck { margin-bottom: 0; }
.teaser .more { margin-bottom: var(--lh); }
.below { grid-column: 1 / -1; }

@media (min-width: 66em) {
  main.front { grid-template-columns: 64ch 31ch; column-gap: 3ch; }
  .lead .cols { columns: 2; column-gap: 2ch; column-rule: var(--hair) solid var(--rule); }
  .lead .cols p { break-inside: avoid-column; }
  .rail {
    border-left: var(--hair) solid var(--rule);
    padding-left: calc(1.5ch - var(--hair));
    margin-left: -1.5ch;
  }
  .rail .teaser:first-child { padding-top: 0; background: none; }
}

/* ---- footer --------------------------------------------------------------- */

.foot {
  color: var(--muted);
  padding-top: var(--lh);
  background: linear-gradient(var(--rule), var(--rule)) 0 calc(var(--lh) / 2) / 100% 3px no-repeat;
}
.foot p { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 2ch; }

/* ---- the grid itself, for checking: add ?grid to the address ---------------- */

.show-grid body {
  background-image:
    repeating-linear-gradient(to bottom, color-mix(in srgb, var(--c2) 30%, transparent) 0 1px, transparent 1px var(--lh)),
    repeating-linear-gradient(to right, color-mix(in srgb, var(--c4) 20%, transparent) 0 1px, transparent 1px 1ch);
  background-origin: content-box;
}

@media (max-width: 40em) {
  body { padding: var(--lh) 1ch; }
  .x3 { font-size: 2rem; line-height: calc(2 * var(--lh)); }
  .x2 { font-size: 1rem; line-height: var(--lh); font-weight: 700; }
}

@media print {
  :root { --bg: #FFFFFF; --fg: #000000; --rule: #000000; }
  .top nav, .foot a { display: none; }
}
