:root {
  --strip: 21vw;
  --gap: 3px;
  --bg: #08080b;
  --hot: #ffb020;
  --audio: #22d3a6;
  --ui: rgba(255, 255, 255, 0.82);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font: 13px/1.35 ui-sans-serif, -apple-system, "Segoe UI", system-ui, sans-serif;
  color: var(--ui);
}

/* ---------- stage ---------- */

.stage {
  display: grid;
  gap: var(--gap);
  width: 100vw;
  height: 100vh;
  padding: var(--gap);
}

.stage:empty::before {
  content: "no streams — press S";
  place-self: center;
  opacity: 0.35;
  letter-spacing: 0.04em;
}

.tile {
  position: relative;
  background: #000;
  border-radius: 5px;
  outline: 1px solid rgba(255, 255, 255, 0.06);
  outline-offset: -1px;
  transition:
    transform 160ms cubic-bezier(0.22, 0.8, 0.3, 1),
    outline-color 200ms ease,
    box-shadow 240ms ease;
}

.tile.is-focused {
  outline-color: rgba(255, 255, 255, 0.16);
}

/* Hype glow. Deliberately loud — it exists to catch peripheral vision. */
.tile.is-hot {
  outline-color: var(--hot);
  box-shadow:
    0 0 0 1px var(--hot),
    0 0 26px -4px rgba(255, 176, 32, 0.75);
}

.tile.has-audio {
  outline-color: var(--audio);
}

/* Peek: scale in place. The grid never reflows, so no iframe is ever
   re-parented and no stream reloads. */
.tile.is-peeking {
  transform: scale(var(--peek-scale, 2));
  z-index: 60;
  box-shadow: 0 24px 70px -12px rgba(0, 0, 0, 0.9);
}

.video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: inherit;
  background: #000;
}

.player-host {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-origin: top left;
}

.player-host iframe {
  width: 100% !important;
  height: 100% !important;
  border: 0;
  display: block;
  border-radius: inherit;
}

.tile.is-offline .video::after {
  content: "";
}

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 4px;
  border-radius: 99px;
  background: rgba(8, 8, 11, 0.62);
  backdrop-filter: blur(6px);
  pointer-events: none;
  font-size: 11px;
  letter-spacing: 0.02em;
}

.hud .num {
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  font-weight: 650;
  font-size: 10px;
}

.hud .name {
  font-weight: 600;
}

.hud .quality {
  opacity: 0.45;
  font-variant-numeric: tabular-nums;
}

.hud .offline-tag {
  display: none;
  color: #ff6b6b;
}

.tile.is-offline .offline-tag {
  display: inline;
}

.tile.is-focused .hud {
  font-size: 12px;
}

/* ---------- hype bar ---------- */

.hypebar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  z-index: 10;
  background: rgba(255, 255, 255, 0.07);
  pointer-events: none;
  border-radius: 0 0 5px 5px;
  overflow: hidden;
}

.hypebar i {
  display: block;
  height: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, #4b7bec, var(--hot));
  transition: transform 220ms ease-out;
}

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

.chat {
  position: absolute;
  /* Bottom-anchored, not full-tile: an idle stream's chat used to grow up the
     whole picture and hide the thing you are here to watch. Capping the box and
     ending it at flex-end means the overflow that gets clipped is the OLD lines,
     so a small tile always shows the most recent ones and nothing else. */
  inset: auto 6px 10px 6px;
  max-height: 34%;
  z-index: 8;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 1px;
  pointer-events: none;
  overflow: hidden;
  font-size: 10.5px;
  /* Fades the clipped top edge instead of guillotining a line mid-glyph. */
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 22px);
  mask-image: linear-gradient(180deg, transparent, #000 22px);
  /* No background: the whole point of rendering chat ourselves is that it can
     be genuinely transparent. Legibility comes from the shadow below. */
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.95),
    0 0 5px rgba(0, 0, 0, 0.85);
}

.tile.is-focused .chat {
  inset: 34px auto 14px 10px;
  max-height: none;
  width: 30%;
  font-size: 12.5px;
}

/* A peeked tile is blown up mid-hover but is still not the focused one — give it
   a little more room than idle without letting it swallow the frame. */
.tile.is-peeking .chat {
  max-height: 45%;
}

body.chat-hidden .chat {
  display: none;
}

.chat-line {
  animation: chat-in 180ms ease-out;
  transition:
    opacity 380ms ease,
    transform 380ms ease;
  overflow-wrap: anywhere;
}

.chat-line.is-leaving {
  opacity: 0;
  transform: translateY(-3px);
}

@keyframes chat-in {
  from {
    opacity: 0;
    transform: translateX(-6px);
  }
}

.chat-name {
  font-weight: 700;
}

.chat-body.is-action {
  font-style: italic;
}

.emote {
  height: 1.55em;
  vertical-align: -0.42em;
}

.tile.is-focused .emote {
  height: 1.75em;
}

/* ---------- hit layer ---------- */

.hit {
  position: absolute;
  inset: 0;
  z-index: 20;
  cursor: pointer;
}

/* Until a stream is actually playing, the hit layer must not cover the
   iframe: a user gesture does not cross a postMessage boundary, so clicking
   Twitch's own play button is the ONLY thing that can start a player that
   autoplay refused. Hover still works — mouseenter fires on the tile itself. */
.tile.needs-play .hit {
  pointer-events: none;
}

/* ---------- chrome ---------- */

.status {
  position: fixed;
  right: 10px;
  bottom: 8px;
  z-index: 100;
  padding: 3px 9px;
  border: 0;
  border-radius: 99px;
  background: rgba(8, 8, 11, 0.7);
  backdrop-filter: blur(6px);
  color: inherit;
  font: inherit;
  font-size: 10.5px;
  opacity: 0.62;
  cursor: pointer;
}

.status:hover,
.status:focus-visible {
  opacity: 1;
}

.status.is-armed {
  opacity: 0.95;
  color: var(--hot);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 120;
  translate: -50% 8px;
  padding: 7px 15px;
  border-radius: 99px;
  background: rgba(20, 20, 26, 0.9);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 34px -10px #000;
  opacity: 0;
  transition:
    opacity 180ms ease,
    translate 180ms ease;
  pointer-events: none;
  font-size: 12px;
}

.toast.is-visible {
  opacity: 1;
  translate: -50% 0;
}

.help {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  place-items: center;
  background: rgba(4, 4, 6, 0.72);
  backdrop-filter: blur(4px);
}

.help.is-visible {
  display: grid;
}

.help-panel {
  min-width: 340px;
  padding: 22px 26px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #121218;
  box-shadow: 0 30px 80px -20px #000;
}

.help-panel h1 {
  margin: 0 0 14px;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.55;
}

.help-panel dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 16px;
  margin: 0;
  font-size: 12.5px;
}

.help-panel dt {
  justify-self: start;
  padding: 1px 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.help-panel dd {
  margin: 0;
  opacity: 0.8;
}

.help-note {
  margin: 16px 0 0;
  padding-top: 13px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11.5px;
  opacity: 0.5;
}

/* ---------- autoplay gate ---------- */

/* Non-blocking hint shown only when autoplay was refused. Twitch requires the
   real click to land inside its cross-origin iframe, so this must never cover
   the player controls. */
.gate {
  position: fixed;
  left: 50%;
  bottom: 38px;
  z-index: 90;
  display: none;
  align-items: center;
  gap: 8px;
  translate: -50% 0;
  padding: 7px 12px 7px 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 99px;
  background: rgba(12, 12, 17, 0.88);
  backdrop-filter: blur(8px);
  box-shadow: 0 12px 34px -12px #000;
  color: var(--ui);
  font-size: 11.5px;
  pointer-events: none;
}

.gate.is-visible {
  display: flex;
}

.gate-play {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 9px;
  padding-left: 2px;
}

.gate b {
  color: #fff;
}

/* ---------- streams panel ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: none;
  place-items: center;
  background: rgba(4, 4, 6, 0.72);
  backdrop-filter: blur(4px);
}

.sheet.is-visible {
  display: grid;
}

.sheet-panel {
  width: min(460px, calc(100vw - 32px));
  max-height: min(78vh, 640px);
  overflow: auto;
  padding: 20px 22px 18px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #121218;
  box-shadow: 0 30px 80px -20px #000;
}

.sheet-panel h1 {
  margin: 0 0 14px;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.55;
}

.roster-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.roster-row {
  display: grid;
  /* grip · number · label · channel · park · remove */
  grid-template-columns: auto 18px auto 1fr auto auto;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
}

.roster-row.is-hidden {
  opacity: 0.4;
}

.roster-row.is-dragging {
  background: rgba(255, 255, 255, 0.12);
  outline: 1px solid rgba(255, 255, 255, 0.2);
}

.roster-row button {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  padding: 2px 4px;
  border-radius: 5px;
  cursor: pointer;
  opacity: 0.6;
}

.roster-row button:hover,
.roster-row button:focus-visible {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

.roster-grip {
  cursor: grab;
  /* Without this a touch drag scrolls the panel instead of moving the row. */
  touch-action: none;
  letter-spacing: -1px;
}

.roster-row.is-dragging .roster-grip {
  cursor: grabbing;
}

.roster-num {
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  opacity: 0.5;
}

.roster-name {
  font-weight: 600;
}

.roster-chan {
  font-size: 11px;
  opacity: 0.42;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roster-del:hover {
  color: #ff6b6b;
}

.roster-add {
  display: flex;
  gap: 7px;
  margin-top: 12px;
}

.roster-add input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  font: inherit;
  font-size: 12.5px;
}

.roster-add input:disabled {
  opacity: 0.45;
}

.roster-add button,
.sheet-foot button {
  padding: 7px 13px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.roster-add button:hover,
.sheet-foot button:hover {
  background: rgba(255, 255, 255, 0.16);
}

.sheet-foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
}

.sheet-foot .ghost {
  border-color: transparent;
  background: none;
  opacity: 0.55;
}

.sheet-foot .ghost:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}

/* The one setting that is not a stream. It lives in the Streams panel because
   that is the only dialog there is, and a preference nobody can find is a
   preference nobody has. */
.sheet-opt {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 14px;
  padding: 9px 11px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 12.5px;
  color: #c8c8d2;
  cursor: pointer;
  user-select: none;
}

.sheet-opt:hover {
  border-color: rgba(255, 255, 255, 0.14);
  color: #eee;
}

.sheet-opt input {
  width: 15px;
  height: 15px;
  accent-color: #9147ff;
  cursor: pointer;
}

.sheet-opt b {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  font: 600 10.5px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #a9a9b6;
}
