/*
  Tokens
  paper   #EDF0F2  cool grey-white sheet
  rule    #C9D0D6  drafting grid / hairlines
  ink     #101C2C  deep navy, all text
  graphite #55616E  secondary text
  cobalt  #1D3FD8  the one signal colour: links, live traffic
  alert   #B8321F  a failed node, nothing else
*/

:root {
  --paper: #edf0f2;
  --paper-2: #e4e8eb;
  --rule: #c9d0d6;
  --ink: #101c2c;
  --graphite: #55616e;
  --cobalt: #1d3fd8;
  --alert: #b8321f;
  --serif: "Newsreader", "Iowan Old Style", "Charter", Georgia, serif;
  --measure: 62ch;
  --gutter: clamp(1.25rem, 5vw, 4rem);
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

/* same tokens, night values */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e1520;
    --paper-2: #151e2b;
    --rule: #2a3646;
    --ink: #e6ebf0;
    --graphite: #9aa7b4;
    --cobalt: #8aa4ff;
    --alert: #ff7a66;
  }
}

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

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

body {
  position: relative;
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-size: 1.1875rem;
  line-height: 1.6;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

/* drafting grid, strongest at the top of the sheet, gone by the fold */
body::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 100vh;
  z-index: -1;
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px);
  background-size: 2rem 2rem;
  background-position: center top;
  opacity: 0.55;
  mask-image: linear-gradient(to bottom, #000 30%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 30%, transparent 100%);
  pointer-events: none;
}

::selection {
  background: var(--cobalt);
  color: var(--paper);
}

a {
  color: var(--cobalt);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
  text-decoration-color: color-mix(in srgb, var(--cobalt) 45%, transparent);
  transition: text-decoration-color 0.15s ease;
}

a:hover {
  text-decoration-color: currentColor;
}

a:focus-visible {
  outline: 2px solid var(--cobalt);
  outline-offset: 3px;
}

p {
  margin: 0 0 1.25em;
  max-width: var(--measure);
}

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

em {
  font-style: italic;
}

/* ---------- page frame ---------- */

.page {
  width: min(100%, 76rem);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--ink);
  font-size: 1rem;
}

.masthead a {
  color: var(--ink);
  text-decoration: none;
}

.masthead a:hover {
  color: var(--cobalt);
}

.masthead__name {
  font-weight: 500;
}

.masthead__nav {
  display: flex;
  gap: 1.5rem;
}

/* ---------- hero ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 5rem);
  align-items: center;
  padding: clamp(3rem, 8vh, 6rem) 0 clamp(3rem, 8vh, 5rem);
  border-bottom: 1px solid var(--ink);
}

.hero h1 {
  margin: 0 0 1.5rem;
  font-size: clamp(2.5rem, 5.4vw, 4.25rem);
  font-weight: 300;
  line-height: 1.05;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.hero__lede {
  font-size: clamp(1.15rem, 1.6vw, 1.35rem);
  line-height: 1.5;
  color: var(--graphite);
  max-width: 34ch;
}

.hero__links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.75rem;
  margin: 2rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 1.05rem;
}

/* diagram */

.diagram {
  position: relative;
  margin: 0;
}

.diagram svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.diagram figcaption {
  margin-top: 1rem;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--graphite);
  max-width: 40ch;
}

.diagram .edge {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1;
  transition: stroke 0.6s ease, stroke-dasharray 0.6s ease, opacity 0.6s ease;
}

.diagram .edge.is-dead {
  stroke: var(--rule);
  stroke-dasharray: 3 5;
}

.diagram .node {
  fill: var(--paper);
  stroke: var(--ink);
  stroke-width: 1.25;
  transition: stroke 0.5s ease, fill 0.5s ease;
}

.diagram .node.is-dead {
  stroke: var(--alert);
  fill: color-mix(in srgb, var(--alert) 10%, var(--paper));
  stroke-dasharray: 2 3;
}

.diagram .node--terminal {
  fill: var(--ink);
}

.diagram .label {
  font-family: var(--serif);
  font-size: 12px;
  fill: var(--graphite);
}

.diagram .label.is-dead {
  fill: var(--alert);
}

.diagram .packet {
  fill: var(--cobalt);
  opacity: 0;
}

.diagram .packet.is-lost {
  fill: var(--alert);
}

/* ---------- sections: title in margin, body in measure ---------- */

.section {
  display: grid;
  grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr);
  gap: 1.5rem clamp(2rem, 5vw, 5rem);
  padding: clamp(2.5rem, 6vh, 4rem) 0;
  border-bottom: 1px solid var(--rule);
}

.section:last-of-type {
  border-bottom: 0;
}

.section h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: 0.005em;
  position: sticky;
  top: 1.5rem;
  align-self: start;
}

.section h2 small {
  display: block;
  font-size: 0.95rem;
  font-weight: 400;
  font-style: italic;
  color: var(--graphite);
}

.section__body {
  min-width: 0;
}

.lead {
  font-size: 1.45rem;
  line-height: 1.45;
  font-weight: 300;
  letter-spacing: -0.005em;
  max-width: 30ch;
}

/* running list with hanging marks */

.marked {
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: var(--measure);
  columns: 2;
  column-gap: 3rem;
}

.marked li {
  position: relative;
  padding-left: 1.25rem;
  margin-bottom: 0.45rem;
  break-inside: avoid;
}

.marked li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.68em;
  width: 0.45rem;
  height: 0.45rem;
  border: 1px solid var(--ink);
}

/* definition table for the stack */

.dl {
  margin: 0;
  max-width: 44rem;
  border-top: 1px solid var(--rule);
}

.dl > div {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 1.5rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--rule);
}

.dl dt {
  color: var(--graphite);
  font-style: italic;
}

.dl dd {
  margin: 0;
}

.aside {
  margin-top: 1.75rem;
  color: var(--graphite);
  max-width: 50ch;
}

/* ordered steps: this list is a sequence, so it may count */

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: var(--measure);
  counter-reset: step;
}

.steps li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: 0.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--rule);
}

.steps li:first-child {
  border-top: 1px solid var(--rule);
}

.steps li::before {
  content: counter(step) ".";
  color: var(--graphite);
  font-variant-numeric: tabular-nums;
}

.direction p {
  font-size: 1.45rem;
  line-height: 1.45;
  font-weight: 300;
  max-width: 34ch;
}

/* contact */

.contact {
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: 44rem;
  border-top: 1px solid var(--rule);
}

.contact li {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 1.5rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--rule);
}

.contact .k {
  color: var(--graphite);
  font-style: italic;
}

.contact a {
  color: var(--ink);
}

.contact a:hover {
  color: var(--cobalt);
}

.colophon {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  padding: 2rem 0 3rem;
  border-top: 1px solid var(--ink);
  font-size: 0.95rem;
  color: var(--graphite);
}

.colophon p {
  margin: 0;
}

/* ---------- mono accents ---------- */

.mono {
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  color: var(--graphite);
}

.hero__tag {
  margin: 0 0 1.25rem;
}

main {
  counter-reset: sec;
}

.section h2::before {
  counter-increment: sec;
  content: counter(sec, decimal-leading-zero);
  display: block;
  margin-bottom: 0.25rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--graphite);
}

/* ---------- selected work ---------- */

.work {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--rule);
  border: 1px solid var(--rule);
}

.card {
  padding: 1.25rem 1.25rem 1.1rem;
  background: var(--paper);
}

.card h3 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  font-weight: 500;
  line-height: 1.3;
}

.card h3 a {
  color: var(--ink);
  text-decoration: none;
}

.card h3 a:hover {
  color: var(--cobalt);
}

.card p {
  font-size: 1rem;
  line-height: 1.5;
  margin: 0 0 0.75rem;
}

.card .card__meta {
  margin: 0;
}

/* ---------- latest writing ---------- */

.writing {
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: 44rem;
  border-top: 1px solid var(--rule);
}

.writing li {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 1rem;
  align-items: baseline;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--rule);
}

.writing a {
  color: var(--ink);
}

.writing a:hover {
  color: var(--cobalt);
}

.writing__all {
  margin-top: 1.25rem;
  font-size: 1rem;
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
    gap: 3rem;
  }

  .diagram {
    max-width: 34rem;
  }

  .section {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .section h2 {
    position: static;
  }

  .marked {
    columns: 1;
  }

  .section h2::before {
    display: inline;
    margin: 0 0.75rem 0 0;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 1.0625rem;
  }

  body::before {
    background-size: 1.5rem 1.5rem;
  }

  .dl > div,
  .contact li {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .masthead {
    flex-direction: column;
    gap: 0.25rem;
  }

  .work {
    grid-template-columns: 1fr;
  }

  .writing li {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .diagram .packet {
    display: none;
  }

  * {
    transition-duration: 0.01ms !important;
  }
}
