* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #060d18;
  font-family: "Courier New", Courier, monospace;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

#wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}

#game {
  display: block;
  flex: 1 1 auto;
  width: min(100vw, calc((100vh - 180px) * 160 / 144));
  height: min(calc(100vh - 180px), calc(100vw * 144 / 160));
  max-width: 100%;
  max-height: calc(100vh - 140px);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0a1628;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 24px rgba(74, 144, 200, 0.12);
}

#controls {
  flex: 0 0 auto;
  width: min(100vw, 420px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px max(14px, env(safe-area-inset-bottom));
  pointer-events: auto;
  z-index: 2;
}

.ctrl-cluster {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* D-pad cross layout */
#dpad {
  position: relative;
  width: 148px;
  height: 148px;
  flex-shrink: 0;
}

.dpad-btn {
  position: absolute;
  border: none;
  background: rgba(26, 48, 80, 0.9);
  color: #7ec8e8;
  box-shadow: inset 0 2px 0 rgba(126, 200, 232, 0.35), 0 4px 0 #0a1628;
  cursor: pointer;
  touch-action: none;
}

.dpad-btn:active,
.dpad-btn.active {
  background: rgba(74, 144, 200, 0.95);
  box-shadow: inset 0 3px 6px rgba(10, 22, 40, 0.5), 0 1px 0 #0a1628;
  transform: translateY(2px);
}

.d-up, .d-down {
  left: 44px;
  width: 60px;
  height: 44px;
}

.d-up { top: 0; border-radius: 10px 10px 4px 4px; }
.d-down { bottom: 0; border-radius: 4px 4px 10px 10px; }

.d-left, .d-right {
  top: 44px;
  width: 44px;
  height: 60px;
}

.d-left { left: 0; border-radius: 10px 4px 4px 10px; }
.d-right { right: 0; border-radius: 4px 10px 10px 4px; }

.d-center {
  left: 44px;
  top: 44px;
  width: 60px;
  height: 60px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0.35;
  box-shadow: none;
}

#action-btns {
  gap: 14px;
  padding-right: 4px;
}

.action-btn {
  width: 88px;
  height: 88px;
  border: none;
  border-radius: 50%;
  font-family: inherit;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.5px;
  color: #0a1628;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 5px 0 rgba(10, 22, 40, 0.9), 0 8px 16px rgba(0, 0, 0, 0.35);
}

.action-btn:active,
.action-btn.active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(10, 22, 40, 0.9);
}

.jump-btn {
  background: linear-gradient(180deg, #7ec8e8 0%, #4a90c8 100%);
}

.fire-btn {
  background: linear-gradient(180deg, #a8dff5 0%, #7ec8e8 100%);
  width: 96px;
  height: 96px;
  font-size: 14px;
}

#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 13, 24, 0.78);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 5;
  padding: 20px;
}

#overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.panel {
  width: min(340px, 92vw);
  background: linear-gradient(180deg, #7ec8e8 0%, #4a90c8 55%, #1a3050 100%);
  border: 4px solid #0a1628;
  border-radius: 4px;
  padding: 24px 20px 20px;
  text-align: center;
  box-shadow: 0 12px 0 #0a1628, 0 20px 40px rgba(0, 0, 0, 0.45), 0 0 32px rgba(126, 200, 232, 0.15);
}

.panel h1 {
  font-size: clamp(18px, 5vw, 24px);
  font-weight: 900;
  color: #0a1628;
  line-height: 1.15;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.tag {
  margin-top: 8px;
  color: #0a1628;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.9;
  font-style: italic;
}

.hint {
  margin-top: 14px;
  color: #0a1628;
  font-size: 11px;
  line-height: 1.45;
  font-weight: 600;
}

#startBtn {
  margin-top: 18px;
  border: 3px solid #0a1628;
  border-radius: 4px;
  padding: 12px 32px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 900;
  color: #7ec8e8;
  background: #0a1628;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 4px 0 #000;
}

#startBtn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #000;
}

.foot {
  margin-top: 14px;
  min-height: 1.4em;
  color: #0a1628;
  font-weight: 800;
  font-size: 13px;
}

@media (orientation: landscape) and (max-height: 520px) {
  #wrap {
    flex-direction: row;
    padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
  }

  #game {
    width: min(calc(100vw - 280px), calc(100vh * 160 / 144));
    height: min(100vh, calc((100vw - 280px) * 144 / 160));
    max-height: 100vh;
  }

  #controls {
    flex-direction: column;
    width: 260px;
    height: 100%;
    justify-content: center;
    padding: 12px;
  }

  #action-btns {
    flex-direction: row;
  }
}

@media (min-width: 720px) {
  #controls .dpad-btn,
  #controls .action-btn {
    outline: none;
  }
}

#muteBtn {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: 10px;
  z-index: 5;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: rgba(10, 22, 40, 0.75);
  color: #7ec8e8;
  font-size: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  cursor: pointer;
  touch-action: manipulation;
}
#muteBtn:active { transform: scale(0.94); }
