/* ---------- Theme tokens ---------- */
:root {
  --bg: #fcfcfa;
  --panel: #f4f5f1;
  --text: #2c2e2a;
  --heading: #141513;
  --muted: #71746c;
  --rule: #e2e4dd;
  --accent: #22614a;
  --accent-soft: rgba(34, 97, 74, 0.08);
  --grid: rgba(34, 97, 74, 0.16);
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #121412;
  --panel: #191c19;
  --text: #d3d6cf;
  --heading: #f1f3ee;
  --muted: #8d9289;
  --rule: #2a2e2a;
  --accent: #6cc59b;
  --accent-soft: rgba(108, 197, 155, 0.12);
  --grid: rgba(108, 197, 155, 0.14);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121412;
    --panel: #191c19;
    --text: #d3d6cf;
    --heading: #f1f3ee;
    --muted: #8d9289;
    --rule: #2a2e2a;
    --accent: #6cc59b;
    --accent-soft: rgba(108, 197, 155, 0.12);
    --grid: rgba(108, 197, 155, 0.14);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
}
a:hover { text-decoration-color: var(--accent); }
p { margin: 0 0 0.9em; }
strong { font-weight: 600; color: var(--heading); }
h1, h2, h3 { color: var(--heading); margin: 0; }
h3 { font-weight: 600; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.wrap { max-width: 1000px; margin: 0 auto; padding: 0 28px; }
.meta { color: var(--muted); font-size: 0.9em; }

/* ---------- Navbar ---------- */
.navbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.navbar-inner { height: 56px; display: flex; align-items: center; gap: 24px; }
.brand {
  font-family: var(--serif); font-weight: 600; font-size: 18px;
  color: var(--heading); text-decoration: none; white-space: nowrap;
}
.nav { margin-left: auto; display: flex; gap: 22px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  font-size: 14px; color: var(--muted); text-decoration: none; white-space: nowrap;
  padding: 4px 0; border-bottom: 1.5px solid transparent;
}
.nav a:hover { color: var(--heading); }
.nav a.active { color: var(--heading); border-bottom-color: var(--accent); }

.theme-toggle {
  flex: none; width: 30px; height: 30px; display: grid; place-items: center;
  background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer;
}
.theme-toggle:hover { color: var(--accent); }
.theme-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.theme-toggle .half { fill: currentColor; stroke: none; }

/* ---------- Hero ---------- */
.hero { padding: 80px 0 64px; }
.hero-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 64px; align-items: center; }

.kicker { font-size: 13.5px; font-weight: 500; color: var(--accent); margin-bottom: 10px; letter-spacing: 0.01em; }
.hero h1 {
  font-family: var(--serif); font-weight: 600;
  font-size: clamp(38px, 5vw, 54px); line-height: 1.08; letter-spacing: -0.015em;
}
.social { list-style: none; padding: 0; margin: 18px 0 24px; display: flex; gap: 14px; }
.social a { display: block; color: var(--accent); transition: transform .15s ease, opacity .15s; }
.social a:hover { transform: translateY(-2px); }
.social svg { width: 28px; height: 28px; display: block; fill: currentColor; }

.lede { font-size: 17.5px; line-height: 1.6; color: var(--heading); margin-bottom: 26px; }

.affiliations { list-style: none; padding: 0; margin: 0; font-size: 14.5px; }
.affiliations li { display: flex; gap: 12px; align-items: baseline; padding: 4px 0; }
.aff-when { flex: none; width: 76px; color: var(--muted); }
.dot { flex: none; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid var(--accent); transform: translateY(-1px); }
.dot-now { background: var(--accent); animation: pulse 2.4s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent); }
  80%, 100% { box-shadow: 0 0 0 7px transparent; }
}

/* Figure 1 */
.figure { margin: 0; }
.continuum {
  display: block; width: 100%; height: auto;
  background: var(--panel); border: 1px solid var(--rule); border-radius: 10px;
}
.grid-dot { fill: var(--grid); }
.route { fill: none; stroke: var(--muted); stroke-opacity: .35; stroke-width: 1.3; stroke-dasharray: 3 4; }
.node-fill { fill: var(--bg); stroke: var(--rule); stroke-width: 1.2; }
.stroke-ink { fill: none; stroke: var(--muted); stroke-width: 1.4; stroke-linecap: round; }
.stroke-accent { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.label { font-family: var(--sans); font-size: 11.5px; font-weight: 600; fill: var(--heading); }
.sublabel { font-family: var(--sans); font-size: 10px; fill: var(--muted); }
.packet { fill: var(--accent); }
.p2, .p3 { opacity: 0.5; }
.figure figcaption { font-size: 13.5px; line-height: 1.55; color: var(--muted); margin-top: 12px; }
.figure figcaption strong { color: var(--heading); }

/* ---------- Sections ---------- */
.section { padding: 32px 0 40px; }
.sc-heading {
  font-family: var(--serif); font-weight: 600; font-size: 26px; letter-spacing: -0.01em;
  padding-bottom: 10px; border-bottom: 1px solid var(--rule); margin-bottom: 24px;
}

/* About */
.about-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 48px; }
.prose p { font-size: 16.5px; line-height: 1.7; }
.side { border-left: 1px solid var(--rule); padding-left: 28px; }
.side-title {
  font-family: var(--sans); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin-bottom: 10px;
}
.interests { list-style: none; padding: 0; margin: 0 0 26px; font-size: 15px; }
.interests li { padding: 3px 0; display: grid; grid-template-columns: 28px 1fr; line-height: 1.45; }
.interests span { font-family: var(--serif); font-style: italic; color: var(--accent); }
.edu { margin-bottom: 14px; font-size: 14.5px; line-height: 1.5; }
.edu p { margin: 0; }
.edu em { font-style: normal; color: var(--text); }

/* News */
.news { list-style: none; padding: 0; margin: 0; }
.news li { display: grid; grid-template-columns: 96px 1fr; gap: 18px; padding: 6px 0; font-size: 15.5px; }
.news time { color: var(--muted); font-size: 14px; white-space: nowrap; padding-top: 1px; font-variant-numeric: tabular-nums; }
.news p { margin: 0; }

/* CV entries */
.cv-entry { margin-bottom: 26px; }
.cv-row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.cv-row h3 { font-size: 16.5px; }
.cv-row.sub { margin-bottom: 6px; color: var(--text); font-size: 15px; }
.cv-row.sub em { font-style: normal; }
.cv-right { color: var(--muted); font-size: 14px; white-space: nowrap; }
.cv-entry ul { margin: 6px 0 0; padding-left: 20px; font-size: 15.5px; }
.cv-entry li { margin-bottom: 4px; }
.cv-entry li::marker { color: var(--muted); }
.cv-entry > p { margin: 4px 0 0; font-size: 15.5px; }

.chip {
  display: inline-block; vertical-align: 2px; margin-left: 8px;
  font-family: var(--sans); font-weight: 500; font-size: 11.5px; letter-spacing: 0.02em;
  padding: 1px 8px; border-radius: 999px; line-height: 1.6;
  color: var(--accent); background: var(--accent-soft);
}
.chip-live { color: var(--bg); background: var(--accent); }

/* Projects */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 22px; }
.filter {
  font-family: var(--sans); font-size: 13.5px; font-weight: 500;
  background: none; border: 1px solid var(--rule); border-radius: 999px; color: var(--muted);
  padding: 5px 14px; cursor: pointer; transition: color .15s, border-color .15s, background .15s;
}
.filter:hover { color: var(--heading); border-color: var(--muted); }
.filter.active { color: var(--bg); background: var(--heading); border-color: var(--heading); }

.projects { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.project {
  border: 1px solid var(--rule); border-radius: 10px; padding: 22px 24px;
  background: var(--bg); transition: border-color .2s;
}
.project:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--rule)); }
.project.hidden { display: none; }
.project h3 { font-family: var(--serif); font-size: 19px; line-height: 1.3; margin-bottom: 4px; letter-spacing: -0.005em; }
.project-cat { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--accent); margin-bottom: 6px; }
.project-cat .chip { margin-left: 6px; text-transform: none; letter-spacing: 0.02em; }
.project-meta { color: var(--muted); font-size: 13.5px; margin-bottom: 10px; }
.project-meta em { font-style: normal; }
.project > p:not(.project-cat):not(.project-meta):not(.stack), .project-body > p { font-size: 15px; line-height: 1.6; }
.stack { font-size: 13px; color: var(--muted); margin: 12px 0 0; }

.project.featured {
  grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1.5fr; gap: 36px;
  background: var(--panel); padding: 28px 30px;
}
.project.featured h3 { font-size: 23px; }
.findings { border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 12px 0 8px; margin: 14px 0; }
.findings-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin-bottom: 6px; }
.findings ul { list-style: none; padding: 0; margin: 0; }
.findings li { display: grid; grid-template-columns: 58px 1fr; gap: 12px; padding: 4px 0; font-size: 14.5px; line-height: 1.5; }
.num { font-family: var(--serif); font-weight: 600; font-size: 16px; color: var(--accent); white-space: nowrap; }
.project-next { font-size: 14px; color: var(--muted); margin-bottom: 0; }

.tiers { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: 14px; }
.tiers caption {
  text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); padding-bottom: 6px;
}
.tiers th, .tiers td { text-align: left; padding: 6px 0; border-top: 1px solid var(--rule); font-weight: 400; }
.tiers tr:last-child th, .tiers tr:last-child td { border-bottom: 1px solid var(--rule); }
.tiers th { color: var(--heading); font-weight: 600; padding-right: 12px; white-space: nowrap; }
.tiers .state { text-align: right; color: var(--muted); }
.tiers .state.done { color: var(--accent); font-weight: 500; }

/* Service */
.service { list-style: none; padding: 0; margin: 0; }
.service li { padding: 9px 0; border-bottom: 1px solid var(--rule); font-size: 15.5px; }
.service li:last-child { border-bottom: 0; }
.service em { font-style: normal; color: var(--muted); font-size: 14.5px; }
.service em a { color: var(--accent); }

/* Honours / skills */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 48px; }
.plain { list-style: none; padding: 0; margin: 0; font-size: 15px; }
.plain li { padding: 4px 0; }
.skills { display: grid; grid-template-columns: 150px 1fr; gap: 6px 16px; margin: 0; font-size: 15px; }
.skills dt { font-weight: 600; color: var(--heading); }
.skills dd { margin: 0; }

/* Contact / footer */
.contact-text { font-family: var(--serif); font-size: 22px; line-height: 1.5; max-width: 680px; color: var(--heading); }
.footer { padding: 24px 0 40px; color: var(--muted); font-size: 13px; }
.footer p { margin: 0; padding-top: 16px; border-top: 1px solid var(--rule); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .hero-grid, .about-grid, .project.featured { grid-template-columns: 1fr; gap: 28px; }
  .side { border-left: 0; padding-left: 0; border-top: 1px solid var(--rule); padding-top: 20px; }
}

@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .navbar-inner { gap: 14px; }
  .brand { display: none; }
  .nav { margin-left: 0; flex: 1; gap: 18px; }
  .hero { padding: 44px 0 36px; }
  .lede { font-size: 16.5px; }
  .sc-heading { font-size: 23px; }
  .news li { grid-template-columns: 1fr; gap: 0; }
  .cv-row { flex-direction: column; gap: 0; }
  .cv-right { white-space: normal; }
  .projects, .two-col { grid-template-columns: 1fr; }
  .two-col { gap: 0; }
  .two-col > div + div { margin-top: 36px; }
  .project, .project.featured { padding: 18px; }
  .skills { grid-template-columns: 1fr; gap: 0; }
  .skills dd { margin-bottom: 8px; }
  .contact-text { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .dot-now { animation: none; }
  .packet { display: none; }
  * { transition: none !important; }
}

/* Highlighted roles and institutions */
.affiliations strong { font-weight: 600; color: var(--heading); }
.inst { color: var(--accent); font-weight: 500; }
.prose strong { font-weight: 600; color: var(--heading); }

/* Figure 1, tucked into the carbon project card (textbook style) */
.fig-mini { margin: 22px 0 0; width: 220px; max-width: 100%; }
.fig-open {
  display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in;
  border-radius: 8px; transition: transform .15s ease;
}
.fig-open:hover { transform: translateY(-1px); }
.fig-open .continuum { border-radius: 8px; }
.fig-open:hover .continuum { border-color: color-mix(in srgb, var(--accent) 45%, var(--rule)); }
.fig-mini figcaption { font-size: 12.5px; line-height: 1.45; color: var(--muted); margin-top: 6px; }
.fig-mini figcaption strong { color: var(--heading); }
.fig-hint { white-space: nowrap; }

.fig-dialog {
  width: min(640px, calc(100vw - 32px)); padding: 20px 20px 16px; border: 1px solid var(--rule);
  border-radius: 12px; background: var(--bg); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.fig-dialog::backdrop { background: rgba(10, 12, 10, 0.45); backdrop-filter: blur(2px); }
.fig-dialog .continuum { border-radius: 8px; }
.fig-dialog-caption { font-size: 14px; line-height: 1.55; color: var(--muted); margin: 12px 0 0; }
.fig-dialog-caption strong { color: var(--heading); }
.fig-close {
  position: absolute; top: 6px; right: 10px; width: 32px; height: 32px;
  background: none; border: 0; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer;
}
.fig-close:hover { color: var(--heading); }
.fig-dialog-slot { margin-top: 18px; }

/* Profile (left) + About (right), one opening section */
.hero { padding: 64px 0 48px; }
.profile-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 64px; align-items: start; }
.profile-col { position: relative; }
.portrait {
  display: block; width: 190px; height: auto; aspect-ratio: 4 / 5; object-fit: cover;
  border-radius: 14px; border: 1px solid var(--rule); margin-bottom: 22px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(0, 0, 0, 0.06);
}
.profile-col h1 { font-size: 34px; line-height: 1.12; }
.profile-col .social { margin: 14px 0 18px; }
.profile-col .lede { font-size: 15.5px; line-height: 1.6; color: var(--text); margin-bottom: 20px; }
.profile-col .affiliations { font-size: 14px; border-top: 1px solid var(--rule); padding-top: 14px; }
.profile-col .affiliations li { padding: 5px 0; }
.profile-col .aff-when { width: 74px; white-space: nowrap; }

.bio-heading {
  font-family: var(--serif); font-weight: 600; font-size: 34px; letter-spacing: -0.01em;
  margin: 2px 0 16px;
}
.bio-col .prose p { font-size: 16.5px; line-height: 1.7; }
.bio-cols {
  display: grid; grid-template-columns: 1fr 1fr; gap: 32px;
  margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--rule);
}
.bio-cols .interests { margin-bottom: 0; }

@media (max-width: 900px) {
  .profile-grid { grid-template-columns: 1fr; gap: 36px; }
  .profile-col { display: grid; grid-template-columns: 150px 1fr; column-gap: 24px; align-items: start; }
  .profile-col .portrait { width: 150px; }
  .profile-col .portrait-btn { grid-row: span 3; margin-bottom: 0; align-self: start; }
  .profile-col .lede, .profile-col .affiliations { grid-column: 1 / -1; }
  .profile-col .lede { margin-top: 20px; }
}
@media (max-width: 640px) {
  .hero { padding: 36px 0 28px; }
  .profile-col { display: block; }
  .profile-col .portrait { width: 132px; }
  .profile-col .portrait-btn { margin-bottom: 18px; }
  .profile-col h1 { font-size: 30px; }
  .bio-heading { font-size: 28px; }
  .bio-cols { grid-template-columns: 1fr; gap: 22px; }
}

/* Easter egg: click the photo, a cat taps its watch for 3 seconds */
.portrait-btn {
  display: block; padding: 0; margin: 0 0 22px; border: 0; background: none;
  cursor: pointer; border-radius: 14px; transition: transform .15s ease;
}
.portrait-btn .portrait { margin-bottom: 0; }
.portrait-btn:hover { transform: rotate(-1.5deg) scale(1.02); }
.portrait-btn:active { transform: scale(0.98); }

.huh {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  pointer-events: none; opacity: 0; transition: opacity .2s ease;
}
.huh.show { opacity: 1; pointer-events: auto; cursor: pointer; }
.huh-card {
  position: relative; width: min(300px, 72vw); aspect-ratio: 1;
  border-radius: 22px; overflow: hidden; background: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28), 0 2px 8px rgba(0, 0, 0, 0.12);
  transform: scale(0.6) rotate(-6deg);
}
.huh.show .huh-card { animation: huh-pop .45s cubic-bezier(.2, 1.6, .4, 1) forwards; }
.huh-base { display: block; width: 100%; height: 100%; }
.huh-hand {
  position: absolute; left: 6.5%; top: 47.75%; width: 38.25%; height: auto;
  transform-origin: 18% 55%;
}
.huh.show .huh-hand { animation: huh-tap .5s ease-in-out .3s 3; }
.huh-bubble {
  position: absolute; top: 9%; right: 7%; padding: 4px 12px; border-radius: 999px;
  font-family: var(--sans); font-weight: 600; font-size: 17px; color: #141513; background: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); transform: scale(0); transform-origin: 20% 100%;
}
.huh.show .huh-bubble { animation: huh-bubble .35s cubic-bezier(.2, 1.6, .4, 1) .15s forwards; }

@keyframes huh-pop { to { transform: scale(1) rotate(0deg); } }
@keyframes huh-bubble { to { transform: scale(1); } }
@keyframes huh-tap {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  45% { transform: translate(5%, 12%) rotate(16deg); }
  60% { transform: translate(6%, 15%) rotate(19deg); }
}
@media (prefers-reduced-motion: reduce) {
  .huh.show .huh-card { animation: none; transform: none; }
  .huh.show .huh-hand { animation: none; }
  .huh.show .huh-bubble { animation: none; transform: none; }
}
