:root {
  --bg: #f4f6f8;
  --paper: #ffffff;
  --ink: #1d2733;
  --muted: #667085;
  --line: #d8dee8;
  --line-strong: #bcc7d6;
  --accent: #0f6b78;
  --accent-dark: #0a4f59;
  --accent-soft: #e8f4f6;
  --warn-soft: #fff7ed;
  --shadow: 0 20px 55px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Serif SC", "Source Han Serif SC", "Microsoft YaHei", serif;
  font-size: 17px;
  line-height: 1.82;
}

body { margin: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  min-height: 54px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: baseline;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}

.brand strong {
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand span {
  color: var(--muted);
  font-size: 0.84rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.button {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--paper);
  color: var(--accent-dark);
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 0.88rem;
  line-height: 1.35;
  text-decoration: none;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.site-main {
  max-width: 1180px;
  margin: 28px auto 80px;
  padding: 0 22px;
}

.catalog-intro {
  margin-bottom: 20px;
  padding: 26px 0 18px;
  border-bottom: 1px solid var(--line);
}

.catalog-intro h1 {
  margin: 0 0 8px;
  color: #17202b;
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 1.9rem;
  line-height: 1.28;
}

.catalog-intro p {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
}

.book-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  padding: 0;
  list-style: none;
}

.book-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 210px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.book-card h2 {
  margin: 0;
  color: #17202b;
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 1.2rem;
  line-height: 1.35;
}

.book-card p {
  margin: 0;
  color: var(--muted);
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 0.94rem;
  line-height: 1.65;
}

.book-card .meta {
  color: var(--accent-dark);
  font-weight: 600;
}

.book-card .card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

.reader-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 12px 36px rgba(16, 24, 40, 0.06);
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
}

.sidebar h2 {
  margin: 0 0 10px;
  color: #17202b;
  font-size: 1rem;
  line-height: 1.35;
}

.sidebar .audience {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.chapter-nav {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chapter-nav a {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  padding: 7px 8px;
  border-radius: 6px;
  color: #344054;
  text-decoration: none;
}

.chapter-nav a:hover,
.chapter-nav a.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.chapter-nav .num {
  color: var(--muted);
  font-size: 0.78rem;
}

.chapter-nav .name {
  overflow: hidden;
  font-size: 0.84rem;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content {
  min-width: 0;
  padding: 40px 44px 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.content h1,
.content h2,
.content h3,
.content h4 {
  color: #17202b;
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  line-height: 1.35;
}

.content h1 {
  margin-top: 0;
  padding-bottom: 0.45em;
  border-bottom: 3px solid var(--accent);
  font-size: 1.85rem;
}

.content h2 {
  margin-top: 2.2em;
  padding-left: 0.72em;
  border-left: 5px solid var(--accent);
  font-size: 1.35rem;
}

.content h3 {
  margin-top: 1.8em;
  font-size: 1.12rem;
}

.content a { color: var(--accent-dark); }

.content blockquote {
  margin: 1.35em 0;
  padding: 1em 1.2em;
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #f5f8fa;
  color: #303947;
}

.content pre {
  overflow-x: auto;
  padding: 1em 1.1em;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #16202a;
  color: #eef6f8;
  line-height: 1.65;
}

.content code {
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 0.92em;
}

.content p code,
.content li code,
.content td code {
  padding: 0.12em 0.35em;
  border-radius: 6px;
  background: var(--accent-soft);
  color: #175d65;
}

.content table {
  width: 100%;
  margin: 1.4em 0;
  border-collapse: collapse;
  font-size: 0.95em;
}

.content th,
.content td {
  padding: 0.72em 0.8em;
  border: 1px solid var(--line);
  vertical-align: top;
}

.content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.25em auto;
  border-radius: 6px;
}

.content figure { margin: 1.6em 0; }

.content figcaption {
  color: var(--muted);
  font-size: 0.92em;
  text-align: center;
}

.notice {
  margin: 0 0 1.3em;
  padding: 12px 14px;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  background: var(--warn-soft);
  color: #7c2d12;
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 0.92rem;
}

@media (max-width: 960px) {
  .reader-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }

  .chapter-nav {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

@media (max-width: 720px) {
  html { font-size: 16px; }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 16px;
  }

  .brand {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .site-main {
    margin: 0;
    padding: 0;
  }

  .catalog-intro {
    padding: 22px 16px 16px;
  }

  .book-list {
    grid-template-columns: 1fr;
    padding: 0 16px 30px;
  }

  .reader-layout {
    gap: 0;
  }

  .sidebar,
  .content {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .content {
    padding: 28px 18px 56px;
  }
}

body.compare-page {
  overflow: hidden;
}

.compare-reader-layout {
  grid-template-columns: minmax(210px, 250px) minmax(0, 1fr);
  align-items: stretch;
  max-width: none;
  height: calc(100vh - 55px);
  height: calc(100dvh - 55px);
  min-height: 0;
  margin: 0;
  padding: 14px 16px 16px;
}

.compare-reader-layout .sidebar {
  top: 0;
  max-height: 100%;
}

.compare-workspace {
  display: flex;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  flex-direction: column;
  gap: 10px;
}

.compare-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 0.86rem;
}

.compare-toolbar strong {
  color: var(--ink);
}

.sync-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.compare-panes {
  display: grid;
  min-height: 0;
  overflow: hidden;
  flex: 1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.compare-pane {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  scrollbar-gutter: stable;
}

.compare-pane .pane-label {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
  color: var(--accent-dark);
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
}

.compare-pane.current .pane-label {
  background: #effaf6;
  color: #166044;
}

.compare-pane .content {
  padding: 30px 34px 64px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.compare-pane .content h1 {
  font-size: 1.55rem;
}

.compare-pane .content h2 {
  font-size: 1.2rem;
}

.version-overview {
  min-height: 100%;
}

.version-overview .chapter-nav {
  margin-top: 1.2rem;
}

@media (max-width: 1080px) {
  body.compare-page {
    overflow: auto;
  }

  .compare-reader-layout {
    height: auto;
    min-height: auto;
    grid-template-columns: 1fr;
  }

  .compare-reader-layout .sidebar {
    position: static;
    max-height: none;
  }

  .compare-workspace {
    height: auto;
    overflow: visible;
  }

  .compare-panes {
    display: block;
    overflow: visible;
  }

  .compare-pane {
    height: auto;
    margin-bottom: 14px;
    overflow: visible;
  }

  .sync-control {
    display: none;
  }
}

@media (max-width: 720px) {
  .compare-reader-layout {
    padding: 0;
  }

  .compare-toolbar,
  .compare-pane {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .compare-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .compare-pane .content {
    padding: 28px 18px 56px;
  }
}
