:root {
  /* VitePress-like tokens (light) */
  --bg: #ffffff;
  --panel: #f6f6f7;
  --text: #213547;
  --muted: rgba(60, 60, 67, 0.78);
  --border: rgba(60, 60, 67, 0.16);
  --link: #6366f1;
  --codebg: rgba(142, 150, 170, 0.14);
  --brand-soft: rgba(99, 102, 241, 0.14);
  --brand-outline: rgba(99, 102, 241, 0.35);
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* VitePress-like tokens (dark) */
    --bg: #1b1b1f;
    --panel: #202127;
    --text: rgba(255, 255, 245, 0.86);
    --muted: rgba(235, 235, 245, 0.6);
    --border: rgba(82, 82, 89, 0.5);
    --link: #a5b4fc;
    --codebg: rgba(101, 117, 133, 0.25);
    --brand-soft: rgba(165, 180, 252, 0.14);
    --brand-outline: rgba(165, 180, 252, 0.35);
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow: hidden;
}

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

a:hover { text-decoration: underline; }

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
  min-height: 0;
}

.brand {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  box-shadow: var(--shadow);
}

.brand .title {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
}

.brand .subtitle {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.nav {
  padding: 10px 8px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  overscroll-behavior: contain;
}

.nav {
  background: var(--bg);
}

.nav-divider {
  margin: 10px 10px 6px;
  padding: 6px 8px;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.nav a {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
}

.nav a:hover {
  background: rgba(142, 150, 170, 0.12);
  text-decoration: none;
}

.nav a.active {
  background: var(--brand-soft);
  outline: 1px solid var(--brand-outline);
}

.footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-brand {
  font-weight: 650;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
}

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

.topbar-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
}

@media (prefers-color-scheme: dark) {
  .topbar {
    background: rgba(32, 33, 39, 0.72);
  }
}

.current-title {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 44vw;
}

.spacer { flex: 1; }

.raw {
  color: var(--muted);
  font-size: 13px;
}

.raw:hover {
  text-decoration: none;
  color: var(--link);
}

.search {
  position: relative;
  width: min(520px, 48vw);
}

.search-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(142, 150, 170, 0.12);
  color: var(--text);
  outline: none;
}

.search-input::placeholder { color: rgba(170, 179, 207, 0.8); }

@media (prefers-color-scheme: light) {
  .search-input::placeholder { color: rgba(60, 60, 67, 0.6); }
}

.search-input:focus {
  border-color: var(--brand-outline);
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 52vh;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  z-index: 20;
}

@media (prefers-color-scheme: dark) {
  .search-results {
    background: rgba(32, 33, 39, 0.98);
  }
}

.search-item {
  display: block;
  padding: 10px 10px;
  border-radius: 12px;
}

.search-item:hover {
  background: rgba(142, 150, 170, 0.12);
  text-decoration: none;
}

.search-item-title {
  font-weight: 650;
  font-size: 13px;
  color: var(--text);
}

.search-item-snippet {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content {
  padding: 18px 22px;
  overflow: auto;
  line-height: 1.65;
  background: var(--bg);
  flex: 1;
  min-height: 0;
  overscroll-behavior: contain;
}

.content {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

.toc {
  border: 1px solid var(--border);
  background: rgba(142, 150, 170, 0.08);
  border-radius: 14px;
  padding: 12px 12px;
  margin: 4px 0 14px;
}

.toc-title {
  font-weight: 650;
  margin-bottom: 6px;
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toc-item {
  color: var(--muted);
  font-size: 13px;
}

.toc-item:hover { color: var(--text); }

.toc-h3 { padding-left: 14px; }

.chapter-checklist {
  border: 1px solid var(--brand-outline);
  background: var(--brand-soft);
  border-radius: 14px;
  padding: 12px 12px;
  margin: 4px 0 14px;
  position: relative;
}

.checklist-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 8px;
}

.checklist-title { font-weight: 700; }

.checklist-progress {
  font-size: 12px;
  color: var(--muted);
}

.checklist-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checklist-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.checklist-item input { margin-top: 3px; }

.checklist-item-text { color: var(--text); }

.content h1, .content h2, .content h3 {
  line-height: 1.25;
}

.content h1 { font-size: 26px; margin: 10px 0 14px; }
.content h2 { font-size: 20px; margin: 22px 0 10px; }
.content h3 { font-size: 16px; margin: 18px 0 8px; }

.content p, .content li { color: var(--text); }
.content ul { padding-left: 18px; }

.content code {
  background: var(--codebg);
  padding: 2px 6px;
  border-radius: 8px;
}

.content pre {
  background: var(--codebg);
  padding: 12px;
  border-radius: 14px;
  overflow: auto;
  border: 1px solid var(--border);
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(142, 150, 170, 0.12);
  color: var(--text);
  cursor: pointer;
}

.copy-btn:hover {
  background: rgba(142, 150, 170, 0.18);
}

.pager {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: var(--bg);
}

.btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.btn:hover { background: rgba(142, 150, 170, 0.12); }

@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar {
    padding: 0 14px;
  }
  .current-title {
    max-width: 52vw;
  }
}
