:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-alt: #21262d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #3fb950;
  --border-alpha: 0.15;
  --shadow-alpha: 0.12;
  --accent-hover-alpha: 0.35;
  --border: rgba(139, 148, 158, var(--border-alpha));
  --shadow-border: 0 0 0 1px rgba(139, 148, 158, var(--shadow-alpha));
  --shadow-border-hover: 0 0 0 1px rgba(63, 185, 80, var(--accent-hover-alpha));
  --card-radius: 8px;
  --card-padding: 24px;
  --font-scale: 1;
}

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

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: calc(0.95rem * var(--font-scale));
  line-height: 1.55;
  min-height: 100vh;
}

/* Header */
header {
  background: var(--bg);
  border-bottom: 1px solid var(--accent);
  padding: 1.25rem 2rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

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

h1 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  margin-top: 4px;
  text-wrap: pretty;
}

.header-title { display: flex; flex-direction: column; gap: 4px; }

.fear-greed {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.fear-greed-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.6;
}

.fear-greed-value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.6rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--text);
}

.fear-greed-class {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
}

.fear-greed-class.extreme-fear  { color: #f85149; }
.fear-greed-class.fear          { color: #e3943a; }
.fear-greed-class.neutral       { color: var(--text-muted); }
.fear-greed-class.greed         { color: #7ee787; }
.fear-greed-class.extreme-greed { color: var(--accent); }

.h1-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.date-tag {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

/* Main layout */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 2rem 64px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

h2 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-wrap: balance;
}

/* Topic layout — stacked rows */
.topics-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Top row: 3 featured cards side by side */
.topics-top {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

/* Bottom panel: topics 4–10, compact list */
.topics-more {
  background: var(--surface);
  box-shadow: var(--shadow-border);
  border-radius: var(--card-radius);
  overflow: hidden;
}

.more-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  opacity: 0.6;
}

.more-topic {
  display: flex;
  gap: 12px;
  padding: 11px 20px;
  border-bottom: 1px solid var(--border);
  opacity: 0;
  animation: fadeInUp 350ms ease-out forwards;
}

.more-topic:last-child { border-bottom: none; }

.more-rank {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.6rem;
  color: var(--text-muted);
  min-width: 22px;
  flex-shrink: 0;
  padding-top: 2px;
  font-variant-numeric: tabular-nums;
}

.more-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.more-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.more-name {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  flex: 1;
}

.more-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.63rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.more-headlines {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.more-headline {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.71rem;
  color: var(--text);
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 120ms ease-out;
}

.more-headline:hover { color: var(--accent); }

.topic-card {
  background: var(--surface);
  box-shadow: var(--shadow-border);
  border-radius: var(--card-radius);
  padding: var(--card-padding);
  display: flex;
  flex-direction: column;
  gap: 16px;
  opacity: 0;
  animation: fadeInUp 400ms ease-out forwards;
  transition-property: box-shadow;
  transition-duration: 150ms;
  transition-timing-function: ease-out;
}

.topic-card:hover { box-shadow: var(--shadow-border-hover); }

.topic-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.topic-name {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.95rem;
  font-weight: 600;
  flex: 1;
  line-height: 1.3;
  color: var(--accent);
}

.badge-new {
  background: var(--accent);
  color: #0d1117;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  flex-shrink: 0;
}

.topic-count {
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.mention-bar {
  height: 3px;
  background: var(--surface-alt);
  border-radius: 2px;
  overflow: hidden;
}

.mention-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-tag {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.articles {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.article-item { display: flex; flex-direction: column; gap: 2px; }

.article-link {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-wrap: pretty;
  transition-property: color;
  transition-duration: 150ms;
}

.article-link:hover { color: var(--accent); }

.article-source {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

/* Skeleton loading */
.skeleton-card {
  background: var(--surface);
  box-shadow: var(--shadow-border);
  border-radius: var(--card-radius);
  height: 210px;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

/* Section header with inline controls */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 { margin-bottom: 0; }

.chart-tabs {
  display: flex;
  gap: 4px;
}

.chart-tab {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition-property: background, color, border-color;
  transition-duration: 150ms;
  transition-timing-function: ease-out;
}

.chart-tab:hover { border-color: var(--accent); color: var(--accent); }

.chart-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0d1117;
}

/* Trend chart */
.chart-container {
  background: var(--surface);
  box-shadow: var(--shadow-border);
  border-radius: var(--card-radius);
  padding: var(--card-padding);
  height: 300px;
}

/* Ticker */
.ticker-wrapper {
  background: var(--surface);
  border-bottom: 1px solid var(--accent);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.ticker-row {
  display: flex;
  align-items: center;
  height: 36px;
  overflow: hidden;
  border-bottom: 1px solid var(--accent);
}

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

.ticker-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.12em;
  white-space: nowrap;
  padding: 0 1.25rem;
  border-right: 1px solid var(--border);
  height: 100%;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  min-width: 80px;
}

.ticker-overflow {
  overflow: hidden;
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  -webkit-mask-image: linear-gradient(90deg, transparent, black 3%, black 97%, transparent);
  mask-image: linear-gradient(90deg, transparent, black 3%, black 97%, transparent);
}

.ticker-track {
  display: flex;
  align-items: center;
  gap: 2.5rem;
  animation: ticker-scroll var(--ticker-dur, 35s) linear infinite;
  width: max-content;
}

.ticker-track:hover { animation-play-state: paused; }

@keyframes ticker-scroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

.ticker-coin {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
}

.ticker-coin-img {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  outline: 1px solid rgba(255, 255, 255, 0.1);
  outline-offset: -1px;
}

.ticker-coin-symbol {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--accent);
}

.ticker-coin-name {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.ticker-divider {
  color: var(--text-muted);
  font-size: 0.7rem;
  user-select: none;
}

.ticker-stock {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  text-decoration: none;
  transition: opacity 120ms ease-out;
}

.ticker-stock:hover { opacity: 0.75; }

.ticker-stock-symbol {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
}

.ticker-stock-name {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.ticker-stock-change {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.ticker-stock-change.up   { color: #3fb950; }
.ticker-stock-change.down { color: #f85149; }
.ticker-stock-change.flat { color: var(--text-muted); }

/* History button (sits between ticker and main) */
.history-bar {
  width: 100%;
}

.history-bar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 2rem;
  display: flex;
  justify-content: flex-end;
}

.history-dropdown {
  position: relative;
}

.history-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 5px 14px;
  border-radius: 4px;
  border: 1px solid rgba(63, 185, 80, 0.4);
  background: rgba(63, 185, 80, 0.07);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 150ms ease-out, background 150ms ease-out, color 150ms ease-out;
}

.history-btn:hover,
.history-dropdown.open .history-btn {
  border-color: var(--accent);
  color: var(--accent);
}

.history-caret {
  font-size: 0.6rem;
  line-height: 1;
  transition: transform 150ms ease-out;
}

.history-dropdown.open .history-caret {
  transform: rotate(180deg);
}

.history-panel {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 16px 20px;
  min-width: 300px;
  max-height: 340px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.history-dropdown.open .history-panel {
  display: block;
}

/* Archive / History */
.archive-nav {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.archive-year {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.archive-year-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.6;
}

.archive-month {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.archive-month-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  min-width: 48px;
  padding-top: 5px;
}

.archive-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.archive-date-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 4px 0;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  width: 34px;
  text-align: center;
  transition-property: background, color, border-color;
  transition-duration: 150ms;
  transition-timing-function: ease-out;
}

.archive-date-btn:hover { border-color: var(--accent); color: var(--accent); }

.archive-date-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface-alt);
}

.archive-date-btn.today {
  border-color: var(--accent);
  background: var(--accent);
  color: #0d1117;
}

/* Footer */
footer {
  text-align: center;
  padding: 1.5rem 2rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* Empty state */
.empty-state {
  font-family: 'IBM Plex Mono', monospace;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 2rem 0;
}

/* Responsive */
@media (max-width: 640px) {
  header { padding: 1rem; }
  h1 { font-size: 1.25rem; }
  .header-inner { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .meta { text-align: left; }
  main { padding: 1rem 1rem 3rem; }
  .topics-top { grid-template-columns: 1fr; }
}

/* ============================================================
   UI TWEAKER — dev tool, toggle with ?tweaker in URL
   ============================================================ */

#tweaker-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9000;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  opacity: 0.4;
  transition: opacity 150ms, border-color 150ms, color 150ms;
}
#tweaker-toggle:hover { opacity: 1; border-color: var(--accent); color: var(--accent); }

#tweaker-panel {
  position: fixed;
  bottom: 64px;
  right: 20px;
  z-index: 9001;
  width: 290px;
  max-height: calc(100vh - 100px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  font-family: 'IBM Plex Mono', monospace;
  transform: translateY(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
}
#tweaker-panel.tw-open { opacity: 1; transform: translateY(0); pointer-events: auto; }

.tw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tw-title {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.tw-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 2px 4px;
  transition: color 120ms;
}
.tw-close:hover { color: var(--text); }

.tw-body { overflow-y: auto; flex: 1; padding: 6px 0; }

.tw-group { border: none; padding: 0; margin: 0 0 2px; }
.tw-legend {
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 8px 14px 4px;
  display: block;
  width: 100%;
}

.tw-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
}
.tw-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  flex: 1;
  white-space: nowrap;
}
.tw-val { color: var(--text); font-variant-numeric: tabular-nums; }

.tw-color {
  width: 28px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 2px;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}
.tw-range {
  width: 88px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.tw-footer {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.tw-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.63rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.tw-copy { flex: 1; background: var(--accent); color: #0d1117; border: none; }
.tw-copy:hover { filter: brightness(1.12); }
.tw-copy.tw-copied { background: var(--surface-alt); color: var(--accent); border: 1px solid var(--accent); }
.tw-reset { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.tw-reset:hover { border-color: var(--text-muted); color: var(--text); }
