/* =============================================================
   Blog stylesheet — independent of the academic homepage.

   Concept: a PC-98 desktop. The page background is a dark dusk
   "desktop"; all content lives inside one cream "window" with a
   pixel title bar and a status bar. The window sits LEFT of
   center (desktop-first, low side gutters). Inside the window a
   left rail holds title / search / tags / nav, and the main pane
   is a timeline archive (year heads, square dots, clamped
   summaries) in the DansBlog spirit.

   The retro layer stays on the chrome — pixel font for UI labels
   and dates, hard offset shadows, dither strips, scanlines. Body
   text is calm, left-aligned, readable.
   ============================================================= */

/* ---------- Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=DotGothic16&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;0,6..72,700;1,6..72,400&family=Mulish:wght@400;500;600;700;800&family=Noto+Serif+SC:wght@400;500;600;700;900&family=Noto+Sans+SC:wght@400;500;700&display=swap');

/* ---------- Design tokens ---------- */
:root {
  /* the desktop */
  --desk:        #1b1936;
  --desk-deep:   #131126;

  /* the window */
  --paper:       #faf6ec;
  --paper-dim:   #f1ecdd;
  --ink:         #2a2745;
  --ink-soft:    #57536f;
  --ink-faint:   #8d89a4;

  /* title/status bars */
  --bar:         #2e2b58;
  --bar-hi:      #413d7a;

  /* the vaporwave pair */
  --cyan:        #0e8a99;
  --cyan-bright: #3fd3e2;
  --magenta:     #c02b8a;
  --magenta-soft:#e35db2;
  --mint:        #3ecf8e;

  --line:        rgba(42, 39, 69, 0.18);
  --line-soft:   rgba(42, 39, 69, 0.09);

  --measure:     44rem;

  --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;
  --serif:      'Newsreader', 'Noto Serif SC', Georgia, 'Songti SC', serif;
  /* pixel font: UI labels, dates, digits. DotGothic16 covers Latin, kana and
     common kanji (年月日 etc.); anything missing falls back to the sans. */
  --pixel:      'DotGothic16', 'Mulish', 'Noto Sans SC', monospace;
  --mono:       ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

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

html { scroll-behavior: smooth; }

body.blog {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-read);
  font-size: 1.05rem;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  text-rendering: optimizeSpeed;
  background:
    /* faint dusk glow, top-left, like a monitor warming up */
    radial-gradient(60rem 40rem at -8% -12%, rgba(192, 43, 138, 0.13), transparent 60%),
    radial-gradient(50rem 34rem at 108% 112%, rgba(14, 138, 153, 0.14), transparent 55%),
    var(--desk);
}
/* desktop dither grain */
body.blog::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: conic-gradient(rgba(255,255,255,0.05) 25%, transparent 0 50%, rgba(255,255,255,0.05) 0 75%, transparent 0);
  background-size: 4px 4px;
  opacity: .35;
}

a { color: var(--cyan); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--magenta); }
::selection { background: rgba(192, 43, 138, 0.22); }

/* ---------- The window ---------- */
.desk {
  position: relative; z-index: 1;
  padding: clamp(1rem, 3vh, 2.5rem) clamp(0.9rem, 2.5vw, 2.5rem);
}
.window {
  max-width: 71rem;
  margin: 0;                    /* left-leaning: no auto centering */
  background: var(--paper);
  border: 2px solid var(--desk-deep);
  box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.45);
  display: flex; flex-direction: column;
  min-height: calc(100vh - 5rem);
}
/* post pages have no rail: the window hugs the reading column */
body.blog:not(.blog-list) .window { max-width: 55rem; }

/* ---------- Title bar ---------- */
.titlebar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .5rem .9rem;
  background: linear-gradient(180deg, var(--bar-hi), var(--bar));
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, var(--bar-hi), var(--bar));
  border-bottom: 2px solid var(--desk-deep);
  font-family: var(--pixel); font-size: .9rem;
}
.tb-brand {
  color: #f4f1ff; letter-spacing: .05em;
  display: inline-flex; align-items: center; gap: .6rem;
}
.tb-brand:hover { color: var(--cyan-bright); }
/* window buttons — magenta / cyan / mint squares */
.tb-brand .dot, .tb-brand .dot::before, .tb-brand .dot::after {
  width: .52rem; height: .52rem; display: inline-block;
}
.tb-brand .dot { position: relative; background: var(--magenta-soft); margin-right: 1.35rem; }
.tb-brand .dot::before { content: ""; position: absolute; left: .78rem; background: var(--cyan-bright); }
.tb-brand .dot::after  { content: ""; position: absolute; left: 1.56rem; background: var(--mint); }
.tb-nav { display: flex; align-items: center; gap: 1rem; }
.tb-nav a { color: rgba(244,241,255,0.78); }
.tb-nav a:hover { color: var(--cyan-bright); }

.px-btn {
  font-family: var(--pixel); font-size: .82rem; line-height: 1;
  padding: .38rem .65rem .34rem; cursor: pointer; border-radius: 0;
  color: #f4f1ff; background: transparent;
  border: 1px solid rgba(244,241,255,0.55);
  box-shadow: 2px 2px 0 rgba(0,0,0,0.35);
  transition: background .15s ease, transform .1s ease, box-shadow .1s ease;
}
.px-btn:hover { background: var(--magenta); border-color: var(--magenta-soft); }
.px-btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 rgba(0,0,0,0.35); }

/* ---------- Window body: rail + main ---------- */
.win-body { display: flex; align-items: stretch; flex: 1; }

.rail {
  width: 17.5rem; flex: 0 0 17.5rem;
  padding: 1.9rem 1.5rem 2.2rem;
  border-right: 1px solid var(--line);
}
.rail-sticky { position: sticky; top: 1.2rem; }

.rail h1 {
  font-family: var(--serif); font-weight: 700; letter-spacing: .01em;
  font-size: 2.1rem; line-height: 1.15; margin: 0 0 .5rem; color: var(--ink);
}
html[lang^="zh"] .rail h1 { font-weight: 900; }
.rail .kicker {
  font-family: var(--pixel); font-size: .78rem; letter-spacing: .08em;
  color: var(--magenta); margin: 0 0 .55rem; display: block;
}
.rail .kicker .cursor {
  display: inline-block; width: .55em; height: 1em; margin-left: .12em;
  background: var(--magenta); vertical-align: text-bottom;
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.rail .sub { color: var(--ink-soft); font-size: .92rem; line-height: 1.7; margin: 0 0 1.4rem; }

.rail-block { margin-top: 1.5rem; }
.rail-label {
  font-family: var(--pixel); font-size: .72rem; letter-spacing: .14em;
  color: var(--ink-faint); margin: 0 0 .6rem; display: flex; align-items: center; gap: .6rem;
}
.rail-label::after {
  content: ""; flex: 1; height: 5px;
  background-image: conic-gradient(var(--ink) 25%, transparent 0 50%, var(--ink) 0 75%, transparent 0);
  background-size: 5px 5px; opacity: .16;
}

/* search */
.searchwrap { position: relative; display: flex; align-items: center; }
.searchwrap .s-ico {
  position: absolute; left: .7rem; width: .95rem; height: .95rem;
  color: var(--ink-faint); pointer-events: none;
}
#post-search {
  width: 100%; font-family: var(--sans); font-size: .9rem; font-weight: 500;
  color: var(--ink); padding: .52rem 2.2rem .52rem 2.2rem;
  border-radius: 0; outline: none;
  border: 2px solid var(--ink);
  background: #fffdf7;
  box-shadow: 3px 3px 0 rgba(42, 39, 69, 0.22);
  transition: border-color .15s ease, box-shadow .15s ease;
  -webkit-appearance: none; appearance: none;
}
#post-search::placeholder { color: var(--ink-faint); }
#post-search:focus { border-color: var(--magenta); box-shadow: 3px 3px 0 rgba(192,43,138,0.35); }
#post-search::-webkit-search-cancel-button { display: none; }
.s-clear {
  position: absolute; right: .45rem; width: 1.5rem; height: 1.5rem;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 0; cursor: pointer;
  font-family: var(--pixel); font-size: .9rem; line-height: 1;
  color: var(--paper); background: var(--ink);
}
.s-clear:hover { background: var(--magenta); }
.s-clear[hidden] { display: none !important; }

/* tag chips (vertical wrap in the rail) */
.tag-row { display: flex; flex-wrap: wrap; gap: .35rem .3rem; }
.chip {
  font-family: var(--pixel); font-size: .75rem; line-height: 1;
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .32rem .5rem .28rem; border-radius: 0; cursor: pointer;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  background: transparent;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.chip:hover { color: var(--magenta); border-color: var(--magenta); }
.chip .count { font-size: .66rem; color: var(--ink-faint); }
.chip.is-active {
  color: var(--paper); background: var(--ink); border-color: var(--ink);
  box-shadow: 2px 2px 0 rgba(42, 39, 69, 0.25);
}
.chip.is-active .count { color: rgba(250,246,236,0.6); }
.tag-row.collapsed .chip:nth-child(n+13):not(.chip-more) { display: none; }
.chip-more { border-style: dashed; color: var(--ink-faint); }

/* rail nav links */
.rail-nav { display: flex; flex-direction: column; gap: .45rem; }
.rail-nav a {
  font-family: var(--pixel); font-size: .82rem; color: var(--ink-soft);
  display: inline-flex; align-items: center; gap: .5rem;
}
.rail-nav a::before { content: "▸"; color: var(--magenta); font-size: .75em; }
.rail-nav a:hover { color: var(--magenta); }

/* ---------- Main pane: timeline archive ---------- */
.main-pane { flex: 1; min-width: 0; padding: 1.9rem 2.4rem 2.6rem 2.2rem; }

.year-group { margin: 0 0 1.9rem; }
.year-head {
  font-family: var(--pixel); font-weight: 400; font-size: 1rem; letter-spacing: .12em;
  color: var(--ink-faint); margin: 0 0 .8rem;
  display: flex; align-items: center; gap: .8rem;
}
.year-head::after {
  content: ""; flex: 1; height: 5px;
  background-image: conic-gradient(var(--ink) 25%, transparent 0 50%, var(--ink) 0 75%, transparent 0);
  background-size: 5px 5px; opacity: .16;
}

/* timeline: left border + square pixel dots */
.year-entries { border-left: 2px solid var(--line); margin-left: .3rem; }

.post-entry {
  position: relative; display: block;
  padding: .55rem 0.8rem .6rem 1.25rem; margin: 0 0 .2rem;
  color: inherit;
  transition: background .15s ease, transform .15s ease;
}
.post-entry::before {
  content: ""; position: absolute; left: -5px; top: 1.05rem;
  width: 8px; height: 8px; background: var(--paper);
  border: 2px solid var(--ink-faint);
  transition: background .15s ease, border-color .15s ease;
}
.post-entry:hover { background: rgba(192, 43, 138, 0.05); transform: translateX(3px); }
.post-entry:hover::before { background: var(--magenta); border-color: var(--magenta); }

.entry-top { display: flex; align-items: baseline; gap: .8rem; }
.entry-date {
  font-family: var(--pixel); font-size: .78rem; color: var(--ink-faint);
  white-space: nowrap; flex: 0 0 auto;
}
.entry-title {
  font-family: var(--serif); font-weight: 600; font-size: 1.13rem; line-height: 1.45;
  color: var(--ink); transition: color .15s ease; min-width: 0;
}
html[lang^="zh"] .entry-title { font-weight: 700; }
.post-entry:hover .entry-title { color: var(--magenta); }
.entry-summary {
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
  margin: .1rem 0 0; padding-left: 3.4rem;
  font-size: .88rem; line-height: 1.6; color: var(--ink-soft);
}
.entry-tags {
  display: block; margin-top: .18rem; padding-left: 3.4rem;
  font-family: var(--pixel); font-size: .7rem; letter-spacing: .03em;
  color: var(--ink-faint);
}
.post-entry:hover .entry-tags { color: var(--cyan); }

/* ---------- Status bar ---------- */
.statusbar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .42rem .9rem .4rem;
  background: var(--bar);
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,0.04) 0 1px, transparent 1px 3px);
  border-top: 2px solid var(--desk-deep);
  font-family: var(--pixel); font-size: .78rem; letter-spacing: .05em;
  color: rgba(244,241,255,0.75);
}
.statusbar a { color: rgba(244,241,255,0.75); }
.statusbar a:hover { color: var(--cyan-bright); }
.statusbar .st-right { color: rgba(244,241,255,0.4); display: flex; gap: .9rem; }
#status-note.filtering { color: var(--cyan-bright); }

/* ---------- Single post ---------- */
.post-pane { flex: 1; min-width: 0; padding: 2.2rem clamp(1.6rem, 4vw, 3.2rem) 3rem; }

.post-head { max-width: var(--measure); margin: 0 0 2.2rem; text-align: left; }
.post-head .kicker {
  font-family: var(--pixel); font-size: .78rem; letter-spacing: .14em;
  text-transform: uppercase; color: var(--magenta);
}
.post-head h1 {
  font-family: var(--serif); font-weight: 700; letter-spacing: 0;
  font-size: clamp(1.8rem, 3.6vw, 2.4rem); line-height: 1.25; margin: .5rem 0 .8rem; color: var(--ink);
}
html[lang^="zh"] .post-head h1 { font-weight: 900; }
.post-head .byline {
  font-family: var(--pixel); font-size: .82rem; color: var(--ink-faint);
  display: flex; gap: .6rem; align-items: center; flex-wrap: wrap;
}
.post-head .rule {
  width: 7.5rem; height: 6px; border: 0; margin: 1.3rem 0 0;
  background-image: conic-gradient(var(--ink) 25%, transparent 0 50%, var(--ink) 0 75%, transparent 0);
  background-size: 6px 6px; opacity: .22;
}

.reading { max-width: var(--measure); margin: 0; }

/* ---------- Prose (the readable core — deliberately calm) ---------- */
.prose { color: var(--ink); font-family: var(--font-read); font-size: 1.07rem; line-height: 1.78; font-weight: 400; }
html[lang^="zh"] .prose { line-height: 1.92; letter-spacing: .005em; }
.prose > * + * { margin-top: 1.6em; }
.prose p + p { margin-top: 1.75em; }
.prose p { margin: 0; }
.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(--cyan); text-decoration: underline; text-decoration-color: rgba(14,138,153,0.4); text-underline-offset: 3px; }
.prose a:hover { color: var(--magenta); text-decoration-color: var(--magenta); }
.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(--cyan-bright), var(--magenta-soft)) 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(--magenta); }

.prose img {
  display: block; max-width: 100%; height: auto; margin: 1.6em auto;
  border-radius: 2px; border: 1px solid var(--line);
  box-shadow: 3px 3px 0 rgba(42, 39, 69, 0.22);
}
.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: 2px; overflow: hidden; border: 1px solid var(--line);
  box-shadow: 3px 3px 0 rgba(42, 39, 69, 0.22); background: var(--line-soft);
  background-size: cover; background-position: center;
}
.img-prog.has-lqip { background-image: var(--lqip); }
.img-prog.has-lqip::before {
  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: 5px; margin: 2.6em auto; width: 9rem;
  background-image: conic-gradient(var(--ink) 25%, transparent 0 50%, var(--ink) 0 75%, transparent 0);
  background-size: 5px 5px; opacity: .22;
}

.prose code {
  font-family: var(--mono);
  font-size: .88em; padding: .12em .4em; border-radius: 2px;
  background: rgba(42,39,69,0.07); color: var(--ink);
}
.prose pre {
  margin: 1.4em 0; padding: .85em 1.05em; border-radius: 2px;
  background: rgba(42,39,69,0.05); color: var(--ink-soft);
  border: 1px solid var(--line-soft); border-left: 3px solid rgba(14,138,153,0.4);
  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; }

.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;
}
.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(42,39,69,0.06); font-family: var(--sans); font-weight: 700; }

.prose mjx-container { overflow-x: auto; overflow-y: hidden; max-width: 100%; }

/* ---------- Post footer / back link ---------- */
.post-foot { max-width: var(--measure); margin: 3.2rem 0 0; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.post-foot .row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.back-link {
  font-family: var(--pixel); font-size: .88rem; color: var(--ink-soft);
  display: inline-flex; align-items: center; gap: .4rem;
}
.back-link:hover { color: var(--magenta); }

.post-tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1.1rem; }
.post-tags .tag {
  font-family: var(--pixel); font-size: .73rem; line-height: 1;
  padding: .3rem .5rem .26rem; border-radius: 0;
  color: var(--ink-soft); border: 1px solid var(--line); background: transparent;
  transition: color .15s ease, border-color .15s ease;
}
.post-tags .tag:hover { color: var(--magenta); border-color: var(--magenta); }

/* ---------- States ---------- */
.loading, .empty {
  color: var(--ink-faint);
  font-family: var(--pixel); font-size: .92rem; padding: 2.5rem 0 2.5rem 1.25rem;
}

.fade-up { opacity: 0; transform: translateY(8px); animation: fadeUp .4s 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; }
  .rail .kicker .cursor { animation: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .desk { padding: .8rem .7rem; }
  .win-body { flex-direction: column; }
  .rail {
    width: auto; flex: none;
    border-right: none; border-bottom: 1px solid var(--line);
    padding: 1.5rem 1.2rem 1.4rem;
  }
  .rail-sticky { position: static; }
  .main-pane { padding: 1.5rem 1.2rem 2rem 1rem; }
  .post-pane { padding: 1.6rem 1.2rem 2.2rem; }
  .entry-summary, .entry-tags { padding-left: 0; }
  .window { min-height: calc(100vh - 1.6rem); }
  body.blog { font-size: 1.02rem; }
  .prose { font-size: 1.05rem; }
}

/* Pre-rendered pages bake both language versions into the HTML; only the
   active one is shown. The native [hidden] attribute does the hiding — these
   are guards in case a future reset re-displays them. */
.post-lang[hidden], .post-list[hidden], .tag-row[hidden],
.post-entry[hidden], .year-group[hidden] { display: none !important; }
