:root {
  color-scheme: light;
  --bg: #f4f0e8;
  --paper: #fffdf8;
  --paper-strong: #ffffff;
  --ink: #211a12;
  --muted: #6f665b;
  --subtle: #9b8f80;
  --line: rgba(62, 48, 34, .13);
  --accent: #9b5b24;
  --accent-strong: #6f3d16;
  --accent-soft: rgba(155, 91, 36, .11);
  --green: #315f42;
  --shadow: 0 24px 70px rgba(73, 55, 34, .10), 0 2px 12px rgba(73, 55, 34, .06);
  --nav: 316px;
  --toc: 316px;
  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-heading: "Songti SC", "STSong", "SimSun", serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(155, 91, 36, .16), transparent 28%),
    radial-gradient(circle at 92% 12%, rgba(49, 95, 66, .12), transparent 30%),
    linear-gradient(135deg, #fbf7ef 0%, #f4efe6 52%, #eee6d9 100%);
  font-family: var(--font-body);
  font-size: 15px;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(89, 66, 42, .045) 1px, transparent 1px), linear-gradient(90deg, rgba(89, 66, 42, .04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at 50% 12%, #000 0%, transparent 68%);
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--nav) minmax(0, 1fr);
  gap: 22px;
  min-height: 100vh;
  padding: 22px;
}

.sidebar {
  position: sticky;
  top: 22px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 44px);
  padding: 18px;
  overflow: hidden;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 253, 248, .94), rgba(255, 253, 248, .78));
  border: 1px solid rgba(255, 255, 255, .8);
  border-radius: 28px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .95);
  backdrop-filter: blur(20px) saturate(1.2);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 8px;
}

.brand a {
  display: block;
}

.brand-title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.04em;
}

.brand-subtitle {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.generated-at {
  display: inline;
  color: var(--subtle);
  font-size: 12px;
}

.font-select {
  border: none;
  background: none;
  color: var(--subtle);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  vertical-align: baseline;
}

.font-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.search-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.search-box input,
.search-box select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .7);
  color: var(--ink);
  outline: none;
}

.search-box input {
  padding: 11px 13px;
}

.search-box select {
  padding: 0 8px;
}

.search-box input:focus,
.search-box select:focus {
  border-color: rgba(155, 91, 36, .45);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.site-nav {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(111, 102, 91, .32) transparent;
}

.nav-group {
  margin: 18px 0 0;
}

.nav-group-secondary {
  opacity: .82;
}

.nav-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 2px 8px;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .11em;
}

.nav-group-title span,
.nav-entry-link small,
.nav-section summary span {
  color: var(--subtle);
  font-size: 11px;
  font-weight: 700;
}

.nav-entry,
.nav-section {
  margin: 4px 0;
}

.nav-entry > summary,
.nav-section > summary {
  list-style: none;
}

.nav-entry > summary::-webkit-details-marker,
.nav-section > summary::-webkit-details-marker {
  display: none;
}

.nav-entry-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 11px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.nav-entry-link:hover,
.nav-entry-link.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.nav-section-list {
  margin: 4px 0 8px 9px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.nav-section summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.nav-section summary:hover {
  background: rgba(255, 255, 255, .55);
}

.nav-doc-list {
  display: grid;
  gap: 2px;
  margin: 2px 0 8px 7px;
  padding-left: 8px;
  border-left: 1px dashed var(--line);
}

.nav-doc,
.nav-more {
  display: block;
  padding: 6px 7px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.nav-doc:hover,
.nav-doc.active {
  color: var(--accent-strong);
  background: rgba(155, 91, 36, .08);
}

.nav-more {
  color: var(--subtle);
}

.mobile-menu,
.nav-scrim {
  display: none;
}

.content-shell {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 18px;
  pointer-events: none;
}

.topbar-note {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, .75);
  color: var(--muted);
  font-size: 12px;
  backdrop-filter: blur(12px);
}

.main-content {
  display: grid;
  gap: 18px;
  width: 100%;
  scroll-margin-top: 22px;
}

.hero,
.entry-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(260px, .7fr);
  gap: 28px;
  padding: clamp(20px, 3vw, 36px);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.hero h1,
.entry-hero h1,
.search-page h1,
.reader-header h1 {
  margin: 0;
  font-family: var(--font-heading);
  letter-spacing: -.045em;
}

.hero h1 {
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1.2;
}

.hero-subtitle {
  margin: 8px 0 0;
  color: var(--accent-strong);
  font-size: clamp(16px, 2vw, 22px);
  font-weight: 850;
}

.hero-text,
.entry-hero p {
  max-width: 700px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.7;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 17px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
  color: var(--accent-strong);
  font-weight: 800;
}

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

.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-content: end;
}

.entry-stats {
  display: flex;
  gap: 8px;
  align-self: center;
}

.entry-stats .stat {
  min-height: auto;
  padding: 8px 14px;
  border-radius: 12px;
  text-align: center;
}

.entry-stats .stat strong {
  font-size: 20px;
}

.entry-stats .stat span {
  margin-top: 2px;
  font-size: 11px;
}

.stat {
  min-height: auto;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, .56);
}

.stat strong {
  display: block;
  font-size: 26px;
  line-height: 1;
}

.stat span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.section-block {
  display: grid;
  gap: 16px;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 0 4px;
}

.section-heading .eyebrow {
  margin-bottom: 0;
}

.section-heading h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 28px;
  letter-spacing: -.035em;
}

.section-heading.compact h2 {
  font-size: 26px;
}

.course-grid,
.feature-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.course-card,
.feature-card,
.doc-card,
.section-card,
.search-page {
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, .78);
  box-shadow: 0 10px 30px rgba(73, 55, 34, .05);
}

.course-card,
.feature-card,
.doc-card {
  display: block;
  border-radius: 22px;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.course-card {
  min-height: 172px;
  padding: 16px 18px;
}

.course-card:hover,
.feature-card:hover,
.doc-card:hover {
  transform: translateY(-2px);
  border-color: rgba(155, 91, 36, .32);
  box-shadow: 0 18px 45px rgba(73, 55, 34, .09);
}

.course-title-row {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.course-index {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.38;
  letter-spacing: .04em;
}

.course-title-row h3 {
  margin: 0;
}

.course-card h3,
.feature-card h3,
.doc-card h3 {
  margin: 12px 0 0;
  font-size: 18px;
  line-height: 1.38;
}

.course-card p,
.feature-card p,
.doc-card p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.68;
}

.course-card small,
.feature-card small,
.doc-card small {
  display: block;
  margin-top: 10px;
  color: var(--subtle);
  line-height: 1.45;
}

.feature-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.feature-card {
  min-height: 190px;
  padding: 20px;
}

.feature-card > span,
.type-pill {
  display: inline-flex;
  width: fit-content;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--subtle);
  font-size: 13px;
}

.breadcrumbs a {
  color: var(--accent-strong);
  font-weight: 800;
}

.breadcrumbs > * + *::before {
  content: '/';
  margin-right: 8px;
  color: var(--subtle);
}

.entry-hero h1,
.search-page h1 {
  font-size: clamp(24px, 3vw, 36px);
}

.entry-hero {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  padding: clamp(18px, 3vw, 30px);
  align-items: center;
}

.entry-hero p {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 0;
}

.doc-list,
.section-list {
  display: grid;
  gap: 12px;
}

.doc-card {
  padding: 16px;
}

.doc-card h3 {
  font-size: 17px;
}

.section-card {
  border-radius: 24px;
  padding: 8px;
}

.section-card > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  list-style: none;
  cursor: pointer;
  font-size: 17px;
  font-weight: 850;
}

.section-card > summary::-webkit-details-marker {
  display: none;
}

.section-card > summary small {
  color: var(--subtle);
  font-size: 12px;
}

.featured-docs {
  grid-template-columns: 1fr;
}

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

.reader {
  width: 100%;
  padding: clamp(24px, 4vw, 56px);
  padding-bottom: clamp(24px, 4vw, 56px);
  min-width: 0;
}

.reader-header {
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.reader-header h1 {
  font-size: clamp(22px, 2.5vw, 30px);
  line-height: 1.25;
}

.reader-path {
  margin: 16px 0 0;
  color: var(--subtle);
  font-size: 13px;
  word-break: break-all;
}

.markdown-body {
  color: #261d14;
  font-size: 15.5px;
  line-height: 1.9;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: .8em 0 .5em;
  font-family: var(--font-heading);
  line-height: 1.35;
  letter-spacing: -.02em;
  scroll-margin-top: 24px;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1 { font-size: 24px; }
.markdown-body h2 { font-size: 17px; }
.markdown-body h3 { font-size: 16px; }
.markdown-body h4 { font-size: 15px; }

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table {
  margin: 1.05em 0;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1.2em 0;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.6em;
}

.markdown-body li + li {
  margin-top: .35em;
}

.markdown-body blockquote {
  padding: 10px 16px;
  margin: .6em 0;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--muted);
}

.markdown-body code {
  padding: 2px 6px;
  border-radius: 7px;
  background: rgba(49, 95, 66, .11);
  color: var(--green);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: .92em;
}

.markdown-body pre {
  overflow-x: auto;
  padding: 16px;
  border-radius: 18px;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--ink);
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.table-wrap {
  overflow-x: auto;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 12px;
  overflow: hidden;
  font-size: 14px;
}

.markdown-body th,
.markdown-body td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  vertical-align: top;
}

.markdown-body th {
  background: var(--accent-soft);
  text-align: left;
}

.markdown-body a {
  color: var(--accent-strong);
  border-bottom: 1px solid rgba(155, 91, 36, .28);
}

.toc {
  position: sticky;
  top: 22px;
  display: grid;
  gap: 6px;
  max-height: calc(100vh - 44px);
  padding: 18px;
  overflow-y: auto;
}

.toc-title {
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .12em;
}

.toc-link {
  display: block;
  padding: 6px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.toc-link:hover {
  color: var(--accent-strong);
}

.toc-link.level-3 { padding-left: 12px; }
.toc-link.level-4 { padding-left: 24px; }

.search-page {
  padding: clamp(24px, 4vw, 42px);
  border-radius: 28px;
}

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 22px 0 12px;
}

.filter-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .62);
  color: var(--muted);
  padding: 8px 13px;
  font-weight: 800;
}

.filter-tab.active {
  border-color: transparent;
  background: var(--accent-strong);
  color: #fffaf1;
}

.search-count,
.empty {
  color: var(--muted);
}

mark {
  padding: 0 2px;
  border-radius: 4px;
  background: rgba(255, 213, 87, .55);
  color: inherit;
}

.fatal {
  max-width: 720px;
  margin: 10vh auto;
  padding: 32px;
  border-radius: 24px;
  background: #fff;
}

@media (max-width: 1320px) {
  .course-grid,
  .feature-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .reader-layout {
    grid-template-columns: minmax(0, 1fr);
  }

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

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(86vw, 360px);
    height: 100vh;
    border-radius: 0 26px 26px 0;
    transform: translateX(-105%);
    transition: transform .22s ease;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .nav-scrim {
    position: fixed;
    inset: 0;
    z-index: 19;
    display: none;
    background: rgba(27, 21, 15, .28);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }

  body.nav-open .nav-scrim {
    display: none;
  }

  .mobile-menu {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 18;
    display: inline-flex;
    border: none;
    border-radius: 999px;
    background: var(--accent-strong);
    color: #fffaf1;
    padding: 13px 18px;
    font-weight: 900;
    box-shadow: var(--shadow);
  }

  .topbar {
    justify-content: flex-start;
  }

  .hero,
  .entry-hero {
    grid-template-columns: 1fr;
  }

  .course-grid,
  .feature-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .hero,
  .entry-hero,
  .reader,
  .search-page {
    border-radius: 22px;
    padding: 22px;
  }

  .hero-stats,
  .entry-stats,
  .course-grid,
  .feature-grid,
  .featured-docs {
    grid-template-columns: 1fr;
  }

  .search-box {
    grid-template-columns: 1fr;
  }

  .section-heading {
    display: block;
  }

  .markdown-body {
    font-size: 16px;
  }
}

@media print {
  body { background: #fff; }
  body::before,
  .sidebar,
  .topbar,
  .toc,
  .mobile-menu,
  .nav-scrim { display: none !important; }
  .app-shell { display: block; padding: 0; }
  .panel { box-shadow: none; border: none; }
  .reader { padding: 0; }
}

.markdown-body.loading {
  color: var(--text-muted, #888);
  text-align: center;
  padding: 3rem 2rem;
  font-size: 0.95rem;
}
