:root {
  --bg: #f5f5f5;
  --bg-card: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #666;
  --border: #e0e0e0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --tag-news: #ef4444;
  --tag-tech: #8b5cf6;
  --tag-ai: #06b6d4;
  --tag-learning: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --text: #e5e5e5;
  --text-secondary: #999;
  --border: #333;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Header */
header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1rem;
}

/* Date navigation */
.date-nav {
  max-width: 960px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.date-nav button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.9rem;
}

.date-nav button:hover { border-color: var(--accent); }

#date-picker {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

/* Category tabs */
.category-tabs {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px 10px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.tab {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.tab:hover { border-color: var(--accent); color: var(--accent); }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Main content */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  min-height: 60vh;
}

.loading, .empty {
  text-align: center;
  padding: 60px 16px;
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Source group */
.source-group {
  margin-bottom: 24px;
  scroll-margin-top: 160px;
}

.source-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
}

.source-name {
  font-weight: 600;
  font-size: 1rem;
}

.category-tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  color: #fff;
  font-weight: 500;
}

.category-tag.news { background: var(--tag-news); }
.category-tag.tech { background: var(--tag-tech); }
.category-tag.ai { background: var(--tag-ai); }
.category-tag.learning { background: var(--tag-learning); }

.article-count {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-left: auto;
}

/* Article card */
.article-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 8px;
  transition: box-shadow 0.2s;
}

.source-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--border);
  color: var(--text-secondary);
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.article-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

.article-card a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  line-height: 1.5;
  display: block;
  padding-right: 80px;
}

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

.article-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.article-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* Collapse toggle */
.collapse-toggle {
  display: block;
  width: 100%;
  padding: 8px;
  margin-top: 4px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  text-align: center;
  transition: background 0.2s;
}

.collapse-toggle:hover {
  background: var(--bg-card);
  border-color: var(--accent);
}

.source-group .article-card.collapsed {
  display: none;
}

/* Source header clickable */
.source-header {
  cursor: pointer;
  user-select: none;
}

.source-header:hover {
  opacity: 0.8;
}

.collapse-icon {
  font-size: 0.75rem;
  transition: transform 0.2s;
}

.collapse-icon.collapsed {
  transform: rotate(-90deg);
}

/* Footer */
footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

#stats {
  margin-bottom: 8px;
}

/* Side navigation */
.side-nav {
  position: fixed;
  right: 16px;
  bottom: 80px;
  z-index: 99;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-height: calc(100vh - 160px);
}

.side-nav-list {
  list-style: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px 0;
  max-height: calc(100vh - 240px);
  overflow-y: auto;
  scrollbar-width: thin;
}

.side-nav-list li {
  padding: 0;
}

.side-nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.2s, background 0.2s;
}

.side-nav-link:hover {
  color: var(--accent);
  background: var(--bg);
}

.side-nav-link.active {
  color: #fff;
  background: var(--accent);
  font-weight: 600;
  border-radius: 4px;
  margin: 2px 6px;
  padding: 4px 10px;
}

.side-nav-link.active .side-nav-count {
  background: rgba(255,255,255,0.25);
  color: #fff;
}

.side-nav-count {
  font-size: 0.65rem;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  background: var(--border);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.back-to-top {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, background 0.2s;
  flex-shrink: 0;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

.back-to-top:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Responsive */
@media (max-width: 640px) {
  h1 { font-size: 1.1rem; }
  .article-card { padding: 10px 12px; }
  .category-tabs { padding: 0 12px 8px; }

  .side-nav-list { display: none; }
  .side-nav { bottom: 24px; right: 12px; }
}
