/* =============================================
   AIMOVIES — ЗАГВАР
   Өнгөө солих бол зөвхөн :root доторх утгуудыг өөрчил.
   ============================================= */
:root {
  --bg: #0b0d12;          /* арын өнгө */
  --bg-2: #161a22;        /* карт, цонхны өнгө */
  --bg-3: #232833;        /* товч, хайлтын өнгө */
  --line: #2a303c;
  --text: #ffffff;
  --muted: #a3a9b6;
  --red: #ff2a2a;         /* үндсэн улаан */
  --red-dark: #d91c1c;
  --blue: #3d8bff;        /* "Бүгдийг харах" холбоос */
  --gold: #ffc531;        /* одны өнгө */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --title-font: "Playfair Display", Georgia, "Times New Roman", serif;
  --side: max(40px, env(safe-area-inset-left, 0px));
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ============ ТОЛГОЙ ХЭСЭГ ============ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  display: flex; align-items: center; gap: 40px;
  height: 64px;
  padding: env(safe-area-inset-top, 0px) var(--side) 0;
  background: linear-gradient(180deg, rgba(8,9,13,.85), rgba(8,9,13,0));
  transition: background .3s;
}
.topbar.solid { background: rgba(11,13,18,.96); box-shadow: 0 1px 0 var(--line); }

.logo {
  display: flex; align-items: center; gap: 2px;
  font-weight: 800; font-size: 30px; letter-spacing: -0.02em; white-space: nowrap;
}
.logo-ai { color: var(--blue); }
.logo-play { width: 22px; height: 24px; fill: var(--red); margin-left: 6px; }
.logo.small { font-size: 20px; }

.menu { display: flex; align-items: center; gap: 32px; font-weight: 500; font-size: 15px; }
.menu > a, .dropdown-btn {
  position: relative; padding: 20px 0; color: #e7e9ee; display: flex; align-items: center; gap: 6px;
}
.menu > a:hover, .dropdown-btn:hover { color: #fff; }
.menu > a.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 12px;
  height: 3px; border-radius: 2px; background: var(--red);
}
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: 56px; left: -16px; min-width: 200px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; display: grid; gap: 2px; box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
.dropdown-menu a { padding: 9px 12px; border-radius: 6px; font-size: 14px; }
.dropdown-menu a:hover { background: var(--bg-3); }

.top-right { margin-left: auto; display: flex; align-items: center; gap: 18px; position: relative; }
.search {
  display: flex; align-items: center; gap: 10px;
  width: 222px; height: 38px; padding: 0 14px;
  background: rgba(40,44,54,.75); border-radius: 8px; color: var(--muted);
}
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: #fff; font: inherit; font-size: 14px; }
.search input::placeholder { color: var(--muted); }
.icon-btn { position: relative; display: grid; place-items: center; width: 36px; height: 36px; color: #fff; }
.search-toggle { display: none; }
.icon-btn .dot { position: absolute; top: 6px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.btn-red {
  background: var(--red); color: #fff; font-weight: 600; font-size: 14px;
  height: 38px; padding: 0 18px; border-radius: 8px;
}
.btn-red:hover { background: var(--red-dark); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--bg-3); display: grid; place-items: center; color: #fff; }

.notif {
  position: absolute; top: 52px; right: 100px; width: 300px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px;
  box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
.notif h4 { margin: 6px 10px 8px; font-size: 14px; }
.notif button { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 8px 10px; border-radius: 8px; }
.notif button:hover { background: var(--bg-3); }
.notif img { width: 64px; aspect-ratio: 16/9; object-fit: cover; border-radius: 4px; }
.notif small { color: var(--muted); display: block; font-size: 12px; }

/* ============ HERO (дээд том слайд) ============ */
.hero { position: relative; height: 470px; overflow: hidden; }
.slide { position: absolute; inset: 0; opacity: 0; transition: opacity .8s ease; pointer-events: none; }
.slide.on { opacity: 1; pointer-events: auto; }
.slide-bg {
  position: absolute; top: 0; right: 0; bottom: 0; width: 78%;
  background-size: cover; background-position: center 20%;
}
.slide::before { /* зүүн болон доод талын бараан уусалт */
  content: ""; position: absolute; inset: 0; z-index: 1;
  background:
    linear-gradient(90deg, var(--bg) 18%, rgba(11,13,18,.75) 34%, rgba(11,13,18,0) 60%),
    linear-gradient(0deg, var(--bg) 0%, rgba(11,13,18,0) 35%);
}
.slide-info { position: absolute; z-index: 2; left: calc(var(--side) + 70px); bottom: 70px; max-width: 640px; }
.slide-title {
  font-family: var(--title-font); font-weight: 900; text-transform: uppercase;
  font-size: clamp(36px, 5vw, 76px); line-height: 1; margin: 0 0 14px; letter-spacing: .01em;
  background: linear-gradient(180deg, #fff6e6 0%, #e4cfa8 45%, #8c7656 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,.6));
  text-wrap: balance;
}
.tags { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: 15px; font-weight: 500; }
.tag { background: rgba(255,255,255,.14); padding: 2px 8px; border-radius: 4px; font-size: 14px; }
.slide-info p { font-size: 16px; margin: 12px 0 20px; color: #eceef2; max-width: 46ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.btn-play {
  display: inline-flex; align-items: center; gap: 12px;
  background: var(--red); color: #fff; font-weight: 700; font-size: 18px;
  height: 48px; padding: 0 32px; border-radius: 8px;
}
.btn-play:hover { background: var(--red-dark); }
.btn-dark {
  display: inline-flex; align-items: center; gap: 10px;
  background: rgba(40,44,54,.85); color: #fff; font-weight: 600; font-size: 14px;
  height: 48px; padding: 0 16px; border-radius: 8px;
}
.btn-dark:hover { background: rgba(60,65,78,.9); }
.btn-text { display: inline-flex; align-items: center; gap: 10px; font-weight: 500; padding: 0 10px; height: 48px; }

.arrow {
  position: absolute; z-index: 3; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(20,22,28,.6); border: 1px solid rgba(255,255,255,.12);
  display: grid; place-items: center; color: #fff;
}
.arrow:hover { background: rgba(40,44,54,.9); }
.arrow.prev { left: max(16px, env(safe-area-inset-left, 0px)); }
.arrow.next { right: max(16px, env(safe-area-inset-right, 0px)); }
.dots { position: absolute; z-index: 3; right: 88px; bottom: 32px; display: flex; gap: 6px; }
.dots button { width: 20px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.35); }
.dots button.on { background: var(--red); }

/* ============ ЭГНЭЭНҮҮД ============ */
.rows { padding: 0 var(--side); display: grid; gap: 22px; margin-top: -24px; position: relative; z-index: 2; }
.row-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.row-head h2 { margin: 0; font-size: 19px; font-weight: 700; }
.see-all { color: var(--blue); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 4px; }
.see-all:hover { text-decoration: underline; }

.cards { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; }
.grid-page .cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); row-gap: 22px; }

.card { text-align: left; min-width: 0; }
.thumb {
  position: relative; aspect-ratio: 237 / 97; border-radius: 6px; overflow: hidden;
  background: var(--bg-2); transition: transform .25s, box-shadow .25s;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.card:hover .thumb { transform: scale(1.04); box-shadow: 0 10px 28px rgba(0,0,0,.6); }
.badge {
  position: absolute; top: 4px; left: 1px;
  background: #1d2028; color: #fff; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 4px;
}
.card-title { margin-top: 7px; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; gap: 12px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.star { color: var(--gold); }

.page-head { padding: 96px var(--side) 18px; }
.page-head h1 { margin: 0; font-size: 28px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.grid-page { padding: 0 var(--side); }
.empty { color: var(--muted); padding: 40px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; }

/* ============ ДЭЛГЭРЭНГҮЙ ЦОНХ ============ */
.overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  position: relative; width: 100%; max-width: 760px; max-height: 92vh; overflow: auto;
  background: var(--bg-2); border-radius: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.7);
}
.modal-img { position: relative; aspect-ratio: 16 / 7; }
.modal-img img { width: 100%; height: 100%; object-fit: cover; }
.modal-img::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, var(--bg-2), transparent 55%); }
.modal-body { padding: 0 28px 28px; margin-top: -30px; position: relative; z-index: 1; }
.modal-body h2 { margin: 0 0 10px; font-size: 30px; }
.modal-body p { color: #d9dce3; margin: 14px 0; }
.genres { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.genres span { border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; font-size: 13px; color: var(--muted); }
.close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 38px; height: 38px; border-radius: 50%; background: rgba(0,0,0,.6); font-size: 22px; line-height: 1;
}

/* Нэвтрэх */
.login { max-width: 400px; padding: 32px; }
.login h2 { margin: 0 0 4px; }
.login p { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; font-size: 14px; }
.field input {
  height: 44px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: #fff; font: inherit;
}
.field input:focus { outline: none; border-color: var(--blue); }
.login .btn-red { width: 100%; height: 46px; font-size: 15px; margin-top: 6px; }
.form-msg { margin-top: 12px; font-size: 13px; color: var(--gold); }
.form-msg.err { color: #ff7b7b; }
.form-msg.ok { color: #5fd38d; }
.login button:disabled { opacity: .6; cursor: wait; }
.btn-google {
  width: 100%; height: 46px; border-radius: 8px; background: #fff; color: #1f1f1f;
  display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 600; font-size: 15px;
}
.btn-google:hover { background: #eef0f3; }
.or { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.link-btn { color: var(--blue); font-size: 13px; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.link-btn.right { display: block; margin: -4px 0 12px auto; }
.login .switch { text-align: center; margin: 16px 0 0; }

/* Профайл */
.avatar.signed { background: var(--red); font-weight: 700; font-size: 16px; overflow: hidden; }
.avatar.signed img { width: 100%; height: 100%; object-fit: cover; }
.user-menu {
  position: absolute; top: 52px; right: 0; width: 240px; z-index: 50;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px;
  box-shadow: 0 16px 40px rgba(0,0,0,.5); display: grid;
}
.um-head { padding: 8px 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; display: grid; gap: 2px; min-width: 0; }
.um-head small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.um-head .link-btn { justify-self: start; margin-top: 6px; }
.user-menu > a, .user-menu > button { text-align: left; padding: 9px 10px; border-radius: 6px; font-size: 14px; }
.user-menu > a:hover, .user-menu > button:hover { background: var(--bg-3); }

/* ============ ТОГЛУУЛАГЧ ============ */
.player { position: fixed; inset: 0; z-index: 80; background: #000; display: flex; align-items: center; justify-content: center; }
.player iframe, .player video { width: 100%; height: 100%; border: 0; }
.player-empty { text-align: center; padding: 20px; max-width: 420px; }
.player-empty h3 { font-size: 22px; margin: 0 0 8px; }
.player-empty p { color: var(--muted); margin: 0; }
.player .close { top: calc(16px + env(safe-area-inset-top, 0px)); right: calc(16px + env(safe-area-inset-right, 0px)); }

/* Мэдэгдэл */
.toast {
  position: fixed; z-index: 90; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: #fff; color: #111; padding: 10px 18px; border-radius: 8px; font-weight: 500; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}

.footer {
  margin-top: 56px; padding: 28px var(--side) calc(28px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line); color: var(--muted); font-size: 13px;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
}
.footer p { margin: 0; }

/* ============ ДЭЛГЭЦИЙН ХЭМЖЭЭНЭЭС ХАМААРАХ ============ */
@media (max-width: 1200px) {
  .topbar { gap: 24px; }
  .menu { gap: 20px; }
  .search { width: 180px; }
}
@media (max-width: 1000px) {
  :root { --side: max(16px, env(safe-area-inset-left, 0px)); }
  .topbar { flex-wrap: wrap; height: auto; padding-bottom: 6px; gap: 0 16px; background: rgba(11,13,18,.96); }
  .logo { font-size: 24px; height: 56px; }
  .menu { order: 3; width: 100%; overflow-x: auto; gap: 22px; scrollbar-width: none; }
  .menu > a, .dropdown-btn { padding: 8px 0 12px; white-space: nowrap; }
  .menu > a.active::after { bottom: 4px; }
  .dropdown { position: static; }
  .dropdown-menu { position: fixed; top: 110px; left: 16px; }
  .search { width: 160px; }
  .hero { height: 520px; margin-top: 0; }
  .slide-bg { width: 100%; }
  .slide::before { background: linear-gradient(0deg, var(--bg) 8%, rgba(11,13,18,.7) 45%, rgba(11,13,18,.1) 80%); }
  .slide-info { left: var(--side); right: var(--side); bottom: 56px; }
  .arrow { display: none; }
  .dots { right: auto; left: var(--side); bottom: 24px; }
  .rows { margin-top: 0; }
  .cards { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 220px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; scrollbar-width: none; }
  .card { scroll-snap-align: start; }
  .grid-page .cards { grid-auto-flow: row; grid-auto-columns: auto; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); overflow: visible; }
  .page-head { padding-top: 130px; }
  .notif { right: 0; }
}
@media (max-width: 600px) {
  .search { display: none; }
  .search-toggle { display: grid; }
  .search.open { display: flex; position: absolute; right: 0; top: 50px; width: calc(100vw - 32px); background: var(--bg-3); }
  .top-right { gap: 8px; }
  .top-right > .btn-red { display: none; } /* утсан дээр профайл дүрс нь нэвтрэх цонхыг нээнэ */
  .btn-play { padding: 0 24px; font-size: 16px; }
  .btn-text { display: none; }
  .modal-body { padding: 0 18px 22px; }
  .modal-body h2 { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
