Detach gallery modals on close, so they don't pile up.