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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  touch-action: none;
  overscroll-behavior: none;
}

#game-wrap {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  user-select: none;
}

canvas#game {
  background: #5c94fc;
  image-rendering: pixelated;
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  display: block;
  touch-action: none;
}

/* Keep canvas at a fixed aspect ratio (800x450 = 16:9) while filling available space */
@media (min-aspect-ratio: 16/9) {
  canvas#game { width: auto; height: 100%; }
}
@media (max-aspect-ratio: 16/9) {
  canvas#game { width: 100%; height: auto; }
}

#hud {
  position: absolute;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  pointer-events: none;
  font-weight: bold;
  font-size: clamp(14px, 2.6vw, 20px);
  color: #fff;
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
  letter-spacing: 1px;
}

#rotate-hint {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-size: 12px;
  text-shadow: 1px 1px 0 #000;
  opacity: 0.85;
  pointer-events: none;
  display: none;
}

@media (orientation: portrait) and (max-width: 600px) {
  #rotate-hint { display: block; }
}

#btn-physics {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 38px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  font-family: inherit;
  font-size: clamp(11px, 2.4vw, 13px);
  font-weight: bold;
  color: #fff;
  background: rgba(92, 148, 252, 0.35);
  border: 1.5px solid rgba(255, 255, 255, 0.5);
  border-radius: 20px;
  padding: 5px 12px;
  cursor: pointer;
}
#btn-physics.on {
  background: rgba(255, 204, 0, 0.85);
  color: #3a2a00;
  border-color: #fff;
}

/* Overlay screens (start / win / game over) */
#overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
#overlay.hidden { display: none; }

#overlay-card {
  text-align: center;
  color: #fff;
  padding: 24px 32px;
  max-width: 86vw;
}

#overlay-title {
  margin: 0 0 8px;
  font-size: clamp(22px, 6vw, 40px);
  color: #ffcc00;
  text-shadow: 3px 3px 0 #c1440e;
}

#overlay-msg {
  margin: 0 0 20px;
  font-size: clamp(13px, 3vw, 16px);
  opacity: 0.9;
}

#overlay-btn {
  font-family: inherit;
  font-weight: bold;
  font-size: clamp(16px, 4vw, 20px);
  padding: 12px 28px;
  border: none;
  border-radius: 8px;
  background: #ffcc00;
  color: #3a2a00;
  cursor: pointer;
  box-shadow: 0 4px 0 #b38600;
}
#overlay-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #b38600;
}

/* Touch controls */
#touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 14px 18px;
  pointer-events: none;
  z-index: 15;
}

.dpad, .action-pad {
  display: flex;
  gap: 12px;
  pointer-events: none;
}

.ctrl-btn {
  pointer-events: auto;
  width: clamp(52px, 13vw, 72px);
  height: clamp(52px, 13vw, 72px);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: clamp(20px, 5vw, 28px);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  touch-action: none;
}

.ctrl-btn:active,
.ctrl-btn.pressed {
  background: rgba(255, 255, 255, 0.45);
}

.ctrl-jump {
  width: clamp(66px, 17vw, 92px);
  height: clamp(66px, 17vw, 92px);
  background: rgba(255, 200, 0, 0.28);
  border-color: rgba(255, 200, 0, 0.7);
}
.ctrl-jump:active,
.ctrl-jump.pressed {
  background: rgba(255, 200, 0, 0.55);
}
