/* =============================================================
   Blog stylesheet — independent of the academic homepage.
   Aesthetic: mostly flat & editorial, with a light touch of
   Frutiger Aero (fresh sky-blue → mint, soft gloss, glass header).
   Readable long-form prose inspired by Tailwind Typography:
   generous line-height, comfortable measure, calm palette.
   Bilingual (CN serif + EN serif). No custom cursor.
   ============================================================= */

/* ---------- Fonts ---------- */
@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=Mulish:wght@400;500;600;700;800&family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@400;500;700&display=swap');

/* ---------- Design tokens ---------- */
:root {
  --blog-sky:   #e7f3ff;   /* pale aero sky   */
  --blog-mint:  #eefaf3;   /* pale aero mint  */
  --blog-paper: #fbfdff;   /* card / surface  */

  --ink:        #1e2a3a;   /* primary text    */
  --ink-soft:   #51607a;   /* secondary text  */
  --ink-faint:  #8493a8;   /* meta / captions */

  --accent:     #1769e0;   /* aero blue link  */
  --accent-deep:#0f4fb0;
  --accent-teal:#16b39a;   /* aero teal/green */

  --line:       rgba(20, 55, 110, 0.10);
  --line-soft:  rgba(20, 55, 110, 0.06);

  --shadow-sm:  0 1px 2px rgba(22, 60, 120, 0.05);
  --shadow:     0 10px 34px -12px rgba(22, 70, 140, 0.18);
  --shadow-lg:  0 22px 54px -20px rgba(22, 70, 140, 0.28);

  --radius:     18px;
  --radius-sm:  12px;

  --measure:    44rem;     /* reading column  */
  /* Readable, universally-rendered sans for BOTH CN & EN (DengXian / 等线-like).
     Latin uses the platform UI sans (SF / Segoe UI), CJK falls to Noto Sans SC
     (web), then PingFang SC / Microsoft YaHei. Renders well in every browser. */
  --font-read:  -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Source Sans 3', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', 'Hiragino Sans GB', sans-serif;
  --sans:       'Mulish', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:       ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Noto Sans SC', monospace;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body.blog {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-read);
  font-size: 1.075rem;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
  background: var(--blog-paper);
  min-height: 100vh;
  /* optimizeLegibility forces kerning/ligatures and is a known scroll-jank
     source on long CJK bodies; default rendering is smooth and looks the same. */
  text-rendering: optimizeSpeed;
}

/* Backdrop on its own composited layer instead of background-attachment:fixed
   (which forces a full repaint on every scroll frame and causes jank). */
body.blog::after {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1200px 520px at 78% -8%, rgba(86, 196, 255, 0.16), transparent 60%),
    radial-gradient(1000px 480px at -6% 8%, rgba(58, 220, 170, 0.12), transparent 55%),
    linear-gradient(180deg, var(--blog-sky) 0%, var(--blog-mint) 42%, #ffffff 100%);
}

/* one readable sans for both languages; CJK resolves via the font stack */
html[lang^="zh"] body.blog { font-family: var(--font-read); }

a { color: var(--accent); text-decoration: none; transition: color .18s ease; }
a:hover { color: var(--accent-deep); }

/* ---------- Header (glass, light aero) ---------- */
.blog-header {
  position: sticky; top: 0; z-index: 50;
  /* a lighter blur recomposites far cheaper on every scroll frame while
     keeping the frosted-glass aero look */
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  background: linear-gradient(180deg, rgba(255,255,255,0.82), rgba(255,255,255,0.62));
  border-bottom: 1px solid var(--line);
}
.blog-header .wrap {
  max-width: 72rem; margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.blog-brand {
  font-family: var(--sans); font-weight: 800; letter-spacing: -0.01em;
  font-size: 1.05rem; color: var(--ink);
  display: inline-flex; align-items: center; gap: .55rem;
}
.blog-brand .dot {
  width: .62rem; height: .62rem; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-teal), var(--accent));
  box-shadow: 0 0 0 3px rgba(23,105,224,0.12);
}
.blog-brand:hover { color: var(--accent-deep); }
.blog-nav { display: flex; align-items: center; gap: 1.1rem; font-family: var(--sans); font-size: .92rem; }
.blog-nav a { color: var(--ink-soft); font-weight: 600; }
.blog-nav a:hover { color: var(--accent); }

/* glossy pill buttons (the one place gloss is allowed to show) */
.aero-btn {
  font-family: var(--sans); font-weight: 700; font-size: .85rem;
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .42rem .85rem; border-radius: 999px; cursor: pointer;
  color: var(--accent-deep);
  border: 1px solid rgba(23,105,224,0.22);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.9), rgba(233,244,255,0.7));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9), var(--shadow-sm);
  transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease;
}
.aero-btn:hover { transform: translateY(-1px); border-color: rgba(23,105,224,0.4); box-shadow: inset 0 1px 0 rgba(255,255,255,0.9), var(--shadow); }
.aero-btn[aria-pressed="true"] {
  color: #fff;
  background: linear-gradient(180deg, #3a93ff, var(--accent));
  border-color: var(--accent-deep);
}

/* ---------- Layout containers ---------- */
.blog-main { max-width: 72rem; margin: 0 auto; padding: 2.6rem 1.5rem 5rem; }
.reading   { max-width: var(--measure); margin: 0 auto; }

/* ---------- Listing: hero ---------- */
.list-hero { text-align: center; margin: 1.5rem auto 2.8rem; max-width: 40rem; }
.list-hero h1 {
  font-family: var(--sans); font-weight: 800; letter-spacing: -0.02em;
  font-size: clamp(2.1rem, 5vw, 3rem); line-height: 1.1; margin: 0 0 .7rem;
  color: var(--ink);
}
.list-hero h1 .accent { background: linear-gradient(120deg, var(--accent), var(--accent-teal)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.list-hero p { color: var(--ink-soft); font-size: 1.08rem; margin: 0; }

/* ---------- Listing: post cards ---------- */
.post-list { display: flex; flex-direction: column; gap: 1.1rem; }
.post-card {
  position: relative;
  display: block;
  padding: 1.5rem 1.6rem;
  border-radius: var(--radius);
  background: var(--blog-paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .25s ease, border-color .25s ease;
  overflow: hidden;
}
/* faint top sheen — the light aero gloss, kept subtle */
.post-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 38%;
  background: linear-gradient(180deg, rgba(255,255,255,0.55), rgba(255,255,255,0));
  pointer-events: none;
}
.post-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: rgba(23,105,224,0.28); }
.post-card .meta {
  font-family: var(--sans); font-size: .8rem; font-weight: 600;
  color: var(--ink-faint); letter-spacing: .02em;
  display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem;
}
.post-card h2 {
  font-family: var(--sans); font-weight: 800; letter-spacing: -0.01em;
  font-size: 1.42rem; line-height: 1.25; margin: 0 0 .5rem; color: var(--ink);
}
html[lang^="zh"] .post-card h2 { font-family: var(--sans); }
.post-card .excerpt { color: var(--ink-soft); font-size: 1.0rem; line-height: 1.7; margin: 0 0 .85rem; }
.post-card:hover h2 { color: var(--accent-deep); }

/* tags */
.tags { display: flex; flex-wrap: wrap; gap: .4rem; }
.tag {
  font-family: var(--sans); font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  padding: .2rem .6rem; border-radius: 999px;
  color: var(--accent-deep); background: rgba(23,105,224,0.08);
  border: 1px solid rgba(23,105,224,0.14);
}

/* ---------- Pagination ---------- */
.pagination {
  margin-top: 2.6rem; display: flex; justify-content: center; align-items: center; gap: .4rem;
  font-family: var(--sans);
}
.pagination button, .pagination .pg {
  min-width: 2.4rem; height: 2.4rem; padding: 0 .7rem;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px; cursor: pointer; font-weight: 700; font-size: .9rem;
  color: var(--ink-soft); background: rgba(255,255,255,0.7);
  border: 1px solid var(--line); transition: all .18s ease;
}
.pagination button:hover:not(:disabled) { color: var(--accent); border-color: rgba(23,105,224,0.3); transform: translateY(-1px); }
.pagination button:disabled { opacity: .4; cursor: default; }
.pagination .pg.active {
  color: #fff; border-color: var(--accent-deep);
  background: linear-gradient(180deg, #3a93ff, var(--accent));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4);
}

/* ---------- Single post ---------- */
.post-head { text-align: center; margin: 0.5rem auto 2.4rem; max-width: var(--measure); }
.post-head .kicker { font-family: var(--sans); font-weight: 700; font-size: .82rem; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.post-head h1 {
  font-family: var(--sans); font-weight: 800; letter-spacing: -0.02em;
  font-size: clamp(1.9rem, 4.4vw, 2.7rem); line-height: 1.18; margin: .6rem 0 .9rem; color: var(--ink);
}
html[lang^="zh"] .post-head h1 { font-family: var(--sans); letter-spacing: 0; }
.post-head .byline { font-family: var(--sans); font-size: .9rem; color: var(--ink-faint); display: flex; gap: .6rem; justify-content: center; align-items: center; flex-wrap: wrap; }
.post-head .rule { width: 3rem; height: 3px; margin: 1.4rem auto 0; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--accent-teal)); }

/* ---------- Prose (the readable core) ---------- */
.prose { color: var(--ink); font-family: var(--font-read); font-size: 1.09rem; line-height: 1.78; font-weight: 400; }
html[lang^="zh"] .prose { line-height: 1.92; letter-spacing: .005em; }
/* a clear blank-line gap between paragraphs (段间距 ≈ one empty line),
   distinctly larger than the line spacing inside a paragraph */
.prose > * + * { margin-top: 1.6em; }
.prose p + p { margin-top: 1.75em; }
.prose p { margin: 0; }
/* Subheadings: left-aligned, bold, modest. Not big banner headers. */
.prose h2 {
  font-family: var(--font-read); font-weight: 700; letter-spacing: 0;
  font-size: 1.22rem; line-height: 1.4; margin: 2.3em 0 0; color: var(--ink);
}
.prose h3 { font-family: var(--font-read); font-weight: 700; font-size: 1.08rem; line-height: 1.4; margin-top: 2em; color: var(--ink); }
.prose h4 { font-family: var(--font-read); font-weight: 700; font-size: 1.0rem; margin-top: 1.7em; color: var(--ink-soft); }
.prose h2:first-child, .prose h3:first-child, .prose h4:first-child { margin-top: 0; }

.prose a { color: var(--accent); text-decoration: underline; text-decoration-color: rgba(23,105,224,0.32); text-underline-offset: 3px; }
.prose a:hover { color: var(--accent-deep); text-decoration-color: var(--accent-deep); }
.prose strong { font-weight: 700; color: var(--ink); }
.prose em { font-style: italic; }

.prose blockquote {
  margin: 1.6em 0; padding: .2em 0 .2em 1.3em;
  border-left: 3px solid; border-image: linear-gradient(180deg, var(--accent), var(--accent-teal)) 1;
  color: var(--ink-soft); font-style: italic;
}
.prose blockquote p { margin-top: .6em; }
.prose blockquote p:first-child { margin-top: 0; }

.prose ul, .prose ol { margin: 1.2em 0; padding-left: 1.5em; }
.prose li { margin: .5em 0; padding-left: .2em; }
.prose li::marker { color: var(--accent); }

.prose img {
  display: block; max-width: 100%; height: auto; margin: 1.6em auto;
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
/* Default images are inset, not full text-width (many are screenshots/portraits).
   Wide diagrams can opt out with alt text containing [wide]. Per-image tuning later. */
.prose img, .prose .img-prog { max-width: min(100%, 33rem); }
.prose img[alt*="[wide]"], .prose .img-prog:has(img[alt*="[wide]"]) { max-width: 100%; }

/* ---- Progressive (blur-up) image loading ---- */
.img-prog {
  display: block; position: relative; margin: 1.8em auto; max-width: 100%;
  border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line);
  box-shadow: var(--shadow); background: var(--line-soft);
  background-size: cover; background-position: center;
}
.img-prog.has-lqip { background-image: var(--lqip); }
.img-prog.has-lqip::before {
  /* soften the upscaled tiny placeholder */
  content: ""; position: absolute; inset: -2px;
  background: inherit; background-size: cover; background-position: center;
  filter: blur(14px); transform: scale(1.06); z-index: 0;
}
.img-prog img {
  position: relative; z-index: 1;
  display: block; width: 100%; height: auto; margin: 0 !important;
  border: 0; border-radius: inherit; box-shadow: none;
  opacity: 0; transition: opacity .55s ease;
}
.img-prog.is-loaded img { opacity: 1; }
.img-prog.is-loaded.has-lqip::before { opacity: 0; transition: opacity .4s ease .2s; }
@media (prefers-reduced-motion: reduce) { .img-prog img { transition: none; } }
.prose figure { margin: 1.8em 0; }
.prose figcaption { text-align: center; font-family: var(--sans); font-size: .85rem; color: var(--ink-faint); margin-top: .6em; }

.prose hr { border: none; height: 1px; background: var(--line); margin: 2.6em 0; }

.prose code {
  font-family: var(--mono);
  font-size: .88em; padding: .12em .4em; border-radius: 6px;
  background: rgba(20,55,110,0.06); color: var(--accent-deep);
}
/* Code blocks hold verbose / skim-only material (e.g. raw model outputs).
   Deliberately quiet and small: soft box, muted text, no heavy contrast,
   signalling "you don't have to read this closely." */
.prose pre {
  margin: 1.4em 0; padding: .85em 1.05em; border-radius: 12px;
  background: rgba(20,55,110,0.045); color: var(--ink-soft);
  border: 1px solid var(--line-soft); border-left: 3px solid rgba(23,105,224,0.28);
  overflow-x: auto; line-height: 1.6; font-size: .8rem;
  font-family: var(--mono); white-space: pre-wrap; word-break: break-word;
}
.prose pre code { background: none; color: inherit; padding: 0; font-size: inherit; font-family: var(--mono); }
html[lang^="zh"] .prose pre { line-height: 1.75; }

/* Figure captions: the *italic* line sits on the line right after the image,
   so marked keeps it in the SAME paragraph as the image. Style that <em>
   as a centered, small, muted caption block. (Works with or without the
   progressive-image wrapper.) */
.prose p:has(> .img-prog) > em,
.prose p:has(> img) > em {
  display: block; text-align: center; font-family: var(--sans);
  font-size: .8rem; color: var(--ink-faint); font-style: normal;
  margin-top: .6em; line-height: 1.5;
}
/* center the image itself within that paragraph */
.prose p:has(> .img-prog), .prose p:has(> img) { text-align: center; }

.prose table { width: 100%; border-collapse: collapse; margin: 1.6em 0; font-size: .98rem; }
.prose th, .prose td { border: 1px solid var(--line); padding: .6em .8em; text-align: left; }
.prose th { background: rgba(23,105,224,0.06); font-family: var(--sans); font-weight: 700; }

/* MathJax shouldn't overflow */
.prose mjx-container { overflow-x: auto; overflow-y: hidden; max-width: 100%; }

/* ---------- Post footer / back link ---------- */
.post-foot { max-width: var(--measure); margin: 3.5rem auto 0; padding-top: 1.8rem; border-top: 1px solid var(--line); }
.post-foot .row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; font-family: var(--sans); }
.back-link { font-family: var(--sans); font-weight: 700; color: var(--ink-soft); display: inline-flex; align-items: center; gap: .4rem; }
.back-link:hover { color: var(--accent); }

/* ---------- Footer ---------- */
.blog-footer {
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(231,243,255,0.5));
  text-align: center; padding: 2.4rem 1.5rem; color: var(--ink-faint);
  font-family: var(--sans); font-size: .85rem;
}
.blog-footer a { color: var(--ink-soft); font-weight: 600; }
.blog-footer a:hover { color: var(--accent); }

/* ---------- States ---------- */
.loading, .empty { text-align: center; color: var(--ink-faint); font-family: var(--sans); padding: 4rem 1rem; }
.spinner {
  width: 28px; height: 28px; margin: 0 auto 1rem; border-radius: 50%;
  border: 3px solid rgba(23,105,224,0.2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* staggered entrance */
.fade-up { opacity: 0; transform: translateY(10px); animation: fadeUp .55s ease forwards; }
@keyframes fadeUp { to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .fade-up { opacity: 1; transform: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .blog-main { padding: 1.8rem 1.1rem 3.5rem; }
  body.blog { font-size: 1.02rem; }
  .prose { font-size: 1.06rem; }
  .post-card { padding: 1.25rem 1.25rem; }
  .blog-nav { gap: .7rem; }
}
