/*
 * Quick Gui 用户指南 — 站点主题
 * 视觉与主页（site-vitepress/docs/.vitepress/theme/custom.css）保持一致。
 *
 * 修改本文件即可调整文档站主题：
 *   - 下方 --qg-* 设计 token 应与主页 custom.css 中的定义保持一致（改一处需同步两处）。
 *   - 布局/组件样式（侧栏、顶栏、正文、代码、表格、分页等）集中在本文件，便于统一维护。
 * build.py 会原样把本文件写入 assets/css/site.css，因此本文件即主题唯一来源。
 */

:root {
  /* ── 设计 token（与主页 custom.css 保持一致） ── */
  --qg-font-display: "IBM Plex Sans", "Noto Sans SC", sans-serif;
  --qg-font-body: "Noto Sans SC", "IBM Plex Sans", sans-serif;
  --qg-font-mono: "JetBrains Mono", "Fira Code", "Sarasa Mono SC", "Noto Sans Mono CJK SC", monospace;

  --qg-canvas: #fafafa;
  --qg-surface: #ffffff;
  --qg-surface-soft: #f4f4f4;
  --qg-hairline: #e0e0e0;
  --qg-hairline-strong: #161616;

  --qg-ink: #161616;
  --qg-ink-title: #161616;
  --qg-ink-heading: #262626;
  --qg-ink-body: #525252;
  --qg-ink-muted: #6f6f6f;
  --qg-ink-soft: #8c8c8c;
  --qg-ink-faint: #a8a8a8;

  --qg-accent: #0f62fe;
  --qg-accent-deep: #0043ce;
  --qg-accent-soft: #4589ff;
  --qg-accent-mist: #e8f0fe;

  --qg-hero-bg: #161616;
  --qg-hero-surface: #262626;
  --qg-on-dark: #ffffff;
  --qg-on-dark-muted: #c6c6c6;
  --qg-on-primary: #ffffff;

  --qg-radius-sm: 2px;
  --qg-radius-md: 4px;
  --qg-radius-lg: 8px;

  --qg-code-bg: #1c1c1e;

  --qg-header-bg: rgb(255 255 255 / 92%);
  --qg-hero-border: #393939;

  /* 滚动条：原生白底就是因为没给颜色，交给浏览器默认绘制 */
  --qg-scroll-track: var(--qg-surface);
  --qg-scroll-thumb: #c6c6c6;
  --qg-scroll-thumb-hover: #a8a8a8;
  color-scheme: light;

  /* ── guides 布局量 ── */
  --sidebar-w: 320px;
  --header-h: 56px;
}

/* 主题色（accent）：页面上「主题设置」面板可切换，改这里的色值即可自定义色板。
   blue 为默认，保持与主页 custom.css 的 #0f62fe 一致。 */
:root[data-accent="cyan"]   { --qg-accent-user: #00838f; }
:root[data-accent="green"]  { --qg-accent-user: #2e7d32; }
:root[data-accent="violet"] { --qg-accent-user: #6a1b9a; }
:root[data-accent="orange"] { --qg-accent-user: #d84315; }
:root[data-accent="rose"]   { --qg-accent-user: #c2185b; }

:root[data-accent]:not([data-accent="blue"]) {
  --qg-accent: var(--qg-accent-user);
  /* 回退值：不支持 color-mix 的浏览器仍能得到可用的主题色 */
  --qg-accent-deep: var(--qg-accent-user);
  --qg-accent-soft: var(--qg-accent-user);
  --qg-accent-mist: var(--qg-surface-soft);
  --qg-accent-deep: color-mix(in srgb, var(--qg-accent-user) 80%, #000);
  --qg-accent-soft: color-mix(in srgb, var(--qg-accent-user) 60%, #fff);
  --qg-accent-mist: color-mix(in srgb, var(--qg-accent-user) 12%, var(--qg-surface));
}

/* 暗色 token：<html data-theme="dark"> 时生效。
   head 里的初始化脚本会把「跟随系统 / 亮色 / 暗色」解析成具体的 light|dark，
   因此这套 token 只需维护一份，且首屏不会闪白。 */
:root[data-theme="dark"] {
  --qg-canvas: #161616;
  --qg-surface: #262626;
  --qg-surface-soft: #393939;
  --qg-hairline: #525252;
  --qg-hairline-strong: #f4f4f4;

  --qg-ink: #f4f4f4;
  --qg-ink-title: #f4f4f4;
  --qg-ink-heading: #e0e0e0;
  --qg-ink-body: #c6c6c6;
  --qg-ink-muted: #a8a8a8;
  --qg-ink-soft: #8c8c8c;
  --qg-ink-faint: #6f6f6f;

  --qg-accent: #4589ff;
  --qg-accent-deep: #0f62fe;
  --qg-accent-soft: #78a9ff;
  --qg-accent-mist: rgb(15 98 254 / 22%);

  --qg-hero-bg: #0a0a0a;
  --qg-hero-surface: #1f1f1f;
  --qg-on-dark: #f4f4f4;
  --qg-on-dark-muted: #c6c6c6;
  --qg-on-primary: #ffffff;

  --qg-code-bg: #141414;
  --qg-header-bg: rgb(22 22 22 / 94%);
  --qg-hero-border: #393939;

  --qg-scroll-thumb: #525252;
  --qg-scroll-thumb-hover: #6f6f6f;
  color-scheme: dark;
}

/* 自定义主题色在暗色下提亮，保证对比度 */
:root[data-theme="dark"][data-accent]:not([data-accent="blue"]) {
  --qg-accent: color-mix(in srgb, var(--qg-accent-user) 62%, #fff);
  --qg-accent-deep: color-mix(in srgb, var(--qg-accent-user) 42%, #fff);
  --qg-accent-soft: color-mix(in srgb, var(--qg-accent-user) 80%, #fff);
  --qg-accent-mist: color-mix(in srgb, var(--qg-accent-user) 22%, transparent);
}

*, *::before, *::after { box-sizing: border-box; }

/* ── 滚动条：跟随主题（浏览器原生绘制白底就是漏了这段） ── */
* { scrollbar-color: var(--qg-scroll-thumb) var(--qg-scroll-track); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--qg-scroll-track); }
::-webkit-scrollbar-thumb {
  background: var(--qg-scroll-thumb);
  border: 2px solid var(--qg-scroll-track);
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover { background: var(--qg-scroll-thumb-hover); }

html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--qg-font-body);
  font-size: 15.5px;
  line-height: 1.7;
  color: var(--qg-ink-body);
  background: var(--qg-canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--qg-accent); text-decoration: none; font-weight: 500; }
a:hover { color: var(--qg-accent-deep); text-decoration: underline; }

/* ── 侧栏 ── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--qg-surface);
  border-right: 1px solid var(--qg-hairline);
  overflow-y: auto;
  z-index: 20;
  padding: 0 0 2rem;
}
.sidebar-brand {
  position: sticky; top: 0;
  background: var(--qg-surface);
  border-bottom: 1px solid var(--qg-hairline);
  font-family: var(--qg-font-display);
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.02em;
  line-height: 1.3;
}
/* 整行（含内边距）都是返回主页的点击区域；spacing 与主页导航栏一致 */
.sidebar-brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.7rem 1.1rem;
  color: var(--qg-ink);
  text-decoration: none;
  transition: background-color 0.15s ease;
}
.sidebar-brand-link:hover { background: var(--qg-surface-soft); }
.sidebar-brand-link:hover span { color: var(--qg-accent); }
.sidebar-logo {
  width: 28px; height: 28px;
  flex: 0 0 auto;
  object-fit: contain;
  border-radius: 6px;
}
.sidebar nav { padding: 0.5rem 0.4rem 1.5rem; }
.sidebar nav a {
  display: block;
  padding: 0.35rem 0.65rem;
  border-radius: var(--qg-radius-md);
  color: var(--qg-ink-muted);
  font-size: 0.88rem;
  text-decoration: none;
  margin: 1px 0;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.sidebar nav a:hover { background: var(--qg-surface-soft); color: var(--qg-ink); }
.sidebar nav a.active {
  background: var(--qg-accent-mist);
  color: var(--qg-accent);
  font-weight: 600;
}
.sidebar .nav-sec {
  margin: 0.85rem 0.65rem 0.25rem;
  font-family: var(--qg-font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--qg-ink-soft);
  font-weight: 500;
}

/* ── 顶部条 ── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  width: calc(100% - var(--sidebar-w));
}
.topbar {
  position: sticky; top: 0; z-index: 10;
  height: var(--header-h);
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0 1.5rem;
  background: var(--qg-header-bg);
  backdrop-filter: blur(14px) saturate(1.15);
  border-bottom: 1px solid var(--qg-hairline);
}
.menu-btn {
  display: none;
  border: 1px solid var(--qg-hairline);
  background: var(--qg-surface);
  border-radius: var(--qg-radius-md);
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.crumb { color: var(--qg-ink-muted); font-size: 0.88rem; }
.content-wrap {
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 1.75rem 2.5rem 3.5rem;
  box-sizing: border-box;
}

/* ── 正文（对齐主页 .vp-doc 风格） ── */
article h1 {
  font-family: var(--qg-font-display);
  font-size: clamp(28px, 3.2vw, 36px);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin: 0.2rem 0 1rem;
  color: var(--qg-ink-title);
  text-wrap: balance;
}
article h2 {
  font-family: var(--qg-font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin: 2.2rem 0 0.75rem;
  padding-top: 0.4rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--qg-hairline);
  color: var(--qg-ink-title);
}
article h3 {
  font-family: var(--qg-font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 1.6rem 0 0.5rem;
  color: var(--qg-ink-heading);
}
article h4 { font-size: 1rem; margin: 1.2rem 0 0.4rem; color: var(--qg-ink-heading); }
article p, article ul, article ol, article table { margin: 0.8rem 0; }
article li { margin: 0.3rem 0; line-height: 1.7; }
article blockquote {
  margin: 1.2rem 0;
  padding: 0.8rem 1rem;
  border-left: 3px solid var(--qg-accent);
  background: var(--qg-accent-mist);
  color: var(--qg-ink-body);
  border-radius: 0 var(--qg-radius-md) var(--qg-radius-md) 0;
}
article blockquote p { margin: 0.35rem 0; }
article hr { border: none; border-top: 1px solid var(--qg-hairline); margin: 2rem 0; }

/* 图片 / 示意图 */
article img, article svg.diagram {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.2rem auto;
}
.diagram-wrap {
  background: var(--qg-surface);
  border: 1px solid var(--qg-hairline);
  border-radius: var(--qg-radius-md);
  padding: 1rem;
  margin: 1.25rem 0;
  overflow-x: auto;
}
.diagram-caption {
  text-align: center;
  color: var(--qg-ink-muted);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

/* ── 代码 ── */
code {
  font-family: var(--qg-font-mono);
  font-size: 0.88em;
  background: var(--qg-surface-soft);
  padding: 0.1em 0.35em;
  border-radius: var(--qg-radius-sm);
  color: var(--qg-ink-heading);
}
pre {
  background: var(--qg-code-bg);
  color: #e6ebf2;
  padding: 1rem 1.15rem;
  border: 1px solid var(--qg-hairline);
  border-radius: var(--qg-radius-md);
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.6;
  margin: 1.1rem 0;
}
pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* pygments / codehilite — 暗色（与主页代码块协调） */
.codehilite { background: var(--qg-code-bg); border: 1px solid var(--qg-hairline); border-radius: var(--qg-radius-md); margin: 1.1rem 0; }
.codehilite pre { margin: 0; background: transparent; border: none; }
.codehilite .hll { background-color: rgba(255,255,255,0.08); }
.codehilite .c, .codehilite .ch, .codehilite .cm, .codehilite .c1, .codehilite .cs { color: #8b949e; }
.codehilite .k, .codehilite .kc, .codehilite .kd, .codehilite .kn, .codehilite .kp, .codehilite .kr, .codehilite .kt { color: #ff7b72; }
.codehilite .s, .codehilite .sa, .codehilite .sb, .codehilite .sc, .codehilite .dl, .codehilite .sd, .codehilite .s2, .codehilite .se, .codehilite .sh, .codehilite .si, .codehilite .sx, .codehilite .sr, .codehilite .s1, .codehilite .ss { color: #a5d6ff; }
.codehilite .m, .codehilite .mb, .codehilite .mf, .codehilite .mh, .codehilite .mi, .codehilite .il, .codehilite .mo { color: #79c0ff; }
.codehilite .n, .codehilite .na, .codehilite .nb, .codehilite .bp, .codehilite .nc, .codehilite .no, .codehilite .nd, .codehilite .ni, .codehilite .ne, .codehilite .nf, .codehilite .nl, .codehilite .nn, .codehilite .nx, .codehilite .py, .codehilite .nt, .codehilite .nv, .codehilite .vc, .codehilite .vg, .codehilite .vi, .codehilite .vm { color: #e6ebf2; }
.codehilite .o, .codehilite .ow { color: #ff7b72; }
.codehilite .p { color: #c9d1d9; }
.codehilite .gd { color: #ffa198; }
.codehilite .gi { color: #7ee787; }
.codehilite .gu { color: #d2a8ff; }
.codehilite .err { color: #ffa198; }

/* ── 表格（对齐主页 .vp-doc table） ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  background: var(--qg-surface);
  border: 1px solid var(--qg-hairline);
  border-radius: var(--qg-radius-md);
  overflow: hidden;
  margin: 1.2rem 0;
}
th, td {
  border-bottom: 1px solid var(--qg-hairline);
  padding: 0.6rem 0.85rem;
  text-align: left;
  vertical-align: top;
}
th { background: var(--qg-surface-soft); font-family: var(--qg-font-display); font-weight: 600; color: var(--qg-ink-heading); }
tr:last-child td { border-bottom: none; }

/* ── 上一页 / 下一页 ── */
.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--qg-hairline);
}
.pager a {
  flex: 1;
  display: block;
  padding: 0.85rem 1rem;
  background: var(--qg-surface);
  border: 1px solid var(--qg-hairline);
  border-radius: var(--qg-radius-md);
  color: var(--qg-ink);
  text-decoration: none;
}
.pager a:hover { border-color: var(--qg-accent); background: var(--qg-accent-mist); text-decoration: none; }
.pager .next { text-align: right; }
.pager .label { display: block; color: var(--qg-ink-muted); font-size: 0.78rem; margin-bottom: 0.2rem; }
.pager .title { font-weight: 600; }

.footer-note {
  margin-top: 2rem;
  color: var(--qg-ink-muted);
  font-size: 0.82rem;
}

/* ── 左侧章节树 ── */
.sidebar .tree-guide {
  margin: 0.15rem 0;
  border: none;
}
.sidebar .tree-guide > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.4rem 0.55rem;
  border-radius: var(--qg-radius-md);
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--qg-ink);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.sidebar .tree-guide > summary::-webkit-details-marker { display: none; }
.sidebar .tree-guide > summary::before {
  content: "▸";
  color: var(--qg-ink-soft);
  font-size: 0.75rem;
  width: 0.9rem;
  flex: 0 0 auto;
}
.sidebar .tree-guide[open] > summary::before { content: "▾"; }
.sidebar .tree-guide > summary:hover { background: var(--qg-surface-soft); color: var(--qg-ink); }
.sidebar .tree-guide.current > summary { background: var(--qg-accent-mist); color: var(--qg-accent); }
.sidebar .tree-chapters { padding: 0.1rem 0 0.35rem 0.55rem; }
.sidebar .tree-chapters a {
  display: block;
  padding: 0.28rem 0.55rem 0.28rem 0.85rem;
  border-radius: var(--qg-radius-md);
  color: var(--qg-ink-muted);
  font-size: 0.82rem;
  text-decoration: none;
  margin: 1px 0;
  border-left: 2px solid transparent;
}
.sidebar .tree-chapters a:hover { background: var(--qg-surface-soft); color: var(--qg-ink); }
.sidebar .tree-chapters a.active {
  background: var(--qg-accent-mist);
  color: var(--qg-accent);
  font-weight: 600;
  border-left-color: var(--qg-accent);
}
.sidebar .nav-home {
  display: block;
  padding: 0.4rem 0.65rem;
  margin: 0 0 0.35rem;
  border-radius: var(--qg-radius-md);
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--qg-ink);
  text-decoration: none;
}
.sidebar .nav-home:hover, .sidebar .nav-home.active {
  background: var(--qg-accent-mist); color: var(--qg-accent);
}

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 15;
}

/* ── 主题设置面板（由 site.js 注入到顶栏，设置保存在本机并对整站生效） ── */
.qg-theme { position: relative; margin-left: auto; flex: 0 0 auto; }
.qg-theme-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  border: 1px solid var(--qg-hairline);
  background: var(--qg-surface);
  color: var(--qg-ink-body);
  border-radius: var(--qg-radius-md);
  padding: 0.35rem 0.7rem;
  font: 500 0.84rem var(--qg-font-body);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}
.qg-theme-btn:hover, .qg-theme-btn[aria-expanded="true"] {
  border-color: var(--qg-accent);
  color: var(--qg-accent);
  background: var(--qg-accent-mist);
}
.qg-theme-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; }

.qg-theme-panel {
  position: absolute; right: 0; top: calc(100% + 10px);
  z-index: 40;
  width: 268px;
  padding: 1rem;
  background: var(--qg-surface);
  border: 1px solid var(--qg-hairline);
  border-radius: var(--qg-radius-lg);
  box-shadow: 0 12px 32px rgb(0 0 0 / 14%), 0 2px 8px rgb(0 0 0 / 8%);
}
.qg-theme-panel[hidden] { display: none; }
.qg-theme-label {
  font: 600 0.76rem var(--qg-font-body);
  letter-spacing: 0.04em;
  color: var(--qg-ink-muted);
  margin: 0 0 0.5rem;
}
.qg-theme-group + .qg-theme-group { margin-top: 1.1rem; }

.qg-theme-modes { display: flex; gap: 0.35rem; }
.qg-theme-mode {
  flex: 1;
  padding: 0.42rem 0.2rem;
  border: 1px solid var(--qg-hairline);
  background: var(--qg-surface);
  color: var(--qg-ink-muted);
  border-radius: var(--qg-radius-md);
  font: 500 0.8rem var(--qg-font-body);
  cursor: pointer;
  white-space: nowrap;
}
.qg-theme-mode:hover { border-color: var(--qg-accent); color: var(--qg-accent); }
.qg-theme-mode[aria-pressed="true"] {
  border-color: var(--qg-accent);
  background: var(--qg-accent-mist);
  color: var(--qg-accent);
  font-weight: 600;
}

.qg-theme-swatches { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.qg-theme-swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--swatch);
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 8%);
  transition: transform 0.12s ease;
}
.qg-theme-swatch:hover { transform: scale(1.12); }
.qg-theme-swatch[aria-pressed="true"] {
  border-color: var(--qg-ink);
  box-shadow: 0 0 0 2px var(--qg-surface), 0 0 0 3px var(--swatch);
}
.qg-theme-hint {
  margin: 0.9rem 0 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--qg-ink-faint);
}

/* ── 窄屏：侧栏抽屉 ── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-block; }
  .content-wrap { padding: 1.1rem 1rem 3rem; }
  .qg-theme-panel { right: 0; width: min(268px, calc(100vw - 2rem)); }
}
