:root {
  --bg: #0e0e10;
  --panel: #18181b;
  --panel-2: #1f1f23;
  --line: #2f2f35;
  --text: #efeff1;
  --muted: #adadb8;
  --purple: #9147ff;
  --purple-2: #772ce8;
  --red: #eb0400;
  --mention: rgba(235, 4, 0, 0.18);
  --question: rgba(145, 71, 255, 0.16);
  --chat-font: 22px;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Roobert", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

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

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.live {
  display: flex; align-items: center; gap: 6px;
  background: var(--red); color: #fff; font-weight: 700; font-size: 12px;
  padding: 3px 8px; border-radius: 4px; letter-spacing: .04em;
}
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.title {
  flex: 1 1 240px; min-width: 0; background: transparent; border: 1px solid transparent;
  font-weight: 600; font-size: 15px; padding: 4px 6px; border-radius: 4px;
}
.title:hover, .title:focus { border-color: var(--line); outline: none; background: var(--bg); }
.stat { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }
.viewers { color: #ff8280; display: flex; gap: 4px; align-items: center; }
.actions { display: flex; gap: 6px; }

/* ---------- buttons ---------- */
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: #2c2c33; }
.btn.accent { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn.accent:hover { background: var(--purple-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.big { padding: 12px 22px; font-size: 17px; width: 100%; }
.btn.on { background: #1f6f3f; border-color: #2ea85f; color: #fff; }

/* ---------- layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.chat {
  flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative;
  background: var(--panel); border-right: 1px solid var(--line);
}
.chat-head {
  display: flex; justify-content: center; gap: 10px; align-items: center;
  padding: 10px; border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 700; letter-spacing: .08em; color: var(--muted);
}
.paused-tag { background: #b8860b; color: #000; padding: 1px 6px; border-radius: 3px; }

.panel {
  width: 340px; flex-shrink: 0; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 12px;
}
body.solo .panel, body.solo .topbar { display: none; }
body.solo .chat { border-right: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card h3 { margin: 0 0 10px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; line-height: 1.4; }
.row { display: flex; gap: 6px; margin-top: 10px; }
.row input, .drawer input:not([type=checkbox]):not([type=range]), .drawer select {
  flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px;
}
.row input:focus, .drawer input:focus { outline: 2px solid var(--purple); border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 10px; cursor: pointer; font-size: 13px;
}
.chip.active { background: var(--purple); border-color: var(--purple); color: #fff; }
.chip kbd { opacity: .6; margin-left: 4px; }
.count { background: var(--purple); color: #fff; border-radius: 999px; padding: 0 8px; font-size: 12px; }

.mic-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.mic-row .btn { flex: 1; }
.meter { width: 60px; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
#micLevel { height: 100%; width: 0; background: #2ea85f; transition: width .1s; }

.clips { margin: 0 0 8px; padding-left: 20px; max-height: 180px; overflow-y: auto; font-size: 13px; }
.clips li { margin-bottom: 4px; color: var(--muted); }
.clips li b { color: var(--text); font-variant-numeric: tabular-nums; }
.shortcuts p { margin: 0; color: var(--muted); line-height: 1.9; font-size: 12px; }
kbd { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 11px; font-family: inherit; }

/* ---------- messages ---------- */
.messages {
  flex: 1; overflow-y: auto; margin: 0; padding: 8px 0; list-style: none;
  font-size: var(--chat-font); line-height: 1.4;
  overscroll-behavior: contain;
}
.msg {
  padding: .22em .7em; word-wrap: break-word; overflow-wrap: anywhere; cursor: pointer;
  border-left: 4px solid transparent; animation: in .18s ease-out;
}
@keyframes in { from { opacity: 0; transform: translateY(6px); } }
.msg:hover { background: rgba(255,255,255,.05); }
.msg .time { color: var(--muted); font-size: .7em; margin-right: .4em; font-variant-numeric: tabular-nums; }
.msg .badge {
  display: inline-block; width: 1em; height: 1em; line-height: 1em; text-align: center; border-radius: 3px;
  font-size: .72em; vertical-align: .1em; margin-right: .22em; font-weight: 800;
}
.badge.mod { background: #00ad03; color: #fff; }
.badge.vip { background: #e005b9; color: #fff; }
.badge.sub { background: var(--purple); color: #fff; }
.badge.prime { background: #0e9bd8; color: #fff; }
.msg .name { font-weight: 700; }
.msg .emote { display: inline-block; transform: scale(1.15); margin: 0 .05em; }
.msg.question.hl { background: var(--question); border-left-color: var(--purple); }
.msg.mention.hl { background: var(--mention); border-left-color: var(--red); }
.msg.answered { opacity: .45; }
.msg .ai-dot { color: var(--purple); font-size: .6em; vertical-align: .3em; margin-left: .3em; }
.msg.event {
  margin: .3em .5em; border-radius: 6px; border-left-color: var(--purple);
  background: linear-gradient(90deg, rgba(145,71,255,.25), rgba(145,71,255,.05));
  font-weight: 600; cursor: default;
}
.msg.event.raid { border-left-color: var(--red); background: linear-gradient(90deg, rgba(235,4,0,.3), rgba(235,4,0,.05)); }
.msg.system { color: var(--muted); font-style: italic; cursor: default; }

.more-below {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: var(--purple); color: #fff; border: 0; border-radius: 999px; padding: 8px 16px; cursor: pointer; font-weight: 700;
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
}

/* ---------- pinned ---------- */
.pinned {
  margin: 8px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--panel-2); border: 1px solid var(--purple);
  box-shadow: 0 0 0 1px rgba(145,71,255,.3), 0 6px 18px rgba(0,0,0,.35);
  animation: in .25s ease-out;
}
.pinned-label { font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: .04em; margin-bottom: 6px; }
.pinned-body { font-size: calc(var(--chat-font) * 1.15); line-height: 1.35; font-weight: 600; }
.pinned-actions { display: flex; gap: 6px; margin-top: 10px; }

/* ---------- drawer ---------- */
.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; display: flex; justify-content: flex-end; }
.drawer-inner {
  width: min(440px, 100%); height: 100%; overflow-y: auto; background: var(--panel);
  border-left: 1px solid var(--line); padding: 16px;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer-head h2 { margin: 0; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 16px 0; font-weight: 600; border: 0; padding: 0; }
.field .hint { font-weight: 400; margin: 0; }
.field input[type=range] { width: 100%; accent-color: var(--purple); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; background: var(--bg); border: 0; padding: 8px; cursor: pointer; font-weight: 600; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--purple); color: #fff; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-weight: 400; }
.checks label, .toggles label, .ai label { display: flex; gap: 8px; align-items: center; font-weight: 400; cursor: pointer; }
input[type=checkbox] { accent-color: var(--purple); width: 16px; height: 16px; }
.ai { border: 1px solid var(--line) !important; border-radius: var(--radius); padding: 12px !important; }
.ai legend { padding: 0 6px; }
.field > div > .btn, .field > .btn { margin: 0 6px 6px 0; }

/* ---------- focus ---------- */
.focus { position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 30; display: grid; place-items: center; padding: 16px; cursor: pointer; }
.focus-card {
  max-width: 1000px; width: 100%; background: var(--panel); border: 2px solid var(--purple);
  border-radius: 12px; padding: 28px; text-align: center;
}
#focusBody { font-size: clamp(28px, 5vw, 64px); line-height: 1.25; font-weight: 600; }
#focusBody .name { font-weight: 800; display: block; font-size: .55em; margin-bottom: .3em; }

/* ---------- start ---------- */
.start { position: fixed; inset: 0; z-index: 40; background: radial-gradient(circle at 50% 30%, #2a1650, var(--bg) 70%); display: grid; place-items: center; padding: 16px; }
.start-card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; text-align: center; }
.start-card h1 { margin: 6px 0 8px; }
.start-card p { color: var(--muted); line-height: 1.5; }
.start-card .field { text-align: left; }
.start-card input { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px; font-size: 16px; }
.start-emoji { font-size: 48px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100%; }
  .layout { flex-direction: column; }
  .chat { height: 70vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .panel { width: 100%; }
  .topbar { padding: 8px 16px; }
}
