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

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: #07131d;
  overscroll-behavior: none;
}

html.pseudo-fullscreen,
html.pseudo-fullscreen body {
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.game-shell {
  width: min(100%, 960px);
  display: grid;
  gap: 8px;
  justify-items: center;
}

.canvas-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: calc(100dvh - 64px);
  background: #000;
  overflow: hidden;
}

#loadingCanvas,
#canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  image-rendering: pixelated;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#canvas {
  visibility: hidden;
}

.web-controls {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #d8e8f2;
  font-size: 13px;
  text-align: center;
}

#fullscreenButton {
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid #5ba0c8;
  border-radius: 4px;
  background: #0a1d29;
  color: #eef7ff;
  font: inherit;
  cursor: pointer;
}

.mobile-name-entry {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  width: min(calc(100% - 16px), 420px);
  transform: translateX(-50%);
  padding: 10px;
  border: 1px solid #5ba0c8;
  border-radius: 8px;
  background: rgba(7, 19, 29, 0.97);
  color: #eef7ff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.mobile-name-entry[hidden] {
  display: none;
}

.mobile-name-entry label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}

.mobile-name-row {
  display: flex;
  gap: 8px;
}

#mobileNameInput {
  min-width: 0;
  flex: 1;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #f0c24d;
  border-radius: 4px;
  background: #fff;
  color: #07131d;
  font: 20px/1.2 system-ui, sans-serif;
  text-transform: uppercase;
}

#mobileNameDone {
  min-height: 44px;
  padding: 8px 14px;
  border: 0;
  border-radius: 4px;
  background: #f0c24d;
  color: #07131d;
  font: 700 15px/1 system-ui, sans-serif;
}

:fullscreen .game-shell,
:-webkit-full-screen .game-shell,
.pseudo-fullscreen .game-shell,
.game-shell:fullscreen,
.game-shell:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  background: #000;
  align-content: center;
}

.pseudo-fullscreen .game-shell {
  position: fixed;
  z-index: 100;
  inset: 0;
}

:fullscreen .game-shell .canvas-frame,
:-webkit-full-screen .game-shell .canvas-frame,
.pseudo-fullscreen .game-shell .canvas-frame,
.game-shell:fullscreen .canvas-frame,
.game-shell:-webkit-full-screen .canvas-frame {
  width: min(100vw, calc(100dvh * 4 / 3));
  max-height: 100dvh;
}

:fullscreen .game-shell .web-controls,
:-webkit-full-screen .game-shell .web-controls,
.pseudo-fullscreen .game-shell .web-controls,
.game-shell:fullscreen .web-controls,
.game-shell:-webkit-full-screen .web-controls {
  position: fixed;
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  opacity: 0.75;
}

@media (max-width: 600px), (max-height: 560px) {
  body {
    padding: 0;
  }

  .game-shell {
    width: 100%;
    gap: 4px;
  }

  .canvas-frame {
    width: min(100vw, calc((100dvh - 44px) * 4 / 3));
    max-height: calc(100dvh - 44px);
  }

  .web-controls {
    min-height: 40px;
    padding: 0 8px max(2px, env(safe-area-inset-bottom));
  }
}
