:root {
  --bg: #0b0e17;
  --bg-2: #10152a;
  --panel: #141a2e;
  --panel-2: #1b2340;
  --line: #273055;
  --text: #e8ecff;
  --muted: #8a93b8;
  --accent: #7c5cff;
  --accent-2: #ffd166;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 12px;
  --font-ui: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
  --font-pixel: "Press Start 2P", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #121733, #0e1226);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { font-family: var(--font-pixel); font-size: 12px; letter-spacing: 1px; color: #fff; }
.brand-sub { color: var(--muted); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.clock { font-family: var(--font-pixel); font-size: 11px; color: var(--accent-2); }
.status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 8px currentColor; }
.status.online .dot { background: var(--ok); color: var(--ok); }
.status.offline .dot { background: var(--bad); color: var(--bad); }
.status.busy .dot { background: var(--accent); color: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }

/* Layout */
.layout { display: flex; flex: 1 1 auto; min-height: 0; }
.stage {
  flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column;
  background:
    radial-gradient(1200px 600px at 50% 20%, #182046 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 31px, #ffffff06 31px 32px),
    repeating-linear-gradient(90deg, transparent 0 31px, #ffffff06 31px 32px),
    var(--bg);
}
.stage-inner { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 12px; }
#scene {
  max-width: 100%; max-height: 100%; width: auto; height: auto;
  image-rendering: pixelated; image-rendering: crisp-edges;
  cursor: default;
}
#scene.hover { cursor: pointer; }
.bubbles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.bubble {
  position: absolute; transform: translate(-50%, -100%);
  max-width: 230px; padding: 7px 10px; border-radius: 10px;
  background: #fffdf6; color: #141a2e; font-size: 12.5px; line-height: 1.3;
  border: 2px solid var(--bc, #333); box-shadow: 0 4px 0 #0008;
  animation: pop .18s ease-out; pointer-events: none; white-space: normal; word-wrap: break-word;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: var(--bc, #333); border-bottom: 0;
}
.bubble::before {
  content: ""; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: #fffdf6; border-bottom: 0; z-index: 1;
}
.bubble .who { display: block; font-family: var(--font-pixel); font-size: 7px; color: var(--bc); margin-bottom: 4px; letter-spacing: .5px; }
.bubble.excited { background: #fff7d6; }
.bubble.annoyed { background: #ffe4e4; }
.bubble.thinking { background: #e8f0ff; }
.bubble.laughing { background: #e9ffe6; }
@keyframes pop { from { transform: translate(-50%, -100%) scale(.7); opacity: 0; } }
.stage-hint { position: absolute; left: 16px; bottom: 10px; font-size: 11px; color: var(--muted); opacity: .8; }

.roster { display: flex; gap: 8px; padding: 8px 12px 12px; flex-wrap: wrap; justify-content: center; flex: 0 0 auto; }
.roster .chip {
  display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-size: 12px;
  transition: border-color .15s, transform .15s;
}
.roster .chip:hover { border-color: var(--c); transform: translateY(-1px); }
.roster .chip img { width: 24px; height: 24px; image-rendering: pixelated; border-radius: 50%; background: #0008; }
.roster .chip .act { color: var(--muted); font-size: 11px; }
.roster .chip.talking { border-color: var(--c); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 35%, transparent); }

/* Side panel */
.panel {
  flex: 0 0 390px; display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--line); background: var(--panel);
}
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.tab {
  flex: 1; padding: 12px 8px; background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); cursor: pointer; font-weight: 600; font-size: 13px;
}
.tab.active { color: #fff; border-bottom-color: var(--accent); }
.tab-page { display: none; flex: 1 1 auto; min-height: 0; flex-direction: column; }
.tab-page.active { display: flex; }

/* Chat */
.chat-log { flex: 1 1 auto; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.msg { display: flex; gap: 10px; align-items: flex-start; animation: fade .25s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.msg img { width: 32px; height: 32px; image-rendering: pixelated; border-radius: 8px; background: #0006; flex: 0 0 auto; border: 1px solid var(--line); }
.msg .body { min-width: 0; }
.msg .name { font-size: 11px; font-weight: 700; letter-spacing: .3px; color: var(--c, var(--muted)); }
.msg .name .role { font-weight: 400; color: var(--muted); margin-left: 6px; }
.msg .text { background: var(--panel-2); padding: 7px 10px; border-radius: 0 10px 10px 10px; margin-top: 3px; font-size: 13px; }
.msg.holder .text { background: #2b2355; border: 1px solid #5b48c7; }
.msg.holder .name { color: var(--accent-2); }
.msg.system { justify-content: center; }
.msg.system .text { background: none; color: var(--muted); font-size: 12px; font-style: italic; padding: 2px 0; }
.msg.system .text a { color: var(--accent-2); }
.scene-title { text-align: center; font-size: 11px; color: var(--muted); letter-spacing: .5px; text-transform: uppercase; margin-top: 4px; }
.scene-title::before, .scene-title::after { content: " — "; }

.tip-form { display: flex; gap: 8px; padding: 10px 12px 4px; border-top: 1px solid var(--line); flex: 0 0 auto; }
.tip-form input {
  flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); outline: none;
}
.tip-form input:focus { border-color: var(--accent); }
.tip-form button {
  padding: 10px 14px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; font-weight: 700; cursor: pointer;
}
.tip-form button:disabled { opacity: .5; cursor: not-allowed; }
.tip-help { padding: 0 12px 10px; font-size: 11px; color: var(--muted); }

/* Coin lab */
#coin-lab { flex: 1 1 auto; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.stages { display: flex; gap: 4px; }
.stages .st { flex: 1; height: 6px; border-radius: 3px; background: var(--line); position: relative; }
.stages .st.done { background: var(--ok); }
.stages .st.now { background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }
.stage-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.stage-label b { color: var(--accent-2); }
.coin-hero { display: flex; gap: 14px; align-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.coin-logo { width: 96px; height: 96px; border-radius: 16px; background: var(--bg-2); border: 1px solid var(--line); overflow: hidden; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; position: relative; }
.coin-logo img { width: 100%; height: 100%; object-fit: cover; }
.coin-logo .ph { font-family: var(--font-pixel); font-size: 18px; color: var(--muted); }
.coin-logo.loading::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, #ffffff22, transparent); animation: shimmer 1.2s infinite; }
@keyframes shimmer { from { transform: translateX(-100%);} to { transform: translateX(100%);} }
.coin-name { font-family: var(--font-pixel); font-size: 14px; line-height: 1.5; }
.coin-ticker { color: var(--accent-2); font-weight: 700; }
.coin-tag { color: var(--muted); font-size: 12px; margin-top: 4px; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.card p { margin: 0; font-size: 13px; }
.card ul { margin: 0; padding-left: 18px; font-size: 13px; }
.card li { margin: 2px 0; }
.empty { color: var(--muted); font-style: italic; font-size: 13px; }
.coin-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); cursor: pointer; font-size: 12px; font-weight: 600; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.disclaimer { font-size: 11px; color: var(--muted); }

/* Agents grid */
.agent-grid { flex: 1 1 auto; overflow-y: auto; padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-content: start; }
.agent-card {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; transition: transform .15s, border-color .15s;
}
.agent-card:hover { transform: translateY(-2px); border-color: var(--c); }
.agent-card img { width: 64px; height: 64px; image-rendering: pixelated; }
.agent-card .n { font-family: var(--font-pixel); font-size: 9px; color: var(--c); }
.agent-card .r { font-size: 11px; color: var(--muted); }
.agent-card .a { font-size: 11px; color: var(--text); opacity: .8; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: #0009; backdrop-filter: blur(3px); }
.modal-card {
  position: relative; width: min(560px, 94vw); max-height: 90vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px;
  box-shadow: 0 20px 60px #000a; animation: rise .2s ease-out;
}
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.modal-card .close { position: absolute; top: 10px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; }
.profile-head { display: flex; gap: 16px; align-items: center; }
.profile-head img { width: 96px; height: 96px; image-rendering: pixelated; background: var(--bg-2); border-radius: 14px; border: 2px solid var(--c); }
.profile-head h2 { margin: 0; font-family: var(--font-pixel); font-size: 14px; color: var(--c); }
.profile-head .role { color: var(--muted); margin-top: 4px; }
.profile-head .quote { margin-top: 8px; font-style: italic; color: var(--text); }
.profile-section { margin-top: 16px; }
.profile-section h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.traits { display: flex; flex-wrap: wrap; gap: 6px; }
.traits span { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.skill { display: grid; grid-template-columns: 120px 1fr 36px; align-items: center; gap: 10px; font-size: 12px; margin: 5px 0; }
.skill .bar { height: 8px; background: var(--bg-2); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.skill .bar i { display: block; height: 100%; background: var(--c); width: 0; transition: width .6s ease-out; }
.skill .v { text-align: right; color: var(--muted); }
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 12px; }
.stat b { display: block; font-size: 14px; color: #fff; }

/* Treasury */
.ticker { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.mode { font-family: var(--font-pixel); font-size: 8px; padding: 4px 6px; border-radius: 6px; background: #3b3f63; color: #fff; letter-spacing: .5px; }
.mode.paper { background: #4b5563; }
.mode.live { background: #16a34a; }
.ticker .eq { font-weight: 700; }
.pnl.up, .up { color: var(--ok); }
.pnl.down, .down { color: var(--bad); }
#treasury { flex: 1 1 auto; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.card.hero .big { font-family: var(--font-pixel); font-size: 18px; margin: 8px 0 4px; }
.card .row { display: flex; align-items: center; gap: 8px; }
.dim { color: var(--muted); font-size: 12px; }
.halt { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: #3b1d1d; border: 1px solid #7f1d1d; font-size: 12px; }
.thesis { margin-top: 8px; font-style: italic; font-size: 13px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; padding: 4px 0; }
.tbl td { padding: 6px 0; border-top: 1px solid var(--line); vertical-align: top; }
.trade { padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; align-items: center; }
.trade:first-child { border-top: 0; }
.trade .side { font-family: var(--font-pixel); font-size: 8px; padding: 3px 6px; border-radius: 4px; background: #14532d; color: #bbf7d0; }
.trade.sell .side { background: #7f1d1d; color: #fecaca; }
.trade .amt { font-weight: 600; }
.trade .who { color: var(--muted); font-size: 11px; }
.trade .why { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.trade a { color: var(--accent-2); }
.addr { display: flex; gap: 8px; align-items: center; margin: 6px 0 8px; }
.addr code { flex: 1; font-size: 11px; word-break: break-all; background: var(--bg-2); padding: 8px; border-radius: 8px; border: 1px solid var(--line); }
.perks, .rules, .wall { margin: 6px 0; padding-left: 18px; font-size: 13px; }
.wall { list-style: none; padding: 0; }
.wall li { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--line); font-size: 12px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.split h5 { margin: 0 0 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.gallery .art img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.perk-form { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.perk-form input { padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font-size: 13px; outline: none; }
.perk-form input:focus { border-color: var(--accent); }
.card.launch { border-color: var(--accent-2); }
.card.research { border-color: #2dd4bf55; }
.card.research h5 { margin: 10px 0 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.trends, .seeds { margin: 0; padding-left: 16px; font-size: 13px; }
.trends li, .seeds li { margin: 4px 0; }
.trends a { color: var(--accent-2); font-size: 11px; }
.card.launch a { color: var(--accent-2); }
.launched { list-style: none; margin: 4px 0 8px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.launched li { display: flex; gap: 10px; align-items: center; font-size: 13px; }
.launched img { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); }

/* Holder vote */
.card.poll { border-color: #7c5cff; }
.vote-opt { padding: 8px 0; border-top: 1px solid var(--line); }
.vote-opt:first-of-type { border-top: 0; }
.vote-opt.mine .vote-row span { color: var(--accent-2); }
.vote-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; }
.vote-bar { height: 6px; border-radius: 3px; background: var(--bg-2); overflow: hidden; margin: 6px 0 4px; }
.vote-bar i { display: block; height: 100%; background: var(--accent); }
.vote-opt.win .vote-bar i { background: var(--ok); }
.vote-foot { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
a.btn { text-decoration: none; display: inline-block; }

/* Leaderboard */
.agents-scroll { flex: 1 1 auto; overflow-y: auto; }
.agents-scroll .agent-grid { overflow: visible; }
#leaderboard { padding: 12px 12px 0; }
.board-row { display: grid; grid-template-columns: 22px 28px 1fr auto auto; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.board-row:first-of-type { border-top: 0; }
.board-row .rank { font-family: var(--font-pixel); font-size: 10px; color: var(--muted); }
.board-row img { width: 28px; height: 28px; image-rendering: pixelated; border-radius: 6px; background: #0006; }
.board-row .nm { font-weight: 700; }

/* Scalper */
.card.scalper { border-color: #f59e0b88; }
.card.scalper .stat-row { margin: 6px 0 8px; }
.sub-h { margin: 8px 0 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.watch { margin: 0; padding-left: 16px; font-size: 12px; }
.watch li { margin: 3px 0; }

/* Upgrades */
.upgrades { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.upgrades li { display: flex; gap: 10px; font-size: 13px; }
.upgrades li > div { flex: 1; }
.upgrades li:not(.have) b { color: var(--muted); }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid var(--panel); }

/* Mobile */
@media (max-width: 900px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100vh; }
  .layout { flex-direction: column; }
  .stage-inner { padding: 8px; }
  .panel { flex: 0 0 auto; border-left: 0; border-top: 1px solid var(--line); height: 70vh; }
  .brand-sub { display: none; }
  .agent-grid { grid-template-columns: 1fr 1fr 1fr; }
}

/* news radar */
.radar-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 8px; }
.radar-list li { font-size: 12px; line-height: 1.35; }
.radar-list a { color: inherit; }
.radar .score { display: inline-block; min-width: 20px; text-align: center; border-radius: 4px; font-weight: 700; font-size: 11px; padding: 0 4px; }
.radar .score.shot { background: #ef4444; color: #fff; }
.radar .score.swarm { background: #f59e0b; color: #111; }
.radar .score.scool { background: rgba(148, 163, 184, .25); }
