:root {
  --brand: #f36805;
  --brand-soft: rgba(243, 104, 5, 0.1);
  --bg: #ffffff;
  --bg-soft: #f8f9fb;
  --bg-code: #f6f7f9;
  --text: #1a1d21;
  --text-muted: #5c6470;
  --border: #e5e8ec;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
  --radius: 10px;
  --sidebar-w: 268px;
  --toc-w: 220px;
  --topbar-h: 60px;
  --info: #0a6aa1;
  --info-bg: #e8f4fb;
  --warn: #9a5b00;
  --warn-bg: #fdf3e2;
  --danger: #a4262c;
  --danger-bg: #fdeced;
}

html[data-theme="dark"] {
  --bg: #0f1115;
  --bg-soft: #161920;
  --bg-code: #1a1e26;
  --text: #e6e8eb;
  --text-muted: #9aa3af;
  --border: #262b35;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --info: #6cc0ef;
  --info-bg: rgba(10, 106, 161, 0.14);
  --warn: #e0a656;
  --warn-bg: rgba(154, 91, 0, 0.16);
  --danger: #f08b91;
  --danger-bg: rgba(164, 38, 44, 0.16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  z-index: 200;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  text-decoration: none;
}
.skip-link:focus { left: 8px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; flex-shrink: 0; }
.brand img { height: 30px; width: auto; }

.topbar-search {
  position: relative;
  flex: 1;
  max-width: 440px;
  margin-left: auto;
}
.topbar-search input {
  width: 100%;
  height: 38px;
  padding: 0 40px 0 38px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.topbar-search input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}
.topbar-search kbd {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  padding: 2px 7px;
  font-family: inherit;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.version-pill {
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: 999px;
}

.ghost-btn {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background .15s, border-color .15s;
}
.ghost-btn:hover { background: var(--bg-soft); border-color: var(--text-muted); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--text);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#themeToggle .moon { display: none; }
html[data-theme="dark"] #themeToggle .sun { display: none; }
html[data-theme="dark"] #themeToggle .moon { display: block; }

/* ---------- Layout ---------- */
.shell { display: flex; align-items: flex-start; }

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  flex-shrink: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--topbar-h));
  padding: 22px 12px 40px 18px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.nav-group { margin-bottom: 22px; }
.nav-group-title {
  margin: 0 0 6px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.nav-link {
  display: block;
  padding: 7px 10px;
  font-size: 14px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 7px;
  transition: background .12s, color .12s;
}
.nav-link:hover { color: var(--text); background: var(--bg-soft); }
.nav-link.active {
  color: var(--brand);
  background: var(--brand-soft);
  font-weight: 500;
}
.nav-link.hidden { display: none; }
.nav-group.hidden { display: none; }

#main { flex: 1; min-width: 0; }
.content { max-width: 800px; padding: 36px 40px 72px; }

.toc {
  position: sticky;
  top: var(--topbar-h);
  flex-shrink: 0;
  width: var(--toc-w);
  height: calc(100vh - var(--topbar-h));
  padding: 26px 20px;
  overflow-y: auto;
}
.toc-title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.toc a {
  display: block;
  padding: 5px 0 5px 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid var(--border);
}
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--brand); border-left-color: var(--brand); }

/* ---------- Content ---------- */
section { scroll-margin-top: calc(var(--topbar-h) + 16px); padding-bottom: 8px; }
section + section { margin-top: 12px; padding-top: 40px; border-top: 1px solid var(--border); }

h2 {
  margin: 0 0 18px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.3;
}
h3 { margin: 34px 0 14px; font-size: 21px; font-weight: 600; letter-spacing: -.01em; }
h4 { margin: 30px 0 12px; font-size: 17px; font-weight: 600; }
h5 { margin: 22px 0 10px; font-size: 15px; font-weight: 600; }

p { margin: 0 0 14px; }
ul, ol { margin: 0 0 16px; padding-left: 22px; }
li { margin-bottom: 7px; }
li > ul, li > ol { margin-top: 7px; }
b, strong { font-weight: 600; }
hr { display: none; }

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

code {
  padding: 2px 6px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .87em;
  color: var(--text);
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 5px;
}

pre {
  position: relative;
  margin: 0 0 18px;
  padding: 0;
  overflow: hidden;
  background: #282c34;
  border-radius: var(--radius);
}
pre code {
  display: block;
  padding: 16px 18px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.65;
  color: #abb2bf;
  background: none;
  border: 0;
  border-radius: 0;
}
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 5px 11px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: #abb2bf;
  background: rgba(255, 255, 255, .08);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, background .15s;
}
pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: rgba(255, 255, 255, .16); }
.copy-btn.done { color: #7ec699; }

kbd {
  padding: 2px 6px;
  font-family: inherit;
  font-size: 12px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-soft);
}

img { max-width: 100%; height: auto; }
.popup-img {
  display: inline-block;
  max-width: 560px;
  margin: 6px 0 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: zoom-in;
  transition: box-shadow .18s, transform .18s;
}
.popup-img:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.popup-img img { display: block; }
.img-fluid.border { border: 0 !important; }

/* ---------- Callouts ---------- */
.alert {
  display: block;
  margin: 0 0 18px;
  padding: 13px 16px;
  font-size: 14px;
  border: 1px solid;
  border-left-width: 3px;
  border-radius: var(--radius);
}
.alert-info { color: var(--info); background: var(--info-bg); border-color: var(--info); }
.alert-warning { color: var(--warn); background: var(--warn-bg); border-color: var(--warn); }
.alert-danger { color: var(--danger); background: var(--danger-bg); border-color: var(--danger); }
.alert a { color: inherit; text-decoration: underline; }
.alert-heading { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.alert .mb-0 { margin-bottom: 0; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  border-radius: 999px;
  vertical-align: middle;
}
.badge-danger { color: #fff; background: var(--danger); }
.badge-light { color: var(--danger); background: rgba(255, 255, 255, .92); }
.text-uppercase { text-transform: uppercase; }
.mr-2 { margin-right: 8px; }

/* ---------- Cards ---------- */
.card {
  margin: 0 0 22px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.card-header {
  padding: 14px 18px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}
.card-header h5 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
.card-header i { display: none; }
.card-body { padding: 18px; }
.card-body > :last-child { margin-bottom: 0; }
.bg-primary, .text-white { background: transparent !important; color: var(--text) !important; }
.border-0 { border: 1px solid var(--border) !important; }
.shadow-sm { box-shadow: var(--shadow) !important; }

/* ---------- Grid helpers from the old markup ---------- */
.row { display: flex; flex-wrap: wrap; gap: 0 28px; }
.row > [class*="col-"] { flex: 1 1 260px; min-width: 0; }
.col-lg-8, .col-sm-6, .col-md-6, .col-12 { padding: 0; }
.pl-0 { padding-left: 0; }
.pl-3, .pl-4 { padding-left: 22px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 26px; }
.mt-5 { margin-top: 32px; }
.mb-4 { margin-bottom: 22px; }
.mb-5 { margin-bottom: 26px; }
.my-2 { margin: 8px 0; }
.py-3 { padding: 14px 18px; }
.lead { font-size: 16px; color: var(--text-muted); }
.list-unstyled { padding-left: 0; list-style: none; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.font-weight-bold, .font-weight-700 { font-weight: 600; }
.underline { text-decoration: underline; }
.bold { font-weight: 600; }
.changelog { padding-left: 0; list-style: none; }
.divider { display: none; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  place-items: center;
  padding: 40px;
  background: rgba(8, 10, 14, .88);
  backdrop-filter: blur(3px);
}
.lightbox.open { display: grid; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 40px;
  height: 40px;
  font-size: 28px;
  line-height: 1;
  color: #fff;
  background: rgba(255, 255, 255, .12);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, .22); }

/* ---------- Back to top ---------- */
.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #fff;
  background: var(--brand);
  border: 0;
  border-radius: 50%;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s, visibility .2s, transform .2s;
}
.back-to-top.show { opacity: 1; visibility: visible; }
.back-to-top:hover { transform: translateY(-2px); }
.back-to-top svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.footer {
  padding: 26px 40px;
  border-top: 1px solid var(--border);
}
.footer p { margin: 0; font-size: 13px; color: var(--text-muted); }

.no-results {
  padding: 14px 10px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- Responsive ---------- */
.backdrop {
  position: fixed;
  inset: var(--topbar-h) 0 0;
  z-index: 40;
  display: none;
  background: rgba(8, 10, 14, .45);
}
.backdrop.open { display: block; }

@media (max-width: 1180px) {
  .toc { display: none; }
}

@media (max-width: 991px) {
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    z-index: 50;
    background: var(--bg);
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .sidebar.open { transform: none; }
  .content { padding: 28px 22px 60px; }
  .footer { padding: 22px; }
  .topbar-search { max-width: none; }
}

@media (min-width: 992px) {
  .lg-hide { display: none; }
}

@media (max-width: 640px) {
  .sm-hide { display: none; }
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar-search kbd { display: none; }
  .version-pill { display: none; }
  h2 { font-size: 23px; }
  .popup-img { max-width: 100%; }
}

.footer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- Reading progress ---------- */
.progress-bar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  z-index: 55;
  height: 2px;
  width: 0;
  background: var(--brand);
  transition: width .1s linear;
}

/* ---------- Collapsible nav groups ---------- */
.nav-group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin: 0 0 4px;
  padding: 6px 10px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  transition: color .12s, background .12s;
}
.nav-group-title:hover { color: var(--text); background: var(--bg-soft); }
.nav-group-title .chev {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: rotate(90deg);
  transition: transform .18s ease;
}
.nav-group-title[aria-expanded="false"] .chev { transform: none; }

.nav-group-items { display: flex; flex-direction: column; gap: 1px; }
.nav-group-title[aria-expanded="false"] + .nav-group-items { display: none; }

.nav-link {
  position: relative;
  padding-left: 22px;
}
.nav-link::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 50%;
  width: 2px;
  height: 0;
  background: var(--brand);
  border-radius: 2px;
  transform: translateY(-50%);
  transition: height .18s ease;
}
.nav-link.active::before { height: 16px; }
.nav-link:focus-visible,
.nav-group-title:focus-visible,
.toc a:focus-visible,
.icon-btn:focus-visible,
.ghost-btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ---------- Anchor links on headings ---------- */
.anchor {
  margin-left: 8px;
  font-size: .8em;
  color: var(--text-muted);
  opacity: 0;
  text-decoration: none;
  transition: opacity .15s;
}
h2:hover .anchor,
h3:hover .anchor,
h4:hover .anchor,
.anchor:focus-visible { opacity: 1; }
.anchor:hover { color: var(--brand); text-decoration: none; }

/* ---------- Prev / next pager ---------- */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  max-width: 800px;
  padding: 0 40px 40px;
}
.pager a {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 16px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.pager a:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow);
  text-decoration: none;
  transform: translateY(-1px);
}
.pager .dir { font-size: 12px; color: var(--text-muted); }
.pager .name { font-size: 15px; font-weight: 600; }
.pager .next { text-align: right; grid-column: 2; }

/* ---------- Search results count ---------- */
.search-count {
  padding: 4px 10px 10px;
  font-size: 12px;
  color: var(--text-muted);
}

@media (max-width: 991px) {
  .pager { padding: 0 22px 32px; }
}
@media (max-width: 640px) {
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; text-align: left; }
}
