:root {
  --bg-canvas: #0f1117;
  --bg-surface: #161b22;
  --bg-inset: #1c2128;
  --bg-tier3: #21262d;
  --text: #e1e4e8;
  --text-dim: #8b949e;
  --text-bright: #f0f6fc;
  --border: #30363d;
  --border-soft: rgba(48, 54, 61, 0.5);
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --purple: #bc8cff;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.02), 0 8px 24px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-canvas);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-bright);
  text-decoration: none;
  letter-spacing: 0.02em;
}
.logo:hover { text-decoration: none; opacity: 0.85; }
.snapshot-badge {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  background: var(--bg-inset);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem;
}

.empty {
  color: var(--text-dim);
  padding: 2rem;
  text-align: center;
  font-style: italic;
}
.empty.error { color: var(--red); font-style: normal; }

/* ---------- Hero ---------- */
.hero {
  margin-bottom: 1.5rem;
}
.hero h1 {
  margin: 0.25rem 0 0.5rem;
  color: var(--text-bright);
  font-size: 2rem;
  font-weight: 700;
}
.hero-meta {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.kicker {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
}
.kicker-pos { color: var(--green); }
.kicker-neg { color: var(--red); }
.kicker-neu { color: var(--purple); }

/* ---------- Scoring mode pills ---------- */
.mode-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem;
  margin-bottom: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-wrap: wrap;
}
.mode-pill {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.mode-pill:hover {
  color: var(--text);
  background: var(--bg-tier3);
}
.mode-pill.active {
  background: var(--bg-tier3);
  color: var(--text-bright);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(88, 166, 255, 0.25);
}
.mode-weights {
  margin-left: auto;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 0.72rem;
  color: var(--text-dim);
  padding: 0 0.5rem;
}

/* ---------- Surface ---------- */
.surface {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}
.surface-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.surface-header h2 {
  margin: 0.25rem 0 0;
  color: var(--text-bright);
  font-size: 1.15rem;
}
.meta {
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ---------- Ranking table ---------- */
.table-wrap { overflow-x: auto; }
.ranking-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.ranking-table th,
.ranking-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.ranking-table th {
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-inset);
}
.ranking-table tbody tr:hover { background: rgba(88, 166, 255, 0.05); }
.idx {
  color: var(--text-dim);
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  width: 2.5rem;
  text-align: right;
}
.entity-cell {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  text-decoration: none;
}
.entity-cell:hover { text-decoration: none; }
.ticker-row {
  display: inline-flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.entity-cell .ticker {
  font-weight: 700;
  color: var(--text-bright);
  font-size: 0.95rem;
}
.row-price {
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--text);
  font-weight: 500;
}
.row-change {
  font-weight: 600;
  font-size: 0.72rem;
}
.row-change.pos { color: var(--green); }
.row-change.neg { color: var(--red); }
.entity-cell .name {
  color: var(--text-dim);
  font-size: 0.78rem;
}
.sector-inline {
  font-size: 0.72rem;
  font-style: italic;
  opacity: 0.8;
}
.sigsum { display: flex; flex-direction: column; gap: 0.15rem; }
.sigsum .total { color: var(--text); font-weight: 600; }
.sigsum .split { font-size: 0.78rem; color: var(--text-dim); }

/* ---------- Score bars ---------- */
.scores {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 320px;
}
.score-line {
  display: grid;
  grid-template-columns: 60px 1fr 60px;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.78rem;
}
.score-label {
  color: var(--text-dim);
  text-align: right;
}
.score-track {
  position: relative;
  height: 6px;
  background: var(--bg-tier3);
  border-radius: 3px;
}
.score-axis {
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 1px;
  background: var(--border);
}
.score-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 2px;
  min-width: 2px;
}
.score-bar-pos { background: var(--green); }
.score-bar-neg { background: var(--red); }
.score-bar-neu { background: var(--text-dim); }
.score-num {
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-weight: 600;
  text-align: right;
}
.score-num-pos { color: var(--green); }
.score-num-neg { color: var(--red); }
.score-num-neu { color: var(--text-dim); }

/* ---------- Polarity inline text ---------- */
.pol-pos, .pol.pol-pos { color: var(--green); }
.pol-neg, .pol.pol-neg { color: var(--red); }
.pol-neu, .pol.pol-neu { color: var(--text-dim); }
.pol-mix, .pol.pol-mix { color: var(--purple); }
.pol {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

/* ---------- Entity hero ---------- */
.entity-hero {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}
.back {
  font-size: 0.85rem;
  color: var(--text-dim);
  display: inline-block;
  margin-bottom: 1rem;
}
.back:hover { color: var(--accent); }
.entity-headline {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}
.entity-title h1 {
  margin: 0;
  color: var(--text-bright);
  font-size: 2.2rem;
  letter-spacing: -0.01em;
}
.entity-price {
  display: inline-flex;
  align-items: baseline;
  gap: 0.6rem;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
}
.price-num {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-bright);
}
.price-change {
  font-size: 0.95rem;
  font-weight: 600;
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
}
.price-change.pos { color: var(--green); }
.price-change.neg { color: var(--red); }
.price-period {
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.entity-name {
  color: var(--text);
  font-size: 1rem;
  margin-top: 0.15rem;
}
.entity-sector {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 0.1rem;
  font-style: italic;
}
.entity-scores {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem;
  margin-top: 1rem;
  max-width: 560px;
}
.entity-scores .score-line {
  grid-template-columns: 80px 1fr 60px;
  font-size: 0.85rem;
}

/* ---------- Chips ---------- */
.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chip {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-tier3);
  color: var(--text-dim);
  border: 1px solid var(--border-soft);
}
.chip-pos { color: var(--green); border-color: rgba(63, 185, 80, 0.3); background: rgba(63, 185, 80, 0.08); }
.chip-neg { color: var(--red); border-color: rgba(248, 81, 73, 0.3); background: rgba(248, 81, 73, 0.08); }
.chip-neu { color: var(--purple); border-color: rgba(188, 140, 255, 0.3); background: rgba(188, 140, 255, 0.08); }

.legend {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin: 0 0 1rem;
}

/* ---------- Contribution rows ---------- */
.contrib-list { display: flex; flex-direction: column; gap: 0.5rem; }
.contrib-row {
  background: var(--bg-inset);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  overflow: hidden;
}
.contrib-row[open] { border-color: var(--border); }
.contrib-row > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.75rem 1rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: start;
}
.contrib-row > summary::-webkit-details-marker { display: none; }
.contrib-row > summary::marker { display: none; }
.contrib-row > summary:hover { background: rgba(88, 166, 255, 0.04); }
.contrib-main { min-width: 0; }
.contrib-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
}
.contrib-head strong {
  color: var(--text-bright);
  font-weight: 600;
}
.dominant {
  font-size: 0.7rem;
  color: var(--text-dim);
  background: var(--bg-tier3);
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
}
.badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-tier3);
  color: var(--text-dim);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-weight: 600;
}
.contrib-copy {
  margin-top: 0.4rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  line-height: 1.4;
}
.contrib-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(54px, auto));
  gap: 0.35rem;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
}
.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-canvas);
  border-radius: 4px;
  padding: 0.3rem 0.4rem;
  font-size: 0.75rem;
  min-width: 54px;
}
.cell-l {
  color: var(--text-dim);
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.cell strong { font-size: 0.85rem; font-weight: 600; }
.cell strong.pos { color: var(--green); }
.cell strong.neg { color: var(--red); }
.cell strong.neu { color: var(--text-dim); }

.contrib-detail {
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding-top: 0.75rem;
}
.note {
  font-size: 0.8rem;
  color: var(--text);
  background: var(--bg-canvas);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}
.note span {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 0.2rem;
  font-weight: 600;
}
.ev {
  font-size: 0.78rem;
  padding: 0.4rem 0.7rem;
  border-radius: 4px;
  border-left: 3px solid;
}
.ev-pos { background: rgba(63, 185, 80, 0.06); border-color: var(--green); color: var(--text); }
.ev-neg { background: rgba(248, 81, 73, 0.06); border-color: var(--red); color: var(--text); }

/* ---------- Context group ---------- */
.ctx-group {
  margin-top: 1rem;
  border-top: 1px solid var(--border-soft);
  padding-top: 1rem;
}
.ctx-group > summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 600;
  padding: 0.5rem 0;
  list-style: none;
}
.ctx-group > summary::-webkit-details-marker { display: none; }
.ctx-group > summary::before {
  content: '▸ ';
  display: inline-block;
  transition: transform 0.15s;
}
.ctx-group[open] > summary::before { transform: rotate(90deg); }
.ctx-list { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }
.ctx-row {
  background: var(--bg-inset);
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border-soft);
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  main { padding: 0.75rem; }
  .topbar { padding: 0.6rem 1rem; }
  .snapshot-badge { font-size: 0.68rem; padding: 0.2rem 0.5rem; }

  .hero { margin-bottom: 1rem; }
  .hero h1 { font-size: 1.4rem; }
  .hero-meta { font-size: 0.78rem; }

  /* Mode bar — compact 1-row scrollable */
  .mode-bar {
    padding: 0.35rem;
    margin-bottom: 0.85rem;
    gap: 0.25rem;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .mode-pill {
    font-size: 0.78rem;
    padding: 0.4rem 0.7rem;
    white-space: nowrap;
    flex: 0 0 auto;
  }
  .mode-weights {
    flex: 0 0 auto;
    margin-left: 0.25rem;
    padding: 0;
    font-size: 0.65rem;
  }

  /* Surface trims */
  .surface { padding: 0.75rem; margin-bottom: 1rem; border-radius: 8px; }
  .surface-header { margin-bottom: 0.75rem; }
  .surface-header h2 { font-size: 1rem; }
  .meta { font-size: 0.72rem; }

  /* Ranking — table flattens to compact 2-line cards */
  .table-wrap { overflow: visible; }
  .ranking-table { font-size: 0.8rem; }
  .ranking-table thead { display: none; }
  .ranking-table tbody, .ranking-table tr, .ranking-table td { display: block; width: auto; }
  .ranking-table tbody { display: flex; flex-direction: column; gap: 0.35rem; }
  .ranking-table tr {
    background: var(--bg-inset);
    border: 1px solid var(--border-soft);
    border-radius: 7px;
    padding: 0.5rem 0.75rem;
    display: grid;
    grid-template-columns: auto 1fr auto;
    column-gap: 0.6rem;
    align-items: center;
  }
  .ranking-table tbody tr:hover { background: var(--bg-inset); }
  .ranking-table td { padding: 0; border: none; }
  .ranking-table .idx {
    width: auto;
    text-align: left;
    color: var(--text-dim);
    font-size: 0.72rem;
    font-weight: 600;
    align-self: center;
  }
  .ranking-table .idx::before { content: '#'; }
  .ranking-table tr td:nth-child(2) { min-width: 0; }
  .ranking-table tr td:nth-child(4) { text-align: right; }

  .entity-cell { gap: 0; }
  .ticker-row { gap: 0.45rem; }
  .entity-cell .ticker { font-size: 0.92rem; }
  .row-price { font-size: 0.74rem; }
  .row-change { font-size: 0.7rem; }
  .entity-cell .name { font-size: 0.68rem; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sector-inline { font-size: 0.65rem; }

  /* Mobile: hide V/G/T, show only Overall as a clean inline number */
  .scores {
    display: block;
    min-width: 0;
  }
  .scores .score-line:not(:first-child) { display: none; }
  .scores .score-line {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    background: transparent;
    padding: 0;
    border-radius: 0;
    gap: 0;
  }
  .score-track { display: none; }
  .scores .score-label { display: none; }
  .score-num {
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.15;
    font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  }

  .sigsum { display: none; }

  /* Entity hero — smaller hero on mobile */
  .entity-hero { padding: 1rem; margin-bottom: 1rem; border-radius: 8px; }
  .entity-headline { gap: 0.6rem; }
  .entity-title h1 { font-size: 1.7rem; }
  .price-num { font-size: 1.1rem; }
  .price-change { font-size: 0.85rem; }
  .entity-name { font-size: 0.9rem; }
  .entity-sector { font-size: 0.75rem; }
  .entity-scores {
    margin-top: 0.85rem;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.4rem;
    max-width: none;
  }
  .entity-scores .score-line {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--bg-canvas);
    border-radius: 6px;
    padding: 0.45rem 0.2rem;
    gap: 0.15rem;
  }
  .entity-scores .score-track { display: none; }
  .entity-scores .score-label {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .entity-scores .score-num {
    text-align: center;
    font-size: 0.95rem;
    font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  }

  /* Contribution rows on mobile — stack summary above the OVGT grid */
  .chips { gap: 0.3rem; }
  .chip { font-size: 0.68rem; padding: 0.18rem 0.5rem; }
  .legend { font-size: 0.75rem; }
  .contrib-row > summary {
    grid-template-columns: 1fr;
    padding: 0.65rem 0.75rem;
    gap: 0.55rem;
  }
  .contrib-head { font-size: 0.8rem; gap: 0.4rem; }
  .contrib-copy { font-size: 0.78rem; }
  .contrib-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.3rem;
  }
  .cell { min-width: 0; padding: 0.3rem 0.2rem; }
  .cell strong { font-size: 0.82rem; }
  .contrib-detail { padding: 0 0.75rem 0.85rem; }
  .note { font-size: 0.78rem; padding: 0.45rem 0.6rem; }
  .ev { font-size: 0.75rem; padding: 0.35rem 0.55rem; }
}
