/* portage-ng.ai — handbook styles */

:root {
  --bg0: #0b0d13;
  --bg1: #10131c;
  --bg2: #161a26;
  --bg3: #1c2130;
  --border: #232939;
  --border-strong: #303850;
  --text: #e8ebf4;
  --text-2: #a6aec2;
  --text-3: #717a92;
  --violet: #a78bfa;
  --green: #4ade80;
  --magenta: #f472b6;
  --blue: #7db3fa;
  --amber: #fbbf24;
  --top-bg: rgba(11, 13, 19, 0.88);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --top-h: 56px;
  --side-w: 300px;
}

/* ---------- light theme ---------- */

html[data-theme="light"] {
  --bg0: #f6f7fb;
  --bg1: #ffffff;
  --bg2: #edeff7;
  --bg3: #e2e6f2;
  --border: #dfe3ee;
  --border-strong: #c7cfe2;
  --text: #1a1e2c;
  --text-2: #4a536d;
  --text-3: #6f7a96;
  --violet: #6d4de0;
  --green: #0e8a4d;
  --magenta: #cf2f8c;
  --blue: #2d6bd0;
  --amber: #9a7305;
  --top-bg: rgba(247, 248, 252, 0.9);
}

/* code blocks follow the theme: white ground and a darker syntax palette
   in light mode */
html[data-theme="light"] .md pre {
  background: #ffffff;
  border-color: var(--border-strong);
}
html[data-theme="light"] .md code {
  color: #7539d6;
}
html[data-theme="light"] .md pre code {
  color: #2a3140;
}
html[data-theme="light"] .md a code {
  color: var(--violet);
}
html[data-theme="light"] .hljs-keyword,
html[data-theme="light"] .hljs-selector-tag,
html[data-theme="light"] .hljs-literal,
html[data-theme="light"] .hljs-section { color: #6d4de0; }
html[data-theme="light"] .hljs-string,
html[data-theme="light"] .hljs-attr { color: #0e8a4d; }
html[data-theme="light"] .hljs-symbol,
html[data-theme="light"] .hljs-bullet,
html[data-theme="light"] .hljs-link,
html[data-theme="light"] .hljs-selector-id { color: #2d6bd0; }
html[data-theme="light"] .hljs-title,
html[data-theme="light"] .hljs-title.function_,
html[data-theme="light"] .hljs-name { color: #1e63c9; }
html[data-theme="light"] .hljs-comment,
html[data-theme="light"] .hljs-quote { color: #8a93ab; }
html[data-theme="light"] .hljs-number,
html[data-theme="light"] .hljs-regexp { color: #9a7305; }
html[data-theme="light"] .hljs-variable,
html[data-theme="light"] .hljs-template-variable,
html[data-theme="light"] .hljs-params { color: #cf2f8c; }
html[data-theme="light"] .hljs-built_in,
html[data-theme="light"] .hljs-type,
html[data-theme="light"] .hljs-class .hljs-title { color: #0e7490; }
html[data-theme="light"] .hljs-meta,
html[data-theme="light"] .hljs-meta .hljs-keyword { color: #5c6b8f; }
html[data-theme="light"] .hljs-addition { color: #0e8a4d; background: rgba(14, 138, 77, 0.08); }
html[data-theme="light"] .hljs-deletion { color: #c72836; background: rgba(215, 60, 60, 0.08); }

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--top-h) + 20px); }

body.docs {
  margin: 0;
  background: var(--bg0);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(167, 139, 250, 0.35); }

a { color: var(--violet); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- top bar ---------- */

.docs-top {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 60;
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--top-bg);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.docs-top .brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15.5px;
  color: var(--text);
  white-space: nowrap;
}
.docs-top .brand:hover { text-decoration: none; }
.docs-top .brand svg { width: 23px; height: 23px; }

.crumb { font-family: var(--mono); font-size: 13px; color: var(--text-3); }

.top-right { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.top-right a { font-size: 13.5px; color: var(--text-2); font-weight: 500; }
.top-right a:hover { color: var(--text); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px; height: 32px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg2);
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover { border-color: var(--violet); color: var(--text); }
.theme-toggle svg {
  width: 16px; height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-toggle .icon-moon { display: none; }
html[data-theme="light"] .theme-toggle .icon-sun { display: none; }
html[data-theme="light"] .theme-toggle .icon-moon { display: block; }

.side-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  width: 36px; height: 36px;
  font-size: 16px;
  cursor: pointer;
  flex: none;
}

/* ---------- shell ---------- */

.docs-shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  max-width: 1240px;
  margin: 0 auto;
  padding-top: var(--top-h);
}

/* ---------- sidebar ---------- */

.docs-sidebar {
  position: sticky;
  top: var(--top-h);
  height: calc(100vh - var(--top-h));
  overflow-y: auto;
  padding: 26px 18px 40px 24px;
  border-right: 1px solid var(--border);
  font-size: 13.5px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.docs-sidebar h5 {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--green);
  margin: 22px 0 8px;
  font-weight: 600;
}

.docs-sidebar ul { list-style: none; margin: 0; padding: 0; }
.docs-sidebar .side-top { margin-bottom: 4px; }

.docs-sidebar li a {
  display: flex;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 7px;
  color: var(--text-2);
  line-height: 1.45;
  transition: background 0.12s ease, color 0.12s ease;
}
.docs-sidebar li a:hover { color: var(--text); background: var(--bg2); text-decoration: none; }
.docs-sidebar li a.active {
  color: var(--violet);
  background: rgba(167, 139, 250, 0.09);
  font-weight: 600;
}

.docs-sidebar .num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  min-width: 17px;
  text-align: right;
  flex: none;
  padding-top: 2px;
}
.docs-sidebar li a.active .num { color: var(--violet); }

/* ---------- main ---------- */

.docs-main {
  padding: 40px 48px 60px;
  min-width: 0;
}

.md { max-width: 780px; }

/* typography */

.md h1 {
  font-family: var(--mono);
  font-size: clamp(26px, 3.4vw, 34px);
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 8px 0 20px;
}

.md h2, .md h3, .md h4 {
  position: relative;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 40px 0 14px;
  line-height: 1.3;
}
.md h2 {
  font-size: 23px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.md h3 { font-size: 18.5px; }
.md h4 { font-size: 16px; }

.md .anchor {
  position: absolute;
  left: -22px;
  color: var(--text-3);
  opacity: 0;
  font-family: var(--mono);
  font-weight: 400;
  transition: opacity 0.15s ease;
}
.md h2:hover .anchor, .md h3:hover .anchor, .md h4:hover .anchor { opacity: 1; }

.md p { margin: 14px 0; color: var(--text-2); }
.md li { color: var(--text-2); margin: 5px 0; }
.md strong { color: var(--text); font-weight: 600; }
.md em { color: var(--text); }

.md ul, .md ol { padding-left: 26px; margin: 14px 0; }

.md blockquote {
  margin: 18px 0;
  padding: 12px 20px;
  border-left: 3px solid var(--violet);
  background: var(--bg1);
  border-radius: 0 10px 10px 0;
}
.md blockquote p { margin: 6px 0; }

.md hr { border: none; border-top: 1px solid var(--border); margin: 36px 0; }

/* inline code */
.md code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1.5px 6px;
  color: #e3b8f5;
  white-space: nowrap;
}
.md a code { color: var(--violet); }
.md h1 code, .md h2 code, .md h3 code, .md h4 code { font-size: 0.88em; white-space: normal; }

/* code blocks */
.md pre {
  background: #0d0f16;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 18px 20px;
  overflow-x: auto;
  margin: 20px 0;
  line-height: 1.6;
  scrollbar-width: thin;
}
.md pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13.5px;
  color: #d6dbeb;
  white-space: pre;
}

/* highlight.js theme — matched to the site palette */
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section { color: #c4a7ff; }
.hljs-string, .hljs-attr { color: #7ee2a8; }
.hljs-symbol, .hljs-bullet, .hljs-link, .hljs-selector-id { color: #9dc4ff; }
.hljs-title, .hljs-title.function_, .hljs-name { color: #82b5ff; }
.hljs-comment, .hljs-quote { color: #626b83; font-style: italic; }
.hljs-number, .hljs-regexp { color: #ffcb6b; }
.hljs-variable, .hljs-template-variable, .hljs-params { color: #f2a7d1; }
.hljs-built_in, .hljs-type, .hljs-class .hljs-title { color: #7fd6e0; }
.hljs-meta, .hljs-meta .hljs-keyword { color: #8fa3c9; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }
.hljs-addition { color: #7ee2a8; background: rgba(74, 222, 128, 0.08); }
.hljs-deletion { color: #ff8896; background: rgba(255, 95, 87, 0.08); }

/* tables */
.table-wrap { overflow-x: auto; margin: 20px 0; border: 1px solid var(--border); border-radius: 12px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; }
.md th, .md td { padding: 10px 16px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.md th {
  background: var(--bg2);
  font-family: var(--mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  white-space: nowrap;
}
.md td { color: var(--text-2); }
.md tr:last-child td { border-bottom: none; }
.md td code, .md th code { white-space: nowrap; }

/* images / diagrams (graphviz svgs ship a white canvas) */
.md img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 24px auto;
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  padding: 14px;
}

/* ---------- pager ---------- */

.docs-pager {
  max-width: 780px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 56px;
}

.pager {
  display: block;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  background: var(--bg1);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.pager:hover { border-color: var(--violet); background: var(--bg2); text-decoration: none; }
.pager.next { text-align: right; }
.pager span { display: block; font-family: var(--mono); font-size: 11px; color: var(--text-3); margin-bottom: 4px; }
.pager strong { color: var(--text); font-size: 14px; font-weight: 600; line-height: 1.35; }

.docs-foot {
  max-width: 780px;
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-3);
}
.docs-foot a { color: var(--text-2); }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .side-toggle { display: block; }

  .docs-shell { grid-template-columns: 1fr; }

  .docs-sidebar {
    position: fixed;
    top: var(--top-h);
    left: 0;
    bottom: 0;
    width: min(320px, 85vw);
    background: var(--bg1);
    border-right: 1px solid var(--border-strong);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    z-index: 50;
    height: auto;
  }
  .docs-sidebar.open { transform: none; box-shadow: 24px 0 60px rgba(0, 0, 0, 0.5); }

  .docs-main { padding: 28px 22px 48px; }
  .docs-pager { grid-template-columns: 1fr; }
  .md .anchor { display: none; }
}

@media (max-width: 520px) {
  .crumb { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .docs-sidebar { transition: none; }
}
