:root {
  --accent: #4dabf7;
  --bg: #020617;
  --panel: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.12);
  --text: #eaeaea;
  --muted: #9aa4af;
  --surface: #111827;
  --muted-2: #1f2937;
}

/* Box-sizing reset */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: Arial, system-ui, sans-serif;
  background: radial-gradient(circle at top, var(--surface), var(--bg));
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  display: flex;
  flex-direction: row;
  height: calc(var(--vh, 1vh) * 100);
  min-height: 0;
}

/* Sidebar: keep a single authoritative width */
#sidebar {
  width: 320px;
  background: var(--surface);
  border-right: 1px solid var(--muted-2);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform 0.3s ease;
}

#controls {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Scope form controls to the controls area */
#controls input,
#controls select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--muted-2);
  color: var(--text);
  font-size: 14px;
}

.tabs {
  display: flex;
}

.tab-btn {
  flex: 1;
  padding: 12px 14px;
  background: var(--muted-2);
  border: none;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
}

.tab-content.active {
  display: block;
}

.channel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--muted-2);
  transition: background 0.18s ease;
  content-visibility: auto;
  contain-intrinsic-size: auto 62px;
}

.channel:hover,
.channel:focus-visible {
  background: rgba(255, 255, 255, 0.04);
  outline: none;
}

.channel:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.channel.active {
  background: rgba(37, 99, 235, 0.25);
}

.logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 6px;
}

.fav {
  margin-left: auto;
  font-size: 18px;
}

.fav.active {
  color: gold;
}

#player {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #000;
  overscroll-behavior: none;
  touch-action: pan-x;
}

/* Prefer the ID selector that matches markup */
#video {
  width: 100%;
  height: 100%;
  background: black;
  flex: 1 1 auto;
  min-height: 0;
}

#info {
  padding: 8px;
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--muted-2);
}

#info > div:not(#playerControls) {
  flex: 1;
  min-width: 0;
}

#playerControls {
  display: flex;
  gap: 8px;
  padding: 0;
  background: transparent;
  border: none;
  flex-shrink: 0;
}

#playerControls button {
  flex: 0 0 auto;
  padding: 6px 10px;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  transition:
    background 0.18s,
    transform 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#playerControls .player-download-btn {
  display: inline-flex;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.06);
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-decoration: none;
  transition: background 0.18s, border-color 0.18s, transform 0.12s;
}

#playerControls .player-download-btn:hover {
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.12);
}

#playerControls button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#playerControls .player-download-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#playerControls button:hover {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
}

/* Network Status Indicator */
#networkStatus {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 4px;
  text-align: center;
  display: none;
}

#networkStatus.offline {
  display: block;
  background: #d84a3f;
  color: white;
}

#networkStatus.online {
  display: block;
  background: #22863a;
  color: white;
}

/* PWA Install Modal */
.install-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.install-modal.show {
  display: flex;
}

.install-modal-content {
  background: var(--muted-2);
  border-radius: 12px;
  padding: 30px;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.install-modal-content h2 {
  margin-top: 0;
  color: #60a5fa;
  font-size: 22px;
}

.install-modal-content p {
  color: #d1d5db;
  line-height: 1.6;
  margin: 12px 0;
}

.install-modal-buttons {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.install-modal-buttons button {
  flex: 1;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.install-btn {
  background: var(--accent);
  color: white;
}

.cancel-btn {
  background: #374151;
  color: white;
}

.category-label {
  font-size: 12px;
  color: var(--muted-2);
  padding: 0 10px;
}

#menuBtn {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 999;
  background: var(--accent);
  border: none;
  color: white;
  padding: 10px;
  border-radius: 8px;
  display: none;
}

.menu-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  border: 0;
  background: rgba(2, 6, 14, 0.58);
}

.menu-backdrop.show {
  display: block;
}

/* Loading Indicator */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}

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

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--muted-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  position: absolute;
  bottom: 28%;
  color: var(--accent);
  font-size: 14px;
  text-align: center;
}

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

  #sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: min(85vh, 760px);
    height: min(calc(var(--vh, 1vh) * 85), 760px);
    max-height: calc(var(--vh, 1vh) * 85);
    overflow-y: auto;
    transform: translateY(100%);
    border-right: none;
    border-top: 1px solid var(--muted-2);
    z-index: 100;
  }

  #sidebar.open {
    transform: translateY(0);
  }

  #menuBtn {
    display: block;
  }

  /* On mobile, avoid forcing the video to full viewport height so the info bar sits below it */
  #video {
    height: auto;
    max-height: calc(var(--vh, 1vh) * 100 - 56px); /* reserve ~56px for #info */
    width: 100%;
  }

  .tabs {
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 10;
  }

}

/* Video Overlay Controls */
#video-overlay-controls {
  opacity: 0;
  transition: opacity 0.3s ease;
  position: absolute;
  top: 50%;
  left: 30px;
  right: 30px;
  transform: translateY(-50%);
  display: flex;
  justify-content: space-between;
  z-index: 10;
  pointer-events: none;
}
#player.controls-visible #video-overlay-controls {
  opacity: 1;
  pointer-events: auto;
}

@media (hover: hover) and (pointer: fine) {
  #player:hover #video-overlay-controls {
    opacity: 1;
    pointer-events: auto;
  }
}

#player:fullscreen,
#player:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

#player:fullscreen #video,
#player:-webkit-full-screen #video {
  width: 100%;
  height: 100%;
  max-height: none;
}

#player:fullscreen #info,
#player:-webkit-full-screen #info {
  display: none;
}

#video-overlay-controls button {
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  font-size: 24px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  justify-content: center;
  align-items: center;
}

#video-overlay-controls button:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* UI polish */
:root {
  color-scheme: dark;
  --accent: #38bdf8;
  --bg: #070b14;
  --panel: rgba(18, 27, 43, 0.88);
  --border: rgba(148, 163, 184, 0.14);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --surface: #0e1726;
  --muted-2: #172338;
}

body {
  background:
    radial-gradient(ellipse at 75% 0%, rgba(14, 116, 144, 0.12), transparent 42%),
    var(--bg);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#sidebar {
  flex: 0 0 340px;
  width: 340px;
  background: linear-gradient(180deg, #101b2c 0%, #0b1321 100%);
  border-right: 1px solid var(--border);
  box-shadow: 12px 0 36px rgba(0, 0, 0, 0.18);
  scrollbar-color: #334155 transparent;
  scrollbar-width: thin;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  padding-left: 2px;
  border: 1px solid rgba(56, 189, 248, 0.38);
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.24), rgba(14, 116, 144, 0.12));
  color: #7dd3fc;
  box-shadow: 0 5px 20px rgba(14, 165, 233, 0.12);
}

.brand-copy {
  display: grid;
  gap: 3px;
}

.brand-copy strong {
  color: var(--text);
  font-size: 13px;
  letter-spacing: 0.12em;
}

.brand-copy span {
  color: var(--muted);
  font-size: 12px;
}

#controls {
  padding: 16px 14px 13px;
  gap: 10px;
}

#controls input,
#controls select {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(5, 12, 23, 0.7);
  transition: border-color 0.18s ease, background 0.18s ease;
}

#controls input::placeholder {
  color: #718096;
}

#controls input:focus,
#controls select:focus {
  border-color: rgba(56, 189, 248, 0.65);
  background: #0a1423;
}

.category-label {
  padding: 2px 2px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tabs {
  gap: 6px;
  padding: 0 14px 12px;
  background: transparent;
}

.tab-btn {
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.tab-btn:hover {
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
}

.tab-btn.active {
  border-color: rgba(56, 189, 248, 0.2);
  background: rgba(14, 165, 233, 0.13);
  color: #7dd3fc;
}

.tab-content {
  scrollbar-color: #334155 transparent;
  scrollbar-width: thin;
}

.channel {
  min-height: 64px;
  gap: 12px;
  padding: 10px 14px;
  border-bottom-color: rgba(148, 163, 184, 0.08);
  color: #dbe5f1;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.channel:hover,
.channel:focus-visible {
  background: rgba(148, 163, 184, 0.07);
}

.channel.active {
  background: linear-gradient(90deg, rgba(14, 165, 233, 0.17), rgba(14, 165, 233, 0.04));
  box-shadow: inset 3px 0 #38bdf8;
  color: #f8fafc;
}

.channel-number {
  width: 30px;
  flex: 0 0 30px;
  color: #718096;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: center;
}

.channel.active .channel-number {
  color: #7dd3fc;
}

.logo {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  padding: 3px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
}

.fav {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border-radius: 9px;
  color: #718096;
  transition: color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.channel:hover .fav,
.fav.active {
  color: #fbbf24;
}

.channel:hover .fav {
  background: rgba(251, 191, 36, 0.1);
}

.channel:active .fav {
  transform: scale(0.92);
}

#player {
  min-width: 0;
  background:
    radial-gradient(ellipse at center, #101827 0%, #05080e 70%);
}

#playbackPrompt {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 12;
  padding: 13px 18px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(125, 211, 252, 0.42);
  border-radius: 999px;
  background: rgba(8, 18, 31, 0.88);
  color: #f1f5f9;
  font-weight: 700;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  backdrop-filter: blur(10px);
}

#playbackPrompt:hover {
  background: rgba(14, 116, 144, 0.9);
}

#playbackPrompt[hidden] {
  display: none;
}

#video {
  object-fit: contain;
}

#info {
  min-height: 64px;
  padding: 10px 18px;
  gap: 14px;
  border-top: 1px solid var(--border);
  background: rgba(10, 17, 29, 0.96);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.16);
}

#now {
  overflow: hidden;
  color: #f1f5f9;
  font-size: 14px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#status {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

#playerControls button {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.06);
}

#playerControls .player-download-btn {
  width: 38px;
  height: 38px;
}

#playerControls button:hover {
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.12);
}

#networkStatus {
  flex: 0 0 auto !important;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 650;
}

#networkStatus.online {
  border-color: rgba(34, 197, 94, 0.25);
  background: rgba(34, 197, 94, 0.1);
  color: #86efac;
}

#networkStatus.offline {
  border-color: rgba(248, 113, 113, 0.25);
  background: rgba(248, 113, 113, 0.1);
  color: #fca5a5;
}

#menuBtn {
  border: 1px solid rgba(125, 211, 252, 0.3);
  border-radius: 12px;
  background: rgba(8, 18, 31, 0.9);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  font-weight: 650;
  backdrop-filter: blur(12px);
}

#video-overlay-controls button {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(8, 15, 25, 0.68);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
}

#video-overlay-controls button:hover {
  background: rgba(14, 165, 233, 0.72);
}

.install-modal {
  padding: 20px;
  background: rgba(2, 6, 14, 0.76);
  backdrop-filter: blur(8px);
}

.install-modal-content {
  width: min(100%, 420px);
  border: 1px solid var(--border);
  background: linear-gradient(145deg, #172338, #0e1726);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.install-btn,
.cancel-btn,
.install-modal-buttons button {
  transition: transform 0.16s ease, filter 0.16s ease;
}

.install-modal-buttons button:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

@media (max-width: 768px) {
  #sidebar {
    width: 100%;
    height: min(85vh, 760px);
    height: min(calc(var(--vh, 1vh) * 85), 760px);
    max-height: calc(var(--vh, 1vh) * 85);
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.45);
  }

  .brand {
    padding: 16px 18px 13px;
  }

  .tabs {
    top: 0;
    padding-top: 8px;
    border-bottom: 1px solid var(--border);
  }

  #menuBtn {
    top: 12px;
    left: 12px;
    padding: 10px 13px;
  }

  #info {
    min-height: 60px;
    padding: 8px 12px;
    gap: 8px;
  }

  #networkStatus {
    padding: 5px 7px;
    font-size: 10px;
  }

  #now {
    font-size: 12px;
  }

  #status {
    font-size: 10px;
  }

  #video-overlay-controls {
    left: 14px;
    right: 14px;
  }

  #video-overlay-controls button {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  .app {
    height: 100vh;
    height: 100dvh;
  }

  #player {
    position: fixed;
    inset: 0;
    z-index: 0;
  }

  #video {
    width: 100%;
    height: 100%;
    max-height: none;
  }

  #info {
    display: none;
  }

  #sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    padding-top: 58px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(100%);
    border: 0;
    border-radius: 0;
    z-index: 100;
  }

  #sidebar.open {
    transform: translateY(0);
  }

  #sidebar .brand {
    flex: 0 0 auto;
    padding: 8px 14px;
  }

  #sidebar .brand-mark {
    width: 34px;
    height: 34px;
  }

  #controls {
    display: grid;
    flex: 0 0 auto;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
  }

  .category-label {
    display: none;
  }

  #controls input,
  #controls select {
    min-width: 0;
    min-height: 38px;
    padding: 8px;
  }

  .tabs {
    flex: 0 0 auto;
    padding: 0 12px 8px;
  }

  .tab-btn {
    min-height: 38px;
    padding: 8px;
  }

  .tab-content,
  .tab-content.active {
    min-height: 0;
    overscroll-behavior: contain;
  }

  #menuBtn {
    display: block;
  }

  #video-overlay-controls {
    left: 14px;
    right: 14px;
  }
}

@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;
  }
}
