/* 《dsh 源码解析》站点样式：深色为默认，浅色为切换态。 */

:root {
  --bg: #0b1120;
  --bg-soft: #111a2e;
  --bg-code: #0d1526;
  --panel: rgba(17, 26, 46, 0.86);
  --border: #1f2b45;
  --border-soft: #17223a;
  --text: #e6ecf7;
  --text-dim: #9aa8c2;
  --text-faint: #6b7a96;
  --accent: #5b9dff;
  --accent-soft: rgba(91, 157, 255, 0.14);
  --mark: #ffd479;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --sidebar-w: 288px;
  --outline-w: 232px;
  --topbar-h: 56px;
  --measure: 860px;
}

html[data-theme='light'] {
  --bg: #f7f9fc;
  --bg-soft: #ffffff;
  --bg-code: #f3f5f9;
  --panel: rgba(255, 255, 255, 0.9);
  --border: #dfe5ef;
  --border-soft: #e9edf4;
  --text: #16202f;
  --text-dim: #4b5a72;
  --text-faint: #7b899f;
  --accent: #1f6feb;
  --accent-soft: rgba(31, 111, 235, 0.1);
  --mark: #b45309;
  --shadow: 0 14px 32px rgba(16, 32, 64, 0.1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  font-size: 16px;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
}

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

code, pre, kbd {
  font-family: 'SFMono-Regular', ui-monospace, 'JetBrains Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

/* ---------- 顶栏 ---------- */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--accent);
  z-index: 60;
  transition: width 0.08s linear;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 9px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  font-weight: 800;
  letter-spacing: 0.4px;
  background: var(--accent);
  color: #fff;
  border-radius: 7px;
  padding: 2px 8px;
  font-size: 14px;
}
.brand-text { font-weight: 600; font-size: 15px; }

.topbar-links { margin-left: auto; display: flex; gap: 18px; font-size: 13.5px; }
.topbar-links a { color: var(--text-dim); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  width: 34px;
  height: 32px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.nav-toggle { display: none; }

html[data-theme='dark'] .only-light,
html[data-theme='light'] .only-dark { display: none; }

/* ---------- 布局 ---------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--outline-w);
  gap: 0;
  max-width: 1560px;
  margin: 0 auto;
}
body.home .shell { grid-template-columns: minmax(0, 1fr); }
body.has-sidebar:not(.has-outline) .shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  border-right: 1px solid var(--border-soft);
  padding: 22px 16px 60px;
}

.nav-head { font-size: 13px; margin-bottom: 14px; }
.nav-group { margin-bottom: 20px; }
.nav-part {
  font-size: 11.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 8px 8px;
}
.nav ul { list-style: none; margin: 0; padding: 0; }
.nav-link {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.55;
}
.nav-link:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-num { font-variant-numeric: tabular-nums; color: var(--text-faint); font-size: 12px; }
.nav-link.active .nav-num { color: var(--accent); }

.main { padding: 34px 44px 80px; min-width: 0; }
body.home .main { padding: 0 24px 90px; }

.outline {
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 26px 18px 60px;
  border-left: 1px solid var(--border-soft);
}
.outline-title {
  font-size: 11.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.outline-nav { display: flex; flex-direction: column; gap: 2px; }
.outline-link {
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.5;
  padding: 4px 8px;
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
}
.outline-link:hover { color: var(--text); text-decoration: none; background: var(--bg-soft); }
.outline-link.lvl3 { padding-left: 20px; font-size: 12px; color: var(--text-faint); }
.outline-link.current { color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); }

.scrim { display: none; }

/* ---------- 正文排版 ---------- */

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

.chapter-eyebrow {
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  text-transform: uppercase;
}
.prose h1 {
  font-size: 33px;
  line-height: 1.35;
  margin: 10px 0 12px;
  letter-spacing: -0.01em;
}
.chapter-summary {
  color: var(--text-dim);
  font-size: 15px;
  margin: 0 0 26px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border-soft);
}

.prose h2 {
  font-size: 23px;
  margin: 52px 0 16px;
  padding-top: 10px;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.prose h3 {
  font-size: 18.5px;
  margin: 34px 0 12px;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.prose h4 { font-size: 16px; margin: 26px 0 10px; }
.prose p { margin: 16px 0; }
.prose ul, .prose ol { padding-left: 24px; margin: 16px 0; }
.prose li { margin: 7px 0; }
.prose li::marker { color: var(--text-faint); }

.prose strong { color: var(--text); font-weight: 700; }
.prose em { color: var(--text-dim); }

.prose blockquote {
  margin: 22px 0;
  padding: 12px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 10px 10px 0;
  color: var(--text-dim);
}
.prose blockquote p { margin: 8px 0; }

.prose :not(pre) > code {
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 1.5px 5px;
  font-size: 0.875em;
  color: var(--text);
  word-break: break-word;
}

.prose pre {
  margin: 20px 0;
  padding: 16px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 13.2px;
  line-height: 1.7;
  background: var(--bg-code) !important;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; }

/* shiki 双主题：同一份 HTML，两套颜色靠 CSS 变量切换 */
html[data-theme='dark'] .shiki span { color: var(--shiki-dark, inherit); }
html[data-theme='light'] .shiki span { color: var(--shiki-light, inherit); }
html[data-theme='dark'] .shiki { color: var(--shiki-dark, inherit); }
html[data-theme='light'] .shiki { color: var(--shiki-light, inherit); }

.prose img {
  display: block;
  max-width: 100%;
  margin: 26px auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #f8fafc;
  box-shadow: var(--shadow);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 22px 0;
  font-size: 13.8px;
  display: block;
  overflow-x: auto;
}
.prose th, .prose td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.prose th { background: var(--bg-soft); font-weight: 600; }
.prose tbody tr:nth-child(even) { background: color-mix(in srgb, var(--bg-soft) 55%, transparent); }

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

/* ---------- 上下章 ---------- */

.prevnext {
  max-width: var(--measure);
  margin: 46px auto 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.prevnext-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
  color: var(--text);
}
.prevnext-item:hover { border-color: var(--accent); text-decoration: none; }
.prevnext-item span { font-size: 12px; color: var(--text-faint); }
.prevnext-item strong { font-size: 14.5px; font-weight: 600; }
.prevnext-item.next { text-align: right; }

/* ---------- 首页 ---------- */

.hero {
  max-width: 960px;
  margin: 0 auto;
  padding: 78px 0 30px;
  text-align: center;
}
.hero-tag {
  display: inline-block;
  font-size: 12.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 5px 14px;
}
.hero h1 { font-size: 44px; line-height: 1.25; margin: 22px 0 18px; letter-spacing: -0.02em; }
.hero-sub { font-size: 21px; font-weight: 500; color: var(--text-dim); }
.hero-desc { max-width: 720px; margin: 0 auto; color: var(--text-dim); font-size: 16px; }
.hero-desc code, .hero-meta code {
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.86em;
}
.hero-actions { display: flex; gap: 12px; justify-content: center; margin: 30px 0 18px; flex-wrap: wrap; }
.btn {
  display: inline-block;
  padding: 10px 22px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 600;
  background: var(--bg-soft);
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.hero-meta { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; color: var(--text-faint); font-size: 13px; }

.home-intro { max-width: var(--measure); margin: 40px auto 10px; }

.part { max-width: 1100px; margin: 54px auto 0; }
.part-title {
  font-size: 15px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  text-transform: uppercase;
  margin: 0 0 16px;
  font-weight: 600;
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card {
  display: block;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-soft);
  color: var(--text);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); text-decoration: none; }
.card-num { font-size: 12px; color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: 0.1em; }
.card h3 { margin: 6px 0 8px; font-size: 16.5px; line-height: 1.5; }
.card p { margin: 0; color: var(--text-dim); font-size: 13.5px; line-height: 1.7; }

.paths { max-width: 1100px; margin: 54px auto 0; }
.path-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.path {
  padding: 16px 18px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
}
.path-goal { font-size: 14px; font-weight: 600; }
.path-route { margin-top: 6px; color: var(--accent); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- 页脚 ---------- */

.footer {
  border-top: 1px solid var(--border);
  padding: 26px 24px 40px;
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.footer code { font-size: 0.9em; }

/* ---------- 响应式 ---------- */

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

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav-toggle { display: inline-block; }
  .topbar-links { display: none; }
  .main { padding: 24px 18px 70px; }
  .hero { padding: 48px 0 16px; }
  .hero h1 { font-size: 31px; }
  .hero-sub { font-size: 17px; }
  .prose h1 { font-size: 26px; }
  .prose h2 { font-size: 20px; }
  .prevnext { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    width: min(84vw, var(--sidebar-w));
    background: var(--bg);
    z-index: 45;
    transform: translateX(-102%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 0;
    background: rgba(4, 8, 18, 0.55);
    z-index: 40;
  }
}

@media print {
  .topbar, .sidebar, .outline, .prevnext, .reading-progress, .footer { display: none !important; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  body { background: #fff; color: #000; }
}
