/* BBR Digital Expander documentation theme.
   Light palette on :root, dark overrides for both the system preference and
   the explicit [data-theme] the header toggle writes to localStorage. */

:root {
  --bg: #ffffff;
  --bg-subtle: #f7f8fa;
  --bg-raised: #ffffff;
  --border: #e4e6ea;
  --border-strong: #d0d4da;
  --text: #23272f;
  --text-muted: #6b7280;
  --text-faint: #9aa1ab;
  --accent: #2f6feb;
  --accent-soft: #eaf1fe;
  --code-bg: #f6f7f9;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);

  --hint-info-bd: #3b82f6;   --hint-info-bg: #eff6ff;
  --hint-success-bd: #10b981; --hint-success-bg: #ecfdf5;
  --hint-warning-bd: #f59e0b; --hint-warning-bg: #fffbeb;
  --hint-danger-bd: #ef4444;  --hint-danger-bg: #fef2f2;

  --sidebar-w: 17rem;
  --onpage-w: 15rem;
  --topbar-h: 3.75rem;
  --prose: 46rem;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --bg-subtle: #1a1d22;
    --bg-raised: #1c1f25;
    --border: #2a2e36;
    --border-strong: #3a3f49;
    --text: #e6e8ec;
    --text-muted: #9ba3ae;
    --text-faint: #6f7883;
    --accent: #6f9bff;
    --accent-soft: #1d2637;
    --code-bg: #1a1d23;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .45);

    --hint-info-bd: #3b82f6;   --hint-info-bg: #16223a;
    --hint-success-bd: #10b981; --hint-success-bg: #10261f;
    --hint-warning-bd: #f59e0b; --hint-warning-bg: #2a2113;
    --hint-danger-bd: #ef4444;  --hint-danger-bg: #2b1719;
  }
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --bg-subtle: #1a1d22;
  --bg-raised: #1c1f25;
  --border: #2a2e36;
  --border-strong: #3a3f49;
  --text: #e6e8ec;
  --text-muted: #9ba3ae;
  --text-faint: #6f7883;
  --accent: #6f9bff;
  --accent-soft: #1d2637;
  --code-bg: #1a1d23;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .45);

  --hint-info-bd: #3b82f6;   --hint-info-bg: #16223a;
  --hint-success-bd: #10b981; --hint-success-bg: #10261f;
  --hint-warning-bd: #f59e0b; --hint-warning-bg: #2a2113;
  --hint-danger-bd: #ef4444;  --hint-danger-bg: #2b1719;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 1rem); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: .6rem 1rem;
}
.skip:focus { left: .5rem; top: .5rem; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1rem;
  height: var(--topbar-h);
  padding: 0 1.25rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-name { font-weight: 650; font-size: .95rem; color: var(--text); letter-spacing: -.01em; }
.brand-tagline { font-size: .72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .08em; }

.menu-btn {
  display: none; flex-direction: column; justify-content: center; gap: 4px;
  width: 2.1rem; height: 2.1rem; padding: 0 .35rem;
  background: none; border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.menu-btn span { display: block; height: 1.5px; background: var(--text); border-radius: 2px; }

.theme-btn {
  flex: none;
  display: grid; place-items: center;
  width: 2.1rem; height: 2.1rem;
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-muted); cursor: pointer;
}
.theme-btn:hover { color: var(--text); border-color: var(--border-strong); }
.theme-btn svg { grid-area: 1 / 1; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}

/* ------------------------------------------------------------------ search */

.search { position: relative; margin-left: auto; width: min(22rem, 42vw); }
#search-input {
  width: 100%; height: 2.1rem;
  padding: 0 2rem 0 .75rem;
  font: inherit; font-size: .875rem;
  color: var(--text); background: var(--bg-subtle);
  border: 1px solid var(--border); border-radius: 8px;
  appearance: none;
}
#search-input:focus { outline: none; border-color: var(--accent); background: var(--bg); }
#search-input::-webkit-search-cancel-button { appearance: none; }

.search-key {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  font-family: var(--mono); font-size: .7rem; color: var(--text-faint);
  border: 1px solid var(--border); border-radius: 4px; padding: 0 .3rem;
  pointer-events: none;
}
#search-input:focus ~ .search-key { display: none; }

.search-results {
  position: absolute; top: calc(100% + .5rem); right: 0;
  width: min(30rem, 90vw); max-height: 65vh; overflow-y: auto;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: .35rem;
}
.search-results a {
  display: block; padding: .5rem .65rem; border-radius: 8px; color: var(--text);
}
.search-results a:hover, .search-results a.sel { background: var(--accent-soft); text-decoration: none; }
.sr-title { display: block; font-weight: 600; font-size: .9rem; }
.sr-section { color: var(--text-faint); font-weight: 400; }
.sr-snippet {
  display: block; font-size: .8rem; color: var(--text-muted); line-height: 1.5;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.sr-snippet mark, .sr-title mark { background: none; color: var(--accent); font-weight: 650; }
.sr-empty { padding: .9rem .75rem; color: var(--text-muted); font-size: .875rem; }

/* ------------------------------------------------------------------ layout */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--onpage-w);
  max-width: 96rem; margin: 0 auto;
  align-items: start;
}

.sidebar, .onpage {
  position: sticky; top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 1.75rem 1rem 3rem 1.25rem;
  font-size: .875rem;
}
.sidebar { border-right: 1px solid var(--border); }
.onpage { padding-left: 1.5rem; }

.nav-group {
  margin: 1.5rem 0 .4rem; padding-left: .6rem;
  font-size: .7rem; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-faint);
}
.nav-group:first-child { margin-top: 0; }
.nav-list { list-style: none; margin: 0 0 .25rem; padding: 0; }
.nav-list a {
  display: block; padding: .32rem .6rem; border-radius: 7px;
  color: var(--text-muted); line-height: 1.45;
}
.nav-list a:hover { background: var(--bg-subtle); color: var(--text); text-decoration: none; }
.nav-list a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.toc-title {
  margin: 0 0 .5rem; font-size: .7rem; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; color: var(--text-faint);
}
.toc-list, .toc-sub { list-style: none; margin: 0; padding: 0; }
.toc-sub { padding-left: .8rem; }
.toc-list a {
  display: block; padding: .22rem 0 .22rem .7rem;
  border-left: 2px solid var(--border);
  color: var(--text-muted); font-size: .82rem; line-height: 1.45;
}
.toc-list a:hover { color: var(--text); text-decoration: none; }
.toc-list a.active { color: var(--accent); border-left-color: var(--accent); }

.content { min-width: 0; padding: 2.5rem 3rem 5rem; }

/* ------------------------------------------------------------------- prose */

.prose { max-width: var(--prose); }
.prose > :first-child { margin-top: 0; }

.prose h1 {
  font-size: 2.2rem; line-height: 1.2; letter-spacing: -.025em;
  font-weight: 700; margin: 0 0 1.25rem;
}
.prose h2 {
  font-size: 1.45rem; line-height: 1.3; letter-spacing: -.015em; font-weight: 650;
  margin: 3rem 0 1rem; padding-top: .75rem; border-top: 1px solid var(--border);
}
.prose h3 { font-size: 1.12rem; font-weight: 650; margin: 2rem 0 .75rem; }
.prose h4 { font-size: 1rem; font-weight: 650; margin: 1.5rem 0 .5rem; }

.prose p, .prose ul, .prose ol { margin: 0 0 1.1rem; }
.prose li { margin-bottom: .4rem; }
.prose li > ul, .prose li > ol { margin: .4rem 0 0; }
.prose strong { font-weight: 650; color: var(--text); }

.headerlink {
  margin-left: .4rem; color: var(--text-faint); font-weight: 400;
  opacity: 0; transition: opacity .12s;
}
h2:hover .headerlink, h3:hover .headerlink, .headerlink:focus { opacity: 1; text-decoration: none; }

.prose blockquote {
  margin: 0 0 1.1rem; padding: .1rem 0 .1rem 1rem;
  border-left: 3px solid var(--border-strong); color: var(--text-muted);
}

.prose table {
  width: 100%; border-collapse: collapse; margin: 0 0 1.25rem; font-size: .9rem;
}
.prose th, .prose td { border: 1px solid var(--border); padding: .5rem .7rem; text-align: left; }
.prose th { background: var(--bg-subtle); font-weight: 650; }
.table-wrap { overflow-x: auto; margin-bottom: 1.25rem; }
.table-wrap table { margin-bottom: 0; }

.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }

/* -------------------------------------------------------------------- code */

code {
  font-family: var(--mono); font-size: .87em;
}
.prose :not(pre) > code {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 5px; padding: .1em .35em; color: var(--text);
  word-break: break-word;
}

.codeblock { position: relative; margin: 0 0 1.35rem; }
.highlight {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 10px; overflow-x: auto;
}
.highlight pre { margin: 0; padding: .95rem 1.1rem; font-size: .85rem; line-height: 1.6; }
.highlight code { background: none; border: 0; padding: 0; }

.copy-btn {
  position: absolute; top: .5rem; right: .5rem;
  padding: .2rem .5rem; font: inherit; font-size: .72rem;
  color: var(--text-muted); background: var(--bg-raised);
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
  opacity: 0; transition: opacity .12s;
}
.codeblock:hover .copy-btn, .copy-btn:focus { opacity: 1; }
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* Pygments tokens (light) */
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs { color: #6a737d; font-style: italic; }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kc, .highlight .kr, .highlight .kt { color: #b3007a; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sc, .highlight .se { color: #0a7c3f; }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .mh { color: #b45309; }
.highlight .nc, .highlight .nn { color: #6f42c1; }
.highlight .nf, .highlight .na { color: #1f6feb; }
.highlight .nb, .highlight .bp { color: #b3007a; }
.highlight .o, .highlight .ow, .highlight .p { color: var(--text-muted); }
.highlight .err { color: inherit; }

:root[data-theme="dark"] .highlight .c,
:root[data-theme="dark"] .highlight .c1,
:root[data-theme="dark"] .highlight .cm { color: #7d8590; }
:root[data-theme="dark"] .highlight .k,
:root[data-theme="dark"] .highlight .kd,
:root[data-theme="dark"] .highlight .kn,
:root[data-theme="dark"] .highlight .kc,
:root[data-theme="dark"] .highlight .kr,
:root[data-theme="dark"] .highlight .kt { color: #ff7bd0; }
:root[data-theme="dark"] .highlight .s,
:root[data-theme="dark"] .highlight .s1,
:root[data-theme="dark"] .highlight .s2,
:root[data-theme="dark"] .highlight .se { color: #7ee2a8; }
:root[data-theme="dark"] .highlight .m,
:root[data-theme="dark"] .highlight .mi,
:root[data-theme="dark"] .highlight .mf { color: #f0b072; }
:root[data-theme="dark"] .highlight .nc,
:root[data-theme="dark"] .highlight .nn { color: #c9a5ff; }
:root[data-theme="dark"] .highlight .nf,
:root[data-theme="dark"] .highlight .na { color: #79b8ff; }
:root[data-theme="dark"] .highlight .nb,
:root[data-theme="dark"] .highlight .bp { color: #ff7bd0; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .highlight .c,
  :root:not([data-theme="light"]) .highlight .c1,
  :root:not([data-theme="light"]) .highlight .cm { color: #7d8590; }
  :root:not([data-theme="light"]) .highlight .k,
  :root:not([data-theme="light"]) .highlight .kd,
  :root:not([data-theme="light"]) .highlight .kn,
  :root:not([data-theme="light"]) .highlight .kc,
  :root:not([data-theme="light"]) .highlight .kr,
  :root:not([data-theme="light"]) .highlight .kt { color: #ff7bd0; }
  :root:not([data-theme="light"]) .highlight .s,
  :root:not([data-theme="light"]) .highlight .s1,
  :root:not([data-theme="light"]) .highlight .s2,
  :root:not([data-theme="light"]) .highlight .se { color: #7ee2a8; }
  :root:not([data-theme="light"]) .highlight .m,
  :root:not([data-theme="light"]) .highlight .mi,
  :root:not([data-theme="light"]) .highlight .mf { color: #f0b072; }
  :root:not([data-theme="light"]) .highlight .nc,
  :root:not([data-theme="light"]) .highlight .nn { color: #c9a5ff; }
  :root:not([data-theme="light"]) .highlight .nf,
  :root:not([data-theme="light"]) .highlight .na { color: #79b8ff; }
  :root:not([data-theme="light"]) .highlight .nb,
  :root:not([data-theme="light"]) .highlight .bp { color: #ff7bd0; }
}

/* ------------------------------------------------------------------- hints */

.hint {
  position: relative;
  margin: 0 0 1.35rem;
  padding: .9rem 1.1rem .9rem 3rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: 10px;
  font-size: .95rem;
}
.hint > :last-child { margin-bottom: 0; }
.hint::before {
  position: absolute; left: 1rem; top: .85rem;
  font-size: 1rem; line-height: 1.4;
}
.hint-info    { background: var(--hint-info-bg);    border-left-color: var(--hint-info-bd); }
.hint-success { background: var(--hint-success-bg); border-left-color: var(--hint-success-bd); }
.hint-warning { background: var(--hint-warning-bg); border-left-color: var(--hint-warning-bd); }
.hint-danger  { background: var(--hint-danger-bg);  border-left-color: var(--hint-danger-bd); }
.hint-info::before    { content: "ℹ"; color: var(--hint-info-bd); }
.hint-success::before { content: "✓"; color: var(--hint-success-bd); }
.hint-warning::before { content: "⚠"; color: var(--hint-warning-bd); }
.hint-danger::before  { content: "⛔"; color: var(--hint-danger-bd); }
.hint :not(pre) > code { background: color-mix(in srgb, var(--text) 8%, transparent); }

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

.pager-row {
  display: flex; gap: 1rem; max-width: var(--prose);
  margin-top: 3.5rem; padding-top: 1.75rem; border-top: 1px solid var(--border);
}
.pager {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; gap: .15rem;
  padding: .8rem 1rem;
  border: 1px solid var(--border); border-radius: 10px;
  color: var(--text);
}
.pager:hover { border-color: var(--accent); text-decoration: none; }
.pager.next { margin-left: auto; text-align: right; }
.pager-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); }
.pager-title { font-weight: 600; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.page-footer {
  max-width: var(--prose); margin-top: 2rem;
  font-size: .82rem; color: var(--text-faint);
}
.page-footer a { color: var(--text-muted); }

.scrim {
  position: fixed; inset: var(--topbar-h) 0 0; z-index: 25;
  background: rgba(0, 0, 0, .35);
}

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

@media (max-width: 1180px) {
  .shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .onpage { display: none; }
  .content { padding: 2.5rem 2rem 5rem; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: flex; }
  .brand-tagline { display: none; }
  .search { width: auto; flex: 1 1 auto; }
  .sidebar {
    position: fixed; z-index: 30; left: 0; top: var(--topbar-h);
    width: min(19rem, 82vw); height: calc(100vh - var(--topbar-h));
    max-height: none; background: var(--bg);
    transform: translateX(-102%); transition: transform .18s ease;
  }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .content { padding: 2rem 1.25rem 4rem; }
  .prose h1 { font-size: 1.85rem; }
  .pager-row { flex-direction: column; }
  .pager.next { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .copy-btn, .headerlink { transition: none; }
}

@media print {
  .topbar, .sidebar, .onpage, .pager-row, .scrim, .copy-btn { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; }
}
