/**
 * 尘渊文化 - 主题与深色模式样式
 * @version 1.0.0
 */

/* ========== CSS变量定义 ========== */
:root {
  /* 浅色主题 (默认) */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-tertiary: #94a3b8;
  --border-color: #e2e8f0;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --overlay-bg: rgba(15, 23, 42, 0.8);
  
  /* 强调色 (保持不变) */
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --secondary: #0ea5e9;
  --accent: #8b5cf6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
}

/* 深色主题 */
[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-tertiary: #94a3b8;
  --border-color: #334155;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --overlay-bg: rgba(0, 0, 0, 0.9);
}

/* 系统偏好自动切换 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --border-color: #334155;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --overlay-bg: rgba(0, 0, 0, 0.9);
  }
}

/* ========== 深色模式特定样式 ========== */
[data-theme="dark"] body {
  background: var(--bg-primary);
  color: var(--text-primary);
}

[data-theme="dark"] .navbar.scrolled {
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid var(--border-color);
}

[data-theme="dark"] .tech-card,
[data-theme="dark"] .area-card,
[data-theme="dark"] .resource-card,
[data-theme="dark"] .demo-card,
[data-theme="dark"] .algo-card,
[data-theme="dark"] .app-card,
[data-theme="dark"] .repo-card,
[data-theme="dark"] .career-card,
[data-theme="dark"] .timeline-node,
[data-theme="dark"] .usecase-card,
[data-theme="dark"] .cap-card,
[data-theme="dark"] .tool-category,
[data-theme="dark"] .metric-card,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .lab-stat {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
}

[data-theme="dark"] .section {
  background: var(--bg-primary) !important;
}

[data-theme="dark"] .section:nth-child(even) {
  background: var(--bg-secondary) !important;
}

[data-theme="dark"] .footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
}

[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-color);
}

[data-theme="dark"] .sidebar {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
}

[data-theme="dark"] .content-area,
[data-theme="dark"] .tutorial-content,
[data-theme="dark"] .playground-panel {
  background: var(--bg-secondary);
}

[data-theme="dark"] .toc-sidebar {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
}

[data-theme="dark"] .prerequisites-box,
[data-theme="dark"] .research-areas,
[data-theme="dark"] .playground-section,
[data-theme="dark"] .tool-ecosystem,
[data-theme="dark"] .demo-showcase {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .nav-btn {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

[data-theme="dark"] .nav-btn:hover {
  background: var(--primary);
}

[data-theme="dark"] .category-list a:hover,
[data-theme="dark"] .category-list a.active {
  background: var(--bg-tertiary);
}

/* ========== 主题切换按钮 ========== */
.theme-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
  z-index: 1000;
  transition: all 0.3s ease;
}

.theme-toggle:hover {
  transform: translateY(-3px) rotate(15deg);
  box-shadow: 0 8px 30px rgba(99, 102, 241, 0.5);
}

.theme-toggle:active {
  transform: scale(0.95);
}

/* 隐藏/显示图标 */
.theme-toggle .sun-icon,
[data-theme="dark"] .theme-toggle .moon-icon {
  display: none;
}

.theme-toggle .moon-icon,
[data-theme="dark"] .theme-toggle .sun-icon {
  display: block;
}

/* ========== 面包屑导航 ========== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.breadcrumb a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

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

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

.breadcrumb-current {
  color: var(--text-primary);
  font-weight: 500;
}

/* ========== 搜索组件 ========== */
.search-container {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  padding: 16px 24px 16px 50px;
  border: 2px solid var(--border-color);
  border-radius: 50px;
  font-size: 1rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: all 0.3s;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.search-icon {
  position: absolute;
  left: 20px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 20px;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

.search-input:not(:placeholder-shown) + .search-clear {
  opacity: 1;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 10px 40px var(--shadow-color);
  max-height: 400px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.2s;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item:focus {
  background: var(--bg-secondary);
}

.search-result-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.search-result-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.search-result-category {
  display: inline-block;
  padding: 2px 8px;
  background: var(--primary);
  color: white;
  border-radius: 12px;
  font-size: 0.75rem;
  margin-top: 8px;
}

/* ========== 图片懒加载占位 ========== */
.lazy-image {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-secondary) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.lazy-image.loaded {
  animation: none;
  background: transparent;
}

/* ========== 增强焦点样式 ========== */
*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
  :root {
    --primary: #4f46e5;
    --text-primary: #000000;
    --text-secondary: #333333;
  }
  
  [data-theme="dark"] {
    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
  }
}

/* 减少动画偏好支持 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .lazy-image {
    animation: none;
  }
}

/* ========== 打印样式优化 ========== */
@media print {
  .theme-toggle,
  .navbar,
  .footer,
  .breadcrumb {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  .section {
    background: white !important;
    page-break-inside: avoid;
  }
}
