:root {
  --bg: #ffffff;
  --bg-subtle: #f7f7f8;
  --bg-elevated: #ffffff;
  --fg: #1f2023;
  --fg-muted: #666970;
  --border: #e6e6e9;
  --accent: #0070f3;
  --accent-soft: #eaf3ff;
  --code-bg: #f6f8fa;
  --code-fg: #24292f;
  --blockquote-bg: #f7f9fc;
  --topbar-height: 60px;
  --sidebar-width: 280px;
  --toc-width: 230px;
  color-scheme: light;
}

html[data-theme='dark'] {
  --bg: #0b0c0e;
  --bg-subtle: #121315;
  --bg-elevated: #17181b;
  --fg: #ededf0;
  --fg-muted: #9b9ea6;
  --border: #2a2b30;
  --accent: #5aa9ff;
  --accent-soft: #122842;
  --code-bg: #15171a;
  --code-fg: #e6e6e6;
  --blockquote-bg: #15171a;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-height) + 16px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  text-decoration: underline;
}

button {
  font: inherit;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--fg);
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
}

.topbar-spacer {
  flex: 1;
}

.router-switch {
  display: flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-subtle);
}

.router-switch a {
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1.4;
}

.router-switch a:hover {
  color: var(--fg);
  text-decoration: none;
}

.router-switch a.active {
  background: var(--bg-elevated);
  color: var(--fg);
  box-shadow: 0 1px 3px rgb(0 0 0 / 12%);
}

.icon-button,
.search-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 13px;
}

.icon-button:hover,
.search-button:hover {
  color: var(--fg);
  text-decoration: none;
}

.search-button kbd {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  font-family: inherit;
  font-size: 11px;
  color: var(--fg-muted);
}

.sidebar-toggle {
  display: none;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--toc-width);
  gap: 40px;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 32px 80px;
}

.sidebar {
  position: sticky;
  top: var(--topbar-height);
  align-self: start;
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  padding: 28px 8px 48px 0;
  border-right: 1px solid var(--border);
  scrollbar-width: thin;
}

.sidebar-label {
  margin: 0 0 10px 12px;
  color: var(--fg-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-group > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--fg);
  list-style: none;
}

.nav-group > summary::-webkit-details-marker {
  display: none;
}

.nav-group > summary::before {
  content: '›';
  color: var(--fg-muted);
  font-size: 16px;
  transition: transform 0.15s ease;
}

.nav-group[open] > summary::before {
  transform: rotate(90deg);
}

.nav-group > summary:hover {
  background: var(--bg-subtle);
}

.nav-group .nav-list {
  margin: 2px 0 6px 10px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.nav-link {
  display: block;
  padding: 4px 10px;
  border-radius: 6px;
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1.5;
}

.nav-link:hover {
  background: var(--bg-subtle);
  color: var(--fg);
  text-decoration: none;
}

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

.nav-index {
  color: var(--fg);
  font-style: italic;
}

.main {
  min-width: 0;
  padding-top: 36px;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
  color: var(--fg-muted);
  font-size: 12px;
}

.breadcrumbs a {
  color: inherit;
}

.breadcrumbs span + span::before {
  content: '/';
  margin-right: 6px;
  color: var(--border);
}

.article {
  max-width: 820px;
}

.article h1 {
  margin: 0 0 12px;
  font-size: 34px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.article h2,
.article h3,
.article h4 {
  margin: 40px 0 12px;
  line-height: 1.3;
  scroll-margin-top: calc(var(--topbar-height) + 20px);
}

.article h2 {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 23px;
}

.article h3 {
  font-size: 18px;
}

.article h4 {
  font-size: 15px;
}

.article h2 .anchor,
.article h3 .anchor,
.article h4 .anchor {
  margin-left: 8px;
  color: var(--border);
  font-weight: 400;
  opacity: 0;
}

.article h2:hover .anchor,
.article h3:hover .anchor,
.article h4:hover .anchor {
  opacity: 1;
}

.lead {
  margin: 0 0 28px;
  color: var(--fg-muted);
  font-size: 17px;
  line-height: 1.6;
}

.version-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.article blockquote.callout-warning {
  border-left-color: #e5a50a;
}

.article blockquote.callout-tip {
  border-left-color: #19b37a;
}

.article p,
.article ul,
.article ol {
  margin: 0 0 18px;
}

.article ul,
.article ol {
  padding-left: 24px;
}

.article li {
  margin: 4px 0;
}

.article li::marker {
  color: var(--fg-muted);
}

.article code {
  padding: 0.15em 0.4em;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-subtle);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  overflow-wrap: anywhere;
}

.article pre {
  margin: 0;
  overflow-x: auto;
}

.article pre code {
  display: block;
  padding: 16px 18px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--code-fg);
  font-size: 13px;
  line-height: 1.65;
}

.code-block {
  margin: 22px 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--code-bg);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 12px;
}

.copy-button {
  border: 0;
  padding: 3px 8px;
  border-radius: 5px;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 12px;
}

.copy-button:hover {
  background: var(--bg-subtle);
  color: var(--fg);
}

.article blockquote {
  margin: 22px 0;
  padding: 12px 18px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--blockquote-bg);
  color: var(--fg);
}

.article blockquote p:last-child {
  margin-bottom: 0;
}

.article table {
  display: block;
  width: 100%;
  margin: 22px 0;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 14px;
}

.article th,
.article td {
  padding: 9px 14px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.article th {
  background: var(--bg-subtle);
  font-weight: 600;
}

.article hr {
  margin: 40px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.doc-image {
  margin: 24px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-subtle);
  text-align: center;
}

.doc-image img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 6px;
}

.doc-image .image-dark {
  display: none;
}

html[data-theme='dark'] .doc-image .image-light {
  display: none;
}

html[data-theme='dark'] .doc-image .image-dark {
  display: block;
}

.doc-image figcaption {
  margin-top: 8px;
  color: var(--fg-muted);
  font-size: 12px;
}

.fix-cards {
  display: grid;
  gap: 12px;
  margin: 22px 0;
}

.fix-card {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
}

.fix-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}

.fix-card .badge {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--fg-muted);
  font-size: 11px;
  text-transform: uppercase;
}

.related {
  margin-top: 48px;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-subtle);
}

.related h2 {
  margin: 0 0 4px;
  font-size: 16px;
}

.related p {
  margin: 0 0 12px;
  color: var(--fg-muted);
  font-size: 13px;
}

.related ul {
  margin: 0;
  padding-left: 18px;
}

.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.page-nav a {
  display: flex;
  flex-direction: column;
  max-width: 48%;
  color: var(--fg-muted);
  font-size: 13px;
}

.page-nav a:last-child {
  text-align: right;
}

.page-nav strong {
  color: var(--fg);
  font-size: 15px;
}

.page-footer {
  margin-top: 40px;
  color: var(--fg-muted);
  font-size: 12px;
}

/* Table of contents */
.toc {
  position: sticky;
  top: var(--topbar-height);
  align-self: start;
  padding: 36px 0 48px;
}

.toc-title {
  margin-bottom: 10px;
  color: var(--fg-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.toc a {
  display: block;
  padding: 3px 0 3px 12px;
  border-left: 2px solid var(--border);
  color: var(--fg-muted);
  font-size: 12px;
  line-height: 1.5;
}

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

.toc a.level-3 {
  padding-left: 24px;
}

/* Search dialog */
.search-dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: min(70vh, 640px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elevated);
  color: var(--fg);
  box-shadow: 0 24px 70px rgb(0 0 0 / 25%);
}

.search-dialog::backdrop {
  background: rgb(0 0 0 / 45%);
  backdrop-filter: blur(2px);
}

.search-dialog form {
  margin: 0;
}

.search-dialog input {
  width: 100%;
  padding: 16px 20px;
  border: 0;
  border-bottom: 1px solid var(--border);
  outline: none;
  background: transparent;
  color: var(--fg);
  font-size: 16px;
}

.search-results {
  max-height: 480px;
  overflow-y: auto;
  margin: 0;
  padding: 8px;
  list-style: none;
}

.search-results a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--fg);
}

.search-results a:hover,
.search-results a.selected {
  background: var(--accent-soft);
  text-decoration: none;
}

.search-results strong {
  display: block;
  font-size: 14px;
}

.search-results small {
  display: block;
  margin-top: 2px;
  color: var(--fg-muted);
  font-size: 12px;
}

.search-empty {
  padding: 24px;
  color: var(--fg-muted);
  text-align: center;
}

/* Router content */
html[data-router='app'] [data-router-group='pages'],
html[data-router='pages'] [data-router-group='app'] {
  display: none !important;
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    gap: 32px;
  }

  .toc {
    display: none;
  }
}

@media (max-width: 800px) {
  .topbar {
    padding: 0 16px;
    gap: 10px;
  }

  .search-button span,
  .search-button kbd {
    display: none;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .layout {
    display: block;
    padding: 0 18px 60px;
  }

  .sidebar {
    display: none;
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    z-index: 20;
    width: min(320px, 86vw);
    height: calc(100vh - var(--topbar-height));
    padding: 24px 16px;
    background: var(--bg);
    box-shadow: 8px 0 30px rgb(0 0 0 / 12%);
  }

  html.sidebar-open .sidebar {
    display: block;
  }

  .main {
    padding-top: 24px;
  }

  .article h1 {
    font-size: 28px;
  }

  .page-nav {
    flex-direction: column;
  }

  .page-nav a {
    max-width: 100%;
  }

  .page-nav a:last-child {
    text-align: left;
  }
}
