:root {
  color-scheme: dark;
  --bg: #08090a;
  --surface-0: #0a0c0e;
  --surface-1: #121416;
  --surface-2: #1a1c1e;
  --surface-3: #1e2022;
  --surface-4: #282a2c;
  --surface-5: #333537;
  --line: #414754;
  --line-strong: #5f6775;
  --text: #e2e2e5;
  --muted: #8b91a0;
  --soft: #c1c6d6;
  --blue: #abc7ff;
  --blue-strong: #4a8eff;
  --cyan: #00ffd5;
  --amber: #ffbf00;
  --amber-soft: #f59e0b;
  --red: #8b0000;
  --red-bright: #ff4d4d;
  --green: #10b981;
  --shadow: 0 16px 32px rgba(0, 0, 0, 0.34);
  font-family: "Hanken Grotesk", "Microsoft YaHei", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(74, 142, 255, 0.08), transparent 28rem),
    var(--bg);
  color: var(--text);
}

body {
  font-family: "JetBrains Mono", "Consolas", "Courier New", monospace;
}

button {
  font: inherit;
}

.terminal-body {
  min-height: 100vh;
  overflow: hidden;
}

.terminal-shell {
  min-height: 100vh;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.terminal-header,
.header-strip,
.system-cluster,
.draw-strip,
.main-layout,
.chart-toolbar,
.chart-tabs,
.page-controls,
.window-header,
.window-title-group,
.legend-item,
.stats-head,
.pair-row {
  display: flex;
  align-items: center;
}

.terminal-header {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
}

.brand-stack {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex: 0 0 auto;
}

.brand-mark {
  font-family: "Hanken Grotesk", sans-serif;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--blue);
}

.brand-stack strong {
  font-size: 14px;
  color: var(--text);
}

.header-strip {
  flex: 1 1 auto;
  gap: 4px;
  min-width: 0;
}

.header-card {
  min-width: 0;
  flex: 1 1 0;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid rgba(139, 145, 160, 0.32);
  background: var(--surface-1);
}

.header-card-wide {
  flex: 1.8 1 0;
}

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

.card-value {
  display: block;
  margin-top: 2px;
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.draw-strip {
  gap: 3px;
  margin-top: 2px;
  flex-wrap: wrap;
}

.draw-chip {
  min-width: 22px;
  min-height: 20px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(139, 145, 160, 0.24);
  background: var(--surface-4);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.draw-sum {
  color: var(--blue);
}

.draw-equals {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.system-cluster {
  gap: 8px;
  flex: 0 0 auto;
}

.system-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #7ee7a3;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.system-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #16a34a;
  box-shadow: 0 0 8px rgba(22, 163, 74, 0.9);
}

.terminal-button {
  border: 1px solid rgba(139, 145, 160, 0.28);
  background: var(--surface-1);
  color: var(--text);
  min-height: 26px;
  padding: 0 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.terminal-button:hover:not(:disabled) {
  border-color: rgba(171, 199, 255, 0.45);
  color: var(--blue);
}

.terminal-button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.icon-button {
  min-width: 30px;
  padding: 0;
  justify-content: center;
}

.main-layout {
  flex: 1;
  gap: 6px;
  align-items: stretch;
  min-height: 0;
}

.main-column {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  min-height: 0;
}

.side-column {
  flex: 0 0 280px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
}

.summary-grid,
.kpi-grid {
  align-items: stretch;
}

.kpi-card,
.summary-card,
.window {
  border: 1px solid rgba(139, 145, 160, 0.24);
  background: var(--surface-2);
  box-shadow: var(--shadow);
}

.kpi-card,
.summary-card,
.header-card {
  box-shadow: none;
}

.kpi-card {
  min-height: 60px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-label,
.summary-label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.kpi-value {
  display: block;
  margin-top: 3px;
  font-size: 27px;
  line-height: 1;
  font-weight: 800;
  color: var(--text);
}

.highlight-blue {
  color: var(--blue);
}

.highlight-red {
  color: #f6a4a4;
}

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

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

.signal-yellow {
  color: var(--amber-soft);
}

.signal-red {
  color: var(--red-bright);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

.summary-card {
  min-height: 56px;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.summary-card:first-child {
  border-right-color: rgba(139, 145, 160, 0.14);
}

.summary-meta {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.summary-value {
  font-size: 34px;
  line-height: 1;
  font-weight: 800;
}

.window {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.window-header {
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 0 12px;
  border-bottom: 1px solid rgba(139, 145, 160, 0.2);
  background: var(--surface-1);
}

.window-title-group {
  gap: 10px;
  min-width: 0;
}

.window-title-group h2 {
  margin: 0;
  color: var(--text);
  font-family: "Hanken Grotesk", sans-serif;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.window-meta,
.window-alert {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.window-alert {
  color: var(--red-bright);
}

.chart-window {
  flex: 1;
}

.kpi-grid + .summary-grid {
  margin-top: -2px;
}

.chart-toolbar {
  gap: 8px;
  margin-left: auto;
}

.chart-tabs {
  border: 1px solid rgba(139, 145, 160, 0.18);
  background: var(--surface-0);
}

.chart-tab {
  min-width: 78px;
  min-height: 28px;
  padding: 4px 9px;
  border: 0;
  border-right: 1px solid rgba(139, 145, 160, 0.18);
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.chart-tab:last-child {
  border-right: 0;
}

.chart-tab small {
  color: inherit;
  font-size: 10px;
}

.chart-tab.active {
  background: var(--surface-5);
  color: var(--blue);
}

.page-controls {
  gap: 8px;
}

.page-indicator {
  min-width: 72px;
  text-align: center;
  color: var(--muted);
  font-size: 10px;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom-level {
  min-width: 54px;
  text-align: center;
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
}

.chart-stage {
  position: relative;
  flex: 1;
  min-height: 420px;
  background: var(--surface-0);
  overflow: hidden;
}

.chart-grid,
.chart-y-labels,
.chart-x-labels,
.trend-svg {
  position: absolute;
}

.chart-grid {
  inset: 40px 40px 32px 42px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}

.chart-grid::before,
.chart-grid::after,
.chart-grid .grid-line {
  content: "";
}

.grid-line {
  border-top: 1px solid rgba(139, 145, 160, 0.1);
}

.chart-y-labels {
  left: 10px;
  top: 40px;
  bottom: 32px;
  width: 32px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: rgba(139, 145, 160, 0.72);
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
}

.chart-x-labels {
  left: 42px;
  right: 40px;
  bottom: 10px;
  display: flex;
  justify-content: space-between;
  color: rgba(139, 145, 160, 0.72);
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
}

.trend-svg {
  inset: 40px 40px 32px 42px;
  width: calc(100% - 82px);
  height: calc(100% - 72px);
  overflow: visible;
  touch-action: none;
}

.chart-legend {
  position: absolute;
  top: 8px;
  right: 10px;
  display: flex;
  gap: 8px;
  padding: 3px 6px;
  border: 1px solid rgba(139, 145, 160, 0.18);
  background: rgba(30, 32, 34, 0.85);
  backdrop-filter: blur(4px);
  z-index: 2;
}

.legend-item {
  gap: 6px;
  color: var(--soft);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.legend-dot {
  display: inline-block;
}

.legend-dot-yellow {
  width: 8px;
  height: 8px;
  background: var(--amber);
  border-radius: 50%;
}

.legend-dot-red {
  width: 2px;
  height: 10px;
  background: var(--red);
}

.trend-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 170px;
  padding: 10px 12px;
  border: 1px solid rgba(171, 199, 255, 0.42);
  background: rgba(26, 28, 30, 0.96);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.28);
  color: var(--text);
  font-size: 11px;
  line-height: 1.55;
  pointer-events: none;
  transform: translate(12px, -100%);
}

.trend-tooltip.hidden {
  display: none;
}

.chart-crosshair.hidden {
  display: none;
}

.chart-crosshair-line {
  stroke: rgba(171, 199, 255, 0.72);
  stroke-width: 1.2;
  stroke-dasharray: 6 6;
  vector-effect: non-scaling-stroke;
}

.chart-crosshair-dot {
  fill: rgba(255, 191, 0, 0.16);
  stroke: var(--amber);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.chart-crosshair-dot.hit {
  fill: rgba(255, 77, 77, 0.18);
  stroke: var(--red-bright);
}

.chart-hit-surface {
  cursor: crosshair;
  pointer-events: all;
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.tooltip-row span:first-child {
  color: var(--muted);
}

.gauge-window,
.history-window,
.stats-window,
.strategy-window {
  min-height: 0;
}

.strategy-window {
  overflow: visible;
}

.gauge-wrap {
  padding: 14px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.gauge-inspector-label {
  color: var(--blue);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.gauge-reset.hidden {
  display: none;
}

.gauge-figure {
  position: relative;
  display: flex;
  justify-content: center;
  min-height: 176px;
}

.gauge-svg {
  width: 100%;
  max-width: 206px;
  height: auto;
}

.gauge-readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 28px;
  pointer-events: none;
}

.gauge-readout strong {
  font-size: 34px;
  line-height: 1;
  font-weight: 900;
  color: var(--red-bright);
  text-shadow: 0 0 12px rgba(255, 77, 77, 0.36);
}

.gauge-readout span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.gauge-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.meta-slot {
  padding-left: 8px;
  border-left: 1px solid rgba(139, 145, 160, 0.24);
}

.meta-slot span {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.meta-slot strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.history-list {
  flex: 1;
  overflow: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  background: var(--surface-3);
  color: var(--soft);
  font-size: 12px;
}

.history-row.hit {
  border-left: 3px solid var(--red);
  background: rgba(139, 0, 0, 0.12);
}

.history-status {
  font-weight: 800;
}

.history-status.hit {
  color: var(--red-bright);
}

.stats-list {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 3px;
  color: var(--soft);
  font-size: 12px;
}

.stats-head strong {
  color: var(--text);
}

.stats-bar {
  height: 4px;
  background: var(--surface-4);
}

.stats-fill {
  height: 100%;
  background: var(--blue-strong);
}

.fill-red {
  background: var(--red-bright);
}

.strategy-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.strategy-panel {
  padding: 12px;
  border: 1px solid rgba(139, 145, 160, 0.2);
  background: rgba(255, 191, 0, 0.06);
  text-align: center;
}

.strategy-panel span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.strategy-panel strong {
  display: block;
  margin-top: 4px;
  color: var(--amber);
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.strategy-pairs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.aftershock-block {
  margin-top: 2px;
  padding: 10px 12px;
  border: 1px solid rgba(139, 145, 160, 0.2);
  background: linear-gradient(180deg, rgba(171, 199, 255, 0.07), rgba(255, 77, 77, 0.04));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.aftershock-title,
.aftershock-label,
.aftershock-row span {
  color: var(--soft);
  font-size: 11px;
}

.aftershock-badge {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.aftershock-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.aftershock-rate {
  color: var(--text);
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.aftershock-deviation {
  font-size: 11px;
  font-weight: 700;
}

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

.aftershock-row strong {
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.pair-row {
  display: block;
  min-width: 0;
  padding: 7px 8px;
  background: rgba(18, 20, 22, 0.7);
  color: var(--soft);
  font-size: 11px;
}

.pair-row strong {
  display: block;
  margin-top: 3px;
  color: var(--text);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.aftershock-grid .aftershock-row {
  display: block;
  min-width: 0;
  padding: 7px 8px;
  background: rgba(18, 20, 22, 0.7);
}

.aftershock-grid .aftershock-row span,
.aftershock-grid .aftershock-row strong {
  display: block;
}

.aftershock-grid .aftershock-row span {
  min-height: 26px;
  font-size: 10px;
}

.aftershock-grid .aftershock-row strong {
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prediction-panel.hidden {
  display: none;
}

.prediction-panel {
  padding: 10px 12px;
  border: 1px solid rgba(171, 199, 255, 0.22);
  background: rgba(171, 199, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prediction-header,
.prediction-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.prediction-header span {
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.prediction-header small,
.prediction-next,
.prediction-note,
.prediction-reason {
  color: var(--muted);
  font-size: 10px;
}

.prediction-next {
  padding: 7px 8px;
  background: rgba(18, 20, 22, 0.78);
  border: 1px solid rgba(139, 145, 160, 0.16);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px;
}

.prediction-next b {
  color: var(--amber);
}

.prediction-targets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.prediction-card {
  min-width: 0;
  padding: 8px;
  background: rgba(18, 20, 22, 0.78);
  border: 1px solid rgba(139, 145, 160, 0.16);
}

.prediction-card-head strong {
  color: var(--text);
  font-size: 12px;
}

.prediction-card-head span {
  color: var(--amber);
  font-size: 18px;
  font-weight: 900;
}

.prediction-meta,
.prediction-hit-rates {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--soft);
  font-size: 10px;
}

.prediction-hit-rates {
  padding-top: 5px;
  border-top: 1px solid rgba(139, 145, 160, 0.14);
}

.prediction-meta b,
.prediction-hit-rates b {
  color: var(--text);
}

.prediction-reason {
  margin: 6px 0 0;
  line-height: 1.35;
}

.prediction-note {
  margin: 0;
  color: var(--amber-soft);
}

@media (min-width: 1024px) {
  .terminal-shell {
    height: 100vh;
  }

  .main-layout {
    overflow: hidden;
  }

  .side-column {
    overflow-y: auto;
    scrollbar-gutter: stable;
  }

  .chart-stage {
    min-height: 0;
    height: clamp(430px, 60vh, 620px);
  }

  .gauge-window {
    flex: 0 0 auto;
    min-height: 338px;
  }

  .history-window {
    flex: 0 0 auto;
    min-height: 360px;
  }

  .stats-window {
    flex: 0 0 auto;
    min-height: 172px;
  }

  .strategy-window {
    flex: 0 0 auto;
    min-height: 372px;
  }
}

@media (max-width: 760px) {
  .terminal-body {
    overflow: auto;
  }

  .main-layout {
    flex-direction: column;
  }

  .side-column {
    flex-basis: auto;
    width: 100%;
  }
}

@media (max-width: 900px) {
  .terminal-shell {
    padding: 10px;
  }

  .terminal-body {
    overflow: auto;
  }

  .terminal-header {
    flex-direction: column;
    align-items: stretch;
    padding: 10px;
  }

  .header-strip {
    flex-wrap: wrap;
  }

  .header-card,
  .header-card-wide {
    flex: 1 1 calc(50% - 6px);
  }

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

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .window-header {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
  }

  .chart-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .chart-tabs {
    width: 100%;
  }

  .chart-tab {
    flex: 1 1 0;
  }

  .page-controls {
    justify-content: flex-end;
  }

  .zoom-controls {
    justify-content: flex-end;
  }

  .chart-stage {
    min-height: 420px;
  }

  .trend-svg {
    inset: 52px 18px 40px 42px;
    width: calc(100% - 60px);
    height: calc(100% - 92px);
  }

  .chart-grid {
    inset: 52px 18px 40px 42px;
  }

  .chart-x-labels {
    left: 42px;
    right: 18px;
  }

  .chart-legend {
    top: 54px;
    right: 14px;
  }
}
