/* Final visual fixes — intentionally loaded after all legacy styles. */
.poster-card img.is-lazy-pending,
.mini-card img.is-lazy-pending {
  opacity: 0;
}

/* Premium badge in user search rows must not inherit the poster-image rules. */
#searchModalResults .user-search-card .user-search-card__avatar-shell > img.premium-crown {
  position: absolute !important;
  inset: -5px -5px auto auto !important;
  z-index: 8 !important;
  display: block !important;
  width: 22px !important;
  min-width: 22px !important;
  max-width: 22px !important;
  height: 22px !important;
  min-height: 22px !important;
  max-height: 22px !important;
  margin: 0 !important;
  padding: 3px !important;
  border: 2px solid #090b0c !important;
  border-radius: 50% !important;
  background: #17130a !important;
  box-shadow: none !important;
  opacity: 1 !important;
  object-fit: contain !important;
  transform: none !important;
  filter: none !important;
}

:root { color-scheme: dark; }

html, body, .site-shell, .home-page,
body.is-library .home-page, body.is-library #catalog {
  background: #050607 !important;
}
body.is-detail, body.is-detail #detailPage { background: #0f1319 !important; }
body.is-watch, body.is-watch #detailPage { background: #030405 !important; }

/* Keep one header geometry and appearance on every route. */
.topbar, body.is-detail .topbar, body.is-watch .topbar {
  min-height: 72px !important;
  height: 72px !important;
  padding: 0 clamp(22px, 3.4vw, 68px) !important;
  border-bottom: 1px solid rgba(255,255,255,.08) !important;
  background: #090a0d !important;
  grid-template-columns: minmax(230px,max-content) minmax(430px,1fr) minmax(340px,640px) max-content !important;
  column-gap: clamp(24px,2.2vw,44px) !important;
}
.topbar .logo, body.is-detail .topbar .logo { min-width: 230px !important; padding: 0 !important; }
.topbar .logo-mark { flex: 0 0 auto !important; }

/* Library pages begin directly below the header. */
body.is-library #catalogPage.catalog-section,
body.is-library #favoritesPage.library-section,
body.is-library #historyPage.library-section {
  width: min(100% - 72px, 1900px) !important;
  margin: 0 auto !important;
  padding-top: 32px !important;
  background: transparent !important;
}
#catalogPage > .page-heading,
#favoritesPage > .page-heading,
#historyPage > .page-heading { display: none !important; }
#profilePage.profile-page { padding-top: 0 !important; }

/* Neutral image loading surface. */
.poster-card, .catalog-card, .favorite-card,
.poster-card img, .catalog-card img, .favorite-card img,
.poster-fallback, .anime-poster, .history-card__poster,
.profile-favorite-card, .search-result-card img {
  background-color: #191b20 !important;
  background-image: linear-gradient(100deg,#191b20 25%,#292c32 42%,#191b20 60%) !important;
  background-size: 220% 100% !important;
  animation: neutral-poster-shimmer 1.35s linear infinite !important;
}
.poster-card img[src], .catalog-card img[src], .favorite-card img[src],
.profile-favorite-card img[src], .search-result-card img[src], .history-card__poster img[src] {
  animation: none !important;
  background-image: none !important;
}
/* The legacy reveal animation starts cards at opacity:0. The shimmer rule
   replaces that animation, therefore the cards must be revealed explicitly. */
.poster-card, .catalog-card, .favorite-card {
  opacity: 1 !important;
  animation: none !important;
}
.poster-fallback {
  color: #555961 !important;
  background: #15161a url("/fallback-poster.webp") center / cover no-repeat !important;
}
.poster-fallback::before { display: none !important; animation: none !important; }
.banner-fallback { object-fit: cover !important; object-position: center !important; }
.poster-fallback--terminal,
.banner-fallback--terminal { background: #15161a !important; }
@keyframes neutral-poster-shimmer { to { background-position: -220% 0; } }

/* Settings controls and uploads. */
.settings-clean-row select,
.settings-clean-row select option {
  color-scheme: dark !important;
  background: #17191e !important;
  color: #f4f4f5 !important;
}
.profile-file-button {
  position: relative;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 190px;
  min-height: 44px;
  padding: 0 18px;
  overflow: hidden;
  border: 1px solid #343740;
  border-radius: 11px;
  background: #1c1e23;
  color: #fff;
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
}
.profile-file-button:hover { background: #292c32; border-color: #4a4d56; }
.profile-file-button input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

/* Search: visible close action and properly aligned user rows. */
#searchModal .search-modal__form {
  display: grid !important;
  grid-template-columns: 24px minmax(0,1fr) 42px !important;
  align-items: center !important;
  max-width: none !important;
}
#searchModal .search-modal__form button.search-form-close {
  display: grid !important;
  place-items: center !important;
  width: 36px !important;
  height: 36px !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 9px !important;
  background: transparent !important;
  color: #a6a9b0 !important;
  font-size: 25px !important;
  cursor: pointer !important;
}
#searchModal .search-modal__form button.search-form-close:hover { background: #292b31 !important; color: #fff !important; }
#searchModalResults .user-search-card {
  display: grid !important;
  grid-template-columns: 56px minmax(0,1fr) 24px !important;
  align-items: center !important;
  gap: 15px !important;
  min-height: 80px !important;
  padding: 12px 16px !important;
}
#searchModalResults .user-search-card .user-search-card__avatar {
  position: static !important;
  grid-column: 1 !important;
  grid-row: 1 !important;
  width: 56px !important;
  height: 56px !important;
  margin: 0 !important;
}
#searchModalResults .user-search-card > div { grid-column: 2 !important; grid-row: 1 !important; align-self: center !important; }
#searchModalResults .user-search-card::after { grid-column: 3 !important; grid-row: 1 !important; }

/* Catalog load-more placement and styling. */
#catalogMore.load-more-episodes {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: max-content !important;
  min-width: 190px !important;
  min-height: 48px !important;
  margin: 34px auto 70px !important;
  padding: 0 24px !important;
  border: 1px solid #343740 !important;
  border-radius: 12px !important;
  background: #1b1d22 !important;
  color: #f6f6f7 !important;
  font-size: 14px !important;
  font-weight: 850 !important;
  cursor: pointer !important;
}
#catalogMore:hover { background: #292c32 !important; border-color: #4a4e57 !important; }
#catalogMore:disabled { opacity: .55 !important; cursor: default !important; }

@media (max-width: 1380px) {
  .topbar, body.is-detail .topbar, body.is-watch .topbar {
    grid-template-columns: max-content minmax(260px,1fr) max-content !important;
  }
}
@media (max-width: 760px) {
  .topbar, body.is-detail .topbar, body.is-watch .topbar { min-height:64px !important; height:64px !important; padding:0 14px !important; }
  body.is-library #catalogPage.catalog-section, body.is-library #favoritesPage.library-section, body.is-library #historyPage.library-section { width: min(100% - 24px,1900px) !important; padding-top:20px !important; }
  .profile-file-button { justify-self: start; }
}

/* Unified mobile UI. This final layer intentionally replaces the accumulated
   legacy phone layouts with one compact system shared by every route. */
@media (max-width: 820px) {
  :root { --mobile-gutter: 14px; --mobile-nav-h: 70px; }

  html, body { width: 100% !important; overflow-x: hidden !important; background: #050607 !important; }
  body { padding-bottom: calc(var(--mobile-nav-h) + 14px + env(safe-area-inset-bottom, 0px)) !important; }
  .site-shell, body.is-home .site-shell, body.is-library .site-shell, body.is-detail .site-shell, body.is-watch .site-shell {
    display: block !important; width: 100% !important; max-width: none !important; min-height: 100svh !important;
    overflow: clip !important; background: #050607 !important;
  }

  /* Header */
  .topbar, body.is-detail .topbar, body.is-watch .topbar {
    position: sticky !important; inset: 0 0 auto !important; z-index: 1000 !important;
    display: grid !important; grid-template-columns: auto minmax(0,1fr) auto !important;
    grid-template-rows: 52px 44px !important; gap: 4px 10px !important;
    width: 100% !important; height: 108px !important; min-height: 108px !important;
    padding: 6px var(--mobile-gutter) 8px !important; background: rgba(8,9,12,.96) !important;
    border-bottom: 1px solid rgba(255,255,255,.08) !important; backdrop-filter: blur(18px) !important;
  }
  .topbar .logo, body.is-detail .topbar .logo {
    grid-area: 1 / 1 !important; min-width: 0 !important; gap: 7px !important; padding: 0 !important;
    font-size: 19px !important;
  }
  .topbar .logo-mark { width: 34px !important; height: 34px !important; flex-basis: 34px !important; }
  .logo-word { display: inline !important; }
  .header-nav { display: none !important; }
  .top-actions { grid-area: 1 / 3 !important; display: flex !important; justify-self: end !important; gap: 7px !important; }
  .notification-button, .profile-button {
    width: 38px !important; min-width: 38px !important; height: 38px !important; padding: 0 !important;
    border: 1px solid rgba(255,255,255,.08) !important; border-radius: 50% !important; background: #15171c !important;
  }
  .profile-button span, #profileButtonName { display: none !important; }
  .profile-avatar { width: 32px !important; height: 32px !important; }
  .top-search {
    grid-area: 2 / 1 / 3 / 4 !important; width: 100% !important; max-width: none !important; height: 44px !important;
    display: grid !important; grid-template-columns: 42px minmax(0,1fr) !important; margin: 0 !important;
    border: 1px solid rgba(255,255,255,.09) !important; border-radius: 12px !important; background: #15171c !important;
  }
  .top-search button { width: 42px !important; height: 42px !important; }
  .top-search input { height: 42px !important; min-width: 0 !important; padding: 0 12px 0 0 !important; font-size: 13px !important; }

  /* Bottom navigation */
  .sidebar { display: contents !important; }
  .sidebar > .nav:not(.nav--footer) {
    position: fixed !important; z-index: 1200 !important; left: 10px !important; right: 10px !important;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important; display: grid !important;
    grid-template-columns: repeat(5,minmax(0,1fr)) !important; width: auto !important; height: var(--mobile-nav-h) !important;
    gap: 3px !important; padding: 6px !important; border: 1px solid rgba(255,255,255,.1) !important;
    border-radius: 20px !important; background: rgba(17,19,24,.96) !important; box-shadow: 0 18px 48px rgba(0,0,0,.5) !important;
    backdrop-filter: blur(18px) !important;
  }
  .sidebar > .nav:not(.nav--footer) a {
    display: grid !important; grid-template-rows: 26px 14px !important; place-items: center !important; gap: 2px !important;
    width: 100% !important; min-height: 56px !important; padding: 6px 1px !important; border: 0 !important;
    border-radius: 14px !important; background: transparent !important; color: #8f939c !important;
    font-size: 9px !important; line-height: 1 !important; text-align: center !important;
  }
  .sidebar > .nav:not(.nav--footer) a span { display: grid !important; width: 26px !important; height: 26px !important; place-items: center !important; font-size: 18px !important; }
  .sidebar > .nav:not(.nav--footer) a.is-active { color: #ff9367 !important; background: rgba(255,255,255,.07) !important; }
  .sidebar > .nav:not(.nav--footer) .nav-mobile-settings, .nav--footer, .bottom-nav { display: none !important; }

  /* Shared page rhythm */
  .home-page, body.is-home .home-page, body.is-library .home-page, .detail-page, body.is-detail .detail-page {
    width: 100% !important; max-width: none !important; margin: 0 !important;
    padding: 14px var(--mobile-gutter) calc(var(--mobile-nav-h) + 28px) !important; overflow: clip !important;
  }
  body.is-library #catalogPage.catalog-section, body.is-library #favoritesPage.library-section, body.is-library #historyPage.library-section,
  #profilePage.profile-page, #settingsPage.settings-section {
    width: 100% !important; max-width: none !important; margin: 0 !important; padding: 10px 0 34px !important;
  }
  .page-heading { display: none !important; }
  .section-head { margin: 0 0 14px !important; }
  .section-head h2 { font-size: clamp(25px,8vw,32px) !important; line-height: 1 !important; letter-spacing: -.035em !important; }

  /* Home */
  body.is-home #continueCard {
    width: calc(100% + (var(--mobile-gutter) * 2)) !important; margin: -14px calc(var(--mobile-gutter) * -1) 34px !important;
    border-radius: 0 !important; overflow: hidden !important;
  }
  body.is-home #continueWatch.hero-carousel.watch-progress {
    width: 100% !important; min-height: min(67svh,520px) !important; padding: 26px var(--mobile-gutter) !important;
    align-content: end !important; border: 0 !important; border-radius: 0 !important; background-position: center !important;
  }
  body.is-home .hero-carousel__copy { width: 100% !important; max-width: 100% !important; }
  body.is-home .hero-carousel.watch-progress h3 { max-width: 95% !important; font-size: clamp(35px,11vw,48px) !important; line-height: .96 !important; }
  body.is-home .poster-section { margin: 0 0 38px !important; padding: 0 !important; }
  body.is-home .poster-grid, #popularGrid, #recommendationsGrid, #ongoingGrid, #moviesGrid {
    display: grid !important; grid-template-columns: none !important; grid-auto-flow: column !important;
    grid-auto-columns: minmax(142px,43vw) !important; gap: 12px !important; width: calc(100% + var(--mobile-gutter)) !important;
    margin-right: calc(var(--mobile-gutter) * -1) !important; padding: 0 var(--mobile-gutter) 8px 0 !important;
    overflow-x: auto !important; overflow-y: hidden !important; scroll-snap-type: x proximity !important; scrollbar-width: none !important;
  }
  body.is-home .poster-grid::-webkit-scrollbar { display: none !important; }
  body.is-home .poster-card { width: 100% !important; min-width: 0 !important; aspect-ratio: 2/3 !important; scroll-snap-align: start !important; border-radius: 14px !important; }
  .poster-card strong { font-size: 13px !important; line-height: 1.18 !important; }
  .card-heart { top: 8px !important; right: 8px !important; width: 32px !important; height: 32px !important; }

  /* Catalog, favorites, history */
  .catalog-toolbar { display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr)) !important; gap: 10px !important; margin: 0 0 22px !important; }
  .catalog-toolbar label { min-width: 0 !important; font-size: 11px !important; }
  .catalog-toolbar label:last-child { grid-column: 1/-1 !important; }
  .catalog-toolbar select { width: 100% !important; min-width: 0 !important; height: 46px !important; padding: 0 11px !important; border-radius: 11px !important; font-size: 12px !important; }
  .catalog-grid, .library-grid, .results { display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr)) !important; gap: 11px !important; }
  .catalog-grid .poster-card, .library-grid .poster-card, .results .poster-card { width: 100% !important; min-width: 0 !important; border-radius: 14px !important; }
  #catalogMore.load-more-episodes { min-width: 164px !important; min-height: 44px !important; margin: 24px auto 36px !important; border-radius: 11px !important; }
  body.is-library #historyGrid.history-list { display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr)) !important; gap: 16px 11px !important; width: 100% !important; }
  body.is-library .history-card { display: block !important; padding: 0 !important; border: 0 !important; background: transparent !important; }
  body.is-library .history-card__poster { width: 100% !important; height: auto !important; aspect-ratio: 16/10 !important; border-radius: 13px !important; }
  body.is-library .history-card__body { display: grid !important; grid-template-columns: 1fr !important; gap: 5px !important; padding: 9px 2px 0 !important; }
  body.is-library .history-card__body strong { font-size: 13px !important; }

  /* Profile */
  .profile-hero { min-height: 300px !important; border-radius: 17px !important; }
  .profile-hero__fade { background: linear-gradient(0deg,rgba(5,6,8,.92),rgba(5,6,8,.08) 70%) !important; }
  .profile-hero__identity { left: 18px !important; right: 18px !important; bottom: 20px !important; max-width: none !important; flex-direction: row !important; align-items: flex-end !important; gap: 13px !important; }
  .profile-hero__avatar { width: 82px !important; height: 82px !important; flex-basis: 82px !important; border-width: 3px !important; }
  .profile-hero__identity h1 { font-size: clamp(28px,9vw,38px) !important; }
  .profile-hero__identity p { margin-top: 5px !important; font-size: 13px !important; }
  .profile-edit-button { top: 14px !important; right: 14px !important; bottom: auto !important; min-width: 0 !important; min-height: 40px !important; padding: 0 13px !important; font-size: 12px !important; }
  .profile-member-since { margin-top: 12px !important; }
  .profile-overview { grid-template-columns: 1fr !important; gap: 12px !important; margin-top: 22px !important; }
  .profile-statistics-card, .profile-friends-card { min-height: 0 !important; padding: 19px !important; border-radius: 16px !important; }
  .profile-statline strong { font-size: 22px !important; }
  .profile-friends-list { max-height: 220px !important; }
  .profile-content-section { margin-top: 32px !important; }
  .profile-section-head h2 { font-size: 25px !important; }
  .profile-favorites-rail { display: flex !important; gap: 11px !important; overflow-x: auto !important; padding-bottom: 8px !important; scroll-snap-type: x proximity !important; scrollbar-width: none !important; }
  .profile-favorite-card { flex: 0 0 43vw !important; max-width: 180px !important; scroll-snap-align: start !important; border-radius: 13px !important; }
  .profile-activity > div { flex-direction: column !important; gap: 7px !important; padding: 14px 0 !important; }

  /* Settings */
  .settings-title { margin-bottom: 20px !important; }
  .settings-title h1 { font-size: 38px !important; }
  .settings-preview { min-height: 160px !important; padding: 18px !important; border-radius: 16px !important; }
  .settings-preview__avatar { width: 72px !important; height: 72px !important; }
  .settings-stack { margin-top: 24px !important; }
  .settings-clean-section { padding: 26px 0 !important; }
  .settings-clean-row { grid-template-columns: 1fr !important; gap: 11px !important; min-height: 0 !important; padding: 15px 0 !important; }
  .settings-clean-row select, .settings-clean-row input[type="text"] { width: 100% !important; background: #17191e !important; color: #fff !important; }
  .settings-clean-row input[type="checkbox"] { justify-self: start !important; }
  .profile-file-button { justify-self: stretch !important; width: 100% !important; min-width: 0 !important; }
  .settings-save-row { align-items: stretch !important; flex-direction: column !important; }
  .settings-save-button { width: 100% !important; }

  /* Anime detail */
  body.is-detail:not(.is-watch) #detailPage { padding: 0 var(--mobile-gutter) calc(var(--mobile-nav-h) + 28px) !important; }
  body.is-detail:not(.is-watch) #detailPage .anime-detail-layout { width: 100% !important; max-width: none !important; }
  body.is-detail:not(.is-watch) #detailPage .detail-banner { height: 132px !important; margin: 0 0 22px !important; border-radius: 0 0 12px 12px !important; }
  body.is-detail:not(.is-watch) #detailPage .anime-detail-main { grid-template-columns: 104px minmax(0,1fr) !important; gap: 15px !important; }
  body.is-detail:not(.is-watch) #detailPage .poster-column { max-width: 104px !important; }
  body.is-detail:not(.is-watch) #detailPage .anime-info { padding-top: 0 !important; }
  body.is-detail:not(.is-watch) #detailPage .title-line h1 { font-size: clamp(25px,8vw,35px) !important; line-height: .98 !important; }
  body.is-detail:not(.is-watch) #detailPage .subtitle { margin: 7px 0 10px !important; font-size: 11px !important; }
  body.is-detail:not(.is-watch) #detailPage .chips { gap: 5px !important; margin-bottom: 11px !important; }
  body.is-detail:not(.is-watch) #detailPage .chips span { min-height: 24px !important; padding: 0 7px !important; font-size: 10px !important; }
  body.is-detail:not(.is-watch) #detailPage .description { font-size: 12px !important; line-height: 1.5 !important; }
  body.is-detail:not(.is-watch) #detailPage .poster-actions { grid-column: 1/-1 !important; gap: 8px !important; margin-top: 14px !important; }
  body.is-detail:not(.is-watch) #detailPage .poster-actions button { min-height: 40px !important; padding: 0 13px !important; font-size: 12px !important; }
  .detail-episodes { margin-top: 34px !important; }
  .detail-episodes button { min-height: 42px !important; border-radius: 9px !important; font-size: 11px !important; }
  .detail-extra { margin-top: 34px !important; }

  /* Watch */
  body.is-watch .detail-page { padding: 12px var(--mobile-gutter) calc(var(--mobile-nav-h) + 24px) !important; }
  .watch-player-page { width: 100% !important; padding: 0 !important; }
  .ah-player { width: 100% !important; max-width: none !important; aspect-ratio: 16/9 !important; border-radius: 10px !important; }
  .ah-player__top { gap: 2px !important; padding: 7px !important; overflow-x: auto !important; scrollbar-width: none !important; }
  .ah-player-select > button { min-height: 32px !important; max-width: 108px !important; padding: 4px 7px !important; }
  .ah-player-select span { font-size: 10px !important; }
  .ah-player-select__menu { max-height: min(54svh,330px) !important; }
  .ah-player__center { width: 52px !important; height: 52px !important; }
  .ah-player__center svg { width: 28px !important; height: 31px !important; }
  .ah-player__controls { padding: 26px 8px 6px !important; }
  .ah-player__row { gap: 2px !important; }
  .ah-player__icon, .ah-player-quality > button { min-width: 32px !important; height: 32px !important; padding: 0 6px !important; }
  .ah-player__time { font-size: 11px !important; }
  .ah-player__volume { display: none !important; }
  .ah-episode-rail-wrap { grid-template-columns: minmax(0,1fr) !important; width: 100% !important; margin-top: 11px !important; }
  .ah-episode-arrow { display: none !important; }
  .ah-episode-card { min-width: 92px !important; min-height: 44px !important; padding: 0 13px !important; font-size: 11px !important; }

  /* Search */
  .search-modal { padding: 0 !important; align-items: stretch !important; }
  .search-modal__panel { width: 100% !important; min-height: 100svh !important; max-height: 100svh !important; padding: 18px var(--mobile-gutter) !important; border: 0 !important; border-radius: 0 !important; background: #08090c !important; }
  .search-modal__head h2 { font-size: 27px !important; }
  #searchModal .search-modal__form { grid-template-columns: 22px minmax(0,1fr) 38px !important; height: 54px !important; }
  #searchModal .search-modal__form input { height: 52px !important; font-size: 13px !important; }
  .search-kind-tabs { gap: 5px !important; }
  .search-kind-tabs button { min-height: 42px !important; font-size: 12px !important; }
  #searchModalResults .user-search-card { grid-template-columns: 48px minmax(0,1fr) 20px !important; min-height: 70px !important; padding: 10px !important; }
  #searchModalResults .user-search-card .user-search-card__avatar { width: 48px !important; height: 48px !important; }
}

@media (max-width: 390px) {
  :root { --mobile-gutter: 11px; }
  .logo-word { font-size: 18px !important; }
  body.is-home .poster-grid, #popularGrid, #recommendationsGrid, #ongoingGrid, #moviesGrid { grid-auto-columns: 44vw !important; }
  .catalog-grid, .library-grid, .results { gap: 9px !important; }
  .profile-edit-button span { display: none !important; }
  body.is-detail:not(.is-watch) #detailPage .anime-detail-main { grid-template-columns: 92px minmax(0,1fr) !important; gap: 12px !important; }
  body.is-detail:not(.is-watch) #detailPage .poster-column { max-width: 92px !important; }
  .ah-player-quality > button { font-size: 10px !important; }
}

.bottom-nav .bottom-nav-icon {
  display: block;
  width: 22px;
  height: 22px;
  object-fit: contain;
}

/* Compact mobile search results: keep the title below the poster's top edge. */
@media (max-width: 820px) {
  #searchModalResults .search-result-card {
    min-height: 132px !important;
    height: 132px !important;
    padding: 38px 12px 12px 108px !important;
    justify-content: flex-start !important;
  }

  #searchModalResults .search-result-title {
    align-self: auto !important;
    margin: 0 !important;
    font-size: 14px !important;
    line-height: 1.22 !important;
    display: -webkit-box !important;
    -webkit-box-orient: vertical !important;
    -webkit-line-clamp: 2 !important;
    overflow: hidden !important;
  }

  #searchModalResults .search-result-meta {
    margin-top: 12px !important;
    font-size: 11px !important;
  }
}

/* Reference-style mobile header: one row with an anchored popup menu. */
.mobile-menu-button { display: none; }
@media (max-width: 820px) {
  body { padding-bottom: env(safe-area-inset-bottom, 0px) !important; }
  .topbar, body.is-detail .topbar, body.is-watch .topbar {
    display: grid !important; grid-template-columns: minmax(0,1fr) 42px 42px auto !important;
    grid-template-rows: 52px !important; gap: 7px !important; width: 100% !important;
    height: 64px !important; min-height: 64px !important; padding: 6px 12px !important; background: #050607 !important;
  }
  .topbar .logo, body.is-detail .topbar .logo { grid-area: 1/1 !important; align-self: center !important; min-width: 0 !important; color: #a8abb2 !important; }
  .topbar .logo-mark { display: none !important; }
  .topbar .logo-word { display: block !important; overflow: hidden !important; font-size: 21px !important; font-weight: 500 !important; text-overflow: ellipsis !important; white-space: nowrap !important; }
  .mobile-menu-button {
    grid-area: 1/2 !important; display: grid !important; width: 42px !important; height: 42px !important; place-items: center !important;
    align-self: center !important; padding: 0 !important; border: 0 !important; border-radius: 13px !important;
    background: #17191e !important; color: #eceef2 !important; cursor: pointer !important;
  }
  .mobile-menu-button svg { width: 23px !important; height: 23px !important; fill: none !important; stroke: currentColor !important; stroke-width: 1.8 !important; stroke-linecap: round !important; }
  body.mobile-menu-open .mobile-menu-button { color: #ff9367 !important; background: #22242a !important; }
  .top-search {
    grid-area: 1/3 !important; align-self: center !important; display: grid !important; width: 42px !important; max-width: 42px !important;
    height: 42px !important; grid-template-columns: 42px !important; overflow: hidden !important; border: 0 !important;
    border-radius: 13px !important; background: #17191e !important;
  }
  .top-search button { width: 42px !important; height: 42px !important; }
  .top-search input { display: none !important; }
  .top-actions { grid-area: 1/4 !important; align-self: center !important; display: flex !important; gap: 7px !important; }
  .notification-button, .profile-button { width: 42px !important; min-width: 42px !important; height: 42px !important; border: 0 !important; border-radius: 13px !important; background: #17191e !important; }
  .profile-button { border-radius: 50% !important; background: transparent !important; }
  .profile-avatar { width: 42px !important; height: 42px !important; }
  .sidebar > .nav:not(.nav--footer) {
    position: fixed !important; z-index: 1300 !important; top: 72px !important; right: 12px !important; bottom: auto !important; left: auto !important;
    display: grid !important; grid-template-columns: 1fr !important; width: min(276px,calc(100vw - 24px)) !important; height: auto !important;
    gap: 3px !important; padding: 12px !important; border: 1px solid rgba(255,255,255,.09) !important; border-radius: 16px !important;
    background: rgba(15,16,21,.98) !important; box-shadow: 0 22px 60px rgba(0,0,0,.62) !important;
    opacity: 0 !important; visibility: hidden !important; pointer-events: none !important; transform: translateY(-8px) scale(.98) !important;
    transform-origin: top right !important; transition: opacity .16s ease, transform .16s ease, visibility .16s ease !important;
  }
  body.mobile-menu-open .sidebar > .nav:not(.nav--footer) { opacity: 1 !important; visibility: visible !important; pointer-events: auto !important; transform: translateY(0) scale(1) !important; }
  .sidebar > .nav:not(.nav--footer) a {
    display: grid !important; grid-template-columns: 34px minmax(0,1fr) !important; grid-template-rows: 1fr !important;
    justify-items: start !important; align-items: center !important; gap: 10px !important; width: 100% !important; min-height: 48px !important;
    padding: 0 11px !important; border-radius: 11px !important; color: #d2d4d9 !important; font-size: 15px !important; text-align: left !important;
  }
  .sidebar > .nav:not(.nav--footer) a span { display: grid !important; width: 30px !important; height: 30px !important; place-items: center !important; color: #f0f1f3 !important; font-size: 18px !important; }
  .sidebar > .nav:not(.nav--footer) a .mobile-nav-icon img {
    display: block !important;
    width: 24px !important;
    height: 24px !important;
    object-fit: contain !important;
  }
  .sidebar > .nav:not(.nav--footer) a .mobile-nav-icon--premium img { width: 22px !important; height: 22px !important; }
  .sidebar > .nav:not(.nav--footer) a.is-active, .sidebar > .nav:not(.nav--footer) a:hover { color: #fff !important; background: #24262c !important; }
  .home-page, body.is-home .home-page, body.is-library .home-page, .detail-page, body.is-detail .detail-page { padding-bottom: 34px !important; }
}

@media (max-width: 390px) {
  .topbar, body.is-detail .topbar, body.is-watch .topbar { grid-template-columns: minmax(0,1fr) 40px 40px auto !important; gap: 5px !important; padding-inline: 10px !important; }
  .mobile-menu-button, .top-search, .top-search button, .notification-button, .profile-button { width: 40px !important; min-width: 40px !important; height: 40px !important; }
  .profile-avatar { width: 40px !important; height: 40px !important; }
  .topbar .logo-word { font-size: 19px !important; }
}

/* Mobile final pass: touch-first behavior and route-safe spacing. */
@media (max-width: 820px) {
  /* Exact centering for the compact header search icon. */
  .top-search button {
    position: relative !important;
    display: grid !important;
    place-items: center !important;
    padding: 0 !important;
  }
  .top-search button::before {
    position: absolute !important;
    inset: 0 !important;
    width: 19px !important;
    height: 19px !important;
    margin: auto !important;
    transform: none !important;
  }

  /* Mobile headings are clean text without the desktop star marker. */
  .section-head h2::before,
  .section-head h2::after,
  .poster-section .section-head h2::before,
  .poster-section .section-head h2::after {
    content: none !important;
    display: none !important;
  }
  .section-head h2 { gap: 0 !important; }

  /* Touch screens must never enter the legacy desktop hover state. */
  .poster-card:hover,
  .catalog-grid .poster-card:hover,
  .poster-grid .poster-card:hover,
  .library-grid .poster-card:hover,
  .results .poster-card:hover,
  .favorite-card:hover,
  .mini-card:hover {
    border-color: transparent !important;
    background: #08090c !important;
    box-shadow: none !important;
    filter: none !important;
    transform: none !important;
  }
  .poster-card:hover > img,
  .catalog-grid .poster-card:hover > img,
  .poster-grid .poster-card:hover > img,
  .library-grid .poster-card:hover > img,
  .results .poster-card:hover > img,
  .favorite-card:hover img {
    filter: saturate(1.08) contrast(1.03) !important;
    transform: none !important;
  }
  .poster-card:hover::after,
  .catalog-grid .poster-card:hover::after,
  .poster-grid .poster-card:hover::after,
  .results .poster-card:hover::after {
    background: linear-gradient(180deg, rgba(3,5,8,0) 38%, rgba(3,5,8,.16) 62%, rgba(3,5,8,.82) 100%) !important;
  }
  .poster-card__overlay,
  .poster-card__play,
  .card-favorite { display: none !important; }

  /* Favorites: three swipeable lanes. Hold a card, then drag it to a lane. */
  body.is-library #favoritesGrid.favorites-board {
    display: grid !important;
    grid-template-columns: repeat(3, calc(100vw - 38px)) !important;
    gap: 12px !important;
    width: calc(100% + var(--mobile-gutter)) !important;
    margin-right: calc(var(--mobile-gutter) * -1) !important;
    padding: 0 var(--mobile-gutter) 14px 0 !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    scroll-snap-type: x mandatory !important;
    scrollbar-width: none !important;
    touch-action: pan-x pan-y !important;
  }
  body.is-library #favoritesGrid.favorites-board::-webkit-scrollbar { display: none !important; }
  body.is-library #favoritesGrid .favorite-column {
    min-width: 0 !important;
    min-height: 320px !important;
    padding: 0 2px 22px !important;
    border-right: 0 !important;
    scroll-snap-align: start !important;
  }
  body.is-library #favoritesGrid .favorite-column__drop {
    min-height: 250px !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 16px 10px !important;
  }
  body.is-library #favoritesGrid .favorite-remove {
    display: grid !important;
    width: 30px !important;
    height: 30px !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    background: rgba(7,8,10,.86) !important;
    color: #fff !important;
  }
  body.is-library #favoritesGrid .favorite-card { touch-action: pan-y !important; }
  body.is-library #favoritesGrid .favorite-card.is-touch-dragging { opacity: .3 !important; }
  body.favorite-touch-drag-active { overflow: hidden !important; touch-action: none !important; }
  .favorite-touch-ghost {
    position: fixed !important;
    z-index: 3000 !important;
    top: 0 !important;
    left: 0 !important;
    width: 126px !important;
    margin: 0 !important;
    opacity: .92 !important;
    pointer-events: none !important;
    transform-origin: top left !important;
    filter: drop-shadow(0 18px 32px rgba(0,0,0,.62)) !important;
  }
  .favorite-touch-ghost .favorite-remove { display: none !important; }

  /* Detail: poster-first mobile composition; desktop banner is intentionally absent. */
  body.is-detail:not(.is-watch) #detailPage.detail-page {
    width: 100% !important;
    padding: 20px 18px 42px !important;
    overflow: visible !important;
  }
  body.is-detail:not(.is-watch) #detailPage .anime-detail-layout {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto !important;
  }
  body.is-detail:not(.is-watch) #detailPage .detail-banner {
    display: none !important;
  }
  body.is-detail:not(.is-watch) #detailPage .anime-detail-main {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) !important;
    gap: 24px !important;
    width: 100% !important;
  }
  body.is-detail:not(.is-watch) #detailPage .poster-column {
    width: min(70vw, 250px) !important;
    max-width: 250px !important;
    margin: 0 auto !important;
  }
  body.is-detail:not(.is-watch) #detailPage .anime-poster {
    width: 100% !important;
    border-radius: 13px !important;
  }
  body.is-detail:not(.is-watch) #detailPage .anime-info {
    width: 100% !important;
    padding: 0 !important;
    align-items: flex-start !important;
    text-align: left !important;
  }
  body.is-detail:not(.is-watch) #detailPage .title-line h1,
  body.is-detail:not(.is-watch) #detailPage .anime-info h1 {
    font-size: clamp(29px, 9vw, 40px) !important;
    line-height: 1 !important;
    text-align: left !important;
  }
  body.is-detail:not(.is-watch) #detailPage .description {
    width: 100% !important;
    font-size: 14px !important;
    line-height: 1.65 !important;
  }
  body.is-detail:not(.is-watch) #detailPage .poster-actions {
    width: 100% !important;
    grid-column: auto !important;
    flex-wrap: wrap !important;
  }
  body.is-detail:not(.is-watch) #detailPage .detail-episodes,
  body.is-detail:not(.is-watch) #detailPage .detail-extra { width: 100% !important; }

  /* Watch: safe gutters and menus that may extend beyond the video frame. */
  body.is-watch #detailPage.detail-page {
    width: 100% !important;
    padding: 18px 14px 38px !important;
    overflow: visible !important;
  }
  body.is-watch .watch-player-page {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  body.is-watch .ah-player {
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
  }
  body.is-watch .ah-player__video,
  body.is-watch .ah-player__upscale,
  body.is-watch .ah-player__embed,
  body.is-watch .ah-player__backdrop {
    border-radius: inherit !important;
  }
  body.is-watch .ah-player__top {
    display: grid !important;
    grid-template-columns: repeat(4,minmax(0,1fr)) !important;
    gap: 2px !important;
    overflow: visible !important;
    padding: 6px !important;
  }
  body.is-watch .ah-player-select { min-width: 0 !important; }
  body.is-watch .ah-player-select > button {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: 31px !important;
    gap: 3px !important;
    padding: 4px 5px !important;
  }
  body.is-watch .ah-player-select span { font-size: 9px !important; }
  body.is-watch .ah-player-select b { flex: 0 0 auto !important; font-size: 10px !important; }
  body.is-watch .ah-player-select__menu {
    z-index: 80 !important;
    min-width: min(210px, calc(100vw - 40px)) !important;
    max-height: 128px !important;
    overflow-y: auto !important;
  }
  body.is-watch .ah-player-select:nth-child(n+3) .ah-player-select__menu {
    right: 0 !important;
    left: auto !important;
  }
  body.is-watch .ah-player-select__menu button { min-height: 38px !important; font-size: 11px !important; }
}

@media (max-width: 390px) {
  body.is-detail:not(.is-watch) #detailPage.detail-page { padding-inline: 15px !important; }
  body.is-watch #detailPage.detail-page { padding-inline: 11px !important; }
  body.is-library #favoritesGrid.favorites-board { grid-template-columns: repeat(3, calc(100vw - 30px)) !important; }
}

/* Mobile polish 2: overlay player menus, corrected search glyph and compact profile/history. */
@media (max-width: 820px) {
  /* Draw the magnifier ourselves for optical rather than box centering. */
  .top-search button::before {
    content: "" !important;
    position: absolute !important;
    inset: 0 !important;
    display: block !important;
    width: 21px !important;
    height: 21px !important;
    margin: auto !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: #a9abb2 !important;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5' fill='none' stroke='black' stroke-width='2'/%3E%3Cpath d='M15.4 15.4 20 20' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat !important;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5' fill='none' stroke='black' stroke-width='2'/%3E%3Cpath d='M15.4 15.4 20 20' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat !important;
    transform: translateX(-1px) !important;
    box-sizing: border-box !important;
  }
  .top-search button::after {
    content: none !important;
    display: none !important;
  }

  /* Each selector opens one full-width floating sheet over the video. */
  body.is-watch .ah-player__top {
    inset: 0 !important;
    z-index: 40 !important;
    isolation: isolate !important;
    align-content: start !important;
    grid-auto-rows: max-content !important;
    pointer-events: none !important;
  }
  body.is-watch .ah-player-select {
    position: static !important;
    pointer-events: auto !important;
  }
  body.is-watch .ah-player-select__menu {
    position: absolute !important;
    z-index: 120 !important;
    top: 42px !important;
    right: 8px !important;
    left: 8px !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    max-height: calc(100% - 52px) !important;
    padding: 7px !important;
    overflow-y: auto !important;
    border-radius: 12px !important;
    background: rgba(12,13,16,.98) !important;
    box-shadow: 0 16px 44px rgba(0,0,0,.72) !important;
    backdrop-filter: blur(16px) !important;
  }
  body.is-watch .ah-player-select:nth-child(n+3) .ah-player-select__menu {
    right: 8px !important;
    left: 8px !important;
  }
  body.is-watch .ah-player-select__menu button {
    min-height: 40px !important;
    padding: 8px 10px !important;
  }

  /* One readable history entry per row. */
  html body.is-library #historyPage #historyGrid.history-list {
    display: grid !important;
    grid-template-columns: 100% !important;
    gap: 14px !important;
    width: 100% !important;
  }
  body.is-library #historyGrid .continue-history-card,
  body.is-library #historyGrid .history-card {
    width: 100% !important;
    min-width: 0 !important;
  }
  body.is-library #historyGrid .continue-history-cover,
  body.is-library #historyGrid .history-card__poster {
    width: 100% !important;
    aspect-ratio: 16/7 !important;
  }

  /* Profile hero stays a banner, and the add action shares one line with its title. */
  #profilePage .profile-hero {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    aspect-ratio: 16/7 !important;
    border-radius: 15px !important;
  }
  #profilePage .profile-section-head {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) auto !important;
    align-items: center !important;
    gap: 10px !important;
  }
  #profilePage .profile-section-head > div { min-width: 0 !important; }
  #profilePage .profile-section-head h2 {
    max-width: none !important;
    font-size: clamp(21px,6.7vw,27px) !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }
  #profilePage .profile-add-favorite {
    min-width: 108px !important;
    min-height: 42px !important;
    padding: 0 12px !important;
    font-size: 12px !important;
    white-space: nowrap !important;
  }
}

/* Mobile search: one icon source and deterministic optical centering. */

/* Full-bleed public profile banner with an avatar straddling its lower edge. */
body.is-library #profilePage.profile-page:not([hidden]) {
  width: 100vw !important;
  max-width: none !important;
  margin: 0 0 0 calc(50% - 50vw) !important;
  padding: 0 0 100px !important;
}

/* The profile hero starts directly under the shared header. */
body.is-library.is-profile .home-page {
  padding-top: 0 !important;
}

/* Keep the desktop banner footprint visible while its image is being fetched. */
@media (min-width: 821px) {
  body.is-detail:not(.is-watch) #detailPage .detail-banner.is-loading {
    display: block !important;
    background: linear-gradient(100deg, #15171c 24%, #252830 42%, #15171c 62%) !important;
    background-size: 220% 100% !important;
    animation: detail-banner-shimmer 1.25s linear infinite !important;
  }
}
body.is-detail:not(.is-watch) #detailPage .detail-banner.is-loading img {
  opacity: 0 !important;
}
body.is-detail:not(.is-watch) #detailPage .detail-banner img {
  transition: opacity 180ms ease;
}
@keyframes detail-banner-shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}
body.is-library #profilePage .profile-hero {
  width: 100% !important;
  min-height: 540px !important;
  overflow: visible !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: #08090b !important;
}
body.is-library #profilePage .profile-hero__banner,
body.is-library #profilePage .profile-hero__fade {
  inset: 0 0 auto !important;
  height: 320px !important;
  border-radius: 0 !important;
}
body.is-library #profilePage .profile-hero__identity {
  left: max(28px, calc((100vw - 1540px) / 2)) !important;
  right: max(28px, calc((100vw - 1540px) / 2)) !important;
  top: 250px !important;
  bottom: auto !important;
  max-width: none !important;
  flex-direction: row !important;
  align-items: flex-start !important;
  gap: 14px !important;
}
body.is-library #profilePage .profile-hero__boundary { width: 140px !important; flex: 0 0 140px !important; }
body.is-library #profilePage .profile-hero__details { padding-top: 16px !important; }
body.is-library #profilePage .profile-hero__avatar {
  width: 140px !important;
  height: 140px !important;
  flex-basis: 140px !important;
  border: 5px solid #08090b !important;
}
body.is-library #profilePage .profile-hero__identity h1 {
  font-size: clamp(32px, 4vw, 54px) !important;
}
body.is-library #profilePage .profile-edit-button {
  right: max(28px, calc((100vw - 1540px) / 2)) !important;
  bottom: 58px !important;
}
body.is-library #profilePage .profile-hero__actions {
  top: 24px !important;
  right: max(28px, calc((100vw - 1540px) / 2)) !important;
  bottom: auto !important;
  height: auto !important;
  align-items: flex-start !important;
}
body.is-library #profilePage .profile-hero__actions button { height: 40px !important; align-self: flex-start !important; }
body.is-library #profilePage > :not(.profile-hero) {
  width: min(100% - 96px, 1540px) !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

body.is-detail:not(.is-watch) #detailPage .detail-episodes__unavailable {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 28px 30px;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 16px;
  background: #15171b;
}
body.is-detail:not(.is-watch) #detailPage .detail-episodes__unavailable strong {
  color: #f5f5f6;
  font-size: clamp(19px, 2vw, 25px);
  font-weight: 900;
}
body.is-detail:not(.is-watch) #detailPage .detail-episodes__unavailable p {
  margin: 0;
  color: rgba(255, 255, 255, .56);
  font-size: 14px;
  line-height: 1.5;
}
#openWatchPage:disabled {
  cursor: default;
  opacity: .58;
}

@media (max-width: 760px) {
  body.is-detail:not(.is-watch) #detailPage .detail-episodes__unavailable {
    padding: 21px 19px;
    border-radius: 13px;
  }
}

/* Registration avatar roulette. */
.avatar-roulette {
  position: relative;
  display: grid;
  gap: 9px;
  margin: 6px 0 4px;
  padding: 12px 0 10px;
  overflow: hidden;
  border: 1px solid #2d3038;
  border-radius: 15px;
  background: #111318;
}
.avatar-roulette[hidden] { display: none !important; }
.avatar-roulette > p { margin: 0 14px; color: #c9cbd1; font-size: 12px; font-weight: 800; }
.avatar-roulette__viewport {
  width: 100%;
  overflow: hidden;
  scroll-behavior: smooth;
  mask-image: linear-gradient(90deg,transparent,#000 18%,#000 82%,transparent);
}
.avatar-roulette__track { display: flex; gap: 10px; width: max-content; padding: 4px calc(50% - 35px); }
.avatar-roulette__track img {
  width: 70px;
  height: 70px;
  flex: 0 0 70px;
  border: 3px solid transparent;
  border-radius: 50%;
  object-fit: cover;
  opacity: .58;
  transform: scale(.9);
  transition: transform .22s ease, opacity .22s ease, border-color .22s ease;
}
.avatar-roulette__track img.is-selected { opacity: 1; transform: scale(1); border-color: #ff986f; }
.avatar-roulette__marker { position: absolute; left: 50%; bottom: 5px; width: 0; height: 0; transform: translateX(-50%); border: 6px solid transparent; border-bottom-color: #ff986f; }
.avatar-roulette.is-spinning .avatar-roulette__track img { filter: saturate(.9); }

@media (max-width: 820px) {

  body.is-library #profilePage .profile-hero {
    min-height: 600px !important;
    aspect-ratio: auto !important;
  }

  body.is-library #profilePage .profile-hero__banner,
  body.is-library #profilePage .profile-hero__fade {
    height: 245px !important;
  }

  body.is-library #profilePage .profile-hero__identity {
    left: 18px !important;
    right: 18px !important;
    top: 190px !important;
    bottom: auto !important;

    display: grid !important;
    grid-template-columns: 110px minmax(0, 1fr) !important;
    grid-template-rows: 110px auto !important;

    column-gap: 16px !important;
    row-gap: 8px !important;

    align-items: center !important;
  }

  /* Аватар */
  body.is-library #profilePage .profile-hero__boundary {
    grid-column: 1 !important;
    grid-row: 1 !important;

    width: 110px !important;
    height: 110px !important;
    flex-basis: auto !important;
  }

  body.is-library #profilePage .profile-avatar-shell {
    position: relative !important;
    display: block !important;

    width: 110px !important;
    height: 110px !important;
  }

  body.is-library #profilePage .profile-hero__avatar {
    width: 110px !important;
    height: 110px !important;
    flex-basis: 110px !important;
  }

  /*
   * Делаем ник и статус отдельными
   * элементами мобильной grid-сетки.
   */
  body.is-library #profilePage .profile-hero__details {
    display: contents !important;
  }

  /* Ник под аватаркой */
  body.is-library #profilePage .profile-handle {
    grid-column: 1 !important;
    grid-row: 2 !important;

    margin: 0 !important;

    font-size: 13px !important;
    line-height: 1.2 !important;

    white-space: nowrap !important;
  }

  /* Старая корона около ника на мобиле не нужна */
  body.is-library #profilePage .profile-handle .premium-crown {
    display: none !important;
  }

  /* Статус сразу справа от аватарки */
  body.is-library #profilePage .profile-rank {
    grid-column: 2 !important;
    grid-row: 1 !important;

    align-self: center !important;
    justify-self: start !important;

    margin: 0 !important;
  }

  /* Premium-корона — сверху справа на аватарке */
  body.is-library #profilePage .profile-avatar-premium:not([hidden]) {
    display: flex !important;

    top: -3px !important;
    right: -3px !important;

    width: 31px !important;
    height: 31px !important;
  }

  /* Онлайн — снизу справа */
  body.is-library #profilePage .profile-avatar-presence {
    right: 3px !important;
    bottom: 3px !important;
  }

  body.is-library #profilePage .profile-edit-button {
    top: auto !important;
    right: 18px !important;
    bottom: 26px !important;
  }

  body.is-library #profilePage .profile-hero__actions {
    top: 14px !important;
    right: 14px !important;
    bottom: auto !important;
    height: auto !important;
  }

  body.is-library #profilePage .profile-hero__actions button {
    height: 36px !important;
  }

  body.is-library #profilePage > :not(.profile-hero) {
    width: calc(100% - 36px) !important;
  }
  .top-search,
  .top-search:hover,
  .top-search:focus-within {
    position: relative !important;
    display: block !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  .top-search button,
  .top-search:hover button,
  .top-search:focus-within button {
    position: absolute !important;
    inset: 0 !important;
    display: grid !important;
    place-items: center !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    transform: none !important;
  }

  .top-search button::before,
  .top-search button::after {
    content: none !important;
    display: none !important;
    -webkit-mask: none !important;
    mask: none !important;
  }

  .top-search button > svg {
    position: static !important;
    inset: auto !important;
    display: block !important;
    visibility: visible !important;
    flex: none !important;
    width: 20px !important;
    height: 20px !important;
    margin: 0 !important;
    overflow: visible !important;
    color: #a9abb2 !important;
    fill: none !important;
    stroke: currentColor !important;
    stroke-width: 2 !important;
    transform: translate(-1px, -1px) !important;
    transform-origin: center !important;
  }
}

@media (max-width: 360px) {
  #profilePage .profile-section-head h2 { font-size: 20px !important; }
  #profilePage .profile-add-favorite { min-width: 100px !important; padding-inline: 9px !important; font-size: 11px !important; }
}

/* Mobile header route lock: detail/watch must use the same single-row header. */
@media (max-width: 820px) {
  html:not([data-theme="light"]) body.is-detail .topbar,
  html:not([data-theme="light"]) body.is-watch .topbar,
  html body.is-detail .topbar,
  html body.is-watch .topbar {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) 42px 42px auto !important;
    grid-template-rows: 52px !important;
    gap: 7px !important;
    width: 100% !important;
    height: 64px !important;
    min-height: 64px !important;
    padding: 6px 12px !important;
    align-items: center !important;
  }

}

@media (max-width: 390px) {
  html:not([data-theme="light"]) body.is-detail .topbar,
  html:not([data-theme="light"]) body.is-watch .topbar,
  html body.is-detail .topbar,
  html body.is-watch .topbar {
    grid-template-columns: minmax(0,1fr) 40px 40px auto !important;
    gap: 5px !important;
    padding-inline: 10px !important;
  }
}
body.is-detail:not(.is-watch) #detailPage .chips span[hidden] {
  display: none !important;
}

/* Per-title history removal: hover on desktop, always visible on touch screens. */
body.is-library #historyGrid .continue-history-card {
  position: relative !important;
}

body.is-library #historyGrid .history-remove {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 6;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 50%;
  background: rgba(8, 9, 11, .82);
  box-shadow: 0 5px 18px rgba(0, 0, 0, .3);
  color: #fff;
  font: 700 25px/1 Arial, sans-serif;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: scale(.9);
  transition: opacity .16s ease, transform .16s ease, background-color .16s ease;
}

body.is-library #historyGrid .continue-history-card:hover .history-remove,
body.is-library #historyGrid .continue-history-card:focus-within .history-remove,
body.is-library #historyGrid .history-remove:focus-visible {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

body.is-library #historyGrid .history-remove:hover,
body.is-library #historyGrid .history-remove:focus-visible {
  background: rgba(207, 55, 55, .94);
  outline: none;
}

body.is-library #historyGrid .history-remove.is-error {
  background: rgba(207, 55, 55, .94);
}

@media (hover: none), (pointer: coarse), (max-width: 760px) {
  body.is-library #historyGrid .history-remove {
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }
}

body.is-detail:not(.is-watch) #detailPage .detail-season-switcher {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-top: 14px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 700;
}

body.is-detail:not(.is-watch) #detailPage .detail-season-switcher[hidden] {
  display: none !important;
}

body.is-detail:not(.is-watch) #detailPage .detail-season-switcher select {
  min-width: 150px;
  padding: 7px 34px 7px 10px;
  border: 0;
  border-radius: 10px;
  background: #292a30;
  color: #fff;
  font: inherit;
  cursor: pointer;
  outline: none;
}

body.is-detail:not(.is-watch) #detailPage .detail-season-switcher select:focus-visible {
  box-shadow: 0 0 0 2px #ff9567;
}

body.is-detail:not(.is-watch) #detailPage .detail-season-switcher option {
  background: #1b1c20;
  color: #fff;
}

@media (max-width: 760px) {
  body.is-detail:not(.is-watch) #detailPage .detail-season-switcher {
    width: fit-content;
    box-sizing: border-box;
  }

  body.is-detail:not(.is-watch) #detailPage .detail-season-switcher select {
    min-width: 150px;
    max-width: min(70vw, 280px);
  }
}

/* Compact desktop navigation: Random and Premium are icon actions. */
.top-actions {
  display: flex !important;
  align-items: center !important;
  justify-self: end !important;
  gap: 5px !important;
}

.header-icon-action {
  display: grid;
  place-items: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #c7c9ce;
  text-decoration: none;
  transition: color .2s ease, background .2s ease, opacity .2s ease;
}
.header-icon-action:hover,
.header-icon-action:focus-visible {
  background: rgba(255,255,255,.055);
  color: #fff;
  outline: none;
}
.header-icon-action svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.header-premium-action img { width: 23px; height: 23px; object-fit: contain; }
.header-premium-action:hover img { filter: brightness(1.12); }

@media (min-width: 1181px) {
  .topbar, body.is-detail .topbar, body.is-watch .topbar {
    grid-template-columns: minmax(205px,max-content) minmax(390px,1fr) minmax(240px,360px) max-content !important;
    column-gap: clamp(16px,1.65vw,30px) !important;
  }
  .topbar .logo, body.is-detail .topbar .logo { min-width: 205px !important; }
  .header-nav {
    display: flex !important;
    min-width: 0 !important;
    gap: clamp(14px,1.4vw,27px) !important;
  }
  .header-nav a { white-space: nowrap; }
  .top-search,
  .top-search:hover,
  .top-search:focus-within {
    width: min(26vw,360px) !important;
    min-width: 240px !important;
    justify-self: end !important;
  }
}

@media (min-width: 821px) and (max-width: 1180px) {
  .topbar, body.is-detail .topbar, body.is-watch .topbar {
    grid-template-columns: max-content minmax(260px,1fr) max-content !important;
  }
  .header-nav { display: none !important; }
  .top-search { width: min(44vw,440px) !important; justify-self: end !important; }
}

@media (max-width: 820px) {
  .header-icon-action {
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
    border-radius: 50% !important;
  }
}

@media (max-width: 520px) {
  .header-icon-action { display: none !important; }
}

/* Premium: matte hero, soft contour glow and typography instead of cards. */
.premium-page {
  padding: clamp(48px,6vw,88px) clamp(24px,5vw,84px) 96px !important;
  background: #070707 !important;
}
.premium-hero { max-width: 920px !important; margin-bottom: clamp(68px,8vw,112px) !important; }
.premium-hero__crown {
  position: relative;
  isolation: isolate;
  width: 154px !important;
  height: 154px !important;
  margin-bottom: 28px !important;
  border: 1px solid rgba(218,178,82,.58) !important;
  border-radius: 42px !important;
  background: #0c0c0b !important;
  box-shadow: 0 0 28px rgba(211,169,67,.12), inset 0 0 24px rgba(211,169,67,.035) !important;
  animation: premium-contour-glow 6.5s ease-in-out infinite;
}
.premium-hero__crown::after {
  content: "";
  position: absolute;
  inset: 8px;
  z-index: -1;
  border: 1px solid rgba(226,188,91,.14);
  border-radius: 34px;
  pointer-events: none;
}
.premium-hero__crown img { width: 96px !important; height: 96px !important; }
.premium-hero h1 {
  max-width: 880px;
  margin: 16px auto 22px !important;
  font-size: clamp(50px,6vw,88px) !important;
  line-height: .94 !important;
}
.premium-hero__lead {
  max-width: 590px !important;
  margin-bottom: 30px !important;
  color: #9b9b97 !important;
  font-size: 16px !important;
  line-height: 1.5 !important;
}
.premium-buy-button,
.premium-trial-button {
  min-height: 48px !important;
  border-radius: 11px !important;
  box-shadow: none !important;
  transform: none !important;
}
.premium-buy-button:hover { background: #e8c66e !important; }
.premium-current-status { margin-bottom: 0 !important; }

@keyframes premium-contour-glow {
  0%,100% { border-color: rgba(218,178,82,.42); box-shadow: 0 0 22px rgba(211,169,67,.09), inset 0 0 22px rgba(211,169,67,.025); }
  50% { border-color: rgba(235,199,106,.76); box-shadow: 0 0 42px rgba(211,169,67,.18), inset 0 0 30px rgba(211,169,67,.055); }
}

.premium-benefits {
  width: min(860px,100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.premium-benefits article {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(250px, 330px) minmax(0, 1fr);
  align-items: baseline;
  column-gap: clamp(48px, 7vw, 110px);
  padding: 24px 0;
  border-top: 1px solid rgba(218,178,82,.24);
  background: transparent;
  text-align: left;
}
.premium-benefits article:last-child { border-bottom: 1px solid rgba(218,178,82,.24); }
.premium-benefits h2 {
  margin: 0;
  color: #f4f3ef;
  font-size: clamp(24px,2.2vw,32px);
  line-height: .98;
  letter-spacing: -.05em;
}
.premium-benefits p {
  max-width: none;
  margin: 0;
  color: #858580;
  font-size: 14px;
  line-height: 1.5;
}
.premium-plan {
  width: min(1320px,100%) !important;
  margin: 78px auto 0 !important;
  padding: 34px 0 0 !important;
  border: 0 !important;
  border-top: 1px solid rgba(255,255,255,.1) !important;
  border-radius: 0 !important;
  background: transparent !important;
}
.premium-plan > img { width: 48px !important; height: 48px !important; opacity: .9; }
.premium-plan h2 { font-size: 26px !important; }
.premium-plan button { min-height: 46px; border-radius: 10px; }

@media (max-width: 900px) {
  .premium-page { padding-top: 40px !important; }
  .premium-hero__crown { width: 132px !important; height: 132px !important; border-radius: 36px !important; }
  .premium-hero__crown img { width: 82px !important; height: 82px !important; }
  .premium-hero h1 { font-size: clamp(45px,12vw,66px) !important; }
}

@media (max-width: 600px) {
  .premium-hero__actions { display: grid !important; grid-template-columns: 1fr !important; }
  .premium-buy-button, .premium-trial-button { width: 100%; justify-content: center; }
  .premium-benefits article { grid-template-columns: 1fr; gap: 10px; padding: 20px 0; }
  .premium-benefits p { grid-column: 1; }
  .premium-plan { margin-top: 56px !important; }
}

/* Three-second entry mark: the muted silhouette is progressively filled by the real logo. */
.brand-intro {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: #050506;
  opacity: 0;
  transition: opacity .28s ease;
}
.brand-intro.is-running { opacity: 1; }
.brand-intro.is-leaving { opacity: 0; pointer-events: none; }
.brand-intro__mark { position: relative; width: 118px; aspect-ratio: 1; }
.brand-intro__outline,
.brand-intro__fill,
.brand-intro__fill img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.brand-intro__outline { filter: grayscale(1) brightness(.62); opacity: .32; }
.brand-intro__fill { overflow: hidden; clip-path: inset(100% 0 0); animation: brand-logo-fill 2.35s .28s cubic-bezier(.45,0,.2,1) forwards; }
.brand-intro__name { color: #f5f4f2; font-size: 22px; font-weight: 900; letter-spacing: -.04em; opacity: 0; animation: brand-name-in .55s 1.85s ease forwards; }
.brand-intro__bubble { position: absolute; bottom: 12px; width: 7px; height: 7px; border-radius: 50%; background: #ff966d; opacity: 0; }
.brand-intro__bubble--one { left: 29%; animation: brand-bubble 1.45s .55s ease-out forwards; }
.brand-intro__bubble--two { right: 26%; animation: brand-bubble 1.25s 1.05s ease-out forwards; }
@keyframes brand-logo-fill { to { clip-path: inset(0 0 0); } }
@keyframes brand-name-in { to { opacity: 1; transform: translateY(0); } from { opacity: 0; transform: translateY(8px); } }
@keyframes brand-bubble { 0% { opacity: 0; transform: translateY(0) scale(.7); } 25% { opacity: .9; } 100% { opacity: 0; transform: translateY(-76px) scale(1.2); } }
.header-random-action[data-loading="1"] svg { animation: randomizer-working .7s linear infinite; }
@keyframes randomizer-working { to { transform: rotate(180deg); } }

@media (prefers-reduced-motion: reduce) {
  .premium-hero__crown { animation: none !important; }
  .brand-intro { display: none; }
}

/* Mobile title page: one calm centered axis from poster to actions. */
.ah-player-source,
.ah-player-telegram {
  min-height: 36px !important;
  font-size: 11.5px !important;
}
.ah-player-source { flex-basis: 88px !important; }
.ah-player-telegram { gap: 7px !important; padding-inline: 14px !important; }
.ah-player-telegram svg { width: 17px !important; height: 17px !important; }

@media (max-width: 760px) {
  body.is-detail:not(.is-watch) #detailPage .anime-info {
    align-items: center !important;
    text-align: center !important;
  }
  body.is-detail:not(.is-watch) #detailPage .title-line {
    width: 100% !important;
    justify-content: center !important;
  }
  body.is-detail:not(.is-watch) #detailPage .title-line h1,
  body.is-detail:not(.is-watch) #detailPage .anime-info h1,
  body.is-detail:not(.is-watch) #detailPage .description,
  body.is-detail:not(.is-watch) #detailPage .meta-list,
  body.is-detail:not(.is-watch) #detailPage #profileVotes {
    text-align: center !important;
  }
  body.is-detail:not(.is-watch) #detailPage .chips,
  body.is-detail:not(.is-watch) #detailPage .poster-actions {
    justify-content: center !important;
  }
  body.is-detail:not(.is-watch) #detailPage .detail-season-switcher {
    display: block !important;
    width: min(70vw, 250px) !important;
    max-width: 250px !important;
    margin: 14px auto 0 !important;
  }
  body.is-detail:not(.is-watch) #detailPage .detail-season-switcher[hidden] {
    display: none !important;
  }
  body.is-detail:not(.is-watch) #detailPage .detail-season-switcher select {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: 52px !important;
    border: 1px solid rgba(255,255,255,.1) !important;
    background: #050506 !important;
    color: #f5f5f5 !important;
  }
  body.is-detail:not(.is-watch) #detailPage article.anime-info p.description {
    text-align: center !important;
  }
  body.is-detail:not(.is-watch) #detailPage .detail-episodes__head {
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    text-align: center !important;
  }
  body.is-detail:not(.is-watch) #detailPage .detail-episodes__head span {
    padding-bottom: 0 !important;
  }
  body.is-detail:not(.is-watch) #detailPage .detail-episodes__list,
  body.is-detail:not(.is-watch) #detailPage .detail-episode-arc,
  body.is-detail:not(.is-watch) #detailPage .detail-episode-arc__grid {
    text-align: center !important;
  }

  .ah-player-sourcebar {
    gap: 5px !important;
    margin-bottom: 7px !important;
  }
  .ah-player-source,
  .ah-player-telegram {
    min-height: 30px !important;
    border-radius: 6px !important;
    font-size: 9.5px !important;
    line-height: 1.1 !important;
  }
  .ah-player-source { flex-basis: 66px !important; }
  .ah-player-telegram {
    gap: 5px !important;
    padding-inline: 8px !important;
    white-space: nowrap !important;
  }
  .ah-player-telegram svg { width: 14px !important; height: 14px !important; }
}

/* Final mobile profile geometry; intentionally last so older responsive rules cannot override it. */
@media (max-width: 820px) {
  body.is-library #profilePage .profile-hero {
    min-height: 385px !important;
  }
  body.is-library #profilePage .profile-hero__identity {
    grid-template-columns: 110px minmax(0, 1fr) !important;
    column-gap: 8px !important;
  }
  body.is-library #profilePage .profile-handle {
    width: 110px !important;
    justify-self: center !important;
    text-align: center !important;
  }
  body.is-library #profilePage .profile-rank {
    margin-left: 0 !important;
    transform: translateX(-2px) !important;
  }
  body.is-library #profilePage .profile-rank span {
    margin-left: 0 !important;
  }
  body.is-library #profilePage .profile-overview {
    margin-top: 10px !important;
  }
  body.is-library #profilePage .profile-friends-card {
    order: -1 !important;
  }
}
