:root {
  color-scheme: light dark;
  --topbar-height: 64px;
  --sidebar-width: 304px;
  --page: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #f0f2f5;
  --surface-raised: #e8ebf0;
  --text: #17191d;
  --text-muted: #626873;
  --border: #d8dce3;
  --accent: #2b64d8;
  --accent-soft: #e7eefc;
  --code: #eef1f5;
  --quote: #eef4ff;
  --video: #b43b45;
  --image: #6f4bb7;
  --tool: #2d7b55;
  --music: #a36b18;
  --danger: #b72f3b;
  --danger-soft: rgb(218 54 51 / 0.08);
  --danger-border: rgb(218 54 51 / 0.34);
  --success: #247a4c;
  --success-soft: rgb(63 185 80 / 0.08);
  --success-border: rgb(63 185 80 / 0.34);
  --warning: #946200;
  --warning-soft: rgb(210 153 34 / 0.09);
  --warning-border: rgb(210 153 34 / 0.38);
  --radius: 6px;
  --shadow: 0 12px 40px rgb(27 35 50 / 0.12);
  font-family: "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

:root[data-theme="dark"] {
  --page: #0d0f12;
  --surface: #14171c;
  --surface-soft: #1b1f26;
  --surface-raised: #242a34;
  --text: #f1f3f6;
  --text-muted: #9da5b1;
  --border: #2c323c;
  --accent: #6d9eff;
  --accent-soft: #1c2d50;
  --code: #20252e;
  --quote: #171f2d;
  --video: #e4636b;
  --image: #a985ec;
  --tool: #62b98a;
  --music: #deb35c;
  --danger: #ff7b72;
  --danger-soft: rgb(218 54 51 / 0.11);
  --danger-border: rgb(218 54 51 / 0.38);
  --success: #56d364;
  --success-soft: rgb(63 185 80 / 0.1);
  --success-border: rgb(63 185 80 / 0.36);
  --warning: #e3b341;
  --warning-soft: rgb(210 153 34 / 0.1);
  --warning-border: rgb(210 153 34 / 0.38);
  --shadow: 0 16px 48px rgb(0 0 0 / 0.34);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  line-height: 1.65;
}

button, input { font: inherit; }
a { color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 30;
  height: var(--topbar-height);
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(260px, 520px) 1fr;
  align-items: center;
  gap: 24px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 750;
  text-decoration: none;
  letter-spacing: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}

.search input {
  width: 100%;
  height: 38px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-soft);
  outline: none;
}

.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.top-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 14px;
  white-space: nowrap;
}

.top-actions > a {
  color: var(--text-muted);
  text-decoration: none;
}

.top-actions > a:hover { color: var(--text); }

.theme-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.theme-control button,
.mobile-menu {
  border: 0;
  border-radius: 4px;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
}

.theme-control button {
  min-width: 44px;
  padding: 4px 8px;
  font-size: 12px;
}

.theme-control button[aria-pressed="true"] {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.08);
}

.layout { min-height: 100dvh; }

.sidebar {
  position: fixed;
  z-index: 20;
  inset: var(--topbar-height) auto 0 0;
  width: var(--sidebar-width);
  overflow-y: auto;
  padding: 18px 14px 32px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar-intro {
  margin-bottom: 18px;
  padding: 13px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  font-size: 12px;
}

.sidebar-intro p {
  margin: 4px 0 0;
  color: var(--text-muted);
  line-height: 1.55;
}

.nav-group { margin: 0 0 14px; }

.nav-group-title {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 4px 8px 7px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 720;
}

.group-key {
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
}

.nav-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  padding: 7px 9px 7px 12px;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
}

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

.nav-item.active {
  border-left-color: var(--accent);
  color: var(--text);
  background: var(--accent-soft);
  font-weight: 650;
}

.nav-tag {
  padding: 1px 6px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.5;
}

.tag-video { color: var(--video); }
.tag-image, .tag-official { color: var(--image); }
.tag-tool, .tag-text, .tag-ref, .tag-guide { color: var(--tool); }
.tag-music { color: var(--music); }

.sidebar-meta {
  margin: 22px 8px 0;
  color: var(--text-muted);
  font-size: 11px;
}

.content {
  margin-left: var(--sidebar-width);
  padding: calc(var(--topbar-height) + 34px) clamp(24px, 5vw, 76px) 80px;
}

.doc-section {
  display: none;
  width: min(100%, 1040px);
  margin: 0 auto;
}

.doc-section.active { display: block; }

.doc-section > h1:first-child {
  margin: 0 0 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
  font-size: clamp(28px, 3vw, 38px);
  line-height: 1.25;
}

h2 {
  margin: 38px 0 14px;
  font-size: 23px;
  line-height: 1.35;
}

h3 {
  margin: 28px 0 12px;
  font-size: 18px;
}

p { max-width: 76ch; }

table {
  width: 100%;
  margin: 16px 0 24px;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 14px;
}

th, td {
  padding: 11px 13px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-raised);
  font-weight: 700;
}

tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-soft) 58%, transparent); }

code {
  padding: 2px 5px;
  border-radius: 4px;
  color: var(--text);
  background: var(--code);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
  overflow-wrap: anywhere;
}

.code-block {
  position: relative;
  margin: 16px 0 24px;
}

pre {
  margin: 0;
  padding: 18px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  line-height: 1.6;
}

pre code { padding: 0; background: transparent; }

.copy-button {
  position: absolute;
  top: 9px;
  right: 9px;
  min-width: 52px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
}

.copy-button:hover { color: var(--text); border-color: var(--accent); }

blockquote {
  margin: 18px 0 24px;
  padding: 14px 17px;
  border-left: 3px solid var(--accent);
  background: var(--quote);
  color: var(--text-muted);
}

.doc-section .vg-callout {
  margin: 16px 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.doc-section .vg-callout.vg-danger {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.doc-section .vg-callout.vg-ok {
  border-color: var(--success-border);
  background: var(--success-soft);
}

.doc-section .vg-callout.vg-warn {
  border-color: var(--warning-border);
  background: var(--warning-soft);
}

.doc-section .vg-t {
  margin-bottom: 6px;
  font-weight: 700;
}

.doc-section .vg-danger .vg-t { color: var(--danger); }
.doc-section .vg-ok .vg-t { color: var(--success); }
.doc-section .vg-warn .vg-t { color: var(--warning); }

.doc-section .vg-card {
  margin: 12px 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.doc-section .vg-card .vg-hd {
  margin-bottom: 6px;
  font-size: 15px;
  font-weight: 700;
}

.doc-section .vg-card blockquote { margin-block: 12px; }
.doc-section .vg-check li { margin: 6px 0; }
.doc-section td.bad { color: var(--danger); }
.doc-section td.good { color: var(--success); }

ul, ol { padding-left: 24px; }
li { margin: 8px 0; }

.empty-search {
  width: min(100%, 760px);
  margin: 80px auto;
  text-align: center;
}

.empty-search p { margin-inline: auto; color: var(--text-muted); }
.mobile-menu, .sidebar-backdrop { display: none; }

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    padding: 0 14px;
  }

  .mobile-menu {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 36px;
    border: 1px solid var(--border);
  }

  .brand span:last-child { display: none; }
  .search { grid-column: 2; }
  .top-actions > a { display: none; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

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

  .sidebar-backdrop {
    position: fixed;
    z-index: 15;
    inset: var(--topbar-height) 0 0;
    border: 0;
    background: rgb(0 0 0 / 0.46);
  }

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

  .content {
    margin-left: 0;
    padding: calc(var(--topbar-height) + 26px) 18px 64px;
  }
}

@media (max-width: 620px) {
  .topbar { grid-template-columns: auto minmax(0, 1fr); }
  .brand { display: none; }
  .top-actions { display: none; }
  .search { grid-column: 2; }
  .sidebar { width: min(88vw, 320px); }
  .doc-section > h1:first-child { font-size: 28px; }
  h2 { font-size: 21px; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
  th, td { white-space: normal; min-width: 132px; }
  .doc-section .vg-callout,
  .doc-section .vg-card { padding: 12px 13px; }
}

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