:root {
  /* Dark theme: black background, white foreground. */
  --bg: #000000;
  --bg-elev: #0c0d10;
  --bg-code: #0a0a0c;
  --bg-sidebar: #060607;
  --border: #23262d;
  --border-soft: #16181d;
  --text: #f2f4f8;
  --text-dim: #9aa3b2;
  --accent: #5ab0ff;
  --accent-dim: #1f4a7a;
  --accent-soft: #11233a;
  --green: #7ee787;
  --yellow: #e3c878;
  --red: #ff7b72;
  --radius: 10px;
  --topbar-h: 60px;
  --sidebar-w: 264px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- Top bar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.topbar img.logo {
  height: 32px;
  width: auto;
  display: block;
}
.topbar .brand {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.topbar .brand .name {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.2px;
}
.topbar .brand .sub {
  font-size: 0.72rem;
  color: var(--text-dim);
}
.topbar .spacer { flex: 1; }
.topbar .topbar-link {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
}
.topbar .topbar-link:hover { color: var(--text); }
.lang-switcher {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
}
.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 5px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font: 600 0.78rem/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  cursor: pointer;
  white-space: nowrap;
}
.lang-btn:hover { color: var(--text); background: var(--border-soft); }
.lang-btn.active {
  color: var(--text);
  background: var(--accent-soft);
}
.lang-btn .flag {
  font-size: 1rem;
  line-height: 1;
}

/* --------------------------------------------------------------- Sidebar */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 0 40px;
}
.sidebar .nav-search {
  padding: 0 16px 14px;
}
.sidebar .nav-search input {
  width: 100%;
  padding: 9px 12px;
  font-size: 0.86rem;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
.sidebar .nav-search input:focus { border-color: var(--accent); }

.sidebar .nav-group { margin: 6px 0 18px; }
.sidebar .nav-group h4 {
  margin: 0;
  padding: 6px 18px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
}
.sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.sidebar li a {
  display: block;
  padding: 7px 18px 7px 22px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 2px solid transparent;
}
.sidebar li a:hover { color: var(--text); background: var(--border-soft); }
.sidebar li a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
}
.sidebar li a .nav-ns {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: "SF Mono", Menlo, monospace;
}

/* --------------------------------------------------------------- Content */
.content {
  margin-left: var(--sidebar-w);
  padding-top: var(--topbar-h);
}
.content .inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 36px 40px 96px;
}

/* Legacy wrappers map onto the new content column so existing markup works. */
.wrap { max-width: 860px; margin: 0 auto; padding: 0 40px; }
/* When the page's own <main class="wrap"> is moved inside the injected
   .content > .inner column, drop its width/padding so it doesn't double up. */
.content .inner .wrap { max-width: none; padding: 0; margin: 0; }
.site-header { display: none; }  /* replaced by the fixed top bar */

main { display: block; }

.intro p { color: var(--text-dim); font-size: 1.02rem; }

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

h1 { font-size: 1.9rem; letter-spacing: -0.5px; margin: 0 0 6px; }
.page-tagline { color: var(--text-dim); margin: 0 0 8px; font-size: 1.02rem; }

h2 {
  margin-top: 44px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 1.35rem;
}
h3 { margin: 28px 0 6px; font-size: 1.12rem; }
h4 { font-size: 1rem; }

p, li { color: var(--text); }

code {
  font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--bg-code);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: #e8ecf2;
}

.breadcrumb { margin: 0 0 18px; font-size: 0.88rem; color: var(--text-dim); }

/* --------------------------------------------------- Class list (index) */
.card-grid {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--accent); transform: translateX(3px); }
.card a { display: block; padding: 18px 20px; color: inherit; }
.card a:hover { text-decoration: none; }
.card h3 { margin: 0 0 4px; }
.card .ns {
  margin: 0 0 8px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 0.8rem;
  color: var(--accent);
}
.card .desc { margin: 0; color: var(--text-dim); font-size: 0.92rem; }
.no-results { color: var(--text-dim); font-style: italic; }

/* The old top-of-page search box is now in the sidebar; hide the inline one. */
.search-block { display: none; }

/* ------------------------------------------------------------- Members */
.signature {
  display: block;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 12px 16px;
  margin: 12px 0;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 0.86rem;
  white-space: pre-wrap;
  overflow-x: auto;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
}
pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text);
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.9rem;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th { color: var(--text-dim); font-weight: 600; }
tbody tr:hover { background: var(--border-soft); }

/* Parameter tables get a touch more structure. */
table.params td:first-child,
table.params th:first-child { white-space: nowrap; }
table.params code { background: var(--accent-soft); border-color: var(--accent-dim); }

/* ------------------------------------------------------ Wiring diagrams */
.wiring {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin: 18px 0;
  overflow-x: auto;
}
.wiring svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.wiring .cap {
  margin: 10px 2px 0;
  font-size: 0.84rem;
  color: var(--text-dim);
  text-align: center;
}
/* SVG primitives shared by the diagrams. */
.wire-svg .chip { fill: var(--bg-sidebar); stroke: var(--border); stroke-width: 1.5; }
.wire-svg .mcu  { fill: #0d1b2a; stroke: var(--accent-dim); stroke-width: 1.5; }
.wire-svg .title { fill: var(--text); font: 700 14px -apple-system, sans-serif; }
.wire-svg .sub   { fill: var(--text-dim); font: 11px "SF Mono", monospace; }
.wire-svg .pin   { fill: var(--text); font: 12px "SF Mono", monospace; }
.wire-svg .pinr  { fill: var(--text); font: 12px "SF Mono", monospace; text-anchor: end; }
.wire-svg .lbl   { fill: var(--text-dim); font: 10px "SF Mono", monospace; text-anchor: middle; }
.wire-svg .pad   { fill: var(--bg-code); stroke: var(--border); stroke-width: 1; }
.wire-svg .w-pwr { stroke: #ff5252; stroke-width: 2.5; fill: none; }
.wire-svg .w-gnd { stroke: #8b97a7; stroke-width: 2.5; fill: none; }
.wire-svg .w-sig { stroke: var(--accent); stroke-width: 2.5; fill: none; }
.wire-svg .w-clk { stroke: #e3c878; stroke-width: 2.5; fill: none; }
.wire-svg .dot-pwr { fill: #ff5252; }
.wire-svg .dot-gnd { fill: #8b97a7; }
.wire-svg .dot-sig { fill: var(--accent); }
.wire-svg .dot-clk { fill: #e3c878; }

/* Small inline legend for diagram wire colors. */
.wire-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.wire-legend span { display: inline-flex; align-items: center; gap: 6px; }
.wire-legend i {
  width: 18px; height: 3px; border-radius: 2px; display: inline-block;
}

.member {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 16px 0;
}
.member h4 {
  margin: 0 0 4px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 0.98rem;
  color: var(--green);
}

.tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  vertical-align: middle;
}
.tag-static { background: var(--accent-soft); color: #cfe6ff; }
.tag-enum { background: #2a2150; color: #d9ccff; }

/* Color swatch: a small circle shown before a status name in the LED tables. */
.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: -1px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 0 5px rgba(255, 255, 255, 0.12);
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ---------------------------------------------------- Callout / try-it box */
.callout {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--bg-elev);
  border-radius: 8px;
  padding: 12px 18px;
  margin: 18px 0;
}
.callout.warn { border-left-color: var(--red); }
.callout .callout-title {
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  margin: 0 0 6px;
}

/* Minimal C++ syntax highlight classes */
.tok-kw { color: var(--red); }
.tok-type { color: var(--yellow); }
.tok-str { color: var(--green); }
.tok-com { color: var(--text-dim); font-style: italic; }
.tok-fn { color: var(--accent); }

/* --------------------------------------------------------------- Responsive */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { margin-left: 0; }
  .content .inner, .wrap { padding-left: 22px; padding-right: 22px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .topbar .brand .sub, .topbar .topbar-link { display: none; }
  .lang-btn span:not(.flag) { display: none; }
  .lang-btn { width: 32px; justify-content: center; padding: 5px; }
}
