:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #f0f2ee;
  --text: #1d2420;
  --muted: #68716c;
  --line: #dfe4df;
  --accent: #136f63;
  --accent-strong: #0b5149;
  --accent-soft: #dceee9;
  --warning: #a44e12;
  --warning-soft: #fff0df;
  --danger: #a13232;
  --danger-soft: #fbe8e8;
  --code-bg: #17201d;
  --code-text: #e5ede9;
  --shadow: 0 10px 30px rgba(27, 42, 36, 0.08);
  --topbar-height: 64px;
  --sidebar-width: 278px;
  --toc-width: 228px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111614;
  --surface: #181f1c;
  --surface-soft: #202925;
  --text: #edf2ef;
  --muted: #9ca8a2;
  --line: #2e3934;
  --accent: #63c6b5;
  --accent-strong: #94dfd1;
  --accent-soft: #203c36;
  --warning: #f0aa65;
  --warning-soft: #3a2a1e;
  --danger: #f08c8c;
  --danger-soft: #3b2424;
  --code-bg: #0c100f;
  --code-text: #e6efeb;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

button, input { font: inherit; }

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

a { color: var(--accent); }

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

.topbar {
  grid-column: 1 / -1;
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-height);
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(280px, 660px) 36px 36px;
  align-items: center;
  gap: 22px;
  padding: 0 24px 0 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--text);
  color: var(--surface);
  font: 700 17px/1 Georgia, serif;
}

.brand-copy {
  display: grid;
  line-height: 1.2;
  overflow: hidden;
}

.brand-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.brand-copy small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

.search-wrap {
  position: relative;
  width: 100%;
  justify-self: center;
}

.search-wrap input {
  width: 100%;
  height: 38px;
  padding: 0 42px 0 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
  background: var(--surface-soft);
  color: var(--text);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.search-wrap input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

.search-icon {
  position: absolute;
  left: 13px;
  top: 7px;
  z-index: 1;
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
}

kbd {
  position: absolute;
  right: 10px;
  top: 9px;
  min-width: 20px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  font: 11px/17px ui-monospace, SFMono-Regular, Consolas, monospace;
  text-align: center;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover { background: var(--surface-soft); border-color: var(--line); }

a.icon-button { text-decoration: none; }

.sidebar {
  grid-column: 1;
  grid-row: 2;
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}

.sidebar-head {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.category-nav {
  display: flex;
  gap: 6px;
  padding: 0 14px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.category-nav::-webkit-scrollbar { display: none; }

.category-button {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.category-button.active,
.category-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.article-nav {
  min-height: 0;
  flex: 1;
  padding: 2px 10px 18px;
  overflow-y: auto;
}

.nav-link {
  width: 100%;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 10px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

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

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

.nav-index {
  padding-top: 1px;
  font: 600 11px/1.7 ui-monospace, SFMono-Regular, Consolas, monospace;
  color: var(--muted);
}

.nav-copy { min-width: 0; display: grid; }

.nav-copy strong {
  overflow: hidden;
  color: inherit;
  font-size: 13px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-copy small {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2eaa78;
  box-shadow: 0 0 0 3px color-mix(in srgb, #2eaa78 20%, transparent);
}

.main-view {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  padding: 40px clamp(28px, 5vw, 72px) 96px;
}

.article {
  width: min(100%, 820px);
  margin: 0 auto;
}

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

.eyebrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  margin-bottom: 14px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.eyebrow span {
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--accent-soft);
}

.article h1 {
  margin: 0 0 12px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.18;
  letter-spacing: 0;
}

.article-description {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
}

.article-body h2,
.article-body h3,
.article-body h4 {
  scroll-margin-top: calc(var(--topbar-height) + 18px);
  line-height: 1.35;
  letter-spacing: 0;
}

.article-body h2 {
  margin: 42px 0 14px;
  padding-top: 3px;
  font-size: 23px;
}

.article-body h3 { margin: 30px 0 11px; font-size: 18px; }
.article-body h4 { margin: 24px 0 9px; font-size: 15px; }
.article-body p { margin: 0 0 16px; }
.article-body ul, .article-body ol { margin: 0 0 18px; padding-left: 23px; }
.article-body li { margin: 5px 0; padding-left: 3px; }
.article-body strong { color: var(--text); }
.article-body hr { margin: 32px 0; border: 0; border-top: 1px solid var(--line); }
.article-body a { text-underline-offset: 3px; }

.article-body img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 680px;
  margin: 22px auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.article-body blockquote {
  margin: 22px 0;
  padding: 15px 18px;
  border-left: 4px solid var(--accent);
  border-radius: 0 6px 6px 0;
  background: var(--accent-soft);
  color: var(--text);
}

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

.article-body table {
  width: 100%;
  margin: 20px 0 24px;
  border-collapse: collapse;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
}

.article-body th,
.article-body td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.article-body th { background: var(--surface-soft); font-weight: 700; }

.table-wrap { width: 100%; overflow-x: auto; }

.code-block {
  position: relative;
  margin: 20px 0 24px;
  border: 1px solid color-mix(in srgb, var(--line) 70%, #000);
  border-radius: 7px;
  background: var(--code-bg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.code-head {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 14px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  color: #96aaa2;
  font: 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.copy-button {
  width: 30px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #c8d6d0;
  cursor: pointer;
}

.copy-button:hover { background: rgba(255,255,255,.1); }

.code-block pre {
  margin: 0;
  padding: 17px;
  overflow-x: auto;
  color: var(--code-text);
  font: 12.5px/1.65 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  tab-size: 2;
}

.article-body :not(pre) > code {
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.toc-panel {
  grid-column: 3;
  grid-row: 2;
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  padding: 36px 22px 24px 0;
  overflow-y: auto;
}

.toc-title {
  margin-bottom: 12px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

#toc { display: grid; gap: 2px; border-left: 1px solid var(--line); }

.toc-link {
  display: block;
  margin-left: -1px;
  padding: 5px 0 5px 13px;
  border-left: 2px solid transparent;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  text-decoration: none;
}

.toc-link.level-3 { padding-left: 25px; }
.toc-link:hover, .toc-link.active { border-left-color: var(--accent); color: var(--accent-strong); }

.source-card {
  display: grid;
  margin-top: 28px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.source-card span, .source-card small { color: var(--muted); font-size: 10px; }
.source-card strong { margin: 3px 0; font-size: 11px; }

.search-summary {
  width: min(100%, 820px);
  margin: 0 auto 22px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

mark {
  padding: 0 2px;
  border-radius: 2px;
  background: #ffe18c;
  color: #2d2512;
}

.empty-state, .loading {
  padding: 70px 20px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  padding: 9px 14px;
  border-radius: 6px;
  background: var(--text);
  color: var(--surface);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.scrim { display: none; }
.mobile-only { display: none; }

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .toc-panel { display: none; }
  .main-view { grid-column: 2; }
}

@media (max-width: 760px) {
  :root { --topbar-height: 58px; }
  .app-shell { display: block; }
  .topbar {
    grid-template-columns: 36px minmax(0, 1fr) 36px 36px;
    gap: 9px;
    height: var(--topbar-height);
    padding: 0 10px;
  }
  .mobile-only { display: grid; }
  .brand { display: none; }
  .search-wrap input { height: 36px; padding-right: 12px; }
  .search-wrap kbd { display: none; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 90;
    width: min(86vw, 310px);
    height: 100vh;
    transform: translateX(-102%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-head { height: 58px; }
  .scrim {
    position: fixed;
    inset: 0;
    z-index: 80;
    border: 0;
    background: rgba(6, 11, 9, .48);
  }
  .scrim.show { display: block; }
  .main-view { padding: 28px 18px 70px; }
  .article h1 { font-size: 30px; }
  .article-description { font-size: 14px; }
  .article-body h2 { margin-top: 34px; font-size: 21px; }
  .article-body table { min-width: 580px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
