/* ================= GLOBAL ================= */
body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: #000;
  color: #fff;
  overflow: hidden;
}

/* ================= LOADING ================= */
#loading {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-container {
  text-align: center;
}

.loading-text {
  margin-top: 20px;
  font-size: 16px;
}

/* ================= LAPISAN PEMUTAR ================= */
#player {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  z-index: 1;
}

#x-matroska {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 2;
  pointer-events: none;
}

/* ================= PLYR ================= */
.plyr {
  width: 100% !important;
  height: 100% !important;
  z-index: 5;
}

.plyr__video-wrapper {
  width: 100% !important;
  height: 100% !important;
}

.plyr__controls {
  position: relative;
  z-index: 1500 !important;
}

/* ================= INFO PLAYLIST ================= */
#playlist-info {
  position: fixed;
  top: 20px;
  right: 20px;
  max-width: 80vw;
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.75);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 900;
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ================= INFO KUALITAS ================= */
.quality-sync {
  position: fixed;
  top: 20px;
  left: 20px;
  background: rgba(0, 168, 255, 0.9);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  z-index: 900;
  pointer-events: none;
}

/* ================= TOMBOL KONTROL ================= */
#button-container {
  position: fixed;
  right: 20px;
  bottom: 140px;
  z-index: 1100;
  display: flex;
  gap: 10px;
}

.video-button {
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: bold;
  transition: all 0.25s;
}

.video-button:hover {
  background: rgba(0, 0, 0, 0.9);
  transform: scale(1.05);
}

/* ================= KOTAK INFO ================= */
#info-box {
  position: fixed;
  bottom: 90px;
  left: 10px;
  right: 10px;
  max-height: 58vh;
  background: rgba(0, 0, 0, 0.92);
  color: #fff;
  padding: 12px;
  border-radius: 8px;
  z-index: 1600;
  display: none;
  overflow: hidden; /* penting: mencegah scroll ganda */
}

/* animasi tampil */
#info-box.show {
  display: block;
  animation: infoFade 0.25s ease;
}

@keyframes infoFade {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ================= BAGIAN DALAM ================= */
.info-inner {
  display: flex;
  gap: 12px;
  max-height: 100%;
  min-height: 0; /* penting */
}

/* ================= POSTER ================= */
.info-poster {
  flex-shrink: 0;
  border-radius: 6px;
  object-fit: cover;
}

/* Desktop besar */
@media (min-width: 1200px) {
  .info-poster {
    width: 160px;
    height: 230px;
  }
}

/* Desktop kecil / tablet */
@media (min-width: 768px) and (max-width: 1199px) {
  .info-poster {
    width: 140px;
    height: 200px;
  }
}

/* Tablet besar / HP kecil */
@media (min-width: 480px) and (max-width: 767px) {
  .info-poster {
    width: 120px;
    height: 170px;
  }
}

/* HP kecil */
@media (max-width: 479px) {
  .info-poster {
    width: 100px;
    height: 145px;
  }
}

/* ================= TEKS ================= */
.info-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* WAJIB */
  overflow: hidden;
  max-height: 100%; /* TAMBAHKAN INI */
}

/* ================= META ================= */
.info-meta {
  list-style: none;
  padding: 0;
  margin: 0 0 10px 0;
  font-size: 13px;
  flex-shrink: 0;
}

.info-meta li {
  margin-bottom: 4px;
}

/* ================= SINOPSIS (AREA SCROLL) ================= */
.info-synopsis {
  margin-top: 6px;
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
  
  /* Scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: #555 transparent;
  
  /* FIX UNTUK LANDSCAPE: berikan batasan tinggi minimum/maksimum */
  min-height: 80px;
  max-height: calc(58vh - 150px); /* Hitungan dinamis berdasarkan tinggi kotak */
}

.info-synopsis::-webkit-scrollbar {
  width: 6px;
}

.info-synopsis::-webkit-scrollbar-track {
  background: transparent;
}

.info-synopsis::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 4px;
}

.info-synopsis::-webkit-scrollbar-thumb:hover {
  background: #666;
}

.synopsis-content {
  font-size: 14px;
  line-height: 1.5;
  padding-bottom: 4px;
  /* PERTAHANKAN BARIS BARU DAN SPASI */
  white-space: pre-wrap; /* Ini yang penting! */
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* ================= TOMBOL TUTUP ================= */
.info-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.info-close:hover {
  background: rgba(0, 0, 0, 0.85);
}

/* ================= PEMILIH EPISODE ================= */
#episode-selector {
  position: fixed;
  right: 20px;
  bottom: 200px;
  z-index: 1200;
  background: rgba(0, 0, 0, 0.85);
  padding: 10px;
  border-radius: 8px;
  display: none;
  width: 220px;
  max-height: 180px;
  overflow-y: auto;
}

.episode-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.episode-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.episode-item.active {
  background: rgba(59, 130, 246, 0.5);
  font-weight: bold;
}

/* ================= MODE EMBED ================= */
.embed-mode #button-container,
.embed-mode #episode-selector,
.embed-mode #playlist-info,
.embed-mode .quality-sync {
  display: none !important;
}

.embed-mode #info-box {
  display: none !important;
}

.embed-mode .plyr__controls {
  z-index: 5 !important;
}

/* ================= RESPONSIF ================= */

/* Mode landscape (lebar lebih besar dari tinggi) */
@media (orientation: landscape) {
  #info-box {
    max-height: 75vh; /* Tinggi lebih besar di landscape */
    bottom: 60px;
  }
  
  .info-inner {
    max-height: 70vh;
  }
  
  .info-synopsis {
    max-height: calc(70vh - 180px) !important; /* Lebih tinggi di landscape */
  }
  
  /* Atur ulang poster di landscape */
  .info-poster {
    width: 140px !important;
    height: 200px !important;
  }
}

/* Mode portrait (tinggi lebih besar dari lebar) */
@media (orientation: portrait) {
  #info-box {
    max-height: 58vh; /* Tinggi lebih kecil di portrait */
  }
  
  .info-synopsis {
    max-height: calc(58vh - 200px) !important;
  }
}

/* Tablet dan desktop kecil */
@media (max-width: 768px) {
  #playlist-info {
    top: 10px;
    right: 10px;
    font-size: 12px;
    padding: 6px 12px;
  }

  .quality-sync {
    top: 10px;
    left: 10px;
    font-size: 12px;
  }

  #button-container {
    bottom: 160px;
  }

  #episode-selector {
    bottom: 220px;
    width: 200px;
  }
  
  /* Responsif untuk info box di mobile */
  #info-box {
    bottom: 80px;
    max-height: 65vh;
  }
  
  .info-synopsis {
    max-height: calc(65vh - 160px) !important;
  }
}

/* HP kecil */
@media (max-width: 479px) {
  #info-box {
    bottom: 70px;
    max-height: 70vh;
  }
  
  .info-inner {
    gap: 10px;
  }
  
  .info-synopsis {
    max-height: calc(70vh - 170px) !important;
  }
  
  .synopsis-content {
    font-size: 13px; /* Sedikit lebih kecil di mobile */
  }
}

/* ================= KOTAK ERROR ================= */
#error-box {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  opacity: 1;
  transition: opacity 0.4s ease;
}

#error-box a {
  color: #4ea3ff;
}

#error-box[hidden] {
  opacity: 0;
  pointer-events: none;
}