/* Set Planner V4 (experimental service): phone portrait + landscape workspace.
   Input, sprite, renderer and desktop CSS are unchanged. Loaded LAST. */

/* Avoid iOS auto-zoom on item search, numeric and appearance inputs. */
@media (pointer:coarse) and (max-width:1100px) {
 html,body{max-width:100%;-webkit-text-size-adjust:100%}
 main :is(input[type="text"],input[type="search"],input[type="number"],select,textarea){
  font-size:16px!important;min-width:0;max-width:100%;box-sizing:border-box
 }
 #v4-library .catalog-controls{min-width:0!important;max-width:100%!important}
 #v4-library .catalog-controls .v4-v2-searchrow{min-width:0!important;max-width:100%!important}
 main :is(.panel,.v4-library-pane,.v4-preview-pane,.v4-appearance-column,.v4-appearance-pane){min-width:0}
 /* Page-level event popup must not escape the phone screen or bury its options. */
 #v4-events-dialog{
  max-width:calc(100vw - 12px)!important;
  width:min(540px,calc(100vw - 12px))!important;
  max-height:calc(100dvh - 12px)!important;
  overflow-y:auto!important;overscroll-behavior:contain
 }
 #v4-events-dialog .v4-events-content{
  max-height:calc(100dvh - 135px)!important;
  overflow-y:auto!important;overscroll-behavior:contain
 }
}
/* Portrait: three functional vertically scrolling panels. Prevent the old
   fullscreen + 100%-height cascade from trapping the wardrobe below the fold.
   Keep all existing panel controls and catalog scroll handling. */
@media(max-width:650px) and (orientation:portrait) {
 html,body{min-height:100dvh!important;max-height:none!important;overflow-x:hidden}
 main,main.v4-inline-resizable-panels,html.v4-embedded main,
 html.v4-embedded main.v4-inline-resizable-panels{
  display:flex!important;flex-direction:column!important;
  height:100dvh!important;max-height:100dvh!important;min-height:0!important;
  width:100%!important;max-width:100%!important;
  overflow-y:auto!important;overflow-x:hidden!important;
  -webkit-overflow-scrolling:touch;overscroll-behavior-y:contain;
  padding:8px 7px max(14px,env(safe-area-inset-bottom,0px))!important;
  gap:9px!important;
 }
 html.v4-embedded main{padding-top:calc(53px + env(safe-area-inset-top,0px))!important}
 main>#v4-character,main>#v4-library,main>.side,
 html.v4-embedded main>#v4-character,html.v4-embedded main>#v4-library,
 html.v4-embedded main>.side{
  position:relative!important;grid-column:auto!important;grid-row:auto!important;
  flex:none!important;width:100%!important;max-width:100%!important;
  height:auto!important;max-height:none!important;min-height:0!important;
  margin:0!important;overflow:visible!important
 }
 main>#v4-character,html.v4-embedded main>#v4-character{
  order:0!important;min-height:370px!important;height:clamp(370px,49dvh,530px)!important;
  overflow:auto!important;overscroll-behavior:contain
 }
 main>#v4-library,html.v4-embedded main>#v4-library{
  order:1!important;height:min(530px,72dvh)!important;min-height:340px!important;
  overflow:hidden!important
 }
 main>.side,html.v4-embedded main>.side{order:2!important;overflow:visible!important;gap:9px!important}
 main>.side>.panel{flex:none!important;height:auto!important;max-height:none!important;min-height:0!important}
 #v4-library .items,#v4-library #results{min-height:0;overscroll-behavior-y:contain}
 main .v4-inline-panel-grip{display:none!important}
 main>#v4-planner-controls{
  position:fixed!important;left:0!important;right:0!important;top:6px!important;
  width:100%!important;pointer-events:none!important
 }
 main>#v4-planner-controls button{pointer-events:auto!important}
 html.v4-embedded main>#v4-planner-controls{display:none!important}
}
/* Landscape phone: show all three panels side-by-side instead of the old
   two-row grid, which made a 350px-tall screen nearly unusable. */
@media(orientation:landscape) and (pointer:coarse) and (max-height:600px) and (max-width:1100px){
 html,body{min-height:0!important;height:100dvh!important;overflow:hidden!important}
 main,main.v4-inline-resizable-panels,
 html.v4-embedded main,html.v4-embedded main.v4-inline-resizable-panels{
  display:grid!important;
  grid-template-columns:minmax(190px,27%) minmax(245px,1fr) minmax(190px,26%)!important;
  grid-template-rows:minmax(0,1fr)!important;
  align-items:stretch!important;
  width:100%!important;max-width:100%!important;
  height:100dvh!important;min-height:0!important;max-height:100dvh!important;
  padding:4px 5px max(5px,env(safe-area-inset-bottom,0px))!important;
  margin:0!important;gap:5px!important;overflow:hidden!important
 }
 html.v4-embedded main{padding-top:calc(48px + env(safe-area-inset-top,0px))!important}
 main>#v4-library,html.v4-embedded main>#v4-library{
  grid-column:1!important;grid-row:1!important;
  display:flex!important;min-height:0!important;height:100%!important;max-height:100%!important;
  overflow:hidden!important
 }
 main>#v4-character,html.v4-embedded main>#v4-character{
  grid-column:2!important;grid-row:1!important;
  display:flex!important;min-height:0!important;height:100%!important;max-height:100%!important;
  overflow-y:auto!important;overflow-x:hidden!important;overscroll-behavior:contain
 }
 main>.side,html.v4-embedded main>.side{
  grid-column:3!important;grid-row:1!important;
  display:flex!important;flex-direction:column!important;
  min-height:0!important;height:100%!important;max-height:100%!important;
  overflow-y:auto!important;overflow-x:hidden!important;
  overscroll-behavior:contain;gap:6px!important
 }
 main>.side>.panel{flex:0 0 auto!important;min-height:0!important}
 #v4-library .panelheader{min-height:39px!important;padding:7px 8px!important}
 #v4-library .catalog-controls{padding:0 7px 6px!important;gap:5px!important}
 #v4-library .items,#v4-library #results{
  min-height:0!important;overflow-y:auto!important;overscroll-behavior-y:contain
 }
 #v4-library .catalog-controls .tabs{gap:3px!important}
 #v4-library .catalog-controls .tab{padding:4px 5px!important;font-size:10px!important}
 main .v4-inline-panel-grip{display:none!important}
 #v4-events-dialog .v4-events-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}
 #v4-events-dialog .v4-events-grid .v4-event-option{min-height:40px!important}
 main>#v4-planner-controls{top:5px!important}
 html.v4-embedded main>#v4-planner-controls{display:none!important}
}
/* Very narrow landscapes cannot fit 3 panels without clipping. Preserve touch
   access with an intentional horizontal workspace scroll, not hidden content. */
@media(orientation:landscape) and (pointer:coarse) and (max-height:600px) and (max-width:695px){
 main,main.v4-inline-resizable-panels,html.v4-embedded main,
 html.v4-embedded main.v4-inline-resizable-panels{
  display:flex!important;flex-direction:row!important;
  overflow-x:auto!important;overflow-y:hidden!important;
  -webkit-overflow-scrolling:touch;overscroll-behavior-x:contain;
  scroll-snap-type:x proximity;justify-content:flex-start!important;
 }
 main>#v4-library,main>#v4-character,main>.side,
 html.v4-embedded main>#v4-library,html.v4-embedded main>#v4-character,
 html.v4-embedded main>.side{
  flex:0 0 min(300px,75vw)!important;
  width:min(300px,75vw)!important;max-width:none!important;
  min-width:0!important;height:100%!important;max-height:100%!important;
  scroll-snap-align:start!important;grid-column:auto!important
 }
 main>#v4-character,html.v4-embedded main>#v4-character{flex-basis:min(360px,85vw)!important;width:min(360px,85vw)!important}
 main>.side,html.v4-embedded main>.side{overflow-y:auto!important}
}
