:root {
  --bg: #faf9f7;
  --fg: #171614;
  --muted: #6f6b64;
  --accent: #b5391a;
  --border: #e6e3de;
  --surface: #f1efeb;
  --max-width: 720px;
  --wide: 1180px;
  --serif: "Fraunces", ui-serif, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --fg: #f3f1ed;
    --muted: #9c9891;
    --accent: #ff8158;
    --border: #2c2a27;
    --surface: #1a1917;
  }
}

/* Per-page theme accents (home / professional / music / running / code) */
body[data-theme="home"] { --hero-bg: #0b0b0b; --hero-fg: #f5f2ec; }
body[data-theme="professional"] {
  --fg: #1c1b19;
  --muted: #6f6b64;
  --border: #e6e3de;
  --surface: #f1efeb;
  --hero-fg: #1c1b19;
  --page-bg: linear-gradient(180deg, #d6d8d5 0%, #c7c8c5 30%, #b3b4b0 100%);
}
body[data-theme="professional"] .hero { background: transparent; }
body[data-theme="music"] { --hero-bg: #0a0a0a; --hero-fg: #f5f2ec; --accent: #ff3b30; }
body[data-theme="running"] { --hero-bg: #fdeee1; --hero-fg: #1c1b19; --accent: #ff6a2b; }
body[data-theme="code"] { --hero-bg: #0d0d10; --hero-fg: #f5f2ec; --accent: #ffb454; }

@media (prefers-color-scheme: dark) {
  body[data-theme="running"] { --hero-bg: #2b1f16; --hero-fg: #f3f1ed; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--page-bg, var(--bg));
  color: var(--fg);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}
.wrap--wide {
  max-width: var(--wide);
  margin: 0 auto;
  padding: 0 1.5rem;
}

a { color: inherit; text-decoration: none; }

.link-underline {
  background-image: linear-gradient(currentColor, currentColor);
  background-position: 0 100%;
  background-repeat: no-repeat;
  background-size: 0% 1px;
  transition: background-size .25s ease;
  padding-bottom: .05em;
}
.link-underline:hover { background-size: 100% 1px; }

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.01em;
  margin: 0 0 .5rem;
}
h1 { font-size: clamp(2.6rem, 6vw, 4.4rem); font-weight: 700; }
h2 { font-size: clamp(1.5rem, 3vw, 2rem); margin-top: 0; }
h3 { font-size: 1.15rem; font-weight: 600; }

p { margin: 0 0 1rem; }

.eyebrow {
  font-family: var(--sans);
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
  display: block;
  margin-bottom: .6rem;
}

.lede {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(1.15rem, 2vw, 1.4rem);
  color: var(--muted);
}

/* Header */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: transparent;
  border-bottom: 1px solid transparent;
  transition: background .3s ease, border-color .3s ease, backdrop-filter .3s ease;
}
.site-header.is-scrolled {
  backdrop-filter: blur(10px) saturate(160%);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-bottom: 1px solid var(--border);
}
/* Pages without a hero don't float over anything, so the header should read solid from the start */
body:not(.has-hero) .site-header {
  position: sticky;
  backdrop-filter: blur(10px) saturate(160%);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1.1rem;
  padding-bottom: 1.1rem;
  color: var(--fg);
}
body.has-hero .site-header:not(.is-scrolled) .header-inner { color: #f5f3ef; }
.brand {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: inherit;
}
.nav-toggle {
  display: none;
  background: none;
  border: 1px solid currentColor;
  opacity: .8;
  color: inherit;
  padding: .35rem .8rem;
  border-radius: 999px;
  font-size: .85rem;
  font-family: var(--sans);
}
.site-nav a {
  color: inherit;
  opacity: .68;
  margin-left: 1.75rem;
  font-size: .88rem;
  font-weight: 500;
  letter-spacing: .01em;
  transition: opacity .2s ease;
}
.site-nav a:hover { opacity: 1; }
.site-nav a[aria-current="page"] { opacity: 1; }

body.has-hero main > *:first-child { margin-top: 0; }

@media (max-width: 640px) {
  .nav-toggle { display: inline-block; }
  .site-nav {
    display: none;
    flex-direction: column;
    width: 100%;
  }
  .site-nav.is-open { display: flex; }
  .site-nav a { margin: .6rem 0 0 0; }
  .header-inner { flex-wrap: wrap; }
}

/* Main content */
main { padding-bottom: 5rem; }
main > .wrap:first-child,
main > .wrap--wide:first-child { padding-top: 3.5rem; }

section + section { margin-top: 3.5rem; }

/* Editorial index (home page) */
.index-list { list-style: none; margin: 0; padding: 0; }
.index-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2rem;
  padding: 1.9rem 0;
  border-bottom: 1px solid var(--border);
  transition: opacity .2s ease;
}
.index-list li:first-child .index-row { padding-top: 0; }
.index-row:hover { opacity: .7; }
.index-row .index-title {
  font-family: var(--serif);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 600;
}
.index-row .index-desc {
  color: var(--muted);
  font-size: .95rem;
  max-width: 22rem;
  text-align: right;
}
@media (max-width: 640px) {
  .index-row { flex-direction: column; gap: .4rem; }
  .index-row .index-desc { text-align: left; }
}

/* Editorial list rows (publications, projects) */
.entry-list { list-style: none; margin: 0; padding: 0; }
.entry {
  padding: 1.6rem 0;
  border-bottom: 1px solid var(--border);
}
.entry:first-child { padding-top: 0; }
.entry-title { font-family: var(--serif); font-weight: 600; font-size: 1.15rem; }
.entry-meta { color: var(--muted); font-size: .9rem; margin-top: .2rem; }

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2.5rem 3rem;
}
.stat { min-width: 5rem; }
.stat-value {
  font-family: var(--serif);
  font-size: 2.2rem;
  font-weight: 700;
  display: block;
  line-height: 1;
}
.stat-label { color: var(--muted); font-size: .85rem; margin-top: .35rem; }

.race-map-section { padding: 2rem 0; }
.race-map-section .wrap h2 { margin-bottom: 1.5rem; }
#race-map {
  width: 100%;
  height: 560px;
}
.leaflet-container { background: transparent !important; }
.leaflet-control-zoom a, .race-map-reset a {
  background: var(--page-bg, var(--bg));
  color: var(--fg);
  border-color: var(--border) !important;
}
.race-map-reset a { font-size: 1.1rem; line-height: 26px; }
.leaflet-tooltip {
  background: var(--page-bg, var(--bg));
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--sans);
  font-size: .82rem;
  box-shadow: none;
}
.leaflet-tooltip-top:before { border-top-color: var(--border); }
.race-map-legend {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  background: var(--page-bg, var(--bg));
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .5rem .7rem;
  font-family: var(--sans);
  font-size: .8rem;
  color: var(--fg);
}
.race-map-legend-item { display: flex; align-items: center; gap: .45rem; }
.race-map-legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: .8rem .25rem;
  border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
td { font-family: var(--serif); font-size: 1.05rem; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  display: flex;
  gap: 1.5rem;
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
}
.timeline li:last-child { border-bottom: none; }
.timeline .years { flex: 0 0 9rem; color: var(--muted); font-size: .88rem; }
.timeline li > span:last-child { min-width: 0; overflow-wrap: break-word; }

.tags { display: flex; flex-wrap: wrap; gap: 0; list-style: none; padding: 0; margin: 0; font-size: .95rem; color: var(--muted); }
.tags li:not(:last-child)::after { content: "·"; margin: 0 .6rem; color: var(--border); }

.notice {
  border-left: 2px solid var(--accent);
  padding: .6rem 1.1rem;
  color: var(--muted);
  font-size: .88rem;
  background: var(--surface);
  border-radius: 0 6px 6px 0;
}

/* Hero — full-bleed, full-viewport, photo as true background */
.hero {
  position: relative;
  width: 100%;
  min-height: 100svh;
  min-height: 100vh;
  background: var(--hero-bg, var(--surface));
  color: var(--hero-fg, var(--fg));
  overflow: hidden;
  display: flex;
  align-items: flex-end;
}
.hero + .wrap, .hero + .wrap--wide,
.segment + .wrap, .segment + .wrap--wide {
  padding-top: 3.5rem;
}
.segment {
  position: relative;
  width: 100%;
  min-height: 100svh;
  min-height: 100vh;
  background: var(--hero-bg, var(--surface));
  color: var(--hero-fg, var(--fg));
  overflow: hidden;
  display: flex;
  align-items: flex-end;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 160px;
  background: linear-gradient(to bottom in oklab, rgba(0,0,0,.5), transparent);
  z-index: 1;
  pointer-events: none;
}
.hero-photo {
  position: absolute;
  top: 0;
  bottom: 0;
  width: clamp(320px, 55vw, 820px);
}
.hero-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}
.hero--photo-left, .segment--photo-left { justify-content: flex-end; }
.hero--photo-left .hero-photo, .segment--photo-left .hero-photo { left: 0; }
.hero--photo-left .hero-photo img, .segment--photo-left .hero-photo img {
  -webkit-mask-image: linear-gradient(to right in oklab, black 58%, transparent 97%);
  mask-image: linear-gradient(to right in oklab, black 58%, transparent 97%);
}
.hero--photo-right, .segment--photo-right { justify-content: flex-start; }
.hero--photo-right .hero-photo, .segment--photo-right .hero-photo { right: 0; }
.hero--photo-right .hero-photo img, .segment--photo-right .hero-photo img {
  -webkit-mask-image: linear-gradient(to left in oklab, black 58%, transparent 97%);
  mask-image: linear-gradient(to left in oklab, black 58%, transparent 97%);
}

/* Full-width banner segment — for wide/landscape photos that shouldn't be cropped into a side column */
.segment--banner { align-items: flex-end; justify-content: flex-start; }
.segment--banner .hero-photo { position: absolute; inset: 0; width: 100%; }
.segment--banner .hero-photo img {
  width: 100%; height: 100%; object-fit: cover; object-position: center 32%;
  -webkit-mask-image: none; mask-image: none;
}
.segment--banner .hero-content {
  max-width: none;
  width: 100%;
  padding: 3rem clamp(1.5rem, 5vw, 4.5rem) 4rem;
  background: linear-gradient(to top in oklab, rgba(0,0,0,.7) 0%, rgba(0,0,0,.25) 55%, transparent 100%);
  color: #f5f3ef;
}

.hero-content {
  position: relative;
  z-index: 2;
  padding: 0 clamp(1.5rem, 5vw, 4.5rem) 4.5rem;
  max-width: 30rem;
  color: var(--hero-fg, var(--fg));
}
.hero-content h2 { font-size: clamp(2rem, 4.5vw, 3.2rem); font-weight: 700; margin-bottom: 1rem; }
.hero-content .entry-title, .hero-content h3, .hero-content .stat-value { color: inherit; }
.hero-content .entry-meta, .hero-content .timeline .years, .hero-content .stat-label { color: inherit; opacity: .65; }
.hero-content .notice { color: inherit; opacity: .8; background: transparent; border-left-color: currentColor; }
.hero-content .entry, .hero-content .timeline li { border-bottom-color: color-mix(in srgb, currentColor 22%, transparent); }
.hero-content a.link-underline { color: inherit; }
.hero--photo-left .hero-content, .segment--photo-left .hero-content { text-align: right; }
.hero--photo-left .hero-content .timeline li, .segment--photo-left .hero-content .timeline li { flex-direction: row-reverse; }
.hero-content h1 { margin-bottom: .6rem; }
.hero-content .lede { color: inherit; opacity: .78; font-style: italic; }

@media (max-width: 780px) {
  .hero, .segment { align-items: flex-end; min-height: 92svh; min-height: 92vh; }
  .hero--photo-left, .hero--photo-right, .segment--photo-left, .segment--photo-right { justify-content: flex-start; }
  .hero-photo { width: 100%; left: 0; right: 0; }
  .hero-photo img { object-position: center 25%; }
  .hero--photo-left .hero-photo img, .hero--photo-right .hero-photo img,
  .segment--photo-left .hero-photo img, .segment--photo-right .hero-photo img {
    -webkit-mask-image: none; mask-image: none;
  }
  .hero-content {
    max-width: none;
    text-align: left !important;
    width: 100%;
    padding: 2.5rem 1.5rem 3rem;
    background: linear-gradient(to top in oklab, color-mix(in srgb, var(--hero-bg) 92%, transparent) 20%, transparent 100%);
  }
  .segment--banner .hero-content { background: linear-gradient(to top in oklab, rgba(0,0,0,.75) 0%, rgba(0,0,0,.2) 55%, transparent 100%); }
  .hero--photo-left .hero-content .timeline li, .segment--photo-left .hero-content .timeline li { flex-direction: row; }
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0;
  color: var(--muted);
  font-size: .85rem;
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.5rem;
  justify-content: space-between;
  align-items: center;
}
.footer-social a { margin-right: 1.25rem; }
.footer-social a:hover { color: var(--fg); }
.footer-meta { display: flex; gap: 1.25rem; align-items: center; }
.footer-meta a:hover { color: var(--fg); }
