/* ============================================================
 * blog/blog.css
 * Page-specific styles for index.html.
 * Loads AFTER lib/design/louie.css so it can extend the M3 :root
 * tokens (--bg, --surface, --accent, etc.).
 * ============================================================ */

/* blog-only body extension */
body { overscroll-behavior: none; }

.fade-in {
  opacity: 0; transform: translateY(20px);
  transition: opacity 0.7s cubic-bezier(0.25, 1, 0.5, 1), transform 0.7s cubic-bezier(0.25, 1, 0.5, 1);
}
.fade-in.visible { opacity: 1; transform: none; }

/* ─── Mobile TOC drawer ─── */
#mobile-toc {
  position: fixed; inset: 0; z-index: 95;
  background: rgba(0,0,0,0);
  pointer-events: none;
  transition: background 0.25s ease;
}
#mobile-toc.open { background: rgba(0,0,0,0.5); pointer-events: auto; }
#mobile-toc-panel {
  position: absolute; top: 64px; left: 0; bottom: 0; width: 280px;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 16px;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
#mobile-toc.open #mobile-toc-panel { transform: translateX(0); }

/* ─── TOC FAB ─── */
#toc-fab {
  position: fixed; bottom: 55px; left: 28px;
  width: 68px; height: 68px; border-radius: 9999px;
  background: var(--accent); color: #fff;
  border: none; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.28), 0 2px 4px rgba(0,0,0,0.18);
  z-index: 80; overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#toc-fab.visible { display: flex; }
#toc-fab:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 16px rgba(0,0,0,0.32), 0 3px 6px rgba(0,0,0,0.2);
}
@media (min-width: 1360px) { #toc-fab { display: none !important; } }

/* ─── Reader Prose Overrides mapped to M3 ─── */
.reader-body { font-size: 16px; line-height: 1.95; color: var(--text); overflow-wrap: break-word; }
.reader-body > * + * { margin-top: 1.25em; }
.reader-body .lead {
  font-size: 18px; color: var(--muted); border-left: 3px solid var(--accent);
  padding-left: 18px; margin-bottom: 32px; font-style: italic;
}
.reader-body h2 {
  font-size: 22px; font-weight: 700; color: #ffffff;
  margin-top: 48px; margin-bottom: 16px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.reader-body h2:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.reader-body h3 { font-size: 18px; font-weight: 700; color: #ffffff; margin-top: 36px; }
.reader-body p { color: var(--text); }
.reader-body strong { color: var(--accent); font-weight: 700; }
.reader-body em { color: var(--muted); font-style: italic; }
.reader-body a {
  color: var(--accent); text-decoration: none;
  border-bottom: 1px solid rgba(217, 119, 87, 0.3); transition: border-color 0.25s ease;
}
.reader-body a:hover { border-bottom-color: var(--accent); }
.reader-body ul, .reader-body ol { padding-left: 28px; color: var(--text); }
.reader-body li + li { margin-top: 6px; }
/* Real, fixed-width JetBrains Mono for code. The site-wide 'JetBrains Mono'
   family (louie.css / fonts.css) is actually a CJK *body* subset — its ASCII
   glyphs aren't reliably monospaced, which made code columns look ragged.
   These two faces load the genuine monospace files (already in the repo). */
@font-face {
  font-family: 'JBMono';
  src: url('../lib/design/JetBrainsMono.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'JBMono';
  src: url('../lib/design/JetBrainsMono-Bold.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}

/* inline code — pill */
.reader-body code {
  font-family: 'JBMono', 'JetBrains Mono', monospace; font-size: 0.9em;
  color: var(--accent-on); background: rgba(217, 119, 87, 0.15);
  padding: 2px 6px; border-radius: 6px;
}

/* ─── Code box (highlight.js VS Code Dark+ theme + custom chrome) ───
   Token COLOURS come from lib/highlight/vs2015.min.css (the upstream,
   maintained theme). Everything below is just the box chrome: header bar
   with language label + copy button, and a line-number gutter. The box
   provides the warm var(--surface) surface; we neutralise the theme's own bg. */
.reader-body .code-box {
  margin: 24px 0; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); overflow: hidden;
  font-family: 'JBMono', 'JetBrains Mono', monospace; font-size: 14px;
  /* keep code literal — no ligatures (-> must not render as →) for tutorials */
  font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0;
}
.reader-body .code-box__bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px 6px 14px;
  background: rgba(0, 0, 0, 0.18); border-bottom: 1px solid var(--border);
}
.reader-body .code-box__lang {
  font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
}
.reader-body .code-box__copy {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  background: none; border: 1px solid transparent; border-radius: 8px;
  color: var(--muted); font: inherit; font-size: 11px; padding: 4px 9px;
  transition: background .2s, color .2s, border-color .2s;
}
.reader-body .code-box__copy:hover {
  color: var(--text); background: rgba(255, 255, 255, 0.06); border-color: var(--border);
}
.reader-body .code-box__copy svg { width: 13px; height: 13px; flex-shrink: 0; }
.reader-body .code-box__copy.copied { color: #6a9955; }

.reader-body .code-box__main { display: flex; align-items: stretch; }
.reader-body .code-box__gutter {
  flex: 0 0 auto; user-select: none; -webkit-user-select: none;
  text-align: right; white-space: pre; tab-size: 4;
  padding: 14px 12px 14px 14px; line-height: 1.7; color: #5c5c5b;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}
.reader-body .code-box__pre {
  flex: 1 1 auto; min-width: 0; margin: 0; padding: 14px 16px;
  overflow-x: auto; line-height: 1.7; background: none;
}
/* the box owns the chrome: strip the inline-code pill (bg/padding) that
   .reader-body code would otherwise apply to plain, un-highlighted blocks,
   and neutralise the vs2015 theme's own block background/padding */
.reader-body .code-box__pre code { color: var(--text); background: none; padding: 0; }
.reader-body .hljs { background: transparent; }

/* stray <pre> without a <code> child (rare) — keep a sane surface */
.reader-body pre:not(.code-box__pre) {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; overflow-x: auto; font-size: 14px; line-height: 1.7;
  font-family: 'JBMono', 'JetBrains Mono', monospace; color: var(--text);
}
.reader-body img {
  max-width: 100%; height: auto; border-radius: 12px;
  margin: 24px auto; display: block; border: 1px solid var(--border);
}
.reader-body blockquote {
  border-left: 4px solid rgba(217, 119, 87, 0.6); padding: 8px 20px;
  margin: 24px 0; color: var(--muted); font-style: italic;
  background: rgba(217, 119, 87, 0.05); border-radius: 0 12px 12px 0;
}
.reader-body hr {
  border: none; height: 1px; margin: 48px 0;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
/* table-scroll: wrapper added by blog-views.js so wide tables scroll inside
   their own box on mobile instead of stretching the page past the viewport. */
.reader-body .table-scroll {
  margin: 24px 0;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;   /* momentum scroll on iOS */
  border-radius: 8px;
}
.reader-body table {
  width: 100%; border-collapse: collapse; font-size: 14px;
  margin: 24px 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
/* inside the scroll wrapper the table keeps its min-content width (so it can
   overflow → scroll) and drops its own outer margin (the wrapper owns it). */
.reader-body .table-scroll > table { margin: 0; width: 100%; }
.reader-body th {
  background: rgba(217, 119, 87, 0.1); color: var(--accent-on);
  font-weight: 700; padding: 12px 16px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.reader-body td { padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.reader-body tr:last-child td { border-bottom: none; }
.reader-body tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

/* ─── TOC sidebar ─── */
#toc-sidebar {
  position: fixed;
  top: 148px;                /* a little below the sticky Back pill, for separation */
  /* 强制限定高度计算，放弃模糊的 bottom / max-height */
  height: calc(100vh - 172px);
  left: max(16px, calc((100vw - 896px) / 2 - 280px));
  width: 260px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#toc-sidebar::-webkit-scrollbar { display: none; }
@media (max-width: 1359px) { #toc-sidebar { display: none !important; } }

/* ─── KaTeX math (rendered at parse time by blog-interpreter.js) ─── */
.reader-body .katex { color: var(--text); font-size: 1.05em; }
.reader-body .katex-display {
  margin: 1.25em 0;
  overflow-x: auto;            /* wide matrices scroll instead of overflowing */
  overflow-y: hidden;
  padding: 4px 2px 10px;       /* room for the scrollbar without clipping glyphs */
}
.reader-body .katex-display > .katex { font-size: 1.15em; }
/* keep strong/em recolouring out of math, and never underline math in links */
.reader-body .katex strong, .reader-body .katex em { color: inherit; font-style: normal; }
.katex-error { color: #ff6b6b; font-family: 'JBMono', monospace; }

/* ─── Librarian breadcrumb (collection navigation) ─── */
#breadcrumb {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  font-size: 13px; margin-bottom: 20px; line-height: 1.6;
}
#breadcrumb .bc-link {
  color: var(--muted); text-decoration: none; transition: color 0.2s ease;
}
#breadcrumb .bc-link:hover { color: var(--accent); }
#breadcrumb .bc-current { color: var(--text); font-weight: 600; }
#breadcrumb .bc-sep { color: var(--muted); opacity: 0.5; }

/* ─── Shared "Back" button (sticky; navigates one level up) ─── */
#back-btn {
  position: sticky;
  top: 76px;                 /* just below the 64px fixed navbar */
  z-index: 40;
  display: flex; align-items: center; gap: 8px;
  width: max-content; max-width: 100%;
  margin-bottom: 24px;       /* a little breathing room before the TOC / content */
  padding: 8px 18px;
  border-radius: 9999px;
  font-size: 14px; font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  transition: color 0.2s ease, background 0.2s ease;
}
#back-btn:hover { color: var(--text); background: var(--surface-high); }
#back-btn svg { flex-shrink: 0; }
/* The compact sticky pill is used at every width (no wide left-rail variant). */

/* ─── Compact list rows — flat Material fills, no outlines ─── */
:root { --collection: #5fa8a0; }            /* teal: marks a collection (not the accent, not purple) */
#blog-list { gap: 8px; }                    /* tighten the grid (overrides tailwind gap-6) */
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; min-width: 0;
  background: var(--surface);
  border-radius: 12px;
  transition: background 0.2s ease;
}
.list-row:hover { background: var(--surface-high); }
.list-row.pinned { background: #2e2723; }    /* subtle warm fill for pinned — no outline */
.list-row.pinned:hover { background: #372d27; }

/* thumbnail — article cover / initial */
.list-row__thumb {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 9px;
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  background: var(--accent-dim); color: var(--accent);
  font-weight: 700; font-size: 16px;
}
.list-row__thumb img { width: 100%; height: 100%; object-fit: cover; }
/* collection folder — distinct teal so it reads as a folder at a glance */
.list-row__thumb--folder { background: rgba(95, 168, 160, 0.16); color: var(--collection); }

/* pin column — fixed width on EVERY row so titles always line up */
.list-row__pin {
  flex: 0 0 16px; display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}

.list-row__title {
  flex: 1 1 auto; min-width: 0;
  font-size: 15px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color 0.2s ease;
}
.list-row:hover .list-row__title { color: var(--accent); }
.list-row--collection:hover .list-row__title { color: var(--collection); }

.list-row__meta {
  flex: 0 0 auto; font-size: 12px; color: var(--muted);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}

/* ─── About button + changelog modal ─── */
#about-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: transparent; border: 1px solid var(--outline); color: var(--muted);
  cursor: pointer; position: relative; overflow: hidden;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
#about-btn:hover { background: var(--accent-dim); color: var(--accent); border-color: rgba(217, 119, 87, 0.5); }

/* Fade in/out (no display toggle) so the ⓘ button's ripple stays visible and
   nothing replays a finished animation when the modal is reopened. */
#about-modal {
  position: fixed; inset: 0; z-index: 10000;
  opacity: 0; visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
#about-modal.open { opacity: 1; visibility: visible; }
.about-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.about-card {
  position: relative; z-index: 1;
  width: min(560px, calc(100vw - 32px));
  max-height: min(82vh, 760px);
  margin: 9vh auto 0;
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 18px;
  padding: 30px 26px 22px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.55);
}
/* Pop only while open — runs on each open, never on load or on a stale toggle. */
#about-modal.open .about-card { animation: about-pop 0.24s cubic-bezier(0.2, 0.8, 0.3, 1); }
@keyframes about-pop { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.about-close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--muted); cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.about-close:hover { background: var(--surface-high); color: var(--text); }
.about-logo {
  width: 60px; height: 60px; margin: 4px auto 14px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-dim); color: var(--accent);
}
.about-name { text-align: center; font-size: 20px; font-weight: 700; color: var(--text); }
.about-name .about-dot { color: var(--accent); }
.about-codename {
  width: max-content; margin: 9px auto 0; padding: 3px 12px; border-radius: 9999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent-on); background: var(--accent-dim);
}
.about-by { text-align: center; font-size: 13px; color: var(--muted); margin-top: 14px; }
.about-author { color: var(--accent); font-weight: 600; }
.about-log {
  flex: 1 1 auto; overflow-y: auto; margin-top: 20px; padding: 16px;
  background: rgba(0, 0, 0, 0.20); border-radius: 12px;
}
.about-rel + .about-rel { margin-top: 18px; }
.about-rel__head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.about-rel__date { font-family: 'JBMono', 'JetBrains Mono', monospace; font-size: 13px; color: var(--text); }
.about-rel__code {
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-dim); padding: 2px 8px; border-radius: 6px;
}
.about-item { display: flex; gap: 8px; align-items: flex-start; margin: 5px 0; font-size: 13.5px; line-height: 1.65; color: var(--muted); }
.about-tag { flex: 0 0 auto; margin-top: 1px; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 5px; line-height: 1.5; }
.about-tag--add { color: #8ab4f8; background: rgba(138, 180, 248, 0.15); }
.about-tag--improve { color: #86c578; background: rgba(134, 197, 120, 0.15); }
.about-tag--fix { color: #e0b34d; background: rgba(224, 179, 77, 0.16); }
.about-origin { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 12.5px; line-height: 1.7; color: var(--muted); }
@media (max-width: 520px) { .about-card { margin-top: 5vh; max-height: 88vh; padding: 26px 18px 18px; } }
