/* Final visual fixes — intentionally loaded after all legacy styles. */
: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: 24px !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; }
@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; align-items: center !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; }
}

/* 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.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; }
  body.is-watch .watch-comments {
    width: 100% !important;
    margin: 28px auto 0 !important;
    padding: 24px 2px 0 !important;
  }
  body.is-watch .watch-comments__head { gap: 12px !important; }
  body.is-watch .watch-comments__head h2 { font-size: 27px !important; }
  body.is-watch .watch-comments .comment-form { padding: 12px !important; }
  body.is-watch .watch-comments .comment-card { padding: 14px 4px !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. */
@media (max-width: 820px) {
  .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;
  }
}
