/* =======================================
   全局样式
======================================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  scroll-behavior: smooth;
}

:root {
  --primary: #42b983;
  --primary-light: #4fc08d;
  --bg: #ffffff;
  --text: #2c3e50;
  --sidebar-bg: #f8f8f8;
  --border: #eaecef;
  --code-bg: #f6f8fa;
  --card-bg: #ffffff;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.dark {
  --primary: #42b983;
  --primary-light: #4fc08d;
  --bg: #121212;
  --text: #e4e4e4;
  --sidebar-bg: #1a1a1a;
  --border: #333;
  --code-bg: #1e1e1e;
  --card-bg: #1a1a1a;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

body {
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
}

/* =======================================
   导航栏
======================================= */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 999;
  box-shadow: var(--shadow);
}

.logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 40px;
}

/* =======================================
   搜索框
======================================= */
.search-box {
  position: relative;
  flex: 1;
  max-width: 380px;
  margin: 0 24px;
}

.search-box input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--sidebar-bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: 0.2s;
}

.search-box input:focus {
  border-color: var(--primary);
  background: var(--bg);
}

.search-box .fa-search {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text);
  opacity: 0.4;
}

.search-results {
  position: absolute;
  top: 50px;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 380px;
  overflow-y: auto;
  z-index: 9999;
  display: none;
  box-shadow: var(--shadow);
}

.search-results.show {
  display: block;
}

.search-result-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.search-result-item:hover {
  background: var(--sidebar-bg);
}

.search-result-item .title {
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 4px;
}

.search-result-item .content {
  font-size: 13px;
  color: var(--text);
  opacity: 0.8;
}

.search-result-item .mark {
  background: #fff200;
  color: #000;
  padding: 1px 3px;
  border-radius: 2px;
}

/* =======================================
   导航链接
======================================= */
.nav-links {
  display: flex;
  gap: 28px;
  list-style: none;
}

.nav-links a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 15px;
  transition: color 0.2s;
}

.nav-links a:hover {
  color: var(--primary);
}

.tools {
  margin-left: auto;
}

#themeBtn {
  background: none;
  border: none;
  font-size: 19px;
  color: var(--text);
  cursor: pointer;
  transition: 0.2s;
}

/* =======================================
   布局
======================================= */
.container {
  display: flex;
  margin-top: 64px;
  min-height: calc(100vh - 64px);
}

/* =======================================
   侧边栏
======================================= */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 30px 20px;
  position: fixed;
  height: calc(100vh - 64px);
  overflow-y: auto;
}

.menu-group {
  margin-bottom: 32px;
}

.menu-group h3 {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 14px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.menu-group ul {
  list-style: none;
}

.menu-group li {
  margin: 10px 0;
}

.menu-group a {
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  transition: color 0.2s;
  display: block;
  padding: 4px 0;
}

.menu-group a:hover {
  color: var(--primary);
}

/* =======================================
   主内容区
======================================= */
.main {
  flex: 1;
  padding: 50px 60px;
  margin-left: 260px;
  max-width: 1000px;
}

#content {
  line-height: 1.85;
  font-size: 16px;
}

#content h1 {
  font-size: 40px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 24px;
}

#content h2 {
  font-size: 28px;
  margin: 40px 0 16px;
  color: var(--text);
  font-weight: 600;
}

#content h3 {
  font-size: 22px;
  margin: 30px 0 12px;
  color: var(--text);
}

#content p {
  margin: 0 0 16px;
  color: var(--text);
}

/* =======================================
   代码块
======================================= */
#content pre {
  background: var(--code-bg);
  padding: 22px;
  border-radius: 10px;
  margin: 20px 0;
  border: 1px solid var(--border);
  overflow-x: auto;
}

#content code {
  font-family: "Consolas", "Monaco", monospace;
  font-size: 14px;
}

#content textarea.code-editor {
  width: 100%;
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  font-family: "Consolas", "Monaco", monospace;
  font-size: 14px;
  line-height: 1.6;
  outline: none;
  margin: 20px 0;
  overflow: hidden;
  resize: none;
  height: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-sizing: border-box;
}

/* =======================================
   滚动条美化
======================================= */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.dark ::-webkit-scrollbar-thumb {
  background: #444;
}

/* =======================================
   响应式
======================================= */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  .main {
    margin-left: 0;
    padding: 30px 20px;
  }
  .search-box {
    margin: 0 12px;
  }
  .nav-links {
    gap: 16px;
  }
}
/* =======================================
   右侧赞助商栏位
======================================= */
.sponsor-sidebar {
  width: 260px;
  padding: 30px 20px;
  flex-shrink: 0;
}

.sponsor-card {
  position: sticky;
  top: 80px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}

.sponsor-card h4 {
  font-size: 16px;
  margin-bottom: 16px;
  color: var(--primary);
  font-weight: 600;
}

.sponsor-item {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  text-align: left;
}

.sponsor-item .icon {
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sponsor-item .text h5 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.sponsor-item .text p {
  font-size: 12px;
  color: var(--text);
  opacity: 0.7;
  margin: 0;
}

.sponsor-btn {
  display: inline-block;
  width: 100%;
  padding: 10px 0;
  background: var(--primary);
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: 0.2s;
}

.sponsor-btn:hover {
  background: #3aa877;
}

/* 小屏幕自动隐藏右侧栏 */
@media (max-width: 1400px) {
  .sponsor-sidebar {
    display: none;
  }
}
/* =======================================
   本页目录（右侧）
======================================= */
.toc-sidebar {
  width: 240px;
  padding: 30px 20px;
  flex-shrink: 0;
}
.toc-card {
  position: sticky;
  top: 80px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.toc-card h4 {
  font-size: 15px;
  margin-bottom: 14px;
  color: var(--primary);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.toc-item {
  padding: 6px 8px;
  font-size: 14px;
  color: var(--text);
  opacity: 0.85;
  cursor: pointer;
  border-radius: 4px;
  transition: 0.2s;
}
.toc-item:hover {
  color: var(--primary);
  background: var(--sidebar-bg);
}
.toc-item.active {
  color: var(--primary);
  font-weight: 500;
  background: var(--sidebar-bg);
}
.toc-h2 {
  padding-left: 0 !important;
  font-weight: 500;
}
.toc-h3 {
  padding-left: 12px !important;
  font-size: 13px;
}

/* 小屏幕隐藏目录 */
@media (max-width: 1400px) {
  .toc-sidebar {
    display: none;
  }
}
/* =========================
   右侧栏（目录 + 赞助商）
========================= */
.right-sidebar {
  width: 240px;
  flex-shrink: 0;
}
.right-sticky {
  position: sticky;
  top: 80px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* === 目录 === */
.toc-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.toc-box h4 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 14px;
  color: var(--text);
}
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 1px solid var(--border);
}
.toc-list li {
  padding: 0;
  margin: 0;
}
.toc-list a {
  display: block;
  padding: 5px 14px;
  color: var(--text);
  opacity: 0.8;
  text-decoration: none;
  transition: all 0.2s;
  border-left: 2px solid transparent;
  font-size: 14px;
}
.toc-list a:hover {
  color: var(--primary);
  opacity: 1;
}
.toc-list a.active {
  color: var(--primary);
  font-weight: 500;
  opacity: 1;
  border-left-color: var(--primary);
}
.toc-list ul {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 1px solid var(--border);
  margin-left: 14px;
}

/* === 赞助商 === */
.sponsor-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
}
.sponsor-box h4 {
  font-size: 14px;
  margin-bottom: 14px;
  color: var(--primary);
  font-weight: 600;
}
.sponsor-btn {
  display: inline-block;
  width: 100%;
  padding: 10px 0;
  background: var(--primary);
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: 0.2s;
}
.sponsor-btn:hover {
  background: #3aa877;
}

/* 小屏幕隐藏 */
@media (max-width: 1200px) {
  .right-sidebar {
    display: none;
  }
}
/* =========================
   1. 返回顶部按钮
========================= */
.back-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 44px;
  height: 44px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: 0.3s;
  z-index: 999;
  box-shadow: 0 4px 12px rgba(66, 185, 131, 0.2);
}
.back-top.show {
  opacity: 1;
  visibility: visible;
}
.back-top:hover {
  background: #3fa877;
  transform: translateY(-2px);
}

/* =========================
   2. 代码复制按钮
========================= */
.code-block-wrapper {
  position: relative;
  margin: 20px 0;
}
.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(66, 185, 131, 0.15);
  color: var(--primary);
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: 0.2s;
}
.code-block-wrapper:hover .copy-btn {
  opacity: 1;
}
.copy-btn:hover {
  background: var(--primary);
  color: #fff;
}

/* =========================
   3. 页面加载动画
========================= */
.loading-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s;
}
.loading-mask.hide {
  opacity: 0;
  pointer-events: none;
}
.loading-spin {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}