/* Installed app safe areas. Reserve system chrome only in app display modes.
   The document and every top-layer dialog are independent layout containers. */
:root{--elf-app-safe-top:0px;--elf-app-safe-bottom:0px}
@media (display-mode:standalone),(display-mode:minimal-ui),(display-mode:window-controls-overlay),(display-mode:fullscreen){
  :root{--elf-app-safe-top:env(safe-area-inset-top,0px);--elf-app-safe-bottom:env(safe-area-inset-bottom,0px)}
}
:root.elf-ios-standalone,:root.elf-installed{
  --elf-app-safe-top:env(safe-area-inset-top,0px);
  --elf-app-safe-bottom:env(safe-area-inset-bottom,0px);
}
:root{--elf-app-safe-height:calc(100dvh - var(--elf-app-safe-top) - var(--elf-app-safe-bottom))}
.elf-w3 .app-shell{box-sizing:border-box;padding-top:var(--elf-app-safe-top)}
/* Retain the main shell's existing bottom navigation inset. Never apply
   the parent document's safe-area insets inside an embedded game/editor. */
@media(max-width:760px),(pointer:coarse){
  /* Full-screen top-layer surfaces: use a safe viewport rectangle rather
     than padding the iframe or its contents. Works for older installed
     iOS apps that retain black-translucent status-bar settings. */
  :root.elf-installed .elf-w3 > :is(#elfAvatarDialog,#raceDialog,#judgeIntroDialog,#elfInstallDialog)[open]{
    position:fixed!important;
    inset-block-start:var(--elf-app-safe-top)!important;
    inset-block-end:var(--elf-app-safe-bottom)!important;
    margin-block:auto!important;
    max-height:var(--elf-app-safe-height)!important;
    box-sizing:border-box;
  }
  /* These previously applied their own insets; the outer dialog now
     accounts for them once. Keep ordinary internal spacing. */
  :root.elf-installed .elf-w3 #judgeIntroDialog .welcome-stage{padding-block:18px}
  :root.elf-installed .elf-w3 #elfInstallDialog .install-header{padding-top:4px}
  :root.elf-installed .elf-w3 #raceDialog .race-results-inner{padding-bottom:12px}
  /* Centre all other top-level dialogs inside the safe region with a
     small breathing margin. Includes dynamically created family and
     confirmation dialogs, event entry/how-to, standings and settings. */
  :root.elf-installed .elf-w3 > dialog[open]:not(:is(#elfAvatarDialog,#raceDialog,#judgeIntroDialog,#elfInstallDialog)){
    position:fixed!important;
    inset-block-start:calc(var(--elf-app-safe-top) + 8px)!important;
    inset-block-end:calc(var(--elf-app-safe-bottom) + 8px)!important;
    margin-block:auto!important;
    max-height:min(94dvh,calc(var(--elf-app-safe-height) - 16px))!important;
    box-sizing:border-box;
  }
  :root.elf-installed .elf-w3 > dialog.dialog[open] > .modal{
    max-height:min(88dvh,calc(var(--elf-app-safe-height) - 16px))!important;
  }
  :root.elf-installed .elf-w3 > #eventDialog[open] > .entry-flow{
    max-height:min(94dvh,calc(var(--elf-app-safe-height) - 16px))!important;
  }
  :root.elf-installed .elf-w3 > :is(#authDialog,#recoveryDialog,#familyClubhouseDialog)[open] > .modal{
    max-height:min(88dvh,calc(var(--elf-app-safe-height) - 24px))!important;
  }
}
