@import url('https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;1,6..72,400&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg: #fdfcfa;
  --bg-alt: #f7f5f2;
  --fg: #1a1a1a;
  --muted: #6b6860;

  --rose: #c45d5d;
  --rose-soft: #f5e8e8;
  --rose-muted: #d4a5a5;

  --sage: #5d8a6b;
  --sage-soft: #e8f0ea;
  --sage-muted: #a5c4ad;

  --gold: #b8860b;
  --gold-soft: #f5f0e0;
  --gold-muted: #d4c4a0;

  --border: #e8e5e0;
  --border-dark: #d0cdc8;
  --max-width: 900px;
  --radius: 12px;
  --radius-sm: 6px;
}

[data-theme="dark"] {
  --bg: #1a1a1f;
  --bg-alt: #232328;
  --fg: #e8e5e0;
  --muted: #a09a90;

  --rose: #e07070;
  --rose-soft: #3a2525;
  --rose-muted: #8a5555;

  --sage: #7ab08a;
  --sage-soft: #253028;
  --sage-muted: #5a8a65;

  --gold: #d4a020;
  --gold-soft: #302a18;
  --gold-muted: #8a7a40;

  --border: #333338;
  --border-dark: #444448;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}

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

a {
  color: inherit;
  text-decoration-color: var(--border-dark);
  text-underline-offset: 3px;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}
a:hover { color: var(--rose); text-decoration-color: var(--rose-muted); }

::selection { background: var(--rose-soft); color: var(--fg); }

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 28px;
}

/* Grain texture overlay */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.03;
  z-index: 1000;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
}
[data-theme="dark"] .grain { opacity: 0.015; }

/* ---------- nav ---------- */

header.site {
  border-bottom: 1px solid var(--border);
  padding: 22px 0;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  z-index: 10;
}
header.site .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 24px;
}
.site-name {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 19px;
  font-weight: 500;
  color: var(--fg);
}
.site-name:hover { color: var(--rose); text-decoration: none; }

nav.site-nav {
  display: flex;
  align-items: center;
  gap: 24px;
}
nav.site-nav a {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
nav.site-nav a:hover { color: var(--fg); text-decoration: none; }
nav.site-nav a.current { color: var(--rose); }

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  color: var(--gold);
  border-color: var(--gold-muted);
  transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.theme-toggle:hover { transform: rotate(20deg); }

/* ---------- blog list (blog.html) ---------- */

.intro {
  padding: 56px 0 40px;
  border-bottom: 1px solid var(--border);
}
.intro h1 {
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 400;
  font-size: 34px;
  letter-spacing: -0.02em;
  margin: 0 0 14px;
}
.intro p {
  max-width: 640px;
  color: var(--muted);
  font-size: 17px;
  margin: 0;
}

.post-list { padding: 10px 0 60px; }
.post-entry {
  padding: 32px 0;
  border-bottom: 1px solid var(--border);
}
.post-entry .post-date {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sage);
  margin-bottom: 8px;
}
.post-entry .post-title {
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 400;
  font-size: 24px;
  margin: 0 0 10px;
}
.post-entry .post-title a { color: var(--fg); }
.post-entry .post-title a:hover { color: var(--rose); text-decoration: none; }
.post-entry .post-excerpt { color: var(--muted); margin: 0 0 12px; max-width: 700px; }
.post-entry .read-more {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--rose);
}
.post-entry .read-more::after { content: " \2192"; }

.empty-state { padding: 30px 0; color: var(--muted); max-width: 560px; }

/* ---------- article page: sidebar TOC layout ---------- */

.blog-layout {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 28px 4rem;
}
.article-wrapper {
  position: relative;
  padding-top: 2rem;
}

.article-toc {
  position: fixed;
  top: 6.5rem;
  left: calc((100vw - var(--max-width) - 56px) / 2 - 200px);
  width: 190px;
  text-align: right;
}
.article-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.article-toc a {
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
  line-height: 1.4;
  display: block;
}
.article-toc a:hover,
.article-toc a.toc-active { color: var(--fg); }
.article-toc a.toc-active { font-weight: 600; }

@media (max-width: 1100px) {
  .article-toc {
    position: static;
    width: auto;
    text-align: left;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1.5rem;
  }
}

main { max-width: 780px; }

article { padding: 2rem 0 4rem; }

article header {
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}
article .kicker {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--rose);
  margin-bottom: 10px;
}
article h1 {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 2.5rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 0.5rem;
  color: var(--fg);
}
article .meta {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--sage);
}

article .content {
  font-family: 'Newsreader', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  font-size: 1.08rem;
  line-height: 1.85;
}
article .content p { margin: 0 0 1.5rem; }

article .content h2 {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 1.45rem;
  font-weight: 400;
  margin: 3rem 0 1.25rem;
  color: var(--fg);
  position: relative;
  padding-left: 1rem;
}
article .content h2::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.3em;
  width: 4px;
  height: 1em;
  background: linear-gradient(180deg, var(--rose), var(--gold));
  border-radius: 2px;
}

article .content ul,
article .content ol { margin: 0 0 1.5rem; padding-left: 1.5rem; }
article .content li { margin-bottom: 0.5rem; }
article .content li::marker { color: var(--rose); }

article .content strong { font-weight: 600; color: var(--fg); }

article .content code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  background: var(--rose-soft);
  padding: 0.2em 0.45em;
  border-radius: 4px;
  color: var(--rose);
}

article .content pre {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin: 0 0 1.5rem;
  overflow-x: auto;
}
article .content pre code {
  background: none;
  padding: 0;
  color: var(--fg);
  font-size: 0.85em;
}

/* Syntax-highlighting token colors for highlight.js (loaded per-post by the
   blog build). No stock hljs theme is used; these follow the site palette
   in both light and dark mode. */
article .content pre .hljs-keyword,
article .content pre .hljs-operator { color: var(--rose); }
article .content pre .hljs-string,
article .content pre .hljs-regexp { color: var(--sage); }
article .content pre .hljs-number,
article .content pre .hljs-literal,
article .content pre .hljs-built_in { color: var(--gold); }
article .content pre .hljs-comment,
article .content pre .hljs-meta { color: var(--muted); font-style: italic; }
article .content pre .hljs-title { color: var(--fg); font-weight: 600; }
article .content pre .hljs-params { color: var(--fg); }

article .content .callout {
  border-left: 3px solid var(--sage);
  background: var(--sage-soft);
  padding: 1.1rem 1.5rem;
  margin: 2rem 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--fg);
}
article .content .callout p:last-child { margin-bottom: 0; }

article .content figure { margin: 2rem 0; }
article .content figure img {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  /* fixed light backing so transparent figures stay readable in dark mode */
  background: #fdfcfa;
  padding: 6px;
  box-sizing: border-box;
}
article .content figcaption {
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.6rem;
  font-style: italic;
}

/* KaTeX display blocks */
article .content .katex-display {
  margin: 1.75rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Citation block */
.citation-block {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.citation-block h2 {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 1.2rem;
  font-weight: 400;
  margin: 0 0 1rem;
  color: var(--fg);
}
.citation-code {
  position: relative;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.25rem 1.5rem;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}
.citation-copy {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.7rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s ease;
}
.citation-copy:hover { color: var(--rose); border-color: var(--rose-muted); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 3rem;
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}
.back-link:hover {
  color: var(--rose);
  border-color: var(--rose-muted);
  transform: translateX(-4px);
}

/* ---------- responsive ---------- */

@media (max-width: 720px) {
  .intro h1 { font-size: 27px; }
  article h1 { font-size: 1.9rem; }
}

@media (max-width: 600px) {
  header.site .wrap { padding: 0 20px; }
  nav.site-nav { gap: 16px; }
  .blog-layout { padding: 0 20px 3rem; }
  article h1 { font-size: 1.7rem; }
}
