/* ---------- Fonts (self-hosted, latin subset) ---------- */
@font-face { font-family: "Plex Sans"; src: url("/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("/fonts/ibm-plex-sans-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("/fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("/fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("/fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }

/* ---------- Theme tokens: dark by default, light via system or toggle ---------- */
:root {
  --bg: #0e0f11;
  --surface: #15171a;
  --line: #262a2f;
  --text: #e9e7e3;
  --muted: #a3a19c;
  --accent: #e8743f;
  --accent-soft: rgba(232, 116, 63, 0.12);
  --grid: rgba(255, 255, 255, 0.035);
  color-scheme: dark;

  --sans: "Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --wrap: 68rem;
  --gutter: clamp(1.25rem, 4vw, 2.5rem);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f4f0;
    --surface: #ffffff;
    --line: #e1ddd5;
    --text: #16171a;
    --muted: #57554f;
    --accent: #b2461a;
    --accent-soft: rgba(178, 70, 26, 0.09);
    --grid: rgba(0, 0, 0, 0.04);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --line: #e1ddd5;
  --text: #16171a;
  --muted: #57554f;
  --accent: #b2461a;
  --accent-soft: rgba(178, 70, 26, 0.09);
  --grid: rgba(0, 0, 0, 0.04);
  color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1.0625rem/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-decoration-color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
::selection { background: var(--accent); color: var(--bg); }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 600; letter-spacing: -0.015em; }
p { margin: 0 0 1em; }
sub, sup { line-height: 0; }
[id] { scroll-margin-top: 5rem; }
ul { margin: 0; padding: 0; }

.wrap { max-width: var(--wrap); margin: 0 auto; padding-inline: var(--gutter); }
.mono { font-family: var(--mono); }
.label {
  font: 500 0.75rem/1.4 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 1rem; top: 1rem; z-index: 10; background: var(--surface); padding: 0.5rem 0.75rem; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap { display: flex; align-items: center; gap: 1rem; min-height: 3.75rem; }
.brand { font: 500 0.95rem var(--mono); text-decoration: none; margin-right: auto; white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; align-items: center; gap: clamp(0.75rem, 2.5vw, 1.75rem); font-size: 0.95rem; }
.nav a { text-decoration: none; color: var(--muted); }
.nav a:hover, .nav a[aria-current="page"] { color: var(--text); }
.nav a[aria-current="page"] { box-shadow: inset 0 -1px 0 var(--accent); }
.nav .hide-sm { display: inline; }
.theme-toggle {
  display: grid; place-items: center;
  width: 2.25rem; height: 2.25rem; padding: 0;
  border: 1px solid var(--line); border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer;
}
.theme-toggle:hover { color: var(--text); border-color: var(--muted); }
.theme-toggle svg { width: 1rem; height: 1rem; }
.theme-toggle .sun { display: none; }
:root[data-theme="light"] .theme-toggle .sun { display: block; }
:root[data-theme="light"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .theme-toggle .sun { display: block; }
  :root:not([data-theme="dark"]) .theme-toggle .moon { display: none; }
}

/* ---------- Hero ---------- */
.hero {
  position: relative;
  padding-block: clamp(3rem, 9vw, 6.5rem) clamp(3rem, 7vw, 5rem);
  border-bottom: 1px solid var(--line);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 48px 48px;
  background-position: -1px -1px;
}
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to bottom, transparent 40%, var(--bg));
}
.hero .wrap { position: relative; z-index: 1; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: clamp(2rem, 6vw, 5rem); align-items: center; }
.hero h1 { font-size: clamp(2.6rem, 7vw, 4.25rem); margin: 0.75rem 0 1.25rem; }
.lead { font-size: clamp(1.125rem, 2.2vw, 1.3rem); line-height: 1.55; max-width: 36rem; color: var(--text); }
.lead + .lead { color: var(--muted); }
.links { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 2rem; }
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.65rem 1rem;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface);
  font: 500 0.9rem/1 var(--sans); text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn svg { width: 1rem; height: 1rem; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn.primary:hover { color: var(--bg); filter: brightness(1.08); }
.portrait {
  width: clamp(11rem, 22vw, 16rem);
  border-radius: 10px;
  border: 1px solid var(--line);
  aspect-ratio: 4 / 5;
  object-fit: cover;
}

/* ---------- Sections ---------- */
.section { padding-block: clamp(3rem, 8vw, 5.5rem); border-bottom: 1px solid var(--line); }
.section:last-of-type { border-bottom: 0; }
.section-head { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 2.25rem; }
.section-head .label { color: var(--accent); }
.section-head h2 { font-size: clamp(1.5rem, 3vw, 1.9rem); }

.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: clamp(2rem, 6vw, 4.5rem); }
.prose { max-width: 38rem; }
.prose p:last-child { margin-bottom: 0; }

.facts { list-style: none; border-top: 1px solid var(--line); }
.facts li { display: grid; grid-template-columns: 8.5rem 1fr; gap: 1rem; padding: 0.8rem 0; border-bottom: 1px solid var(--line); font-size: 0.975rem; }
.facts .label { padding-top: 0.2rem; }

/* Teaser list on home page */
.teasers { list-style: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.teaser a {
  display: block; height: 100%;
  padding: 1.25rem 1.35rem 1.35rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); text-decoration: none;
  transition: border-color 0.15s;
}
.teaser a:hover { border-color: var(--accent); color: inherit; }
.teaser h3 { font-size: 1.125rem; margin: 0.5rem 0 0.4rem; }
.teaser p { color: var(--muted); font-size: 0.95rem; margin: 0; }
.more { display: inline-block; margin-top: 1.75rem; font-weight: 500; }

/* ---------- Work page ---------- */
.page-intro { padding-block: clamp(2.75rem, 7vw, 4.5rem) clamp(1.5rem, 4vw, 2.5rem); border-bottom: 1px solid var(--line); }
.page-intro h1 { font-size: clamp(2rem, 5vw, 2.9rem); margin: 0.6rem 0 1rem; }
.page-intro p { color: var(--muted); max-width: 40rem; margin: 0; }
.toc { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin-top: 1.5rem; font: 400 0.85rem var(--mono); }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--accent); }

.role {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.25rem 2rem;
  padding: 1.5rem; margin-bottom: 2rem;
  border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px;
  background: var(--surface);
}
.role h3 { font-size: 1.2rem; }
.role .when { text-align: right; }
.role p { grid-column: 1 / -1; margin: 0.75rem 0 0; color: var(--muted); max-width: 46rem; }

.project { padding-block: 2.25rem; border-top: 1px solid var(--line); }
.project:first-of-type { border-top: 0; padding-top: 0; }
.project-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.35rem 2rem; align-items: baseline; margin-bottom: 1.25rem; }
.project-head h3 { font-size: clamp(1.25rem, 2.6vw, 1.5rem); }
.project-head .num { color: var(--accent); margin-right: 0.6rem; font: 500 0.95rem var(--mono); }
.project-head .meta { color: var(--muted); font-size: 0.95rem; }
.project-head .when { text-align: right; }
.tags { display: flex; flex-wrap: wrap; gap: 0.4rem; list-style: none; grid-column: 1 / -1; margin-top: 0.5rem; }
.tags li { font: 400 0.75rem/1 var(--mono); padding: 0.4rem 0.55rem; border-radius: 4px; background: var(--accent-soft); color: var(--text); }

.detail { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 0; margin: 0; max-width: 54rem; }
.detail dt, .detail dd { padding: 0.85rem 0; border-top: 1px solid var(--line); }
.detail dt { padding-top: 1.05rem; }
.detail dd { margin: 0; }
.detail dd p:last-child, .detail dd ul:last-child { margin-bottom: 0; }
.detail ul { padding-left: 1.1rem; }
.detail li { margin-bottom: 0.35rem; }
.detail li::marker { color: var(--accent); }
.status { display: inline-flex; align-items: center; gap: 0.5rem; }
.status::before { content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--muted); }
.status.live::before { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.edu { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.edu article { padding: 1.5rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.edu h3 { font-size: 1.15rem; }
.edu .sub { color: var(--muted); margin: 0.3rem 0 1rem; font-size: 0.95rem; }
.edu ul { padding-left: 1.1rem; font-size: 0.975rem; }
.edu li { margin-bottom: 0.35rem; }
.edu li::marker { color: var(--accent); }

.skills { display: grid; grid-template-columns: 9rem minmax(0, 1fr); max-width: 54rem; margin: 0; }
.skills dt, .skills dd { padding: 0.85rem 0; border-top: 1px solid var(--line); margin: 0; }
.skills dt { padding-top: 1.05rem; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding-block: 2.5rem; font-size: 0.95rem; }
.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1.25rem 2rem; align-items: center; }
.site-footer ul { list-style: none; display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; }
.site-footer small { color: var(--muted); font: 400 0.8rem var(--mono); }

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  .hero .wrap { grid-template-columns: 1fr; }
  .portrait { width: 9.5rem; }
  .split, .edu, .teasers { grid-template-columns: 1fr; }
  .detail, .skills { grid-template-columns: 1fr; }
  .detail dt, .skills dt { padding-bottom: 0.15rem; }
  .detail dd, .skills dd { border-top: 0; padding-top: 0.25rem; }
  .project-head, .role { grid-template-columns: 1fr; }
  .project-head .when, .role .when { text-align: left; }
  .facts li { grid-template-columns: 1fr; gap: 0.2rem; }
}
@media (max-width: 420px) {
  .nav .hide-sm { display: none; }
  .btn { padding: 0.6rem 0.85rem; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
