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

:root {
  --bg: #000008;
  --panel-bg: rgba(4,6,22,0.94);
  --border: rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.15);
  --text-primary: rgba(255,255,255,0.88);
  --text-secondary: rgba(255,255,255,0.50);
  --text-muted: rgba(255,255,255,0.30);
  --accent: rgba(80,130,255,1);
}

html, body {
  width: 100%; min-height: 100%;
  background: var(--bg);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text-primary);
  overflow-x: hidden;
}

#app { position: relative; min-height: 100vh; }

/* ── Starfield ───────────────────────────────────────────────────────────────── */
#starfield {
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none;
}

/* ── Loading ─────────────────────────────────────────────────────────────────── */
#loading {
  position: fixed; inset: 0; z-index: 300;
  background: #000008;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  transition: opacity 0.45s;
}
#loading.fade-out { opacity: 0; pointer-events: none; }
#loading.hidden { display: none; }

#loading-text {
  font-size: 0.94rem; letter-spacing: 0.38em; text-transform: uppercase;
  color: rgba(255,255,255,0.32);
}
#loading-sub {
  font-size: 0.78rem; letter-spacing: 0.12em;
  color: rgba(255,255,255,0.16);
}
#loading-bar-wrap {
  width: 220px; height: 2px;
  background: rgba(255,255,255,0.06); border-radius: 1px;
}
#loading-bar {
  height: 100%; border-radius: 1px;
  background: rgba(160,200,255,0.55);
  width: 0%; transition: width 0.35s ease;
}

/* ── Header ──────────────────────────────────────────────────────────────────── */
#header {
  position: fixed; top: 44px; left: 0; right: 0; z-index: 20;
  background: linear-gradient(to bottom, rgba(0,0,10,0.96) 0%, rgba(0,0,10,0.88) 100%);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px 12px;
}

#header-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}

#brand { display: flex; align-items: center; gap: 12px; }

#brand h1 {
  font-size: 1.28rem; font-weight: 300;
  letter-spacing: 0.46em; text-transform: uppercase;
  color: rgba(255,255,255,0.75);
}
#brand h1 span { color: rgba(160,200,255,0.6); font-weight: 200; }

#live-badge {
  font-size: 0.70rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: rgba(74,222,128,0.82);
  background: rgba(74,222,128,0.08);
  border: 1px solid rgba(74,222,128,0.22);
  padding: 2px 8px; border-radius: 10px;
  animation: pulse-badge 2.4s ease-in-out infinite;
}
@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

#header-actions { display: flex; align-items: center; gap: 10px; }

#article-count {
  font-size: 0.78rem; color: var(--text-muted); letter-spacing: 0.08em;
}

/* ── Pill / filter buttons ───────────────────────────────────────────────────── */
.pill-btn {
  padding: 5px 14px; border-radius: 22px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.13);
  color: rgba(255,255,255,0.45);
  cursor: pointer; font-size: 0.88rem; font-weight: 500;
  letter-spacing: 0.08em; font-family: inherit;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  white-space: nowrap;
}
.pill-btn:hover:not(:disabled) {
  background: rgba(255,255,255,0.10);
  border-color: rgba(255,255,255,0.28);
  color: rgba(255,255,255,0.82);
}
.pill-btn:disabled { opacity: 0.4; cursor: default; }

#source-filters { display: flex; gap: 7px; flex-wrap: wrap; }

.filter-btn {
  padding: 4px 13px; border-radius: 20px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
  color: rgba(255,255,255,0.38);
  cursor: pointer; font-size: 0.82rem; font-weight: 500;
  letter-spacing: 0.10em; font-family: inherit;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  white-space: nowrap;
}
.filter-btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.22);
  color: rgba(255,255,255,0.72);
}
.filter-btn.active {
  background: rgba(var(--source-rgb, 80,130,255), 0.12);
  border-color: rgba(var(--source-rgb, 80,130,255), 0.45);
  color: var(--source-color, rgba(140,185,255,0.9));
}

/* ── Main content ────────────────────────────────────────────────────────────── */
#main {
  position: relative; z-index: 1;
  padding-top: 168px;
  min-height: 100vh;
}

/* ── Article grid ────────────────────────────────────────────────────────────── */
#article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 15px;
  padding: 22px 24px 40px;
  max-width: 1700px;
  margin: 0 auto;
}

/* ── Article cards ───────────────────────────────────────────────────────────── */
.article-card {
  background: rgba(4,6,22,0.70);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  display: flex; flex-direction: column;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: transform 0.22s cubic-bezier(0.4,0,0.2,1),
              border-color 0.22s,
              background 0.22s,
              box-shadow 0.22s;
}
.article-card:hover {
  transform: translateY(-4px);
  border-color: rgba(var(--source-rgb, 80,130,255), 0.28);
  background: rgba(4,6,22,0.88);
  box-shadow: 0 10px 36px rgba(0,0,0,0.55),
              0 0 0 1px rgba(var(--source-rgb, 80,130,255), 0.06);
}

.card-img-wrap {
  width: 100%; height: 172px; overflow: hidden; flex-shrink: 0;
  background: rgba(4,6,22,0.5);
}
.card-img-wrap img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 0.4s ease;
  display: block;
}
.article-card:hover .card-img-wrap img { transform: scale(1.04); }

.card-img-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg,
    rgba(var(--source-rgb, 30,40,80), 0.18) 0%,
    rgba(0,0,10,0.55) 100%);
  font-size: 2.6rem; opacity: 0.45;
  user-select: none;
}

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

.source-badge {
  display: inline-block; align-self: flex-start;
  padding: 2px 9px; border-radius: 10px;
  font-size: 0.69rem; letter-spacing: 0.15em; text-transform: uppercase;
  font-weight: 600; margin-bottom: 9px;
  border: 1px solid rgba(var(--source-rgb, 80,130,255), 0.35);
  background: rgba(var(--source-rgb, 80,130,255), 0.10);
  color: var(--source-color, rgba(140,185,255,0.9));
}

.card-title {
  font-size: 1.00rem; font-weight: 400; line-height: 1.45;
  color: var(--text-primary); margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-excerpt {
  font-size: 0.86rem; line-height: 1.62;
  color: rgba(255,255,255,0.37);
  margin-bottom: 12px; flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: 0.75rem; color: var(--text-muted);
  letter-spacing: 0.06em;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ── Empty state ─────────────────────────────────────────────────────────────── */
#empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; min-height: 40vh;
  color: var(--text-muted);
}
#empty-state.hidden { display: none; }
#empty-icon { font-size: 3rem; }
#empty-text {
  font-size: 0.92rem; letter-spacing: 0.22em; text-transform: uppercase;
}

/* ── Detail overlay ──────────────────────────────────────────────────────────── */
#detail-overlay {
  position: fixed; inset: 0; z-index: 25;
  background: rgba(0,0,0,0.48);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.35s;
}
#detail-overlay.visible { opacity: 1; pointer-events: auto; }

/* ── Detail panel ────────────────────────────────────────────────────────────── */
#detail-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
  width: 840px;
  background: rgba(4,6,22,0.97);
  border-left: 1px solid rgba(255,255,255,0.08);
  -webkit-backdrop-filter: blur(30px);
  backdrop-filter: blur(30px);
  overflow-y: auto;
  padding: 54px 28px 60px;
  transform: translateX(100%) translateZ(0);
  transition: transform 0.40s cubic-bezier(0.4,0,0.2,1);
}
#detail-panel.visible { transform: translateX(0) translateZ(0); }

#detail-panel::-webkit-scrollbar { width: 3px; }
#detail-panel::-webkit-scrollbar-track { background: transparent; }
#detail-panel::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.10); border-radius: 2px;
}

#detail-close {
  position: absolute; top: 16px; right: 16px;
  background: none; border: none;
  color: rgba(255,255,255,0.32);
  width: 32px; height: 32px; border-radius: 50%;
  cursor: pointer; font-size: 1.18rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.2s, background 0.2s;
}
#detail-close:hover {
  color: rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.08);
}

.detail-color-bar {
  height: 2px; border-radius: 1px;
  background: var(--source-color, rgba(80,130,255,0.8));
  margin-bottom: 22px; opacity: 0.7;
}

.detail-source-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
}

.detail-badge {
  padding: 2px 10px; border-radius: 11px;
  font-size: 0.70rem; letter-spacing: 0.15em; text-transform: uppercase;
  font-weight: 600;
  border: 1px solid rgba(var(--source-rgb, 80,130,255), 0.40);
  background: rgba(var(--source-rgb, 80,130,255), 0.12);
  color: var(--source-color, rgba(140,185,255,0.9));
}

.detail-date {
  font-size: 0.79rem; color: var(--text-muted); letter-spacing: 0.06em;
}

.detail-title {
  font-size: 1.58rem; font-weight: 300;
  letter-spacing: 0.03em; line-height: 1.32;
  color: var(--text-primary);
  margin-bottom: 18px;
}

.detail-divider {
  height: 1px; background: var(--border); margin: 18px 0;
}

.detail-image {
  width: 100%; border-radius: 10px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  object-fit: cover; max-height: 230px; display: block;
}

.detail-description {
  font-size: 1.00rem; line-height: 1.80;
  color: rgba(255,255,255,0.50);
  margin-bottom: 28px;
}

.detail-read-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 16px; border-radius: 20px;
  background: rgba(80,130,255,0.08);
  border: 1px solid rgba(80,130,255,0.28);
  color: rgba(140,185,255,0.80);
  font-size: 0.84rem; letter-spacing: 0.10em; text-transform: uppercase;
  text-decoration: none;
  font-family: inherit; cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.detail-read-btn:hover {
  background: rgba(80,130,255,0.18);
  border-color: rgba(80,130,255,0.50);
  color: rgba(160,200,255,0.95);
}

/* ── Article reader ──────────────────────────────────────────────────────────── */

.load-article-btn {
  display: inline-flex; align-items: center; gap: 7px;
  margin-top: 14px;
  padding: 7px 16px; border-radius: 20px;
  background: rgba(80,130,255,0.08);
  border: 1px solid rgba(80,130,255,0.28);
  color: rgba(140,185,255,0.80);
  font-size: 0.84rem; letter-spacing: 0.10em; text-transform: uppercase;
  font-family: inherit; cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.load-article-btn::before { content: '↓'; }
.load-article-btn:hover {
  background: rgba(80,130,255,0.18);
  border-color: rgba(80,130,255,0.50);
  color: rgba(160,200,255,0.95);
}

.article-loading {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-muted); font-size: 0.86rem; letter-spacing: 0.1em;
  padding: 24px 0;
}
.article-spinner {
  width: 15px; height: 15px; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.08);
  border-top-color: rgba(160,200,255,0.6);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.article-fetch-error {
  font-size: 0.80rem; color: rgba(248,113,113,0.55);
  letter-spacing: 0.06em; padding: 10px 0;
}

.detail-byline {
  font-size: 0.80rem; color: var(--text-muted);
  letter-spacing: 0.08em; margin-bottom: 18px;
}

.article-body {
  font-size: 1.24rem; line-height: 1.82;
  color: rgba(255,255,255,0.58);
}
.article-body p { margin-bottom: 1.15em; }
.article-body p:last-child { margin-bottom: 0; }

.article-body h1, .article-body h2, .article-body h3,
.article-body h4, .article-body h5 {
  color: rgba(255,255,255,0.86); font-weight: 300;
  letter-spacing: 0.03em; line-height: 1.3;
  margin: 1.5em 0 0.55em;
}
.article-body h1 { font-size: 1.63rem; }
.article-body h2 { font-size: 1.43rem; }
.article-body h3 { font-size: 1.29rem; }

.article-body img {
  width: 100%; border-radius: 8px; display: block;
  margin: 1.1em 0; border: 1px solid var(--border);
  object-fit: cover;
}
.article-body figure { margin: 1.2em 0; }
.article-body figcaption {
  font-size: 0.78rem; color: rgba(255,255,255,0.28);
  margin-top: 5px; letter-spacing: 0.04em; line-height: 1.5;
}

.article-body a {
  color: rgba(140,185,255,0.82); text-decoration: none;
  border-bottom: 1px solid rgba(140,185,255,0.20);
  transition: color 0.15s, border-color 0.15s;
}
.article-body a:hover {
  color: rgba(180,215,255,1);
  border-color: rgba(180,215,255,0.45);
}

.article-body ul, .article-body ol {
  padding-left: 1.5em; margin-bottom: 1.1em;
}
.article-body li { margin-bottom: 0.35em; }

.article-body blockquote {
  border-left: 2px solid rgba(80,130,255,0.45);
  padding-left: 1em; margin: 1.2em 0;
  color: rgba(255,255,255,0.42); font-style: italic;
}

.article-body table {
  width: 100%; border-collapse: collapse;
  font-size: 0.88rem; margin-bottom: 1.2em;
}
.article-body th, .article-body td {
  padding: 6px 10px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.article-body th { color: rgba(255,255,255,0.55); font-weight: 500; }

.article-body pre, .article-body code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.87em;
  background: rgba(255,255,255,0.04);
  border-radius: 4px;
}
.article-body pre {
  padding: 12px 14px; overflow-x: auto; margin-bottom: 1.1em;
  border: 1px solid var(--border);
}
.article-body code { padding: 1px 5px; }
.article-body pre code { padding: 0; background: none; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  #detail-panel { width: 100%; border-left: none; }
}

@media (max-width: 640px) {
  #header { padding: 14px 16px 10px; }
  #brand h1 { font-size: 1.06rem; letter-spacing: 0.32em; }
  #article-grid {
    grid-template-columns: 1fr;
    padding: 16px 14px 32px;
    gap: 12px;
  }
  #main { padding-top: 174px; }
  #detail-panel { padding: 54px 20px 48px; }
  .detail-title { font-size: 1.35rem; }
}

@media (max-height: 600px) {
  #main { padding-top: 154px; }
}
