:root {
  color-scheme: dark;
  --bg: #08090d;
  --surface: #111319;
  --surface-2: #181b23;
  --surface-3: #222631;
  --text: #f4f6fb;
  --muted: #979daa;
  --line: rgba(255, 255, 255, 0.09);
  --accent: #ff335f;
  --accent-soft: rgba(255, 51, 95, 0.14);
  --success: #31d07f;
  --danger: #ff5c72;
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% -10%, rgba(255, 51, 95, 0.14), transparent 32rem),
    var(--bg);
  color: var(--text);
  overflow: hidden;
}

button, input, select { font: inherit; }
button { color: inherit; }

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: 70px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 9, 13, 0.86);
  backdrop-filter: blur(18px);
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, #ff5075, #c71543);
  box-shadow: 0 8px 25px rgba(255, 51, 95, 0.24);
  font-weight: 900;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: 0.01em; }
.brand small { color: var(--muted); font-size: 12px; margin-top: 2px; }

.layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
}

.player-panel {
  min-width: 0;
  overflow-y: auto;
  padding: clamp(16px, 2.2vw, 32px);
}

.video-frame {
  position: relative;
  width: 100%;
  max-height: calc(100dvh - 220px);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000;
  border: 1px solid var(--line);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.38);
}

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

.player-empty,
.loading-overlay,
.error-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(circle at center, #1b1e27 0, #090a0e 72%);
}

.player-empty h1 { margin: 18px 0 7px; font-size: clamp(22px, 3vw, 34px); }
.player-empty p { margin: 0; color: var(--muted); }
.empty-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  padding-left: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 24px;
}

.loading-overlay { background: rgba(0, 0, 0, 0.68); gap: 14px; }
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-overlay { background: rgba(8, 9, 13, 0.9); gap: 9px; }
.error-overlay strong { font-size: 20px; }
.error-overlay span { color: var(--muted); max-width: 520px; }
.error-overlay button,
.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface-3);
  border-radius: 11px;
  padding: 10px 14px;
  cursor: pointer;
}
.error-overlay button { margin-top: 9px; background: var(--accent); border-color: transparent; font-weight: 700; }

.now-playing {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 2px 14px;
}

.channel-avatar {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 12px;
  background: linear-gradient(145deg, #2d3240, #171a22);
  border: 1px solid var(--line);
  color: #dfe3ec;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
}
.channel-avatar.large { width: 54px; height: 54px; border-radius: 15px; font-size: 14px; }
.channel-avatar img { width: 100%; height: 100%; object-fit: contain; background: white; }

.now-details { min-width: 0; flex: 1; }
.eyebrow { display: block; color: var(--accent); font-weight: 800; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; }
.now-details h2 { margin: 4px 0 3px; font-size: clamp(19px, 2.2vw, 26px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-details p { margin: 0; color: var(--muted); font-size: 13px; }

.player-actions { display: flex; align-items: center; gap: 9px; }
.quality-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
select {
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 30px 9px 10px;
  outline: none;
}
select:disabled, button:disabled { opacity: 0.45; cursor: not-allowed; }

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
}
.icon-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button.active { color: #ffd261; background: rgba(255, 210, 97, 0.12); }
.icon-button.active svg { fill: currentColor; }

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  padding: 0 3px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #707683; }
.status-dot.loading { background: #f2b84b; box-shadow: 0 0 0 4px rgba(242, 184, 75, 0.1); }
.status-dot.live { background: var(--success); box-shadow: 0 0 0 4px rgba(49, 208, 127, 0.1); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 4px rgba(255, 92, 114, 0.1); }

.channels-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border-left: 1px solid var(--line);
  background: rgba(17, 19, 25, 0.76);
}
.channels-header { padding: 16px; border-bottom: 1px solid var(--line); }
.search-box { position: relative; }
.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
}
.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  padding: 12px 12px 12px 40px;
}
.search-box input:focus { border-color: rgba(255, 51, 95, 0.6); box-shadow: 0 0 0 3px var(--accent-soft); }

.group-tabs {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-top: 12px;
}
.group-tabs::-webkit-scrollbar { display: none; }
.group-tab {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 7px 11px;
  font-size: 12px;
  cursor: pointer;
}
.group-tab.active { color: white; background: var(--accent-soft); border-color: rgba(255, 51, 95, 0.32); }

.channel-list {
  min-height: 0;
  overflow-y: auto;
  padding: 9px;
  padding-bottom: calc(12px + var(--safe-bottom));
}
.channel-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 9px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.channel-item:hover { background: rgba(255, 255, 255, 0.04); }
.channel-item.active { background: var(--accent-soft); border-color: rgba(255, 51, 95, 0.22); }
.channel-meta { min-width: 0; flex: 1; }
.channel-meta strong, .channel-meta small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-meta strong { font-size: 13px; }
.channel-meta small { color: var(--muted); margin-top: 4px; font-size: 11px; }
.favorite-badge { color: #ffd261; font-size: 15px; }
.playing-bars { display: inline-flex; gap: 2px; align-items: end; height: 14px; }
.playing-bars i { width: 2px; background: var(--accent); animation: bars 0.8s ease-in-out infinite alternate; }
.playing-bars i:nth-child(1) { height: 7px; }
.playing-bars i:nth-child(2) { height: 13px; animation-delay: -0.3s; }
.playing-bars i:nth-child(3) { height: 9px; animation-delay: -0.5s; }
@keyframes bars { to { height: 3px; } }

.list-empty { padding: 34px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.mobile-only { display: none; }

@media (max-width: 900px) {
  body { overflow: auto; }
  .app-shell { min-height: 100dvh; }
  .mobile-only { display: inline-grid; }
  .layout { display: block; }
  .player-panel { padding: 12px; overflow: visible; }
  .video-frame { max-height: none; border-radius: 14px; }
  .now-playing { align-items: flex-start; flex-wrap: wrap; }
  .now-details { min-width: calc(100% - 70px); }
  .player-actions { width: 100%; padding-left: 68px; flex-wrap: wrap; }
  .channels-panel {
    position: fixed;
    z-index: 30;
    top: 70px;
    right: 0;
    bottom: 0;
    width: min(92vw, 390px);
    transform: translateX(102%);
    transition: transform 180ms ease;
    box-shadow: -20px 0 60px rgba(0, 0, 0, 0.5);
    border-left: 1px solid var(--line);
  }
  .channels-panel.open { transform: translateX(0); }
}

@media (max-width: 520px) {
  .topbar { height: 62px; padding: 0 12px; }
  .channels-panel { top: 62px; }
  .player-panel { padding: 8px; }
  .video-frame { border-radius: 11px; }
  .now-playing { padding: 14px 3px 11px; gap: 10px; }
  .channel-avatar.large { width: 46px; height: 46px; border-radius: 12px; }
  .now-details { min-width: calc(100% - 58px); }
  .now-details h2 { font-size: 19px; }
  .player-actions { padding-left: 0; }
  .quality-control span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
