:root {
  --bg: #0f1117;
  --bg-panel: #161922;
  --bg-elevated: #1c2029;
  --border: #2a2f3a;
  --text: #e4e7ee;
  --text-dim: #9aa2b1;
  --accent: #5fb3f2;
  --accent-soft: rgba(95, 179, 242, 0.12);
  --code-bg: #11141c;
  --green: #7bd88f;
  --yellow: #e8c170;
  --zebra: rgba(255, 255, 255, 0.015);
  --radius: 10px;
  --sidebar-w: 260px;
  --toc-w: 220px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-panel: #f7f8fa;
  --bg-elevated: #eef0f4;
  --border: #e1e4ea;
  --text: #1f2430;
  --text-dim: #667085;
  --accent: #2f7dc0;
  --accent-soft: rgba(47, 125, 192, 0.1);
  --code-bg: #f3f4f7;
  --green: #1f8a4c;
  --yellow: #9a6b00;
  --zebra: rgba(0, 0, 0, 0.02);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  scroll-behavior: smooth;
  transition: background-color 0.15s ease, color 0.15s ease;
}

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

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 20px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.brand .logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #5fb3f2, #7b6ff0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #0f1117;
  font-size: 14px;
}

.brand .title {
  font-weight: 600;
  font-size: 15px;
}

.brand .subtitle {
  font-size: 11px;
  color: var(--text-dim);
}

.nav-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  padding: 16px 8px 6px 8px;
}

.collapse-all-btn {
  text-transform: none;
  letter-spacing: 0;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}

.collapse-all-btn:hover {
  text-decoration: underline;
}

.nav-doc-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-doc-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.nav-doc-row .nav-doc-link {
  flex: 1;
  min-width: 0;
}

.nav-toggle {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: transform 0.15s ease;
}

.nav-toggle:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

.nav-toggle.open {
  transform: rotate(90deg);
}

.nav-doc-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13.5px;
  cursor: pointer;
}

.nav-doc-link:hover {
  background: var(--bg-elevated);
  text-decoration: none;
}

.nav-doc-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-doc-link .icon {
  width: 18px;
  text-align: center;
  opacity: 0.9;
}

.nav-headings {
  display: none;
  flex-direction: column;
  gap: 1px;
  margin: 2px 0 8px 30px;
  border-left: 1px solid var(--border);
  padding-left: 10px;
}

.nav-headings.open { display: flex; }

.nav-headings a {
  color: var(--text-dim);
  font-size: 12.5px;
  padding: 4px 0;
  line-height: 1.3;
}

.nav-headings a:hover, .nav-headings a.active {
  color: var(--accent);
  text-decoration: none;
}

/* Main content */
.content-wrap {
  padding: 40px 48px 100px 48px;
  min-width: 0;
}

.doc {
  max-width: 780px;
  margin: 0 auto;
}

/* Quick links (Tutorial / Cheatsheet / Mini Project) */
.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 780px;
  margin: 0 auto 24px auto;
}

.quick-links a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
}

.quick-links a:hover {
  color: var(--text);
  border-color: var(--accent);
  text-decoration: none;
}

.quick-links a.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.doc h1 {
  font-size: 30px;
  margin: 0 0 6px 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}

.doc > p:first-of-type {
  color: var(--text-dim);
  font-size: 15px;
  margin-top: 14px;
}

.doc h2 {
  font-size: 21px;
  margin: 40px 0 12px 0;
  padding-top: 8px;
  scroll-margin-top: 20px;
}

.doc h3 {
  font-size: 16.5px;
  color: var(--accent);
  margin: 26px 0 8px 0;
  scroll-margin-top: 20px;
}

.doc p, .doc li {
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--text);
}

.doc ul, .doc ol {
  padding-left: 22px;
}

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

.doc blockquote {
  margin: 16px 0;
  padding: 10px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
  color: var(--text-dim);
  font-size: 13.5px;
}

.doc blockquote p { margin: 0; color: inherit; }

.doc code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12.5px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  color: var(--yellow);
}

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

.doc pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
}

.doc table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0;
  font-size: 13.5px;
}

.doc th, .doc td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.doc th {
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.doc tr:nth-child(even) td {
  background: var(--zebra);
}

/* Table of contents (right rail) */
.toc {
  padding: 40px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-left: 1px solid var(--border);
}

.toc-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-left: 1px solid var(--border);
}

.toc-list a {
  color: var(--text-dim);
  font-size: 12.5px;
  padding: 4px 0 4px 12px;
  line-height: 1.4;
  border-left: 2px solid transparent;
  margin-left: -1px;
}

.toc-list a.h3 {
  padding-left: 24px;
  font-size: 12px;
}

.toc-list a:hover {
  color: var(--text);
  text-decoration: none;
}

.toc-list a.active {
  color: var(--accent);
  border-left: 2px solid var(--accent);
  font-weight: 600;
}

/* Search box */
.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 8px 4px 8px;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-box input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px 8px 30px;
  font-size: 13px;
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
}

.search-box .icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 12px;
}

/* Theme toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.theme-toggle-icon {
  font-size: 15px;
  line-height: 1;
}

.footer-note {
  margin-top: 60px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

/* Mobile */
@media (max-width: 1100px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 780px) {
  .layout { display: block; }
  .sidebar {
    position: relative;
    height: auto;
    width: 100%;
  }
  .content-wrap { padding: 28px 20px 80px 20px; }
}

/* Loading / error states */
.state-msg {
  color: var(--text-dim);
  font-size: 14px;
  padding: 40px 0;
}
