/* ---------- Theme tokens ---------- */
:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --text: #1b1c1f;
  --muted: #5d6169;
  --border: #e3e1db;
  --accent: #2f5bd3;
  --accent-soft: #e6ecfb;
  --boid: #2f5bd3;
  --boid-alt: #d9572b;
  --grid-low: #c9cfdb;
  --grid-mid: #7d97d9;
  --grid-high: #1f45b5;
  --particle: #e0531f;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --max-w: 760px;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111215;
    --surface: #18191d;
    --text: #e8e8ea;
    --muted: #a0a3aa;
    --border: #2a2c31;
    --accent: #7ea2ff;
    --accent-soft: #1d2540;
    --boid: #7ea2ff;
    --boid-alt: #ff9466;
    --grid-low: #2e3340;
    --grid-mid: #4d68b0;
    --grid-high: #9db8ff;
    --particle: #ff8a57;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111215;
  --surface: #18191d;
  --text: #e8e8ea;
  --muted: #a0a3aa;
  --border: #2a2c31;
  --accent: #7ea2ff;
  --accent-soft: #1d2540;
  --boid: #7ea2ff;
  --boid-alt: #ff9466;
  --grid-low: #2e3340;
  --grid-mid: #4d68b0;
  --grid-high: #9db8ff;
  --particle: #ff8a57;
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

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

h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 0 0 0.5rem; }
h2 { font-size: 1.5rem; margin: 2.5rem 0 1rem; }
h3 { font-size: 1.1rem; margin: 0 0 0.25rem; }

p { margin: 0 0 1rem; }

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

img { max-width: 100%; display: block; }

.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 16px;
}

.muted { color: var(--muted); }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 56px;
  max-width: 1100px;
}

.brand {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

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

.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  font-size: 0.95rem;
}

.nav a:hover { color: var(--text); background: var(--accent-soft); }
.nav a[aria-current="page"] { color: var(--text); font-weight: 600; }

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  width: 34px;
  height: 34px;
  margin-left: 0.25rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle svg { width: 16px; height: 16px; }

/* ---------- Hero / simulation ---------- */
.hero {
  position: relative;
  height: calc(100svh - 57px);
  min-height: 420px;
  max-height: 900px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  touch-action: pan-y;
}

/* Home page shows only the simulation, so let it fill the screen. */
body.home .hero {
  max-height: none;
  border-bottom: none;
}

#sim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hero-text {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12%;
  pointer-events: none;
}

.hero-text .container { max-width: 1100px; }

.hero-text h1 { margin-bottom: 0.25rem; }

.hero-text p {
  font-size: 1.15rem;
  color: var(--muted);
  max-width: 34ch;
}

.hero-text h1,
.hero-text p {
  /* Keeps the text readable over the simulation */
  text-shadow: 0 0 12px var(--bg), 0 0 4px var(--bg);
}

.hero-text a { pointer-events: auto; }

/* Simulation controls */
.sim-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  width: min(260px, calc(100% - 32px));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.sim-controls summary {
  cursor: pointer;
  padding: 0.55rem 0.8rem;
  font-weight: 600;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sim-controls summary::-webkit-details-marker { display: none; }
.sim-controls summary::after { content: "+"; color: var(--muted); font-weight: 400; }
.sim-controls[open] summary::after { content: "–"; }

.sim-controls .body { padding: 0 0.8rem 0.8rem; }

.control { margin-bottom: 0.6rem; }

.control label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  margin-bottom: 0.1rem;
}

.control output { font-family: var(--font-mono); color: var(--text); }

.control input[type="range"] { width: 100%; accent-color: var(--accent); }

.control select {
  width: 100%;
  font: inherit;
  padding: 0.25rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.button-row { display: flex; gap: 0.5rem; margin-top: 0.75rem; }

.btn {
  flex: 1;
  font: inherit;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  display: inline-block;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }

.sim-hint { color: var(--muted); font-size: 0.8rem; margin: 0.5rem 0 0; }

.sim-controls .body {
  max-height: calc(100svh - 57px - 100px);
  overflow-y: auto;
}

/* Network diagram card, bottom-right of the simulation */
.network-card {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 1;
  width: 200px;
  padding: 0.5rem 0.6rem 0.6rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.network-title { margin: 0 0 0.35rem; font-size: 0.75rem; color: var(--muted); }
.topology-view { display: block; width: 100%; height: 120px; }

.sim-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 0.75rem 0 0;
}
.sim-stats div {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
}
.sim-stats dt { color: var(--muted); font-size: 0.75rem; }
.sim-stats dd { margin: 0; font-family: var(--font-mono); font-size: 1rem; }

@media (pointer: fine) {
  #sim { cursor: grab; }
  #sim:active { cursor: grabbing; }
}

/* Swarm success tile */
.sim-side {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 1;
  width: 250px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Pace buttons: a segmented control */
.pace-buttons { display: flex; gap: 0; }
.pace-buttons .btn {
  font-size: 0.8rem;
  padding: 0.45rem 0.4rem;
  border-radius: 0;
  margin-left: -1px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.pace-buttons .btn:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.pace-buttons .btn:last-child { border-radius: 0 6px 6px 0; }
.pace-buttons .btn[aria-pressed="true"] {
  position: relative;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.story-line {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--muted);
  text-shadow: 0 0 6px var(--bg), 0 0 2px var(--bg);
}

.perf-tile {
  padding: 0.6rem 0.75rem 0.55rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.75rem;
  color: var(--muted);
}

.perf-head { display: flex; justify-content: space-between; align-items: baseline; }
.perf-label { font-weight: 600; color: var(--text); font-size: 0.85rem; }
.perf-value { font-weight: 600; color: var(--text); font-size: 1.6rem; line-height: 1.1; }
.perf-sub { margin: 0 0 0.4rem; }

.perf-chart { position: relative; }
.perf-chart canvas { display: block; width: 100%; height: 56px; cursor: crosshair; touch-action: pan-y; }

.perf-tip {
  position: absolute;
  bottom: calc(100% + 6px);
  padding: 0.35rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.12);
  white-space: nowrap;
  pointer-events: none;
  color: var(--muted);
}
.perf-tip b { color: var(--text); font-weight: 600; margin-left: 0.25rem; }
.perf-tip-time { color: var(--text); margin-bottom: 0.15rem; }

.perf-legend { display: flex; gap: 0.9rem; margin-top: 0.35rem; align-items: center; white-space: nowrap; }
.perf-sub { white-space: nowrap; }

.sw {
  display: inline-block;
  width: 12px;
  height: 2px;
  border-radius: 1px;
  margin-right: 0.35rem;
  vertical-align: middle;
}
.sw.best { background: var(--particle); }
.sw.avg { background: var(--muted); }

@media (max-width: 700px) {
  /* On phones the controls button spans the top, so the tile sits just below it. */
  .sim-side { top: 68px; width: 244px; }
  .network-card { display: none; }
  /* Keep the column short on phones: the number stays, the chart goes. */
  .perf-chart, .perf-legend, .perf-sub { display: none; }
}

.no-webgl-msg { display: none; }
.hero.no-webgl .no-webgl-msg {
  display: block;
  position: absolute;
  top: 40%;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--muted);
}

/* ---------- Content sections ---------- */
main.page { padding: 3rem 0 4rem; }

.section-intro { color: var(--muted); margin-top: -0.5rem; }

.card-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
}

.card p { margin: 0.25rem 0 0.5rem; color: var(--muted); }
.card .card-meta { font-size: 0.85rem; margin-top: -0.25rem; }

.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.tag {
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.card-links { display: flex; gap: 1rem; font-size: 0.9rem; margin-top: 0.5rem; }

/* ---------- About ---------- */
.about-head {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 1.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.portrait {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 30%; /* keep the face centred in the circle */
  background: var(--accent-soft);
  border: 1px solid var(--border);
}

.contact-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
}

@media (max-width: 560px) {
  .about-head { grid-template-columns: 1fr; text-align: left; }
  .portrait { width: 120px; height: 120px; }
}

/* ---------- CV ---------- */
.cv-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 1rem;
}

.cv-entry {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 1rem;
  padding: 0.6rem 0;
}

.cv-entry + .cv-entry { border-top: 1px solid var(--border); }

.cv-date { color: var(--muted); font-family: var(--font-mono); font-size: 0.85rem; padding-top: 0.15rem; }

.cv-entry p { margin: 0; color: var(--muted); }

.pub-list { padding-left: 1.25rem; }
.pub-list li { margin-bottom: 0.75rem; }
.pub-list .me { font-weight: 600; }

@media (max-width: 560px) {
  .cv-entry { grid-template-columns: 1fr; gap: 0.1rem; }
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.site-footer .container { max-width: 1100px; }

/* ---------- Print (for the CV) ---------- */
@media print {
  .site-header, .site-footer, .no-print { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  main.page { padding: 0; }
  a { color: inherit; text-decoration: none; }
  h2 { margin-top: 1.25rem; }
  .cv-entry { break-inside: avoid; }
}
