/* Shared stylesheet for blog posts (report style — Tufte academic).
   Posts are standalone HTML files under /blog/<slug>.html and link this file.
   Aesthetic: warm cream + Georgia + academic blue + accent red,
   double-column with left sticky TOC. */

:root {
  --bg: #fdfcf7;
  --bg-soft: #f4f1ea;
  --bg-code: #f8f5ec;
  --ink: #1a1a1a;
  --ink-soft: #4a4a4a;
  --ink-muted: #6b6b6b;
  --primary: #1a4a8c;
  --primary-soft: #2d6cb8;
  --accent: #b8390e;
  --accent-deep: #9c3f1a;
  --border: #d6d0c0;
  --border-soft: #e8e3d5;
  --warn-bg: #fef3c7; --warn: #b45309;
  --info-bg: #dbeafe;
  --good-bg: #d1fae5; --good: #065f46;

  --font-serif: Georgia, "Songti SC", "Times New Roman", serif;
  --font-mono:  "JetBrains Mono", "SF Mono", Menlo, monospace;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: #f5d59b; color: var(--ink); }
code, pre, kbd { font-family: var(--font-mono); }
button { font-family: inherit; cursor: pointer; }

/* Reading progress bar (script: /blog/post.js) */
.progress-bar {
  position: fixed; top: 0; left: 0;
  height: 3px; width: 0;
  background: var(--accent);
  z-index: 100;
  transition: width 0.05s linear;
  pointer-events: none;
}

/* ==================== Page layout: 260px sticky TOC + main ==================== */
.page {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 48px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 56px 40px;
}

/* ==================== TOC ==================== */
.toc {
  position: sticky; top: 32px; align-self: start;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  font-size: 15px; line-height: 1.5;
  padding-right: 24px;
  border-right: 1px solid var(--border);
}
.post-back {
  display: inline-block;
  margin-bottom: 20px;
  font-family: var(--font-mono); font-size: 12px;
  color: var(--ink-muted); letter-spacing: 0.04em;
  text-decoration: none;
}
.post-back:hover { color: var(--accent); }
.toc-title {
  font-size: 11px; color: var(--ink-muted);
  letter-spacing: 0.1em; text-transform: uppercase;
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.toc ol { list-style: none; padding: 0; margin: 0; counter-reset: toc; }
.toc ol li.major { counter-increment: toc; }
.toc li { margin: 0; }
.toc a {
  color: var(--ink-soft); text-decoration: none;
  display: flex; align-items: baseline;
  padding: 7px 0; transition: color 0.15s;
}
.toc a:hover { color: var(--primary); }
.toc a:hover .label {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--primary);
  text-underline-offset: 4px;
  text-decoration-thickness: 1.5px;
}
.toc a.active { color: var(--accent); font-weight: 600; }
.toc li.major > a::before {
  content: counter(toc) ".";
  display: inline-block; width: 2em; text-align: right;
  margin-right: 0.9em; color: var(--ink-muted);
  font-variant-numeric: tabular-nums; flex-shrink: 0;
}
.toc li.major > a.active::before { color: var(--accent); }
.toc li.sub > a {
  font-size: 13.5px; color: var(--ink-muted); padding: 5px 0;
}
.toc li.sub > a::before {
  content: "→";
  display: inline-block; width: 2em; text-align: right;
  margin-right: 0.9em; margin-left: 1em;
  color: var(--ink-muted); flex-shrink: 0;
}
.toc li.sub > a.active,
.toc li.sub > a.active::before { color: var(--accent); }

/* ==================== Main column ==================== */
main { min-width: 0; max-width: 820px; }

.hero {
  margin-bottom: 36px;
  padding-bottom: 24px;
  border-bottom: 3px double var(--primary);
}
.hero .meta-line {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--ink-muted); letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 0 0 14px;
  display: flex; flex-wrap: wrap; gap: 14px;
}
.hero .meta-line .date { color: var(--accent); }
.post-title, .hero h1 {
  font-family: var(--font-serif); font-size: 42px;
  font-weight: 700; line-height: 1.1;
  letter-spacing: -0.02em; color: var(--ink);
  margin: 0;
}
.hero .subtitle {
  font-size: 19px; color: var(--ink-muted);
  font-style: italic; margin: 12px 0 0;
  line-height: 1.45;
}

/* ==================== Body ==================== */
.post-body p { margin: 0 0 16px; color: var(--ink-soft); }
.post-body .lede {
  font-size: 20px; line-height: 1.6;
  color: var(--ink); margin: 0 0 36px;
}
.post-body strong { color: var(--accent); font-weight: 600; }
.post-body em { color: var(--ink-soft); }
.post-body a {
  color: var(--primary); text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.post-body a:hover { border-bottom-color: var(--primary); }
.post-body ul, .post-body ol {
  padding-left: 24px; margin: 0 0 16px;
}
.post-body li { margin: 6px 0; color: var(--ink-soft); }

.post-body h2 {
  font-size: 26px; font-weight: 600; color: var(--ink);
  margin: 56px 0 16px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: 24px;
  display: flex; align-items: baseline; gap: 12px;
}
.post-body h2 .sec-num {
  color: var(--primary); font-weight: 600;
  font-size: 0.85em;
  font-variant-numeric: tabular-nums;
}
.post-body h3 {
  font-size: 19px; font-weight: 600; color: var(--primary);
  margin: 32px 0 10px; scroll-margin-top: 24px;
}
.post-body blockquote {
  margin: 16px 0; padding: 4px 20px;
  border-left: 3px solid var(--border);
  color: var(--ink-soft); font-style: italic;
}
.post-body code {
  background: var(--bg-code); color: var(--accent);
  padding: 1px 6px; border-radius: 3px;
  font-size: 0.88em; border: 1px solid var(--border-soft);
  font-family: var(--font-mono);
}
.post-body pre {
  background: var(--bg-code);
  border-left: 4px solid var(--primary);
  padding: 14px 18px; overflow-x: auto;
  font-family: var(--font-mono); font-size: 14px;
  line-height: 1.55; margin: 16px 0;
  border-radius: 0 4px 4px 0;
}
.post-body pre code { background: transparent; border: none; padding: 0; color: inherit; }
.post-body img { max-width: 100%; height: auto; display: block; margin: 24px auto; }
/* ==================== Tables (蓝表头 + striped) ==================== */
.post-body table {
  width: 100%; border-collapse: collapse; margin: 20px 0;
  font-size: 14.5px;
  font-family: var(--font-serif);
}
.post-body thead th {
  background: var(--primary); color: #fff; text-align: left;
  padding: 10px 14px; font-weight: 600; font-size: 13.5px;
  letter-spacing: 0.02em;
}
.post-body tbody td, .post-body tbody th {
  padding: 9px 14px; border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
.post-body tbody tr:nth-child(even) { background: var(--bg-soft); }
.post-body tbody tr:last-child td { border-bottom: none; }
.post-body tbody th { text-align: left; font-weight: 600; }
.post-body table strong { color: var(--accent); }

/* ==================== MathJax display equation framing ==================== */
.post-body mjx-container[display="true"] {
  margin: 22px auto;
}
.post-body p.eq {
  text-align: center;
  margin: 22px 0;
}

.post-body figure { margin: 28px 0; }
.post-body figure img { margin: 0 auto 10px; border: 1px solid var(--border); border-radius: 3px; }
.post-body figcaption {
  text-align: center;
  font-family: Georgia, "Source Han Serif SC", serif;
  font-size: 14px;
  color: var(--ink-soft, #5b5249);
  font-style: italic;
  line-height: 1.5;
  max-width: 80%;
  margin: 0 auto;
}
.post-body hr {
  border: none; border-top: 1px solid var(--border); margin: 32px 0;
}

/* ==================== Callout (info / warn / good) ==================== */
.post-body .callout {
  margin: 20px 0; padding: 14px 18px;
  border-left: 4px solid; border-radius: 0 4px 4px 0;
  font-size: 15px;
}
.post-body .callout > :first-child { margin-top: 0; }
.post-body .callout > :last-child  { margin-bottom: 0; }
.post-body .callout.info { background: var(--info-bg); border-color: var(--primary); }
.post-body .callout.warn { background: var(--warn-bg); border-color: var(--warn); }
.post-body .callout.good { background: var(--good-bg); border-color: var(--good); }
.post-body .callout-title {
  font-weight: 600; margin-bottom: 4px;
  font-size: 13px; letter-spacing: 0.05em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}
.post-body .callout.info .callout-title { color: var(--primary); }
.post-body .callout.warn .callout-title { color: var(--warn); }
.post-body .callout.good .callout-title { color: var(--good); }

/* ==================== Editorial decorations (optional, class-based) ==================== */
.post-body .pullquote {
  margin: 32px 0 28px;
  padding: 18px 0 20px;
  font-family: var(--font-serif); font-weight: 500;
  font-size: 22px; line-height: 1.4;
  color: var(--ink); font-style: italic;
  letter-spacing: -0.005em;
  border-top: 1px solid var(--accent);
  border-bottom: 1px solid var(--accent);
  text-align: center;
}
.post-body .pullquote::before {
  content: "❝"; display: block;
  color: var(--accent); font-size: 26px; line-height: 1;
  margin-bottom: 8px; font-style: normal;
}
.post-body .num {
  font-family: var(--font-mono); font-size: 0.92em;
  color: var(--accent); font-weight: 500;
  letter-spacing: -0.01em;
}
.post-body .endmark {
  text-align: center; margin: 40px 0 0; line-height: 1;
}
.post-body .endmark::before {
  content: "■"; color: var(--accent); font-size: 14px;
}

/* ==================== Footer ==================== */
.post-footer {
  margin-top: 64px; padding-top: 24px;
  border-top: 1px dashed var(--border);
  font-family: var(--font-mono); font-size: 12px;
  color: var(--ink-muted); text-align: center;
}

/* ==================== Responsive: TOC collapses to top ==================== */
@media (max-width: 900px) {
  .page {
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 32px 20px;
  }
  .toc {
    position: static; max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: 16px;
  }
  .toc ol { display: flex; flex-wrap: wrap; gap: 4px 16px; }
  .toc li.sub { display: none; }
  .hero h1, .post-title { font-size: 32px; }
}
