@font-face {
  font-family: "Press Start 2P";
  src: url("assets/pressstart2p.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #0B1220;
  --horizon: #1A2436;
  --yellow: #FFD400;
  --red: #FF2B2B;
  --enemy-red: #E63A2E;
  --enemy-blue: #2F7BFF;
  --brass: #D9A441;
  --white: #F4EFE6;
  --plate: rgba(0, 0, 0, 0.85);
  --ui: "Press Start 2P", "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  color: var(--white);
  font-family: var(--ui);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--ink);
  touch-action: none;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  transition: filter 420ms ease;
}

#stage.over #game {
  filter: saturate(0.25) brightness(0.72) contrast(0.96);
}

#stage.playing {
  cursor: none;
}

#scanlines,
#vignette,
#damageFlash,
#whiteFlash {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#scanlines {
  z-index: 4;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.34) 0px,
    rgba(0, 0, 0, 0.34) 1px,
    transparent 1px,
    transparent 3px
  );
  opacity: 0.13;
  mix-blend-mode: multiply;
}

#vignette {
  z-index: 4;
  background: radial-gradient(
    ellipse at 50% 44%,
    rgba(0, 0, 0, 0) 46%,
    rgba(0, 0, 0, 0.38) 78%,
    rgba(0, 0, 0, 0.68) 100%
  );
}

#damageFlash {
  z-index: 4;
  opacity: 0;
  box-shadow:
    inset 0 0 60px 22px rgba(255, 43, 43, 0.85),
    inset 0 0 160px 70px rgba(150, 12, 12, 0.45);
}

#damageFlash.on {
  animation: damagePulse 0.34s ease-out forwards;
}

@keyframes damagePulse {
  0% { opacity: 0.95; }
  100% { opacity: 0; }
}

#whiteFlash {
  z-index: 10;
  background: #FFFFFF;
  opacity: 0;
}

#whiteFlash.on {
  animation: whitePulse 0.45s ease-out forwards;
}

@keyframes whitePulse {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

#hud {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: clamp(4px, 0.8vw, 14px);
  padding-top: calc(env(safe-area-inset-top, 0px) + clamp(6px, 1.5vh, 18px));
  padding-left: calc(env(safe-area-inset-left, 0px) + clamp(6px, 1.2vw, 22px));
  padding-right: calc(env(safe-area-inset-right, 0px) + clamp(6px, 1.2vw, 22px));
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms linear;
}

#stage.playing #hud {
  opacity: 1;
}

.plate {
  width: max-content;
  max-width: 100%;
  background: var(--plate);
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.75),
    0 5px 18px rgba(0, 0, 0, 0.4);
  padding: clamp(4px, 0.65vw, 9px) clamp(6px, 0.95vw, 13px);
}

.hud-label {
  color: var(--yellow);
  font-size: clamp(6px, 0.82vw, 10px);
  letter-spacing: 0.08em;
  line-height: 1;
  text-shadow: 2px 2px 0 #000;
}

.hud-value {
  margin-top: clamp(4px, 0.55vw, 8px);
  color: #FFFFFF;
  font-size: clamp(10px, 1.45vw, 18px);
  line-height: 1;
  letter-spacing: 0.06em;
  text-shadow:
    2px 2px 0 #000,
    3px 3px 0 rgba(0, 0, 0, 0.7);
}

.score-plate {
  justify-self: start;
}

.time-plate {
  justify-self: center;
  text-align: center;
}

.time-value {
  color: var(--yellow);
  font-size: clamp(20px, 3.15vw, 38px);
  letter-spacing: 0.03em;
  min-width: 4.7em;
}

.time-value.low {
  color: var(--red);
  animation: timePulse 1s steps(2, end) infinite;
}

.time-value.bump {
  animation: timeBump 0.46s ease-out;
}

.time-value.low.bump {
  animation:
    timeBump 0.46s ease-out,
    timePulse 1s steps(2, end) infinite;
}

@keyframes timePulse {
  0%, 58% { opacity: 1; }
  59%, 100% { opacity: 0.35; }
}

@keyframes timeBump {
  0% { color: #FFFFFF; transform: scale(1.2); }
  100% { color: var(--yellow); transform: scale(1); }
}

.health-plate {
  justify-self: end;
  text-align: right;
}

.health-blocks {
  display: flex;
  gap: clamp(3px, 0.4vw, 6px);
  margin-top: clamp(4px, 0.55vw, 8px);
}

.health-block {
  width: clamp(9px, 1.28vw, 18px);
  height: clamp(9px, 1.28vw, 18px);
  background: linear-gradient(180deg, #FF7A5E 0%, var(--enemy-red) 42%, #A21D14 100%);
  border: 2px solid rgba(255, 185, 160, 0.72);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.28);
}

.health-block.off {
  background: rgba(230, 58, 46, 0.09);
  border-color: rgba(230, 58, 46, 0.28);
  box-shadow: none;
}

.health-block.lost {
  animation: blockLost 0.38s ease-out;
}

@keyframes blockLost {
  0% { background: #FFFFFF; border-color: #FFFFFF; transform: translateY(-4px) scale(1.15); }
  55% { background: #FF8D77; border-color: #FFD0C6; transform: translateY(2px) scale(0.92); }
  100% { background: rgba(230, 58, 46, 0.09); border-color: rgba(230, 58, 46, 0.28); transform: none; }
}

.ammo-plate {
  position: absolute;
  right: calc(env(safe-area-inset-right, 0px) + clamp(6px, 1.2vw, 22px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + clamp(8px, 1.4vh, 20px));
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transition: opacity 160ms linear;
}

#stage.playing .ammo-plate {
  opacity: 1;
}

.ammo-pips {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(3px, 0.45vw, 6px);
  margin-top: clamp(4px, 0.6vw, 8px);
  height: clamp(26px, 3.4vw, 46px);
}

.pip {
  width: clamp(7px, 0.95vw, 13px);
  height: 100%;
  border: 2px solid #6E5626;
  border-radius: 2px 2px 1px 1px;
  background: linear-gradient(
    180deg,
    #FFE8A6 0%,
    #F0C15E 16%,
    var(--brass) 48%,
    #A56B22 100%
  );
  box-shadow:
    inset 0 0 0 1px rgba(255, 240, 190, 0.25),
    0 0 8px rgba(217, 164, 65, 0.16);
  transition:
    background 90ms linear,
    border-color 90ms linear,
    opacity 90ms linear;
}

.pip.spent {
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(217, 164, 65, 0.32);
  box-shadow: none;
}

#coverTag {
  display: none;
  margin-left: 6px;
  color: #FFFFFF;
  background: #C77718;
  padding: 2px 4px;
  font-size: 0.82em;
}

#coverTag.on {
  display: inline-block;
}

#reloadWarn {
  position: absolute;
  left: 50%;
  top: 59%;
  z-index: 6;
  transform: translate(-50%, -50%);
  display: none;
  color: var(--red);
  font-size: clamp(20px, 3.5vw, 46px);
  letter-spacing: 0.08em;
  text-shadow:
    3px 0 0 #000,
    -3px 0 0 #000,
    0 3px 0 #000,
    0 -3px 0 #000,
    4px 4px 0 #000,
    -4px 4px 0 #000;
  pointer-events: none;
  white-space: nowrap;
}

#reloadWarn.on {
  display: block;
  animation: reloadBlink 0.33s steps(1, end) infinite;
}

@keyframes reloadBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

#coverBtn {
  position: absolute;
  left: calc(env(safe-area-inset-left, 0px) + clamp(6px, 1.2vw, 22px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + clamp(8px, 1.4vh, 20px));
  z-index: 6;
  display: flex;
  align-items: center;
  gap: clamp(6px, 0.7vw, 10px);
  max-width: min(64vw, 330px);
  padding: clamp(6px, 0.8vw, 10px) clamp(7px, 0.9vw, 12px);
  background: var(--plate);
  color: var(--yellow);
  border: 1px solid rgba(255, 212, 0, 0.42);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 5px 18px rgba(0, 0, 0, 0.4);
  font-family: var(--ui);
  text-align: left;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  touch-action: none;
  transition:
    opacity 160ms linear,
    background 80ms linear,
    color 80ms linear;
}

#stage.playing #coverBtn {
  opacity: 1;
  pointer-events: auto;
}

#coverBtn.active {
  background: rgba(255, 212, 0, 0.94);
  color: #16130A;
  border-color: #FFE880;
}

#coverBtn .key {
  display: inline-block;
  padding: clamp(4px, 0.5vw, 6px) clamp(4px, 0.55vw, 7px);
  border: 1px solid currentColor;
  font-size: clamp(7px, 0.9vw, 10px);
  line-height: 1;
  flex: 0 0 auto;
}

#coverBtn .btn-copy {
  display: block;
  min-width: 0;
}

#coverBtn .btn-main {
  display: block;
  font-size: clamp(7px, 0.98vw, 11px);
  line-height: 1.35;
}

#coverBtn .btn-sub {
  display: block;
  margin-top: 4px;
  font-size: clamp(6px, 0.82vw, 9px);
  line-height: 1.35;
  opacity: 0.72;
}

#waveFlash {
  position: absolute;
  left: 50%;
  top: 33%;
  z-index: 6;
  transform: translate(-50%, -50%);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

#waveFlash .flash-big {
  color: var(--yellow);
  font-size: clamp(26px, 5.2vw, 62px);
  letter-spacing: 0.04em;
  text-shadow:
    3px 3px 0 #7A4A00,
    6px 6px 0 #000;
}

#waveFlash .flash-small {
  margin-top: clamp(8px, 1.2vw, 16px);
  color: #FFFFFF;
  font-size: clamp(11px, 1.8vw, 22px);
  letter-spacing: 0.18em;
  text-shadow:
    2px 2px 0 #000,
    4px 4px 0 rgba(0, 0, 0, 0.75);
}

#waveFlash.on {
  animation: wavePop 1.32s cubic-bezier(0.18, 0.9, 0.28, 1) forwards;
}

@keyframes wavePop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.38); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.03); }
  28% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  72% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -58%) scale(1); }
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  padding:
    clamp(18px, 4vw, 58px)
    calc(env(safe-area-inset-right, 0px) + clamp(18px, 4vw, 62px))
    calc(env(safe-area-inset-bottom, 0px) + clamp(20px, 5vh, 58px))
    calc(env(safe-area-inset-left, 0px) + clamp(18px, 4vw, 62px));
  background: linear-gradient(
    180deg,
    rgba(4, 7, 14, 0) 24%,
    rgba(4, 7, 14, 0.28) 52%,
    rgba(4, 7, 14, 0.82) 100%
  );
  cursor: pointer;
}

.screen.hidden {
  display: none;
}

.start-inner {
  width: min(760px, 100%);
}

.title {
  display: flex;
  flex-direction: column;
  color: var(--yellow);
  font-size: clamp(26px, 4.4vw, 66px);
  line-height: 1.08;
  letter-spacing: 0.02em;
  text-shadow:
    3px 3px 0 #A22B21,
    7px 7px 0 #000;
}

.title span {
  display: block;
}

.tagline {
  margin-top: clamp(14px, 2.2vh, 24px);
  max-width: 680px;
  color: #FFFFFF;
  font-size: clamp(7px, 1.02vw, 12px);
  line-height: 1.9;
  text-shadow: 2px 2px 0 #000;
}

.tagline.small {
  margin-top: 8px;
  color: var(--yellow);
}

.instructions {
  margin-top: clamp(12px, 2vh, 22px);
  padding: clamp(9px, 1.3vw, 16px) clamp(10px, 1.5vw, 18px);
  background: rgba(0, 0, 0, 0.62);
  border-left: 3px solid var(--yellow);
  color: #FFFFFF;
  font-size: clamp(7px, 0.98vw, 11px);
  line-height: 2.1;
  text-shadow: 2px 2px 0 #000;
}

.instructions b {
  color: var(--yellow);
  font-weight: 400;
}

.prompt {
  margin-top: clamp(14px, 2.4vh, 26px);
  color: #FFFFFF;
  font-size: clamp(10px, 1.55vw, 18px);
  letter-spacing: 0.08em;
  text-shadow:
    2px 2px 0 #000,
    0 0 18px rgba(255, 212, 0, 0.28);
}

.blink {
  animation: promptBlink 1.12s steps(1, end) infinite;
}

@keyframes promptBlink {
  0%, 54% { opacity: 1; }
  55%, 100% { opacity: 0.18; }
}

#gameOver {
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 50%, rgba(9, 14, 26, 0.42) 0%, rgba(4, 7, 14, 0.86) 74%),
    linear-gradient(180deg, rgba(4, 7, 14, 0.12), rgba(4, 7, 14, 0.5));
}

.over-inner {
  width: min(780px, 100%);
}

#gameOver.show .go-title {
  animation: slamIn 0.34s cubic-bezier(0.12, 0.9, 0.24, 1) both;
}

#gameOver.show .over-inner {
  animation: overFade 0.4s ease-out both;
}

@keyframes overFade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes slamIn {
  0% { transform: scale(1.7); opacity: 0; }
  60% { transform: scale(0.94); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.go-reason {
  color: var(--yellow);
  font-size: clamp(14px, 2.2vw, 28px);
  letter-spacing: 0.16em;
  text-shadow:
    2px 2px 0 #000,
    4px 4px 0 rgba(0, 0, 0, 0.7);
}

.go-title {
  margin-top: clamp(8px, 1.2vw, 16px);
  color: var(--red);
  font-size: clamp(28px, 5.6vw, 82px);
  line-height: 1.1;
  letter-spacing: 0.02em;
  text-shadow:
    3px 3px 0 #4A0505,
    6px 6px 0 #000;
}

.go-stats {
  margin-top: clamp(16px, 2.8vh, 32px);
  display: inline-flex;
  flex-direction: column;
  gap: clamp(8px, 1.2vh, 14px);
  padding: clamp(10px, 1.5vw, 18px) clamp(14px, 2vw, 26px);
  background: rgba(0, 0, 0, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-align: left;
}

.go-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: clamp(14px, 2.4vw, 34px);
  font-size: clamp(8px, 1.1vw, 13px);
  line-height: 1.6;
}

.go-row span {
  color: var(--yellow);
  text-shadow: 2px 2px 0 #000;
}

.go-row b {
  color: #FFFFFF;
  font-weight: 400;
  font-size: clamp(11px, 1.5vw, 18px);
  text-shadow:
    2px 2px 0 #000,
    3px 3px 0 rgba(0, 0, 0, 0.7);
}

#goScore {
  color: var(--yellow);
}

#goWaves,
.go-row:nth-child(2) span {
  color: #FFFFFF;
}

#gameOver .prompt {
  margin-top: clamp(18px, 3vh, 34px);
}

@media (pointer: coarse) {
  #coverBtn .key {
    display: none;
  }
}

@media (max-width: 620px) {
  #hud {
    gap: 3px;
    padding-top: calc(env(safe-area-inset-top, 0px) + 6px);
    padding-left: calc(env(safe-area-inset-left, 0px) + 5px);
    padding-right: calc(env(safe-area-inset-right, 0px) + 5px);
  }

  .plate {
    padding: 4px 5px;
  }

  .hud-label {
    font-size: 7px;
  }

  .hud-value {
    margin-top: 4px;
    font-size: 11px;
  }

  .time-value {
    font-size: clamp(17px, 5vw, 24px);
    min-width: 4.4em;
  }

  .health-block {
    width: 8px;
    height: 8px;
    border-width: 1px;
  }

  .health-blocks {
    gap: 2px;
  }

  .ammo-pips {
    height: 28px;
    gap: 3px;
  }

  .pip {
    width: 7px;
    border-width: 1px;
  }

  .tagline {
    font-size: 8px;
  }

  .instructions {
    font-size: 8px;
    line-height: 2;
  }

  .prompt {
    font-size: 12px;
  }

  #coverBtn .btn-main {
    font-size: 8px;
  }

  #coverBtn .btn-sub {
    font-size: 7px;
  }

  #reloadWarn {
    top: 56%;
  }
}

@media (max-aspect-ratio: 1/1) {
  .screen {
    align-items: center;
    text-align: center;
    padding-left: calc(env(safe-area-inset-left, 0px) + 16px);
    padding-right: calc(env(safe-area-inset-right, 0px) + 16px);
  }

  .start-inner {
    width: min(620px, 100%);
  }

  .title {
    align-items: center;
  }

  .tagline {
    margin-left: auto;
    margin-right: auto;
  }

  .instructions {
    text-align: left;
  }

  .go-stats {
    text-align: left;
  }

  #coverBtn {
    max-width: 58vw;
  }
}

@media (max-height: 520px) {
  .tagline.small,
  .instructions {
    margin-top: 8px;
  }

  .title {
    font-size: clamp(22px, 3.6vw, 44px);
  }

  .prompt {
    margin-top: 10px;
  }
}
