/*
 * The depth ladder.
 *
 * Read at speed, so every numeral is tabular: proportional figures make a column of
 * prices jitter as digits change, and a jittering column is one the eye has to re-find
 * on every update. The size bars are painted behind the text with a gradient rather than
 * as separate elements — one node per row, one repaint, no layout.
 */

.ladder {
  display: flex;
  flex-direction: column;
  font-variant-numeric: tabular-nums;
  font-size: var(--font-size-sm, 0.75rem);
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
}

.ladder__side {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

/* Asks stack upward so the touch of both sides meets at the spread row. */
.ladder__side--ask {
  flex-direction: column-reverse;
  justify-content: flex-start;
}

.ladder__row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-2, 0.5rem);
  padding: 0 var(--space-2, 0.5rem);
  cursor: pointer;
  isolation: isolate;
}

/* The bar is a background layer, not a node: one element per row keeps a twelve-level
   book at twelve DOM nodes per side however fast the sizes change. */
.ladder__row::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--bar, 0%);
  z-index: -1;
  transition: width 90ms linear;
}

.ladder__row--bid::before {
  background: color-mix(in srgb, var(--green) 22%, transparent);
}

.ladder__row--ask::before {
  background: color-mix(in srgb, var(--orange) 22%, transparent);
}

.ladder__row:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.ladder__price {
  font-weight: 600;
}

.ladder__row--bid .ladder__price {
  color: var(--green);
}

.ladder__row--ask .ladder__price {
  color: var(--orange);
}

.ladder__size,
.ladder__total {
  color: var(--ink-muted);
  text-align: right;
}

/* The spread row is the ladder's anchor — the one line the eye returns to. */
.ladder__spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-1, 0.25rem) var(--space-2, 0.5rem);
  border-block: 1px solid var(--line);
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  font-weight: 600;
}

.ladder__mid {
  color: var(--ink);
}

.ladder__ticks {
  color: var(--ink-muted);
  font-size: var(--font-size-xs, 0.6875rem);
}

/* A crossed book is corrupt or stale; it must look wrong, not merely be wrong. */
.ladder__spread--crossed {
  color: var(--orange);
  border-color: var(--orange);
}

@media (prefers-reduced-motion: reduce) {
  .ladder__row::before {
    transition: none;
  }
}

/*
 * The tape.
 *
 * Rows are inserted at the top constantly, so the flash animation must be
 * compositor-only: an insert that triggers layout on a 500-row list is a frame lost
 * every print, and prints are exactly what arrive fastest.
 */

.tape {
  display: flex;
  flex-direction: column;
  font-variant-numeric: tabular-nums;
  font-size: var(--font-size-sm, 0.75rem);
  height: 100%;
  overflow: hidden;
}

.tape__row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-2, 0.5rem);
  padding: 0 var(--space-2, 0.5rem);
  animation: tape-flash 240ms ease-out;
}

.tape__row--buy .tape__price {
  color: var(--green);
}

.tape__row--sell .tape__price {
  color: var(--orange);
}

.tape__time {
  color: var(--ink-muted);
}

.tape__size {
  text-align: right;
}

/* Opacity only — no width, no colour, nothing the compositor cannot do alone. */
@keyframes tape-flash {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tape__row {
    animation: none;
  }
}

/*
 * The imbalance gauge.
 *
 * A split bar rather than a needle: the eye reads "which half is bigger" faster than it
 * reads a position on a scale, and at scalping speed that difference is the whole value
 * of the indicator.
 */

.gauge {
  position: relative;
  display: flex;
  height: 0.75rem;
  border: 1px solid var(--line);
  overflow: hidden;
  flex: 0 0 auto;
}

.gauge__seg {
  display: block;
  height: 100%;
  transition: width 120ms linear;
}

.gauge__seg--bid {
  background: color-mix(in srgb, var(--green) 60%, transparent);
}

.gauge__seg--ask {
  background: color-mix(in srgb, var(--orange) 60%, transparent);
}

.gauge__label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: var(--font-size-xs, 0.6875rem);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  mix-blend-mode: difference;
}

/* Past the threshold the gauge glows — unmissable in peripheral vision, which is where
   pressure needs to register while the eye is on the tape. */
.gauge--hot {
  box-shadow: 0 0 8px color-mix(in srgb, var(--green) 50%, transparent);
  border-color: var(--green);
}

@media (prefers-reduced-motion: reduce) {
  .gauge__seg {
    transition: none;
  }
}

/*
 * Whales.
 *
 * One pulse cycle, on compositor-only properties. A whale must grab the eye and then
 * get out of the way — a permanently glowing row is one the eye learns to ignore, which
 * defeats the point.
 */

.ladder__row--whale,
.tape__row--whale {
  animation: whale-pulse 700ms ease-out 1;
  font-weight: 700;
}

.ladder__row--whale::after,
.tape__row--whale::after {
  content: '◆';
  position: absolute;
  right: 2px;
  font-size: var(--font-size-xs, 0.6875rem);
  opacity: 0.8;
}

.tape__row--whale {
  position: relative;
}

@keyframes whale-pulse {
  0% {
    opacity: 0.4;
    transform: scale(1.02);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ladder__row--whale,
  .tape__row--whale {
    animation: none;
  }
}

.ladder__groups {
  display: flex;
  gap: var(--space-1, 0.25rem);
  padding-block: var(--space-1, 0.25rem);
  flex: 0 0 auto;
}

.tape__bar {
  display: flex;
  align-items: center;
  gap: var(--space-1, 0.25rem);
  padding-block: var(--space-1, 0.25rem);
  flex: 0 0 auto;
}

/* The badge answers the question a noise floor creates: how much am I not seeing. */
.tape__hidden {
  margin-left: auto;
  color: var(--ink-muted);
  font-size: var(--font-size-xs, 0.6875rem);
  font-variant-numeric: tabular-nums;
}

/* Spacers stand in for the rows not in the DOM, so the scrollbar reflects the whole
   tape rather than the thirty rows currently rendered. */
.tape__spacer {
  flex: 0 0 auto;
}

.tape__rows {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/*
 * A degraded book is dimmed and its rows stop being click targets. The prefill action
 * refuses these clicks anyway; the cursor says so before the click happens.
 */
.ladder--degraded {
  opacity: 0.55;
}

.ladder--degraded .ladder__row {
  cursor: not-allowed;
}

.chip--warn {
  color: var(--orange);
  border-color: var(--orange);
}
