/* ========== CSS 变量 ========== */
:root {
  --bg: #fafafa;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.1);
  --radius: 14px;
  --radius-sm: 8px;
  --transition: all 0.2s ease;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-card: #141414;
  --bg-elevated: #1a1a1a;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --border: #262626;
  --border-hover: #404040;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-light: #1e1b4b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
               sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.3s, color 0.3s;
  min-height: 100vh;
}

/* ========== 头部 ========== */
.header {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
  color: white;
  padding: 1.5rem 1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

[data-theme="dark"] .header {
  background: linear-gradient(135deg, #4338ca 0%, #6d28d9 50%, #be185d 100%);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 2rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.logo-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-subtitle {
  font-size: 0.75rem;
  opacity: 0.85;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.icon-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: rgba(255,255,255,0.25);
  transform: scale(1.05);
}

.icon-btn:active {
  transform: scale(0.95);
}

.refresh-icon.spinning {
  animation: spin 1s linear infinite;
}

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

/* 统计卡片 */
.stats-bar {
  max-width: 1100px;
  margin: 1.25rem auto 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.stat-item {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  backdrop-filter: blur(10px);
}

.stat-icon {
  font-size: 1.4rem;
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.7rem;
  opacity: 0.85;
  margin-top: 2px;
}

/* ========== 主体 ========== */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ========== 控件区 ========== */
.controls {
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 0.75rem;
  transition: var(--transition);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.search-icon {
  font-size: 1rem;
  margin-right: 0.5rem;
  opacity: 0.5;
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 0.75rem 0;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

.search-box input::placeholder {
  color: var(--text-light);
}

.clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
  display: none;
}

.clear-btn.visible {
  display: block;
}

.clear-btn:hover { color: var(--danger); }

.filter-chips {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.chip-count {
  background: rgba(255,255,255,0.25);
  padding: 0.05rem 0.4rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
}

.chip:not(.active) .chip-count {
  background: var(--accent-light);
  color: var(--accent);
}

.sort-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.sort-label {
  color: var(--text-muted);
}

.sort-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  transition: var(--transition);
}

.sort-btn:hover { color: var(--text); border-color: var(--border-hover); }
.sort-btn.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* ========== 文章网格 ========== */
.feed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
  animation: fadeIn 0.3s ease-out backwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--accent);
  transform: scaleY(0);
  transform-origin: top;
  transition: transform 0.2s ease;
}

.card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.card:hover::before {
  transform: scaleY(1);
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  gap: 0.5rem;
}

.card-source {
  background: var(--accent-light);
  color: var(--accent);
  padding: 0.15rem 0.55rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 65%;
}

.card-date {
  white-space: nowrap;
  font-size: 0.72rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: -0.01em;
}

.card-title a {
  color: var(--text);
  text-decoration: none;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color 0.2s;
}

.card-title a:hover {
  color: var(--accent);
}

.card-summary {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.card-author {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.card-arrow {
  color: var(--accent);
  font-size: 1.1rem;
  transition: transform 0.2s;
}

.card:hover .card-arrow {
  transform: translateX(3px);
}

/* ========== 加载状态 ========== */
.loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

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

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

/* ========== 页脚 ========== */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.footer p { margin: 0.25rem 0; }

.footer-links a {
  color: var(--accent);
  text-decoration: none;
}

.footer-links a:hover { text-decoration: underline; }

.footer-links span {
  margin: 0 0.5rem;
  color: var(--text-light);
}

/* ========== 返回顶部 ========== */
.back-to-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.3rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: var(--transition);
  z-index: 50;
}

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

.back-to-top:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

/* ========== 响应式 ========== */
@media (max-width: 640px) {
  .header { padding: 1rem 0.75rem 1.25rem; }
  .logo-title { font-size: 1.15rem; }
  .logo-subtitle { font-size: 0.7rem; }
  .stats-bar { gap: 0.5rem; }
  .stat-item { padding: 0.6rem; }
  .stat-value { font-size: 0.9rem; }
  .stat-label { font-size: 0.65rem; }
  .container { padding: 1rem 0.75rem 2rem; }
  .feed-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  .card { padding: 1rem; }
  .card-title { font-size: 0.95rem; }
}

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* 选中文本 */
::selection {
  background: var(--accent);
  color: white;
}
