/* ---------- Theme tokens ---------- */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #070707;
  --surface-2: #0f0f0f;
  --border: #181818;
  --track: #161616;
  --text: #f2f2f2;
  --muted: #6e6e6e;
  --accent: #8ab4ff;

  --extreme-fear: #ff3b3b;
  --fear: #ff8a3d;
  --neutral: #d4b13a;
  --greed: #9ccc65;
  --extreme-greed: #22c55e;

  --radius: 12px;
  --gutter: 16px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f6f6;
  --border: #e8e8e8;
  --track: #ececec;
  --text: #0a0a0a;
  --muted: #6b6b6b;
  --accent: #1d4ed8;

  --extreme-fear: #e11d1d;
  --fear: #ea6a1c;
  --neutral: #b8960a;
  --greed: #5e9e2e;
  --extreme-greed: #15803d;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

/* Thin scrollbars: standard property (Firefox, Chrome 121+) plus WebKit fallback */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-corner { background: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px var(--gutter);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: 0.01em; }

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.status { color: var(--muted); font-size: 12px; }

.badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.live { color: var(--extreme-greed); border-color: var(--extreme-greed); }

.btn,
.icon-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.btn { padding: 6px 12px; }
.btn:hover,
.icon-btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.4; cursor: progress; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
}
.icon-btn svg { width: 16px; height: 16px; }
:root[data-theme="dark"] .icon-moon,
:root[data-theme="light"] .icon-sun { display: none; }

/* ---------- Info popover ---------- */
.info { position: relative; }

.info-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: min(300px, 86vw);
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  text-align: left;
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
}
.info-panel p { margin: 0 0 8px; }
.info-panel strong { color: var(--text); font-weight: 600; }
.info-title { color: var(--text); font-weight: 600; font-size: 13px; }
.info-note { margin: 0; font-size: 11px; opacity: 0.8; }

/* Tap-to-open (touch and everything else) */
.info.open .info-panel { opacity: 1; visibility: visible; transform: none; }

/* Hover-to-open on devices with a real pointer */
@media (hover: hover) {
  .info:hover .info-panel,
  .info:focus-within .info-panel { opacity: 1; visibility: visible; transform: none; }
}

/* ---------- Layout ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px var(--gutter) 48px;
  display: grid;
  gap: 56px;
}

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 0 0 14px;
  font-weight: 600;
}

/* ---------- Main index ---------- */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 32px 0 0;
}

.hero-gauge { width: min(620px, 100%); }
.hero-gauge svg { width: 100%; height: auto; display: block; }

.hero-name {
  margin: -4px 0 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 600;
}

.hero-score {
  margin-top: -6px;
  font-size: clamp(64px, 10vw, 112px);
  font-weight: 200;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.hero-band {
  margin: 10px 0 6px;
  font-size: 18px;
  font-weight: 500;
  color: var(--band, var(--text));
}

.hero-meta { margin: 0; color: var(--muted); font-size: 12px; }

.gauge-tick-label { fill: var(--muted); font-size: 5.5px; font-family: inherit; }

.band-legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  padding: 0;
  margin: 22px 0 0;
}
.band-legend li {
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  opacity: 0.5;
  padding-bottom: 4px;
  border-bottom: 2px solid transparent;
}
.band-legend li.active {
  opacity: 1;
  color: var(--band);
  border-bottom-color: var(--band);
  font-weight: 600;
}

.history {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: min(480px, 100%);
  margin: 24px 0 0;
}
.history div { border-top: 1px solid var(--border); padding-top: 10px; }
.history dt { font-size: 11px; color: var(--muted); margin: 0; }
.history dd {
  margin: 2px 0 0;
  font-size: 18px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--band, var(--text));
}
.history dd span { font-size: 11px; font-weight: 500; margin-left: 6px; }


/* Band colors, applied to any element with data-band */
[data-band="extreme-fear"] { --band: var(--extreme-fear); }
[data-band="fear"] { --band: var(--fear); }
[data-band="neutral"] { --band: var(--neutral); }
[data-band="greed"] { --band: var(--greed); }
[data-band="extreme-greed"] { --band: var(--extreme-greed); }
.cat-score, .cat-band, .score-pill { color: var(--band, var(--text)); }

/* ---------- Category indexes ---------- */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.cat-card {
  appearance: none;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s;
}
.cat-card:hover { border-color: var(--muted); }
.cat-card.active { border-color: var(--text); }

.cat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cat-name { font-weight: 600; font-size: 14px; }
.cat-desc { color: var(--muted); font-size: 12px; margin: 0; }
.cat-score { font-size: 28px; font-weight: 300; font-variant-numeric: tabular-nums; }
.cat-band { font-size: 12px; font-weight: 500; }

.meter {
  position: relative;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff3b3b 0%, #d4b13a 50%, #22c55e 100%);
}
.meter-dot {
  position: absolute;
  top: 50%;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text);
  transform: translate(-50%, -50%);
}

.cat-foot { color: var(--muted); font-size: 11px; }

/* ---------- Feed ---------- */
.feed-section { display: grid; gap: 14px; }

.feed-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.feed-header .section-title { margin: 0; }

.feed-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px;
  cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] { color: var(--bg); background: var(--text); border-color: var(--text); }

select {
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
}

.feed { display: grid; gap: 8px; }

.tweet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
}

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2);
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
}

.tweet-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  font-size: 13px;
}
.tweet-name { font-weight: 600; }
.tweet-handle, .tweet-time { color: var(--muted); }
.tag {
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 6px;
}
.score-pill {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.tweet-text { margin: 6px 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; }

.tweet-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.tweet-meta a { color: var(--muted); text-decoration: none; margin-left: auto; }
.tweet-meta a:hover { color: var(--text); }

.noscript { max-width: 60ch; margin: 24px auto; padding: 0 var(--gutter); color: var(--muted); text-align: center; }

.empty { color: var(--muted); padding: 24px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); font-size: 13px; }

.skeleton {
  height: 96px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border: 1px solid var(--border);
}
@keyframes shimmer { to { background-position: -200% 0; } }

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  padding: 16px var(--gutter) 32px;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .topbar { padding: 12px var(--gutter); }
  .topbar-right { width: 100%; justify-content: space-between; margin-left: 0; }
  .tweet { grid-template-columns: 1fr; }
  .avatar { display: none; }
  .tweet-meta a { margin-left: 0; }
  .score-pill { margin-left: 0; }
  .container { gap: 40px; }
}
