* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #0b0b0b;
  color: #e8e0c8;
  font-family: Tahoma, Geneva, Verdana, sans-serif;
}

#wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
}

#game {
  width: min(100vw - 24px, 960px);
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  box-shadow: 0 0 0 4px #222, 0 12px 40px rgba(0, 0, 0, 0.65);
}

#hint {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.04em;
  opacity: 0.7;
}

/* On-screen controls (src/touch.js). Everything below only applies once the
   controls are switched on, which adds .touch-on to <body>. */

body.touch-on {
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

body.touch-on #wrap {
  padding: 0;
  gap: 0;
}

/* Fill the screen without cropping: as wide as it goes, or as tall as it goes. */
/* Keep clear of the notch and the home bar, which phones draw over the page. */
body.touch-on #game {
  width: min(
    100vw - env(safe-area-inset-left) - env(safe-area-inset-right),
    (100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 4 / 3
  );
  box-shadow: none;
  touch-action: none;
}

body.touch-on #hint {
  display: none;
}

/* The picture sits at the top: upright, the controls get the space below;
   sideways, it keeps the picture off the home bar at the bottom. */
body.touch-on #wrap {
  justify-content: flex-start;
  padding-top: env(safe-area-inset-top);
}

.touch {
  position: fixed;
  inset: 0;
  pointer-events: none;
  /* touch.js moves and shrinks this layer to stay on screen if the page zooms. */
  transform-origin: 0 0;
  --pad: min(40vmin, 180px);
  --btn: min(22vmin, 92px);
  --edge: max(14px, 3vmin);
}

.touch > * {
  pointer-events: auto;
  touch-action: none;
}

.touch-pad {
  position: absolute;
  left: calc(var(--edge) + env(safe-area-inset-left));
  bottom: calc(var(--edge) + env(safe-area-inset-bottom));
  width: var(--pad);
  height: var(--pad);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.28);
}

.touch-knob {
  position: absolute;
  left: 30%;
  top: 30%;
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.42);
  pointer-events: none;
}

.touch-buttons {
  position: absolute;
  right: calc(var(--edge) + env(safe-area-inset-right));
  bottom: calc(var(--edge) + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: calc(var(--btn) * 0.22);
}

.touch-btn,
.touch-small {
  font: inherit;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border: 2px solid rgba(255, 255, 255, 0.32);
  padding: 0;
}

.touch-btn {
  width: var(--btn);
  height: var(--btn);
  border-radius: 50%;
  font-size: calc(var(--btn) * 0.4);
  font-weight: bold;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* The use button sits higher, where the thumb rests. */
.touch-c {
  margin-bottom: calc(var(--btn) * 0.45);
}

.touch-label {
  font-size: calc(var(--btn) * 0.17);
  font-weight: normal;
  letter-spacing: 0.06em;
  opacity: 0.8;
  margin-top: 0.15em;
}

/* The row of small buttons in the top right corner: pause first, then full
   screen and tilt on devices that can do them. */
.touch-top {
  position: absolute;
  top: calc(var(--edge) + env(safe-area-inset-top));
  right: calc(var(--edge) + env(safe-area-inset-right));
  display: flex;
  flex-direction: row-reverse;
  gap: 10px;
}

.touch-small {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: bold;
}

.touch-pause {
  font-size: 15px;
  letter-spacing: 0.1em;
}

.touch-tilt {
  font-size: 11px;
}

/* Lit while tilt-to-walk is switched on. */
.touch-tilt.on {
  background: rgba(127, 194, 56, 0.55);
  border-color: rgba(190, 240, 130, 0.9);
}

/* Held sideways, the controls live in the black bars beside the picture, so
   stack the buttons into a narrow column instead of spreading them over it. */
@media (orientation: landscape) {
  .touch {
    --pad: min(37vmin, 180px);
  }

  .touch-buttons {
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: calc(var(--btn) * 0.12);
  }

  .touch-c {
    margin-bottom: 0;
  }

  .touch-x {
    margin-right: calc(var(--btn) * 0.55);
  }
}

/* Held upright, keep them off the picture: tuck them just under the game. */
@media (orientation: portrait) {
  .touch-top {
    top: calc(100vw * 3 / 4 + var(--edge) + env(safe-area-inset-top));
  }
}

.touch-btn.held,
.touch-small.held,
.touch-full:active {
  background: rgba(255, 255, 255, 0.4);
}

/* If the page does get zoomed, let a pinch on the picture undo it and say so. */
body.touch-on.touch-zoomed,
body.touch-zoomed #game {
  touch-action: pinch-zoom;
}

.touch-zoom-note,
.touch-msg {
  display: none;
  position: absolute;
  top: calc(var(--edge) + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
}

body.touch-zoomed .touch-zoom-note,
.touch-msg.show {
  display: block;
}
