:root {
  --bg: #0f1115;
  --panel: #161922;
  --panel-2: #1c202b;
  --border: #262b38;
  --text: #e6e9f0;
  --text-dim: #9aa3b5;
  --accent: #5b9dff;
  --accent-2: #7ee0c0;
  --code-bg: #10131a;
  --radius: 10px;
  --sidebar-w: 300px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

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

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: rgba(15,17,21,0.9);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
}

.topbar .brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

#menuToggle {
  display: none;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 16px;
}

.searchWrap {
  flex: 1;
  max-width: 420px;
  position: relative;
}

#searchInput {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
}
#searchInput:focus { outline: 2px solid var(--accent); }

.searchWrap::before {
  content: "🔍";
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  opacity: 0.6;
}

#searchCount {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  max-width: 1280px;
  margin: 0 auto;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 53px;
  align-self: start;
  height: calc(100vh - 53px);
  overflow-y: auto;
  padding: 18px 10px 40px;
  border-right: 1px solid var(--border);
}

.sidebar .group {
  margin-bottom: 6px;
}

.sidebar .group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 14px 12px 6px;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 14px;
  text-decoration: none;
}

.sidebar a .num {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  opacity: 0.7;
}

.sidebar a:hover {
  background: var(--panel);
  color: var(--text);
}

.sidebar a.active {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar a.hidden-by-search {
  display: none;
}

/* ---------- Content ---------- */
main {
  padding: 30px 40px 120px;
  min-width: 0;
}

.hero {
  padding: 30px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 30px;
}

.hero h1 {
  font-size: 32px;
  margin: 0 0 10px;
}

.hero p {
  color: var(--text-dim);
  font-size: 16px;
  max-width: 640px;
}

.badges { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

section.lesson {
  padding: 40px 0;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: 70px;
}

section.lesson:last-of-type { border-bottom: none; }

section.lesson .kicker {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

section.lesson h2 {
  font-size: 24px;
  margin: 0 0 16px;
}

section.lesson h3 {
  font-size: 17px;
  margin: 26px 0 10px;
  color: var(--text);
}

section.lesson p { margin: 0 0 14px; color: #d3d7e2; }

section.lesson ul, section.lesson ol {
  margin: 0 0 14px;
  padding-left: 22px;
  color: #d3d7e2;
}
section.lesson li { margin-bottom: 6px; }

section.lesson code.inline {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 5px;
  font-family: "Cascadia Code", Consolas, Menlo, monospace;
  font-size: 13px;
  color: var(--accent-2);
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 16px;
}

pre code {
  font-family: "Cascadia Code", Consolas, Menlo, monospace;
  font-size: 13px;
  color: #c9e8ff;
  line-height: 1.6;
}

.callout {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px 16px;
  margin: 0 0 16px;
  background: var(--panel);
}
.callout.tip { border-left: 3px solid var(--accent-2); }
.callout.warn { border-left: 3px solid #f0b95b; }
.callout .label { font-weight: 700; font-size: 13px; margin-bottom: 4px; }

table.field-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 18px;
  font-size: 14px;
}
table.field-table th, table.field-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}
table.field-table th {
  background: var(--panel);
  color: var(--text-dim);
  font-weight: 600;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 0 0 16px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card h4 { margin: 0 0 6px; font-size: 14px; }
.card p { margin: 0; font-size: 13px; color: var(--text-dim); }

.footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 30px 0 60px;
}

mark {
  background: rgba(91,157,255,0.35);
  color: inherit;
  border-radius: 3px;
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  :root { --sidebar-w: 260px; }
  #menuToggle { display: inline-block; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0; top: 53px;
    width: var(--sidebar-w);
    height: calc(100vh - 53px);
    background: var(--bg);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 40;
  }
  .sidebar.open { transform: translateX(0); }
  main { padding: 24px 18px 100px; }
  .searchWrap { max-width: none; }
}
