/* ==========================================================================
   Magnus Saebo — personal site
   Tokens first, then base, then components. Every color comes from a token
   so light and dark both resolve as a set.
   ========================================================================== */

:root {
  color-scheme: light;

  --bg:          #F6F5F0;
  --bg-2:        #ECEBE4;
  --ink:         #1B1D19;
  --ink-2:       #474A43;
  --muted:       #767970;
  --line:        #DAD9D0;
  --line-2:      #C6C5BB;
  --accent:      #2B6B45;
  --accent-2:    #1D4D31;
  --accent-tint: rgba(43, 107, 69, 0.09);
  --sel:         rgba(43, 107, 69, 0.20);
  --dot:         27, 29, 25;      /* rgb triplets for the canvas */
  --dot-accent:  43, 107, 69;
  --shadow:      0 1px 2px rgba(27, 29, 25, 0.06), 0 12px 32px -18px rgba(27, 29, 25, 0.25);

  --display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --wrap:    1040px;
  --measure: 64ch;
  --gutter:  clamp(16px, 4vw, 40px);
  --radius:  4px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:          #131512;
    --bg-2:        #1B1E19;
    --ink:         #E7E6DF;
    --ink-2:       #B9BAB1;
    --muted:       #8C8F86;
    --line:        #2C302A;
    --line-2:      #3A3F37;
    --accent:      #7CC497;
    --accent-2:    #A6DDB9;
    --accent-tint: rgba(124, 196, 151, 0.12);
    --sel:         rgba(124, 196, 151, 0.28);
    --dot:         231, 230, 223;
    --dot-accent:  124, 196, 151;
    --shadow:      0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px -18px rgba(0, 0, 0, 0.8);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:          #131512;
  --bg-2:        #1B1E19;
  --ink:         #E7E6DF;
  --ink-2:       #B9BAB1;
  --muted:       #8C8F86;
  --line:        #2C302A;
  --line-2:      #3A3F37;
  --accent:      #7CC497;
  --accent-2:    #A6DDB9;
  --accent-tint: rgba(124, 196, 151, 0.12);
  --sel:         rgba(124, 196, 151, 0.28);
  --dot:         231, 230, 223;
  --dot-accent:  124, 196, 151;
  --shadow:      0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px -18px rgba(0, 0, 0, 0.8);
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 4.5rem;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--display);
  font-optical-sizing: auto;
  font-weight: 400;
  font-size: 1.0625rem;              /* 17px */
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

@media (min-width: 720px) {
  body { font-size: 1.125rem; }      /* 18px */
}

::selection { background: var(--sel); }

img { max-width: 100%; height: auto; display: block; }

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 0.14em;
  text-decoration-thickness: 1px;
  transition: color 0.15s ease, background-color 0.15s ease;
}
a:hover { color: var(--accent-2); text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

h1, h2, h3 {
  font-family: var(--display);
  font-weight: 500;
  line-height: 1.15;
  margin: 0;
  text-wrap: balance;
  letter-spacing: -0.005em;
}

p { margin: 0; }

.wrap {
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.mono {
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -3rem;
  padding: 0.5rem 0.75rem;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--mono);
  font-size: 0.8rem;
  z-index: 100;
}
.skip:focus { top: 0.5rem; }

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */

.top {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}

.top__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
  flex-wrap: wrap;
  padding-block: 0.5rem;
}

.brand {
  font-family: var(--display);
  font-style: italic;
  font-weight: 500;
  font-size: 1.25rem;
  font-variation-settings: "SOFT" 60, "WONK" 1;
  color: var(--ink);
  white-space: nowrap;
}
.brand:hover { color: var(--accent); text-decoration: none; }

.nav {
  display: flex;
  align-items: center;
  gap: clamp(0.9rem, 2.5vw, 1.6rem);
  font-family: var(--mono);
  font-size: 0.8rem;
}
.nav a {
  color: var(--ink-2);
  padding-block: 0.25rem;
  border-bottom: 1px solid transparent;
}
.nav a:hover { color: var(--ink); text-decoration: none; border-bottom-color: var(--line-2); }
.nav a[aria-current="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.theme {
  appearance: none;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink-2);
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}
.theme:hover { color: var(--ink); border-color: var(--ink-2); background: var(--accent-tint); }
.theme svg { width: 15px; height: 15px; }
.theme .moon { display: none; }
:root[data-theme="dark"] .theme .moon { display: block; }
:root[data-theme="dark"] .theme .sun  { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme .moon { display: block; }
  :root:not([data-theme="light"]) .theme .sun  { display: none; }
}

/* --------------------------------------------------------------------------
   Hero
   -------------------------------------------------------------------------- */

.hero {
  position: relative;
  overflow: hidden;
  padding-block: clamp(3rem, 9vw, 6.5rem) clamp(3rem, 7vw, 5.5rem);
}

.field {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(90deg, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.55) 42%, #000 68%);
          mask-image: linear-gradient(90deg, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.55) 42%, #000 68%);
}

.hero__grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(220px, 27vw, 320px);
  gap: clamp(2rem, 6vw, 5rem);
  align-items: end;
}

.kicker {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  margin-bottom: 1.25rem;
}

.hero h1 {
  font-size: clamp(2.75rem, 7vw, 4.75rem);
  font-weight: 500;
  font-variation-settings: "opsz" 144, "SOFT" 40, "WONK" 1;
  line-height: 1;
  letter-spacing: -0.02em;
  margin-bottom: 1.25rem;
}

.lede {
  font-style: italic;
  font-size: clamp(1.3rem, 2.6vw, 1.7rem);
  font-variation-settings: "opsz" 40, "SOFT" 30, "WONK" 1;
  line-height: 1.3;
  max-width: 30ch;
  text-wrap: balance;
  margin-bottom: 1rem;
}

.sub {
  color: var(--ink-2);
  max-width: 46ch;
  margin-bottom: 1.75rem;
}

.links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  font-family: var(--mono);
  font-size: 0.8rem;
}
.links a {
  color: var(--ink-2);
  border-bottom: 1px solid var(--line-2);
  padding-bottom: 1px;
}
.links a:hover { color: var(--accent); border-bottom-color: var(--accent); text-decoration: none; }

/* Portrait */

.portrait {
  margin: 0;
  justify-self: end;
  width: 100%;
}

.portrait__btn {
  appearance: none;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  display: block;
  width: 100%;
  border-radius: var(--radius);
  outline-offset: 4px;
}
.portrait__frame {
  display: block;
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 6;          /* the frame is fixed; photos are cropped into it */
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--bg-2);
  isolation: isolate;
}
.portrait__frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(27, 29, 25, 0.12);
  pointer-events: none;
}
.portrait__frame img {
  position: absolute;           /* out of flow, so it can never change the frame's height */
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.22s ease, transform 0.5s ease;
}
.portrait__btn.is-swapping img { opacity: 0; }
.portrait__btn:hover img { transform: scale(1.015); }

.portrait figcaption {
  margin-top: 0.6rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.4;
  height: 1.4em;                /* one line, always, so nothing below it moves */
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
}
.portrait figcaption span:first-child {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.portrait figcaption .n {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 719px) {
  .hero__grid {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
  .portrait { justify-self: start; max-width: 260px; }
  .field {
    -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.45) 50%, #000 100%);
            mask-image: linear-gradient(180deg, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.45) 50%, #000 100%);
  }
}

/* --------------------------------------------------------------------------
   Sections
   -------------------------------------------------------------------------- */

.section {
  padding-block: clamp(2.25rem, 5vw, 3.75rem);
  border-top: 1px solid var(--line);
}

.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: clamp(1.25rem, 3vw, 2rem);
}

.section h2 {
  font-size: clamp(1.6rem, 3vw, 2rem);
  font-variation-settings: "opsz" 72, "SOFT" 40, "WONK" 1;
  font-weight: 500;
}

.section__aside {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

.prose { max-width: var(--measure); }
.prose p + p { margin-top: 1.1em; }
.prose a {
  color: var(--ink);
  border-bottom: 1px solid var(--line-2);
}
.prose a:hover { color: var(--accent); border-bottom-color: var(--accent); text-decoration: none; }
.prose .quiet { color: var(--muted); }

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink);
  border: 1px solid var(--ink);
  padding: 0.55em 1em;
  border-radius: 999px;
  transition: background-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--ink); color: var(--bg); text-decoration: none; }
.btn svg { width: 14px; height: 14px; }

/* --------------------------------------------------------------------------
   News
   -------------------------------------------------------------------------- */

.news {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 72ch;
}
.news li {
  display: grid;
  grid-template-columns: 8.5ch minmax(0, 1fr);
  gap: 1.25rem;
  padding-block: 0.7rem;
  border-bottom: 1px solid var(--line);
}
.news li:first-child { padding-top: 0; }
.news time {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  padding-top: 0.32em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.news li.is-new time { color: var(--accent); }

/* --------------------------------------------------------------------------
   Research
   -------------------------------------------------------------------------- */

.papers {
  list-style: none;
  margin: 0;
  padding: 0;
}

.paper {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  gap: clamp(1.25rem, 3vw, 2rem);
  padding-block: clamp(1.4rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
}
.paper:first-child { padding-top: 0; }

.paper__fig {
  margin: 0;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg-2);
  align-self: start;
}
.paper__fig a { display: block; height: 100%; }
.paper__fig img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}
.paper__fig a:hover img { transform: scale(1.03); }

/* Text tile for a paper that has no figure yet */
.paper__fig.is-tile {
  display: grid;
  place-items: center;
  background: var(--accent-tint);
  border-color: transparent;
  padding: 0.75rem;
  text-align: center;
}
.paper__fig.is-tile span {
  font-style: italic;
  font-size: 1.2rem;
  font-variation-settings: "opsz" 48, "SOFT" 60, "WONK" 1;
  color: var(--accent);
  line-height: 1.1;
}

.paper__title {
  font-size: 1.15rem;
  font-weight: 600;
  font-variation-settings: "opsz" 24, "SOFT" 20;
  line-height: 1.3;
  margin-bottom: 0.3rem;
}
.paper__title a { color: var(--ink); }
.paper__title a:hover { color: var(--accent); text-decoration: none; }

.paper__authors {
  color: var(--ink-2);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 0.35rem;
}
.paper__authors b { color: var(--ink); font-weight: 600; }
.paper__authors .eq { color: var(--accent); font-weight: 600; }

.paper__venue {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  margin-bottom: 0.7rem;
}
.tag {
  display: inline-block;
  padding: 0.12em 0.55em;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--ink-2);
}
.tag.is-accent {
  border-color: transparent;
  background: var(--accent-tint);
  color: var(--accent);
}

.paper__summary {
  color: var(--ink-2);
  font-size: 0.97rem;
  line-height: 1.55;
  max-width: 68ch;
  margin-bottom: 0.7rem;
}

.paper__links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
  font-family: var(--mono);
  font-size: 0.78rem;
}
.paper__links a {
  color: var(--accent);
  border-bottom: 1px solid transparent;
}
.paper__links a:hover { border-bottom-color: var(--accent); text-decoration: none; }

@media (max-width: 599px) {
  .paper { grid-template-columns: 1fr; gap: 1rem; }
  .paper__fig { max-width: 240px; }
}

/* --------------------------------------------------------------------------
   Experience
   -------------------------------------------------------------------------- */

/* Timeline of overlapping roles. Rows are built by script.js from a data
   list; bar positions are percentages of the Jan 2019 to Jan 2027 span. */

.gantt {
  --label-w: 13rem;
  --now: 0%;
  --years: 8;
  display: grid;
  grid-template-columns: var(--label-w) minmax(0, 1fr);
  row-gap: 0.45rem;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.74rem;
  margin-top: clamp(2.25rem, 5vw, 3.5rem);
}
.gantt:empty { display: none; }
.gantt__axis {
  grid-column: 2;
  position: relative;
  height: 1.3rem;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.2rem;
}
.gantt__axis span {
  position: absolute;
  top: 0;
  padding-left: 0.35em;
  font-variant-numeric: tabular-nums;
}
.gantt__label {
  color: var(--muted);
  padding-right: 1rem;
  line-height: 1.3;
  display: flex;
  flex-wrap: wrap;
  gap: 0 0.5em;
  min-width: 0;
}
.gantt__label b { color: var(--ink); font-weight: 500; }
.gantt__label span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt__track {
  position: relative;
  height: 1.05rem;
  background-image: linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: calc(100% / var(--years)) 100%;
}
.gantt__track::after {
  content: "";
  position: absolute;
  top: -0.25rem;
  bottom: -0.25rem;
  left: var(--now);
  border-left: 1px dashed var(--accent);
  opacity: 0.75;
  pointer-events: none;
}
.gantt__bar {
  position: absolute;
  top: 0.2rem;
  height: 0.65rem;
  border-radius: 2px;
  background: var(--ink-2);
  min-width: 3px;
}
.gantt__bar.is-edu {
  background: transparent;
  border: 1px solid var(--ink-2);
  box-sizing: border-box;
}
.gantt__bar.is-now { background: var(--accent); }
.gantt__mark {
  position: absolute;
  top: -0.55rem;
  transform: translateX(3px);
  font-size: 0.62rem;
  line-height: 1;
  color: var(--accent);
  background: var(--bg);
  padding: 0 0.2em;
  border-radius: 2px;
}
.sr {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 599px) {
  .gantt { --label-w: 7.25rem; font-size: 0.68rem; row-gap: 0.55rem; }
  .gantt__label { display: block; }
  .gantt__label b { display: block; }
  .gantt__label span { display: block; }
  .gantt__axis span:nth-child(even) { display: none; }
}

.exp-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 4rem);
}
@media (max-width: 719px) {
  .exp-grid { grid-template-columns: 1fr; }
}

.exp-grid h3 {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.9rem;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}
.timeline li {
  display: grid;
  grid-template-columns: 12.5ch minmax(0, 1fr);
  gap: 1.25rem;
  padding-block: 0.8rem;
  border-top: 1px solid var(--line);
}
.timeline time,
.timeline .when {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
  padding-top: 0.35em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.timeline .role {
  font-weight: 600;
  font-variation-settings: "opsz" 18, "SOFT" 20;
}
.timeline .org { color: var(--ink-2); }
.timeline .note {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  margin-top: 0.15rem;
}
.timeline li.is-current time,
.timeline li.is-current .when { color: var(--accent); }

@media (max-width: 479px) {
  .timeline li { grid-template-columns: 1fr; gap: 0.2rem; }
  .news li { grid-template-columns: 1fr; gap: 0.15rem; }
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */

.foot {
  border-top: 1px solid var(--line);
  padding-block: 2rem 3rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
}
.foot__inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem 2rem;
}
.foot ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
}
.foot a { color: var(--ink-2); }
.foot a:hover { color: var(--accent); }

/* --------------------------------------------------------------------------
   Motion
   -------------------------------------------------------------------------- */

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