/* Mobile / H5 layout.
 *
 * Breakpoint matches the reference demo: a narrow viewport OR a portrait-ish
 * aspect ratio. The second condition catches phones in landscape, where the
 * width is large but the UI still needs the touch layout. */

@media (max-aspect-ratio: 4/5), (max-width: 760px) {

  .topbar {
    height: calc(58px + var(--safe-top));
    padding: var(--safe-top) 10px 0;
    gap: 8px;
    position: relative;
    justify-content: center;
  }

  .mobileCategoryBtn {
    display: block;
    position: absolute;
    left: 10px;
    top: calc(50% + var(--safe-top) / 2);
    transform: translateY(-50%);
    z-index: 3;
    border: 1px solid var(--line);
    background: var(--panel);
    color: #fff;
    border-radius: 10px;
    padding: 9px 12px;
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
  }

  .brand {
    position: absolute;
    left: 50%;
    top: calc(50% + var(--safe-top) / 2);
    transform: translate(-50%, -50%);
    gap: 8px;
    z-index: 2;
  }
  .brand .logo { width: 30px; height: 30px; border-radius: 9px; }
  .brandCopy { align-items: center; }
  .brandName { font-size: 15px; }
  .brandSlogan { display: none; }

  .topNav { display: none; }

  .toolbar { position: absolute; right: 10px; top: calc(50% + var(--safe-top) / 2); transform: translateY(-50%); }
  .searchBox { display: none; }  /* search lives on its own page on mobile */
  .pill { padding: 8px 11px; font-size: 12px; }

  .mobileCategoryMenu {
    position: absolute;
    left: 10px;
    top: calc(60px + var(--safe-top));
    z-index: 45;
    width: min(230px, calc(100vw - 20px));
    background: #17171d;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
  }
  .mobileCategoryMenu.show { display: grid; gap: 4px; }
  .mobileCategoryMenu button {
    border: 0;
    background: transparent;
    color: #eee;
    text-align: left;
    padding: 12px;
    border-radius: 9px;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
  }
  .mobileCategoryMenu button:hover,
  .mobileCategoryMenu button.active { background: var(--panel2); color: #fff; }

  .page { padding: 12px 10px 0; }

  .hero {
    min-height: 230px;
    padding: 18px;
    border-radius: 20px;
  }
  .hero h1 { font-size: clamp(24px, 8vw, 32px); }
  .hero p { font-size: 14px; }
  .hero::after { right: -6%; width: 46%; }

  /* Rows become horizontal scrollers with snap points. */
  .grid {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .grid::-webkit-scrollbar { display: none; }
  .grid.singleRow .card:nth-child(n+7) { display: block; }  /* scroll, don't hide */
  .card { flex: 0 0 41vw; min-width: 0; scroll-snap-align: start; }

  .section { margin-top: 22px; }
  .sectionHead h2 { font-size: 17px; }
  .moreBtn { font-size: 12px; }

  .backRow h1 { font-size: 21px; }
  .listingGrid, .page .grid:not(.singleRow) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    overflow: visible;
  }
  .listingGrid .card, .page .grid:not(.singleRow) .card {
    flex: none;
    width: auto;
    min-width: 0;
  }

  .legalDoc { padding: 18px; }
  .siteFooter { margin-top: 30px; }

  .pager { margin: 24px 0 10px; }

  /* ---- page layout collapses; the sidebar flows to the bottom ----
     minmax(0, 1fr), not 1fr: a bare `1fr` is minmax(auto, 1fr), and the auto
     minimum lets a wide child (the hero/chip scrollers) stretch the column to
     its intrinsic width instead of the viewport. */
  .pageLayout { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  .siteSidebar { gap: 14px; }

  /* ---- series detail ---- */
  .seriesHero { grid-template-columns: 1fr; gap: 18px; }
  /* A definite width, not just a max-width.
     `margin: 0 auto` opts a grid item out of the default stretch, so its width
     falls back to fit-content — and every child of a `.cover` is absolutely
     positioned (`img` and the play button both are), so fit-content is zero.
     The poster then collapsed to its own 12px padding: a 24x36 box, which on a
     phone reads as "the poster is missing". `max-width: 100%` keeps it inside
     the viewport on the narrowest screens. */
  .seriesPoster { width: 200px; max-width: 100%; margin: 0 auto; }
  .seriesMeta h1 { font-size: 21px; }
  .seriesSynopsis { font-size: 13px; -webkit-line-clamp: 5; }
  .infoRow { grid-template-columns: 96px 1fr; }
  .episodeGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .episodeCard { padding: 10px 12px; }

  /* ---- history ---- */
  .historyRow { padding: 10px; gap: 11px; }
  .historyThumb { width: 52px; }
  .historyActions { flex-direction: column; gap: 6px; }
  .historyActions .btn { padding: 9px 12px; font-size: 12px; }

  /* ---- hero ---- */
  .heroCard { width: 44vw; }
  .heroSlides { gap: 10px; }

  /* ---- mobile bottom tab bar ----
     Fixed, so the page needs bottom padding to clear it. */
  .main { padding-bottom: calc(58px + var(--safe-bottom)); }

  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    background: rgba(14, 14, 18, .96);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    padding-bottom: var(--safe-bottom);
  }
  .tabbar.hidden { display: none; }

  .tabItem {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 9px 0 8px;
    color: #8b8b96;
    font-size: 10px;
    font-weight: 700;
    transition: color .15s;
  }
  .tabItem.active { color: #fff; }
  .tabIcon { font-size: 17px; line-height: 1; }

  /* The full-screen player covers the tab bar rather than sitting above it. */
  body:has(#playerPage.show) .tabbar { display: none; }

  /* Player */
  .info { left: 14px; right: 70px; bottom: calc(64px + var(--safe-bottom)); }
  .info h2 { font-size: 19px; }
  .info .desc { font-size: 12px; }
  .sideActions { right: 10px; bottom: calc(112px + var(--safe-bottom)); }
  .action { width: 44px; height: 44px; font-size: 17px; }
  .swipeHint { top: calc(62px + var(--safe-top)); }
  .backBtn { left: 12px; top: calc(12px + var(--safe-top)); }
  .posterArt { width: min(64%, 260px); font-size: 18px; }

  .modal { padding: 20px; }
  .modalActions { flex-direction: column-reverse; }
  .googleRewardModal .modalActions { flex-direction: row; }

  .newsContent { padding: 24px 16px 100px; }
  .newsContent p { font-size: 16px; }
}

/* Very small phones: keep two cards visible with a hint of the next. */
@media (max-width: 360px) {
  .card { flex: 0 0 46vw; }
}

/* Respect users who ask for less motion. */
@media (prefers-reduced-motion: reduce) {
  .stage.gestureAnimating { transition: none; }
  .skeleton { animation: none; }
  .card:hover { transform: none; }
}
