/* KinoOqimi Mini App — kinematik qorong'i uslub (YANGI.TV ilhomida). */

:root {
  --bg: #0a0b10;
  --bg-soft: #12141d;
  --bg-card: #171a26;
  --text: #f2f3f7;
  --text-dim: #9aa0b4;
  --accent: #f5b942;
  --accent-red: #e5322d;
  --radius: 14px;
}

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

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

.hidden { display: none !important; }

.view { min-height: 100vh; padding-bottom: 32px; }

/* ================= TOPBAR ================= */

.topbar {
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 16px 4px;
  animation: fadeDown .5s ease both;
}
.brand { font-size: 20px; font-weight: 800; letter-spacing: .5px; }
.brand span { background: linear-gradient(90deg, var(--accent), #f58442); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

.search-wrap { position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-dim); }
#search-input {
  width: 100%; padding: 12px 14px 12px 40px;
  background: var(--bg-soft); color: var(--text);
  border: 1px solid #232636; border-radius: 12px;
  font-size: 15px; outline: none; transition: border-color .2s, box-shadow .2s;
  -webkit-appearance: none;
}
#search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(245,185,66,.12); }
#search-input::placeholder { color: var(--text-dim); }

/* ================= HERO KARUSEL ================= */

.hero {
  position: relative; margin: 12px 16px 4px;
  height: 210px; border-radius: 18px; overflow: hidden;
  background: var(--bg-card);
  animation: heroIn .7s cubic-bezier(.2,.9,.3,1) both;
  box-shadow: 0 12px 34px rgba(0,0,0,.45);
  /* Gorizontal svayp JS orqali ushlanadi, vertikal sahifa skrolli buzilmasin. */
  touch-action: pan-y;
}
.hero-track { position: absolute; inset: 0; }
.hero-slide {
  position: absolute; inset: 0; overflow: hidden;
  opacity: 0; transform: scale(1.06);
  transition: opacity .8s ease, transform 6s linear;
  /* Nofaol slaydlar bosilmasin — aks holda barchasi ustma-ust turgani uchun
     DOIM eng oxirgi (DOM tartibida yuqoridagi) slayd bosilib, qaysi rasmga
     bossang ham bitta xato filmni ochib qo'yardi. Faqat .active bosiladigan
     qilib qo'yamiz. */
  pointer-events: none;
}
.hero-slide.active { opacity: 1; transform: scale(1); pointer-events: auto; }
.hero-slide-placeholder {
  display: flex; align-items: center; justify-content: center; font-size: 54px;
}
/* Orqa fon: xiralashtirilgan "cover" nusxa — butun (gorizontal) qutini
   chiroyli, bo'sh joysiz to'ldiradi (muallif talabi: "rasmlar har doim
   to'liq holatda chiroyli tiniq bo'lib ko'rinishi kerak"). */
.hero-slide-bg {
  position: absolute; inset: -20px;
  background-size: cover; background-position: center;
  filter: blur(26px) brightness(.55) saturate(1.15);
  transform: scale(1.15);
}
/* Old plan: rasmning O'ZI — "contain" bilan, HECH QACHON kesilmaydi.
   Vertikal (2:3) poster ham to'liq va tiniq ko'rinadi (yon tomonlar xira fon). */
.hero-slide-fg {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 10px 26px rgba(0,0,0,.55));
}
/* Haqiqiy GORIZONTAL (16:9 TMDB backdrop) rasm bo'lsa — slaydni TO'LIQ
   to'ldiradi (cover), ikki cheti bo'sh qolmaydi (muallif talabi:
   "rasmlar ikki cheti bosh full emas — full bo'lishi kerak"). Backdrop
   nisbati slayd bilan deyarli bir xil (~16:9), shuning uchun kesilish
   sezilmaydi; xira fon ham ko'rinmay qoladi. */
.hero-slide-filled .hero-slide-fg { object-fit: cover; filter: none; }
.hero-gradient {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(10,11,16,0) 30%, rgba(10,11,16,.55) 70%, rgba(10,11,16,.92) 100%);
}
.hero-info { position: absolute; left: 16px; right: 16px; bottom: 14px; pointer-events: none; }
.hero-title {
  font-size: 15px; font-weight: 700; text-shadow: 0 2px 10px rgba(0,0,0,.7);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hero-dots { position: absolute; bottom: 10px; left: 0; right: 0; display: flex; gap: 6px; justify-content: center; }
.hero-dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.35); transition: all .3s; }
.hero-dot.active { background: var(--accent-red); width: 16px; border-radius: 4px; }

/* ================= JANR CHIPLAR ================= */

.genre-chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 14px 16px 6px;
  scrollbar-width: none;
}
.genre-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 8px 16px;
  background: var(--bg-soft); border: 1px solid #232636;
  border-radius: 999px; font-size: 13.5px; font-weight: 600; color: var(--text-dim);
  cursor: pointer; transition: all .25s; user-select: none;
}
.chip.active {
  background: linear-gradient(135deg, var(--accent), #f58442);
  color: #1a1204; border-color: transparent;
  box-shadow: 0 4px 14px rgba(245,185,66,.35);
  transform: translateY(-1px);
}
/* Admin uchun "🎬 Slayd" boshqaruv bo'limi — oddiy janrlardan ajralib tursin. */
.chip-featured { border-color: rgba(229,50,45,.45); color: #ff8f8b; }
.chip-featured.active {
  background: linear-gradient(135deg, var(--accent-red), #f04641);
  color: #fff;
  box-shadow: 0 4px 14px rgba(229,50,45,.35);
}
/* "📺 Seriallar" — hammaga ko'rinadigan bo'lim, oddiy janrlardan ajralib tursin. */
.chip-series { border-color: rgba(66,181,245,.45); color: #8fd0ff; }
.chip-series.active {
  background: linear-gradient(135deg, #42b5f5, #2f8fd6);
  color: #06202e;
  box-shadow: 0 4px 14px rgba(66,181,245,.35);
}

/* Kartochkada serial belgisi (muallif talabi: foydalanuvchi bu ko'p
   qismli serial ekanligini darhol bilishi kerak). */
.poster-series-badge {
  position: absolute; left: 7px; bottom: 7px; z-index: 2;
  padding: 3px 8px; border-radius: 8px;
  background: rgba(47,143,214,.85); backdrop-filter: blur(6px);
  font-size: 10px; font-weight: 800; color: #fff;
}

.section-title { font-size: 16px; font-weight: 800; padding: 12px 16px 2px; }

/* ================= GRID ================= */

.grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  /* stretch (default) o'rniga start: qatordagi eng baland kartochka
     boshqalarni ham cho'zib, ularni "kattaroq" ko'rsatib qo'ymasin —
     har kartochka o'z tabiiy balandligida qoladi. */
  align-items: start;
  gap: 12px; padding: 12px 16px;
}
@media (min-width: 520px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.movie-card {
  cursor: pointer;
  animation: cardIn .55s cubic-bezier(.2,.9,.3,1) both;
  transition: transform .18s ease;
}
.movie-card:active { transform: scale(.94); }

.poster-frame {
  position: relative;
  width: 100%;
  /* padding-top foiz nisbati — HAR DOIM ustunning eniga nisbatan hisoblanadi,
     shu sabab `aspect-ratio`ni qo'llab-quvvatlamaydigan (yoki noto'g'ri
     qo'llaydigan) eski Telegram WebView'larda ham 2:3 nisbat barqaror
     bo'ladi. Aynan shu — turli qurilmalarda "kino o'lchamlari o'zgarib
     ketyabdi" muammosining ehtimoliy sababi edi: `aspect-ratio` yagona
     tayanch bo'lganda ba'zi webview'lar rasmning tabiiy o'lchamiga qaytib
     ketardi.
     */
  padding-top: 150%;
  border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(160deg, #1b1e2d, #12141d);
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
}
.poster-frame img,
.poster-frame .poster-placeholder {
  position: absolute; inset: 0;
}
.poster-frame img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s ease; }
.movie-card:active .poster-frame img { transform: scale(1.07); }
.poster-placeholder { display: flex; align-items: center; justify-content: center; font-size: 34px; opacity: .6; }

/* O'ng-yuqori USTUN: "⋮" menyu, uning tagida yurakcha (muallif talabi:
   "yurakchani 3 nuqta tagiga qo'yib qo'y"). Tashqi nomzod uchun "kanaldan"
   belgisi ham shu ustunda (ular birga chiqmaydi, hech qanday ustma-ustlik yo'q). */
.poster-top-right {
  position: absolute; top: 7px; right: 7px; z-index: 2;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
.poster-badge {
  padding: 3px 8px; border-radius: 8px;
  background: rgba(10,11,16,.75); backdrop-filter: blur(6px);
  font-size: 10.5px; font-weight: 700; color: var(--accent);
}

/* "Saqlash" yurakchasi — barcha foydalanuvchiga ko'rinadi, endi "⋮" menyu
   tagida (o'ng-yuqori ustunda, poster-top-right'ning oddiy flex farzandi
   sifatida — shuning uchun endi absolute pozitsiya shart emas). */
.card-heart {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: rgba(10,11,16,.6); backdrop-filter: blur(6px);
  border: none; display: flex; align-items: center; justify-content: center;
  font-size: 13px; cursor: pointer; transition: transform .15s;
  color: #fff;
}
.card-heart:active { transform: scale(.85); }
.card-heart.saved { color: var(--accent-red); }

/* Admin: kartochka menyusi ("⋮" — o'chirish/tahrirlash). */
.card-menu-btn {
  width: 22px; height: 22px; border-radius: 7px;
  background: rgba(10,11,16,.75); backdrop-filter: blur(6px);
  border: none; color: var(--text); font-size: 15px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; line-height: 1; padding: 0;
}
.card-menu-btn:active { transform: scale(.85); }
.card-title {
  margin-top: 7px; font-size: 12.5px; font-weight: 700; line-height: 1.25;
  /* min-height = doim 2 qator joyi — 1 qatorli va 2 qatorli nomlar
     kartochka balandligini har xil qilib qo'ymasin (bir xil tekis panjara). */
  min-height: 2.5em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* ================= BO'SH HOLAT / LOADER ================= */

.empty-state { text-align: center; padding: 46px 20px; color: var(--text-dim); }
.empty-emoji { font-size: 42px; margin-bottom: 8px; }

.sentinel { height: 2px; }
.grid-loader { display: flex; justify-content: center; padding: 18px; }

.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid #232636; border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.spinner.big { width: 40px; height: 40px; }

.full-loader {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,11,16,.82); backdrop-filter: blur(4px);
}

/* ================= DETAL EKRAN ================= */

#detail-view { animation: detailIn .45s cubic-bezier(.2,.9,.3,1) both; }

.detail-poster-wrap { position: relative; height: 46vh; min-height: 300px; overflow: hidden; background: var(--bg-card); }
.detail-poster { width: 100%; height: 100%; object-fit: cover; display: block; animation: heroZoom 8s ease both; }
.detail-poster-placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 72px; opacity: .5; }
.detail-poster-gradient {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(10,11,16,.25) 0%, rgba(10,11,16,0) 30%, rgba(10,11,16,.6) 75%, var(--bg) 100%);
}
.back-fab {
  position: absolute; top: 14px; left: 14px; z-index: 5;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(10,11,16,.6); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.12); color: var(--text);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: transform .15s;
}
.back-fab:active { transform: scale(.9); }
.back-fab svg { width: 20px; height: 20px; }

.detail-save-fab {
  position: absolute; top: 14px; right: 14px; z-index: 5;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(10,11,16,.6); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.12); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: transform .15s; font-size: 18px;
}
.detail-save-fab:active { transform: scale(.9); }
.detail-save-fab.saved { color: var(--accent-red); }

.detail-content { padding: 4px 18px 40px; margin-top: -34px; position: relative; }
.detail-title { font-size: 25px; font-weight: 800; line-height: 1.2; animation: fadeUp .5s .05s ease both; }

.detail-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; animation: fadeUp .5s .12s ease both; }
.meta-pill {
  padding: 6px 12px; border-radius: 10px;
  background: var(--bg-soft); border: 1px solid #232636;
  font-size: 12.5px; font-weight: 600; color: #cdd1de;
}

.detail-rating { margin-top: 12px; font-size: 15px; font-weight: 700; color: var(--accent); animation: fadeUp .5s .18s ease both; }
.rating-count { color: var(--text-dim); font-weight: 500; font-size: 13px; }

.watch-btn {
  width: 100%; margin-top: 18px; padding: 16px;
  background: linear-gradient(135deg, #f04641, var(--accent-red));
  border: none; border-radius: 14px; color: #fff;
  font-size: 16px; font-weight: 800; letter-spacing: .6px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  cursor: pointer; box-shadow: 0 8px 24px rgba(229,50,45,.35);
  transition: transform .15s, box-shadow .2s;
  animation: fadeUp .5s .24s ease both;
  font-family: inherit;
}
.watch-btn:active { transform: scale(.97); box-shadow: 0 4px 12px rgba(229,50,45,.3); }
.watch-btn-icon { font-size: 14px; }
.watch-btn.loading { opacity: .7; pointer-events: none; }

.detail-section-title { margin-top: 22px; font-size: 15.5px; font-weight: 800; animation: fadeUp .5s .3s ease both; }
.detail-description { margin-top: 8px; font-size: 14.5px; line-height: 1.65; color: #c9cddb; animation: fadeUp .5s .34s ease both; }

/* ================= ANIMATSIYALAR ================= */

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

@keyframes fadeDown { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

@keyframes heroIn {
  from { opacity: 0; transform: translateY(18px) scale(.96); }
  to { opacity: 1; transform: none; }
}
@keyframes heroZoom { from { transform: scale(1.08); } to { transform: scale(1); } }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(22px) scale(.92); }
  to { opacity: 1; transform: none; }
}

@keyframes detailIn {
  from { opacity: 0; transform: translateY(6vh) scale(.98); }
  to { opacity: 1; transform: none; }
}

/* ================= ADMIN BOSHQARUVI ================= */
/* Faqat admin foydalanuvchida ko'rinadi (app.js state.isAdmin). Server ham
   har o'chirish so'rovini qayta tekshiradi — bu faqat qulaylik. */

.admin-genre-bar { margin: 4px 0 14px; animation: fadeUp .4s ease both; }
.admin-genre-delete {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid rgba(229, 50, 45, .5);
  background: rgba(229, 50, 45, .12);
  color: #ff6b66;
  font-size: 13.5px;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.admin-genre-delete:active { transform: scale(.98); background: rgba(229, 50, 45, .22); }

.admin-delete-btn {
  margin-top: 24px;
  width: 100%;
  padding: 13px 16px;
  border: 1px solid rgba(229, 50, 45, .55);
  background: rgba(229, 50, 45, .12);
  color: #ff6b66;
  font-size: 14px;
  font-weight: 800;
  border-radius: 14px;
  cursor: pointer;
  transition: background .15s, transform .1s;
  animation: fadeUp .5s .38s ease both;
}
.admin-delete-btn:active { transform: scale(.98); background: rgba(229, 50, 45, .22); }

.admin-edit-btn {
  margin-top: 18px;
  width: 100%;
  padding: 13px 16px;
  border: 1px solid rgba(245, 185, 66, .5);
  background: rgba(245, 185, 66, .1);
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
  border-radius: 14px;
  cursor: pointer;
  transition: background .15s, transform .1s;
  animation: fadeUp .5s .36s ease both;
}
.admin-edit-btn:active { transform: scale(.98); background: rgba(245, 185, 66, .2); }

/* ================= ADMIN "⋮" MENYU / TAHRIRLASH MODAL ================= */

.sheet-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .2s ease both;
}
.sheet {
  width: 100%; max-width: 520px;
  background: var(--bg-card); border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  animation: sheetUp .3s cubic-bezier(.2,.9,.3,1) both;
}
.sheet-handle { width: 40px; height: 4px; border-radius: 3px; background: #3a3f52; margin: 6px auto 14px; }
.sheet-title { font-size: 16px; font-weight: 800; margin-bottom: 12px; }
.sheet-item {
  width: 100%; padding: 14px; margin-bottom: 8px;
  background: var(--bg-soft); border: 1px solid #232636; border-radius: 12px;
  color: var(--text); font-size: 14.5px; font-weight: 600; text-align: left;
  cursor: pointer; font-family: inherit; display: flex; align-items: center; gap: 10px;
}
.sheet-item:active { background: #1c2030; }
.sheet-item.danger { color: #ff6b66; border-color: rgba(229,50,45,.4); }
.sheet-label { display: block; font-size: 12.5px; color: var(--text-dim); margin: 10px 2px 6px; font-weight: 600; }
.sheet-input, .sheet-textarea {
  width: 100%; padding: 12px 14px; background: var(--bg-soft); color: var(--text);
  border: 1px solid #232636; border-radius: 12px; font-size: 14.5px; font-family: inherit;
  outline: none; transition: border-color .2s;
}
.sheet-input:focus, .sheet-textarea:focus { border-color: var(--accent); }
.sheet-textarea { resize: vertical; min-height: 84px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-btn {
  flex: 1; padding: 13px; border: none; border-radius: 12px; font-size: 14.5px;
  font-weight: 800; cursor: pointer; font-family: inherit;
}
.sheet-btn.primary { background: linear-gradient(135deg, var(--accent), #f58442); color: #1a1204; }
.sheet-btn.ghost { background: var(--bg-soft); color: var(--text-dim); border: 1px solid #232636; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
