/* Self-hosted fonts — replaces the render-blocking Google Fonts CSS.
   font-display: swap lets the browser paint with the fallback first and
   swap to the web font once it's available, so text never blocks render. */
@font-face {
  font-family: "Instrument Serif";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/instrument-serif-400.woff2") format("woff2");
}
@font-face {
  font-family: "Instrument Serif";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/instrument-serif-400-italic.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/inter-var.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("/fonts/jetbrains-mono-var.woff2") format("woff2");
}

:root {
  color-scheme: light dark;

  --bg: #eef0ee;
  --bg-deep: #e3e6e3;
  --ink: #14161e;
  --ink-soft: #2c2f3a;
  --muted: #5b5f68;
  --rule: #d2d5d2;

  --accent-warm: #2e4cc7;
  --accent-cool: #7a92dc;

  --serif: "Instrument Serif", "EB Garamond", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
    sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --max: 1120px;
  --gutter: clamp(1.25rem, 4vw, 3rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0e14;
    --bg-deep: #07080d;
    --ink: #ece8de;
    --ink-soft: #c4c2bd;
    --muted: #7a7d86;
    --rule: #242736;

    --accent-warm: #6f8cf0;
    --accent-cool: #b0c2f2;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 300;
  font-size: 17px;
  line-height: 1.6;
  letter-spacing: 0.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
  overflow-x: hidden;
}

/* ---------- ambient layers ---------- */

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}
@media (prefers-color-scheme: dark) {
  .grain {
    mix-blend-mode: screen;
    opacity: 0.35;
  }
}

/* Two soft cobalt orbs revolving around the viewport center as a slow
   ambient backdrop. The container sits at the screen's center; each orb
   is translated out to its corner-ish position and the container's
   rotation animation orbits them around that center. */

.orb-orbit {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 0;
  animation: orbit-rotate 60s linear infinite;
  will-change: transform;
}

.orb {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(80px);
  opacity: 0.55;
  will-change: transform;
}
.orb-a {
  width: 520px;
  height: 520px;
  background: radial-gradient(circle, var(--accent-warm), transparent 65%);
  transform: translate(calc(35vw - 50%), calc(-35vh - 50%));
}
.orb-b {
  width: 460px;
  height: 460px;
  background: radial-gradient(circle, var(--accent-warm), transparent 65%);
  transform: translate(calc(-35vw - 50%), calc(35vh - 50%));
}

@media (prefers-color-scheme: dark) {
  .orb {
    opacity: 0.35;
  }
}

@keyframes orbit-rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .orb-orbit {
    animation: none;
  }
  html {
    scroll-behavior: auto;
  }
}

/* ---------- top bar ---------- */

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem var(--gutter);
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.02em;
}
.topbar .mark {
  color: var(--ink);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-decoration: none;
  transition: color 0.2s;
}
a.mark:hover {
  color: var(--accent-warm);
}
.topbar .status {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}
.topbar .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-warm);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-warm) 60%, transparent);
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-warm) 50%, transparent);
  }
  50% {
    box-shadow: 0 0 0 8px transparent;
  }
}

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

main {
  position: relative;
  z-index: 2;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

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

.hero {
  min-height: calc(100vh - 6rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4rem 0 6rem;
}

.name {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(3.4rem, 11vw, 8.5rem);
  line-height: 0.95;
  letter-spacing: -0.025em;
  margin: 0 0 2.5rem;
  color: var(--ink);
}
.name-line {
  display: block;
  margin-left: calc(var(--i) * 1.6ch);
  opacity: 0;
  transform: translateY(0.6em);
  animation: rise 1s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  animation-delay: calc(120ms + var(--i) * 130ms);
}
.name-line:nth-child(2) {
  font-style: italic;
  font-weight: 400;
  color: var(--ink-soft);
}
.name-line:nth-child(3) {
  background: linear-gradient(
    100deg,
    var(--accent-warm) 0%,
    var(--ink) 55%,
    var(--accent-cool) 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.dot-end {
  color: var(--accent-warm);
}

@keyframes rise {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.lede {
  font-family: var(--serif);
  font-size: clamp(1.15rem, 1.6vw, 1.45rem);
  line-height: 1.5;
  max-width: 38ch;
  color: var(--ink-soft);
  margin: 0 0 2.5rem;
  margin-left: clamp(0px, 6vw, 4ch);
  opacity: 0;
  animation: rise 1s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  animation-delay: 700ms;
}
.lede em {
  font-style: normal;
  color: var(--accent-warm);
  margin-right: 0.25rem;
}
.lede a {
  color: var(--ink);
  border-bottom: 1px solid var(--accent-warm);
  text-decoration: none;
  transition: color 0.2s;
}
.lede a:hover {
  color: var(--accent-warm);
}
.lede .muted {
  color: var(--muted);
}

.quicknav {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-left: clamp(0px, 6vw, 4ch);
  opacity: 0;
  animation: rise 1s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  animation-delay: 900ms;
}
.quicknav a {
  color: var(--ink-soft);
  text-decoration: none;
  padding: 0 0.35em;
  transition: color 0.2s;
}
.quicknav a:hover {
  color: var(--accent-warm);
}

/* ---------- sections ---------- */

.section {
  display: grid;
  grid-template-columns: 8rem 1fr;
  gap: clamp(1.5rem, 4vw, 3rem);
  padding: 5rem 0;
  border-top: 1px solid var(--rule);
  align-items: start;
}

@media (max-width: 720px) {
  .section {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    padding: 3.5rem 0;
  }
}

.section-label {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.06em;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  position: sticky;
  top: 2rem;
}
.section-label .num {
  color: var(--accent-warm);
  font-weight: 500;
}
@media (max-width: 720px) {
  .section-label {
    position: static;
    flex-direction: row;
    gap: 0.75rem;
  }
}

.section-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.8rem, 3.4vw, 2.6rem);
  line-height: 1.1;
  letter-spacing: -0.015em;
  margin: 0 0 2rem;
  color: var(--ink);
}

.section-body {
  max-width: 60ch;
}

.about p {
  font-family: var(--serif);
  font-size: clamp(1.1rem, 1.4vw, 1.3rem);
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0 0 1.25rem;
}
.about .muted {
  color: var(--muted);
  font-style: italic;
}

/* ---------- timeline (work) ---------- */

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}
.timeline li {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 1.5rem;
  padding: 1.25rem 0;
  border-top: 1px dashed var(--rule);
  align-items: baseline;
}
.timeline li:first-child {
  border-top: none;
  padding-top: 0;
}
.timeline .years {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.timeline h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.4rem;
  letter-spacing: -0.01em;
  margin: 0 0 0.15rem;
  color: var(--ink);
}
.timeline .org {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.timeline .org a,
.about a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, currentColor 30%, transparent);
  transition: color 0.2s, border-color 0.2s;
}
.timeline .org a:hover,
.about a:hover {
  color: var(--accent-warm);
  border-bottom-color: var(--accent-warm);
}

@media (max-width: 540px) {
  .timeline li {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }
}

/* ---------- projects ---------- */

.projects {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}
.projects li {
  padding: 1.5rem 0;
  border-top: 1px solid var(--rule);
  position: relative;
  transition: padding-left 0.3s ease;
}
.projects li:first-child {
  border-top: none;
}
.projects li::before {
  content: "";
  position: absolute;
  left: -0.5rem;
  top: 50%;
  width: 0;
  height: 1px;
  background: var(--accent-warm);
  transition: width 0.3s ease;
}
.projects li:hover {
  padding-left: 1rem;
}
.projects li:hover::before {
  width: 1rem;
}
.projects h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.55rem;
  letter-spacing: -0.01em;
  margin: 0 0 0.25rem;
  color: var(--ink);
}
.projects .meta {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.06em;
  margin: 0 0 0.85rem;
}
.projects p {
  margin: 0;
  color: var(--ink-soft);
  max-width: 58ch;
}
.projects a {
  color: var(--ink);
  border-bottom: 1px solid var(--accent-warm);
  text-decoration: none;
}
.projects a:hover {
  color: var(--accent-warm);
}

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

.writing {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
}
.writing li {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 1.5rem;
  padding: 1.25rem 0;
  border-top: 1px dashed var(--rule);
  align-items: baseline;
}
.writing li:first-child {
  border-top: none;
  padding-top: 0;
}
.writing .years {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}
.writing h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.3rem;
  letter-spacing: -0.005em;
  margin: 0 0 0.2rem;
}
.writing h3 a {
  color: var(--ink);
  border-bottom: 1px solid var(--accent-warm);
  text-decoration: none;
  transition: color 0.2s;
}
.writing h3 a:hover {
  color: var(--accent-warm);
}
.writing .meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.aside {
  color: var(--muted);
  font-style: italic;
  font-family: var(--serif);
  margin-top: 1.5rem;
}
.aside a {
  color: var(--ink);
  border-bottom: 1px solid var(--accent-warm);
  text-decoration: none;
  transition: color 0.2s, border-color 0.2s;
}
.aside a:hover {
  color: var(--accent-warm);
}

@media (max-width: 540px) {
  .writing li {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }
}

/* ---------- contact ---------- */

.contact {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.contact a {
  font-family: var(--serif);
  font-size: 1.55rem;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.35rem;
  display: inline-flex;
  justify-content: space-between;
  width: 100%;
  max-width: 22rem;
  transition: color 0.2s, border-color 0.2s;
}
.contact a:hover {
  color: var(--accent-warm);
  border-bottom-color: var(--accent-warm);
}

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

.footer {
  position: relative;
  z-index: 2;
  max-width: var(--max);
  margin: 4rem auto 0;
  padding: 2rem var(--gutter) 3rem;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.footer .muted {
  color: var(--muted);
  font-style: italic;
}

/* ---------- reveal on scroll ---------- */

.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.9s cubic-bezier(0.2, 0.8, 0.2, 1),
    transform 0.9s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* ---------- page transitions ----------
   Cross-document View Transitions for same-origin navigation: the old
   page fades out and the new one fades in. Browsers without support
   just navigate instantly — no degradation, no JS needed. */

@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: vt-fade-out 260ms cubic-bezier(0.4, 0, 1, 0.6) forwards;
}
::view-transition-new(root) {
  animation: vt-fade-in 320ms cubic-bezier(0, 0.4, 0.4, 1) 160ms both;
}

@keyframes vt-fade-out {
  to {
    opacity: 0;
  }
}
@keyframes vt-fade-in {
  from {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none !important;
  }
}

/* ---------- breadcrumbs (shared by /lab and /writing) ---------- */

.crumbs {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-bottom: 3rem;
  text-transform: lowercase;
}
.crumbs a {
  color: var(--ink-soft);
  text-decoration: none;
  transition: color 0.2s;
}
.crumbs a:hover {
  color: var(--accent-warm);
}
.crumbs span[aria-hidden] {
  margin: 0 0.5rem;
  color: var(--muted);
}

/* ---------- lab cards (shared by /lab/ index and the home page) ---------- */

.lab-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 640px) {
  .lab-list {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.75rem 2rem;
  }
}

@media (min-width: 1000px) {
  .lab-list {
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem 2.25rem;
  }
}

.lab-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.5rem 0 0;
  text-decoration: none;
  color: inherit;
  border-top: 1px solid var(--rule);
  height: 100%;
  position: relative;
}
.lab-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: -1px;
  height: 2px;
  width: 0;
  background: var(--accent-warm);
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.lab-card:hover::before {
  width: 55%;
}

.lab-num {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent-warm);
  letter-spacing: 0.04em;
}
.lab-name {
  font-family: var(--serif);
  font-size: 1.55rem;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--ink);
}
.lab-meta {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.04em;
}
.lab-desc {
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-top: 0.3rem;
}

/* ---------- selection ---------- */

::selection {
  background: var(--accent-warm);
  color: var(--bg);
}
