:root {
  --bg: #0b0e14;
  --bg-elev: #131826;
  --bg-elev2: #1b2233;
  --bg-elev3: #242e44;
  --text: #e8ecf4;
  --text-dim: #9aa4bd;
  --text-faint: #6b7590;
  --accent: #e50914;
  --accent-hi: #ff3b45;
  --accent2: #7b2ff7;
  --focus: #fff;
  --focus-border: 3px solid var(--focus);
  --radius: 12px;
  --card-w: 176px;
  --card-h: 264px;
  --gap: 14px;
  --row-h: 316px;
  --shadow: 0 10px 30px rgba(0,0,0,.5);
  --ok: #2fbf71;
  --warn: #f0a832;
  --err: #ff4d5e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

html, body { height: 100%; -webkit-tap-highlight-color: transparent; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#app { flex: 1 0 auto; }

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  tap-highlight-color: transparent;
}

img { display: block; }
input, select, textarea {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--bg-elev2);
  border: 1px solid #2c3752;
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(180deg, rgba(11,14,20,.96) 0%, rgba(11,14,20,.85) 70%, rgba(11,14,20,0) 100%);
  transition: background .3s;
}
/* Safe area for installed PWAs only: push the hamburger/brand below the
   system status bar on mobile (iPhone notch / Android camera punch-hole).
   Normal browser mobile view is not affected. */
@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui) {
  .topbar { padding-top: env(safe-area-inset-top); }
}
/* Desktop / big screens: truly fixed bar (sticky is unreliable with
   body overflow-x hidden). The app content gets matching top padding. */
@media (min-width: 901px) {
  .topbar { position: fixed; left: 0; right: 0; }
  .app { padding-top: 66px; }
  .focusable { scroll-margin-top: 76px; }
}
.topbar.scrolled { background: rgba(11,14,20,.98); }
.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
}
.brand {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--accent);
  margin-right: 8px;
  padding: 6px 10px;
  border-radius: 8px;
}
.topnav { display: flex; gap: 2px; flex: 1; }
#btnMenu { display: none; }
.nav-link {
  padding: 9px 14px;
  border-radius: 8px;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  transition: color .2s;
}
.nav-link:hover { color: var(--text); }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text);
  flex-shrink: 0;
}

.mobile-menu {
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-bottom: 1px solid #223;
  padding: 8px;
  gap: 4px;
}
.mobile-menu .nav-link { text-align: left; font-size: 17px; padding: 12px 16px; }

/* ---------- Layout / pages ---------- */
.app { padding-bottom: 60px; }
.page { max-width: 1440px; margin: 0 auto; padding: 0 20px; }

.section { margin-top: 34px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
/* Combined back-button + title row (live & category pages). Keeps the back
   arrow and the title on one line instead of stacking them on mobile. */
.page-head { gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.page-head-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1 1 auto;
}
.page-head-left .back-btn { margin: 0; }
.page-head-left .section-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-head-action { flex-shrink: 0; }
.section-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: .3px;
}
.section-title a { color: inherit; text-decoration: none; }
.section-sub {
  margin: -8px 0 14px;
  font-size: 13px;
  color: var(--muted, #9aa3b5);
}

/* ---------- Hero ---------- */
.hero {
  position: relative;
  min-height: 380px;
  display: flex;
  align-items: flex-end;
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 10px;
  background: linear-gradient(160deg, #1a2136, #0b0e14);
}
.hero-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-size: cover;
  background-position: center 20%;
  opacity: .45;
}
.hero-bg::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, rgba(11,14,20,.92) 0%, rgba(11,14,20,.55) 45%, rgba(11,14,20,.25) 100%),
              linear-gradient(0deg, var(--bg) 0%, transparent 60%);
}
.hero-bg img {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.hero-bg .poster-fallback { position: absolute; top: 0;
  left: 0;
  right: 0;
  bottom: 0; display: flex; align-items: center; justify-content: center; font-size: 60px; color: var(--text-faint); opacity: .4; }
.hero-body { position: relative; padding: 30px; max-width: 640px; }
.hero-title { font-size: 42px; font-weight: 900; margin-bottom: 8px; text-shadow: 0 2px 12px rgba(0,0,0,.7); }
.hero-meta { color: var(--text-dim); margin-bottom: 10px; }
.hero-desc {
  color: var(--text-dim);
  margin-bottom: 18px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 16px;
  transition: transform .12s, background .2s, box-shadow .2s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hi); }
.btn-secondary { background: var(--bg-elev3); color: var(--text); }
.btn-secondary:hover { background: #2d3852; }
.btn-ghost { background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.25); }
.btn-ghost:hover { background: rgba(255,255,255,.2); }
.btn-danger { background: transparent; color: var(--err); border: 1px solid var(--err); }
.btn-danger:hover { background: rgba(255,77,94,.12); }
.btn-ok { background: var(--ok); color: #fff; border: 1px solid var(--ok); }
.btn-sm { padding: 8px 14px; font-size: 14px; }

/* ---------- Rows & cards ---------- */
.row {
  position: relative;
  display: flex;
  gap: var(--gap);
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 4px 14px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-elev3) transparent;
}
.row::-webkit-scrollbar { height: 8px; }
.row::-webkit-scrollbar-thumb { background: var(--bg-elev3); border-radius: 4px; }
.row::-webkit-scrollbar-track { background: transparent; }

.card {
  flex: 0 0 auto;
  width: var(--card-w);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elev);
  position: relative;
  outline: none;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
  -webkit-tap-highlight-color: transparent;
}
.card:hover { transform: translateY(-4px); }

.card-poster {
  width: var(--card-w);
  height: var(--card-h);
  background: var(--bg-elev2);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-poster img { width: 100%; height: 100%; object-fit: cover; }
.card-poster .poster-fallback {
  font-size: 60px;
  color: var(--text-faint);
  opacity: .5;
}
.card-body { padding: 10px 10px 12px; }
.card-title {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-sub {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 4px;
  background: rgba(255,255,255,.15);
}
.card-progress .bar { height: 100%; background: var(--accent); }

.card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,.72);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: .5px;
}
.card-badge.watched { background: var(--accent); }
.badge-type {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent2);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 1px;
}
.badge-type.direct { background: #0e7a4a; }
.badge-type.embed { background: var(--accent2); }

/* progress on card */
.card-progress-wrap {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 5px;
  background: rgba(255,255,255,.14);
}
.card-progress-wrap .pbar { height: 100%; background: var(--accent); }

/* grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-w), 1fr));
  gap: var(--gap);
  padding: 8px 4px 20px;
}
.grid .card { width: 100%; }
.grid .card-poster, .grid .card-poster img { width: 100%; height: auto; aspect-ratio: 2/3; }

/* category cards (landscape banner look, same card language) */
.category-card .card-poster {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
}
.category-card .card-poster .poster-fallback {
  font-size: 42px;
  opacity: .6;
}
.category-card .card-title {
  font-size: 16px;
}
.grid .category-card { width: 100%; }
.grid .category-card .card-poster,
.grid .category-card .card-poster img { width: 100%; height: auto; aspect-ratio: 16 / 10; }

/* load more / pagination */
.load-more {
  display: block;
  margin: 6px auto 26px;
}
.section-link {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
}
.section-link:hover { text-decoration: underline; }
.search-more {
  color: var(--text-faint);
  font-size: 13px;
  padding: 10px 4px;
}

/* ---------- History page remove button ---------- */
.history-card-wrap {
  position: relative;
  width: 100%;
}
.history-card-wrap .card {
  width: 100%;
}
.history-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  left: auto;
  z-index: 10;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.72);
  color: #fff;
  font-size: 0;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  border: 1px solid rgba(255,255,255,.18);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity .15s ease, background .15s ease, transform .1s ease;
}
.history-card-wrap:hover .history-remove,
.history-card-wrap:focus-within .history-remove,
.history-card-wrap .history-remove.focused,
.history-card-wrap .history-remove.spatial-focus,
.history-remove:hover,
.history-remove:focus-visible {
  opacity: 1;
  visibility: visible;
}
.history-remove:hover,
.history-remove:focus-visible {
  background: var(--err);
  color: #fff;
}
.history-remove:active { transform: scale(.92); }

/* Mobile / touch / small screens: hamburger menu is visible (max-width: 900px),
   so always show the remove button so it can be tapped. */
@media (max-width: 900px), (pointer: coarse) {
  .history-remove {
    opacity: .78;
    visibility: visible;
  }
}

/* ---------- Focus ring (Smart TV / keyboard) ---------- */
.focusable {
  outline: none;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  tap-highlight-color: transparent;
}
.focusable:focus-visible,
.focusable.focused,
.spatial-focus {
  outline: var(--focus-border) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 6px rgba(255,255,255,.18) !important;
}
.spatial-focus { z-index: 5; }

/* On touch/pointer devices the spatial focus ring and native :focus-visible
   outlines must be completely hidden, even if the browser heuristic or a
   direct .focus() call would otherwise show one. The data-input-mode attribute
   is set by navigation.js on first load. */
[data-input-mode="pointer"] .focusable:focus-visible,
[data-input-mode="pointer"] .focusable.focused,
[data-input-mode="pointer"] .spatial-focus {
  outline: none !important;
  box-shadow: none !important;
}

/* ---------- Details / series pages ---------- */
.detail-backdrop { min-height: 320px; }
.detail-header {
  display: flex;
  gap: 28px;
  margin-top: -120px;
  position: relative;
  z-index: 2;
  padding-bottom: 10px;
}
.detail-poster {
  width: 220px;
  aspect-ratio: 2/3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elev2);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.detail-poster img { width: 100%; height: 100%; object-fit: cover; }
.detail-poster .poster-fallback { font-size: 70px; color: var(--text-faint); opacity: .5; }
.detail-info { padding-top: 60px; flex: 1; min-width: 0; }
.detail-title { font-size: 38px; font-weight: 900; }
.detail-meta { color: var(--text-dim); margin: 6px 0 12px; display: flex; gap: 14px; flex-wrap: wrap; }
.detail-meta .dot { color: var(--text-faint); }
.detail-desc { color: var(--text-dim); max-width: 760px; margin-bottom: 18px; }
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.tag-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 4px; }
.tag {
  background: var(--bg-elev2);
  border: 1px solid #2c3752;
  color: var(--text-dim);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 16px 0;
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--text-dim);
  font-weight: 600;
}
.back-btn:hover { color: var(--text); background: var(--bg-elev); }

/* season selector */
.season-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.season-pill {
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--bg-elev2);
  color: var(--text-dim);
  font-weight: 700;
  border: 1px solid transparent;
}
.season-pill.active { background: var(--accent); color: #fff; }

.episode-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 900px;
}
.episode {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elev);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
  transition: background .15s;
}
.episode:hover { background: var(--bg-elev2); }
.episode-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  background: none;
  border: none;
  padding: 2px 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.episode-edit { flex-shrink: 0; white-space: nowrap; }
.episode-thumb {
  position: relative;
  width: 120px;
  aspect-ratio: 16/9;
  border-radius: 8px;
  background: var(--bg-elev2);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-faint);
  overflow: hidden;
}
.episode-thumb img {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.episode-thumb .poster-fallback { font-size: 20px; opacity: .6; }
.episode-num {
  font-weight: 800;
  color: var(--text-faint);
  font-size: 20px;
  width: 40px;
  text-align: center;
  flex-shrink: 0;
}
.episode-body { flex: 1; min-width: 0; }
.episode-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.episode-sub { color: var(--text-faint); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.episode-watch { color: var(--err); flex-shrink: 0; font-size: 13px; white-space: nowrap; margin-left: auto; }
.episode-watch.watched { color: var(--ok); font-weight: 700; }
.episode .ep-progress {
  position: absolute;
  bottom: 0; left: 0;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
}

/* ---------- Player ---------- */
.player-page { max-width: 1200px; margin: 0 auto; padding: 0 20px 60px; }
.player-wrap {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-top: 16px;
  /* Fixed 16:9 box built with the classic padding-bottom trick so it works on
     every browser/WebView, including smart TVs without aspect-ratio support.
     Keeps the player from collapsing or expanding while a video is loading. */
  height: 0;
  padding-bottom: 56.25%;
}
.player-wrap .player-loader {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.player-wrap .player-loader.show {
  opacity: 1;
  visibility: visible;
}
.player-wrap .player-loader::after {
  content: "";
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: player-spin 1s linear infinite;
}
@keyframes player-spin {
  to { transform: rotate(360deg); }
}
.player-wrap video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
  border: none;
}

/* Suppress any browser/TV native media controls that may still appear
   despite the video element having controls=false and controlsList set. */
.player-wrap video::-webkit-media-controls,
.player-wrap video::-webkit-media-controls-enclosure,
.player-wrap video::-webkit-media-controls-panel,
.player-wrap video::-webkit-media-controls-overlay-enclosure,
.player-wrap video::-webkit-media-controls-play-button,
.player-wrap video::-webkit-media-controls-start-playback-button,
.player-wrap video::-webkit-media-controls-timeline,
.player-wrap video::-webkit-media-controls-volume-control,
.player-wrap video::-webkit-media-controls-mute-button,
.player-wrap video::-webkit-media-controls-fullscreen-button,
.player-wrap video::-webkit-media-controls-rewind-button,
.player-wrap video::-webkit-media-controls-return-to-realtime-button,
.player-wrap video::-webkit-media-controls-toggle-closed-captions-button {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
.player-wrap video::-webkit-media-controls,
.player-wrap video::-webkit-media-controls-enclosure,
.player-wrap video::-webkit-media-controls-panel {
  display: none !important;
}
.player-wrap video::-webkit-media-controls-overlay-play-button,
.player-wrap video::-webkit-media-controls-play-button,
.player-wrap video::-webkit-media-controls-start-playback-button {
  display: none !important;
}
.video-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 30px 16px 10px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0));
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.video-bar.show {
  opacity: 1;
  visibility: visible;
}
.video-bar.instant {
  transition: none !important;
}
.video-progress {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 14px;
  padding: 0;
  margin: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  outline: none;
  cursor: pointer;
  pointer-events: auto;
  overflow: visible;
}
.video-progress::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  height: 3px;
  border: none;
  border-radius: 1.5px;
  background: rgba(255, 255, 255, 0.3);
}
.video-progress::-moz-range-track {
  height: 3px;
  border: none;
  border-radius: 1.5px;
  background: rgba(255, 255, 255, 0.3);
}
.video-progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  margin-top: -5.5px;
}
.video-progress::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}
.video-bar-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  pointer-events: auto;
}
.bar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 36px;
  min-width: 40px;
  padding: 0 10px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
}
.bar-btn:hover,
.bar-btn:focus-visible {
  background: rgba(255, 255, 255, 0.25);
}
.bar-btn.bar-back,
.bar-btn.bar-fwd {
  background: transparent;
  padding: 0 4px;
}
.bar-btn.bar-back:hover,
.bar-btn.bar-back:focus-visible,
.bar-btn.bar-fwd:hover,
.bar-btn.bar-fwd:focus-visible {
  background: rgba(255, 255, 255, 0.12);
}
.bar-ico { width: 20px; height: 20px; }
.bar-ico-seek { width: 18px; height: 18px; }
.bar-ico-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1;
  pointer-events: none;
}
.bar-fwd .bar-ico-seek { transform: scaleX(-1); }
.bar-time {
  font-size: 13px;
  color: #fff;
  opacity: 0.85;
  padding: 0 6px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.bar-spacer { flex: 1; }
.bar-volume {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  pointer-events: auto;
}
.bar-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: none;
}
.bar-volume::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: none;
}
.bar-vol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-width: 28px;
  padding: 0;
}
.bar-vol .bar-ico {
  width: 16px;
  height: 16px;
}
.bar-epnav-wrap {
  display: inline-flex;
  gap: 6px;
}
.bar-epnav {
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  min-width: auto;
}
.bar-final {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}
.player-epnav-wrap {
  display: flex;
  gap: 10px;
}
.player-epnav-wrap .bar-final {
  opacity: 0.5;
  pointer-events: none;
}
.player-under-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.bar-vol:hover,
.bar-vol:focus-visible {
  background: rgba(255, 255, 255, 0.25);
}
.bar-vol .bar-ico {
  width: 16px;
  height: 16px;
}
.player-wrap:fullscreen,
.player-wrap:-webkit-full-screen {
  width: 100%;
  height: 100%;
  padding-bottom: 0;
  border-radius: 0;
  margin-top: 0;
}

/* Transparent overlay that captures mouse/touch in fullscreen so the custom
   control bar can be revealed when the user moves or taps the screen. It is
   on top of the video but behind the control bar, and becomes non-interactive
   while the control bar is visible so the bar buttons remain clickable. */
.player-fs-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  pointer-events: none;
}
.player-wrap:fullscreen .player-fs-overlay,
.player-wrap:-webkit-full-screen .player-fs-overlay {
  pointer-events: auto;
}
.player-wrap:fullscreen .video-bar.show ~ .player-fs-overlay,
.player-wrap:-webkit-full-screen .video-bar.show ~ .player-fs-overlay {
  pointer-events: none;
}

.player-wrap .embed-wrap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.player-wrap .embed-wrap iframe {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  display: block;
  border: none;
}
/* Messages shown inside the player area (errors, tap hints, embed notices)
   overlay the video instead of flowing under it, so they stay visible even
   though .player-wrap has a zero-height content box (16:9 padding box). */
.player-wrap .player-msg {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  margin: 0;
  z-index: 4;
}
.player-head {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 22px;
}
.player-head h2 { font-size: 26px; font-weight: 800; min-width: 0; }
.player-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.player-msg {
  margin-top: 14px;
  padding: 16px 18px;
  border-radius: 10px;
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 15px;
}
.player-error {
  border-left: 4px solid var(--err);
  color: var(--text);
}
.player-note {
  border-left: 4px solid var(--warn);
}
.player-info {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.55;
}
.player-info-title { font-weight: 700; color: var(--text); margin-bottom: 4px; }
.player-info-link { overflow-wrap: anywhere; }
.player-info-link a { color: var(--accent); text-decoration: none; }
.player-info-link a:hover { text-decoration: underline; }
.player-info-desc { margin-top: 4px; }

/* ---------- Live (two-pane: channel list + inline player) ---------- */
.live-page { max-width: 1500px; margin: 0 auto; padding: 0 20px 60px; }
.live-layout {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  margin-top: 6px;
}
.live-list {
  width: 44%;
  max-width: 460px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.live-filter {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
}
.live-filter:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.live-list-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: calc(100vh - 250px);
  overflow-y: auto;
  padding-right: 4px;
}
.live-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}
.live-item:hover { background: rgba(255, 255, 255, 0.06); }
.live-item.active { background: var(--bg-elev3); }
.live-item.active .live-ico { background: var(--accent); color: #06120d; }
.live-ico {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
.live-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.live-grp {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.live-item-wrap {
  display: flex;
  align-items: stretch;
  gap: 4px;
}
.live-item-wrap .live-item { flex: 1 1 auto; width: auto; min-width: 0; }
.live-pin {
  flex: 0 0 auto;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  opacity: .85;
  transition: background .15s ease, opacity .15s ease;
}
.live-pin:hover, .live-pin:focus-visible { background: rgba(255, 255, 255, .08); opacity: 1; }
.live-pin.pinned {
  background: var(--bg-elev3);
  color: var(--accent);
  opacity: 1;
}
.live-pin.pinned:hover, .live-pin.pinned:focus-visible { background: var(--bg-elev2); }
.live-more {
  font-size: 12px;
  color: var(--text-dim);
  padding: 10px 12px;
  text-align: center;
}
.live-player { flex: 1; min-width: 0; }
.live-player .player-wrap { margin-top: 0; }
.live-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  color: var(--text-faint);
  font-size: 16px;
  text-align: center;
  padding: 16px;
  background: var(--bg-elev);
}

/* ---------- Search ---------- */
.search-bar { position: relative; margin-top: 18px; margin-bottom: 22px; max-width: none; }
.search-bar input { font-size: 20px; padding: 14px 16px; border-radius: 12px; }
.search-results { margin-top: 10px; }
.result-list { display: flex; flex-direction: column; gap: 6px; max-width: 900px; }
.result-item {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--bg-elev);
  border-radius: 10px;
  padding: 8px 12px;
  outline: none;
  cursor: pointer;
}
.result-item:hover { background: var(--bg-elev2); }
.result-thumb {
  width: 60px;
  aspect-ratio: 2/3;
  border-radius: 6px;
  background: var(--bg-elev2);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  flex-shrink: 0;
}
.result-item .r-title { font-weight: 700; }
.result-item .r-sub { color: var(--text-faint); font-size: 13px; }

/* ---------- Forms / settings ---------- */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-top: 22px;
}
.panel {
  background: var(--bg-elev);
  border-radius: var(--radius);
  padding: 22px;
}
.panel h3 { font-size: 19px; font-weight: 800; margin-bottom: 6px; }
.panel p { color: var(--text-dim); font-size: 14px; margin-bottom: 14px; }
.panel .btn { width: 100%; justify-content: center; margin-top: 8px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; font-weight: 700; color: var(--text-dim); margin-bottom: 6px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; }
.file-drop {
  border: 2px dashed #33405f;
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color .2s;
  margin-bottom: 10px;
}
.file-drop:hover, .file-drop.dragover { border-color: var(--accent); color: var(--text); }
.file-drop input { display: none; }
.url-import-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.url-import-row input { flex: 1 1 220px; }
.url-import-row .btn { flex-shrink: 0; }

/* Maintenance buttons: one row with clear spacing between them. On narrow
   screens they wrap to multiple lines instead of stacking full-width. */
.maint-actions { display: flex; flex-direction: row; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.maint-actions .btn { margin-top: 0; width: auto; }

/* Desktop library layout: fixed 4-column arrangement so spatial navigation
   follows a predictable order (mobile keeps the single-column auto-fit). */
@media (min-width: 1200px) {
  .settings-grid {
    grid-template-columns: repeat(4, 1fr);
    grid-template-areas:
      "import xtream export add"
      "opts   opts   opts   opts"
      "edit   delete maint  maint";
  }
  .panel-import { grid-area: import; }
  .panel-importopts { grid-area: opts; }
  .panel-xtream { grid-area: xtream; }
  .panel-export { grid-area: export; }
  .panel-add { grid-area: add; }
  .panel-edit { grid-area: edit; }
  .panel-delete { grid-area: delete; }
  .panel-maint { grid-area: maint; }
  .import-options {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    max-width: 880px;
    margin: 0 auto;
  }
  .maint-actions { flex-wrap: nowrap; }
  .maint-actions .btn { flex: 1 1 0; padding: 12px 10px; font-size: 14px; white-space: nowrap; }
}
.url-hint {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 8px;
  word-break: break-all;
}
.picker-search { margin-bottom: 10px; }

/* ---------- Import Options toggles ---------- */
.import-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.import-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-elev2);
  border: 1px solid #2b3550;
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  text-align: left;
  transition: border-color .2s, background .2s;
}
.import-toggle:hover { border-color: #3d4a6e; }
.import-toggle.on { border-color: #26664a; background: rgba(38, 102, 74, .10); }
.import-toggle-label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.import-toggle-label small {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-faint);
}
.import-toggle .switch {
  position: relative;
  flex: 0 0 44px;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: var(--bg-elev3);
  transition: background .2s;
}
.import-toggle .switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform .2s, background .2s;
}
.import-toggle.on .switch { background: rgba(38, 102, 74, .30); }
.import-toggle.on .switch::after {
  transform: translateX(20px);
  background: #2f7a57;
}

/* Standalone switch (used next to the regex field). */
.switch-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 8px;
  border-radius: 8px;
  background: var(--bg-elev2);
  border: 1px solid #2c3752;
  transition: border-color .2s, background .2s;
}
.switch-btn:hover { border-color: #3d4a6e; }
.switch-btn .switch {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: var(--bg-elev3);
  transition: background .2s;
}
.switch-btn .switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform .2s, background .2s;
}
.switch-btn.on { border-color: #26664a; background: rgba(38, 102, 74, .10); }
.switch-btn.on .switch { background: rgba(38, 102, 74, .30); }
.switch-btn.on .switch::after {
  transform: translateX(20px);
  background: #2f7a57;
}

/* Advanced regex skip row inside the Import Options panel. */
.import-regex-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
}
.import-regex-row .import-regex-input { flex: 0 1 50%; min-width: 0; }
.import-regex-input:disabled { opacity: .55; }
.import-regex-input.invalid { border-color: var(--err); }
.import-regex-input.invalid:focus { border-color: var(--err); }

/* ---------- Empty states ---------- */
.empty {
  text-align: center;
  padding: 70px 20px;
  color: var(--text-faint);
}
.empty .big { font-size: 56px; margin-bottom: 12px; opacity: .6; }
.empty h3 { color: var(--text-dim); font-size: 22px; margin-bottom: 8px; }
.empty p { max-width: 460px; margin: 0 auto 18px; }

/* ---------- Modals ---------- */
.modal-root {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 300;
  background: rgba(0,0,0,.66);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-root[hidden] { display: none; }
.modal {
  background: var(--bg-elev);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow: auto;
  padding: 26px;
  box-shadow: var(--shadow);
}
.modal h3 { font-size: 22px; font-weight: 800; margin-bottom: 8px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.modal .form-grid { grid-template-columns: 1fr 1fr; }
.modal .form-grid .full { grid-column: 1 / -1; }

/* ---------- Import progress ---------- */
.progress-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 400;
  background: rgba(0, 0, 0, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.progress-overlay[hidden] { display: none; }
.progress-card {
  background: var(--bg-elev);
  border-radius: 14px;
  padding: 30px 36px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 380px;
  width: 100%;
}
.progress-spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .15);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-title { font-size: 20px; font-weight: 800; margin-bottom: 6px; }
.progress-status { color: var(--text-dim); font-size: 14px; min-height: 18px; }

/* ---------- Toast ---------- */
.toast-root {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--bg-elev3);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-weight: 600;
  animation: toastIn .25s ease;
  max-width: 90vw;
}
.toast.err { border-left: 4px solid var(--err); }
.toast.ok { border-left: 4px solid var(--ok); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (min-width: 901px) {
  #btnMenu { display: none; }
  .mobile-menu { display: none !important; }
}

@media (max-width: 900px) {
  .topnav { display: none; }
  #btnMenu { display: grid; }
  .topbar-inner { padding: 8px 12px; }
  .hero-title { font-size: 32px; }
  .hero { min-height: 300px; }
  .hero-body { padding: 18px 16px; }
  .hero-actions .btn { padding: 10px 16px; font-size: 14px; }
  .detail-header { flex-direction: column; align-items: flex-start; margin-top: -40px; }
  .detail-info { padding-top: 10px; }
  .detail-poster { width: 180px; }
  .detail-title { font-size: 28px; }
  :root { --card-w: 150px; --card-h: 226px; --row-h: 280px; }
  .live-layout { flex-direction: column; align-items: stretch; }
  .live-list { width: 100%; max-width: none; order: 2; }
  .live-list-body { max-height: 42vh; }
  .live-player { order: 1; width: 100%; }
  .live-page { padding: 0 12px 60px; }
  .page { padding: 0 12px; }
}

@media (max-width: 520px) {
  :root { --card-w: 132px; --card-h: 198px; --row-h: 252px; }
  .bar-volume { display: none; }
  .bar-vol { margin-right: 2px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal .form-grid { grid-template-columns: 1fr; }
  .player-head h2 { font-size: 20px; }
  .episode { padding: 8px 10px; gap: 8px; }
  .episode-main { gap: 10px; }
  .episode-thumb { width: 72px; }
  .episode-num { display: none; }
  .episode-watch { font-size: 12px; }
  .episode-edit { padding: 6px 10px; }
  .section-title { font-size: 20px; }
  .page-head { gap: 10px; margin-top: 16px; margin-bottom: 12px; }
  .page-head-left { gap: 14px; }
  .page-head-action { padding: 8px 12px; font-size: 13px; }
  .live-item { padding: 8px 10px; gap: 8px; font-size: 13px; }
  .live-ico { width: 26px; height: 26px; font-size: 10px; }
  .live-grp { max-width: 80px; font-size: 10px; }
  .live-list-body { max-height: 38vh; }
  .hero-title { font-size: 26px; }
  .hero-body { padding: 14px 14px; }
  .hero-desc { -webkit-line-clamp: 2; }
}

@media (min-width: 1600px) {
  :root { --card-w: 200px; --card-h: 300px; --row-h: 352px; }
}

@media (pointer: coarse) {
  .card { transform: none !important; }
  /* On touch devices, hide episode prev/next buttons inside the control bar
     in both fullscreen and non-fullscreen. The under-player strip is always
     visible and not affected. */
  .bar-epnav-wrap { display: none !important; }
}

/* ---------- Footer ---------- */
.app-footer {
  flex-shrink: 0;
  padding: 10px 16px;
  background: var(--bg-elev);
  border-top: 1px solid var(--bg-elev3);
}
.app-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: center;
}
.app-footer-donate {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}
.footer-btn {
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s ease;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  line-height: 1.6;
  position: relative;
}
.footer-btn:hover,
.footer-btn:focus-visible {
  background: transparent;
  color: var(--text);
}
.footer-btn:hover::after,
.footer-btn:focus-visible::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--accent);
}
.footer-btn.footer-danger {
  border: 1px solid var(--err);
  border-radius: 6px;
  color: var(--err);
}
.footer-btn.footer-danger:hover,
.footer-btn.footer-danger:focus-visible {
  background: var(--err);
  color: #fff;
}
.footer-btn.footer-danger:hover::after,
.footer-btn.footer-danger:focus-visible::after {
  display: none;
}
.footer-btn.footer-primary {
  border: none;
  border-radius: 0;
  color: var(--err);
}
.footer-btn.footer-primary:hover,
.footer-btn.footer-primary:focus-visible {
  background: transparent;
  color: var(--err);
}
.footer-btn.footer-primary:hover::after,
.footer-btn.footer-primary:focus-visible::after {
  background: var(--err);
}
.footer-btn.footer-donate {
  background: var(--bg-elev2);
  border: 1px solid var(--bg-elev3);
  border-radius: 6px;
  color: var(--text-dim);
}
.footer-btn.footer-donate:hover,
.footer-btn.footer-donate:focus-visible {
  background: var(--bg-elev3);
  color: var(--text);
}
@media (max-width: 520px) {
  .footer-btn { padding: 5px 8px; font-size: 11px; }
}
