/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: #f5f5f5;
  color: #333;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 18px;
}

/* Header */
header {
  background: #f9f9f9;
  border-bottom: 1px solid #e0e0e0;
  padding: 16px 0;
  margin-bottom: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
}

.header-meta {
  min-width: 0;
}

.header-title {
  font-size: 0.95rem;
  color: #777;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  line-height: 1.2;
}

.header-subtext {
  font-size: 0.8rem;
  color: #999;
  margin: 4px 0 0;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  line-height: 1.2;
}

.version-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
  font-size: 0.65rem;
  color: #999;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  justify-self: end;
}

.theme-label {
  font-size: 0.8rem;
  color: #999;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.theme-select {
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  padding: 6px 10px;
  background: #f5f5f5;
  color: #999;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.4px;
}

/* Main content */
main {
  flex: 1;
  padding: 18px 0 0;
}

/* Loading state */
.loading {
  text-align: center;
  padding: 60px 20px;
  font-size: 1.1rem;
  color: #666;
}

.loading::after {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-left: 10px;
  border: 3px solid #e0e0e0;
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

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

/* Error state */
.error {
  background: #fee;
  border: 1px solid #fcc;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  color: #c33;
}

/* News feed — Masonry.js handles layout */
.news-feed {
  margin-bottom: 16px;
  transition: opacity 0.2s ease;
}

#load-more-sentinel {
  height: 1px;
  width: 100%;
}

/* Fade during Masonry recalculation */
.news-feed.masonry-recalc {
  opacity: 0;
}

/* Hidden sizer tells Masonry the column width */
.news-feed-sizer {
  width: calc(25% - 12px); /* (100% − 3×16px) ÷ 4 columns */
}

.day-group-item {
  width: calc(25% - 12px);
  margin-bottom: 16px;
}

.day-group-item .news-card {
  width: 100%;
  margin-bottom: 0;
}

/* Day dividers */
.day-divider {
  width: 100%;
  margin: 0 0 16px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  min-height: 56px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.day-divider-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  white-space: nowrap;
  padding: 0 10px;
}

/* Card styles */
.news-card {
  width: calc(25% - 12px); /* matches .news-feed-sizer */
  background: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition:
    box-shadow 0.3s ease,
    opacity 0.3s ease;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  margin-bottom: 16px;
}

.news-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.news-card:active {
  opacity: 0.95;
}

/* Card content */
.news-card-content {
  padding: 14px;
  display: flex;
  flex-direction: column;
}

.news-card-source {
  font-size: 0.85rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  font-weight: 600;
}

.news-card-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 10px;
  line-height: 1.4;
  color: #222;
}

.news-card-summary {
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 12px;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: break-word;
  word-break: normal;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.news-card-meta {
  font-size: 0.8rem;
  color: #aaa;
  padding-top: 12px;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.news-card-date {
  display: block;
}

.news-card-link {
  display: inline-block;
  margin-top: 12px;
  padding: 8px 16px;
  background: #667eea;
  color: white;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.3s ease;
  align-self: flex-start;
}

.news-card-link:hover {
  background: #764ba2;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: #999;
}

.empty-state h2 {
  font-size: 1.5rem;
  margin-bottom: 10px;
  color: #666;
}

/* Footer */
footer {
  background: #f9f9f9;
  border-top: 1px solid #e0e0e0;
  padding: 16px 0;
  margin-top: auto;
  text-align: center;
}

.footer-subtext {
  font-size: 0.8rem;
  color: #999;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin: 0;
}

/* Responsive design */
@media (max-width: 1100px) {
  /* 3 columns at ≤ 1100px */
  .news-feed-sizer,
  .day-group-item,
  .news-card {
    width: calc(33.333% - 10.667px);
  }
}

@media (max-width: 768px) {
  /* 2 columns at ≤ 768px */
  .news-feed-sizer,
  .day-group-item,
  .news-card {
    width: calc(50% - 8px);
  }

  .day-divider-label {
    font-size: 0.8rem;
  }

  .news-card-content {
    padding: 12px;
  }

  .news-card-title {
    font-size: 1.1rem;
  }

  .news-card-summary {
    font-size: 0.9rem;
    -webkit-line-clamp: 2;
  }
}

@media (max-width: 480px) {
  /* 1 column at ≤ 480px */
  .news-feed-sizer,
  .day-group-item,
  .news-card {
    width: 100%;
  }

  .container {
    padding: 0 15px;
  }

  header {
    padding: 16px 0;
    margin-bottom: 0;
  }

  .header-controls {
    gap: 6px;
  }

  .header-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
  }

  .header-title {
    font-size: 0.88rem;
  }

  .header-subtext {
    font-size: 0.72rem;
  }

  .theme-select {
    padding: 8px 10px;
    font-size: 0.85rem;
  }

  .news-card-title {
    font-size: 1rem;
  }

  main {
    min-height: auto;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  body {
    background-color: #1a1a1a;
    color: #e0e0e0;
  }

  .header-title,
  .header-subtext {
    color: #777;
  }

  header {
    background: #252525;
    border-bottom-color: #333;
  }

  .theme-label {
    color: #777;
  }

  .theme-select {
    background: #1a1a1a;
    color: #ddd;
    border-color: #333;
  }

  .news-card {
    background: #2a2a2a;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }

  .news-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  }

  .news-card-title {
    color: #f0f0f0;
  }

  .news-card-summary {
    color: #b0b0b0;
  }

  footer {
    background: #252525;
    border-top-color: #333;
  }

  .footer-subtext {
    color: #777;
  }

  .header-text {
    color: #777;
  }

  .error {
    background: #3a2020;
    border-color: #664444;
    color: #ff9999;
  }

  .empty-state h2 {
    color: #aaa;
  }

  .day-divider {
    background: #1a1a1a;
    border-color: #333;
    box-shadow: none;
  }

  .day-divider-label {
    color: #777;
  }
}

/* Explicit dark theme override (dropdown selection) */
:root[data-theme='dark'] body {
  background-color: #1a1a1a;
  color: #e0e0e0;
}

:root[data-theme='dark'] header {
  background: #252525;
  border-bottom-color: #333;
}

:root[data-theme='dark'] .header-title,
:root[data-theme='dark'] .header-subtext,
:root[data-theme='dark'] .theme-label,
:root[data-theme='dark'] .footer-subtext,
:root[data-theme='dark'] .day-divider-label {
  color: #777;
}

:root[data-theme='dark'] .theme-select {
  background: #1a1a1a;
  color: #ddd;
  border-color: #333;
}

:root[data-theme='dark'] .news-card {
  background: #2a2a2a;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

:root[data-theme='dark'] .news-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

:root[data-theme='dark'] .news-card-title {
  color: #f0f0f0;
}

:root[data-theme='dark'] .news-card-summary {
  color: #b0b0b0;
}

:root[data-theme='dark'] footer {
  background: #252525;
  border-top-color: #333;
}

:root[data-theme='dark'] .error {
  background: #3a2020;
  border-color: #664444;
  color: #ff9999;
}

:root[data-theme='dark'] .empty-state h2 {
  color: #aaa;
}

:root[data-theme='dark'] .day-divider {
  background: #1a1a1a;
  border-color: #333;
  box-shadow: none;
}

/* Explicit light theme override (dropdown selection) */
:root[data-theme='light'] body {
  background-color: #f5f5f5;
  color: #333;
}

:root[data-theme='light'] header {
  background: #f9f9f9;
  border-bottom-color: #e0e0e0;
}

:root[data-theme='light'] .header-title,
:root[data-theme='light'] .header-subtext,
:root[data-theme='light'] .theme-label,
:root[data-theme='light'] .footer-subtext,
:root[data-theme='light'] .day-divider-label {
  color: #999;
}

:root[data-theme='light'] .theme-select {
  background: #f5f5f5;
  color: #999;
  border-color: #e5e5e5;
}

:root[data-theme='light'] .news-card {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

:root[data-theme='light'] .news-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

:root[data-theme='light'] .news-card-title {
  color: #222;
}

:root[data-theme='light'] .news-card-summary {
  color: #555;
}

:root[data-theme='light'] footer {
  background: #f9f9f9;
  border-top-color: #e0e0e0;
}

:root[data-theme='light'] .error {
  background: #fee;
  border-color: #fcc;
  color: #c33;
}

:root[data-theme='light'] .empty-state h2 {
  color: #666;
}

:root[data-theme='light'] .day-divider {
  background: #f5f5f5;
  border-color: #e5e5e5;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}
