:root {
  color-scheme: dark;
  --bg: #07090c;
  --panel: #0a0d11;
  --panel-2: #0e1217;
  --chrome: #0b0e12;
  --input: #080b0f;
  --line: #1b222b;
  --line-bright: #2b3541;
  --text: #d7dde4;
  --ink: #eef2f6;
  --muted: #687482;
  --dim: #5a6570;
  --bid: #19d3c5;
  --ask: #e93bd0;
  --buy: #2de28c;
  --sell: #ff5b69;
  --accent: #f0c86b;
  --brand: #a5f3fc;
  --desk-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  font: 10px/1.25 var(--desk-mono);
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.desk-bar {
  display: flex;
  gap: 4px 8px;
  align-items: center;
  flex-wrap: nowrap;
  min-height: 28px;
  padding: 3px 7px;
  border-bottom: 1px solid var(--line);
  background: var(--chrome);
  user-select: none;
  flex: 0 0 auto;
}

.desk-brand {
  padding-right: 8px;
  border-right: 1px solid var(--line);
  font-size: 10px;
  letter-spacing: .04em;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.desk-brand-mark {
  width: 15px;
  height: 15px;
  display: inline-grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--brand) 45%, transparent);
  color: var(--brand);
  font-size: 8px;
  font-weight: 800;
}

.desk-brand strong {
  color: var(--ink);
  font-size: 10px;
}

.desk-brand small {
  color: var(--bid);
  font-size: 8px;
  font-weight: 500;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: 9px;
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex: 0 0 auto;
}

.pill.ok { color: var(--text); }
.pill.ok::before { background: var(--buy); }
.pill.warn { color: var(--accent); }
.pill.warn::before { background: var(--accent); }
.pill.bad { color: var(--sell); }
.pill.bad::before { background: var(--sell); }
#desk-count::before { background: var(--bid); box-shadow: none; }

form.add { margin-left: auto; display: flex; height: 21px; }

input, button {
  font: inherit;
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--line-bright);
  border-radius: 0;
  outline: none;
}

input { height: 21px; padding: 0 6px; width: 126px; }
input:focus { border-color: var(--bid); }
button { height: 21px; padding: 0 6px; cursor: pointer; background: transparent; color: var(--muted); }
button:hover { color: var(--text); border-color: var(--line-bright); }
form.add button { color: var(--bid); border-left: 0; }
button.ghost { height: 18px; padding: 0 4px; background: transparent; color: var(--muted); border-color: var(--line); }
.action-button { font-size: 8px; letter-spacing: .04em; }

#desk-board {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 3px;
  padding: 3px;
  grid-template-columns: repeat(var(--desk-columns, 1), minmax(290px, 1fr));
  grid-template-rows: minmax(0, 1fr);
  overflow-x: auto;
  overflow-y: hidden;
}

.card {
  container: desk-card / inline-size;
  background: var(--panel);
  border: 1px solid var(--line-bright);
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card.crossed { box-shadow: inset 0 0 0 1px var(--sell); }

.hd {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 3px 5px 2px;
  border-bottom: 1px solid var(--line);
}

.sym { font-size: 10px; font-weight: 700; letter-spacing: .04em; color: var(--ink); }
.last { font-size: 11px; font-weight: 650; white-space: nowrap; }
.last .k, .k { font-size: 8px; font-weight: 500; color: var(--dim); letter-spacing: .02em; }
.up { color: var(--buy); }
.down { color: var(--sell); }

.basis {
  display: block;
  padding: 2px 5px;
  color: var(--dim);
  font-size: 8px;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--line);
}

.basis span + span { margin-left: 7px; }
.basis b {
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
  font-size: 9px;
  color: var(--text);
}

.account-viz {
  flex: 0 0 auto;
  max-height: 78px;
  overflow: auto;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel-2) 72%, transparent);
}

.account-hd,
.acct-more {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 5px 1px;
  color: var(--dim);
  font-size: 7px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.acct-row {
  padding: 0 5px 1px;
  font-size: 8px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.acct-row.is-long { color: var(--bid); }
.acct-row.is-short,
.acct-row.is-sl { color: color-mix(in srgb, var(--ask) 55%, var(--bid)); }
.acct-row.is-buy { color: var(--buy); }
.acct-row.is-sell { color: var(--sell); }
.acct-row.is-tp { color: var(--accent); }

.user-mark {
  margin-left: 3px;
  color: var(--accent);
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0;
}

.chart-shell {
  flex: 0 0 clamp(145px, 25%, 235px);
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 20px minmax(0, 1fr);
  border-bottom: 1px solid var(--line-bright);
  background: var(--panel);
  overflow: hidden;
}

.chart-bar {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 4px;
  border-bottom: 1px solid var(--line);
  color: var(--dim);
  font-size: 7px;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.chart-bar strong { color: var(--text); font-size: 8px; }
.chart-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-zoom,
.chart-range {
  height: 17px;
  padding: 0 2px;
  border: 1px solid var(--line);
  background: var(--input);
  color: var(--text);
  font: 7px var(--desk-mono);
}
.chart-zoom { width: 40px; margin-left: auto; }
.chart-range { width: 56px; }

.price-chart {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.venues {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.venue-list {
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  align-content: start;
  font-size: 8px;
  font-variant-numeric: tabular-nums lining-nums;
}

.venue-row {
  width: 100%;
  height: 14px;
  min-height: 14px;
  max-height: 14px;
  min-width: 0;
  flex: 0 0 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 4.6ch 11ch 6.4ch 5.2ch;
  align-items: center;
  column-gap: 4px;
  padding: 0 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 8px;
  line-height: 14px;
  text-align: right;
  overflow: hidden;
}

.venue-row:hover { background: var(--panel-2); }
.venue-row.is-selected { background: var(--panel-2); box-shadow: inset 2px 0 var(--accent); }
.venue-row.is-stale, .venue-row.is-offline { color: var(--dim); }
.venue-row.is-crossed .venue-price { color: var(--sell); }
.venue-name,
.venue-kind,
.venue-price,
.venue-spread,
.venue-status {
  min-width: 0;
  overflow: hidden;
  text-overflow: clip;
  white-space: pre;
  font-variant-numeric: tabular-nums lining-nums;
}
.venue-name {
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0;
}
.venue-kind {
  color: var(--dim);
  text-align: left;
  text-transform: uppercase;
  font-size: 7px;
  letter-spacing: 0;
}
.venue-price { color: var(--ink); font-weight: 650; text-align: right; }
.venue-spread { color: var(--muted); text-align: right; }
.venue-status {
  color: var(--dim);
  font-size: 7px;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0;
}
.venue-row.is-live .venue-status { color: var(--buy); }
.venue-row.is-partial .venue-status { color: var(--accent); }
.venue-row.has-tape:not(.is-live) .venue-status { color: var(--bid); }

.venue-detail {
  min-width: 0;
  min-height: 0;
  border-top: 1px solid var(--line-bright);
  background: var(--panel-2);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

.venue-hd {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  padding: 2px 4px;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.venue-hd b { color: var(--ink); font-weight: 650; letter-spacing: 0; text-transform: none; font-size: 10px; }
.kind { color: var(--dim); font-style: normal; }

.meta {
  display: flex;
  gap: 0 5px;
  padding: 0 4px 2px;
  color: var(--dim);
  font-size: 7px;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.meta b { color: var(--text); font-weight: 600; letter-spacing: 0; text-transform: none; font-size: 8px; }

.microstructure {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(105px, .9fr);
  border-top: 1px solid var(--line);
  overflow: hidden;
}

.book-pane,
.tape-pane {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.book-pane {
  display: grid;
  grid-template-rows: 15px minmax(0, 1fr) auto;
  border-right: 1px solid var(--line-bright);
}

.book-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 4px 0;
  color: var(--dim);
  font-size: 7px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.book {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr) 14px minmax(0, 1fr);
  padding: 0;
  font-size: 9px;
  min-height: 0;
}

.book .col {
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(6, minmax(0, 1fr));
}

.row {
  width: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6.5ch;
  justify-content: stretch;
  gap: 4px;
  align-items: center;
  padding: 0 4px;
  position: relative;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  overflow: hidden;
  font-variant-numeric: tabular-nums lining-nums;
}

.row i {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  opacity: 0.14;
  pointer-events: none;
}

.asks .row { color: var(--ask); }
.asks .row i { background: var(--ask); }
.bids .row { color: var(--bid); }
.bids .row i { background: var(--bid); }
.row.has-order.is-buy { background: color-mix(in srgb, var(--buy) 16%, transparent); }
.row.has-order.is-sell { background: color-mix(in srgb, var(--sell) 16%, transparent); }
.row.has-order.is-tp { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.row.has-order.is-sl { background: color-mix(in srgb, var(--ask) 14%, transparent); }
.row.has-position.is-long {
  background: color-mix(in srgb, var(--bid) 16%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bid) 80%, transparent);
}
.row.has-position.is-short {
  background: color-mix(in srgb, var(--ask) 14%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ask) 70%, var(--bid));
}
.row.has-order::after,
.row.has-position::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
}
.row.has-order.is-buy::after { background: var(--buy); }
.row.has-order.is-sell::after { background: var(--sell); }
.row.has-order.is-tp::after { background: var(--accent); }
.row.has-order.is-sl::after,
.row.has-position.is-short::after { background: color-mix(in srgb, var(--ask) 55%, var(--bid)); }
.row.has-position.is-long::after { background: var(--bid); }
.row span { position: relative; white-space: pre; overflow: hidden; text-align: right; }

.book-mid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 5px;
  padding: 0 5px;
  border-top: 1px solid var(--line-bright);
  border-bottom: 1px solid var(--line-bright);
  color: var(--dim);
  font-size: 7px;
  letter-spacing: .08em;
}

.book-mid span:last-child { text-align: right; }
.book-mid b { color: var(--text); font-size: 8px; font-weight: 600; }

.near, .flow {
  display: flex;
  flex-wrap: wrap;
  gap: 0 5px;
  padding: 1px 4px;
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: 7px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.near b, .flow b { letter-spacing: 0; text-transform: none; font-size: 8px; font-weight: 650; }
.bidc { color: var(--bid); }
.askc { color: var(--ask); }

.tape-pane {
  display: grid;
  grid-template-rows: 17px 12px minmax(0, 1fr);
}

.tape-hd {
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3px;
  padding: 0 4px;
  color: var(--dim);
  font-size: 7px;
  letter-spacing: .06em;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.tape-hd > span:first-child { color: var(--text); font-weight: 700; }
.tape-hd > span:first-child b {
  margin-left: 2px;
  font-size: 7px;
  font-weight: 650;
  letter-spacing: 0;
}
.tape-stats { display: flex; align-items: center; gap: 3px; font-size: 6px; letter-spacing: 0; }
.tape-stats b { font-weight: 650; }
.tape-stats span { color: var(--dim); }
.tape-buy-bias {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 1px;
  background: var(--buy);
  box-shadow: 100vw 0 var(--sell);
  opacity: .65;
}

.tape-cols,
.tape-row {
  width: 100%;
  display: grid;
  grid-template-columns: 5ch minmax(0, 1fr) 6ch 4.2ch;
  gap: 3px;
  align-items: center;
  padding: 0 3px;
  font-variant-numeric: tabular-nums lining-nums;
}

.tape-cols {
  color: var(--dim);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 6px;
  letter-spacing: .05em;
  text-align: right;
}
.tape-cols span:first-child { text-align: left; }

.tape {
  min-height: 0;
  /* A busy venue can easily have more recent prints than fit in this pane.
     Keep those rows reachable instead of silently clipping them at the
     bottom edge. */
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  padding: 0;
  font-size: 7px;
  line-height: 1;
  background: var(--panel-2);
  display: grid;
  grid-auto-flow: row;
  grid-auto-rows: 11px;
  align-content: start;
}

.tape::-webkit-scrollbar { width: 6px; }
.tape::-webkit-scrollbar-thumb { background: var(--line-bright); }

.tape-row {
  min-height: 0;
  position: relative;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
  overflow: hidden;
}
.tape-row:nth-child(even) { background: color-mix(in srgb, var(--panel) 48%, transparent); }
.tape-row > span { position: relative; z-index: 1; text-align: right; white-space: pre; overflow: hidden; }
.tape-row .tape-time { color: var(--dim); text-align: left; }
.tape-row .tape-size { color: var(--text); }
.tape-row .tape-venue { color: var(--dim); font-size: 6px; }
.tape-row.is-large .tape-size { color: var(--accent); font-weight: 700; }
.tape-row.is-liquidation > span { color: var(--accent); }
.tape-size-bar {
  position: absolute;
  z-index: 0;
  right: 0;
  top: 1px;
  bottom: 1px;
  background: var(--buy);
  opacity: .1;
  pointer-events: none;
}
.tape-row.down .tape-size-bar { background: var(--sell); }
.tape-row.is-liquidation .tape-size-bar { background: var(--accent); opacity: .16; }
.tape-row.is-hot { animation: tape-flash .7s ease-out; }
@keyframes tape-flash {
  from { background: color-mix(in srgb, currentColor 28%, transparent); }
  to { background: transparent; }
}
.tape > .empty { display: grid; grid-template-columns: 1fr; place-items: center; }
.empty { color: var(--dim); padding: 8px; letter-spacing: .08em; font-size: 8px; }

@container desk-card (max-width: 245px) {
  .basis span:nth-child(2), .basis span:nth-child(4) { display: none; }
  .near { display: none; }
  .chart-shell { min-height: 90px; }
}

@container desk-card (max-width: 380px) {
  .tape-cols,
  .tape-row { grid-template-columns: 4.4ch minmax(0, 1fr) 5.4ch; }
  .tape-cols span:last-child,
  .tape-venue { display: none; }
  .tape-stats span { display: none; }
}

@media (max-width: 1100px) {
  #desk-board { grid-template-columns: repeat(var(--desk-columns, 1), minmax(290px, 1fr)); }
}

@media (max-width: 760px) {
  .desk-bar { flex-wrap: wrap; }
}

@media (pointer: coarse) {
  .chart-zoom, .chart-range { min-height: 22px; }
}
