:root {
  color-scheme: dark;
  --bg: #080b0c;
  --surface: #111719;
  --surface-2: #151d21;
  --surface-3: #0f1613;
  --line: #25323a;
  --text: #eef4ef;
  --muted: #9dafb1;
  --green: #45d483;
  --red: #ef6262;
  --amber: #f2b84b;
  --cyan: #66d9ef;
  --blue: #7aa7ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 16% 0%, rgba(69, 212, 131, 0.11), transparent 28%),
    radial-gradient(circle at 88% 12%, rgba(102, 217, 239, 0.08), transparent 24%),
    linear-gradient(180deg, #0d1214 0%, var(--bg) 52%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
a {
  font: inherit;
}

.app-shell {
  width: min(1480px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar,
.metric-strip,
.equity-panel,
.workspace,
.lower-grid {
  width: 100%;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 0 20px;
}

.eyebrow,
.label {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 4.7rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.45rem;
  letter-spacing: 0;
}

.control-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.segmented {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.segment {
  min-width: 72px;
  min-height: 38px;
  border: 0;
  color: var(--muted);
  background: transparent;
}

.segment.active {
  color: #06100a;
  background: var(--green);
  font-weight: 800;
}

.toggle-row,
.tool-link,
.secondary-button,
.danger-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 750;
}

.tool-link {
  text-decoration: none;
}

.secondary-button {
  cursor: pointer;
}

.danger-button {
  border-color: rgba(239, 98, 98, 0.6);
  color: #ffb8b8;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric-strip div,
.panel,
.market-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 23, 25, 0.92);
}

.metric-strip div {
  min-height: 72px;
  padding: 14px;
}

.metric-strip span,
.market-stats span,
dt {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.metric-strip strong {
  display: block;
  margin-top: 8px;
  font-size: 1.2rem;
  letter-spacing: 0;
}

.good {
  color: var(--green);
}

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

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

.equity-summary {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.equity-summary span {
  min-height: 40px;
  border: 1px solid #223039;
  border-radius: 6px;
  padding: 8px 10px;
  background: #0c1214;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.equity-summary b {
  margin-left: 6px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.equity-chart {
  height: 220px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 12px;
}

.market-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.market-card {
  min-height: 430px;
  padding: 16px;
  background: var(--surface-2);
}

.market-card.active {
  background: var(--surface-3);
  border-color: rgba(69, 212, 131, 0.42);
}

.market-head,
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.bias {
  min-width: 70px;
  border-radius: 999px;
  padding: 7px 10px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.bias.long {
  color: #041008;
  background: var(--green);
}

.bias.short {
  color: #1d0707;
  background: var(--red);
}

.bias.flat {
  color: #160f00;
  background: var(--amber);
}

canvas {
  width: 100%;
  height: 150px;
  margin-top: 16px;
  border: 1px solid #1f2c31;
  border-radius: 6px;
  background: #080c0e;
}

.market-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.market-stats span {
  min-height: 54px;
  border: 1px solid #223039;
  border-radius: 6px;
  padding: 9px;
  background: #0c1214;
}

.market-stats b {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 0.96rem;
  overflow-wrap: anywhere;
}

.pressure {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  height: 12px;
  margin-top: 16px;
}

.pressure span {
  display: block;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(69, 212, 131, 0.18), var(--green));
  transform-origin: left center;
}

.pressure span + span {
  background: linear-gradient(90deg, var(--red), rgba(239, 98, 98, 0.18));
  transform-origin: right center;
}

.order-flow {
  margin-top: 16px;
  border: 1px solid #223039;
  border-radius: 6px;
  padding: 12px;
  background: #0a1012;
}

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

.flow-head span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.flow-head strong {
  font-size: 0.86rem;
  font-weight: 850;
}

.flow-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.flow-grid span {
  min-height: 50px;
  border: 1px solid #1f2c31;
  border-radius: 6px;
  padding: 8px;
  background: #0c1214;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 750;
}

.flow-grid b {
  display: block;
  margin-top: 5px;
  color: var(--text);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.imbalance-track {
  position: relative;
  height: 12px;
  margin-top: 12px;
  border: 1px solid #223039;
  border-radius: 999px;
  overflow: hidden;
  background: #070b0d;
}

.imbalance-track::after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: #314149;
  content: "";
}

.imbalance-track i {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 50%;
  min-width: 4px;
  border-radius: 999px;
  background: var(--green);
  transition:
    width 180ms ease,
    background 180ms ease;
}

.imbalance-track i.negative {
  right: 50%;
  left: auto;
  background: var(--red);
}

.plan {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.5;
}

.side-stack {
  display: grid;
  gap: 12px;
  align-content: start;
}

.panel {
  padding: 16px;
}

.engine-panel {
  min-height: 292px;
}

.pipeline {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.pipe-step {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid #233138;
  border-radius: 6px;
  padding: 8px;
  background: #0c1214;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px rgba(69, 212, 131, 0.5);
  justify-self: center;
}

.pipe-step.warn .dot {
  background: var(--amber);
  box-shadow: 0 0 12px rgba(242, 184, 75, 0.45);
}

.pipe-step.stop .dot {
  background: var(--red);
  box-shadow: 0 0 12px rgba(239, 98, 98, 0.45);
}

.pipe-step strong {
  display: block;
  font-size: 0.9rem;
}

.pipe-step span {
  color: var(--muted);
  font-size: 0.78rem;
}

.risk-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 0;
}

.risk-grid div {
  min-height: 72px;
  border: 1px solid #233138;
  border-radius: 6px;
  padding: 10px;
  background: #0c1214;
}

.risk-grid dd {
  margin: 8px 0 0;
  font-size: 1.15rem;
  font-weight: 850;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(340px, 0.75fr);
  gap: 12px;
  margin-top: 12px;
}

.backtests-shell h1 {
  font-size: clamp(2.4rem, 6vw, 5.4rem);
}

.backtest-controls-panel,
.backtest-table-panel {
  margin-bottom: 12px;
}

.backtest-controls-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(180px, 0.8fr) minmax(260px, 1.4fr) minmax(100px, 0.4fr);
  gap: 10px;
}

.backtest-controls-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.backtest-controls-grid input,
.backtest-controls-grid select {
  min-height: 42px;
  width: 100%;
  border: 1px solid #2b3a42;
  border-radius: 8px;
  background: #070b0d;
  color: var(--text);
  padding: 0 10px;
}

.table-note {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.table-scroll {
  overflow: auto;
  margin-top: 12px;
  border: 1px solid #223039;
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid #223039;
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

th {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
}

.table-scroll table {
  min-width: 2200px;
  margin-top: 0;
}

.backtest-table {
  table-layout: auto;
}

.backtest-table th,
.backtest-table td {
  white-space: nowrap;
}

.backtest-table td:nth-child(4) {
  min-width: 360px;
  max-width: 520px;
  white-space: normal;
}

.backtest-table td:nth-child(17) {
  min-width: 220px;
  max-width: 360px;
  white-space: normal;
}

.backtest-table tbody tr {
  cursor: pointer;
}

.backtest-table tbody tr:hover,
.backtest-table tbody tr.active {
  background: rgba(69, 212, 131, 0.08);
}

.sort-button {
  width: 100%;
  border: 0;
  color: inherit;
  background: transparent;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font-size: inherit;
  font-weight: 850;
  text-transform: inherit;
}

.sort-button.asc::after {
  content: " ↑";
}

.sort-button.desc::after {
  content: " ↓";
}

.warn {
  color: var(--amber);
}

.metric-detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  max-height: 540px;
  overflow: auto;
  margin-top: 12px;
}

.metric-detail-grid div {
  min-height: 62px;
  border: 1px solid #223039;
  border-radius: 6px;
  background: #0c1214;
  padding: 9px;
}

.metric-detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.metric-detail-grid strong {
  display: block;
  margin-top: 7px;
  color: var(--text);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

#event-log {
  min-height: 228px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

#event-log li {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  gap: 10px;
  border-bottom: 1px solid #223039;
  padding: 10px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

#event-log time {
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}

.auth-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.auth-shell {
  width: min(460px, calc(100% - 28px));
}

.auth-shell.wide {
  width: min(720px, calc(100% - 28px));
}

.auth-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 23, 25, 0.96);
  padding: 24px;
}

.auth-panel h1 {
  margin-bottom: 22px;
  font-size: clamp(2rem, 9vw, 4rem);
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.auth-form input {
  min-height: 48px;
  border: 1px solid #2b3a42;
  border-radius: 8px;
  background: #070b0d;
  color: var(--text);
  padding: 0 12px;
  text-transform: none;
}

.primary-action,
.secondary-action {
  min-height: 48px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 850;
  text-align: center;
}

.primary-action {
  border-color: rgba(69, 212, 131, 0.64);
  color: #041008;
  background: var(--green);
}

.link-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.auth-divider {
  display: grid;
  place-items: center;
  margin: 18px 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.auth-status {
  min-height: 24px;
  margin: 16px 0 0;
  color: var(--muted);
}

.auth-status.good {
  color: var(--green);
}

.auth-status.bad {
  color: var(--red);
}

.passkey-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.passkey-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.passkey-row,
.empty-state {
  border: 1px solid #223039;
  border-radius: 8px;
  background: #0c1214;
  padding: 14px;
}

.passkey-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 12px;
  align-items: center;
}

.passkey-row strong,
.passkey-row span,
.passkey-row small {
  display: block;
}

.passkey-row span,
.passkey-row small,
.empty-state {
  color: var(--muted);
}

.passkey-row button {
  min-height: 38px;
  border: 1px solid rgba(239, 98, 98, 0.55);
  border-radius: 8px;
  color: #ffb8b8;
  background: transparent;
  cursor: pointer;
}

@media (max-width: 1180px) {
  .workspace,
  .lower-grid,
  .backtest-controls-grid {
    grid-template-columns: 1fr;
  }

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

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

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

  .control-strip {
    justify-content: flex-start;
  }

  .metric-strip,
  .market-board,
  .side-stack,
  .passkey-actions {
    grid-template-columns: 1fr;
  }

  .equity-summary {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 18px, 1480px);
    padding-top: 12px;
  }

  h1 {
    font-size: 2.1rem;
  }

  .market-card {
    min-height: 390px;
  }

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

  .equity-chart {
    height: 180px;
  }

  .passkey-row {
    grid-template-columns: 1fr;
  }

  .metric-detail-grid {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 10px 6px;
    font-size: 0.8rem;
  }
}
