:root {
  --bg: #f4f6f8;
  --bg-elev: #eef2f5;
  --panel: #ffffff;
  --panel-soft: #f9fbfc;
  --text: #1f2730;
  --muted: #667788;
  --accent: #8c5dd6;
  --accent-soft: rgba(140, 93, 214, 0.12);
  --line: #d7dde5;
  --line-strong: #bcc7d3;
  --code-bg: #edf3f7;
  --shadow: none;
  --reading-width: 76ch;
}

html[data-theme="dark"] {
  --bg: #1a2028;
  --bg-elev: #1f2630;
  --panel: #232b36;
  --panel-soft: #1f2731;
  --text: #dde5ef;
  --muted: #9ba8b8;
  --accent: #c5a7ff;
  --accent-soft: rgba(197, 167, 255, 0.16);
  --line: #344050;
  --line-strong: #465568;
  --code-bg: #2a3442;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--code-bg);
  color: var(--text);
  padding: 0.1rem 0.32rem;
  border-radius: 0.28rem;
}
.topbar {
  position: sticky; top: 0; z-index: 30; display: grid;
  grid-template-columns: auto minmax(200px, 360px) minmax(240px, 1fr) minmax(280px, 420px);
  gap: 0.8rem; align-items: center; padding: 0.75rem 0.95rem;
  border-bottom: 1px solid var(--line); background: var(--panel-soft);
}
.topbar h1 { margin: 0; font-size: 0.98rem; letter-spacing: 0.07em; }
.subtitle { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.75rem; line-height: 1.35; }
.menu-btn, .theme-btn, .addr-jump button {
  height: 2.15rem; border: 1px solid var(--line-strong); border-radius: 0.45rem;
  background: var(--panel); color: var(--text); cursor: pointer;
}
.menu-btn { width: 2.2rem; font-size: 1rem; }
.topbar-main { min-width: 0; }
.search-wrap { position: relative; }
#site-search {
  width: 100%; height: 2.2rem; border-radius: 0.45rem; border: 1px solid var(--line-strong);
  background: var(--panel); color: var(--text); padding: 0 0.75rem; font-size: 0.88rem;
}
.topbar-actions { display: flex; gap: 0.55rem; align-items: center; justify-content: flex-end; }
.addr-jump { display: grid; grid-template-columns: minmax(130px, 1fr) auto; gap: 0.45rem; width: min(100%, 290px); }
#addr-jump {
  height: 2.15rem; border-radius: 0.45rem; border: 1px solid var(--line-strong); background: var(--panel);
  color: var(--text); padding: 0 0.62rem; font-size: 0.83rem;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#addr-jump.invalid { border-color: #c45d5d; }
.theme-btn { width: 4.25rem; font-size: 0.83rem; }
.search-results {
  display: none; position: absolute; top: calc(100% + 0.28rem); left: 0; right: 0; max-height: 55vh; overflow: auto;
  border: 1px solid var(--line-strong); border-radius: 0.45rem; background: var(--panel);
}
.search-results.open { display: block; }
.search-item { display: block; padding: 0.58rem 0.72rem; border-bottom: 1px solid var(--line); }
.search-item:last-child { border-bottom: 0; }
.search-item .kind { color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; }
.search-item .title { display: block; color: var(--text); margin-top: 0.16rem; font-size: 0.84rem; }
.search-item .excerpt { color: var(--muted); font-size: 0.8rem; margin-top: 0.2rem; line-height: 1.36; }
.shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: calc(100vh - 72px); }
.sidebar { border-right: 1px solid var(--line); background: var(--panel-soft); padding: 0.8rem 0.7rem 1.2rem; overflow: auto; }
.home-link {
  display: block; padding: 0.52rem 0.6rem; margin-bottom: 0.52rem; border: 1px solid var(--line-strong);
  border-radius: 0.42rem; color: var(--text); font-weight: 600;
}
.nav-part { margin-bottom: 0.52rem; border: 1px solid var(--line); border-radius: 0.42rem; background: var(--panel); }
.nav-part summary { list-style: none; padding: 0.52rem 0.6rem; cursor: pointer; border-bottom: 1px solid var(--line); }
.nav-part summary::-webkit-details-marker { display: none; }
.nav-part summary a {
  color: var(--text); font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8rem;
}
.nav-section-list { list-style: none; margin: 0; padding: 0.24rem; }
.sec-link { display: block; padding: 0.3rem 0.45rem; border-radius: 0.32rem; color: var(--muted); font-size: 0.8rem; line-height: 1.35; }
.sec-link.ready { color: var(--text); }
.sec-link.active, .sec-link:hover { color: var(--text); background: var(--accent-soft); }
.content { padding: 1rem; }
.reader-grid { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 1rem; align-items: start; }
.reader-main { min-width: 0; max-width: 1100px; }
.info-panel { border: 1px solid var(--line); border-radius: 0.45rem; background: var(--panel); padding: 0.7rem; position: sticky; top: 84px; }
.panel-section + .panel-section { border-top: 1px solid var(--line); margin-top: 0.7rem; padding-top: 0.7rem; }
.panel-title { margin: 0 0 0.45rem; color: var(--muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; }
.panel-list { list-style: none; margin: 0; padding: 0; }
.panel-list li { margin-bottom: 0.35rem; font-size: 0.8rem; }
.crumbs {
  color: var(--muted); font-size: 0.8rem; margin-bottom: 0.75rem;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.sep { color: var(--line-strong); }
.hero, .card {
  border: 1px solid var(--line); border-radius: 0.45rem; background: var(--panel);
  box-shadow: var(--shadow); padding: 0.85rem 0.95rem; margin-bottom: 0.8rem;
}
.card.warn { border-color: #b8a87e; background: var(--panel-soft); }
.node-kind {
  display: inline-flex; align-items: center; padding: 0.12rem 0.38rem; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--accent-soft); color: var(--text);
  font-size: 0.68rem; letter-spacing: 0.05em; text-transform: uppercase; margin-bottom: 0.45rem;
}
.hero h2, .card h2, .card h3 { margin-top: 0; }
.cards.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem; }
.card.big h3 { margin-bottom: 0.35rem; }
.badge {
  margin-left: 0.45rem; padding: 0.08rem 0.36rem; border-radius: 0.35rem; border: 1px solid var(--line-strong);
  color: var(--muted); font-size: 0.7rem; font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.link-list, .toc-list { list-style: none; margin: 0; padding: 0; }
.link-list li, .toc-list li { margin-bottom: 0.4rem; }
.toc-list a { color: var(--text); }
.prose {
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif; line-height: 1.78;
  font-size: clamp(1rem, 0.95rem + 0.28vw, 1.1rem); max-width: var(--reading-width); text-wrap: pretty;
}
.prose p, .prose li, .prose blockquote { color: var(--text); }
.prose p { margin: 0 0 1.05rem; }
.prose ul, .prose ol { padding-left: 1.2rem; margin: 0.55rem 0 1.05rem; }
.prose li { margin-bottom: 0.44rem; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif; line-height: 1.34; color: var(--text); letter-spacing: 0.01em;
}
.prose h1 { font-size: clamp(1.62rem, 1.46rem + 0.6vw, 2.05rem); margin: 0.2rem 0 1rem; }
.prose h2 { font-size: clamp(1.35rem, 1.25rem + 0.36vw, 1.66rem); margin: 1.6rem 0 0.82rem; }
.prose h3 { font-size: clamp(1.16rem, 1.1rem + 0.25vw, 1.35rem); margin: 1.38rem 0 0.7rem; }
.prose h4 { font-size: 1.05rem; margin: 1.2rem 0 0.55rem; }
.prose pre { overflow-x: auto; border: 1px solid var(--line); border-radius: 0.42rem; padding: 0.7rem; background: var(--panel-soft); }
.prose pre code { background: transparent; padding: 0; }
.prose blockquote { margin: 0.9rem 0; padding: 0.52rem 0.72rem; border-left: 2px solid var(--line-strong); background: var(--panel-soft); }
.pager { display: flex; flex-wrap: wrap; gap: 0.52rem; margin: 0.8rem 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; padding: 0.4rem 0.66rem;
  border: 1px solid var(--line-strong); border-radius: 0.42rem; background: var(--panel); color: var(--text);
}
.muted { color: var(--muted); }
.footer { color: var(--muted); font-size: 0.75rem; margin-top: 1.1rem; }

@media (max-width: 1320px) {
  .reader-grid { grid-template-columns: minmax(0, 1fr); }
  .info-panel { position: static; order: -1; }
}
@media (max-width: 1120px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "menu main" "search search" "actions actions";
  }
  .menu-btn { grid-area: menu; }
  .topbar-main { grid-area: main; }
  .search-wrap { grid-area: search; }
  .topbar-actions { grid-area: actions; justify-content: flex-start; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(320px, 86vw); transform: translateX(-105%);
    transition: transform 0.2s ease-out; z-index: 50; border-right: 1px solid var(--line);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .content { padding: 0.82rem; }
  .cards.two { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .addr-jump { width: 100%; }
  .topbar-actions { flex-direction: column; align-items: stretch; }
  .theme-btn { width: 100%; }
  .subtitle { font-size: 0.7rem; line-height: 1.28; }
  .card, .hero { padding: 0.78rem 0.82rem; }
  .prose { line-height: 1.82; font-size: 1.03rem; max-width: 100%; }
  .prose p { margin-bottom: 1.12rem; }
}
