/* ============================================
   长生造物 — 主题样式表
   设计系统：极简 / 明暗双主题 / CSS 变量驱动
   ============================================ */

/* === 明色主题（默认） === */
:root {
  /* 背景 */
  --bg: #ffffff;
  --bg-secondary: #f7f8fa;
  --bg-card: #ffffff;
  --bg-hover: #f3f4f6;

  /* 文字 */
  --text-primary: #1a1a1a;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;

  /* 边框与分隔线 */
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  /* 强调色 */
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #dbeafe;

  /* 阴影 */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);

  /* 圆角 */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* 过渡 */
  --transition: 0.2s ease;
}

/* === 暗色主题 === */
[data-theme="dark"] {
  --bg: #0f1117;
  --bg-secondary: #141620;
  --bg-card: #16182a;
  --bg-hover: #1e2036;

  --text-primary: #e5e7eb;
  --text-secondary: #9ca3af;
  --text-tertiary: #6b7280;

  --border: #282c44;
  --border-strong: #3a4060;

  --accent: #80b3f7;
  --accent-hover: #a3c8ff;
  --accent-light: #1e3050;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* === 基础重置 === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition), color var(--transition);
  min-height: 100vh;
  min-height: 100dvh;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
  background-color: var(--bg-secondary);
  object-fit: cover;
  /* U2：图片加载淡入 */
  opacity: 0;
  animation: imgFadeIn 0.35s ease forwards;
}

@keyframes imgFadeIn {
  to { opacity: 1; }
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input {
  font-family: inherit;
  font-size: inherit;
  border: none;
  outline: none;
}

/* === 顶部导航栏 === */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  /* U1：半透明模糊背景，内容隐约透出 */
  background-color: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.navbar.scrolled {
  border-bottom-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.navbar__brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
}

.navbar__links {
  display: flex;
  gap: 24px;
  align-items: center;
}

.navbar__link {
  font-size: 14px;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.navbar__link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.navbar__link--active {
  color: var(--accent);
  font-weight: 600;
}

/* === 主题切换按钮 === */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-secondary);
  transition: background-color var(--transition);
}

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

.theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: var(--text-primary);
  transition: transform var(--transition);
}

.theme-toggle:hover svg {
  transform: rotate(15deg);
}

/* === 面包屑 === */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.breadcrumb a {
  color: var(--accent);
}

.breadcrumb span {
  color: var(--text-tertiary);
}

/* === 返回顶部 === */
.back-top {
  position: fixed;
  bottom: 32px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  z-index: 50;
}

.back-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-top:hover {
  background-color: var(--bg-hover);
}

/* === P2：返回顶部滚动进度环 === */
.back-top__progress {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  pointer-events: none;
}

.back-top__progress circle {
  stroke: var(--accent);
  stroke-dasharray: 113;
  stroke-dashoffset: 113;
  transition: stroke-dashoffset 0.1s ease;
  opacity: 0;
}

.back-top.visible .back-top__progress circle {
  opacity: 0.35;
}

.back-top__arrow {
  width: 18px;
  height: 18px;
  stroke: var(--text-primary);
}

/* === 页脚 === */
.footer {
  text-align: center;
  padding: 32px 24px;
  font-size: 13px;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border);
}

/* === A3 页脚链接 hover 下划线动画 === */
.footer a {
  color: var(--text-secondary);
  background-image: linear-gradient(var(--accent), var(--accent));
  background-size: 0% 1px;
  background-repeat: no-repeat;
  background-position: 50% 100%;
  transition: color var(--transition), background-size 0.2s ease;
  padding-bottom: 1px;
}

.footer a:hover {
  color: var(--accent);
  background-size: 100% 1px;
}

/* === 通用容器 === */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

/* === 空状态 === */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* === 加载失败 === */
.error-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-secondary);
}

.error-state button {
  margin-top: 16px;
  padding: 8px 24px;
  border-radius: var(--radius-sm);
  background-color: var(--accent);
  color: #ffffff;
  font-size: 14px;
  transition: background-color var(--transition);
}

.error-state button:hover {
  background-color: var(--accent-hover);
}

/* === 加载动画 === */
.page-loader {
  display: none;
  justify-content: center;
  align-items: center;
  padding: 80px 24px;
}

/* 骨架屏模式下的 page-loader（由 JS 切换为 display:grid） */
.page-loader[style*="grid"] {
  justify-content: unset;
  align-items: unset;
  gap: 20px;
  grid-template-columns: repeat(4, 1fr);
  padding: 0;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 1279px) {
  .page-loader[style*="grid"] { grid-template-columns: repeat(3, 1fr); gap: 16px; }
}

@media (max-width: 767px) {
  .page-loader[style*="grid"] { grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 0 12px; }
}

@media (max-width: 639px) {
  .page-loader[style*="grid"] { grid-template-columns: 1fr; }
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === 主题切换图标 === */
.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  display: none;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 明色模式显示太阳（提示可切暗色） */
[data-theme="light"] .theme-toggle .icon-sun { display: block; }
/* 暗色模式显示月亮（提示可切明色） */
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* === 版本历史最新版 === */
.version-item--latest {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  background-color: var(--accent-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.version-item--latest .version-item__badge {
  display: inline-block;
  margin-left: 8px;
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 10px;
  background-color: var(--accent);
  color: #fff;
  font-weight: 500;
  vertical-align: middle;
}

/* === 搜索栏容器 === */

/* 桌面端 ≥ 1280px */
@media (min-width: 1280px) {
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

/* 平板 768px – 1279px */
@media (min-width: 768px) and (max-width: 1279px) {
  .grid-4 { grid-template-columns: repeat(3, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

/* 小平板 640px – 767px */
@media (min-width: 640px) and (max-width: 767px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* 手机端 < 640px */
@media (max-width: 639px) {
  .grid-4 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }

  .navbar {
    height: 56px;
    padding: 0 16px;
  }

  .navbar__brand {
    font-size: 16px;
  }

  .navbar__links {
    gap: 16px;
  }

  .navbar__link {
    font-size: 13px;
  }
}

/* ============================================
   V1 Hero 视觉锚点：底部极细分隔线
   ============================================ */
.hero::after {
  content: '';
  display: block;
  width: 60px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  margin: 28px auto 0;
  opacity: 0.6;
  border-radius: 1px;
}

/* ============================================
   V5 主题切换过渡：平滑颜色变化
   ============================================ */
body {
  transition: background-color 0.35s ease, color 0.35s ease;
}
.theme-toggle svg {
  transition: transform 0.4s ease;
}

/* ============================================
   V2 骨架屏：加载时的占位卡片
   ============================================ */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-hover) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-lg);
  height: 140px;
}

.skeleton-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.skeleton-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.skeleton-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.skeleton-name {
  width: 60%;
  height: 16px;
  border-radius: 4px;
}

.skeleton-version {
  width: 30%;
  height: 12px;
  border-radius: 4px;
  margin-top: 4px;
}

.skeleton-desc {
  width: 100%;
  height: 13px;
  border-radius: 4px;
}

.skeleton-desc-short {
  width: 70%;
  height: 13px;
  border-radius: 4px;
  margin-top: 4px;
}

.skeleton-tags {
  display: flex;
  gap: 4px;
  margin-top: auto;
}

.skeleton-tag {
  width: 40px;
  height: 18px;
  border-radius: 10px;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
  body {
    transition: none;
  }
  img {
    animation: none;
    opacity: 1;
  }
  .app-card {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
  .app-grid {
    transition: none !important;
  }
}

/* ============================================
   V4 卡片交错淡入动画
   ============================================ */
@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.app-card--animate {
  animation: cardFadeIn 0.25s ease forwards;
}

/* ============================================
   V3 分类切换过渡：卡片容器淡出淡入
   ============================================ */
.app-grid {
  transition: opacity 0.2s ease;
}

.app-grid.fade-out {
  opacity: 0;
}

/* ============================================
   U3 详情页头部层次感
   ============================================ */
.detail-header {
  position: relative;
  padding-bottom: 24px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.detail-header::before {
  content: '';
  position: absolute;
  inset: -16px -24px -24px;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, transparent 100%);
  border-radius: var(--radius-md);
  z-index: -1;
  opacity: 0.5;
}

/* ============================================
   U4 Tab 激活圆点指示器
   ============================================ */
.tab {
  position: relative;
}

.tab--active::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: var(--accent);
  display: block;
}

@media (max-width: 639px) {
  .tab--active::after {
    bottom: -4px;
  }
}

/* ============================================
   U5 图标容器内描边
   ============================================ */
.app-card__icon,
.detail-header__icon {
  box-shadow: inset 0 0 0 1px var(--border);
}

/* ============================================
   P5 详情页标题视觉锚点
   ============================================ */
.section-title {
  position: relative;
  padding-left: 14px;
}

.section-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  border-radius: 2px;
  background-color: var(--accent);
}

/* ============================================
   P3 详情页板块交错淡入
   ============================================ */
.detail-main > * {
  opacity: 0;
  transform: translateY(12px);
  animation: sectionFadeIn 0.4s ease forwards;
}

.detail-main > :nth-child(1) { animation-delay: 0ms; }
.detail-main > :nth-child(2) { animation-delay: 80ms; }
.detail-main > :nth-child(3) { animation-delay: 160ms; }
.detail-main > :nth-child(4) { animation-delay: 240ms; }
.detail-main > :nth-child(5) { animation-delay: 320ms; }
.detail-main > :nth-child(6) { animation-delay: 400ms; }

@keyframes sectionFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   T1 搜索结果计数
   ============================================ */
.tabs-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.result-count {
  font-size: 13px;
  color: var(--text-tertiary);
  height: 0;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.25s ease, height 0.25s ease, padding 0.25s ease;
  padding: 0;
}

.result-count.visible {
  height: 24px;
  opacity: 1;
  padding: 4px 0 0;
}

@media (max-width: 639px) {
  .tabs-wrap { padding: 0 16px; }
}

/* ============================================
   T2 手机端 Tab 横滚渐隐提示
   ============================================ */
.tabs {
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
}

@media (min-width: 1280px) {
  .tabs {
    -webkit-mask-image: none;
    mask-image: none;
  }
}

/* ============================================
   T5 Tab 栏搜索时平滑收起
   ============================================ */
.tabs-wrap {
  transition: opacity 0.25s ease, transform 0.25s ease, max-height 0.25s ease;
  overflow: hidden;
}

.tabs-wrap.hidden {
  opacity: 0;
  transform: translateY(-8px);
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
}
