:root {
  --bg: #0e0e10;
  --bg-1: #121214;
  --bg-2: #18181b;
  --bg-3: #1f1f23;
  --bg-4: #26262c;
  --line: #2a2a30;
  --text: #efeff1;
  --text-2: #adadb8;
  --text-3: #7a7a85;
  --accent: #9147ff;
  --accent-2: #a970ff;
  --live: #eb0400;
  --ok: #00c48c;
  --mention: rgba(235, 4, 0, .16);
  --chat-w: 340px;
  --chat-font: 13px;
  --toolbar-h: 44px;
  --radius: 6px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
@supports (height: 100dvh) { body { height: 100dvh; } }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
svg .stroke { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
kbd {
  font: 11px/1 ui-monospace, Consolas, monospace;
  padding: 2px 5px; border-radius: 4px;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text-2);
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }

.primary {
  background: var(--accent); border: 0; border-radius: var(--radius);
  padding: 6px 12px; font-weight: 600; color: #fff;
}
.primary:hover { background: var(--accent-2); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: var(--radius);
  background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: var(--bg-4); color: var(--text); }
.icon-btn.on { color: var(--accent-2); }

/* ---------------- toolbar ---------------- */

#toolbar {
  height: var(--toolbar-h);
  flex: none;
  display: flex; align-items: center; gap: 6px;
  padding: 0 8px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 7px; font-weight: 700; letter-spacing: .2px; padding-right: 6px; }
.brand svg { width: 20px; height: 20px; color: var(--accent-2); }
.channel-bar { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 0 1 auto; }
.add-form {
  display: flex; align-items: center;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  height: 30px; width: 230px; flex: none;
}
.add-form:focus-within { border-color: var(--accent); }
.add-form input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 0 9px; outline: none; }
.add-form input::placeholder { color: var(--text-3); }
.add-form .icon-btn { width: 28px; height: 28px; }

.chips-wrap { display: flex; align-items: center; min-width: 0; flex: 0 1 auto; }
.chips { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; min-width: 0; padding: 2px; }
.chips.fade-start { -webkit-mask-image: linear-gradient(90deg, transparent, #000 20px); mask-image: linear-gradient(90deg, transparent, #000 20px); }
.chips.fade-end { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 20px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 20px), transparent); }
.chips.fade-start.fade-end { -webkit-mask-image: linear-gradient(90deg, transparent, #000 20px, #000 calc(100% - 20px), transparent); mask-image: linear-gradient(90deg, transparent, #000 20px, #000 calc(100% - 20px), transparent); }
.chips-arrow {
  display: none; place-items: center; flex: none;
  width: 24px; height: 28px; padding: 0;
  border: 0; border-radius: var(--radius); background: transparent; color: var(--text-2);
}
.chips-wrap.overflowing .chips-arrow { display: grid; }
.chips-arrow:hover:not(:disabled) { background: var(--bg-4); color: var(--text); }
.chips-arrow:disabled { opacity: .25; cursor: default; }
.chips-arrow svg { width: 16px; height: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 4px 0 9px; flex: none;
  border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--text-2);
  cursor: pointer; white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: #3a3a42; }
.chip.selected { color: var(--text); border-color: var(--accent); background: rgba(145, 71, 255, .14); }
/* A channel-points bonus is waiting for a manual claim: channel-points green glow. */
.chip.claimable { border-color: #00f593; box-shadow: 0 0 8px rgba(0, 245, 147, .55), inset 0 0 6px rgba(0, 245, 147, .18); animation: chip-claim 1.8s ease-in-out infinite; }
@keyframes chip-claim { 50% { box-shadow: 0 0 13px rgba(0, 245, 147, .8), inset 0 0 6px rgba(0, 245, 147, .25); } }
.chip.dragging { opacity: .4; }
.chip.drop-before { box-shadow: -3px 0 0 var(--accent-2); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.chip.live .dot { background: var(--live); }
.chip .x { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 0; background: transparent; color: var(--text-3); padding: 0; }
.chip .x:hover { background: var(--bg-4); color: var(--text); }
.chip .x svg { width: 12px; height: 12px; }
.spacer { flex: 1; }

/* Groups: one button per group (number + avatars), then the groups menu button. */
.groups { display: flex; align-items: center; gap: 4px; flex: none; }
.group-tabs { display: flex; gap: 3px; padding: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); }
.group-tab {
  position: relative; display: flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 6px 0 7px; border: 1px solid transparent; border-radius: 4px;
  background: transparent; color: var(--text-3); white-space: nowrap;
}
.group-tab:hover { color: var(--text); background: var(--bg-3); }
.group-tab.active { color: var(--text); background: var(--bg-4); border-color: var(--accent); }
.group-tab .g-num { font-weight: 700; font-size: 12px; min-width: 7px; text-align: center; }
.group-tab.live .g-num { color: var(--live); }
.group-tab.active.live .g-num { color: var(--accent-2); }
.g-avatars { display: flex; align-items: center; }
.g-avatars > * { width: 16px; height: 16px; border-radius: 50%; margin-left: -4px; box-shadow: 0 0 0 1.5px var(--bg); flex: none; }
.g-avatars > :first-child { margin-left: 0; }
.g-initial, .g-more { display: grid; place-items: center; background: var(--bg-4); color: var(--text-2); font-size: 9px; font-weight: 700; }
.g-more { width: auto; min-width: 16px; padding: 0 3px; border-radius: 8px; }
.g-mentions { font-size: 10px; font-weight: 700; padding: 0 4px; border-radius: 7px; background: var(--accent); color: #fff; line-height: 14px; }
.group-tab.claimable { border-color: #00f593; box-shadow: 0 0 6px rgba(0, 245, 147, .5); }
.group-tab.drop-target, #btn-groups.drop-target { border-color: var(--accent-2); background: rgba(145, 71, 255, .22); color: var(--text); }
#btn-groups { width: 30px; height: 30px; border: 1px solid transparent; }
.groups-menu { width: 250px; }
.groups-menu .split { display: flex; flex-direction: column; gap: 6px; padding: 6px 10px 8px; color: var(--text-2); }
.groups-menu .split .seg { align-self: flex-start; }
.groups-menu .split .seg button { width: 30px; color: var(--text-2); font-weight: 600; padding: 0; text-align: center; display: grid; }
.groups-menu .split .seg button:hover { background: var(--bg-4); color: var(--text); }
.menu-hint { margin: 4px 0 0; padding: 8px 10px 4px; border-top: 1px solid var(--line); color: var(--text-3); font-size: 11.5px; line-height: 1.4; }

.volume { display: flex; align-items: center; gap: 2px; flex: none; }
#volume-range {
  --fill: 50%;
  width: 72px; height: 4px; margin: 0 6px 0 0; padding: 0; cursor: pointer;
  -webkit-appearance: none; appearance: none; border-radius: 2px; outline-offset: 4px;
  background: linear-gradient(90deg, var(--accent-2) var(--fill), var(--bg-4) var(--fill));
}
#volume-range::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: var(--text); border: 0; }
#volume-range::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--text); border: 0; }
#volume-range:hover::-webkit-slider-thumb { background: #fff; transform: scale(1.15); }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 2px; gap: 2px; }
.seg button {
  display: grid; place-items: center; width: 32px; height: 26px;
  border: 0; border-radius: 4px; background: transparent; color: var(--text-3); padding: 0;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--bg-4); color: var(--accent-2); }

.account {
  display: flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 10px 0 4px; border-radius: 15px;
  border: 1px solid var(--line); background: var(--bg-3); white-space: nowrap;
}
.account:hover { border-color: #3a3a42; }
.account img { width: 22px; height: 22px; border-radius: 50%; }
.account.logged-out { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 0 12px; }
.account.logged-out:hover { background: var(--accent-2); }
.account svg { width: 16px; height: 16px; }

@media (max-width: 1100px) {
  .brand span { display: none; }
  .add-form { width: 170px; }
}
@media (max-width: 860px) {
  .account span { display: none; }
  .account { padding: 0 4px; }
}

/* fullscreen: toolbar slides away, revealed from the top edge */
#top-hotzone { display: none; }
body.fullscreen #top-hotzone { display: block; position: fixed; top: 0; left: 0; right: 0; height: 6px; z-index: 30; }
body.fullscreen #toolbar {
  position: fixed; top: 0; left: 0; right: 0;
  transform: translateY(-100%); transition: transform .15s ease;
}
body.fullscreen.reveal #toolbar { transform: none; }

/* ---------------- layout ---------------- */

#main { flex: 1; display: flex; min-height: 0; }
#stage { position: relative; flex: 1; min-width: 0; overflow: hidden; background: var(--bg); }
body.resizing webview, body.resizing .tile iframe { pointer-events: none; }
body.resizing { cursor: col-resize; }
body.resizing.resizing-row { cursor: row-resize; }

.tile { position: absolute; background: #000; border-radius: 3px; overflow: hidden; contain: strict; }
.tile webview { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.embed-host { position: absolute; inset: 0; overflow: hidden; }
iframe.embed-host { width: 100%; height: 100%; border: 0; display: block; }
.embed-target { width: 100%; height: 100%; }
.embed-target iframe { display: block; width: 100%; height: 100%; border: 0; }
.tile.hidden { visibility: hidden; pointer-events: none; }
body:not(.chat-hidden) #stage[data-mode="grid"] .tile.chatting { outline: 2px solid rgba(145, 71, 255, .65); outline-offset: 1px; }

/* No control bar over the videos: the toolbar chips, the mode buttons and the
   Twitch player cover everything it had, and "reload player" is in the chat
   header (with the latency). Desktop thumbnails keep a click catcher. */
.tile-catcher { display: none; }
.tile.thumb .tile-catcher {
  display: block;
  position: absolute; inset: 0; z-index: 3; cursor: pointer;
  border: 2px solid transparent; border-radius: 3px;
  transition: border-color .1s ease;
}
.tile.thumb .tile-catcher:hover { border-color: var(--accent-2); }
/* Channel name on every tile, small and faint so it barely covers the video. */
#stage.no-names .tile-name { display: none; }
/* Focus mode: drag the gap between the main video and the thumbnails (players.js setupSplitter). */
.focus-splitter { position: absolute; z-index: 5; cursor: row-resize; touch-action: none; }
.focus-splitter:hover, body.resizing-row .focus-splitter { background: linear-gradient(var(--accent), var(--accent)) center / 100% 2px no-repeat; }
.tile-name {
  position: absolute; top: 5px; left: 5px; z-index: 3; max-width: calc(100% - 10px);
  padding: 1px 5px; border-radius: 3px;
  background: rgba(0, 0, 0, .55); color: #fff; opacity: .75;
  font-size: 10.5px; font-weight: 600; line-height: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; pointer-events: none;
}

.tile-error {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--bg-1); color: var(--text-2);
}
.tile-error button { background: var(--bg-4); border: 0; border-radius: var(--radius); padding: 6px 14px; }

/* ---------------- empty state ---------------- */

.empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 4px;
}
.empty h1 { font-size: 22px; margin: 18px 0 4px; }
.empty p { color: var(--text-2); margin: 4px 0; }
.empty .hint { margin-top: 22px; font-size: 12px; color: var(--text-3); line-height: 2; }
.empty-art { display: grid; grid-template-columns: repeat(2, 64px); gap: 6px; }
.empty-art span { height: 36px; border-radius: 5px; background: var(--bg-3); border: 1px solid var(--line); }
.empty-art span:first-child { background: rgba(145, 71, 255, .35); border-color: var(--accent); }
.empty-form { display: flex; gap: 8px; margin-top: 10px; }
.empty-form input {
  width: 300px; height: 36px; padding: 0 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); outline: none;
}
.empty-form input:focus { border-color: var(--accent); }
.empty-form .primary { height: 36px; padding: 0 18px; }

/* ---------------- chat ---------------- */

#chat {
  position: relative;
  width: var(--chat-w); flex: none;
  display: flex; flex-direction: column;
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  min-height: 0;
}
body.chat-hidden #chat { display: none; }
html[data-platform="web"] .desktop-only { display: none; }
html:not([data-platform="web"]) .web-only { display: none; }
html[data-points="off"] .points-on, html:not([data-points="off"]) .points-off { display: none; }
html[data-rate="off"] .rate-on, html:not([data-rate="off"]) .rate-off { display: none; }
#chat-resizer { position: absolute; left: 0; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 5; }
#chat-resizer:hover, body.resizing #chat-resizer { background: linear-gradient(90deg, var(--accent) 2px, transparent 2px); }

.chat-tabs {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 6px 8px; border-bottom: 1px solid var(--line);
}
.chat-tabs:empty { display: none; }
.chat-tab {
  display: flex; align-items: center; gap: 5px;
  height: 24px; padding: 0 8px; border-radius: 12px;
  border: 1px solid transparent; background: var(--bg-3); color: var(--text-2);
  font-size: 12px; max-width: 150px;
}
.chat-tab:hover { color: var(--text); }
.chat-tab.active { background: rgba(145, 71, 255, .18); border-color: var(--accent); color: var(--text); }
.chat-tab .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); flex: none; }
.chat-tab.live .dot { background: var(--live); }
.chat-tab .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-tab .count { font-size: 10px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.chat-tab .count:empty { display: none; }
.chat-tab.has-mention .count { color: #fff; background: var(--live); padding: 0 5px; border-radius: 7px; }

#chat.no-channel .chat-header { display: none; }
.chat-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 10px; min-height: 38px; border-bottom: 1px solid var(--line);
}
.chat-heading { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.chat-title { border: 0; background: none; padding: 0; font-weight: 700; font-size: 14px; white-space: nowrap; }
.chat-title:hover { color: var(--accent-2); }
.chat-meta { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-meta.live::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--live); margin-right: 5px; vertical-align: 1px; }
.chat-header-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.pin-show {
  display: grid; place-items: center; width: 26px; height: 24px; padding: 0;
  border: 0; border-radius: 12px; background: var(--bg-3); color: var(--accent-2);
}
.pin-show:hover { background: var(--bg-4); }
.pin-show svg { width: 15px; height: 15px; }

.chat-pinned {
  margin: 6px 8px 0; padding: 6px 4px 4px;
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 6px; background: var(--bg-3);
  font-size: var(--chat-font);
}
.pin-head { display: flex; align-items: center; gap: 6px; padding: 0 6px 2px; color: var(--text-2); font-size: 11px; font-weight: 600; }
.pin-icon svg { width: 13px; height: 13px; color: var(--accent-2); display: block; }
.pin-by { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-close { border: 0; background: none; color: var(--text-3); font-size: 11px; padding: 1px 4px; border-radius: 4px; }
.pin-close:hover { color: var(--text); background: var(--bg-4); }
.pin-body { max-height: calc(var(--chat-font) * 1.55 * 3 + 6px); overflow: hidden; user-select: text; }
.chat-pinned.clamped .pin-body { cursor: pointer; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.chat-pinned.expanded .pin-body { max-height: 40vh; overflow-y: auto; -webkit-mask-image: none; mask-image: none; }
.pin-body .msg { padding: 1px 6px; }
.pin-body .msg:hover { background: none; }

.pin-show.on { background: rgba(145, 71, 255, .22); color: var(--text); }

/* Reload player + latency to the broadcaster (like the Enhancer extension) */
.latency {
  display: flex; align-items: center; gap: 4px; height: 24px; padding: 0 6px; flex: none;
  border: 0; border-radius: 12px; background: var(--bg-3); color: var(--text-2);
  font-weight: 600; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.latency:hover { background: var(--bg-4); color: var(--text); }
.latency-icon { display: grid; color: var(--accent-2); }
.latency-icon svg { width: 15px; height: 15px; }
.latency-text:empty { display: none; }
.latency-text small { font-size: 10.5px; font-weight: 600; color: var(--text-3); }
.latency:active .latency-icon svg { transform: rotate(-90deg); transition: transform .15s ease; }

.claim-btn {
  --claim-fg: #0e0e10;
  display: grid; place-items: center; width: 28px; height: 24px; padding: 0;
  border: 0; border-radius: 12px; background: #00f593; color: var(--claim-fg);
  animation: claim-pulse 1.6s ease-in-out infinite;
}
.claim-btn:hover { filter: brightness(1.1); }
.claim-btn svg { width: 16px; height: 16px; }
.claim-btn.busy { animation: none; opacity: .6; cursor: progress; }
@keyframes claim-pulse { 50% { box-shadow: 0 0 0 4px rgba(0, 245, 147, .25); } }

.community {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column;
  background: var(--bg-2);
}
.cm-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 6px; }
#community-search {
  flex: 1; min-width: 0; height: 28px; padding: 0 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); outline: none;
}
#community-search:focus { border-color: var(--accent); }
.cm-head button {
  height: 28px; padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg-3); color: var(--text-2); font-size: 12px;
}
.cm-head button:hover { background: var(--bg-4); color: var(--text); }
.cm-summary { padding: 0 10px 8px; }
.cm-count { font-weight: 700; font-size: 12px; color: var(--text); }
.cm-sources { font-size: 11px; color: var(--text-3); }
.community-list {
  flex: 1; overflow-y: auto; margin: 0 8px 8px; padding: 4px 0;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  user-select: text;
}
.cm-group + .cm-group { margin-top: 4px; }
.cm-group h4 {
  display: flex; align-items: baseline; margin: 0; padding: 6px 10px 3px;
  font-size: var(--chat-font); font-weight: 700; color: var(--accent-2);
}
.cm-group h4 span { flex: 1; }
.cm-group h4 small { font-size: 11px; font-weight: 400; color: var(--text-3); }
.cm-user {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 4px 10px; font-weight: 400; font-size: var(--chat-font); color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cm-user:hover { background: rgba(255, 255, 255, .06); }
.cm-user .cm-login { color: var(--text-3); }
.cm-note { color: var(--text-3); font-size: 12px; padding: 8px 10px; }

/* popup windows (search, user card, thread): the panel fills the window */
body.popup { display: block; background: var(--bg-2); }
body.popup > .chat-search, body.popup > .user-card, body.popup > .thread { position: fixed; inset: 0; }
body.popup .uc-close, body.popup .cs-close, body.popup .th-close { display: none; }

/* reply thread (click "Replying to …"), like Moltorino's Reply Thread popup */
.thread {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column;
  background: var(--bg-2);
}
.th-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.th-sub { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 12px; color: var(--text-2); }
.th-sub input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }
.th-count { flex: 1; text-align: right; color: var(--text-3); font-size: 11px; }
.th-close { border: 0; background: var(--bg-3); color: var(--text-2); font-size: 11px; padding: 3px 8px; border-radius: 4px; }
.th-close:hover { background: var(--bg-4); color: var(--text); }
.th-messages {
  flex: 1; min-height: 0; overflow-y: auto; padding: 6px 0 8px;
  font-size: var(--chat-font); line-height: 1.55; user-select: text; overscroll-behavior: contain;
}
.th-messages::-webkit-scrollbar { width: 8px; }
.th-messages::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 4px; }
.th-sep { height: 1px; margin: 4px 10px; background: var(--line); }
.th-note { color: var(--text-3); font-size: 12px; padding: 6px 10px; font-style: italic; }
.msg.th-synthetic .ts { visibility: hidden; }
.th-form { display: flex; gap: 6px; align-items: flex-end; padding: 8px; border-top: 1px solid var(--line); }
.th-form textarea {
  flex: 1; resize: none; min-height: 34px; max-height: 110px;
  padding: 7px 10px; border-radius: var(--radius); outline: none;
  background: var(--bg); border: 1px solid var(--line); line-height: 1.4; user-select: text;
}
.th-form textarea:focus { border-color: var(--accent); }
.th-form .primary { height: 34px; }
.th-login { padding: 8px; border-top: 1px solid var(--line); }
.th-login .primary { width: 100%; height: 34px; }

/* polls and predictions (Moltorino's PollBanner / PredictionBanner) */
.chat-events { display: flex; flex-direction: column; gap: 6px; padding: 6px 8px 0; }
.chat-events[hidden] { display: none; }
.ev {
  padding: 6px 8px 7px; border-radius: 6px; cursor: pointer;
  background: var(--bg-3); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  font-size: 12px; line-height: 1.35;
}
.ev-poll { border-left-color: #22c55e; }
.ev:hover { border-color: #3a3a42; border-left-color: inherit; }
.ev-prediction:hover { border-left-color: var(--accent); }
.ev-poll:hover { border-left-color: #22c55e; }
.ev-head { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 11px; font-weight: 600; }
.ev-icon { display: grid; color: var(--accent-2); }
.ev-poll .ev-icon { color: #4ade80; }
.ev-icon svg { width: 14px; height: 14px; }
.ev-meta { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-age { font-weight: 400; color: var(--text-3); }
.ev-timer { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ev-timer[data-state="live"] { color: #9147ff; }
.ev-timer[data-state="long"] { color: #f59e0b; }
.ev-timer[data-state="short"] { color: #ef4444; }
.ev-timer[data-state="poll"] { color: #a855f7; }
.ev-timer[data-state="locked"] { color: #d99024; }
.ev-timer[data-state="resolved"] { color: #22c55e; }
.ev-timer[data-state="canceled"], .ev-timer[data-state="ended"] { color: #9ca3af; }
.ev-close { display: grid; place-items: center; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 4px; background: none; color: var(--text-3); }
.ev-close:hover { background: var(--bg-4); color: var(--text); }
.ev-close svg { width: 11px; height: 11px; }
.ev-title { margin: 2px 0 3px; font-size: 13px; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-summary { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.ev-side { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-side.right { text-align: right; flex: none; max-width: 50%; }
.ev-dim { color: var(--text-3); }
.ev-win { color: #22c55e; }
.ev-bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: var(--bg-4); gap: 1px; }
.ev-bar span { display: block; height: 100%; min-width: 2px; transition: width .6s ease, background-color .3s ease; }
.ev-details { display: none; margin-top: 6px; }
.ev.expanded .ev-details { display: grid; gap: 3px; }
.ev-row { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; column-gap: 6px; align-items: baseline; padding: 3px 0; border-top: 1px solid var(--line); }
.ev-row.won .ev-row-title { color: #22c55e; }
.ev-dot { width: 8px; height: 8px; border-radius: 50%; align-self: center; }
.ev-row-title { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-row-pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.ev-row-stats { grid-column: 2 / -1; color: var(--text-3); font-size: 11px; }
.ev-row-top { grid-column: 2 / -1; color: var(--text-3); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-choice { position: relative; display: flex; justify-content: space-between; gap: 8px; padding: 4px 6px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.ev-choice-fill { position: absolute; inset: 0 auto 0 0; opacity: .28; transition: width .6s ease; }
.ev-choice > span { position: relative; }
.ev-choice .ev-row-stats { grid-column: auto; flex: none; font-variant-numeric: tabular-nums; color: var(--text-2); }
.ev-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.ev-action { border: 0; border-radius: 4px; padding: 4px 10px; background: var(--accent); color: #fff; font-weight: 600; font-size: 11px; }
.ev-action:hover { background: var(--accent-2); }

/* user card (click a name) */
.user-card {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column;
  background: var(--bg-2);
}
.uc-head { display: flex; align-items: flex-start; gap: 10px; padding: 10px 10px 6px; }
.uc-avatar { width: 64px; height: 64px; border-radius: 6px; object-fit: cover; flex: 0 0 auto; }
.uc-who { flex: 1; min-width: 0; }
.uc-name { font-size: 15px; }
.uc-login { color: var(--text-3); font-size: 12px; }
.uc-info { margin-top: 4px; font-size: 12px; color: var(--text-2); display: grid; gap: 1px; user-select: text; }
.uc-row { display: flex; align-items: center; gap: 5px; }
.uc-label { color: var(--text-3); }
.uc-swatch { width: 9px; height: 9px; border-radius: 2px; }
.uc-note { color: var(--text-3); }
.uc-close, .uc-actions button { border: 0; background: var(--bg-3); color: var(--text-2); font-size: 11px; padding: 3px 8px; border-radius: 4px; }
.uc-close:hover, .uc-actions button:hover { background: var(--bg-4); color: var(--text); }
.uc-bio { padding: 0 10px 6px; font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; user-select: text; max-height: 4.5em; overflow-y: auto; }
.uc-actions { display: flex; align-items: center; gap: 6px; padding: 4px 10px 8px; border-bottom: 1px solid var(--line); }
.uc-count { flex: 1; text-align: right; color: var(--text-3); font-size: 11px; }
.uc-messages { flex: 1; overflow-y: auto; padding: 4px 0 8px; user-select: text; }

/* shared chat: the channels in the session, like Twitch's header avatars */
.chat-shared {
  display: flex; align-items: center; gap: 8px; padding: 4px 10px;
  border-bottom: 1px solid var(--line); font-size: 12px; color: var(--text-2);
}
.chat-shared[hidden] { display: none; }
.sh-avatars { display: flex; flex: 0 0 auto; }
.sh-avatars button { padding: 0; border: 2px solid var(--bg-2); border-radius: 50%; background: none; margin-left: -6px; line-height: 0; }
.sh-avatars button:first-child { margin-left: 0; }
.sh-avatars button.host { border-color: var(--accent); }
.sh-avatars img { width: 22px; height: 22px; border-radius: 50%; }
.sh-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sh-label b { color: var(--text); font-weight: 600; }
.badge.shared-badge { border-radius: 50%; }

/* chat search (Ctrl+F) */
.chat-search {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column;
  background: var(--bg-2);
}
.cs-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px 4px; }
#chat-search-input {
  flex: 1; min-width: 0; height: 30px; padding: 0 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); outline: none;
}
#chat-search-input:focus { border-color: var(--accent); }
.cs-close { border: 0; background: var(--bg-3); color: var(--text-2); font-size: 11px; padding: 3px 8px; border-radius: 4px; }
.cs-close:hover { background: var(--bg-4); color: var(--text); }
.cs-info { padding: 0 12px 4px; color: var(--text-3); font-size: 11px; }
.cs-results {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  border-top: 1px solid var(--line); padding: 4px 0;
  font-size: var(--chat-font); line-height: 1.55; user-select: text;
  overscroll-behavior: contain;
}
.cs-results::-webkit-scrollbar { width: 8px; }
.cs-results::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 4px; }
.cs-results .msg { cursor: pointer; }
.cs-results .msg.historical { opacity: 1; }
.cs-channel { color: var(--text-3); font-size: .85em; margin-right: 5px; }
.cs-help { padding: 5px 10px 7px; border-top: 1px solid var(--line); color: var(--text-3); font-size: 11px; line-height: 1.7; }
.cs-help code { font: 10.5px ui-monospace, Consolas, monospace; background: var(--bg-3); padding: 1px 4px; border-radius: 3px; color: var(--text-2); }
::highlight(chat-search-hit) { background: rgba(255, 214, 0, .35); color: #fff; }
.msg.jump-flash { animation: jump-flash 1.8s ease; }
@keyframes jump-flash { 0%, 35% { background: rgba(145, 71, 255, .35); } }

/* emote hover tooltip */
.emote-tip {
  position: fixed; left: 0; top: 0; z-index: 60;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; align-items: flex-start;
  max-width: 320px; padding: 8px 10px;
  background: rgba(0, 0, 0, .92); border: 1px solid #2c2c32; border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .55);
  pointer-events: none;
  color: #fff; font-size: 12px; line-height: 1.35; text-align: center;
}
.emote-tip-card { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.emote-tip-img { height: 112px; width: auto; max-width: 296px; object-fit: contain; }
.emote-tip.stack .emote-tip-img { height: 72px; max-width: 140px; }
.emote-tip-text { overflow-wrap: anywhere; }

.row-actions { padding: 2px 0 4px 26px; }
.settings .hint { margin: 2px 0 6px; font-size: 12px; line-height: 1.45; color: var(--text-3); }
.secondary { background: var(--bg-4); border: 0; border-radius: var(--radius); padding: 5px 12px; color: var(--text); }
.secondary:hover { background: #33333b; }

.chat-points {
  display: flex; align-items: center; gap: 5px; flex: none;
  padding: 2px 8px; border-radius: 12px; background: var(--bg-3);
  font-weight: 600; font-size: 12px; font-variant-numeric: tabular-nums; cursor: default;
}
.chat-points img, .chat-points svg { width: 16px; height: 16px; color: var(--accent-2); }
.chat-points.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: var(--accent); color: #fff; } 100% { background: var(--bg-3); } }

.chat-body { position: relative; flex: 1; min-height: 0; }
.chat-log {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  padding: 6px 0 8px;
  font-size: var(--chat-font);
  line-height: 1.55;
  user-select: text;
  overscroll-behavior: contain;
}
.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 4px; }
.chat-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); padding: 20px; text-align: center; }

.msg { padding: 2px 10px; overflow-wrap: anywhere; contain: content; }
.msg:hover { background: rgba(255, 255, 255, .03); }
.msg .ts { display: none; color: var(--text-3); font-size: .85em; margin-right: 5px; font-variant-numeric: tabular-nums; }
.show-ts .msg .ts { display: inline; }
.msg.system .ts { display: inline; }
.msg .badges { margin-right: 3px; }
.badge { width: 18px; height: 18px; vertical-align: -4px; margin-right: 3px; border-radius: 3px; }
.msg .name { font-weight: 700; cursor: pointer; }
.msg .name:hover { text-decoration: underline; }
.msg .name.painted {
  background-color: currentColor; background-size: cover; background-position: center;
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.msg .at { font-weight: 600; color: var(--text); }
.msg a.link { color: var(--accent-2); text-decoration: none; }
.msg a.link:hover { text-decoration: underline; }
.emote { height: 28px; width: auto; vertical-align: middle; margin: -4px 1px; image-rendering: auto; }
.emote-stack { display: inline-grid; vertical-align: middle; margin: -4px 1px; }
.emote-stack > .emote { grid-area: 1 / 1; margin: 0; justify-self: center; align-self: center; }
.msg.system { color: var(--text-3); font-style: italic; }
.msg.historical { opacity: .6; }
.msg.mention { background: var(--mention); box-shadow: inset 3px 0 0 var(--live); }
.msg.first { box-shadow: inset 3px 0 0 var(--ok); }
.msg.notice { margin: 4px 0; background: rgba(145, 71, 255, .08); box-shadow: inset 3px 0 0 var(--accent); padding-top: 5px; padding-bottom: 5px; }
.notice-system { color: var(--text-2); font-weight: 600; }
.msg .reply { color: var(--text-3); font-size: .9em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg .reply[data-thread] { cursor: pointer; }
.msg .reply[data-thread]:hover { color: var(--text-2); text-decoration: underline; }
.msg .reply::before { content: "↩ "; }
.msg.deleted .text { opacity: .35; text-decoration: line-through; }

.chat-more {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  border: 0; border-radius: 15px; padding: 5px 14px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
}

.chat-form { display: flex; gap: 6px; align-items: flex-end; padding: 8px; border-top: 1px solid var(--line); }
.chat-form textarea {
  flex: 1; resize: none; min-height: 34px; max-height: 110px;
  padding: 7px 10px; border-radius: var(--radius); outline: none;
  background: var(--bg); border: 1px solid var(--line); line-height: 1.4;
  user-select: text;
}
.chat-form textarea:focus { border-color: var(--accent); }
.chat-form .primary { height: 34px; }
/* Tab-completion carousel above the input (like Moltorino) */
.chat-complete {
  display: flex; gap: 4px; padding: 6px 8px 0; overflow-x: auto; overflow-y: hidden;
  border-top: 1px solid var(--line); scrollbar-width: thin;
}
.chat-complete[hidden] { display: none; }
.chat-complete + .chat-form { border-top: 0; }
.cc-item {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px;
  min-width: 64px; max-width: 120px; height: 62px; padding: 4px 6px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.cc-item:hover { border-color: var(--accent-2); }
.cc-item.selected { border-color: var(--accent); background: rgba(145, 71, 255, .14); }
.cc-item img { max-height: 32px; max-width: 100%; object-fit: contain; }
.cc-item .cc-name { font-size: 11px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-item.user { justify-content: center; }
.cc-item.user .cc-name { font-size: 12px; font-weight: 600; }
.chat-login { padding: 10px; border-top: 1px solid var(--line); }
.chat-login .primary { width: 100%; height: 36px; }

/* ---------------- popover, dialog, toasts ---------------- */

.popover {
  position: fixed; z-index: 40; min-width: 210px;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .55); padding: 6px;
}
.popover .who { padding: 8px 10px; color: var(--text-2); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.popover .who b { color: var(--text); }
.popover button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 5px; }
.popover button:hover { background: var(--bg-4); }

dialog {
  border: 1px solid var(--line); border-radius: 10px; padding: 0;
  background: var(--bg-2); color: var(--text);
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 40px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.settings header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 4px 18px; }
.settings h2 { margin: 0; font-size: 17px; }
.settings section { padding: 6px 18px 10px; }
.settings h3 { margin: 10px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
.settings .row { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.settings .row.col { flex-direction: column; gap: 6px; cursor: default; }
.settings .row small { display: block; color: var(--text-3); font-size: 12px; margin-top: 1px; }
.settings input[type="checkbox"] { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.settings input[type="range"] { width: 100%; accent-color: var(--accent); }
.settings .reducer-opts { padding: 0 0 4px 26px; }
.settings .reducer-opts:has(input:disabled) { opacity: .5; }
.settings .num { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 0; }
.settings .num small { display: block; color: var(--text-3); font-size: 12px; margin-top: 1px; }
.settings .num-field { display: flex; align-items: center; gap: 5px; flex: none; color: var(--text-3); font-size: 12px; }
.settings .num-field i { font-style: normal; width: 8px; }
.settings input[type="number"] { width: 70px; height: 28px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 6px; text-align: right; }
.settings input[type="number"]:focus { outline: none; border-color: var(--accent); }
.settings input[type="number"]:invalid { border-color: var(--live); }
.settings select { width: 100%; height: 32px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 8px; }
.settings footer { padding: 10px 18px 16px; border-top: 1px solid var(--line); margin-top: 4px; }
.muted { color: var(--text-3); font-size: 12px; }

.toasts { position: fixed; left: 12px; bottom: 12px; z-index: 50; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast {
  background: var(--bg-3); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  padding: 8px 12px; border-radius: 6px; max-width: 360px; box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
  animation: toast-in .15s ease;
}
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------------- browser version ----------------
   Twitch pauses embeds that have anything drawn over them, so nothing may
   overlap a player: the channel name becomes a strip above the video
   (EmbedPlayer.nameBar), and toasts/fullscreen chrome stay out of the stage. */

html[data-platform="web"] .tile { background: var(--bg-2); }
html[data-platform="web"] .tile-catcher { display: none !important; }
html[data-platform="web"] #stage:not(.no-names) .embed-host { top: 16px; }
html[data-platform="web"] #stage:not(.no-names) iframe.embed-host { height: calc(100% - 16px); }
html[data-platform="web"] .tile-name {
  top: 0; left: 0; right: 0; max-width: none; height: 16px;
  padding: 0 6px; border-radius: 0; opacity: 1;
  color: rgba(255, 255, 255, .75); line-height: 16px;
}

html[data-platform="web"] .toasts { top: 6px; bottom: auto; left: 50%; transform: translateX(-50%); }
html[data-platform="web"] .toast { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; padding: 6px 12px; }
html[data-platform="web"] body.fullscreen #toolbar { position: static; transform: none; }
html[data-platform="web"] body.fullscreen #top-hotzone { display: none; }

/* ---------------- phones & tablets ---------------- */

/* Touch: bigger targets, no hover-only affordances, and 16px inputs so iOS
   doesn't zoom the page when one gets focus. */
@media (hover: none) {
  input, textarea, select { font-size: 16px; }
  #volume-range { display: none; }
  .empty .hint { display: none; }
  .chip .x { width: 26px; height: 26px; }
  .chips-wrap.overflowing .chips-arrow { display: none; }
  .msg:hover { background: none; }
}

/* Narrow screens: the toolbar becomes two rows, buttons on top and the
   channel input + chips underneath. */
@media (max-width: 860px) {
  #volume-range { width: 56px; }
}
@media (max-width: 700px) {
  #volume-range { display: none; }
  #toolbar { height: auto; flex-wrap: wrap; row-gap: 6px; padding: 6px 8px; }
  .brand { padding-right: 0; }
  .channel-bar { order: 10; flex: 1 0 100%; }
  .add-form { width: 140px; }
  .chips-wrap { flex: 1 1 auto; }
  .g-avatars { display: none; }
  .account span { display: none; }
  .account { padding: 0 4px; }
  .toast, html[data-platform="web"] .toast { max-width: calc(100vw - 24px); }
  .empty { padding: 16px; }
  .empty h1 { font-size: 19px; }
  .empty-form { flex-wrap: wrap; justify-content: center; width: 100%; }
  .empty-form input { flex: 1 1 200px; width: auto; max-width: 320px; }
  dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .settings section { padding: 6px 14px 10px; }
}
@media (max-width: 360px) {
  .seg button { width: 28px; }
  .icon-btn { width: 30px; }
}

/* Landscape phones: keep the videos the main thing. */
@media (orientation: landscape) and (max-height: 500px) {
  #chat { width: min(var(--chat-w), 42vw); }
}

/* Portrait phones (html.stacked, set from app.js): videos on top, chat below.
   The video height comes from app.js (--stage-h); the bar on the chat's top
   edge resizes it (double-tap/double-click: back to automatic). */
html.stacked #main { flex-direction: column; }
html.stacked #stage { flex: none; height: var(--stage-h, 45%); }
html.stacked body.chat-hidden #stage { flex: 1; height: auto; }
/* The resize handle stays inside the chat: overlapping the stage, even by a
   few pixels, makes Twitch pause the embed underneath. */
html.stacked #chat { width: auto; flex: 1; min-height: 0; border-left: 0; border-top: 1px solid var(--line); padding-top: 12px; }
html.stacked #chat-resizer {
  left: 0; right: 0; top: 0; bottom: auto; width: auto; height: 12px;
  cursor: row-resize; touch-action: none;
}
html.stacked #chat-resizer::after {
  content: ""; position: absolute; left: 50%; top: 4px; width: 36px; height: 4px; margin-left: -18px;
  border-radius: 2px; background: var(--bg-4);
}
html.stacked #chat-resizer:hover, html.stacked body.resizing #chat-resizer { background: none; }
html.stacked #chat-resizer:hover::after, html.stacked body.resizing #chat-resizer::after { background: var(--accent); }
html.stacked body.resizing { cursor: row-resize; }
html.stacked .chat-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
html.stacked .chat-tabs::-webkit-scrollbar { display: none; }
html.stacked .chat-tab { flex: none; }
html.stacked .chat-form { padding: 6px 8px; }
html.stacked .chat-tabs { padding-top: 0; }
