* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: #0b1020; color: white;
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden; overscroll-behavior: none;
  user-select: none;
}
#game-wrap { position: fixed; inset: 0; overflow: hidden; }
#game { width: 100%; height: 100%; display: block; background: #0b1020; touch-action: none; }

#hud {
  position: absolute; top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex; justify-content: space-between; align-items: center;
  font-size: 20px; font-weight: 800; pointer-events: none;
  text-shadow: 0 2px 8px rgba(0,0,0,.6);
}
.hud-chip {
  display: inline-flex; align-items: center;
  background: rgba(23, 20, 20, .7);
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .25);
}
#kills { gap: 2px; padding: 3px 8px 3px 3px; }
#kills img { width: 34px; height: 34px; image-rendering: pixelated; }
#killsCount { font-size: clamp(15px, 3.8vw, 18px); font-variant-numeric: tabular-nums; }
.hud-right { display: flex; align-items: center; gap: 10px; }
#ammo {
  gap: 2px; padding: 2px 8px 2px 3px;
  white-space: nowrap;
}
#ammo img {
  width: 36px; height: 36px; object-fit: contain;
  image-rendering: pixelated;
}
#ammoCount {
  color: #ffe2a1; font-size: clamp(14px, 3.8vw, 18px);
  font-variant-numeric: tabular-nums;
}
#lives {
  gap: 1px; padding: 3px 4px;
}
#lives img { width: 28px; height: 28px; image-rendering: pixelated; }
#lives img.empty { filter: brightness(2); }
#armor { padding: 4px; }
#armor img { width: 26px; height: 30px; }
#armor.hidden, #hud.hidden, #controls.hidden { display: none; }
#stageBanner {
  position: absolute; top: max(56px, calc(env(safe-area-inset-top) + 46px));
  left: 50%; transform: translateX(-50%);
  z-index: 4; pointer-events: none;
  color: #fff1c7; font: 800 clamp(11px, 2.8vw, 16px)/1.2 ui-monospace, monospace;
  letter-spacing: .06em; text-align: center;
  text-shadow: 2px 2px 0 #241c19, 0 2px 9px #241c19;
  white-space: nowrap;
}
@media (max-width: 360px) {
  .hud-right { gap: 5px; }
  #ammo { padding-right: 5px; }
  #ammo img { width: 30px; height: 30px; }
  #kills img { width: 30px; height: 30px; }
  #lives img { width: 24px; height: 24px; }
  #armor img { width: 22px; height: 26px; }
}

#overlay {
  position: absolute; inset: 0;
  display: flex; justify-content: center; align-items: safe center;
  background: rgba(15, 16, 16, .84); backdrop-filter: blur(3px);
  z-index: 10;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow-x: hidden; overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}
#overlay.hidden { display: none; }
.title-screen {
  position: relative;
  flex: 0 1 900px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(220px, .85fr);
  grid-template-areas: "copy police" "actions actions";
  width: 100%; min-width: 0;
  min-height: 450px;
  padding: clamp(22px, 4vw, 42px);
  background: rgba(35, 34, 31, .94);
  border: 2px solid #776d61;
  box-shadow: 8px 8px 0 #151413, 0 26px 65px rgba(0, 0, 0, .5);
  color: #f0e5d3;
}
.title-screen::before {
  content: "";
  position: absolute; top: -2px; left: -2px;
  width: 33%; height: 6px;
  background: #b94836;
}
.title-copy { grid-area: copy; align-self: center; min-width: 0; z-index: 1; }
.title-kicker {
  margin: 0 0 18px;
  color: #d0bfa4; font: 800 12px/1.4 ui-monospace, monospace;
  letter-spacing: .12em;
}
.title-kicker span { color: #c1533e; }
#gameTitle {
  margin: 0 0 20px;
  width: fit-content;
  color: #f2e9d9;
  text-align: left;
  text-shadow: 5px 5px 0 #8d3329;
}
#gameTitle .t-code {
  display: block;
  font: 1000 clamp(44px, 8vw, 96px)/1 ui-monospace, monospace;
  letter-spacing: -.04em;
}
#gameTitle .t-num {
  display: block;
  font: 1000 clamp(44px, 8vw, 96px)/1 ui-monospace, monospace;
  letter-spacing: -.04em;
  text-align: center;
}
.title-caption {
  margin: 20px 0 0;
  color: #d2c6b5; font-size: clamp(16px, 2vw, 20px);
  line-height: 1.4;
}
.title-police {
  grid-area: police;
  display: grid; place-items: end center;
  min-height: 330px;
  min-width: 0; overflow: hidden;
  background: radial-gradient(ellipse at 50% 80%, rgba(174, 130, 84, .23), transparent 62%);
  border-bottom: 4px solid #554d43;
}
.title-police img {
  display: block;
  width: min(100%, 340px); height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(8px 8px 0 rgba(0, 0, 0, .4));
}
.title-actions {
  grid-area: actions;
  display: flex; align-items: center; gap: 24px;
  margin-top: 24px; padding-top: 22px;
  border-top: 1px solid #655b50;
}
#startBtn {
  flex: 0 0 auto;
  background: #b94836; color: #fff3da;
  border: 2px solid #e7b77a; border-radius: 3px;
  box-shadow: 4px 4px 0 #191412;
  font: 900 19px ui-monospace, monospace;
  padding: 15px 25px; cursor: pointer;
}
#startBtn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 #191412; }
#startBtn:focus-visible { outline: 3px solid #fff3da; outline-offset: 4px; }
#startBtn { touch-action: manipulation; }
.title-actions p {
  margin: 0; color: #bfb2a0;
  font: 700 11px/1.6 ui-monospace, monospace;
  letter-spacing: .03em;
}
#overlay.game-over .title-police img { filter: grayscale(.65) drop-shadow(8px 8px 0 rgba(0, 0, 0, .4)); }

@media (max-width: 640px) {
  .title-screen {
    grid-template-columns: 1fr;
    grid-template-areas: "copy" "police" "actions";
    min-height: 0;
    padding: clamp(12px, 3.5vw, 20px);
    text-align: center;
  }
  #gameTitle { margin-inline: auto; text-align: center; }
  .title-kicker { margin-bottom: 10px; }
  #gameTitle { margin-bottom: 10px; }
  #gameTitle .t-code, #gameTitle .t-num { font-size: clamp(38px, 12vw, 58px); }
  .title-caption { margin-top: 8px; }
  .title-police { min-height: 0; height: clamp(125px, 26dvh, 210px); margin-top: 6px; }
  .title-police img { width: min(58vw, 210px); max-height: 100%; object-fit: contain; }
  .title-actions { flex-direction: column; gap: 10px; margin-top: 12px; padding-top: 12px; }
  #startBtn { width: 100%; }
}
@media (max-width: 640px) and (max-height: 650px) {
  .title-screen { padding: 12px 16px; }
  #gameTitle .t-code, #gameTitle .t-num { font-size: clamp(34px, 11vw, 42px); }
  .title-police { height: clamp(95px, 22dvh, 145px); }
  .title-police img { width: 145px; }
  #startBtn { padding: 11px 18px; font-size: 16px; }
  .title-actions p { display: none; }
}
@media (min-width: 641px) and (max-height: 520px) {
  .title-screen { min-height: 0; padding: 14px 22px; }
  #gameTitle .t-code, #gameTitle .t-num { font-size: clamp(42px, 9dvh, 64px); }
  .title-kicker { margin-bottom: 8px; }
  .title-caption { margin-top: 8px; }
  .title-police { min-height: 0; height: clamp(140px, 45dvh, 220px); }
  .title-police img { width: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
  .title-actions { margin-top: 10px; padding-top: 10px; }
  #startBtn { padding: 10px 18px; font-size: 16px; }
  .title-actions p { display: none; }
}
@media (orientation: landscape) and (max-width: 1000px) and (max-height: 600px) {
  .title-screen {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
    grid-template-rows: auto auto;
    grid-template-areas: "copy police" "actions police";
    column-gap: clamp(8px, 3vw, 24px);
    min-height: 0;
    padding: 12px clamp(12px, 3vw, 24px);
  }
  .title-copy { align-self: end; text-align: center; }
  .title-kicker { margin-bottom: 6px; font-size: 11px; }
  #gameTitle { margin: 0 auto 6px; text-align: center; }
  #gameTitle .t-code, #gameTitle .t-num { font-size: clamp(34px, 10dvh, 50px); }
  .title-caption { margin: 6px 0 0; font-size: 14px; line-height: 1.25; }
  .title-police {
    align-self: center;
    height: clamp(130px, 58dvh, 220px);
    min-height: 0;
  }
  .title-police img {
    width: auto; height: 100%;
    max-width: 100%; max-height: 100%;
    object-fit: contain;
  }
  .title-actions {
    flex-direction: column;
    justify-content: center;
    gap: 0;
    margin-top: 10px; padding-top: 10px;
  }
  #startBtn { width: min(100%, 300px); padding: 10px 12px; font-size: 16px; }
  .title-actions p { display: none; }
}

#controls {
  position: absolute; bottom: max(16px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex; justify-content: flex-end;
  z-index: 5; pointer-events: none;
}
@media (hover: hover) and (pointer: fine) {
  #controls { display: none; }
}
.fire-button {
  width: 72px; height: 72px; padding: 0;
  display: grid; place-items: center;
  border: 2px solid rgba(255, 236, 198, .38);
  border-radius: 50%;
  background: rgba(17, 20, 23, .3);
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, .055), 0 4px 12px rgba(0, 0, 0, .18);
  -webkit-appearance: none; appearance: none;
  pointer-events: auto; touch-action: manipulation;
  cursor: pointer;
}
.fire-button img {
  display: block; width: 24px; height: 32px;
  image-rendering: pixelated;
  opacity: .86;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, .35));
  pointer-events: none;
}
.fire-button:active {
  transform: scale(.94);
  background: rgba(17, 20, 23, .48);
  border-color: rgba(255, 236, 198, .72);
}
.fire-button:focus-visible { outline: 3px solid #fff3da; outline-offset: 3px; }
