:root {
  --bg: #faf6f1;
  --surface: #ffffff;
  --text: #262733;
  --muted: #6e6c7e;
  --border: #e6dfdb;
  --accent: #bf5a1e;
  --heading: #3a3c5a;
  --accent-soft: #fbe7d6;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171f;
    --surface: #1f212c;
    --text: #ece8e3;
    --muted: #a3a1b5;
    --border: #313447;
    --accent: #f2a35e;
    --heading: #d9d6ee;
    --accent-soft: #3b2c22;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* Two-column layout: sidebar + content */
.layout {
  max-width: 1120px; margin: 0 auto; padding: 0 2rem;
  display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 4.5rem;
}

/* Sidebar */
.sidebar {
  position: sticky; top: 0; align-self: start;
  height: 100vh; padding: 3.5rem 0 2rem;
  display: flex; flex-direction: column;
}
.photo {
  width: 170px; height: 170px; border-radius: 50%;
  object-fit: cover; object-position: center 22%;
  border: 4px solid var(--surface); box-shadow: 0 0 0 1px var(--border);
}
.sidebar h1 {
  font-family: var(--serif); font-size: 1.9rem; font-weight: 600; line-height: 1.15;
  letter-spacing: -0.01em; margin-top: 1.5rem;
}
.role { color: var(--muted); font-size: 0.95rem; line-height: 1.45; margin-top: 0.6rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 0.15rem; margin-top: 2.25rem; }
.sidebar nav a {
  color: var(--text); font-size: 1rem; padding: 0.3rem 0 0.3rem 0.9rem;
  border-left: 2px solid var(--border); transition: border-color 0.15s, color 0.15s;
}
.sidebar nav a:hover, .sidebar nav a.active { color: var(--accent); border-left-color: var(--accent); text-decoration: none; }
.contact { margin-top: auto; padding-top: 2rem; font-size: 0.88rem; color: var(--muted); line-height: 1.55; }
.contact a { font-weight: 600; }
.contact p + p { margin-top: 0.6rem; }

/* Content */
main { padding: 3.5rem 0 2rem; min-width: 0; }
section { padding-bottom: 4rem; scroll-margin-top: 2rem; }
h2 {
  font-family: var(--serif); font-size: 1.9rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2;
  margin-bottom: 1.5rem;
}
h2::after { content: ""; display: block; width: 2.5rem; height: 3px; background: var(--accent); margin-top: 0.7rem; }

.about p { font-family: var(--serif); font-size: 1.2rem; line-height: 1.65; }
.about p + p { margin-top: 1.1rem; }

/* Group labels: Publications / Working papers / Work in progress */
h3 {
  display: flex; align-items: baseline; gap: 0.6rem;
  font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--accent); margin: 2.75rem 0 0.25rem;
}
h2 + h3 { margin-top: 0; }
h3 .count { color: var(--muted); font-weight: 400; letter-spacing: 0; }

/* Papers */
.papers { list-style: none; }
.paper { padding: 1.35rem 0; border-bottom: 1px solid var(--border); }
.paper:last-child { border-bottom: none; }
.paper h4 { font-family: var(--serif); font-size: 1.2rem; font-weight: 600; line-height: 1.35; }
.paper .authors { color: var(--muted); font-size: 0.95rem; margin-top: 0.2rem; }
.paper .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.9rem; margin-top: 0.6rem; font-size: 0.88rem; }
.tag {
  background: var(--accent-soft); color: var(--accent);
  padding: 0.12rem 0.6rem; border-radius: 4px; font-weight: 600;
}
.tag.plain { background: transparent; color: var(--muted); padding-left: 0; font-weight: 400; font-style: italic; }
.paper .meta a { font-weight: 600; }

/* Abstract toggle */
.paper details { margin-top: 0.6rem; }
.paper summary {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.88rem; font-weight: 600; color: var(--muted);
  cursor: pointer; list-style: none; user-select: none;
}
.paper summary::-webkit-details-marker { display: none; }
.paper summary::before {
  content: "+"; display: inline-grid; place-items: center;
  width: 1.1rem; height: 1.1rem; border: 1px solid var(--border); border-radius: 50%;
  font-size: 0.85rem; line-height: 1; background: var(--surface);
}
.paper details[open] summary::before { content: "–"; }
.paper summary:hover { color: var(--accent); }
.paper details p {
  margin-top: 0.75rem; padding: 1rem 1.25rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  font-size: 0.95rem; line-height: 1.65;
}

/* Teaching */
.scale { color: var(--muted); font-size: 0.88rem; font-style: italic; margin-bottom: 0.25rem; }
.courses { list-style: none; }
.courses li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.15rem 1rem; align-items: baseline;
  padding: 0.8rem 0; border-bottom: 1px solid var(--border);
}
.courses li:last-child { border-bottom: none; }
.courses .name { font-family: var(--serif); font-size: 1.08rem; font-weight: 600; }
.courses .detail { grid-column: 1; color: var(--muted); font-size: 0.9rem; }
.courses .score { grid-column: 2; grid-row: 1; font-size: 0.88rem; font-weight: 600; color: var(--accent); white-space: nowrap; }
.courses .score.none { color: var(--muted); font-weight: 400; font-style: italic; }

footer { border-top: 1px solid var(--border); padding: 1.5rem 0 0; color: var(--muted); font-size: 0.85rem; }

/* Narrow screens: sidebar becomes a header */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; gap: 0; padding: 0 1.25rem; }
  .sidebar {
    position: static; height: auto; padding: 2.5rem 0 2rem; align-items: center; text-align: center;
    border-bottom: 1px solid var(--border);
  }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 0.25rem 1.25rem; margin-top: 1.5rem; }
  .sidebar nav a { border-left: 0; padding: 0.2rem 0; }
  .contact { margin-top: 1.5rem; padding-top: 0; }
  main { padding-top: 2.5rem; }
  section { padding-bottom: 3rem; }
  .about p { font-size: 1.1rem; }
}

/* Photo: plain rectangle, centred above the name */
.identity { display: flex; flex-direction: column; align-items: center; text-align: center; width: fit-content; }
.photo {
  width: 190px; height: 238px; border-radius: 4px;
  border: 0; box-shadow: none; object-position: center 15%;
}

/* Banner across the top (the fjord sunset from the original site) */
.banner {
  height: clamp(130px, 21vw, 230px);
  background: #262733 url("banner.jpg") center 42% / cover no-repeat;
}

/* Role line left-aligned under the centred photo and name */
.identity .role { align-self: flex-start; text-align: left; }
@media (max-width: 860px) {
  .identity .role { align-self: center; text-align: center; }
}

/* Headings in the dusk blue of the banner's mountains and sky */
.sidebar h1, h2, .paper h4, .courses .name { color: var(--heading); }

/* Section links: a row at the top of the content column, visible on load and sticky while scrolling */
.tabs {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 0.25rem 2rem;
  padding: 1rem 0; margin-bottom: 2.5rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.tabs a {
  color: var(--heading); font-weight: 600; font-size: 1rem;
  padding-bottom: 0.15rem; border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tabs a:hover, .tabs a.active { color: var(--accent); border-bottom-color: var(--accent); text-decoration: none; }
main { padding-top: 1.5rem; }
section { scroll-margin-top: 5rem; }
.sidebar { padding-top: 2.75rem; }
.contact { margin-top: 2rem; }
@media (max-width: 860px) {
  .tabs { justify-content: center; margin-bottom: 2rem; }
  main { padding-top: 0; }
}

/* Selected work: one figure + abstract per paper */
.feature { padding: 0.25rem 0 2.5rem; }
.feature + .feature { border-top: 1px solid var(--border); padding-top: 2.5rem; }
.feature:last-child { padding-bottom: 0; }
.feature h3 {
  display: block; font-family: var(--serif); font-size: 1.4rem; font-weight: 600; line-height: 1.3;
  text-transform: none; letter-spacing: -0.005em; color: var(--heading); margin: 0;
}
.feature .authors { color: var(--muted); font-size: 0.95rem; margin-top: 0.3rem; }
.feature .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.9rem; margin-top: 0.6rem; font-size: 0.88rem; }
.feature .meta a { font-weight: 600; }
.feature figure {
  margin: 1.5rem 0 1.25rem; padding: 1rem;
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
}
.feature figure img { display: block; width: 100%; height: auto; }
.feature figcaption { font-size: 0.85rem; color: #6e6c7e; margin-top: 0.75rem; text-align: center; font-style: italic; }
.feature .abstract { font-size: 1rem; line-height: 1.65; }

/* Selected work: abstract (left) and figure (right) side by side */
.layout { max-width: 1280px; }
.feature-body {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2rem;
  align-items: start; margin-top: 1.25rem;
}
.feature-body .abstract { font-size: 0.9rem; line-height: 1.6; }
.feature-body figure { margin: 0; padding: 0.75rem; }
.feature-body figure a { display: block; cursor: zoom-in; }
.feature-body figcaption { font-size: 0.8rem; margin-top: 0.6rem; }
@media (max-width: 1080px) {
  .feature-body { grid-template-columns: 1fr; gap: 1.25rem; }
  .feature-body figure { order: -1; }
}

/* Selected work: balance abstract and figure heights */
.feature-body { align-items: center; }
.feature-body figure img { width: auto; max-width: 100%; max-height: 360px; margin: 0 auto; }
.abstract-wrap .abstract { overflow: hidden; }
.abstract-wrap.clamped .abstract {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 3.5rem), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 3.5rem), transparent);
}
.more {
  margin-top: 0.5rem; padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 0.88rem; font-weight: 600; color: var(--accent);
}
.more:hover { text-decoration: underline; text-underline-offset: 3px; }

/* Coauthor links: quiet, underlined, accent on hover */
.authors a.co {
  color: inherit; text-decoration: underline; text-decoration-color: var(--border);
  text-decoration-thickness: 1px; text-underline-offset: 3px;
}
.authors a.co:hover { color: var(--accent); text-decoration-color: currentColor; }

/* Embedded CV */
.cv-actions { display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; font-size: 0.95rem; font-weight: 600; margin-bottom: 1rem; }
.cv-viewer {
  display: block; width: 100%; height: min(85vh, 1100px); min-height: 520px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
}
.cv-fallback { padding: 2rem; text-align: center; color: var(--muted); }
#cv { padding-bottom: 3rem; }

/* Justified body text (about, abstracts); hyphenation keeps word gaps even */
.about p, .abstract, .paper details p {
  text-align: justify; text-justify: inter-word;
  hyphens: auto; -webkit-hyphens: auto;
}
