/* ==========================================================================
   Theme tokens
   ========================================================================== */
:root {
  --gap: 24px;
  --content-gap: 20px;
  --nav-width: 1024px;
  --main-width: 720px;
  --header-height: 60px;
  --footer-height: 60px;
  --radius: 8px;

  --theme: #ffffff;
  --entry: #ffffff;
  --primary: #1e1e1e;
  --secondary: #6c6c6c;
  --tertiary: #d6d6d6;
  --content: #1f1f1f;
  --link: #1d5fa8;
  --code-block-bg: #1c1d21;
  --code-bg: #f5f5f5;
  --border: #eeeeee;
}

:root[data-theme="dark"] {
  --theme: #1d1e20;
  --entry: #2e2e33;
  --primary: #dadadb;
  --secondary: #9b9c9d;
  --tertiary: #414244;
  --content: #c4c4c5;
  --link: #7fb2f0;
  --code-block-bg: #2e2e33;
  --code-bg: #37383e;
  --border: #333333;
}

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

html { -webkit-tap-highlight-color: transparent; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  word-break: break-word;
  color: var(--primary);
  background: var(--theme);
}

h1, h2, h3, h4, h5, h6 { color: var(--primary); line-height: 1.25; }
a { color: inherit; text-decoration: none; }
img, svg, video { max-width: 100%; }
button { font: inherit; background: none; border: 0; color: inherit; cursor: pointer; }
ul { padding-inline-start: 22px; }

/* ==========================================================================
   Header / navigation
   ========================================================================== */
.nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  max-width: calc(var(--nav-width) + var(--gap) * 2);
  margin: 0 auto;
  line-height: var(--header-height);
}
.logo { display: flex; align-items: center; margin: 0 var(--gap); }
.logo a { font-size: 22px; font-weight: 700; }
#theme-toggle { display: inline-flex; margin-inline-start: 10px; padding: 4px; }
#theme-toggle svg { height: 18px; }
:root[data-theme="dark"] .icon-moon,
:root:not([data-theme="dark"]) .icon-sun { display: none; }

#menu {
  display: flex;
  list-style: none;
  margin: 0 var(--gap);
  padding: 0;
  overflow-x: auto;
  white-space: nowrap;
  word-break: keep-all;
}
#menu li + li { margin-inline-start: var(--gap); }
#menu a { font-size: 16px; }
#menu a.active { font-weight: 500; border-bottom: 2px solid currentColor; }

/* ==========================================================================
   Main column
   ========================================================================== */
.main {
  position: relative;
  min-height: calc(100vh - var(--header-height) - var(--footer-height));
  max-width: calc(var(--main-width) + var(--gap) * 2);
  margin: auto;
  padding: var(--gap);
}

.page-header h1 { font-size: 40px; margin: 0 0 8px; }
.page-header { margin: 24px 0 32px; }
.page-subtitle { color: var(--secondary); margin: 0; }
.page-subtitle a { text-decoration: underline; }

/* ==========================================================================
   Home: intro + post list
   ========================================================================== */
.home-info { margin: var(--gap) 0 calc(var(--gap) * 2); }
.home-info h1 { font-size: 34px; margin: 0 0 12px; }
.home-info .entry-content {
  display: block;
  overflow: visible;
  -webkit-line-clamp: unset;
  color: var(--secondary);
  font-size: 16px;
}
.home-info .entry-content a { color: var(--primary); }
.home-info .entry-content p { margin: 0 0 10px; }

.social-icons { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 12px; }
.social-icons a { display: inline-flex; padding: 6px; border-radius: 6px; }
.social-icons a:hover { background: var(--border); }
.social-icons svg { width: 26px; height: 26px; }

.post-entry {
  position: relative;
  margin-bottom: var(--gap);
  padding: var(--gap);
  background: var(--entry);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: transform 0.1s;
}
.post-entry:active { transform: scale(0.98); }
.post-entry:hover { border-color: var(--tertiary); }
.entry-header h2 { font-size: 24px; margin: 0; line-height: 1.3; }
.entry-content {
  margin: 8px 0;
  color: var(--secondary);
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.entry-content p { margin: 0; }
.entry-footer { color: var(--secondary); font-size: 13px; }
.entry-link { position: absolute; inset: 0; }

.pagination { display: flex; justify-content: space-between; margin-top: var(--gap); }
.pagination a {
  padding: 0 16px;
  line-height: 36px;
  border-radius: calc(36px / 2);
  background: var(--primary);
  color: var(--theme);
  font-size: 13px;
}
.pagination .next { margin-inline-start: auto; }

/* ==========================================================================
   Single post / page
   ========================================================================== */
.post-header { margin: 24px auto var(--content-gap); }
.post-title { font-size: 36px; margin: 0 0 4px; }
.post-description { color: var(--secondary); margin: 4px 0 8px; }
.post-meta { color: var(--secondary); font-size: 14px; display: flex; flex-wrap: wrap; align-items: center; }

.post-content { color: var(--content); }
.post-content h1 { margin: 40px auto 24px; font-size: 32px; }
.post-content h2 { margin: 32px auto 20px; font-size: 26px; }
.post-content h3 { margin: 24px auto 16px; font-size: 20px; }
.post-content h4 { margin: 20px auto 12px; font-size: 17px; }
.post-content a,
.toc a:hover { color: var(--link); box-shadow: 0 1px 0 color-mix(in srgb, var(--link) 40%, transparent); }
.post-content a:hover { box-shadow: 0 1px 0 var(--link); }
.post-content p, .post-content ul, .post-content ol, .post-content dl,
.post-content table, .post-content blockquote, .post-content figure { margin: 0 0 var(--content-gap); }
.post-content li { margin-top: 5px; }
.post-content li p { margin-bottom: 0; }
.post-content img { display: block; margin: 0 auto; border-radius: 4px; height: auto; }
.post-content hr { margin: 30px 0; height: 1px; background: var(--border); border: 0; }
.post-content blockquote {
  margin-inline: 0;
  padding: 0 14px;
  border-inline-start: 3px solid var(--tertiary);
  color: var(--secondary);
}

.post-content table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 15px;
}
.post-content th, .post-content td { padding: 6px 10px; border: 1px solid var(--border); text-align: start; }
.post-content th { background: var(--code-bg); }

/* kramdown "{:toc}" — rendered as a boxed table of contents */
.post-content #markdown-toc {
  list-style: none;
  margin: 0 0 32px;
  padding: 12px 16px 12px 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--entry);
  font-size: 15px;
}
.post-content #markdown-toc ul,
.post-content #markdown-toc ol { list-style: none; padding-inline-start: 18px; margin: 0; }
.post-content #markdown-toc a { box-shadow: none; color: var(--content); }
.post-content #markdown-toc a:hover { color: var(--link); }

/* Inline code and code blocks */
code, pre, kbd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }
.post-content code {
  margin: auto 3px;
  padding: 3px 5px;
  font-size: 0.85em;
  line-height: 1.5;
  background: var(--code-bg);
  border-radius: 3px;
}
.post-content pre,
.post-content .highlight {
  background: var(--code-block-bg) !important;
  border-radius: var(--radius);
}
.post-content pre {
  margin: 0 0 var(--content-gap);
  padding: 12px 16px;
  overflow-x: auto;
  color: #d5d5d6;
  font-size: 14px;
  line-height: 1.5;
}
.post-content pre code { margin: 0; padding: 0; background: none; font-size: inherit; color: inherit; }
.post-content .highlight { margin: 0 0 var(--content-gap); }
.post-content .highlight pre { margin: 0; }

/* MathJax: let wide equations scroll instead of overflowing the column */
mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
body.distill d-article mjx-container[display="true"] { margin: 1.25em 0 !important; }
/* Display equations may use Distill's wider page column (same centre line as the text). */
body.distill d-article > mjx-container[display="true"],
body.distill d-article > span:has(> mjx-container[display="true"]) { grid-column: page; }

/* Post footer */
.post-footer { margin-top: 48px; }
.post-tags { display: flex; flex-wrap: wrap; gap: 10px; list-style: none; padding: 0; margin: 0 0 24px; }
.post-tags a, .tag-cloud a {
  display: inline-block;
  padding: 0 14px;
  font-size: 14px;
  line-height: 34px;
  color: var(--secondary);
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.post-tags a:hover, .tag-cloud a:hover { background: var(--border); }

.paginav {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  line-height: 1.4;
}
.paginav a { flex: 1; padding: 12px 16px; font-weight: 500; }
.paginav .title { font-size: 13px; color: var(--secondary); font-weight: 400; letter-spacing: 1px; text-transform: uppercase; }
.paginav .next { text-align: end; margin-inline-start: auto; }
.paginav .prev + .next { border-inline-start: 1px solid var(--border); }

.comments { margin-top: 40px; }

/* ==========================================================================
   Archive, tags, search
   ========================================================================== */
.archive-year { margin-top: 40px; }
.archive-year h2 { font-size: 28px; margin: 0 0 8px; }
.archive-entry {
  position: relative;
  padding: 6px 0;
  display: flex;
  gap: 16px;
  align-items: baseline;
}
.archive-entry .date { flex: 0 0 64px; color: var(--secondary); font-size: 14px; }
.archive-entry a:hover { color: var(--link); }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 10px; list-style: none; padding: 0; margin: 0 0 40px; }
.tag-cloud sup { font-size: 11px; margin-inline-start: 2px; }
.tag-section h2 { font-size: 22px; margin: 32px 0 8px; }
.tag-section ul { margin: 0; }

#search-input {
  width: 100%;
  padding: 10px 16px;
  font-size: 16px;
  color: var(--primary);
  background: var(--entry);
  border: 1px solid var(--tertiary);
  border-radius: var(--radius);
  outline: none;
}
#search-input:focus { border-color: var(--secondary); }
#search-results { list-style: none; padding: 0; margin: 24px 0 0; }
#search-results li { padding: 12px 0; border-bottom: 1px solid var(--border); }
#search-results .title { font-weight: 600; }
#search-results .title:hover { color: var(--link); }
#search-results .snippet { color: var(--secondary); font-size: 14px; margin: 4px 0 0; }
#search-results mark { background: color-mix(in srgb, var(--link) 25%, transparent); color: inherit; border-radius: 2px; }

/* ==========================================================================
   Publications, projects, talks, news
   ========================================================================== */
.pub-year { font-size: 22px; margin: 36px 0 12px; color: var(--secondary); }
.pub {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.pub .pub-title { font-weight: 600; color: var(--primary); }
.pub .pub-authors, .pub .pub-venue { font-size: 15px; color: var(--secondary); }
.pub .pub-authors strong { color: var(--primary); }
.pub-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; list-style: none; padding: 0; }
.pub-links a {
  display: inline-block;
  padding: 0 10px;
  font-size: 13px;
  line-height: 26px;
  color: var(--secondary);
  border: 1px solid var(--tertiary);
  border-radius: 13px;
  box-shadow: none !important;
}
.pub-links a:hover { color: var(--primary); border-color: var(--secondary); }

.project {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 20px;
  margin-bottom: var(--gap);
  padding: var(--gap);
  background: var(--entry);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.project img { width: 140px; height: 110px; object-fit: cover; border-radius: 6px; margin: 0; }
.project img[style*="contain"] { background: #fff; padding: 6px; }
.project-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 140px;
  height: 110px;
  font-size: 44px;
  border-radius: 6px;
  background: var(--code-bg);
  border: 1px solid var(--border);
}
.project h2 { font-size: 19px; margin: 0 0 6px; }
.project ul { margin: 0; font-size: 15px; color: var(--content); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.timeline .date { flex: 0 0 92px; color: var(--secondary); font-size: 14px; padding-top: 1px; }


/* ==========================================================================
   Footer
   ========================================================================== */
.footer {
  max-width: calc(var(--main-width) + var(--gap) * 2);
  margin: auto;
  padding: calc((var(--footer-height) - var(--gap)) / 2) var(--gap);
  text-align: center;
  line-height: 24px;
  font-size: 12px;
  color: var(--secondary);
}
.footer span { margin-inline: 2px; }
.footer a { border-bottom: 1px solid var(--secondary); }

.top-link {
  position: fixed;
  right: 30px;
  bottom: 60px;
  z-index: 99;
  width: 42px;
  height: 42px;
  padding: 12px;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--tertiary);
  border-radius: 64px;
  opacity: 0.8;
}
.top-link.visible { display: flex; }
.top-link svg { color: var(--primary); }

/* ==========================================================================
   Small screens
   ========================================================================== */
@media (max-width: 768px) {
  :root { --gap: 16px; }
  .nav { justify-content: flex-start; }
  #menu { width: 100%; }
  .home-info h1 { font-size: 28px; }
  .post-title { font-size: 28px; }
  .page-header h1 { font-size: 32px; }
  .entry-header h2 { font-size: 20px; }
  .project { grid-template-columns: 1fr; }
  .project img, .project-icon { width: 100%; height: 160px; }
  .timeline .date { flex-basis: 80px; }
  .top-link { right: 16px; bottom: 24px; }
}

/* ==========================================================================
   Syntax highlighting (rouge) — dark code blocks in both themes
   ========================================================================== */
.highlight .c, .highlight .ch, .highlight .cd, .highlight .cm, .highlight .cpf,
.highlight .c1, .highlight .cs { color: #7f848e; font-style: italic; }
.highlight .cp { color: #c678dd; }
.highlight .k, .highlight .kc, .highlight .kd, .highlight .kn, .highlight .kp,
.highlight .kr, .highlight .kv, .highlight .ow { color: #c678dd; }
.highlight .kt { color: #e5c07b; }
.highlight .s, .highlight .sa, .highlight .sb, .highlight .sc, .highlight .dl,
.highlight .sd, .highlight .s2, .highlight .se, .highlight .sh, .highlight .si,
.highlight .sx, .highlight .s1, .highlight .ss, .highlight .sr { color: #98c379; }
.highlight .m, .highlight .mb, .highlight .mf, .highlight .mh, .highlight .mi,
.highlight .il, .highlight .mo, .highlight .mx { color: #d19a66; }
.highlight .nf, .highlight .fm, .highlight .nx { color: #61afef; }
.highlight .nc, .highlight .nn, .highlight .ne { color: #e5c07b; }
.highlight .nb, .highlight .bp, .highlight .no { color: #56b6c2; }
.highlight .nd, .highlight .na { color: #e5c07b; }
.highlight .nt { color: #e06c75; }
.highlight .nv, .highlight .vc, .highlight .vg, .highlight .vi, .highlight .vm { color: #e06c75; }
.highlight .o { color: #56b6c2; }
.highlight .p { color: #abb2bf; }
.highlight .gd { color: #e06c75; }
.highlight .gi { color: #98c379; }
.highlight .gh, .highlight .gu { color: #61afef; font-weight: bold; }
.highlight .err { color: #e06c75; }

/* ==========================================================================
   Distill layout (layout: distill)
   The Distill template injects its own styles after this file, so rules here
   use slightly higher specificity where they need to win.
   ========================================================================== */
body.distill .main { max-width: none; padding: 0; }
body.distill .header a, body.distill .footer a { color: inherit; }
body.distill .footer a { border-bottom: 1px solid var(--secondary); }

body.distill d-title { padding-top: 40px; }
body.distill d-title h1 { color: var(--primary); }
body.distill d-title p { color: var(--secondary); }

.distill-byline { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.distill-byline .byline-grid {
  grid-column: text;
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: start;
  column-gap: 48px;
  row-gap: 12px;
  padding: 20px 0;
  font-size: 14px;
  line-height: 1.6;
}
.distill-byline h3 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--secondary);
}
.distill-byline p { margin: 0; color: var(--primary); }
.distill-byline a { color: var(--link); }
.distill-byline .affiliation { color: var(--secondary); }

body.distill d-article { color: var(--content); border-top: 0; }
body.distill d-article h2,
body.distill d-article h3,
body.distill d-article h4 { color: var(--primary); }
body.distill d-article h2 { border-bottom-color: var(--border); }
body.distill d-article a { color: var(--link); border-bottom-color: color-mix(in srgb, var(--link) 40%, transparent); }
body.distill d-article img { display: block; margin: 0 auto 24px; max-width: 100%; height: auto; border-radius: 4px; }
body.distill d-article hr { border: 0; height: 1px; background: var(--border); }
body.distill d-article blockquote { color: var(--secondary); border-left-color: var(--tertiary); }

/* Inline code and highlighted blocks, matching the rest of the site */
body.distill d-article code {
  padding: 2px 5px;
  font-size: 0.85em;
  background: var(--code-bg);
  border-radius: 3px;
  color: inherit;
}
body.distill d-article div.highlight,
body.distill d-article pre {
  background: var(--code-block-bg);
  border-radius: var(--radius);
}
body.distill d-article pre {
  margin: 0 0 24px;
  padding: 12px 16px;
  overflow-x: auto;
  color: #d5d5d6;
  font-size: 14px;
  line-height: 1.5;
}
body.distill d-article pre code { padding: 0; background: none; font-size: inherit; color: inherit; }

/* kramdown "{:toc}" */
body.distill d-article #markdown-toc {
  list-style: none;
  padding: 12px 16px 12px 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--entry);
  font-size: 15px;
}
body.distill d-article #markdown-toc ul,
body.distill d-article #markdown-toc ol { list-style: none; padding-inline-start: 18px; margin: 0; }
body.distill d-article #markdown-toc li { margin-bottom: 0; }
body.distill d-article #markdown-toc a { border-bottom: 0; color: var(--content); }
body.distill d-article #markdown-toc a:hover { color: var(--link); }

body.distill d-appendix { color: var(--secondary); background: var(--entry); border-top-color: var(--border); }
body.distill d-appendix h3 { color: var(--primary); }
body.distill d-appendix a { color: var(--link); }
body.distill d-appendix pre.citation {
  grid-column: text;
  overflow-x: auto;
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--content);
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.distill-after > * { grid-column: text; }
.distill-after .post-footer { margin-top: 32px; }

/* d-cite / d-footnote render in shadow DOM with hard-coded light colours;
   inverting them in dark mode keeps the numbers and hover boxes readable. */
:root[data-theme="dark"] body.distill d-cite,
:root[data-theme="dark"] body.distill d-footnote { filter: invert(1) hue-rotate(180deg); }

@media (max-width: 768px) {
  .distill-byline .byline-grid { grid-template-columns: 1fr 1fr; }
}
