/* On narrow screens the engine settings are a viewport-fixed bottom sheet.
   Layout containment on the panel otherwise makes fixed descendants use the
   panel as their containing block, moving the sheet below the viewport. */
/* An open dialog can outgrow the visible part of its native panel after a
   resize or page scroll. The same family fallback is selected by the common
   controls mount; fitting desktop anchors keep their original positioning. */
.studio .play-panel:has(.settings-fit-viewport) { contain: style !important; }
.studio :is(.game-settings,.spark-engine-settings).settings-fit-viewport {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: auto;
  left: auto;
  width: min(420px,calc(100vw - 24px));
  max-width: none;
  box-sizing: border-box;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 60;
}
.studio :is(.game-settings,.spark-engine-settings).settings-fit-viewport :is(.game-settings-head,.spark-engine-settings-head) {
  position: sticky;
  top: 0;
  z-index: 1;
}
/* A short wide window cannot rely on panel anchoring: opening its trigger may
   scroll the panel above the viewport. Both existing dialogs use the same
   viewport policy, while normal-height desktop anchoring stays unchanged. */
@media (min-width: 521px) and (max-height: 600px) {
  .studio .play-panel { contain: style !important; }

  .studio :is(.game-settings,.spark-engine-settings) {
    position: fixed;
    top: 12px;
    right: 12px;
    bottom: auto;
    left: auto;
    width: min(420px,calc(100vw - 24px));
    max-width: none;
    box-sizing: border-box;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 60;
  }

  .studio :is(.game-settings,.spark-engine-settings) :is(.game-settings-head,.spark-engine-settings-head) {
    position: sticky;
    top: 0;
    z-index: 1;
  }
}
@media (max-width: 520px) {
  .studio .play-panel { contain: style !important; }

  /* Both game and engine sheets are viewport dialogs. On short screens the
     sheet itself scrolls, while its close control remains pinned at the top. */
  .studio :is(.game-settings,.spark-engine-settings) {
    box-sizing: border-box;
    max-height: 100vh;
    max-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .studio :is(.game-settings,.spark-engine-settings) :is(.game-settings-head,.spark-engine-settings-head) {
    position: sticky;
    top: 0;
    z-index: 1;
  }
}
