:root {
  --bg: #07080c;
  --bg-2: #0f1118;
  --panel: #14161f;
  --panel-2: #191c27;
  --line: #242836;
  --text: #e9ecf3;
  --muted: #8b90a3;
  --cyan: #25f4ee;
  --red: #fe2c55;
  --gold: #ffcb57;
  --ok: #38d39f;
  --warn: #ffb020;
  --radius: 16px;
  --grad: linear-gradient(135deg, var(--cyan), var(--red));
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background:
    radial-gradient(1000px 600px at 12% -10%, rgba(37,244,238,.09), transparent 60%),
    radial-gradient(1000px 600px at 100% 0%, rgba(254,44,85,.09), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }
code { background: var(--bg-2); padding: 1px 6px; border-radius: 5px; font-size: 12px; color: var(--cyan); }

/* ---------- Brand ---------- */
.brand { font-weight: 900; letter-spacing: -.02em; font-size: 17px; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand em { font-style: normal; color: var(--muted); font-weight: 600; }
.brand-lg { font-size: 23px; margin-bottom: 6px; }
.logo-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--grad); box-shadow: 0 0 16px rgba(37,244,238,.5); }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; }
.login-card { width: min(380px, 90vw); background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 32px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.login-card input, .login-card button { padding: 13px 14px; border-radius: 11px; font-size: 15px; }
.login-card input { background: var(--bg-2); border: 1px solid var(--line); color: var(--text); }
.login-card button { border: 0; background: var(--grad); color: #04121a; font-weight: 800; }
.error { color: var(--red); font-size: 13px; min-height: 16px; }

/* ---------- App shell ---------- */
.app { height: 100vh; display: flex; flex-direction: column; padding: 14px; gap: 12px; max-width: 1600px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; flex: none; }
.connect { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 6px 6px 12px; margin-left: auto; }
.connect .at { color: var(--muted); font-weight: 700; }
.connect input { background: transparent; border: 0; color: var(--text); font-size: 15px; width: 170px; outline: none; }
.connect button { border: 0; border-radius: 9px; padding: 9px 16px; font-weight: 800; background: var(--grad); color: #04121a; }
.connect button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.connect button:disabled { opacity: .45; cursor: not-allowed; }
.status { display: flex; align-items: center; gap: 10px; }
.pill { padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; border: 1px solid var(--line); white-space: nowrap; }
.pill.idle { color: var(--muted); }
.pill.connecting { color: var(--warn); border-color: rgba(255,176,32,.4); }
.pill.live { color: #04121a; background: var(--cyan); border-color: transparent; box-shadow: 0 0 20px rgba(37,244,238,.4); }
.pill.ended, .pill.error { color: var(--red); border-color: rgba(254,44,85,.4); }
.pill.sendon { color: #04121a; background: var(--ok); border-color: transparent; }
.icon-btn { background: var(--panel); border: 1px solid var(--line); color: var(--text); width: 40px; height: 40px; border-radius: 11px; font-size: 16px; }

/* ---------- Studio grid ---------- */
.studio { flex: 1; min-height: 0; display: grid; grid-template-columns: 340px 1fr 340px; gap: 12px; }
.stage, .chatcol, .rail { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- Stage (video) ---------- */
.stage { padding: 12px; gap: 12px; }
.stage-video { position: relative; flex: 1; min-height: 0; border-radius: 12px; overflow: hidden; background: #000; display: flex; align-items: center; justify-content: center; }
.stage-video video { width: 100%; height: 100%; object-fit: cover; }
.stage-placeholder { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 20px;
  background: radial-gradient(400px 400px at 50% 40%, rgba(37,244,238,.12), transparent 70%), linear-gradient(160deg, #11131b, #0a0b10); }
.ph-glow { position: absolute; width: 220px; height: 220px; border-radius: 50%; background: var(--grad); filter: blur(80px); opacity: .25; }
.ph-avatar { width: 72px; height: 72px; border-radius: 50%; border: 2px solid var(--cyan); z-index: 1; object-fit: cover; }
.ph-icon { font-size: 44px; color: var(--cyan); z-index: 1; opacity: .8; }
.ph-text { color: var(--muted); font-size: 14px; z-index: 1; max-width: 240px; }
.ph-open { z-index: 1; color: #04121a; background: var(--grad); text-decoration: none; font-weight: 800; padding: 10px 16px; border-radius: 10px; font-size: 13px; }

.stage-top { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; z-index: 2; pointer-events: none; }
.live-badge { background: var(--red); color: #fff; font-weight: 900; font-size: 12px; padding: 5px 11px; border-radius: 999px; letter-spacing: .03em; box-shadow: 0 2px 12px rgba(254,44,85,.5); animation: livepulse 2s infinite; }
@keyframes livepulse { 0%,100%{opacity:1} 50%{opacity:.6} }
.viewers-badge { background: rgba(0,0,0,.5); backdrop-filter: blur(6px); color: #fff; font-weight: 700; font-size: 12px; padding: 5px 11px; border-radius: 999px; }
.stage-bottom { position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 2; background: linear-gradient(transparent, rgba(0,0,0,.75)); padding: 20px 4px 4px; border-radius: 10px; }
.stage-title { font-weight: 800; font-size: 15px; line-height: 1.3; text-shadow: 0 1px 4px rgba(0,0,0,.8); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.stage-sub { display: flex; gap: 8px; align-items: center; margin-top: 5px; }
.stage-owner { color: #d7dbe6; font-size: 13px; font-weight: 600; }
.stage-cat { font-size: 11px; font-weight: 800; color: var(--cyan); background: rgba(37,244,238,.15); padding: 2px 8px; border-radius: 999px; }
.stage-cat:empty { display: none; }

.float-hearts { position: absolute; right: 10px; bottom: 70px; width: 60px; height: 50%; pointer-events: none; z-index: 2; overflow: hidden; }
.heart { position: absolute; bottom: 0; font-size: 22px; animation: floatUp 2.6s ease-out forwards; }
@keyframes floatUp { 0%{transform:translateY(0) scale(.6);opacity:0} 15%{opacity:1} 100%{transform:translateY(-220px) translateX(var(--dx,0)) scale(1.1);opacity:0} }

/* quick stats */
.stage-stats { flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.qs { background: var(--bg-2); border: 1px solid var(--line); border-radius: 11px; padding: 9px 6px; text-align: center; }
.qs span { display: block; font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.qs span.gold { color: var(--gold); } .qs span.red { color: var(--red); }
.qs em { font-style: normal; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Chat column ---------- */
.col-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); flex: none; }
.col-head h2 { margin: 0; font-size: 15px; font-weight: 800; }
.toggle { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.feed { overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 7px; min-height: 0; }
.chat-feed { flex: 1; }
.feed::-webkit-scrollbar { width: 8px; }
.feed::-webkit-scrollbar-thumb { background: #2a2f40; border-radius: 8px; }

.row { display: flex; gap: 10px; padding: 7px 10px; border-radius: 12px; animation: slideIn .25s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.row:hover { background: var(--bg-2); }
.row.flagged { background: rgba(254,44,85,.1); border: 1px solid rgba(254,44,85,.3); }
.ava { width: 32px; height: 32px; border-radius: 50%; background: var(--panel-2); flex: none; object-fit: cover; border: 1px solid var(--line); }
.row .body { min-width: 0; }
.row .name { font-weight: 700; font-size: 12.5px; color: var(--muted); }
.row .name .you { color: var(--cyan); }
.row .text { font-size: 14px; color: #e9ecf3; word-wrap: break-word; line-height: 1.35; }
.row .flag-tag { display: inline-block; margin-top: 4px; font-size: 11px; color: var(--red); background: rgba(254,44,85,.15); padding: 2px 8px; border-radius: 6px; font-weight: 700; }
.row.self .text { color: var(--cyan); }

/* composer */
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: var(--bg-2); align-items: center; flex: none; }
.comp-ava { width: 34px; height: 34px; border-radius: 50%; background: var(--grad); display: grid; place-items: center; font-size: 16px; flex: none; }
.composer input { flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 11px 16px; font-size: 14px; outline: none; }
.composer input:focus { border-color: var(--cyan); }
.composer button { border: 0; border-radius: 999px; padding: 0 20px; height: 42px; font-weight: 800; background: var(--grad); color: #04121a; }
.composer input:disabled, .composer button:disabled { opacity: .4; cursor: not-allowed; }
.composer-hint { padding: 0 14px 10px; font-size: 11.5px; color: var(--muted); background: var(--bg-2); flex: none; }

/* ---------- Rail ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tab { flex: 1; background: transparent; border: 0; color: var(--muted); padding: 13px 4px; font-size: 13px; font-weight: 700; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--cyan); }
.tab-panel { display: none; flex: 1; min-height: 0; flex-direction: column; }
.tab-panel.active { display: flex; }
.rail-note { padding: 10px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--bg-2); flex: none; }
.badge { background: var(--red); color: #fff; border-radius: 999px; padding: 1px 7px; font-size: 11px; font-weight: 800; margin-left: 4px; }

.evt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; font-size: 13px; animation: slideIn .25s ease; }
.evt .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.evt.join .dot { background: var(--muted); }
.evt.follow .dot { background: var(--cyan); }
.evt.share .dot { background: #a78bfa; }
.evt.gift { background: rgba(255,203,87,.08); border: 1px solid rgba(255,203,87,.22); }
.evt .gift-img { width: 26px; height: 26px; border-radius: 6px; }
.evt b { font-weight: 700; }
.evt .diamonds { margin-left: auto; color: var(--gold); font-weight: 800; font-variant-numeric: tabular-nums; }

.leaderboard { overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; background: var(--bg-2); }
.lb-rank { width: 22px; text-align: center; font-weight: 800; color: var(--muted); }
.lb-rank.top { color: var(--gold); }
.lb-name { font-weight: 600; font-size: 13px; }
.lb-dia { margin-left: auto; color: var(--gold); font-weight: 800; font-variant-numeric: tabular-nums; }

.ob { padding: 10px 12px; border-radius: 10px; background: var(--bg-2); border-left: 3px solid var(--cyan); animation: slideIn .25s ease; }
.ob .to { font-size: 12px; color: var(--muted); }
.ob .msg { font-size: 14px; margin-top: 3px; }
.ob .st { float: right; font-size: 11px; font-weight: 800; padding: 1px 8px; border-radius: 6px; }
.ob.queued { border-left-color: var(--muted); } .ob.queued .st { color: var(--muted); background: rgba(139,144,163,.15); }
.ob.sending .st { color: var(--warn); background: rgba(255,176,32,.15); }
.ob.sent { border-left-color: var(--ok); } .ob.sent .st { color: var(--ok); background: rgba(56,211,159,.15); }
.ob.failed { border-left-color: var(--red); } .ob.failed .st { color: var(--red); background: rgba(254,44,85,.15); }
.empty { color: var(--muted); text-align: center; padding: 40px 10px; font-size: 13px; }

/* ---------- Log + drawer ---------- */
.logline { font-size: 12px; color: var(--muted); min-height: 16px; padding: 0 4px; flex: none; }
.logline.ok { color: var(--ok); } .logline.warn { color: var(--warn); } .logline.error { color: var(--red); }

.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; display: flex; justify-content: flex-end; }
.drawer-inner { width: min(460px, 94vw); height: 100%; background: var(--panel); border-left: 1px solid var(--line); padding: 22px; overflow-y: auto; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.drawer-head h2 { margin: 0; font-size: 18px; }
.field { margin-bottom: 24px; }
.field h3 { font-size: 14px; margin: 0 0 10px; }
.vars-hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; line-height: 1.7; }
.field textarea, .field > input { width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 11px; font-size: 14px; margin-top: 8px; }
.rule { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.rule input, .rule select { background: var(--bg-2); border: 1px solid var(--line); color: var(--text); border-radius: 9px; padding: 9px; font-size: 13px; }
.rule .reply { grid-column: 1 / 3; }
.rule .rm { background: transparent; border: 1px solid var(--line); color: var(--red); border-radius: 9px; padding: 8px 10px; }
.rule .en { display: flex; align-items: center; justify-content: center; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 14px; }
.ghost.small { padding: 7px 12px; font-size: 13px; }
.save { width: 100%; border: 0; background: var(--grad); color: #04121a; font-weight: 800; padding: 14px; border-radius: 12px; font-size: 15px; }
.saved { color: var(--ok); font-size: 13px; min-height: 16px; margin-top: 8px; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .studio { grid-template-columns: 300px 1fr; }
  .rail { display: none; }
}
@media (max-width: 860px) {
  .app { height: auto; min-height: 100vh; }
  .studio { grid-template-columns: 1fr; }
  .stage { order: 0; }
  .stage-video { aspect-ratio: 9/16; flex: none; }
  .chatcol { min-height: 60vh; }
  .connect { margin-left: 0; width: 100%; }
  .connect input { flex: 1; width: auto; }
}
