/* ==========================================================================
   FoxRouter 文档站样式
   布局：顶栏 + 左侧导航 + 正文（含右侧目录）
   主题：浅色 / 深色，跟随系统并可手动切换
   ========================================================================== */

/* ---------------------------------------------------------------- Tokens */

:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --topbar-h: 3.5rem;
  --sidebar-w: 17rem;
  --toc-w: 15rem;
  --content-max: 46rem;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  /* 品牌色：狐狸橙，只用于强调，不铺满页面 */
  --brand: #d9541f;
  --brand-hover: #b8461a;
  --brand-soft: rgba(217, 84, 31, 0.1);
  --brand-ring: rgba(217, 84, 31, 0.35);
}

:root,
[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --bg-subtle: #fafaf9;
  --bg-elevated: #ffffff;
  --bg-sidebar: #fbfaf9;
  --bg-inset: #f4f4f2;
  --bg-code: #f7f7f5;
  --bg-hover: rgba(15, 15, 14, 0.045);
  --bg-active: rgba(217, 84, 31, 0.09);
  --fg: #16161a;
  --fg-muted: #5c5c66;
  --fg-subtle: #83838f;
  --border: #e6e5e2;
  --border-strong: #d6d5d0;
  --shadow-sm: 0 1px 2px rgba(15, 15, 14, 0.05);
  --shadow: 0 4px 16px -4px rgba(15, 15, 14, 0.1), 0 2px 6px -2px rgba(15, 15, 14, 0.06);
  --shadow-lg: 0 24px 48px -12px rgba(15, 15, 14, 0.22);
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;
  --info-fg: #1e40af;
  --info-icon: #2563eb;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --warn-fg: #92400e;
  --warn-icon: #d97706;
  --tip-bg: #f0fdf4;
  --tip-border: #bbf7d0;
  --tip-fg: #166534;
  --tip-icon: #16a34a;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111113;
  --bg-subtle: #17171a;
  --bg-elevated: #1a1a1e;
  --bg-sidebar: #141416;
  --bg-inset: #202024;
  --bg-code: #1a1a1e;
  --bg-hover: rgba(255, 255, 255, 0.055);
  --bg-active: rgba(240, 122, 62, 0.16);
  --fg: #f0efee;
  --fg-muted: #a3a3ad;
  --fg-subtle: #7c7c88;
  --border: #27272c;
  --border-strong: #35353c;
  --brand: #f07a3e;
  --brand-hover: #f79463;
  --brand-soft: rgba(240, 122, 62, 0.14);
  --brand-ring: rgba(240, 122, 62, 0.45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 6px 20px -6px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 28px 56px -16px rgba(0, 0, 0, 0.7);
  --info-bg: #14213b;
  --info-border: #1e3a68;
  --info-fg: #c7dcff;
  --info-icon: #6ba5f5;
  --warn-bg: #2a2011;
  --warn-border: #4d3a15;
  --warn-fg: #f5d9a8;
  --warn-icon: #e0a53c;
  --tip-bg: #10241a;
  --tip-border: #1c4430;
  --tip-fg: #b7ecc9;
  --tip-icon: #4ade80;
}

/* ---------------------------------------------------------------- Base */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 1.25rem);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  color: var(--brand);
}

img {
  max-width: 100%;
  height: auto;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.icon {
  width: 1.05em;
  height: 1.05em;
  flex: none;
  vertical-align: -0.16em;
}

.skip-link {
  position: absolute;
  left: 50%;
  top: 0.5rem;
  transform: translate(-50%, -200%);
  z-index: 100;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  background: var(--fg);
  color: var(--bg);
  font-size: 0.85rem;
  font-weight: 600;
}

.skip-link:focus {
  transform: translate(-50%, 0);
}

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0.1em 0.35em;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-inset);
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 0.72em;
  line-height: 1.4;
  text-align: center;
}

/* ---------------------------------------------------------------- Topbar */

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

.topbar-spacer {
  flex: 1;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand:hover {
  color: var(--fg);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--brand), #f0a05e);
  color: #fff;
  font-size: 1.05rem;
  box-shadow: var(--shadow-sm);
}

.brand-text {
  font-size: 0.98rem;
}

.brand-dot {
  margin: 0 0.15rem;
  color: var(--fg-subtle);
  font-weight: 400;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2.15rem;
  height: 2.15rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  transition: background-color 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

.topbar-menu {
  display: none;
}

.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.15rem;
  padding: 0 0.6rem 0 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--fg-subtle);
  font-size: 0.85rem;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}

.search-trigger:hover {
  border-color: var(--border-strong);
  background: var(--bg-inset);
  color: var(--fg-muted);
}

.search-trigger-text {
  min-width: 6.5rem;
  text-align: left;
}

.theme-icon {
  display: none;
}

[data-theme="light"] .theme-icon--light,
[data-theme="dark"] .theme-icon--dark {
  display: inline-flex;
}

.topbar-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 2.15rem;
  padding: 0 0.85rem;
  border-radius: var(--radius);
  background: var(--fg);
  color: var(--bg);
  font-size: 0.85rem;
  font-weight: 550;
  transition: opacity 0.15s;
}

.topbar-cta:hover {
  color: var(--bg);
  opacity: 0.85;
}

/* ---------------------------------------------------------------- Shell */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  max-width: 90rem;
  margin: 0 auto;
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 1.5rem 1rem 3rem;
  border-right: 1px solid var(--border);
  background: var(--bg-sidebar);
  scrollbar-width: thin;
}

.sidebar-head,
.sidebar-scrim {
  display: none;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.nav-group-title {
  margin: 0 0 0.5rem;
  padding-left: 0.6rem;
  color: var(--fg-subtle);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-link {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  transition: background-color 0.12s, color 0.12s;
}

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

.nav-link.is-active {
  background: var(--bg-active);
  color: var(--brand);
  font-weight: 550;
}

[data-theme="dark"] .nav-link.is-active {
  color: var(--brand);
}

.main {
  min-width: 0;
  padding: 2.5rem 2rem 4rem;
}

/* 正文 + 目录两列 */
.doc {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--toc-w);
  align-items: start;
  gap: 0 3rem;
  max-width: calc(var(--content-max) + var(--toc-w) + 3rem);
  margin: 0 auto;
}

.doc-head,
.doc-body {
  min-width: 0;
}

/* ---------------------------------------------------------------- Breadcrumb */

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
  color: var(--fg-subtle);
  font-size: 0.8rem;
}

.breadcrumb a:hover {
  color: var(--brand);
}

.breadcrumb-current {
  color: var(--fg-muted);
}

/* ---------------------------------------------------------------- 标题 */

.doc-title {
  margin: 0 0 0.5rem;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.022em;
  line-height: 1.25;
}

.doc-lede {
  margin: 0 0 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 1rem;
  line-height: 1.7;
}

/* ---------------------------------------------------------------- Prose */

.prose {
  color: var(--fg);
  font-size: 0.95rem;
  line-height: 1.8;
}

.prose > *:first-child {
  margin-top: 0;
}

.prose h2 {
  position: relative;
  margin: 2.75rem 0 0.85rem;
  padding-top: 0.25rem;
  font-size: 1.4rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.35;
}

.prose h3 {
  margin: 2rem 0 0.6rem;
  font-size: 1.1rem;
  font-weight: 620;
  letter-spacing: -0.008em;
  line-height: 1.4;
}

.prose h4 {
  margin: 1.6rem 0 0.5rem;
  font-size: 0.98rem;
  font-weight: 620;
}

.prose .anchor {
  position: absolute;
  left: -1.1em;
  padding-right: 0.2em;
  color: var(--fg-subtle);
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.prose h2:hover .anchor,
.prose h3:hover .anchor,
.prose .anchor:focus-visible {
  opacity: 1;
}

.prose .anchor:hover {
  color: var(--brand);
}

.prose p {
  margin: 0.85rem 0;
}

.prose a {
  color: var(--brand);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.prose a:hover {
  color: var(--brand-hover);
}

.prose strong {
  font-weight: 640;
  color: var(--fg);
}

.prose ul,
.prose ol {
  margin: 0.85rem 0;
  padding-left: 1.4rem;
}

.prose li {
  margin: 0.35rem 0;
}

.prose li::marker {
  color: var(--fg-subtle);
}

.prose li > ul,
.prose li > ol {
  margin: 0.35rem 0;
}

.prose hr {
  margin: 2.25rem 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.prose blockquote {
  margin: 1.25rem 0;
  padding: 0.15rem 0 0.15rem 1rem;
  border-left: 3px solid var(--border-strong);
  color: var(--fg-muted);
}

.prose blockquote p {
  margin: 0.4rem 0;
}

.prose :not(pre) > code {
  padding: 0.14em 0.4em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-inset);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 0.86em;
  word-break: break-word;
}

/* ---------------------------------------------------------------- 表格 */

.table-wrap {
  margin: 1.35rem 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
  line-height: 1.65;
}

.prose thead {
  background: var(--bg-subtle);
}

.prose th {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg-muted);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.prose td {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.prose tbody tr:last-child td {
  border-bottom: 0;
}

.prose tbody tr:hover {
  background: var(--bg-hover);
}

/* ---------------------------------------------------------------- 代码块 */

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

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.5rem 0.35rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
}

.code-lang {
  color: var(--fg-subtle);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.code-copy {
  padding: 0.2rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--fg-subtle);
  font-size: 0.75rem;
  transition: background-color 0.15s, color 0.15s;
}

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

.code-copy.is-done {
  color: var(--tip-icon);
}

.code-block pre {
  margin: 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
}

.code-block code {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.7;
  color: var(--fg);
  white-space: pre;
}

/* ---------------------------------------------------------------- Callout */

.callout {
  display: flex;
  gap: 0.7rem;
  margin: 1.35rem 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.72;
}

.callout-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.35rem;
  height: 1.35rem;
  margin-top: 0.18rem;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  font-style: normal;
}

.callout-body {
  min-width: 0;
}

.callout-body > *:first-child {
  margin-top: 0;
}

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

.callout-body ul,
.callout-body ol {
  padding-left: 1.15rem;
}

.callout--info {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info-fg);
}

.callout--info .callout-icon {
  background: var(--info-icon);
  color: #fff;
}

.callout--warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-fg);
}

.callout--warn .callout-icon {
  background: var(--warn-icon);
  color: #fff;
}

.callout--tip {
  background: var(--tip-bg);
  border-color: var(--tip-border);
  color: var(--tip-fg);
}

.callout--tip .callout-icon {
  background: var(--tip-icon);
  color: #fff;
}

.callout a {
  color: inherit;
  text-decoration: underline;
}

/* ---------------------------------------------------------------- 截图占位 */

.shot {
  margin: 1.5rem 0;
  text-align: center;
}

.shot img {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
}

.shot-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 9rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(45deg, transparent 0 8px, var(--bg-hover) 8px 16px),
    var(--bg-subtle);
}

.shot-badge {
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg-subtle);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}

.shot-title {
  color: var(--fg-muted);
  font-size: 0.9rem;
}

.shot figcaption {
  margin-top: 0.5rem;
  color: var(--fg-subtle);
  font-size: 0.8rem;
}

/* ---------------------------------------------------------------- TOC */

.toc {
  position: sticky;
  top: calc(var(--topbar-h) + 2.5rem);
  align-self: start;
  max-height: calc(100vh - var(--topbar-h) - 5rem);
  overflow-y: auto;
  padding-bottom: 2rem;
  font-size: 0.83rem;
  scrollbar-width: thin;
}

.toc-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.6rem;
  color: var(--fg);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.toc-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-left: 1px solid var(--border);
}

.toc-item a {
  display: block;
  padding: 0.28rem 0 0.28rem 0.75rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--fg-muted);
  line-height: 1.5;
  transition: color 0.12s, border-color 0.12s;
}

.toc-item--h3 a {
  padding-left: 1.5rem;
  font-size: 0.8rem;
}

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

.toc-item a.is-active {
  border-left-color: var(--brand);
  color: var(--brand);
  font-weight: 550;
}

/* ---------------------------------------------------------------- Pager */

.pager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
  margin-top: 3rem;
}

.pager-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.pager-card:hover {
  border-color: var(--brand-ring);
  box-shadow: var(--shadow);
  color: inherit;
}

.pager-card--next {
  text-align: right;
}

.pager-label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--fg-subtle);
  font-size: 0.76rem;
}

.pager-card--next .pager-label {
  justify-content: flex-end;
}

.pager-title {
  color: var(--fg);
  font-size: 0.92rem;
  font-weight: 550;
}

/* ---------------------------------------------------------------- Footer */

.doc-footer {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--fg-subtle);
  font-size: 0.78rem;
}

.doc-footer-brand {
  margin: 0 0 0.35rem;
  color: var(--fg-muted);
  font-weight: 550;
}

.doc-footer-note {
  margin: 0;
  line-height: 1.7;
}

/* ---------------------------------------------------------------- 首页 */

.shell--home {
  display: block;
  max-width: none;
}

.main--home {
  max-width: 68rem;
  margin: 0 auto;
  padding: 3.5rem 2rem 4rem;
}

.hero {
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--border);
}

.hero-eyebrow {
  margin: 0 0 0.75rem;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-title {
  margin: 0 0 0.85rem;
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  font-weight: 720;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.hero-text {
  max-width: 40rem;
  margin: 0 0 1.75rem;
  color: var(--fg-muted);
  font-size: 1rem;
  line-height: 1.75;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 550;
  transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn--primary {
  background: var(--brand);
  color: #fff;
}

.btn--primary:hover {
  background: var(--brand-hover);
  color: #fff;
}

.btn--ghost {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
  color: var(--fg);
}

.btn--ghost:hover {
  border-color: var(--fg-subtle);
  color: var(--fg);
}

.home-section {
  margin-top: 3rem;
}

.home-section-title {
  margin: 0 0 1.15rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--fg-subtle);
  text-transform: uppercase;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17.5rem, 1fr));
  gap: 0.85rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card-link {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  height: 100%;
  padding: 1.1rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.card-link:hover {
  border-color: var(--brand-ring);
  box-shadow: var(--shadow);
  color: inherit;
  transform: translateY(-1px);
}

.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.card-desc {
  flex: 1;
  margin: 0;
  color: var(--fg-muted);
  font-size: 0.85rem;
  line-height: 1.65;
}

.card-more {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  color: var(--brand);
  font-size: 0.8rem;
  font-weight: 550;
}

/* ---------------------------------------------------------------- 搜索 */

.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12vh 1rem 2rem;
  background: rgba(15, 15, 14, 0.42);
  backdrop-filter: blur(3px);
}

.search-overlay[hidden] {
  display: none;
}

.search-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 40rem;
  max-height: 70vh;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
}

.search-field {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg-subtle);
}

.search-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 0.95rem;
  outline: none;
}

.search-field input::placeholder {
  color: var(--fg-subtle);
}

.search-close {
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-subtle);
}

.search-close:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.search-empty {
  margin: 0;
  padding: 1.5rem 0.85rem;
  color: var(--fg-subtle);
  font-size: 0.86rem;
  text-align: center;
}

.search-hit {
  display: block;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.search-hit:hover,
.search-hit.is-selected {
  background: var(--bg-hover);
}

.search-hit-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--fg);
  font-size: 0.9rem;
  font-weight: 550;
}

.search-hit-group {
  color: var(--fg-subtle);
  font-size: 0.72rem;
  font-weight: 400;
}

.search-hit-snippet {
  margin: 0.15rem 0 0;
  color: var(--fg-muted);
  font-size: 0.8rem;
  line-height: 1.6;
}

.search-hit-snippet mark {
  padding: 0 0.1em;
  border-radius: 3px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}

.search-foot {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0.85rem;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--fg-subtle);
  font-size: 0.72rem;
}

/* ---------------------------------------------------------------- 回到顶部 */

.to-top {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 30;
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--fg-muted);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, color 0.15s;
}

.to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
}

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

/* ---------------------------------------------------------------- 响应式 */

@media (max-width: 1180px) {
  .doc {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "head"
      "body"
      "foot";
    max-width: var(--content-max);
  }

  .doc > .toc {
    display: none;
  }
}

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

  .topbar-menu {
    display: inline-grid;
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    z-index: 60;
    width: min(19rem, 84vw);
    height: calc(100vh - var(--topbar-h));
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
  }

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

  .sidebar-head {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.75rem;
  }

  .sidebar-scrim {
    position: fixed;
    inset: var(--topbar-h) 0 0;
    z-index: 55;
    display: block;
    background: rgba(15, 15, 14, 0.4);
  }

  .sidebar-scrim[hidden] {
    display: none;
  }

  .main {
    padding: 2rem 1.25rem 3.5rem;
  }

  .main--home {
    padding: 2.5rem 1.25rem 3rem;
  }

  .doc-title {
    font-size: 1.65rem;
  }

  .search-trigger-text {
    display: none;
  }

  .search-trigger kbd {
    display: none;
  }
}

@media (max-width: 560px) {
  .brand-text {
    font-size: 0.92rem;
  }

  .topbar-cta {
    display: none;
  }

  .prose h2 {
    font-size: 1.22rem;
  }

  .prose h3 {
    font-size: 1.02rem;
  }

  .pager {
    grid-template-columns: minmax(0, 1fr);
  }

  .pager-card--next {
    text-align: left;
  }

  .pager-card--next .pager-label {
    justify-content: flex-start;
  }

  .card-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

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

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------------------------------------------------------------- 打印 */

@media print {
  .topbar,
  .sidebar,
  .toc,
  .pager,
  .to-top,
  .search-overlay,
  .code-copy {
    display: none !important;
  }

  .doc {
    display: block;
  }

  body {
    font-size: 11pt;
  }
}