:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #111827;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #60a5fa;
  --up: #22c55e;
  --down: #ef4444;
  --flat: #e5e7eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.error-banner {
  margin: 0.75rem 1.25rem 0;
  padding: 0.65rem 0.85rem;
  border: 1px solid #7f1d1d;
  border-radius: 6px;
  background: #3f1212;
  color: #fecaca;
  font-size: 0.85rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: #0d131a;
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
}

.tagline {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.75rem;
  color: var(--muted);
}

input, select, button {
  font: inherit;
}

input, select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
}

button {
  background: var(--accent);
  color: #04101f;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem 0.75rem;
}

.metrics .label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metrics .value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.05rem;
}

.price-block {
  padding: 0.75rem 0.85rem;
}

.price-block .audio-metrics {
  margin: 0.65rem 0 0;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0b0f14;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: #93c5fd;
}

.chart-panel {
  min-height: unset;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.chart-head h2 {
  margin: 0;
  font-size: 1rem;
}

.chart-meta {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
}

.chart-wrap {
  height: 240px;
  min-height: 240px;
  border: 1px solid #3b82f6;
  border-radius: 6px;
  overflow: hidden;
  background: #0b0f14;
}

.chart-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.35fr);
  gap: 1rem;
  padding: 0.85rem 1.25rem 1.25rem;
  align-items: stretch;
  min-height: calc(100vh - 7.5rem);
}

.left-stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
}

.book-panel {
  flex: 1;
  min-height: 200px;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.panel h3 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.book-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

th, td {
  text-align: left;
  padding: 0.25rem 0.35rem;
}

th {
  color: var(--muted);
  font-weight: 500;
}

.tape-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.tape-head,
.tape-row {
  display: grid;
  grid-template-columns: 9.5rem 6.5rem 4.5rem 2.5rem;
  gap: 0.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

.tape-head {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.tape {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.tape-row {
  padding: 0.15rem 0;
  white-space: nowrap;
}

.tape-row.new {
  background: rgba(59, 130, 246, 0.12);
}

.footer {
  padding: 0.6rem 1.25rem 1.2rem;
  color: var(--muted);
  font-size: 0.78rem;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
    min-height: unset;
  }

  .tape-panel {
    min-height: 420px;
  }
}