:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f3f7;
  --text: #111827;
  --muted: #6b7280;
  --line: #d9dee7;
  --blue: #007aff;
  --green: #17803d;
  --red: #c7362f;
  --orange: #b85b00;
  --shadow: 0 16px 42px rgba(29, 42, 68, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #181b21;
    --panel-2: #20242d;
    --text: #f4f6fb;
    --muted: #9ba3b1;
    --line: #303642;
    --blue: #2997ff;
    --green: #42d17b;
    --red: #ff6b63;
    --orange: #ffad4d;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--blue);
}

.shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.topbar,
.section-head,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
}

.section-head p,
.risk-grid,
small {
  color: var(--muted);
}

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

.actions button {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 18px;
}

.status-strip,
.sim-panel,
.risk-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  overflow: hidden;
  margin-bottom: 12px;
}

.status-strip div {
  min-width: 0;
  background: var(--panel);
  padding: 14px 16px;
}

.status-strip span,
.sim-output span {
  display: block;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
}

.status-strip small,
.sim-output small {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}

.sim-panel {
  padding: 16px;
  margin-bottom: 20px;
}

.panel-head {
  margin-bottom: 12px;
}

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

.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

label {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
}

.sim-output {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.sim-output div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-2);
}

.section-head {
  margin: 20px 0 12px;
}

.section-head.compact {
  margin-top: 28px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 150px;
  gap: 8px;
}

.filters input,
.filters select {
  margin: 0;
}

.route-list,
.universe-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.route-card,
.market-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.route-card {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(280px, 1.6fr);
  gap: 12px;
  padding: 14px;
}

.route-card.selected {
  border-color: var(--blue);
}

.route-main {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.symbol-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.symbol {
  font-size: 22px;
  font-weight: 750;
}

.venue-chip,
.flag,
.side-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.venue-chip {
  background: rgba(0, 122, 255, 0.12);
  color: var(--blue);
}

.flag {
  background: rgba(184, 91, 0, 0.12);
  color: var(--orange);
}

.flag.good {
  background: rgba(23, 128, 61, 0.12);
  color: var(--green);
}

.metric-large {
  font-size: 30px;
  line-height: 1;
  font-weight: 800;
}

.metric-large.positive {
  color: var(--green);
}

.route-detail {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 10px;
  min-width: 0;
}

.metric b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.metric small {
  font-size: 11px;
}

.direction {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.market-card {
  padding: 12px;
}

.market-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.market-venues {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.side-chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}

.side-chip.actionable {
  color: var(--green);
  border-color: rgba(23, 128, 61, 0.4);
}

.risk-panel {
  padding: 16px;
  margin-top: 28px;
}

.risk-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.45;
}

.empty,
.error {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  color: var(--muted);
  background: var(--panel);
}

.error {
  color: var(--red);
}

@media (max-width: 860px) {
  .shell {
    width: min(100vw - 20px, 720px);
    padding-top: 16px;
  }

  .topbar,
  .section-head,
  .panel-head {
    align-items: flex-start;
  }

  h1 {
    font-size: 24px;
  }

  .status-strip,
  .controls,
  .sim-output,
  .route-list,
  .universe-list,
  .risk-grid {
    grid-template-columns: 1fr;
  }

  .route-card {
    grid-template-columns: 1fr;
  }

  .route-detail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filters {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .section-head {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .route-detail {
    grid-template-columns: 1fr;
  }
}
