:root {
  --bg: #f5f2eb;
  --bg-grid: rgba(30, 85, 135, 0.06);
  --card: rgba(255, 252, 247, 0.84);
  --card-strong: rgba(255, 255, 255, 0.92);
  --ink: #19314a;
  --muted: #5f7388;
  --line: rgba(16, 44, 73, 0.1);
  --brand: #165b8f;
  --brand-strong: #0f3a5d;
  --teal: #1b7f6b;
  --orange: #b36a18;
  --red: #a34e35;
  --shadow: 0 24px 56px rgba(15, 39, 64, 0.1);
  --mono: 'JetBrains Mono', 'Cascadia Mono', 'Consolas', ui-monospace, monospace;
  --sans: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', 'Helvetica Neue', sans-serif;
  --serif: 'Songti SC', 'STSong', 'Noto Serif CJK SC', serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  min-height: 100vh;
  background:
    linear-gradient(90deg, transparent 31px, var(--bg-grid) 32px, transparent 33px),
    linear-gradient(transparent 31px, var(--bg-grid) 32px, transparent 33px),
    radial-gradient(circle at top left, rgba(16, 91, 143, 0.12), transparent 26%),
    radial-gradient(circle at bottom right, rgba(179, 106, 24, 0.1), transparent 22%),
    var(--bg);
  background-size: 32px 32px, 32px 32px, auto, auto, auto;
}

#app,
.app-shell {
  min-height: 100vh;
}

body,
input,
button {
  font-family: var(--sans);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.boot-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
  padding: calc(16px + env(safe-area-inset-top)) 28px 16px;
  background: rgba(245, 242, 235, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar-actions {
  display: flex;
  justify-content: flex-end;
}

.brand-mark {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark strong {
  font-family: var(--serif);
  font-size: 1.5rem;
  letter-spacing: 0.02em;
}

.brand-kicker,
.hero-kicker {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--brand);
}

.topnav {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.topnav a,
.mobile-tabbar a,
.context-card a,
.rail-group a,
.tree-link-list a,
.stack-item,
.result-card,
.feature-card,
.related-item,
.quick-card,
.primary-link,
.ghost-link,
.panel-head a,
.crumb-row a {
  text-decoration: none;
  color: inherit;
}

.topnav a {
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 700;
  color: var(--muted);
}

.topnav a:hover,
.topnav a.active {
  background: rgba(22, 91, 143, 0.12);
  color: var(--brand-strong);
}

.search-button,
.menu-button,
.close-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 14px;
  background: var(--brand-strong);
  color: #fff;
  font-weight: 700;
  padding: 12px 16px;
  cursor: pointer;
}

.drawer-backdrop {
  display: none;
}

.page-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 240px;
  gap: 24px;
  padding: 24px;
}

.left-rail,
.right-rail {
  position: sticky;
  top: calc(92px + env(safe-area-inset-top));
  align-self: start;
}

.left-rail {
  max-height: calc(100vh - 124px - env(safe-area-inset-top));
  background: rgba(250, 248, 244, 0.74);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.rail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.rail-head p,
.context-card p,
.tree-head span,
.panel-head a,
.doc-excerpt,
.stack-item span,
.result-card span,
.related-item span,
.feature-tag {
  color: var(--muted);
}

.rail-scroll {
  max-height: calc(100vh - 184px - env(safe-area-inset-top));
  overflow: auto;
  padding: 14px 18px 24px;
}

.rail-section + .rail-section {
  margin-top: 22px;
}

.rail-section h3,
.tree-head h2,
.panel-head h2,
.doc-head h1,
.search-head h1,
.missing-view h1 {
  margin: 0;
  font-family: var(--serif);
}

.rail-group + .rail-group {
  margin-top: 14px;
}

.rail-group-title {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.rail-group {
  display: grid;
  gap: 8px;
}

.rail-group a,
.context-card a {
  line-height: 1.55;
}

.main-stage {
  min-width: 0;
  display: grid;
  gap: 24px;
}

.card-surface,
.panel-card,
.tree-card,
.context-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.hero-card {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(260px, 0.75fr);
  gap: 24px;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(15, 58, 93, 0.96), rgba(22, 91, 143, 0.82)),
    var(--brand-strong);
  color: #f8fbff;
  border-radius: 30px;
  box-shadow: 0 24px 60px rgba(11, 37, 58, 0.24);
}

.hero-card .hero-kicker,
.hero-card .hero-text,
.hero-card .hero-stats span {
  color: rgba(244, 248, 255, 0.8);
}

.hero-card h1,
.view-header h1,
.search-head h1,
.missing-view h1 {
  margin: 10px 0 14px;
  font-family: var(--serif);
  font-size: clamp(2rem, 4vw, 3.3rem);
  line-height: 1.08;
}

.hero-text {
  max-width: 60ch;
  line-height: 1.8;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.primary-link,
.ghost-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 800;
}

.primary-link {
  background: #f6efe2;
  color: var(--brand-strong);
}

.ghost-link {
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
}

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

.hero-stats article {
  display: grid;
  gap: 6px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.hero-stats strong {
  font-size: 2rem;
}

.two-up {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}

.panel-card,
.tree-card,
.context-card,
.doc-head,
.doc-body,
.loading-card,
.view-header,
.search-panel,
.missing-view {
  padding: 24px;
}

.panel-head,
.tree-head,
.search-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.quick-grid,
.feature-grid,
.related-grid,
.tree-sections {
  display: grid;
  gap: 16px;
}

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

.quick-card,
.feature-card,
.related-item,
.stack-item,
.result-card {
  display: grid;
  gap: 8px;
  padding: 18px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--card-strong);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.quick-card:hover,
.feature-card:hover,
.related-item:hover,
.stack-item:hover,
.result-card:hover,
.tree-link-list a:hover,
.rail-group a:hover,
.context-card a:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 28px rgba(17, 42, 67, 0.1);
  border-color: rgba(22, 91, 143, 0.22);
}

.quick-card span,
.feature-card h3,
.related-item strong,
.stack-item strong,
.result-card strong,
.tree-link-list a {
  font-weight: 800;
}

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

.feature-card {
  min-height: 200px;
}

.theme-blue { border-top: 4px solid var(--brand); }
.theme-teal { border-top: 4px solid var(--teal); }
.theme-orange { border-top: 4px solid var(--orange); }
.theme-red { border-top: 4px solid var(--red); }

.accent-blue { border-left: 5px solid var(--brand); }
.accent-green { border-left: 5px solid var(--teal); }
.accent-orange { border-left: 5px solid var(--orange); }
.accent-red { border-left: 5px solid var(--red); }

.stack-list,
.related-grid,
.search-results {
  display: grid;
  gap: 12px;
}

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

.tree-group-block + .tree-group-block {
  margin-top: 16px;
}

.tree-group-block p {
  margin: 0 0 10px;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--muted);
}

.tree-link-list {
  display: grid;
  gap: 10px;
}

.tree-link-list a {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255,255,255,0.78);
  border: 1px solid var(--line);
}

.search-panel input {
  width: 100%;
  min-height: 54px;
  padding: 0 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fffdfa;
  font-size: 1rem;
  outline: none;
}

.search-panel input:focus {
  border-color: rgba(22, 91, 143, 0.38);
  box-shadow: 0 0 0 4px rgba(22, 91, 143, 0.08);
}

.doc-head h1 {
  font-size: clamp(2rem, 3.2vw, 2.8rem);
  line-height: 1.15;
}

.crumb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.crumb-row a {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(22, 91, 143, 0.08);
  font-size: 0.9rem;
}

.doc-body {
  overflow: hidden;
}

.doc-body h1,
.doc-body h2,
.doc-body h3,
.doc-body h4 {
  font-family: var(--serif);
  line-height: 1.22;
  color: var(--brand-strong);
}

.doc-body h1 { font-size: 2.2rem; }
.doc-body h2 { font-size: 1.65rem; margin-top: 2.2rem; }
.doc-body h3 { font-size: 1.28rem; margin-top: 1.6rem; }

.doc-body p,
.doc-body li,
.doc-body blockquote {
  line-height: 1.85;
}

.doc-body pre,
.doc-body code {
  font-family: var(--mono);
}

.doc-body pre {
  overflow: auto;
  padding: 16px;
  border-radius: 18px;
  background: #142437;
  color: #ecf5ff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05);
}

.doc-body :not(pre) > code {
  padding: 0.18em 0.42em;
  border-radius: 8px;
  background: rgba(15, 58, 93, 0.08);
  color: var(--brand-strong);
  word-break: break-word;
}

.doc-body blockquote {
  margin: 1.2rem 0;
  padding: 14px 18px;
  border-left: 4px solid var(--brand);
  background: rgba(22, 91, 143, 0.06);
  border-radius: 0 16px 16px 0;
}

.table-wrap {
  overflow: auto;
  margin: 1rem 0;
}

.doc-body table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  background: rgba(255,255,255,0.78);
  border-radius: 18px;
  overflow: hidden;
}

.doc-body th,
.doc-body td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.doc-body th {
  background: rgba(22, 91, 143, 0.08);
  font-weight: 800;
}

.doc-body a {
  color: var(--brand);
}

.doc-body .header-anchor {
  margin-left: 8px;
  opacity: 0.35;
  text-decoration: none;
}

.doc-body .header-anchor:hover {
  opacity: 1;
}

.doc-body .mermaid-panel {
  overflow: auto;
  margin: 1rem 0;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
}

.context-card {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.context-card a.level-3 {
  padding-left: 12px;
  color: var(--muted);
}

.empty-state {
  padding: 18px;
  border-radius: 18px;
  background: rgba(255,255,255,0.72);
  border: 1px dashed rgba(16, 44, 73, 0.15);
}

.mobile-only {
  display: none;
}

.mobile-tabbar {
  display: none;
}

.feature-card p,
.result-card p,
.related-item span,
.stack-item span,
.doc-excerpt {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
}

.feature-card p,
.result-card p,
.related-item span,
.doc-excerpt {
  -webkit-line-clamp: 3;
}

.stack-item span {
  -webkit-line-clamp: 2;
}

@media (max-width: 1180px) {
  .page-layout {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .right-rail {
    display: none;
  }

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

@media (max-width: 960px) {
  .app-shell.drawer-open {
    height: 100vh;
    overflow: hidden;
  }

  .topbar {
    grid-template-columns: 46px minmax(0, 1fr) 46px;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    background: rgba(247, 244, 238, 0.98);
    backdrop-filter: none;
  }

  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: inline-flex;
  }

  .page-layout {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 12px 12px calc(98px + env(safe-area-inset-bottom));
  }

  .left-rail {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    width: min(88vw, 360px);
    max-height: none;
    transform: translateX(-110%);
    transition: transform 220ms ease;
    border-radius: 0 26px 26px 0;
    background: #f7f4ee;
    box-shadow: 0 18px 42px rgba(10, 28, 46, 0.24);
  }

  .left-rail.open {
    transform: translateX(0);
  }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    border: 0;
    padding: 0;
    background: rgba(12, 28, 46, 0.32);
  }

  .rail-head {
    position: sticky;
    top: 0;
    z-index: 1;
    padding-top: calc(14px + env(safe-area-inset-top));
    background: #f7f4ee;
  }

  .rail-scroll {
    max-height: calc(100vh - 88px - env(safe-area-inset-top));
    padding-bottom: calc(120px + env(safe-area-inset-bottom));
  }

  .rail-group a {
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--line);
  }

  .brand-mark {
    gap: 1px;
  }

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

  .brand-kicker {
    font-size: 0.58rem;
    letter-spacing: 0.16em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .hero-card h1,
  .view-header h1,
  .search-head h1,
  .missing-view h1 {
    font-size: clamp(1.7rem, 7vw, 2.2rem);
  }

  .hero-text,
  .doc-body p,
  .doc-body li,
  .doc-excerpt {
    font-size: 0.96rem;
  }

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

  .hero-card,
  .two-up,
  .feature-grid,
  .tree-sections,
  .quick-grid {
    grid-template-columns: 1fr;
  }

  .hero-card {
    padding: 22px 18px;
    border-radius: 24px;
  }

  .panel-card,
  .tree-card,
  .context-card,
  .doc-head,
  .doc-body,
  .loading-card,
  .view-header,
  .search-panel,
  .missing-view {
    padding: 18px 16px;
    border-radius: 22px;
    background: #fffdf8;
    box-shadow: 0 14px 30px rgba(15, 39, 64, 0.08);
  }

  .doc-head h1,
  .doc-body h1 {
    font-size: 1.8rem;
  }

  .doc-body h2 {
    font-size: 1.38rem;
  }

  .doc-body h3 {
    font-size: 1.14rem;
  }

  .doc-body table {
    min-width: 560px;
  }

  .mobile-tabbar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 44;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    border-radius: 18px;
    background: rgba(15, 58, 93, 0.98);
    box-shadow: 0 14px 32px rgba(15, 39, 64, 0.2);
  }

  .app-shell.drawer-open .mobile-tabbar {
    opacity: 0;
    pointer-events: none;
    transform: translateY(18px);
  }

  .mobile-tabbar a {
    display: grid;
    place-items: center;
    min-height: 38px;
    font-size: 0.76rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.86);
    border-radius: 12px;
  }

  .mobile-tabbar a.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.14);
  }

  .menu-button,
  .search-button,
  .close-button {
    min-height: 42px;
    min-width: 42px;
    padding: 0;
    border-radius: 12px;
  }

  .topbar-actions .search-button {
    width: 42px;
  }

  .panel-head {
    align-items: center;
  }

  .panel-head a {
    font-size: 0.86rem;
  }
}
