:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar-bg: #f7f7f6;
  --surface: #ffffff;
  --surface-subtle: #f7f7f7;
  --surface-hover: #efefee;
  --text: #18181b;
  --text-soft: #5f6368;
  --text-faint: #8a8d91;
  --border: #e3e3e1;
  --border-strong: #d5d5d2;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --accent-border: #bfdbfe;
  --code-bg: #171717;
  --code-text: #f5f5f4;
  --shadow: 0 8px 24px rgba(18, 18, 18, 0.08), 0 1px 2px rgba(18, 18, 18, 0.06);
  --sidebar-width: 270px;
  --toc-width: 270px;
  --mobile-header-height: 58px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111214;
  --sidebar-bg: #17181a;
  --surface: #1b1c1f;
  --surface-subtle: #202226;
  --surface-hover: #292b30;
  --text: #f4f4f5;
  --text-soft: #b3b5ba;
  --text-faint: #868991;
  --border: #303237;
  --border-strong: #41434a;
  --accent: #7aa2ff;
  --accent-soft: #1c2942;
  --accent-border: #37578f;
  --code-bg: #090a0b;
  --code-text: #f5f5f4;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.32), 0 1px 2px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 28px;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.7;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.page-progress {
  position: fixed;
  z-index: 100;
  top: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent);
  transition: width 80ms linear;
}

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

.sidebar {
  position: fixed;
  z-index: 30;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
}

.sidebar-inner {
  display: flex;
  height: 100%;
  flex-direction: column;
  padding: 22px 18px 14px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  margin: 0 3px 18px;
}

.brand,
.mobile-brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
}

.brand {
  gap: 9px;
  font-size: 15px;
}

.brand-mark {
  display: inline-grid;
  width: 25px;
  height: 25px;
  flex: 0 0 25px;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-family: Georgia, serif;
  font-size: 14px;
  font-weight: 700;
}

.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
}

.icon-button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-button svg,
.button svg,
.search-trigger svg,
.toc-title svg,
.back-to-top svg,
.search-input-wrap svg,
.action-menu svg,
.code-copy svg {
  width: 16px;
  height: 16px;
  stroke-width: 1.8;
}

.sidebar-close {
  display: none;
}

.search-trigger {
  display: flex;
  width: 100%;
  height: 38px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text-soft);
  padding: 0 8px 0 10px;
  cursor: pointer;
}

.search-trigger:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.search-label {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

kbd {
  border: 1px solid var(--border);
  border-bottom-color: var(--border-strong);
  border-radius: 5px;
  background: var(--surface-subtle);
  color: var(--text-faint);
  font-family: inherit;
  font-size: 11px;
  line-height: 20px;
  padding: 0 6px;
  white-space: nowrap;
}

.side-nav {
  min-height: 0;
  flex: 1;
  overflow: auto;
  margin: 24px -4px 14px;
  padding: 0 4px 20px;
  scrollbar-width: thin;
}

.side-group {
  margin-bottom: 22px;
}

.side-group-title {
  display: block;
  margin: 0 8px 7px;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.4;
  text-decoration: none;
}

.side-group-title:hover,
.side-group-title.active {
  color: var(--accent);
}

.side-link {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  border-left: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.35;
  padding: 7px 10px;
  text-decoration: none;
}

.side-link svg {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  stroke-width: 1.8;
}

.side-link:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.side-link.active,
.side-link.current {
  border-left-color: var(--text);
  background: var(--surface-hover);
  color: var(--text);
  font-weight: 550;
}

.side-link.level-3 {
  padding-left: 22px;
}

.sidebar-footer {
  display: flex;
  height: 42px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  padding: 3px 4px 3px 11px;
}

.sidebar-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-faint);
  font-size: 11px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22a06b;
}

.main {
  grid-column: 2;
  min-width: 0;
}

.article-shell {
  width: min(100%, 900px);
  margin: 0 auto;
  padding: 54px 36px 96px;
}

.article-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 24px;
}

.eyebrow {
  margin-bottom: 12px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 550;
}

.article-header h1 {
  margin: 0;
  color: var(--text);
  font-size: clamp(30px, 2.5vw, 36px);
  font-weight: 760;
  line-height: 1.18;
  letter-spacing: 0;
}

.lead {
  max-width: 760px;
  margin: 14px 0 0;
  color: var(--text-soft);
  font-size: 17px;
  line-height: 1.7;
}

.article-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}

.button {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 550;
  padding: 7px 10px;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover {
  border-color: var(--border-strong);
  background: var(--surface-subtle);
}

.button-chevron {
  width: 14px !important;
  height: 14px !important;
  color: var(--text-faint);
}

.action-menu-wrap {
  position: relative;
}

.action-menu {
  position: absolute;
  z-index: 15;
  top: calc(100% + 6px);
  left: 0;
  width: 190px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 5px;
}

.action-menu a,
.action-menu button {
  display: flex;
  width: 100%;
  min-height: 34px;
  align-items: center;
  gap: 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  padding: 7px 8px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.action-menu a:hover,
.action-menu button:hover {
  background: var(--surface-hover);
}

.article-content {
  color: var(--text);
  padding-top: 18px;
}

.article-content > :first-child {
  margin-top: 0;
}

.article-content h2,
.article-content h3,
.article-content h4 {
  position: relative;
  scroll-margin-top: 32px;
  color: var(--text);
  line-height: 1.3;
  letter-spacing: 0;
}

.article-content h2 {
  margin: 54px 0 18px;
  border-top: 1px solid var(--border);
  padding-top: 42px;
  font-size: 28px;
  font-weight: 730;
}

.article-content h2:first-of-type {
  margin-top: 24px;
  border-top: 0;
  padding-top: 0;
}

.article-content h3 {
  margin: 34px 0 12px;
  font-size: 21px;
  font-weight: 690;
}

.article-content h4 {
  margin: 26px 0 10px;
  font-size: 17px;
  font-weight: 680;
}

.heading-anchor {
  position: absolute;
  right: calc(100% + 7px);
  top: inherit;
  color: var(--text-faint);
  opacity: 0;
  text-decoration: none;
  transition: opacity 120ms ease;
}

h2:hover > .heading-anchor,
h3:hover > .heading-anchor,
h4:hover > .heading-anchor,
.heading-anchor:focus {
  opacity: 1;
}

.article-content p {
  margin: 14px 0;
  color: var(--text-soft);
}

.article-content strong {
  color: var(--text);
  font-weight: 680;
}

.article-content a {
  color: var(--text);
  font-weight: 550;
  text-decoration-color: var(--text-faint);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.article-content a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.article-content ul,
.article-content ol {
  margin: 14px 0;
  padding-left: 24px;
  color: var(--text-soft);
}

.article-content li {
  margin: 6px 0;
  padding-left: 3px;
}

.article-content li::marker {
  color: var(--text-faint);
}

.article-content hr {
  height: 1px;
  margin: 42px 0;
  border: 0;
  background: var(--border);
}

.article-content img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 24px auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.article-content blockquote {
  margin: 22px 0;
  border-left: 3px solid var(--border-strong);
  color: var(--text-soft);
  padding: 1px 0 1px 18px;
}

.article-content blockquote p {
  margin: 8px 0;
}

.article-content .callout {
  position: relative;
  margin: 20px 0;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--surface-subtle);
  box-shadow: 0 1px 2px rgba(18, 18, 18, 0.04);
  padding: 13px 17px 14px 42px;
}

.callout::before {
  position: absolute;
  top: 15px;
  left: 16px;
  display: grid;
  width: 17px;
  height: 17px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  content: "i";
  font-family: Georgia, serif;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.callout.callout-warning,
.callout.callout-caution {
  border-left-color: #d97706;
}

.callout.callout-warning::before,
.callout.callout-caution::before {
  background: #d97706;
  content: "!";
}

.callout.callout-important {
  border-left-color: #7c3aed;
}

.callout.callout-important::before {
  background: #7c3aed;
  content: "!";
}

.callout-title {
  margin: 0 0 3px !important;
  color: var(--text) !important;
  font-size: 13px;
  font-weight: 680;
}

.callout > :last-child {
  margin-bottom: 0;
}

.article-content code:not(pre code) {
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-subtle);
  color: var(--text);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.88em;
  padding: 2px 5px;
}

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

.code-header {
  display: flex;
  height: 38px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #a8a8a8;
  padding: 0 8px 0 14px;
}

.code-language {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  text-transform: uppercase;
}

.code-copy {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #b5b5b5;
  cursor: pointer;
}

.code-copy:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.article-content pre {
  overflow: auto;
  margin: 0;
  background: var(--code-bg);
  padding: 17px 18px 19px;
  scrollbar-color: #555 transparent;
}

.article-content pre code {
  color: var(--code-text);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
  tab-size: 2;
}

.table-wrap {
  overflow-x: auto;
  margin: 22px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.article-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.article-content th,
.article-content td {
  border-bottom: 1px solid var(--border);
  color: var(--text-soft);
  padding: 11px 13px;
  text-align: left;
  vertical-align: top;
}

.article-content th {
  background: var(--surface-subtle);
  color: var(--text);
  font-weight: 650;
}

.article-content tr:last-child td {
  border-bottom: 0;
}

.toc-panel {
  position: fixed;
  z-index: 10;
  inset: 0 0 0 auto;
  width: var(--toc-width);
  border-left: 1px solid transparent;
  background: var(--bg);
}

.toc-inner {
  height: 100%;
  overflow: auto;
  padding: 48px 28px 28px 24px;
  scrollbar-width: thin;
}

.toc-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 12px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 650;
}

.toc {
  position: relative;
  border-left: 1px solid var(--border);
}

.toc a {
  position: relative;
  display: block;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.45;
  padding: 6px 0 6px 14px;
  text-decoration: none;
}

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

.toc a.active {
  color: var(--text);
  font-weight: 600;
}

.toc a.active::before {
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: -1px;
  width: 2px;
  background: var(--text);
  content: "";
}

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

.toc a.level-4 {
  padding-left: 38px;
}

.back-to-top {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 20px;
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 12px;
  padding: 6px 0;
  cursor: pointer;
}

.back-to-top:hover {
  color: var(--text);
}

.mobile-header {
  display: none;
}

.drawer-backdrop {
  position: fixed;
  z-index: 25;
  inset: 0;
  background: rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(2px);
}

.search-dialog {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: rgba(16, 16, 18, 0.42);
  padding: 12vh 20px 20px;
  backdrop-filter: blur(3px);
}

.search-panel {
  width: min(100%, 620px);
  max-height: min(620px, 72vh);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.22);
}

.search-input-wrap {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  height: 54px;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-faint);
  padding: 0 14px 0 17px;
}

.search-input-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 15px;
}

.search-input-wrap input::placeholder {
  color: var(--text-faint);
}

.search-results {
  max-height: calc(min(620px, 72vh) - 54px);
  overflow: auto;
  padding: 7px;
}

.search-result {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 10px 11px;
  text-align: left;
  cursor: pointer;
}

.search-result:hover,
.search-result:focus {
  background: var(--surface-hover);
}

.search-result-title {
  display: block;
  font-size: 13px;
  font-weight: 650;
}

.search-result-kicker {
  display: block;
  margin-bottom: 2px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 650;
}

.search-result-preview {
  display: -webkit-box;
  overflow: hidden;
  margin-top: 3px;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.search-empty {
  color: var(--text-faint);
  font-size: 13px;
  padding: 28px 14px;
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 90;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  padding: 10px 13px;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.loading-state {
  display: grid;
  gap: 14px;
  padding: 18px 0;
}

.loading-bar {
  width: 100%;
  height: 14px;
  border-radius: 5px;
  background: var(--surface-hover);
}

.loading-bar.short {
  width: 64%;
}

.error-state {
  margin: 24px 0;
  border: 1px solid #efb1b1;
  border-radius: 8px;
  background: #fff5f5;
  color: #8b1f1f;
  padding: 16px;
}

html[data-theme="dark"] .error-state {
  border-color: #6f3434;
  background: #2c1a1a;
  color: #f2b8b8;
}

@media (max-width: 1180px) {
  :root {
    --toc-width: 230px;
  }

  .article-shell {
    padding-right: 28px;
    padding-left: 28px;
  }

  .toc-inner {
    padding-right: 18px;
    padding-left: 18px;
  }
}

@media (max-width: 1020px) {
  .app-shell {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

  .toc-panel {
    display: none;
  }

  .article-shell {
    width: min(100%, 900px);
  }
}

@media (max-width: 760px) {
  html {
    scroll-padding-top: calc(var(--mobile-header-height) + 12px);
  }

  body.drawer-open {
    overflow: hidden;
  }

  .mobile-header {
    position: fixed;
    z-index: 22;
    top: 0;
    right: 0;
    left: 0;
    display: flex;
    height: var(--mobile-header-height);
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    padding: 0 12px;
    backdrop-filter: blur(12px);
  }

  .mobile-brand {
    gap: 8px;
    max-width: calc(100vw - 120px);
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-brand .brand-mark {
    width: 23px;
    height: 23px;
    flex-basis: 23px;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    width: min(310px, 88vw);
    transform: translateX(-102%);
    transition: transform 180ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close {
    display: inline-grid;
  }

  .main {
    padding-top: var(--mobile-header-height);
  }

  .article-shell {
    width: 100%;
    padding: 34px 20px 72px;
  }

  .article-header h1 {
    font-size: 30px;
  }

  .lead {
    font-size: 15px;
  }

  .article-content h2 {
    margin-top: 42px;
    padding-top: 34px;
    font-size: 24px;
    scroll-margin-top: calc(var(--mobile-header-height) + 16px);
  }

  .article-content h3 {
    font-size: 19px;
    scroll-margin-top: calc(var(--mobile-header-height) + 16px);
  }

  .heading-anchor {
    display: none;
  }

  .toc-panel {
    z-index: 30;
    display: block;
    width: min(310px, 88vw);
    border-left: 1px solid var(--border);
    transform: translateX(102%);
    transition: transform 180ms ease;
  }

  .toc-panel.open {
    transform: translateX(0);
  }

  .toc-inner {
    padding: 26px 22px;
  }

  .toc-title {
    margin-bottom: 16px;
    font-size: 13px;
  }

  .toc a {
    font-size: 13px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .toast {
    right: 16px;
    bottom: 16px;
  }
}

@media (max-width: 430px) {
  .article-shell {
    padding-right: 16px;
    padding-left: 16px;
  }

  .article-actions {
    align-items: stretch;
  }

  .button {
    min-height: 38px;
  }

  .article-actions > .button {
    flex: 1;
  }

  .action-menu-wrap {
    width: auto;
    flex: 1;
  }

  .action-menu-wrap > .button {
    width: 100%;
  }

  .action-menu {
    right: 0;
    left: auto;
    width: 100%;
  }

  .article-content .callout {
    padding-right: 14px;
    padding-left: 39px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
