/* ===== 字体（自托管，避免 Google Fonts 在国内被墙）===== */
@font-face {
  font-family: 'Fraunces Display';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/fraunces-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Fraunces Display';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/fraunces-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Fraunces Display';
  font-style: italic;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/fraunces-600italic.woff2') format('woff2');
}
@font-face {
  font-family: 'Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/plexmono-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Plex Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/plexmono-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Plex Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/plexmono-600.woff2') format('woff2');
}

/* ===== 设计变量 ===== */
:root {
  --font-display: 'Fraunces Display', 'PingFang SC', 'Microsoft YaHei', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', sans-serif;
  --font-mono: 'Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;

  --accent: #12965f;
  --accent-strong: #0d7a4c;
  --accent-soft: #e4f4ec;
  --accent-soft-line: #bfe6d2;

  --bg: #faf9f5;
  --bg-raised: #ffffff;
  --bg-sunken: #f2f1ea;
  --border: #e6e3d8;
  --text: #1d201d;
  --text-muted: #63665f;
  --text-faint: #8b8d84;
  --code-bg: #1d201d;
  --code-text: #eef1ea;
  --shadow: 0 1px 2px rgba(29, 32, 29, 0.04), 0 8px 24px rgba(29, 32, 29, 0.05);

  --sidebar-w: 260px;
  --toc-w: 220px;
  --topbar-h: 56px;
}

:root[data-theme='dark'] {
  --accent: #4fd897;
  --accent-strong: #7ce7b3;
  --accent-soft: rgba(79, 216, 151, 0.12);
  --accent-soft-line: rgba(79, 216, 151, 0.28);

  --bg: #0e1210;
  --bg-raised: #161a17;
  --bg-sunken: #0a0d0b;
  --border: #262b26;
  --text: #e9ece8;
  --text-muted: #a2a89f;
  --text-faint: #6f756c;
  --code-bg: #0a0d0b;
  --code-text: #d7ddd2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --accent: #4fd897;
    --accent-strong: #7ce7b3;
    --accent-soft: rgba(79, 216, 151, 0.12);
    --accent-soft-line: rgba(79, 216, 151, 0.28);
    --bg: #0e1210;
    --bg-raised: #161a17;
    --bg-sunken: #0a0d0b;
    --border: #262b26;
    --text: #e9ece8;
    --text-muted: #a2a89f;
    --text-faint: #6f756c;
    --code-bg: #0a0d0b;
    --code-text: #d7ddd2;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

a { color: inherit; }

/* ===== 顶部导航 ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(1.4) blur(8px);
}
.topbar-inner {
  height: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
.brand-mark {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  background: var(--accent);
  color: var(--bg-raised);
  border-radius: 6px;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
:root[data-theme='dark'] .brand-mark { color: #06110c; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.01em;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.icon-sun, .icon-moon { display: none; }
:root[data-theme='light'] .icon-sun,
:root:not([data-theme]) .icon-sun { display: block; }
:root[data-theme='dark'] .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .icon-sun { display: none; }
  :root:not([data-theme]) .icon-moon { display: block; }
}

/* ===== 三栏布局 ===== */
.layout {
  max-width: 1440px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 0;
  align-items: start;
}

.sidebar-left, .sidebar-right {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 28px 8px 40px;
}
.sidebar-left { border-right: 1px solid var(--border); padding-left: 20px; }
.sidebar-right { padding-right: 20px; }

.toc-section-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  text-transform: uppercase;
  margin: 8px 6px 10px;
}
.toc-list { list-style: none; margin: 0 0 20px; padding: 0; }
.toc-link {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border-left: 2px solid transparent;
  margin-bottom: 2px;
  transition: background 0.15s ease, color 0.15s ease;
}
.toc-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}
.toc-link:hover { background: var(--bg-sunken); color: var(--text); }
.toc-link.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-left-color: var(--accent);
  font-weight: 600;
}
.toc-link.active .toc-num { color: var(--accent-strong); }

/* ===== 正文区 ===== */
.content {
  padding: 32px 48px 80px;
  min-width: 0;
  animation: fade-up 0.35s ease both;
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.term-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 32px;
}
.term-card-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
}
.term-dots { display: inline-flex; gap: 6px; margin-right: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-red { background: #ff5f57; }
.dot-yellow { background: #febc2e; }
.dot-green { background: #28c840; }
.term-path { flex: 1; }
.term-meta { color: var(--text-faint); }

.page-title {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 600;
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}
.page-subtitle {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 18px;
  color: var(--text-muted);
  margin: 0 0 32px;
  max-width: 60ch;
}

/* ===== Markdown 正文排版 ===== */
.prose { max-width: 74ch; }
.prose h2 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  margin: 48px 0 16px;
  padding-top: 8px;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.prose h3 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  margin: 32px 0 12px;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.prose p { margin: 0 0 18px; color: var(--text); }
.prose strong { color: var(--text); font-weight: 700; }
.prose ul, .prose ol { margin: 0 0 18px; padding-left: 1.4em; }
.prose li { margin-bottom: 8px; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 40px 0; }

.prose a { color: var(--accent-strong); text-decoration-color: var(--accent-soft-line); text-underline-offset: 3px; }
.prose a:hover { color: var(--accent); }

.prose blockquote {
  margin: 24px 0;
  padding: 16px 20px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  color: var(--text);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose blockquote strong { color: var(--accent-strong); }

.prose pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 18px 20px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 24px 0;
  font-size: 13.5px;
  line-height: 1.65;
}
.prose pre code {
  font-family: var(--font-mono);
  background: none;
  padding: 0;
}
.prose :not(pre) > code {
  font-family: var(--font-mono);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.88em;
}

.prose img {
  max-width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin: 8px 0 28px;
  display: block;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  font-size: 14.5px;
}
.prose th, .prose td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
}
.prose th {
  background: var(--bg-sunken);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
}

/* ===== 上/下一节 ===== */
.page-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.page-nav-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.page-nav-item:hover { border-color: var(--accent); transform: translateY(-2px); }
.page-nav-next { text-align: right; align-items: flex-end; grid-column: 2; }
.page-nav-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.page-nav-title { font-family: var(--font-display); font-weight: 600; color: var(--text); }

/* ===== 本页目录（右栏）===== */
.onpage-toc-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 12px;
}
.onpage-toc-list { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.onpage-toc-list li { margin: 0; }
.onpage-toc-list .level-3 { padding-left: 14px; }
.onpage-toc-link {
  display: block;
  text-decoration: none;
  color: var(--text-faint);
  font-size: 13px;
  padding: 6px 0 6px 14px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  line-height: 1.4;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.onpage-toc-link:hover { color: var(--text); }
.onpage-toc-link.active { color: var(--accent-strong); border-left-color: var(--accent); font-weight: 600; }
.onpage-toc-empty { font-size: 13px; color: var(--text-faint); }

/* ===== 专注阅读 ===== */
.focus-btn {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.focus-btn:hover { border-color: var(--accent); color: var(--accent-strong); transform: translateY(-1px); }
.focus-icon { font-family: var(--font-mono); }

body.focus-mode .sidebar-left,
body.focus-mode .sidebar-right {
  display: none;
}
body.focus-mode .layout {
  grid-template-columns: minmax(0, 1fr);
}
body.focus-mode .content {
  max-width: 760px;
  margin: 0 auto;
  padding-left: 20px;
  padding-right: 20px;
}
body.focus-mode .focus-btn {
  background: var(--accent);
  color: var(--bg-raised);
  border-color: var(--accent);
}
:root[data-theme='dark'] body.focus-mode .focus-btn { color: #06110c; }

/* ===== 移动端 ===== */
.mobile-nav-toggle {
  display: none;
  width: 100%;
  padding: 12px 20px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

@media (max-width: 1180px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .sidebar-right { display: none; }
}

@media (max-width: 860px) {
  .mobile-nav-toggle { display: block; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar-left {
    position: fixed;
    top: calc(var(--topbar-h) + 45px);
    left: 0;
    width: 84vw;
    max-width: 320px;
    height: calc(100vh - var(--topbar-h) - 45px);
    background: var(--bg);
    border-right: 1px solid var(--border);
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar-left.open { transform: translateX(0); box-shadow: var(--shadow); }
  .content { padding: 24px 20px 72px; }
  .page-title { font-size: 26px; }
  .page-subtitle { font-size: 15px; }
  .page-nav { grid-template-columns: 1fr; }
  .page-nav-next { grid-column: 1; text-align: left; align-items: flex-start; }
  .focus-btn span.focus-icon + span { display: none; }
}
