@font-face {
  font-family: "Schibsted Grotesk";
  src: url("fonts/schibsted-grotesk.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
}

:root {
  /* Colour: one ground, one ink, one accent */
  --bg: #fbfbfa;
  --surface: #f0f0ee;
  --text: #16181d;
  --muted: #5d6370;
  --accent: #2a5bd7;
  --accent-strong: #1f48b3;
  --accent-text: #ffffff;
  --shot-bg: #ffffff;

  /* Type: five sizes */
  --fs-small: 0.875rem;
  --fs-body: clamp(1.0625rem, 1rem + 0.25vw, 1.1875rem);
  --fs-lead: clamp(1.25rem, 1.1rem + 0.7vw, 1.5rem);
  --fs-head: clamp(2rem, 1.3rem + 3vw, 3.5rem);
  --fs-display: clamp(2rem, 1rem + 5.4vw, 5.5rem);
  --font-display: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Space: 4-unit scale */
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --s-8: 4rem;
  --margin: clamp(1rem, 2.2vw, 2rem);
  --section: clamp(4rem, 2rem + 6vw, 8rem);

  /* Motion */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  /* Light by default; theme.js sets data-theme="dark" when the visitor picks it */
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a20;
  --text: #eceef2;
  --muted: #9aa1ad;
  --accent: #7aa2ff;
  --accent-strong: #9bb9ff;
  --accent-text: #0f1115;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
  accent-color: var(--accent);
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-body)/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-underline-offset: 0.2em; touch-action: manipulation; }
::selection { background: var(--accent); color: var(--accent-text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

h1, h2, h3, h4, .brand { font-family: var(--font-display); }
h1, h2 { text-wrap: balance; font-weight: 600; }
p, dd { text-wrap: pretty; }
h3, h4 { font-weight: 600; margin: 0; }

/* ---------- Frame ---------- */
.nav {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: var(--s-4);
  padding: var(--s-4) max(var(--margin), calc((100% - 1200px) / 2));
  background: var(--bg);
}
.brand { font-weight: 600; text-decoration: none; letter-spacing: -0.01em; }
.nav nav { display: flex; align-items: center; gap: var(--s-5); }

/* Theme toggle: hidden until theme.js runs, since it can't work without it */
.theme-toggle {
  display: none; place-items: center;
  width: 40px; height: 40px; margin: -10px -10px -10px 0; padding: 0;
  border: 0; border-radius: 999px; background: transparent; color: var(--muted);
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: color 150ms ease, transform 160ms var(--ease-out);
}
.has-theme-toggle .theme-toggle { display: inline-grid; }
.theme-toggle:active { transform: scale(0.94); }
.theme-toggle svg {
  grid-area: 1 / 1; width: 18px; height: 18px;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}
/* Shows the theme you'd switch to: moon in light, sun in dark */
.theme-toggle .icon-sun { opacity: 0; transform: rotate(-45deg) scale(0.6); }
[data-theme="dark"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(45deg) scale(0.6); }
[data-theme="dark"] .theme-toggle .icon-sun { opacity: 1; transform: none; }
.nav nav a {
  color: var(--muted); text-decoration: none; font-size: var(--fs-small);
  padding: 10px 4px; margin: -10px -4px;
  transition: color 150ms ease;
}

section {
  padding: var(--section) max(var(--margin), calc((100% - 1200px) / 2));
  scroll-margin-top: 3.5rem;
}
h2 { font-size: var(--fs-head); line-height: 1.05; letter-spacing: -0.03em; margin: 0 0 var(--s-7); }
h2.sub { margin-top: var(--section); }
.field { background: var(--surface); }

/* ---------- Hero ---------- */
.hero { padding-top: clamp(4rem, 2rem + 8vw, 9rem); }
h1 {
  font-size: var(--fs-display); line-height: 0.98; letter-spacing: -0.035em;
  max-width: 20ch; margin: 0 0 var(--s-6);
}
.lede { font-size: var(--fs-lead); line-height: 1.4; max-width: 38ch; margin: 0 0 var(--s-7); }

/* ---------- Actions ---------- */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-5) var(--s-6); }
.btn {
  display: inline-block; padding: 14px 24px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
  text-decoration: none; font-weight: 600; font-size: var(--fs-small);
  user-select: none; -webkit-user-select: none;
  transition: transform 160ms var(--ease-out), background-color 180ms ease;
}
.btn:active { transform: scale(0.97); }
.link {
  position: relative; color: var(--accent); font-weight: 600; text-decoration: none;
}
/* Underline draws in from the left on hover or keyboard focus */
.link::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 1.5px;
  background: currentColor; transform: scaleX(0); transform-origin: left;
  transition: transform 200ms var(--ease-out);
}
.link:focus-visible::after { transform: scaleX(1); }

/* ---------- Work rows ---------- */
.rows { display: grid; gap: var(--s-6); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); column-gap: clamp(1.5rem, 4vw, 4rem); }
.row h3 { font-size: var(--fs-lead); line-height: 1.3; }
.row p { margin: 0; max-width: 60ch; }
.row.lead h3 { font-size: var(--fs-head); line-height: 1; letter-spacing: -0.03em; }
.row.lead p { font-size: var(--fs-lead); line-height: 1.4; }
.row.lead { padding-bottom: var(--s-5); }

/* ---------- Project ---------- */
.project { display: grid; grid-template-columns: 1.2fr 1fr; gap: clamp(1.5rem, 4vw, 4rem); align-items: center; }
.shot {
  display: block; background: var(--shot-bg);
  transition: transform 160ms var(--ease-out);
}
.shot:active { transform: scale(0.98); }
.shot img { display: block; width: 100%; height: auto; }
.project h3 { font-size: var(--fs-lead); margin-bottom: var(--s-3); }
.project p { margin: 0 0 var(--s-4); max-width: 60ch; }
.meta { color: var(--muted); font-size: var(--fs-small); }

/* ---------- Experience ---------- */
.timeline { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s-6); }
.timeline li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); column-gap: clamp(1.5rem, 4vw, 4rem); }
.timeline h3 { font-size: var(--fs-body); margin-bottom: var(--s-2); }
.timeline p { margin: 0; max-width: 60ch; }
.when { color: var(--muted); font-size: var(--fs-small); font-variant-numeric: tabular-nums; padding-top: 0.2em; }

/* ---------- Education ---------- */
.columns { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-7) clamp(1.5rem, 4vw, 4rem); }
.label { color: var(--muted); font-size: var(--fs-small); font-weight: 600; margin-bottom: var(--s-5); }
.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s-5); }
.plain h4 { font-size: var(--fs-body); margin-bottom: var(--s-2); }
.plain p { margin: 0; max-width: 52ch; }

.skills { margin: 0; display: grid; gap: var(--s-4); }
.skills div { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); column-gap: clamp(1.5rem, 4vw, 4rem); }
.skills dt { font-weight: 600; }
.skills dd { margin: 0; max-width: 60ch; }

/* ---------- Contact: the ending ---------- */
.contact, footer { background: var(--text); color: var(--bg); }
.contact { padding-bottom: var(--s-7); }
.contact h2 {
  font-size: var(--fs-display); line-height: 0.98; letter-spacing: -0.035em;
  margin: 0 0 var(--s-5); max-width: 12ch;
}
.contact h2 a {
  text-decoration: underline; text-decoration-thickness: 0.06em; text-underline-offset: 0.12em;
  transition: text-decoration-color 180ms ease;
}
.contact p { margin: 0; }
.contact :focus-visible { outline-color: currentColor; }
footer {
  font-size: var(--fs-small);
  padding: var(--s-6) max(var(--margin), calc((100% - 1200px) / 2)) var(--s-7);
}

/* ---------- Hover: pointer devices only ---------- */
@media (hover: hover) and (pointer: fine) {
  .nav nav a:hover, .theme-toggle:hover { color: var(--text); }
  .btn:hover { background: var(--accent-strong); }
  .link:hover::after { transform: scaleX(1); }
  .contact h2 a:hover { text-decoration-color: transparent; }
}

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  .row, .timeline li, .skills div, .project, .columns { grid-template-columns: 1fr; }
  .row, .timeline li, .skills div { row-gap: var(--s-2); }
  .row.lead { padding-bottom: 0; }
}
@media (max-width: 600px) {
  .nav { position: static; }
  .nav .wide-only { display: none; }
  .nav nav { gap: var(--s-5); }
  section { scroll-margin-top: 0; }
}

/* ---------- Entrance and scroll reveal ---------- */
/* Hero: one staggered entrance per visit. `both` + from-only keyframes
   means the content is simply visible if animations don't run. */
@keyframes enter { from { opacity: 0; translate: 0 12px; } }
@keyframes fade { from { opacity: 0; } }
.hero > * { animation: enter 420ms var(--ease-out) both; }
.hero > :nth-child(2) { animation-delay: 70ms; }
.hero > :nth-child(3) { animation-delay: 140ms; }

/* Sections: fade up once on first view. Only hidden when motion.js has
   added .motion to <html>, so no-JS visitors see everything. Uses the
   `translate` property so it never fights the press `transform`. */
.motion [data-reveal] {
  opacity: 0; translate: 0 14px;
  transition: opacity 500ms var(--ease-out), translate 500ms var(--ease-out);
}
.motion [data-reveal].is-visible { opacity: 1; translate: none; }
/* Siblings entering together stagger by 60ms */
.motion :is(.rows, .timeline, .columns, .skills) > :nth-child(2) { transition-delay: 60ms; }
.motion :is(.rows, .timeline, .columns, .skills) > :nth-child(3) { transition-delay: 120ms; }
.motion :is(.rows, .timeline, .columns, .skills) > :nth-child(4) { transition-delay: 180ms; }
.motion :is(.rows, .timeline, .columns, .skills) > :nth-child(5) { transition-delay: 240ms; }
.motion .project .body[data-reveal] { transition-delay: 150ms; }

/* Backtester chart wipes left to right, so the curves read as drawing across time.
   A background-coloured panel slides off the chart rather than clipping the chart
   itself: a fully clipped image never counts as "in view", so it would never load. */
.motion .shot[data-reveal] { opacity: 1; translate: none; position: relative; }
.motion .shot[data-reveal]::after {
  content: ""; position: absolute; inset: 0;
  background: var(--surface); transform-origin: right;
  transition: transform 1100ms var(--ease-in-out);
}
.motion .shot[data-reveal].is-visible::after { transform: scaleX(0); }

/* ---------- Reduced motion: keep fades and colour feedback, drop movement ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .btn:active, .shot:active { transform: none; }
  .hero > * { animation: fade 200ms ease both; }
  .motion [data-reveal] { translate: none; transition: opacity 200ms ease; }
  .motion .shot[data-reveal]::after { display: none; }
  .link::after { transition: none; }
  .theme-toggle:active { transform: none; }
  .theme-toggle .icon-sun { transform: none; }
  [data-theme="dark"] .theme-toggle .icon-moon { transform: none; }
}
