/* Atomic Scroll — facts-first news site */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0f172a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --max: 720px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;

  /* Topic color tokens */
  --topic-us-politics: #2563eb;
  --topic-economics: #059669;
  --topic-world-news: #d97706;
  --topic-finance: #7c3aed;
  --topic-technology: #db2777;
  --topic-entertainment: #0d9488;
  --topic-unknown: #6b7280;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  opacity: 0.85;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
}

.market-ticker {
  background: #0f172a;
  color: #e2e8f0;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid #1e293b;
  overflow: hidden;
}

.market-ticker-track {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.45rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.25rem;
  align-items: baseline;
}

.ticker-item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  white-space: nowrap;
}

.ticker-label {
  font-weight: 650;
  color: #94a3b8;
  letter-spacing: 0.02em;
}

.ticker-price {
  color: #f8fafc;
  font-weight: 600;
}

.ticker-change {
  font-weight: 650;
}

.ticker-item.up .ticker-change {
  color: #4ade80;
}

.ticker-item.down .ticker-change {
  color: #f87171;
}

.ticker-loading {
  color: #94a3b8;
}

.ticker-item.flash-up .ticker-price {
  color: #4ade80;
  transition: color 0.2s ease;
}

.ticker-item.flash-down .ticker-price {
  color: #f87171;
  transition: color 0.2s ease;
}

.ticker-item .ticker-price {
  transition: color 0.35s ease;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.site-header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  flex-shrink: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 8px;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.brand-name {
  font-weight: 750;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand-tag {
  font-size: 0.75rem;
  color: var(--muted);
}

.site-search {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  max-width: 22rem;
  justify-content: flex-end;
}

.site-search input[type="search"] {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
}

.site-search button {
  appearance: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
}

.site-search button:hover {
  opacity: 0.9;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.search-heading {
  margin: 0 0 0.35rem;
  font-size: clamp(1.35rem, 3.5vw, 1.75rem);
  letter-spacing: -0.03em;
}

.search-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.subject-hashtags {
  list-style: none;
  margin: 0.85rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.subject-hashtags .hashtag-link,
.hashtag-link {
  display: inline-block;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 650;
  color: #1d4ed8;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
}

.subject-hashtags .hashtag-link:hover,
.hashtag-link:hover {
  opacity: 1;
  background: #dbeafe;
}

.infinite-scroll-sentinel {
  height: 1px;
  width: 100%;
  margin: 0;
  padding: 0;
  pointer-events: none;
}

.infinite-scroll-status {
  margin: 0.75rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.page-intro {
  margin-bottom: 1.5rem;
}

.page-intro h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.5rem, 4vw, 2rem);
  letter-spacing: -0.03em;
}

.page-intro p {
  margin: 0;
  color: var(--muted);
  max-width: 40rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 0.25rem;
  padding: 0;
  list-style: none;
}

.legend-item {
  display: inline-flex;
  align-items: center;
}

.legend-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.legend-link:hover {
  opacity: 1;
  border-color: var(--topic, #94a3b8);
  color: var(--topic, var(--text));
}

.legend-link.is-active {
  border-color: var(--topic, var(--text));
  color: var(--topic, var(--text));
  background: color-mix(in srgb, var(--topic, #0f172a) 12%, white);
  font-weight: 650;
}

.legend-swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.legend-swatch-all {
  background: linear-gradient(135deg, #2563eb, #059669, #d97706, #7c3aed, #db2777, #0d9488);
}

/* Topic classes */
.topic-us-politics { --topic: var(--topic-us-politics); color: var(--topic-us-politics); }
.topic-economics { --topic: var(--topic-economics); color: var(--topic-economics); }
.topic-world-news { --topic: var(--topic-world-news); color: var(--topic-world-news); }
.topic-finance { --topic: var(--topic-finance); color: var(--topic-finance); }
.topic-technology { --topic: var(--topic-technology); color: var(--topic-technology); }
.topic-entertainment { --topic: var(--topic-entertainment); color: var(--topic-entertainment); }
.topic-unknown { --topic: var(--topic-unknown); color: var(--topic-unknown); }

.legend-swatch.topic-us-politics { background: var(--topic-us-politics); }
.legend-swatch.topic-economics { background: var(--topic-economics); }
.legend-swatch.topic-world-news { background: var(--topic-world-news); }
.legend-swatch.topic-finance { background: var(--topic-finance); }
.legend-swatch.topic-technology { background: var(--topic-technology); }
.legend-swatch.topic-entertainment { background: var(--topic-entertainment); }

/* Front-page article list */
.article-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.article-list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border-left: 4px solid var(--topic, var(--topic-unknown));
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.article-list-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.1);
}

.article-list-item a {
  display: block;
  padding: 1rem 1.1rem;
  text-decoration: none;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.85rem;
  align-items: center;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.topic-badge {
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 0.68rem;
}

.article-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--text);
  line-height: 1.35;
}

.article-summary {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Article detail — same content width as home-page article titles (.main is 960px) */
.article-page {
  max-width: none;
}

.article-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.25rem;
  border-top: 4px solid var(--topic, var(--accent));
}

.article-hero-body {
  padding: 1.25rem 1.35rem 1.4rem;
}

.article-hero img.hero-image {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  object-position: center;
  background: #0f172a;
  border-radius: 0;
}

.facts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.fact-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
}

.fact-card.has-subfacts {
  padding-bottom: 0.85rem;
}

.fact-card.has-subfacts .fact-main {
  cursor: pointer;
  border-radius: calc(var(--radius) - 2px);
  margin: -0.25rem -0.35rem;
  padding: 0.25rem 0.35rem;
  outline: none;
}

.fact-card.has-subfacts .fact-main:hover {
  background: rgba(15, 23, 42, 0.03);
}

.fact-card.has-subfacts .fact-main:focus-visible {
  box-shadow: 0 0 0 2px #93c5fd;
}

.fact-meta {
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: 0.55rem;
}

.fact-meta .fact-expand-affordance {
  order: 1;
  flex: 0 0 auto;
}

.fact-meta .fact-sources {
  order: 2;
  margin: 0;
  margin-left: auto;
  justify-content: flex-end;
}

.fact-expand-affordance {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #1d4ed8;
  user-select: none;
}

.fact-expand-chevron {
  display: inline-block;
  transition: transform 0.15s ease;
  font-size: 0.85rem;
  line-height: 1;
}

.fact-card.is-expanded .fact-expand-chevron {
  transform: rotate(90deg);
}

.fact-card .fact-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.fact-card p,
.fact-card .fact-text {
  margin: 0;
  font-size: 1.02rem;
}

.subfacts {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0.65rem 0 0.15rem 0.85rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.subfacts[hidden] {
  display: none !important;
}

.subfact-card {
  background: rgba(15, 23, 42, 0.03);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  padding: 0.7rem 0.85rem;
}

.subfact-card .subfact-text {
  margin: 0;
  font-size: 0.95rem;
  color: #1e293b;
}

.subfact-card .fact-sources {
  margin-top: 0.45rem;
}

.fact-sources {
  margin: 0.55rem 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.fact-sources li {
  font-size: 0.82rem;
}

.fact-sources a,
a.source-cite {
  position: relative;
  color: #1d4ed8;
  text-decoration: none;
  font-weight: 650;
  font-size: 0.85rem;
  word-break: normal;
}

a.source-cite:hover {
  text-decoration: underline;
  opacity: 1;
}

/* Hover popup showing the full source URL */
a.source-cite[data-url]:hover::after,
a.source-cite[data-url]:focus-visible::after {
  content: attr(data-url);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 0.45rem);
  transform: translateX(-50%);
  z-index: 40;
  min-width: 12rem;
  max-width: min(28rem, 80vw);
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  background: #0f172a;
  color: #f8fafc;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0;
  text-decoration: none;
  white-space: normal;
  word-break: break-all;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.28);
  pointer-events: none;
}

a.source-cite[data-url]:hover::before,
a.source-cite[data-url]:focus-visible::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 0.15rem);
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #0f172a;
  z-index: 41;
  pointer-events: none;
}

.fact-images {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.fact-images img {
  max-width: 180px;
  border: 1px solid var(--border);
}

.related-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.related-dates {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.related-date-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
}

.related-date-btn:hover,
.related-date-btn:focus-visible {
  color: var(--text);
  border-color: #94a3b8;
  outline: none;
}

.related-date-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.related-date-item.is-expanded {
  display: block;
  width: 100%;
}

.thread-expanded-slot {
  margin-top: 0.25rem;
}

.thread-expanded-slot > .article-page {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.related-dates a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

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

/* Publish form */
.publish-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.35rem;
  max-width: var(--max);
}

.form-grid {
  display: grid;
  gap: 1rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="datetime-local"],
select,
textarea {
  font: inherit;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

.facts-editor {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.fact-editor-row {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  display: grid;
  gap: 0.5rem;
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 650;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
}

.btn:hover {
  opacity: 0.9;
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.flash-ok {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.flash-err {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.site-footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

.empty-state {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}

/* Responsive: phone */
@media (max-width: 640px) {
  .site-header-inner {
    padding: 0.75rem 1rem;
    align-items: stretch;
    flex-direction: column;
    gap: 0.75rem;
  }

  .brand-tag {
    max-width: 100%;
  }

  .main {
    padding: 1rem 1rem 2.5rem;
  }

  .page-intro {
    margin-bottom: 1rem;
  }

  .legend {
    gap: 0.35rem;
  }

  .legend-link {
    font-size: 0.75rem;
    padding: 0.4rem 0.65rem;
  }

  .article-list-item a {
    padding: 0.85rem 0.95rem;
  }

  .article-title {
    font-size: 1.02rem;
    line-height: 1.4;
  }

  .article-hero img.hero-image {
    max-height: 200px;
  }

  .article-hero-body {
    padding: 1rem;
  }

  .article-hero-body .article-title {
    font-size: 1.25rem !important;
  }

  .fact-card {
    padding: 0.85rem 0.95rem;
  }

  .fact-card p,
  .fact-card .fact-text {
    font-size: 0.98rem;
  }

  /* Details below sources on narrow screens */
  .fact-meta {
    flex-direction: column;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.4rem;
  }

  .fact-meta .fact-sources {
    order: 1;
    margin-left: 0;
    justify-content: flex-start;
  }

  .fact-meta .fact-expand-affordance {
    order: 2;
  }

  .fact-sources a,
  a.source-cite {
    font-size: 0.8rem;
  }

  .fact-images img {
    max-width: 100%;
  }

  .site-search {
    max-width: none;
    width: 100%;
    justify-content: stretch;
  }

  .site-search button {
    flex-shrink: 0;
  }

  .market-ticker-track {
    padding: 0.4rem 1rem;
    gap: 0.35rem 0.9rem;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .site-footer {
    padding: 1.25rem 1rem 2rem;
  }
}

/* Responsive: desktop */
@media (min-width: 900px) {
  .article-list {
    gap: 0.75rem;
  }

  .article-title {
    font-size: 1.12rem;
  }

  .main {
    padding-top: 2rem;
  }
}
