/* Koolay docs — vanilla CSS, light/dark mode, responsive */
:root {
  --bg: #ffffff;
  --bg-alt: #fafaf9;
  --bg-elevated: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --gold: #ca8a04;
  --gold-soft: #fef3c7;
  --gold-strong: #a16207;
  --link: #b45309;
  --link-hover: #92400e;
  --code-bg: #f3f4f6;
  --code-border: #e5e7eb;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.04);
  --radius: 10px;
  --header-h: 60px;
  --sidebar-w: 280px;
  --toc-w: 220px;
  --content-max: 760px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "Cascadia Mono", Menlo, Monaco, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-alt: #14171d;
    --bg-elevated: #1a1d24;
    --border: #2a2e37;
    --border-strong: #3a3f4a;
    --text: #e5e7eb;
    --text-muted: #9ca3af;
    --text-faint: #6b7280;
    --gold: #fbbf24;
    --gold-soft: #1f1a08;
    --gold-strong: #f59e0b;
    --link: #fbbf24;
    --link-hover: #fcd34d;
    --code-bg: #1a1d24;
    --code-border: #2a2e37;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 22px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(8px);
}
.menu-toggle {
  display: none;
  background: none; border: 1px solid var(--border); border-radius: 6px;
  width: 36px; height: 36px;
  font-size: 20px; line-height: 1; cursor: pointer; color: var(--text);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); font-weight: 600;
}
.brand img { display: block; }
.brand span { font-size: 15px; color: var(--text-muted); font-weight: 500; }
.search-wrap {
  position: relative; flex: 1; max-width: 480px; margin-left: auto;
}
.search-wrap input {
  width: 100%; padding: 8px 60px 8px 36px;
  background: var(--bg-alt); border: 1px solid var(--border); border-radius: 8px;
  font: inherit; color: var(--text); font-size: 14px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.3-4.3'/></svg>");
  background-repeat: no-repeat;
  background-position: 10px center;
}
.search-wrap input:focus { outline: none; border-color: var(--gold); }
.search-wrap kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  padding: 2px 6px; font-size: 11px; color: var(--text-muted);
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 4px;
  font-family: var(--font);
}
.topbar-link { font-size: 13px; color: var(--text-muted); }
.topbar-link:hover { color: var(--text); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  max-height: 70vh; overflow: auto;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 50;
}
.search-results .result {
  display: block; padding: 10px 12px; border-radius: 8px;
  color: var(--text); cursor: pointer;
}
.search-results .result:hover, .search-results .result.active { background: var(--bg-alt); text-decoration: none; }
.search-results .result-title { font-weight: 500; font-size: 14px; }
.search-results .result-path { font-size: 12px; color: var(--text-muted); }
.search-results .result-snippet { font-size: 13px; color: var(--text-muted); margin-top: 2px; line-height: 1.5; }
.search-results .result-snippet mark { background: var(--gold-soft); color: var(--gold-strong); padding: 0 2px; border-radius: 2px; }
.search-results .empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  align-items: start;
  min-height: calc(100vh - var(--header-h));
}
.sidebar {
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 22px 18px 32px;
  border-right: 1px solid var(--border);
  background: var(--bg);
}
.sidebar nav > .nav-guide + .nav-guide { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--border); }
.nav-guide-title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; color: var(--text); font-size: 14px;
  text-transform: uppercase; letter-spacing: .04em;
}
.nav-guide-title:hover { color: var(--gold); text-decoration: none; }
.nav-guide-tagline { margin: 2px 0 12px; font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.nav-section { margin-bottom: 4px; }
.nav-section summary {
  cursor: pointer; padding: 6px 8px; border-radius: 6px;
  color: var(--text); font-size: 13px; font-weight: 500;
  list-style: none; display: flex; align-items: center; gap: 6px;
}
.nav-section summary::-webkit-details-marker { display: none; }
.nav-section summary::before {
  content: "›"; font-size: 14px; color: var(--text-muted);
  transform: rotate(0deg); transition: transform .15s;
}
.nav-section[open] summary::before { transform: rotate(90deg); }
.nav-section summary:hover { background: var(--bg-alt); }
.nav-pages { padding: 4px 0 8px 18px; display: flex; flex-direction: column; gap: 1px; }
.nav-page {
  display: block; padding: 6px 10px; border-radius: 6px;
  color: var(--text-muted); font-size: 13px;
  border-left: 2px solid transparent;
}
.nav-page:hover { color: var(--text); background: var(--bg-alt); text-decoration: none; }
.nav-page.active {
  color: var(--gold-strong); font-weight: 500;
  background: var(--gold-soft); border-left-color: var(--gold);
}
.sidebar-foot { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.back-link { font-size: 12px; color: var(--text-muted); }
.guide-icon {
  display: inline-block; width: 16px; height: 16px;
  background: var(--gold); border-radius: 4px;
  -webkit-mask: var(--icon-mask) center / contain no-repeat; mask: var(--icon-mask) center / contain no-repeat;
}
.guide-icon[data-icon="shield"] { --icon-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'><path d='M12 2L4 5v6c0 5 3.4 9.4 8 11 4.6-1.6 8-6 8-11V5l-8-3z'/></svg>"); }
.guide-icon[data-icon="heart"] { --icon-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'><path d='M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z'/></svg>"); }

/* Content */
.content { padding: 28px 38px 80px; max-width: calc(var(--content-max) + 76px); }
.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb span { margin: 0 6px; color: var(--text-faint); }
.breadcrumb strong { color: var(--text); font-weight: 500; }
.doc-article { max-width: var(--content-max); }
.doc-article h1 { font-size: 32px; line-height: 1.2; margin: 0 0 14px; font-weight: 700; }
.doc-article h2 { font-size: 22px; line-height: 1.3; margin: 36px 0 12px; font-weight: 600; padding-top: 8px; border-top: 1px solid var(--border); }
.doc-article > h2:first-of-type, .doc-article h2:first-child { border-top: 0; padding-top: 0; }
.doc-article h3 { font-size: 18px; margin: 28px 0 10px; font-weight: 600; }
.doc-article h4 { font-size: 15px; margin: 22px 0 8px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.doc-article p { margin: 0 0 14px; }
.doc-article .lead { font-size: 18px; color: var(--text-muted); line-height: 1.55; margin: 0 0 28px; }
.doc-article ul, .doc-article ol { padding-left: 22px; margin: 0 0 16px; }
.doc-article li { margin: 4px 0; }
.doc-article img {
  max-width: 100%; height: auto; border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow); margin: 16px 0;
}
.doc-article code { font-family: var(--mono); font-size: 13px; padding: 1px 6px; background: var(--code-bg); border-radius: 4px; color: var(--text); border: 1px solid var(--code-border); }
.doc-article pre { margin: 16px 0; padding: 14px 16px; background: var(--code-bg); border: 1px solid var(--code-border); border-radius: var(--radius); overflow-x: auto; font-size: 13px; line-height: 1.55; }
.doc-article pre code { padding: 0; background: none; border: 0; }
.doc-article blockquote {
  margin: 16px 0; padding: 12px 18px; border-left: 4px solid var(--gold);
  background: var(--gold-soft); border-radius: 0 8px 8px 0; color: var(--text);
}
.doc-article hr { border: 0; height: 1px; background: var(--border); margin: 32px 0; }
.doc-article table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px; }
.doc-article th, .doc-article td { border-bottom: 1px solid var(--border); padding: 10px 12px; text-align: left; }
.doc-article th { background: var(--bg-alt); font-weight: 600; }

/* Page foot nav */
.page-foot-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border);
}
.page-foot-nav a {
  display: block; padding: 14px 18px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg);
}
.page-foot-nav a:hover { border-color: var(--gold); text-decoration: none; }
.page-foot-nav a span { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.page-foot-nav a strong { display: block; color: var(--text); font-weight: 500; }
.page-foot-nav .next { text-align: right; }

/* TOC */
.page-toc {
  position: sticky; top: calc(var(--header-h) + 28px);
  align-self: start;
  padding: 14px 16px; margin: 28px 22px 0 0;
  font-size: 13px;
}
.page-toc h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; color: var(--text-muted); letter-spacing: .06em; }
.page-toc ul { list-style: none; padding: 0; margin: 0; border-left: 1px solid var(--border); }
.page-toc li { margin: 0; }
.page-toc li a {
  display: block; padding: 4px 12px; color: var(--text-muted);
  border-left: 2px solid transparent; margin-left: -1px;
  font-size: 13px; line-height: 1.4;
}
.page-toc li a:hover { color: var(--text); text-decoration: none; }
.page-toc li.toc-h3 a { padding-left: 24px; font-size: 12px; }

/* Hub */
.hub-hero { margin-bottom: 40px; padding: 30px 0 10px; }
.hub-hero h1 { font-size: 38px; margin: 0 0 8px; }
.hub-hero .lead { font-size: 18px; color: var(--text-muted); margin: 0; max-width: 600px; }
.hub-search-hint { margin-top: 16px; font-size: 13px; color: var(--text-muted); }
.hub-search-hint kbd { padding: 2px 6px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 4px; font: inherit; font-size: 12px; }
.hub-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 48px; }
.hub-card {
  display: block; padding: 24px; border-radius: 14px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  position: relative; overflow: hidden; transition: all .2s;
}
.hub-card:hover { border-color: var(--gold); transform: translateY(-1px); box-shadow: var(--shadow); text-decoration: none; }
.hub-card h2 { font-size: 22px; margin: 12px 0 6px; color: var(--text); }
.hub-card p { color: var(--text-muted); font-size: 14px; margin: 0 0 12px; }
.hub-card .hub-sections { font-size: 12px; color: var(--text-faint); }
.hub-icon { width: 36px; height: 36px; border-radius: 8px; background: var(--gold-soft); display: flex; align-items: center; justify-content: center; }
.hub-icon::before { content: "★"; color: var(--gold); font-size: 18px; }
.hub-card-users .hub-icon::before { content: "♥"; }
.hub-arrow { position: absolute; top: 24px; right: 24px; font-size: 18px; color: var(--text-faint); transition: all .2s; }
.hub-card:hover .hub-arrow { color: var(--gold); transform: translateX(4px); }
.hub-popular { margin-top: 32px; }
.hub-popular h2 { font-size: 18px; margin: 0 0 14px; }
.popular-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.popular-grid a {
  display: block; padding: 14px 16px; border-radius: 8px;
  background: var(--bg-alt); border: 1px solid transparent;
}
.popular-grid a:hover { border-color: var(--gold); text-decoration: none; background: var(--bg-elevated); }
.popular-grid strong { display: block; color: var(--text); font-weight: 500; margin-bottom: 2px; }
.popular-grid span { display: block; font-size: 13px; color: var(--text-muted); }

.page-list { list-style: none; padding: 0; }
.page-list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.page-list li:last-child { border-bottom: 0; }
.page-list a { color: var(--text); font-size: 15px; }

/* Mobile */
@media (max-width: 1100px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .page-toc { display: none; }
}
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0;
    width: 280px; height: calc(100vh - var(--header-h));
    transform: translateX(-100%); transition: transform .2s;
    z-index: 25; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 22px 18px 60px; }
  .doc-article h1 { font-size: 28px; }
  .doc-article h2 { font-size: 20px; }
  .topbar-link { display: none; }
  .search-wrap { max-width: none; }
  .brand span { display: none; }
  .page-foot-nav { grid-template-columns: 1fr; }
}

/* Print */
@media print {
  .topbar, .sidebar, .page-toc, .page-foot-nav, .menu-toggle { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  .content { padding: 0; max-width: none; }
  .doc-article img { box-shadow: none; }
  body { font-size: 11pt; }
}
