:root {
  --theme-color: #3451b2;
  --sidebar-width: 300px;
  --content-max: 920px;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
  color: #2c2c2c;
  background: #fff;
}

.sidebar {
  width: var(--sidebar-width);
  border-right: 1px solid #ececec;
  background: #fafafa;
  padding-top: 54px;
  scroll-padding-top: 66px;
}

.sidebar .app-name {
  padding: 10px 20px 12px;
  font-size: 18px;
  letter-spacing: 0.01em;
}

.sidebar .search {
  position: sticky;
  top: 0;
  z-index: 50;
  margin-bottom: 8px;
  padding: 10px 16px 8px;
  background: #fafafa;
  border-bottom: 1px solid #efefef;
}

.sidebar .search input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid #ddd;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.sidebar .search input:focus {
  border-color: var(--theme-color);
  box-shadow: 0 0 0 3px rgba(52, 81, 178, 0.1);
}

.sidebar-nav {
  padding: 4px 8px 28px;
}

.sidebar-nav ul {
  margin: 0;
}

.sidebar-nav li {
  margin: 1px 0;
}

.sidebar-nav a {
  display: block;
  padding: 5px 10px;
  border-radius: 6px;
  color: #555;
  font-size: 13px;
  line-height: 1.55;
  text-decoration: none;
}

.sidebar-nav a:hover {
  color: var(--theme-color);
  background: #f0f3fb;
}

.sidebar .app-sub-sidebar {
  padding-left: 12px !important;
}

.sidebar .app-sub-sidebar .app-sub-sidebar {
  padding-left: 14px !important;
}

.sidebar .app-sub-sidebar > li > a {
  font-size: 12.8px;
  color: #5f6368;
}

.sidebar .app-sub-sidebar .app-sub-sidebar > li > a {
  font-size: 12.2px;
  color: #70757c;
}

.sidebar-nav li.active > a {
  color: var(--theme-color);
  font-weight: 600;
}

/* 正文 h2 / h3 自动生成的两级目录 */
.site-toc,
.site-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-group {
  margin: 2px 0;
}

.toc-chapter-row {
  display: flex;
  align-items: flex-start;
  gap: 2px;
}

.toc-toggle,
.toc-toggle-spacer {
  flex: 0 0 18px;
  width: 18px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  line-height: 24px;
  text-align: center;
}

.toc-toggle {
  position: relative;
  z-index: 2;
  color: #9aa0a6;
  font-size: 0;
  cursor: pointer;
}

.toc-toggle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  margin: -3px 0 0 -4px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  transform-origin: 50% 30%;
  transition: transform 0.15s;
}

.toc-group.is-collapsed .toc-toggle::before {
  transform: rotate(-90deg);
}

.toc-toggle:hover {
  color: var(--theme-color);
}

.toc-chapter {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border-radius: 6px;
  color: #222;
  font-size: 13.2px;
  font-weight: 600;
  line-height: 1.5;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-chapter:hover {
  background: #f0f3fb;
  color: var(--theme-color);
}

.toc-sections {
  margin: 1px 0 4px 34px !important;
  padding-left: 0 !important;
}

.toc-section {
  display: block;
  padding: 4px 8px;
  border-radius: 6px;
  color: #69707a;
  font-size: 12.2px;
  line-height: 1.55;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-section:hover {
  background: #f0f3fb;
  color: var(--theme-color);
}

.toc-group.is-collapsed .toc-sections {
  display: none;
}

.toc-group.is-active > .toc-chapter-row > .toc-chapter {
  color: var(--theme-color);
}

.toc-chapter.is-active,
.toc-section.is-active {
  background: #eef2fc;
  color: var(--theme-color);
  font-weight: 600;
}

/* 拖拽调整目录宽度 */
#sidebar-resizer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: var(--sidebar-width);
  width: 8px;
  transform: translateX(-4px);
  z-index: 45;
  cursor: col-resize;
}

#sidebar-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3px;
  width: 1px;
  background: #e6e6e6;
  transition: background-color 0.15s, width 0.15s;
}

#sidebar-resizer::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 50%;
  width: 5px;
  height: 34px;
  margin-top: -17px;
  border-radius: 3px;
  background: #d8dbe0;
  opacity: 0.35;
  transition: opacity 0.15s, background-color 0.15s;
}

#sidebar-resizer:hover::before,
body.is-resizing #sidebar-resizer::before {
  opacity: 1;
  background: var(--theme-color);
}

#sidebar-resizer:hover::after,
#sidebar-resizer:focus-visible::after,
body.is-resizing #sidebar-resizer::after {
  left: 3px;
  width: 2px;
  background: var(--theme-color);
}

body.is-resizing {
  cursor: col-resize;
  user-select: none;
}

body.is-resizing .content {
  transition: none;
}

@media (max-width: 768px) {
  #sidebar-resizer {
    display: none;
  }
}

.sidebar-nav > ul > li > a {
  color: #222;
  font-weight: 600;
}

/* 搜索下拉面板 */
.search .results-panel {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 100%;
  z-index: 40;
  max-height: 70vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(30, 35, 50, 0.14);
}

.search .matching-post {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f1f1;
}

.search .matching-post:last-child {
  border-bottom: 0;
}

.search .matching-post a {
  display: block;
  text-decoration: none;
}

.search .matching-post h2 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: #222;
}

.search .matching-post p {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: #777;
}

.search .search-keyword {
  color: var(--theme-color);
  font-style: normal;
}

.markdown-section {
  max-width: var(--content-max);
  padding: 42px 44px 100px;
  font-size: 16px;
  line-height: 1.9;
}

.markdown-section h1 {
  font-size: 2rem;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

.markdown-section h2 {
  margin-top: 2.6em;
  padding-top: 1em;
  border-top: 1px solid #eee;
  font-size: 1.55rem;
  line-height: 1.45;
}

.markdown-section h3 {
  margin-top: 2em;
  font-size: 1.28rem;
}

.markdown-section h4 {
  font-size: 1.08rem;
}

.markdown-section p,
.markdown-section li {
  line-height: 1.9;
}

.markdown-section strong {
  color: #111;
}

.markdown-section table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 14px;
}

.markdown-section table th,
.markdown-section table td {
  padding: 8px 12px;
  border: 1px solid #e6e6e6;
  vertical-align: top;
}

.markdown-section table th {
  background: #f7f7f7;
  white-space: nowrap;
}

.markdown-section table tr:nth-child(even) {
  background: #fbfbfb;
}

.markdown-section blockquote {
  border-left: 3px solid #c9d4f0;
  background: #f7f9fe;
  padding: 10px 16px;
  color: #444;
  border-radius: 0 8px 8px 0;
}

.markdown-section blockquote p {
  margin: 0;
}

.markdown-section code {
  font-family: 'Cascadia Code', 'JetBrains Mono', Consolas, monospace;
  font-size: 0.86em;
  background: #f5f5f5;
  border-radius: 4px;
  padding: 1px 4px;
}

.markdown-section pre {
  border-radius: 10px;
}

.markdown-section pre > code {
  background: transparent;
  padding: 0;
  font-size: 13px;
}

.markdown-section a {
  color: var(--theme-color);
}

.markdown-section .mermaid {
  display: flex;
  justify-content: center;
  overflow-x: auto;
  margin: 20px 0;
}

.markdown-section .mermaid svg {
  max-width: 100%;
  height: auto;
}

.markdown-section .anchor-target {
  height: 0;
  margin: 0;
  padding: 0;
}

/* Docsify 自带的“编辑/返回顶部”按钮不做展示 */
.github-corner {
  display: none;
}
@media (min-width: 769px) {
  .content {
    left: var(--sidebar-width);
  }

  .sidebar-toggle {
    display: none;
  }
}

@media (max-width: 768px) {
  html,
  body {
    -webkit-text-size-adjust: 100%;
  }

  .sidebar {
    width: 300px;
    z-index: 20;
    visibility: hidden;
    pointer-events: none;
    -webkit-overflow-scrolling: touch;
    transition: transform 0.25s ease-out, visibility 0s linear 0.25s;
  }

  body.close .sidebar {
    visibility: visible;
    pointer-events: auto;
    transition: transform 0.25s ease-out, visibility 0s;
  }

  .sidebar-toggle,
  body.close .sidebar-toggle {
    z-index: 30;
    width: 48px !important;
    padding: 14px 16px !important;
    border-radius: 0;
    background-color: transparent;
    box-shadow: none;
    touch-action: manipulation;
  }

  .sidebar-toggle {
    padding-bottom: calc(14px + env(safe-area-inset-bottom)) !important;
  }

  body.close .sidebar-toggle {
    background-color: #fff;
    border-radius: 0 10px 10px 0;
    box-shadow: 0 2px 10px rgba(20, 30, 60, 0.12);
  }

  .sidebar-nav a,
  .toc-toggle {
    touch-action: manipulation;
  }

  .markdown-section {
    padding: 24px 16px 84px;
    font-size: 16px;
  }

  .markdown-section h1 {
    font-size: 1.68rem;
    line-height: 1.35;
  }

  .markdown-section h2 {
    margin-top: 2.1em;
    padding-top: 0.8em;
    font-size: 1.4rem;
  }

  .markdown-section h3 {
    margin-top: 1.8em;
    font-size: 1.2rem;
  }

  .markdown-section h4 {
    font-size: 1.05rem;
  }

  .markdown-section p,
  .markdown-section li {
    line-height: 1.85;
  }

  .markdown-section p,
  .markdown-section li,
  .markdown-section td {
    overflow-wrap: anywhere;
  }

  .markdown-section table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 13px;
  }

  .markdown-section th,
  .markdown-section td {
    padding: 7px 10px;
  }

  .markdown-section pre {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .markdown-section pre > code {
    font-size: 12px;
  }

  .markdown-section :not(pre) > code {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .markdown-section .mermaid {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .markdown-section .mermaid svg {
    max-width: 100%;
    height: auto;
  }

  .sidebar .search input {
    /* 16px 以上可避免 iOS Safari 聚焦输入框时自动放大页面 */
    font-size: 16px;
  }

  .toc-chapter {
    padding: 7px 8px;
    font-size: 13.5px;
  }

  .toc-section {
    padding: 7px 8px;
    font-size: 12.8px;
  }

  .toc-toggle,
  .toc-toggle-spacer {
    flex-basis: 30px;
    width: 30px;
    height: 32px;
    line-height: 32px;
  }

  .toc-sections {
    margin-left: 44px !important;
  }
}

/* 移动端/触屏设备通用兜底 */
html.is-mobile body {
  -webkit-text-size-adjust: 100%;
}

html.is-mobile .sidebar .search input {
  font-size: 16px;
}

html.is-mobile .markdown-section img,
html.is-mobile .markdown-section video {
  max-width: 100%;
  height: auto;
}
