:root {
  color-scheme: dark;
  background: #05070b;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #05070b;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  display: grid;
  /* A DEFINITE column, so #game-frame has a definite width and the canvas's
     max-width: 100% actually resolves. Without it the column falls back to
     the canvas's min-content width and a narrow (portrait) viewport is
     overflowed by the engine's own pixel width. */
  grid-template-columns: minmax(0, 1fr);
  /* ONE row. The second `auto` row existed only to seat the preparation rack;
     with the rack gone the launcher/canvas frame is the whole box, and the
     presentation scalar (#canvas below) re-fits the engine rectangle into the
     taller frame by itself. Nothing else about the geometry changes. */
  grid-template-rows: minmax(0, 1fr);
  width: 100%;
  height: 100%;
}

#game-frame {
  position: relative;
  display: grid;
  /* DEFINITE tracks. A percentage max-height only resolves against a
     definite containing block, and an implicit auto row is indefinite --
     which silently disables the canvas's max-height: 100% and lets the
     engine's pixel height overflow the frame. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  min-width: 0;
  min-height: 0;
  /* The canvas is momentarily at its raw pixel size between window creation
     and the first presentation; it must not be able to blow up the layout. */
  overflow: hidden;
  background: #05070b;
}

/*
 * No border or padding: LÖVE's mouse/touch coordinates assume the canvas box.
 *
 * NO CSS WIDTH/HEIGHT/ASPECT-RATIO HERE, and that is the whole point.
 * SDL's emscripten backend probes the canvas at window creation (backing set
 * to 1x1, CSS box read back): if the CSS box is not 1x1, the canvas is
 * flagged EXTERNALLY SIZED and every love.window.setMode is discarded in
 * favour of floor(cssW) x floor(cssH). A stylesheet that sizes this element
 * therefore takes the window away from the engine -- which is exactly what
 * kept the game at its old shape. The size below is published by
 * web-bridge-v13.js only AFTER the engine has chosen its rectangle.
 */
#canvas {
  display: none;
  /* PRESENTATION, and nothing else: a canvas is a replaced element with an
     intrinsic size and ratio taken from its width/height ATTRIBUTES -- which
     SDL owns. auto sizes plus these two maxima are therefore a uniform
     "contain" fit of the engine's rectangle inside the frame: scaleX ==
     scaleY by definition of the rule, computed by the browser, with no
     scalar for anything to get wrong. And it is invisible to SDL's probe,
     because a 1x1 canvas is already under both maxima. */
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border: 0;
  padding: 0;
  outline: none;
  image-rendering: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/*
 * While SDL creates or re-creates the window, the canvas must keep a LAYOUT
 * box (so the 1x1 probe reads a real element) but must not be seen at its
 * raw pixel size for a frame. visibility, never display.
 */
body.web-engine-resizing #canvas {
  visibility: hidden;
}

#spinner {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: .75rem;
  justify-items: center;
  color: #dbeafe;
  font-size: .95rem;
}

#spinner:not(.pending):not(.loading):not(.error) {
  display: none;
}

.spinner-dot {
  width: 2rem;
  height: 2rem;
  border: .2rem solid #334155;
  border-top-color: #60a5fa;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

#spinner.error .spinner-dot {
  border-color: #ef4444;
  animation: none;
}

/* The preparation rack (#web-tools, #rom-button, #mod-button,
   #fullscreen-button, #web-status) was removed with this build. Its one
   irreplaceable job -- reporting a Web-side failure the launcher never gets to
   see, such as a rejected file type or size -- is now a transient toast that
   owns no layout: it is position: fixed, appears only on a blocking error and
   removes itself. It is never a permanent bar and never covers a control. */
#web-toast {
  position: fixed;
  left: max(.6rem, env(safe-area-inset-left));
  right: max(.6rem, env(safe-area-inset-right));
  bottom: max(.6rem, env(safe-area-inset-bottom));
  z-index: 99998;
  padding: .55rem .7rem;
  border: 1px solid #ef4444;
  border-radius: .6rem;
  background: rgba(20, 8, 8, .92);
  color: #fee2e2;
  font-size: .82rem;
  line-height: 1.25;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity .18s ease;
  pointer-events: none;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#web-toast.visible {
  opacity: 1;
  visibility: visible;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Portrait needs no special rule: the engine keeps its launcher rectangle and
   the presentation scalar already fits it to the frame. */

@media (prefers-reduced-motion: reduce) {
  .spinner-dot { animation-duration: 1.8s; }
}


/* Game mode keeps the actual safe-area box as the game measurement box. */
body.web-immersive {
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.web-immersive #app {
  grid-template-rows: minmax(0, 1fr);
  height: 100%;
}
body.web-immersive #game-frame {
  width: 100%;
  height: 100%;
}
/* Game mode changes only the size of the frame; the presentation scalar
   re-derives itself from it, and the engine rectangle follows on the next
   published target. */

#immersive-exit {
  position: fixed;
  top: max(.45rem, env(safe-area-inset-top));
  right: max(.45rem, env(safe-area-inset-right));
  z-index: 100000;
  display: none;
  min-width: 2.35rem;
  min-height: 2.35rem;
  border: 1px solid rgba(255,255,255,.38);
  border-radius: 999px;
  background: rgba(5,7,11,.66);
  color: #fff;
  font: 700 1rem/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
body.web-immersive #immersive-exit {
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  #web-toast { transition: none; }
}
