:root {
  --bg: #04050a;
  --ink: #e8ecf6;
  --dim: #8b93a8;
  --faint: #566078;
  --line: rgba(140, 160, 210, .16);
  --glass: rgba(10, 13, 24, .62);
  --up: #3dffb4;
  --down: #ff4d6d;
  --accent: #6ad7ff;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pad: clamp(12px, 2vw, 24px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(120% 90% at 50% 40%, #0a1022 0%, var(--bg) 62%);
  color: var(--ink);
  font: 14px/1.4 var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }

.lbl {
  position: absolute; left: 0; top: 0;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(6, 9, 18, .72);
  border: 1px solid var(--line);
  font: 600 11px/1.2 var(--mono);
  letter-spacing: .02em;
  white-space: nowrap;
  will-change: transform;
  transition: opacity .25s;
}
.lbl b { font-weight: 700; margin-left: 6px; }
.lbl.up b { color: var(--up); }
.lbl.down b { color: var(--down); }
.lbl.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 18px rgba(106, 215, 255, .35); }

/* ---------- top ---------- */
.top {
  position: fixed; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: calc(var(--pad) + env(safe-area-inset-top)) var(--pad) 0;
  pointer-events: none;
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  border: 1px solid var(--line); background: var(--glass);
  display: grid; place-items: center; position: relative;
}
.logo span { width: 12px; height: 12px; border-radius: 50%; background: var(--up); box-shadow: 0 0 16px var(--up); animation: beat 2.4s ease-in-out infinite; }
@keyframes beat { 50% { transform: scale(.7); opacity: .7; } }
h1 { margin: 0; font: 800 18px/1 var(--sans); letter-spacing: .14em; }
h1 i { color: var(--up); font-style: normal; }
.tag { margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--dim); font-size: 12px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px 2px 8px; border-radius: 999px;
  font: 700 10.5px/1.6 var(--mono); letter-spacing: .12em; text-transform: uppercase;
  border: 1px solid currentColor;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.live { color: var(--up); }
.pill.live::before { animation: blink 1.4s steps(2) infinite; }
.pill.wait { color: var(--accent); }
.pill.off { color: var(--down); }
@keyframes blink { 50% { opacity: .25; } }
.paper { padding: 2px 9px; border-radius: 999px; background: rgba(255, 255, 255, .06); border: 1px solid var(--line); font-size: 11.5px; color: var(--ink); }

.equity { text-align: right; }
.eq-label { color: var(--dim); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }
.eq-value { font: 700 clamp(26px, 4.4vw, 46px)/1.05 var(--mono); letter-spacing: -.02em; text-shadow: 0 0 28px rgba(106, 215, 255, .25); }
.eq-pnl { font: 600 13px/1.4 var(--mono); color: var(--dim); }
.eq-pnl.up { color: var(--up); }
.eq-pnl.down { color: var(--down); }

/* ---------- stats ---------- */
.stats {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(var(--pad) + env(safe-area-inset-top));
  display: flex; gap: 0;
  background: var(--glass); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.stats div { padding: 9px 18px; text-align: center; border-left: 1px solid var(--line); }
.stats div:first-child { border-left: 0; }
.stats b { display: block; font: 700 17px/1.2 var(--mono); }
.stats span { display: block; color: var(--dim); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }

/* ---------- panels ---------- */
.panel {
  position: fixed;
  background: var(--glass); border: 1px solid var(--line); border-radius: 16px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 14px 14px 10px;
  display: flex; flex-direction: column; min-height: 0;
}
.panel h2 { margin: 0 0 8px; font: 700 11px/1.3 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--dim); display: flex; justify-content: space-between; }
.panel h2 em { font-style: normal; color: var(--faint); letter-spacing: .04em; text-transform: none; }
.panel.left { left: var(--pad); top: 132px; width: 264px; max-height: calc(100vh - 132px - 250px); }
.panel.right { right: var(--pad); top: 132px; width: 264px; max-height: calc(100vh - 132px - 250px); }
.panel.chart { left: 50%; transform: translateX(-50%); bottom: 44px; width: min(760px, calc(100vw - 2 * var(--pad))); height: 172px; }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 9px; font: 600 12.5px/1.3 var(--mono); }
.list li + li { margin-top: 2px; }
#pos-list li { cursor: pointer; }
#pos-list li:hover, #pos-list li.sel { background: rgba(106, 215, 255, .1); }
.list .sym { display: flex; align-items: center; gap: 8px; min-width: 0; }
.list .sym span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--dim); box-shadow: 0 0 8px currentColor; }
.up .dot { background: var(--up); color: var(--up); }
.down .dot { background: var(--down); color: var(--down); }
.list .val { text-align: right; white-space: nowrap; }
.list .val small { display: block; color: var(--faint); font-weight: 500; font-size: 10.5px; }
.up .val > span { color: var(--up); }
.down .val > span { color: var(--down); }
.feed li { font-weight: 500; color: var(--ink); }
.feed li.new { animation: slide .5s ease-out; }
.feed .what small { color: var(--faint); white-space: nowrap; }
.feed time { color: var(--faint); font-size: 10.5px; flex: none; }
.feed .what b { font-weight: 700; }
.feed .up .what i, .feed .down .what i { font-style: normal; font-weight: 700; }
.feed .up .what i { color: var(--up); }
.feed .down .what i { color: var(--down); }
@keyframes slide { from { opacity: 0; transform: translateY(-6px); } }
.empty { margin: 6px 8px 8px; color: var(--faint); font-size: 12.5px; }

.chart-wrap { position: relative; flex: 1; min-height: 0; }
#chart { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }

.tip {
  position: fixed; z-index: 5; pointer-events: none;
  padding: 5px 9px; border-radius: 8px;
  background: rgba(6, 9, 18, .92); border: 1px solid var(--line);
  font: 600 11.5px/1.35 var(--mono); white-space: nowrap;
}
.chart-wrap .tip { position: absolute; }
.tip small { display: block; color: var(--dim); font-weight: 500; }

/* ---------- selected coin card ---------- */
.card {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, 70px);
  width: 250px; padding: 14px 16px 12px;
  background: rgba(8, 11, 22, .86); border: 1px solid var(--accent); border-radius: 16px;
  box-shadow: 0 0 40px rgba(106, 215, 255, .18);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.card[hidden] { display: none; }
.card button { position: absolute; right: 8px; top: 6px; width: 28px; height: 28px; border: 0; background: none; color: var(--dim); font-size: 20px; cursor: pointer; border-radius: 8px; }
.card button:hover { color: var(--ink); background: rgba(255, 255, 255, .08); }
.card-sym { font: 800 20px/1.1 var(--mono); }
.card-name { color: var(--dim); font-size: 12px; margin: 2px 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card dl { margin: 0; display: grid; gap: 6px; }
.card dl div { display: flex; justify-content: space-between; }
.card dt { color: var(--dim); font-size: 12px; }
.card dd { margin: 0; font: 700 13px/1.3 var(--mono); }
.card dd.up { color: var(--up); }
.card dd.down { color: var(--down); }

/* ---------- foot ---------- */
.foot {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 0 var(--pad) calc(12px + env(safe-area-inset-bottom));
  display: flex; justify-content: space-between; gap: 12px;
  color: var(--faint); font-size: 11.5px; pointer-events: none;
}
.tabs { display: none; }
.noscript { position: fixed; inset: auto 0 40%; text-align: center; color: var(--dim); }

body.no3d #scene, body.no3d #labels, body.no3d .hint { display: none; }

/* ---------- medium ---------- */
@media (max-width: 1180px) {
  .stats { top: auto; bottom: 228px; }
  .panel.left, .panel.right { top: 108px; width: 232px; max-height: calc(100vh - 108px - 320px); }
}

/* ---------- phone ---------- */
@media (max-width: 760px) {
  body { font-size: 13px; }
  h1 { font-size: 15px; }
  .logo { width: 32px; height: 32px; border-radius: 10px; }
  .tag { font-size: 11px; gap: 6px; }
  .paper { font-size: 10.5px; }
  .top { flex-direction: column; gap: 8px; }
  .equity { text-align: left; }
  .eq-label { display: none; }
  .stats {
    left: var(--pad); right: var(--pad); transform: none; top: auto;
    bottom: calc(40vh + 58px + env(safe-area-inset-bottom));
    display: grid; grid-template-columns: repeat(4, 1fr);
  }
  .stats div { padding: 7px 4px; }
  .stats div:last-child { display: none; }
  .stats b { font-size: 14px; }
  .stats span { font-size: 9px; letter-spacing: .04em; }
  .tabs {
    position: fixed; left: var(--pad); right: var(--pad);
    bottom: calc(40vh + 14px + env(safe-area-inset-bottom));
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px;
    background: var(--glass); border: 1px solid var(--line); border-radius: 12px;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  }
  .tabs button { border: 0; border-radius: 9px; padding: 8px 4px; background: none; color: var(--dim); font: 700 11px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; }
  .tabs button.on { background: rgba(106, 215, 255, .14); color: var(--ink); }
  .panel, .panel.left, .panel.right, .panel.chart {
    left: var(--pad); right: var(--pad); top: auto; transform: none; width: auto; max-height: none;
    bottom: calc(8px + env(safe-area-inset-bottom)); height: 40vh;
    display: none;
  }
  .panel.show { display: flex; }
  .foot { display: none; }
  .card { top: 30%; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .logo span, .pill.live::before, .feed li.new { animation: none; }
}
