:root {
  --bg: #070a10;
  --panel: #0e131c;
  --panel-2: #131a26;
  --line: #1e2736;
  --text: #e6ecf5;
  --text-dim: #8794a8;
  --up: #24c98a;
  --down: #f2545b;
  --accent: #f7a44b;
  --chart-grid: #161d2a;
  --ema-9: #f7a44b;
  --ema-21: #4aa8f0;
  --ema-50: #9b7ff0;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

/* A class-level `display` beats the UA rule for [hidden], so hiding an element
   whose class sets display (e.g. .legend-keys) silently fails without this. */
[hidden] {
  display: none !important;
}

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

body {
  background: radial-gradient(1200px 600px at 20% -10%, #101827 0%, var(--bg) 60%);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 10, 16, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--accent), #d9762a);
  color: #100d06;
  font-size: 20px;
  font-weight: 700;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
}

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--panel);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
}

.pill[data-state='live'] .dot {
  background: var(--up);
  box-shadow: 0 0 0 3px rgba(36, 201, 138, 0.15);
}

.pill[data-state='connecting'] .dot {
  background: var(--accent);
  animation: blink 1s infinite;
}

.pill[data-state='down'] .dot {
  background: var(--down);
}

@keyframes blink {
  50% {
    opacity: 0.25;
  }
}

.clock {
  text-align: right;
  font-family: var(--mono);
  font-size: 13px;
}

.clock-label {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

/* ---------- layout ---------- */

main {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  padding: 16px 20px 24px;
  max-width: 1600px;
  margin: 0 auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.hint {
  font-size: 11px;
  color: var(--text-dim);
}

.hero {
  grid-column: span 5;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}
.venues {
  grid-column: span 7;
}
.chart-card {
  grid-column: span 8;
}
.signal-card {
  grid-column: span 4;
  display: flex;
  flex-direction: column;
}
/* Rows tile to exactly 12 columns in DOM order, so no gaps are left behind:
   5+7 | 8+4 | 4+4+4 | 6+6 | 4+8 */
.confluence-card {
  grid-column: span 4;
  display: flex;
  flex-direction: column;
}
.book-card,
.tape-card,
.fng-card {
  grid-column: span 4;
}
.portfolio-card,
.alert-card {
  grid-column: span 6;
}
.chain-card {
  grid-column: span 8;
}

/* Cards stretch to their row's height; centre the dial rather than letting it
   sit against the top of a tall card. */
.fng-card {
  display: flex;
  flex-direction: column;
}

.fng-card .fng {
  flex: 1;
}

@media (max-width: 1100px) {
  .hero,
  .venues,
  .chart-card,
  .confluence-card,
  .signal-card,
  .book-card,
  .tape-card,
  .portfolio-card,
  .fng-card,
  .chain-card,
  .alert-card {
    grid-column: span 6;
    grid-row: auto;
  }
}

@media (max-width: 720px) {
  main {
    padding: 12px;
  }
  .hero,
  .venues,
  .chart-card,
  .confluence-card,
  .signal-card,
  .book-card,
  .tape-card,
  .portfolio-card,
  .fng-card,
  .chain-card,
  .alert-card {
    grid-column: span 12;
  }
}

/* ---------- hero ---------- */

.hero-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.hero-price {
  font-family: var(--mono);
  font-size: clamp(30px, 5vw, 44px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  transition: color 0.4s ease;
}

.hero-price.up {
  color: var(--up);
}
.hero-price.down {
  color: var(--down);
}

.hero-change {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-dim);
}

.hero-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
}

.meta-item {
  display: flex;
  flex-direction: column;
  min-width: 130px;
}

.meta-item span {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.meta-item strong {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
}

/* ---------- venues ---------- */

.venue-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.venue {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.venue-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
}

.venue-pair {
  font-size: 10px;
  color: var(--text-dim);
}

.venue-price {
  font-family: var(--mono);
  font-size: 17px;
  margin-top: 4px;
  transition: color 0.35s ease;
}

.venue-change {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

.venue.stale {
  opacity: 0.45;
}

.up {
  color: var(--up);
}
.down {
  color: var(--down);
}

/* ---------- chart ---------- */

.chart-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--text-dim);
}

.ohlc {
  font-family: var(--mono);
}

.legend-keys {
  display: flex;
  align-items: center;
  gap: 6px;
}

.key {
  width: 12px;
  height: 2px;
  border-radius: 2px;
  display: inline-block;
  margin-left: 8px;
}

.key-9 {
  background: var(--ema-9);
}
.key-21 {
  background: var(--ema-21);
}
.key-50 {
  background: var(--ema-50);
}

.chart-wrap {
  height: 480px;
  position: relative;
}

/* The widget renders into an iframe that fills this box. */
.tv-chart {
  height: 100%;
  width: 100%;
}

.tv-chart iframe {
  border: 0;
  border-radius: 8px;
  display: block;
}

.chart-wrap canvas {
  display: block;
  cursor: crosshair;
}

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

.tf-tabs button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
}

.tf-tabs button:hover {
  color: var(--text);
}

.tf-tabs button[aria-selected='true'] {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
}

/* ---------- order book ---------- */

.book-side {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

#book-asks {
  flex-direction: column-reverse;
}

.book-row {
  position: relative;
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 2px 6px;
  border-radius: 3px;
  overflow: hidden;
}

.book-row .depth {
  position: absolute;
  inset: 0 auto 0 0;
  opacity: 0.14;
}

.book-row span {
  position: relative;
}

.book-row.ask .depth {
  background: var(--down);
}
.book-row.bid .depth {
  background: var(--up);
}
.book-row.ask .price {
  color: var(--down);
}
.book-row.bid .price {
  color: var(--up);
}

/* Shown when a feed is unreachable, in place of the data it would have held. */
.feed-note {
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-dim);
  text-align: center;
  padding: 12px 8px;
}

.book-mid {
  font-family: var(--mono);
  font-size: 13px;
  text-align: center;
  padding: 7px 0;
  margin: 4px 0;
  border-block: 1px dashed var(--line);
  color: var(--text-dim);
}

/* ---------- tape ---------- */

.tape-head,
.tape-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.9fr;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 2px 4px;
}

.tape-head {
  color: var(--text-dim);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  padding-bottom: 5px;
  margin-bottom: 4px;
}

.tape {
  /* Grows to fill its grid row; the trade buffer caps the row count. */
  overflow: hidden;
}

.tape-row span:last-child {
  color: var(--text-dim);
  text-align: right;
}

.tape-row.buy .price {
  color: var(--up);
}
.tape-row.sell .price {
  color: var(--down);
}

.tape-row.fresh {
  animation: flash 0.6s ease-out;
}

@keyframes flash {
  from {
    background: rgba(255, 255, 255, 0.07);
  }
  to {
    background: transparent;
  }
}

/* ---------- signals ---------- */

.bias {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.gauge {
  flex: 1;
}

.gauge-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  overflow: hidden;
}

.gauge-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  background: var(--text-dim);
  transition: all 0.5s ease;
}

.gauge-zero {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--line);
}

.gauge-scale {
  display: flex;
  justify-content: space-between;
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 5px;
}

.bias-read {
  text-align: right;
  min-width: 96px;
}

.bias-read strong {
  display: block;
  font-size: 14px;
}

.bias-read span {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

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

.readings li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}

.readings li:last-child {
  border-bottom: 0;
}

.readings .label {
  color: var(--text-dim);
}

.readings .value {
  font-family: var(--mono);
}

.disclaimer {
  margin: 12px 0 0;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--text-dim);
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

/* ---------- fear & greed ---------- */

.fng {
  display: flex;
  align-items: center;
  gap: 16px;
}

.fng-dial {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 700;
  background: conic-gradient(var(--down) 0deg, var(--accent) 90deg, var(--up) 180deg, var(--line) 180deg);
  position: relative;
  flex-shrink: 0;
}

.fng-dial::after {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--panel);
}

.fng-dial span {
  position: relative;
  z-index: 1;
}

.fng-read strong {
  display: block;
  font-size: 16px;
}

.fng-read span {
  font-size: 12px;
  color: var(--text-dim);
}

/* ---------- chain stats ---------- */

.stat-grid {
  display: grid;
  /* Four across in the wide slot, folding to two when the card narrows. */
  grid-template-columns: repeat(auto-fit, minmax(122px, 1fr));
  gap: 10px;
}

.stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 10px;
}

.stat span {
  display: block;
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.stat strong {
  font-family: var(--mono);
  font-size: 16px;
}

/* ---------- alerts ---------- */

.alert-form {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.alert-form select,
.alert-form input,
.alert-form button {
  font: inherit;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 9px;
  min-width: 0;
}

.alert-form input {
  flex: 1;
  font-family: var(--mono);
}

.alert-form button {
  background: var(--accent);
  border-color: var(--accent);
  color: #100d06;
  font-weight: 600;
  cursor: pointer;
}

.alert-form button:hover {
  filter: brightness(1.08);
}

.alert-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.alert-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 12px;
}

.alert-list li.triggered {
  border-color: var(--accent);
  color: var(--accent);
}

.alert-list button {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}

.alert-list button:hover {
  color: var(--down);
}

.empty {
  font-size: 12px;
  color: var(--text-dim);
  font-family: inherit;
  justify-content: center;
}

/* ---------- confluence ---------- */

.verdict {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}

.verdict-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.verdict-head strong {
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.verdict-score {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-dim);
}

.conf-meter {
  position: relative;
  height: 8px;
  margin: 10px 0 7px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  overflow: hidden;
}

.conf-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  background: var(--text-dim);
  transition: all 0.5s ease;
}

.conf-zero {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--line);
}

.conf-agree {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: var(--text-dim);
}

.conf-agree span:first-child {
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.factors {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
}

.factor {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.factor:last-child {
  border-bottom: 0;
}

.factor-name {
  font-size: 12.5px;
}

.factor-verdict {
  font-family: var(--mono);
  font-size: 12px;
  text-align: right;
}

.factor-detail {
  grid-column: 1 / -1;
  font-size: 10.5px;
  color: var(--text-dim);
}

/* Each factor carries its own signed bar, so a lone dissenter is visible
   rather than being averaged out of sight in the headline number. */
.factor-bar {
  grid-column: 1 / -1;
  position: relative;
  height: 3px;
  margin-top: 4px;
  border-radius: 2px;
  background: var(--panel-2);
}

.factor-bar i {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  border-radius: 2px;
  transition: all 0.4s ease;
}

.factor.absent {
  opacity: 0.45;
}

/* ---------- portfolio ---------- */

.pf-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.pf-stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 10px;
}

.pf-stat span {
  display: block;
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.pf-stat strong {
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.35;
}

.pf-stat em {
  font-family: var(--mono);
  font-size: 11px;
  font-style: normal;
  color: var(--text-dim);
}

/* The P&L tile carries the colour so the eye lands on it first. */
.pf-pnl.up {
  border-color: rgba(36, 201, 138, 0.4);
  background: rgba(36, 201, 138, 0.08);
}

.pf-pnl.down {
  border-color: rgba(242, 84, 91, 0.4);
  background: rgba(242, 84, 91, 0.08);
}

.pf-pnl.up strong,
.pf-pnl.up em {
  color: var(--up);
}

.pf-pnl.down strong,
.pf-pnl.down em {
  color: var(--down);
}

.pf-form {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.pf-form input {
  flex: 1 1 130px;
  min-width: 0;
  font: inherit;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 9px;
}

.pf-form button {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #100d06;
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
}

.pf-form button:hover {
  filter: brightness(1.08);
}

.pf-head,
.pf-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.1fr 28px;
  gap: 8px;
  align-items: center;
  font-family: var(--mono);
  font-size: 12px;
  padding: 5px 4px;
}

.pf-head {
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  margin-bottom: 2px;
}

.pf-row {
  border-bottom: 1px solid var(--line);
}

.pf-row:last-child {
  border-bottom: 0;
}

.pf-row button {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
  justify-self: end;
}

.pf-row button:hover {
  color: var(--down);
}

.pf-empty {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 14px 0 6px;
}

/* ---------- footer ---------- */

footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px 26px;
  max-width: 1600px;
  margin: 0 auto;
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid var(--line);
}
