:root {
  --bg: #0d1017;
  --panel: #151a23;
  --line: #262d3a;
  --text: #e6e9ef;
  --muted: #8a93a6;
  --up: #16a34a;
  --down: #dc2626;
  --flat: #3a404d;
  --accent: #4f8cff;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.home { display: inline-flex; align-items: center; gap: 8px; padding: 3px 6px; margin-left: -6px; border-radius: 6px; color: var(--text); text-decoration: none; }
.home:hover { background: var(--line); }
.home:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tabs { display: inline-flex; gap: 2px; margin-left: 8px; padding: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; font-size: 13px; }
.tabs a { color: var(--muted); text-decoration: none; padding: 3px 10px; border-radius: 5px; }
.tabs a:hover { color: var(--text); }
.tabs a.on { background: var(--line); color: var(--text); }
.logo {
  width: 18px; height: 18px; border-radius: 3px;
  background:
    linear-gradient(var(--up), var(--up)) 0 0 / 55% 62% no-repeat,
    linear-gradient(var(--down), var(--down)) 100% 0 / 40% 38% no-repeat,
    linear-gradient(var(--up), var(--up)) 100% 100% / 40% 56% no-repeat,
    linear-gradient(var(--down), var(--down)) 0 100% / 55% 32% no-repeat;
}

.stats { display: flex; gap: 12px; color: var(--muted); white-space: nowrap; }
.stats em { font-style: normal; }

/* Fear & Greed tachometer (needle angle set by Heatmap.setFearGreed) */
.fg { display: inline-flex; align-items: center; gap: 5px; flex: none; color: var(--muted); }
.fg-dial { width: 26px; height: 15px; overflow: visible; }
.fg-dial path { fill: none; stroke-width: 6; stroke-linecap: butt; }
.fg-needle { transition: transform .8s cubic-bezier(.3, 1.4, .5, 1); transform-origin: 32px 32px; }
.fg-needle line { stroke: var(--text); stroke-width: 2.5; stroke-linecap: round; }
.fg-dial circle { fill: var(--text); }
/* Same scale as the other header stats: bold value, muted label, one line */
.fg-text { display: inline-flex; align-items: baseline; gap: 4px; white-space: nowrap; }
.fg-text b { font-weight: 600; font-variant-numeric: tabular-nums; }
.fg-text em { font-style: normal; }
.stats b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.controls {
  display: flex; align-items: center; gap: 6px;
  margin-left: auto; flex-wrap: wrap;
}

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.chk { white-space: nowrap; }
.seg button, .btn, select, input[type="search"] {
  background: transparent;
  color: var(--text);
  border: 0;
  font: inherit;
  padding: 5px 10px;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.btn, select, input[type="search"] { border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
select option { background: var(--panel); }
input[type="search"] { width: 104px; cursor: text; }
input[type="search"]:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }

.chk { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); cursor: pointer; user-select: none; }

/* Signal bars: latency up to 60 min (see Heatmap.setSignal) */
.sig { display: inline-flex; align-items: flex-end; gap: 2px; height: 18px; }
.sig b { width: 4px; border-radius: 1px; background: var(--line); }
.sig b:nth-child(1) { height: 20%; }
.sig b:nth-child(2) { height: 40%; }
.sig b:nth-child(3) { height: 60%; }
.sig b:nth-child(4) { height: 80%; }
.sig b:nth-child(5) { height: 100%; }
.sig[data-level="1"] b:nth-child(-n+1), .sig[data-level="2"] b:nth-child(-n+2), .sig[data-level="3"] b:nth-child(-n+3),
.sig[data-level="4"] b:nth-child(-n+4), .sig[data-level="5"] b:nth-child(-n+5) { background: var(--sig); }
.sig[data-level="0"] b { background: color-mix(in srgb, var(--sig, #ef4444) 35%, var(--line)); }
.sig.sm { height: 14px; gap: 1.5px; }
.sig.sm b { width: 3px; }
.lag { color: var(--text); font-variant-numeric: tabular-nums; }
.lag-sep { color: var(--line); }
.lag-delayed { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.lag-delayed[hidden] { display: none; }
.live { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); min-width: 70px; background: none; border: 0; font: inherit; cursor: pointer; padding: 4px 2px; font-variant-numeric: tabular-nums; }
.live:hover { color: var(--text); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #a16207; flex: none; }
.live.ok i { background: var(--up); box-shadow: 0 0 0 0 rgba(22, 163, 74, .6); animation: pulse 2s infinite; }
.live.bad i { background: var(--down); }

/* Latency histogram in the sources panel */
.lat-hist { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; align-items: end; height: 64px; margin: 16px 0 2px; }
.lat-hist div { position: relative; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.lat-hist i { display: block; min-height: 2px; border-radius: 2px 2px 0 0; background: var(--c); }
.lat-hist span { position: absolute; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--text); }
.lat-axis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; font-size: 10px; color: var(--muted); text-align: center; margin-bottom: 8px; }
@keyframes pulse { 70% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); } 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); } }

main { position: relative; flex: 1; min-height: 0; }

/* ---------- Detail pane (splits down from the top) ---------- */
.split { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.detail {
  flex: none; height: 0; overflow: hidden;
  background: var(--panel);
  border-bottom: 1px solid transparent;
  transition: height .3s ease, border-color .3s;
}
.detail.open { height: clamp(320px, 50vh, 480px); border-bottom-color: var(--line); }
@media (prefers-reduced-motion: reduce) { .detail { transition: none; } }
.d-wrap { height: 100%; display: flex; flex-direction: column; gap: 8px; padding: 10px 16px 12px; }
.d-top { display: flex; align-items: flex-start; gap: 12px; }
.d-head { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; }
.d-head img { width: 32px; height: 32px; border-radius: 50%; }
.d-name { display: flex; flex-direction: column; line-height: 1.2; }
.d-name b { font-size: 16px; }
.d-name small { color: var(--muted); }
.d-price { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; transition: color .4s; }
.d-price.up { color: #22c55e; }
.d-price.down { color: #ef4444; }
.chip {
  padding: 2px 8px; border-radius: 999px; font-size: 12px;
  background: var(--bg); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.chip em { font-style: normal; color: var(--muted); margin-right: 4px; }
.d-close {
  flex: none; width: 30px; height: 30px; padding: 0;
  background: none; color: var(--muted); border: 1px solid var(--line); border-radius: 6px;
  font-size: 20px; line-height: 1; cursor: pointer;
}
.d-close:hover { color: var(--text); }
.d-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; }
.d-right { display: grid; grid-template-columns: 280px 320px; gap: 16px; min-height: 0; }

/* Order book */
.d-book { display: flex; flex-direction: column; min-height: 0; font-size: 12px; font-variant-numeric: tabular-nums; }
.d-book[hidden] { display: none; }
.b-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.b-head h4 { margin: 0; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.b-venue { padding: 1px 4px; font-size: 12px; }
.b-venue[hidden] { display: none; }
.b-pair { margin-left: auto; color: var(--muted); font-size: 11px; }
.b-cols, .b-row { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 6px; }
.b-cols { color: var(--muted); padding: 2px 4px; border-bottom: 1px solid var(--line); }
.b-cols[hidden] { display: none; }
.b-cols span:not(:first-child), .b-row span:not(:first-child) { text-align: right; }
.b-asks, .b-bids { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.b-asks { justify-content: flex-end; }
.b-row { height: 17px; line-height: 17px; padding: 0 4px; }
.b-row.ask { background: linear-gradient(to left, rgba(220, 38, 38, .16) var(--d), transparent var(--d)); }
.b-row.bid { background: linear-gradient(to left, rgba(22, 163, 74, .16) var(--d), transparent var(--d)); }
.b-row.ask span:first-child { color: #ef4444; }
.b-row.bid span:first-child { color: #22c55e; }
.b-mid { display: flex; align-items: baseline; gap: 8px; padding: 3px 4px; border-block: 1px solid var(--line); }
.b-mid b { font-size: 15px; transition: color .3s; }
.b-mid b.up { color: #22c55e; }
.b-mid b.down { color: #ef4444; }
.b-mid span { color: var(--muted); font-size: 11px; margin-left: auto; }
.b-imb {
  position: relative; height: 14px; margin-top: 4px; border-radius: 3px; overflow: hidden;
  background: linear-gradient(90deg, rgba(22, 163, 74, .55) var(--b, 50%), rgba(220, 38, 38, .55) var(--b, 50%));
}
.b-imb::after { content: attr(data-label); position: absolute; inset: 0; text-align: center; font-size: 10px; line-height: 14px; color: #fff; }
.b-imb i { display: none; }
.b-note { margin: 8px 0 0; color: var(--muted); }
.b-note[hidden] { display: none; }
.d-chart { position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.d-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.d-src { color: var(--muted); font-size: 12px; }
.d-canvas { flex: 1; min-height: 0; min-width: 0; overflow: hidden; }
.d-overlay { position: absolute; pointer-events: none; }
.d-liqbtn { padding: 3px 9px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; }
.d-liqbtn.on { color: var(--text); border-color: rgba(239, 68, 68, .5); background: linear-gradient(90deg, rgba(239, 68, 68, .18), rgba(34, 197, 94, .18)); }
.d-liqbtn[hidden] { display: none; }
.d-msg { position: absolute; inset: 36px 0 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.d-msg[hidden] { display: none; }
.d-side { min-height: 0; overflow: auto; font-variant-numeric: tabular-nums; }
.d-side h4 { margin: 2px 0 6px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.d-side dl { display: grid; grid-template-columns: auto auto; gap: 3px 12px; margin: 0 0 12px; }
.d-side dt { color: var(--muted); }
.d-side dd { margin: 0; text-align: right; }
.d-side table { width: 100%; border-collapse: collapse; font-size: 12px; }
.d-side th { text-align: left; color: var(--muted); font-weight: 500; padding: 2px 0; border-bottom: 1px solid var(--line); }
.d-side td { padding: 2px 0; }
.d-side th:not(:first-child), .d-side td:not(:first-child) { text-align: right; }
.d-side tr.sel td { color: #fbbf24; }
.d-side tr.stale td { opacity: .45; }
@media (max-width: 1280px) {
  .d-right { grid-template-columns: 300px; grid-auto-rows: max-content; overflow: auto; }
  .d-book { height: 330px; }
  .d-side { overflow: visible; }
}
@media (max-width: 900px) {
  .detail.open { height: 62vh; }
  .d-right { grid-template-columns: minmax(0, 1fr); overflow: visible; }
  .d-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(200px, 1fr) auto; overflow: auto; }
  .d-side { overflow: visible; }
}
canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
canvas.dragging { cursor: grabbing; }
canvas.pointer { cursor: pointer; }

.empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--muted); font-size: 15px;
  pointer-events: none;
}
.empty[hidden], .tip[hidden], .sources[hidden] { display: none; }
.src-col { min-width: 0; }
@media (max-width: 800px) { .sources { grid-template-columns: 1fr; width: 380px; } }

.sources {
  /* Anchored under the Live button by JS (top/right); page-level so the detail pane can't push it down */
  position: fixed; top: 56px; right: 16px; z-index: 20;
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
  width: 720px; max-width: calc(100vw - 32px); max-height: calc(100vh - 72px); overflow: auto;
  padding: 12px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .75), 0 6px 18px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .04);
  font-variant-numeric: tabular-nums;
}
.src-sum { display: flex; justify-content: space-between; color: var(--muted); margin-bottom: 8px; }
.src-sum b { color: var(--text); }
.sources table { width: 100%; border-collapse: collapse; }
.sources th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 4px 0; }
.sources td { padding: 2px 0; }
.sources th:nth-child(n+3), .sources td:nth-child(n+3) { text-align: right; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.ok { background: var(--up); }
.dot.poll { background: #eab308; }
.dot.bad { background: var(--down); }
.src-note { color: var(--muted); font-size: 11px; margin: 8px 0 0; }
.src-h { margin: 14px 0 4px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

.tip {
  position: absolute; z-index: 2;
  min-width: 220px; padding: 10px 12px;
  background: rgba(21, 26, 35, .97);
  border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.tip header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tip header img { width: 22px; height: 22px; border-radius: 50%; }
.tip header small { color: var(--muted); }
.tip .price { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.tip .tag { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 4px; background: var(--line); color: var(--muted); font-size: 11px; }
.tip dl + dl { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
.tip dl { display: grid; grid-template-columns: auto auto; gap: 2px 16px; margin: 0; }
.tip dt { color: var(--muted); }
.tip dd { margin: 0; text-align: right; }
.up { color: #22c55e; }
.down { color: #ef4444; }

.foot { border-top: 1px solid var(--line); border-bottom: 0; color: var(--muted); font-size: 12px; padding: 6px 16px; }
.foot a { color: var(--muted); }
.legend { display: flex; align-items: center; gap: 6px; }
.ramp {
  width: 160px; height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, #c81e1e, #7a3434 37.5%, var(--flat), #2b6a42 62.5%, #16a34a);
}
.hint { margin-left: auto; }

/* Keep the header to one row: header stats give way to controls as the window narrows */
@media (max-width: 1800px) { .stats span:nth-child(3) { display: none; } } /* Up/Down */
@media (max-width: 1700px) { .stats span:nth-child(2) { display: none; } } /* BTC dom. / Open interest */
@media (max-width: 1560px) { .stats { display: none; } }                     /* market cap is in the tab title */
@media (max-width: 900px) {
  .stats, .hint { display: none; }
  .controls { margin-left: 0; }
}
