:root {
  --paper: #f5f4f1;
  --ink: #262523;
  --ink-soft: #6f6d68;
  --ink-faint: #9b9892;
  --rule: #e0ddd6;
  --underline: #c2bfb7;

  /* Left rail. Narrow by default: the off-centre composition is a wide-screen
     move, and on a phone it only steals width from the text. */
  --rail: 1.5rem;
  /* The text column's width, and the breathing room between it and the ASCII
     block. Everything in the right-hand composition is measured off these, so
     the two stay in step at any zoom level. */
  --measure: 30rem;
  --gutter: 4rem;
  /* Width left over beside the text column. */
  --spare: calc(100vw - var(--rail) - var(--measure));
}

/* Dark applies when the OS asks for it and the visitor has not chosen light,
   or when they have explicitly chosen dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1a1917;
    --ink: #fff7f0;
    --ink-soft: #97938c;
    --ink-faint: #6a665f;
    --rule: #2d2b27;
    --underline: #4a4640;
  }
}

:root[data-theme="dark"] {
  --paper: #1a1917;
  --ink: #fff7f0;
  --ink-soft: #97938c;
  --ink-faint: #6a665f;
  --rule: #2d2b27;
  --underline: #4a4640;
}

/* Above this width there is room to hang the column off a deep left rail and
   let the leftover space collect on the right instead of splitting evenly. */
@media (min-width: 60rem) {
  :root { --rail: clamp(2rem, 18vw, 16rem); }
}

* { box-sizing: border-box; }

html {
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 2rem var(--rail) 10rem;
  color: var(--ink);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

nav,
.hero,
main {
  max-width: var(--measure);
}

/* One ink colour throughout; the underline is the only link affordance, kept
   faint until hover. Taken from daoho.dev's .ink-link. */
a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--underline);
  text-underline-offset: 4px;
  transition: text-decoration-color 0.15s ease;
}

a:hover,
a:focus-visible { text-decoration-color: currentColor; }

a:focus-visible {
  outline: 1px solid var(--underline);
  outline-offset: 3px;
  border-radius: 2px;
}

nav {
  display: flex;
  gap: 1.5rem;
  margin-bottom: min(20vh, 11rem);
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

nav a { text-decoration: none; }
nav a:hover,
nav a:focus-visible {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 4px;
}

nav .here { color: var(--ink); }

/* Theme toggle. Sits with the nav links and reads as one of them. */
.theme {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.theme:hover,
.theme:focus-visible { color: var(--ink); }

.theme:focus-visible {
  outline: 1px solid var(--underline);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Only the icon for the theme you would switch *to* is shown. */
.theme .to-light { display: none; }
:root[data-theme="dark"] .theme .to-light { display: inline; }
:root[data-theme="dark"] .theme .to-dark { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme .to-light { display: inline; }
  :root:not([data-theme="light"]) .theme .to-dark { display: none; }
}

/* The ASCII animation that occupies the right-hand negative space. Decorative
   only: it never takes pointer events or a place in the accessibility tree, and
   it is hidden at the widths where there is no space to spare. */
#ascii {
  position: fixed;
  top: 50%;
  /* Centred in whatever is actually left over to the right of the text column.
     Deriving this from --rail rather than assuming its maximum keeps the block
     in the same place at every window width and zoom level; the old fixed
     46rem only lined up when the rail happened to be at its 16rem cap. */
  left: calc(var(--rail) + var(--measure) + var(--spare) / 2);
  transform: translate(-50%, -50%);
  margin: 0;
  z-index: -1;
  color: var(--ink-soft);
  /* The grid is 64 x 32 characters and the font advance is 0.6em, so the block
     is 38.4em wide and 32em tall. Dividing the spare width by 42 leaves a
     little slack at the edges; the vh term caps it against a short window. */
  font-size: clamp(9px, min(calc((var(--spare) - var(--gutter)) / 42), 2.3vh), 30px);
  line-height: 1;
  white-space: pre;
  pointer-events: none;
  user-select: none;
  opacity: 0.72;
}

/* Below this the leftover strip is narrower than the block at its 9px floor,
   so it would start crowding the text column. 64 cols x 0.6em x 9px = 346px,
   against a spare strip of ~386px here. */
@media (max-width: 66rem) {
  #ascii { display: none; }
}

p {
  margin: 0 0 0.9rem;
  text-wrap: pretty;
}

.hero p:last-child { margin-bottom: 0; }

.lede {
  margin-bottom: 1.6rem;
  font-size: 1.0625rem;
  font-weight: 500;
}

.quiet { color: var(--ink-soft); }

h1 {
  margin: 0 0 1.5rem;
  font-size: 1.0625rem;
  font-weight: 500;
}

/* Section labels. Quiet, but still readable — they sit a step below the body
   text, not two. */
h2 {
  margin: 0 0 1rem;
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  color: var(--ink-soft);
}

section { margin-top: 5rem; }

/* Coursework and research. Annotations sit directly after the item, in faint
   ink — close enough to read as belonging to it. */
.stack {
  margin: 0;
  padding: 0;
  list-style: none;
}

.stack li { padding: 0.08rem 0; }

.ann {
  color: var(--ink-faint);
  white-space: nowrap;
}

.note {
  margin: 1.25rem 0 0;
  font-size: 0.8125rem;
  color: var(--ink-faint);
}

.contact {
  margin-top: 5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-soft);
}

/* Blog posts. */
article {
  margin-bottom: 2.5rem;
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--rule);
}

article:last-of-type {
  margin-bottom: 2rem;
  padding-bottom: 0;
  border-bottom: 0;
}

article h2 {
  margin: 0 0 0.35rem;
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
}

article p { margin-bottom: 0.5rem; }
article p:last-child { margin-bottom: 0; }

.meta {
  font-size: 0.8125rem;
  color: var(--ink-faint);
}

/* Theme wipe. The toggle sits at the top right, so the incoming theme is
   revealed from the right edge inward — it reads as the switch sweeping across
   the page rather than the colours simply cross-fading.

   This is the View Transitions API: the browser snapshots the page before and
   after the data-theme flip and gives us the two layers to animate. Browsers
   without it just flip, which is the behaviour the site had before. */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-old(root) { z-index: 0; }

::view-transition-new(root) {
  z-index: 1;
  animation: theme-wipe 0.55s cubic-bezier(0.65, 0, 0.35, 1) both;
}

@keyframes theme-wipe {
  from { clip-path: inset(0 0 0 100%); }
  to { clip-path: inset(0 0 0 0); }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-new(root) { animation: none; }
}
