* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  /* Cloth, not black. Any band this shows through — the safe-area insets below, or the
     frame before the first paint — reads as part of the quilt instead of as a letterbox. */
  background: #F2E8D5;
  touch-action: none;
  overscroll-behavior: none;
}

#game {
  display: block;
  width: 100vw;
  /* Fallback only. See below: on iOS this is the WRONG height and always too tall. */
  height: 100vh;
  touch-action: none;
}

/* SPEC §13 A116 — THE VIEWPORT UNIT.
   iOS Safari resolves 100vh to the viewport height with the browser toolbars RETRACTED.
   This page cannot scroll (overflow: hidden, touch-action: none), so the toolbars never
   retract and that height is never the height the player can see. The canvas therefore
   ran underneath the bottom toolbar and the last row of every layout was off-screen —
   measured on an iPhone at 402 CSS px wide: computeMenuLayout was handed vh = 874 and
   put HOW TO PLAY's bottom edge at 854, about 154px below the ~700px that was visible.
   Nothing was wrong with the layout; it was being told the wrong size.
   dvh is the viewport that is actually visible, and because this page never scrolls it
   does not thrash between the small and large values the way a scrolling document does. */
@supports (height: 100dvh) {
  #game {
    height: 100dvh;
  }
}

/* index.html sets viewport-fit=cover so the cloth reaches the physical screen edges. That
   also means the notch and the home indicator are drawn OVER the page unless the content
   is inset out from under them — which matters most in the bKash mini-app webview, where
   there is no browser chrome to push the UI clear of either. Applied as margins plus a
   reduced box so the canvas becomes exactly the safe drawing area, which Renderer.resize()
   then picks up from getBoundingClientRect() with no JS change at all. */
@supports (height: 100dvh) and (padding: env(safe-area-inset-top)) {
  #game {
    width: calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    margin: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
            env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  }
}
