:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232d;
  --line: #262e3a;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #3b82f6;
  --sidebar-w: 300px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* ------------------------------------------------------------- sidebar --- */

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.sidebar-head h1 {
  margin: 0;
  font-size: 13px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

#search, #group-filter {
  width: 100%;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
#search:focus, #group-filter:focus { border-color: var(--accent); }
#search::placeholder { color: var(--muted); }

.channel-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.channel-list::-webkit-scrollbar { width: 9px; }
.channel-list::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 5px;
}

.channel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  outline: none;
}
.channel:hover, .channel:focus-visible { background: var(--panel-2); }
.channel.active { background: var(--accent); }
.channel.active .channel-group { color: rgba(255,255,255,.8); }

.logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  flex: 0 0 34px;
  background: #0b0e13;
  border-radius: 5px;
}

.channel-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.channel-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-group {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-foot {
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

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

.stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.player-wrap {
  position: relative;
  flex: 1 1 auto;
  background: #000;
  min-height: 0;
}

/* Both players are stacked; only the one marked .is-live is visible.
   The hidden one is still decoding, which is what makes the swap instant. */
.player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}

.player.is-live {
  opacity: 1;
  pointer-events: auto;
  z-index: 2;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 13, .82);
  text-align: center;
  padding: 24px;
}
.overlay[hidden] { display: none; }

.overlay-inner { max-width: 420px; }

.overlay-title {
  margin: 12px 0 4px;
  font-size: 17px;
  font-weight: 600;
}

.overlay-sub {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

.spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}
.spinner[hidden] { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.5s; }
}

.retry {
  margin-top: 14px;
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 7px;
  font-size: 14px;
  cursor: pointer;
}
.retry[hidden] { display: none; }
.retry:hover { filter: brightness(1.1); }

.now-playing {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 14px;
  min-height: 44px;
}

.menu-btn {
  display: none;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 11px;
  font-size: 16px;
  cursor: pointer;
}

/* -------------------------------------------------------------- mobile --- */

@media (max-width: 700px) {
  .app { flex-direction: column; }

  .menu-btn { display: block; }

  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 10;
    width: 84%;
    max-width: 320px;
    flex: none;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.6);
  }
  .sidebar.open { transform: none; }

  .stage { height: 100%; }

  .player-wrap { flex: 0 0 auto; aspect-ratio: 16 / 9; }
}
