:root {
  --bg: #0f0f23;
  --panel: #1a1a2e;
  --border-soft: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --faint: #6b7280;
  --green: #22c55e;
  --green-soft: #4ade80;
  --blue: #3b82f6;
  --blue-soft: #60a5fa;
  --red: #ef4444;
  --tape-muted: #75848b;
  --tape-faint: #4b5a61;
  --tape-text: #d9e1e4;
  --line: #1e2a30;
  --line-hot: #33444b;
  --cyan: #35d4df;
  --amber: #f0b64d;
  --coral: #ff6f61;
  --sans: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", Arial, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", "Roboto Mono", monospace;
  --display: var(--sans);
  --numeric: var(--mono);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  font-family: var(--sans);
}

button {
  font: inherit;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  transform: translateY(-160%);
  border: 1px solid var(--amber);
  background: #070b0d;
  color: var(--text);
  font: 700 13px var(--display);
  text-decoration: none;
}

.skip-link:focus-visible {
  transform: translateY(0);
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.dashboard-shell {
  display: grid;
  width: 100%;
  max-width: 100%;
  height: 100dvh;
}

.strategy-switcher {
  display: flex;
  min-width: 0;
  min-height: 44px;
  padding-left: 8px;
  border-bottom: 1px solid var(--line-hot);
  background: #070b0d;
  font-family: var(--display);
}

.strategy-link {
  position: relative;
  display: flex;
  width: 220px;
  min-width: 0;
  min-height: 44px;
  flex: 0 0 220px;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  padding: 4px 16px 3px;
  border-right: 1px solid var(--line);
  border-bottom: 2px solid transparent;
  color: var(--tape-muted);
  font-size: 14px;
  font-weight: 750;
  line-height: 1.05;
  text-decoration: none;
}

.strategy-link:hover {
  background: rgba(53, 212, 223, 0.04);
  color: var(--tape-text);
}

.strategy-link[aria-current="page"] {
  border-bottom-color: var(--cyan);
  background: rgba(53, 212, 223, 0.09);
  color: var(--cyan);
}

.strategy-link:focus-visible,
.interval-button:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--amber);
  outline-offset: -3px;
}

.strategy-pair {
  color: var(--tape-faint);
  font-family: var(--numeric);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.topbar {
  display: grid;
  border-bottom: 1px solid var(--line-hot);
  background: rgba(7, 11, 13, 0.95);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  font-family: var(--numeric);
  font-variant-numeric: tabular-nums lining-nums;
}

.brand {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.brand::before {
  position: absolute;
  top: 0;
  left: 0;
  width: 5px;
  height: 68%;
  background: var(--cyan);
  box-shadow: 0 0 22px rgba(53, 212, 223, 0.3);
  content: "";
}

.brand-title {
  color: var(--tape-text);
  font-family: var(--display);
  font-size: clamp(20px, 1.85vw, 30px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 0.95;
  white-space: nowrap;
}

.brand-title span {
  color: var(--cyan);
}

.brand-meta {
  display: grid;
  gap: 3px;
  color: var(--tape-faint);
  font-size: 11px;
  letter-spacing: 0.09em;
}

.brand-kicker,
.stat-label {
  color: var(--tape-muted);
  font-family: var(--display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  line-height: 1.2;
  text-transform: uppercase;
}

.stat-label.instrument-label {
  font-size: clamp(14px, 1.35vw, 17px);
}

.instrument-stat .stat-label {
  font-size: clamp(14px, 1.35vw, 17px);
}

.instrument-grid {
  display: grid;
  min-width: 0;
}

.stat {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  border-right: 1px solid var(--line);
}

.stat::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  background: transparent;
  content: "";
}

.stat[data-tone="cyan"]::after {
  background: var(--green);
}

.stat[data-tone="blue"]::after {
  background: var(--blue);
}

.stat[data-tone="amber"]::after {
  background: var(--amber);
}

.stat[data-tone="gap"]::after {
  background: var(--coral);
}

.stat-value {
  min-width: 0;
  overflow: hidden;
  color: var(--tape-text);
  font-size: clamp(17px, 1.45vw, 23px);
  font-weight: 650;
  letter-spacing: -0.045em;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-value[data-tone="cyan"] {
  color: var(--green-soft);
}

.stat-value[data-tone="blue"] {
  color: var(--blue-soft);
}

.stat-value[data-tone="amber"] {
  color: var(--amber);
}

.stat-value[data-sign="negative"] {
  color: var(--red);
}

.stat-value[data-sign="positive"] {
  color: var(--coral);
}

.gap-summary {
  gap: 5px;
  padding-left: 20px;
  background: #0d1215;
}

.gap-summary-label {
  color: var(--coral);
  font-size: 10px;
}

.gap-summary-value {
  color: var(--coral);
  font-size: clamp(29px, 2.55vw, 43px);
  font-weight: 700;
  letter-spacing: -0.065em;
}

.gap-summary-context {
  color: var(--tape-muted);
  font-family: var(--display);
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-cluster {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  background: #090d10;
}

.connection-shell {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--tape-muted);
  font-family: var(--display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.connection-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.connection-detail {
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: var(--tape-muted);
  font: 500 10px var(--numeric);
  letter-spacing: 0;
  text-overflow: ellipsis;
  text-transform: none;
  white-space: nowrap;
}

.connection-value,
.feed-status {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 8px;
  color: #aab6ba;
  white-space: nowrap;
}

.feed-status {
  width: max-content;
  overflow: hidden;
  padding: 4px 6px;
  border: 1px solid var(--line-hot);
  font-size: 10px;
  letter-spacing: 0.07em;
  text-overflow: ellipsis;
}

.connection-dot {
  width: 7px;
  height: 7px;
  border: 1px solid #6f7c81;
  border-radius: 50%;
  background: #344046;
}

.connection-value[data-state="live"] {
  color: var(--cyan);
}

.connection-value[data-state="live"] .connection-dot {
  border-color: var(--cyan);
  background: var(--cyan);
  box-shadow: 0 0 0 4px rgba(53, 212, 223, 0.08), 0 0 14px rgba(53, 212, 223, 0.45);
  animation: pulse 2.4s ease-out infinite;
}

.connection-value[data-state="connecting"] .connection-dot,
.connection-value[data-state="reconnecting"] .connection-dot {
  border-color: var(--amber);
  background: var(--amber);
}

.connection-value[data-state="error"] {
  color: var(--coral);
}

.connection-value[data-state="error"] .connection-dot {
  border-color: var(--coral);
  background: var(--coral);
}

@keyframes pulse {
  0%, 40% { box-shadow: 0 0 0 0 rgba(53, 212, 223, 0.22), 0 0 14px rgba(53, 212, 223, 0.4); }
  78%, 100% { box-shadow: 0 0 0 7px rgba(53, 212, 223, 0), 0 0 14px rgba(53, 212, 223, 0.12); }
}

.intervals {
  display: grid;
  border: 1px solid var(--line-hot);
}

.interval-button {
  min-width: 0;
  min-height: 40px;
  padding: 0 8px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: #0d1417;
  color: var(--tape-muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  transition: background-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.interval-button:last-child {
  border-right: 0;
}

.interval-button:hover {
  background: #121c20;
  color: var(--tape-text);
}

.interval-button[aria-pressed="true"] {
  background: var(--cyan);
  box-shadow: inset 0 -2px 0 #baf7f4;
  color: #041012;
}

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 16px;
  overflow: hidden;
  border-bottom: 1px solid var(--panel);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.section-label .hint {
  overflow: hidden;
  color: var(--faint);
  font-size: 11.5px;
  text-overflow: ellipsis;
}

.series-legend[data-tone="cyan"] {
  color: var(--cyan);
}

.series-legend[data-tone="blue"] {
  color: var(--blue-soft);
}

.series-legend[data-tone="amber"] {
  color: var(--amber);
}

.chart-frame {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.chart-frame + .section-label {
  border-top: 1px solid var(--panel);
}

.chart {
  position: absolute;
  inset: 0;
}

.chart a {
  color: var(--faint) !important;
}

.chart-state {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 15, 35, 0.75);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  transition: opacity 160ms ease, visibility 160ms ease;
}

.chart-state[hidden] {
  display: grid;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.statusbar {
  display: flex;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 4px 16px;
  border-top: 1px solid var(--border-soft);
  background: var(--bg);
  color: var(--faint);
  font-size: 11.5px;
}

.statusbar strong {
  color: var(--muted);
  font-weight: 500;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 760px) {
  html,
  body {
    min-width: 0;
  }

  html body {
    overflow: auto;
  }

  .dashboard-shell {
    height: auto;
    min-height: 100dvh;
  }

  .strategy-switcher {
    padding-left: 0;
  }

  .strategy-link {
    width: 50%;
    min-height: 48px;
    flex: 1 1 50%;
    padding-right: 12px;
    padding-left: 12px;
  }

  #main-content .topbar {
    grid-template-columns: 1fr;
  }

  .brand {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  #main-content .instrument-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat {
    border-bottom: 1px solid var(--line);
  }

  .gap-summary {
    grid-column: 1 / -1;
    min-height: 90px;
  }

  #main-content .gap-summary-value {
    font-size: 38px;
  }

  #main-content .control-cluster {
    align-items: stretch;
    flex-direction: column;
    padding: 12px 14px;
  }

  .connection-shell {
    align-items: flex-start;
  }

  .intervals {
    width: 100%;
  }

  .interval-button {
    min-height: 44px;
  }

  .section-label {
    align-items: flex-start;
    flex-wrap: wrap;
    white-space: normal;
  }

  .section-label > * {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .statusbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
    padding: 6px 16px;
  }
}

@media (max-width: 374px) {
  #main-content .instrument-grid {
    grid-template-columns: 1fr;
  }

  .strategy-link {
    padding-right: 8px;
    padding-left: 8px;
    font-size: 13px;
  }

  .connection-shell {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
