@font-face {
  font-family: "Newsreader";
  src: url("/fonts/newsreader.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Newsreader";
  src: url("/fonts/newsreader-italic.woff2") format("woff2");
  font-weight: 200 800;
  font-style: italic;
  font-display: swap;
}

:root {
  /* An exercise-book page: off-white paper, blue-black ink, a pink margin
     rule, and one red correction pen. */
  --paper: #fafaf6;
  --ink: #1c2433;
  --pencil: #6c717c;
  --rule: #e58d93;
  --red: #d0222b;
  --hairline: #e3e4e7;

  --margin: clamp(5rem, 13vw, 10.5rem);
  --gap: clamp(1.25rem, 2.6vw, 2.25rem);
  --measure: 40rem;

  --body: 1.1875rem;
  --small: 0.9375rem;

  --pen: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'%3E%3Cpath d='M3 25l2.6-7.4L19.4 3.8a2 2 0 0 1 2.8 0l2 2a2 2 0 0 1 0 2.8L10.4 22.4z' fill='%23d0222b' stroke='%23fafaf6' stroke-width='1.4' stroke-linejoin='round'/%3E%3Cpath d='M3 25l4.4-4.4' stroke='%23fafaf6' stroke-width='1.2' stroke-linecap='round'/%3E%3C/svg%3E") 3 25, auto;
}

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

html {
  background-color: var(--paper);
  /* A whisper of paper grain. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.11 0 0 0 0 0.14 0 0 0 0 0.2 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: "Newsreader", "Iowan Old Style", Georgia, serif;
  font-size: 100%;
  font-optical-sizing: auto;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

@media (pointer: fine) {
  html,
  a,
  button {
    cursor: var(--pen);
  }
}

body {
  margin: 0;
  font-size: var(--body);
  line-height: 1.6;
  font-variant-numeric: lining-nums;
}

::selection {
  background: rgba(208, 34, 43, 0.16);
}

h1,
h2,
h3,
p,
ol,
ul {
  margin: 0;
}

ol,
ul {
  padding: 0;
  list-style: none;
}

/* The sheet: a wide left margin with the writing area to its right. */
.sheet {
  position: relative;
  max-width: calc(var(--margin) + var(--gap) + var(--measure) + 6rem);
  margin: 0 auto;
  padding: 0 1.5rem 0 calc(var(--margin) + var(--gap));
}

.margin-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--margin);
  width: 1.5px;
  background: var(--rule);
  transform-origin: top;
}

html.motion .margin-line {
  transform: scaleY(0);
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--measure);
  padding: 2rem 0 0;
  font-size: var(--small);
}

/* Links: a hand-drawn red underline is pulled in from the left on hover. */
.ink-link {
  position: relative;
  color: inherit;
  text-decoration: none;
}

.ink-link::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: -0.3em;
  height: 0.5em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 8' preserveAspectRatio='none'%3E%3Cpath d='M1 5.2C18 3.4 31 6.4 48 4.6S82 2.6 99 4.4 114 5.4 119 3.6' fill='none' stroke='%23d0222b' stroke-width='1.7' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
  clip-path: inset(0 100% 0 0);
  transition: clip-path 0.42s cubic-bezier(0.65, 0, 0.25, 1);
}

.ink-link:hover::after,
.ink-link:focus-visible::after {
  clip-path: inset(0 0 0 0);
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 4px;
  border-radius: 2px;
}

/* ---------- Opening ---------- */

.hero {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: min(92svh, 60rem);
  max-width: 54rem;
  padding: 4rem 0 5rem;
}

.drafts {
  margin-bottom: 0.9rem;
}

.draft {
  position: relative;
  color: var(--pencil);
  font-style: italic;
  font-weight: 350;
}

.hero .draft {
  font-size: clamp(1.15rem, 2.4vw, 1.75rem);
  line-height: 1.45;
}

/* Struck-through drafts. Without motion, plain red line-through; with motion
   the pen strike is drawn by script. */
.draft .t,
.swap .was .t {
  position: relative;
  text-decoration: line-through;
  text-decoration-color: var(--red);
  text-decoration-thickness: 0.075em;
}

html.motion .draft .t,
html.motion .swap .was .t {
  text-decoration: none;
}

.thesis {
  font-size: clamp(3.1rem, 7.4vw, 5.75rem);
  font-weight: 480;
  line-height: 1.02;
  letter-spacing: -0.022em;
  text-wrap: balance;
}

.write {
  position: relative;
  display: block;
}

.write .typed {
  display: none;
}

html.motion .write:not(.done) .ghost {
  color: transparent;
}

html.motion .write:not(.done) .typed {
  display: block;
  position: absolute;
  inset: 0;
}

.caret {
  display: inline-block;
  width: 0;
  height: 0.82em;
  margin-left: 0.04em;
  vertical-align: -0.06em;
  border-left: max(2px, 0.045em) solid var(--red);
  animation: blink 1.05s steps(1) infinite;
}

.typing .caret {
  animation: none;
}

.write.done .caret,
.caret.off {
  display: none;
}

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

.hero-after {
  max-width: 34rem;
  margin-top: clamp(1.75rem, 4vh, 2.75rem);
}

.intro {
  font-size: clamp(1.15rem, 1.8vw, 1.35rem);
  line-height: 1.5;
}

.replay {
  margin-top: 1.25rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--pencil);
  font: italic 400 var(--small) / 1.4 "Newsreader", Georgia, serif;
}

.replay:hover {
  color: var(--red);
}

html:not(.motion) .replay {
  display: none;
}

html.motion .hero-after {
  opacity: 0;
  transform: translateY(0.5rem);
  transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1);
}

html.motion .hero-after.shown {
  opacity: 1;
  transform: none;
}

/* Overlay used by the pen: strikes and circles. */
.pen-svg {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}

.pen-svg path {
  fill: none;
  stroke: var(--red);
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Sections ---------- */

section + section {
  padding-top: clamp(5rem, 13vh, 9rem);
}

h2 {
  max-width: var(--measure);
  margin-bottom: 2.75rem;
  font-size: clamp(1.9rem, 3.4vw, 2.6rem);
  font-style: italic;
  font-weight: 380;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

/* ---------- What changed ---------- */

.figures {
  max-width: var(--measure);
}

.result {
  display: grid;
  grid-template-columns: 9rem minmax(0, 1fr);
  gap: 2rem;
  align-items: baseline;
  padding: 1.6rem 0;
  border-top: 1px solid var(--hairline);
}

.result:last-child {
  border-bottom: 1px solid var(--hairline);
}

.figure {
  font-size: 3.4rem;
  font-weight: 430;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: lining-nums;
}

.figure .mark {
  position: relative;
  display: inline-block;
}

.figure.swap {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 2.1rem;
  letter-spacing: -0.015em;
}

.swap .was {
  position: relative;
  align-self: flex-start;
  color: var(--pencil);
  font-size: 0.7em;
  font-style: italic;
}

.swap .now {
  position: relative;
  color: var(--red);
  font-style: italic;
}

html.motion .swap .now:not(.done) {
  color: transparent;
}

/* ---------- Pinned scroll ----------
   With motion on, "What changed" and "How I think" hold still while you
   scroll, and the scroll plays the pen. Script sets --steps and drives
   each item. Without motion they stay as plain lists. */

html.motion section.scrolly {
  padding-top: 0;
}

html.motion .scrolly {
  --step: 135svh;
  height: calc(var(--steps, 4) * var(--step) + 100svh);
}

html.motion .scrolly .pin {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100svh;
  padding: clamp(3.5rem, 11svh, 7rem) 0 clamp(2rem, 8svh, 4rem);
}

html.motion .scrolly h2 {
  margin-bottom: 0;
}

html.motion .scrolly .pin > ul {
  position: relative;
  flex: 1;
}

html.motion .scrolly .pin > ul > li {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  will-change: opacity, transform;
}

.step-count {
  display: none;
}

html.motion .scrolly .step-count {
  display: block;
  position: absolute;
  bottom: clamp(2rem, 8svh, 4rem);
  right: calc(100% + var(--gap) + 0.85rem);
  color: var(--pencil);
  font-size: var(--small);
  font-style: italic;
  font-variant-numeric: tabular-nums lining-nums;
  white-space: nowrap;
}

/* Pinned results: one big figure at a time. */
html.motion .results .result {
  gap: clamp(1rem, 3svh, 1.75rem);
}

html.motion .results .figure {
  margin-left: 1.75rem;
  font-size: clamp(5.5rem, 15vw, 10.5rem);
  letter-spacing: -0.04em;
}

html.motion .results .figure.swap {
  font-size: clamp(3.6rem, 9vw, 6.5rem);
}

html.motion .results .result p {
  max-width: 26rem;
  font-size: clamp(1.2rem, 2vw, 1.5rem);
  line-height: 1.4;
}

html.motion .swap .now:not(.done) {
  color: var(--red);
}

/* Pinned beliefs: one rewrite at a time. */
html.motion .beliefs .belief .draft {
  font-size: clamp(1.3rem, 2.4vw, 1.8rem);
}

html.motion .beliefs .belief .final {
  margin-top: 0.5rem;
  font-size: clamp(2.3rem, 5.6vw, 4.2rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
}

html.motion .beliefs .belief .draft .t {
  display: inline-block;
}

/* ---------- I still build things myself ---------- */

.code {
  max-width: var(--measure);
}

.code-lede {
  max-width: 34rem;
}

.code-lede strong {
  font-weight: 600;
}

.calendar {
  margin: 2.25rem 0 0;
}

.calendar-sheet svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  touch-action: pan-y;
}

.calendar .squares {
  stroke: var(--hairline);
  stroke-width: 1;
}

.calendar .month {
  fill: var(--pencil);
  font-size: 11px;
  font-style: italic;
}

.calendar .day {
  fill: var(--ink);
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1.4), opacity 0.35s ease;
}

html.motion .calendar:not(.inked) .day {
  opacity: 0;
  transform: scale(0.2);
}

.calendar .day.picked {
  fill: var(--red);
}

.calendar .busiest {
  fill: none;
  stroke: var(--red);
  stroke-width: 1.6;
  stroke-linecap: round;
}

.calendar .today {
  fill: none;
  stroke: var(--red);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.calendar-note {
  min-height: 1.6em;
  margin-top: 1rem;
  color: var(--pencil);
  font-size: var(--small);
  font-style: italic;
}

.code-link {
  margin-top: 1.25rem;
  font-size: var(--small);
}

/* ---------- What I work with ---------- */

.kit {
  max-width: var(--measure);
}

.kit-lede {
  max-width: 34rem;
}

.kit-list {
  margin: 2.25rem 0 0;
}

.kit-group {
  display: grid;
  grid-template-columns: 9rem minmax(0, 1fr);
  gap: 2rem;
  padding: 1.1rem 0;
  border-top: 1px solid var(--hairline);
}

.kit-group:last-child {
  border-bottom: 1px solid var(--hairline);
}

.kit-group dt {
  padding-top: 0.15rem;
  color: var(--pencil);
  font-size: var(--small);
  font-style: italic;
}

.kit-group dd {
  margin: 0;
}

.kit-group ul {
  columns: 2 13rem;
  column-gap: 2rem;
}

.kit-group li {
  break-inside: avoid;
  font-size: 1.0625rem;
  line-height: 1.45;
  padding: 0.12rem 0;
}

/* ---------- How I think ---------- */

.rewrites {
  max-width: var(--measure);
}

.belief + .belief {
  margin-top: 2.6rem;
}

.belief .draft {
  font-size: 1.3rem;
  line-height: 1.45;
}

.belief .final {
  margin-top: 0.3rem;
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  font-weight: 450;
  line-height: 1.2;
  letter-spacing: -0.012em;
  text-wrap: balance;
}

html.motion .hero .draft {
  opacity: 0;
}

/* ---------- Say hello ---------- */

.hello {
  max-width: var(--measure);
  padding-bottom: 6rem;
}

.hello > p:not(.links):not(.signoff) {
  max-width: 34rem;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2.25rem;
  margin-top: 1.75rem;
  font-size: clamp(1.35rem, 2.6vw, 1.75rem);
}

.signoff {
  margin-top: 3rem;
  font-size: 2.6rem;
  font-style: italic;
  font-weight: 350;
  line-height: 1;
}

.signoff .write {
  display: inline-block;
}

.foot {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--measure);
  padding: 1.5rem 0 2.25rem;
  border-top: 1px solid var(--hairline);
  color: var(--pencil);
  font-size: var(--small);
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  :root {
    --margin: 3.1rem;
    --gap: 0.95rem;
    --body: 1.0625rem;
    --small: 0.875rem;
  }

  .sheet {
    padding-right: 1.25rem;
  }

  .top {
    padding-top: 1.4rem;
  }

  .hero {
    min-height: 88svh;
    padding: 3rem 0 4rem;
  }

  .kit-group {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.4rem;
  }

  .result {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.6rem;
  }

  .figure {
    font-size: 2.9rem;
  }

  html.motion .results .figure {
    margin-left: 1.6rem;
  }

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