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

body {
  background: #050a12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  font-family: "Courier New", monospace;
  color: #fff;
  overflow: hidden;
  user-select: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(
      ellipse at 20% 50%,
      rgba(245, 166, 35, 0.04) 0%,
      transparent 60%
    ),
    radial-gradient(
      ellipse at 80% 50%,
      rgba(100, 181, 246, 0.04) 0%,
      transparent 60%
    );
  pointer-events: none;
}

#wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(100vw, 860px);
  padding: 12px;
}

#game-shell {
  position: relative;
  width: 100%;
}

#utility-bar {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-top: 2px;
}

body.mobile-controls-enabled #utility-bar {
  justify-content: flex-end;
  padding-right: max(8px, env(safe-area-inset-right));
}

#gameCanvas {
  display: block;
  border: 2px solid #f5a623;
  border-radius: 6px;
  box-shadow:
    0 0 30px rgba(245, 166, 35, 0.35),
    0 0 80px rgba(245, 166, 35, 0.12),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  max-width: 100vw;
  image-rendering: pixelated;
  width: 100%;
  height: auto;
  touch-action: none;
}

#fullscreen-btn {
  position: relative;
  min-width: 122px;
  padding: 8px 12px;
  border: 2px solid #f5a623;
  border-radius: 10px;
  background: rgba(10, 16, 26, 0.88);
  color: #f5a623;
  font-family: "Courier New", monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(245, 166, 35, 0.24);
  z-index: 5;
}

#fullscreen-btn:hover {
  background: rgba(24, 36, 52, 0.92);
}

#fullscreen-btn:active {
  transform: translateY(1px);
}

#fullscreen-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

#fullscreen-btn[hidden] {
  display: none;
}

#controls-hint {
  font-size: 12px;
  color: #556;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

#mobile-controls {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(10px, env(safe-area-inset-bottom));
  width: 100%;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  padding: 0 14px;
  z-index: 30;
  pointer-events: none;
}

.touch-pad,
.touch-middle,
.touch-actions {
  display: flex;
  gap: 14px;
  pointer-events: auto;
}

.touch-middle {
  align-items: center;
  justify-content: center;
  min-width: 72px;
}

.touch-btn {
  border: 2px solid #f5a623;
  border-radius: 14px;
  background: rgba(10, 16, 26, 0.92);
  color: #f5a623;
  font-family: "Courier New", monospace;
  font-weight: 700;
  letter-spacing: 0.6px;
  box-shadow: 0 0 18px rgba(245, 166, 35, 0.25);
  user-select: none;
  touch-action: none;
}

.touch-btn:active {
  transform: translateY(1px);
  background: rgba(28, 40, 58, 0.95);
}

.touch-pad .touch-btn {
  width: 104px;
  height: 104px;
  border-radius: 52px;
  font-size: 38px;
}

.touch-btn-jump {
  width: 138px;
  height: 104px;
  border-radius: 52px;
  font-size: 22px;
}

.touch-btn-back {
  min-width: 84px;
  height: 64px;
  border-radius: 32px;
  font-size: 14px;
  padding: 0 14px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

#fullscreen-inline-btn[hidden] {
  display: none;
}

#mobile-controls-hint {
  display: none;
  font-size: 11px;
  color: #6f7d90;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

body.mobile-controls-enabled {
  overflow: hidden;
}

body.mobile-controls-enabled #mobile-controls,
body.mobile-controls-enabled #mobile-controls-hint {
  display: flex;
}

body.mobile-controls-enabled #wrapper {
  padding-bottom: calc(150px + env(safe-area-inset-bottom));
}

body.mobile-controls-enabled #controls-hint {
  display: none;
}

body.fullscreen-active.mobile-controls-enabled #utility-bar {
  display: none;
}

body.pseudo-fullscreen {
  background: #000;
  overflow: hidden;
}

body.pseudo-fullscreen #wrapper {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: var(--pseudo-vw, 100dvw);
  max-width: none;
  height: var(--pseudo-vh, 100dvh);
  padding: 0;
  gap: 8px;
}

body.pseudo-fullscreen #game-shell {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

body.pseudo-fullscreen #gameCanvas {
  width: 100%;
  max-width: 100vw;
  max-height: 100%;
  height: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body.pseudo-fullscreen #utility-bar {
  position: relative;
  width: 100%;
  justify-content: flex-end;
  padding: 0 max(10px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) 10px;
  margin-top: 0;
}

body.pseudo-fullscreen.mobile-controls-enabled #wrapper {
  padding-bottom: calc(112px + env(safe-area-inset-bottom));
}

body.pseudo-fullscreen.mobile-controls-enabled #mobile-controls {
  display: flex;
  z-index: 60;
}

body.fullscreen-active.mobile-controls-enabled #mobile-controls {
  display: flex;
  bottom: 0;
  align-items: flex-end;
  min-height: 42vh;
  padding: 0 14px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.78) 0%,
    rgba(0, 0, 0, 0.55) 42%,
    rgba(0, 0, 0, 0) 100%
  );
  z-index: 75;
}

body.fullscreen-active.mobile-controls-enabled #wrapper,
body.fullscreen-active.mobile-controls-enabled #wrapper:fullscreen,
body.fullscreen-active.mobile-controls-enabled #wrapper:-webkit-full-screen {
  padding-bottom: 0;
}

#wrapper:fullscreen,
#wrapper:-webkit-full-screen {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100vw;
  max-width: none;
  height: 100vh;
  padding: 0;
  gap: 8px;
  background: #000;
}

#wrapper:fullscreen #game-shell,
#wrapper:-webkit-full-screen #game-shell {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#wrapper:fullscreen #gameCanvas,
#wrapper:-webkit-full-screen #gameCanvas {
  width: 100%;
  max-width: 100vw;
  max-height: 100%;
  height: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

#wrapper:fullscreen #utility-bar,
#wrapper:-webkit-full-screen #utility-bar {
  width: 100%;
  justify-content: flex-end;
  padding: 0 max(10px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) 10px;
  margin-top: 0;
}

body.mobile-controls-enabled #wrapper:fullscreen,
body.mobile-controls-enabled #wrapper:-webkit-full-screen {
  padding-bottom: calc(112px + env(safe-area-inset-bottom));
}

body.mobile-controls-enabled #wrapper:fullscreen #mobile-controls,
body.mobile-controls-enabled #wrapper:-webkit-full-screen #mobile-controls {
  display: flex;
  z-index: 60;
}

@media (orientation: landscape) {
  body.fullscreen-active.mobile-controls-enabled #mobile-controls {
    min-height: min(52vh, 230px);
    gap: 10px;
    padding: 0 10px max(8px, env(safe-area-inset-bottom));
  }

  body.fullscreen-active.mobile-controls-enabled .touch-pad .touch-btn {
    width: 78px;
    height: 78px;
    border-radius: 39px;
    font-size: 30px;
  }

  body.fullscreen-active.mobile-controls-enabled .touch-btn-jump,
  body.fullscreen-active.mobile-controls-enabled .touch-actions .touch-btn {
    width: 104px;
    height: 78px;
    border-radius: 39px;
    font-size: 20px;
  }

  body.fullscreen-active.mobile-controls-enabled .touch-btn-back {
    min-width: 72px;
    height: 52px;
    border-radius: 26px;
    font-size: 12px;
  }
}

@media (hover: none) and (pointer: coarse) {
  #mobile-controls,
  #mobile-controls-hint {
    display: flex;
  }

  #controls-hint {
    display: none;
  }

  #wrapper {
    padding-bottom: calc(150px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 900px) {
  body {
    justify-content: flex-start;
    padding: 10px 0;
  }
}

@media (max-width: 520px) {
  #wrapper {
    padding: 8px;
    gap: 10px;
  }

  #utility-bar {
    justify-content: flex-end;
    padding-right: max(6px, env(safe-area-inset-right));
  }

  #fullscreen-btn {
    min-width: 108px;
    padding: 7px 10px;
    font-size: 11px;
  }

  .touch-pad .touch-btn {
    width: 90px;
    height: 90px;
    font-size: 34px;
  }

  .touch-btn-jump,
  .touch-actions .touch-btn {
    width: 118px;
    height: 90px;
  }
}
