/* ========================================
   1. 全局基础样式
   作用：重置默认样式、设置页面背景和基础字体
======================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  overflow: auto !important;
  height: auto !important;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background: linear-gradient(135deg, #f0f4ff 0%, #f7f9ff 100%);
  color: #1f2937;
  line-height: 1.6;
  min-height: 100vh;
  transition: all 0.3s ease;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* ========================================
   2. 标题与访问统计
   作用：页面大标题、访问量显示样式
======================================== */
h1 {
  text-align: center;
  margin: 20px 0;
  font-size: 28px;
  font-weight: 600;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.visit-info {
  text-align: center;
  margin: 10px 0;
  font-size: 14px;
  color: #6b7280;
}

/* ========================================
   3. 导航折叠面板（核心修改部分）
   作用：控制导航栏的展开/收起，使用网格布局解决换行问题
======================================== */
.nav-section {
  margin: 30px 0;
  position: relative;
  z-index: 1;
}

/* 折叠面板的标题栏 */
.fold-header {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  padding: 16px 22px;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0, 20, 60, 0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.fold-header:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(59, 130, 246, 0.12);
}

.fold-header h3 {
  font-size: 18px;
  color: #1f2937;
  font-weight: 600;
}

.fold-icon {
  font-size: 14px;
  color: #6b7280;
}

/* 折叠面板的内容区（已改为网格布局） */
.fold-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease;
  
  /* 关键修改：使用 CSS Grid 实现整齐的网格布局 */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); /* 自动填充，最小宽度180px */
  gap: 12px; /* 卡片之间的间距 */
  
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-radius: 0 0 14px 14px;
  box-shadow: 0 4px 20px rgba(0, 20, 60, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.3);
}
/* 单独给B站折叠内容关闭网格，全屏宽 */
#bilibili-section .fold-content {
  display: block !important;
  gap: 0 !important;
}

.fold-content.fold-open {
  max-height: 1200px;
  padding: 20px;
}

/* ========================================
   4. 导航卡片（带标题+描述）
   作用：控制每个导航链接的卡片样式，已适配网格布局
======================================== */
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%; /* 让卡片填满网格单元格 */
}

.nav-card {
  width: 100%;
  background: rgba(255, 255, 255, 0.95);
  padding: 12px 14px;
  border-radius: 10px;
  border-left: 3px solid #3b82f6;
  transition: all 0.28s ease;
  box-shadow: 0 2px 8px rgba(0, 20, 60, 0.05);
  text-decoration: none;
  color: #1f2937;
  font-weight: 500;
  text-align: center;
}

.nav-card:hover {
  background: rgba(239, 246, 255, 1);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.12);
  border-left-color: #2563eb;
}

.nav-desc {
  margin-top: 6px;
  font-size: 12px;
  color: #6b7280;
  line-height: 1.4;
  text-align: center;
}

/* ========================================
   5. 搜索框
   作用：顶部搜索栏和下拉结果样式
======================================== */
.search-box {
  max-width: 600px;
  margin: 20px auto;
  position: relative;
  z-index: 10;
}

#searchInput {
  width: 100%;
  padding: 15px 20px;
  border-radius: 14px;
  border: 1px solid rgba(59, 130, 246, 0.15);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  font-size: 15px;
  transition: all 0.3s ease;
}

#searchInput:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

#searchResult {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(12px);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 20, 60, 0.12);
  padding: 10px;
  display: none;
  z-index: 999;
}

.search-item {
  display: block;
  padding: 11px 16px;
  border-radius: 8px;
  transition: background 0.2s;
  text-decoration: none;
  color: #1f2937;
}

.search-item:hover {
  background: rgba(59, 130, 246, 0.08);
}

/* ========================================
   6. 留言板
   作用：留言输入框、提交按钮和留言列表样式
======================================== */
.message-section {
  margin: 40px 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  padding: 26px;
  border-radius: 18px;
  box-shadow: 0 8px 30px rgba(0, 20, 60, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.3);
  position: relative;
  z-index: 1;
}

.message-input {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

#nameInput, #contentInput {
  padding: 15px;
  border-radius: 12px;
  border: 1px solid rgba(59, 130, 246, 0.12);
  background: rgba(255, 255, 255, 0.95);
  font-size: 15px;
  transition: all 0.3s ease;
}

#contentInput {
  min-height: 130px;
  resize: vertical;
}

#nameInput:focus, #contentInput:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

#submitBtn {
  padding: 14px 24px;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  color: #fff;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 500;
  border: none;
  font-size: 15px;
}

#submitBtn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.25);
}

#submitBtn:disabled {
  background: #9ca3af;
  transform: none;
  box-shadow: none;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-item {
  background: rgba(248, 250, 252, 0.9);
  padding: 18px;
  border-radius: 12px;
  border-left: 4px solid #3b82f6;
  transition: all 0.3s ease;
}

.message-item:hover {
  background: rgba(239, 246, 255, 0.9);
  transform: translateX(3px);
}

.message-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 14px;
}

.message-name {
  font-weight: bold;
  color: #1f2937;
}

.message-time {
  color: #6b7280;
}

.loading, .empty-tip {
  text-align: center;
  color: #6b7280;
  padding: 20px 0;
}

/* ========================================
   7. MD 内容区域
   作用：Markdown 渲染内容的容器样式
======================================== */
.md-section {
  margin: 40px 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  padding: 26px;
  border-radius: 18px;
  box-shadow: 0 8px 30px rgba(0, 20, 60, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.md-section h2 {
  margin-bottom: 18px;
  color: #1f2937;
  font-weight: 600;
}

/* ========================================
   8. 暗黑模式适配
   作用：当系统为深色模式时，自动切换为暗色主题
======================================== */
@media (prefers-color-scheme: dark) {
  body {
    background: #111827;
    color: #f3f4f6;
  }

  .fold-header,
  .fold-content,
  .message-section,
  .md-section {
    background: rgba(31, 41, 55, 0.9);
    border-color: rgba(55, 65, 81, 0.4);
  }

  .nav-card {
    background: #1f2937;
    color: #f3f4f6;
    border-color: #3b82f6;
  }

  .nav-desc {
    color: #9ca3af;
  }

  .message-item {
    background: #1f2937;
  }

  #nameInput,
  #contentInput,
  #searchInput {
    background: #1f2937;
    color: #f3f4f6;
    border-color: #374151;
  }
}

/* ============================ */
/* 左侧固定全局导航（外置样式） */
/* ============================ */
.left-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 170px;
  height: 100vh;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-right: 1px solid #eee;
  padding: 30px 15px;
  z-index: 999;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.left-sidebar h3 {
  text-align: center;
  margin-bottom: 25px;
  font-size: 16px;
  color: #3b82f6;
  transition: color 0.3s ease;
}

.sidebar-item {
  display: block;
  padding: 11px 14px;
  margin: 6px 0;
  border-radius: 8px;
  text-decoration: none;
  color: #333;
  font-size: 14px;
  transition: all 0.2s ease;
}

.sidebar-item:hover {
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
}

/* 内容右移，不被侧边栏遮挡 */
.container {
  margin-left: 190px;
}

/* 平滑滚动 */
html {
  scroll-behavior: smooth;
}

/* ========== 🔥 终极修复：按钮切换暗黑模式 ========== */
html.dark .left-sidebar {
  background: rgba(31, 41, 55, 0.95) !important;
  border-right-color: rgba(55, 65, 81, 0.5) !important;
}
html.dark .sidebar-item {
  color: #e5e7eb !important;
}
html.dark .left-sidebar h3 {
  color: #60a5fa !important;
}

/* ========== 系统暗黑模式 ========== */
@media (prefers-color-scheme: dark) {
  .left-sidebar {
    background: rgba(31, 41, 55, 0.95);
    border-right-color: rgba(55, 65, 81, 0.5);
  }
  .sidebar-item {
    color: #e5e7eb;
  }
}