:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --accent: #ffb347;
  --danger: #ff4d4d;
  --ok: #7dffa9;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #05070b;
  color: #e8ecf1;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }

#hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
}

#wave-label {
  font-size: 22px; font-weight: 800; letter-spacing: 2px;
  color: var(--accent); text-shadow: 0 0 12px rgba(255,179,71,.5);
}
#enemies-left { font-size: 13px; opacity: .85; margin-top: 2px; }

#hud-right { display: flex; gap: 8px; pointer-events: auto; }
#btn-pause, #btn-settings {
  width: 44px; height: 44px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(10,14,20,.6); color: #e8ecf1;
  font-size: 14px; font-weight: 700;
  backdrop-filter: blur(6px);
}
#btn-pause:active, #btn-settings:active { background: rgba(255,255,255,.15); }

#hud-bottom {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
}

#health-box { position: absolute; left: calc(16px + var(--safe-left)); bottom: calc(110px + var(--safe-bottom)); width: 150px; }
#health-bar-outer {
  height: 12px; border-radius: 6px; overflow: hidden;
  background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.2);
}
#health-bar { height: 100%; width: 100%; background: var(--ok); transition: width .15s, background .3s; }
#health-text { font-size: 12px; font-weight: 700; margin-top: 3px; text-align: center; opacity: .9; }

#ammo-box { position: absolute; right: calc(20px + var(--safe-right)); bottom: calc(150px + var(--safe-bottom)); text-align: right; }
#ammo-text { font-size: 30px; font-weight: 800; letter-spacing: 1px; text-shadow: 0 2px 8px rgba(0,0,0,.8); }
#weapon-name { font-size: 12px; font-weight: 700; letter-spacing: 2px; color: var(--accent); }

#crosshair {
  position: absolute; left: 50%; top: 46%;
  width: 34px; height: 34px; transform: translate(-50%,-50%);
}
#crosshair span {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.75);
  box-shadow: 0 0 8px rgba(0,0,0,.6), inset 0 0 6px rgba(0,0,0,.4);
}
#crosshair span::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 3px; height: 3px; background: #fff; border-radius: 50%;
  transform: translate(-50%,-50%);
}
#crosshair.shooting span { border-color: var(--accent); transform: scale(1.15); }

#hitmarker {
  position: absolute; left: 50%; top: 46%; width: 26px; height: 26px;
  transform: translate(-50%,-50%) rotate(45deg) scale(.4);
  opacity: 0; transition: opacity .12s, transform .12s;
}
#hitmarker::before, #hitmarker::after {
  content: ""; position: absolute; background: #fff;
}
#hitmarker::before { left: 50%; top: 0; width: 2px; height: 100%; transform: translateX(-50%); }
#hitmarker::after { top: 50%; left: 0; height: 2px; width: 100%; transform: translateY(-50%); }
#hitmarker.show { opacity: .95; transform: translate(-50%,-50%) rotate(45deg) scale(1); }
#hitmarker.kill { background: var(--danger); }

#damage-vignette {
  position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 140px rgba(255,30,30,.0);
  transition: box-shadow .25s;
}
#damage-vignette.hurt { box-shadow: inset 0 0 160px rgba(255,30,30,.55); }

#interact-hint {
  position: absolute; left: 50%; bottom: calc(190px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(10,14,20,.7); border: 1px solid rgba(255,179,71,.5);
  padding: 6px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
}

/* ---------- touch zones ---------- */
#joy-zone {
  position: absolute; left: 0; bottom: 0;
  width: 45%; height: 45%;
  pointer-events: auto;
}
#joy-base {
  position: absolute; left: 50%; top: 50%;
  width: 128px; height: 128px;
  transform: translate(-50%,-50%);
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.05);
  backdrop-filter: blur(2px);
  opacity: .9;
}
#joy-stick {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px;
  border-radius: 50%;
  transform: translate(-50%,-50%);
  background: rgba(255,179,71,.85);
  box-shadow: 0 0 14px rgba(255,179,71,.45);
}

#aim-zone {
  position: absolute; right: 0; top: 0;
  width: 55%; height: 70%;
  pointer-events: auto;
}

#buttons {
  position: absolute; right: calc(14px + var(--safe-right));
  bottom: calc(96px + var(--safe-bottom));
  display: flex; gap: 12px; align-items: flex-end;
  pointer-events: auto;
}
.ctl-btn {
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.3);
  background: rgba(12,16,24,.65);
  color: #e8ecf1; font-weight: 800; letter-spacing: 1px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.ctl-btn:active { background: rgba(255,255,255,.18); }
#btn-shoot { width: 88px; height: 88px; font-size: 16px; border-color: rgba(255,77,77,.6); color: #ffd9d9; }
#btn-shoot:active { background: rgba(255,77,77,.35); }
#btn-switch { width: 62px; height: 62px; font-size: 12px; }
#btn-reload { width: 62px; height: 62px; font-size: 12px; }

/* ---------- overlays ---------- */
#start-screen, #pause-screen, #settings-screen, #gameover-screen {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(3,5,9,.82);
  backdrop-filter: blur(8px);
  padding: calc(16px + var(--safe-left)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom));
}

#start-card, #pause-card, #settings-card, #gameover-card {
  width: min(440px, 100%);
  background: linear-gradient(180deg, rgba(14,19,28,.95), rgba(8,11,17,.95));
  border: 1px solid rgba(255,179,71,.35);
  border-radius: 16px;
  padding: 28px 26px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}

#start-card h1 {
  font-size: 42px; letter-spacing: 6px; font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(255,179,71,.45);
}
.tagline { margin-top: 6px; font-size: 14px; opacity: .8; font-style: italic; }

.howto {
  list-style: none; text-align: left; margin: 20px 0;
  font-size: 13.5px; line-height: 1.7; opacity: .95;
}
.howto b { color: var(--accent); }

#btn-start, #pause-card button, #settings-card button, #gameover-card button {
  display: block; width: 100%;
  padding: 14px; margin-top: 12px;
  font-size: 16px; font-weight: 800; letter-spacing: 2px;
  color: #0a0d12;
  background: var(--accent);
  border: none; border-radius: 10px;
}
#btn-start:active, #pause-card button:active, #settings-card button:active, #gameover-card button:active {
  filter: brightness(.85);
}
#pause-card button:not(:first-child), #gameover-card button:not(:first-child) {
  background: rgba(255,255,255,.12); color: #e8ecf1;
}
#btn-quit { background: rgba(255,77,77,.25) !important; color: #ffd9d9 !important; }

#pause-card h2, #settings-card h2, #gameover-card h2 {
  font-size: 30px; letter-spacing: 4px; font-weight: 900;
  color: var(--accent);
}
#final-score { margin-top: 10px; font-size: 15px; opacity: .9; }

#settings-card label {
  display: block; text-align: left; margin-top: 16px;
  font-size: 13px; font-weight: 700; letter-spacing: 1px; opacity: .9;
}
#settings-card input[type=range] {
  width: 100%; margin-top: 8px;
  -webkit-appearance: none; appearance: none;
  height: 6px; border-radius: 3px;
  background: rgba(255,255,255,.2);
  outline: none;
}
#settings-card input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0a0d12;
  box-shadow: 0 0 8px rgba(255,179,71,.5);
}

#arcade-nav, #arcade-nav2, #arcade-nav3 { margin-top: 18px; }
#arcade-nav a, #arcade-nav2 a, #arcade-nav3 a {
  font-size: 11px; letter-spacing: 1px;
  color: rgba(255,255,255,.45); text-decoration: none;
  border-bottom: 1px dotted rgba(255,255,255,.3);
}
#arcade-nav a:active, #arcade-nav2 a:active, #arcade-nav3 a:active { color: var(--accent); }

#wave-banner {
  position: absolute; left: 0; right: 0; top: 30%;
  text-align: center; z-index: 20; pointer-events: none;
}
#wave-banner span {
  display: inline-block;
  font-size: 46px; font-weight: 900; letter-spacing: 8px;
  color: #fff;
  text-shadow: 0 0 30px rgba(255,179,71,.8), 0 4px 18px rgba(0,0,0,.8);
  animation: bannerPop 2.2s ease forwards;
}
@keyframes bannerPop {
  0% { opacity: 0; transform: scale(.6); }
  15% { opacity: 1; transform: scale(1.08); }
  25% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.02); }
}
