:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-soft: #f3f5fa;
  --text: #24303a;
  --muted: #6c7783;
  --line: #dbe1ea;
  --accent: #5d7f31;
  --accent-dark: #46601f;
  --link: #2d5f95;
  --link-hover: #21496f;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --sidebar-width: 320px;
}

html.theme-dark {
  --bg: #11161c;
  --panel: #17202a;
  --panel-soft: #1d2732;
  --text: #e7edf4;
  --muted: #9ba8b5;
  --line: #2b3948;
  --accent: #9abb65;
  --accent-dark: #b8d785;
  --link: #8ab8f0;
  --link-hover: #b4d3f7;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.65;
}

img {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: var(--link-hover);
}

.container {
  width: min(1200px, calc(100% - 24px));
  margin: 0 auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 70;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

html.theme-dark .site-header {
  background: rgba(17, 22, 28, 0.9);
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
}

.branding {
  min-width: 0;
}

.site-title {
  display: inline-block;
  color: var(--text);
  font-size: clamp(1.15rem, 3vw, 1.5rem);
  font-weight: 700;
  line-height: 1.2;
}

.site-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle,
.menu-toggle {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 11px;
  cursor: pointer;
  font: inherit;
}

.theme-toggle-dark {
  display: none;
}

html.theme-dark .theme-toggle-light {
  display: none;
}

html.theme-dark .theme-toggle-dark {
  display: inline;
}

.kb-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: calc(100vh - 70px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.sidebar-inner {
  position: sticky;
  top: 71px;
  height: calc(100vh - 71px);
  overflow-y: auto;
  padding: 18px 14px 24px;
}

.sidebar-top-links {
  display: grid;
  gap: 6px;
  margin-bottom: 18px;
}

.sidebar-top-links a {
  display: block;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--muted);
}

.sidebar-top-links a:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.kb-tree,
.kb-subtree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.kb-tree-item + .kb-tree-item {
  margin-top: 4px;
}

.kb-tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
}

.kb-toggle {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.kb-toggle:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.kb-toggle-icon {
  display: inline-block;
  transition: transform 0.18s ease;
  font-size: 0.9rem;
}

.kb-toggle.is-open .kb-toggle-icon {
  transform: rotate(90deg);
}

.kb-section-link {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
  padding: 7px 8px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 600;
}

.kb-section-link:hover {
  background: var(--panel-soft);
}

.kb-section-link.is-active {
  background: rgba(45, 95, 149, 0.12);
  color: var(--link);
}

.kb-subtree {
  display: none;
  margin: 2px 0 8px 32px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.kb-subtree.is-open {
  display: block;
}

.kb-subtree li + li {
  margin-top: 2px;
}

.kb-subtree a {
  display: block;
  padding: 7px 8px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.96rem;
}

.kb-subtree a:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.kb-subtree a.is-active {
  background: rgba(45, 95, 149, 0.12);
  color: var(--link);
  font-weight: 600;
}

.main-content {
  min-width: 0;
}

.content-wrap {
  width: min(860px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.hero,
.page-box,
.article-page,
.home-sections {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.hero {
  margin-bottom: 20px;
}

.hero h1,
.page-header h1,
.article-header h1 {
  margin-top: 0;
  line-height: 1.15;
}

.page-content,
.article-content {
  color: var(--text);
}

.article-content h2,
.article-content h3 {
  line-height: 1.25;
  margin-top: 28px;
}

.article-content p,
.article-content ul,
.article-content ol {
  margin: 0 0 16px;
}

.article-content ul,
.article-content ol,
.home-sections ul {
  padding-left: 22px;
}

.site-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  padding: 18px 0 26px;
}

.menu-toggle {
  display: none;
}

@media (max-width: 980px) {
  .kb-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 65px;
    left: 0;
    width: min(88vw, 340px);
    height: calc(100vh - 65px);
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    z-index: 80;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-inner {
    position: static;
    height: 100%;
  }

  .menu-toggle {
    display: inline-block;
  }

  .content-wrap {
    width: min(860px, calc(100% - 20px));
    padding: 18px 0 30px;
  }
}

@media (max-width: 640px) {
  .site-subtitle {
    display: none;
  }

  .hero,
  .page-box,
  .article-page,
  .home-sections {
    padding: 18px;
    border-radius: 14px;
  }
}

/* === utility === */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.no-scroll {
  overflow: hidden;
}

/* === active top links === */
.sidebar-top-links a.is-active {
  background: rgba(45, 95, 149, 0.12);
  color: var(--link);
  font-weight: 600;
}

/* === search === */
.sidebar-search {
  margin-bottom: 16px;
}

.sidebar-search-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
}

.sidebar-search-input::placeholder {
  color: var(--muted);
}

.sidebar-search-input:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 3px rgba(45, 95, 149, 0.12);
}

/* === stronger active section === */
.kb-section-link.is-current-section {
  background: rgba(45, 95, 149, 0.09);
  color: var(--text);
}

.kb-section-link.is-current-section span:last-child {
  font-weight: 700;
}

.kb-section-icon {
  display: inline-flex;
  width: 1.35rem;
  justify-content: center;
  margin-right: 8px;
  flex: 0 0 auto;
}

/* === overlay for mobile === */
.mobile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 18, 25, 0.42);
  z-index: 75;
}

.mobile-overlay[hidden] {
  display: none;
}

/* === Pagefind Search UI === */
:root {
  --pagefind-ui-scale: 1;
  --pagefind-ui-primary: var(--link);
  --pagefind-ui-text: var(--text);
  --pagefind-ui-background: var(--panel);
  --pagefind-ui-border: var(--line);
  --pagefind-ui-tag: var(--panel-soft);
  --pagefind-ui-border-width: 1px;
  --pagefind-ui-border-radius: 12px;
  --pagefind-ui-image-border-radius: 10px;
  --pagefind-ui-font: inherit;
}

.pagefind-ui {
  margin-top: 20px;
}

.pagefind-ui__search-input {
  background: var(--panel);
  color: var(--text);
}

.pagefind-ui__result {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.pagefind-ui__result-title {
  font-weight: 700;
}

.pagefind-ui__result-excerpt {
  color: var(--muted);
}

/* === Callout blocks === */
.callout {
  margin: 20px 0;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.callout-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.callout-body > :last-child {
  margin-bottom: 0;
}

.callout-note { border-left: 4px solid #5b8def; }
.callout-warning { border-left: 4px solid #f0a500; }
.callout-success { border-left: 4px solid #2ea56e; }
.callout-myth { border-left: 4px solid #d6457b; }
.callout-insight { border-left: 4px solid #7a5af8; }

/* === NEW: Compare Grid (Cards side-by-side) === */
.kb-compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.kb-compare-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.kb-compare-title {
  font-weight: 700;
  font-size: 1.05em;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

.kb-compare-body > :last-child {
  margin-bottom: 0;
}

/* === NEW: Box (Replaces Details) === */
.kb-box {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin: 24px 0;
  padding: 20px;
}

.kb-box-title {
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--link);
}

.kb-box-body > :last-child {
  margin-bottom: 0;
}