/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --paper: #fbfcfc;
  --ink: #17212b;
  --muted: #5c6b77;
  --line: #dde3e7;
  --accent: #154e63;      /* deep teal: links, focus, top grid level */
  --tint-1: #e6eef1;      /* activity levels */
  --tint-2: #b4cdd6;
  --tint-3: #6f9fb0;
  --tint-4: #154e63;

  --font: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.75rem;
  --step-3: clamp(2.25rem, 4vw + 1rem, 3.25rem);

  --measure: 64ch;
  --code-bg: #f0f3f5;
}

/* Dark theme: follows the OS unless the visitor picks one with the switch */
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #121a20;
  --ink: #e3e9ed;
  --muted: #93a2ad;
  --line: #26333c;
  --accent: #7cc3d6;
  --tint-1: #1c2a32;
  --tint-2: #255467;
  --tint-3: #3d8aa3;
  --tint-4: #7cc3d6;
  --code-bg: #1a252c;
}

/* ---------- Theme switch ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  margin: 1.5rem 0 0;
  padding: .35rem .75rem .35rem .55rem;
  font: inherit;
  font-size: var(--step--1);
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  align-self: flex-start;   /* don't stretch inside the sidebar's flex column */
  transition: color .15s, border-color .15s;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--muted); }
.theme-toggle svg { width: 1rem; height: 1rem; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.post-page .theme-toggle { margin: 0 0 0 1.5rem; }
.post-top { display: flex; align-items: center; justify-content: space-between; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s, color .2s;
}

p { text-wrap: pretty; }

a { color: var(--accent); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.skip { position: absolute; left: -999px; top: 0; padding: .5rem 1rem; background: var(--ink); color: var(--paper); }
.skip:focus { left: 1rem; top: 1rem; z-index: 10; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Layout: sticky identity column + reading column ---------- */
.layout {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: minmax(15rem, 20rem) minmax(0, 1fr);
  gap: 4rem;
}

.side {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  padding: 4.5rem 0 3rem;
  display: flex;
  flex-direction: column;
}

.handle { margin: 0 0 .75rem; font-size: var(--step--1); }
.handle a { color: var(--muted); text-decoration: none; }
.handle a:hover { color: var(--accent); }

.name {
  margin: 0;
  font-size: var(--step-3);
  line-height: 1.02;
  font-weight: 700;
  letter-spacing: -0.035em;
}
.role { margin: 1rem 0 0; color: var(--muted); max-width: 26ch; }

.nav { list-style: none; padding: 0; margin: 3rem 0 0; display: grid; gap: .35rem; }
.nav a {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  padding: .1rem 0 .1rem .9rem;
  border-left: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="true"] { color: var(--ink); border-left-color: var(--accent); }

.links { list-style: none; padding: 0; margin: auto 0 0; display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; font-size: var(--step--1); }

main { padding: 4.5rem 0 3rem; min-width: 0; }

section { padding-bottom: 4.5rem; }
section + section { border-top: 1px solid var(--line); padding-top: 3rem; }

h2 { margin: 0 0 1.5rem; font-size: var(--step-1); font-weight: 700; letter-spacing: -0.01em; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.quiet { font-size: var(--step--1); color: var(--muted); }
.quiet:hover { color: var(--accent); }

.prose { max-width: var(--measure); }
.prose p { margin: 0 0 1rem; }
.prose p:first-child { font-size: var(--step-1); line-height: 1.5; }

/* ---------- Activity grid (the signature element) ---------- */
.activity { padding-bottom: 3.5rem; }
.grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  gap: 4px;
  width: 100%;
  max-width: 40rem;
}
.grid span {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--tint-1);
  opacity: 0;
  animation: cell-in .5s ease-out forwards;
}
.grid span[data-l="1"] { background: var(--tint-2); }
.grid span[data-l="2"] { background: var(--tint-3); }
.grid span[data-l="3"] { background: var(--tint-4); }
@keyframes cell-in { to { opacity: 1; } }
.activity-caption { margin: 1rem 0 0; color: var(--muted); font-size: var(--step--1); max-width: var(--measure); }

/* ---------- Now ---------- */
.now { margin: 2rem 0 0; padding: 1.25rem 1.5rem; border-left: 2px solid var(--accent); background: var(--tint-1); max-width: var(--measure); border-radius: 0 6px 6px 0; }
.now h3 { margin: 0 0 .5rem; font-size: var(--step-0); }
.now ul { margin: 0; padding-left: 1.1rem; }
.now li + li { margin-top: .2rem; }
.now-date { margin: .75rem 0 0; color: var(--muted); font-size: var(--step--1); }

/* ---------- Certifications ---------- */
.certs { list-style: none; padding: 0; margin: 0; max-width: var(--measure); }
.certs li { display: grid; grid-template-columns: 8.5rem 1fr; gap: 1.5rem; padding: .55rem 0; }
.cert-year { color: var(--muted); font-size: var(--step--1); padding-top: .15rem; font-variant-numeric: tabular-nums; }
.cert-issuer { display: block; color: var(--muted); font-size: var(--step--1); }

/* ---------- Skills ---------- */
.skills { display: grid; grid-template-columns: max-content 1fr; gap: .6rem 2rem; margin: 2rem 0 0; max-width: var(--measure); }
.skills dt { color: var(--muted); font-size: var(--step--1); padding-top: .15rem; }
.skills dd { margin: 0; }

/* ---------- Featured projects ---------- */
.projects { list-style: none; padding: 0; margin: 0; display: grid; gap: 2.75rem; }
.project h3 { margin: 0; font-size: var(--step-2); line-height: 1.15; letter-spacing: -0.02em; font-weight: 700; }
.project h3 a { color: var(--ink); text-decoration: none; }
.project h3 a:hover { color: var(--accent); }
.project p { margin: .6rem 0 0; max-width: var(--measure); }
.project .meta { margin-top: .75rem; display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: var(--step--1); color: var(--muted); }
.project .stack { display: flex; flex-wrap: wrap; gap: .4rem; list-style: none; padding: 0; margin: 0; }
.project .stack li { border: 1px solid var(--line); border-radius: 999px; padding: 0 .6rem; }

/* ---------- Repositories ---------- */
.repos { list-style: none; padding: 0; margin: 0; }
.repos li { border-bottom: 1px solid var(--line); }
.repos li:first-child { border-top: 1px solid var(--line); }
.repo {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .25rem 1.5rem;
  padding: 1rem .25rem;
  text-decoration: none;
  color: inherit;
}
.repo:hover .repo-name { color: var(--accent); text-decoration: underline; }
.repo-name { font-weight: 500; }
.repo-desc { grid-column: 1; color: var(--muted); font-size: var(--step--1); }
.repo-stats { grid-column: 2; grid-row: 1 / span 2; align-self: center; text-align: right; font-size: var(--step--1); color: var(--muted); white-space: nowrap; }
.lang-dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; background: var(--tint-3); margin-right: .35rem; vertical-align: .05em; }
.placeholder { padding: 1rem .25rem; color: var(--muted); }

/* ---------- Experience timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; max-width: var(--measure); }
.timeline li { display: grid; grid-template-columns: 8.5rem 1fr; gap: 1.5rem; padding-bottom: 1.75rem; }
.timeline .when { color: var(--muted); font-size: var(--step--1); padding-top: .2rem; font-variant-numeric: tabular-nums; }
.timeline h3 { margin: 0; font-size: var(--step-0); font-weight: 700; }
.timeline .org { color: var(--muted); font-weight: 400; }
.timeline p { margin: .35rem 0 0; }

/* ---------- Writing ---------- */
.posts { list-style: none; padding: 0; margin: 0; max-width: var(--measure); }
.posts li { display: grid; grid-template-columns: 8.5rem 1fr; gap: 1.5rem; padding: .6rem 0; }
.posts time { color: var(--muted); font-size: var(--step--1); padding-top: .15rem; font-variant-numeric: tabular-nums; }

.foot { color: var(--muted); font-size: var(--step--1); padding-top: 2rem; border-top: 1px solid var(--line); }

/* ---------- Small screens ---------- */
@media (max-width: 52rem) {
  .layout { grid-template-columns: 1fr; gap: 0; }
  .side { position: static; height: auto; padding: 3rem 0 2rem; }
  .nav { display: none; }
  .links { margin-top: 1.5rem; }
  main { padding-top: 1rem; }
}
@media (max-width: 34rem) {
  .timeline li, .posts li, .certs li { grid-template-columns: 1fr; gap: .15rem; }
  .skills { grid-template-columns: 1fr; gap: .1rem; }
  .skills dd { margin-bottom: .6rem; }
  .repo { grid-template-columns: 1fr; }
  .repo-stats { grid-column: 1; grid-row: auto; text-align: left; }
}

/* ---------- Blog post pages ---------- */
.post-page { max-width: 52rem; margin: 0 auto; padding: 4rem 1.5rem; }
.post-page .back { font-size: var(--step--1); }
.post-page h1 { font-size: var(--step-3); line-height: 1.05; letter-spacing: -0.03em; margin: 1.5rem 0 .5rem; }
.post-page .date { color: var(--muted); font-size: var(--step--1); margin: 0 0 2.5rem; }
.post-page article { max-width: 100%; }
.post-page article p { line-height: 1.75; text-wrap: pretty; }
.post-page article li { line-height: 1.7; text-wrap: pretty; }
.post-page article h2 { margin-top: 2.5rem; }
/* ---------- Case studies ---------- */
.case .lede { font-size: var(--step-1); line-height: 1.5; margin: 1rem 0 2rem; color: var(--muted); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 2rem; margin: 0 0 2.5rem; padding: 1.25rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: var(--step--1); padding-top: .15rem; }
.facts dd { margin: 0; }
.results { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 1.5rem; }
.results strong { display: block; font-size: var(--step-2); line-height: 1.1; letter-spacing: -0.02em; color: var(--accent); }
.results span { color: var(--muted); font-size: var(--step--1); }
.post-page figure { margin: 2rem 0; }
.post-page figure img { max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; }
.post-page figcaption { color: var(--muted); font-size: var(--step--1); margin-top: .5rem; }
.case-foot { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }

/* ---------- Résumé ---------- */
.resume-bar { max-width: 50rem; margin: 0 auto; padding: 2rem 1.5rem 0; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.resume-bar .back { font-size: var(--step--1); }
.resume-actions { display: flex; align-items: center; gap: .75rem; }
.resume-actions .theme-toggle { margin: 0; }
.btn { font: inherit; font-size: var(--step--1); font-weight: 500; color: var(--paper); background: var(--accent); border: 0; border-radius: 999px; padding: .45rem 1rem; cursor: pointer; }
.btn:hover { filter: brightness(1.1); }

.resume { max-width: 50rem; margin: 0 auto; padding: 2.5rem 1.5rem 4rem; }
.r-head h1 { margin: 0; font-size: var(--step-3); line-height: 1.05; letter-spacing: -0.035em; }
.r-role { margin: .5rem 0 0; color: var(--muted); max-width: var(--measure); }
.r-contact { list-style: none; padding: 0; margin: 1rem 0 0; display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; font-size: var(--step--1); }
.resume section { padding: 1.75rem 0 0; border: 0; margin: 1.75rem 0 0; border-top: 1px solid var(--line); }
.resume h2 { font-size: var(--step-0); margin: 0 0 1rem; color: var(--accent); }
.r-item + .r-item { margin-top: 1.25rem; }
.r-item-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.r-item h3 { margin: 0; font-size: var(--step-0); }
.r-item h3 a { color: var(--ink); }
.r-org, .r-when, .r-meta, .r-stack { color: var(--muted); font-weight: 400; }
.r-when { font-size: var(--step--1); white-space: nowrap; font-variant-numeric: tabular-nums; }
.r-item p { margin: .3rem 0 0; }
.r-item ul { margin: .4rem 0 0; padding-left: 1.1rem; }
.r-stack { font-size: var(--step--1); }
.r-skills { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 2rem; margin: 0; }
.r-skills dt { color: var(--muted); }
.r-skills dd { margin: 0; }
.r-list { list-style: none; padding: 0; margin: 0; }
.r-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .2rem 0; }
.r-list .r-meta { font-size: var(--step--1); white-space: nowrap; }

@page { size: A4; margin: 14mm 16mm; }
@media print {
  :root, :root[data-theme="dark"] {
    color-scheme: light;
    --paper: #fff; --ink: #000; --muted: #444; --line: #ccc; --accent: #154e63;
  }
  body { font-size: 10pt; line-height: 1.45; transition: none; }
  .resume-bar, .skip { display: none !important; }
  .resume { max-width: none; padding: 0; }
  .r-head h1 { font-size: 22pt; }
  .resume section { margin-top: 10pt; padding-top: 8pt; }
  .r-item { break-inside: avoid; }
  .resume h2 { break-after: avoid; }
  a { color: inherit; text-decoration: none; }
}
@media (max-width: 34rem) {
  .r-item-head, .r-list li { flex-direction: column; gap: 0; }
  .r-skills { grid-template-columns: 1fr; gap: 0; }
  .r-skills dd { margin-bottom: .5rem; }
}

.notfound .empty-grid { max-width: 12rem; margin: 3.5rem 0 0; }
.notfound h1 { margin-top: 2rem; }
.post-page pre { background: var(--code-bg); padding: 1rem; border-radius: 6px; overflow-x: auto; font-size: var(--step--1); }
