:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #eef2f6;
  --text: #141b24;
  --text-muted: #526071;
  --border: #dce3ec;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: #eff6ff;
  --code-bg: #f1f5f9;
  --quote-bg: #f1f5fb;
  --font-sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b;
    --surface: #151c26;
    --surface-muted: #1b2431;
    --text: #e6edf5;
    --text-muted: #93a3b8;
    --border: #263244;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-soft: #17253d;
    --code-bg: #161f2b;
    --quote-bg: #141d2b;
  }
}

:root[data-theme="dark"] {
  --bg: #0f141b;
  --surface: #151c26;
  --surface-muted: #1b2431;
  --text: #e6edf5;
  --text-muted: #93a3b8;
  --border: #263244;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --accent-soft: #17253d;
  --code-bg: #161f2b;
  --quote-bg: #141d2b;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 4.5rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand:hover {
  color: var(--accent);
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.35rem;
  font-size: 0.92rem;
}

.site-nav a {
  color: var(--text-muted);
}

.site-nav a:hover {
  color: var(--text);
  text-decoration: none;
}

.theme-toggle {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.84rem;
  padding: 0.28rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* Home */
.home-main {
  max-width: 820px;
  margin: 0 auto;
  padding: 3.2rem 1.5rem 4rem;
}

.intro {
  padding-bottom: 2.2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}

.intro-title {
  margin: 0 0 0.75rem;
  font-size: clamp(1.75rem, 3.2vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.intro-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 1.02rem;
  max-width: 62ch;
}

.section {
  margin-bottom: 3rem;
}

.section-heading {
  margin: 0 0 1.2rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Series box */
.series-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
}

.series-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.series-name {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 700;
}

.series-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.series-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.series-list li {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  align-items: baseline;
  gap: 0.65rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--border);
}

.series-list li:first-child {
  border-top: none;
  padding-top: 0.2rem;
}

.series-idx {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.series-link {
  color: var(--text);
  font-weight: 500;
}

.series-link:hover {
  color: var(--accent);
}

.series-date {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Post list */
.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-row {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 1.5rem;
  padding: 1.45rem 0;
  border-bottom: 1px solid var(--border);
}

.post-row:first-child {
  padding-top: 0.3rem;
}

.post-row-meta {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.86rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  padding-top: 0.22rem;
}

.post-row-title {
  margin: 0 0 0.45rem;
  font-size: 1.2rem;
  line-height: 1.4;
  font-weight: 700;
}

.post-row-title a {
  color: var(--text);
}

.post-row-title a:hover {
  color: var(--accent);
}

.post-row-summary {
  margin: 0 0 0.7rem;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.65;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tag {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--surface-muted);
  padding: 0.14rem 0.55rem;
  border-radius: 4px;
}

/* Post layout */
.post-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4.5rem;
  display: grid;
  grid-template-columns: minmax(0, 740px) minmax(0, 240px);
  justify-content: space-between;
  gap: 3rem;
}

.post-header {
  padding-bottom: 1.5rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.post-series-crumb {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.7rem;
}

.crumb-sep {
  margin: 0 0.4rem;
}

.post-title {
  margin: 0 0 0.9rem;
  font-size: clamp(1.65rem, 3vw, 2.15rem);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.post-tags {
  margin-top: 0.85rem;
}

/* Mobile TOC */
.mobile-toc {
  display: none;
  margin-bottom: 1.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
}

.mobile-toc summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
}

.mobile-toc ul {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
}

.mobile-toc li {
  margin: 0.35rem 0;
  font-size: 0.9rem;
}

/* Desktop TOC */
.toc-sticky {
  position: sticky;
  top: 5rem;
  max-height: calc(100vh - 6.5rem);
  overflow-y: auto;
  padding-left: 1rem;
  border-left: 1px solid var(--border);
}

.toc-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.7rem;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-list li {
  margin: 0.38rem 0;
  line-height: 1.45;
}

.toc-list a {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: color 0.15s ease;
}

.toc-list a:hover,
.toc-list a.active {
  color: var(--accent);
  text-decoration: none;
}

.toc-list a.active {
  font-weight: 600;
}

.toc-l3 {
  padding-left: 0.85rem;
}

/* Prose typography */
.prose {
  font-size: 1.02rem;
  line-height: 1.84;
  word-break: break-word;
}

.prose > *:first-child {
  margin-top: 0;
}

.prose h2 {
  margin: 2.6rem 0 1rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
  font-size: 1.42rem;
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.prose h3 {
  margin: 2rem 0 0.75rem;
  font-size: 1.16rem;
  line-height: 1.4;
  font-weight: 700;
}

.prose h4 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.02rem;
  font-weight: 600;
}

.prose p {
  margin: 0 0 1.15rem;
}

.prose ul,
.prose ol {
  margin: 0 0 1.2rem;
  padding-left: 1.55rem;
}

.prose li {
  margin: 0.38rem 0;
}

.prose li > p {
  margin-bottom: 0.45rem;
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.2rem 0;
}

.prose blockquote {
  margin: 1.4rem 0;
  padding: 0.9rem 1.2rem;
  background: var(--quote-bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  color: var(--text);
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.6rem auto;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.87em;
  background: var(--code-bg);
  padding: 0.14em 0.38em;
  border-radius: 4px;
}

.prose pre {
  position: relative;
  margin: 1.4rem 0;
  padding: 1.05rem 1.2rem;
  background: var(--code-bg) !important;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  line-height: 1.6;
  font-size: 0.87rem;
}

.prose pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

.code-copy-btn {
  position: absolute;
  top: 0.55rem;
  right: 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  padding: 0.18rem 0.52rem;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.85;
}

.code-copy-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  opacity: 1;
}

/* Tables */
.table-wrap {
  margin: 1.5rem 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  line-height: 1.6;
}

.prose th,
.prose td {
  padding: 0.68rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.prose thead th {
  background: var(--surface-muted);
  font-weight: 600;
  white-space: nowrap;
}

.prose tbody tr:last-child td {
  border-bottom: none;
}

/* Mermaid diagrams */
.mermaid-wrap {
  margin: 1.75rem 0;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  text-align: center;
}

.mermaid-wrap pre.mermaid {
  background: transparent !important;
  border: none;
  margin: 0;
  padding: 0;
  text-align: center;
}

.mermaid-wrap svg {
  max-width: 100%;
  height: auto;
}

/* Series pager */
.series-pager {
  margin-top: 3.2rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.pager-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.95rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

.pager-item:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.pager-next {
  text-align: right;
}

.pager-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pager-title {
  font-size: 0.94rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--accent);
}

/* 404 */
.not-found {
  max-width: 600px;
  margin: 5rem auto;
  padding: 0 1.5rem;
  text-align: center;
}

.not-found h1 {
  font-size: 3rem;
  margin: 0 0 0.5rem;
}

.not-found p {
  color: var(--text-muted);
  margin: 0 0 1.5rem;
}

.back-home {
  display: inline-block;
  padding: 0.5rem 1.15rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-weight: 600;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  gap: 1.2rem;
}

.footer-links a {
  color: var(--text-muted);
}

.footer-links a:hover {
  color: var(--text);
}

@media (max-width: 980px) {
  .post-shell {
    grid-template-columns: minmax(0, 1fr);
    padding-top: 1.8rem;
  }

  .desktop-toc {
    display: none;
  }

  .mobile-toc {
    display: block;
  }
}

@media (max-width: 640px) {
  .post-row {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }

  .post-row-meta {
    flex-direction: row;
    gap: 0.9rem;
  }

  .series-list li {
    grid-template-columns: 1.4rem 1fr;
  }

  .series-date {
    display: none;
  }

  .series-pager {
    grid-template-columns: 1fr;
  }
}

/* Chroma light theme */
/* Background */ .bg { background-color: #ffffff; }
/* PreWrapper */ .chroma { background-color: #ffffff; }
/* Error */ .chroma .err { color: #a61717; background-color: #e3d2d2 }
/* LineTableTD */ .chroma .lntd { vertical-align: top; padding: 0; margin: 0; border: 0; }
/* LineTable */ .chroma .lntable { border-spacing: 0; padding: 0; margin: 0; border: 0; }
/* LineHighlight */ .chroma .hl { background-color: #e5e5e5 }
/* LineNumbersTable */ .chroma .lnt { white-space: pre; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #7f7f7f }
/* LineNumbers */ .chroma .ln { white-space: pre; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #7f7f7f }
/* Line */ .chroma .line { display: flex; }
/* Keyword */ .chroma .k { color: #000000; font-weight: bold }
/* KeywordConstant */ .chroma .kc { color: #000000; font-weight: bold }
/* KeywordDeclaration */ .chroma .kd { color: #000000; font-weight: bold }
/* KeywordNamespace */ .chroma .kn { color: #000000; font-weight: bold }
/* KeywordPseudo */ .chroma .kp { color: #000000; font-weight: bold }
/* KeywordReserved */ .chroma .kr { color: #000000; font-weight: bold }
/* KeywordType */ .chroma .kt { color: #445588; font-weight: bold }
/* NameAttribute */ .chroma .na { color: #008080 }
/* NameBuiltin */ .chroma .nb { color: #0086b3 }
/* NameBuiltinPseudo */ .chroma .bp { color: #999999 }
/* NameClass */ .chroma .nc { color: #445588; font-weight: bold }
/* NameConstant */ .chroma .no { color: #008080 }
/* NameDecorator */ .chroma .nd { color: #3c5d5d; font-weight: bold }
/* NameEntity */ .chroma .ni { color: #800080 }
/* NameException */ .chroma .ne { color: #990000; font-weight: bold }
/* NameFunction */ .chroma .nf { color: #990000; font-weight: bold }
/* NameLabel */ .chroma .nl { color: #990000; font-weight: bold }
/* NameNamespace */ .chroma .nn { color: #555555 }
/* NameTag */ .chroma .nt { color: #000080 }
/* NameVariable */ .chroma .nv { color: #008080 }
/* NameVariableClass */ .chroma .vc { color: #008080 }
/* NameVariableGlobal */ .chroma .vg { color: #008080 }
/* NameVariableInstance */ .chroma .vi { color: #008080 }
/* LiteralString */ .chroma .s { color: #dd1144 }
/* LiteralStringAffix */ .chroma .sa { color: #dd1144 }
/* LiteralStringBacktick */ .chroma .sb { color: #dd1144 }
/* LiteralStringChar */ .chroma .sc { color: #dd1144 }
/* LiteralStringDelimiter */ .chroma .dl { color: #dd1144 }
/* LiteralStringDoc */ .chroma .sd { color: #dd1144 }
/* LiteralStringDouble */ .chroma .s2 { color: #dd1144 }
/* LiteralStringEscape */ .chroma .se { color: #dd1144 }
/* LiteralStringHeredoc */ .chroma .sh { color: #dd1144 }
/* LiteralStringInterpol */ .chroma .si { color: #dd1144 }
/* LiteralStringOther */ .chroma .sx { color: #dd1144 }
/* LiteralStringRegex */ .chroma .sr { color: #009926 }
/* LiteralStringSingle */ .chroma .s1 { color: #dd1144 }
/* LiteralStringSymbol */ .chroma .ss { color: #990073 }
/* LiteralNumber */ .chroma .m { color: #009999 }
/* LiteralNumberBin */ .chroma .mb { color: #009999 }
/* LiteralNumberFloat */ .chroma .mf { color: #009999 }
/* LiteralNumberHex */ .chroma .mh { color: #009999 }
/* LiteralNumberInteger */ .chroma .mi { color: #009999 }
/* LiteralNumberIntegerLong */ .chroma .il { color: #009999 }
/* LiteralNumberOct */ .chroma .mo { color: #009999 }
/* Operator */ .chroma .o { color: #000000; font-weight: bold }
/* OperatorWord */ .chroma .ow { color: #000000; font-weight: bold }
/* Comment */ .chroma .c { color: #999988; font-style: italic }
/* CommentHashbang */ .chroma .ch { color: #999988; font-style: italic }
/* CommentMultiline */ .chroma .cm { color: #999988; font-style: italic }
/* CommentSingle */ .chroma .c1 { color: #999988; font-style: italic }
/* CommentSpecial */ .chroma .cs { color: #999999; font-weight: bold; font-style: italic }
/* CommentPreproc */ .chroma .cp { color: #999999; font-weight: bold; font-style: italic }
/* CommentPreprocFile */ .chroma .cpf { color: #999999; font-weight: bold; font-style: italic }
/* GenericDeleted */ .chroma .gd { color: #000000; background-color: #ffdddd }
/* GenericEmph */ .chroma .ge { color: #000000; font-style: italic }
/* GenericError */ .chroma .gr { color: #aa0000 }
/* GenericHeading */ .chroma .gh { color: #999999 }
/* GenericInserted */ .chroma .gi { color: #000000; background-color: #ddffdd }
/* GenericOutput */ .chroma .go { color: #888888 }
/* GenericPrompt */ .chroma .gp { color: #555555 }
/* GenericStrong */ .chroma .gs { font-weight: bold }
/* GenericSubheading */ .chroma .gu { color: #aaaaaa }
/* GenericTraceback */ .chroma .gt { color: #aa0000 }
/* GenericUnderline */ .chroma .gl { text-decoration: underline }
/* TextWhitespace */ .chroma .w { color: #bbbbbb }

/* Chroma dark theme */

@media (prefers-color-scheme: dark) {
}
