:root {
  --background: #171714;
  --text: #f0eee8;
  --muted: #aaa49b;
  --rule: #393832;
  --sidebar-width: 330px;
  --main-width: 980px;
}

html[data-theme="light"] {
  --background: #f7f6f2;
  --text: #252521;
  --muted: #706e68;
  --rule: #d8d5ce;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  font-size: 18px;
  line-height: 1.6;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  color: var(--text);
}

.about a,
.item-description a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  align-self: start;
  padding: 40px 32px;
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
}

.identity {
  margin-bottom: 34px;
}

.avatar {
  display: block;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  margin-bottom: 20px;
}

.name {
  display: block;
  font-size: 25px;
  line-height: 1.2;
  font-weight: 700;
  margin-bottom: 8px;
}

.headline {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.headline-role,
.headline-affiliation {
  display: block;
}

.profile-links {
  margin-top: 8px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.profile-links a {
  color: var(--muted);
  font-size: 10px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.profile-links a:hover {
  color: var(--text);
}

.nav {
  border-top: 1px solid var(--rule);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav a {
  display: block;
  color: var(--muted);
  font-size: 19px;
  padding: 3px 0;
}

.nav a:hover,
.nav a[aria-current="page"] {
  color: var(--text);
}

.theme-toggle {
  margin-top: auto;
  align-self: flex-start;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--muted);
}

.main {
  width: min(var(--main-width), calc(100% - 80px));
  margin-left: 54px;
  padding-bottom: 48px;
}

.section {
  padding: 36px 0 42px;
  border-bottom: 1px solid var(--rule);
  scroll-margin-top: 24px;
}

.about-section {
  padding-top: 36px;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

h1,
h2 {
  margin: 0;
  font-size: 32px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 28px;
}

.section-header h2 a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
}

.view-all {
  color: var(--muted);
  white-space: nowrap;
  font-size: 15px;
}

.view-all:hover {
  color: var(--text);
}

.about {
  max-width: 900px;
  font-size: 18px;
  line-height: 1.6;
}

.items {
  display: flex;
  flex-direction: column;
}

.item {
  display: grid;
  grid-template-columns: 95px minmax(0, 1fr);
  gap: 22px;
  padding: 16px 0;
  border-top: 1px solid color-mix(in srgb, var(--text) 7%, transparent);
}

.item:first-child {
  border-top: 0;
  padding-top: 0;
}

.item-date {
  color: var(--muted);
  font-size: 14px;
  padding-top: 3px;
}

.item-main {
  min-width: 0;
}

.item-main a:hover,
.publication-title a:hover,
.funding-title a:hover,
.hiring-title a:hover,
.service-title a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.publication-item,
.funding-item,
.hiring-item,
.service-item {
  grid-template-columns: 1fr;
}

.publication-title,
.funding-title,
.hiring-title,
.service-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.45;
}

.authors,
.metadata,
.item-description {
  margin-top: 4px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.publication-extras {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.publication-extras a {
  color: var(--muted);
}

.publication-extras a:hover {
  color: var(--text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.publication-extras .publication-award {
  color: var(--text);
  font-weight: 600;
}

.service-group {
  margin-top: 30px;
}

.service-group:first-of-type {
  margin-top: 0;
}

.service-group h2 {
  margin-bottom: 12px;
  font-size: 22px;
}

.service-group .service-item {
  margin: 0 0 9px;
  font-size: 16px;
  line-height: 1.5;
}

.service-group .service-item:last-child {
  margin-bottom: 0;
}

.service-group .service-item strong {
  font-weight: 600;
}

.listing-page {
  min-height: calc(100vh - 100px);
}

footer {
  color: var(--muted);
  font-size: 13px;
  padding-top: 20px;
}

@media (max-width: 800px) {
  .layout {
    display: block;
  }

  .sidebar {
    position: relative;
    height: auto;
    padding: 20px 22px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
  }

  /*
   * Mobile-only header layout. The desktop sidebar remains untouched.
   *
   *   avatar | name
   *   avatar | headline
   *   avatar | Scholar / ORCID
   *   navigation + theme toggle
   */
  .identity {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    grid-template-areas:
      "avatar name"
      "avatar headline"
      "avatar links"
      "nav nav";
    column-gap: 14px;
    row-gap: 0;
    margin: 0;
  }

  .identity > a:first-child {
    grid-area: avatar;
    align-self: start;
  }

  .avatar {
    width: 76px;
    height: 76px;
    margin: 0;
  }

  .name {
    grid-area: name;
    align-self: end;
    margin: 0 0 2px;
    font-size: 23px;
    line-height: 1.15;
  }

  .headline {
    grid-area: headline;
    margin-top: 2px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.35;
  }

  .profile-links {
    grid-area: links;
    align-self: start;
    margin-top: 5px;
    gap: 12px;
  }

  .profile-links a {
    font-size: 10px;
  }

  .nav {
    grid-area: nav;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 0;
    margin-top: 14px;
    padding: 10px 0 0;
    border-top: 1px solid var(--rule);
  }

  /*
   * Five menu items or fewer stay on one line. If a sixth item (or more)
   * is present, switch automatically to a compact four-column grid:
   * 4 + 2 for six items, 4 + 3 for seven, 4 + 4 for eight.
   */
  .nav:has(a:nth-child(6)) {
    display: grid;
    grid-template-columns: repeat(4, max-content);
    justify-content: start;
    gap: 2px clamp(14px, 5vw, 24px);
  }

  .nav a {
    padding: 1px 0;
    font-size: 15px;
    line-height: 1.4;
    white-space: nowrap;
  }

  .theme-toggle {
    position: absolute;
    top: 20px;
    right: 22px;
    z-index: 2;
    width: 32px;
    height: 32px;
    margin: 0;
    font-size: 16px;
  }

  .main {
    width: auto;
    margin: 0;
    padding: 0 22px 40px;
  }

  .section {
    padding: 32px 0 36px;
  }

  .about-section {
    padding-top: 26px;
  }

  h1 {
    font-size: 28px;
  }

  h2 {
    font-size: 25px;
  }

  .about {
    font-size: 17px;
  }

  .item {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}

/* Compact homepage cards: News + Blog */
.compact-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.compact-card {
  min-width: 0;
  min-height: 142px;
  padding: 14px 15px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  display: flex;
  flex-direction: column;
  color: var(--text);
}

.compact-card:hover {
  border-color: var(--muted);
}

.card-date {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  margin-bottom: 7px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.card-summary {
  margin-top: 7px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.card-more {
  margin-top: auto;
  padding-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.news-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.45;
}

.news-title a:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Blog */
.blog-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.blog-list .compact-card {
  min-height: 155px;
}

.blog-post {
  max-width: 820px;
}

.blog-post-header {
  margin-bottom: 34px;
}

.back-link {
  display: inline-block;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 20px;
}

.back-link:hover {
  color: var(--text);
}

.blog-post-date {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}

.blog-post-summary {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.55;
}

.blog-content {
  font-size: 18px;
  line-height: 1.7;
}

.blog-content p,
.blog-content ul,
.blog-content ol,
.blog-content blockquote,
.blog-content pre {
  margin: 0 0 1.25em;
}

.blog-content h1,
.blog-content h2,
.blog-content h3,
.blog-content h4 {
  margin: 1.5em 0 0.65em;
}

.blog-content h2 {
  font-size: 25px;
}

.blog-content h3 {
  font-size: 21px;
}

.blog-content h4 {
  font-size: 18px;
}

.blog-content a {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.blog-content blockquote {
  margin-left: 0;
  padding-left: 18px;
  border-left: 2px solid var(--rule);
  color: var(--muted);
}

.blog-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
}

.blog-content pre {
  overflow-x: auto;
  padding: 14px;
  border: 1px solid var(--rule);
  border-radius: 5px;
}

.blog-content hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 2em 0;
}

.empty-state {
  color: var(--muted);
}

@media (max-width: 800px) {
  .compact-grid,
  .blog-list {
    grid-template-columns: 1fr;
  }

  .compact-card,
  .blog-list .compact-card {
    min-height: 0;
  }

  .blog-content,
  .blog-post-summary {
    font-size: 17px;
  }
}
