/* ==========================================================================
   richardhu.org — single stylesheet for the whole site.

   Palette is deliberately limited to four values (see --paper, --ink,
   --polemonium, --range-of-light). The two chromatic accents are used
   sparingly: the wordmark, nav tabs, and a few small marks.
   Greys are always the ink colour at reduced alpha, never a new hue.
   ========================================================================== */

@font-face {
  font-family: "Berkeley Oldstyle";
  src: url("/assets/fonts/BerkeleyStd-Black.otf") format("opentype");
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #ffffff;
  --ink: #000000;
  --polemonium: #7a7eb9;
  --range-of-light: #ff9f6a;
  --cal-gold: #FDB515;
  --shadow: #91170A;

  /* Ink at reduced strength. Keeps the palette to four colours. */
  --ink-70: rgba(0, 0, 0, 0.7);
  --ink-55: rgba(0, 0, 0, 0.55);
  --ink-40: rgba(0, 0, 0, 0.4);
  --ink-12: rgba(0, 0, 0, 0.12);
  --ink-06: rgba(0, 0, 0, 0.06);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --font-display: "Berkeley Oldstyle", serif;

  --measure: 44rem;
  --measure-wide: 62rem;
  --measure-gallery: 78rem;
  --gutter: 1.5rem;
}

/* Dark palette. Toggled by data-theme="dark" on <html>. */
[data-theme="dark"] {
  --paper: #161616;
  --ink: #e8e8e8;
  --polemonium: #9da1d4;
  --range-of-light: #ff9f6a;

  --ink-70: rgba(232, 232, 232, 0.7);
  --ink-55: rgba(232, 232, 232, 0.55);
  --ink-40: rgba(232, 232, 232, 0.4);
  --ink-12: rgba(232, 232, 232, 0.12);
  --ink-06: rgba(232, 232, 232, 0.06);

  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.65;
  letter-spacing: -0.003em;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* --------------------------------------------------------------- skip link */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--paper);
  z-index: 100;
}

.skip-link:focus {
  left: 0;
}

/* -------------------------------------------------------------------- header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--paper);
  border-bottom: 1px solid var(--ink-12);
}

.site-header__inner {
  max-width: var(--measure-wide);
  margin: 0 auto;
  padding: 0 var(--gutter);
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.wordmark {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: 0.01em;
  text-decoration: none;
  color: var(--cal-gold);
  text-shadow: -0.11em 0.05em 0 var(--shadow);
  white-space: nowrap;
}

.wordmark::after,
.wordmark:hover::after {
  display: none;
}

.wordmark__accent {
  background: none;
  color: inherit;
  padding: 0;
  margin-left: 0;
  border-radius: 0;
}

.nav {
  display: flex;
  align-items: center;
  gap: 1.75rem;
}

.nav a {
  position: relative;
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-55);
  text-decoration: none;
  padding: 0.35rem 0;
}

.nav a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.15rem;
  height: 2px;
  background: var(--range-of-light);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 250ms ease;
}

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

.nav a:hover::after {
  transform: scaleX(1);
}

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

.nav a[aria-current="page"]::after {
  transform: scaleX(1);
}

.nav:hover a[aria-current="page"]::after {
  transform: scaleX(0);
}

.nav a[aria-current="page"]:hover::after {
  transform: scaleX(1);
}

/* Dark-mode toggle lives at the right edge of the header bar. */
.theme-toggle {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink-12);
  border-radius: 50%;
  background: transparent;
  color: var(--ink-55);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
  transition: border-color 150ms ease, color 150ms ease;
  padding: 0;
}

.theme-toggle:hover {
  border-color: var(--ink-40);
  color: var(--ink);
}

.theme-toggle .icon-moon,
[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

/* The wordmark plus three tabs must fit a 320px-wide phone without forcing
   the page to scroll sideways, so both shrink together. */
@media (max-width: 30rem) {
  :root {
    --gutter: 1.15rem;
  }

  .site-header__inner {
    height: 3.5rem;
    gap: 0.75rem;
  }

  .wordmark {
    font-size: 0.95rem;
  }

  .nav {
    gap: 0.9rem;
  }

  .nav a {
    font-size: 0.7rem;
    letter-spacing: 0.05em;
  }
}

@media (max-width: 22rem) {
  .wordmark {
    display: none;
  }

  .nav {
    width: 100%;
    justify-content: space-between;
  }
}

/* --------------------------------------------------------------------- main */

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 4rem var(--gutter) 6rem;
}

/* The photography grid gets more room than a column of text needs. */
.wrap--gallery {
  max-width: var(--measure-gallery);
}

/* Standfirst paragraph under a page's <h1>. */
.page-intro {
  margin: 0.9rem 0 0;
  max-width: 42rem;
  font-size: 1.02rem;
  color: var(--ink-70);
  text-wrap: pretty;
}

/* --------------------------------------------------------------- typography */

h1,
h2,
h3,
h4 {
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0;
  font-weight: 650;
}

h1 {
  font-size: clamp(1.9rem, 5vw, 2.5rem);
}

/* Section label: small, uppercase, preceded by a hairline rule. */
.section {
  margin-top: 4rem;
}

.section > h2 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  padding-top: 1.1rem;
  border-top: 1px solid var(--ink-12);
  margin-bottom: 1.75rem;
}

h3 {
  font-size: 1.15rem;
  margin-top: 2.75rem;
  margin-bottom: 0.85rem;
}

p {
  margin: 0 0 1.15rem;
}

a {
  position: relative;
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: var(--ink-40);
  transition: text-decoration-color 250ms ease;
}

a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 1px;
  background: var(--range-of-light);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 250ms ease;
}

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

a:hover::after {
  transform: scaleX(1);
}

strong {
  font-weight: 650;
}

em {
  font-style: italic;
}

hr {
  border: 0;
  border-top: 1px solid var(--ink-12);
  margin: 3rem 0;
}

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

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

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

.hero {
  display: flex;
  align-items: flex-start;
  gap: 2rem;
}

.hero__portrait {
  flex: 0 0 auto;
  width: 132px;
  height: 132px;
  object-fit: cover;
  border-radius: 2px;
  background: var(--ink-06);
}

.hero__body {
  min-width: 0;
}

.hero__body h1 {
  font-family: var(--font-display);
  font-weight: 900;
  color: var(--cal-gold);
  text-shadow: -0.1em 0.05em 0 var(--shadow);
}

.hero__role {
  margin: 0.7rem 0 0;
  font-size: 1.02rem;
  color: var(--ink-70);
  text-wrap: pretty;
}


/* Inline list of external profiles. */
.linkrow {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
}

.linkrow a {
  position: relative;
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-decoration: none;
  padding-bottom: 0.15rem;
}

.linkrow a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--range-of-light);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 250ms ease;
}

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

.linkrow a:hover::after {
  transform: scaleX(1);
}

@media (max-width: 34rem) {
  .hero {
    flex-direction: column;
    gap: 1.5rem;
  }

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

/* ------------------------------------------------------------------ about me */

/* One job or degree. Title left, place/date right, collapsing on mobile. */
.entry {
  margin-bottom: 2.5rem;
}

.entry:last-child {
  margin-bottom: 0;
}

.entry__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.15rem;
}

.entry__org {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.entry__org a::after {
  bottom: 0;
}

.entry__meta {
  flex: 0 0 auto;
  font-size: 0.82rem;
  color: var(--ink-55);
  white-space: nowrap;
}

.entry__title {
  font-size: 0.95rem;
  font-style: italic;
  color: var(--ink-70);
  margin-bottom: 0.7rem;
}

.entry__head .entry__title {
  margin-bottom: 0;
}

.entry p {
  margin-bottom: 0.7rem;
}

/* Technology list, e.g. Python • C++ • Linux */
.stack {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--ink-55);
  text-transform: uppercase;
}

.stack span {
  color: var(--polemonium);
  padding: 0 0.15rem;
}

@media (max-width: 34rem) {
  .entry__head {
    flex-direction: column;
    gap: 0.1rem;
  }

  .entry__meta {
    white-space: normal;
  }
}

/* Bulleted content lists. */
.list {
  margin: 0 0 1.15rem;
  padding-left: 1.1rem;
}

.list li {
  margin-bottom: 0.5rem;
}

.list li::marker {
  color: var(--ink-40);
}

.list--tight li {
  margin-bottom: 0.3rem;
}

.list ul {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
}

/* Adventure log: a definition-style list of trips. */
.trips {
  margin: 0;
  padding-left: 1.1rem;
}

.trips > li {
  margin-bottom: 1rem;
}

.trips > li::marker {
  color: var(--ink-40);
}

.trips .trips__party {
  margin-left: 0.5em;
  font-size: 0.85rem;
  color: var(--ink-55);
}

.trips .trips__where {
  display: block;
  font-size: 0.85rem;
  color: var(--ink-55);
}

/* ------------------------------------------------------------- photography */

/* Three photographs per row, dropping to two and then one as space runs out.
   Every frame is a fixed 4:3 window and the image is cropped to fill it, so the
   grid stays even no matter what is dropped into content/photos.yaml. */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem;
  margin-top: 2.75rem;
}

.tile {
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: var(--ink-06);
  text-decoration: none;
  cursor: zoom-in;
}

.tile::after {
  display: none;
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Hovering fades in a black scrim and the caption together, which reads as the
   photograph gradually darkening. Leaving reverses it over the same duration. */
.tile__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 1.25rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.55);
  color: #ffffff;
  opacity: 0;
  transition: opacity 420ms ease;
}

.tile:hover .tile__overlay,
.tile:focus-visible .tile__overlay {
  opacity: 1;
}

.tile__title {
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.tile__place {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: rgba(255, 255, 255, 0.75);
}

/* Caption notes are shown in the hover overlay, styled for the dark scrim. */
.grid .tile__note {
  margin-top: 0.5rem;
  font-size: 0.76rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.82);
  max-width: 22rem;
  text-transform: none;
  letter-spacing: normal;
}

.grid .tile__note cite {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.68rem;
  font-style: normal;
  color: rgba(255, 255, 255, 0.6);
}

@media (max-width: 62rem) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 30rem) {
  .grid {
    grid-template-columns: 1fr;
    gap: 0.7rem;
  }
}

/* Touch screens have no hover, so show the caption over a bottom gradient
   instead of hiding it behind an interaction that cannot happen. */
@media (hover: none) {
  .tile__overlay {
    opacity: 1;
    align-items: flex-start;
    justify-content: flex-end;
    text-align: left;
    padding: 1rem;
    background: linear-gradient(
      to top,
      rgba(0, 0, 0, 0.75) 0%,
      rgba(0, 0, 0, 0.35) 45%,
      rgba(0, 0, 0, 0) 100%
    );
  }
}

/* ------------------------------------------------------------------ lightbox */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  background: var(--paper);
}

.lightbox.is-open {
  display: grid;
  grid-template-rows: 1fr auto;
  height: 100dvh;
}

.lightbox__stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  padding: 4rem 1.5rem 0;
  box-sizing: border-box;
}

.lightbox__img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lightbox__bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1rem 1.25rem 1.25rem;
  font-size: 0.85rem;
  color: var(--ink-55);
}

.lightbox__caption {
  margin: 0;
  max-width: 46rem;
}

/* The caption markup is reused from the grid, where it sits on a dark scrim. */
.lightbox__caption .tile__title {
  display: block;
  color: var(--ink);
  font-weight: 500;
}

.lightbox__caption .tile__place {
  display: block;
  color: var(--ink-55);
}

.lightbox__caption .tile__note {
  display: block;
  margin-top: 0.7rem;
  padding-left: 0.9rem;
  border-left: 2px solid var(--range-of-light);
  font-size: 0.9rem;
  color: var(--ink-70);
  text-transform: none;
  letter-spacing: normal;
}

.lightbox__caption .tile__note cite {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.82rem;
  font-style: normal;
  color: var(--ink-55);
}

.lightbox__controls {
  display: flex;
  gap: 0.4rem;
  flex: 0 0 auto;
}

.iconbtn {
  width: 2.4rem;
  height: 2.4rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink-12);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  font-family: var(--font-sans);
}

.iconbtn:hover {
  border-color: var(--ink);
}

.lightbox__close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
}

/* --------------------------------------------------------------------- blog */

.postlist {
  margin-top: 3rem;
  list-style: none;
  padding: 0;
}

.postlist li {
  padding-top: 2rem;
  margin-top: 2rem;
  border-top: 1px solid var(--ink-12);
}

.postlist li:first-child {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

.postlist h2 {
  font-size: 1.3rem;
  margin-bottom: 0.4rem;
}

.postlist h2 a {
  text-decoration: none;
}

.postlist h2 a::after {
  bottom: 0;
}

.postlist h2 a:hover::after {
  transform: scaleX(1);
}

.dateline {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-55);
}

.tags {
  margin: 0.9rem 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tags li {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  color: var(--ink-55);
  border: 1px solid var(--ink-12);
  border-radius: 2px;
  padding: 0.1rem 0.45rem;
  margin: 0;
}

/* -------------------------------------------------------------- post bodies */

/* Holds only the date and the title; the standfirst paragraphs follow it. */
.post header {
  margin-bottom: 0.6rem;
}

.post h1 {
  font-size: clamp(1.7rem, 4.4vw, 2.2rem);
  margin-bottom: 0.7rem;
  text-wrap: balance;
}

.post h3 {
  padding-top: 2.5rem;
  margin-top: 3rem;
  border-top: 1px solid var(--ink-12);
  font-size: 1.25rem;
}

.post h3 .anchor {
  float: right;
  font-size: 0.9rem;
  font-weight: 400;
  text-decoration: none;
  color: var(--ink-40);
}

.post h3 .anchor::after {
  display: none;
}

.post h3 .anchor:hover {
  color: var(--range-of-light);
}

.post img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 2rem auto;
}

.post figure {
  margin: 2rem 0;
}

.post figure img {
  margin-bottom: 0.75rem;
}

.post figcaption {
  font-size: 0.85rem;
  color: var(--ink-55);
  text-align: center;
}

/* Diagrams are capped narrower than the text column, but must still shrink on
   a phone rather than pushing the page sideways. */
.post .diagram {
  width: 100%;
  max-width: 24rem;
}

/* Table of contents at the top of a post. */
.toc {
  border: 1px solid var(--ink-12);
  border-radius: 2px;
  padding: 1.25rem 1.5rem;
  margin: 2.5rem 0;
}

.toc h2 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-bottom: 0.75rem;
}

.toc ol {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.95rem;
}

.toc li {
  margin-bottom: 0.25rem;
}

.toc li::marker {
  color: var(--ink-40);
  font-variant-numeric: tabular-nums;
}

/* Boxed algorithm / theorem statement. */
.callout {
  border-left: 2px solid var(--polemonium);
  padding: 0.25rem 0 0.25rem 1.35rem;
  margin: 2rem 0;
}

.callout__label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 0.6rem;
}

.callout p {
  margin-bottom: 0.7rem;
}

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

.callout ol {
  margin: 0;
  padding-left: 1.3rem;
}

.callout ol li {
  margin-bottom: 0.6rem;
}

.callout ol li:last-child {
  margin-bottom: 0;
}

/* ------------------------------------------------------------------- code */

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--ink-06);
  padding: 0.08em 0.2em;
  border-radius: 2px;
}

pre {
  margin: 1.75rem 0;
  padding: 1.1rem 1.25rem;
  overflow-x: auto;
  background: var(--paper);
  border: 1px solid var(--ink-12);
  border-left: 2px solid var(--ink);
  border-radius: 2px;
  line-height: 1.55;
  tab-size: 4;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.82rem;
  white-space: pre;
}

/* ------------------------------------------------------------------- math */

/* Vendored KaTeX handles the glyphs; this only manages overflow so long
   display equations scroll instead of breaking the layout on phones. */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.5rem 0;
}

/* ------------------------------------------------------------------ footer */

.site-footer {
  border-top: 1px solid var(--ink-12);
  margin-top: 2rem;
}

.site-footer__inner {
  max-width: var(--measure-wide);
  margin: 0 auto;
  padding: 2rem var(--gutter) 3rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--ink-55);
}

.site-footer a::after {
  bottom: 0;
}

.backtotop {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ------------------------------------------------------------------ 404 */

.notfound {
  text-align: center;
  padding: 7rem var(--gutter);
}

.notfound__code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  color: var(--range-of-light);
  margin-bottom: 1rem;
}

/* -------------------------------------------------------------- print (CV) */

@media print {
  .site-header,
  .site-footer,
  .lightbox,
  .skip-link,
  .linkrow {
    display: none !important;
  }

  body {
    font-size: 10.5pt;
  }

  .wrap {
    max-width: none;
    padding: 0;
  }

  a::after {
    display: none !important;
  }

  .section {
    break-inside: avoid;
  }

  .entry {
    break-inside: avoid;
  }
}

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

  * {
    transition: none !important;
    animation: none !important;
  }
}
