/* Mobile-first: base rules target small screens, min-width queries add layout. */

:root {
  color-scheme: dark;
  --bg: #0e1012;
  --surface: #16191d;
  --line: #2a2f36;
  --text: #e8e6e1;
  --muted: #9aa3ad;
  --accent: #f0b85a;
  --accent-ink: #1a1408;
  --header-bg: rgba(14, 16, 18, 0.88);
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --header-h: 60px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f4ee;
  --surface: #fffefb;
  --line: #d9d5ca;
  --text: #16181b;
  --muted: #565c63;
  --accent: #8a5200;
  --accent-ink: #fffefb;
  --header-bg: rgba(246, 244, 238, 0.88);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 16px);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.65 var(--sans);
  transition: background-color 0.25s ease, color 0.25s ease;
}

h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
img { display: block; max-width: 100%; height: auto; background: #1b1f24; }

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.wrap { width: min(100% - 2.5rem, 1080px); margin-inline: auto; }
.accent { color: var(--accent); }
.muted { color: var(--muted); }
.label, .eyebrow, .role-date, .entry-meta, .project-kicker {
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--muted);
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 20;
  padding: 0.5rem 0.75rem;
  background: var(--accent);
  color: var(--accent-ink);
}
.skip-link:focus { top: 0.5rem; }

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--header-h);
}
.logo {
  font: 500 1rem var(--mono);
  color: var(--text);
  text-decoration: none;
}
.header-actions { display: flex; align-items: center; gap: 0.75rem; }

.site-nav {
  display: none;
  position: absolute;
  inset: 100% 0 auto 0;
  padding: 0.5rem 1.25rem 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.site-nav.is-open { display: block; }
.site-nav a {
  display: block;
  padding: 0.65rem 0;
  font: 400 0.9375rem var(--mono);
  color: var(--muted);
  text-decoration: none;
}
.site-nav a:hover, .site-nav a.is-active { color: var(--accent); }

.nav-toggle {
  min-height: 36px;
  padding: 0 0.75rem;
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: 400 0.8125rem var(--mono);
  cursor: pointer;
}

.theme-toggle {
  position: relative;
  width: 46px;
  height: 26px;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  cursor: pointer;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}
.theme-toggle::before {
  /* Pseudo-element touch target: the visible switch stays small. */
  content: "";
  position: absolute;
  inset: -10px -4px;
}
.theme-toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform 0.25s ease, background-color 0.25s ease;
}
.theme-toggle[aria-checked="true"] .theme-toggle-knob { transform: translateX(20px); }

/* Hero */
.hero {
  display: grid;
  gap: 2.5rem;
  padding-block: 3.5rem;
}
.eyebrow { margin-bottom: 0.75rem; }
h1 {
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.hero-lede {
  margin-top: 1.25rem;
  max-width: 28ch;
  font-size: clamp(1.25rem, 3.4vw, 1.5rem);
  line-height: 1.35;
}
.hero-role {
  margin-top: 1rem;
  font: 400 0.875rem/1.7 var(--mono);
  color: var(--muted);
}
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.75rem; }
.button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 1.1rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: 500 0.875rem var(--mono);
  text-decoration: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.button:hover { border-color: var(--accent); }
.button-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* Quantization demo */
.quant-demo {
  min-width: 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}
.quant-head code { font: 400 0.875rem var(--mono); }
.quant-head output { color: var(--accent); }
#q-canvas { display: block; width: 100%; height: 190px; margin-top: 0.75rem; }
.quant-slider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  font: 400 0.8125rem var(--mono);
  color: var(--muted);
}
.quant-slider span { flex: none; }
.quant-slider input {
  flex: 1;
  min-width: 0;
  height: 28px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.quant-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.quant-stats dt, .metrics dt { font: 400 0.75rem var(--mono); color: var(--muted); }
.quant-stats dd, .metrics dd { font: 500 1rem var(--mono); }
.quant-note { margin-top: 0.75rem; font-size: 0.8125rem; line-height: 1.5; color: var(--muted); }

/* Sections */
.section { padding-block: 3.5rem; border-top: 1px solid var(--line); }
h2 {
  margin-bottom: 2rem;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.ssa {
  margin-right: 0.35em;
  font: 400 0.7em var(--mono);
  color: var(--accent);
  white-space: nowrap;
}
h3 { font-size: 1.125rem; font-weight: 600; line-height: 1.35; }
h4 { font-size: 1rem; font-weight: 600; line-height: 1.4; }

/* About */
.about-grid { display: grid; gap: 2rem; }
.portrait { width: min(100%, 240px); border: 1px solid var(--line); border-radius: 6px; }
.prose { display: grid; gap: 1rem; max-width: 66ch; }
.interests .label { display: block; margin-bottom: 0.15rem; }

/* Experience and education rows */
.org + .org { margin-top: 2.5rem; }
.org-place { margin-left: 0.35rem; font: 400 0.8125rem var(--mono); color: var(--muted); }
.role { display: grid; gap: 0.25rem; padding-top: 1.25rem; }
.role ul { display: grid; gap: 0.5rem; margin-top: 0.5rem; max-width: 72ch; }
.role li { position: relative; padding-left: 1.1rem; }
.role li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.75em;
  width: 0.45rem;
  height: 1px;
  background: var(--accent);
}
#education .role p:not(.role-date) { max-width: 72ch; }

/* Projects */
.project-grid { display: grid; gap: 1.25rem; }
.project {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  transition: background-color 0.25s ease, border-color 0.15s ease;
}
.project:hover { border-color: var(--accent); }
.project img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.project-body { display: flex; flex: 1; flex-direction: column; gap: 0.6rem; padding: 1.1rem; }
.tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.25rem; }
.tags li {
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  font: 400 0.75rem/1.6 var(--mono);
  color: var(--muted);
}
.project-link {
  align-self: flex-start;
  margin-top: auto;
  padding-block: 0.4rem;
  font: 500 0.8125rem var(--mono);
}
.metrics { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; }

/* Publications */
.group-title {
  margin-top: 2.25rem;
  font: 500 0.8125rem var(--mono);
  color: var(--accent);
}
.group-title:first-of-type { margin-top: 0; }
.entries { display: grid; gap: 1.5rem; margin-top: 1rem; }
.entries p:not(.entry-meta) { max-width: 72ch; }

/* Skills */
.skill-grid { display: grid; gap: 1.5rem; }
.skill-grid dt { font-weight: 600; }
.skill-grid dd { color: var(--muted); }

/* Contact */
.contact-lede { max-width: 48ch; margin-bottom: 1.5rem; font-size: 1.125rem; }
.contact-list { display: grid; gap: 0.5rem; }
.contact-list li { display: grid; overflow-wrap: anywhere; }
.contact-list a { padding-block: 0.15rem; font-family: var(--mono); }

.site-footer {
  padding-block: 1.5rem;
  border-top: 1px solid var(--line);
  font-size: 0.8125rem;
  color: var(--muted);
}

@media (min-width: 640px) {
  .about-grid { grid-template-columns: 200px 1fr; }
  .project-grid { grid-template-columns: repeat(2, 1fr); }
  .project-featured { grid-column: 1 / -1; }
  .skill-grid { grid-template-columns: repeat(2, 1fr); }
  .role { grid-template-columns: 170px 1fr; gap: 1.5rem; }
  .contact-list li { grid-template-columns: 90px 1fr; align-items: baseline; }
}

@media (min-width: 900px) {
  .nav-toggle { display: none; }
  .site-nav {
    display: flex;
    position: static;
    gap: 1.25rem;
    padding: 0;
    background: none;
    border: 0;
  }
  .site-nav a { padding: 0.25rem 0; font-size: 0.8125rem; }
  .header-actions { order: 3; }

  .hero {
    grid-template-columns: 1fr minmax(0, 440px);
    align-items: center;
    gap: 3rem;
    padding-block: 5.5rem;
  }
  .about-grid { grid-template-columns: 240px 1fr; gap: 3rem; }
  .project-featured { flex-direction: row; }
  .project-featured img { width: 50%; aspect-ratio: auto; }
  .project-featured .project-body { padding: 1.5rem; }
  .skill-grid { grid-template-columns: repeat(3, 1fr); }
  .section { padding-block: 4.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}
