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

/* ── Utility ────────────────────────────────── */
.hidden { display: none !important; }

/* ── Tokens ─────────────────────────────────── */
:root {
  /* Core dark background (terminal-style) */
  --bg:        #0a0c0f;
  --surface:   #0e1116;
  --surface2:  #141820;
  --surface3:  #1a2030;
  --border:    rgba(0,255,136,0.08);
  --border2:   rgba(0,255,136,0.16);

  /* Text */
  --text:      #e2e8f0;
  --text2:     #64748b;
  --text3:     #334155;

  /* Green accent (Linux terminal green) */
  --accent:    #00e676;
  --accent-dim: #00b85a;
  --accent-bg: rgba(0,230,118,0.08);
  --accent-glow: rgba(0,230,118,0.25);

  /* Status */
  --red:       #ff4757;
  --orange:    #ff9f43;

  /* Layout */
  --sidebar-w: 264px;
  --chat-w:    340px;
  --bar-h:     52px;
  --radius:    4px;
  --ease:      cubic-bezier(0.4, 0, 0.2, 1);

  /* Mono font for terminal feel */
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-ui:   'Inter', system-ui, sans-serif;
}

/* ── Base ────────────────────────────────── */
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 99px; }

/* ── Scanline overlay (subtle CRT effect) ─── */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.03) 2px,
    rgba(0,0,0,0.03) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* ── Top Bar ─────────────────────────────── */
.topbar {
  height: var(--bar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  user-select: none;
  position: relative;
}

/* Subtle green glow on topbar bottom border */
.topbar::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-glow), transparent);
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.88rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  white-space: nowrap;
  text-shadow: 0 0 12px var(--accent-glow);
}

.logo-mark {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(0,230,118,0.3));
}

.logo-text { color: var(--accent); }

.logo-blink {
  animation: termBlink 1.2s step-end infinite;
  color: var(--accent);
}

@keyframes termBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.sep {
  width: 1px;
  height: 20px;
  background: var(--border2);
  flex-shrink: 0;
}

.now-playing {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 1px solid rgba(255,71,87,0.5);
  color: var(--red);
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 3px;
  flex-shrink: 0;
  text-shadow: 0 0 8px rgba(255,71,87,0.5);
}

.live-dot {
  width: 5px; height: 5px;
  background: var(--red);
  border-radius: 50%;
  animation: blink 1.6s ease-in-out infinite;
  box-shadow: 0 0 6px var(--red);
}

@keyframes blink { 0%,100% { opacity:1 } 50% { opacity:0.3 } }

.np-name {
  font-size: 0.8rem;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.np-name strong {
  color: var(--text);
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bar-btn {
  width: 34px; height: 34px;
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--text2);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s;
  flex-shrink: 0;
}

.bar-btn:hover {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent-dim);
}

.bar-btn.on {
  background: var(--accent-bg);
  border-color: var(--accent-dim);
  color: var(--accent);
}

/* ── Layout ─────────────────────────────── */
.app {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.22s var(--ease);
  overflow: hidden;
  position: relative;
}

.sidebar.closed { width: 0; border-right: none; }

/* Green accent line on sidebar right edge */
.sidebar::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 1px;
  background: linear-gradient(to bottom, transparent, var(--accent-glow) 40%, var(--accent-glow) 60%, transparent);
  pointer-events: none;
}

.sidebar-header {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-title {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-title svg { opacity: 0.7; }

.channel-count {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text3);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 10px;
}

.sidebar-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-wrap svg {
  position: absolute;
  left: 9px;
  color: var(--text3);
  pointer-events: none;
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  padding: 7px 10px 7px 30px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input::placeholder { color: var(--text3); }
.search-input:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 2px rgba(0,230,118,0.08);
}

/* Remove default search clear button on Chrome */
.search-input::-webkit-search-cancel-button { display: none; }

.ch-scroll { flex: 1; overflow-y: auto; padding: 4px 0 12px; }

.cat-label {
  padding: 14px 14px 6px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.cat-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.ch-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.12s;
  position: relative;
  border-left: 2px solid transparent;
}

.ch-item:hover { background: var(--surface2); }

.ch-item.active {
  background: var(--accent-bg);
  border-left-color: var(--accent);
}

.ch-avatar {
  width: 34px; height: 34px;
  border-radius: 6px;
  background: var(--surface3);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  overflow: hidden;
}

.ch-avatar img { width: 100%; height: 100%; object-fit: cover; }

.ch-info { flex: 1; min-width: 0; }

.ch-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ch-item.active .ch-name { color: var(--accent); }

.ch-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}

.q-badge {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 1px 5px;
  border-radius: 2px;
  text-transform: uppercase;
}

.q-badge.fhd { color: var(--accent); background: rgba(0,230,118,0.1); border: 1px solid rgba(0,230,118,0.2); }
.q-badge.hd  { color: #38bdf8; background: rgba(56,189,248,0.1); border: 1px solid rgba(56,189,248,0.2); }
.q-badge.sd  { color: var(--orange); background: rgba(255,159,67,0.1); border: 1px solid rgba(255,159,67,0.2); }

.ch-live-dot {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--text3);
}

.ch-item.active .ch-live-dot {
  background: var(--accent);
  box-shadow: 0 0 4px var(--accent);
  animation: blink 1.6s ease-in-out infinite;
}

/* ── Stage ─────────────────────────────── */
.stage {
  flex: 1;
  background: #000;
  position: relative;
  min-width: 0;
  overflow: hidden;
  cursor: default;
}

.stage.idle { cursor: none; }

#player {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}

/* ── Floating Control Bar ─────────────────────────── */
.ctrl-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 40px 20px 18px;
  background: linear-gradient(to top, rgba(0,0,0,0.82) 0%, rgba(0,0,0,0.4) 60%, transparent 100%);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 5;
  transition: opacity 0.35s var(--ease), transform 0.35s var(--ease);
}

.stage.idle .ctrl-bar {
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
}

.ctrl-btn {
  width: 36px; height: 36px;
  border: none;
  background: transparent;
  color: var(--text2);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.ctrl-btn:hover { color: var(--accent); background: var(--accent-bg); }

.ctrl-live-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px solid rgba(255,71,87,0.4);
  background: transparent;
  border-radius: 3px;
  color: var(--red);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}

.ctrl-live-btn:hover {
  background: rgba(255,71,87,0.1);
  box-shadow: 0 0 8px rgba(255,71,87,0.2);
}

.ctrl-live-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1.6s infinite;
  box-shadow: 0 0 5px var(--red);
}

/* Volume */
.vol-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.vol-slider {
  -webkit-appearance: none;
  width: 72px;
  height: 3px;
  border-radius: 99px;
  background: var(--surface3);
  outline: none;
  cursor: pointer;
  accent-color: var(--accent);
}

.vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.vol-slider:hover::-webkit-slider-thumb {
  transform: scale(1.2);
  box-shadow: 0 0 8px var(--accent-glow);
}

.ctrl-spacer { flex: 1; }

.ctrl-channel-name {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent-dim);
  font-weight: 400;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Player State Overlays ─────────────────────────── */
.state-overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0,0,0,0.88);
  z-index: 10;
  backdrop-filter: blur(2px);
}

.state-overlay.show { display: flex; }

/* Terminal-style loader */
.terminal-loader {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 14px 20px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-glow);
  animation: termFade 1.5s ease-in-out infinite alternate;
}

.tl-line { display: flex; align-items: center; gap: 2px; }

.tl-cursor {
  animation: termBlink 0.8s step-end infinite;
  color: var(--accent);
}

@keyframes termFade {
  from { opacity: 0.7; }
  to   { opacity: 1; }
}

/* Error */
.err-overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg);
  z-index: 11;
}

.err-overlay.show { display: flex; }

.err-icon { font-size: 32px; opacity: 0.4; }

.err-title {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text2);
}

.err-sub {
  font-size: 0.75rem;
  color: var(--text3);
  text-align: center;
  max-width: 280px;
  line-height: 1.6;
  font-family: var(--font-mono);
}

.retry-btn {
  margin-top: 6px;
  padding: 8px 20px;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}

.retry-btn:hover {
  background: var(--accent-bg);
  box-shadow: 0 0 12px var(--accent-glow);
}

/* ── Chat Panel ─────────────────────────────── */
.chat {
  width: var(--chat-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.22s var(--ease);
  overflow: hidden;
}

.chat.closed { width: 0; border-left: none; }

.chat-head {
  height: var(--bar-h);
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.05em;
}

.chat-live {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text3);
}

.chat-live-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 5px var(--accent);
}

.chat-body { flex: 1; overflow: hidden; }
.chat-body iframe { display: block; width: 100%; height: 100%; border: none; }

/* ── Toast ─────────────────────────────── */
.toasts {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 999;
  pointer-events: none;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 9px 16px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  white-space: nowrap;
  animation: tIn 0.2s var(--ease) both;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4), 0 0 12px rgba(0,230,118,0.1);
}

.toast.out { animation: tOut 0.2s var(--ease) both; }

@keyframes tIn  { from { opacity:0; transform:translateY(6px) } to { opacity:1; transform:none } }
@keyframes tOut { to   { opacity:0; transform:translateY(6px) } }

/* ── Category icon ─────────────────────────── */
.cat-icon {
  font-size: 0.75rem;
  margin-right: 2px;
}

/* ── Channel avatar initials ─────────────── */
.ch-initials {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--accent);
}

/* ── Sidebar no-result ─────────────────────────────── */
.no-results {
  padding: 24px 14px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text3);
  text-align: center;
  display: none;
}

/* ══════════════════════════════════════════
   RESPONSIVE — TABLET (≤ 900px)
   ══════════════════════════════════════════ */
@media (max-width: 900px) {
  :root {
    --sidebar-w: 240px;
    --chat-w: 280px;
  }

  .ctrl-channel-name { display: none; }

  /* Hide vol slider, keep mute button */
  .vol-slider { width: 56px; }
}

/* ══════════════════════════════════════════
   RESPONSIVE — MOBILE (≤ 768px)
   ══════════════════════════════════════════ */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 100vw;
    --chat-w: 100vw;
    --bar-h: 48px;
  }

  /* Sidebar slides over video (overlay mode) */
  .sidebar {
    position: fixed;
    top: var(--bar-h);
    left: 0;
    bottom: 0;
    z-index: 200;
    width: var(--sidebar-w);
    transform: translateX(0);
    transition: transform 0.25s var(--ease), width 0s;
    border-right: none;
    box-shadow: 4px 0 24px rgba(0,0,0,0.6);
  }

  .sidebar.closed {
    transform: translateX(-100%);
    width: var(--sidebar-w); /* keep width so transition works */
    box-shadow: none;
  }

  /* Chat also overlays from the right */
  .chat {
    position: fixed;
    top: var(--bar-h);
    right: 0;
    bottom: 0;
    z-index: 200;
    width: var(--chat-w);
    transform: translateX(0);
    transition: transform 0.25s var(--ease), width 0s;
    border-left: none;
    box-shadow: -4px 0 24px rgba(0,0,0,0.6);
  }

  .chat.closed {
    transform: translateX(100%);
    width: var(--chat-w);
    box-shadow: none;
  }

  .ctrl-bar {
    padding: 24px 12px 12px;
    gap: 8px;
  }

  .ctrl-channel-name { display: none; }

  /* Vol slider shorter on mobile */
  .vol-slider { width: 52px; }

  /* Logo branding compact */
  .logo-text { font-size: 0.82rem; }

  /* Now playing shorter */
  .np-name { font-size: 0.72rem; }

  /* Scanlines too heavy on small screens */
  body::after { display: none; }

  /* Toast above ctrl bar */
  .toasts { bottom: 64px; }
}

/* ══════════════════════════════════════════
   RESPONSIVE — SMALL PHONE (≤ 480px)
   ══════════════════════════════════════════ */
@media (max-width: 480px) {
  .now-playing { display: none; }

  .topbar { gap: 8px; }

  .vol-wrap { display: none; }

  .ctrl-bar { padding: 0 8px; gap: 6px; }
}

