/* ==========================================================================
   ViewStax — design tokens
   Flat, neutral, one accent. Platform colours are used only as small markers.
   ========================================================================== */
:root {
  --bg: #0c0c0e;
  --bar: #111113;
  --surface: #151518;
  --surface-2: #1b1b1f;
  --surface-3: #232328;
  --border: #26262b;
  --border-strong: #3a3a42;
  --text: #ececee;
  --text-dim: #8d8d97;
  --text-faint: #62626b;
  --accent: #0433d9;
  --accent-text: #6f90ff;
  --accent-ink: #fff;
  --accent-soft: rgba(4, 51, 217, 0.22);
  --ok: #4ade80;
  --danger: #f87171;

  --twitch: #9146ff;
  --youtube: #ff4d4d;
  --kick: #53fc18;

  --radius: 8px;
  --bar-h: 30px; /* keep in sync with BAR_H in js/layout.js */
  --topbar-h: 46px;
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  position: relative;
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
  position: relative;
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-h);
  padding: 6px 12px;
  background: var(--bar);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; flex: none; color: var(--text); text-decoration: none; }
.brand__logo { display: block; height: 28px; width: auto; }

.add-form { display: flex; align-items: center; gap: 8px; flex: 1 1 360px; min-width: 0; max-width: 560px; }

.platforms {
  display: flex; flex: none; margin: 0; padding: 2px;
  border: 1px solid var(--border); border-radius: 7px; background: var(--bg);
}
.platform { position: relative; cursor: pointer; }
.platform input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.platform__pill {
  display: flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 5px;
  font-size: 12px; font-weight: 500; color: var(--text-dim);
  transition: background 0.12s, color 0.12s;
}
.platform__pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--dot, var(--text-faint)); }
.platform__pill--twitch { --dot: var(--twitch); }
.platform__pill--youtube { --dot: var(--youtube); }
.platform__pill--kick { --dot: var(--kick); }
.platform input:hover + .platform__pill { color: var(--text); }
.platform input:checked + .platform__pill { color: var(--text); background: var(--surface-3); }
.platform input:focus-visible + .platform__pill { outline: 2px solid var(--accent); outline-offset: 1px; }

.add-input {
  flex: 1;
  min-width: 100px;
  height: 32px;
  padding: 0 11px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  transition: border-color 0.12s;
}
.add-input::placeholder { color: var(--text-faint); }
.add-input:hover { border-color: var(--border-strong); }
.add-input:focus { outline: none; border-color: var(--accent); }

.check { display: inline-flex; align-items: center; gap: 6px; flex: none; font-size: 12px; color: var(--text-dim); cursor: pointer; white-space: nowrap; user-select: none; }
.check input { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; }
.check:hover { color: var(--text); }

.toolbar { display: flex; align-items: center; gap: 4px; margin-left: auto; flex: none; }
.group { display: flex; gap: 2px; }
.sep { width: 1px; height: 18px; margin: 0 6px; background: var(--border); }
.menu { position: relative; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.btn svg { flex: none; width: 15px; height: 15px; }
.btn:hover:not(:disabled, [aria-disabled="true"]) { color: var(--text); background: var(--surface-3); }
.btn:is(:disabled, [aria-disabled="true"]) { opacity: 0.4; cursor: not-allowed; }
.btn[aria-pressed="true"] { color: var(--text); }
.btn--toggle[aria-pressed="true"] { color: var(--accent-text); background: var(--accent-soft); }
.btn#multichat-btn[aria-pressed="true"], .btn--menu[aria-expanded="true"] { color: var(--text); background: var(--surface-3); }
.btn__value { padding-left: 6px; margin-left: 2px; color: var(--text-faint); border-left: 1px solid var(--border); font-weight: 400; }
.btn--menu[aria-expanded="true"] .btn__value { color: var(--text-dim); }
.btn--icon { width: 30px; padding: 0; justify-content: center; }
.btn--danger:hover:not(:disabled, [aria-disabled="true"]) { color: var(--danger); background: rgba(248, 113, 113, 0.1); }

/* Highlighted buttons (Add, Layouts) so they are easy to find */
.btn--primary,
#presets-btn,
#presets-btn[aria-expanded="true"] {
  height: 32px;
  padding: 0 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(180deg, #2a55f0 0%, var(--accent) 100%);
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 4px 14px -4px rgba(4, 51, 217, 0.8);
}
.btn--primary:hover:not(:disabled, [aria-disabled="true"]),
#presets-btn:hover:not(:disabled) { color: #fff; background: linear-gradient(180deg, #3d68ff 0%, #1a45e8 100%); }
.btn--primary:active:not(:disabled, [aria-disabled="true"]),
#presets-btn[aria-expanded="true"] { background: linear-gradient(180deg, #1a45e8 0%, #032bb8 100%); }
#presets-btn .btn__value { color: rgba(255, 255, 255, 0.75); border-left-color: rgba(255, 255, 255, 0.3); }
#presets-btn[aria-expanded="true"] .btn__value { color: rgba(255, 255, 255, 0.75); }

/* Layouts panel */
.panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 10;
  width: 600px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.8);
}
.panel[hidden] { display: none; }
.panel__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.panel__head strong { font-size: 13px; font-weight: 600; }
.panel__head span, .panel__empty { font-size: 12px; color: var(--text-dim); }
.panel__empty { margin: 4px 0 6px; }
.panel__group + .panel__group { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.panel__group h3 { display: flex; align-items: baseline; gap: 10px; margin: 0 0 8px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
.panel__group h3 small { font-size: 11.5px; font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--text-faint); }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.card {
  display: flex; flex-direction: column; gap: 7px; padding: 7px;
  color: var(--text-dim); text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}
.card:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-3); }
.card[aria-pressed="true"] { color: var(--text); border-color: var(--accent); }
.card__label { padding: 0 2px 1px; font-size: 12px; font-weight: 500; }
.card__preview { position: relative; display: block; aspect-ratio: 16 / 9; background: var(--bg); border-radius: 4px; overflow: hidden; }
.cell { position: absolute; display: block; background: #3b3b44; border-radius: 2px; outline: 1px solid var(--bg); outline-offset: -1px; }
.cell--main { background: var(--accent); }
.cell--chat { background: #2b3550; }
.card[aria-pressed="true"] .cell:not(.cell--main):not(.cell--chat) { background: #4d4d58; }

/* Hide / peek the bar */
.peek-zone { display: none; position: fixed; z-index: 10001; top: 0; left: 0; right: 0; height: 5px; }
.bar-tab {
  display: none;
  position: fixed;
  z-index: 10001;
  top: 0;
  left: 50%;
  width: 40px;
  height: 16px;
  padding: 0;
  place-items: center;
  color: var(--text-dim);
  background: var(--bar);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  opacity: 0.6;
  transform: translateX(-50%);
  cursor: pointer;
  transition: opacity 0.15s, color 0.15s;
}
.bar-tab svg { width: 14px; height: 14px; }
.bar-tab:hover { opacity: 1; color: var(--text); }

body.bar-hidden .topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  transform: translateY(-100%);
  border-bottom-color: var(--border-strong);
  transition: transform 0.16s ease;
}
body.bar-hidden.bar-peek .topbar,
body.bar-hidden .topbar:focus-within,
body.bar-hidden .topbar.panel-open {
  transform: none;
  box-shadow: 0 14px 30px -10px rgba(0, 0, 0, 0.8);
}
body.bar-hidden .peek-zone { display: block; }
body.bar-hidden .bar-tab { display: grid; }
body.bar-hidden.bar-peek .bar-tab { opacity: 0; pointer-events: none; }

/* ==========================================================================
   Tooltip
   ========================================================================== */
.tooltip {
  position: fixed;
  z-index: 30000;
  max-width: 260px;
  padding: 6px 9px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: 0 10px 24px -8px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  animation: tooltip-in 0.12s ease-out;
}
.tooltip[hidden] { display: none; }
@keyframes tooltip-in { from { opacity: 0; transform: translateY(-2px); } }

/* ==========================================================================
   Banner & toasts
   ========================================================================== */
.banner { z-index: 9999; padding: 9px 14px; color: #fde8e8; background: #5c1d1d; border-bottom: 1px solid #7f2a2a; }
.banner[hidden] { display: none; }
.banner code { padding: 1px 5px; border-radius: 4px; background: rgba(0, 0, 0, 0.3); }

.toasts { position: fixed; z-index: 20000; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  max-width: 380px;
  padding: 10px 14px;
  line-height: 1.4;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--text-dim);
  border-radius: 8px;
  box-shadow: 0 12px 32px -10px rgba(0, 0, 0, 0.8);
  animation: toast-in 0.2s ease-out;
}
.toast--error { border-left-color: var(--danger); }
.toast--ok { border-left-color: var(--ok); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Welcome popup */
.welcome {
  position: fixed; z-index: 20000; top: 50%; left: 50%;
  width: min(480px, calc(100vw - 32px));
  padding: 40px 36px 36px;
  text-align: center;
  color: #fff;
  background: var(--accent);
  border-radius: 20px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.6), 0 30px 80px -10px rgba(0, 0, 0, 0.7);
  transform: translate(-50%, -50%);
  animation: welcome-in 0.35s ease-out;
}
.welcome[hidden] { display: none; }
.welcome.is-leaving { opacity: 0; transform: translate(-50%, -48%); transition: opacity 0.3s, transform 0.3s; }
.welcome__logo { display: block; height: 96px; width: auto; max-width: 100%; margin: 0 auto 12px; }
.welcome__title { margin: 0 0 8px; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.welcome__text { margin: 0; font-size: 16px; line-height: 1.5; color: rgba(255, 255, 255, 0.85); }
.welcome__close {
  position: absolute; top: 12px; right: 14px;
  width: 32px; height: 32px; padding: 0;
  font-size: 24px; line-height: 1; color: rgba(255, 255, 255, 0.8);
  background: none; border: 0; border-radius: 8px; cursor: pointer;
}
.welcome__close:hover { color: #fff; background: rgba(255, 255, 255, 0.15); }
@keyframes welcome-in { from { opacity: 0; transform: translate(-50%, -46%) scale(0.96); } }

/* ==========================================================================
   Board
   ========================================================================== */
.board { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--bg); }
.board::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 20px 20px;
  transition: opacity 0.2s;
}
.board.show-grid::before {
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
}

/* Empty state */
.empty { position: absolute; inset: 0; display: flex; overflow: auto; padding: 24px; }
.empty[hidden] { display: none; }
.hero { width: min(640px, 100%); margin: auto; text-align: center; }
.hero__logo { display: block; height: 72px; width: auto; margin: 0 auto 10px; }
.hero__title { margin: 0 0 8px; font-size: 30px; font-weight: 650; letter-spacing: -0.03em; }
.hero__lead { margin: 0 auto 22px; max-width: 460px; font-size: 14px; line-height: 1.55; color: var(--text-dim); }

.hero__row {
  display: flex; gap: 8px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.hero__row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hero__input { flex: 1; min-width: 0; height: 38px; padding: 0 10px; font-size: 15px; color: var(--text); background: none; border: 0; outline: none; }
.hero__input::placeholder { color: var(--text-faint); }
.hero__go { height: 38px; padding: 0 18px; font-size: 13.5px; }
.hero__opts { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 12px; }

.demo { margin-top: 30px; }
.demo__stage { position: relative; aspect-ratio: 16 / 9; width: min(100%, 520px); margin: 0 auto; }
.demo__tile {
  position: absolute; display: block; overflow: hidden;
  padding: 7px 9px;
  font: 500 10.5px/1 var(--mono); text-align: left; letter-spacing: 0.02em;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  transition: left 0.5s cubic-bezier(0.3, 0.8, 0.2, 1), top 0.5s cubic-bezier(0.3, 0.8, 0.2, 1),
    width 0.5s cubic-bezier(0.3, 0.8, 0.2, 1), height 0.5s cubic-bezier(0.3, 0.8, 0.2, 1),
    background 0.3s, border-color 0.3s;
}
.demo__tile::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--dot, var(--text-faint)); }
.demo__tile--main { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.demo__tile--chat { --dot: var(--accent-text); background: #151b2e; }
.demo__tabs { display: inline-flex; gap: 2px; margin-top: 16px; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.demo__tab { height: 26px; padding: 0 12px; font: inherit; font-size: 12px; color: var(--text-dim); background: none; border: 0; border-radius: 5px; cursor: pointer; }
.demo__tab:hover { color: var(--text); }
.demo__tab.is-on { color: #fff; background: var(--accent); }
.hero__keys { margin: 22px 0 0; font-size: 12px; color: var(--text-faint); }
@media (max-height: 700px) { .demo { display: none; } }
@media (prefers-reduced-motion: reduce) { .demo__tile { transition: none; } }
code, kbd {
  font-family: var(--mono);
  font-size: 0.9em;
  padding: 1px 5px;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
}

/* ==========================================================================
   Tiles
   ========================================================================== */
.tile {
  position: absolute;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px -14px rgba(0, 0, 0, 0.9);
  /* Animate preset changes, but never while the user is dragging. */
  transition-property: border-color, left, top, width, height;
  transition-duration: 0.15s, 0.26s, 0.26s, 0.26s, 0.26s;
  transition-timing-function: ease, cubic-bezier(0.3, 0.8, 0.3, 1);
}
.board.is-interacting .tile { transition-property: border-color; }
.tile:hover { border-color: var(--border-strong); }

.tile__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 var(--bar-h);
  height: var(--bar-h);
  padding: 0 4px 0 10px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  background: var(--surface-2);
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
  border-bottom: 1px solid var(--border);
}
.tile__bar:active { cursor: grabbing; }

.tile--stream.tile--twitch .tile__bar {
  position: absolute;
  inset: 0 0 auto;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-100%);
  transition: opacity 0.14s, transform 0.14s;
}
.tile--stream.tile--twitch:hover .tile__bar,
.tile--stream.tile--twitch:focus-within .tile__bar {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.tile--stream.tile--twitch .tile__body { border-radius: calc(var(--radius) - 1px); }
@media (hover: none) {
  .tile--stream.tile--twitch .tile__bar {
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dot, var(--text-faint)); }
.badge--twitch { --dot: var(--twitch); }
.badge--youtube { --dot: var(--youtube); }
.badge--kick { --dot: var(--kick); }

.tile__title { flex: 1; min-width: 0; overflow: hidden; font-size: 12.5px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.tile__title[hidden] { display: none; }
.tile__warn { display: inline-flex; flex: none; color: #fbbf24; cursor: help; }
.tile__warn[hidden] { display: none; }

/* Site-native dropdown (see js/dropdown.js) */
.dd {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  height: 22px;
  padding: 0 6px 0 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  transition: border-color 0.12s;
}
.dd:hover, .dd[aria-expanded="true"] { border-color: var(--border-strong); }
.dd:disabled { opacity: 0.5; cursor: default; }
.dd__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd svg { flex: none; width: 12px; height: 12px; color: var(--text-dim); }
.dd--tile { flex: 1; justify-content: space-between; }

.dd-menu {
  position: fixed;
  z-index: 25000;
  overflow-y: auto;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 16px 36px -10px rgba(0, 0, 0, 0.85);
}
.dd-menu[hidden] { display: none; }
.dd-menu__item {
  padding: 5px 10px 5px 8px;
  font-size: 12px;
  color: var(--text-dim);
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  outline: none;
}
.dd-menu__item:focus, .dd-menu__item:hover { color: var(--text); background: var(--surface-3); }
.dd-menu__item[aria-selected="true"] { color: var(--accent-text); }

.tile__actions { display: flex; flex: none; gap: 1px; }
.tile__btn {
  display: grid;
  place-items: center;
  width: 24px;
  height: 22px;
  padding: 0;
  color: var(--text-dim);
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.tile__btn svg { width: 14px; height: 14px; }
.tile__btn:hover:not(:disabled, [aria-disabled="true"]) { color: var(--text); background: var(--surface-3); }
.tile__btn[aria-pressed="true"] { color: var(--accent-text); }
.tile__btn[data-action="audio"][aria-pressed="true"] { color: var(--ok); }
.tile__btn[data-action="remove"]:hover { color: var(--danger); background: rgba(248, 113, 113, 0.12); }
.tile__btn:is(:disabled, [aria-disabled="true"]) { opacity: 0.35; cursor: not-allowed; }

.tile__body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #000;
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
}
.tile--chat .tile__body { background: #18181b; }
.player-holder, .embed-frame, .player-holder iframe { display: block; width: 100%; height: 100%; border: 0; }
.embed-frame[hidden] { display: none; }

.tile__error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  color: #fdd;
  background: rgba(20, 8, 8, 0.92);
}

/* Iframes swallow pointer events; during a drag a shield sits on top of them. */
.tile__shield { position: absolute; inset: var(--bar-h) 0 0 0; display: none; z-index: 2; }
.board.is-interacting .tile__shield { display: block; }
.board.is-interacting iframe { pointer-events: none; }

/* In focus/theater the other streams get a small "Make main" button; the player itself stays clickable. */
.tile__swap {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 14px;
  display: none;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  opacity: 0;
  transform: translate(-50%, 4px);
  transition: opacity 0.14s, transform 0.14s, background 0.12s;
}
.tile.is-secondary .tile__swap { display: block; }
.tile.is-secondary:hover .tile__swap, .tile__swap:focus-visible { opacity: 1; transform: translateX(-50%); }
.tile__swap:hover { background: #2150f0; }
.board.is-interacting .tile__swap, .tile:fullscreen .tile__swap { display: none; }


.tile__readout {
  position: absolute;
  z-index: 4;
  top: 50%;
  left: 50%;
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  background: rgba(12, 12, 14, 0.9);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.tile__readout[hidden] { display: none; }

/* Twitch controls float over a soft player fade instead of taking a solid strip of video. */
.tc {
  position: absolute;
  z-index: 4;
  inset: auto 0 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 68px;
  padding: 22px 12px 10px;
  background: linear-gradient(180deg, transparent 0%, rgba(8, 8, 10, 0.38) 36%, rgba(8, 8, 10, 0.9) 100%);
  opacity: 0;
  pointer-events: auto;
  transform: translateY(4px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.tile:hover .tc, .tc:hover, .tc:focus-within, .tc:has(.dd[aria-expanded="true"]) {
  opacity: 1;
  transform: translateY(0);
}
.tc__group {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 42px;
  padding: 4px 6px;
  background: rgba(20, 20, 23, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.24);
}
.tc__spacer { flex: 1; min-width: 0; }
.tc__btn {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: rgba(255, 255, 255, 0.78);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, transform 0.12s;
}
.tc__btn:hover { color: #fff; background: rgba(255, 255, 255, 0.12); }
.tc__btn:active { transform: scale(0.94); }
.tc__btn svg { width: 17px; height: 17px; }
.tc__volume {
  width: 92px;
  min-width: 48px;
  height: 20px;
  margin: 0 5px;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.tc__volume::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--accent) var(--volume-level, 50%), rgba(255, 255, 255, 0.25) var(--volume-level, 50%));
}
.tc__volume::-moz-range-track {
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.25);
}
.tc__volume::-moz-range-progress { height: 4px; border-radius: 99px; background: var(--accent); }
.tc__volume::-webkit-slider-thumb {
  width: 12px;
  height: 12px;
  margin-top: -4px;
  appearance: none;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.tc__volume::-moz-range-thumb {
  width: 9px;
  height: 9px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.tc__quality { display: flex; align-items: center; gap: 6px; padding-left: 4px; color: var(--text-dim); }
.tc__quality > svg { flex: none; width: 16px; height: 16px; }
.tc .dd--tc {
  max-width: 104px;
  height: 30px;
  padding: 0 7px;
  background: transparent;
  border-color: transparent;
  border-radius: 8px;
}
.tc .dd--tc:hover, .tc .dd--tc[aria-expanded="true"] {
  color: var(--text);
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.08);
}
.tc .dd--tc .dd__label { font-size: 12px; }
.tc .dd--tc svg { color: currentColor; }
@media (hover: none) {
  .tc { opacity: 1; pointer-events: auto; transform: none; }
}
.board.is-interacting .tc { display: none; }
.tile--twitch .tile__swap { bottom: 64px; }

/* Resize handles sit on the tile edge, mostly outside the player. */
.tile__handle { position: absolute; z-index: 3; touch-action: none; }
.tile__handle--n  { top: -5px;    left: 14px;  right: 14px;  height: 10px; cursor: ns-resize; }
.tile__handle--s  { bottom: -5px; left: 14px;  right: 14px;  height: 10px; cursor: ns-resize; }
.tile__handle--e  { right: -5px;  top: 14px;   bottom: 14px; width: 10px;  cursor: ew-resize; }
.tile__handle--w  { left: -5px;   top: 14px;   bottom: 14px; width: 10px;  cursor: ew-resize; }
.tile__handle--ne { top: -6px;    right: -6px;  width: 18px; height: 18px; cursor: nesw-resize; }
.tile__handle--nw { top: -6px;    left: -6px;   width: 18px; height: 18px; cursor: nwse-resize; }
.tile__handle--se { bottom: -6px; right: -6px;  width: 18px; height: 18px; cursor: nwse-resize; }
.tile__handle--sw { bottom: -6px; left: -6px;   width: 18px; height: 18px; cursor: nesw-resize; }
.tile__handle--se::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 8px;
  height: 8px;
  border-right: 2px solid rgba(255, 255, 255, 0.35);
  border-bottom: 2px solid rgba(255, 255, 255, 0.35);
  border-bottom-right-radius: 3px;
  opacity: 0;
  transition: opacity 0.15s;
}
.tile:hover .tile__handle--se::after { opacity: 1; }

/* Keep the cursor consistent for the whole drag. */
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }
body.is-resizing[data-cursor="n"], body.is-resizing[data-cursor="n"] *,
body.is-resizing[data-cursor="s"], body.is-resizing[data-cursor="s"] * { cursor: ns-resize !important; }
body.is-resizing[data-cursor="e"], body.is-resizing[data-cursor="e"] *,
body.is-resizing[data-cursor="w"], body.is-resizing[data-cursor="w"] * { cursor: ew-resize !important; }
body.is-resizing[data-cursor="ne"], body.is-resizing[data-cursor="ne"] *,
body.is-resizing[data-cursor="sw"], body.is-resizing[data-cursor="sw"] * { cursor: nesw-resize !important; }
body.is-resizing[data-cursor="nw"], body.is-resizing[data-cursor="nw"] *,
body.is-resizing[data-cursor="se"], body.is-resizing[data-cursor="se"] * { cursor: nwse-resize !important; }
body.is-dragging, body.is-resizing { user-select: none; }

.tile:fullscreen { border-radius: 0; }
.tile:fullscreen .tile__bar, .tile:fullscreen .tile__body { border-radius: 0; }
.tile:fullscreen .tile__handle { display: none; }

/* Popped-out single-tile window */
body.solo .topbar, body.solo .bar-tab, body.solo .peek-zone { display: none; }

/* Narrow windows: drop labels first, then let the bar wrap. */
@media (max-width: 1280px) {
  .btn--menu .btn__value { display: none; }
  #multichat-btn span:last-child, #share-btn span:last-child { display: none; }
  #multichat-btn, #share-btn { width: 30px; padding: 0; justify-content: center; }
}
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .toolbar { margin-left: 0; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
