:root {
  /* SF Pro Rounded where available (Safari via ui-rounded, or installed locally), else Rouna */
  --body-font: ui-rounded, "SF Pro Rounded", "Rouna";
  --heading-font: var(--body-font);
  --ink: #222;
  --text: #111;
  --bg: #fff;
  /* Light grey behind code, pre and selected text */
  --tint: #f0f0f0;
  --line: 9px;
  --rule-gap: 22px;
  --split: 70%;
  --gutter: 88px;
  --logo: 230px;
  --frame-top: 64px;
  /* Text sits inset within <main>: left and right space, and line length */
  --inset: calc(var(--gutter) * 1.2);
  --inset-end: 48px;
  --measure: 33em;
  /* Everything above <main>: top space, three rules and gaps, masthead (logo minus its overlap), rule */
  --header-h: calc(var(--frame-top) + 2 * var(--line) + 2 * var(--rule-gap) + var(--logo));
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body-font), system-ui, sans-serif;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Set color too, or inverted text (hovered links, .brand) turns white-on-tint */
::selection {
  background: var(--tint);
  color: var(--ink);
}

a {
  color: inherit;
  text-decoration: none;
  text-underline-offset: 3px;
}

/* Page frame (baseof): <main> is pulled up behind the header to the top of the page, */
/* so its right border is the full-height vertical rule */

.frame {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-top: var(--frame-top);
  /* Anchors the side column (.side) */
  position: relative;
}

.rules,
.masthead,
.rule {
  /* Paint over <main>, which sits behind them */
  position: relative;
  z-index: 1;
}

.rules {
  display: flex;
  flex-direction: column;
  gap: var(--rule-gap);
}

.rules span,
.rule {
  display: block;
  height: var(--line);
  background: var(--ink);
}

/* Masthead */

.masthead {
  display: grid;
  grid-template-columns: var(--split) 1fr;
  align-items: end;
}

.brand {
  display: flex;
  align-items: center;
  gap: 48px;
  padding-left: var(--gutter);
  color: var(--ink);
  text-decoration: none;
}

.logo {
  flex: none;
  display: grid;
  place-items: center;
  width: var(--logo);
  height: var(--logo);
  border: var(--line) solid var(--ink);
  border-radius: 50%;
  /* Pull the circle over the rules above and below it */
  margin: calc(-1 * var(--line)) 0;
  position: relative;
  z-index: 1;
  background: var(--bg);
}

.logo img {
  width: 56%;
  transform: translateY(-4%);
}

.masthead h1,
.byline {
  font-family: var(--heading-font), var(--body-font), sans-serif;
}

.masthead h1 {
  margin: 0;
  font-size: 84px;
  font-weight: 500;
  line-height: 1.02;
  text-transform: uppercase;
}

/* Bigger single-word heading for section pages, e.g. News */
/* Fixed per breakpoint, sized to clear the divider at the narrowest width of each range */
.masthead h1.big {
  font-size: 160px;
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: -0.02em;
}

.byline {
  margin: 0;
  padding: 0 32px 18px 40px;
  font-size: 1rem;
  font-weight: 500;
  text-transform: uppercase;
  text-wrap: balance;
}

/* Hover: invert the brand cell (logo + title), not the byline */

@media (hover: hover) {
  .brand:hover {
    background: var(--ink);
    color: #fff;
  }

  .brand:hover .logo {
    background: #fff;
  }
}

/* Body */

.page-body {
  flex: 1;
  width: var(--split);
  margin-top: calc(-1 * var(--header-h));
  padding: calc(var(--header-h) + 96px) 0 120px;
  border-right: var(--line) solid var(--ink);
}

/* The column spans <main>; each container of text within it carries its own inset, */
/* so others (e.g. news posts) can run full width */
.text {
  max-width: calc(var(--measure) + var(--inset) + var(--inset-end));
  padding: 0 var(--inset-end) 0 var(--inset);
}

.news {
  list-style: none;
  padding-left: 0 !important;
}

/* One line per item; long titles trail off */
.news li {
  margin-bottom: 0.4em;
  padding-left: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.news .date {
  display: inline-block;
  min-width: 5.5em;
  color: #777;
}

/* Past work: screenshots with captions in a two-column grid; landscape ones span both, */
/* and dense packing pulls a later card up into any gap they leave */
.work {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-flow: dense;
  /* Cards stay image height, so the caption stays on the image bottom */
  align-items: start;
  gap: 1.5em;
  margin-bottom: 1.4em;
}

.work figure {
  position: relative;
  margin: 0;
}

.work .landscape {
  grid-column: 1 / -1;
}

/* Hover: the card (image + caption) does a cartoon newspaper spin, one turn while shrinking, */
/* and stays small and tilted until the pointer leaves. The full turn is a one-shot animation */
/* (360deg looks the same as 0, so dropping it is seamless); the tilt and shrink are transitions, */
/* so leaving only unwinds those. The hover and link are on the unmoving .cell, so the shrinking */
/* card can't slip out from under the pointer */
@keyframes work-spin {
  to {
    transform: rotate(1turn);
  }
}

@media (hover: hover) {
  .work figure {
    transition: rotate 0.25s linear, scale 0.25s linear;
  }

  .work .cell:hover figure {
    rotate: 20deg;
    scale: 0.6;
    animation: work-spin 0.25s linear;
  }
}

/* One frame shape per orientation, so every row ends level; crop from the top to keep titles */
.work img {
  display: block;
  margin: 0;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: top;
  border: 4px solid var(--ink);
}

.work .landscape img {
  aspect-ratio: 16 / 10;
}

/* The book photo sits low in its frame: the caption stripe hides its base while backdrop fills */
/* the top. Bottom-padding (in the photo's own backdrop grey) lifts it clear of the caption, */
/* and the slight upward object-position shift trades top backdrop for bottom, centering it */
.work .book img {
  padding-bottom: 3em;
  background: #e2e2e2;
  object-position: 50% 25%;
}

/* The "see more" tile: an empty frame in the portrait image shape, label centered */
.work .more figure {
  display: grid;
  place-items: center;
  aspect-ratio: 3 / 4;
  border: 4px solid var(--ink);
}

/* Caption: a black stripe along the bottom of the image, merging with its border */
.work figcaption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.9em 0.8em;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.8em;
  line-height: 1.25;
  text-align: center;
  text-wrap: balance;
}

@media (max-width: 500px) {
  .work {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Wide content (e.g. the education widget) uses the whole left column */

.wide {
  padding: 0 var(--inset-end) 0 var(--inset);
}

/* Side column, right of the vertical rule, from below the header to the bottom of the page */

.side {
  position: absolute;
  top: var(--header-h);
  bottom: 0;
  left: var(--split);
  right: 0;
}

/* Table of contents for the news page; stays in view while scrolling, and scrolls itself if too long */

html:has(.toc) {
  scroll-behavior: smooth;
}

.toc {
  position: sticky;
  top: 0;
  max-height: 100dvh;
  overflow-y: auto;
  /* Padding lives here, not on .side, so the scrollbar sits at the page edge */
  padding: 40px 32px 40px 40px;
  font-size: 0.85rem;
}

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

.toc li {
  margin: 0 0 1.2em;
  line-height: 1.25;
}

@media (hover: hover) {
  .toc a:hover {
    text-decoration: underline;
  }
}

.toc .date {
  display: block;
  font-size: 0.8em;
  color: #777;
}

/* News posts: full width of <main>, so the separator runs from the page edge to the vertical rule */

.post {
  margin-bottom: 2.5em;
  padding-bottom: 2.5em;
  border-bottom: var(--line) solid var(--ink);
  scroll-margin-top: 24px;
}

.post:last-child {
  border-bottom: none;
}

.column .post h2 {
  margin-top: 0;
  margin-bottom: 0.3em;
}

/* Thin, light underline so the title reads as a link without shouting */
.post h2 a {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-decoration-color: #ccc;
  text-underline-offset: 5px;
}

@media (hover: hover) {
  .post h2 a:hover {
    text-decoration-color: currentColor;
  }
}

.post-meta {
  color: #777;
}

/* Medium screens: shrink the logo and heading before the layout stacks */

@media (max-width: 1200px) {
  :root {
    --gutter: 48px;
    --logo: 160px;
  }

  .brand {
    gap: 32px;
  }

  .masthead h1 {
    font-size: 60px;
  }

  .masthead h1.big {
    font-size: 112px;
  }
}

/* Smaller screens: drop the side column, stack the masthead */

@media (max-width: 800px) {
  :root {
    --line: 6px;
    --rule-gap: 14px;
    --gutter: 24px;
    --frame-top: 32px;
    --inset: var(--gutter);
    --inset-end: var(--gutter);
  }

  html,
  body {
    font-size: 18px;
  }

  .masthead {
    grid-template-columns: minmax(0, 1fr);
  }

  .brand {
    gap: 20px;
    padding: 0 var(--gutter);
  }

  .logo {
    width: 108px;
    height: 108px;
  }

  .masthead h1 {
    font-size: 40px;
  }

  .masthead h1.big {
    font-size: 72px;
  }

  .byline {
    padding: 16px var(--gutter);
    border-top: var(--line) solid var(--ink);
  }

  .side {
    display: none;
  }

  .page-body {
    width: auto;
    margin-top: 0;
    padding: 48px 0 72px;
    border-right: none;
  }
}
