/* =====================================================================
   Kinolar — Telegram Mini App.
   Qorong'i ko'k fon + oltin urg'u. Telefon uchun yozilgan (mobile-first).
   ===================================================================== */

:root {
  --bg: #070b1f;
  --bg-2: #0d1330;
  --card: #141a36;
  --card-2: #1b2244;
  --line: #262d50;
  --gold: #e9b949;
  --gold-soft: #f3d98a;
  --gold-deep: #3d3217;
  --text: #f5f0e4;
  --muted: #8d92ae;
  --red: #ef4b5b;
  --green: #35c27a;
  --radius: 16px;
  --gutter: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --cta-h: 64px;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  background:
    radial-gradient(120% 60% at 50% -10%, #1a2250 0%, transparent 60%),
    var(--bg);
  min-height: 100vh;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:disabled { opacity: .55; cursor: default; }
input { font: inherit; color: inherit; }

.hidden { display: none !important; }
.muted { color: var(--muted); }

#app { padding: 12px var(--gutter) calc(32px + var(--safe-bottom)); max-width: 720px; margin: 0 auto; }

/* ------------------------------------------------------------ sarlavha */

.top { display: flex; align-items: center; gap: 10px; }

.btn-gold {
  display: inline-flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 18px; border-radius: 15px;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: #1a1405; font-weight: 700; font-size: 16px;
  box-shadow: 0 6px 18px rgba(233, 185, 73, .28);
}
.btn-gold:active { transform: scale(.97); }

.tabs {
  flex: 1; min-width: 0; display: flex; gap: 6px; padding: 4px;
  border: 1px solid var(--line); border-radius: 18px; background: rgba(13, 19, 48, .7);
}
.tab {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 13px; font-weight: 700; color: var(--muted);
}
.tab.active { background: linear-gradient(180deg, var(--gold-soft), var(--gold)); color: #1a1405; flex: 1; }

.btn-heart {
  width: 46px; height: 46px; border-radius: 15px; flex: none;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(180deg, #ff6f7d, var(--red));
  box-shadow: 0 6px 18px rgba(239, 75, 91, .3);
  transition: transform .15s;
}
.btn-heart:active { transform: scale(.94); }
.btn-heart.on { outline: 2px solid var(--gold-soft); outline-offset: 2px; }

.count { margin: 10px 2px 12px; font-size: 14px; }

/* -------------------------------------------------------------- qidiruv */

.search {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 6px 6px 6px 14px; border-radius: 18px;
  background: var(--card); border: 1px solid var(--line);
}
.search:focus-within { border-color: var(--gold); }
.search-ico { color: var(--muted); flex: none; }
.search input {
  flex: 1; min-width: 0; height: 44px; border: 0; outline: 0; background: transparent;
  font-size: 17px; -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }
.btn-dice {
  width: 48px; height: 48px; border-radius: 14px; flex: none; display: grid; place-items: center;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold)); color: #1a1405;
}
.btn-dice:active { transform: rotate(-14deg) scale(.95); }

/* ----------------------------------------------------------------- chips */

.chips {
  display: flex; gap: 10px; overflow-x: auto; padding: 14px var(--gutter) 6px;
  margin: 0 calc(var(--gutter) * -1); scrollbar-width: none;
  scroll-snap-type: x proximity; scroll-padding-left: var(--gutter);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 42px; padding: 0 18px; border-radius: 999px; scroll-snap-align: start;
  border: 1px solid var(--line); background: rgba(20, 26, 54, .8);
  font-weight: 700; font-size: 16px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: linear-gradient(180deg, var(--gold-soft), var(--gold)); color: #1a1405; border-color: transparent; }
.chip.section { border-color: var(--gold); color: var(--gold-soft); }
.chip.section .x { opacity: .8; font-size: 18px; line-height: 1; }

/* --------------------------------------------------------------- bo'limlar */

.section-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin: 22px 2px 12px;
}
.section-title h2 { margin: 0; font-size: 26px; letter-spacing: -.3px; }
.section-title .note { color: var(--muted); font-size: 14px; white-space: nowrap; }

/* ---------------------------------------------------------------- kartalar */

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.card { display: block; width: 100%; text-align: left; min-width: 0; }
.card:active { transform: scale(.97); }

.poster {
  position: relative; aspect-ratio: 2 / 3; border-radius: 18px; overflow: hidden;
  background: var(--card); isolation: isolate;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .35);
}
.poster .ph {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 12px;
  text-align: center; font-weight: 800; font-size: 15px; line-height: 1.2; color: rgba(255, 255, 255, .92);
  text-shadow: 0 2px 10px rgba(0, 0, 0, .45); word-break: break-word;
}
.poster img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .25s;
}
.poster img.loaded { opacity: 1; }
.poster .ph { transition: opacity .25s; }
.poster.has-img .ph { opacity: 0; }
.poster::after {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,.28) 0, transparent 30%, transparent 62%, rgba(0,0,0,.55) 100%);
}

.badge {
  position: absolute; z-index: 2; font-size: 13px; font-weight: 800; line-height: 1;
  padding: 6px 10px; border-radius: 999px; background: rgba(40, 46, 70, .78); white-space: nowrap;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); color: #fff;
}
.badge.code { top: 8px; left: 8px; }
.badge.epc { left: 8px; bottom: 8px; }
.badge.done {
  top: 8px; right: 8px; width: 26px; height: 26px; padding: 0; display: grid; place-items: center;
  background: var(--green); font-size: 14px;
}

.card .name {
  margin-top: 8px; font-size: 15px; font-weight: 600; color: #d9d6cc;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.25;
}

/* ----------------------------------------------------------------- Top 10 */

.rail {
  display: flex; gap: 14px; overflow-x: auto; padding: 4px var(--gutter) 10px;
  margin: 0 calc(var(--gutter) * -1); scrollbar-width: none; scroll-snap-type: x proximity;
  scroll-padding-left: var(--gutter);
}
.rail::-webkit-scrollbar { display: none; }
.rail .card { flex: none; width: 150px; scroll-snap-align: start; }
.rail .poster { border-radius: 20px; }
.rank {
  position: absolute; z-index: 3; right: 8px; bottom: -4px; font-size: 54px; font-weight: 900; line-height: 1;
  color: transparent; -webkit-text-stroke: 2.5px var(--gold); letter-spacing: -3px;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, .6));
}
.rail .card:first-child .poster { outline: 2px solid var(--gold); outline-offset: -2px; }
.rail .badge.epc { display: none; } /* raqam bilan ustma-ust tushmasin */

/* ---------------------------------------------------------- holat xabarlari */

.state { text-align: center; padding: 56px 24px; color: var(--muted); }
.state .big { font-size: 42px; margin-bottom: 8px; }
.state b { color: var(--text); display: block; font-size: 17px; margin-bottom: 6px; }
.state button {
  margin-top: 16px; height: 42px; padding: 0 22px; border-radius: 14px; font-weight: 700;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold)); color: #1a1405;
}

.skel { aspect-ratio: 2 / 3; border-radius: 18px; background: linear-gradient(100deg, var(--card) 30%, var(--card-2) 50%, var(--card) 70%); background-size: 300% 100%; animation: shimmer 1.3s infinite linear; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

#sentinel { height: 1px; }

.credit { margin: 28px 4px 0; text-align: center; font-size: 12px; color: var(--muted); opacity: .75; }
.credit a { color: inherit; text-decoration: underline; }

/* -------------------------------------------------------------- asar sahifasi */

.detail {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto; background: var(--bg);
  padding-bottom: calc(var(--cta-h) + 40px + var(--safe-bottom)); animation: slide .22s ease-out;
}
@keyframes slide { from { transform: translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }

.hero { position: relative; padding: 18px var(--gutter) 6px; text-align: center; overflow: hidden; }
.hero .bg {
  position: absolute; inset: -30px; z-index: 0; background-size: cover; background-position: center;
  filter: blur(34px) saturate(1.3); opacity: .55; transform: scale(1.1);
}
.hero::after { content: ""; position: absolute; inset: 0; z-index: 0; background: linear-gradient(180deg, transparent 40%, var(--bg) 100%); }
.hero > * { position: relative; z-index: 1; }
.hero .poster { width: min(62vw, 270px); margin: 6px auto 0; border-radius: 22px; box-shadow: 0 18px 50px rgba(0, 0, 0, .55); }

.back {
  position: absolute; z-index: 5; top: 12px; left: 12px; width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center; background: rgba(13, 19, 48, .7); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px); border: 1px solid var(--line);
}
.fav-toggle {
  position: absolute; z-index: 5; top: 12px; right: 12px; width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center; background: rgba(13, 19, 48, .7); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px); border: 1px solid var(--line); color: var(--muted);
  transition: transform .15s, color .15s;
}
.fav-toggle.on { color: var(--red); border-color: var(--red); }
.fav-toggle:active { transform: scale(.9); }

.detail h1 { margin: 18px var(--gutter) 12px; text-align: center; font-size: 30px; line-height: 1.15; letter-spacing: -.4px; }

.facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; padding: 0 var(--gutter); }
.fact {
  display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(20, 26, 54, .85); font-weight: 700;
}

.info { padding: 0 var(--gutter); margin-top: 18px; }
.info hr { border: 0; height: 2px; width: 160px; background: var(--line); margin: 0 0 14px; }
.info p { margin: 6px 0; font-size: 17px; }
.about { white-space: pre-line; color: #d6d3ca; }
.about.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.more { margin-top: 8px; color: var(--gold); font-weight: 700; font-size: 17px; }

.eps-title { margin: 26px var(--gutter) 12px; font-size: 24px; display: flex; align-items: center; gap: 10px; }
.season { margin: 14px var(--gutter) 8px; color: var(--muted); font-weight: 700; font-size: 14px; text-transform: uppercase; letter-spacing: .6px; }
.eps { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; padding: 0 var(--gutter); }
.ep {
  height: 54px; border-radius: 14px; background: var(--card); border: 1px solid var(--line);
  font-size: 20px; font-weight: 800;
}
.ep:active { transform: scale(.94); }
.ep.watched { background: var(--gold-deep); border-color: #6a5320; color: var(--gold-soft); }
.ep.sending { animation: pulse .8s infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: .45; } }

.cta-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; padding: 12px var(--gutter) calc(12px + var(--safe-bottom));
  background: linear-gradient(180deg, transparent, rgba(7, 11, 31, .94) 28%);
}
.cta {
  width: 100%; height: 56px; border-radius: 18px; font-size: 19px; font-weight: 800; color: #1a1405;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold)); box-shadow: 0 10px 28px rgba(233, 185, 73, .3);
}
.cta:active { transform: scale(.985); }

/* ------------------------------------------------------------------ drawer */

.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .55); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 82vh; overflow-y: auto;
  padding: 10px var(--gutter) calc(24px + var(--safe-bottom)); border-radius: 26px 26px 0 0;
  background: var(--bg-2); border-top: 1px solid var(--line); animation: sheet .24s ease-out;
}
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.drawer h3 { margin: 16px 2px 10px; font-size: 18px; }
.drawer .opts { display: flex; flex-wrap: wrap; gap: 10px; }
.opt {
  height: 42px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  font-weight: 700; display: inline-flex; align-items: center; gap: 8px;
}
.opt small { color: var(--muted); font-weight: 600; }
.opt.active { border-color: var(--gold); color: var(--gold-soft); }

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--cta-h) + 34px + var(--safe-bottom)); z-index: 60;
  transform: translate(-50%, 12px); max-width: min(86vw, 420px); padding: 14px 20px; border-radius: 18px;
  background: #f4ecdc; color: #1b1810; font-size: 17px; font-weight: 700; text-align: center;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .5); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #ffe2e4; color: #6b0f1a; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
