:root {
  color-scheme: dark;
  font-family: "Courier New", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #050505;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #050505; }
body { overscroll-behavior: none; touch-action: manipulation; overflow-x: hidden; }
button { font: inherit; }
.app {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: max(2px, env(safe-area-inset-top)) max(2px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(2px, env(safe-area-inset-left));
}
.game-shell {
  width: min(99.5vw, 1880px);
  background: #000;
  border: 2px solid #242424;
  box-shadow: 0 16px 50px rgba(0,0,0,.55);
}
.game-wrap { position: relative; width: 100%; background: #000; overflow: hidden; line-height: 0; }
canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1448 / 1240;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  touch-action: none;
}

.control-deck {
  position: static !important;
  width: 100%;
  min-height: 250px;
  background: #000;
  border-top: 4px solid #2d2d2d;
  display: grid;
  grid-template-columns: minmax(280px,.9fr) minmax(360px,1.25fr) minmax(280px,.9fr);
  gap: clamp(20px,3vw,52px);
  align-items: center;
  padding: 18px clamp(18px,3vw,48px) 22px;
  line-height: 1.15;
}

.joystick-zone,
.fire-zone {
  min-height: 210px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 8px;
}
.control-label {
  color: #8affff;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .12em;
}

.joystick {
  position: relative;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  border: 5px solid #7a7a7a;
  background: radial-gradient(circle at 50% 45%, #242424 0 42%, #121212 43% 66%, #050505 67% 100%);
  box-shadow: inset 0 0 0 5px #000, 0 7px 0 #151515;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.joystick:active { cursor: grabbing; }
.joystick-cross::before,
.joystick-cross::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: #363636;
  transform: translate(-50%,-50%);
  pointer-events: none;
}
.joystick-cross::before { width: 126px; height: 3px; }
.joystick-cross::after { width: 3px; height: 126px; }
.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 78px;
  height: 78px;
  margin-left: -39px;
  margin-top: -39px;
  border-radius: 50%;
  border: 4px solid #e7e7e7;
  background: radial-gradient(circle at 36% 28%, #676767 0 10%, #252525 35%, #090909 72%);
  box-shadow: 0 5px 0 #000, inset -7px -8px 0 rgba(0,0,0,.4);
  transform: translate(0px,0px);
  pointer-events: none;
  will-change: transform;
}

.fire-button {
  width: 172px;
  height: 172px;
  border-radius: 50%;
  border: 7px solid #ffd1d1;
  background: radial-gradient(circle at 38% 30%, #ff8a8a 0 9%, #ed2222 30%, #8f0808 72%);
  color: #fff;
  font-size: 31px;
  font-weight: 900;
  letter-spacing: .05em;
  text-shadow: 2px 2px 0 #6c0000;
  box-shadow: 0 9px 0 #4c0000, inset -8px -9px 0 rgba(0,0,0,.25);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.fire-button:active,
.fire-button.active {
  transform: translateY(5px);
  box-shadow: 0 4px 0 #4c0000, inset -4px -5px 0 rgba(0,0,0,.25);
  background: radial-gradient(circle at 38% 30%, #fff0b1 0 8%, #ff4a35 31%, #b30a00 75%);
}

.control-center { display: grid; gap: 18px; align-content: center; }
.control-copy { display: grid; gap: 8px; text-align: center; color: #cfcfcf; line-height: 1.35; }
.control-copy strong { color: #7affff; font-size: clamp(19px,1.6vw,29px); }
.control-copy span { font-size: clamp(11px,1vw,16px); }
.utility-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.utility-controls button {
  min-height: 54px;
  border: 3px solid #fff;
  border-radius: 7px;
  background: #101010;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  padding: 8px 10px;
}
.utility-controls button:active { background: #6cf45f; color: #000; transform: translateY(1px); }

.overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  padding: 20px; background: rgba(0,0,0,.82); z-index: 10; line-height: 1.2;
}
.overlay.show { display: flex; }
.panel {
  width: min(760px,92%); max-height: 92%; overflow: auto;
  border: 5px solid #fff; background: #080808; padding: clamp(18px,4vw,38px);
  text-align: center; box-shadow: 10px 10px 0 #000;
}
.panel h2 { margin: 0 0 14px; font-size: clamp(28px,5vw,54px); color: #fff; }
.button-stack { display: grid; gap: 10px; }
.button-stack button { min-height: 56px; border: 3px solid #fff; background: #47e83f; color: #000; font-weight: 900; cursor: pointer; }
.button-stack button.secondary { background: #161616; color: #fff; }
.save-status { color: #62f05a; min-height: 2.8em; line-height: 1.4; }
.pause-help { color: #ddd; border: 2px solid #333; padding: 12px; margin-top: 14px; line-height: 1.5; font-size: 13px; }
.pause-help strong { color: #f7ef42; }
.fine { color: #aaa; font-size: 12px; line-height: 1.45; margin: 14px 0 0; }
.toast {
  position: absolute; left: 50%; bottom: 4%; transform: translate(-50%,20px);
  background: #000; border: 3px solid #62f05a; color: #fff; padding: 10px 16px;
  font-weight: 900; opacity: 0; pointer-events: none; z-index: 20;
  transition: opacity .15s ease, transform .15s ease; text-align: center; line-height: 1.2;
}
.toast.show { opacity: 1; transform: translate(-50%,0); }
button:focus-visible, .joystick:focus-visible { outline: 4px solid #f7ef42; outline-offset: 3px; }

.game-shell:fullscreen { width: 100vw; min-height: 100vh; border: 0; overflow: auto; background: #000; }
.game-shell:fullscreen .game-wrap { width: min(100vw, calc((100vh - 256px) * 1448 / 1240)); margin: 0 auto; }
.game-shell:fullscreen .control-deck { width: min(100vw,1880px); margin: 0 auto; }

@media (max-width: 900px) {
  .control-deck { grid-template-columns: minmax(210px,.8fr) minmax(250px,1fr) minmax(210px,.8fr); gap: 12px; min-height: 230px; padding-left: 12px; padding-right: 12px; }
  .joystick { width: 160px; height: 160px; }
  .joystick-knob { width: 66px; height: 66px; margin-left: -33px; margin-top: -33px; }
  .joystick-cross::before { width: 106px; }
  .joystick-cross::after { height: 106px; }
  .fire-button { width: 145px; height: 145px; font-size: 27px; }
}

@media (max-width: 650px) {
  .game-shell { width: 100%; border-left: 0; border-right: 0; }
  .control-deck {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "joy fire" "center center";
    min-height: 380px;
    padding: 14px 10px 18px;
    gap: 10px 16px;
  }
  .joystick-zone { grid-area: joy; min-height: 190px; }
  .fire-zone { grid-area: fire; min-height: 190px; }
  .control-center { grid-area: center; gap: 10px; }
  .joystick { width: 150px; height: 150px; }
  .joystick-knob { width: 62px; height: 62px; margin-left: -31px; margin-top: -31px; }
  .fire-button { width: 138px; height: 138px; font-size: 25px; }
  .utility-controls { width: min(94vw,420px); justify-self: center; }
  .utility-controls button { min-height: 50px; font-size: 13px; }
}
