:root {
  --bg: #f5f1e8;
  --bg-dark: #ebe3d9;
  --card: #ffffff;
  --ink: #1f1b16;
  --muted: #6b5f54;
  --accent: #1f6f5b;
  --accent-soft: rgba(31, 111, 91, 0.12);
  --danger: #b0413e;
  --bid: #16736a;
  --ask: #c15a2b;
  --flow-green: #1f6f5b;
  --flow-red: #c15a2b;
  --flow-yellow: #d0a12a;
  --shadow: 0 16px 40px rgba(26, 22, 18, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 15% 20%, #f9f4ed, #efe7db 45%, #e6dccd 100%);
  min-height: 100vh;
  position: relative;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(31, 27, 22, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 27, 22, 0.04) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
  opacity: 0.35;
  z-index: 0;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #8c8c8c;
}

.status-dot.ok {
  background: var(--accent);
}

.status-dot.bad {
  background: var(--danger);
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.layout {
  position: relative;
  z-index: 1;
  padding: 16px;
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr 20vw;
  min-height: 100vh;
}

.left-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid #e3d7c9;
}

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

.card h2,
.card h3 {
  margin: 0;
}

.controls {
  padding: 12px 14px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  align-items: end;
}

.controls label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

input {
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid #d8cbb9;
  background: #fff;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.mode {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.mode-buttons {
  display: flex;
  gap: 8px;
}

button {
  border: none;
  padding: 6px 10px;
  border-radius: 999px;
  background: #e9dfd1;
  font-weight: 600;
  cursor: pointer;
  font-size: 11px;
}

button.active {
  background: var(--accent);
  color: white;
}

.controls-meta {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  font-family: "IBM Plex Mono", monospace;
  align-items: center;
}

.controls-meta .label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.chart {
  padding: 10px 12px;
  height: 720px;
}

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

.book {
  grid-column: 2 / 3;
  height: calc(100vh - 32px);
  position: sticky;
  top: 16px;
  align-self: start;
}

.book-shell {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  height: 100%;
  align-items: stretch;
}

.flow-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  height: 100%;
}

.runway-value {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.runway-value.green {
  color: var(--flow-green);
}

.runway-value.red {
  color: var(--flow-red);
}

.runway-value.yellow {
  color: var(--flow-yellow);
}

.flow-bar {
  position: relative;
  width: 18px;
  flex: 1 1 0;
  border-radius: 10px;
  background: rgba(31, 27, 22, 0.08);
  border: 1px solid rgba(31, 27, 22, 0.15);
  overflow: hidden;
  --flow-up: 0%;
  --flow-down: 0%;
  --flow-color: var(--flow-yellow);
}

.flow-bar.green {
  --flow-color: var(--flow-green);
}

.flow-bar.red {
  --flow-color: var(--flow-red);
}

.flow-bar.yellow {
  --flow-color: var(--flow-yellow);
}

.flow-bar-fill {
  position: absolute;
  left: 0;
  right: 0;
  background: var(--flow-color);
  opacity: 0.95;
}

.flow-bar-fill.up {
  bottom: 50%;
  height: var(--flow-up);
}

.flow-bar-fill.down {
  top: 50%;
  height: var(--flow-down);
}

.flow-bar-zero {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: rgba(31, 27, 22, 0.45);
}

.book-vertical {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

.book-half {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 0;
  min-height: 0;
}

.book-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.book-list {
  display: grid;
  gap: 6px;
  overflow: auto;
  flex: 1 1 0;
  min-height: 0;
}

.book-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 6px 8px;
  height: 24px;
  border-radius: 8px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(31, 27, 22, 0.08);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.65);
}

.book-row .bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--bar, 0%);
  opacity: 0.85;
  z-index: 0;
  transition: width 0.35s ease;
  background: rgba(31, 111, 91, 0.9);
}

.book-row span {
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.book-row.ask .bar {
  left: auto;
  right: 0;
  background: rgba(193, 90, 43, 0.9);
}

.book-row.bid {
  background: rgba(31, 111, 91, 0.14);
}

.book-row.ask {
  background: rgba(193, 90, 43, 0.14);
}

.book-row.bid span:first-child {
  color: var(--bid);
  font-weight: 600;
}

.book-row.ask span:first-child {
  color: var(--ask);
  font-weight: 600;
}

.book-row.is-top {
  box-shadow: 0 0 0 1px rgba(31, 27, 22, 0.35) inset;
}

.book-row.delta-up {
  background: rgba(31, 111, 91, 0.12);
  animation: flash-up 0.6s ease;
}

.book-row.delta-down {
  background: rgba(193, 90, 43, 0.12);
  animation: flash-down 0.6s ease;
}

@keyframes flash-up {
  0% {
    background: rgba(31, 111, 91, 0.35);
  }
  100% {
    background: rgba(31, 111, 91, 0.12);
  }
}

@keyframes flash-down {
  0% {
    background: rgba(193, 90, 43, 0.35);
  }
  100% {
    background: rgba(193, 90, 43, 0.12);
  }
}

.book-mid {
  background: linear-gradient(120deg, #efe4d6, #f4ede4);
  border-radius: 16px;
  padding: 12px;
  font-family: "IBM Plex Mono", monospace;
  display: grid;
  gap: 10px;
  border: 1px solid #e0d2c2;
}

.mid-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.badges {
  display: flex;
  gap: 8px;
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.badge.ghost {
  background: #efe7dc;
  color: var(--muted);
}

.tape {
  grid-column: 1 / 2;
}

.tape-list {
  display: grid;
  gap: 8px;
  max-height: 480px;
  overflow: auto;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.tape-row {
  display: grid;
  grid-template-columns: auto auto auto;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 8px;
  background: #f3ece2;
}

.tape-row.buy {
  color: var(--bid);
}

.tape-row.sell {
  color: var(--ask);
}

.impact {
  grid-column: 1 / 2;
}

.impact-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.impact-box {
  background: #f6efe6;
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.impact-box.buy {
  border-left: 4px solid var(--bid);
}

.impact-box.sell {
  border-left: 4px solid var(--ask);
}

.metric {
  display: flex;
  justify-content: space-between;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: #2d2620;
}

.metrics {
  grid-column: 1 / 2;
}

.metrics-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .left-col,
  .book,
  .controls,
  .chart,
  .impact,
  .metrics {
    grid-column: 1 / -1;
  }

  .book {
    position: static;
    height: auto;
    grid-row: auto;
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .layout {
    padding: 16px;
  }
}
