:root {
  color-scheme: light dark;

  /* One system for home + essays (signal field). */
  --bg: light-dark(#eef4ea, #0c100b);
  --bg-card: light-dark(#fbfdf9, #161c13);
  --ink: light-dark(#121612, #f2f7ef);
  --ink-muted: light-dark(#4d5c50, #9aab98);
  --rule: light-dark(#c9d6c4, #2a3327);
  --accent: light-dark(#107c3b, #5eef8a);
  --accent-ink: light-dark(#ffffff, #0e2415);

  --font: 'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Type scale. Steps are 10 / 7 / 5 / 3 / 1, spaced evenly at 2.78px per step
     between body text (17px) and the title (42px). Every heading on the site
     draws from these five values — don't set a bare font-size on a heading.
     Step  Role         rem        px
      10   title        2.625      42.0
       7   heading 1    2.104      33.7
       5   heading 2    1.757      28.1
       3   heading 3    1.410      22.6
       1   normal text  1.0625     17.0 */
  --fs-title: 2.625rem;
  --fs-h1: 2.104rem;
  --fs-h2: 1.757rem;
  --fs-h3: 1.41rem;
  --fs-body: 1.0625rem;
  --measure: 58rem;
  --essay-pad: clamp(1.25rem, 3vw, 2.75rem);
  --radius-card: 1.25rem;
  --radius-pill: 999px;
  --glass: color-mix(in srgb, var(--bg-card) 78%, transparent);
  --shadow-soft: 0 10px 40px color-mix(in srgb, var(--ink) 10%, transparent);

  /* Heights of the two stacked sticky bars. Anything that scrolls to an anchor
     must offset by these, or the target lands underneath them. */
  --header-h: 4.1rem;
  --nav-h: 3.4rem;
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

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

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.6rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 100;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 1rem;
}

html { scroll-behavior: smooth; }

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

body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 90% 55% at 8% -15%, color-mix(in srgb, var(--accent) 26%, transparent), transparent 58%),
    radial-gradient(ellipse 70% 45% at 100% 5%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 52%),
    radial-gradient(ellipse 55% 35% at 50% 110%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 50%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
em {
    color: var(--accent)
}

::selection {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--ink);
}

a { color: var(--accent); }
ul { margin: 0; padding: 0; list-style: none; }

.page {
  max-width: min(900px, var(--measure));
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3.5rem;
}

/* Title */
.title-page { margin-bottom: 2.25rem; }

.eyebrow {
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 0 0 0.9rem;
  padding: 0.38rem 0.75rem;
  border-radius: var(--radius-pill);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.signature {
  font-weight: 800;
  font-size: clamp(2.4rem, 5.5vw, 3.4rem);
  line-height: 0.98;
  letter-spacing: -0.035em;
  margin: 0;
  text-wrap: balance;
}

.subhead {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--ink-muted);
  max-width: 36ch;
  margin: 1rem 0 0;
  line-height: 1.45;
}

#theme-toggle,
.theme-toggle {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 80;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: 50%;
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent),
    0 12px 32px color-mix(in srgb, var(--accent) 35%, transparent);
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

#theme-toggle:hover,
#theme-toggle:focus-visible,
.theme-toggle:hover,
.theme-toggle:focus-visible {
  transform: translateY(-3px) scale(1.04);
  box-shadow:
    0 0 0 5px color-mix(in srgb, var(--accent) 28%, transparent),
    0 16px 40px color-mix(in srgb, var(--accent) 45%, transparent);
}

#theme-toggle svg,
.theme-toggle svg {
  position: absolute;
  width: 20px;
  height: 20px;
  transition: opacity 0.25s ease, transform 0.3s ease;
}

.icon-moon {
  opacity: 0;
  transform: scale(0.5) rotate(-40deg);
}

:root[data-theme="dark"] .icon-sun {
  opacity: 0;
  transform: scale(0.5) rotate(40deg);
}

:root[data-theme="dark"] .icon-moon {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .icon-sun {
    opacity: 0;
    transform: scale(0.5) rotate(40deg);
  }
  :root:not([data-theme]) .icon-moon {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

/* Tabs — standalone look when not nested; nested look under home .site-header-inner */
.tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem;
  margin: 0 0 2.5rem;
  border: 1px solid color-mix(in srgb, var(--rule) 90%, var(--accent));
  border-radius: var(--radius-pill);
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.15);
  box-shadow: var(--shadow-soft);
}

.tabs a {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-muted);
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-pill);
  transition: color 0.15s ease, background 0.15s ease;
}

.tabs a:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.tabs a.active {
  color: var(--accent-ink);
  background: var(--accent);
}

/* Cards */
.card {
  background:
    linear-gradient(
      165deg,
      color-mix(in srgb, var(--bg-card) 96%, var(--accent)) 0%,
      var(--bg-card) 40%,
      var(--bg-card) 100%
    );
  border: 1px solid color-mix(in srgb, var(--rule) 85%, var(--accent));
  border-radius: var(--radius-card);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 8%, transparent),
    var(--shadow-soft);
  padding: 1.7rem 1.8rem;
  margin-bottom: 1.25rem;
}

/* Section titles */
.section-title {
  font-weight: 800;
  font-size: clamp(1.55rem, 2.5vw, var(--fs-h1));
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0 0 1.35rem;
}

section { margin-bottom: 4.5rem; scroll-margin-top: calc(var(--header-h) + var(--nav-h) + 1.75rem); }

/* Timeline / postcards */
.timeline {
  border-left: 2px solid var(--rule);
  padding-left: 1.6rem;
  margin-left: 0.2rem;
}

.postcard {
  position: relative;
  padding: 0 0 1.6rem;
}

.postcard:last-child { padding-bottom: 0; }

.postcard::before {
  content: "";
  position: absolute;
  left: -1.85rem;
  top: 0.5rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.postmark {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--ink-muted);
  margin-bottom: 0.35rem;
}

.postcard h3 {
  font-size: var(--fs-h3);
  font-weight: 700;
  margin: 0;
  line-height: 1.4;
}

.role {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--ink-muted);
}

.job-sub {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.subsection-title {
  font-size: var(--fs-h2);
  font-weight: 700;
  color: var(--ink);
  margin: 3rem 0 1.6rem;
}

/* Ticket list */
.ticket-list {
  border: 1px solid color-mix(in srgb, var(--rule) 85%, var(--accent));
  border-radius: var(--radius-card);
  background: var(--bg-card);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.ticket-list li { border-bottom: 1px solid var(--rule); }
.ticket-list li:last-child { border-bottom: none; }

.ticket-list a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 1rem 1.15rem;
  transition: background 0.15s ease;
}

.ticket-list a:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.ticket-list a:hover .ticket-title { color: var(--accent); }

.ticket-title {
  font-size: 1rem;
  font-weight: 600;
  transition: color 0.15s ease;
}

.ticket-date {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  white-space: nowrap;
}

.more-link {
  display: inline-flex;
  align-items: center;
  margin-top: 1.15rem;
  padding: 0.5rem 0.95rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.more-link:hover {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-color: var(--accent);
}

/* The margin above is spacing off a preceding list; a lone link in a card
   (the 404 page) would otherwise sit off-centre in its own padding. */
.card > .more-link:only-child { margin-top: 0; }

/* Contact */
.postcard-contact {
  max-width: 560px;
  background:
    linear-gradient(
      165deg,
      color-mix(in srgb, var(--bg-card) 96%, var(--accent)) 0%,
      var(--bg-card) 100%
    );
  border: 1px solid color-mix(in srgb, var(--rule) 85%, var(--accent));
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  padding: 2rem 2.2rem;
}

.labels {
  display: flex;
  gap: 1.4rem;
  flex-wrap: wrap;
}

.label-tag {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-muted);
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.label-tag:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* Projects */
.project-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}

@media (min-width: 860px) {
  .project-grid { grid-template-columns: repeat(3, 1fr); }
}

.project-grid .project-card { margin-bottom: 0; }

.project-card h3 {
  font-size: var(--fs-h3);
  font-weight: 700;
  margin: 0 0 0.6rem;
}

.project-card p {
  margin: 0 0 0.9rem;
}

.project-card .tags {
  font-size: 0.78rem;
  color: var(--accent);
  margin: 0 0 1.2rem;
}

/* Footer */
.site-footer {
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--ink-muted);
  margin-top: 2.5rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-muted);
  border-radius: var(--radius-pill);
  border: 1px solid var(--rule);
  background: var(--glass);
  backdrop-filter: blur(10px);
  transition: color 0.15s ease, border-color 0.15s ease;
}

.back-link:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ── Shared chrome (home + essay) ────────────────────────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: transparent;
  border-bottom: none;
  backdrop-filter: none;
  padding: 0.65rem 0 0;
}

.site-header-inner {
  max-width: min(900px, var(--measure));
  height: 3rem;
  margin: 0 auto;
  padding: 0 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-size: 0.85rem;
  border: 1px solid color-mix(in srgb, var(--rule) 90%, var(--accent));
  border-radius: var(--radius-pill);
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.2);
  box-shadow:
    0 1px 0 color-mix(in srgb, #fff 8%, transparent) inset,
    var(--shadow-soft);
}

/* Essay & deck shells; same language as home. */
body:has(.post) .site-header-inner,
body:has(.post) .page {
  max-width: var(--measure);
}

body:has(.deck) .site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 0.65rem 1rem 0;
  pointer-events: none;
}

body:has(.deck) .site-header-inner {
  max-width: var(--stage, min(1100px, calc(100vw - 2.5rem)));
  pointer-events: auto;
}

body:has(.post) .page {
  padding: 1.25rem 1.25rem 4.5rem;
}

body:has(.post) .site-footer {
  margin-top: 0.75rem;
}

.post {
  max-width: 100%;
  position: relative;
  padding: var(--essay-pad);
  border-radius: calc(var(--radius-card) + 0.25rem);
  border: 1px solid color-mix(in srgb, var(--rule) 85%, var(--accent));
  background:
    linear-gradient(
      165deg,
      color-mix(in srgb, var(--bg-card) 96%, var(--accent)) 0%,
      var(--bg-card) 38%,
      var(--bg-card) 100%
    );
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 10%, transparent),
    0 30px 90px color-mix(in srgb, var(--ink) 12%, transparent),
    0 2px 0 color-mix(in srgb, #fff 6%, transparent) inset;
  overflow: clip;
}

.post::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 14rem;
  pointer-events: none;
  background:
    radial-gradient(ellipse 70% 90% at 0% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%),
    radial-gradient(ellipse 50% 80% at 100% 10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 65%);
  opacity: 0.9;
}

.post > * {
  position: relative;
  z-index: 1;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 1.35rem;
  font-size: 0;
}

.post-meta span {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 0.38rem 0.75rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.post h1 {
  font-weight: 800;
  font-size: clamp(2.35rem, 5.2vw, 3.55rem);
  line-height: 0.98;
  letter-spacing: -0.035em;
  text-wrap: balance;
  margin: 0 0 1.15rem;
  max-width: 14ch;
}

.post-dek {
  font-size: clamp(1.08rem, 1.6vw, 1.28rem);
  font-weight: 500;
  font-style: normal;
  line-height: 1.45;
  color: var(--ink);
  text-wrap: pretty;
  margin: 0 0 2.75rem;
  padding: 1rem 1.15rem 1rem 1.25rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 14px 14px 0;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent);
}

.post h1 + h2,
.post-dek + h2 {
  margin-top: 0.5rem;
}

.post h2 {
  font-weight: 800;
  font-size: clamp(1.35rem, 2.2vw, 1.7rem);
  letter-spacing: -0.025em;
  line-height: 1.2;
  color: var(--ink);
  text-wrap: balance;
  margin: 2.75rem 0 1.05rem;
  padding: 1.35rem 0 0;
  border-top: 1px solid color-mix(in srgb, var(--rule) 80%, var(--accent));
  font-variant-numeric: tabular-nums;
}

.h2-num {
  display: inline-block;
  min-width: 1.5em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.site-wordmark {
  flex: none;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
  transition: color 0.15s ease;
}

.site-wordmark:hover { color: var(--accent); }

/* Home: one sticky pill under the hero. Tabs always; wordmark expands in after
   the hero scrolls away. Grid 0fr→1fr + opacity/transform keeps the motion smooth. */
body:has(.title-page) {
  --header-h: 0px;
}

body:has(.title-page) .site-header {
  position: sticky;
  top: 0.65rem;
  z-index: 50;
  padding: 0;
  margin: 0 0 2.25rem;
  background: transparent;
  border: none;
}

body:has(.title-page) .site-header-inner {
  max-width: none;
  width: 100%;
  height: auto;
  min-height: 3rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0;
}

/* Tabs live inside the pill — drop the nested card chrome. Stay right so they
   never jump when the name expands on the left. */
body:has(.title-page) .site-header .tabs {
  display: flex;
  flex-wrap: nowrap;
  flex: 1 1 auto;
  justify-content: flex-end;
  margin: 0;
  margin-left: auto;
  padding: 0.15rem;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

body:has(.title-page) section {
  scroll-margin-top: 5.25rem;
}

/* Expand/collapse: outer grid 0fr→1fr, inner clip + fade/slide on the link. */
body:has(.title-page) .site-wordmark-slot {
  display: grid;
  grid-template-columns: 0fr;
  transition: grid-template-columns 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

body:has(.title-page) .site-wordmark-clip {
  min-width: 0;
  overflow: hidden;
}

body:has(.title-page) .site-wordmark-slot .site-wordmark {
  display: block;
  width: max-content;
  white-space: nowrap;
  padding-right: 0.85rem;
  opacity: 0;
  transform: translate3d(-0.5rem, 0, 0);
  pointer-events: none;
  transition:
    opacity 0.35s ease 0.02s,
    transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

body.header-compact:has(.title-page) .site-wordmark-slot {
  grid-template-columns: 1fr;
}

body.header-compact:has(.title-page) .site-wordmark-slot .site-wordmark {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  pointer-events: auto;
}

@media (prefers-reduced-motion: reduce) {
  body:has(.title-page) .site-wordmark-slot,
  body:has(.title-page) .site-wordmark-slot .site-wordmark {
    transition-duration: 0.01ms;
  }
}

/* Breadcrumb: Back > Title > heading 1 > heading 2 */
.crumb-back {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--ink);
  text-decoration: none;
  padding: 0.28rem 0.65rem 0.28rem 0.45rem;
  border-radius: var(--radius-pill);
  border: 1px solid color-mix(in srgb, var(--rule) 85%, transparent);
  background: color-mix(in srgb, var(--bg-card) 60%, transparent);
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  line-height: 1;
}

.crumb-back:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.crumb-back svg {
  flex: none;
  width: 14px;
  height: 14px;
  transition: transform 0.15s ease;
}

.crumb-back:hover svg {
  transform: translateX(-2px);
}

.crumb {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: baseline;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
}

.crumb-context,
.crumb-position {
  min-width: 0;
  display: flex;
  align-items: baseline;
  overflow: hidden;
}

.crumb-root,
.crumb-title,
.crumb-h1,
.crumb-h2 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* One divider rule for every crumb item */
.crumb-root::before,
.crumb-title::before,
.crumb-h1::before,
.crumb-h2::before {
  content: "\203A";
  margin: 0 0.5rem;
  color: color-mix(in srgb, var(--ink-muted) 75%, transparent);
}

.crumb-root { flex: none; transition: color 0.15s ease; color: inherit; text-decoration: none; }
.crumb-root:hover { color: var(--accent); }

.crumb-title { flex: 0 4 auto; color: inherit; text-decoration: none; transition: color 0.15s ease; }
.crumb-title:hover { color: var(--accent); }

.crumb-h1 { flex: 0 1 auto; }
.crumb-h2 { flex: 0 2 auto; }

/* Green marks only the deepest level currently in view */
.crumb .is-current {
  color: var(--accent);
  font-weight: 500;
}

.crumb-h1:empty,
.crumb-h1[hidden],
.crumb-h2:empty,
.crumb-h2[hidden] { display: none; }
.crumb-h1:empty::before,
.crumb-h2:empty::before { content: none; }

/* Deep links to a numbered section must clear the header. */
.post h2, .post h3 { scroll-margin-top: calc(var(--header-h) + 1rem); }

/* Pipe progress: a conduit that fills as you read. Must read as a clear object
   even at 0% fill (empty tube), on both light and dark essay backgrounds. */
.reading-progress {
  position: fixed;
  left: 50%;
  bottom: 1.35rem;
  top: auto;
  z-index: 80;
  width: min(var(--measure, 56.25rem), calc(100vw - 6rem));
  transform: translateX(-50%);
  pointer-events: none;
  padding: 0 0.65rem;
  box-sizing: border-box;
  /* Keep it out from under browser UI / home indicators a bit. */
  margin: 0;
}

.reading-progress-pipe {
  position: relative;
  height: 0.85rem;
  border-radius: 999px;
  border: 2px solid var(--accent);
  /* Hollow track: clearly lighter/darker than the page so the empty pipe shows. */
  background: light-dark(
    color-mix(in srgb, #ffffff 88%, var(--accent)),
    color-mix(in srgb, #0a0f09 55%, var(--accent))
  );
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent),
    0 0 24px color-mix(in srgb, var(--accent) 35%, transparent),
    0 10px 28px color-mix(in srgb, var(--ink) 16%, transparent),
    inset 0 1px 2px color-mix(in srgb, #000 22%, transparent),
    inset 0 -1px 0 color-mix(in srgb, #fff 12%, transparent);
  overflow: hidden;
}

/* Coupling rings — bright so the pipe is recognizable as a pipe. */
.reading-progress-pipe::before,
.reading-progress-pipe::after {
  content: "";
  position: absolute;
  top: 50%;
  z-index: 2;
  width: 0.62rem;
  height: 1.15rem;
  border-radius: 4px;
  transform: translateY(-50%);
  border: 2px solid var(--accent);
  background: light-dark(
    color-mix(in srgb, #fff 70%, var(--accent)),
    color-mix(in srgb, #1a2418 40%, var(--accent))
  );
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent),
    0 2px 8px color-mix(in srgb, var(--ink) 20%, transparent);
}

.reading-progress-pipe::before { left: -0.28rem; }
.reading-progress-pipe::after { right: -0.28rem; }

.reading-progress-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  min-width: 0;
  border-radius: 999px;
  background:
    linear-gradient(
      90deg,
      color-mix(in srgb, var(--accent) 70%, #064e2a),
      var(--accent) 40%,
      color-mix(in srgb, var(--accent) 65%, #fff)
    );
  box-shadow:
    0 0 14px color-mix(in srgb, var(--accent) 75%, transparent),
    inset 0 1px 0 color-mix(in srgb, #fff 40%, transparent);
  transition: width 50ms linear;
}

/* Leading meniscus when there is any fill (class set from JS). */
.reading-progress-bar.has-fill::after {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 0.7rem;
  border-radius: 999px;
  background: color-mix(in srgb, #fff 55%, var(--accent));
  opacity: 0.65;
  filter: blur(0.5px);
}

body:has(.post) .reading-progress {
  width: min(var(--measure), calc(100vw - 6.5rem));
}

@media (max-width: 640px) {
  .reading-progress {
    bottom: 1rem;
    left: 0.75rem;
    right: 4.25rem;
    width: auto;
    transform: none;
    padding: 0 0.5rem;
  }

  .reading-progress-pipe {
    height: 0.75rem;
  }

  body:has(.post) .reading-progress {
    width: auto;
  }
}

.post h3 {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.015em;
  line-height: 1.3;
  color: var(--ink);
  text-wrap: balance;
  margin: 2rem 0 0.7rem;
}

.post p strong:only-child {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-top: 0.35rem;
}

.post p strong:only-child::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.post p:has(> strong:only-child) {
  margin-bottom: 0.4rem;
}

.post p {
  margin: 0 0 1.15rem;
  line-height: 1.72;
  text-wrap: pretty;
  font-size: 1.0625rem;
}

.post ul {
  list-style: none;
  margin: 0 0 1.15rem;
  padding-left: 0;
}

.post ol:not(.references) {
  list-style: none;
  margin: 0 0 1.15rem;
  padding-left: 0;
  counter-reset: post-ol;
}

.post ol:not(.references) > li {
  counter-increment: post-ol;
  padding-left: 1.7rem;
  position: relative;
}

.post ol:not(.references) > li::before {
  content: counter(post-ol);
  position: absolute;
  left: 0;
  top: 0.1em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.post ul > li {
  position: relative;
  padding-left: 1.25rem;
}

.post ul > li::before {
  content: "";
  position: absolute;
  left: 0.15rem;
  top: 0.65em;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--accent);
}

.post li {
  margin-bottom: 0.55rem;
  line-height: 1.68;
}

.post table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0.6rem 0 1.7rem;
  font-size: 0.9rem;
  line-height: 1.5;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg) 55%, var(--bg-card));
}

.post th, .post td {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

.post th {
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

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

.post td:first-child {
  font-weight: 700;
  padding-right: 1rem;
}

.post code {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.86em;
  color: light-dark(#0d6b38, #b6ffce);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: 6px;
  padding: 0.08em 0.35em;
}

/* Section h2s carry their own top border. script.js inserts post-rule
   dividers for h3/h4 blocks. */
/* Footnote markers. Superscript links out to the reference list; adjacent markers
   on one claim (e.g. "4 15") get a hairline separator so they don't read as "415". */
.post sup.fn {
  font-size: 0.62em;
  line-height: 0;
  vertical-align: super;
  white-space: nowrap;
}

.post sup.fn a {
  color: var(--accent);
  font-weight: 700;
  /* A bare superscript digit is far too small to tap. Pad the hit area out and
     pull the margins back in so the line box is unaffected. */
  padding: 0.75em 0.7em;
  margin: -0.75em -0.45em;
}

.post sup.fn a:hover { text-decoration: underline; }

.post sup.fn a + a::before {
  content: ",";
  color: var(--ink-muted);
  margin-right: 0.1em;
}

.post ol.references,
.references {
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.55;
  counter-reset: ref;
  list-style: none;
  padding: 0;
  margin: 0;
}

.references li {
  position: relative;
  margin-bottom: 0.85rem;
  padding: 0.35rem 0.5rem 0.35rem 2rem;
  /* Jumping from a marker must clear the sticky header. */
  scroll-margin-top: calc(var(--header-h) + 1.5rem);
  transition: background 0.2s ease;
}

.references li::before {
  counter-increment: ref;
  content: counter(ref) ".";
  position: absolute;
  left: 0;
  top: 0.35rem;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.references li:target {
  /* Brief tint so the reader can see which entry they landed on. */
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 4px;
}

.references .ref-pub,
.references .ref-note { color: var(--ink-muted); }

.references a {
  color: var(--accent);
  overflow-wrap: anywhere;
}

.references a:hover { text-decoration: underline; }

/* Essay figures — static images exported from tldraw offline. */
.post-figure {
  margin: 1.85rem 0 2.15rem;
  padding: 0;
  border: none;
  background: transparent;
}

.post-figure img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  border-radius: var(--radius-card);
  border: 1px solid color-mix(in srgb, var(--rule) 88%, var(--accent));
  background: color-mix(in srgb, var(--bg-card) 90%, var(--bg));
  box-shadow: 0 1px 0 color-mix(in srgb, #fff 6%, transparent) inset;
}

.post-figure figcaption {
  margin: 0.85rem 0 0;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--ink-muted);
  text-align: center;
  text-wrap: balance;
}

.post-rule {
  border: none;
  position: relative;
  height: 1px;
  margin: 2.75rem 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    color-mix(in srgb, var(--accent) 70%, var(--rule)) 18%,
    color-mix(in srgb, var(--accent) 70%, var(--rule)) 82%,
    transparent 100%
  );
}

.post-rule--1::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--bg-card) 90%, transparent);
}

.post-rule--2,
.post-rule--3 {
  background: linear-gradient(
    90deg,
    transparent,
    var(--rule) 20%,
    var(--rule) 80%,
    transparent
  );
}

.post-rule--2::after,
.post-rule--3::after {
  display: none;
}

/* Scroll reveal */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .reveal {
      animation: reveal-in linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 25%;
    }
  }
}

@keyframes reveal-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (max-width: 720px) {
  .project-grid { grid-template-columns: 1fr; gap: 0.95rem; }

  body {
    background-attachment: scroll;
  }

  .page {
    padding: 1.15rem 0.85rem 3.5rem;
  }

  .site-header {
    padding: 0;
    top: 0.35rem;
  }

  body:has(.title-page) .site-header {
    margin-bottom: 1.75rem;
  }

  .site-header-inner {
    height: 2.75rem;
    min-height: 2.75rem;
    border-radius: var(--radius-pill);
    padding: 0 0.55rem;
    font-size: 0.78rem;
    gap: 0.25rem;
  }

  .site-wordmark {
    font-size: 0.78rem;
    font-weight: 700;
  }

  body:has(.title-page) .site-wordmark-slot {
    display: none !important;
  }

  body:has(.title-page) .site-header .tabs {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 0;
    padding: 0;
    gap: 0.25rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  body:has(.title-page) .site-header .tabs::-webkit-scrollbar { display: none; }

  body:has(.title-page) .site-header .tabs a {
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Crumb on essay & deck pages: full-width edge-to-edge flush navbar matching presentation deck */
  :root:has(.crumb), :root:has(.crumb-back) { --header-h: 2.85rem; }

  body:has(.post) .site-header,
  body:has(.deck) .site-header {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    padding: 0;
    margin: 0;
  }

  body:has(.deck) .site-header {
    position: fixed;
  }

  body:has(.post) .site-header-inner,
  body:has(.deck) .site-header-inner,
  .site-header-inner:has(.crumb),
  .site-header-inner:has(.crumb-back) {
    max-width: none;
    width: 100%;
    height: 2.85rem;
    min-height: 2.85rem;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    border-bottom: 1px solid color-mix(in srgb, var(--rule) 90%, var(--accent));
    box-shadow: none;
    padding: 0 0.85rem;
    gap: 0.45rem;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
  }

  .crumb-back {
    padding: 0.22rem 0.55rem 0.22rem 0.38rem;
    font-size: 0.78rem;
    gap: 0.25rem;
  }

  .crumb-back svg {
    width: 13px;
    height: 13px;
  }

  .crumb {
    flex: 1 1 auto;
    min-width: 0;
    gap: 0;
  }

  .crumb-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .crumb-title::before {
    margin: 0 0.35rem;
  }

  /* When scrolled into a section on mobile, hide the article title so the section gets full space */
  .crumb:has(.crumb-h1:not([hidden]):not(:empty)) .crumb-title {
    display: none;
  }

  .crumb-position {
    display: flex;
    min-width: 0;
    overflow: hidden;
  }

  .crumb-h1 {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .crumb-h1::before {
    content: "\203A";
    margin: 0 0.35rem 0 0;
    color: color-mix(in srgb, var(--ink-muted) 75%, transparent);
  }

  .crumb-h2 {
    display: none;
  }

  .card, .project-card {
    padding: 1.25rem 1.15rem;
    border-radius: 1rem;
    margin-bottom: 1rem;
  }

  .postcard-contact {
    padding: 1.35rem 1.25rem;
    border-radius: 1rem;
  }

  .timeline {
    padding-left: 1.25rem;
    margin-left: 0.15rem;
  }

  .postcard::before {
    left: -1.45rem;
  }

  .section-title {
    font-size: 1.45rem;
    margin-bottom: 1rem;
  }

  section {
    margin-bottom: 3.25rem;
  }

  body:has(.post) .page {
    padding: 0.85rem 0.75rem 3rem;
  }

  .post {
    border-radius: 1.15rem;
    padding: 1.25rem 1.15rem 1.75rem;
  }

  .post h1 {
    font-size: clamp(1.8rem, 8vw, 2.4rem);
    max-width: none;
  }

  .post-dek {
    font-size: 0.95rem;
    padding: 0.75rem 0.85rem;
  }

  #theme-toggle,
  .theme-toggle {
    width: 44px;
    height: 44px;
    right: 0.85rem;
    bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
  }
}
