/* ------------------------------------------------------------------
   Tokens
------------------------------------------------------------------ */
:root {
  --bg: #ffffff;
  --bg-2: #f5f5f4;
  --fg: #1a1a1a;
  --fg-2: #3d3d3d;
  --muted: #6b6b6b;
  --muted-2: #a3a3a3;
  --line: #e7e7e5;
  --line-2: #d4d4d2;
  --accent: #1f5591;
  --accent-2: #173f6c;
  --code-bg: #f5f5f4;
  --tile-hover: #fafaf9;

  --serif: ui-serif, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* page shell, and the narrower cap used for running prose */
  --shell: 64rem;
  --prose: 64rem;
}

html.dark {
  --bg: #161616;
  --bg-2: #1f1f1f;
  --fg: #e6e6e6;
  --fg-2: #c4c4c4;
  --muted: #999999;
  --muted-2: #666666;
  --line: #2b2b2b;
  --line-2: #3a3a3a;
  --accent: #8cb4e0;
  --accent-2: #b3cdea;
  --code-bg: #1f1f1f;
  --tile-hover: #1b1b1b;
}

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

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.25s ease, color 0.25s ease;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 500; }
p { margin: 0; }
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
svg { flex-shrink: 0; }
ul { margin: 0; padding: 0; list-style: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

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

::selection { background: var(--line-2); color: var(--fg); }

/* Text links with an arrow */
.lnk {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--accent);
  white-space: nowrap;
  transition: color 0.2s ease;
}
.lnk::after {
  content: "↗";
  display: inline-block;
  margin-left: 0.2em;
  transition: transform 0.2s ease;
}
.lnk:hover { color: var(--accent-2); }
.lnk:hover::after { transform: translate(1px, -1px); }
.lnk.plain::after { content: none; }

/* ------------------------------------------------------------------
   Top bar
------------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.brand {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand em { font-style: italic; font-weight: 400; color: var(--muted); }
@media (max-width: 719px) { .brand em { display: none; } }

.topnav {
  display: flex;
  gap: 0;
  margin-left: auto;
  padding: 0 1rem;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  mask-image: linear-gradient(to right, transparent, #000 1rem, #000 calc(100% - 1rem), transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 1rem, #000 calc(100% - 1rem), transparent);
}
.topnav::-webkit-scrollbar { display: none; }
.nav-link {
  display: inline-block;
  padding: 0.35rem 0.5rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.01em;
  color: var(--muted);
  border-bottom: 1px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
  white-space: nowrap;
}
.nav-link:hover { color: var(--fg); }
.nav-link.active { color: var(--fg); border-bottom-color: var(--fg); }

.theme-toggle {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  color: var(--muted);
  border-radius: 999px;
  border: 1px solid var(--line);
  transition: color 0.2s ease, border-color 0.2s ease;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--fg); border-color: var(--line-2); }
.theme-toggle .icon-moon { display: none; }
html.dark .theme-toggle .icon-moon { display: block; }
html.dark .theme-toggle .icon-sun { display: none; }

/* ------------------------------------------------------------------
   Page shell
------------------------------------------------------------------ */
.page {
  position: relative;
  z-index: 1;
  max-width: var(--shell);
  margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
}
@media (min-width: 720px) {
  .page { padding-top: 4.5rem; }
}

/* Hero --------------------------------------------------------------- */
.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  align-items: center;
  padding-bottom: 3rem;
  margin-bottom: 3rem;
  border-bottom: 1px solid var(--line);
}
@media (min-width: 640px) {
  .hero { grid-template-columns: minmax(0, 1fr) auto; gap: 3rem; }
}

.avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
  background: var(--bg-2);
  order: -1;
}
@media (min-width: 640px) {
  .avatar { order: 0; width: 156px; height: 156px; }
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1rem;
}
.hero h1 {
  font-family: var(--serif);
  font-size: clamp(2.6rem, 6.5vw, 3.9rem);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -0.025em;
  font-variation-settings: "opsz" 72;
}
.tagline {
  font-family: var(--serif);
  font-size: clamp(1.2rem, 2.4vw, 1.45rem);
  line-height: 1.4;
  color: var(--fg-2);
  margin-top: 0.85rem;
  max-width: 32ch;
}
.tagline em { font-style: italic; color: var(--fg); }

.contact {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  margin-top: 1.5rem;
}
.contact a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  transition: color 0.2s ease;
}
.contact a:hover { color: var(--accent); }
.contact svg { width: 13px; height: 13px; }

/* Sections ------------------------------------------------------------- */
section { scroll-margin-top: 4.5rem; }
section + section { margin-top: 4rem; }

.sec-head {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  padding-bottom: 0.65rem;
  margin-bottom: 1.4rem;
  border-bottom: 1px solid var(--line);
}
.sec-head .num {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}
.sec-head h2 {
  font-family: var(--serif);
  font-size: 1.65rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.sec-head .aside {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
}
.sec-head .aside a { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-2); }
.sec-head .aside a:hover { color: var(--accent); }

/* About -------------------------------------------------------------- */
.bio {
  max-width: var(--prose);
  font-family: var(--serif);
  font-size: 1.16rem;
  line-height: 1.65;
  color: var(--fg-2);
}
.bio p + p { margin-top: 1rem; }
.bio a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--line-2);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: text-decoration-color 0.2s ease, color 0.2s ease;
}
.bio a:hover { color: var(--accent); text-decoration-color: var(--accent); }

.interests {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1.5rem;
}
.interests li {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
}

/* Ruled rows (news, education, experience) ----------------------------- */
.rows > .row + .row { border-top: 1px solid var(--line); }
.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.25rem 1.5rem;
  padding: 1rem 0;
}
@media (min-width: 560px) {
  .row { grid-template-columns: 8rem 1fr; }
}
.row .date {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  padding-top: 0.25rem;
  font-variant-numeric: tabular-nums;
}
.row .title {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.35;
}
.row .title a { transition: color 0.2s ease; }
.row .title a:hover { color: var(--accent); }
.row .title a::after {
  content: "↗";
  font-family: var(--mono);
  font-size: 0.7em;
  margin-left: 0.35em;
  color: var(--muted-2);
}
.row .desc {
  margin-top: 0.3rem;
  max-width: 54rem;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--muted);
}
.row .sub { margin-top: 0.15rem; font-size: 0.92rem; color: var(--fg-2); }
.row .meta {
  margin-top: 0.35rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}
.row .meta a { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-2); }
.row .meta a:hover { color: var(--accent); }
.row .meta + .meta { margin-top: 0.15rem; }

.collapsible[data-collapsed="true"] .row.extra { display: none; }
.show-more {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  transition: color 0.2s ease;
}
.show-more:hover { color: var(--accent); }
.show-more svg { transition: transform 0.25s ease; }
.collapsible[data-collapsed="false"] + .show-more svg { transform: rotate(180deg); }
.show-more .less { display: none; }
.collapsible[data-collapsed="false"] + .show-more .less { display: inline; }
.collapsible[data-collapsed="false"] + .show-more .more { display: none; }

/* Projects -------------------------------------------------------------- */
.tiles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}
@media (min-width: 560px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 1.15rem 1.2rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.tile:hover { background: var(--tile-hover); border-color: var(--line-2); }
.tile-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}
.tile h3 {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.tile .tags {
  font-family: var(--mono);
  font-size: 0.67rem;
  line-height: 1.5;
  color: var(--muted);
}
.tile p {
  font-size: 0.87rem;
  line-height: 1.55;
  color: var(--muted);
  flex: 1;
}
.tile .links { display: flex; flex-wrap: wrap; gap: 0.9rem; margin-top: 0.4rem; }

/* Publications ---------------------------------------------------------- */
.pubs > .pub + .pub { border-top: 1px solid var(--line); }
.pub {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.25rem 1.5rem;
  padding: 1.1rem 0;
}
@media (min-width: 560px) {
  .pub { grid-template-columns: 8rem 1fr; }
}
.pub .year {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  padding-top: 0.3rem;
}
.pub h3 {
  font-family: var(--serif);
  font-size: 1.14rem;
  font-weight: 500;
  line-height: 1.35;
  max-width: 46rem;
}
.pub .authors {
  margin-top: 0.3rem;
  font-size: 0.87rem;
  color: var(--muted);
}
.pub .authors strong { color: var(--fg); font-weight: 500; }
.pub .venue {
  margin-top: 0.3rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--fg-2);
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  align-items: center;
}
.badge {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border: 1px solid var(--line-2);
  border-radius: 3px;
  color: var(--fg-2);
}
.pub .links { display: flex; flex-wrap: wrap; gap: 0.9rem; margin-top: 0.6rem; }
.pub .links button { line-height: inherit; }
.load-error { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); }

.bibtex { display: none; margin-top: 0.75rem; max-width: 46rem; }
.bibtex.open { display: block; }
.bibtex pre {
  margin: 0;
  padding: 0.8rem 0.95rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  line-height: 1.5;
  color: var(--fg-2);
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
}
.bibtex .copy {
  margin-top: 0.4rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
}
.bibtex .copy:hover { color: var(--accent); }

/* Logo mark in education / experience --------------------------------- */
.row.with-logo .body { display: flex; gap: 0.85rem; align-items: flex-start; }
.mark {
  position: relative;
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  margin-top: 0.1rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg-2);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 0.58rem;
  color: var(--muted);
}
.mark img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain; padding: 3px;
  background: #fff;
}

/* Footer -------------------------------------------------------------- */
.footer {
  margin-top: 5rem;
  padding-top: 1.35rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
}
.footer a { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-2); }
.footer a:hover { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

@media print {
  .topbar, .show-more, .bibtex { display: none !important; }
  .collapsible[data-collapsed="true"] .row.extra { display: grid; }
}
