/* ═══════════════════════════════════════════════════════════════════════════
   The Feed — CSS Design System
   Dark theme, card-based layout, clean & scannable
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Reset & Base ─────────────────────────────────────────────────────────── */

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

:root {
  /* Background layers */
  --bg-primary: #0f1117;
  --bg-secondary: #161822;
  --bg-card: #1c1f2e;
  --bg-card-hover: #232639;

  /* Text */
  --text-primary: #e8e9ed;
  --text-secondary: #9a9caa;
  /* #6b6d7b read at 3.19:1 on cards — below the 4.5:1 WCAG AA minimum for body
     text. This clears it on every surface it lands on. The binding constraint
     is the hover card (#232639), the lightest of them: timestamps stay muted
     while the card lightens underneath them.
     hover 4.53:1 · card 4.97:1 · page 5.73:1 · count pill 5.12:1 */
  --text-muted: #8b8d9b;

  /* Accents */
  --accent-blue: #5b8af5;
  --accent-purple: #a78bfa;
  --accent-green: #34d399;
  --accent-orange: #fb923c;
  --accent-red: #f87171;
  --accent-pink: #f472b6;
  --accent-cyan: #22d3ee;
  --accent-yellow: #fbbf24;

  /* Category colors */
  /* Nudged up from #5b8af5, which hit only 4.03:1 against its own 15% badge
     tint. The other five categories already cleared 4.5:1. */
  --cat-news: #6796ff;
  --cat-local: #34d399;
  --cat-sports: #fb923c;
  --cat-reddit: #f87171;
  --cat-video: #f472b6;
  --cat-more: #a78bfa;

  /* Borders & effects */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.1);
  /* High-contrast against both the page and card backgrounds so the keyboard
     focus ring is unmistakable wherever it lands. */
  --focus-ring: #ffd166;
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-card-hover: 0 8px 24px rgba(0, 0, 0, 0.4);
  --glow-card-hover: 0 0 20px rgba(91, 138, 245, 0.08);

  /* Layout */
  --max-width: 1280px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ─── Focus Visibility ─────────────────────────────────────────────────────────
   WCAG 2.4.7. :focus-visible rather than :focus so the ring appears for
   keyboard and assistive-tech users without firing on mouse clicks. The
   default UA ring is nearly invisible against this dark palette. */

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Cards are large targets — offset inward so the ring isn't clipped by the
   neighbouring grid cell, and lift the card so the ring is never overlapped. */
.feed-card:focus-visible {
  outline-offset: -3px;
  border-color: var(--focus-ring);
  position: relative;
  z-index: 1;
}

/* Forced-colors (Windows High Contrast) ignores custom colours entirely, so
   defer to the system highlight rather than fighting it. */
@media (forced-colors: active) {
  :focus-visible {
    outline: 3px solid Highlight;
  }
}

/* ─── Header ───────────────────────────────────────────────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.site-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.title-icon {
  -webkit-text-fill-color: initial;
  font-size: 1.4rem;
}

.site-tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
  letter-spacing: 0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.last-updated {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ─── Region Picker ────────────────────────────────────────────────────────── */

.region-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.2);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.region-picker:hover {
  background: rgba(52, 211, 153, 0.16);
  border-color: rgba(52, 211, 153, 0.35);
}

.region-picker-label {
  font-size: 0.8rem;
  line-height: 1;
}

.region-picker select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  color: var(--cat-local);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  padding-right: 2px;
  max-width: 15ch;
  text-overflow: ellipsis;
}

/* The dropdown list itself renders in the OS palette, so force dark there. */
.region-picker select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* The select has no border of its own, so put the ring on the wrapper to keep
   it clear of the 📍 glyph. Suppressing the select's own ring is gated behind
   :has() support — without it the wrapper rule never fires, and the select
   must keep the ring it inherits from the global :focus-visible rule. */
@supports selector(:has(*)) {
  .region-picker:has(select:focus-visible) {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
  }

  .region-picker select:focus-visible {
    outline: none;
  }
}

.refresh-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(91, 138, 245, 0.12);
  color: var(--accent-blue);
  border: 1px solid rgba(91, 138, 245, 0.2);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.refresh-btn:hover {
  background: rgba(91, 138, 245, 0.2);
  border-color: rgba(91, 138, 245, 0.35);
  transform: translateY(-1px);
}

.refresh-btn:active {
  transform: translateY(0);
}

.refresh-btn.loading .refresh-icon {
  animation: spin 0.8s linear infinite;
}

.refresh-icon {
  transition: transform var(--transition-fast);
}

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

/* ─── Main Content ─────────────────────────────────────────────────────────── */

.main-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 32px 24px;
  min-height: calc(100vh - 160px);
}

/* ─── Loading State ────────────────────────────────────────────────────────── */

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 20px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ─── Error State ──────────────────────────────────────────────────────────── */

.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 12px;
}

.error-icon {
  font-size: 2.5rem;
}

.error-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* ─── Status Banner ────────────────────────────────────────────────────────── */

.status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  padding: 12px 16px;
  background: rgba(251, 146, 60, 0.1);
  border: 1px solid rgba(251, 146, 60, 0.22);
  border-radius: var(--radius-sm);
  color: var(--accent-orange);
  font-size: 0.82rem;
  line-height: 1.5;
}

.status-banner-icon {
  flex-shrink: 0;
  font-size: 0.95rem;
}

/* ─── Feed Container ───────────────────────────────────────────────────────── */

.feed-container {
  display: flex;
  flex-direction: column;
  gap: 40px;
}

/* ─── Category Section ─────────────────────────────────────────────────────── */

.category-section {
  animation: fadeInUp var(--transition-slow) both;
}

.category-section:nth-child(1) { animation-delay: 0ms; }
.category-section:nth-child(2) { animation-delay: 80ms; }
.category-section:nth-child(3) { animation-delay: 160ms; }
.category-section:nth-child(4) { animation-delay: 240ms; }
.category-section:nth-child(5) { animation-delay: 320ms; }
.category-section:nth-child(6) { animation-delay: 400ms; }

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

.category-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.category-emoji {
  font-size: 1.3rem;
}

.category-title {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.category-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 8px;
  border-radius: 10px;
}

/* Category accent colors */
.category-section[data-category="news"] .category-title { color: var(--cat-news); }
.category-section[data-category="local"] .category-title { color: var(--cat-local); }
.category-section[data-category="sports"] .category-title { color: var(--cat-sports); }
.category-section[data-category="reddit"] .category-title { color: var(--cat-reddit); }
.category-section[data-category="video"] .category-title { color: var(--cat-video); }
.category-section[data-category="more"] .category-title { color: var(--cat-more); }

/* ─── Card Grid ────────────────────────────────────────────────────────────── */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

/* ─── Feed Card ────────────────────────────────────────────────────────────── */

.feed-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all var(--transition-normal);
  cursor: pointer;
}

.feed-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-card-hover), var(--glow-card-hover);
  transform: translateY(-2px);
}

.feed-card:active {
  transform: translateY(0);
}

.card-image {
  width: 100%;
  height: 180px;
  object-fit: cover;
  background: var(--bg-secondary);
}

.card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.source-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

/* Source badge colors by category */
.source-badge[data-category="news"]   { background: rgba(91, 138, 245, 0.15); color: var(--cat-news); }
.source-badge[data-category="local"]  { background: rgba(52, 211, 153, 0.15); color: var(--cat-local); }
.source-badge[data-category="sports"] { background: rgba(251, 146, 60, 0.15); color: var(--cat-sports); }
.source-badge[data-category="reddit"] { background: rgba(248, 113, 113, 0.15); color: var(--cat-reddit); }
.source-badge[data-category="video"]  { background: rgba(244, 114, 182, 0.15); color: var(--cat-video); }
.source-badge[data-category="more"]   { background: rgba(167, 139, 250, 0.15); color: var(--cat-more); }

.card-timestamp {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  /* Clamp to 3 lines */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-summary {
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--text-secondary);
  /* Clamp to 2 lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: auto;
  padding-top: 8px;
  transition: color var(--transition-fast);
}

.feed-card:hover .card-link {
  color: var(--accent-blue);
}

.card-link-arrow {
  transition: transform var(--transition-fast);
}

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

/* ─── Footer ───────────────────────────────────────────────────────────────── */

.site-footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 24px 40px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
}

/* ─── Utilities ────────────────────────────────────────────────────────────── */

.hidden {
  display: none !important;
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

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

  .main-content {
    padding: 20px 16px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 480px) {
  .card-image {
    height: 140px;
  }

  .card-body {
    padding: 12px;
  }
}

/* ─── Skeleton Loading (for individual cards) ──────────────────────────────── */

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-card) 25%,
    var(--bg-card-hover) 50%,
    var(--bg-card) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

.skeleton-card {
  height: 200px;
  border-radius: var(--radius-md);
}

/* ─── Scrollbar ────────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}
