/* Studio mobile layout: keep cards in normal flow and reserve space for navigation. */
@media (max-width:900px) {
  body[data-area="studio"]:not(.editing) .ws-main,
  body[data-area="studio"]:not(.editing) .ws-main :is(.grid2,.stats,.stat,.lane,.panel,.grp,.sq-card,.lab-pick,.o-h-b,.sec-r) { min-width:0; }
  body[data-area="studio"]:not(.editing) .ws-main { overflow-wrap:anywhere; }
  body[data-area="studio"]:not(.editing) .app { padding-bottom:calc(130px + env(safe-area-inset-bottom,0px)); }
  body[data-area="studio"]:not(.editing) .sp-stage { height:auto; perspective:none; padding:14px; cursor:auto; }
  body[data-area="studio"]:not(.editing) .sp-world { position:relative; inset:auto; display:grid; grid-template-columns:minmax(0,1fr); gap:12px; padding:0; overflow:visible; perspective:none; transform:none!important; translate:none!important; transform-style:flat; will-change:auto; }
  body[data-area="studio"]:not(.editing) .sp-center,
  body[data-area="studio"]:not(.editing) .sp-p { position:relative; inset:auto; width:100%; max-width:100%; min-width:0; margin:0; flex:auto; transform:none!important; translate:none!important; scale:none!important; animation:none!important; opacity:1; }
  body[data-area="studio"]:not(.editing) .sp-center { padding:12px 0 20px; }
  body[data-area="studio"]:not(.editing) .sp-p { min-height:0; padding:16px; }
  body[data-area="studio"]:not(.editing) :is(.sp-fx,.sp-hint) { display:none; }
  body[data-area="studio"]:not(.editing) .sp-list span { flex-wrap:wrap; }
  body[data-area="studio"]:not(.editing) .sp-list span em { white-space:normal; }
  body[data-area="studio"]:not(.editing) .st-two { grid-template-columns:minmax(0,1fr)!important; }
  body[data-area="studio"]:not(.editing) .stats { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
  body[data-area="studio"]:not(.editing) .stat :is(.v,.k) { overflow-wrap:anywhere; }
  body[data-area="studio"]:not(.editing) :is(.lane header,.sq-head,.sq-c-top) { flex-wrap:wrap; gap:10px; }
  body[data-area="studio"]:not(.editing) .sq-list { grid-template-columns:repeat(auto-fit,minmax(min(100%,260px),1fr)); }
  body[data-area="studio"]:not(.editing) .ws-tabbar button { min-width:0; overflow-wrap:anywhere; }
  body[data-area="studio"]:not(.editing) .ws-sheet { bottom:calc(10px + env(safe-area-inset-bottom,0px)); max-height:calc(100dvh - 32px - env(safe-area-inset-bottom,0px)); }
}
@media (max-width:480px) {
  body[data-area="studio"]:not(.editing) :is(.stats,.mny-kpis,.sq-stats,.st-grid) { grid-template-columns:minmax(0,1fr); }
  body[data-area="studio"]:not(.editing) .lrow { display:grid; grid-template-columns:36px minmax(0,1fr); gap:8px; }
  body[data-area="studio"]:not(.editing) .lrow-r { grid-column:2; align-items:flex-start; }
  body[data-area="studio"]:not(.editing) .ot-r { grid-template-columns:minmax(0,1fr); }
  body[data-area="studio"]:not(.editing) .ot-r>span:nth-child(2) { grid-column:auto; }
}
/* The set builder uses the same safe sizing when opened as a full screen editor. */
@media (max-width:999px) {
  :is(.sd,.sd-over) :is(.sd-bar,.sd-tb,.sd-main,.sd-add,.sd-side,.sd-tabs) { min-width:0; max-width:100%; }
  :is(.sd,.sd-over) .sd-main { grid-template-columns:minmax(0,1fr); height:auto; min-height:0; }
  .sd-bar>.sd-tb { flex:1 1 100%; }
  .sd-bar>.sd-r { margin-left:0; }
  :is(.sd,.sd-over) :is(.sd-tabs,.sd-views,.sd-sub) { overflow-x:auto; flex-wrap:nowrap; }
  :is(.sd,.sd-over) .sd-stage { min-height:240px; }
  :is(.sd,.sd-over) .sd-tools { right:10px; width:max-content; max-width:calc(100% - 20px); flex-wrap:wrap; border-radius:16px; }
  :is(.sd,.sd-over) .sd-hint { border-radius:12px; white-space:normal; }
  :is(.sd,.sd-over) .sd-seg { flex-wrap:wrap; }
  :is(.sd,.sd-over) .sd-seg button { flex:1 1 80px; min-width:0; }
}

/* Mobile scroll repair: full editor content must participate in its scroll area. */
@media (max-width:999px) {
  .sd-over { height:100dvh; max-height:100dvh; }
  .sd-over .sd-oh { position:relative; inset:auto; flex:0 0 auto; padding:10px 12px; }
  .sd-over .sd-ob { overflow-x:hidden; overflow-y:auto; min-height:0; -webkit-overflow-scrolling:touch; overscroll-behavior-y:contain; padding:0 10px calc(20px + env(safe-area-inset-bottom,0px)); }
  .sd-over .sd { height:auto; min-height:0; display:grid; gap:10px; }
  .sd-over .sd-main { position:relative!important; inset:auto; display:grid!important; height:auto!important; min-height:0; }
  .sd-over .sd-stage { position:relative!important; inset:auto; height:46dvh!important; min-height:240px!important; }
  .sd-over :is(.sd-bar,.sd-tabs) { position:relative; inset:auto; width:100%; max-width:100%; }
  .sd-over :is(.sd-add,.sd-side) { position:relative!important; inset:auto; max-height:none; overflow:visible; transform:none!important; transition:none; }
  .sd-over .sd[data-sheet="0"] :is(.sd-add,.sd-side) { display:none!important; }
  .sd-over .sd-grab { display:none!important; }
  .sd .sd-tile { touch-action:pan-x pan-y; }
  .sd :is(.sd-add,.sd-side) { -webkit-overflow-scrolling:touch; }
}
@media (max-width:900px) {
  /* A retained/hidden chat node must not disable document scrolling. */
  body:has(.chat):not(.editing):not(.lb-open):not(:has(.ws-sheet)) { overflow-x:clip; overflow-y:visible; }
  html.sd-lock:not(:has(.sd-over,.dv-over,.dv-full)),
  html.sd-lock:not(:has(.sd-over,.dv-over,.dv-full)) body { overflow-x:clip!important; overflow-y:auto!important; }
  .ws-sheet>* { flex-shrink:0; }
  .labc-card { max-height:none; }
  .labc-b { overflow:visible; }
  .s3-track { height:auto!important; max-height:none!important; }
}
