:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --ok: #047857;
  --warn: #b45309;
  --shot: #1e293b;
  --radius: 12px;
  --sidebar: 300px;
  --top: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--brand);
  color: #fff;
  padding: 8px 12px;
  z-index: 20;
}
.skip-link:focus { top: 12px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  height: var(--top);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: #0f172a;
  color: #fff;
}

.menu-btn {
  display: none;
  background: transparent;
  color: #fff;
  border: 1px solid #334155;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  font-size: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-width: 180px;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  font-weight: 800;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { color: #94a3b8; font-size: 12px; }

.search { flex: 1; max-width: 520px; }
.search input {
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 15px;
}

.top-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 11px;
  color: #cbd5e1;
  white-space: nowrap;
}

.search-panel {
  position: sticky;
  top: var(--top);
  z-index: 7;
  background: #fff;
  border-bottom: 1px solid var(--line);
  max-height: 50vh;
  overflow: auto;
  padding: 8px 16px 16px;
}
.search-panel[hidden] { display: none; }
.search-hint { color: var(--muted); margin: 8px 0; }
.search-panel a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink);
}
.search-panel a:hover, .search-panel a:focus { background: var(--brand-soft); }
.search-panel small { display: block; color: var(--muted); }

.layout { display: flex; min-height: calc(100vh - var(--top)); }
.sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 12px 40px;
  overflow: auto;
  position: sticky;
  top: var(--top);
  height: calc(100vh - var(--top));
}
.sidebar h2 {
  margin: 18px 8px 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
}
.sidebar a {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  color: #334155;
  text-decoration: none;
  font-size: 14px;
}
.sidebar a.active, .sidebar a:hover { background: var(--brand-soft); color: var(--brand); }

.main {
  flex: 1;
  min-width: 0;
  padding: 24px 32px 64px;
  max-width: 980px;
}
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.crumbs a { color: var(--brand); text-decoration: none; }
.article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.04);
}
.article h1 { margin-top: 0; font-size: 2rem; }
.article h2 { margin-top: 2rem; border-top: 1px solid var(--line); padding-top: 1.2rem; }
.article h3 { margin-top: 1.4rem; }
.article a { color: var(--brand); }
.article table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 14px; }
.article th, .article td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.article th { background: #f1f5f9; }
.article code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 0.92em; }
.article pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: 10px;
  overflow: auto;
}
.article pre code { background: transparent; color: inherit; padding: 0; }
.article blockquote {
  margin: 1rem 0;
  padding: 10px 14px;
  border-left: 4px solid var(--brand);
  background: var(--brand-soft);
}
.article ul.checklist { list-style: none; padding-left: 0; }
.article .shot {
  margin: 16px 0;
  padding: 28px 16px;
  border: 2px dashed #94a3b8;
  border-radius: 10px;
  background: #f8fafc;
  color: var(--shot);
  text-align: center;
  font-weight: 600;
}
.article .note {
  border-radius: 10px;
  padding: 12px 14px;
  margin: 14px 0;
}
.article .note.warn { background: #fff7ed; border: 1px solid #fdba74; }
.article .note.ok { background: #ecfdf5; border: 1px solid #6ee7b7; }
.article .flow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 16px 0;
}
.article .flow .node {
  background: var(--brand-soft);
  color: #312e81;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
}
.article .flow .arrow { color: #64748b; }

.mermaid-fallback {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}
.mermaid-fallback .step {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
}

.related, .pager { margin-top: 24px; }
.related ul { padding-left: 18px; }
.pager { display: flex; justify-content: space-between; gap: 12px; }
.pager-link {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
}
.pager-link.next { margin-left: auto; }
.pager-link[hidden] { display: none; }

.backdrop { display: none; }

@media (max-width: 900px) {
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .top-meta { display: none; }
  .sidebar {
    position: fixed;
    left: 0;
    top: var(--top);
    transform: translateX(-110%);
    transition: transform 0.2s ease;
    z-index: 9;
    box-shadow: 20px 0 40px rgba(15, 23, 42, 0.2);
  }
  .sidebar.open { transform: none; }
  .backdrop {
    display: block;
    position: fixed;
    inset: var(--top) 0 0 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 8;
  }
  .backdrop[hidden] { display: none; }
  .main { padding: 16px; }
  .article { padding: 18px 16px; }
}
