:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --bg2: var(--tg-theme-secondary-bg-color, #171a21);
  --text: var(--tg-theme-text-color, #e8eaed);
  --hint: var(--tg-theme-hint-color, #8b93a1);
  --link: var(--tg-theme-link-color, #5aa9ff);
  --btn: var(--tg-theme-button-color, #2f6fed);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  min-height: 100%;
}

#app { display: flex; flex-direction: column; min-height: 100vh; }

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

#topbar h1 { font-size: 17px; margin: 0; font-weight: 600; }



#view { flex: 1; padding: 14px; padding-top: 18px; }

.hidden { display: none !important; }

/* ---------- плавное появление экрана ----------
   Анимируем прямых детей #view. Обёртку не добавляем:
   она ломала отступы и позиционирование плеера. */
@keyframes screen-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.screen-fade {
  animation: screen-fade-in 0.18s ease both;
}

/* ---------- stagger-появление карточек ---------- */
@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card,
.dropdown-row {
  animation: card-in 0.26s ease both;
}

.list > .card:nth-child(1) { animation-delay: 0.02s; }
.list > .card:nth-child(2) { animation-delay: 0.05s; }
.list > .card:nth-child(3) { animation-delay: 0.08s; }
.list > .card:nth-child(4) { animation-delay: 0.11s; }
.list > .card:nth-child(5) { animation-delay: 0.14s; }
.list > .card:nth-child(6) { animation-delay: 0.17s; }
.list > .card:nth-child(7) { animation-delay: 0.20s; }
.list > .card:nth-child(8) { animation-delay: 0.23s; }
.list > .card:nth-child(9) { animation-delay: 0.26s; }
.list > .card:nth-child(n+10) { animation-delay: 0.29s; }

.dropdown-row:nth-child(1) { animation-delay: 0.02s; }
.dropdown-row:nth-child(2) { animation-delay: 0.05s; }
.dropdown-row:nth-child(3) { animation-delay: 0.08s; }
.dropdown-row:nth-child(4) { animation-delay: 0.11s; }
.dropdown-row:nth-child(5) { animation-delay: 0.14s; }
.dropdown-row:nth-child(n+6) { animation-delay: 0.17s; }

@media (prefers-reduced-motion: reduce) {
  .screen-fade, .card, .dropdown-row { animation: none !important; transition: none !important; }
}

/* search */
.search-box { display: flex; gap: 8px; margin-bottom: 16px; }

.search-box input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: var(--bg2);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.search-box input:focus { border-color: var(--btn); }

.search-box button {
  padding: 0 18px;
  border-radius: 12px;
  border: none;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* рекламный слот (создаётся только при ADS_ENABLED = true) */
.ad-slot {
  margin: 0 0 14px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ad-slot img {
  display: block;
  width: 100%;
  height: auto;
}

/* выпадашка с последними просмотренными */
.search-dropdown {
  margin: -8px 0 14px;
  background: var(--bg2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.dropdown-title {
  padding: 10px 12px 6px;
  font-size: 12px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.dropdown-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.dropdown-row:active { background: rgba(255, 255, 255, 0.06); }

.dropdown-row img {
  width: 38px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  background: #222;
  flex: 0 0 auto;
}

.dropdown-info { min-width: 0; }

.dropdown-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-meta { font-size: 12px; color: var(--hint); margin-top: 2px; }

/* list */
.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  display: flex;
  gap: 12px;
  padding: 10px;
  border-radius: 14px;
  background: var(--bg2);
  cursor: pointer;
  transition: transform .08s;
}

.card:active { transform: scale(0.985); }

.card img {
  width: 62px;
  height: 92px;
  object-fit: cover;
  border-radius: 8px;
  background: #222;
  flex-shrink: 0;
}

.card .info { display: flex; flex-direction: column; justify-content: center; gap: 4px; min-width: 0; }

.card .name { font-weight: 600; font-size: 15px; line-height: 1.25; }

.card .meta { color: var(--hint); font-size: 13px; }

/* последние фильмы */
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--hint);
  padding: 6px 2px 0;
}

.card.recent img { width: 72px; height: 106px; }
.card.recent .info { gap: 6px; }
.card.recent .btn.small {
  width: auto;
  align-self: flex-start;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 10px;
  margin-top: 2px;
}

/* movie page */
.movie { display: flex; flex-direction: column; gap: 14px; padding-top: 8px; }

.movie-head { display: flex; gap: 14px; align-items: flex-start; }

.movie-head img {
  width: 110px;
  height: 165px;
  object-fit: cover;
  border-radius: 12px;
  background: #222;
  flex-shrink: 0;
}

.movie-head .info { display: flex; flex-direction: column; gap: 6px; }

.movie-head .name { font-size: 19px; font-weight: 700; line-height: 1.2; }

.movie-head .orig { color: var(--hint); font-size: 13px; font-style: italic; }

.movie-head .meta { color: var(--hint); font-size: 13px; }

.rating { color: #ffc83d; font-weight: 600; }

.overview { line-height: 1.5; color: var(--text); }

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: none;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn:active { opacity: .85; }

.btn.secondary { background: var(--bg2); color: var(--text); }

/* player */
.player-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  /* отступ снизу, чтобы нативные контролы видео не пересекались
     с системными кнопками телефона */
  box-sizing: border-box;
}

/* нативная кнопка fullscreen в WebView не работает — прячем её,
   вместо неё своя кнопка в .player-overlay */
.player-wrap video::-webkit-media-controls-fullscreen-button,
.player-wrap video::-webkit-media-controls-picture-in-picture-button {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

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

.player-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.subscribe {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 40px 20px;
  text-align: center;
}

.subscribe-icon { font-size: 48px; }

.subscribe-title { font-size: 20px; font-weight: 700; }

.subscribe-text { color: var(--hint); font-size: 14px; line-height: 1.5; max-width: 320px; }

.subscribe .btn { max-width: 320px; }

.fs-btn { margin-top: 10px; }

.player-wrap.pseudo-fs {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  z-index: 2147483647;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 0;
  background: #000;
  aspect-ratio: auto !important;
  box-sizing: border-box !important;
  /* видео центрируем: нативные контролы должны быть у нижней границы
     видео, а не у нижней границы экрана */
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.player-wrap.pseudo-fs video {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
}

/* ---------- поворот в горизонталь при заблокированной ориентации ----------
   screen.orientation.lock() игнорируется, если в системе включена блокировка
   поворота. Разворачиваем контейнер трансформом на 90°: ширина становится
   высотой экрана и наоборот. */
.player-wrap.cp-rotate {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  width: 100vh !important;
  height: 100vw !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 0;
  background: #000;
  aspect-ratio: auto !important;
  box-sizing: border-box !important;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center center;
  z-index: 2147483647;
  /* .pseudo-fs ставит display:flex — в повёрнутом режиме он не нужен:
     stage занимает весь контейнер, центрировать нечего */
  display: block !important;
}

.player-wrap.cp-rotate video {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
}

/* блокируем скролл страницы в полноэкранном режиме */
body.fs-lock {
  overflow: hidden !important;
  overscroll-behavior: none;
  position: fixed;
  width: 100%;
  height: 100%;
}

body.fs-lock #topbar {
  display: none !important;
}

/* продолжение просмотра */
.resume-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg2);
}

.resume-text { font-size: 14px; color: var(--hint); }

.resume-row { display: flex; gap: 8px; }

.resume-row .btn.small {
  width: auto;
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
  border-radius: 10px;
}

/* iframe (трейлер) в fullscreen растягиваем на весь экран;
   video уже настроен выше — центрируется с сохранением пропорций */
.player-wrap.pseudo-fs iframe {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
}

/* кнопки поверх видео */
/* ================= кастомный плеер ================= */

/* область видео: контролы позиционируются относительно неё,
   а не относительно всего экрана */
.cp-stage {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
}

.cp-ui {
  position: absolute;
  inset: 0;
  z-index: 5;
  opacity: 1;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.cp-ui.hidden {
  display: block !important;
  opacity: 0;
  pointer-events: none;
}

/* центральная кнопка play/pause — лежит прямо в .cp-stage,
   поэтому не гаснет вместе с .cp-ui */
.cp-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  z-index: 6;
  transition: opacity 0.2s ease;
}

.cp-center.hidden { display: none !important; }

/* индикатор загрузки потока */
.cp-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: cp-spin 0.8s linear infinite;
  pointer-events: none;
  z-index: 6;
}

.cp-spinner.hidden { display: none !important; }

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

/* текст под спиннером */
.cp-loading-text {
  position: absolute;
  top: calc(50% + 34px);
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  pointer-events: none;
  z-index: 6;
}

.cp-loading-text.hidden { display: none !important; }

/* подсказка перемотки при двойном тапе */
.cp-seek-hint {
  position: absolute;
  top: 50%;
  transform: translateY(-50%) scale(0.9);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
  z-index: 7;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.cp-seek-hint.left { left: 12%; }
.cp-seek-hint.right { right: 12%; }

.cp-seek-hint.show {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

/* нижняя панель */
.cp-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
  pointer-events: auto;
}

.cp-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}

.cp-btn:active { background: rgba(255, 255, 255, 0.15); }

.cp-play { font-size: 15px; }
.cp-vol { font-size: 15px; }
.cp-audio { font-size: 15px; }

.cp-time {
  flex: 0 0 auto;
  color: #fff;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0.9;
}

/* прогресс */
.cp-progress {
  flex: 1 1 auto;
  position: relative;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  touch-action: none;
}

.cp-progress::before {
  /* увеличиваем зону касания */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -10px;
  bottom: -10px;
}

.cp-progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  border-radius: 2px;
  background: #e50914;
  pointer-events: none;
}

.cp-progress-knob {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  margin-top: -6px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

/* в fullscreen .cp-stage точно совпадает с областью видео.
   --cp-ar задаётся из JS по реальным пропорциям (videoWidth/videoHeight),
   поэтому работает для любого формата: 16:9, 2.35:1, 4:3 и т.д. */
.player-wrap.pseudo-fs .cp-stage {
  width: min(100vw, calc(100dvh * var(--cp-ar, 1.7778))) !important;
  height: min(100dvh, calc(100vw / var(--cp-ar, 1.7778))) !important;
  margin: auto;
}

/* ПОВЁРНУТЫЙ режим (блокировка ориентации включена).
   Идёт ПОСЛЕ .pseudo-fs и с более высокой специфичностью, иначе
   min(100vw, ...) из правила выше побеждает и видео становится
   маленьким прямоугольником: vw/vh внутри повёрнутого контейнера
   считаются от неповёрнутого вьюпорта.
   Здесь stage занимает весь контейнер, пропорции сохраняет <video>
   через object-fit: contain. */
.player-wrap.cp-rotate .cp-stage,
.player-wrap.pseudo-fs.cp-rotate .cp-stage {
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
}

.player-wrap.pseudo-fs .cp-bar {
  height: 56px;
  padding: 0 16px;
}
.audio-panel {
  position: absolute;
  bottom: 56px;
  right: 10px;
  width: min(78%, 320px);
  max-height: 62%;
  z-index: 6;
  background: rgba(18, 22, 30, 0.96);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  z-index: 6;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
}

.audio-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.audio-panel-close {
  background: transparent;
  border: none;
  color: var(--hint);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
}

.audio-panel .audio-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.audio-panel .audio-row {
  padding: 8px 10px;
  font-size: 13px;
}

/* оверлей «Продолжить» внутри окна */
.resume-overlay {
  position: absolute;
  left: 8px;
  bottom: 8px;
  right: 8px;
  background: rgba(18, 22, 30, 0.94);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
}

.resume-overlay .resume-text { font-size: 13px; }

.resume-overlay .resume-row .btn.small {
  padding: 8px 12px;
  font-size: 13px;
}

/* loader */
#loader {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.35);
  z-index: 50;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--btn);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

.empty { text-align: center; color: var(--hint); padding: 40px 10px; }

.error { color: #ff6b6b; text-align: center; padding: 20px; }

/* ---------- modal: выбор озвучки ---------- */

.audio-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.audio-modal {
  background: #161a22;
  border-radius: 14px;
  padding: 16px;
  width: min(90vw, 460px);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .55);
}

.audio-modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

.audio-list {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.audio-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #1d232e;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
}

.audio-row:hover {
  background: #252c39;
}

.audio-row-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  word-break: break-word;
}

.audio-row-warn {
  font-size: 12px;
  color: #eab308;
  margin-top: 2px;
}

.audio-row-check {
  color: var(--btn);
  font-weight: 700;
  min-width: 20px;
  text-align: right;
}

.audio-loading,
.audio-empty {
  color: var(--hint);
  padding: 16px;
  text-align: center;
}
