/* BDIX CloudStream Web — exact CloudStream app theme
   Palette from app/src/main/res/values/colors.xml (cs3 master) */
:root {
  --colorPrimary: #3d50fa;
  --colorAccent: #3b65f5;
  --primaryGrayBackground: #2B2C30;
  --primaryBlackBackground: #111111;
  --iconGrayBackground: #1C1C20;
  --boxItemBackground: #161616;
  --textColor: #e9eaee;
  --grayTextColor: #9ba0a4;
  --darkBarTransparent: rgba(18, 18, 18, 0.75);
  --skipOpTransparent: rgba(18, 18, 18, 0.30);
  --dubColorBg: #3B65F5;
  --subColorBg: #F53B66;
  --videoProgress: rgba(181, 181, 181, 0.4);
  --iconColor: #9ba0a6;
  --cardW: 114px;
  --cardH: 180px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--primaryBlackBackground);
  color: var(--textColor);
  font-family: Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
::-webkit-scrollbar { height: 0; width: 0; }

/* ============ HOME HEADER (fragment_home_head.xml) ============ */
.home-header {
  background: var(--primaryBlackBackground);
  padding-top: env(safe-area-inset-top, 0);
}
.home-topbar {
  display: flex; align-items: center; height: 50px; padding: 0 8px;
}
.home-topbar .search-trigger {
  flex: 1; display: flex; align-items: center; height: 40px; padding: 0 12px;
  color: #fff; opacity: .9; gap: 10px; cursor: pointer;
}
.home-topbar .avatar {
  width: 30px; height: 30px; border-radius: 20px; overflow: hidden;
  background: var(--iconGrayBackground); display: flex; align-items: center;
  justify-content: center; cursor: pointer; flex-shrink: 0;
}
.home-topbar .avatar span { font-size: 15px; color: var(--textColor); }

/* source chips (CloudStream home API filter style) */
.source-chips {
  display: flex; gap: 8px; padding: 4px 12px 10px; overflow-x: auto;
  scrollbar-width: none;
}
.chip {
  border-radius: 19px; padding: 7px 14px; font-size: 13px; white-space: nowrap;
  background: var(--primaryGrayBackground); color: var(--textColor);
  border: 1px solid transparent; cursor: pointer; opacity: .85;
}
.chip.active {
  background: rgba(61, 80, 250, .18); color: #cdd4ff;
  border-color: rgba(61, 80, 250, .55); opacity: 1;
}

/* ============ ROWS (homepage_parent.xml) ============ */
.row { margin: 4px 0 10px; }
.row-header {
  display: flex; align-items: center; padding: 12px;
  font-weight: 500; font-size: 16px; color: #fff; cursor: pointer;
}
.row-header .arrow {
  margin-left: auto; width: 18px; height: 18px; opacity: .9;
}
.row-scroll {
  display: flex; gap: 8px; overflow-x: auto; padding: 0 5px 6px;
  scrollbar-width: none; scroll-snap-type: x proximity;
}

/* ============ CARD (home_result_grid.xml: 114x180dp) ============ */
.card {
  width: var(--cardW); min-width: var(--cardW); height: var(--cardH);
  border-radius: 3px; position: relative; overflow: hidden;
  background: var(--boxItemBackground); cursor: pointer;
  scroll-snap-align: start;
}
.card img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  background: var(--iconGrayBackground);
}
.card .shadow {
  position: absolute; inset: auto 0 0 0; height: 50px;
  background: linear-gradient(transparent, rgba(0,0,0,.85));
}
.card .img-text {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 6px 5px;
  font-size: 11.5px; line-height: 1.25; color: var(--textColor);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .badges { position: absolute; top: 4px; right: 4px; display: flex; gap: 3px; }
.badge {
  font-size: 9.5px; font-weight: 600; padding: 1.5px 5px; border-radius: 3px;
  color: #fff; letter-spacing: .2px;
}
.badge.quality { background: rgba(0,0,0,.65); border: 1px solid rgba(255,255,255,.28); }
.badge.dub { background: var(--dubColorBg); }
.badge.hevc { background: #6a3df0; }

/* ============ SEARCH ============ */
.search-page { position: fixed; inset: 0; background: var(--primaryBlackBackground); z-index: 60; display: flex; flex-direction: column; }
.search-bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--primaryBlackBackground);
  padding-top: calc(10px + env(safe-area-inset-top, 0));
}
.search-bar input {
  flex: 1; background: var(--primaryGrayBackground); border: none; outline: none;
  color: #fff; font-size: 16px; padding: 12px 14px; border-radius: 4px;
}
.icon-btt {
  background: none; border: none; color: #fff; cursor: pointer; padding: 8px;
  display: flex; align-items: center; justify-content: center; opacity: .92;
}
.search-results {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px; padding: 10px 12px 30px; overflow-y: auto; flex: 1;
}
.search-results .card { width: 100%; min-width: 0; height: auto; aspect-ratio: 114/180; }

/* ============ DETAIL (fragment_result.xml) ============ */
.detail { padding-bottom: 90px; }
.detail-banner {
  position: relative; height: 300px; background: var(--primaryGrayBackground);
}
.detail-banner img.bg {
  width: 100%; height: 100%; object-fit: cover; opacity: .45;
}
.detail-banner .fade {
  position: absolute; inset: 0;
  background: linear-gradient(rgba(17,17,17,.15), var(--primaryBlackBackground));
}
.detail-head {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex;
  padding: 14px; gap: 14px; align-items: flex-end;
}
.detail-head img.poster {
  width: 110px; border-radius: 4px; aspect-ratio: 114/180; object-fit: cover;
  background: var(--iconGrayBackground); flex-shrink: 0;
}
.detail-head .titles { min-width: 0; }
.detail-head h1 {
  font-size: 18px; line-height: 1.3; margin: 0 0 6px; color: #fff;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.detail-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.detail-badges .badge { font-size: 10.5px; padding: 2.5px 7px; }
.detail-body { padding: 12px 14px; }
.detail-tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.detail-tags span {
  background: var(--primaryGrayBackground); padding: 4px 10px;
  border-radius: 15px; font-size: 12px; color: var(--grayTextColor);
}
.detail-plot {
  white-space: pre-line; color: var(--grayTextColor); font-size: 13.5px;
  line-height: 1.55; margin: 8px 0 0;
}
.play-fab {
  position: fixed; right: 18px; bottom: 22px; z-index: 40;
  background: var(--colorPrimary); color: #fff; border: none;
  border-radius: 26px; padding: 13px 22px; font-size: 15px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,.5);
}

/* episodes */
.ep-list { margin-top: 6px; }
.ep-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px;
  background: var(--boxItemBackground); border-radius: 4px; margin-bottom: 6px;
  cursor: pointer;
}
.ep-item .num {
  width: 34px; height: 34px; border-radius: 4px; background: var(--primaryGrayBackground);
  display: flex; align-items: center; justify-content: center; font-weight: 600;
  font-size: 14px; flex-shrink: 0; color: #cdd4ff;
}
.ep-item .meta { min-width: 0; }
.ep-item .meta .t { font-size: 14px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ep-item .meta .s { font-size: 11.5px; color: var(--grayTextColor); margin-top: 2px; }
.ep-item .go { margin-left: auto; opacity: .6; }

/* source sheet (player_select_source_and_subs.xml vibe) */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 80;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--iconGrayBackground); width: 100%; max-width: 560px;
  border-radius: 12px 12px 0 0; padding: 14px 0 calc(14px + env(safe-area-inset-bottom, 0));
  max-height: 72vh; display: flex; flex-direction: column;
}
.sheet h3 { margin: 0 14px 10px; font-size: 16px; color: #fff; }
.sheet .links { overflow-y: auto; padding: 0 10px; }
.link-item {
  display: flex; align-items: center; gap: 10px; padding: 12px 10px;
  border-radius: 5px; cursor: pointer; background: transparent; width: 100%;
  border: none; color: var(--textColor); text-align: left; font-size: 14px;
}
.link-item:hover { background: var(--primaryGrayBackground); }
.link-item .q {
  background: var(--colorAccent); color: #fff; font-size: 11px; font-weight: 700;
  padding: 3px 7px; border-radius: 4px; min-width: 46px; text-align: center;
}
.link-item .lbl { flex: 1; word-break: break-all; }
.link-item .external { opacity: .55; font-size: 11px; }

/* loading spinner (CloudStream main_load) */
.spinner {
  width: 42px; height: 42px; border: 3.5px solid rgba(255,255,255,.18);
  border-top-color: var(--colorPrimary); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 26px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-box { padding: 40px 0; text-align: center; color: var(--grayTextColor); font-size: 13px; }
.empty-box { padding: 40px 16px; text-align: center; color: var(--grayTextColor); }

/* ============ PLAYER (fragment_player.xml + player_custom_layout.xml) ============ */
.player-page {
  position: fixed; inset: 0; background: #000; z-index: 100; display: flex;
  align-items: center; justify-content: center;
}
.player-page video { width: 100%; height: 100%; background: #000; object-fit: contain; }
.player-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: rgba(0,0,0,.35);
  gap: 4px;
}
.player-loading .skip-btt {
  margin-top: 18px; background: var(--skipOpTransparent); border: 1px solid rgba(255,255,255,.35);
  color: #fff; padding: 8px 18px; border-radius: 4px; font-size: 13px; cursor: pointer;
}
.player-overlay { position: absolute; inset: 0; opacity: 0; transition: opacity .18s; }
.player-overlay.visible { opacity: 1; }
.player-overlay .scrim-top {
  position: absolute; top: 0; left: 0; right: 0; height: 110px;
  background: linear-gradient(rgba(0,0,0,.75), transparent);
}
.player-overlay .scrim-bottom {
  position: absolute; bottom: 0; left: 0; right: 0; height: 150px;
  background: linear-gradient(transparent, rgba(0,0,0,.8));
}
.player-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center;
  padding: calc(8px + env(safe-area-inset-top, 0)) 8px 8px; gap: 4px;
}
.player-top .titles { min-width: 0; margin-right: auto; }
.player-top .title {
  font-size: 15px; color: #fff; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; font-weight: 500;
}
.player-top .info { font-size: 12px; color: var(--grayTextColor); margin-top: 1px; }
.player-center {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; gap: 34px;
}
.pb-btt {
  background: none; border: none; color: #fff; cursor: pointer; padding: 10px;
  display: flex; align-items: center; justify-content: center;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.7));
}
.pb-btt.small svg { width: 34px; height: 34px; }
.pb-btt.big svg { width: 62px; height: 62px; }
.player-bottom { position: absolute; bottom: 0; left: 0; right: 0; padding: 0 10px calc(10px + env(safe-area-inset-bottom, 0)); }
.player-times {
  display: flex; align-items: center; justify-content: space-between;
  color: #fff; font-size: 12.5px; font-variant-numeric: tabular-nums;
  padding: 0 4px; margin-bottom: 2px; opacity: .95;
}
.seekbar { position: relative; height: 26px; display: flex; align-items: center; cursor: pointer; }
.seekbar .track {
  position: absolute; left: 0; right: 0; height: 3.5px; border-radius: 2px;
  background: var(--videoProgress); overflow: hidden;
}
.seekbar .buffer { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(255,255,255,.28); width: 0; }
.seekbar .played {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--colorPrimary); width: 0;
}
.seekbar .knob {
  position: absolute; width: 13px; height: 13px; border-radius: 50%;
  background: var(--colorPrimary); transform: translateX(-50%); left: 0;
  box-shadow: 0 0 4px rgba(0,0,0,.6);
}
.player-actions { display: flex; align-items: center; gap: 2px; margin-top: 2px; }
.player-actions .spacer { flex: 1; }

/* misc */
.top-back {
  position: absolute; top: calc(8px + env(safe-area-inset-top, 0)); left: 6px;
  z-index: 10;
}
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--primaryGrayBackground); color: #fff; padding: 10px 18px;
  border-radius: 6px; font-size: 13.5px; z-index: 200; max-width: 86vw;
  box-shadow: 0 4px 14px rgba(0,0,0,.5); text-align: center;
}
.err-card {
  margin: 20px 14px; background: rgba(245, 59, 102, .12); border: 1px solid rgba(245,59,102,.4);
  border-radius: 8px; padding: 14px; color: #ffd7de; font-size: 13.5px; line-height: 1.5;
}
.page-title { padding: 14px; font-size: 17px; font-weight: 500; color: #fff; }
.load-more {
  display: block; margin: 10px auto 26px; background: var(--primaryGrayBackground);
  border: 1px solid rgba(255,255,255,.12); color: var(--textColor);
  padding: 10px 22px; border-radius: 20px; font-size: 13.5px; cursor: pointer;
}
