/* ===== Theme Variables ===== */
:root {
  --bg-page: #f4f1ec;
  --bg-card: #ffffff;
  --bg-card-hover: #fafaf8;
  --bg-trending: #fffdf7;
  --bg-trending-border: #e0d8c8;
  --bg-header: #ffffff;
  --text-primary: #2c2c2c;
  --text-secondary: #6b6b6b;
  --text-heading: #1a1a1a;
  --text-link: #2d5a9e;
  --text-link-hover: #1a3d6e;
  --accent: #2d5a9e;
  --border: #ddd8ce;
  --border-card: #d8d2c4;
  --heat-high: #c2590a;
  --heat-high-bg: rgba(194, 89, 10, 0.08);
  --heat-med: #8a7520;
  --heat-med-bg: rgba(138, 117, 32, 0.08);
  --badge-bg: #eee9df;
  --badge-text: #6b6050;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-card-hover: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-trending: 0 2px 8px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  --radius: 10px;
  --section-label-bg: #e8e3d9;
  --section-label-text: #5a5345;
  --notice-bg: rgba(194, 89, 10, 0.06);
  --notice-border: rgba(194, 89, 10, 0.15);
  --toggle-bg: #e0dbd0;
  --toggle-icon: "☀️";
}

[data-theme="dark"] {
  --bg-page: #111318;
  --bg-card: #1a1d24;
  --bg-card-hover: #22252e;
  --bg-trending: #1c1f2a;
  --bg-trending-border: #2e3348;
  --bg-header: #15171d;
  --text-primary: #c8c8d0;
  --text-secondary: #7e7e8a;
  --text-heading: #e4e4ec;
  --text-link: #8aabe0;
  --text-link-hover: #b0c8f0;
  --accent: #8aabe0;
  --border: #282a35;
  --border-card: #2a2d3a;
  --heat-high: #d4923a;
  --heat-high-bg: rgba(212, 146, 58, 0.1);
  --heat-med: #a09530;
  --heat-med-bg: rgba(160, 149, 48, 0.1);
  --badge-bg: #252838;
  --badge-text: #8a8a98;
  --shadow-card: 0 1px 4px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-card-hover: 0 4px 16px rgba(0,0,0,0.4), 0 2px 6px rgba(0,0,0,0.25);
  --shadow-trending: 0 2px 10px rgba(0,0,0,0.35), 0 1px 4px rgba(0,0,0,0.2);
  --radius: 10px;
  --section-label-bg: #1e2130;
  --section-label-text: #8888a0;
  --notice-bg: rgba(212, 146, 58, 0.06);
  --notice-border: rgba(212, 146, 58, 0.18);
  --toggle-bg: #282a35;
  --toggle-icon: "🌙";
}

/* ===== Reset ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ===== Body ===== */
body {
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 1.125rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

/* ===== Header ===== */
.site-header {
  background: var(--bg-header);
  border-bottom: 2px solid var(--border);
  padding: 1.5rem 2rem 1.25rem;
  max-width: 820px;
  margin: 0 auto;
  transition: background 0.3s, border-color 0.3s;
}

.header-content {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.site-title {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-heading);
  letter-spacing: -0.02em;
  transition: color 0.3s;
}

.last-updated {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.theme-toggle {
  background: var(--toggle-bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background 0.3s, border-color 0.3s;
}

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

.source-notice {
  margin-top: 0.75rem;
  padding: 0.5rem 0.85rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.85rem;
  color: var(--heat-high);
  background: var(--notice-bg);
  border: 1px solid var(--notice-border);
  border-radius: 6px;
  transition: background 0.3s, border-color 0.3s, color 0.3s;
}

/* ===== Main Content ===== */
main {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 2rem 4rem;
}

/* ===== Category Sections ===== */
.category-section {
  padding-top: 2.5rem;
}

.category-section:first-child {
  padding-top: 2rem;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.section-label {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--section-label-text);
  background: var(--section-label-bg);
  padding: 0.3rem 0.85rem;
  border-radius: 4px;
  white-space: nowrap;
  transition: background 0.3s, color 0.3s;
}

.section-rule {
  flex: 1;
  height: 1px;
  background: var(--border);
  transition: background 0.3s;
}

/* ===== Trending Cards ===== */
.trending-group {
  margin-bottom: 1.5rem;
}

.subsection-label {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 0.85rem;
}

.trending-card {
  background: var(--bg-trending);
  border: 1px solid var(--bg-trending-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-trending);
  transition: background 0.3s, border-color 0.3s, box-shadow 0.3s, transform 0.15s;
}

.trending-card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-1px);
}

.trending-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.heat-badge {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.heat-high {
  color: var(--heat-high);
  background: var(--heat-high-bg);
}

.heat-med {
  color: var(--heat-med);
  background: var(--heat-med-bg);
}

.trending-topic-summary {
  font-style: italic;
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 0.85rem;
  line-height: 1.5;
}

.trending-lead-title {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.45rem;
}

.trending-lead-title a {
  color: var(--text-heading);
  text-decoration: none;
  transition: color 0.15s;
}

.trending-lead-title a:hover {
  color: var(--text-link-hover);
}

.trending-lead-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  flex-wrap: wrap;
}

.trending-lead-summary {
  font-size: 1.05rem;
  color: var(--text-primary);
  line-height: 1.65;
  margin-bottom: 0.85rem;
}

.related-toggle {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.85rem;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.3rem 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: color 0.15s;
}

.related-toggle:hover {
  color: var(--text-link-hover);
}

.related-toggle .arrow {
  font-size: 0.65rem;
  transition: transform 0.2s;
  display: inline-block;
}

.related-toggle.open .arrow {
  transform: rotate(90deg);
}

.related-list {
  display: none;
  margin-top: 0.75rem;
  padding-left: 0.2rem;
  border-left: 2px solid var(--bg-trending-border);
}

.related-list.open {
  display: block;
}

.related-item {
  padding: 0.4rem 0 0.4rem 0.85rem;
}

.related-item a {
  font-size: 0.95rem;
  color: var(--text-link);
  text-decoration: none;
  transition: color 0.15s;
}

.related-item a:hover {
  color: var(--text-link-hover);
  text-decoration: underline;
}

.related-item .source-badge {
  margin-left: 0.5rem;
}

/* ===== Article Cards ===== */
.articles-group {
  margin-bottom: 1rem;
}

.article-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow-card);
  transition: background 0.3s, border-color 0.3s, box-shadow 0.2s, transform 0.15s;
}

.article-card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-1px);
}

.article-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 0.35rem;
}

.article-title a {
  color: var(--text-heading);
  text-decoration: none;
  transition: color 0.15s;
}

.article-title a:hover {
  color: var(--text-link-hover);
}

.article-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  flex-wrap: wrap;
}

.article-summary {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ===== Shared ===== */
.source-badge {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: var(--badge-bg);
  color: var(--badge-text);
  white-space: nowrap;
  transition: background 0.3s, color 0.3s;
}

.time-ago {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* ===== Header Buttons ===== */
.header-btn {
  background: var(--toggle-bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.3s, border-color 0.3s;
  color: var(--text-secondary);
}

.header-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.header-btn-icon {
  line-height: 1;
}

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

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

/* ===== Progress Bar ===== */
.progress-bar {
  margin-top: 0.75rem;
  position: relative;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.4s ease, background 0.3s;
}

.progress-fill.error {
  background: var(--heat-high);
}

.progress-label {
  position: absolute;
  top: 8px;
  left: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ===== Settings Panel ===== */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s;
}

.settings-overlay.open {
  opacity: 1;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 90vw;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index: 101;
  transform: translateX(100%);
  transition: transform 0.25s ease, background 0.3s, border-color 0.3s;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-header h2 {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-heading);
}

.settings-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
  padding: 0.25rem;
}

.settings-close:hover {
  color: var(--text-primary);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
}

.settings-section {
  margin-bottom: 1.75rem;
}

.settings-section-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--section-label-text);
  margin-bottom: 0.85rem;
}

/* ===== Source Toggle Rows ===== */
.source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
}

.source-row:last-child {
  border-bottom: none;
}

.source-info {
  flex: 1;
  min-width: 0;
}

.source-name {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.source-detail {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.source-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1rem;
  padding: 0.2rem;
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.15s, color 0.15s;
}

.source-remove:hover {
  opacity: 1;
  color: var(--heat-high);
}

/* ===== CSS Toggle Switch ===== */
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

/* ===== Add Source Form ===== */
.add-source-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.add-source-form input {
  flex: 1;
  min-width: 120px;
  padding: 0.4rem 0.65rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-page);
  color: var(--text-primary);
  transition: border-color 0.15s;
}

.add-source-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.add-source-form button {
  padding: 0.4rem 0.85rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}

.add-source-form button:hover {
  opacity: 0.85;
}

/* ===== Category Reorder ===== */
.reorder-list {
  list-style: none;
}

.reorder-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.35rem;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: grab;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.9rem;
  color: var(--text-primary);
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}

.reorder-item:active {
  cursor: grabbing;
}

.reorder-item.drag-over {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.drag-handle {
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: grab;
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
  font-size: 1rem;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  body {
    font-size: 1.05rem;
  }

  .site-header {
    padding: 1.25rem 1.25rem 1rem;
  }

  .header-content {
    flex-direction: column;
    gap: 0.5rem;
  }

  .header-right {
    justify-content: space-between;
    width: 100%;
  }

  .site-title {
    font-size: 1.65rem;
  }

  main {
    padding: 0 1.25rem 3rem;
  }

  .trending-card {
    padding: 1.15rem;
  }

  .trending-lead-title {
    font-size: 1.2rem;
  }

  .article-card {
    padding: 1rem 1.15rem;
  }

  .settings-panel {
    width: 100%;
    max-width: 100vw;
  }
}
