:root {
  --bg-0: #07121a;
  --bg-1: #112433;
  --frame: #d4e2ee;
  --frame-shadow: rgba(0, 0, 0, 0.45);
  --hud: #ffffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 20% 18%, rgba(59, 112, 151, 0.26), transparent 43%),
    radial-gradient(circle at 82% 78%, rgba(130, 148, 83, 0.2), transparent 37%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  color: var(--hud);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

.page-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(0.3rem, 1.5vw, 1.1rem);
}

.game-frame {
  width: min(100%, 1100px);
  border: 2px solid var(--frame);
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 18px 40px var(--frame-shadow),
    inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  background: #000;
  position: relative;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  touch-action: none;
}

#game:focus-visible,
.touch-btn:focus-visible {
  outline: 3px solid #f7f2bd;
  outline-offset: -2px;
}

.touch-controls {
  pointer-events: none;
  position: absolute;
  inset: 0;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.touch-stick {
  width: 178px;
  height: 178px;
  position: relative;
  pointer-events: auto;
  touch-action: none;
  border-radius: 999px;
}

.touch-stick-ring,
.touch-stick-core,
.touch-stick-knob {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 999px;
}

.touch-stick-ring {
  width: 178px;
  height: 178px;
  border: 2px solid rgba(220, 236, 247, 0.48);
  background:
    radial-gradient(circle at 35% 35%, rgba(105, 158, 191, 0.2), rgba(8, 20, 29, 0.62)),
    rgba(6, 16, 22, 0.55);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.42);
}

.touch-stick-core {
  width: 54px;
  height: 54px;
  border: 1px solid rgba(223, 238, 249, 0.5);
  background: rgba(10, 25, 36, 0.7);
}

.touch-stick-knob {
  width: 72px;
  height: 72px;
  border: 1px solid rgba(227, 241, 251, 0.7);
  background:
    radial-gradient(circle at 35% 30%, rgba(157, 213, 242, 0.55), rgba(22, 58, 80, 0.9)),
    rgba(11, 33, 46, 0.74);
  transform: translate(var(--stick-x, 0px), var(--stick-y, 0px));
  transition: transform 80ms ease-out;
}

.touch-stick.active .touch-stick-knob {
  transition: transform 10ms linear;
}

.touch-actions {
  display: grid;
  gap: 10px;
  justify-items: end;
  margin-bottom: 6px;
}

.touch-btn {
  pointer-events: auto;
  border: 1px solid rgba(219, 238, 255, 0.6);
  border-radius: 12px;
  background: rgba(4, 13, 18, 0.58);
  color: #edf6ff;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.touch-btn.active {
  background: rgba(117, 198, 245, 0.42);
}

.touch-actions .touch-start,
.touch-actions .touch-pause {
  width: 104px;
  height: 42px;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.touch-actions .touch-fire {
  width: 118px;
  height: 84px;
  font-size: 21px;
  font-weight: 700;
}

.touch-hint {
  margin: 8px 0 0;
  text-align: center;
  font-size: 13px;
  color: rgba(226, 236, 245, 0.8);
  display: none;
}

/* Fallback: keep touch UI available on narrow displays even when pointer media
   queries are unavailable (desktop emulation, some webviews). */
@media (max-width: 900px) {
  .page-shell {
    padding: 0;
  }

  .game-frame {
    width: 100vw;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .touch-controls {
    display: flex;
  }

  .touch-hint {
    display: block;
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

@media (hover: none) and (pointer: coarse) {
  .page-shell {
    padding: 0;
  }

  .game-frame {
    width: 100vw;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .touch-controls {
    display: flex;
  }

  .touch-hint {
    display: block;
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

@media (hover: none) and (pointer: coarse) and (max-width: 780px) {
  .touch-controls {
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .touch-stick {
    width: 152px;
    height: 152px;
  }

  .touch-stick-ring {
    width: 152px;
    height: 152px;
  }

  .touch-stick-knob {
    width: 66px;
    height: 66px;
  }

  .touch-actions .touch-fire {
    width: 108px;
    height: 76px;
    font-size: 19px;
  }

  .touch-actions .touch-start,
  .touch-actions .touch-pause {
    width: 96px;
    height: 40px;
    font-size: 13px;
  }
}
