/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fff;
  --bg-secondary: #f3f3f3;
  --bg-tertiary: #e9eaec;
  --text: #3d4144;
  --text-secondary: #6f777d;
  --text-muted: #959da5;
  --border: #e4e5e6;
  --accent: #2f7bbf;
  --accent-hover: #2669a3;
  --code-bg: #f6f8fa;
  --code-border: #e1e4e8;
  --shadow: 0 1px 1px rgba(0,0,0,.075);
  --shadow-lg: 0 2px 8px rgba(0,0,0,.1);
  --radius: 0;
  --font-system: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "Roboto", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "Fira Code", "Consolas", monospace;
  --sidebar-width: 220px;
  --toc-width: 220px;
  --max-content: 800px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-system);
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s;
}

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

/* ===== Masthead ===== */
.masthead {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  animation: intro .3s both;
  animation-delay: .15s;
}

.masthead__inner {
  max-width: calc(var(--sidebar-width) + var(--max-content) + var(--toc-width) + 80px);
  margin: 0 auto;
  padding: 0 20px;
}

.greedy-nav {
  display: flex;
  align-items: center;
  min-height: 56px;
}

.site-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 1.25em;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  margin-right: 32px;
  white-space: nowrap;
}

.site-title:hover {
  color: var(--accent);
  text-decoration: none;
}

.version {
  font-size: .7em;
  font-weight: 400;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 1px 8px;
  border-radius: 0;
}

.visible-links {
  display: flex;
  list-style: none;
  gap: 4px;
}

.visible-links a {
  display: block;
  padding: 6px 14px;
  font-size: .875em;
  color: var(--text-secondary);
  border-radius: var(--radius);
  text-decoration: none;
  transition: all .15s;
}

.visible-links a:hover {
  color: var(--text);
  background: var(--bg-secondary);
  text-decoration: none;
}

.visible-links a.active {
  color: var(--accent);
  background: rgba(47,123,191,.08);
}

/* ===== Main Layout ===== */
.initial-content {
  flex: 1;
  max-width: calc(var(--sidebar-width) + var(--max-content) + var(--toc-width) + 80px);
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

#main {
  display: flex;
  gap: 0;
  padding-top: 32px;
}

/* ===== Left Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  padding-right: 20px;
  opacity: .85;
  transition: opacity .2s;
}

.sidebar:hover {
  opacity: 1;
}

.sidebar.sticky {
  position: sticky;
  top: calc(56px + 32px);
  align-self: flex-start;
  max-height: calc(100vh - 56px - 64px);
  overflow-y: auto;
}

.nav__list {
  margin-bottom: 1.5em;
}

.nav__sub-title {
  display: block;
  font-size: .75em;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.nav__items {
  list-style: none;
  font-size: .875em;
}

.nav__items li {
  margin-bottom: 2px;
}

.nav__items a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  color: var(--text-secondary);
  border-radius: var(--radius);
  text-decoration: none;
  transition: all .15s;
}

.nav__items a:hover {
  color: var(--text);
  background: var(--bg-secondary);
  text-decoration: none;
}

.nav__items a.active {
  color: var(--accent);
  background: rgba(47,123,191,.08);
  font-weight: 500;
}

.nav__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: .7em;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-radius: 0;
  flex-shrink: 0;
}

.nav__items a.active .nav__icon {
  color: #fff;
  background: var(--accent);
}

/* ===== Content ===== */
.page {
  flex: 1;
  min-width: 0;
  padding: 0 32px;
  max-width: var(--max-content);
}

.page__inner {
  animation: intro .3s both;
}

.page h2 {
  font-size: 1.6em;
  font-weight: 700;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  color: var(--text);
}

.page h3 {
  font-size: 1.2em;
  font-weight: 600;
  margin: 28px 0 10px;
  color: var(--text);
}

.page h4 {
  font-size: 1em;
  font-weight: 600;
  margin: 20px 0 8px;
  color: var(--text-secondary);
}

.page p {
  margin-bottom: 12px;
}

.page ul, .page ol {
  margin: 8px 0 16px 24px;
}

.page li {
  margin-bottom: 4px;
}

.page strong {
  font-weight: 600;
  color: var(--text);
}

/* ===== Right Sidebar (TOC) ===== */
.sidebar__right {
  width: var(--toc-width);
  flex-shrink: 0;
  padding-left: 20px;
}

.sidebar__right.sticky {
  position: sticky;
  top: calc(56px + 32px);
  align-self: flex-start;
}

.toc {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toc .nav__title {
  margin: 0;
  padding: 8px 14px;
  font-size: .75em;
  font-weight: 700;
  color: #fff;
  background: var(--text-secondary);
  border-radius: 0;
}

.toc__menu {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: .75em;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

.toc__menu li {
  border-bottom: 1px solid var(--border);
}

.toc__menu li:last-child {
  border-bottom: none;
}

.toc__menu a {
  display: block;
  padding: 6px 14px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all .15s;
  border-left: 2px solid transparent;
}

.toc__menu a:hover {
  color: var(--text);
  background: var(--bg-secondary);
  text-decoration: none;
}

.toc__menu a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(47,123,191,.04);
  font-weight: 500;
}

.toc__menu .toc-h3 {
  padding-left: 28px;
  font-size: .95em;
}

/* ===== Code ===== */
code {
  font-family: var(--font-mono);
  font-size: .85em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 0;
  padding: 1px 5px;
  color: #24292e;
  word-break: break-word;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 16px 0;
  overflow-x: auto;
  font-size: .85em;
  line-height: 1.6;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* ===== Info Boxes ===== */
.info-box {
  background: #f0f7ff;
  border: 1px solid #b3d8ff;
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 16px 0;
  font-size: .9em;
}

.info-box p {
  margin: 0;
}

.info-box.warning {
  background: #fff8e6;
  border-color: #ffd666;
  border-left-color: #e6a700;
}

.info-box.tip {
  background: #e8f5e9;
  border-color: #a5d6a7;
  border-left-color: #4caf50;
}

/* ===== Feature Grid ===== */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.feature-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: box-shadow .2s;
}

.feature-card:hover {
  box-shadow: var(--shadow-lg);
}

.feature-card h4 {
  margin: 0 0 6px;
  font-size: .95em;
}

.feature-card p {
  margin: 0;
  font-size: .85em;
  color: var(--text-secondary);
}

/* ===== Page Nav ===== */
.page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: .9em;
}

.page-nav a {
  font-weight: 500;
}

/* ===== Table ===== */
.page table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: .9em;
}

.page th {
  text-align: left;
  background: var(--bg-secondary);
  padding: 8px 12px;
  border: 1px solid var(--border);
  font-weight: 600;
}

.page td {
  padding: 8px 12px;
  border: 1px solid var(--border);
}

.page tr:nth-child(even) td {
  background: var(--bg-secondary);
}

/* ===== Loading ===== */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 1em;
}

/* ===== Footer ===== */
.page__footer {
  margin-top: 60px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.page__footer-inner {
  max-width: calc(var(--sidebar-width) + var(--max-content) + var(--toc-width) + 80px);
  margin: 0 auto;
  padding: 20px;
  font-size: .8em;
  color: var(--text-muted);
  text-align: center;
}

/* ===== Animations ===== */
@keyframes intro {
  0% {
    opacity: 0;
    transform: translateY(8px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 0;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  .sidebar__right {
    display: none;
  }
}

@media (max-width: 900px) {
  .sidebar {
    display: none;
  }

  .page {
    padding: 0;
  }

  .visible-links {
    display: none;
  }

  .masthead__inner {
    padding: 0 16px;
  }

  .initial-content {
    padding: 0 16px;
  }
}