
:root {
  color-scheme: dark;
  --game-aspect: 16 / 9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  background: #030719;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  font-family: Arial, Helvetica, sans-serif;
  touch-action: manipulation;
}

#shell {
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  max-width: 1280px;
  max-height: 720px;
  aspect-ratio: var(--game-aspect);
  margin: auto;
  overflow: hidden;
  background: #10183c;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  outline: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#nicknameInput {
  position: absolute;
  display: none;
  z-index: 20;
  border: 0;
  outline: 0;
  background: transparent;
  color: #11183c;
  font: 700 clamp(16px, 2.5vw, 28px) Arial, sans-serif;
  text-align: center;
  padding: 0 .45em;
  border-radius: 14px;
}

#mobileKeyboardInput {
  position: fixed;
  z-index: 9999;
  width: 1px;
  height: 1px;
  left: -100px;
  bottom: calc(env(safe-area-inset-bottom) + 1px);
  opacity: .01;
  border: 0;
  padding: 0;
  font-size: 16px;
  color: transparent;
  background: transparent;
  caret-color: transparent;
}

#mobileHint {
  display: none;
  position: absolute;
  z-index: 15;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(3,7,25,.82);
  border: 1px solid rgba(126,221,255,.8);
  color: #fff7dc;
  font-size: clamp(12px, 3.2vw, 16px);
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease;
  white-space: nowrap;
}

#mobileHint.show {
  display: block;
  opacity: 1;
}

@media (orientation: portrait) and (max-width: 900px) {
  body {
    align-items: start;
    padding-top: max(env(safe-area-inset-top), 8px);
  }

  #shell {
    width: 100vw;
    height: calc(100vw * 9 / 16);
    max-width: none;
    max-height: none;
    margin-top: max(0px, calc((100dvh - (100vw * 9 / 16)) / 2));
  }
}

@media (pointer: coarse) {
  #mobileHint { display: block; }
}


#mobilePauseButton {
  display: none;
  position: absolute;
  z-index: 40;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 64px;
  height: 64px;
  padding: 0;
  border: 2px solid rgba(126,221,255,.95);
  border-radius: 18px;
  background: rgba(8,18,48,.88);
  color: #fff7dc;
  font: 800 30px/1 Arial, sans-serif;
  box-shadow:
    0 0 18px rgba(126,221,255,.35),
    inset 0 1px 0 rgba(255,255,255,.20);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

#mobilePauseButton.show {
  display: grid;
  place-items: center;
}

#mobilePauseButton:active {
  transform: scale(.94);
  box-shadow:
    0 0 24px rgba(126,221,255,.55),
    inset 0 0 0 2px rgba(255,255,255,.28);
}

@media (pointer: coarse) and (max-height: 520px) {
  #mobilePauseButton {
    width: 58px;
    height: 58px;
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    font-size: 27px;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  #mobilePauseButton {
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
  }
}


/* Mobile visual-viewport mode:
   keep the game pinned into the actually visible part of the screen,
   not the larger layout viewport hidden behind the software keyboard. */
@media (pointer: coarse) {
  html, body {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  body {
    display: block;
    padding: 0;
  }

  #shell {
    margin: 0;
    max-width: none;
    max-height: none;
  }

  body.mobile-keyboard-open #mobileHint {
    display: none !important;
  }
}
