/* main.css - externalized core styles, shared list styles, and skeletons */
:root {
  /* Light mode colors */
  --primary: #2c3e50;
  --secondary: #34495e;
  --accent: #3498db;
  --success: #27ae60;
  --warning: #f39c12;
  --background: #f8f9fa;
  --surface: #ffffff;
  --text-primary: #2c3e50;
  --text-secondary: #6c757d;
  --border-light: #e9ecef;
  --shadow-light: rgba(0, 0, 0, 0.05);
  --shadow-medium: rgba(0, 0, 0, 0.1);
}

/* Dark mode colors */
[data-theme="dark"] {
  --primary: #3498db;
  --secondary: #2980b9;
  --accent: #e74c3c;
  --success: #2ecc71;
  --warning: #f39c12;
  --background: #1a1a1a;
  --surface: #2d2d2d;
  --text-primary: #ecf0f1;
  --text-secondary: #bdc3c7;
  --border-light: #404040;
  --shadow-light: rgba(0, 0, 0, 0.2);
  --shadow-medium: rgba(0, 0, 0, 0.3);
}

/* Set dark mode as default */
:root {
  color-scheme: dark;
}

html {
  background: var(--background);
  transition: background-color 0.3s ease;
}

body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: color 0.3s ease;
}

/* 重置默认margin，避免浏览器默认样式干扰 */
h1, h2, h3, h4, h5, h6, p {
  margin: 0;
  padding: 0;
}

/* Skeletons */
.skeleton { background: linear-gradient(90deg, #e9ecef, #f8f9fa, #e9ecef); background-size:200% 100%; animation: sk 1.2s infinite; height: 16px; border-radius: 4px; }
@keyframes sk { 0%{background-position: 200% 0} 100%{background-position: -200% 0} }

/* Shared resource list styles (match category pages) */
.resource-table {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px var(--shadow-light);
  border: 1px solid var(--border-light);
}
.table-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-light);
  align-items: center;
  background: var(--surface);
  transition: background-color 0.2s ease;
}
.table-row:hover {
  background: var(--background);
}
.col-title { display: flex; flex-direction: column; gap: 2px; }
.col-links { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.resource-title { font-weight: 600; color: var(--text-primary); font-size: 0.85rem; line-height: 1.2; }
.resource-category-inline { color: var(--text-secondary); font-weight: normal; font-size: 0.7rem; }

.link-btn {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  background: var(--success);
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px var(--shadow-light);
  min-width: 0;
  white-space: nowrap;
  border: none;
}
.link-btn:hover {
  background: #219a52;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px var(--shadow-medium);
}

/* Responsive tweaks to match category pages */
@media (max-width: 768px) {
  .table-row {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 8px 12px;
  }
  .col-links {
    justify-content: flex-start;
    gap: 4px;
  }
  .link-btn {
    padding: 6px 10px;
    font-size: 0.75rem;
    min-width: 60px;
    justify-content: center;
  }
  .container {
    padding: 10px;
  }
  .header {
    padding: 12px;
    margin-bottom: 12px;
  }
  .header h1 {
    font-size: 1.4rem;
    margin: 0 0 4px 0;
  }
  .header p {
    font-size: 0.9rem;
    line-height: 1.3;
    margin: 0;
  }
  .card {
    padding: 12px;
    margin-bottom: 16px;
  }
  .category-card {
    padding: 12px;
  }
  .category-card h3 {
    font-size: 1.0rem;
    margin-bottom: 6px;
  }
  .category-card p {
    font-size: 0.8rem;
    margin-bottom: 10px;
    line-height: 1.3;
    /* 在移动端限制描述文字行数 */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .category-card .card-footer {
    margin-top: 10px;
    padding-top: 8px;
  }
  .category-card .resource-count {
    font-size: 0.75rem;
  }
  .category-card .arrow {
    font-size: 1.0rem;
  }
  .table-header {
    padding: 6px 12px;
    font-size: 0.75rem;
  }
  .hot-resources-title {
    font-size: 1.2rem;
    margin-bottom: 12px;
  }
}

/* 超小屏幕优化 (小于480px) */
@media (max-width: 480px) {
  .header {
    padding: 10px;
    margin-bottom: 10px;
  }
  .header h1 {
    font-size: 1.2rem;
    margin: 0 0 3px 0;
  }
  .header p {
    font-size: 0.85rem;
    margin: 0;
    line-height: 1.2;
  }
  .container {
    padding: 10px;
  }
  .grid {
    gap: 8px;
  }
  .category-card {
    padding: 10px;
  }
  .category-card h3 {
    font-size: 0.9rem;
    margin-bottom: 4px;
  }
  .category-card p {
    font-size: 0.75rem;
    margin-bottom: 8px;
    -webkit-line-clamp: 1; /* 超小屏幕只显示1行描述 */
  }
  .card {
    padding: 10px;
    margin-bottom: 12px;
  }
}

/* Global layout styles */
html { background: var(--background); min-height: 100%; }
body {
  background: var(--background);
  min-height: 100vh;
  line-height: 1.6;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  margin: 0;
  padding: 0;
}
.container { max-width: 1200px; margin: 0 auto; padding: 12px; }

.header {
  background: var(--surface);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px var(--shadow-light);
  border: 1px solid var(--border-light);
  text-align: center;
}
.header h1 {
  font-size: 2.5rem;
  color: var(--primary);
  margin: 0 0 8px 0;
  font-weight: 700;
}
.header p {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin: 0;
}

.card {
  background: var(--surface);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 2px 8px var(--shadow-light);
  border: 1px solid var(--border-light);
  margin-bottom: 20px;
  transition: box-shadow 0.2s ease;
}
.card:hover {
  box-shadow: 0 4px 12px var(--shadow-medium);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

/* 移动端网格布局优化 - 提高特异性 */
@media (max-width: 768px) {
  .container .grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
}

@media (max-width: 480px) {
  .container .grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
}

.category-card {
  background: var(--surface);
  border-radius: 8px;
  padding: 12px;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: all 0.2s ease;
  border: 1px solid var(--border-light);
  box-shadow: 0 2px 8px var(--shadow-light);
  position: relative;
}
.category-card::before {
  content:'';
  position:absolute;
  top:0;
  left:0;
  right:0;
  height:3px;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 0.2s ease;
}
.category-card:hover::before { transform: scaleX(1); }
.category-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px var(--shadow-medium);
  text-decoration:none;
  color:inherit;
}
.category-card h3 {
  font-size: 1.3rem;
  margin-bottom: 12px;
  color: var(--text-primary);
  font-weight: 600;
}
.category-card p {
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}
.category-card .card-footer {
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-top:20px;
  padding-top:16px;
  border-top:1px solid var(--border-light);
}
.category-card .resource-count {
  color: var(--text-secondary);
  font-size:0.9rem;
}
.category-card .arrow {
  color: var(--accent);
  font-size:1.2rem;
  transition: transform 0.2s ease;
}
.category-card:hover .arrow { transform: translateX(4px); }

.btn {
  display:inline-block;
  padding:12px 24px;
  background: var(--primary);
  color:white;
  text-decoration:none;
  border-radius:6px;
  border:none;
  cursor:pointer;
  transition: all 0.2s ease;
  font-weight:500;
  box-shadow:0 2px 4px var(--shadow-light);
  font-size: 0.9rem;
}
.btn:hover {
  background: var(--secondary);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--shadow-medium);
}
.btn-success {
  background: var(--success);
  box-shadow: 0 2px 4px var(--shadow-light);
}
.btn-success:hover {
  background: #219a52;
  box-shadow: 0 4px 8px var(--shadow-medium);
}
.back-btn {
  background: var(--text-secondary);
  color: white;
  padding:10px 20px;
  text-decoration:none;
  border-radius:6px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.back-btn:hover {
  background: var(--primary);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px var(--shadow-medium);
}

/* 黑夜模式下的返回按钮特殊处理 */
[data-theme="dark"] .back-btn {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

[data-theme="dark"] .back-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.subcategory-nav {
  background: var(--surface);
  padding:20px;
  border-radius:8px;
  margin-bottom:24px;
  border:1px solid var(--border-light);
  box-shadow: 0 2px 4px var(--shadow-light);
}
.subcategory-nav a {
  display:inline-block;
  margin:4px 8px 4px 0;
  padding:8px 16px;
  background: var(--surface);
  color: var(--text-primary);
  text-decoration:none;
  border-radius:20px;
  font-size:14px;
  transition: all 0.2s ease;
  border:1px solid var(--border-light);
}
.subcategory-nav a:hover, .subcategory-nav a.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* 黑夜模式下子分类的特殊处理 */
[data-theme="dark"] .subcategory-nav a {
  background: var(--background);
  color: var(--text-secondary);
  border-color: var(--border-light);
}

[data-theme="dark"] .subcategory-nav a:hover,
[data-theme="dark"] .subcategory-nav a.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* 合并到header中的子分类导航 */
.header-subcategory-nav {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.header-subcategory-nav a {
  display: inline-block;
  margin: 4px 8px 4px 0;
  padding: 6px 12px;
  background: var(--surface);
  color: var(--text-primary);
  text-decoration: none;
  border-radius: 16px;
  font-size: 13px;
  transition: all 0.2s ease;
  border: 1px solid var(--border-light);
}

.header-subcategory-nav a:hover,
.header-subcategory-nav a.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* 黑夜模式下header内子分类的特殊处理 */
[data-theme="dark"] .header-subcategory-nav a {
  background: var(--background);
  color: var(--text-secondary);
  border-color: var(--border-light);
}

[data-theme="dark"] .header-subcategory-nav a:hover,
[data-theme="dark"] .header-subcategory-nav a.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* 移动端优化 */
@media (max-width: 768px) {
  .header-subcategory-nav {
    margin-top: 12px;
    padding-top: 12px;
  }

  .header-subcategory-nav a {
    padding: 5px 10px;
    font-size: 12px;
    margin: 3px 6px 3px 0;
  }
}

@media (max-width: 480px) {
  .header-subcategory-nav {
    margin-top: 10px;
    padding-top: 10px;
  }

  .header-subcategory-nav a {
    padding: 4px 8px;
    font-size: 11px;
    margin: 2px 4px 2px 0;
  }
}

footer {
  text-align:center;
  margin-top:12px;
  padding:12px;
  background: var(--surface);
  border-radius:8px;
  color: var(--text-secondary);
  border:1px solid var(--border-light);
  box-shadow: 0 2px 4px var(--shadow-light);
}

/* Category-page specific styles moved from inline */
.table-header {
  display:grid;
  grid-template-columns: 2fr 1fr;
  gap:12px;
  padding:8px 16px;
  background: var(--primary);
  color:#fff;
  font-weight:600;
  font-size:0.8rem;
}
.resource-category {
  font-size:0.8rem;
  color: var(--accent);
  background: rgba(52, 152, 219, 0.1);
  padding:4px 8px;
  border-radius:12px;
  display:inline-block;
  width:fit-content;
  border: 1px solid rgba(52, 152, 219, 0.2);
}
.link-btn:active { transform: translateY(0); }

/* Different cloud colors */
.link-btn[href*="baidu"] { background: #1976d2; }
.link-btn[href*="baidu"]:hover { background: #1565c0; }
.link-btn[href*="aliyun"] { background: #ff9800; }
.link-btn[href*="aliyun"]:hover { background: #f57c00; }
.link-btn[href*="189"] { background: #9c27b0; }
.link-btn[href*="189"]:hover { background: #7b1fa2; }

/* Loading spinner + load more button */
.loading-spinner {
  width:32px;
  height:32px;
  border:3px solid var(--border-light);
  border-top:3px solid var(--accent);
  border-radius:50%;
  animation: spin 1s linear infinite;
  margin:0 auto 16px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

#load-more-btn .btn {
  background: var(--accent);
  color:#fff;
  border:none;
  padding:12px 32px;
  border-radius:6px;
  cursor:pointer;
  font-size:16px;
  transition: all 0.2s ease;
}
#load-more-btn .btn:hover {
  background: #2980b9;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--shadow-medium);
}
#load-more-btn .btn:disabled {
  opacity:0.6;
  cursor:not-allowed;
  transform:none;
}

/* Back to top button */
.back-to-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 2px 8px var(--shadow-medium);
  transition: all 0.3s ease;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  z-index: 1000;
  user-select: none;
  white-space: nowrap;
}

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

.back-to-top:hover {
  background: var(--secondary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow-medium);
}

.back-to-top:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px var(--shadow-medium);
}

/* 移动端适配 */
@media (max-width: 768px) {
  .back-to-top {
    bottom: 20px;
    right: 20px;
    padding: 10px 14px;
    font-size: 13px;
  }
}

/* 新增实用样式 */
.resource-stats {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px var(--shadow-light);
}

.resource-stats .stat-item {
  text-align: center;
}

.resource-stats .stat-number {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--primary);
  display: block;
}

.resource-stats .stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.search-box {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 24px;
  box-shadow: 0 2px 4px var(--shadow-light);
}

.search-box input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  font-size: 1rem;
  transition: border-color 0.2s ease;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* 热门资源标签 */
.hot-badge {
  background: var(--warning);
  color: white;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 8px;
  font-weight: 500;
}

/* 热门资源标题 */
.hot-resources-title {
  margin-bottom: 20px;
  color: var(--text-primary);
  font-size: 1.5rem;
  font-weight: 600;
}

/* 黑夜模式下热门资源标题特殊处理 */
[data-theme="dark"] .hot-resources-title {
  color: var(--text-primary);
}

/* 资源类型图标 */
.resource-type-icon {
  width: 20px;
  height: 20px;
  margin-right: 8px;
  opacity: 0.7;
}

/* 主题切换按钮 */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow-medium);
  transition: all 0.3s ease;
  z-index: 1001;
  font-size: 20px;
}

.theme-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px var(--shadow-medium);
}

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

/* 主题图标 */
.theme-icon {
  transition: opacity 0.3s ease;
}

[data-theme="dark"] .theme-toggle .sun-icon {
  opacity: 1;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  opacity: 0;
}

[data-theme="light"] .theme-toggle .sun-icon {
  opacity: 0;
}

[data-theme="light"] .theme-toggle .moon-icon {
  opacity: 1;
}

.theme-toggle .theme-icon {
  position: absolute;
}

/* 移动端主题按钮调整 */
@media (max-width: 768px) {
  .theme-toggle {
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
}
