/* ==========================================
   mobile.css - Mobile navigation, browse sheet, and compact layout
   ========================================== */

.mobile-tabbar,
.mobile-browse-sheet {
  display: none;
}

@media (max-width: 768px) {
  .tv-topbar {
    height: 64px;
    padding: 0 12px;
    gap: 10px;
    flex-wrap: nowrap;
  }

  .tv-topbar .app-nav-center {
    flex: 1;
    min-width: 0;
    max-width: none;
  }

  .tv-topbar .app-nav-left {
    min-width: 0;
  }

  .tv-topbar .tv-brand {
    width: auto;
    min-width: 0;
    height: 40px;
  }



  .tv-now-playing {
    display: none;
  }

  .tv-browse {
    padding-inline: 12px;
  }

  .carousel-track {
    grid-auto-columns: 44vw;
  }
}

@media (max-width: 480px) {
  .tv-topbar .app-nav-center {
    max-width: none;
  }


}

@media (max-width: 768px) {
  .guide-shell {
    display: none;
  }

  .guide-shell:not(.closed) {
    width: min(340px, calc(100vw - 24px));
  }

  .guide-shell .guide-rail {
    display: none;
  }

  .guide-shell:not(.closed) .guide-panel,
  body.guide-categories-open .guide-shell:not(.closed) .guide-panel {
    display: flex;
  }

  body.guide-categories-open .guide-shell:not(.closed) .guide-category-list {
    display: block;
  }

  body.guide-categories-open .guide-shell:not(.closed) .ch-scroll {
    display: none;
  }

  .guide-backdrop {
    inset: 0 0 calc(64px + env(safe-area-inset-bottom)) 0;
  }

  .chat-panel {
    bottom: calc(64px + env(safe-area-inset-bottom));
  }

  .ch-meta,
  .ch-live-dot {
    display: none !important;
  }

  .tv-topbar {
    position: fixed;
    bottom: 0;
    top: auto;
    height: 60px;
    padding-inline: 10px;
    z-index: 1000;
  }

  .tv-topbar .app-nav-left,
  .tv-topbar .app-nav-right {
    gap: 6px;
  }

  .tv-topbar .app-nav-center {
    max-width: none;
  }

  .tv-search .search-input {
    height: 40px;
    font-size: 0.86rem;
  }

  .tv-brand .brand-logo {
    width: 28px;
    height: 28px;
    max-width: 28px;
    max-height: 28px;
    flex-basis: 28px;
  }



  .tv-browse {
    padding: 14px 12px calc(86px + env(safe-area-inset-bottom));
    gap: 28px;
  }

  .carousel-track {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row;
    grid-auto-columns: initial;
    gap: 12px;
    margin: -10px -10px -2px;
    padding: 14px 10px 18px;
    overflow-x: visible;
    scroll-snap-type: none;
  }

  .carousel-track:not(.live-carousel-track) {
    display: grid;
  }

  .channel-carousel {
    padding-top: 0;
  }

  .home-section:not(.live-banner-section) {
    gap: 10px;
  }

  .home-section:not(.live-banner-section) .section-title {
    margin-bottom: 0;
  }

  .home-ch-card {
    scroll-snap-align: none;
  }

  .carousel-track:not(.live-carousel-track)>.home-ch-card {
    width: 100%;
    min-width: 0;
  }

  .home-ch-name,
  .channel-card-title {
    font-size: 0.86rem;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    min-height: 2.3em;
  }

  .channel-card-meta {
    font-size: 0.72rem;
  }

  .carousel-controls {
    position: static;
    padding: 3px;
    gap: 6px;
    flex: 0 0 auto;
  }

  .carousel-nav-btn {
    width: 40px;
    height: 40px;
  }

  .home-section:not(.live-banner-section) .carousel-controls {
    display: none;
  }

  body.is-watching .tv-player-shell {
    position: sticky;
    top: 60px;
    z-index: 90;
  }

  body.is-watching .stage {
    aspect-ratio: 16 / 9;
    height: auto;
    max-height: none;
  }

  .ctrl-bar {
    min-height: auto;
    padding: 8px 10px 4px;
    display: grid;
    grid-template-rows: auto auto;
    grid-template-columns: 1fr;
    gap: 6px;
    align-content: end;
  }

  .ctrl-bar .ctrl-btn,
  .ctrl-bar .ctrl-qual-btn,
  .ctrl-bar .ctrl-live-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 8px 10px;
  }

  .ctrl-bar .vol-wrap {
    grid-column: auto;
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0;
    order: 0;
  }

  .ctrl-bar .vol-wrap .ctrl-btn {
    flex-shrink: 0;
  }

  .ctrl-bar .vol-slider {
    flex: 0 0 auto;
    height: 3px;
    accent-color: #fff;
  }

  .ctrl-bar .ctrl-spacer {
    display: none;
  }

  .ctrl-bar .ctrl-channel-name {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 2px 8px;
    order: 3;
  }

  .ctrl-bar .qual-wrap {
    display: flex;
    gap: 6px;
    justify-content: center;
    order: 2;
  }

  .ctrl-bar .ctrl-qual-btn#ctrl-qual:not([hidden]),
  .ctrl-bar .ctrl-qual-btn#ctrl-srv:not([hidden]) {
    display: inline-flex;
  }

  .ctrl-bar .qual-wrap:has(.ctrl-qual-btn:not([hidden])) {
    display: flex;
  }

  .ctrl-quality-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    order: 2;
    margin-left: auto;
  }

  .quality-badge {
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    min-width: 36px;
    text-align: center;
  }

  .buffer-indicator {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    height: 10px;
  }

  .buffer-bar {
    width: 3px;
    height: 100%;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 1px;
    transition: background-color 0.2s ease, height 0.2s ease;
  }

  .buffer-bar.filled {
    background: var(--accent);
    box-shadow: 0 0 4px var(--accent-glow);
  }
}

@media (max-width: 520px) {
  .tv-topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 8px;
  }

  .tv-now-playing {
    display: none;
  }

  .tv-search .search-input {
    padding-left: 36px;
  }

  .carousel-track {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row;
    grid-auto-columns: initial !important;
  }

  .carousel-track:not(.live-carousel-track)>.home-ch-card {
    width: 100%;
    max-width: none;
  }

  .home-section:not(.live-banner-section) .section-title {
    padding-right: 0;
  }
}

@media (max-width: 768px) {
  body.is-watching {
    height: auto;
    min-height: 100dvh;
    overflow: hidden;
  }

  body.is-watching .tv-main {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #000;
  }

  body.is-watching .tv-player-shell {
    position: sticky;
    top: 0;
    z-index: 100;
    margin: 0;
  }

  body.is-watching .stage {
    aspect-ratio: 16 / 9;
    height: auto;
    max-height: none;
  }

  body.is-watching #watch-more {
    display: block;
    padding-top: 34px;
    padding-bottom: 32px;
    background: #000;
  }

  body.is-watching .wm-header {
    display: flex;
    padding: 16px 16px 12px;
    border-top: 0;
    background: #000;
  }

  body.is-watching .wm-title {
    display: block;
    font-size: 0.94rem;
  }

  body.is-watching #wm-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  body.is-watching .wm-toggle-btn {
    min-height: 32px;
    padding: 5px 10px;
    border-radius: 0;
    font-size: 0.76rem;
  }

  body.is-watching .wm-category {
    margin-bottom: 18px;
  }

  body.is-watching .wm-cat-title {
    padding: 0 16px;
    margin-bottom: 8px;
    font-size: 1rem;
  }

  body.is-watching .wm-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding: 0 16px 22px;
  }

  body.is-watching .wm-thumb {
    border-radius: 8px;
  }

  body.is-watching .wm-name {
    margin-top: 8px;
    font-size: 0.84rem;
    font-weight: 700;
  }

  body.is-watching .wm-meta {
    font-size: 0.72rem;
  }
}

@media (max-width: 768px) {
  .ctrl-quality-indicator {
    padding: 3px 8px;
    font-size: 0.6rem;
  }

  .ctrl-quality-indicator .buffer-bar {
    width: 30px;
  }
}

@media (max-width: 480px) {
  body.is-watching .wm-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding-inline: 16px;
  }
}

@media (max-width: 768px) {
  body.is-watching {
    height: auto;
    min-height: 100dvh;
    overflow: hidden;
    background: #000;
  }

  body.is-watching .app {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  body.is-watching .tv-main,
  body.is-watching .app-main {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #000;
  }

  body.is-watching .tv-player-shell,
  body.is-watching .player-shell {
    position: sticky;
    top: 0;
    z-index: 90;
    width: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #000;
  }

  body.is-watching .stage {
    width: 100%;
    aspect-ratio: auto;
    height: calc(100vw * 9 / 16);
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  body.is-watching .stage.is-embed {
    width: 100%;
    aspect-ratio: auto;
    height: calc(100vw * 9 / 16);
    border-radius: 0;
  }

  body.is-watching #watch-more {
    display: block;
    padding: 14px 12px calc(92px + env(safe-area-inset-bottom));
    background: #000;
  }

  body.is-watching .wm-header {
    align-items: center;
    padding: 4px 0 12px;
    background: transparent;
  }

  body.is-watching .wm-title {
    font-size: 0.95rem;
    color: var(--text2);
    font-weight: 800;
  }

  body.is-watching .wm-toggle-btn {
    min-height: 34px;
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 0.72rem;
    color: var(--text2);
    background: #080808;
  }

  body.is-watching .wm-category {
    margin-bottom: 22px;
  }

  body.is-watching .wm-cat-title {
    padding: 0;
    margin: 0 0 10px;
    font-size: 1.05rem;
    line-height: 1.2;
  }

  body.is-watching .wm-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 12px;
    padding: 0;
  }

  body.is-watching .wm-thumb {
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    background: #f7f7f7;
  }

  body.is-watching .wm-name {
    margin-top: 8px;
    min-height: auto;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 800;
    line-height: 1.25;
    -webkit-line-clamp: 2;
  }

  body.is-watching .wm-meta {
    display: none;
  }

  body.is-watching .guide-shell {
    display: none;
  }

  body.is-watching .ctrl-bar {
    position: absolute;
    inset: auto 0 0;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 34px 10px 10px;
    pointer-events: auto;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.82), rgba(0, 0, 0, 0.24) 62%, transparent);
  }

  body.is-watching .ctrl-bar .ctrl-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border-radius: 999px;
    background: transparent;
    backdrop-filter: none;
  }

  body.is-watching .ctrl-bar .ctrl-btn:hover,
  body.is-watching .ctrl-bar .ctrl-btn:focus-visible {
    background: rgba(255, 255, 255, 0.14);
  }

  body.is-watching .ctrl-bar .ctrl-live-btn {
    width: auto;
    height: 30px;
    min-height: 30px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 0.68rem;
    background: rgba(0, 0, 0, 0.5);
  }

  body.is-watching .ctrl-bar .vol-wrap {
    display: flex;
    align-items: center;
  }

  body.is-watching .ctrl-bar .vol-slider,
  body.is-watching .ctrl-bar #ctrl-cc,
  body.is-watching .ctrl-bar .ctrl-quality-indicator,
  body.is-watching .ctrl-bar .ctrl-channel-name {
    display: none !important;
  }

  body.is-watching .ctrl-bar .qual-wrap {
    display: flex;
    position: relative;
    align-items: center;
    flex: 0 0 auto;
  }

  body.is-watching .ctrl-bar .ctrl-qual-btn {
    gap: 4px;
    min-width: 34px;
    min-height: 30px;
    height: 30px;
    padding: 0 7px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.5);
    font-size: 0.56rem;
    letter-spacing: 0.02em;
    backdrop-filter: blur(10px);
  }

  body.is-watching .ctrl-bar .ctrl-qual-btn svg {
    width: 11px;
    height: 11px;
  }

  body.is-watching .ctrl-bar .qual-menu {
    right: 0;
    bottom: calc(100% + 6px);
    min-width: 0;
    width: min(168px, calc(100vw - 24px));
    max-height: 42dvh;
    border-radius: 12px;
    overflow-y: auto;
  }

  body.is-watching .ctrl-bar .qual-menu-label {
    padding: 8px 12px 6px;
    font-size: 0.58rem;
  }

  body.is-watching .ctrl-bar .qual-item {
    min-height: 34px;
    padding: 7px 12px;
    font-size: 0.72rem;
  }

  body.is-watching .ctrl-bar .qual-item:hover,
  body.is-watching .ctrl-bar .qual-item:focus-visible {
    padding-left: 14px;
  }

  body.is-watching .ctrl-bar .qual-item.active::after {
    font-size: 0.68rem;
  }

  body.is-watching .ctrl-bar .qual-bitrate {
    margin-left: 6px;
    font-size: 0.58rem;
  }

  body.is-watching .ctrl-bar .ctrl-spacer {
    display: block !important;
    flex: 1 1 auto;
    min-width: 0;
  }

  body.is-watching .ctrl-bar #ctrl-fs {
    margin-left: 0;
    order: 20;
  }

  body.is-watching.chat-open .tv-main,
  body.is-watching.chat-open .app-main {
    flex: 0 0 auto;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  body.is-watching.chat-open .tv-player-shell,
  body.is-watching.chat-open .player-shell {
    position: relative;
    top: auto;
    flex: 0 0 auto;
  }

  body.is-watching.chat-open .chat-panel {
    display: flex !important;
    flex: 1 1 auto !important;
    width: 100% !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border) !important;
    border-left: 0 !important;
    background: #050505;
  }

  body.is-watching.chat-open .chat-header {
    display: flex;
    flex: 0 0 auto;
  }

  body.is-watching.chat-open .chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    padding: 14px;
  }

  body.is-watching.chat-open .chat-input-area {
    flex: 0 0 auto;
  }
}

@media (max-width: 380px) {
  body.is-watching #watch-more {
    padding-inline: 10px;
  }

  body.is-watching .wm-grid {
    gap: 12px 10px;
  }

  body.is-watching .wm-name {
    font-size: 0.78rem;
  }
}

@media (max-width: 768px) {
  :root {
    --nav-h: 78px;
  }

  body {
    height: auto;
    min-height: 100dvh;
    overflow-x: hidden;
  }

  .mobile-tabbar {
    position: fixed;
    left: 50%;
    right: auto;
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 1100;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: min(calc(100vw - 24px), 300px);
    min-height: 58px;
    padding: 6px;
    border: 1px solid rgba(255, 255, 255, 0.11);
    border-radius: 20px;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.028)),
      rgba(9, 12, 17, 0.88);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.12),
      0 18px 54px rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(18px);
    transform: translateX(-50%);
  }

  .mobile-tabbar-btn {
    display: grid;
    place-items: center;
    min-width: 0;
    min-height: 46px;
    border: 0;
    border-radius: 16px;
    background: transparent;
    color: var(--text3);
    font: inherit;
    cursor: pointer;
    transition:
      background var(--transition-fast),
      color var(--transition-fast),
      transform var(--transition-fast),
      box-shadow var(--transition-fast);
  }

  .mobile-tabbar-btn svg {
    width: 21px;
    height: 21px;
  }

  .mobile-tabbar-btn span {
    display: none;
  }

  #mobile-tab-chat {
    display: none !important;
  }

  body.is-watching .mobile-tabbar {
    bottom: calc(4px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: min(calc(100vw - 18px), 390px);
    min-height: 60px;
  }

  body.is-watching #mobile-tab-chat {
    display: grid !important;
  }

  .mobile-tabbar-btn.is-active {
    color: var(--accent);
    background: rgba(53, 214, 164, 0.14);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.08),
      0 10px 28px rgba(53, 214, 164, 0.12);
  }

  .mobile-tabbar-btn:focus-visible {
    color: var(--text);
    outline: 0;
    background: rgba(255, 255, 255, 0.1);
    box-shadow:
      0 0 0 2px rgba(255, 255, 255, 0.14),
      0 0 0 5px rgba(53, 214, 164, 0.12);
  }

  .mobile-tabbar-btn:active {
    transform: scale(0.96);
  }

  body.mobile-browse-open .mobile-tabbar {
    z-index: 1601;
  }

  .mobile-browse-sheet {
    position: fixed;
    inset: 0;
    z-index: 1500;
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding: 18px 14px calc(92px + env(safe-area-inset-bottom));
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(14px);
  }

  body.mobile-browse-open .mobile-browse-sheet {
    display: flex;
  }

  .mobile-browse-shell {
    width: min(360px, 100%);
    max-height: min(70dvh, 520px);
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 18px;
    background:
      linear-gradient(180deg, rgba(15, 17, 23, 0.97), rgba(7, 8, 11, 0.98)),
      #08090d;
    box-shadow: 0 24px 90px rgba(0, 0, 0, 0.62);
  }

  .mobile-browse-head {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 14px 14px 10px;
    background: rgba(8, 9, 13, 0.9);
    backdrop-filter: blur(14px);
  }

  .mobile-browse-head h2 {
    color: var(--text);
    font-size: 1rem;
    font-weight: 900;
    text-align: center;
  }

  .mobile-browse-close {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text2);
  }

  .mobile-browse-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    padding: 10px 12px 16px;
  }

  .mobile-browse-btn {
    min-width: 0;
    min-height: 84px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 6px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font: inherit;
  }

  .mobile-browse-btn:active {
    transform: scale(0.97);
  }

  .mobile-browse-icon {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: rgba(53, 214, 164, 0.1);
    color: var(--accent);
  }

  .mobile-browse-icon svg {
    width: 20px;
    height: 20px;
  }

  .mobile-browse-name {
    max-width: 100%;
    overflow: hidden;
    font-size: 0.68rem;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-browse-count {
    color: var(--text3);
    font-size: 0.62rem;
    font-weight: 800;
  }

  body.is-watching .player-shell,
  body.is-watching .tv-player-shell {
    flex: none;
  }

  body.is-watching .player-shell .stage,
  body.is-watching .tv-player-shell .stage {
    aspect-ratio: auto !important;
    height: calc(100vw * 9 / 16) !important;
    min-height: 0 !important;
    max-height: none !important;
    flex: none !important;
  }

  body.is-watching .player-shell #player,
  body.is-watching .player-shell #embed-player,
  body.is-watching .tv-player-shell #player,
  body.is-watching .tv-player-shell #embed-player {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain !important;
    object-position: center center;
  }
}
