:root {
  --bg: #020a13;
  --bg-deep: #01060c;
  --holo: #5fe1ff;          /* primary hologram cyan */
  --holo-soft: rgba(95, 225, 255, 0.55);
  --holo-faint: rgba(95, 225, 255, 0.14);
  --glass: rgba(10, 40, 62, 0.28);
  --glass-edge: rgba(95, 225, 255, 0.35);
  --text: #cdefff;
  --dim: rgba(160, 215, 240, 0.55);
  --long: #3dffc5;
  --short: #ff5d7d;
  --accent: #ffc35c;
  --glow: 0 0 6px rgba(95, 225, 255, 0.55), 0 0 18px rgba(95, 225, 255, 0.25);
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "Cascadia Mono",
    "DejaVu Sans Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg-deep);
  color: var(--text);
  font: 14px/1.55 var(--mono);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- ambient layers ---------------------------------------------------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 70% 55% at 50% 45%, rgba(30, 120, 170, 0.28), transparent 70%),
    radial-gradient(circle at 15% 85%, rgba(20, 90, 140, 0.18), transparent 40%),
    linear-gradient(var(--holo-faint) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(90deg, var(--holo-faint) 1px, transparent 1px) 0 0 / 44px 44px,
    var(--bg);
  mask-image: radial-gradient(ellipse 90% 80% at 50% 50%, #000 55%, transparent 100%);
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(95, 225, 255, 0.035) 0 1px,
    transparent 1px 3px
  );
}

.scanlines::after {
  /* a slow bright band sweeping down, like a projector refresh */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 120px;
  background: linear-gradient(to bottom, transparent, rgba(95, 225, 255, 0.06), transparent);
  animation: sweep 7s linear infinite;
}

@keyframes sweep { from { top: -120px; } to { top: 100%; } }

/* ---- top bar ----------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--holo-faint);
  letter-spacing: 0.22em;
  font-size: 12px;
  color: var(--holo);
  text-shadow: var(--glow);
}

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

.brand-mark {
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--holo);
  transform: rotate(45deg);
  box-shadow: var(--glow);
}

.topbar-meta { display: flex; gap: 14px; align-items: center; }
.clock { font-variant-numeric: tabular-nums; }

/* ---- layout ------------------------------------------------------------ */

.hud {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 260px;
  gap: 22px;
  padding: 22px 28px 28px;
}

/* ---- glass panels ------------------------------------------------------ */

.panel {
  position: relative;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 18px 20px;
  background:
    linear-gradient(160deg, rgba(95, 225, 255, 0.08), transparent 40%),
    var(--glass);
  border: 1px solid var(--glass-edge);
  backdrop-filter: blur(6px);
  box-shadow:
    inset 0 0 40px rgba(95, 225, 255, 0.06),
    0 0 30px rgba(20, 120, 180, 0.12);
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 18px 100%, 0 calc(100% - 18px));
  animation: materialize 0.9s ease-out both;
}

/* center column: open positions on top (the main thing on screen — the
page runs unattended on a stream, so all of it must be visible without
scrolling), the console in a band under it */
.center {
  min-height: 0;
  min-width: 0; /* let the wide positions table scroll instead of widening the page */
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.center .positions { flex: 1 1 auto; }
.center .console { flex: 0 0 26%; }

.core { animation-delay: 0.1s; }
.console { animation-delay: 0.25s; }
.stats { animation-delay: 0.4s; }
.positions { animation-delay: 0.55s; }

@keyframes materialize {
  0% { opacity: 0; transform: translateY(8px) scaleY(0.96); filter: blur(4px); }
  60% { opacity: 0.8; }
  70% { opacity: 0.4; }
  100% { opacity: 1; transform: none; filter: none; }
}

.corner {
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: var(--holo);
  border-style: solid;
  filter: drop-shadow(0 0 4px var(--holo));
}
.corner.tl { top: 6px; left: 6px; border-width: 2px 0 0 2px; }
.corner.tr { top: 6px; right: 22px; border-width: 2px 2px 0 0; }
.corner.bl { bottom: 6px; left: 22px; border-width: 0 0 2px 2px; }
.corner.br { bottom: 6px; right: 6px; border-width: 0 2px 2px 0; }

.panel-title {
  margin: 0 0 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3em;
  color: var(--holo);
  text-shadow: var(--glow);
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--holo-soft), transparent);
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--long);
  box-shadow: 0 0 8px var(--long);
  animation: pulse 1.6s ease-in-out infinite;
  order: 1;
}

@keyframes pulse { 50% { opacity: 0.25; } }

/* ---- core / reactor ---------------------------------------------------- */

.reactor {
  position: relative;
  width: 190px;
  max-width: 100%;
  aspect-ratio: 1;
  margin: 4px auto 18px;
}

.reactor svg { width: 100%; height: 100%; overflow: visible; }

.ring {
  fill: none;
  stroke: var(--holo);
  transform-origin: 100px 100px;
  filter: drop-shadow(0 0 3px var(--holo));
}
.r1 { stroke-width: 1; stroke-dasharray: 3 7; opacity: 0.6; animation: spin 40s linear infinite; }
.r2 { stroke-width: 2.5; stroke-dasharray: 60 22 8 22; opacity: 0.85; animation: spin 18s linear infinite reverse; }
.r3 { stroke-width: 1; stroke-dasharray: 1 5; opacity: 0.7; animation: spin 26s linear infinite; }
.r4 { stroke-width: 4; stroke-dasharray: 90 30; opacity: 0.9; animation: spin 9s linear infinite; }

.ticks line { stroke: var(--holo-soft); stroke-width: 1.5; }

.core-glow {
  fill: rgba(95, 225, 255, 0.18);
  stroke: var(--holo);
  stroke-width: 1;
  filter: drop-shadow(0 0 12px var(--holo));
  animation: breathe 3.2s ease-in-out infinite;
  transform-origin: 100px 100px;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { transform: scale(0.88); opacity: 0.7; } }

/* busy = a trade is coming in: everything spins up */
.reactor.busy .ring { animation-duration: 3s; }
.reactor.busy .core-glow { fill: rgba(61, 255, 197, 0.3); stroke: var(--long); }

.core-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  letter-spacing: 0.25em;
  color: var(--text);
  text-shadow: var(--glow);
}

.readout { margin: 0; display: grid; gap: 10px; }
.readout div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--holo-faint);
  font-size: 11px;
}
.readout dt { color: var(--dim); letter-spacing: 0.15em; }
.readout dd { margin: 0; color: var(--holo); text-shadow: var(--glow); text-align: right; }

/* ---- console ----------------------------------------------------------- */

.screen {
  flex: 1;
  min-height: 0;
  margin: 0;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  text-shadow: 0 0 6px rgba(95, 225, 255, 0.35);
  scrollbar-width: thin;
  scrollbar-color: var(--holo-soft) transparent;
}

.line { min-height: 1.55em; animation: flicker-in 0.25s ease-out; }
/* wrapped detail text stays under the └, not back at the left edge */
.line.detail { padding-left: 6ch; text-indent: -2ch; }

@keyframes flicker-in { 0% { opacity: 0.2; } 40% { opacity: 1; } 60% { opacity: 0.6; } 100% { opacity: 1; } }

.prompt { color: var(--holo); }
.dim { color: var(--dim); }
.long { color: var(--long); text-shadow: 0 0 8px rgba(61, 255, 197, 0.5); }
.short { color: var(--short); text-shadow: 0 0 8px rgba(255, 93, 125, 0.5); }
.accent { color: var(--accent); text-shadow: 0 0 8px rgba(255, 195, 92, 0.45); }
.ok { color: var(--long); }

.cursor {
  display: inline-block;
  width: 0.6em;
  height: 1.15em;
  vertical-align: text-bottom;
  background: var(--holo);
  box-shadow: var(--glow);
  animation: blink 1s steps(1) infinite;
}

/* solid while "keys" are being pressed, like a real terminal */
.cursor.busy { animation: none; }
.cursor.hidden { display: none; }

@keyframes blink { 50% { opacity: 0; } }

/* ---- open positions ---------------------------------------------------- */

.title-meta {
  order: 2;
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--dim);
  text-shadow: none;
}

.title-meta.stale { color: var(--accent); }

/* --fit is set by app.js (fitPositions) so every row fits the panel's
   height; overflow stays hidden unless even the smallest scale can't */
.positions-scroll {
  --fit: 1;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--holo-soft) transparent;
}

.positions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: calc(15px * var(--fit));
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.positions-table th {
  position: sticky;
  top: 0;
  padding: 0 calc(12px * var(--fit)) calc(8px * var(--fit)) 0;
  text-align: left;
  font-size: calc(11px * var(--fit));
  font-weight: 400;
  letter-spacing: 0.18em;
  color: var(--dim);
  background: rgba(4, 22, 36, 0.92);
}

.positions-table td {
  padding: calc(8px * var(--fit)) calc(12px * var(--fit)) calc(8px * var(--fit)) 0;
  border-top: 1px solid var(--holo-faint);
  color: var(--text);
  text-shadow: 0 0 6px rgba(95, 225, 255, 0.25);
}

.positions-table .num { text-align: right; }
.positions-table td.symbol { color: var(--holo); font-weight: 600; }
.positions-table td.long, .positions-table td.short { font-weight: 600; }
.positions-table tr.empty td { color: var(--dim); border-top: 0; letter-spacing: 0.12em; }
.positions-table .sub { display: block; font-size: 0.8em; color: var(--dim); }

/* dense (many positions): one line per row — ROE next to PnL, the
   exchange / margin-mode captions dropped (the panel title names the
   exchange already) */
.positions-table.dense .sub { display: inline; margin-left: 0.6em; }
.positions-table.dense .sub.minor { display: none; }
.positions-table.dense td { padding-top: calc(3px * var(--fit)); padding-bottom: calc(3px * var(--fit)); }

/* unrealized PnL: the whole cell goes green in profit, red in loss */
.positions-table td.pnl { padding-left: calc(12px * var(--fit)); }
.positions-table td.pnl-up {
  color: var(--long);
  background: linear-gradient(90deg, rgba(61, 255, 197, 0.08), rgba(61, 255, 197, 0.22));
  box-shadow: inset -3px 0 0 var(--long);
  text-shadow: 0 0 8px rgba(61, 255, 197, 0.6);
}
.positions-table td.pnl-down {
  color: var(--short);
  background: linear-gradient(90deg, rgba(255, 93, 125, 0.08), rgba(255, 93, 125, 0.24));
  box-shadow: inset -3px 0 0 var(--short);
  text-shadow: 0 0 8px rgba(255, 93, 125, 0.6);
}
.positions-table td.pnl-up .sub,
.positions-table td.pnl-down .sub { color: inherit; opacity: 0.8; }

/* a value that just changed flares for a moment (brightness, so it works
   on top of the PnL cell's own colour) */
.positions-table td.changed { animation: value-flash 1.2s ease-out; }
@keyframes value-flash { 0% { filter: brightness(1.9); } 100% { filter: none; } }

/* ---- telemetry --------------------------------------------------------- */

.hint { margin: -8px 0 14px; font-size: 11px; color: var(--dim); letter-spacing: 0.1em; }

.metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px solid var(--holo-faint);
}

.metric-label { font-size: 10px; letter-spacing: 0.22em; color: var(--dim); }

.metric-value {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  color: var(--holo);
  text-shadow: var(--glow);
}

.metric.account { padding-top: 0; margin-bottom: 14px; }
.section-title {
  margin: 18px 0 2px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.28em;
  color: var(--holo);
  text-shadow: var(--glow);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--holo-soft), transparent);
}
.metric-row { display: flex; gap: 18px; }
.metric-row .metric { flex: 1; }
.metric-value.big { font-size: 34px; }
.metric-sub { font-size: 11px; color: var(--dim); letter-spacing: 0.06em; }
.metric-sub b { font-weight: 400; color: var(--text); font-variant-numeric: tabular-nums; }
#equity-asset.stale { color: var(--accent); }
/* equity moved since the last refresh */
.metric-value.tick { animation: value-flash 1.2s ease-out; }

.metric-value.long { color: var(--long); }
.metric-value.short { color: var(--short); }

/* one bar per closed trade in the window, height = |pnl %| */
.bars {
  flex: 1;
  min-height: 60px;
  margin-top: 16px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  border-bottom: 1px solid var(--holo-soft);
}

.bar {
  flex: 1;
  max-width: 14px;
  min-height: 3px;
  background: linear-gradient(to top, rgba(61, 255, 197, 0.15), var(--long));
  box-shadow: 0 0 6px rgba(61, 255, 197, 0.45);
  transition: height 0.6s ease-out;
}

.bar.neg {
  background: linear-gradient(to top, rgba(255, 93, 125, 0.15), var(--short));
  box-shadow: 0 0 6px rgba(255, 93, 125, 0.45);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- smaller screens --------------------------------------------------- */

@media (max-width: 1100px) {
  body { overflow: auto; height: auto; min-height: 100%; }
  .hud { flex: none; grid-template-columns: 1fr 1fr; }
  .core, .stats { min-height: auto; }
  .bars { flex: none; height: 80px; }
  .center { grid-column: 1 / -1; grid-row: 1; }
  .center .console { height: 60vh; flex: none; }
  .center .positions { flex: none; }
  .positions-scroll { overflow: auto; }
}

@media (max-width: 640px) {
  body { font-size: 12px; }
  .topbar { padding: 12px 16px; letter-spacing: 0.12em; font-size: 10px; }
  .hud { grid-template-columns: 1fr; gap: 14px; padding: 14px 16px 20px; }
  .center .console { height: 65vh; }
  .positions-table { font-size: 11.5px; }
  .reactor { width: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
