/* Podcast modali — kartochka bosilganda alohida sahifa o'rniga shu qoplama.
   ------------------------------------------------------------------------
   Markup: templates/includes/podcast_modal.html + media/_podcast_modal_body.html,
   xatti-harakat: assets/js/podcast-modal.js.

   Tuzilishi qidiruv modali bilan bir xil: `position: fixed` qoplama +
   markazlashgan panel, holatlar `.podcast-modal` dagi atributlarda:
     [data-open]     — ochiq;
     [data-loading]  — javob kutilyapti: skelet ko'rinadi, tana yashirin.

   Modal `.page` dan tashqarida, shuning uchun sahifaning `zoom` va
   `position` resetlari unga tegmaydi. */

.podcast-modal {
  position: fixed;
  inset: 0;
  z-index: 520;
  /* Markazlashtirish FLEX bilan: panel balandligi kontentga qarab o'zgaradi.
     `inset: 0` + `margin: auto` da balandlik `auto` bo'lgani uchun brauzer
     panelni yuqoridan pastgacha cho'zib qo'yardi (`max-height` gacha) va
     qisqa materialda tagida bo'sh joy qolardi. */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
  font-family: 'Helvetica Neue', 'HelveticaNeue', Helvetica, Arial, sans-serif;
  color: #132745;

  --pm-line: #eaeef3;
  --pm-muted: #6b7785;
  --pm-faint: #9aa5b1;
  --pm-brand: #ff800a;
  --pm-radius: 22px;
}
.podcast-modal[hidden] { display: none; }
/* Reel modali — panelning o'zi kadr: vertikal (9:16), fon quyuq, ichida
   skroll yo'q. Balandlik oynadan kelib chiqadi, eni esa nisbatdan — ya'ni
   ekran qanday bo'lmasin, video to'liq va markazda turadi. */
.podcast-modal[data-kind="reel"] .podcast-modal-panel {
  width: auto;
  max-width: 100%;
  height: min(100%, 920px);
  max-height: 100%;
  aspect-ratio: 9 / 16;
  background-color: #0b1626;
  overflow: hidden;
}
/* Tana panelni to'liq to'ldiradi — kadr panel bo'yi bo'ylab cho'zilsin.
   (Panel `flex-direction: column`, tana esa uning yagona ko'rinadigan bolasi.) */
.podcast-modal[data-kind="reel"] .pm-body { flex: 1 1 auto; min-height: 0; }
.podcast-modal[data-open] {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

.podcast-modal-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(9, 18, 33, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.podcast-modal-panel {
  /* Flex bola: eni qat'iy, balandligi esa kontent bo'yicha — faqat uzun
     materialda `max-height` ga yetib, panel ichida skroll paydo bo'ladi.
     `transform` esa faqat ochilish animatsiyasiga qoladi. */
  position: relative;
  flex: 0 1 auto;
  width: min(880px, 100%);
  max-height: min(100%, 960px);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
  border-radius: var(--pm-radius);
  box-shadow:
    0 1px 2px rgba(19, 39, 69, 0.06),
    0 18px 40px rgba(19, 39, 69, 0.18),
    0 60px 110px rgba(19, 39, 69, 0.26);
  overflow: hidden auto;
  scrollbar-width: thin;
  transform: translateY(18px) scale(0.97);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.podcast-modal[data-open] .podcast-modal-panel { transform: none; }
.podcast-modal-panel:focus { outline: none; }
@media (prefers-reduced-motion: reduce) {
  .podcast-modal, .podcast-modal-panel { transition: none; }
}

/* Yopish tugmasi rasm ustida turadi — o'z foni bo'lmasa oq muqovada
   ko'rinmay qolardi. */
.pm-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #ffffff;
  text-decoration: none;
  background-color: rgba(9, 18, 33, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}
.pm-close:hover { background-color: rgba(9, 18, 33, 0.72); }
.pm-close:active { transform: scale(0.94); }
.pm-close svg { pointer-events: none; }

/* ===================== 1. Muqova / video ===================== */

.pm-media {
  position: relative;
  flex: none;
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: #0b1626;
  overflow: hidden;
}
.pm-video,
.pm-cover {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: cover;
}
/* Muqova fokusi/masshtabi — kartochkalardagi bilan bir xil o'zgaruvchilar. */
.pm-cover {
  object-position: var(--cover-focus-x, 50%) var(--cover-focus-y, 50%);
  transform: scale(var(--cover-zoom, 1));
}
/* Rasm holatida chekkalar quyuqlashadi — panel burchagi aniq ko'rinadi. */
.pm-cover-veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(9, 18, 33, 0.32) 0%, rgba(9, 18, 33, 0) 42%, rgba(9, 18, 33, 0.18) 100%);
  pointer-events: none;
}

/* ===================== 2. Matn qismi ===================== */

.pm-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px 32px 32px;
}

.pm-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pm-chip {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 12px;
  border-radius: 999px;
  background-color: #f3f5f8;
  font-size: 13px;
  line-height: 1;
  font-weight: 500;
  color: var(--pm-muted);
  white-space: nowrap;
}
.pm-chip--brand { background-color: rgba(255, 128, 10, 0.12); color: var(--pm-brand); }

.pm-title {
  margin: 0;
  font-size: 30px;
  line-height: 1.22;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: #132745;
}

.pm-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  font-size: 14px;
  color: var(--pm-muted);
}
.pm-host { display: inline-flex; align-items: center; gap: 10px; }
.pm-host-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: rgba(255, 128, 10, 0.14);
  color: var(--pm-brand);
  font-size: 13px;
  font-weight: 700;
}
.pm-host-name { font-weight: 500; color: #132745; }
.pm-listens { display: inline-flex; align-items: center; gap: 6px; }

.pm-audio {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  /* Brauzerning o'z pleyeri — ranglar shu ikki xossa orqali moslanadi. */
  color-scheme: light;
  accent-color: var(--pm-brand);
}

.pm-caption { margin: 0; font-size: 13px; color: var(--pm-faint); }
.pm-text {
  font-size: 16px;
  line-height: 1.65;
  color: #3a4759;
}
.pm-text p { margin: 0 0 12px; }
.pm-text p:last-child { margin-bottom: 0; }

/* ===================== 3. Reel modali ===================== */
/* Reels — vertikal video, va modalning butun mazmuni shu video. Matn ustiga
   emas, YONIGA qo'yilganda (ikki ustun) e'tibor matnga ketardi; shuning uchun
   sarlavha va meta kadrning pastki chekkasida, gradient ustida turadi. */

.pm-reel { position: relative; width: 100%; height: 100%; }
.pm-reel-video {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  /* `contain` — kadr hech qachon qirqilmaydi; 9:16 manbada panel ham 9:16
     bo'lgani uchun chetda bo'sh joy umuman qolmaydi. */
  object-fit: contain;
  background-color: #0b1626;
}

.pm-reel-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* Pastdan 64px — brauzerning o'z pleyer paneli uchun joy: yozuv uning
     ustiga tushmaydi. */
  padding: 64px 22px 64px;
  background: linear-gradient(0deg, rgba(9, 18, 33, 0.88) 0%, rgba(9, 18, 33, 0.55) 45%, rgba(9, 18, 33, 0) 100%);
  color: #ffffff;
  /* Yozuv pleyer tugmalarini hech qachon to'smaydi. */
  pointer-events: none;
}

.pm-reel-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin: 0;
  font-size: 12px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.72);
}
.pm-reel-tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  background-color: var(--pm-brand);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.pm-reel-stat { display: inline-flex; align-items: center; gap: 5px; }

/* Sarlavha va tavsif — qisqa: kadrni yopib qo'ymasligi uchun qatorlar soni
   cheklanadi, davomi kesiladi. */
.pm-reel-title {
  margin: 0;
  font-size: 19px;
  line-height: 1.3;
  font-weight: 600;
  color: #ffffff;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.pm-reel-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.7);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

/* ===================== 4. Yuklanish va xato ===================== */

.pm-skeleton { display: none; flex-direction: column; gap: 14px; padding: 0 32px 32px; }
.podcast-modal[data-loading] .pm-skeleton { display: flex; }
.podcast-modal[data-loading] .pm-body { display: none; }
.pm-skeleton-media { height: 0; padding-top: 56.25%; margin: 0 -32px 14px; }
.pm-skeleton-line { height: 16px; border-radius: 8px; }
.pm-skeleton-line--chip { width: 180px; height: 26px; border-radius: 999px; }
.pm-skeleton-line--title { width: 72%; height: 30px; }
.pm-skeleton-line--short { width: 46%; }
.pm-skeleton-media,
.pm-skeleton-line {
  background: linear-gradient(90deg, #eef1f5 25%, #f7f9fb 50%, #eef1f5 75%);
  background-size: 400% 100%;
  animation: pm-shimmer 1.4s ease-in-out infinite;
}
@keyframes pm-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  .pm-skeleton-media, .pm-skeleton-line { animation: none; }
}

.pm-error {
  margin: 0;
  padding: 28px 32px 32px;
  font-size: 15px;
  color: #c0392b;
}

/* ===================== 5. Tor ekran ===================== */

@media (max-width: 767.98px) {
  /* Telefonda — pastdan chiqadigan varaq: ekranning yuqori qismi ochiq
     qoladi, yopish uchun panelni pastga surish tabiiy his beradi. */
  .podcast-modal { align-items: flex-end; padding: 0; }
  .podcast-modal-panel {
    width: 100%;
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
  }
  .pm-content { gap: 14px; padding: 20px 18px 28px; }
  /* Reel modali telefonda — deyarli butun ekran: kadr bo'y bo'ylab cho'ziladi,
     yozuv esa pastda gradient ustida qoladi. */
  .podcast-modal[data-kind="reel"] .podcast-modal-panel {
    width: 100%;
    height: 92vh;
    aspect-ratio: auto;
    border-radius: 20px 20px 0 0;
  }
  .pm-reel-overlay { padding: 56px 18px 58px; }
  .pm-reel-title { font-size: 17px; }
  .pm-title { font-size: 22px; }
  .pm-text { font-size: 15px; }
  .pm-skeleton { padding: 0 18px 28px; }
  .pm-skeleton-media { margin: 0 -18px 14px; }
  .pm-error { padding: 20px 18px 28px; }
  .pm-close { top: 12px; right: 12px; }
}
