/* KD385 - landscape touch layout. Prevent desktop dock/tablet overflow.
 * Visual-only: no changes to RTS selection or commands. */
@media (pointer:coarse), (max-width:850px), (max-height:560px) {
  html:has(body.kd-android-touch373),html:has(body.kd-ios375),
  html:has(body.kd-mobile-fit385) {
    width:100%!important;max-width:100%!important;overflow-x:hidden!important;
    overscroll-behavior-x:none!important;
  }
  html body.kd-android-touch373,html body.kd-ios375,html body.kd-mobile-fit385{
    --kd-top:60px!important;--kd-rail:0px!important;--kd-dock-h:0px!important;
    --kd385-touch-bar:calc(64px + env(safe-area-inset-bottom,0px));
    box-sizing:border-box!important;min-width:0!important;
    width:100vw!important;max-width:100vw!important;
    overflow:hidden!important;overscroll-behavior:none!important;
  }
  html body.kd-android-touch373 #stage,html body.kd-android-touch373 #vignette,
  html body.kd-ios375 #stage,html body.kd-ios375 #vignette,
  html body.kd-mobile-fit385 #stage,html body.kd-mobile-fit385 #vignette {
    position:fixed!important;left:0!important;right:0!important;top:60px!important;
    bottom:var(--kd385-touch-bar)!important;
    width:100vw!important;max-width:100vw!important;
    height:auto!important;min-width:0!important;
    box-sizing:border-box!important;overflow:hidden!important;
  }
  html body.kd-android-touch373 #stage canvas,
  html body.kd-ios375 #stage canvas,
  html body.kd-mobile-fit385 #stage canvas{
    display:block!important;max-width:100vw!important;touch-action:none!important;
  }
  /* The 40%-high desktop bottom dock was accidentally activated on tablets.
     The full controls remain accessible through the existing touch ORDINI button. */
  html body.kd-android-touch373 #kd-reference-sidebar,
  html body.kd-ios375 #kd-reference-sidebar,
  html body.kd-mobile-fit385 #kd-reference-sidebar{
    box-sizing:border-box!important;position:fixed!important;
    display:flex!important;flex-direction:column!important;
    top:auto!important;left:0!important;right:0!important;
    bottom:var(--kd385-touch-bar)!important;
    width:100vw!important;min-width:0!important;max-width:100vw!important;
    height:min(60dvh,440px)!important;
    max-height:calc(100dvh - 80px - env(safe-area-inset-top,0px))!important;
    margin:0!important;padding:7px 8px 8px!important;
    overflow-y:auto!important;overflow-x:hidden!important;overscroll-behavior:contain!important;
    border-radius:11px 11px 0 0!important;
    transform:translateY(calc(100% + var(--kd385-touch-bar) + 4px))!important;
    pointer-events:none!important;visibility:hidden!important;z-index:146!important;
  }
  html body.kd-android-touch373.kd-mobile-open #kd-reference-sidebar,
  html body.kd-ios375.kd-mobile-open #kd-reference-sidebar,
  html body.kd-mobile-fit385.kd-mobile-open #kd-reference-sidebar{
    transform:translateY(0)!important;pointer-events:auto!important;visibility:visible!important;
  }
  html body.kd-android-touch373 #kd-reference-sidebar > .kd-hud-block:first-child,
  html body.kd-ios375 #kd-reference-sidebar > .kd-hud-block:first-child,
  html body.kd-mobile-fit385 #kd-reference-sidebar > .kd-hud-block:first-child{
    display:none!important;
  }
  html body.kd-android-touch373 #kd-reference-sidebar #kd-one-context,
  html body.kd-ios375 #kd-reference-sidebar #kd-one-context,
  html body.kd-mobile-fit385 #kd-reference-sidebar #kd-one-context{
    flex:1 1 auto!important;display:flex!important;flex-direction:column!important;
    box-sizing:border-box!important;width:100%!important;max-width:100%!important;
    min-width:0!important;min-height:0!important;height:auto!important;
    overflow-y:auto!important;overflow-x:hidden!important;
    margin:0!important;
  }
  html body.kd-android-touch373 #kd-one-context #kd-context-body,
  html body.kd-ios375 #kd-one-context #kd-context-body,
  html body.kd-mobile-fit385 #kd-one-context #kd-context-body{
    display:block!important;min-width:0!important;max-width:100%!important;
    overflow-x:hidden!important;overflow-y:auto!important;
    padding:5px!important;
  }
  html body.kd-android-touch373 #kd-one-context #kd-action-zone123,
  html body.kd-ios375 #kd-one-context #kd-action-zone123,
  html body.kd-mobile-fit385 #kd-one-context #kd-action-zone123{
    box-sizing:border-box!important;min-width:0!important;max-width:100%!important;
    overflow-x:hidden!important;overflow-y:auto!important;
  }
  html body.kd-android-touch373 #kd-one-context #kd-action-zone123 .orders-buttons,
  html body.kd-ios375 #kd-one-context #kd-action-zone123 .orders-buttons,
  html body.kd-mobile-fit385 #kd-one-context #kd-action-zone123 .orders-buttons{
    display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;
    width:100%!important;min-width:0!important;max-width:100%!important;
    gap:5px!important;
  }
  html body.kd-android-touch373 #kd-one-context #kd-action-zone123 .orders-buttons button,
  html body.kd-ios375 #kd-one-context #kd-action-zone123 .orders-buttons button,
  html body.kd-mobile-fit385 #kd-one-context #kd-action-zone123 .orders-buttons button{
    box-sizing:border-box!important;min-width:0!important;width:100%!important;
    max-width:100%!important;min-height:65px!important;height:65px!important;
    padding:36px 5px 6px!important;
    font:700 12px/1.1 system-ui,sans-serif!important;
  }
  html body.kd-android-touch373 #kd-one-context #kd-action-zone123 .orders-buttons button::before,
  html body.kd-ios375 #kd-one-context #kd-action-zone123 .orders-buttons button::before,
  html body.kd-mobile-fit385 #kd-one-context #kd-action-zone123 .orders-buttons button::before{
    height:30px!important;width:30px!important;top:3px!important;
  }
  /* Touch overlay is an independent panel: clip and size its grid to
     the actual viewport rather than inheriting the wide desktop grid. */
  html body.kd-android-touch373 #kdTouchMore373,
  html body.kd-ios375 #kdTouchMore373,
  html body.kd-mobile-fit385 #kdTouchMore373{
    box-sizing:border-box!important;position:fixed!important;
    left:8px!important;right:8px!important;width:auto!important;
    min-width:0!important;max-width:calc(100vw - 16px)!important;
    top:auto!important;
    bottom:var(--kd385-touch-bar)!important;
    height:auto!important;min-height:0!important;
    max-height:min(58dvh,calc(100dvh - 100px))!important;
    margin:0!important;padding:9px!important;
    overflow-x:hidden!important;overflow-y:auto!important;
    overscroll-behavior:contain!important;
    border-radius:10px!important;z-index:160!important;
    touch-action:pan-y!important;
  }
  html body.kd-android-touch373 #kdTouchMore373:not(.open),
  html body.kd-ios375 #kdTouchMore373:not(.open),
  html body.kd-mobile-fit385 #kdTouchMore373:not(.open){display:none!important}
  html body.kd-android-touch373 #kdTouchMore373.open,
  html body.kd-ios375 #kdTouchMore373.open,
  html body.kd-mobile-fit385 #kdTouchMore373.open{display:block!important}
  html body.kd-android-touch373 #kdTouchMore373 .kd-title,
  html body.kd-ios375 #kdTouchMore373 .kd-title,
  html body.kd-mobile-fit385 #kdTouchMore373 .kd-title{
    position:sticky!important;top:-9px!important;z-index:2!important;
    width:100%!important;max-width:100%!important;
    box-sizing:border-box!important;background:#10251ff5!important;
    margin:0 0 7px!important;padding:6px 4px!important;
    font:700 14px/1.15 system-ui,sans-serif!important;
  }
  html body.kd-android-touch373 #kdTouchMore373 .kd-grid,
  html body.kd-ios375 #kdTouchMore373 .kd-grid,
  html body.kd-mobile-fit385 #kdTouchMore373 .kd-grid{
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    box-sizing:border-box!important;width:100%!important;max-width:100%!important;
    min-width:0!important;gap:5px!important;align-items:stretch!important;
    padding:0!important;margin:0!important;overflow-x:hidden!important;
  }
  html body.kd-android-touch373 #kdTouchMore373 .kd-grid>button,
  html body.kd-ios375 #kdTouchMore373 .kd-grid>button,
  html body.kd-mobile-fit385 #kdTouchMore373 .kd-grid>button{
    display:flex!important;align-items:center!important;justify-content:center!important;
    box-sizing:border-box!important;width:100%!important;max-width:100%!important;
    min-width:0!important;min-height:39px!important;height:auto!important;
    margin:0!important;padding:5px 4px!important;
    font:700 clamp(10px,1.45vw,13px)/1.18 system-ui,sans-serif!important;
    overflow-wrap:anywhere!important;white-space:normal!important;
    text-align:center!important;touch-action:manipulation!important;
  }
  html body.kd-android-touch373 #kdTouchBar373,
  html body.kd-ios375 #kdTouchBar373,
  html body.kd-mobile-fit385 #kdTouchBar373{
    position:fixed!important;left:0!important;right:0!important;bottom:0!important;
    box-sizing:border-box!important;width:100vw!important;max-width:100vw!important;
    min-width:0!important;min-height:0!important;
    height:var(--kd385-touch-bar)!important;
    display:grid!important;grid-template-columns:repeat(7,minmax(0,1fr))!important;
    gap:3px!important;align-items:stretch!important;
    margin:0!important;
    padding:5px calc(5px + env(safe-area-inset-right,0px))
      calc(5px + env(safe-area-inset-bottom,0px))
      calc(5px + env(safe-area-inset-left,0px))!important;
    overflow:hidden!important;z-index:161!important;
  }
  html body.kd-android-touch373 #kdTouchBar373 button,
  html body.kd-ios375 #kdTouchBar373 button,
  html body.kd-mobile-fit385 #kdTouchBar373 button{
    box-sizing:border-box!important;display:block!important;width:100%!important;max-width:100%!important;
    min-width:0!important;height:100%!important;min-height:0!important;
    padding:3px 0!important;line-height:1.05!important;
    font-size:clamp(9px,1.45vw,12px)!important;
    white-space:pre-line!important;overflow:hidden!important;
    overflow-wrap:anywhere!important;touch-action:manipulation!important;
  }
  html body.kd-android-touch373 #kd378-root,
  html body.kd-ios375 #kd378-root,
  html body.kd-mobile-fit385 #kd378-root{
    max-width:calc(100vw - 12px)!important;
  }
  /* Preserve the group toolbar's user-driven drag positioning. */
  html body.kd-android-touch373 #kd378-root:not([style*="top:"]),
  html body.kd-ios375 #kd378-root:not([style*="top:"]),
  html body.kd-mobile-fit385 #kd378-root:not([style*="top:"]){
    bottom:calc(var(--kd385-touch-bar) + 5px)!important;
  }
  html body.kd-android-touch373:has(#kdTouchMore373.open) #kd378-root,
  html body.kd-ios375:has(#kdTouchMore373.open) #kd378-root,
  html body.kd-mobile-fit385:has(#kdTouchMore373.open) #kd378-root{
    visibility:hidden!important;pointer-events:none!important;
  }
  html body.kd-android-touch373 #kdTouchHint373,
  html body.kd-ios375 #kdTouchHint373,
  html body.kd-mobile-fit385 #kdTouchHint373{
    box-sizing:border-box!important;
    max-width:min(350px,calc(100vw - 24px))!important;
    top:calc(65px + env(safe-area-inset-top,0px))!important;
    overflow-wrap:anywhere!important;
  }
  html body.kd-android-touch373 #kdTouchPad373,
  html body.kd-ios375 #kdTouchPad373,
  html body.kd-mobile-fit385 #kdTouchPad373{
    max-width:calc(100vw - 16px)!important;
  }
  html body.kd-android-touch373 #kdDockHandle363,
  html body.kd-ios375 #kdDockHandle363,
  html body.kd-mobile-fit385 #kdDockHandle363{display:none!important}
}
/* Extra-small phones: two readable columns, not three clipped ones. */
@media (max-width:600px) {
 html body.kd-android-touch373 #kdTouchMore373 .kd-grid,
 html body.kd-ios375 #kdTouchMore373 .kd-grid,
 html body.kd-mobile-fit385 #kdTouchMore373 .kd-grid{
  grid-template-columns:repeat(2,minmax(0,1fr))!important;
 }
 html body.kd-android-touch373 #kdTouchBar373 button,
 html body.kd-ios375 #kdTouchBar373 button,
 html body.kd-mobile-fit385 #kdTouchBar373 button{
  font-size:9px!important;letter-spacing:-.2px!important
 }
}
@media(pointer:coarse) and (orientation:portrait) {
 html body.kd-android-touch373 #stage,html body.kd-ios375 #stage{top:85px!important}
 html body.kd-android-touch373 #top,html body.kd-ios375 #top{height:85px!important}
}
