/* ============================================
   Git Knowledge Base - Global Styles
   ============================================ */

/* --- CSS Variables --- */
:root {
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-rgb: 37, 99, 235;
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --surface: #f1f5f9;
  --ink: #0f172a;
  --ink-secondary: #334155;
  --muted: #64748b;
  --rule: #e2e8f0;
  --rule-strong: #cbd5e1;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --code-bg: #1e293b;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -2px rgba(15, 23, 42, 0.04);
  --radius: 8px;
  --radius-sm: 4px;
  --max-width: 1200px;
  --nav-height: 60px;
  --toc-width: 240px;
  /* 移动端悬浮目录：面板底色通透度(0~1，◐ 按钮调节；文本不透明保证可读) */
  --toc-float-bg: 0.82;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', 'HarmonyOS Sans', 'HarmonyOS Sans SC', 'Noto Sans CJK SC', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-rgb: 59, 130, 246;
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --surface: #1e293b;
  --ink: #f8fafc;
  --ink-secondary: #cbd5e1;
  --muted: #94a3b8;
  --rule: #334155;
  --rule-strong: #475569;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  /* 不再设 scroll-padding-top：会与 .section 的 scroll-margin-top 叠加（双倍偏移），
     导致锚点落点过低、目标节上方露出上一块约 96px 空白。导航偏移统一由 .section 的
     scroll-margin-top: calc(var(--nav-height) + 20px) 负责（navigateToSection 亦读该值）。 */
}

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition), color var(--transition);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

/* --- Typography --- */
h1, h2, h3, h4 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.4rem, 3vw, 1.8rem); margin-top: 2.5rem; margin-bottom: 1rem; }
h3 { font-size: clamp(1.1rem, 2vw, 1.3rem); margin-top: 1.8rem; margin-bottom: 0.75rem; }
h4 { font-size: 1rem; margin-top: 1.4rem; margin-bottom: 0.6rem; }

p {
  margin-bottom: 0.75rem;
  color: var(--ink-secondary);
}

ul, ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.4rem;
  color: var(--ink-secondary);
}

strong {
  color: var(--ink);
  font-weight: 600;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--surface);
  color: var(--accent);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
}

pre {
  background: var(--code-bg);
  color: #ccc;
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  position: relative;
}

pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* --- Layout --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1rem;
}

/* --- Navbar --- */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--rule);
  z-index: 1000;
  transition: background-color var(--transition), border-color var(--transition);
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.logo {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
  text-decoration: none;
  flex-shrink: 0;
}

.logo svg {
  width: 28px;
  height: 28px;
  fill: var(--accent);
}

.logo:hover {
  text-decoration: none;
}

.logo-sub {
  flex-basis: 100%;
  font-weight: 400;
  font-size: 0.72rem;
  line-height: 1.25;
  color: var(--muted, #64748b);
  margin-top: 0.1rem;
}

.nav-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 600px;
  margin: 0 1rem;
  min-width: 0;
}

.search-box {
  position: relative;
  width: 100%;
  min-width: 0;
}

.search-box input {
  width: 100%;
  height: 38px;
  padding: 0 2.5rem 0 2.5rem;
  border: 1px solid var(--rule);
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px; /* ≥16px：防止 iOS Safari 聚焦输入框时自动放大页面 */
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

.search-box .search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}

.search-box .search-shortcut {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--rule);
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-sm);
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--muted);
  color: var(--bg-elevated);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.search-clear.visible {
  display: flex;
}

.search-clear:hover {
  background: var(--ink-secondary);
}

.search-clear svg {
  width: 12px;
  height: 12px;
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
  display: none;
  z-index: 1001;
}

.search-dropdown.active {
  display: block;
}

.search-dropdown .search-item {
  display: block;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  transition: background-color var(--transition);
}

.search-dropdown .search-item:hover,
.search-dropdown .search-item.active {
  background: var(--surface);
}

.search-dropdown .search-item:last-child {
  border-bottom: none;
}

.search-item-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
  margin-bottom: 0.2rem;
}

.search-item-desc {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-no-results {
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.search-highlight {
  background: rgba(var(--accent-rgb), 0.12);
  color: inherit;
  border-radius: 2px;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

/* --- Buttons & Icons --- */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: var(--surface);
  color: var(--ink);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.theme-icon-dark {
  display: none;
}

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

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

/* --- Dropdown --- */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: -30px;
  min-width: 90px;
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  overflow: hidden;
  z-index: 1002;
}

.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 0.9rem;
  border: none;
  background: none;
  color: var(--ink-secondary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition);
}

.dropdown-item:hover {
  background: var(--surface);
  color: var(--ink);
}

.dropdown-item.active {
  color: var(--accent);
  font-weight: 500;
}

.dropdown-label {
  padding: 0.4rem 0.9rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --- Mobile Menu Toggle --- */
.menu-toggle {
  display: none;
}

/* --- Hero --- */
.hero {
  padding: calc(var(--nav-height) + 3rem) 1rem 3rem;
  text-align: center;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--rule);
}

.hero-title {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 800;
  margin-bottom: 0.75rem;
  color: var(--ink);
}

.hero-subtitle {
  font-size: clamp(1rem, 2.5vw, 1.3rem);
  color: var(--muted);
  margin-bottom: 1.25rem;
  font-weight: 400;
}

.hero-desc {
  max-width: 640px;
  margin: 0 auto;
  color: var(--ink-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  text-decoration: none;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  text-decoration: none;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--ink);
  border-color: var(--rule);
}

.btn-secondary:hover {
  background: var(--surface);
  border-color: var(--rule-strong);
  text-decoration: none;
}

/* --- Main Layout with TOC --- */
.main-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1rem;
}

.main-layout > main {
  max-width: 100%;
  min-width: 0;
}

.toc-sidebar {
  display: none;
}

.toc-sidebar h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.75rem;
  margin-top: 0;
}

.toc-list {
  list-style: none;
  padding: 0;
  position: sticky;
  top: calc(var(--nav-height) + 2rem);
}

.toc-list li {
  margin: 0;
}

.toc-list a {
  display: block;
  padding: 0.35rem 0 0.35rem 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  border-left: 2px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
}

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

.toc-list a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* --- Sections --- */
.section {
  margin-bottom: 3rem;
  scroll-margin-top: calc(var(--nav-height) + 20px); /* 固定导航栏高度 + 留白，避免锚点跳转后标题被遮挡 */
}

.section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--rule);
}

.section-header h2 {
  margin: 0;
}

.section-icon {
  width: 32px;
  height: 32px;
  color: var(--accent);
  flex-shrink: 0;
}

.section-content {
  color: var(--ink-secondary);
  overflow-wrap: break-word;
  word-break: break-word;
}

.section-content h4 {
  color: var(--ink);
  font-weight: 600;
  margin-top: 1.5rem;
}

.section-content p {
  line-height: 1.7;
}

/* --- Cards / Grids --- */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin: 1.5rem 0;
  max-width: 100%;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: box-shadow var(--transition), border-color var(--transition);
  max-width: 100%;
  overflow: hidden;
}

.card:hover {
  box-shadow: var(--shadow);
  border-color: var(--rule-strong);
}

.card h4 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  color: var(--ink);
}

/* --- Tables --- */
.table-wrap {
  overflow-x: auto;
  margin: 1.5rem 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.65rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--rule);
}

th {
  background: var(--surface);
  font-weight: 600;
  color: var(--ink);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:last-child td {
  border-bottom: none;
}

/* --- Code Block with Syntax Highlighting --- */
.code-block {
  position: relative;
  max-width: 100%;
  overflow: hidden;
}

.code-block pre[class*="language-"] {
  padding: 1rem 3rem 1rem 1rem;
  margin: 0;
  border-radius: var(--radius);
  tab-size: 2;
  max-width: 100%;
  overflow-x: auto;
}

.code-block code {
  max-width: 100%;
  word-break: break-all;
  white-space: pre-wrap;
}

/* Prism Tomorrow Night token overrides */
.code-block .token.comment,
.code-block .token.prolog,
.code-block .token.doctype,
.code-block .token.cdata { color: #7a7a7a; }
.code-block .token.punctuation { color: #ccc; }
.code-block .token.property,
.code-block .token.tag,
.code-block .token.boolean,
.code-block .token.number,
.code-block .token.constant,
.code-block .token.symbol { color: #f08d49; }
.code-block .token.selector,
.code-block .token.attr-name,
.code-block .token.string,
.code-block .token.char,
.code-block .token.builtin,
.code-block .token.inserted { color: #7ec699; }
.code-block .token.operator,
.code-block .token.entity,
.code-block .token.url { color: #67cdcc; }
.code-block .token.atrule,
.code-block .token.attr-value,
.code-block .token.keyword { color: #cc99cd; }
.code-block .token.function,
.code-block .token.class-name { color: #6196cc; }
.code-block .token.regex,
.code-block .token.important,
.code-block .token.variable { color: #e2777a; }

/* Copy button - always visible in top-right corner */
.code-block .copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.3rem 0.5rem;
  font-size: 0.72rem;
  background: rgba(255,255,255,0.08);
  color: #999;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0.7;
  transition: all var(--transition);
  font-family: var(--font-body);
  z-index: 2;
}

.code-block .copy-btn:hover {
  background: rgba(255,255,255,0.16);
  color: #ccc;
  opacity: 1;
}

.code-block .copy-btn:active {
  transform: scale(0.95);
}

.code-block .copy-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Toast notification for copy success */
.copy-toast {
  position: fixed;
  top: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #fdecbe;
  color: #000;
  padding: 0.6rem 1.2rem;
  border: 1px solid #fbc16b;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-family: var(--font-body);
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  pointer-events: none;
}

.copy-toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* --- Footer --- */
.footer {
  background: var(--surface);
  border-top: 1px solid var(--rule);
  padding: 1.25rem 1rem;
  margin-top: 2rem;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.footer-links {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.footer-links a {
  color: var(--muted);
  font-size: 0.85rem;
}

.footer-links a:hover {
  color: var(--ink);
}

.footer-copy {
  font-size: 0.8rem;
  color: var(--muted);
}

.footer-trademark {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--muted);  max-width: 60ch;
}

/* ICP 备案号（中国大陆托管合规展示，链接至工信部备案系统） */
.footer-icp {
  flex-basis: 100%;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}
.footer-icp a { color: var(--muted); text-decoration: none; }
.footer-icp a:hover { color: var(--ink); }

/* --- Back to Top --- */
.back-to-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
  box-shadow: var(--shadow);
  z-index: 999;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* --- Mobile Nav Overlay --- */
.mobile-nav {
  display: none;
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-elevated);
  z-index: 999;
  padding: 1rem;
  overflow-y: auto;
}

.mobile-nav.open {
  display: block;
}

.mobile-nav a {
  display: block;
  padding: 0.75rem 0;
  color: var(--ink);
  font-size: 1rem;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
}

.mobile-nav a:hover {
  color: var(--accent);
}

/* ============================================
   Responsive Styles
   ============================================ */

/* ============================================
   Mobile Floating TOC (≤767px)
   把首页完整目录(left-sidebar)改为左侧居中悬浮收起式边缘栏：
   默认收起为半透明毛玻璃细条，点按展开全部 16 项；滚动时滑出左缘(吸附)，停滑滑回；
   面板内 ◐ 按钮循环 3 档"底色通透度"(localStorage 记忆)，文字始终不透明保证可读。
   ============================================ */

/* 默认隐藏移动专属控制条（仅 ≤767px 悬浮态显示） */
.toc-float-bar { display: none; }

@media (max-width: 767px) {
  .toc-sidebar.left-sidebar {
    display: block;
    position: fixed;
    left: 0;
    top: 50%;
    transform: translate(0, -50%);
    z-index: 40;
    width: max-content;
    max-height: 74vh;
    margin: 0;
    padding: 0;
    background: var(--surface); /* 不支持 color-mix 时的兜底：实底 */
    background: color-mix(in srgb, var(--surface) calc(var(--toc-float-bg, 0.82) * 100%), transparent);
    -webkit-backdrop-filter: blur(12px) saturate(1.3);
    backdrop-filter: blur(12px) saturate(1.3);
    border: 1px solid var(--border);
    border-left: 0;
    border-radius: 0 14px 14px 0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
    transition: transform 0.35s ease;
    overflow: hidden;
  }
  [data-theme="dark"] .toc-sidebar.left-sidebar {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }

  /* 收起态：仅显示控制条细条（隐藏标题与列表） */
  .toc-sidebar.left-sidebar .ui-toc,
  .toc-sidebar.left-sidebar .toc-list {
    display: none;
  }

  /* 展开态：显示完整 16 项，限高内部滚动 */
  .toc-sidebar.left-sidebar.open {
    width: min(78vw, 252px);
    overflow-y: auto;
    overflow-x: hidden;
  }
  .toc-sidebar.left-sidebar.open .toc-list {
    display: block;
  }

  .toc-float-bar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 0.6rem;
    background: transparent;
  }
  .toc-float-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 0.82rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.35rem;
    border-radius: 8px;
  }
  .toc-float-toggle svg { width: 16px; height: 16px; }
  .toc-float-opacity {
    display: none;            /* 仅展开时显示，保持收起细条最窄 */
    margin-left: auto;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.35rem;
    border-radius: 8px;
  }
  .toc-sidebar.left-sidebar.open .toc-float-opacity { display: inline-flex; }

  .toc-sidebar.left-sidebar .toc-list {
    position: static;
    top: auto;
    padding: 0.2rem 0.5rem 0.7rem;
    max-height: none;
  }
  .toc-sidebar.left-sidebar .toc-list a {
    padding: 0.5rem 0.6rem 0.5rem 0.8rem;
    font-size: 0.82rem;
    border-left: 2px solid transparent;
  }
  .toc-sidebar.left-sidebar .toc-list a.active {
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    border-radius: 0 8px 8px 0;
  }

  /* 滚动时：滑出左缘(吸附边缘)，停滑滑回 */
  .toc-sidebar.left-sidebar.scrolling {
    transform: translate(-90%, -50%);
  }
}

/* Tablet and up */
@media (min-width: 768px) {
  .main-layout {
    grid-template-columns: 1fr var(--toc-width);
    padding: 2.5rem 1.5rem;
  }

  .toc-sidebar {
    display: block;
  }

  .left-sidebar {
    display: none;
  }

  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .hero {
    padding: calc(var(--nav-height) + 4rem) 1.5rem 4rem;
  }

  .footer {
    padding: 1.25rem 1.5rem;
  }

  .footer-inner {
    justify-content: space-between;
    text-align: left;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .main-layout {
    grid-template-columns: var(--toc-width) 1fr var(--toc-width);
    gap: 2.5rem;
  }

  .left-sidebar {
    display: block;
  }

  .search-box .search-shortcut {
    display: inline;
  }
}

/* Mobile adjustments */
@media (max-width: 767px) {
  /* 导航栏改为两行：第一行「品牌 + 操作按钮」，第二行「搜索框全宽」。
     单行时品牌副标题会把 .nav-center 挤出视口（实测 390px 下搜索框 left:388 完全不可见）。 */
  :root {
    --nav-height: 104px;
  }

  .navbar .container {
    flex-wrap: wrap;
    align-content: center;
    row-gap: 0.35rem;
    padding: 0 0.75rem;
  }

  .logo {
    order: 1;
    flex: 1 1 auto;
    min-width: 0;
    font-size: 1rem;
    gap: 0.3rem;
  }

  /* 移动端导航栏空间有限，副标题让位给搜索框（≥768px 仍显示） */
  .logo-sub {
    display: none;
  }

  .logo svg {
    width: 24px;
    height: 24px;
  }

  .nav-actions {
    order: 2;
    flex-shrink: 0;
  }

  .nav-center {
    order: 3;
    flex-basis: 100%;
    max-width: none;
    margin: 0;
  }

  .search-box input {
    height: 34px;
    padding: 0 2rem 0 2rem;
    font-size: 16px; /* ≥16px：防止 iOS Safari 聚焦搜索框时自动放大页面 */
  }

  .search-box .search-icon {
    left: 0.6rem;
    width: 16px;
    height: 16px;
  }

  .search-box .search-shortcut {
    display: none;
  }

  .search-clear {
    width: 18px;
    height: 18px;
    right: 0.4rem;
  }

  .menu-toggle {
    display: flex;
  }

  .hero {
    padding: calc(var(--nav-height) + 2rem) 0.75rem 2rem;
  }

  .hero-desc {
    font-size: 0.88rem;
  }

  .hero-actions {
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
  }

  .hero-actions .btn {
    width: 100%;
    max-width: 280px;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 1rem;
  }

  .section {
    margin-bottom: 2rem;
  }

  .section-header {
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
  }

  .section-icon {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
  }

  th, td {
    padding: 0.4rem 0.5rem;
    font-size: 0.82rem;
  }

  .code-block pre[class*="language-"] {
    padding: 0.75rem 2.5rem 0.75rem 0.75rem;
    font-size: 0.8rem;
  }

  .code-block .copy-btn {
    opacity: 1;
    top: 0.35rem;
    right: 0.35rem;
    padding: 0.25rem 0.4rem;
  }

  .code-block .copy-btn svg {
    width: 12px;
    height: 12px;
  }

  .main-layout {
    padding: 1.5rem 0.75rem;
  }

  .footer {
    padding: 1.25rem 0.75rem;
  }

  .footer-links {
    gap: 0.75rem;
  }

  .footer-links a {
    font-size: 0.78rem;
  }

  .footer-copy {
    font-size: 0.78rem;
  }

  .footer-trademark {
    font-size: 0.8rem;
  }
}

/* Very small screens */
@media (max-width: 374px) {
  body {
    font-size: 13px;
  }

  .navbar .container {
    padding: 0 0.4rem;
  }

  /* 导航栏已改两行布局，空间充足，小屏也保留品牌名可见 */

  .logo svg {
    width: 22px;
    height: 22px;
  }

  .nav-center {
    margin: 0 0.25rem;
  }

  .search-box input {
    height: 32px;
    padding: 0 1.8rem;
    font-size: 16px; /* ≥16px：防止 iOS Safari 聚焦搜索框时自动放大页面 */
  }

  .hero-actions .btn {
    max-width: 100%;
    font-size: 0.8rem;
  }

  .section-icon {
    width: 22px;
    height: 22px;
  }

  .code-block pre[class*="language-"] {
    font-size: 0.75rem;
    padding: 0.6rem 2.2rem 0.6rem 0.6rem;
  }
}

/* Search shortcut hidden (must override desktop media query) */
.search-box .search-shortcut.hidden {
  display: none !important;
}

/* Print styles */
@media print {
  .navbar,
  .toc-sidebar,
  .back-to-top,
  .icon-btn,
  .search-shortcut,
  .copy-btn,
  .copy-toast {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  pre {
    background: #f5f5f5;
    color: #000;
    border: 1px solid #ddd;
  }

  a {
    color: #000;
    text-decoration: underline;
  }

  .section {
    page-break-inside: avoid;
  }
}

/* --- Git Viz (interactive merge / rebase demo) --- */
.gitviz {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.gitviz-tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.85rem; }
.gitviz-tab {
  border: 1px solid var(--rule-strong);
  background: transparent;
  color: var(--ink-secondary);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}
.gitviz-tab:hover { color: var(--ink); border-color: var(--accent); }
.gitviz-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.gitviz-stage {
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--bg);
  overflow: hidden;
}
.gitviz-svg { display: block; width: 100%; height: auto; }
/* 桌面端限制演示图高度：1920x1080 等宽屏下整个组件（图+命令+说明+按钮）一屏看完 */
@media (min-width: 641px) {
  .gitviz-svg { max-height: min(60vh, 520px); margin: 0 auto; }
}
.gitviz-edge { stroke: var(--rule-strong); stroke-width: 2; transition: opacity 0.45s ease; }
.gitviz-edge.ghost { stroke-dasharray: 5 4; opacity: 0.3; }
.gitviz-node { transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.45s ease; }
.gitviz-node circle { fill: var(--bg-elevated); stroke-width: 2.5; }
.gitviz-node.is-main circle { stroke: var(--accent); }
.gitviz-node.is-feature circle { stroke: var(--success); }
.gitviz-node text { font-family: var(--font-mono); font-size: 10px; font-weight: 600; fill: var(--ink); }
.gitviz-node.ghost { opacity: 0.3; }
.gitviz-node.ghost circle { stroke: var(--rule-strong); stroke-width: 2; stroke-dasharray: 4 3; }
.gitviz-ref { transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1); }
.gitviz-ref > rect { stroke: none; }
.gitviz-ref.is-main > rect { fill: var(--accent); }
.gitviz-ref.is-feature > rect { fill: var(--success); }
.gitviz-ref > text { font-family: var(--font-mono); font-size: 11px; font-weight: 600; fill: #fff; }
.gitviz-headchip { opacity: 0; transition: opacity 0.35s ease; }
.gitviz-ref.onhead .gitviz-headchip { opacity: 1; }
.gitviz-headchip rect { fill: var(--warning); stroke: none; }
.gitviz-headchip text { font-family: var(--font-mono); font-size: 9.5px; font-weight: 700; fill: #0f172a; }
.gitviz-cmd { margin-top: 0.75rem; }
.gitviz-cmd code {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  color: var(--ink);
  min-height: 1.2em;
  white-space: pre-wrap;
  word-break: break-all;
}
.gitviz-caption { margin-top: 0.6rem; }
.gitviz-caption p { font-size: 0.9rem; color: var(--ink-secondary); line-height: 1.6; min-height: 4.4em; }
.gitviz-controls { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.4rem; }
.gitviz-btn {
  border: 1px solid var(--rule-strong);
  background: var(--bg-elevated);
  color: var(--ink-secondary);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition), background var(--transition), border-color var(--transition), opacity var(--transition);
}
.gitviz-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.gitviz-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.gitviz-btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.gitviz-btn-primary:hover:not(:disabled) { color: #fff; filter: brightness(1.08); }
.gitviz-stepnum { font-family: var(--font-mono); font-size: 0.8rem; color: var(--muted); margin-left: auto; }

/* todo 编辑器（交互式变基 -i） */
.gitviz-todo {
  margin-top: 0.75rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 0.65rem 0.85rem;
}
.gitviz-todo-head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.45rem; }
.gitviz-todo-title { font-size: 0.85rem; font-weight: 700; color: var(--ink); }
.gitviz-todo-hint { font-size: 0.75rem; color: var(--muted); }
.gitviz-todo-rows { display: flex; flex-direction: column; gap: 0.35rem; }
.gitviz-todo-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink-secondary);
  transition: opacity var(--transition);
}
.gitviz-todo-row.is-dropping { opacity: 0.45; text-decoration: line-through; }
.gitviz-todo-row code { color: var(--accent); }
.gitviz-todo-row .gitviz-todo-msg { font-family: var(--font-body); }
.gitviz-todo-act {
  border: 1px solid var(--rule-strong);
  background: transparent;
  color: var(--ink-secondary);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
  min-width: 6.5em;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}
.gitviz-todo-act.is-pick { border-color: var(--success); color: var(--success); }
.gitviz-todo-act.is-reword { border-color: var(--accent); color: var(--accent); }
.gitviz-todo-act.is-squash { border-color: var(--warning); color: var(--warning); }
.gitviz-todo-act.is-drop { border-color: var(--danger, #dc2626); color: var(--danger, #dc2626); }
.gitviz-todo-act:hover { background: var(--bg-elevated); }

/* 提交徽标：✎ reword / + squash */
.gitviz-badge circle { fill: var(--warning); stroke: var(--bg); stroke-width: 1.5; }
.gitviz-badge text { fill: #0f172a; font-size: 10px; font-weight: 700; }

@media (max-width: 640px) {
  .gitviz { padding: 0.75rem; }
  .gitviz-caption p { min-height: 6.2em; }
  .gitviz-todo-row .gitviz-todo-msg { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* FAQ（常见问题）section */
.faq-list { display: flex; flex-direction: column; gap: 1rem; }
.faq-item {
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  background: var(--bg-elevated, #fff);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.faq-item:hover { border-color: var(--accent); box-shadow: 0 2px 12px rgba(var(--accent-rgb), 0.08); }
.faq-q { font-size: 1.05rem; font-weight: 700; margin: 0 0 0.5rem; color: var(--ink, #0f172a); }
.faq-a { color: var(--ink-secondary, #475569); line-height: 1.7; }
.faq-a p { margin: 0; }
.faq-a code { background: var(--bg-code, #f1f5f9); padding: 0.1rem 0.4rem; border-radius: 6px; font-size: 0.9em; }
