:root {
  --bg: #050816;
  --panel: rgba(6, 10, 25, 0.82);
  --panel-strong: rgba(7, 12, 28, 0.96);
  --line: rgba(255, 255, 255, 0.08);
  --text: #edf3ff;
  --muted: rgba(237, 243, 255, 0.58);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  --gap: 6px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(63, 88, 160, 0.22), transparent 24%),
    radial-gradient(circle at bottom right, rgba(32, 196, 82, 0.08), transparent 22%),
    var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", sans-serif;
}

button,
input {
  font: inherit;
}

.page {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.feedback {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 30;
  transform: translateX(-50%);
  min-height: 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.feedback:not(:empty) {
  opacity: 1;
}

.feedback[data-state="error"] {
  color: #ff9e9b;
}

.grid {
  display: grid;
  width: 100%;
  height: 100%;
  gap: var(--gap);
  padding: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
}

.grid[data-layout="split"] {
  gap: 0;
  padding: 0;
}

.grid[data-count="1"] {
  grid-template-columns: 1fr;
}

.grid[data-count="2"] {
  grid-template-columns: repeat(2, 1fr);
}

.grid[data-count="3"] {
  grid-template-columns: repeat(3, 1fr);
}

.grid[data-count="4"] {
  grid-template-columns: repeat(2, 1fr);
}

.grid[data-layout="featured"] .cell--featured,
.grid[data-layout="featured"] .cell--secondary {
  min-height: 0;
}

/* 3 streams: 2 featured top, 1 centered bottom */
.grid[data-layout="featured"][data-count="3"] {
  grid-template-columns: 1fr 1fr;
}
.grid[data-layout="featured"][data-count="3"] .cell:nth-child(3) {
  grid-column: 1 / -1;
  justify-self: center;
  width: 50%;
}

/* 4 streams: 2x2 grid */
.grid[data-layout="featured"][data-count="4"] {
  grid-template-columns: 1fr 1fr;
}

/* 5 streams: 2 top + 3 bottom */
.grid[data-layout="featured"][data-count="5"] {
  grid-template-columns: 1fr 1fr 1fr;
}

/* 6+ streams: flexible grid */
.grid[data-layout="featured"][data-count="6"],
.grid[data-layout="featured"][data-count="7"],
.grid[data-layout="featured"][data-count="8"],
.grid[data-layout="featured"][data-count="9"],
.grid[data-layout="featured"][data-count="10"],
.grid[data-layout="featured"][data-count="11"],
.grid[data-layout="featured"][data-count="12"] {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}

.cell {
  position: relative;
  min-height: 0;
  min-width: 0;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 18px;
  background: #030712;
  box-shadow: var(--shadow);
}

.drop-mask {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
}

body.is-reordering .drop-mask {
  display: block;
}

.grid[data-layout="split"] .cell {
  border-radius: 0;
}

.grid[data-layout="split"] .cell:first-child {
  border-radius: 18px 0 0 18px;
}

.grid[data-layout="split"] .cell:last-child {
  border-radius: 0 18px 18px 0;
}

.cell.is-dragging {
  opacity: 0.55;
}

.cell.drop-target::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid rgba(241, 245, 249, 0.7);
  border-radius: inherit;
  pointer-events: none;
  z-index: 4;
}

.player-wrap {
  position: absolute;
  inset: 0;
  background: #020617;
}

.player-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.twitch-player {
  position: absolute;
  inset: 0;
}

.card-head {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.52), transparent);
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
  z-index: 3;
}

.cell:hover .card-head,
.cell:focus-within .card-head {
  opacity: 1;
  pointer-events: auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(5, 8, 22, 0.72);
  backdrop-filter: blur(14px);
  font-family: "Archivo", sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.drag-handle {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(5, 8, 22, 0.82);
  color: var(--muted);
  backdrop-filter: blur(14px);
  font-family: "Archivo", sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: grab;
  pointer-events: auto;
}

.drag-handle:active {
  cursor: grabbing;
}

.badge-twitch {
  color: #cbb7ff;
}

.badge-kick {
  color: #93efb1;
}

.badge-youtube {
  color: #ffb0b0;
}

.remove-btn {
  border: 0;
  border-radius: 999px;
  min-width: 24px;
  height: 24px;
  padding: 0 10px;
  margin-left: auto;
  background: rgba(5, 8, 22, 0.76);
  color: var(--text);
  backdrop-filter: blur(14px);
  cursor: pointer;
  pointer-events: auto;
}

.remove-btn:hover {
  background: rgba(103, 22, 22, 0.88);
}

.label {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(5, 8, 22, 0.68);
  color: var(--muted);
  backdrop-filter: blur(14px);
  font-size: 0.74rem;
  opacity: 0;
  transition: opacity 0.18s ease;
  z-index: 3;
}

.splitter {
  position: relative;
  width: 10px;
  height: 100%;
  background: transparent;
  cursor: col-resize;
}

.splitter::before {
  content: none;
}

.cell:hover .label,
.cell:focus-within .label {
  opacity: 1;
}

.hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 14px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.56), transparent);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.page:hover .hud-top,
.page:focus-within .hud-top {
  opacity: 1;
}

.brand-block {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(5, 8, 22, 0.54);
  backdrop-filter: blur(16px);
}

.eyebrow,
.meta {
  margin: 0;
}

.eyebrow {
  font-family: "Archivo", sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.dock {
  position: absolute;
  left: 50%;
  right: auto;
  bottom: 0;
  width: min(720px, calc(100vw - 24px));
  padding: 18px 0 16px;
  transform: translate(-50%, calc(100% - 18px));
  transition: transform 0.22s ease;
}

.page:hover .dock,
.page:focus-within .dock,
.dock:hover {
  transform: translate(-50%, 0);
}

.dock::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 24px 24px 0 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.72), transparent);
  pointer-events: none;
}

.composer-form {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.composer-form::before {
  content: "Add stream";
  position: absolute;
  top: -26px;
  left: 14px;
  color: var(--muted);
  font-family: "Archivo", sans-serif;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.composer-form input {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: none;
}

.composer-form input::placeholder {
  color: rgba(237, 243, 255, 0.42);
}

.composer-form button {
  height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: #f1f5f9;
  color: #060b1a;
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.empty {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  background:
    radial-gradient(circle at center, rgba(57, 76, 145, 0.22), transparent 28%),
    linear-gradient(180deg, rgba(14, 22, 44, 0.9), rgba(4, 8, 18, 0.96));
  text-align: center;
}

.empty-inner {
  padding: 32px;
}

.empty strong {
  display: block;
  margin-bottom: 8px;
  font-family: "Archivo", sans-serif;
  font-size: clamp(1.4rem, 2.8vw, 2.8rem);
  font-weight: 600;
  letter-spacing: -0.03em;
}

.empty span {
  color: var(--muted);
  font-size: 0.95rem;
}

/* Layout toggle button */
.layout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 10px;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(5, 8, 22, 0.68);
  color: var(--muted);
  font-family: "Archivo", sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.15s ease, color 0.15s ease;
}
.layout-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

/* Focus mode: hidden cards */
.cell--hidden {
  display: none;
}

/* Focus mode: focused card fills the grid */
.grid[data-layout="focus"] {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

/* Preset modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.modal {
  width: min(420px, calc(100vw - 32px));
  max-height: min(600px, calc(100vh - 80px));
  border-radius: 18px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head .eyebrow {
  font-size: 0.75rem;
}
.modal-close {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover {
  color: var(--text);
}
.modal-body {
  padding: 12px 18px 18px;
  overflow-y: auto;
}
.preset-section h3 {
  margin: 12px 0 8px;
  font-family: "Archivo", sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.preset-section:first-child h3 {
  margin-top: 0;
}
.preset-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  pointer-events: auto;
  text-align: left;
  transition: background 0.15s ease;
}
.preset-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}
.preset-btn strong {
  font-family: "Archivo", sans-serif;
  font-size: 0.85rem;
}
.preset-btn span {
  color: var(--muted);
  font-size: 0.72rem;
}

@media (max-width: 820px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .grid[data-layout="split"] {
    gap: var(--gap);
    padding: var(--gap);
    grid-template-columns: 1fr;
  }

  .grid[data-layout="featured"] {
    gap: var(--gap);
    padding: var(--gap);
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-rows: minmax(220px, 1fr);
  }

  .grid[data-layout="featured"] .cell--hero,
  .grid[data-layout="featured"] .cell--thumb-single,
  .grid[data-layout="featured"] .cell--thumb-half,
  .grid[data-layout="featured"] .cell--thumb-third {
    grid-column: auto;
  }

  .grid[data-layout="split"] .cell,
  .grid[data-layout="split"] .cell:first-child,
  .grid[data-layout="split"] .cell:last-child {
    border-radius: 18px;
  }

  .splitter {
    display: none;
  }

  .dock {
    width: calc(100vw - 18px);
  }

  .composer-form {
    gap: 8px;
    padding: 8px;
  }

  .composer-form button {
    padding: 0 14px;
  }
}

body.is-resizing {
  cursor: col-resize;
}
