/* ==========================================================================
   Minimal blog-first theme. Plain CSS, variables on :root.
   Theme: follows the OS (prefers-color-scheme) unless <html data-theme="light|dark">
   ========================================================================== */

:root {
  --bg: #fdfdfc;
  --fg: #26292e;
  --muted: #6b7280;
  --border: #e6e7ea;
  --accent: #2456c4;
  --accent-underline: rgba(36, 86, 196, 0.35);
  --code-bg: #f4f5f7;
  --code-fg: #26292e;
  --note-bg: #f1f6ff;
  --note-border: #9db8ee;
  --mark: #fff3b0;

  /* syntax highlighting (GitHub light) */
  --hl-comment: #6e7781;
  --hl-keyword: #cf222e;
  --hl-string: #0a3069;
  --hl-number: #0550ae;
  --hl-func: #8250df;
  --hl-type: #953800;
  --hl-const: #0550ae;
  --hl-tag: #116329;
  --hl-var: #953800;
  --hl-del-bg: #ffebe9;
  --hl-ins-bg: #dafbe1;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1114;
    --fg: #d9dce1;
    --muted: #8b93a1;
    --border: #262b32;
    --accent: #7fa9ff;
    --accent-underline: rgba(127, 169, 255, 0.4);
    --code-bg: #161b22;
    --code-fg: #d9dce1;
    --note-bg: #14202f;
    --note-border: #35557f;
    --mark: #4a4300;

    --hl-comment: #8b949e;
    --hl-keyword: #ff7b72;
    --hl-string: #a5d6ff;
    --hl-number: #79c0ff;
    --hl-func: #d2a8ff;
    --hl-type: #ffa657;
    --hl-const: #79c0ff;
    --hl-tag: #7ee787;
    --hl-var: #ffa657;
    --hl-del-bg: #4c1f21;
    --hl-ins-bg: #1b3a26;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1114;
  --fg: #d9dce1;
  --muted: #8b93a1;
  --border: #262b32;
  --accent: #7fa9ff;
  --accent-underline: rgba(127, 169, 255, 0.4);
  --code-bg: #161b22;
  --code-fg: #d9dce1;
  --note-bg: #14202f;
  --note-border: #35557f;
  --mark: #4a4300;

  --hl-comment: #8b949e;
  --hl-keyword: #ff7b72;
  --hl-string: #a5d6ff;
  --hl-number: #79c0ff;
  --hl-func: #d2a8ff;
  --hl-type: #ffa657;
  --hl-const: #79c0ff;
  --hl-tag: #7ee787;
  --hl-var: #ffa657;
  --hl-del-bg: #4c1f21;
  --hl-ins-bg: #1b3a26;
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap {
  width: 100%;
  max-width: 760px;           /* 720px content + 2 x 20px padding */
  margin: 0 auto;
  padding: 0 20px;
}

main.wrap { flex: 1; padding-top: 2.5rem; padding-bottom: 4rem; }

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
a:hover { text-decoration-color: currentColor; }

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--bg); padding: .5rem 1rem; z-index: 10;
}
.skip-link:focus { left: 0; }

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

h1, h2, h3, h4 {
  font-family: var(--font-sans);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin: 2em 0 0.6em;
}
h1 { font-size: 1.9rem; margin-top: 0; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }

p, ul, ol, pre, blockquote, table, figure, details { margin: 0 0 1.2em; }

img { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2.5em 0; }

::selection { background: var(--accent-underline); }
mark { background: var(--mark); color: inherit; padding: 0 .15em; }

/* ---------- header / footer ---------- */
.site-header { padding: 1.4rem 0 0; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.site-title {
  color: var(--fg);
  font-weight: 600;
  text-decoration: none;
  letter-spacing: -0.01em;
}
.site-nav { display: flex; align-items: center; gap: 1.25rem; font-size: 0.95rem; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--fg); }

.theme-toggle {
  appearance: none; background: none; border: 0; padding: 4px; margin: 0 -4px 0 0;
  color: var(--muted); cursor: pointer; line-height: 0; border-radius: 6px;
}
.theme-toggle:hover { color: var(--fg); }
.theme-toggle:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: inline; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}
:root[data-theme="dark"] .icon-sun { display: inline; }
:root[data-theme="dark"] .icon-moon { display: none; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0 2.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 0 .6rem; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--fg); }

/* ---------- home ---------- */
.intro { display: flex; gap: 1.75rem; align-items: flex-start; margin-bottom: 1rem; }
.intro .avatar { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; flex: none; margin-top: .35rem; }
.intro .content { flex: 1; min-width: 0; }
.intro .content > :first-child { margin-top: 0; }
.social-links { font-size: .95rem; margin-top: -.4rem; }
.social-links .sep { color: var(--muted); margin: 0 .45rem; }
@media (max-width: 600px) {
  .intro { flex-direction: column; gap: 1rem; }
}

.home-section h2 {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 600; margin: 2.5rem 0 .8rem;
}
.more { font-size: .95rem; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { margin: 0 0 .6em; line-height: 1.55; }

/* ---------- post lists (home + blog) ---------- */
.post-list { list-style: none; padding: 0; margin: 0 0 1em; }
.post-list li { display: flex; gap: 1.25rem; align-items: baseline; padding: .3em 0; }
.post-date {
  flex: none; min-width: 5.6em;
  font-family: var(--font-mono); font-size: 0.82rem; color: var(--muted);
}
.post-entry { min-width: 0; }
.post-list a { color: var(--fg); text-decoration: none; }
.post-list a:hover { color: var(--accent); }
.post-desc { color: var(--muted); font-size: .9rem; line-height: 1.5; margin-top: .1em; }
.page .year { font-size: 1.1rem; margin: 2rem 0 .4rem; padding-bottom: .3rem; border-bottom: 1px solid var(--border); }
@media (max-width: 480px) {
  .post-list li { flex-direction: column; gap: 0; }
}

/* ---------- publications ---------- */
.page-title { margin-bottom: 1.5rem; }
.content .entry-list, .content .post-list { list-style: none; padding: 0; }
.content .entry-list > li { margin: 0 0 1.9em; }
.entry { margin: 0 0 1.5em; line-height: 1.55; }
.entry-title { font-weight: 600; }
.entry.has-thumb { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.entry-thumb {
  width: 160px; aspect-ratio: 4 / 3; object-fit: cover; margin-top: .25em;
  border-radius: 6px; border: 1px solid var(--border); background: var(--bg-alt, transparent);
}
@media (max-width: 560px) {
  .entry.has-thumb { grid-template-columns: 96px minmax(0, 1fr); gap: .9rem; }
  .entry-thumb { width: 96px; }
}
.entry-body p { margin: 0; font-size: .92rem; }
.entry-venue { font-style: italic; color: var(--muted); font-size: .9rem; margin: .1em 0 .25em; }
.entry-body .links { margin-top: .2em; }
.links { font-size: .92rem; }
details { font-size: .92rem; margin: .4em 0 0; }
summary { cursor: pointer; color: var(--muted); }
summary:hover { color: var(--fg); }
details p { margin: .5em 0 0; color: var(--fg); }
/* Abstract / BibTeX toggles sit on one row while closed; an open one takes the full width. */
.entry-toggles { margin-top: .35em; }
.entry-toggles details { display: inline-block; margin: 0 1.1rem 0 0; vertical-align: top; }
.entry-toggles details[open] { display: block; margin: 0 0 .4em; }
.code-block { position: relative; margin-top: .5em; }
.bibtex pre {
  margin: 0; padding: .75rem .9rem; font-size: .78rem; line-height: 1.5;
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 6px; overflow-x: auto;
}

/* ---------- post ---------- */
.post-header { margin-bottom: 2rem; }
.post-title { font-size: 2.1rem; line-height: 1.2; margin-bottom: .5rem; }
.post-meta { color: var(--muted); font-size: .88rem; margin: 0; }
.tag { margin-right: .3em; }

.toc {
  border: 1px solid var(--border); border-radius: 8px; padding: .8rem 1.1rem .5rem;
  margin: 0 0 2rem; font-size: .92rem; line-height: 1.5;
}
.toc[hidden] { display: none; }
.toc-title { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; color: var(--muted); font-weight: 600; margin-bottom: .3rem; }
.toc-list, .toc-list ol { list-style: none; padding: 0; margin: 0; }
.toc-list ol { padding-left: 1.1rem; }
.toc-list li { margin: .15em 0; }
.toc a { color: var(--fg); text-decoration: none; }
.toc a:hover { color: var(--accent); }
.toc a.active { color: var(--accent); font-weight: 600; }

/* Wide screens: TOC moves into the right gutter and follows the reader. */
.post { position: relative; }
@media (min-width: 1240px) {
  .toc {
    position: absolute; top: 0; bottom: 0; left: calc(100% + 2.5rem); width: 210px;
    margin: 0; padding: 0; border: 0; border-radius: 0; font-size: .84rem;
  }
  .toc-inner {
    position: sticky; top: 2rem; max-height: calc(100vh - 4rem); overflow-y: auto;
    border-left: 1px solid var(--border); padding-left: .9rem;
  }
  .toc-list ol { padding-left: .8rem; }
  .toc a { color: var(--muted); display: block; padding: .1em 0; }
  .toc a:hover { color: var(--fg); }
  .toc a.active { color: var(--accent); font-weight: 600; }
}

.post-content h2, .post-content h3, .post-content h4 { position: relative; scroll-margin-top: 1.5rem; }
.heading-anchor {
  position: absolute; left: -1.1em; padding-right: .3em; text-decoration: none;
  color: var(--muted); opacity: 0; font-weight: 400;
}
h2:hover > .heading-anchor, h3:hover > .heading-anchor, h4:hover > .heading-anchor,
.heading-anchor:focus { opacity: 1; }
@media (max-width: 800px) { .heading-anchor { display: none; } }

.content ul, .content ol { padding-left: 1.5rem; }
.content li { margin: .25em 0; }
.content li > p { margin-bottom: .5em; }

blockquote {
  margin-left: 0; margin-right: 0; padding: .1em 0 .1em 1.1rem;
  border-left: 3px solid var(--border); color: var(--muted);
}
blockquote > :last-child { margin-bottom: 0; }

/* note / callout: `> text` followed by `{: .note}` or `{: .note}` on a paragraph */
.note {
  background: var(--note-bg); border: 1px solid var(--note-border); border-left-width: 4px;
  border-radius: 6px; padding: .75rem 1rem; color: var(--fg);
}
blockquote.note { margin-left: 0; }
.note > :last-child { margin-bottom: 0; }

/* tables: scroll inside themselves on narrow screens */
table {
  display: block; width: max-content; max-width: 100%; overflow-x: auto;
  border-collapse: collapse; font-size: .92rem; line-height: 1.5;
}
th, td { padding: .45em .9em; border-bottom: 1px solid var(--border); text-align: left; }
th { font-weight: 600; border-bottom: 2px solid var(--border); }

/* figures */
figure { margin: 1.8em 0; text-align: center; }
figure img, p > img { display: block; margin: 0 auto; border-radius: 4px; }
figcaption { color: var(--muted); font-size: .88rem; line-height: 1.5; margin-top: .6em; }

/* footnotes (kramdown) */
.footnotes { font-size: .88rem; color: var(--muted); border-top: 1px solid var(--border); margin-top: 3rem; padding-top: .5rem; }
.footnotes ol { padding-left: 1.2rem; }
.footnotes p { margin-bottom: .3em; }
sup[role="doc-noteref"], sup { line-height: 0; }
a.footnote { text-decoration: none; }

/* ---------- code ---------- */
code, pre, kbd, samp { font-family: var(--font-mono); }

:not(pre) > code {
  font-size: .86em; background: var(--code-bg); color: var(--code-fg);
  padding: .15em .38em; border-radius: 4px;
  overflow-wrap: anywhere;
}

pre {
  background: var(--code-bg); color: var(--code-fg);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .9rem 1.1rem; overflow-x: auto;
  font-size: .84rem; line-height: 1.55; tab-size: 4;
}
pre code { font-size: inherit; background: none; padding: 0; white-space: pre; }

div.highlighter-rouge { position: relative; margin: 0 0 1.2em; }
div.highlighter-rouge pre { margin: 0; }
div.highlighter-rouge .highlight { margin: 0; }

.copy-btn {
  position: absolute; top: .45rem; right: .45rem;
  font: 500 .72rem var(--font-sans); letter-spacing: .02em;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border); border-radius: 5px;
  padding: .2rem .55rem; cursor: pointer; opacity: 0; transition: opacity .15s;
}
div.highlighter-rouge:hover .copy-btn, .code-block:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; }
.copy-btn:hover { color: var(--fg); }
@media (hover: none) { .copy-btn { opacity: .8; } }

/* ---------- math (KaTeX) ---------- */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: .2em 0; margin: 1.1em 0; }
.katex { font-size: 1.06em; }

/* ---------- post nav ---------- */
.post-nav {
  display: flex; justify-content: space-between; gap: 1.5rem;
  border-top: 1px solid var(--border); margin-top: 3.5rem; padding-top: 1.2rem;
  font-size: .92rem; line-height: 1.45;
}
.post-nav a { text-decoration: none; color: var(--fg); max-width: 48%; }
.post-nav a:hover { color: var(--accent); }
.post-nav .next { text-align: right; margin-left: auto; }
.post-nav .muted { font-size: .78rem; }

/* ---------- 404 ---------- */
.not-found { text-align: center; padding: 4rem 0; }
.not-found h1 { font-size: 4rem; margin-bottom: .5rem; }

@media print {
  .site-header, .site-footer, .copy-btn, .post-nav, .theme-toggle { display: none; }
  body { font-size: 12pt; }
}
.site-footer .sep { margin: 0; color: inherit; }

/* ---------- drafts (local preview only) ---------- */
.draft-badge {
  display: inline-block; font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent); border: 1px solid currentColor; border-radius: 4px; padding: .05em .45em; vertical-align: middle;
}
.draft-banner { font-size: .85rem; color: var(--muted); margin: 0 0 1rem; }
