.stream-area:has(.focus-wrapper),
.stream-area:has(.stream-unified--focused) {
  padding: 4px 6px 8px;
  gap: 3px;
  --focus-under-player-reserve: 4.35rem;
}
@media (min-height: 1180px) {
  .stream-area:has(.focus-wrapper),
  .stream-area:has(.stream-unified--focused) {
    --focus-under-player-reserve: 4rem;
  }
}
/* Unified focus: no toolbar row under main — use every pixel of vertical space.
 * Reserve is kept at a bare minimum (just a few px for rounding/border safety); the stream area
 * vertical padding is also zeroed so the tile can grow as tall as the viewport allows. */
.stream-area:has(.stream-unified--focused) {
  padding-top: 0;
  padding-bottom: 0;
  --focus-under-player-reserve: 0.25rem;
}
@media (min-height: 1180px) {
  .stream-area:has(.stream-unified--focused) {
    --focus-under-player-reserve: 0.2rem;
  }
}
/* Out of flow when hidden — some resets strip [hidden]; keeps gap from leaving a strip */
#globalStreamToolbar[hidden] {
  display: none !important;
}

/* Holds .grid-equal / .grid-3 / .focus-wrapper so layout roots are not direct children of .stream-area. */
#streamLayoutHost.stream-layout-host {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
/* One parent for all tiles — equal vs focus toggles CSS grid on .stream-cells-plane only (no iframe reparent). */
.stream-unified-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
}
.stream-unified-layout .stream-cells-plane {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 8px;
}
/* Vertically center the plane’s content in the column when shorter than the area (grid itself stays flex:1 for definite 1fr / CQ sizes). */
.stream-unified-layout.stream-unified--focused {
  justify-content: center;
  /* Paused overlay: same --ui-scale as smaller displays, extra multipliers on wide viewports only (focus main + minis). */
  --focus-main-paused-scale: 1;
  --focus-mini-paused-scale: 0.82;
}
@media (min-width: 1800px) {
  .stream-unified-layout.stream-unified--focused {
    --focus-main-paused-scale: 1.06;
    --focus-mini-paused-scale: 0.88;
  }
}
@media (min-width: 2200px) {
  .stream-unified-layout.stream-unified--focused {
    --focus-main-paused-scale: 1.12;
    --focus-mini-paused-scale: 0.92;
  }
}
@media (min-width: 2560px) {
  .stream-unified-layout.stream-unified--focused {
    --focus-main-paused-scale: 1.18;
    --focus-mini-paused-scale: 0.96;
  }
}
.stream-unified-layout.stream-unified--focused .stream-cells-plane {
  overflow: auto;
}
.stream-unified--equal .stream-cells-plane[data-count="1"] {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}
/* 2-stream: keep each cell at exactly 16:9 and center the row vertically.
 * aspect-ratio on the .stream-cell (not the body) gives a definite height that satisfies
 * container-type:size; grid-template-rows:auto then sizes the row to that computed height
 * instead of stretching cells to fill the full container. */
.stream-unified--equal .stream-cells-plane[data-count="2"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto;
  align-content: center;
}
.stream-unified--equal .stream-cells-plane[data-count="2"] .stream-cell {
  aspect-ratio: 16 / 9;
}
.stream-unified--equal .stream-cells-plane[data-count="4"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.stream-unified--focused .stream-cells-plane {
  container-type: size;
  container-name: unified-focus-plane;
}
.stream-unified--focused .stream-cells-plane .stream-cell.side-stream {
  width: 100%;
  flex-shrink: 0;
  flex-grow: 0;
  /* Height = video height + bar height, computed in JS and set as --side-cell-h on the plane.
   * Provides a definite block size so container-query cqh works inside the cell.
   * Falls back to auto when the variable is not yet set (first paint / non-focus). */
  height: var(--side-cell-h, auto);
  min-height: 0;
}
/* 16:9 aspect ratio on the video host only — the bar is excluded from the ratio. */
.stream-unified--focused .stream-cells-plane .stream-cell.side-stream .twitch-embed-host {
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: 16 / 9;
}
.stream-unified--focused .stream-cells-plane .stream-cell.side-stream .cell-bar {
  cursor: grab;
}
.stream-unified--focused .stream-cells-plane .stream-cell.side-stream .cell-bar:active {
  cursor: grabbing;
}
/* Outer cell: stretch for grid + definite CQ height; border/background on .stream-cell-body only. */
.stream-unified--focused .stream-cells-plane .stream-cell.focused {
  flex-shrink: 0;
  max-width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  overflow: visible;
}
/* Focus + chat: VS Code–style tabs (active tab connects to the stream body below). */
.stream-unified--focused .stream-cells-plane .stream-cell.focused:has(.focus-stream-chat-tabs) {
  justify-content: center;
}
.focus-stream-chat-tabs {
  width: fit-content;
  max-width: 100%;
  align-self: flex-start;
  flex-shrink: 0;
  box-sizing: border-box;
  min-width: 0;
  margin-top: -3px;
  margin-left: -2px;
  overflow: visible;
}
.focus-stream-chat-tabs__strip {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 2px;
  overflow: visible;
  scrollbar-width: thin;
  min-height: 35px;
  padding: 2px 2px 0;
  box-sizing: border-box;
  max-width: min(100%, var(--focus-slot-w, 100%));
}
.focus-stream-chat-tabs__tab-wrap {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}
.focus-stream-chat-tabs__tab {
  flex: 0 1 auto;
  min-width: 48px;
  max-width: 220px;
  margin: 0;
  padding: 6px 30px 5px 10px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 3px 3px 0 0;
  cursor: pointer;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.focus-stream-chat-tabs__tab-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 0 1 auto;
}
.focus-stream-chat-tabs__tab-sep {
  flex: 0 0 auto;
  color: var(--cell-bar-muted);
  opacity: 0.9;
  font-size: 13px;
  line-height: 1;
}
.focus-stream-chat-tabs__tab-status {
  flex: 0 0 auto;
  font-size: 13px;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--cell-bar-muted);
  opacity: 0.95;
}
.focus-stream-chat-tabs__tab-status--ingame { color: var(--green-live); }
.focus-stream-chat-tabs__tab-status--live { color: var(--blue-live); }
.focus-stream-chat-tabs__tab-status--variety { color: var(--purple-variety); }
.focus-stream-chat-tabs__tab-status--loading { color: var(--accent); }
.focus-stream-chat-tabs__tab-status--offline { color: var(--cell-bar-muted); }
.focus-stream-chat-tabs__tab:first-child {
  margin-left: 0;
}
.focus-stream-chat-tabs__tab:hover:not(.focus-stream-chat-tabs__tab--active) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--border);
}
.focus-stream-chat-tabs__tab--active {
  color: #ffdbe0;
  background: var(--bg-card);
  border-color: var(--border);
  border-bottom-color: var(--bg-card);
  z-index: 6;
  position: relative;
  margin-top: -2px;
  margin-bottom: -1px;
  box-shadow: none;
}
.focus-stream-chat-tabs__tab--active::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
  pointer-events: none;
}
.focus-stream-chat-tabs__tab--active::after {
  content: '';
  position: absolute;
  left: 1px;
  right: 1px;
  bottom: -1px;
  height: 2px;
  background: var(--bg-card);
  pointer-events: none;
}
.focus-stream-chat-tabs__strip--dragging .focus-stream-chat-tabs__tab--active:not(.focus-stream-chat-tabs__tab--dragging):not(.focus-stream-chat-tabs__tab--drag-over) {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--border);
  border-bottom: none;
  margin-top: 0;
  margin-bottom: 0;
  z-index: auto;
  box-shadow: none;
}
.focus-stream-chat-tabs__strip--dragging .focus-stream-chat-tabs__tab--active:not(.focus-stream-chat-tabs__tab--dragging):not(.focus-stream-chat-tabs__tab--drag-over)::before,
.focus-stream-chat-tabs__strip--dragging .focus-stream-chat-tabs__tab--active:not(.focus-stream-chat-tabs__tab--dragging):not(.focus-stream-chat-tabs__tab--drag-over)::after {
  display: none;
}
/* Drop target: same look whether or not this tab is the focused stream (active kept accent chrome elsewhere). */
.focus-stream-chat-tabs__tab--drag-over {
  margin-top: 0;
  margin-bottom: 0;
  z-index: auto;
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(232, 52, 74, 0.08);
}
.focus-stream-chat-tabs__tab--drag-over .focus-stream-chat-tabs__tab-label,
.focus-stream-chat-tabs__tab--drag-over .focus-stream-chat-tabs__tab-status,
.focus-stream-chat-tabs__tab--drag-over .focus-stream-chat-tabs__tab-sep {
  color: inherit;
  opacity: 1;
}
.focus-stream-chat-tabs__strip--dragging .focus-stream-chat-tabs__tab--active:not(.focus-stream-chat-tabs__tab--dragging):hover:not(.focus-stream-chat-tabs__tab--drag-over) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--border);
}
.focus-stream-chat-tabs__strip--dragging .focus-stream-chat-tabs__tab--active.focus-stream-chat-tabs__tab--drag-over::before,
.focus-stream-chat-tabs__strip--dragging .focus-stream-chat-tabs__tab--active.focus-stream-chat-tabs__tab--drag-over::after {
  display: none;
}
.focus-stream-chat-tabs__strip--dragging .focus-stream-chat-tabs__tab {
  transition: none;
}
.focus-stream-chat-tabs__tab--dragging {
  opacity: 0.55;
  transform: scale(0.985) translateY(0);
}
.focus-stream-chat-tabs__tab[draggable='true'] {
  cursor: pointer;
}
.focus-stream-chat-tabs__tab[draggable='true']:active {
  cursor: pointer;
}
.focus-stream-chat-tabs__tab-close {
  position: absolute;
  top: 50%;
  right: 5px;
  width: 20px;
  height: 20px;
  transform: translateY(calc(-50% - 0.5px));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0.9;
  z-index: 10;
  border-radius: 3px;
}
.focus-stream-chat-tabs__tab-close svg {
  display: block;
  width: 12px;
  height: 12px;
}
.focus-stream-chat-tabs__tab-close svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}
.focus-stream-chat-tabs__tab-close:focus-visible {
  color: #fff;
  opacity: 1;
  background: rgba(255, 255, 255, 0.06);
}
.focus-stream-chat-tabs__tab-wrap:has(.focus-stream-chat-tabs__tab--active) .focus-stream-chat-tabs__tab-close {
  color: #fff;
  opacity: 1;
}
.focus-stream-chat-tabs__strip--dragging .focus-stream-chat-tabs__tab-wrap:has(.focus-stream-chat-tabs__tab--active:not(.focus-stream-chat-tabs__tab--dragging))
  .focus-stream-chat-tabs__tab-close {
  color: var(--text-secondary);
  opacity: 0.9;
}
.stream-unified--focused .stream-cells-plane .stream-cell.focused:has(.focus-stream-chat-tabs) .stream-cell-body {
  border-top-left-radius: 0;
  border-top-right-radius: 4px;
  border-top: 1px solid var(--border);
  margin-top: 0;
}
/* In focus+chat tab mode, keep card border stable (no accent hover outline flicker). */
.stream-area:has(#sideChatPanel.side-chat-panel--focused:not([hidden])) .stream-unified--focused .stream-cells-plane .stream-cell.focused .stream-cell-body:hover {
  border-color: var(--border);
}
/* With tab-close controls present, hide the top-right stream remove x to avoid duplicate actions. */
.stream-unified--focused .stream-cells-plane .stream-cell.focused:has(.focus-stream-chat-tabs) .stream-cell-playing-remove,
.stream-unified--focused .stream-cells-plane .stream-cell.focused:has(.focus-stream-chat-tabs) .play-overlay-remove-btn {
  display: none !important;
}
/* Focused + chat: stream column inset from the left rail; gap vs chat is applied in JS (see CHAT_PANEL_FOCUS_GAP_UI_PX). */
.stream-area:has(#sideChatPanel.side-chat-panel--focused:not([hidden])) {
  padding-left: calc(4.8px * var(--ui-scale, 1.25));
  padding-right: 0;
}
.stream-area:has(#sideChatPanel.side-chat-panel--focused:not([hidden])) .stream-unified--focused .stream-cells-plane .stream-cell.focused {
  align-items: flex-start;
}
.stream-unified--focused .stream-cells-plane .stream-cell.focused .stream-cell-body {
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
/* Focused main: no accent hover unless drag reorder (drop-target class on body). */
.stream-unified--focused .stream-cells-plane .stream-cell.focused .stream-cell-body:hover {
  border-color: var(--border);
}
/* Default .twitch-embed-host { flex:1 } — fixed-aspect main tile inside the inner frame. */
.stream-unified--focused .stream-cells-plane .stream-cell.focused .stream-cell-body .twitch-embed-host {
  flex: 0 0 auto;
  min-height: 4.5rem;
  width: 100%;
  aspect-ratio: 16 / 9;
}
@supports (width: 1cqw) {
  .stream-unified--focused .stream-cells-plane .stream-cell.focused .stream-cell-body {
    --focus-dvh-cap: 100dvh;
    --focus-tile-max-h: min(
      var(--focus-dvh-cap),
      max(
        5.5rem,
        calc(
          100cqh
          - var(--focus-under-player-reserve, 4.35rem)
          - var(--focus-over-player-reserve, 0px)
        )
      )
    );
    /* Cap body width to (focusTileMaxH − barH) × 16/9 so the video host is always exactly 16:9
     * on any monitor aspect ratio.  Without this cap, a viewport wider than its height × 16/9
     * (e.g. 2560×1080 ultra-wide) makes the body wider than the host's max-height allows, the
     * host's max-height then breaks the aspect-ratio, and Twitch letterboxes internally.
     * Applied unconditionally — not gated on min-height — so all viewport sizes are covered. */
    --focus-slot-w: min(100cqw, calc(100dvw - 16px));
    --focus-body-max-w: calc((var(--focus-tile-max-h) - 32px * var(--ui-scale, 1.25)) * 16 / 9);
    width: min(var(--focus-slot-w), var(--focus-body-max-w));
    max-width: min(var(--focus-slot-w), var(--focus-body-max-w));
    max-height: var(--focus-tile-max-h);
    height: auto;
    box-sizing: border-box;
  }
  .stream-unified--focused .stream-cells-plane .stream-cell.focused .stream-cell-body .twitch-embed-host {
    max-height: max(0px, calc(var(--focus-tile-max-h) - 32px * var(--ui-scale, 1.25)));
  }
  .stream-unified--focused .stream-cells-plane .stream-cell.focused:has(.focus-stream-chat-tabs) {
    --focus-over-player-reserve: 34px;
  }
}
@supports not (width: 1cqw) {
  .stream-unified--focused .stream-cells-plane .stream-cell.focused .stream-cell-body {
    width: 100%;
    max-height: calc(100dvh - 12rem);
  }
  .stream-area:has(.stream-unified--focused) .stream-cells-plane .stream-cell.focused .stream-cell-body {
    max-height: calc(100dvh - var(--header-bar-height) - 6.5rem);
  }
  .stream-unified--focused .stream-cells-plane .stream-cell.focused .stream-cell-body .twitch-embed-host {
    max-height: calc(100% - 32px * var(--ui-scale, 1.25));
  }
}
.unified-focus-chrome {
  min-width: 0;
  box-sizing: border-box;
}
.stream-unified--focused .unified-focus-chrome .focus-dual-toolbar {
  margin-top: 0;
}

.grid-equal {
  display: grid;
  gap: 8px;
  flex: 1;
  min-height: 0;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}
.grid-equal[data-count="2"] { grid-template-columns: 1fr 1fr; }
.grid-equal[data-count="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.grid-equal[data-count="6"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr 1fr; }
.grid-equal[data-count="8"] { grid-template-columns: repeat(4, 1fr); grid-template-rows: 1fr 1fr; }
.grid-equal[data-count="9"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr 1fr 1fr; }

/* Three streams: single grid parent (cells are direct children); row layout from JS
   so drag-reorder stays in one DOM parent like mini-stream column — no embed reload. */
.grid-3 {
  display: grid;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

/* ── Focus mode ─────────────────────────────────────── */

/* Outer wrapper: stacks main row + optional bottom strip */
.focus-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 8px;
}
.stream-area:has(.focus-wrapper) .focus-wrapper {
  gap: 2px;
}

/* Main row: left column (focused + aux controls) + side column (right) */
.focus-main-row {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 8px;
  align-items: stretch;
}
.stream-area:has(.focus-wrapper) .focus-main-row {
  gap: 6px;
}

.focus-main-column {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  align-self: stretch;
}
.focus-wrapper .focus-main-column {
  box-sizing: border-box;
}

/* Slot fills column height; stack (player + toolbars); scroll if a tight viewport still overflows. */
.focus-stream-slot {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  container-type: size;
  container-name: focus-stream-slot;
}
/* Vertically center main player + toolbars in the slot (collapsed or expanded sidebar). */
.stream-area:has(.focus-wrapper) .focus-stream-slot {
  justify-content: center;
  padding-top: 0;
  padding-bottom: 0;
  box-sizing: border-box;
}

.focus-stream-slot > .focus-main-stack {
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  align-self: center;
}

/* Stage wraps the tile only — do not flex-grow or the toolbar is pushed to the bottom of the viewport. */
.focus-main-stage {
  flex: 0 0 auto;
  max-width: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.focus-main-stage-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 0 1 auto;
  width: 100%;
  max-width: 100%;
  min-height: 0;
}

/* 16:9 tile — dvh cap alone overflows at ~1080p: dual toolbar + gap sit below player inside the slot. */
.focus-stream-slot .stream-cell.focused {
  flex-shrink: 0;
  max-width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}
/* Hide focused body for one paint during focus swaps to avoid tiny pre-layout flash. */
.stream-cell.focused.focus-swap-pending .stream-cell-body {
  visibility: hidden;
}
@supports (width: 1cqw) {
  .focus-stream-slot .stream-cell.focused {
    /*
     * cqh/cqw — .focus-stream-slot. Reserve: dual toolbar + stack gap (slot scrolls if they wrap).
     * --focus-under-player-reserve inherited from .stream-area:has(.focus-wrapper) (tunable).
     */
    --focus-dvh-cap: 100dvh;
    --focus-tile-max-h: min(
      var(--focus-dvh-cap),
      max(5.5rem, calc(100cqh - var(--focus-under-player-reserve, 4.35rem)))
    );
    width: min(100cqw, calc(100dvw - 16px));
    max-width: min(100cqw, calc(100dvw - 16px));
    max-height: var(--focus-tile-max-h);
    height: auto;
    box-sizing: border-box;
  }

  /* Tall windows only: fit largest 16×9 in slot height (uses vertical “black bar” as video). */
  @media (min-height: 1040px) {
    .stream-area:has(.focus-wrapper) .focus-stream-slot .stream-cell.focused {
      --focus-slot-w: min(100cqw, calc(100dvw - 16px));
      width: min(var(--focus-slot-w), calc(var(--focus-tile-max-h) * 16 / 9));
      max-width: min(var(--focus-slot-w), calc(var(--focus-tile-max-h) * 16 / 9));
    }
  }
}
@supports not (width: 1cqw) {
  .focus-stream-slot .stream-cell.focused {
    width: 100%;
    max-height: calc(100dvh - 12rem);
  }
  .stream-area:has(.focus-wrapper) .focus-stream-slot .stream-cell.focused {
    max-height: calc(100dvh - var(--header-bar-height) - 6.5rem);
  }
}

.focus-main-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}
.stream-area:has(.focus-wrapper) .focus-main-stack {
  gap: 6px;
}
.focus-stream-slot .focus-main-stack > .focus-dual-toolbar {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  flex-shrink: 0;
}

.focus-dual-toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 12px 28px;
  width: 100%;
  margin-top: 4px;
  box-sizing: border-box;
  zoom: var(--ui-scale, 1.25);
}
.stream-area:has(.focus-wrapper) .focus-dual-toolbar {
  margin-top: 0;
}
.focus-mini-stream-controls {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 1 auto;
  min-width: 0;
  max-width: min(220px, 46vw);
  width: auto;
}
.focus-mini-stream-controls-heading.section-label {
  color: var(--text-secondary);
  letter-spacing: 0.2em;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 8px;
  width: 100%;
  text-align: center;
}
.focus-mini-stream-sel-ic-row {
  width: 100%;
}

/* Right-side column: width derived from video dimensions so 3 minis fill the column height.
   gap = 8px, barH = 32px; for 3 minis: videoH = (H − 2×8 − 3×32) / 3
   colW = videoH × 16/9 = (H − 112px) × 16/27 */
.side-col {
  --focus-row-h: calc(100dvh - var(--header-bar-height) - 28px);
  --side-w-from-height: calc((var(--focus-row-h) - 112px) * 16 / 27);
  width: clamp(380px, min(36vw, var(--side-w-from-height)), 860px);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  align-self: stretch;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}
/* 16:9 on the video host only — bar sits below and is excluded from the ratio. */
.side-col .stream-cell {
  width: 100%;
  flex-shrink: 0;
  flex-grow: 0;
  height: auto;
  min-height: 0;
}
.side-col .stream-cell .twitch-embed-host {
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: 16 / 9;
}

.stream-cell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  /* Toast uses cqw/cqh — size of this cell (focus / grid / side column). */
  container-type: size;
  container-name: stream-cell;
}
/* Focus main: neutral frame — accent only as drop target during drag reorder. */
.stream-cell.focused { border-color: var(--border); }
.stream-cell.focused:hover { border-color: var(--border); }

/* Drag-over rules live after .side-stream:hover (they must win :hover border-color on minis). */

/* Embeds + bar live here so the outer .stream-cell can stretch (grid) while an inner frame sizes to the video. */
.stream-cell-body {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

/* Game-ended swap prompt — above cell bar, width follows copy (not full cell) */
.stream-game-finished-toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(32px * var(--ui-scale, 1.25));
  z-index: 35;
  zoom: var(--ui-scale, 1.25);
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  max-width: calc(100% - 12px);
  box-sizing: border-box;
}
@supports (width: 1cqw) {
  .stream-game-finished-toast {
    padding: 0 clamp(4px, 1.8cqw, 14px) clamp(3px, 1.2cqh, 10px);
  }
  .stream-game-finished-toast__inner {
    padding: clamp(6px, 1.6cqh, 14px) clamp(7px, 2.4cqw, 18px) clamp(7px, 1.8cqh, 14px);
    border-radius: clamp(4px, 1cqw, 10px);
    box-shadow: 0 clamp(2px, 0.8cqh, 8px) clamp(12px, 3cqh, 28px) rgba(0,0,0,0.5);
  }
  .stream-game-finished-toast__text {
    font-size: clamp(10px, 3.1cqw, 18px);
    margin: 0 0 clamp(4px, 1.2cqh, 10px);
    line-height: 1.35;
    max-width: 100%;
  }
  .stream-game-finished-toast__bar {
    height: clamp(2px, 0.85cqw, 5px);
    border-radius: clamp(1px, 0.4cqw, 3px);
    margin-bottom: clamp(4px, 1.2cqh, 10px);
  }
  .stream-game-finished-toast__actions {
    gap: clamp(4px, 1.5cqw, 12px);
  }
  .stream-game-finished-toast__btn {
    font-size: clamp(10px, 2.8cqw, 16px);
    padding: clamp(2px, 0.9cqh, 8px) clamp(8px, 2.5cqw, 16px);
  }
}
@supports not (width: 1cqw) {
  .stream-game-finished-toast {
    padding: 0 6px 4px;
  }
  .stream-game-finished-toast__inner {
    padding: 7px 9px 8px;
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  }
  .stream-game-finished-toast__text {
    font-size: clamp(10px, 1.6vmin, 18px);
    margin: 0 0 6px;
    line-height: 1.35;
    max-width: 100%;
  }
  .stream-game-finished-toast__bar {
    height: 3px;
    border-radius: 2px;
    margin-bottom: 6px;
  }
  .stream-game-finished-toast__actions {
    gap: 6px;
  }
  .stream-game-finished-toast__btn {
    font-size: clamp(10px, 1.5vmin, 16px);
    padding: 3px 10px;
  }
}
.stream-game-finished-toast__inner {
  pointer-events: auto;
  display: table;
  width: auto;
  max-width: 100%;
  margin-inline: auto;
  box-sizing: border-box;
  background: rgba(16,16,20,0.94);
  border: 1px solid var(--border-bright);
}
.stream-game-finished-toast__text {
  color: var(--text-primary);
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 400;
  letter-spacing: 0.02em;
}
.stream-game-finished-toast__bar {
  background: var(--border);
  overflow: hidden;
}
.stream-game-finished-toast__bar-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left center;
  transform: scaleX(0);
  will-change: transform;
}
.stream-game-finished-toast__actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}
.stream-game-finished-toast__btn {
  min-height: 0;
  line-height: 1.2;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: none;
}

.twitch-embed-host {
  flex: 1;
  min-height: 0;
  width: 100%;
  position: relative;
  z-index: 0; /* below .play-overlay (2) and .cell-bar (3) inside .stream-cell-body */
}
.twitch-embed-host iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Chrome: cross-origin Twitch iframe wins hit-testing during drag; pointer goes to the host/cell instead of sticking on the iframe edge. */
body.stream-cell-dragging .twitch-embed-host iframe {
  pointer-events: none;
}

.cell-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  --cell-bar-gap-hit: 6px;
  --cell-bar-pad-x: 9px;
  padding: 0 9px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  height: 32px;
  position: relative;
  z-index: 3; /* above .play-overlay (2) if layout rounds into the bar strip */
  user-select: none;
  zoom: var(--cell-bar-zoom, 1);
}
/* Reserve space so focus icons are not clipped (narrow side column + overflow:hidden on .stream-cell) */
.cell-bar:has(.focus-swap-btn),
.cell-bar:has(.exit-focus-btn) {
  /* 2px top + 24px btn + 2px right — match vertical inset of absolute focus controls */
  padding-right: 28px;
}
/* Main tile: exit in flex flow + full bar height — neutral vertical center vs status text everywhere. */
.stream-cell.focused .cell-bar:has(.exit-focus-btn) {
  padding-right: 2px;
}
.stream-cell.focused .cell-bar .exit-focus-btn {
  position: relative;
  inset: auto;
  transform: none; /* cancel translateY(-50%) from base rule; flex align-items handles centering */
  margin: 0 0 0 auto;
  flex-shrink: 0;
  align-self: stretch;
  width: 24px;
  min-width: 24px;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 0;
}
/* Default: no nudge (1440p, sidebar open, etc.). */
.stream-cell.focused .cell-bar .exit-focus-btn svg {
  display: block;
  transform: none;
}
/*
 * ~1080p-class viewport + collapsed sidebar: wide stream column + subpixel rounding made the bracket read low;
 * keep the lift scoped so other layouts stay centered.
 */
@media (max-width: 2100px) {
  body:has(#sidebar.collapsed) .stream-cell.focused .cell-bar .exit-focus-btn svg {
    transform: translateY(-1.5px);
  }
}
/* Side strip + equal grid: grab only on the bar, not the video / paused overlay. */
.side-col .stream-cell .twitch-embed-host,
.side-col .stream-cell .play-overlay {
  cursor: default;
}
.grid-equal .stream-cell .twitch-embed-host,
.grid-equal .stream-cell .play-overlay,
.grid-3 .stream-cell .twitch-embed-host,
.grid-3 .stream-cell .play-overlay,
.stream-unified--equal .stream-cells-plane .stream-cell .twitch-embed-host,
.stream-unified--equal .stream-cells-plane .stream-cell .play-overlay {
  cursor: default;
}

/* Side mini-streams + equal / grid-3: bar is the drag handle (see initStreamCellDrag) */
.side-col .stream-cell .cell-bar { cursor: grab; }
.side-col .stream-cell .cell-bar:active { cursor: grabbing; }
.grid-equal .cell-bar,
.grid-3 .stream-cell .cell-bar,
.stream-unified--equal .stream-cells-plane .stream-cell .cell-bar {
  cursor: grab;
}
.grid-equal .cell-bar:active,
.grid-3 .stream-cell .cell-bar:active,
.stream-unified--equal .stream-cells-plane .stream-cell .cell-bar:active {
  cursor: grabbing;
}
.stream-cell.focused .cell-bar { cursor: grab; }
.stream-cell.focused .cell-bar:active { cursor: grabbing; }
/* Real controls use pointer; bar + pause cluster (incl. drag shield) inherit grab from .cell-bar. */
.side-col .stream-cell .cell-bar button,
.grid-equal .cell-bar button,
.grid-3 .stream-cell .cell-bar button,
.stream-unified--equal .stream-cells-plane .stream-cell .cell-bar button,
.stream-cell.focused .cell-bar button,
.stream-unified--focused .stream-cells-plane .stream-cell.side-stream .cell-bar button {
  cursor: pointer;
}
.cell-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  height: 100%;
  container-type: inline-size;
  container-name: cellmeta;
}
/* Single flex child of .cell-meta — keeps streamer|rank and WR from splitting across free space. */
.cell-meta-cluster {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: 100%;
  flex: 0 1 auto;
}
/* Ellipsis when tight; shrink inside cluster only. */
.cell-meta-lead {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-meta-streamer-name {
  color: #ffffff;
  font-weight: 400;
}
.cell-meta-acc-name {
  color: #9aa3b2;
}
.cell-meta-account-slot {
  flex: 0 0 auto;
  min-width: 0;
  white-space: nowrap;
}
.cell-meta-region {
  display: inline-block;
  color: var(--text-secondary);
  opacity: 0.88;
  flex-shrink: 0;
  margin-left: 0.35em;
  vertical-align: baseline;
}
.cell-meta-sep {
  color: var(--text-secondary);
  font-size: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 500;
  line-height: 1.05;
  opacity: 0.88;
  display: inline-flex;
  align-items: center;
  transform: translateY(-1px);
  margin: 0 4px;
}
.cell-meta .cell-rank {
  font-weight: 400;
}
.cell-meta .cell-meta-rank-slot {
  flex: 0 0 auto;
  min-width: 0;
}
.cell-meta .cell-rank .cell-rank-pending,
.cell-meta .cell-rank-pending {
  color: #8a93a6;
  font-weight: 400;
}
.cell-meta .cell-rank .cell-rank-unranked,
.cell-meta .cell-rank-unranked {
  color: #8c8c8c;
  font-weight: 400;
}
.cell-meta .cell-rank-tier {
  font-weight: 500;
}
.cell-meta .cell-rank-tier--lb {
  position: relative;
}
.cell-meta .cell-rank-paren {
  color: var(--text-secondary);
  opacity: 0.88;
}
.cell-meta .cell-rank-tier + .cell-rank-paren {
  margin-left: 0.35em;
}
.cell-meta .cell-rank-lb {
  font-weight: 400;
}
.cell-meta .cell-rank-lb-group {
  margin-left: 0.35em;
}
.cell-meta .cell-rank-lb--rest {
  color: var(--text-secondary);
  opacity: 0.9;
}
.cell-meta .cell-rank-lb--gold {
  color: #e8c547;
  text-shadow: 0 0 12px rgba(232, 197, 71, 0.22);
}
.cell-meta .cell-rank-lb--silver {
  color: #c5cedd;
  text-shadow: 0 0 10px rgba(197, 206, 221, 0.18);
}
.cell-meta .cell-rank-lb--bronze {
  color: #d18b52;
  text-shadow: 0 0 10px rgba(209, 139, 82, 0.2);
}
/* Narrow tiles (e.g. mini-streams): swap to abbreviated rank (GM / C / …). */
.cell-meta .cell-rank--adaptive .cell-rank__abbr {
  display: none;
}
@container cellmeta (max-width: 520px) {
  .cell-meta .cell-rank--adaptive .cell-rank__verbose {
    display: none;
  }
  .cell-meta .cell-rank--adaptive .cell-rank__abbr {
    display: inline;
  }
}
@container cellmeta (max-width: 430px) {
  /* JS priority cuts handle LB -> WR -> region in overflow order. */
}
/* Shrink-wrap adaptive rank so hidden verbose doesn’t reserve width after abbrev swap. */
.cell-meta .cell-rank--adaptive {
  display: inline-block;
  max-width: 100%;
  vertical-align: baseline;
}
/* Solo ranked win rate (league entry W/L) — bands: under 50%, 50–55, 55–60, 60–70, 70+ */
.cell-meta .cell-wr {
  flex-shrink: 0;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.02em;
  line-height: 1;
}
.cell-meta .cell-wr--wr-na {
  color: #6b7280;
  font-weight: 400;
}
.cell-meta .cell-wr--wr-bad {
  color: #b86b70;
}
.cell-meta .cell-wr--wr-near50 {
  color: #9aa3b2;
}
.cell-meta .cell-wr--wr-fiftys {
  color: #89b4e8;
}
.cell-meta .cell-wr--wr-green {
  color: #7dcea0;
}
.cell-meta .cell-wr--wr-yellow {
  color: #e8d55d;
}
.cell-meta .cell-wr--wr-gold {
  color: #d4a84b;
}
.cell-meta .cell-wr-paren {
  color: var(--text-secondary);
  opacity: 0.88;
  margin-left: 0.16em;
  font-size: 11px;
  line-height: 1;
}
.cell-meta .cell-wr-group {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
.cell-meta .cell-rank-lb-cut {
  display: none;
}
.cell-meta.cell-meta--cut-lb .cell-rank-lb-group {
  display: none;
}
.cell-meta.cell-meta--cut-wr .cell-wr-group {
  display: none;
}
.cell-meta.cell-meta--cut-region .cell-meta-region {
  display: none;
}
.cell-meta .cell-wl {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.02em;
  line-height: 1;
}
.cell-meta .cell-stat-wins {
  color: #6bcf7f;
  font-weight: 500;
}
.cell-meta .cell-stat-losses {
  color: #e07070;
  font-weight: 500;
}
.cell-meta .cell-wl-sep {
  color: var(--text-secondary);
  opacity: 0.9;
  font-weight: 600;
  margin: 0 1px;
}
/* In-flow “● LIVE” etc. under each tile (not Twitch’s in-player chrome — that’s inside the iframe). */
.cell-status {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--green-live);
  letter-spacing: 0.1em;
  line-height: 1;
  text-transform: uppercase;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  height: 100%;
  margin-left: auto;
}
/* Compact roster copresence hint after status (hidden when empty; see streams.js) */
.cell-copresence-hint {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  line-height: 1.1;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  flex: 0 1 auto;
  min-width: 0;
  max-width: 14ch;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-left: 4px;
  cursor: default;
}
/*
 * Pulls under .cell-bar horizontal padding so real spans (not ::before) own hit-testing.
 * [pad-left][cluster+shield][pad-right] — all inside closest(.cell-bar-pause-lead) drag-exempt.
 */
.cell-bar-pause-lead {
  display: flex;
  align-items: stretch;
  align-self: stretch;
  flex-shrink: 0;
  margin-left: calc(-1 * var(--cell-bar-pad-x, 9px));
  cursor: default;
}
.cell-bar-pause-pad-left {
  flex: 0 0 var(--cell-bar-pad-x, 9px);
  width: var(--cell-bar-pad-x, 9px);
  min-width: var(--cell-bar-pad-x, 9px);
  align-self: stretch;
  flex-shrink: 0;
}
.cell-bar-pause-pad-right {
  flex: 0 0 var(--cell-bar-gap-hit, 6px);
  width: var(--cell-bar-gap-hit, 6px);
  min-width: var(--cell-bar-gap-hit, 6px);
  align-self: stretch;
  flex-shrink: 0;
}
/* Non-drag band inside lead; shield pads flex gap before meta (see streams.js). */
.cell-bar-pause-cluster {
  display: flex;
  align-items: center;
  align-self: stretch;
  flex-shrink: 0;
  /* Left inset only — matches bar pad + icon breathing room; avoid extra gap before meta */
  padding: 0 0 0 2px;
  margin: 0;
}
.cell-bar-pause-cluster__shield {
  flex: 0 0 4px;
  min-width: 4px;
  align-self: stretch;
}
/* Pull meta toward pause so pause-to-text gap reads like pause-to-edge (cluster pad + bar pad). */
.cell-bar-pause-lead + .cell-meta {
  margin-left: -3px;
}
.cell-pause-btn {
  position: relative;
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--cell-bar-muted);
  cursor: pointer;
  padding: 0 1px 0 2px;
  margin: 0;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: color 0.15s;
  font-size: 10px;
}
.cell-pause-btn:hover {
  color: var(--text-primary);
}
.cell-pause-btn:focus-visible {
  outline: 2px solid var(--accent-dim);
  outline-offset: 1px;
}

.placeholder-cell {
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  opacity: 0.45;
  position: relative;
  overflow: hidden;
}
.placeholder-cell::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 8px,
    rgba(255,255,255,0.012) 8px,
    rgba(255,255,255,0.012) 9px
  );
}
.ph-icon {
  width: 36px; height: 36px;
  border: 1px solid var(--text-dim);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  overflow: hidden;
  flex-shrink: 0;
}
.ph-icon img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.streamer-avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border-bright);
  flex-shrink: 0;
}
.ph-name {
  font-family: 'Rajdhani', sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}
.ph-status {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.placeholder-cell.variety {
  border-color: var(--purple-dim);
  opacity: 0.85;
}
.placeholder-cell.variety .ph-icon   { border-color: var(--purple-variety); color: var(--purple-variety); }
.placeholder-cell.variety .ph-name   { color: var(--purple-variety); }
.placeholder-cell.variety .ph-status { color: var(--purple-variety); }

.placeholder-cell.live {
  border-color: var(--blue-dim);
  opacity: 0.85;
}
.placeholder-cell.live .ph-icon   { border-color: var(--blue-live); color: var(--blue-live); }
.placeholder-cell.live .ph-name   { color: var(--blue-live); }
.placeholder-cell.live .ph-status { color: var(--blue-live); }

.empty-state {
  flex: 1;
  width: 100%;
  min-height: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 1.6vmin, 28px);
  color: var(--text-dim);
}
.empty-state-radar {
  /* Scales with viewport (vmin) so it looks proportional on all resolutions */
  width: clamp(calc(96px * var(--ui-scale, 1.25)), 18vmin, calc(220px * var(--ui-scale, 1.25)));
  height: clamp(calc(96px * var(--ui-scale, 1.25)), 18vmin, calc(220px * var(--ui-scale, 1.25)));
  flex-shrink: 0;
  opacity: 0.88;
  filter: drop-shadow(0 0 clamp(8px, 1vmin, 18px) rgba(232, 52, 74, 0.15));
}
.empty-radar-svg {
  display: block;
  width: 100%;
  height: 100%;
}
@keyframes empty-radar-spin {
  to { transform: rotate(-360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .poll-radar-svg .poll-radar-sweep {
    animation-duration: 18s;
  }
  .poll-radar-svg .poll-radar-blip-hit {
    animation: none;
    opacity: 0.72;
  }
  .streamer-status-loading__bar {
    animation: none;
    transform: none;
    opacity: 0.55;
  }
}
.empty-state > p:first-of-type {
  font-family: 'IBM Plex Mono', monospace;
  font-size: clamp(calc(13px * var(--ui-scale, 1.25)), 1.6vmin, calc(21px * var(--ui-scale, 1.25)));
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.empty-state-hint {
  font-family: 'IBM Plex Mono', monospace;
  font-size: clamp(calc(9px * var(--ui-scale, 1.25)), 1.1vmin, calc(14px * var(--ui-scale, 1.25)));
  letter-spacing: 0.04em;
  text-transform: none;
  color: #6e7685;
  max-width: clamp(calc(220px * var(--ui-scale, 1.25)), 28vmin, calc(420px * var(--ui-scale, 1.25)));
  text-align: center;
  line-height: 1.5;
}

