/* ── Custom Properties ───────────────────────────────────────────── */
:root {
  --bg:          #0f0f0f;
  --surface:     #1a1a1a;
  --border:      #2e2e2e;
  --border-live: #ff4444;
  --accent:      #3ea6ff;
  --accent-hover:#5ab8ff;
  --text:        #e8e8e8;
  --text-muted:  #888;
  --header-h:    56px;
  --gap:         8px;
  --radius:      6px;
}

/* ── Reset ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  font-size: 14px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────── */
header {
  height: var(--header-h);
  min-height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
}

header h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
  white-space: nowrap;
}

.header-left {
  display: flex;
  align-items: center;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

#add-stream-form {
  display: flex;
  gap: 6px;
  flex: 1;
  max-width: 480px;
}

#stream-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0 10px;
  height: 32px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

#stream-input:focus {
  border-color: var(--accent);
}

button {
  height: 32px;
  padding: 0 14px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

button:hover { background: var(--accent-hover); }

#go-live-btn {
  background: var(--border-live);
  color: #fff;
}

#go-live-btn:hover { background: #ff6666; }

/* ── Unmute overlay ──────────────────────────────────────────────── */
#unmute-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#unmute-overlay[hidden] { display: none; }

#unmute-overlay p {
  color: rgba(255, 255, 255, 0.45);
  font-size: 12px;
  letter-spacing: 0.4px;
}

#unmute-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 40px;
  background: transparent;
  color: #fff;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 100px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  overflow: hidden;
}

/* Animated glow ring */
#unmute-btn::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 100px;
  background: conic-gradient(
    from 0deg,
    var(--accent),
    #a259ff,
    #ff4ecd,
    var(--accent)
  );
  z-index: -1;
  animation: spin-glow 3s linear infinite;
  opacity: 0.8;
}

/* Dark fill behind text so glow ring shows as border */
#unmute-btn::after {
  content: '';
  position: absolute;
  inset: 1.5px;
  border-radius: 100px;
  background: #111;
  z-index: -1;
}

@keyframes spin-glow {
  to { transform: rotate(360deg); }
}

/* Play icon */
#unmute-btn .btn-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
  font-size: 8px;
  padding-left: 2px; /* optical centre for triangle */
  color: #000;
}

#unmute-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: scale(1.03);
}

#unmute-btn:active {
  transform: scale(0.98);
}

/* ── Stream Grid ─────────────────────────────────────────────────── */
#stream-grid {
  flex: 1;
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
  overflow: hidden;
}

/* grid column/row counts set by JS via data attribute */
#stream-grid[data-count="1"]  { grid-template-columns: 1fr; grid-template-rows: 1fr; }
#stream-grid[data-count="2"]  { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
#stream-grid[data-count="3"]  { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
#stream-grid[data-count="4"]  { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
#stream-grid[data-count="5"]  { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
#stream-grid[data-count="6"]  { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
#stream-grid[data-count="7"]  { grid-template-columns: 1fr 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
#stream-grid[data-count="8"]  { grid-template-columns: 1fr 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
#stream-grid[data-count="9"]  { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; }

/* span first tile to fill gap when count is odd in a 2-col layout */
#stream-grid[data-count="3"] .stream-tile:first-child { grid-column: span 2; }

/* ── Stream Tile ─────────────────────────────────────────────────── */
.stream-tile {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  border: 2px solid transparent;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
}

.stream-tile.selected {
  border-color: var(--accent);
}

.stream-tile iframe {
  width: 100%;
  height: 100%;
  display: block;
}

/* click overlay — intercepts click for selection, then passes through */
.stream-tile .click-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.stream-tile.selected .click-overlay {
  /* selected tile: let iframe receive pointer events */
  pointer-events: none;
}

/* ── Channel label ───────────────────────────────────────────────── */
.stream-label {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  max-width: calc(100% - 48px); /* don't overlap remove btn */
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  color: rgba(255, 255, 255, 0.85);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  text-decoration: none;
  transition: opacity 0.2s, background 0.15s;
}

.stream-label:not(:empty) {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

.stream-label:hover {
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
}

/* ── Drag handle ─────────────────────────────────────────────────── */
.drag-handle {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.7);
  cursor: grab;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: auto;
}

.drag-handle svg {
  width: 16px;
  height: 16px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.8));
}

.stream-tile:hover .drag-handle { opacity: 1; }
.drag-handle:active { cursor: grabbing; }

/* Dragging state */
.stream-tile.dragging {
  opacity: 0.4;
  cursor: grabbing;
}

/* Drop target highlight */
.stream-tile.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

/* ── Remove button ───────────────────────────────────────────────── */
.remove-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 24px;
  height: 24px;
  padding: 0;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.stream-tile:hover .remove-btn { opacity: 1; }

/* ── Empty state ─────────────────────────────────────────────────── */
#empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
}

#empty-state p:first-child { font-size: 16px; font-weight: 600; }

/* ── History button ──────────────────────────────────────────────── */
#history-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  margin-left: auto;
}

#history-btn:hover {
  background: var(--border);
}

#history-btn.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

/* ── History panel ───────────────────────────────────────────────── */
#history-panel {
  position: fixed;
  top: var(--header-h);
  right: 0;
  width: 300px;
  height: calc(100dvh - var(--header-h));
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

#history-panel:not([hidden]) {
  display: flex;
  transform: translateX(0);
}

#history-panel[hidden] {
  display: flex;
  transform: translateX(100%);
  pointer-events: none;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  flex-shrink: 0;
}

#history-close-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#history-close-btn:hover {
  background: var(--border);
  color: var(--text);
}

#history-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}

#history-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  display: none;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  transition: background 0.1s;
}

.history-item:hover {
  background: rgba(255,255,255,0.04);
}

.history-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 3px;
  letter-spacing: 0.3px;
}

.history-badge.yt {
  background: #ff0000;
  color: #fff;
}

.history-badge.twitch {
  background: #9146ff;
  color: #fff;
}

.history-label {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-add-btn {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.history-add-btn:hover { background: var(--accent-hover); }

.history-remove-btn {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 50%;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-remove-btn:hover {
  background: var(--border);
  color: var(--text);
}
