/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
  --paper: #FAF9F6;
  --paper-alt: #F1EFE8;
  --ink: #1B1D22;
  --ink-soft: #3A3D45;
  --muted: #6B6F76;
  --rule: #DAD6CC;
  --rule-strong: #C7C2B5;
  --accent: #2B4570;
  --accent-soft: #E9EEF4;
  --accent-2: #8B3A3A;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Serif 4", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --measure: 46rem;
  --space-1: 0.5rem;
  --space-2: 0.875rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --space-5: 4rem;
  --space-6: 6rem;
}

/* ==========================================================================
   Reset & base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

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

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:hover { text-decoration-thickness: 2px; }

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

.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;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 0.75rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

.wrap {
  max-width: 62rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  line-height: 1.15;
}

/* ==========================================================================
   Header / navigation
   ========================================================================== */
.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 20;
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
  padding-bottom: 1rem;
  gap: 1rem;
}

.site-header__id {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--ink);
  line-height: 1.2;
}
.site-header__name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
}
.site-header__role {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.site-nav ol {
  display: flex;
  gap: 1.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-nav a {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.95rem;
}
.site-nav a:hover { color: var(--accent); }
.site-nav__num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent);
}

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}
.nav-toggle span {
  width: 22px;
  height: 2px;
  background: var(--ink);
  display: block;
}

@media (max-width: 700px) {
  .nav-toggle { display: flex; }
  .site-nav {
    display: none;
    width: 100%;
  }
  .site-nav.is-open { display: block; }
  .site-nav ol {
    flex-direction: column;
    gap: 0;
    border-top: 1px solid var(--rule);
    margin-top: 1rem;
  }
  .site-nav a {
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--rule);
    width: 100%;
  }
  .site-header__inner { flex-wrap: wrap; }
}

/* ==========================================================================
   Hero
   ========================================================================== */
.hero {
  padding-top: var(--space-6);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--rule);
}
.hero__grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-4);
  align-items: start;
}
.hero__photo {
  position: relative;
  width: 11rem;
  aspect-ratio: 320 / 380;
  border: 1px solid var(--rule-strong);
  background: var(--paper-alt);
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}
.hero__photo img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.hero__photo-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 2.4rem;
  color: var(--rule-strong);
  z-index: 0;
}
@media (max-width: 640px) {
  .hero__grid { grid-template-columns: 1fr; }
  .hero__photo { width: 8rem; order: -1; margin-bottom: 0.5rem; }
}
.hero__eyebrow {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 0 0 1rem;
}
.hero__name {
  font-size: clamp(2.4rem, 5vw, 3.6rem);
  margin: 0 0 0.75rem;
}
.hero__tagline {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1.25rem;
  color: var(--ink-soft);
  max-width: 38rem;
  margin: 0 0 1.75rem;
}
.hero__links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}
.hero__links a {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-decoration: none;
  border-bottom: 1px solid var(--rule-strong);
  padding-bottom: 2px;
}
.hero__links a:hover { border-color: var(--accent); color: var(--accent); }

/* ==========================================================================
   Sections
   ========================================================================== */
.section {
  padding-top: var(--space-5);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--rule);
}
.section:last-of-type { border-bottom: none; }
.page-head { padding-bottom: var(--space-3); }

.section__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px dashed var(--rule-strong);
}
.section__title {
  font-size: 1.65rem;
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}
.section__num {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 500;
}

/* Marginalia: a manuscript-review-style annotation beside each heading */
.marginnote {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent-2);
  background: var(--accent-soft);
  border: 1px solid var(--rule);
  padding: 0.3rem 0.6rem;
  border-radius: 2px;
  margin: 0;
  white-space: normal;
}
.marginnote a { color: var(--accent-2); }

.prose { max-width: var(--measure); }
.prose p { margin: 0 0 1.1rem; }
.prose h2.cv-block__title { margin-top: 2rem; }

/* Topic list */
.topic-list {
  list-style: none;
  margin: var(--space-3) 0 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
  max-width: var(--measure);
}
.topic-list li {
  display: flex;
  gap: 0.85rem;
  align-items: baseline;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--rule);
  font-size: 1rem;
}
.topic-list__tag {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* ==========================================================================
   Publications (signature bibliography component)
   ========================================================================== */
.pub-year-group { margin-bottom: var(--space-4); }
.pub-year-group:last-child { margin-bottom: 0; }
.pub-year-group__year {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.5rem;
  margin: 0 0 1rem;
}

.pub-list { display: flex; flex-direction: column; }

.pub {
  border-bottom: 1px solid var(--rule);
}
.pub:first-child { border-top: 1px solid var(--rule); }

.pub__toggle {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  padding: 1.1rem 0;
  color: inherit;
  font: inherit;
}
.pub__toggle:hover { background: var(--paper-alt); }

.pub__index {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 0.9rem;
  padding-top: 0.15rem;
  flex-shrink: 0;
  width: 2.2rem;
}
.pub__body { flex: 1; min-width: 0; }
.pub__title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.08rem;
  color: var(--ink);
  display: block;
}
.pub__meta {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.pub__venue { font-style: italic; }

.pub__chevron {
  flex-shrink: 0;
  width: 0.6rem;
  height: 0.6rem;
  margin-top: 0.5rem;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}
.pub__toggle[aria-expanded="true"] .pub__chevron { transform: rotate(-135deg); }

.pub__detail {
  padding: 0 0 1.4rem 3.1rem;
  max-width: var(--measure);
}
.pub__detail-body {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
.pub__figure {
  margin: 0;
  flex-shrink: 0;
  width: 100%;
  border: 1px solid var(--rule);
  background: var(--paper-alt);
  padding: 0.4rem;
  border-radius: 3px;
}
.pub__figure img {
  width: 100%;
  height: auto;
  display: block;
}

.pub__figure video {
  width: 100%;
  height: auto;
  display: block;
}
.pub__abstract {
  color: var(--ink-soft);
  margin: 0 0 0.9rem;
  flex: 1;
  min-width: 14rem;
}
.pub__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  align-items: center;
}
.pub__link {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  text-decoration: none;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  border-bottom: 1px solid transparent;
}
.pub__link:hover { border-color: var(--accent); }

.pub__bibtex {
  margin-top: 0.9rem;
  background: var(--ink);
  color: #E7E4DA;
  padding: 0.9rem 1rem;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  overflow-x: auto;
  white-space: pre;
}

.tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.1rem 0.4rem;
  border-radius: 2px;
  margin-left: 0.5rem;
  vertical-align: middle;
}
.tag--red { color: var(--accent-2); border-color: var(--accent-2); }
.tag--muted { color: var(--muted); border-color: var(--rule-strong); }

.see-all { margin-top: var(--space-3); }
.see-all a { font-family: var(--font-mono); font-size: 0.9rem; }

/* ==========================================================================
   Projects
   ========================================================================== */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr));
  gap: 1.25rem;
}
.project-card {
  border: 1px solid var(--rule);
  background: var(--paper-alt);
  padding: 1.4rem;
  border-radius: 3px;
}
.project-card__name {
  font-size: 1.05rem;
  margin: 0 0 0.2rem;
}
.project-card__period {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}
.project-card__summary {
  font-size: 0.95rem;
  color: var(--ink-soft);
  margin: 0 0 1rem;
}
.project-card__stack {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0;
  margin: 0 0 1rem;
}
.project-card__stack li {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 0.15rem 0.45rem;
  border-radius: 2px;
  color: var(--ink-soft);
}
.project-card__links {
  display: flex;
  gap: 1rem;
}
.project-card__links a {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-decoration: none;
  border-bottom: 1px solid var(--rule-strong);
}
.project-card__links a:hover { border-color: var(--accent); color: var(--accent); }

/* ==========================================================================
   Blog — index list
   ========================================================================== */
.post-list {
  display: flex;
  flex-direction: column;
  max-width: var(--measure);
}
.post-list__item {
  padding: 1.4rem 0;
  border-bottom: 1px solid var(--rule);
}
.post-list__item:first-child { border-top: 1px solid var(--rule); }
.post-list__date {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 0.4rem;
}
.post-list__title {
  font-size: 1.25rem;
  margin: 0 0 0.5rem;
}
.post-list__title a { color: var(--ink); text-decoration: none; }
.post-list__title a:hover { color: var(--accent); }
.post-list__summary {
  color: var(--ink-soft);
  margin: 0 0 0.6rem;
  font-size: 0.98rem;
}
.post-list__tags {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0;
  margin: 0;
}
.post-list__tags li {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent);
  border: 1px solid var(--rule);
  background: var(--accent-soft);
  padding: 0.1rem 0.45rem;
  border-radius: 2px;
}

/* ==========================================================================
   Blog — single post
   ========================================================================== */
.post {
  padding-top: var(--space-4);
  padding-bottom: var(--space-6);
}
.post__back { font-family: var(--font-mono); font-size: 0.85rem; }
.post__back a { text-decoration: none; }
.post__back--bottom { margin-top: var(--space-5); padding-top: var(--space-3); border-top: 1px solid var(--rule); }
.post__head { margin: 1.5rem 0 var(--space-4); }
.post__date {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.6rem;
}
.post__title {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  margin: 0 0 0.75rem;
  max-width: var(--measure);
}

.post__body { max-width: var(--measure); }
.post__body h2 {
  font-size: 1.35rem;
  margin: 2.2rem 0 1rem;
  padding-top: 1.5rem;
  border-top: 1px dashed var(--rule-strong);
}
.post__body h2:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.post__body h3 { font-size: 1.1rem; margin: 1.8rem 0 0.75rem; }
.post__body p { margin: 0 0 1.15rem; }
.post__body ul, .post__body ol { margin: 0 0 1.15rem; padding-left: 1.4rem; }
.post__body li { margin-bottom: 0.4rem; }
.post__body blockquote {
  margin: 0 0 1.15rem;
  padding: 0.2rem 0 0.2rem 1.1rem;
  border-left: 3px solid var(--accent);
  color: var(--ink-soft);
  font-style: italic;
}
.post__body a { color: var(--accent); }

/* Inline code */
.post__body :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--paper-alt);
  border: 1px solid var(--rule);
  padding: 0.1em 0.35em;
  border-radius: 2px;
}

/* Fenced code blocks (highlighted at build time by eleventy-plugin-syntaxhighlight) */
.post__body pre[class*="language-"] {
  background: var(--ink);
  color: #E7E4DA;
  padding: 1.1rem 1.2rem;
  border-radius: 3px;
  overflow-x: auto;
  margin: 0 0 1.4rem;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.55;
}
.post__body pre[class*="language-"] code { background: none; border: none; padding: 0; }

/* Custom token palette matched to the site's ink/accent/accent-2 tokens */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata { color: #8B9099; font-style: italic; }
.token.keyword,
.token.selector,
.token.important { color: #9FB6D9; }
.token.string,
.token.attr-value { color: #C9B27C; }
.token.number,
.token.boolean,
.token.constant { color: #D08F8F; }
.token.function,
.token.class-name { color: #E7E4DA; font-weight: 600; }
.token.operator,
.token.punctuation { color: #A9AEB6; }
.token.builtin,
.token.tag { color: #9FB6D9; }

/* KaTeX math: align with body type rather than the KaTeX default font weight */
.katex { font-size: 1.05em; }
.post__body .katex-display {
  margin: 1.5rem 0;
  padding: 0.75rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ==========================================================================
   CV
   ========================================================================== */
.cv-block__title {
  font-size: 1.15rem;
  margin: 0 0 1rem;
}
.cv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: var(--measure);
}
.cv-list__item {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--rule);
  font-size: 0.98rem;
}
.cv-list__period {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
}
.cv-list--plain .cv-list__item--plain {
  display: block;
  color: var(--ink-soft);
}
.skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1.5rem;
  max-width: var(--measure);
}
.skills-group__title {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 0.6rem;
}
.skills-group__list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0;
  margin: 0;
}
.skills-group__list li {
  font-size: 0.88rem;
  background: var(--paper-alt);
  border: 1px solid var(--rule);
  padding: 0.25rem 0.6rem;
  border-radius: 2px;
  color: var(--ink-soft);
}
@media (max-width: 560px) {
  .cv-list__item { grid-template-columns: 1fr; gap: 0.15rem; }
}

/* ==========================================================================
   Contact
   ========================================================================== */
.contact-list {
  margin: var(--space-3) 0;
  max-width: var(--measure);
}
.contact-list__row {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--rule);
}
.contact-list dt {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
}
.contact-list dd { margin: 0; }
@media (max-width: 520px) {
  .contact-list__row { grid-template-columns: 1fr; gap: 0.15rem; }
}

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
  border-top: 1px solid var(--rule);
  padding: var(--space-4) 0;
  margin-top: var(--space-4);
}
.site-footer__inner {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.site-footer p {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
}

/* ==========================================================================
   Reveal-on-scroll (subtle, orchestrated once per element)
   ========================================================================== */
.pub, .project-card, .cv-list__item {
  opacity: 0;
  transform: translateY(8px);
  animation: reveal 0.5s ease forwards;
  animation-play-state: paused;
}
.pub.is-visible, .project-card.is-visible, .cv-list__item.is-visible {
  animation-play-state: running;
}
@keyframes reveal {
  to { opacity: 1; transform: translateY(0); }
}
