/* ---------- tokens ---------- */
:root {
  --bg: #fbfaf7;
  --fg: #1c1c1e;
  --muted: #6a6a70;
  --rule: #e5e2dc;
  --accent: #1d4ed8;
  --accent-hover: #1e3a8a;
  --code-bg: #f2f0eb;
  --callout-bg: #f3f1ec;
  --figure-bg: #ffffff;

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --measure: 42rem;

  /* syntax */
  --hl-comment: #6a737d;
  --hl-keyword: #b3135c;
  --hl-string: #0b6e3d;
  --hl-number: #1d4ed8;
  --hl-name: #6f42c1;
  --hl-builtin: #9a5a00;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131315;
    --fg: #e7e5e0;
    --muted: #9b9ba2;
    --rule: #2a2a2f;
    --accent: #93b4ff;
    --accent-hover: #c3d4ff;
    --code-bg: #1c1c20;
    --callout-bg: #1b1b1f;
    --hl-comment: #8b949e;
    --hl-keyword: #ff7ab2;
    --hl-string: #7ee2a8;
    --hl-number: #93b4ff;
    --hl-name: #d2a8ff;
    --hl-builtin: #f0b46b;
  }
}

:root[data-theme="dark"] {
  --bg: #131315;
  --fg: #e7e5e0;
  --muted: #9b9ba2;
  --rule: #2a2a2f;
  --accent: #93b4ff;
  --accent-hover: #c3d4ff;
  --code-bg: #1c1c20;
  --callout-bg: #1b1b1f;
  --hl-comment: #8b949e;
  --hl-keyword: #ff7ab2;
  --hl-string: #7ee2a8;
  --hl-number: #93b4ff;
  --hl-name: #d2a8ff;
  --hl-builtin: #f0b46b;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.65;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
}

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 1rem;
}

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

h1, h2, h3 { line-height: 1.25; font-weight: 600; }
h2 { font-size: 1.5rem; margin: 2.5rem 0 0.75rem; }
h3 { font-size: 1.2rem; margin: 2rem 0 0.5rem; }

hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

/* ---------- header / footer ---------- */
.site-header { border-bottom: 1px solid var(--rule); }
.header-inner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 1.1rem;
  padding-bottom: 1.1rem;
  font-family: var(--sans);
}
.site-title { font-weight: 600; font-size: 1rem; color: var(--fg); text-decoration: none; }
.site-nav { display: flex; 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); }

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

.site-footer { border-top: 1px solid var(--rule); font-family: var(--sans); font-size: 0.85rem; color: var(--muted); }
.footer-inner { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding-top: 1.25rem; padding-bottom: 2rem; }

/* ---------- social icons ---------- */
.social { display: flex; align-items: center; gap: 0.9rem; list-style: none; margin: 0; padding: 0; }
.social a { display: inline-flex; padding: 0.2rem; border-radius: 6px; color: var(--muted); }
.social a:hover, .social a:focus-visible { color: var(--fg); }
.social svg { display: block; width: 1.1rem; height: 1.1rem; fill: currentColor; }
.social-home { gap: 1.1rem; margin-top: 1.25rem; margin-left: -0.2rem; }
.social-home svg { width: 1.5rem; height: 1.5rem; }

/* ---------- home ---------- */
.intro h1 { font-size: 2rem; margin: 0 0 0.25rem; }

.section-label {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 3rem 0 0.75rem;
}

/* ---------- post lists ---------- */
.page-title { font-size: 2rem; margin: 0 0 1.5rem; }
.post-list { list-style: none; margin: 0; padding: 0; }
.post-list li { padding: 0.9rem 0; border-top: 1px solid var(--rule); }
.post-list li:last-child { border-bottom: 1px solid var(--rule); }
.post-list time { display: block; font-family: var(--sans); font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.post-list a { font-weight: 600; text-decoration: none; color: var(--fg); }
.post-list a:hover { color: var(--accent); }
.post-list p { margin: 0.2rem 0 0; font-size: 1rem; color: var(--muted); }

/* ---------- publications ---------- */
.pub { margin: 0 0 1.75rem; }
.pub-title { font-weight: 600; }
.pub-authors, .pub-venue { font-size: 1rem; }
.pub-venue { color: var(--muted); font-style: italic; }
.pub-links { font-family: var(--sans); font-size: 0.85rem; display: flex; gap: 0.9rem; margin-top: 0.2rem; }
.me { text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px; }

/* ---------- post ---------- */
.post-header { margin-bottom: 2rem; }
.post-title { font-size: 2.2rem; margin: 0 0 0.5rem; letter-spacing: -0.01em; }
.post-meta { font-family: var(--sans); font-size: 0.9rem; color: var(--muted); margin: 0; }
.post-meta .sep { margin: 0 0.4rem; }

.post-content p, .post-content ul, .post-content ol { margin: 0 0 1.15rem; }
.post-content li { margin: 0.3rem 0; }

.post-content blockquote,
.callout {
  margin: 1.5rem 0;
  padding: 0.9rem 1.1rem;
  background: var(--callout-bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
}
.post-content blockquote p:last-child, .callout p:last-child { margin-bottom: 0; }

.todo {
  font-family: var(--sans);
  font-size: 0.9rem;
  background: #fff3c4;
  color: #5c4400;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

/* ---------- figures ---------- */
.figure { margin: 2rem 0; }
.figure img {
  display: block;
  width: 100%;
  height: auto;
  background: var(--figure-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.75rem;
}
.figure figcaption { font-size: 0.95rem; color: var(--muted); margin-top: 0.6rem; line-height: 1.5; }
.figure-pair .figure-images { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.figure-narrow .figure-images { max-width: 22rem; margin: 0 auto; }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; margin: 1.5rem 0; }
.post-content table {
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  width: 100%;
  margin: 1.5rem 0;
}
.post-content th, .post-content td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--rule); text-align: right; white-space: nowrap; }
.post-content th:first-child, .post-content td:first-child { text-align: left; }
.post-content thead th { font-weight: 600; border-bottom: 1.5px solid var(--fg); }

/* ---------- math ---------- */
.katex { font-size: 1.05em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 0.25rem 0; }

/* ---------- code ---------- */
code, pre { font-family: var(--mono); font-size: 0.85em; }
:not(pre) > code { background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 4px; }
pre {
  background: var(--code-bg);
  padding: 1rem 1.1rem;
  border-radius: 8px;
  overflow-x: auto;
  line-height: 1.5;
  margin: 1.5rem 0;
}
pre code { background: none; padding: 0; font-size: 0.82rem; }
div.highlighter-rouge, figure.highlight { margin: 0; }

.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs { color: var(--hl-comment); font-style: italic; }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kc, .highlight .kr, .highlight .ow { color: var(--hl-keyword); }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sd, .highlight .si, .highlight .sa { color: var(--hl-string); }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .mh { color: var(--hl-number); }
.highlight .nf, .highlight .fm, .highlight .nc, .highlight .nd { color: var(--hl-name); }
.highlight .nb, .highlight .bp { color: var(--hl-builtin); }

/* ---------- small screens ---------- */
@media (max-width: 600px) {
  body { font-size: 1.0625rem; }
  .post-title { font-size: 1.75rem; }
  .intro h1, .page-title { font-size: 1.7rem; }
  main.wrap { padding-top: 1.75rem; }
  .figure img { padding: 0.4rem; }
  .figure-pair .figure-images { grid-template-columns: 1fr; max-width: 20rem; margin: 0 auto; }
}
