body {
  margin: 0;
  min-height: 100vh;
  box-sizing: border-box;
  padding: 16px 16px 40px;
  background: #05060f;
  color: #e6e9ff;
  font-family: system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

h1 {
  margin: 0;
  font: 900 clamp(26px, 6vw, 40px) "Orbitron", sans-serif;
  letter-spacing: 3px;
  color: #ffffff;
}

h2 {
  margin: 8px 0 4px;
  font: 800 14px "Orbitron", sans-serif;
  letter-spacing: 2px;
  color: #aab2ff;
}

.back-link {
  align-self: flex-start;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  color: inherit;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 14px;
}

.controls label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.controls select,
.controls button {
  min-height: 44px;
  padding: 8px 14px;
  border: 2px solid #3b4290;
  border-radius: 10px;
  background: #0d1030;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.controls button:hover,
.controls select:hover {
  border-color: #7c86ff;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid #7c86ff;
  outline-offset: 2px;
}

/* 960 x 600 arena, scaled to fit */
.arena {
  position: relative;
  width: min(100%, 1200px, calc((100vh - 220px) * 1.6));
  min-width: min(100%, 320px);
}

#game {
  display: block;
  width: 100%;
  height: auto;
  border: 2px solid #1d2150;
  border-radius: 10px;
  box-sizing: border-box;
  touch-action: none;
}

.fullscreen-btn {
  position: absolute;
  top: calc(12.5% + 6px); /* below the score and health bars */
  right: 8px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid #3b4290;
  border-radius: 10px;
  background: rgba(13, 16, 48, 0.75);
  color: #e6e9ff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10; /* above the on-screen controls, which cover a small arena */
}

.fullscreen-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Full screen (real full screen, or the arena filling the window on iPhone) */
body.is-fullscreen {
  overflow: hidden;
}

body.is-fullscreen .arena {
  position: fixed;
  inset: 0;
  z-index: 50;
  width: auto;
  min-width: 0;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
}

body.is-fullscreen #game {
  width: min(100vw, calc(100vh * 1.6));
  width: min(100vw, calc(100dvh * 1.6));
  border: none;
  border-radius: 0;
}

body.is-fullscreen .fullscreen-btn {
  top: max(calc(12.5% + 6px), env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
}

.pad-status {
  margin: 0;
  min-height: 1.2em;
  color: #8ce99a;
  font-size: 14px;
  text-align: center;
}

.controls button[aria-pressed="true"] {
  border-color: #7c86ff;
  background: #2a3180;
}

.help {
  width: min(100%, 960px);
  font-size: 15px;
  line-height: 1.6;
  color: #c3c8ee;
}

.help p,
.help ul {
  margin: 0;
}

.weapons {
  padding-left: 20px;
}

.w-machine { color: #ffe066; }
.w-artillery { color: #ffa94d; }
.w-sniper { color: #74c0fc; }
.blue { color: #4dabf7; }
.red { color: #ff6b6b; }

/* ---------- Touch controls, laid over the bottom corners of the arena ---------- */

.touch-controls {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none; /* only the controls themselves catch touches */
  user-select: none;
  -webkit-user-select: none;
}

/* Shown on touch screens (or as soon as someone touches the page) */
body.touch .touch-controls {
  display: flex;
}

@media (any-pointer: coarse) {
  .touch-controls {
    display: flex;
  }
}

.joystick {
  position: relative;
  width: clamp(110px, 22vmin, 150px);
  height: clamp(110px, 22vmin, 150px);
  border: 2px solid rgba(124, 134, 255, 0.6);
  border-radius: 50%;
  background: rgba(13, 16, 48, 0.45);
  pointer-events: auto;
  touch-action: none;
}

.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44%;
  height: 44%;
  margin: -22% 0 0 -22%;
  border-radius: 50%;
  background: rgba(124, 134, 255, 0.75);
  box-shadow: 0 0 12px rgba(124, 134, 255, 0.6);
}

.touch-buttons {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  pointer-events: auto;
}

.touch-buttons button {
  border-radius: 50%;
  color: #ffffff;
  font: 800 11px "Orbitron", sans-serif;
  letter-spacing: 1px;
  touch-action: none;
  cursor: pointer;
}

.fire-btn {
  width: clamp(84px, 18vmin, 112px);
  height: clamp(84px, 18vmin, 112px);
  border: 3px solid #ff6b6b;
  background: rgba(255, 107, 107, 0.3);
}

.weapon-btn {
  width: 64px;
  height: 64px;
  margin-bottom: 8px;
  border: 2px solid #ffe066;
  background: rgba(255, 224, 102, 0.2);
  font-size: 9px !important;
}

/* GO / BRAKE stacked beside FIRE, WEAPON above FIRE */
.speed-btns,
.shoot-btns {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.shoot-btns .weapon-btn {
  margin-bottom: 0;
}

.go-btn,
.brake-btn {
  width: clamp(64px, 14vmin, 84px);
  height: clamp(64px, 14vmin, 84px);
  font-size: 10px !important;
}

.go-btn {
  border: 3px solid #51cf66;
  background: rgba(81, 207, 102, 0.28);
}

.brake-btn {
  border: 3px solid #ffa94d;
  background: rgba(255, 169, 77, 0.28);
}

.touch-buttons button.pressed {
  filter: brightness(1.6);
  transform: scale(0.95);
}

/* On a small screen outside full screen, keep the controls readable below the arena */
@media (max-width: 700px) {
  body:not(.is-fullscreen) .touch-controls {
    position: static;
    padding: 12px 0 0;
  }
}

.controls[hidden],
.controls [hidden] {
  display: none !important;
}

.controls input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: #7c86ff;
}

.controls select:disabled,
.controls input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ---------- Adventure upgrade shop, laid over the arena ---------- */

.shop {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(5, 6, 15, 0.8);
  border-radius: 10px;
}

.shop[hidden] {
  display: none;
}

.shop-box {
  width: min(100%, 460px);
  max-height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
  padding: 16px 18px;
  border: 2px solid #ffd43b;
  border-radius: 14px;
  background: #0b0d22;
}

.shop-box h2 {
  margin: 0 0 6px;
  color: #ffd43b;
}

.shop-credits {
  margin: 0 0 10px;
}

.shop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid #1d2150;
}

.shop-desc {
  color: #8f96d6;
  font-size: 13px;
}

.pips {
  color: #ffd43b;
  letter-spacing: 2px;
}

.shop button {
  min-height: 44px;
  min-width: 110px;
  padding: 8px 12px;
  border: 2px solid #ffd43b;
  border-radius: 10px;
  background: #0d1030;
  color: #ffffff;
  font: 600 14px system-ui, sans-serif;
  cursor: pointer;
}

.shop button:disabled {
  border-color: #3b4290;
  color: #8f96d6;
  cursor: not-allowed;
}

.shop .shop-done {
  width: 100%;
  margin-top: 10px;
  background: #ffd43b;
  color: #1a1a1a;
}

.shop .tiers {
  display: inline-flex;
  gap: 3px;
  vertical-align: middle;
}

.shop .tier {
  min-width: 18px;
  padding: 0 4px;
  border: 1px solid #3b4290;
  border-radius: 5px;
  color: #8f96d6;
  font: 700 10px system-ui, sans-serif;
  text-align: center;
}

.shop .tier.on {
  border-color: #ffd43b;
  background: #ffd43b;
  color: #1a1a1a;
}

.shop-row.bundle {
  margin-bottom: 4px;
  padding: 8px;
  border: 2px solid #ffd43b;
  border-radius: 10px;
  background: #1f1a05;
}

.shop-row.picked strong {
  color: #ffd43b;
}
