:root {
  --game-title: #91a5b8;
  --page: #10151b;
  --surface: #171e26;
  --raised: #202b36;
  --border: #2e3b48;
  --text: #e9eff5;
  --muted: #a0afbd;
  --accent: #a5c5e1;
  --auction: #d3b485;
  --selection: #506f8d;
  --topbar-height: 38px;
  --twitch: #c1a8ff;
  --kick: #b4e789;
  --radius: 6px;
  color-scheme: dark;
  color: var(--text);
  background: var(--page);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="winter"] {
  --page: #10191f;
  --surface: #172229;
  --raised: #21323a;
  --border: #354750;
  --text: #edf2f4;
  --muted: #b1bdc4;
  --accent: #bdcfda;
  --game-title: #a29d96;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  display: grid;
  grid-template-rows: var(--topbar-height) minmax(0, 1fr);
  height: 100dvh;
  margin: 0;
  overflow: hidden;
}
[hidden] { display: none !important; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin: 0; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  padding: 0 5px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.top-actions, .top-start, .stream-meta { display: flex; align-items: center; gap: 4px; }
.top-start { grid-column: 1; grid-row: 1; justify-self: start; }
.wordmark { grid-column: 2; justify-self: center; }
.wordmark img { display: block; width: 104px; height: auto; }
.top-actions { grid-column: 3; justify-self: end; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
}
.icon-button:hover, #events-toggle[aria-expanded="true"] { color: var(--text); background: var(--raised); border-color: var(--border); }
.icon-button:focus-visible { outline-offset: -2px; }
.icon-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-button[aria-expanded="true"] .when-collapsed,
.icon-button[aria-expanded="false"] .when-expanded { display: none; }
.quiet-button {
  min-height: 26px;
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--raised);
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}
.quiet-button:hover:not(:disabled), .quiet-button[aria-pressed="true"] { border-color: var(--selection); color: var(--text); }
.quiet-button[aria-pressed="true"] { background: #2c4358; }
.quiet-button:disabled { cursor: default; opacity: .55; }
.count {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 13px;
  padding: 0 3px;
  border: 1px solid var(--surface);
  border-radius: 10px;
  background: var(--accent);
  color: #131d28;
  font: 750 9px/12px system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

.layout {
  --stream-header-height: 32px;
  --roster-width: 210px;
  --visible-chat-width: var(--chat-width, 320px);
  --resizer-width: 8px;
  position: relative;
  display: grid;
  grid-template-columns: var(--roster-width) minmax(0, 1fr) var(--resizer-width) var(--visible-chat-width);
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  padding: 4px;
  background: var(--page);
}
.layout.roster-collapsed { --roster-width: 52px; }
.layout.chat-hidden { --visible-chat-width: 0px; --resizer-width: 0px; }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.roster { --roster-row-height: 36px; --avatar-size: 26px; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.sidebar-heading, .stream-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
}
.sidebar-heading { min-height: 38px; }
.sidebar-heading h2 { font-size: 13px; font-weight: 750; }
.participant-list { flex: 1 1 auto; min-height: 0; display: grid; grid-auto-rows: var(--roster-row-height); align-content: start; gap: 2px; padding: 4px; margin: 0; overflow-y: auto; overscroll-behavior: contain; list-style: none; scrollbar-color: var(--border) transparent; scrollbar-width: thin; }
.participant-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 21px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.participant-row:hover { background: var(--raised); }
.participant-row[data-live="online"] { border-color: #426a4e; }
.participant-row[data-live="offline"] { background: #171c22; border-color: #2a323b; }
.participant-row.is-selected { background: #253749; border-color: var(--selection); }
.participant-row[data-live="offline"] .avatar { filter: grayscale(.85); opacity: .8; }
.participant-row[data-live="offline"] .participant-name { color: #b6b3ae; }
.participant-row.is-dragging { opacity: .55; }
.participant-row.is-drop-target { outline: 1px solid var(--accent); outline-offset: -1px; }
.participant {
  display: grid;
  grid-template-columns: var(--avatar-size) minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  width: 100%;
  min-height: calc(var(--roster-row-height) - 2px);
  padding: 2px 5px;
  border: 0;
  border-radius: 7px;
  text-align: left;
  background: transparent;
}
.participant:focus-visible, .drag-handle:focus-visible { outline-offset: -2px; }
.avatar { position: relative; display: grid; place-items: center; width: var(--avatar-size); height: var(--avatar-size); border-radius: 6px; overflow: hidden; background: #2c3b4c; color: var(--text); font-size: 10px; font-weight: 750; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--raised); }
.participant-details { display: grid; min-width: 0; gap: 1px; line-height: 1.15; }
.participant-name, .participant-phase { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.participant-name { font-weight: 650; font-size: 12px; }
.participant-phase { font-size: 10px; color: var(--muted); }
.participant-phase:empty { display: none; }
.participant-phase[data-phase="awaiting-content"] { color: var(--auction); }
.participant-phase[data-phase="in-casino"] { color: var(--twitch); }
.roster .participant-phase[data-phase="in-content"] { color: var(--game-title); }
.roster .participant-phase[data-phase="turn-end"] { color: #a7a5a0; }
.roster .participant-row[data-live="offline"] .participant-phase { color: #898885; }
.drag-handle { display: grid; place-items: center; border: 0; border-radius: 6px; padding: 0; background: transparent; color: var(--muted); cursor: grab; }
.drag-handle:active { cursor: grabbing; }
.drag-handle:hover { background: #ffffff0b; color: var(--accent); }
.drag-handle::before { content: ""; width: 10px; height: 15px; background: radial-gradient(circle, currentColor 1px, transparent 1.3px) 0 0 / 5px 5px; }
.judge-section { flex: none; padding: 4px; border-top: 1px solid var(--border); background: var(--raised); }
.judge-section h2 { margin: 0 4px 3px; color: var(--accent); font-size: 11px; font-weight: 750; }
.judge-section .participant-row { grid-template-columns: minmax(0, 1fr); }
.roster-collapsed .roster { --roster-row-height: 41px; --avatar-size: 35px; }
.roster-collapsed .participant-list { justify-items: center; padding-inline: 0; scrollbar-width: none; }
.roster-collapsed .roster .participant-row {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  width: 100%;
  border: 0;
  background: transparent;
}
.roster-collapsed .participant {
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  width: var(--roster-row-height);
  padding: 0;
}
.roster-collapsed .participant-details, .roster-collapsed .drag-handle { display: none; }
.roster-collapsed .avatar { border: 2px solid #71869b; border-radius: 8px; }
.roster-collapsed .participant-row[data-live="online"] .avatar { border-color: #9fdbac; }
.roster-collapsed .participant-row[data-live="offline"] .avatar { border-color: #89949e; }
.roster-collapsed .participant-row[data-live="offline"] .avatar { filter: none; opacity: 1; }
.roster-collapsed .participant-row[data-live="offline"] .avatar img { filter: grayscale(.85); opacity: .8; }
.roster-collapsed .participant-row[data-phase="in-content"] .avatar { border-color: #acc9e7; }
[data-theme="winter"] .roster-collapsed .participant-row[data-phase="in-content"] .avatar { border-color: #ded0ba; }
.roster-collapsed .participant-row[data-phase="awaiting-content"] .avatar { border-color: #ffd18a; }
.roster-collapsed .participant-row[data-phase="in-casino"] .avatar { border-color: #d3b1ff; }
.roster-collapsed .participant-row[data-phase="turn-end"] .avatar { border-color: #f0f3f6; }
.roster-collapsed .judge-section .avatar { border-color: #8bc7d7; }
.roster-collapsed .participant:hover .avatar, .roster-collapsed .participant-row.is-selected .avatar {
  box-shadow: 0 0 0 2px var(--selection);
}
.roster-collapsed .judge-section { padding-inline: 0; }
.roster-collapsed .judge-section h2 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.platform-chip {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 20px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 850;
  background: #2f2443;
  color: var(--twitch);
}
.platform-chip.kick { color: var(--kick); background: #26351f; }

.view { min-height: 0; margin-left: 4px; background: #0c1117; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-gutter: stable; }
.view:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }
.stream-header { height: var(--stream-header-height); padding: 3px 7px; gap: 6px; background: var(--surface); }
.stream-identity { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.stream-identity h2 { min-width: 0; font-size: 13px; font-weight: 750; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stream-meta { flex: none; font-size: 11px; }
.stream-meta .platform-chip { width: auto; height: auto; background: none; padding: 0; font-size: inherit; }
.providers { display: flex; flex: none; gap: 4px; }
.provider-button { border: 1px solid var(--border); border-radius: 5px; padding: 3px 6px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 650; }
.provider-button[aria-pressed="true"], .provider-button:hover { color: var(--text); background: var(--raised); border-color: var(--selection); }
.plain-link { flex: none; font-size: 12px; color: var(--accent); }
.plain-link:hover { text-decoration: underline; }
.plain-link[target="_blank"]::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 4px;
  border-top: 1px solid currentColor;
  border-right: 1px solid currentColor;
  background: linear-gradient(135deg, transparent 44%, currentColor 44%, currentColor 55%, transparent 55%);
}
.stream-screen, .chat-screen { background: #0c1117; }
.stream-screen { position: relative; aspect-ratio: 16 / 9; }
.stream-deck > .stream-screen {
  width: min(100%, calc(var(--main-player-height) * 16 / 9));
  margin-inline: auto;
}
.stream-screen > iframe { position: absolute; inset: 0; }
.stream-deck {
  --main-player-height: calc(100dvh - var(--topbar-height) - var(--stream-header-height) - 10px);
  --preview-min-width: 402px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--preview-min-width)), 1fr));
  align-items: start;
  gap: 6px;
  overflow-x: auto;
}
.stream-deck > .stream-screen, .stream-card.is-active {
  grid-column: 1 / -1;
  order: 0;
  min-height: var(--main-player-height);
}
.stream-deck > .stream-screen { aspect-ratio: auto; }
.stream-deck > .stream-screen > iframe {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}
.stream-card.is-active .stream-screen {
  width: min(100%, calc(var(--main-player-height) * 16 / 9));
  margin-inline: auto;
}
.multistream-controls { grid-column: 1 / -1; order: 1; padding: 6px 8px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.multistream-toolbar { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 5px 8px; }
#multistream-status { padding-block: 4px; }
.stream-chooser[open] { flex: 1 1 100%; }
.stream-chooser summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; }
.stream-chooser summary::-webkit-details-marker { display: none; }
.stream-chooser summary::after { content: '▾'; }
.stream-chooser[open] summary::after { content: '▴'; }
.stream-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 145px), 1fr)); gap: 4px; margin-top: 6px; max-width: 760px; }
.stream-option { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 3px 6px; background: var(--surface); border-radius: 4px; cursor: pointer; }
.stream-option span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.stream-option input { margin: 0; accent-color: var(--accent); }
.stream-option:has(input:disabled) { cursor: default; opacity: .65; }
.stream-card { order: 2; min-width: 0; }
.stream-card:not(.is-active) { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); }
.stream-card[data-platform="twitch"] { min-width: var(--preview-min-width); }
.stream-card[data-platform="twitch"] .stream-screen { min-height: 300px; }
.stream-card.is-active[data-platform="twitch"], .stream-card.is-active[data-platform="twitch"] .stream-screen,
.stream-deck > .stream-screen[data-platform="twitch"] { min-width: 534px; }
.stream-card-controls { display: flex; align-items: center; padding-right: 4px; background: var(--raised); border-bottom: 1px solid var(--border); }
.stream-card.is-active .stream-card-controls { display: none; }
.stream-card-controls > :first-child { flex: 1; min-width: 0; padding: 5px 8px; border: 0; background: transparent; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stream-card-controls > :first-child:focus-visible { outline-offset: -2px; }
.stream-card-controls > :first-child:hover { color: var(--accent); }
.stream-icon { width: 26px; height: 25px; flex: none; }
.stream-icon svg { width: 17px; height: 17px; }
.stream-icon[data-muted="true"] .sound-on, .stream-icon[data-muted="false"] .sound-off { display: none; }
.stream-icon.remove-stream:hover { color: #ff9a9a; }
.frame { display: block; width: 100%; height: 100%; border: 0; }
.chat { min-height: 0; overflow: hidden; }
.chat-screen { height: 100%; }
.chat-resizer { display: grid; place-items: center; cursor: col-resize; touch-action: none; }
.chat-resizer::before { content: ""; width: 2px; height: 32px; border-radius: 2px; background: var(--border); }
.chat-resizer:hover::before, .chat-resizer:focus-visible::before, .chat-resizing .chat-resizer::before { background: var(--accent); }
.chat-resizer:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; border-radius: 3px; }
.chat-resizing { cursor: col-resize; user-select: none; }
.chat-resizing iframe { pointer-events: none; }
.chat-link { position: relative; display: grid; place-items: center; flex: none; width: 25px; height: 25px; color: var(--accent); border: 1px solid var(--border); border-radius: 5px; }
.chat-link:hover { background: var(--raised); border-color: var(--selection); }
.chat-link::before { content: ""; width: 12px; height: 9px; border: 1px solid currentColor; border-radius: 3px; }
.chat-link::after { content: ""; position: absolute; bottom: 5px; left: 8px; width: 4px; height: 4px; border-left: 1px solid currentColor; transform: skewY(-32deg); }
.empty { padding: 14px; color: var(--muted); font-size: 13px; }

.events-panel {
  --avatar-size: 26px;
  position: fixed;
  z-index: 4;
  inset: calc(var(--topbar-height) + 2px) auto auto 39px;
  display: flex;
  flex-direction: column;
  width: min(350px, calc(100vw - 43px));
  max-height: calc(100dvh - var(--topbar-height) - 8px);
  box-shadow: 0 10px 26px #0008;
}
.events-backdrop { display: none; position: fixed; inset: var(--topbar-height) 0 0; z-index: 3; }
body:has(#events-panel:not([hidden])) .events-backdrop { display: block; }
.events-status { padding: 3px 10px 8px; font-size: 12px; color: var(--muted); }
.events-status:empty { display: none; }
.event-list {
  list-style: none;
  margin: 0;
  padding: 0 7px;
  min-height: 0;
  max-height: 56dvh;
  overflow-y: auto;
  scrollbar-color: var(--border) transparent;
}
.event-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 5px; padding-right: 5px; border-top: 1px solid var(--border); }
.event-select { display: grid; grid-template-columns: var(--avatar-size) minmax(0, 1fr) 7px; align-items: center; gap: 7px; padding: 5px 3px; border: 0; border-radius: 4px; text-align: left; background: transparent; }
.event-select:hover { background: var(--raised); }
.event-select:focus-visible { outline-offset: -2px; }
.event-details { display: grid; min-width: 0; line-height: 1.25; }
.event-name, .event-activity { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-name { font-size: 12px; font-weight: 700; }
.event-activity, .event-time { color: var(--muted); font-size: 11px; }
.event-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.events-actions { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 8px; border-top: 1px solid var(--border); }
.toasts {
  position: fixed;
  left: 16px;
  bottom: 17px;
  z-index: 5;
  display: grid;
  gap: 5px;
  width: min(265px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  --avatar-size: 24px;
  grid-template-columns: minmax(0, 1fr) 24px;
  align-items: center;
  box-shadow: 0 7px 25px #000a;
  pointer-events: auto;
}
.toast-action { display: grid; grid-template-columns: var(--avatar-size) minmax(0, 1fr); align-items: center; gap: 7px; min-height: 40px; padding: 5px 7px; border: 0; border-radius: 6px; background: transparent; text-align: left; }
.toast-activity { font-size: 11px; }
.toast-close { width: 22px; height: 24px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 16px; }
.toast-close:hover { background: #ffffff0b; color: var(--text); }
.toast-action:focus-visible, .toast-close:focus-visible { outline-offset: -2px; }

@media (max-width: 760px) {
  .layout { --visible-chat-width: 0px; --resizer-width: 0px; }
  .chat { position: absolute; inset: 4px 4px 4px auto; width: min(var(--chat-width, 320px), calc(100% - 8px)); z-index: 1; }
  .chat-resizer { display: none; }
}

[data-theme="winter"] .topbar {
  background:
    radial-gradient(circle at 18px 13px, #c0d8e26b 1px, transparent 2px) 0 0 / 117px 43px,
    radial-gradient(circle at 61px 26px, #c0d8e24a 1px, transparent 2px) 0 0 / 149px 53px,
    linear-gradient(110deg, #162128, #293d47 50%, #162128);
}
[data-theme="winter"] .quiet-button[aria-pressed="true"] { background: #344a56; }

@media (prefers-reduced-motion: no-preference) {
  .layout { transition: grid-template-columns 175ms ease; }
  .layout.chat-resizing { transition: none; }
  .participant-row, .quiet-button { transition: background-color 140ms ease, border-color 140ms ease; }
  .toast { animation: toast-enter 180ms ease-out; }
  @keyframes toast-enter {
    from { opacity: 0; transform: translateX(-6px); }
    to { opacity: 1; transform: translateX(0); }
  }
}
