: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;
  grid-template-rows: minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
}

#game-frame {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  background: #05070b;
}

/* No border or padding: LOVE's mouse/touch coordinates assume the canvas box. */
#canvas {
  display: none;
  width: min(100%, calc((100dvh - 3.25rem - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 4 / 3));
  height: auto;
  max-height: 100%;
  aspect-ratio: 4 / 3;
  border: 0;
  padding: 0;
  outline: none;
  image-rendering: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#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;
}

#web-tools {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 3.25rem;
  padding: .45rem .65rem;
  background: #111827;
  border-top: 1px solid #263244;
}

#rom-button,
#mod-button,
#fullscreen-button {
  flex: 0 0 auto;
  min-height: 2.35rem;
  padding: .45rem .8rem;
  border: 1px solid #60a5fa;
  border-radius: .55rem;
  color: #eff6ff;
  background: #1d4ed8;
  font: inherit;
  font-weight: 700;
}

#rom-button:active,
#mod-button:active,
#fullscreen-button:active {
  background: #1e40af;
}

#rom-button:disabled,
#mod-button:disabled,
#fullscreen-button:disabled {
  opacity: .5;
}

#web-status {
  min-width: 0;
  overflow: hidden;
  color: #cbd5e1;
  font-size: .78rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

@media (orientation: portrait) {
  #canvas {
    width: 100%;
  }
}

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


/* Game mode: maximize the 4:3 framebuffer without stretching it. */
body.web-immersive {
  padding: 0;
}
body.web-immersive #app {
  grid-template-rows: minmax(0, 1fr);
  height: 100dvh;
}
body.web-immersive #web-tools {
  display: none;
}
body.web-immersive #game-frame {
  width: 100vw;
  height: 100dvh;
}
body.web-immersive #canvas {
  width: min(100vw, calc(100dvh * 4 / 3));
  max-width: 100vw;
  max-height: 100dvh;
}

#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 (max-width: 760px) {
  #web-tools { gap: .4rem; }
  #rom-button, #mod-button, #fullscreen-button {
    padding-left: .55rem;
    padding-right: .55rem;
    font-size: .82rem;
  }
}
