* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #000;
  color: #ddd;
  font-family: Geneva, Verdana, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

.wrap {
  /* Height kept free below the game for the buttons. */
  --reserve: 56px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  gap: 8px;
}

/* The game is 4:3. Make it as big as fits in both directions. */
.stage {
  position: relative;
  flex: none;
  width: min(100vw - 16px, (100vh - var(--reserve)) * 4 / 3);
  width: min(100vw - 16px, (100dvh - var(--reserve)) * 4 / 3);
  aspect-ratio: 4 / 3;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------------------------------------------------------- title screen */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: #000 url("assets/title-splash.png") center / cover no-repeat;
  image-rendering: pixelated;
  overflow: auto;
}

.overlay[hidden] {
  display: none;
}

.panel {
  width: 100%;
  max-height: 100%;
  overflow: auto;
  padding: 10px 16px 12px;
  background: rgba(0, 0, 0, 0.82);
  text-align: center;
  font-size: clamp(11px, 1.6vw, 14px);
}

.panel p {
  margin: 6px 0;
}

.result {
  font-weight: bold;
  color: #ff0;
}

.best {
  color: #7575ff;
  min-height: 1em;
}

.keys {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 2px 12px;
  margin: 8px 0;
  text-align: left;
}

.keys div {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.keys dt {
  color: #7575ff;
  font-weight: bold;
  white-space: nowrap;
}

.keys dd {
  margin: 0;
}

.credits {
  font-size: 0.85em;
  color: #aaa;
  line-height: 1.35;
}

.credits a {
  color: #9ab4ff;
}

/* ---------------------------------------------------------------- buttons */

button {
  font: inherit;
  font-weight: bold;
  color: #ddd;
  background: #16163a;
  border: 2px solid #7575ff;
  border-radius: 8px;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button:active,
button.held {
  background: #7575ff;
  color: #000;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

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

.play {
  padding: 8px 36px;
  font-size: 1.3em;
}

.bar {
  display: flex;
  gap: 8px;
}

.bar button {
  padding: 6px 12px;
  font-size: 14px;
}

/* On-screen controls: only shown on touch devices. */
.touch {
  display: none;
  width: 100%;
  max-width: 640px;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}

.touch .group {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.touch button {
  width: 64px;
  height: 64px;
  font-size: 18px;
}

.touch button.small {
  width: 56px;
  height: 44px;
  font-size: 12px;
}

@media (pointer: coarse) {
  .wrap {
    --reserve: 136px;
  }

  .touch {
    display: flex;
  }
}

/* A phone held sideways has no room below the game, so the controls sit on
   top of its bottom corners instead. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  .wrap {
    --reserve: 16px;
  }

  .touch {
    position: fixed;
    left: 0;
    right: 0;
    bottom: max(8px, env(safe-area-inset-bottom));
    max-width: none;
    padding: 0 max(12px, env(safe-area-inset-left)) 0 max(12px, env(safe-area-inset-right));
    pointer-events: none;
  }

  .touch button {
    pointer-events: auto;
    opacity: 0.55;
  }

  .bar {
    position: fixed;
    top: 8px;
    right: max(8px, env(safe-area-inset-right));
    flex-direction: column;
    opacity: 0.7;
  }
}
