:root {
  --bg: #ffffff;
  --bg-soft: #f6f6f3;
  --bg-code: #f7f7f5;
  --text: #1b1b19;
  --text-soft: #5c5b55;
  --text-mute: #8d8b82;
  --border: #e7e5df;
  --border-strong: #d6d3cb;
  --accent: #0f6e56;
  --accent-soft: #eaf4f0;
  --radius: 10px;
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", "Cascadia Mono",
    Consolas, "Liberation Mono", monospace;
  --maxw: 780px;
}

[data-theme="dark"] {
  --bg: #16181c;
  --bg-soft: #1e2126;
  --bg-code: #1b1e23;
  --text: #e9e8e3;
  --text-soft: #a9aaa4;
  --text-mute: #7b7d78;
  --border: #2b2f35;
  --border-strong: #3b4047;
  --accent: #63d3ad;
  --accent-soft: #1a2b26;
}

*,
*::before,
*::after { box-sizing: border-box; }

html {
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .18s ease, color .18s ease;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover { color: var(--accent); }

::selection {
  background: var(--accent);
  color: var(--bg);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--bg-soft);
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 99;
}
.skip-link:focus { left: 16px; top: 12px; }

/* ---------- header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: .98rem;
  letter-spacing: .01em;
  white-space: nowrap;
}

.brand-mark {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--accent);
  transform: rotate(45deg);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: .9rem;
  color: var(--text-soft);
}

.site-nav a { position: relative; padding: 4px 0; }

.site-nav a:hover { color: var(--text); }

.site-nav a.is-active { color: var(--text); }

.site-nav a.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.theme-toggle {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  padding: 0;
  transition: border-color .15s ease, color .15s ease;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.theme-toggle svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[data-theme="light"] .ico-sun { display: none; }
[data-theme="dark"] .ico-moon { display: none; }

/* ---------- layout ---------- */

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 24px 80px;
}

.container-wide { max-width: 900px; }

.hero {
  padding: 56px 0 8px;
}

.hero-title {
  margin: 0 0 10px;
  font-size: 1.85rem;
  line-height: 1.35;
  font-weight: 600;
  letter-spacing: -.01em;
}

.hero-desc {
  margin: 0;
  color: var(--text-soft);
  font-size: 1rem;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 44px 0 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.section-head h2 {
  margin: 0;
  font-size: .82rem;
  font-weight: 500;
  letter-spacing: .12em;
  color: var(--text-mute);
  text-transform: uppercase;
}

.section-count {
  font-size: .78rem;
  color: var(--text-mute);
}

/* ---------- post list ---------- */

.post-item {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 18px;
  padding: 22px 0;
  border-bottom: 1px solid var(--border);
}

.post-item:last-child { border-bottom: none; }

.post-item-date {
  font-family: var(--font-mono);
  font-size: .76rem;
  color: var(--text-mute);
  letter-spacing: .02em;
  padding-top: 5px;
  white-space: nowrap;
}

.post-item-title {
  margin: 0 0 6px;
  font-size: 1.06rem;
  font-weight: 600;
  line-height: 1.5;
}

.post-item-summary {
  margin: 0 0 8px;
  color: var(--text-soft);
  font-size: .92rem;
  line-height: 1.65;
}

.post-item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  color: var(--text-mute);
}

.post-item-tags { display: inline-flex; gap: 6px; flex-wrap: wrap; }

.tag {
  font-size: .76rem;
  color: var(--text-soft);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
  white-space: nowrap;
}

a.tag:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dot { color: var(--text-mute); }

/* ---------- list page ---------- */

.list-header {
  padding: 52px 0 6px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.list-header h1 {
  margin: 0 0 12px;
  font-size: 1.6rem;
  font-weight: 600;
}

.list-count {
  margin: 0 0 12px;
  font-size: .8rem;
  color: var(--text-mute);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 28px 0 8px;
}

.tag-link {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: .88rem;
  background: var(--bg-soft);
}

.tag-link:hover { border-color: var(--accent); color: var(--accent); }

.tag-num {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--text-mute);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 0 0;
  font-size: .88rem;
  color: var(--text-soft);
}

.pager-info { font-family: var(--font-mono); font-size: .78rem; color: var(--text-mute); }

.empty-hint {
  color: var(--text-mute);
  font-size: .9rem;
  padding: 28px 0;
}

/* ---------- single post ---------- */

.post { padding-top: 52px; }

.post-header { margin-bottom: 34px; }

.post-title {
  margin: 0 0 14px;
  font-size: 1.72rem;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: -.01em;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  font-size: .82rem;
  color: var(--text-mute);
}

.post-tags { display: inline-flex; gap: 6px; flex-wrap: wrap; }

.draft-badge {
  display: inline-block;
  margin: 14px 0 0;
  font-size: .78rem;
  color: #8a5a00;
  background: #fdf3e0;
  border: 1px solid #f0dcb8;
  border-radius: 6px;
  padding: 3px 9px;
}

.post-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 178px;
  gap: 52px;
  align-items: start;
}

.post-layout.no-toc { grid-template-columns: minmax(0, 1fr); }

.post-content {
  min-width: 0;
  font-size: 1rem;
  line-height: 1.85;
}

.post-content > * + * { margin-top: 1.15em; }

.post-content p { margin: 0; }

.post-content h2 {
  margin-top: 2.3em;
  margin-bottom: .7em;
  font-size: 1.26rem;
  font-weight: 600;
  line-height: 1.5;
  scroll-margin-top: 80px;
}

.post-content h3 {
  margin-top: 1.9em;
  margin-bottom: .55em;
  font-size: 1.08rem;
  font-weight: 600;
  scroll-margin-top: 80px;
}

.post-content h4 {
  margin-top: 1.6em;
  font-size: .98rem;
  font-weight: 600;
}

.post-content ul,
.post-content ol { padding-left: 1.35em; }

.post-content li { margin: .4em 0; }

.post-content li::marker { color: var(--text-mute); }

.post-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.post-content a:hover { text-decoration-color: var(--accent); }

.post-content blockquote {
  margin: 1.5em 0;
  padding: 2px 0 2px 18px;
  border-left: 2px solid var(--accent);
  color: var(--text-soft);
}

.post-content blockquote p { margin: 0; }

.post-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.4em 0;
}

.post-content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.6em auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.post-content figure { margin: 1.6em 0; }

.post-content figcaption {
  text-align: center;
  font-size: .8rem;
  color: var(--text-mute);
  margin-top: .6em;
}

.post-content code {
  font-family: var(--font-mono);
  font-size: .87em;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .1em .36em;
}

.post-content pre {
  margin: 1.5em 0;
  padding: 16px 18px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .84rem;
  line-height: 1.7;
  -webkit-overflow-scrolling: touch;
}

.post-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 1em;
}

.post-content .highlight { position: relative; margin: 1.5em 0; }

.post-content .highlight pre { margin: 0; }

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  font-family: var(--font-sans);
  font-size: .72rem;
  color: var(--text-mute);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s ease, color .15s ease;
}

.highlight:hover .copy-btn { opacity: 1; }

.copy-btn:hover { color: var(--accent); border-color: var(--accent); }

.post-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

.post-content th,
.post-content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}

.post-content th {
  background: var(--bg-soft);
  font-weight: 600;
}

.post-content th:first-child,
.post-content td:first-child { white-space: nowrap; }

.post-content td code { white-space: nowrap; }

.post-content mjx-container[display="true"] {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 0;
}

/* ---------- toc ---------- */

.toc {
  position: sticky;
  top: 88px;
  font-size: .82rem;
  border-left: 1px solid var(--border);
  padding-left: 16px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.toc-title {
  margin: 0 0 8px;
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-mute);
}

.toc nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc nav ul ul { padding-left: 12px; }

.toc nav li { margin: 5px 0; }

.toc nav a {
  color: var(--text-soft);
  line-height: 1.5;
  display: block;
}

.toc nav a:hover { color: var(--accent); }

/* ---------- post nav ---------- */

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.post-nav-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s ease, background .15s ease;
}

.post-nav-item:hover { border-color: var(--accent); background: var(--accent-soft); }

.post-nav-item.next { grid-column: 2; text-align: right; }

.post-nav-label { font-size: .74rem; color: var(--text-mute); }

.post-nav-title { font-size: .92rem; font-weight: 500; line-height: 1.5; }

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

.footer-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 26px 24px 44px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  font-size: .8rem;
  color: var(--text-mute);
}

.footer-inner p { margin: 0; }

.footer-meta { display: inline-flex; gap: 8px; }

.footer-meta a:hover { color: var(--accent); }

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .post-layout { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 640px) {
  html { font-size: 16px; }

  .header-inner { padding: 0 18px; height: 56px; gap: 12px; }
  .site-nav { gap: 14px; font-size: .85rem; }
  .brand-text { display: none; }
  .container { padding: 0 18px 60px; }
  .hero { padding-top: 40px; }
  .hero-title { font-size: 1.55rem; }
  .post-item { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .post-item-date { padding-top: 0; }
  .post-title { font-size: 1.45rem; }
  .post { padding-top: 38px; }
  .post-nav { grid-template-columns: 1fr; }
  .post-nav-item.next { grid-column: 1; text-align: left; }
  .post-content table { display: block; overflow-x: auto; font-size: .84rem; }
  .copy-btn { opacity: 1; }
}
