Keeping containers intact on one page

Hi there nice people from the typst community, i’m creating a template for academic writing. So far i have some proof box defined, but there is a pretty annoying layout problem: sometimes the upper block and the bottom one of the problem box gets split across two pages, sometimes the QED block is drawn on the next page but the proof is on the current page.
I’d like to know if there is a way to make sure a block stays on one page, or at least, make sure the top part is. Thanks!

#let problem(content, bg: none) = context {
  block(
    [ #block(text([*Problem*], fill: white), inset: (top: 8pt, left: 8pt, bottom: -5pt)) // hard-coded but works
      #block(
        [ #content ],
        fill: accent-lighten(bg), // defined above
        inset: 8pt,
        width: page.width - page.margin.left * 2,
      )
    ],
    fill: (bg),
    width: page.width - page.margin.left * 2,
  )
}

You should try breakable: false in your first block.

#let problem(content, bg: none) = context {
  block(breakable: true)[...]
}

For further details, take a look at the doc :smiley:

If you have two blocks like this: #block() #block() and the first one is short and should always stick to the other block, then use #block(sticky: true) #block(). Sticky blocks are used for headings for example, to make sure they don’t lose contact with the paragraph that directly follows them.