/* ============================================================
   KinoMix24 — mobile.css   (подключать ПОСЛЕ styles.css)
   Всё внутри @media / @media(hover:none) — десктоп почти не меняется.
   Новое вне медиазапросов: .movie-meta, .filters-toggle (скрыты),
   drawer категорий, кнопка «наверх», вид блока актёров под плеером.
   ============================================================ */

* { -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }

/* --- Мета-строка карточки (рейтинг · жанр). На десктопе скрыта. --- */
.movie-meta {
  display: none;
  align-items: center; gap: 7px;
  padding: 5px 10px 11px; min-width: 0;
  font-size: 12px; line-height: 1.2; color: var(--text-2);
}
.movie-meta .mm-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.movie-meta .mm-rating {
  flex: 0 0 auto; font-weight: 800; font-size: 12px;
  padding: 2px 7px; border-radius: 6px;
  background: var(--gold); color: #12100A;
}
.movie-meta .mm-rating.good { background: var(--success); color: #04150C; }
.movie-meta .mm-rating.low  { background: var(--ember);   color: #fff; }

/* --- Кнопка «Фильтры» (видна только на телефоне) --- */
.filters-toggle {
  display: none; align-items: center; gap: 9px; box-sizing: border-box;
  width: 100%; margin-bottom: 14px; padding: 12px 16px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-2); border-radius: var(--radius);
  font-family: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
}
.filters-toggle svg { width: 18px; height: 18px; color: var(--gold); }
.filters-toggle .ft-chevron { margin-left: auto; transition: transform .2s ease; }
.filters-toggle.open .ft-chevron { transform: rotate(180deg); }

/* --- Бургер, drawer, зона свайпа: по умолчанию скрыты (десктоп) --- */
.mnav-burger { display: none; }
.mnav-drawer { display: none; }
.mnav-backdrop { display: none; }
.mnav-edge { display: none; }

/* ============================================================
   ВЫДВИЖНОЕ МЕНЮ КАТЕГОРИЙ (drawer) — общий вид
   Показывается только на телефоне (медиазапрос ниже включает display).
   ============================================================ */
.mnav-drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 400;
  width: 78vw; max-width: 320px;
  background: var(--surface); border-right: 1px solid var(--line-2);
  box-shadow: 6px 0 40px rgba(0,0,0,.5);
  transform: translateX(-100%);
  transition: transform .28s cubic-bezier(.2,.7,.3,1);
  display: flex; flex-direction: column;
  -webkit-overflow-scrolling: touch;
}
.mnav-drawer.open { transform: translateX(0); }
.mnav-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 12px; border-bottom: 1px solid var(--line);
}
.mnav-title {
  font-family: 'Bebas Neue', sans-serif; font-size: 22px;
  letter-spacing: .1em; color: var(--gold);
}
.mnav-close {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line-2);
  color: var(--text-2); display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.mnav-close svg { width: 16px; height: 16px; }
.mnav-list { padding: 12px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.mnav-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 14px; border-radius: 12px;
  background: transparent; border: 1px solid transparent;
  color: var(--text-2); font-family: inherit; font-size: 15.5px; font-weight: 600;
  cursor: pointer; text-align: left; width: 100%;
}
.mnav-item svg { width: 22px; height: 22px; flex: 0 0 auto; }
.mnav-item.active {
  color: #12100A; background: linear-gradient(135deg, var(--gold-2), var(--gold));
}

.mnav-backdrop {
  position: fixed; inset: 0; z-index: 390;
  background: rgba(4,5,9,.6); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .28s ease;
}
.mnav-backdrop.open { opacity: 1; pointer-events: auto; }

/* Зона для свайпа от левого края экрана */
.mnav-edge {
  position: fixed; top: var(--topbar-h, 64px); left: 0; bottom: 0;
  width: 22px; z-index: 380;
}

/* ============================================================
   КНОПКА «НАВЕРХ»
   ============================================================ */
.to-top-btn {
  position: fixed; right: 16px; bottom: 18px; z-index: 300;
  width: 46px; height: 46px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  color: #12100A; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  opacity: 0; transform: translateY(12px) scale(.9); pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.to-top-btn svg { width: 22px; height: 22px; }
.to-top-btn.show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

/* ============================================================
   АКТЁРЫ ПОД ПЛЕЕРОМ (общий вид, все экраны)
   ============================================================ */
.detail-container > .cast-block { margin-top: 30px; margin-bottom: 28px; }
.detail-container > .cast-block .cast-list,
.detail-container > .cast-block .cast-grid {
  /* ровные ряды по центру: число колонок задаёт сервер (--cast-cols) */
  grid-template-columns: repeat(var(--cast-cols, 6), minmax(0, 150px)) !important;
  justify-content: center;
  gap: 14px !important;
}

/* ============================================================
   АКТЁРЫ НА ПК: ровные ряды по количеству карточек (чистый CSS,
   не зависит ни от сервера, ни от скриптов):
   7–8 → по 4 в ряд, 9–10 → по 5 (5+5, 5+4), 11–12 → по 6 (6+6, 6+5)
   ============================================================ */
@media (min-width: 961px) {
  .detail-container > .cast-block .cast-list:has(> :nth-child(1):last-child) { grid-template-columns: repeat(1, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(2):last-child) { grid-template-columns: repeat(2, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(3):last-child) { grid-template-columns: repeat(3, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(4):last-child) { grid-template-columns: repeat(4, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(5):last-child) { grid-template-columns: repeat(5, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(6):last-child) { grid-template-columns: repeat(6, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(7):last-child) { grid-template-columns: repeat(4, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(8):last-child) { grid-template-columns: repeat(4, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(9):last-child) { grid-template-columns: repeat(5, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(10):last-child) { grid-template-columns: repeat(5, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(11):last-child) { grid-template-columns: repeat(6, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(12):last-child) { grid-template-columns: repeat(6, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(13):last-child) { grid-template-columns: repeat(5, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(14):last-child) { grid-template-columns: repeat(5, minmax(0, 150px)) !important; }
  .detail-container > .cast-block .cast-list:has(> :nth-child(15):last-child) { grid-template-columns: repeat(5, minmax(0, 150px)) !important; }
}

/* Убираем «залипший» ховер на тач-устройствах любой ширины */
@media (hover: none) {
  .movie-card:hover { transform: none; box-shadow: none; border-color: var(--line); z-index: auto; }
  .fav-btn, .movie-card:hover .fav-btn { opacity: 1; }
}

/* ============================================================
   АКТЁРЫ: 5 в ряд, мелкие карточки — телефоны И ландшафт (<=960px)
   ============================================================ */
@media (max-width: 960px) {
  .detail-container > .cast-block .cast-list,
  .detail-container > .cast-block .cast-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  .detail-container > .cast-block .cast-item { padding: 4px; border-radius: 9px; }
  .detail-container > .cast-block .cast-photo,
  .detail-container > .cast-block .cast-photo--empty,
  .detail-container > .cast-block .cast-photo--broken {
    max-width: 100%; border-radius: 7px;
  }
  .detail-container > .cast-block .cast-photo--empty,
  .detail-container > .cast-block .cast-photo--broken { font-size: 1.1rem; }
  .detail-container > .cast-block .cast-meta { margin-top: 5px; }
  .detail-container > .cast-block .cast-name { font-size: 10.5px; line-height: 1.2; }
  .detail-container > .cast-block .cast-title { margin-bottom: 12px; }
}

/* ============================================================
   ТЕЛЕФОНЫ / НЕБОЛЬШИЕ ПЛАНШЕТЫ  (<= 768px)
   ============================================================ */
@media (max-width: 768px) {

  /* Показываем бургер, drawer, зону свайпа */
  .mnav-burger {
    display: flex; align-items: center; justify-content: center;
    flex: 0 0 auto; width: 38px; height: 38px; margin-right: 2px;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 10px; color: var(--text); cursor: pointer;
  }
  .mnav-burger svg { width: 20px; height: 20px; }
  .mnav-drawer { display: flex; }
  .mnav-backdrop { display: block; }
  .mnav-edge { display: block; }

  /* Прячем десктопную панель категорий под шапкой */
  .catbar { display: none; }

  .brand-name { font-size: 22px; }

  /* ---------- Заголовок / фильтры ---------- */
  .catalog { padding-top: 18px; }
  #pageTitle { font-size: 30px; }

  .filters-toggle { display: flex; }

  .filters-bar { display: none; }
  .filters-bar.filters-open {
    display: flex; flex-direction: column; align-items: stretch; gap: 16px;
  }
  .filter-field, .filter-year { flex: 1 1 100%; min-width: 0; width: 100%; }
  .filters-reset { width: 100%; justify-content: center; }
  .cs-panel { max-height: 260px; }

  /* ---------- Сетка каталога: 3 колонки, постер + инфо снизу ---------- */
  .movies-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }

  .movie-poster-wrap { border-radius: 14px; }
  .movie-info { padding: 8px 4px 0; }
  .movie-title { font-size: 13.5px; min-height: 2.4em; }
  .movie-title .year { font-size: 12px; }
  .movie-meta { display: flex; margin-top: 4px; }
  .fav-btn { opacity: 1; }

  .load-more-btn { width: 100%; }

  /* ============================================================
     ДЕТАЛЬНАЯ СТРАНИЦА
     ============================================================ */
  .detail-container { padding: 22px 14px 60px; }

  .movie-detail-page { gap: 20px; }
  .poster-column { width: 100%; max-width: 240px; }
  .poster-actions { margin-top: 12px; }

  .movie-title-main { font-size: clamp(1.9rem, 7.5vw, 2.6rem); text-align: center; }
  .original-title { text-align: center; margin-bottom: 16px; }

  /* Рейтинги — компактные аккуратные чипы по центру */
  .ratings-row { justify-content: center; gap: 10px; margin-bottom: 20px; }
  .rating-chip { padding: 8px 14px; gap: 9px; border-radius: 12px; }
  .rating-score { font-size: 1.7rem; }
  .rating-source { font-size: 10.5px; }
  .rating-votes { font-size: 11px; }

  /* Поля «название — значение» */
  .field { padding: 9px 0; }
  .field-title { font-size: 10.5px; }
  .field-value { font-size: 14px; }
  .description { font-size: 14.5px; line-height: 1.7; margin-top: 20px; }

  /* Плеер — адаптивная высота 16:9 */
  .player-section { margin-top: 26px; }
  .player-wrapper iframe { width: 100% !important; height: 56vw !important; max-height: 420px; }

  /* Сиквелы/приквелы */
  .related-section { width: auto; padding: 16px; }
  .related-rail { --rel-w: 120px; }
  .rail-nav { display: none !important; }

  /* Комментарии */
  .comments-section { padding: 18px 14px; }
  .section-title { font-size: 16px; }
  .comment-avatar { width: 38px; height: 38px; }
  .emoji-popover emoji-picker { width: min(92vw, 340px); }

  /* Поддержка / профиль — мелкие правки */
  .support-thread-user .stu-actions { flex-wrap: wrap; }
  .support-img { width: 44vw; height: auto; max-width: 200px; }
  .admin-reply-box textarea { width: 100%; box-sizing: border-box; }
}

/* ---------- Обычные телефоны в портрете: 2 колонки в каталоге ---------- */
@media (max-width: 520px) {
  .movies-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
  .movie-title { font-size: 14px; }
}
@media (max-width: 360px) {
  .movies-grid { gap: 9px; }
  .brand-name { font-size: 20px; }
  #pageTitle { font-size: 26px; }
}

/* ============================================================
   АВТОСКРЫТИЕ ВЕРХНЕЙ ПАНЕЛИ ПРИ ЛИСТАНИИ (только телефон)
   ============================================================ */
@media (max-width: 768px) {
  .topbar {
    transition: transform .28s cubic-bezier(.2,.7,.3,1);
    will-change: transform;
  }
  /* класс вешает main.js, когда листаем вниз */
  body.topbar-hidden .topbar {
    transform: translateY(-100%);
  }
}

/* ============================================================
   ПАНЕЛЬ ЖАНРОВ НА ТЕЛЕФОНЕ — выезжает слева по кнопке «Жанры»
   ============================================================ */
@media (max-width: 768px) {
  /* ничего не должно вылезать за правый край экрана */
  html, body { max-width: 100%; overflow-x: hidden; }
  .page { padding-left: 14px; padding-right: 14px; }
  .page-layout { display: block; width: 100%; min-width: 0; }
  .page-layout > .catalog { width: 100%; min-width: 0; }
  .movies-grid { width: 100%; min-width: 0; }
  .movie-card, .movie-info, .movie-title, .movie-meta { min-width: 0; max-width: 100%; }
  .movie-title { overflow-wrap: anywhere; }
  .catalog-head { flex-wrap: wrap; gap: 6px 12px; }
  .stats-bar { flex-wrap: wrap; }

  .mobile-tools { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-bottom: 14px; }
  .mobile-tools .filters-toggle { margin-bottom: 0; height: 48px; padding: 0 14px; }
  .mobile-tools .filters-toggle { flex: 1 1 0; width: auto; min-width: 0; }
  .mobile-tools .filters-toggle span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .genres-open.has-value { border-color: var(--gold); color: var(--gold-2); }

  .genre-panel {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 410;
    height: 100vh; height: 100dvh;   /* dvh — учитывает панели браузера на телефоне */
    margin: 0; width: 82vw; max-width: 320px; max-height: none; flex: none;
    border-radius: 0 18px 18px 0; border-left: none;
    box-shadow: 6px 0 40px rgba(0,0,0,.55);
    transform: translateX(-105%);
    transition: transform .28s cubic-bezier(.2,.7,.3,1);
  }
  .genre-panel.open { transform: translateX(0); }
  .gp-head { padding: 18px 14px 12px 18px; }
  .gp-toggle { display: none; }
  .gp-close { display: flex; }
  .gp-list { padding: 10px; gap: 4px; min-height: 0; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .gp-head, .gp-foot { flex: none; }
  .genre-item { padding: 12px 14px; font-size: 15px; }
  .gp-foot { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }
  .gp-done { display: inline-block; }

  .genre-backdrop {
    display: block; position: fixed; inset: 0; z-index: 405;
    background: rgba(4,5,9,.6); backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none; transition: opacity .28s ease;
  }
  .genre-backdrop.open { opacity: 1; pointer-events: auto; }
  body.no-scroll { overflow: hidden; }

  /* выпадающий список стран — во всю ширину */
  .ms-panel { min-width: 0; }
  .ms-options { max-height: 240px; }

  .player-removed { min-height: 220px; padding: 28px 16px; }
  .player-removed .pr-title { font-size: 17px; }

  /* SEO-блоки */
  .seo-text { padding: 16px; font-size: 13.5px; }
  .seo-links-row { font-size: 12.5px; gap: 5px 10px; }

  /* круглая кнопка «назад» */
  .back-btn--round { width: 44px; height: 44px; }
}