:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --text: #1c2330;
  --muted: #5b6573;
  --accent: #2563eb;
  --accent-soft: #eaf0fe;
  --border: #e3e7ee;
  --code-bg: #f3f5f8;
  --max: 46rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c;
    --bg-soft: #171c25;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --accent: #7aa2f7;
    --accent-soft: #1d2638;
    --border: #2a3140;
    --code-bg: #1b2230;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.6rem 1.2rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.topbar .tagline { color: var(--muted); font-size: 0.85rem; }

#menu {
  display: none;
  font-size: 1.2rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.15rem 0.5rem;
  cursor: pointer;
}

#search {
  margin-left: auto;
  width: 16rem;
  max-width: 40vw;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

#search-results {
  position: absolute;
  top: 3.1rem;
  right: 1.2rem;
  width: 24rem;
  max-width: 90vw;
  max-height: 60vh;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

#search-results a {
  display: block;
  padding: 0.5rem 0.9rem;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

#search-results a:hover, #search-results a.selected { background: var(--accent-soft); }
#search-results .where { color: var(--muted); font-size: 0.8rem; display: block; }

.layout {
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr) 16rem;
  gap: 2.5rem;
  max-width: 90rem;
  margin: 0 auto;
  padding: 0 1.2rem;
}

.sidebar {
  position: sticky;
  top: 3.2rem;
  height: calc(100vh - 3.2rem);
  overflow-y: auto;
  padding: 1.2rem 0.4rem 2rem 0;
  border-right: 1px solid var(--border);
  font-size: 0.92rem;
}

.nav-section {
  margin: 1.1rem 0 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar ul { list-style: none; margin: 0; padding: 0; }

.sidebar li a {
  display: block;
  padding: 0.28rem 0.6rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}

.sidebar li a:hover { background: var(--bg-soft); }
.sidebar li.active a { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.content { padding: 1.6rem 0 4rem; min-width: 0; }
.content article { max-width: var(--max); }

.content footer {
  max-width: var(--max);
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.rail { padding: 1.6rem 0; font-size: 0.85rem; }

.toc {
  position: sticky;
  top: 4.2rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
}

.toc p {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.4rem;
}

.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc li a {
  display: block;
  padding: 0.18rem 0.8rem;
  color: var(--muted);
  text-decoration: none;
}
.toc li.d3 a { padding-left: 1.7rem; }
.toc li a:hover { color: var(--accent); }

h1, h2, h3, h4 { line-height: 1.25; scroll-margin-top: 4rem; }
h1 { font-size: 2rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.45rem; margin-top: 2.4rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
h3 { font-size: 1.15rem; margin-top: 1.8rem; }
h4 { font-size: 1rem; margin-top: 1.5rem; }

.anchor {
  margin-left: 0.4rem;
  color: var(--border);
  text-decoration: none;
  font-weight: 400;
}
h2:hover .anchor, h3:hover .anchor { color: var(--accent); }

a { color: var(--accent); }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  line-height: 1.5;
}

pre code { background: none; padding: 0; font-size: 0.85rem; }

blockquote {
  margin: 1rem 0;
  padding: 0.2rem 1.1rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
}

table { border-collapse: collapse; width: 100%; margin: 1rem 0; font-size: 0.92rem; }
th, td { border: 1px solid var(--border); padding: 0.45rem 0.7rem; text-align: left; vertical-align: top; }
th { background: var(--bg-soft); }

ul, ol { padding-left: 1.4rem; }
li { margin: 0.18rem 0; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 16rem minmax(0, 1fr); }
  .rail { display: none; }
}

@media (max-width: 800px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  #menu { display: block; }
  .topbar .tagline { display: none; }
  .sidebar {
    display: none;
    position: fixed;
    top: 3.2rem;
    left: 0;
    width: 18rem;
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding-left: 1rem;
    z-index: 9;
  }
  .sidebar.open { display: block; }
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  margin-bottom: 0.4rem;
}
.badge-essentials { background: var(--accent-soft); color: var(--accent); }
.badge-advanced { background: #fdf1df; color: #92600a; }
.badge-tool-authors { background: #e8f6ee; color: #19744a; }
@media (prefers-color-scheme: dark) {
  .badge-advanced { background: #3a2d14; color: #e3b264; }
  .badge-tool-authors { background: #14301f; color: #6fcf97; }
}

.rule-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--code-bg);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  margin-right: 0.45rem;
  text-decoration: none;
  vertical-align: 1px;
}
.rule-id:hover { color: var(--accent); }
li:target { background: var(--accent-soft); border-radius: 6px; }
