/* Blog styles for lingxiao-guo.github.io — shares tokens with the homepage. */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --card: #ffffff;
  --ink: #1a1c1f;
  --ink-soft: #4a4e55;
  --ink-faint: #8b9096;
  --line: #e6e8ec;
  --link: #1772d0;
  --link-hover: #f09228;
  --accent: #e01b24;
  --blue: #1772d0;
  --blue-soft: rgba(23, 114, 208, .09);
  --orange: #e8820e;
  --orange-soft: rgba(232, 130, 14, .10);
  --green: #14894e;
  --green-soft: rgba(20, 137, 78, .10);
  --red: #d23a3a;
  --red-soft: rgba(210, 58, 58, .09);
  --violet: #6d4fd1;
  --violet-soft: rgba(109, 79, 209, .10);
  --code-bg: #f4f5f7;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
  --col: 720px;
  --wide: 1040px;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --sans: 'Titillium Web', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114;
    --bg-soft: #15181c;
    --card: #16191d;
    --ink: #e8eaed;
    --ink-soft: #b9bec5;
    --ink-faint: #868c94;
    --line: #262a30;
    --link: #6ab0ff;
    --link-hover: #ffb265;
    --accent: #ff6b6b;
    --blue: #6ab0ff;
    --blue-soft: rgba(106, 176, 255, .12);
    --orange: #ffaa4d;
    --orange-soft: rgba(255, 170, 77, .12);
    --green: #4fd18b;
    --green-soft: rgba(79, 209, 139, .12);
    --red: #ff7a7a;
    --red-soft: rgba(255, 122, 122, .12);
    --violet: #a993ff;
    --violet-soft: rgba(169, 147, 255, .13);
    --code-bg: #171a1f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18.5px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  counter-reset: figure;
}

a { color: var(--link); text-decoration: none; transition: color .15s ease; }
a:hover, a:focus { color: var(--link-hover); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
}
.topbar-inner {
  max-width: var(--wide); margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 18px; font-size: 15.5px; font-weight: 600;
}
.topbar .home { color: var(--ink); font-weight: 700; letter-spacing: .01em; }
.topbar .home:hover { color: var(--link); }
.topbar nav { margin-left: auto; display: flex; gap: 18px; }
.topbar nav a { color: var(--ink-soft); }
.topbar nav a:hover { color: var(--link); }
.progress { position: absolute; left: 0; bottom: -1px; height: 2px; width: 0; background: var(--link); }

/* ---------- hero ---------- */
.hero { max-width: var(--wide); margin: 0 auto; padding: 56px 20px 10px; text-align: center; }
.kicker {
  display: inline-block; font-family: var(--sans); font-size: 13.5px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase; color: var(--link); margin-bottom: 14px;
}
.hero h1 {
  font-family: var(--sans); font-weight: 700; margin: 0 auto 14px; max-width: 900px;
  font-size: clamp(32px, 5vw, 48px); line-height: 1.12; letter-spacing: -.005em;
}
.hero .dek {
  max-width: 720px; margin: 0 auto 22px; color: var(--ink-soft);
  font-size: clamp(18px, 2.2vw, 21px); line-height: 1.55;
}
.byline {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 26px;
  font-family: var(--sans); font-size: 15.5px; color: var(--ink-soft);
}
.byline .who a { font-weight: 600; }
.byline .who sup { color: var(--ink-faint); }
.byline .meta { color: var(--ink-faint); }
.tags { margin-top: 14px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; font-family: var(--sans); }
.tag {
  font-size: 13px; font-weight: 600; padding: 2px 11px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--ink-soft); background: var(--card);
}
.hero-media { max-width: var(--wide); margin: 34px auto 0; padding: 0 20px; }
.hero-media video, .hero-media img {
  width: 100%; display: block; border-radius: var(--radius); box-shadow: var(--shadow); background: #000;
}
.hero-media figcaption { counter-increment: none; }
.hero-media figcaption::before { content: none !important; }

/* ---------- layout with TOC ---------- */
.layout {
  max-width: calc(var(--col) + 2 * 250px); margin: 0 auto; padding: 0 20px;
  display: grid; grid-template-columns: 1fr minmax(0, var(--col)) 1fr; column-gap: 40px;
}
.toc {
  grid-column: 1; justify-self: end; width: 210px;
  position: sticky; top: 74px; align-self: start; margin-top: 52px;
  font-family: var(--sans); font-size: 14px; line-height: 1.45;
  max-height: calc(100vh - 100px); overflow: auto;
}
.toc .toc-title {
  font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 10px;
}
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc li a {
  display: block; padding: 5px 0 5px 14px; margin-left: -1px; color: var(--ink-faint);
  border-left: 2px solid transparent; font-weight: 600;
}
.toc li a:hover { color: var(--ink); }
.toc li a.active { color: var(--link); border-left-color: var(--link); }
.toc li.sub a { padding-left: 26px; font-weight: 400; font-size: 13.5px; }

article.post { grid-column: 2; min-width: 0; padding-bottom: 40px; }

@media (max-width: 1180px) {
  .layout { display: block; max-width: calc(var(--col) + 40px); }
  .toc { display: none; }
}

/* ---------- prose ---------- */
.post > p, .post li { hyphens: auto; }
.post p { margin: 0 0 1.15em; }
.post h2 {
  font-family: var(--sans); font-weight: 700; font-size: 29px; line-height: 1.25;
  margin: 2.3em 0 .6em; letter-spacing: -.005em; scroll-margin-top: 72px;
}
.post h2 .num { color: var(--ink-faint); font-weight: 600; margin-right: .45em; }
.post h3 {
  font-family: var(--sans); font-weight: 700; font-size: 21px; line-height: 1.3;
  margin: 1.8em 0 .5em; scroll-margin-top: 72px;
}
.post h4 { font-family: var(--sans); font-size: 17px; margin: 1.4em 0 .4em; }
.post ul, .post ol { padding-left: 1.3em; margin: 0 0 1.2em; }
.post li { margin: .3em 0; }
.post strong { font-weight: 650; }
.post hr { border: 0; height: 1px; background: var(--line); margin: 2.6em 0; }
.post blockquote {
  margin: 1.5em 0; padding: .2em 0 .2em 1.1em; border-left: 3px solid var(--link);
  color: var(--ink-soft); font-style: italic;
}
.lede { font-size: 21px; line-height: 1.6; color: var(--ink); }
.lede::first-letter {
  float: left; font-family: var(--sans); font-weight: 700; font-size: 3.4em; line-height: .9;
  padding: 6px 10px 0 0; color: var(--link);
}

code, kbd { font-family: var(--mono); font-size: .84em; }
:not(pre) > code {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 5px; padding: .08em .35em;
}
pre {
  font-family: var(--mono); font-size: 13.5px; line-height: 1.6;
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; overflow-x: auto; margin: 1.4em 0;
}
pre code { font-size: inherit; background: none; border: 0; padding: 0; }
.code-label {
  font-family: var(--sans); font-size: 13px; font-weight: 600; color: var(--ink-faint);
  margin: 1.4em 0 -1em; display: flex; justify-content: space-between;
}
.code-label + pre { margin-top: 1.4em; }

/* simple syntax colors (hand-tagged spans) */
.c-k { color: var(--violet); font-weight: 600; }
.c-s { color: var(--green); }
.c-c { color: var(--ink-faint); font-style: italic; }
.c-n { color: var(--orange); }
.c-f { color: var(--blue); }

/* ---------- figures ---------- */
figure { margin: 2em 0; }
figure.wide { margin-left: calc((var(--col) - min(var(--wide), 100vw - 40px)) / 2); margin-right: calc((var(--col) - min(var(--wide), 100vw - 40px)) / 2); }
@media (max-width: 1180px) { figure.wide { margin-left: 0; margin-right: 0; } }
figure video, figure img, figure .frame {
  width: 100%; display: block; border-radius: 12px; background: var(--bg-soft);
  border: 1px solid var(--line);
}
figure video { background: #000; }
figcaption {
  font-family: var(--sans); font-size: 14.5px; line-height: 1.55; color: var(--ink-soft);
  margin-top: 10px; padding: 0 2px;
}
figure.numbered figcaption::before {
  counter-increment: figure; content: "Figure " counter(figure) ". ";
  font-weight: 700; color: var(--ink);
}
.grid-2, .grid-3, .grid-4 { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 640px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 460px) { .grid-2 { grid-template-columns: 1fr; } }
.panel { position: relative; }
.panel .label {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  font-family: var(--sans); font-size: 12.5px; font-weight: 700; letter-spacing: .02em;
  padding: 2px 9px; border-radius: 999px; color: #fff; background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(4px);
}
.panel .label.bad { background: rgba(196, 40, 40, .85); }
.panel .label.good { background: rgba(16, 128, 72, .88); }
.panel .sub { font-family: var(--sans); font-size: 13px; color: var(--ink-faint); margin-top: 6px; text-align: center; }

/* diagrams */
figure.diagram .frame { padding: 18px 16px; }
figure.diagram svg { width: 100%; height: auto; display: block; }
svg text { font-family: var(--sans); }
svg .t-ink { fill: var(--ink); }
svg .t-soft { fill: var(--ink-soft); }
svg .t-faint { fill: var(--ink-faint); }
svg .t-blue { fill: var(--blue); }
svg .t-orange { fill: var(--orange); }
svg .t-green { fill: var(--green); }
svg .t-red { fill: var(--red); }
svg .t-violet { fill: var(--violet); }
svg .box { fill: var(--card); stroke: var(--line); stroke-width: 1.5; }
svg .box-blue { fill: var(--blue-soft); stroke: var(--blue); stroke-width: 1.5; }
svg .box-orange { fill: var(--orange-soft); stroke: var(--orange); stroke-width: 1.5; }
svg .box-green { fill: var(--green-soft); stroke: var(--green); stroke-width: 1.5; }
svg .box-red { fill: var(--red-soft); stroke: var(--red); stroke-width: 1.5; }
svg .box-violet { fill: var(--violet-soft); stroke: var(--violet); stroke-width: 1.5; }
svg .edge { stroke: var(--ink-faint); stroke-width: 1.6; fill: none; }
svg .edge-blue { stroke: var(--blue); stroke-width: 1.8; fill: none; }
svg .edge-orange { stroke: var(--orange); stroke-width: 1.8; fill: none; }
svg .edge-green { stroke: var(--green); stroke-width: 1.8; fill: none; }
svg .edge-red { stroke: var(--red); stroke-width: 1.8; fill: none; }
svg .edge-violet { stroke: var(--violet); stroke-width: 1.8; fill: none; }
svg .dash { stroke-dasharray: 5 4; }
svg .grid { stroke: var(--line); stroke-width: 1; }
svg .f-blue { fill: var(--blue); } svg .f-orange { fill: var(--orange); }
svg .f-green { fill: var(--green); } svg .f-red { fill: var(--red); }
svg .f-violet { fill: var(--violet); } svg .f-faint { fill: var(--ink-faint); }
svg .f-line { fill: var(--line); } svg .f-card { fill: var(--card); } svg .f-soft { fill: var(--bg-soft); }
svg .s-card { stroke: var(--card); }

/* ---------- callouts ---------- */
.callout {
  margin: 1.8em 0; padding: 16px 20px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-soft);
  font-family: var(--sans); font-size: 16.5px; line-height: 1.6;
}
.callout p:last-child, .callout ul:last-child { margin-bottom: 0; }
.callout .ct {
  display: block; font-size: 12.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  margin-bottom: 6px;
}
.callout.tldr { background: var(--blue-soft); border-color: transparent; }
.callout.tldr .ct { color: var(--blue); }
.callout.caveat { background: var(--orange-soft); border-color: transparent; }
.callout.caveat .ct { color: var(--orange); }
.callout.fail { background: var(--red-soft); border-color: transparent; }
.callout.fail .ct { color: var(--red); }
.callout.note .ct { color: var(--ink-faint); }
.callout ul { padding-left: 1.2em; }

.prompt {
  margin: 1.6em 0; border-radius: 12px; overflow: hidden; border: 1px solid var(--line);
  background: var(--card); box-shadow: var(--shadow);
}
.prompt .bar {
  display: flex; align-items: center; gap: 7px; padding: 8px 14px;
  border-bottom: 1px solid var(--line); background: var(--bg-soft);
  font-family: var(--sans); font-size: 13px; font-weight: 600; color: var(--ink-faint);
}
.prompt .bar i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); display: inline-block; }
.prompt .bar span { margin-left: 6px; }
.prompt .body { padding: 14px 18px; font-family: var(--mono); font-size: 14px; line-height: 1.65; white-space: pre-wrap; color: var(--ink); }
.prompt .body .who { color: var(--blue); font-weight: 700; }

/* ---------- stats ---------- */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 1.8em 0;
  font-family: var(--sans);
}
.stat {
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: var(--card);
}
.stat .v { font-size: 24px; font-weight: 700; line-height: 1.15; letter-spacing: -.01em; white-space: nowrap; }
.stat .v .arr { color: var(--ink-faint); font-weight: 400; padding: 0 .12em; }
.stat .v .to { color: var(--green); }
.stat .k { font-size: 14px; color: var(--ink-soft); line-height: 1.4; margin-top: 4px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 1.6em 0; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: 15px; line-height: 1.45; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 700; background: var(--bg-soft); color: var(--ink); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .up { color: var(--green); font-weight: 700; }
td .down { color: var(--red); font-weight: 700; }
.table-note { font-family: var(--sans); font-size: 13.5px; color: var(--ink-faint); margin: -1em 0 1.6em; }

/* ---------- steps ---------- */
.steps { counter-reset: step; list-style: none; padding: 0 !important; margin: 1.6em 0; }
.steps > li {
  position: relative; padding: 0 0 14px 46px; margin: 0;
}
.steps > li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: 2px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-family: var(--sans); font-weight: 700; font-size: 15px;
  color: var(--link); background: var(--blue-soft);
}
.steps > li::after {
  content: ""; position: absolute; left: 14.5px; top: 36px; bottom: 4px; width: 1px; background: var(--line);
}
.steps > li:last-child::after { display: none; }
.steps > li > b:first-child { font-family: var(--sans); }

/* ---------- refs, footer ---------- */
.refs { font-family: var(--sans); font-size: 15px; line-height: 1.55; padding-left: 1.6em !important; }
.refs li { margin: .5em 0; color: var(--ink-soft); }
.cite { font-family: var(--sans); font-size: .78em; vertical-align: super; line-height: 0; }
.bibtex { font-size: 12.5px; }
.post-foot {
  margin-top: 3em; padding-top: 18px; border-top: 1px solid var(--line);
  font-family: var(--sans); font-size: 14.5px; color: var(--ink-faint);
  display: flex; flex-wrap: wrap; gap: 10px 22px; justify-content: space-between;
}
.ack { font-family: var(--sans); font-size: 15.5px; color: var(--ink-soft); }

/* ---------- blog index ---------- */
.index-wrap { max-width: 940px; margin: 0 auto; padding: 0 20px 72px; font-family: var(--sans); }
.index-wrap h1 { font-size: 40px; margin: 54px 0 4px; }
.index-wrap .sub { color: var(--ink-faint); margin: 0 0 26px; font-size: 16px; }
.post-card {
  display: grid; grid-template-columns: 38% 1fr; gap: 26px; align-items: start;
  padding: 22px; margin: 0 -22px; border-radius: var(--radius); color: inherit;
  transition: background .2s ease, box-shadow .2s ease, transform .2s ease;
}
.post-card:hover { background: var(--bg-soft); box-shadow: var(--shadow); transform: translateY(-2px); color: inherit; }
.post-card video, .post-card img { width: 100%; display: block; border-radius: 13px; background: #000; }
.post-card .t { font-size: 20px; font-weight: 700; line-height: 1.3; color: var(--link); }
.post-card .a { color: var(--ink-soft); font-size: 15.5px; margin-top: 4px; }
.post-card .d { color: var(--ink-soft); font-size: 16px; margin-top: 8px; line-height: 1.55; }
.post-card .m { color: var(--ink-faint); font-size: 14px; margin-top: 8px; }
@media (max-width: 760px) {
  body { font-size: 17.5px; }
  .post-card { grid-template-columns: 1fr; gap: 14px; padding: 16px; margin: 0 -16px; }
  .hero { padding-top: 36px; }
  .post h2 { font-size: 25px; }
  .lede { font-size: 19.5px; }
}

/* katex tweaks */
.katex { font-size: 1.04em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

.copy-btn {
  position: absolute; top: 8px; right: 8px; font-family: var(--sans); font-size: 12px; font-weight: 600;
  padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink-soft); cursor: pointer;
}
.copy-btn:hover { color: var(--link); border-color: var(--link); }

/* ---------- charts (palette validated for CVD + contrast in both modes) ---------- */
:root { --c-before: #c4610c; --c-after: #1772d0; }
@media (prefers-color-scheme: dark) { :root { --c-before: #c9742a; --c-after: #3f8ee6; } }
svg .c-before { fill: var(--c-before); } svg .c-after { fill: var(--c-after); }
svg .s-before { stroke: var(--c-before); } svg .s-after { stroke: var(--c-after); }
svg .axis { stroke: var(--ink-faint); stroke-width: 1; }
svg .hit { fill: transparent; }
svg .hit:hover + .dot-ring, svg g.row:hover .rowbg { fill: var(--bg-soft); }
svg .rowbg { fill: transparent; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-family: var(--sans); font-size: 13.5px; color: var(--ink-soft); margin: 0 0 8px; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend i.before { background: var(--c-before); } .legend i.after { background: var(--c-after); }
.legend i.hollow { background: transparent; border: 2px solid var(--c-after); }
details.data { font-family: var(--sans); font-size: 14px; margin-top: 8px; }
details.data summary { cursor: pointer; color: var(--ink-faint); font-weight: 600; }
details.data .table-wrap { margin: 8px 0 0; }
