/* Phone Watch controls; portrait/landscape only. Desktop and Chat Only are untouched. */
.mobile-watch-status{display:none}
/* Never expose the mobile-only rotation setting on desktop or Chat Only. */
#mobileWatchOrientationBtn[hidden]{display:none!important}
@media (max-width:820px), (pointer:coarse) and (max-width:1000px) and (orientation:landscape){
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active:not(.theater) #stage{
    display:block!important;
    grid-template-columns:minmax(0,1fr)!important;
    height:calc(var(--pp-mobile-viewport-height,100dvh) - var(--topbar-height,58px));
    overflow:hidden;
    position:relative;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active:not(.theater) #stage:fullscreen{
    height:100dvh!important;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active:not(.theater) .content-column{
    display:flex!important;
    width:100%!important;
    height:100%!important;
    max-height:none;
    grid-column:1!important;
    grid-row:1!important;
    background:#000;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active:not(.theater) #playerShell{
    width:100%!important;
    height:100%!important;
    max-height:none;
    aspect-ratio:auto!important;
  }
  /* Chat and fullscreen now use the existing bottom player controls. */
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active #collapseChatBtn{display:grid!important}
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active #mobileWatchOrientationBtn:not([hidden]){display:flex}
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active #qualityMenu:not([hidden]){
    max-height:calc(100dvh - var(--topbar-height,58px) - 64px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));
    overflow-y:auto;
    overscroll-behavior:contain;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active .mobile-watch-status:not([hidden]){
    display:block;
    position:absolute;
    z-index:57;
    bottom:calc(66px + env(safe-area-inset-bottom,0px));
    right:calc(8px + env(safe-area-inset-right,0px));
    width:min(320px,calc(100vw - 16px));
    padding:10px 12px;
    border:1px solid #557390;
    border-radius:9px;
    background:rgba(7,18,29,.96);
    color:#e8f3ff;
    font:600 12px/1.4 system-ui,-apple-system,sans-serif;
  }
  /* The pre-existing portrait grid leaves chat under the video. This makes it
     an optional overlay drawer instead, without replacing/reparenting video. */
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active:not(.theater) #chatPanel{
    position:fixed!important;
    z-index:60!important;
    display:flex!important;
    flex-direction:column;
    grid-column:auto!important;
    grid-row:auto!important;
    top:auto!important;
    bottom:8px!important;
    left:8px!important;
    right:8px!important;
    width:auto!important;
    height:min(72dvh,620px)!important;
    max-height:calc(100dvh - 16px)!important;
    min-height:0;
    border:1px solid #39536a;
    border-radius:13px;
    background:#0b1825;
    box-shadow:0 12px 44px rgba(0,0,0,.62);
    overflow:hidden;
    transform:translate3d(0,calc(100% + 20px),0)!important;
    transition:transform .18s ease,visibility .18s ease!important;
    visibility:hidden;
    pointer-events:none;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatPanel{
    transform:translate3d(0,0,0)!important;
    visibility:visible;
    pointer-events:auto;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active:not(.theater) #chatPanel .chat-header{
    display:flex!important;
    flex:0 0 auto;
    min-height:48px;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active:not(.theater) #chatCloseBtn{display:grid!important}
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatScrim:not([hidden]){
    display:block!important;
    position:fixed;
    z-index:55;
    inset:0;
    background:rgba(0,0,0,.28);
    pointer-events:auto!important;
  }
}
@media (pointer:coarse) and (max-width:1000px) and (orientation:landscape){
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active:not(.theater) #chatPanel{
    /* Keep Poll and Close below the fixed top navigation on short phones. */
    top:calc(var(--topbar-height,58px) + 8px)!important;
    left:auto!important;
    right:8px!important;
    bottom:8px!important;
    width:min(370px,78vw)!important;
    height:calc(100dvh - var(--topbar-height,58px) - 16px)!important;
    max-height:calc(100dvh - var(--topbar-height,58px) - 16px)!important;
    transform:translate3d(calc(100% + 20px),0,0)!important;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatPanel{
    transform:translate3d(0,0,0)!important;
  }
}
@media (max-width:820px) and (orientation:landscape){
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active:not(.theater) #chatPanel{
    top:calc(var(--topbar-height,58px) + 8px)!important;left:auto!important;right:8px!important;bottom:8px!important;
    width:min(370px,78vw)!important;height:calc(100dvh - var(--topbar-height,58px) - 16px)!important;
    transform:translate3d(calc(100% + 20px),0,0)!important;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatPanel{
    transform:translate3d(0,0,0)!important;
  }
}
@media (prefers-reduced-motion:reduce){
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active #chatPanel{transition:none!important}
}

/* Keep touch scrolling inside the visible Watch chat drawer. Schedule is
   deliberately excluded; the protected chat and player JS stay untouched. */
@media (max-width:820px), (pointer:coarse) and (max-width:1000px) and (orientation:landscape){
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatPanel #messages{
    flex:1 1 0%;min-height:0;overflow-x:hidden;overflow-y:auto;
    overscroll-behavior-y:contain;touch-action:pan-y;-webkit-overflow-scrolling:touch;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatPanel :is(#emotePicker,#giphyPicker):not([hidden]){
    max-height:calc(100% - 112px);pointer-events:auto;
  }
}

/* Mobile Chrome touch reliability: preserve a stable scroll target and real
   keyboard/button hit areas inside the open drawer, independently of inert.
   These rules do not apply to desktop, Chat Only, or Schedule. */
@media (max-width:820px), (pointer:coarse) and (max-width:1000px) and (orientation:landscape){
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatPanel .chat-composer{
    position:relative;z-index:3;flex-shrink:0;pointer-events:auto;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatPanel .chat-input-wrap,
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatPanel #chatInput,
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatPanel :is(#emoteBtn,#giphyBtn,#sendBtn){
    pointer-events:auto;touch-action:manipulation;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatPanel #chatInput{
    -webkit-user-select:text;user-select:text;font-size:max(16px,1em);
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open:not(.theater) #chatPanel :is(#emotePicker,#giphyPicker):not([hidden]){
    z-index:12;overflow-y:auto;overscroll-behavior-y:contain;-webkit-overflow-scrolling:touch;
  }
}


/* Keyboard is a browser viewport overlay on some Android Chrome versions.
   Move ONLY the visible mobile Watch chat drawer; never resize the player. */
@media (max-width:820px), (pointer:coarse) and (max-width:1000px) and (orientation:landscape){
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open.mobile-watch-keyboard-open:not(.theater) #chatPanel{
    top:auto!important;
    bottom:calc(8px + var(--pp-android-chat-keyboard-inset,0px))!important;
    height:min(72dvh,620px,max(145px,calc(var(--pp-android-chat-visible-height,100dvh) - var(--topbar-height,58px) - 16px)))!important;
    max-height:max(145px,calc(var(--pp-android-chat-visible-height,100dvh) - var(--topbar-height,58px) - 16px))!important;
    transition:none!important;
  }
}


/* Mobile landscape: optional Twitch-style split layout without moving/reparenting
   the existing video element or modifying the frozen playback/event modules.
   The player shell continues to fill its existing Watch stage; keyboard clearance
   is confined to chat so input/pickers stay reachable during typing. */
@media (orientation:landscape) and (max-width:820px),
       (orientation:landscape) and (pointer:coarse) and (max-width:1000px){
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-active.mobile-watch-chat-open.mobile-watch-landscape-split:not(.theater) #stage{
    display:grid!important;
    grid-template-columns:minmax(0,1fr) clamp(230px,40vw,370px)!important;
    grid-template-rows:minmax(0,1fr)!important;
    gap:0;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-landscape-split:not(.theater) #stage .content-column{
    grid-column:1!important;
    grid-row:1!important;
    width:100%!important;
    height:100%!important;
    min-width:0;
    min-height:0;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-landscape-split:not(.theater) #chatPanel{
    position:relative!important;
    inset:auto!important;
    grid-column:2!important;
    grid-row:1!important;
    align-self:start;
    left:auto!important;
    right:auto!important;
    top:auto!important;
    bottom:auto!important;
    width:100%!important;
    height:var(--pp-watch-split-chat-visible-height,100%)!important;
    max-height:var(--pp-watch-split-chat-visible-height,100%)!important;
    min-height:0;
    border:0;
    border-left:1px solid #39536a;
    border-radius:0;
    box-shadow:none;
    transform:none!important;
    transition:none!important;
    visibility:visible;
    pointer-events:auto;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-landscape-split:not(.theater) #chatPanel .chat-header{
    display:flex!important;
    min-height:42px;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-landscape-split:not(.theater) #chatScrim{
    display:none!important;
    pointer-events:none!important;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-landscape-split:not(.theater) #chatPanel #messages{
    flex:1 1 0%;
    min-height:0;
    overflow-y:auto;
    overscroll-behavior-y:contain;
    -webkit-overflow-scrolling:touch;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-landscape-split:not(.theater) #chatPanel :is(#emotePicker,#giphyPicker):not([hidden]){
    position:absolute!important;
    top:auto!important;
    left:6px!important;
    right:6px!important;
    bottom:72px!important;
    width:auto!important;
    height:min(360px,calc(100% - 80px))!important;
    max-height:calc(100% - 80px)!important;
    min-height:0;
    z-index:20;
    overflow:hidden;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-landscape-split:not(.theater) #chatPanel :is(#emoteGrid,#giphyGrid){
    min-height:0;
    overflow-y:auto;
    overscroll-behavior-y:contain;
    -webkit-overflow-scrolling:touch;
  }
  html:not(.chat-only-page):not(.schedule-only-page) body.mobile-watch-landscape-split.mobile-watch-split-keyboard-open:not(.theater) #chatPanel .chat-header{
    display:none!important;
  }
}
