/* The rules behind this file are written down in STYLE.md. */

/* Three typefaces, one job each: Michroma labels things, IBM Plex Mono states
   facts, IBM Plex Serif carries prose that is meant to be read at length. */
@font-face {
  font-family: "Michroma";
  src: url("/fonts/michroma-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/fonts/plex-mono-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Serif";
  src: url("/fonts/plex-serif-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Serif";
  src: url("/fonts/plex-serif-400-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Serif";
  src: url("/fonts/plex-serif-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

/* Black and white. One colour is spent on attention: whatever is being
   pointed at, focused, selected or dragged. A second is spent on a single dot. */
:root {
  --ground: #000;
  --ink: #fff;
  --dim: #8c8c8c;
  --rule: #333;
  --attention: #ff4f00;
  --dot: #a9c8ee;

  --line: 1.5rem;
  --gutter: 11rem;
  --measure: 36rem;

  --label: "Michroma", "Eurostile", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --serif: "IBM Plex Serif", "Iowan Old Style", Georgia, serif;

  color-scheme: dark;
}

/* Light, when the reader has turned the switch at the top (theme.js). */
:root[data-theme="light"] {
  --ground: #fff;
  --ink: #000;
  --dim: #6e6e6e;
  --rule: #ccc;
  --attention: #e63c00;
  --dot: #4f86cf;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 0.9375rem / var(--line) var(--mono);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: var(--attention);
  color: #000;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--dim);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.3em;
}

a:hover {
  color: var(--attention);
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: 1px solid var(--attention);
  outline-offset: 0.25rem;
}

p {
  max-width: 62ch;
  margin: 0;
}

p + p {
  margin-top: var(--line);
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Page */

.page {
  max-width: 60rem;
  margin: 0 auto;
  padding: clamp(3rem, 12vh, 8rem) clamp(1.25rem, 6vw, 3rem) calc(var(--line) * 4);
}

/* Labels: section names, navigation */

h2,
.top nav a {
  margin: 0;
  color: var(--dim);
  font: 400 0.625rem / var(--line) var(--label);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* The top of every page: the name, and where else to go. Where the two do
   not fit side by side, the navigation goes underneath. */

.top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: calc(var(--line) / 2) 3ch;
  margin-bottom: calc(var(--line) * 4);
}

.mark {
  flex: none;
  width: 219px; /* 73 × 7 cells of 3px */
  height: 21px;
  background: currentColor;
  -webkit-mask: url("/name.svg") center / contain no-repeat;
  mask: url("/name.svg") center / contain no-repeat;
}

.mark:hover {
  color: var(--attention);
}

.top nav {
  display: flex;
  gap: 3ch;
}

.top nav a {
  text-decoration: none;
}

.top nav a[aria-current] {
  color: var(--ink);
}

.top nav a:hover {
  color: var(--attention);
}

/* The light switch: a circle, half filled, and the one icon on the site. It
   is as tall as a line so that it is easy to hit, and the circle is drawn in
   the middle of it. Turned, the circle is the other way round. */

.theme {
  appearance: none;
  flex: none;
  width: var(--line);
  height: var(--line);
  margin: 0 calc((0.625rem - var(--line)) / 2);
  padding: 0;
  border: 0;
  background: none;
  color: var(--dim);
  cursor: pointer;
}

.theme::before {
  content: "";
  display: block;
  width: 0.625rem;
  height: 0.625rem;
  margin: auto;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: linear-gradient(to right, transparent 50%, currentColor 50%);
}

:root[data-theme="light"] .theme::before {
  transform: rotate(180deg);
}

.theme:hover {
  color: var(--attention);
}

.top + * {
  margin-top: 0;
}

/* Figures: a stage, then a caption with an optional readout on the right */

figure {
  margin: 0;
}

figure :is(svg, img, canvas) {
  display: block;
  max-width: 100%;
  height: auto;
}

figcaption {
  display: flex;
  justify-content: space-between;
  gap: 3ch;
  margin-top: calc(var(--line) / 2);
  color: var(--dim);
  font: 400 0.8125rem / var(--line) var(--mono);
}

.readout {
  flex: none;
  font-variant-numeric: tabular-nums;
}

figure.live .readout {
  color: var(--attention);
}

/* Words in the pixel font, as wide as the page: the 404 page */

.signal {
  margin-bottom: calc(var(--line) * 3);
}

.signal svg {
  width: 100%;
  fill: currentColor;
}

.signal figcaption {
  margin-top: var(--line);
}

/* Fig. 1 on the home page: my light cone. A map around the Sun with a line
   to each bright star and, as a circle, the light that left Earth in 1993.
   Everything from here to "End of Fig. 1" belongs to that figure and to
   lightcone.js, and nothing else uses it.

   The drawing is a square, --s on a side, and the circle fills it: half of
   --s is as many light-years as the light has travelled (--front), which is
   all the script has to say. A star stands --x and --y light-years from the
   Sun. Left of the square there is room (--L) for the names of stars that
   lie outside the circle on that side. */

.cone {
  --s: 18rem;
  --L: 8rem;
  --track: 0.2em; /* between the letters of a name */
  margin: calc(var(--line) * 3) 0;
}

.cone .chart {
  position: relative;
  height: var(--s);
}

.cone.readable .chart {
  cursor: crosshair;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.cone svg {
  position: absolute;
  top: 0;
  left: var(--L);
  width: var(--s);
  max-width: none;
  height: var(--s);
  overflow: visible;
  fill: none;
  stroke: var(--dim);
}

.cone svg * {
  vector-effect: non-scaling-stroke;
}

/* One division for each year the light has travelled, on the line towards
   the centre of the Galaxy. */
.cone .years {
  stroke: var(--rule);
}

.cone :is(.axis, .light) {
  stroke: currentColor;
}

/* What the light has not reached yet is dotted. */
.cone .ray.ahead {
  stroke-dasharray: 2 3;
}

.cone [hidden] {
  display: none;
}

/* The line to the centre of the Galaxy leaves the circle and runs to the
   edge of the page, dotted: not reached, and from there on not to scale. Its
   name and its distance stand over the far end. */
.cone .beyond {
  position: absolute;
  top: calc(var(--s) / 2);
  right: 0;
  left: calc(var(--L) + var(--s) + 3px);
  height: 1px;
  background: repeating-linear-gradient(to right, var(--dim) 0 2px, transparent 2px 5px);
}

.cone .place {
  position: absolute;
  top: calc(var(--s) / 2 - var(--line));
  right: 0;
  color: var(--dim);
  line-height: var(--line);
  white-space: nowrap;
}

.cone .place .at {
  margin-left: 1ch;
}

/* A star: the point where its line ends. */
.cone .star {
  position: absolute;
  top: calc(var(--s) * (0.5 + var(--y) / (2 * var(--front))));
  left: calc(var(--L) + var(--s) * (0.5 + var(--x) / (2 * var(--front))));
  width: 0;
  height: 0;
  color: var(--dim);
}

/* Its name and its distance, set against that point by hand: --wx and --wy
   pixels across and down on a wide page, --nx and --ny on a narrow one. The
   offset is to the left edge of the name, or to its right edge with the
   class wR or nR. With w-stack or n-stack the number goes under the name, and
   with w-wrap or n-wrap the words take a line each within --ww or --nw. */
.cone .label {
  position: absolute;
  font-size: 0.8125rem;
  line-height: 14px;
  white-space: nowrap;
}

.cone .name {
  font: 400 0.625rem / 14px var(--label);
  letter-spacing: var(--track);
  text-transform: uppercase;
}

.cone .at {
  font-variant-numeric: tabular-nums;
}

/* A star can have one place for its name while the light has yet to reach
   it, outside the circle, and another once it has been passed. */
.cone .star.ahead .if-passed,
.cone .star:not(.ahead) .if-ahead {
  display: none;
}

/* Wide enough for the longest reading, so nothing beside it moves. */
.cone .readout {
  min-width: 21ch;
  text-align: right;
}

@media (min-width: 52rem) {
  .cone .label {
    top: calc(var(--wy) * 1px);
    left: calc(var(--wx) * 1px);
  }

  .cone .label.wR {
    right: calc(var(--wx) * -1px);
    left: auto;
    text-align: right;
  }

  .cone .label.w-stack .at {
    display: block;
  }

  .cone .label.w-wrap {
    width: calc(var(--ww) * 1px);
    white-space: normal;
  }

  /* The caption stands in the empty space right of the circle, level with
     its foot. If the caption and the readout do not fit on one line there,
     the readout takes the next one, still on the right. */
  .cone {
    display: grid;
    grid-template-columns: calc(var(--L) + var(--s) + var(--line) / 2) minmax(0, 1fr);
  }

  .cone .chart {
    grid-area: 1 / 1 / 2 / 3;
  }

  .cone figcaption {
    grid-area: 1 / 2;
    flex-wrap: wrap;
    align-self: end;
    gap: 0 3ch;
    margin-top: 0;
  }

  .cone figcaption > :first-child {
    white-space: nowrap;
  }

  .cone .readout {
    margin-left: auto;
  }
}

@media (max-width: 51.99rem) {
  /* The circle is as wide as the page allows once the room on its left is
     taken off. The clamp is the page's own padding at the sides. */
  .cone {
    --s: min(16.25rem, calc(100vw - 2 * clamp(1.25rem, 6vw, 3rem) - var(--L)));
    --L: 4.25rem;
    --track: 0.1em;
  }

  /* When no star on a narrow page stands outside the circle, the room on
     its left is given back to it. */
  .cone:not(:has(.star.ahead:not(.wide-only):not([hidden]))) {
    --L: 0rem;
  }

  .cone .label {
    top: calc(var(--ny) * 1px);
    left: calc(var(--nx) * 1px);
  }

  .cone .label.nR {
    right: calc(var(--nx) * -1px);
    left: auto;
    text-align: right;
  }

  .cone .label.n-stack .at {
    display: block;
  }

  .cone .label.n-wrap {
    width: calc(var(--nw) * 1px);
    white-space: normal;
  }

  /* No room outside the circle for the stars the light has yet to reach,
     apart from the nearest. */
  .cone .wide-only {
    display: none;
  }

  .cone figcaption {
    margin-top: var(--line);
  }
}

@media (max-width: 44rem) {
  /* No room beside the circle for a name at the end of the line to the
     centre: the line is the scale of years and nothing more. */
  .cone .beyond,
  .cone .place {
    display: none;
  }

  .cone .readout {
    min-width: 0;
    text-align: left;
  }
}

/* End of Fig. 1 */

/* Sections: a label in the margin, content beside it */

section,
footer {
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  align-items: baseline;
  margin-top: calc(var(--line) * 2);
}

/* A label keeps clear of what it labels, and takes a second line if it must. */

section > h2 {
  padding-right: var(--line);
}

/* Rows: key, value, note */

.rows {
  margin: 0;
  padding: 0;
  list-style: none;
}

.rows a {
  display: grid;
  grid-template-columns: 12ch minmax(0, 1fr) auto;
  column-gap: 2ch;
  text-decoration: none;
}

.rows .key,
.rows .note,
.more {
  color: var(--dim);
}

/* A row that a link elsewhere on the page has just pointed to */

.rows li {
  scroll-margin-top: calc(var(--line) * 2);
}

.rows li:target a {
  color: var(--attention);
}

/* A timeline: rows with a dot beside each key and a line through the dots.
   A milestone has an orange dot, and says what it marks when its key is
   pointed at. This is the one place where orange is shown at rest. */

.timeline {
  --dot-at: 6ch;
  --dot-size: 7px;
  --row-gap: 0rem;
}

.timeline li {
  position: relative;
}

.timeline li:not(:last-child)::before {
  content: "";
  position: absolute;
  top: calc(var(--line) / 2);
  left: calc(var(--dot-at) + var(--dot-size) / 2 - 0.5px);
  width: 1px;
  height: calc(100% + var(--row-gap));
  background: var(--rule);
}

.timeline li::after {
  content: "";
  position: absolute;
  top: calc((var(--line) - var(--dot-size)) / 2);
  left: var(--dot-at);
  width: var(--dot-size);
  height: var(--dot-size);
  border: 1px solid var(--dim);
  border-radius: 50%;
  background: var(--ground);
  pointer-events: none;
}

.timeline .milestone::after {
  border-color: var(--attention);
  background: var(--attention);
}

.timeline a {
  align-items: baseline;
}

.timeline .key {
  grid-area: 1 / 1;
  align-self: stretch;
}

.timeline .value {
  grid-area: 1 / 2;
}

.timeline .note {
  grid-area: 1 / 3;
}

.timeline .value,
.milestone-text {
  transition: opacity 0.2s;
}

/* The shorter line lets the small text sit on the baseline of the row without
   making the row taller. */

.milestone-text {
  grid-area: 1 / 2;
  color: var(--attention);
  font-size: 0.8125rem;
  line-height: 1.25rem;
  opacity: 0;
  pointer-events: none;
}

.milestone .key:hover ~ .value {
  opacity: 0;
}

.milestone .key:hover ~ .milestone-text {
  opacity: 1;
}

/* Where nothing can be pointed at, a milestone says what it marks all the time. */

@media (hover: none) {
  .milestone-text {
    grid-area: auto / 2;
    color: var(--dim);
    line-height: var(--line);
    opacity: 1;
  }
}

.more {
  margin-top: var(--line);
}

/* The end of every page */

footer {
  margin-top: calc(var(--line) * 4);
}

.dot {
  grid-column: 2;
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 1.5ch;
  min-width: var(--line);
  min-height: var(--line);
  color: var(--dim);
  font-size: 0.8125rem;
  text-decoration: none;
}

.dot::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--dot);
}

/* The one link that does not turn orange: its label takes the colour of the dot. */
.dot:hover,
.dot:focus-visible {
  color: var(--dot);
}

.dot span {
  opacity: 0;
  transition: opacity 0.2s;
}

.dot:hover span,
.dot:focus-visible span {
  opacity: 1;
}

/* A piece of writing: date and kind in the margin, title beside them */

.post > header {
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  align-items: baseline;
  margin-bottom: calc(var(--line) * 2);
}

.post .meta {
  display: flex;
  flex-direction: column;
  color: var(--dim);
  font-size: 0.8125rem;
}

.post h1 {
  max-width: var(--measure);
  margin: 0;
  font: 400 1.25rem / calc(var(--line) * 1.5) var(--label);
  text-wrap: balance;
}

.post .lede {
  grid-column: 2;
  max-width: var(--measure);
  margin-top: var(--line);
  color: var(--dim);
}

/* Prose. Everything sits in the text column; h2 sits in the margin beside
   whatever follows it; anything marked .wide spans both. */

.prose {
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  align-items: baseline;
  row-gap: var(--line);
  font: 400 1.0625rem / 1.75rem var(--serif);
}

.prose > * {
  grid-column: 2;
  min-width: 0;
  max-width: var(--measure);
  margin: 0;
}

.prose > h2 {
  grid-column: 1;
  padding-right: 2ch;
}

.prose > h2:has(+ :is(figure, pre, table, hr)) {
  align-self: start;
}

.prose > h2,
.prose > h2 + * {
  margin-top: var(--line);
}

.prose > h3 {
  margin-top: var(--line);
  font: 400 0.6875rem / var(--line) var(--label);
  letter-spacing: 0.08em;
}

.prose > :is(figure, pre, table) {
  max-width: 100%;
}

.prose > .wide {
  grid-column: 1 / -1;
  max-width: 100%;
}

.prose p {
  max-width: none;
}

.prose strong {
  font-weight: 600;
}

.prose blockquote {
  padding-left: var(--line);
  border-left: 1px solid var(--dim);
}

.prose blockquote footer {
  display: block;
  margin-top: calc(var(--line) / 2);
  color: var(--dim);
  font: 400 0.8125rem / var(--line) var(--mono);
}

.prose :is(ul, ol) {
  padding-left: var(--line);
}

.prose ul {
  list-style: "–  ";
}

.prose li::marker {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.875em;
}

.prose li + li {
  margin-top: calc(var(--line) / 4);
}

.prose :is(code, kbd, samp) {
  font: 400 0.875em var(--mono);
}

.prose pre {
  padding: calc(var(--line) / 2) 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  overflow-x: auto;
  font: 400 0.8125rem / var(--line) var(--mono);
}

.prose pre code {
  font: inherit;
}

.prose hr {
  justify-self: start;
  width: 3rem;
  height: 0;
  border: 0;
  border-top: 1px solid var(--dim);
}

.prose table {
  justify-self: start;
  border-collapse: collapse;
  border-top: 1px solid var(--dim);
  border-bottom: 1px solid var(--dim);
  font: 400 0.8125rem / var(--line) var(--mono);
  font-variant-numeric: tabular-nums;
}

.prose :is(th, td) {
  padding: calc(var(--line) / 4) 3ch calc(var(--line) / 4) 0;
  text-align: left;
  font-weight: 400;
  vertical-align: baseline;
}

.prose :is(th, td):last-child {
  padding-right: 0;
}

.prose th {
  border-bottom: 1px solid var(--rule);
  color: var(--dim);
}

.prose .num {
  text-align: right;
}

/* A raised mark: a note number in a post, a dagger after a name */
sup,
.prose sup {
  font: 400 0.75em / 0 var(--mono);
}

.prose sup a {
  padding: 0 0.15em;
  text-decoration: none;
}

.prose .footnotes {
  padding-top: var(--line);
  padding-left: 3ch;
  border-top: 1px solid var(--rule);
  color: var(--dim);
  font: 400 0.8125rem / var(--line) var(--mono);
}

.prose .footnotes li::marker {
  font-size: 1em;
}

/* Maths, set by KaTeX: flush left, like everything else */

.prose .katex {
  font-size: 1.08em;
}

.prose .katex-display {
  margin: 0;
  padding-left: var(--line);
  overflow-x: auto;
  overflow-y: hidden;
}

.prose .katex-display.fleqn > .katex {
  padding-left: 0;
}

/* Plates: photographs, uncropped, one after another */

.plates {
  display: grid;
  row-gap: calc(var(--line) * 4);
}

.plate img,
.plate .blank {
  max-height: 86vh;
  width: auto;
}

.plate .blank {
  width: min(100%, 86vh * var(--w) / var(--h));
  aspect-ratio: var(--w) / var(--h);
  border: 1px solid var(--rule);
}

/* Narrow screens: labels move above their content */

@media (max-width: 44rem) {
  .top {
    margin-bottom: calc(var(--line) * 3);
  }

  .mark {
    width: 146px; /* cells of 2px */
    height: 14px;
  }

  .top nav {
    gap: 2ch;
  }

  figcaption {
    flex-direction: column;
    gap: 0;
  }

  section,
  footer,
  .post > header,
  .prose {
    grid-template-columns: minmax(0, 1fr);
  }

  h2 {
    margin-bottom: calc(var(--line) / 2);
  }

  .rows a {
    grid-template-columns: 12ch minmax(0, 1fr);
  }

  .rows .note {
    grid-column: 2;
  }

  .rows li + li {
    margin-top: calc(var(--line) / 2);
  }

  .timeline {
    --row-gap: calc(var(--line) / 2);
  }

  .timeline .note {
    grid-area: 2 / 2;
  }

  .dot,
  .post .lede,
  .prose > *,
  .prose > h2 {
    grid-column: 1;
  }

  .post .meta {
    flex-direction: row;
    gap: 2ch;
    margin-bottom: calc(var(--line) / 2);
  }

  .prose > h2 {
    margin-bottom: calc(var(--line) / -2);
    padding-right: 0;
  }

  .prose > h2 + * {
    margin-top: 0;
  }

  .plates {
    row-gap: calc(var(--line) * 3);
  }
}

@media print {
  .theme {
    display: none;
  }

  :root {
    --ground: #fff;
    --ink: #000;
    --dim: #555;
    --rule: #bbb;
  }
}
