/* ---------- Tokens ---------- */
:root {
  --ink: #121110;
  --graphite: #1c1a16;
  --graphite-2: #24211c;
  --bone: #ebe5d9;
  --bone-2: #d8d1c4;
  --ash: #8e877a;
  --rule: #2a2721;
  --rule-strong: #3a362e;
  --brass: #d6b25e;

  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --gutter: clamp(16px, 4vw, 48px);
  --maxw: 1200px;
  --space-section: clamp(64px, 10vw, 128px);
  --bar-h: 64px;

  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--bone);
  font: 400 1rem/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
h1, h2, h3, p, ul, ol, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
svg { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; border-radius: 4px; }
::selection { background: var(--brass); color: var(--ink); }

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 100;
  background: var(--brass); color: var(--ink); padding: 8px 14px; border-radius: 6px;
}
.skip:focus { top: 12px; }

/* ---------- Top bar ---------- */
.bar {
  height: var(--bar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-inline: var(--gutter);
  border-bottom: 1px solid var(--rule);
}
.bar__mark { font: 500 1.2rem/1 var(--serif); letter-spacing: 0.02em; }
.bar__nav { display: flex; gap: clamp(16px, 3vw, 32px); font-size: 0.95rem; }
.bar__nav a { color: var(--ash); transition: color 0.2s; }
.bar__nav a:hover { color: var(--bone); }

/* ---------- Hero / playground ---------- */
.hero {
  position: relative;
  padding: clamp(28px, 6vw, 72px) var(--gutter) var(--gutter);
  border-bottom: 1px solid var(--rule);
}
.hero__text { position: relative; z-index: 1; max-width: var(--maxw); pointer-events: none; }
.hero h1 {
  font: 300 clamp(3rem, 0.9rem + 8.2vw, 8.75rem)/0.92 var(--serif);
  letter-spacing: -0.035em;
  max-width: 11ch;
}
.hero__lede {
  margin-top: clamp(20px, 3vw, 32px);
  max-width: 32ch;
  font: 400 clamp(1.15rem, 0.95rem + 0.9vw, 1.6rem)/1.4 var(--serif);
  color: var(--bone-2);
}
.hero__hint { margin-top: 14px; font-size: 0.88rem; color: var(--ash); }
.pg:not(.is-live) .hero__hint { display: none; } /* nothing is draggable in the static layout */

/* Static layout: used when physics can't run (reduced motion, CDN blocked). */
.pg-items {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-top: clamp(32px, 5vw, 56px);
}
.pg-item {
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Live physics layout */
.pg.is-live {
  height: calc(100svh - var(--bar-h));
  min-height: 560px;
  max-height: 1000px;
  overflow: hidden;
  touch-action: pan-y;
}
.pg.is-live .pg-items { display: block; margin: 0; }
.pg.is-live .pg-item {
  position: absolute; left: 0; top: 0; z-index: 2;
  touch-action: none; cursor: grab; will-change: transform;
  visibility: hidden;
}
.pg.is-live .pg-item.is-placed { visibility: visible; }
.pg.is-live .pg-item.is-grabbed { cursor: grabbing; z-index: 10; }

.pg-job {
  width: 15rem; padding: 18px 20px 16px;
  display: grid; gap: 2px;
  background: var(--graphite); border: 1px solid var(--rule-strong); border-radius: 10px;
  transition: border-color 0.2s;
}
.pg-job:hover { border-color: var(--ash); }
.pg-job strong { font: 400 1.45rem/1.15 var(--serif); margin-bottom: 4px; }
.pg-job span { font-size: 0.88rem; color: var(--bone-2); line-height: 1.35; }
.pg-job .pg-job__years { color: var(--ash); font-size: 0.82rem; margin-top: 6px; }

.pg-metric {
  display: inline-flex; align-items: baseline; gap: 8px;
  height: 46px; padding: 0 20px; line-height: 46px;
  background: var(--graphite); border: 1px solid var(--rule-strong); border-radius: 999px;
  font-size: 0.9rem; color: var(--bone-2); white-space: nowrap;
}
.pg-metric b { font: 500 1.2rem/1 var(--serif); color: var(--bone); }

.pg-avatar {
  width: 136px; height: 136px; border-radius: 50%; overflow: hidden;
  background: var(--graphite-2); border: 1px solid var(--rule-strong);
}
.pg-avatar svg { width: 100%; height: 100%; pointer-events: none; }
.pg-avatar.is-ouch svg { animation: ouch 0.3s ease-out; }
@keyframes ouch { 30% { transform: scale(0.92); } }

/* Detection overlay: axis-aligned box that tracks each body */
.bbox {
  position: absolute; left: 0; top: 0; z-index: 3;
  border: 1px solid var(--brass);
  pointer-events: none;
  opacity: 0; transition: opacity 0.6s ease;
}
.bbox.is-seen { opacity: 1; transition-duration: 0.15s; }
.bbox.is-front { z-index: 11; }
.bbox__label {
  position: absolute; left: -1px; bottom: 100%;
  padding: 2px 6px 1px;
  background: var(--brass); color: var(--ink);
  font: 400 11px/1.4 var(--mono); white-space: nowrap;
}

/* ---------- Sections ---------- */
.section {
  max-width: var(--maxw); margin-inline: auto;
  padding: var(--space-section) var(--gutter) 0;
  display: grid; gap: clamp(20px, 3vw, 32px);
}
.section__title {
  justify-self: start; position: relative;
  font: 300 clamp(2.75rem, 1.4rem + 4.6vw, 5.75rem)/0.95 var(--serif);
  letter-spacing: -0.03em;
  margin-bottom: clamp(8px, 2vw, 24px);
}
/* Detection box: locks onto the title when it scrolls into view, then fades (hover brings it back). */
.section__title-box {
  position: absolute; inset: -0.08em -0.22em -0.12em;
  border: 1px solid var(--brass);
  opacity: 0; pointer-events: none;
  transition: opacity 0.6s ease;
}
.section__title-box::before {
  content: attr(data-label);
  position: absolute; left: -1px; bottom: 100%;
  padding: 2px 6px 1px;
  background: var(--brass); color: var(--ink);
  font: 400 11px/1.4 var(--mono); letter-spacing: 0; white-space: nowrap;
}
.section__title.is-detected .section__title-box { animation: detect 2.4s ease-out both; }
.section__title:hover .section__title-box { opacity: 1; transition-duration: 0.15s; }
@keyframes detect {
  0%   { opacity: 0; transform: scale(1.08); }
  12%  { opacity: 1; transform: scale(1); }
  70%  { opacity: 1; }
  100% { opacity: 0; }
}
.section__body { min-width: 0; }

.prose { font: 400 1.1rem/1.7 var(--serif); color: var(--bone-2); max-width: 66ch; }
.prose a, .contact__email { color: var(--brass); }

/* About */
#about .section__body { display: grid; gap: 24px; }
.about__lead {
  font: 300 clamp(1.35rem, 1.05rem + 1.2vw, 2rem)/1.38 var(--serif);
  max-width: 34ch; letter-spacing: -0.01em;
}
.edu { display: grid; gap: 18px; margin-top: 12px; padding-top: 24px; border-top: 1px solid var(--rule); }
.edu dt { font-size: 0.9rem; color: var(--ash); }
.edu dd { font: 400 1.1rem/1.5 var(--serif); }

/* Work */
.jobs { display: grid; }
.job { padding-block: 0 clamp(40px, 6vw, 64px); }
.job + .job { padding-top: clamp(40px, 6vw, 64px); border-top: 1px solid var(--rule); }
.job:last-child { padding-bottom: 0; }
.job__head { display: grid; gap: 4px; margin-bottom: 20px; }
.job h3 { font: 400 clamp(1.75rem, 1.3rem + 1.6vw, 2.6rem)/1.1 var(--serif); letter-spacing: -0.015em; }
.job__role { color: var(--bone); }
.job__meta { color: var(--ash); font-size: 0.92rem; }
.job__list { display: grid; gap: 14px; }
.job__list li { position: relative; padding-left: 1.2em; }
.job__list li::before {
  content: ""; position: absolute; left: 0; top: 0.78em;
  width: 5px; height: 5px; border-radius: 50%; background: var(--rule-strong);
}
.job:target h3 { color: var(--brass); }

/* Skills */
.skills > div { display: grid; gap: 4px; padding: 16px 0; border-top: 1px solid var(--rule); }
.skills > div:last-child { border-bottom: 1px solid var(--rule); }
.skills dt { font-size: 0.92rem; color: var(--ash); }
.skills dd { font: 400 1.1rem/1.55 var(--serif); color: var(--bone-2); max-width: 66ch; }

/* Contact */
.contact { display: grid; gap: 20px; justify-items: start; }
.contact__line { font: 400 1.1rem/1.6 var(--serif); color: var(--bone-2); max-width: 44ch; }
.contact__email {
  font: 300 clamp(1.35rem, 0.8rem + 2.6vw, 2.9rem)/1.2 var(--serif);
  letter-spacing: -0.01em;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em;
  overflow-wrap: anywhere;
}
.contact__links { display: flex; flex-wrap: wrap; gap: 8px 28px; }
.contact__links a { color: var(--ash); transition: color 0.2s; }
.contact__links a:hover { color: var(--bone); }

.footer {
  max-width: var(--maxw); margin: var(--space-section) auto 0;
  padding: 24px var(--gutter) 40px;
  color: var(--ash); font-size: 0.85rem;
}

/* ---------- Phones ---------- */
@media (max-width: 767px) {
  :root { --bar-h: 56px; }
  .pg.is-live { min-height: 600px; }
  .pg-job { width: 12.5rem; padding: 14px 16px 12px; }
  .pg-job strong { font-size: 1.2rem; }
  .pg-job span { font-size: 0.8rem; }
  .pg-metric { height: 40px; line-height: 40px; padding: 0 16px; font-size: 0.82rem; }
  .pg-metric b { font-size: 1.05rem; }
  .pg-avatar { width: 104px; height: 104px; }
  .pg [data-optional] { display: none; }
}

/* ---------- Larger screens: headings move into a left rail ---------- */
@media (min-width: 768px) {
  .edu { grid-template-columns: 1fr 1fr; gap: 32px; }
  .skills > div { grid-template-columns: 10rem 1fr; gap: 24px; }
}
@media (min-width: 1024px) {
  .section { grid-template-columns: 11rem 1fr; column-gap: 48px; }
  .section__title { grid-column: 1 / -1; }
  .section__body { grid-column: 2; }
  .contact__line { font-size: 1.2rem; }
}

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