:root {
  --topbar-height: 64px;
  --bg0: #0b111d;
  --bg1: #111b2d;
  --panel: #172233;
  --panel-soft: #1a273a;
  --line: rgba(142, 170, 209, 0.22);
  --text: #e8eef9;
  --muted: #93a9cb;
  --accent: #ff4e45;
  --accent-alt: #2bd2c4;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Manrope", sans-serif;
  min-height: 100vh;
  background:
    radial-gradient(circle at 0 0, #1a2d4b 0%, transparent 30%),
    radial-gradient(circle at 100% 10%, #173943 0%, transparent 34%),
    linear-gradient(170deg, var(--bg0), var(--bg1));
  overflow: hidden;
  overflow-x: hidden;
}

.fx {
  position: fixed;
  pointer-events: none;
  filter: blur(72px);
  opacity: 0.25;
}

.fx-a { width: 260px; height: 260px; background: #2bd2c4; top: 50%; left: -100px; }
.fx-b { width: 220px; height: 220px; background: #ff6a5a; top: -90px; right: -50px; }

.topbar,
.app { position: relative; z-index: 1; }

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.9rem;
  align-items: center;
  min-height: var(--topbar-height);
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 16, 27, 0.85);
  backdrop-filter: blur(10px);
  z-index: 1000;
  overflow: visible;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-dot {
  width: 30px;
  height: 22px;
  border-radius: 7px;
  background: linear-gradient(120deg, #ff6459, #ff3e32);
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-family: "Bebas Neue", sans-serif;
  font-weight: 400;
  letter-spacing: 0.05em;
  font-size: clamp(1.3rem, 3vw, 2rem);
}

.toolbar {
  display: grid;
  grid-template-columns: auto;
  gap: 0.45rem;
  align-items: center;
  justify-content: end;
  position: relative;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  justify-content: end;
}

.field {
  display: grid;
  gap: 0.18rem;
  color: var(--muted);
  font-size: 0.7rem;
}

.field input,
.field select,
.text-input,
.btn {
  height: 2.2rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #101a2a;
  color: var(--text);
  font-family: inherit;
  padding: 0 0.85rem;
}

.field input { min-width: 180px; }

.btn {
  border: 0;
  cursor: pointer;
  font-weight: 800;
  background: linear-gradient(120deg, #ff5f55, #ff4036);
  white-space: nowrap;
}

.icon-btn {
  height: 2.2rem;
  width: 2.2rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #101a2a;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

.settings-panel {
  position: absolute;
  right: 0;
  top: 2.65rem;
  width: min(320px, 92vw);
  padding: 0.65rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(14, 23, 36, 0.96);
  display: none;
  gap: 0.55rem;
  z-index: 100;
}

.settings-panel.open {
  display: grid;
}

.genre-strip {
  position: relative;
  z-index: 2;
  padding: 0.5rem 1rem 0.2rem;
  background: transparent;
  backdrop-filter: none;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.stage-meta .genre-strip {
  padding: 0.38rem 0 0;
  width: 100%;
  max-width: 100%;
  position: relative;
  z-index: 1;
}

.settings-sync {
  width: 100%;
  border-radius: 10px;
}

.settings-secondary {
  width: 100%;
  border-radius: 10px;
  background: #203049;
}

.lang-checklist {
  max-height: 140px;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101a2a;
  padding: 0.3rem 0.35rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.2rem 0.55rem;
}

.lang-option {
  display: grid;
  grid-template-columns: 13px 1fr;
  align-items: center;
  gap: 0.28rem;
  font-size: 0.74rem;
  line-height: 1.1;
  color: var(--text);
  min-width: 0;
  width: 100%;
}

.lang-option input[type="checkbox"] {
  accent-color: #ff5f55;
  width: 13px;
  height: 13px;
  margin: 0;
}

.lang-text {
  display: block;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #dbe7ff;
  font-size: 0.74rem;
}

@media (max-width: 700px) {
  .lang-checklist {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1080px) and (orientation: landscape) {
  .stage {
    margin: 0;
    padding: 0;
  }

  #tvPlayer {
    height: 100vh;
  }

  .genre-strip,
  .stage-meta {
    display: none;
  }
}

@media (max-width: 1080px) {
  .mobile-landscape-mode .topbar {
    display: none;
  }

  .mobile-landscape-mode .app {
    margin-top: 0;
    height: 100dvh;
    gap: 0;
    overflow: hidden;
  }

  .mobile-landscape-mode .stage {
    position: fixed;
    inset: 0;
    z-index: 1200;
    margin: 0;
    padding: 0;
    background: #000;
  }

  .mobile-landscape-mode .video-shell {
    width: 100vw;
    height: 100dvh;
  }

  .mobile-landscape-mode #tvPlayer {
    width: 100vw;
    height: 100dvh;
    object-fit: contain;
    background: #000;
  }

  .mobile-landscape-mode .stage-meta,
  .mobile-landscape-mode .browser {
    display: none;
  }
}

.app {
  margin-top: var(--topbar-height);
  padding: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.9rem;
  position: relative;
  z-index: 1;
  height: calc(100vh - var(--topbar-height));
  height: calc(100dvh - var(--topbar-height));
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  min-width: 0;
  max-width: 100%;
}

.panel {
  background: rgba(23, 34, 51, 0.72);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.stage {
  padding: 0;
  margin: 0 -1rem;
  min-width: 0;
  max-width: 100%;
  position: relative;
  z-index: 1;
}

.stage.panel {
  border: 0;
  background: transparent;
}

.video-shell {
  position: relative;
  min-width: 0;
  max-width: 100%;
}

.live-badge {
  position: absolute;
  top: 0.7rem;
  left: 0.7rem;
  z-index: 3;
  padding: 0.2rem 0.48rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 98, 89, 0.9);
  background: rgba(160, 10, 18, 0.82);
  color: #fff4f3;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.live-badge.visible {
  opacity: 1;
  transform: translateY(0);
}

#tvPlayer {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: min(64vh, 56vw);
  border: 0;
  border-radius: 0;
  background: #000;
  object-fit: contain;
}

.stage-meta {
  margin-top: 0.55rem;
  padding: 0 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
}

.stage-meta > div:first-child {
  flex: 1;
  min-width: 0;
}

.stage-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
}

#nowPlaying {
  margin: 0;
  font-size: clamp(0.98rem, 2vw, 1.28rem);
  line-height: 1.3;
  flex: 1 1 auto;
  min-width: 0;
}

.meta-actions {
  display: flex;
  gap: 0.5rem;
}

.playlist-link {
  color: #ffd08b;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.8rem;
}

.browser {
  padding: 0.7rem;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: contain;
  min-width: 0;
  max-width: 100%;
}

.genre-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.12rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}

.genre-chips::-webkit-scrollbar {
  display: none;
}

.genre-chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #102139;
  color: #cfe0ff;
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  font-size: 0.74rem;
  white-space: nowrap;
  cursor: pointer;
}

.genre-chip.active {
  border-color: rgba(255, 95, 85, 0.8);
  background: rgba(255, 95, 85, 0.2);
  color: #ffe6e3;
}

.browser-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0.7rem 0 0.45rem;
}

.browser-title h3 {
  margin: 0;
  font-family: "Bebas Neue", sans-serif;
  letter-spacing: 0.06em;
  font-size: 1.2rem;
  font-weight: 400;
}

.browser-title p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.channel-list {
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  gap: 0.5rem;
  padding-right: 0.1rem;
  min-height: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  overscroll-behavior-y: contain;
}

.channel-list::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
  display: none !important;
  background: transparent !important;
}

.channel-list::-webkit-scrollbar-thumb,
.channel-list::-webkit-scrollbar-track {
  background: transparent !important;
}

.channel-card {
  border: 1px solid rgba(140, 166, 203, 0.2);
  border-radius: 12px;
  background: rgba(19, 30, 47, 0.96);
  cursor: pointer;
  text-align: left;
  padding: 0.45rem;
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 0.58rem;
  align-items: center;
  transform: translateY(8px);
  opacity: 0;
  animation: appear 0.25s ease forwards;
}

.channel-card:hover {
  border-color: rgba(255, 95, 85, 0.52);
}

.channel-card.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.channel-logo {
  width: 118px;
  height: 66px;
  object-fit: contain;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.channel-name {
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.channel-meta {
  margin-top: 0.24rem;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes appear {
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 1080px) {
  body {
    overflow-y: hidden;
    overflow-x: hidden;
  }

  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    grid-template-columns: 1fr auto;
    align-items: center;
    transition: transform 180ms ease, opacity 180ms ease;
  }

  .toolbar {
    grid-template-columns: auto;
    justify-content: end;
    align-items: center;
  }

  .toolbar-actions {
    gap: 0.4rem;
  }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: calc(100dvh - var(--topbar-height));
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    padding: 0;
    gap: 0.45rem;
    margin-top: var(--topbar-height);
    min-width: 0;
    max-width: 100%;
  }

  .mobile-header-hidden .topbar {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
  }

  .mobile-header-hidden .app {
    margin-top: 0;
    height: 100dvh;
  }

  .browser {
    min-height: 0;
    height: 100%;
    overflow: hidden;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  #tvPlayer {
    height: 40vh;
  }

  .genre-strip {
    padding: 0.42rem 0.7rem 0.3rem;
  }

  .mobile-home-btn {
    display: none;
  }

  .stage {
    position: relative;
    z-index: 1;
    margin: 0;
    padding: 0 0 0.45rem;
    background: rgba(10, 16, 27, 0.98);
    min-width: 0;
    max-width: 100%;
  }

  #tvPlayer {
    height: 33vh;
  }

  .mobile-square-card {
    border: 1px solid rgba(140, 166, 203, 0.28);
    border-radius: 8px;
    background: transparent;
    padding: 0;
    min-height: 0;
    height: 0;
    padding-bottom: 100%;
    position: relative;
    display: block;
    width: 100%;
    overflow: hidden;
    animation: none;
    opacity: 1;
    transform: none;
  }

  .mobile-square-card.active {
    border-color: rgba(255, 95, 85, 0.9);
    box-shadow: none;
  }

  .channel-icon-square {
    position: absolute;
    top: 50%;
    left: 50%;
    width: calc(100% - 0.36rem);
    height: calc(100% - 0.36rem);
    display: block;
    margin: 0;
    transform: translate(-50%, -50%);
    object-fit: contain;
    border-radius: 6px;
    background: transparent;
    padding: 0.08rem;
    image-rendering: auto;
    filter: none;
  }

  .browser-title {
    padding: 0 0.7rem;
    margin: 0.5rem 0 0.45rem;
  }

  .channel-list {
    gap: 0.22rem;
    padding-right: 0.2rem;
    padding-left: 0.2rem;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: unset;
    align-content: start;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 700px) {
  .toolbar {
    grid-template-columns: auto;
    justify-content: end;
  }

  .field input,
  .field select,
  .text-input,
  .btn {
    border-radius: 10px;
  }

  #tvPlayer {
    height: 31vh;
  }

  .channel-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.2rem;
    padding-left: 0.16rem;
    padding-right: 0.16rem;
  }
}
