:root {
  --bg: #0b1020;
  --bg-2: #111832;
  --panel: #151d3b;
  --panel-2: #1b2550;
  --line: #2a3672;
  --ink: #eef1ff;
  --ink-2: #aab3dd;
  --ink-3: #7480b4;
  --gold: #ffc94a;
  --gold-2: #ffdf87;
  --gain: #3ee08f;
  --loss: #ff5d73;
  --warn: #ffb547;
  --info: #6cb6ff;
  --accent: #9b7bff;
  --radius: 14px;
  --shadow: 0 0 0 1px var(--line), 0 10px 30px rgba(0, 0, 0, .35);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #1d2a66 0%, transparent 60%), var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 14px/1.45 var(--sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, select { font: inherit; color: inherit; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.muted { color: var(--ink-3); }
.hidden { display: none !important; }

/* ---- top bar --------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: rgba(11, 16, 32, .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: .2px; }
.brand-logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--gold), #ff9b3d); color: #3a2300; font-weight: 900;
  box-shadow: 0 0 18px rgba(255, 201, 74, .45);
}
.badge {
  font: 700 11px/1 var(--mono); letter-spacing: .6px; padding: 5px 8px; border-radius: 999px;
  border: 1px solid currentColor; text-transform: uppercase;
}
.badge.paper { color: var(--info); }
.badge.sim { color: var(--accent); }
.pills { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 999px;
  background: var(--panel); box-shadow: 0 0 0 1px var(--line); font-size: 12.5px; color: var(--ink-2);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.ok { background: var(--gain); box-shadow: 0 0 10px var(--gain); animation: pulse 2s infinite; }
.dot.warn { background: var(--warn); box-shadow: 0 0 10px var(--warn); }
.dot.bad { background: var(--loss); box-shadow: 0 0 10px var(--loss); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.icon-btn {
  background: var(--panel); border: 0; box-shadow: 0 0 0 1px var(--line); border-radius: 10px;
  padding: 6px 10px; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { color: var(--ink); background: var(--panel-2); }
.icon-btn[aria-pressed="true"] { color: var(--gold); }

/* ---- layout ---------------------------------------------------------- */
main { max-width: 1440px; margin: 0 auto; padding: 18px 20px 40px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
main > *, .arena > * { min-width: 0; }
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 13px; letter-spacing: .3px; text-transform: uppercase; color: var(--ink-2);
}
.panel-head .right { margin-left: auto; display: flex; gap: 6px; align-items: center; text-transform: none; font-weight: 500; }

/* ---- stats ----------------------------------------------------------- */
.stats { display: grid; grid-template-columns: minmax(0, 1.6fr) repeat(6, minmax(0, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; position: relative; overflow: hidden; }
.stat .label { font-size: 11.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }
.stat .value { font: 700 20px/1.25 var(--mono); font-variant-numeric: tabular-nums; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.hero { background: linear-gradient(135deg, #2a2357, #1a2350); }
.stat.hero .value { font-size: 30px; color: var(--gold); text-shadow: 0 0 22px rgba(255, 201, 74, .35); }
.stat.hero::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 120px; height: 120px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 201, 74, .25), transparent 70%);
}
.flash-gain { animation: flashg 1.2s; }
.flash-loss { animation: flashl 1.2s; }
@keyframes flashg { 0% { background-color: rgba(62, 224, 143, .25); } }
@keyframes flashl { 0% { background-color: rgba(255, 93, 115, .25); } }

/* ---- game + feed ----------------------------------------------------- */
.arena { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; }
.city { overflow: hidden; position: relative; }
.city canvas { display: block; width: 100%; aspect-ratio: 16 / 9; max-width: 100%; background: #2d7fc4; touch-action: none; cursor: grab; }
.city canvas:active { cursor: grabbing; }
.scene-wrap { position: relative; }
.scene-controls { position: absolute; right: 12px; top: 12px; display: grid; gap: 6px; z-index: 2; }
.scene-controls button {
  width: 36px; height: 36px; border-radius: 10px; border: 0; cursor: pointer; font-size: 18px; font-weight: 800;
  background: rgba(11, 16, 32, .78); color: var(--ink); box-shadow: 0 0 0 1px var(--line), 0 4px 12px rgba(0, 0, 0, .3);
}
.scene-controls button:hover, .scene-controls button:focus-visible { background: var(--panel-2); outline: 2px solid var(--gold); outline-offset: 1px; }
.scene-card {
  position: absolute; left: 12px; top: 12px; z-index: 2; max-width: min(300px, calc(100% - 72px)); padding: 12px 34px 12px 14px;
  border-radius: 12px; background: rgba(11, 16, 32, .9); box-shadow: 0 0 0 1px var(--line), 0 10px 24px rgba(0, 0, 0, .4);
  display: grid; gap: 3px; font-size: 13px; animation: pop .3s cubic-bezier(.2, 1.4, .4, 1);
}
.scene-card b:first-of-type { font-size: 16px; color: var(--gold); }
.scene-card .x { position: absolute; right: 6px; top: 4px; border: 0; background: none; color: var(--ink-3); font-size: 20px; cursor: pointer; }
.scene-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 1; pointer-events: none; white-space: nowrap;
  padding: 7px 12px; border-radius: 999px; background: rgba(11, 16, 32, .75); color: var(--ink); font-size: 12.5px; transition: opacity .8s;
}
.scene-hint.fade { opacity: 0; }

.ticker { overflow: hidden; white-space: nowrap; border-top: 1px solid var(--line); background: #070b18; font: 12px/30px var(--mono); }
.ticker-inner { display: inline-block; padding-left: 100%; animation: tick 60s linear infinite; }
.ticker-inner span { margin-right: 36px; color: var(--ink-2); }
@keyframes tick { to { transform: translateX(-100%); } }

.feed { display: flex; flex-direction: column; min-height: 0; max-height: 100%; }
.arena > .feed { height: 0; min-height: 100%; }
.feed-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.feed-item {
  display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 9px 8px; border-radius: 10px;
  animation: slidein .45s ease;
}
.feed-item + .feed-item { border-top: 1px solid rgba(42, 54, 114, .5); }
.feed-item .ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 15px; background: var(--bg-2); }
.feed-item .msg { font-size: 13px; overflow-wrap: anywhere; }
.feed-item .when { font-size: 11.5px; color: var(--ink-3); }
.feed-item.fill .ico { background: rgba(255, 201, 74, .15); }
.feed-item.order .ico { background: rgba(108, 182, 255, .15); }
.feed-item.warning .ico { background: rgba(255, 181, 71, .15); }
.feed-item.error .ico { background: rgba(255, 93, 115, .18); }
@keyframes slidein { from { transform: translateX(16px); opacity: 0; background: rgba(255, 201, 74, .12); } }

/* ---- tabs + tables --------------------------------------------------- */
.tabs { display: flex; gap: 4px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--ink-3); font-weight: 700;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--ink); border-color: var(--gold); }
.tabpanel { padding: 14px 16px 16px; }
.seg { display: inline-flex; background: var(--bg-2); border-radius: 10px; padding: 3px; box-shadow: inset 0 0 0 1px var(--line); }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 8px; cursor: pointer; color: var(--ink-3); font-size: 12px; font-weight: 700; }
.seg button[aria-pressed="true"] { background: var(--panel-2); color: var(--ink); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.filters select { background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 6px 9px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--ink-3); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid rgba(42, 54, 114, .45); white-space: nowrap; }
td.wrap { white-space: normal; min-width: 220px; color: var(--ink-2); }
th.r, td.r { text-align: right; }
tbody tr:hover { background: rgba(255, 255, 255, .025); }
.tag { font: 700 11px/1 var(--mono); padding: 4px 7px; border-radius: 6px; display: inline-block; }
.tag.BUY, .tag.buy { color: var(--gain); background: rgba(62, 224, 143, .12); }
.tag.SELL, .tag.sell { color: var(--loss); background: rgba(255, 93, 115, .12); }
.tag.HOLD { color: var(--ink-3); background: rgba(116, 128, 180, .14); }
.tag.blocked { color: var(--warn); background: rgba(255, 181, 71, .12); }
.tag.ordered { color: var(--info); background: rgba(108, 182, 255, .12); }
.more { margin-top: 12px; }
.empty { padding: 30px; text-align: center; color: var(--ink-3); }

/* ---- charts ---------------------------------------------------------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 300px; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--ink-3); font: 11px var(--mono); }
.chart .tip {
  position: absolute; pointer-events: none; background: #0a0f22; box-shadow: 0 0 0 1px var(--line), 0 8px 20px rgba(0, 0, 0, .4);
  border-radius: 10px; padding: 8px 10px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -100%); opacity: 0; transition: opacity .1s;
}
.chart .tip b { font: 700 14px var(--mono); display: block; }
.chart-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 8px; flex-wrap: wrap; }
.chart-head .big { font: 700 22px var(--mono); }

/* ---- toasts + banners ------------------------------------------------ */
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 10px; z-index: 50; max-width: min(360px, calc(100vw - 36px)); }
.toast {
  display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; background: #141c3d;
  box-shadow: 0 0 0 1px var(--line), 0 12px 30px rgba(0, 0, 0, .5); animation: pop .4s cubic-bezier(.2, 1.4, .4, 1);
}
.toast .big-ico { font-size: 24px; }
.toast b { display: block; }
.toast.gold { box-shadow: 0 0 0 1px var(--gold), 0 0 24px rgba(255, 201, 74, .3); }
.toast.out { animation: fade .4s forwards; }
@keyframes pop { from { transform: translateY(20px) scale(.9); opacity: 0; } }
@keyframes fade { to { transform: translateX(30px); opacity: 0; } }
.banner { padding: 12px 16px; border-radius: 12px; background: rgba(255, 181, 71, .12); box-shadow: inset 0 0 0 1px rgba(255, 181, 71, .4); color: var(--warn); }

/* ---- login ----------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 28px; text-align: center; }
.login-card h1 { font-size: 20px; margin: 14px 0 4px; }
.login-card p { color: var(--ink-3); margin: 0 0 18px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2);
  color: var(--ink); font: inherit; margin-bottom: 12px;
}
.login-card input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.btn-gold {
  width: 100%; padding: 12px; border: 0; border-radius: 10px; cursor: pointer; font-weight: 800;
  background: linear-gradient(135deg, var(--gold), #ff9b3d); color: #3a2300;
}
.login-error { color: var(--loss) !important; font-weight: 600; }

/* ---- responsive ------------------------------------------------------ */
@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat.hero { grid-column: span 2; }
  .arena { grid-template-columns: minmax(0, 1fr); }
  .arena > .feed { height: auto; min-height: 0; max-height: 380px; }
}
@media (max-width: 640px) {
  main { padding: 12px 12px 32px; gap: 12px; }
  .topbar { padding: 10px 12px; }
  .pills { margin-left: 0; width: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 11px 12px; }
  .stat .value { font-size: 16px; }
  .stat.hero .value { font-size: 24px; }
  .chart svg { height: 240px; }
  .city canvas { aspect-ratio: 1 / 1; }
  .scene-hint { white-space: normal; text-align: center; width: max-content; max-width: calc(100% - 24px); }
  .toasts { right: 12px; bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  .ticker-inner { animation: none !important; padding-left: 16px; }
}
