/* Stock Investment Vane — OLED dark, Bento grid, IBM Plex Sans
   Design tokens come from ui-ux-pro-max: Stock Investment Vane
   Primary: #0F172A  Secondary: #1E293B  CTA: #22C55E  BG: #020617  Text: #F8FAFC
*/

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg:           #020617;
  --bg-2:         #0B1220;
  --surface:      #0F172A;
  --surface-2:    #1E293B;
  --surface-3:    #243349;
  --line:         rgba(248, 250, 252, 0.08);
  --line-2:       rgba(248, 250, 252, 0.16);
  --ink:          #F8FAFC;
  --ink-2:        #94A3B8;
  --ink-3:        #64748B;
  --accent:       #22C55E;
  --accent-dim:   #16A34A;
  --blue:         #38BDF8;
  --amber:        #FBBF24;
  --fear:         #F87171;
  --extreme-fear: #DC2626;
  --greed:        #22C55E;
  --extreme-greed:#F59E0B;
  --neutral:      #94A3B8;
  --warn:         #FBBF24;
  --radius:       12px;
  --radius-lg:    20px;
  --radius-xl:    28px;
  --font:         "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono:         "IBM Plex Mono", ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

/* ================= Layout ================= */
.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 28px 80px;
}

@media (max-width: 720px) {
  .app { padding: 16px 14px 60px; }
}

/* ================= Header ================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent) 0%, #0EA5E9 100%);
  display: grid;
  place-items: center;
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.25);
}
.brand-mark svg { display: block; }
.brand h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
  color: var(--ink);
}
.brand .sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-3);
  letter-spacing: 0.04em;
}

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

/* ================= Tabs ================= */
.tabs {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}
.tabs button {
  appearance: none;
  background: transparent;
  border: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tabs button:hover { color: var(--ink); }
.tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tabs button.active {
  background: var(--ink);
  color: var(--bg);
}
.tabs .pulse {
  width: 7px; height: 7px;
  background: var(--fear);
  border-radius: 50%;
  display: inline-block;
  animation: pulse 1.4s ease-in-out infinite;
}
.tabs button.active .pulse { background: var(--fear); }
@keyframes pulse {
  0%, 100% { opacity: 0.35; box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.4); }
  50%      { opacity: 1;    box-shadow: 0 0 0 4px rgba(248, 113, 113, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .tabs .pulse { animation: none; }
}

/* ================= Icon button ================= */
.icon-btn {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  color: var(--ink-2);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-2); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn svg { display: block; }

/* ================= Bento Grid ================= */
.bento {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: minmax(0, auto);
  gap: 16px;
}
.bento-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.bento-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(800px circle at var(--mx, 30%) var(--my, 0%), rgba(56, 189, 248, 0.06), transparent 50%);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.bento-card:hover { border-color: var(--line-2); }
.bento-card:hover::before { opacity: 1; }

/* Grid placement — desktop */
.card-hero       { grid-column: span 4; grid-row: span 2; min-height: 320px; padding: 28px 32px; }
.card-mode       { grid-column: span 2; }
.card-meta       { grid-column: span 2; }
.card-trend      { grid-column: span 3; }
.card-volume     { grid-column: span 3; }
.card-sub        { grid-column: span 2; }
.card-sub:nth-of-type(6n+6) { grid-column: span 2; }
.card-history    { grid-column: span 6; min-height: 260px; }

/* Tablet */
@media (max-width: 980px) {
  .card-hero    { grid-column: span 6; }
  .card-mode    { grid-column: span 3; }
  .card-meta    { grid-column: span 3; }
  .card-trend   { grid-column: span 3; }
  .card-volume  { grid-column: span 3; }
  .card-sub     { grid-column: span 3; }
  .card-history { grid-column: span 6; }
}

/* Mobile */
@media (max-width: 600px) {
  .bento { gap: 12px; }
  .bento-card { padding: 18px 18px; }
  .card-hero, .card-mode, .card-meta,
  .card-trend, .card-volume, .card-sub, .card-history {
    grid-column: span 6;
  }
  .card-hero { min-height: 280px; padding: 22px 20px; }
}

/* ================= Hero card ================= */
.eyebrow {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.eyebrow .dot {
  display: inline-block;
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}
.hero-body {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  align-items: center;
  margin-top: 18px;
}
@media (max-width: 600px) {
  .hero-body { grid-template-columns: 1fr; }
}
.gauge-svg { width: 100%; max-width: 300px; height: auto; }
.hero-num {
  font-family: var(--mono);
  font-size: 92px;
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: -0.04em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 30px rgba(248, 250, 252, 0.05);
}
@media (max-width: 600px) { .hero-num { font-size: 76px; } }
.hero-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 500;
  margin-top: 10px;
}
.hero-label .range {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-3);
  font-family: var(--mono);
}
.hero-advice {
  font-size: 14px;
  color: var(--ink-2);
  line-height: 1.6;
  margin-top: 12px;
  max-width: 36em;
}

/* ================= Tile cards (mode / meta) ================= */
.tile-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.tile-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
  color: var(--ink);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.tile-sub {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 4px;
}
.tile-tickers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.tag {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
  letter-spacing: 0.02em;
}

/* ================= Trend & Volume cards ================= */
.metric-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.metric-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}
.metric-num {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.metric-desc {
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 6px;
  line-height: 1.5;
}
.bar {
  height: 6px;
  background: var(--bg-2);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 10px;
}
.bar > span {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--ink);
  transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.bar.fear > span { background: var(--fear); }
.bar.extreme-fear > span { background: var(--extreme-fear); }
.bar.neutral > span { background: var(--neutral); }
.bar.greed > span { background: var(--greed); }
.bar.extreme-greed > span { background: var(--extreme-greed); }

/* ================= Sub-score grid ================= */
.sub-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.sub {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color 0.2s ease, transform 0.2s ease;
  cursor: default;
}
.sub:hover { border-color: var(--line-2); transform: translateY(-1px); }
.sub-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.sub-name {
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 500;
}
.sub-weight {
  font-size: 10px;
  color: var(--ink-3);
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
.sub-val {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.sub-desc {
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 6px;
  line-height: 1.5;
}

/* ================= History card ================= */
.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.history-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
.history-hint {
  font-size: 12px;
  color: var(--ink-3);
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--ink-2);
}
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

#histChart {
  width: 100% !important;
  height: 100% !important;
}

/* ================= States ================= */
.loading, .error {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin: 0;
}
.loading {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 10px;
}
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--line-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}
.error {
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid rgba(220, 38, 38, 0.4);
  color: #FCA5A5;
}

/* ================= Footnote ================= */
.foot {
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--ink-3);
}
.foot a { color: var(--ink-3); }
.foot a:hover { color: var(--ink-2); }
.foot code {
  font-family: var(--mono);
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

/* ================= Accessibility helpers ================= */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus ring for keyboard users */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ================= Poll indicator ================= */
#poll-indicator {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-2);
  font-family: var(--mono);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
  animation: pollSlideIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes pollSlideIn {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  #poll-indicator { animation: none; }
}
.poll-pulse {
  width: 7px; height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: pollBlink 1.4s ease-in-out infinite;
  display: inline-block;
}
@keyframes pollBlink {
  0%, 100% { opacity: 0.3; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50%      { opacity: 1;   box-shadow: 0 0 0 4px rgba(34, 197, 94, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .poll-pulse { animation: none; opacity: 1; }
}
#poll-countdown {
  color: var(--ink);
  font-weight: 500;
  min-width: 20px;
  text-align: right;
  display: inline-block;
}
#poll-indicator .poll-pause {
  font-size: 13px;
  color: var(--ink-3);
  display: inline-block;
}
#poll-indicator.paused {
  opacity: 0.7;
}
@media (max-width: 600px) {
  #poll-indicator { bottom: 12px; right: 12px; font-size: 11px; }
}
