:root {
  --bg: #05080e;
  --bg-panel: #0a121c;
  --bg-panel-2: #0d1622;
  --cyan: #38f0e8;
  --cyan-dim: #1c6b6a;
  --amber: #ffb03b;
  --red: #ff4d5e;
  --green: #59e88c;
  --text: #d9f3f1;
  --text-dim: #6f8f94;
  --border: rgba(56, 240, 232, 0.16);
  --border-strong: rgba(56, 240, 232, 0.38);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100%;
  overscroll-behavior-y: none;
}

body {
  background:
    radial-gradient(1200px 700px at 20% -10%, rgba(56, 240, 232, 0.07), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(255, 176, 59, 0.05), transparent 55%),
    var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
  padding-top: env(safe-area-inset-top);
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.0) 0px,
    rgba(255, 255, 255, 0.0) 2px,
    rgba(56, 240, 232, 0.012) 3px,
    rgba(0, 0, 0, 0) 4px
  );
  mix-blend-mode: overlay;
}

/* ---- Topbar ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, rgba(10, 18, 28, 0.9), rgba(10, 18, 28, 0.4));
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px 2px var(--cyan), 0 0 22px 6px rgba(56, 240, 232, 0.35);
  animation: brandPulse 2.6s ease-in-out infinite;
}

@keyframes brandPulse {
  0%, 100% { opacity: 0.65; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

.brand-text {
  font-family: var(--mono);
  letter-spacing: 0.14em;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.brand-accent { color: var(--cyan); }

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: rgba(56, 240, 232, 0.06);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim);
}

.status-pill[data-state="running"] { border-color: rgba(89, 232, 140, 0.45); background: rgba(89, 232, 140, 0.08); }
.status-pill[data-state="running"] .status-dot { background: var(--green); box-shadow: 0 0 8px 2px var(--green); animation: dotPulse 1.8s ease-in-out infinite; }
.status-pill[data-state="halted"] { border-color: rgba(255, 77, 94, 0.5); background: rgba(255, 77, 94, 0.1); }
.status-pill[data-state="halted"] .status-dot { background: var(--red); box-shadow: 0 0 8px 2px var(--red); }

@keyframes dotPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ---- Hero strip: net P&L + elapsed-time counter ---- */

.hero {
  display: flex;
  align-items: stretch;
  max-width: 1200px;
  margin: 14px auto 0;
  padding: 0 14px;
  gap: 0;
}

@media (max-width: 640px) {
  .hero { flex-direction: column; gap: 14px; }
}

.hero-cell {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  position: relative;
  overflow: hidden;
}

.hero-cell::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--cyan), transparent);
  opacity: 0.5;
}

.hero-divider {
  width: 14px;
  flex: 0 0 14px;
}
@media (max-width: 640px) { .hero-divider { display: none; } }

.hero-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--cyan);
  font-weight: 600;
}

.hero-value {
  font-family: var(--mono);
  font-size: clamp(28px, 6vw, 40px);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.15;
  color: var(--text-dim);
  text-shadow: none;
  transition: color 0.3s ease, text-shadow 0.3s ease;
}

.hero-value[data-state="positive"] { color: var(--green); text-shadow: 0 0 18px rgba(89, 232, 140, 0.45); }
.hero-value[data-state="negative"] { color: var(--red); text-shadow: 0 0 18px rgba(255, 77, 94, 0.45); }
.hero-value[data-state="neutral"] { color: var(--cyan); text-shadow: 0 0 14px rgba(56, 240, 232, 0.3); }

.hero-value--time { font-size: clamp(22px, 4.6vw, 32px); color: var(--cyan); text-shadow: 0 0 14px rgba(56, 240, 232, 0.3); }

.hero-sub {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.sparkline {
  width: 100%;
  max-width: 220px;
  height: 40px;
  margin-top: 2px;
  overflow: visible;
}

.balance-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}
.range-toggle { display: flex; gap: 6px; }
.range-btn {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.range-btn.active { color: var(--cyan); border-color: var(--border-strong); background: rgba(56, 240, 232, 0.08); }
.export-link {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
}
.export-link:hover, .export-link:focus { color: var(--cyan); border-color: var(--border-strong); }
.sparkline polyline#sparkline-line {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
  filter: drop-shadow(0 0 4px rgba(56, 240, 232, 0.55));
}
.sparkline polyline.sparkline-fill {
  fill: rgba(56, 240, 232, 0.08);
  stroke: none;
}

/* ---- Layout ---- */

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 14px;
  max-width: 1200px;
  margin: 0 auto;
}

@media (min-width: 900px) {
  .grid {
    grid-template-columns: 1.5fr 1fr;
    grid-template-areas:
      "map ks"
      "trades reports";
  }
  .map-panel { grid-area: map; }
  .killswitch-panel { grid-area: ks; }
  .trades-panel { grid-area: trades; }
  .reports-panel { grid-area: reports; }
}

.panel {
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  position: relative;
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--cyan), transparent);
  opacity: 0.5;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 6px;
}

.panel-head h2 {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  margin: 0;
  color: var(--cyan);
  font-weight: 600;
}

.dim { color: var(--text-dim); font-weight: 400; }

.panel-sub {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

/* ---- Map ---- */

.map-frame { position: relative; }

#map-svg {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 45%, rgba(56, 240, 232, 0.05), transparent 65%);
}

.grid-line { stroke: rgba(56, 240, 232, 0.10); stroke-width: 1; }
.grid-line-strong { stroke: rgba(56, 240, 232, 0.22); stroke-width: 1; stroke-dasharray: 2 4; }

#sweep-group { transform-origin: 500px 310px; animation: sweep 8s linear infinite; }
@keyframes sweep { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.city-node circle.core { fill: var(--cyan); }
.city-node circle.glow { fill: url(#nodeGlow); }
.city-node[data-hot="1"] circle.core { fill: var(--amber); }
.city-node[data-hot="1"] circle.glow { fill: url(#hotGlow); }
.city-node[data-hot="1"] circle.pulse-ring {
  stroke: var(--amber);
  animation: pulseRing 2.2s ease-out infinite;
}
.city-node circle.pulse-ring { fill: none; stroke: var(--cyan); stroke-width: 1.4; opacity: 0; }
.city-node:not([data-hot="1"]) circle.pulse-ring { display: none; }

@keyframes pulseRing {
  0% { r: 6; opacity: 0.9; stroke-width: 2; }
  100% { r: 26; opacity: 0; stroke-width: 0.5; }
}

.city-label {
  font-family: var(--mono);
  font-size: 9px;
  fill: var(--text-dim);
  letter-spacing: 0.04em;
}

.map-legend {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.map-legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.map-legend .dot.cyan { background: var(--cyan); }
.map-legend .dot.amber { background: var(--amber); }
.map-legend .dot.red { background: var(--red); }
.pulse-legend { animation: dotPulse 1.6s ease-in-out infinite; }

/* ---- Kill switch panel ---- */

.ks-body { display: flex; flex-direction: column; gap: 12px; }

.ks-readout { display: flex; flex-direction: column; gap: 6px; }
.ks-field { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 12px; }
.ks-field .k { color: var(--text-dim); letter-spacing: 0.08em; }
.ks-field .v { color: var(--text); }
.ks-reason .v { color: var(--amber); text-align: right; max-width: 65%; }

.ks-button {
  width: 100%;
  padding: 16px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: rgba(89, 232, 140, 0.12);
  color: var(--green);
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.12em;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease;
}
.ks-button:active { transform: scale(0.98); }
.ks-button[data-state="running"] {
  background: rgba(255, 77, 94, 0.12);
  border-color: rgba(255, 77, 94, 0.45);
  color: var(--red);
  box-shadow: 0 0 0 rgba(255, 77, 94, 0);
}
.ks-button[data-state="running"]:hover { box-shadow: 0 0 22px rgba(255, 77, 94, 0.25); }
.ks-button[data-state="halted"] {
  background: rgba(89, 232, 140, 0.12);
  border-color: rgba(89, 232, 140, 0.45);
  color: var(--green);
}
.ks-button[data-state="halted"]:hover { box-shadow: 0 0 22px rgba(89, 232, 140, 0.25); }
.ks-button:disabled { opacity: 0.5; cursor: wait; }

.ks-hint { font-size: 11px; color: var(--text-dim); margin: 0; line-height: 1.4; }

/* ---- Trades ---- */

.trades-list { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow-y: auto; }

.trade-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  font-family: var(--mono);
  font-size: 11px;
}
.trade-row .badge {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 5px;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.badge.high { background: rgba(56, 240, 232, 0.14); color: var(--cyan); }
.badge.low { background: rgba(120, 170, 255, 0.14); color: #9fc4ff; }
.badge.precip { background: rgba(160, 130, 255, 0.14); color: #c3b0ff; }
.trade-city { color: var(--text); text-transform: capitalize; }
.trade-meta { color: var(--text-dim); font-size: 10px; }
.trade-status { text-align: right; font-size: 10px; }
.trade-status.win { color: var(--green); }
.trade-status.loss { color: var(--red); }
.trade-status.open { color: var(--amber); }
.trade-status.other { color: var(--text-dim); }

.empty { color: var(--text-dim); font-family: var(--mono); font-size: 12px; }

/* ---- Reports ---- */

.tabs { display: flex; gap: 6px; }
.tab {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  padding: 5px 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.tab.active { color: var(--cyan); border-color: var(--border-strong); background: rgba(56, 240, 232, 0.08); }

.report-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
  max-height: 360px;
  overflow-y: auto;
}

/* ---- Footer ---- */

.footer {
  display: flex;
  justify-content: space-between;
  padding: 12px 18px 20px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  max-width: 1200px;
  margin: 0 auto;
}

/* ---- Scrollbars (webkit) ---- */
.trades-list::-webkit-scrollbar, .report-text::-webkit-scrollbar { width: 6px; }
.trades-list::-webkit-scrollbar-thumb, .report-text::-webkit-scrollbar-thumb { background: var(--cyan-dim); border-radius: 4px; }
