/* ============================================
   Main CSS - 分类层级、热力图、响应式
   ============================================
   
   此文件包含以下未独立拆分的样式：
   - 分类层级样式 (.category, .category-level-*, .group-*)
   - GitHub 热力图 (.gh-*)
   - 全局响应式设计 (@media)
   - 搜索结果区域 (#search-results)
   
   ============================================ */

/* 分类样式 */
.category {
  background: linear-gradient(145deg, var(--card-bg-gradient-1), var(--card-bg-gradient-2));
  border-radius: var(--radius-xl);
  padding: 1rem;
  margin: 0 auto 1.2rem auto;
  width: 100%;
  max-width: var(--page-max-width);
  position: relative;
  z-index: 1;
  opacity: 1;
  box-shadow: 0 4px 20px var(--shadow-color);
  border: 1px solid var(--border-color);
  transition:
    background var(--transition-normal),
    box-shadow var(--transition-normal);
}

/* 分类标题容器 */
.category-header {
  border-radius: var(--radius-md);
  padding: 0.4rem;
  margin: -0.4rem -0.4rem 0.8rem -0.4rem;
  transition: all var(--transition-normal);
}

/* 标题前图标固定宽度：避免不同图标宽度导致标题文本不对齐 */
.category-header [data-editable='category-name'] > i,
.group-header [data-editable='group-name'] > i {
  width: 1.25em;
  min-width: 1.25em;
  text-align: center;
  flex: 0 0 1.25em;
}

/* 分组标题容器：与分类保持一致的悬浮动效基础 */
.group-header {
  border-radius: var(--radius-md);
  transition: all var(--transition-normal);
}

/* 仅可折叠的标题显示交互态 */
.category-header[data-toggle='category'],
.group-header[data-toggle='group'] {
  cursor: pointer;
  user-select: none;
}

.category-header[data-toggle='category']:hover {
  transform: translateY(-2px);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
}

.group-header[data-toggle='group']:hover {
  transform: translateY(-2px);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
}

.category-header[data-toggle='category']:active {
  transform: translateY(0);
}

.group-header[data-toggle='group']:active {
  transform: translateY(0);
}

.category h2 {
  font-size: 1.2rem;
  margin-bottom: 0;
  color: var(--text-bright);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  letter-spacing: 0.3px;
  transition: color 0.3s ease;
}

.category h2 > i {
  color: var(--accent-color);
  font-size: 1.3rem;
  transition: all 0.3s ease;
}

.category-header[data-toggle='category']:hover h2 > i {
  transform: scale(1.1);
  color: var(--accent-hover);
}

/* 多层级嵌套样式 - 扁平化设计 */

/* 通用重置：移除所有嵌套层级的卡片背景和边框 */
.category-level-2,
.category-level-3,
.category-level-4,
.group-level-3,
.group-level-4 {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  width: 100%;
  margin: 0;
}

/* 嵌套层级指示线 (Hierarchy Indicator A) */
.category-level-2::before,
.category-level-3::before,
.group-level-3::before,
.category-level-4::before,
.group-level-4::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background-color: var(--border-color);
  opacity: 0.6;
}

/* 层级2: 子分类 */
.category-level-2 {
  margin-top: 0;
  margin-bottom: 0;
  padding-left: 1rem;
  border-left: none;
  position: relative;
}

/* 层级2: 标题样式 */
.category-level-2 .category-header {
  margin: 0 -0.5rem 1rem -0.5rem;
  padding: 0.5rem;
  background: none;
  border-radius: var(--radius-md);
}

.category-level-2 .category-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-bright);
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.category-level-2 .category-header h3 > i {
  color: var(--accent-color);
  font-size: 1.2rem;
  opacity: 0.9;
}

/* 层级3: 分组 */
.group-level-3,
.category-level-3 {
  margin-top: 0;
  margin-bottom: 0;
  padding-left: 1rem;
  position: relative;
}

/* 层级3: 标题样式 */
.group-level-3 .group-header,
.category-level-3 .category-header {
  margin: 0 0 0.8rem 0;
  padding: 0.3rem 0;
  background: none;
}

.group-level-3 .group-header h4,
.category-level-3 .category-header h4 {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-color);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.group-level-3 .group-header h4 i,
.category-level-3 .category-header h4 i {
  color: var(--text-muted);
  font-size: 1rem;
}

/* 层级4: 子分组 */
.group-level-4,
.category-level-4 {
  margin-top: 0;
  margin-bottom: 0;
  padding-left: 1rem;
  position: relative;
}

/* 嵌套层级间距：仅在同级相邻时增加间距，避免首项被额外下推 */
.subcategories-container > .category-level-2 + .category-level-2 {
  margin-top: 1rem;
}

.groups-container > .group-level-3 + .group-level-3,
.groups-container > .category-level-3 + .category-level-3 {
  margin-top: 0.8rem;
}

.subgroups-container > .group-level-4 + .group-level-4,
.subcategories-container > .category-level-4 + .category-level-4 {
  margin-top: 0.6rem;
}

/* 层级4: 标题样式 */
.group-level-4 .group-header,
.category-level-4 .category-header {
  margin: 0 0 0.6rem 0;
  padding: 0.2rem 0;
  background: none;
}

.group-level-4 .group-header h5,
.category-level-4 .category-header h5 {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.group-level-4 .group-header h5 i,
.category-level-4 .category-header h5 i {
  font-size: 0.9rem;
  opacity: 0.7;
}

/* 移除悬停时的缩放效果，保持简洁 */
.category-level-2 .category-header:hover h3 > i,
.group-level-3 .group-header:hover h4 i,
.category-level-3 .category-header:hover h4 i,
.group-level-4 .group-header:hover h5 i,
.category-level-4 .category-header:hover h5 i {
  transform: none;
}

/* 切换图标样式 */
.category-header .toggle-icon,
.group-header .toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-left: auto;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.category-header .toggle-icon i,
.group-header .toggle-icon i {
  transition:
    transform 0.3s ease,
    color 0.3s ease;
  transform: rotate(0deg);
}

/* 展开态：图标旋转 180°（类似参考样式1） */
.category:not(.collapsed) > .category-header .toggle-icon i,
.group:not(.collapsed) > .group-header .toggle-icon i {
  transform: rotate(180deg);
  color: var(--text-bright);
}

.category-header[data-toggle='category']:hover .toggle-icon i,
.group-header[data-toggle='group']:hover .toggle-icon i {
  color: var(--accent-color);
}

/* 分类/分组折叠图标：桌面端默认隐藏，悬停/收起时显示，避免按钮过多 */
@media (hover: hover) and (pointer: fine) {
  .category-header .toggle-icon,
  .group-header .toggle-icon {
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  .category-header[data-toggle='category']:hover .toggle-icon,
  .category.collapsed > .category-header .toggle-icon,
  .group-header[data-toggle='group']:hover .toggle-icon,
  .group.collapsed > .group-header .toggle-icon {
    opacity: 1;
  }
}

/* 展开/折叠动画 */
.category-content,
.group-content {
  overflow: visible;
  transition:
    max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 5000px;
  opacity: 1;
}

.category.collapsed .category-content,
.group.collapsed .group-content {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

/* 收起状态下调整header的下边距 */
.category.collapsed > .category-header {
  margin-bottom: -0.5rem;
}

.category-level-2.collapsed > .category-header {
  margin-bottom: 0;
  border-bottom: none;
}

.group-level-3.collapsed > .group-header,
.category-level-3.collapsed > .category-header {
  margin-bottom: 0;
}

.group-level-4.collapsed > .group-header,
.category-level-4.collapsed > .category-header {
  margin-bottom: 0;
}

/* 收起态默认向下，无需额外旋转（保持 0deg） */

/* 空内容提示 */
.empty-content {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 1rem;
  font-size: 0.9rem;
}

/* 子容器样式 */
.subcategories-container,
.groups-container {
  width: 100%;
}

/* 当分类同时包含子分类和站点时的样式优化 */
.category-content .subcategories-container + .sites-grid {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* 当分类同时包含分组和站点时的样式优化 */
.category-content .groups-container + .sites-grid {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* 子分类容器底部间距调整 */
.category-content .subcategories-container:not(:last-child),
.category-content .groups-container:not(:last-child) {
  margin-bottom: 0.6rem;
}

/* 确保嵌套的网站网格正确显示 */
.category-level-2 .sites-grid,
.group-level-3 .sites-grid,
.category-level-3 .sites-grid,
.group-level-4 .sites-grid,
.category-level-4 .sites-grid {
  margin-top: 0;
  gap: 0.75rem;
  /* 保持与顶层一致的网格布局 */
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* 响应式设计 - 嵌套结构 */
@media (max-width: 768px) {
  .category-level-2 {
    padding-left: 0.75rem;
  }

  .group-level-3,
  .category-level-3 {
    padding-left: 0.75rem;
  }

  .group-level-4,
  .category-level-4 {
    padding-left: 0.75rem;
  }

  .subcategories-container > .category-level-2 + .category-level-2 {
    margin-top: 0.8rem;
  }

  .groups-container > .group-level-3 + .group-level-3,
  .groups-container > .category-level-3 + .category-level-3 {
    margin-top: 0.7rem;
  }

  .subgroups-container > .group-level-4 + .group-level-4,
  .subcategories-container > .category-level-4 + .category-level-4 {
    margin-top: 0.55rem;
  }

  .category-level-2 .sites-grid,
  .group-level-3 .sites-grid,
  .category-level-3 .sites-grid,
  .group-level-4 .sites-grid,
  .category-level-4 .sites-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--spacing-sm);
  }
}

@media (max-width: 480px) {
  .category {
    margin-left: 0.5rem;
    margin-right: 0.5rem;
    padding: 1rem;
  }

  .category-level-2,
  .group-level-3,
  .category-level-3 {
    margin-left: 0;
    padding-left: 0.75rem;
    width: 100%;
  }

  .group-level-4,
  .category-level-4 {
    margin-left: 0;
    padding-left: 0.75rem;
    width: 100%;
  }

  .category-level-2 .sites-grid,
  .group-level-3 .sites-grid,
  .category-level-3 .sites-grid,
  .group-level-4 .sites-grid,
  .category-level-4 .sites-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }
}

/* projects：GitHub 热力图（github-calendar.js，底部展示） */
.page-template-projects .gh-heatmap-category {
  /* 外层已复用一级分类卡片（.category），这里仅保留热力图内部布局/色阶 */
  --gh-text: var(--text-color);
  --gh-text-muted: var(--text-muted);
  --gh-level-0: rgba(255, 255, 255, 0.08);
  --gh-level-1: rgba(55, 178, 77, 0.35);
  --gh-level-2: rgba(55, 178, 77, 0.55);
  --gh-level-3: rgba(55, 178, 77, 0.75);
  --gh-level-4: rgba(55, 178, 77, 0.95);
  --gh-radius: 3px;

  margin: 0 auto 1.2rem auto;
}

.page-template-projects .gh-heatmap-wrapper {
  margin-top: 0;
}

/* 浅色主题：更接近 GitHub 原色阶 */
html.theme-preload .page-template-projects .gh-heatmap-category,
body.light-theme .page-template-projects .gh-heatmap-category {
  /* 浅色主题下，空格子需要比背景更明显一点 */
  --gh-level-0: #d8dee4;
  --gh-level-1: #9be9a8;
  --gh-level-2: #40c463;
  --gh-level-3: #30a14e;
  --gh-level-4: #216e39;
}

/* 标题中的用户名（@xxx）更弱化一点，像副标题 */
.page-template-projects .gh-heatmap-username {
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 0.35rem;
}

/* 使用一级分类标题的排版节奏，略收紧热力图区域 */
.page-template-projects .gh-heatmap-category .category-header {
  margin-bottom: 0.8rem;
}

/* 标题行：左侧标题 + 右侧 legend（不占内容区高度） */
.page-template-projects .gh-heatmap-category .gh-heatmap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.page-template-projects .gh-heatmap-category .gh-heatmap-header h2 {
  margin: 0;
}

/* 让 legend 与标题体系保持一致：放在标题区右侧 */
.page-template-projects .gh-heatmap-category .gh-legend {
  justify-content: flex-end;
  margin: 0;
}

.page-template-projects .gh-header {
  display: none;
}

.page-template-projects .gh-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--gh-text-muted);
  white-space: nowrap;
}

/* heatmap：移动端标题/legend 文本简写 */
.gh-text-mobile {
  display: none;
}

@media (max-width: 480px) {
  .gh-text-desktop {
    display: none;
  }

  .gh-text-mobile {
    display: inline;
  }

  .page-template-projects .gh-heatmap-category .gh-heatmap-header {
    flex-wrap: wrap;
  }

  .page-template-projects .gh-heatmap-category .gh-legend {
    gap: 2px;
    font-size: 0.7rem;
  }

  .page-template-projects .gh-legend-item {
    width: 8px;
    height: 8px;
  }
}

.page-template-projects .gh-legend-item {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.page-template-projects .gh-legend .level-0 {
  background-color: var(--gh-level-0);
}

.page-template-projects .gh-legend .level-1 {
  background-color: var(--gh-level-1);
}

.page-template-projects .gh-legend .level-2 {
  background-color: var(--gh-level-2);
}

.page-template-projects .gh-legend .level-3 {
  background-color: var(--gh-level-3);
}

.page-template-projects .gh-legend .level-4 {
  background-color: var(--gh-level-4);
}

/* github-calendar 注入的内容容器 */
.page-template-projects .gh-calendar {
  border: none !important;
  min-height: 0;
  width: 100%;
  /* 构建期注入：避免 flex 居中导致内容超宽“撑破卡片” */
  display: block;
}

/* 顶部统计标题：XXX contributions in the last year */
.page-template-projects .gh-calendar #js-contribution-activity-description {
  /* 注意：全局 .category h2 会把 h2 设为 flex，导致“看起来左对齐”。这里强制回退为 block。 */
  display: block;
  width: 100%;
  text-align: center;
  margin: 0 0 12px 0;
}

/* 外层包裹：强制占满卡片宽度，滚动发生在内部 */
.page-template-projects .gh-calendar .graph-before-activity-overview {
  width: 100%;
}

/* 允许移动端横向滚动查看（GitHub 风格） */
.page-template-projects .gh-calendar .js-calendar-graph {
  width: 100%;
  /* 构建期注入 GitHub 原生 table：滚动交给内层容器，避免裁剪 */
  display: block;
}

/* GitHub 原生 markup：通常在 .js-calendar-graph 内有一个 div 设置 overflow-x */
.page-template-projects .gh-calendar .js-calendar-graph > div {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  /* 由 table 的 margin:auto 来实现“可居中 + 可滚动时左对齐起始列” */
  display: block;
  padding-bottom: 10px;
}

.page-template-projects .gh-calendar .js-calendar-graph-svg {
  width: 100%;
  height: auto;
}

/* 覆盖每个方块的颜色（依赖 github-calendar 的 data-level） */
.page-template-projects .gh-calendar .day {
  rx: var(--gh-radius);
  ry: var(--gh-radius);
  outline: none;
}

.page-template-projects .gh-calendar .day[data-level='0'] {
  fill: var(--gh-level-0);
}

.page-template-projects .gh-calendar .day[data-level='1'] {
  fill: var(--gh-level-1);
}

.page-template-projects .gh-calendar .day[data-level='2'] {
  fill: var(--gh-level-2);
}

.page-template-projects .gh-calendar .day[data-level='3'] {
  fill: var(--gh-level-3);
}

.page-template-projects .gh-calendar .day[data-level='4'] {
  fill: var(--gh-level-4);
}

.page-template-projects .gh-calendar text {
  fill: var(--gh-text-muted);
  font-size: 10px;
}

/* 去掉库自带 footer（更简洁） */
.page-template-projects .gh-calendar .contrib-footer {
  display: none !important;
}

.page-template-projects .gh-calendar.gh-calendar-error {
  color: var(--gh-text-muted);
  font-size: 0.85rem;
}

/* github-calendar（HTML table 版）：适配 ContributionCalendar-* 类名 */
.page-template-projects .gh-calendar table {
  /* 让热力图在卡片内尽量铺满宽度；需要时仍可横向滚动 */
  /* 关键：避免 table 按列拉伸导致 day 变成长方形 */
  display: table;
  /* 不强制占满：保持自然宽度，并在容器内居中 */
  width: max-content;
  min-width: max-content;
  max-width: none;
  table-layout: auto;
  border-collapse: separate;
  border-spacing: 5px !important;
  /* table 未超宽时居中；超宽时 margin auto 会退化为 0（滚动起始列左对齐） */
  margin: 0 auto;
}

/* GitHub 原生 table：thead 行内写死 height:15px，需强制更高以避免月份 label 压到格子 */
.page-template-projects .gh-calendar table thead tr {
  height: 20px !important;
}

/* GitHub 原生 table 的月份 label 使用 absolute 定位，需要为 thead 行预留高度，避免与格子重叠 */
.page-template-projects .gh-calendar .ContributionCalendar-label {
  height: 16px;
  position: relative;
  padding-bottom: 4px;
  font-size: 10px;
  line-height: 10px;
  font-weight: 400;
  vertical-align: bottom;
}

@media (max-width: 600px) {
  /* 移动端：格子更紧凑，减少横向滚动压力 */
  .page-template-projects .gh-calendar table {
    border-spacing: 3px !important;
  }

  .page-template-projects .gh-calendar .ContributionCalendar-day {
    width: 12px;
    height: 12px;
    min-width: 12px;
    min-height: 12px;
  }

  .page-template-projects .gh-calendar #js-contribution-activity-description {
    font-size: 0.95rem;
  }
}

/* GitHub 原生 footer：保留“Learn how we count contributions”，隐藏右侧自带 legend（避免与自定义 legend 重复） */
.page-template-projects .gh-calendar .float-right.color-fg-muted.d-flex.flex-items-center {
  display: none !important;
}

/* 按需求：去除 “Learn how we count contributions” */
.page-template-projects .gh-calendar .float-left {
  display: none !important;
}

/* Link--muted 目前不展示（float-left 已隐藏）；保留基础链接色由下方 a 规则兜底 */

.page-template-projects .gh-calendar .ContributionCalendar-day {
  /* 固定正方形，防止被 table 列宽拉伸 */
  width: 15px;
  height: 15px;
  min-width: 15px;
  min-height: 15px;
  aspect-ratio: 1 / 1;
  border-radius: var(--gh-radius);
  background-color: var(--gh-level-0);
}

.page-template-projects .gh-calendar .ContributionCalendar-day[data-level='0'] {
  background-color: var(--gh-level-0) !important;
}

.page-template-projects .gh-calendar .ContributionCalendar-day[data-level='1'] {
  background-color: var(--gh-level-1) !important;
}

.page-template-projects .gh-calendar .ContributionCalendar-day[data-level='2'] {
  background-color: var(--gh-level-2) !important;
}

.page-template-projects .gh-calendar .ContributionCalendar-day[data-level='3'] {
  background-color: var(--gh-level-3) !important;
}

.page-template-projects .gh-calendar .ContributionCalendar-day[data-level='4'] {
  background-color: var(--gh-level-4) !important;
}

/* a11y 跳转链接：视觉隐藏（保留可访问性） */
.page-template-projects .gh-calendar a[href^='#year-list'],
.page-template-projects .gh-calendar a[href*='year-list'],
.page-template-projects .gh-calendar a[href*='contributions-year'] {
  /* GitHub 注入的 "Skip to contributions year list"（常见为 show-on-focus） */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .welcome-section {
    padding: 0 var(--spacing-lg);
    margin-bottom: 2rem;
  }

  .category {
    max-width: 1100px;
    margin: 0 auto 2.5rem auto;
  }
}

@media (max-width: 768px) {
  .mobile-buttons {
    display: flex;
  }

  :root {
    /* 与移动端搜索框高度更贴合（搜索框更高一些，菜单按钮同步放大） */
    --mobile-top-button-size: 2.9rem;
  }

  .menu-toggle {
    width: var(--mobile-top-button-size);
    height: var(--mobile-top-button-size);
    background: rgba(var(--card-bg-rgb), 0.65);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 4px 16px var(--shadow-color);
  }

  /* 移动端：右下角磁贴与侧边栏按钮磁贴统一风格 */
  .theme-toggle,
  .category-toggle {
    width: var(--mobile-top-button-size);
    height: var(--mobile-top-button-size);
    background: rgba(var(--card-bg-rgb), 0.65);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 4px 16px var(--shadow-color);
    transition: all var(--transition-normal);
    transition-timing-function: var(--transition-bounce);
  }

  .theme-toggle:hover,
  .category-toggle:hover {
    transform: translateY(-2px);
    background: rgba(var(--card-bg-rgb), 0.75);
    box-shadow: 0 6px 20px var(--shadow-color);
    color: var(--accent-color);
  }

  .theme-toggle:active,
  .category-toggle:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px var(--shadow-color);
  }

  main.content {
    margin-left: 0;
    width: 100vw;
    max-width: 100vw;
    padding-top: calc(var(--spacing-md) + var(--mobile-top-button-size) + var(--spacing-sm));
    padding-top: calc(
      env(safe-area-inset-top) + var(--spacing-md) + var(--mobile-top-button-size) +
        var(--spacing-sm)
    );
    /* 缩短分类卡片与页面边缘的左右留白，扩大分类卡片可用宽度 */
    padding-left: calc(var(--spacing-sm) + var(--spacing-xs));
    padding-right: calc(var(--spacing-sm) + var(--spacing-xs));
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 100vw;
    overflow-x: hidden;
  }

  .sidebar .logo {
    padding-top: 1.5rem;
    display: flex;
    align-items: center;
    height: 60px;
  }

  /* 移动端下隐藏侧边栏折叠按钮 */
  .sidebar-toggle {
    display: none;
  }

  .sidebar.active {
    transform: translateX(0);
    box-shadow: 2px 0 10px var(--shadow-color);
    z-index: 1000;
    /* 增加侧边栏激活时的z-index，确保显示在按钮之上 */
  }

  /* 重置移动端下的侧边栏展开状态 */
  .sidebar.collapsed {
    width: var(--sidebar-width);
  }

  .sidebar.collapsed .logo h1,
  .sidebar.collapsed .nav-item .nav-text,
  .sidebar.collapsed .nav-item .external-icon {
    opacity: 1;
    transform: none;
    width: auto;
  }

  .sidebar.collapsed .sidebar-footer {
    height: auto;
    padding: 1rem 1.2rem;
    visibility: visible;
    pointer-events: auto;
    border-top: 1px solid var(--border-color);
  }

  .sidebar.collapsed .sidebar-social {
    padding: 0.2rem 1.2rem 0.8rem;
    flex-direction: row;
  }

  .sidebar.collapsed .nav-item {
    padding: 0.6rem 0.8rem;
    justify-content: flex-start;
  }

  .sidebar.collapsed .nav-item .icon-container {
    margin-right: 1rem;
  }

  /* 移动端：搜索框常驻显示（与侧边栏按钮同一行，无需“悬浮磁贴”） */
  .search-container {
    position: fixed;
    top: var(--spacing-md);
    top: calc(env(safe-area-inset-top) + var(--spacing-md));
    /* 给左侧菜单按钮留出空间 */
    left: calc(var(--spacing-md) + var(--mobile-top-button-size) + var(--spacing-sm));
    right: var(--spacing-md);
    left: calc(
      env(safe-area-inset-left) + var(--spacing-md) + var(--mobile-top-button-size) +
        var(--spacing-sm)
    );
    right: calc(env(safe-area-inset-right) + var(--spacing-md));
    width: auto;
    padding: 0;
    margin-bottom: 0;
    box-shadow: none;
    z-index: 900;
  }

  .search-box {
    max-width: 100%;
  }

  .search-box input {
    padding: 0.8rem 3rem 0.8rem 1rem;
    font-size: 0.95rem;
  }

  .search-box::after {
    right: 0.8rem;
  }

  .search-shortcut-hint {
    right: 1.2rem;
    font-size: 0.72rem;
    padding: 0.1rem 0.35rem;
  }

  .search-engine-button {
    width: 104px;
    flex: 0 0 104px;
    padding: 0 0.6rem;
  }

  .sidebar .logo h1,
  .sidebar .nav-item span {
    opacity: 1;
    display: block;
  }

  /* 欢迎区域样式 */
  .welcome-section {
    padding: 0 1rem;
    margin-top: 1rem;
    /* 增加顶部间距 */
  }

  .page {
    padding-left: 0.15rem;
    padding-right: 0.15rem;
  }

  .welcome-section h2 {
    font-size: 1.5rem;
  }

  .welcome-section h3 {
    font-size: 1rem;
    background: none;
    -webkit-background-clip: border-box;
    background-clip: border-box;
    animation: none;
    color: var(--text-muted);
  }

  /* 移动端分类切换按钮 */
  .category-toggle {
    bottom: 4rem;
    bottom: calc(env(safe-area-inset-bottom) + 4rem);
    right: 1rem;
    right: calc(env(safe-area-inset-right) + 1rem);
  }

  /* 移动端：隐藏搜索按钮（未删除，仅隐藏；搜索框常驻） */
  .search-toggle {
    display: none;
  }

  /* 分类样式优化 */
  .category {
    margin: 0 auto var(--spacing-lg) auto;
    padding: var(--spacing-md);
    width: 100%;
  }

  .sites-grid {
    gap: var(--spacing-sm);
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .site-card {
    /* 移动端保持与客户端一致：横排卡片（图标在左，文本左对齐） */
    flex-direction: row;
    align-items: center;
    text-align: left;
    padding: 0.75rem 0.65rem;
    gap: 0.6rem;
  }

  .site-card-icon {
    width: 2.2rem;
    height: 2.2rem;
  }

  .site-card .site-icon {
    font-size: 1.5rem;
  }

  .site-card .favicon-icon,
  .site-card .icon-placeholder,
  .site-card .icon-fallback,
  .site-card .icon-container {
    width: 1.5rem;
    height: 1.5rem;
  }

  .site-card .icon-placeholder,
  .site-card .icon-fallback {
    line-height: 1.5rem;
    font-size: 1.3rem;
  }

  .site-card-content {
    text-align: left;
  }

  .site-card h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .site-card p {
    font-size: 0.9rem;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* 在移动端的主题切换按钮 */
  .theme-toggle {
    bottom: 1rem;
    bottom: calc(env(safe-area-inset-bottom) + 1rem);
    right: 1rem;
    right: calc(env(safe-area-inset-right) + 1rem);
  }

  .sidebar .submenu {
    margin-left: 1rem;
  }

  .sidebar.active .submenu-item {
    padding: 0.5rem 0.6rem;
  }

  /* 确保移动设备上子菜单不会出现漏出问题 */
  .sidebar.collapsed .submenu {
    display: none;
  }
}

@media (max-width: 480px) {
  .welcome-section {
    padding: 0 1rem;
    margin-bottom: 1rem;
  }

  .category {
    margin: 0 auto 1.3rem auto;
    padding: 0.95rem;
    width: 100%;
  }

  .search-container {
    left: calc(var(--spacing-md) + var(--mobile-top-button-size) + var(--spacing-sm));
    right: var(--spacing-md);
    left: calc(
      env(safe-area-inset-left) + var(--spacing-md) + var(--mobile-top-button-size) +
        var(--spacing-sm)
    );
    right: calc(env(safe-area-inset-right) + var(--spacing-md));
  }

  .page {
    padding-top: 1rem;
    padding-left: 0.1rem;
    padding-right: 0.1rem;
  }

  .sites-grid {
    gap: 0.5rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .site-card {
    padding: 0.75rem 0.5rem;
    gap: 0.5rem;
  }

  .site-card-icon {
    width: 2rem;
    height: 2rem;
  }

  .site-card .site-icon {
    font-size: 1.3rem;
  }

  .site-card .favicon-icon,
  .site-card .icon-placeholder,
  .site-card .icon-fallback,
  .site-card .icon-container {
    width: 1.35rem;
    height: 1.35rem;
  }

  .site-card .icon-placeholder,
  .site-card .icon-fallback {
    line-height: 1.35rem;
    font-size: 1.2rem;
  }

  .site-card h3 {
    font-size: 1rem;
    margin-bottom: 0.3rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .site-card p {
    font-size: 0.9rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 400px) {
  .category {
    padding: 0.85rem;
    margin: 0 0.05rem 1.2rem 0.05rem;
    width: calc(100% - 0.1rem);
  }

  .sites-grid {
    gap: 0.4rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .site-card {
    padding: 0.6rem 0.4rem;
    gap: 0.45rem;
  }

  .site-card-icon {
    width: 1.9rem;
    height: 1.9rem;
  }

  .site-card .site-icon {
    font-size: 1.2rem;
  }

  .site-card .favicon-icon,
  .site-card .icon-placeholder,
  .site-card .icon-fallback,
  .site-card .icon-container {
    width: 1.25rem;
    height: 1.25rem;
  }

  .site-card .icon-placeholder,
  .site-card .icon-fallback {
    line-height: 1.25rem;
    font-size: 1.1rem;
  }

  .site-card h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .site-card p {
    font-size: 0.9rem;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* 搜索结果页面 */
#search-results {
  position: relative;
  width: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  /* 保持在搜索框之下，避免滚动时覆盖 sticky 的搜索容器 */
  z-index: 1;
  transform: none !important;
  /* 确保没有变换 */
  min-height: 400px;
  /* 确保最小高度，防止内容过少时的布局跳动 */
}

#search-results.active {
  display: flex;
  animation: fadeIn 0.3s ease-out forwards;
}

/* 搜索结果区域 */
.search-section {
  width: 100%;
  max-width: var(--page-max-width);
  margin: 0 auto 2.5rem auto;
  position: relative;
  z-index: 1;
  transform: none !important;
  opacity: 1 !important;
}

/* 确保搜索结果中的网格有正确的间距 */
.search-section .sites-grid {
  margin-top: 1rem;
}

/* 搜索结果页：按来源页面复用对应网格规则（方案 2：复用原卡片 DOM） */
#search-results [data-section='projects'] .sites-grid {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

#search-results [data-section='articles'] .sites-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1024px) {
  #search-results [data-section='articles'] .sites-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

@media (max-width: 480px) {
  #search-results [data-section='articles'] .sites-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }
}

/* 确保搜索结果中的卡片样式一致 */
.search-section .site-card {
  max-width: 100%;
}

/* 加载中动画 */
.page {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.page.active {
  opacity: 1;
}

/* 模态框动画 */
@keyframes modalFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modalContentShow {
  from {
    opacity: 0;
    transform: scale(0.9);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.sites-grid {
  transition: gap 0.3s ease;
}

/* 侧边栏底部：社交图标（位于 sidebar-footer 上方） */
.sidebar-social {
  grid-area: social;
  padding: 0.2rem 1.2rem 0.8rem;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.9rem;
}

.social-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  border-radius: var(--radius-full);
  color: var(--nav-item-color);
  text-decoration: none;
  transition:
    color var(--transition-fast),
    transform var(--transition-fast);
}

.social-icon:hover {
  color: var(--accent-color);
  transform: translateY(-1px);
}

.social-icon:active {
  transform: translateY(0);
}

.social-icon:focus-visible {
  outline: 2px solid rgba(118, 148, 185, 0.35);
  outline-offset: 2px;
}

.social-icon i {
  width: auto;
  font-size: 1.2rem;
}

/* 侧边栏底部：版权信息 */
.sidebar-footer {
  grid-area: footer;
  padding: 1rem 1.2rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border-color);
  background-color: var(--sidebar-bg);
  /* 使用变量 */
  transition:
    background-color 0.3s ease,
    color 0.3s ease,
    opacity 0.3s ease;
}

.sidebar-footer .copyright {
  margin: 0;
}

.sidebar.collapsed .sidebar-social {
  padding: 0.2rem 0.5rem 0.8rem;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.copyright a {
  color: var(--accent-color);
  text-decoration: none;
  transition: all 0.3s ease;
}

.copyright a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* 导航项包装器 - 包含导航项和子菜单 */
.nav-item-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* 子菜单容器 */
.submenu {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  margin-left: 1.5rem;
  opacity: 0;
  visibility: hidden;
}

/* 子菜单展开状态 */
.nav-item-wrapper.expanded .submenu {
  max-height: none;
  overflow: visible;
  opacity: 1;
  visibility: visible;
}
