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

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #fff4b8;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #2a2208;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* Allow mouse-wheel scroll on menus (body touch-action is none for the game) */
body.menu-open {
  touch-action: auto;
}

body.desktop-cursor {
  cursor: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#top-bar {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 40px;
}

.stat {
  text-align: center;
  min-width: 80px;
}

.stat .label,
.health-block .label,
.ammo-block .label,
#weapon-name {
  display: block;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: #8a6a00;
  opacity: 0.95;
  font-weight: 700;
}

.stat span:last-child {
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #1a1500;
  text-shadow: 0 0 10px rgba(255, 220, 50, 0.9), 0 1px 2px rgba(255, 255, 255, 0.8);
}

#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  opacity: 0.95;
}

.ch-h, .ch-v {
  position: absolute;
  background: #c99000;
  box-shadow: 0 0 6px #ffdd33;
}

.ch-h {
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  margin-top: -1px;
  background: transparent;
}

.ch-h::before, .ch-h::after {
  content: "";
  position: absolute;
  top: 0;
  width: 8px;
  height: 2px;
  background: #b87800;
  box-shadow: 0 0 4px #ffcc00;
}

.ch-h::before { left: 0; }
.ch-h::after { right: 0; }

.ch-v {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: transparent;
}

.ch-v::before, .ch-v::after {
  content: "";
  position: absolute;
  left: 0;
  width: 2px;
  height: 8px;
  background: #b87800;
  box-shadow: 0 0 6px #ffcc00;
}

.ch-v::before { top: 0; }
.ch-v::after { bottom: 0; }

.ch-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 3px;
  margin: -1.5px 0 0 -1.5px;
  background: #5a4000;
  border-radius: 50%;
  box-shadow: 0 0 4px #ffdd22;
}

#crosshair.shooting {
  transform: translate(-50%, -50%) scale(1.25);
  opacity: 1;
}

#hit-marker {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  transform: translate(-50%, -50%) scale(0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.05s, transform 0.05s;
}

#hit-marker::before,
#hit-marker::after {
  content: "";
  position: absolute;
  background: #cc0000;
  box-shadow: 0 0 8px #ff3333;
}

#hit-marker::before {
  width: 100%;
  height: 2px;
  top: 50%;
  left: 0;
  transform: rotate(45deg);
}

#hit-marker::after {
  width: 100%;
  height: 2px;
  top: 50%;
  left: 0;
  transform: rotate(-45deg);
}

#hit-marker.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#damage-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(200, 0, 40, 0.5) 100%);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

#damage-vignette.active {
  opacity: 1;
}

#bottom-bar {
  position: absolute;
  bottom: 28px;
  left: 32px;
  right: 32px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.health-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bar-track {
  width: 180px;
  height: 14px;
  background: rgba(80, 60, 0, 0.15);
  border: 1px solid rgba(180, 140, 0, 0.55);
  border-radius: 2px;
  overflow: hidden;
}

#health-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff3b5c, #ffaa33 40%, #66cc22);
  box-shadow: 0 0 12px rgba(255, 200, 50, 0.5);
  transition: width 0.2s ease, background 0.2s;
}

#health-text {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  color: #1a1500;
}

.ammo-block {
  text-align: right;
}

#ammo {
  font-size: 42px;
  font-weight: 800;
  color: #1a1500;
  text-shadow: 0 0 12px rgba(255, 220, 40, 0.8);
  font-variant-numeric: tabular-nums;
}

.ammo-sep {
  font-size: 24px;
  color: #a08000;
  margin: 0 4px;
}

#reserve {
  font-size: 22px;
  color: #665500;
  font-variant-numeric: tabular-nums;
}

.ammo-block .label {
  margin-top: 2px;
}

#weapon-name {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  letter-spacing: 0.3em;
  color: #8a6a00;
}

#kill-feed {
  position: absolute;
  top: 80px;
  right: 24px;
  width: 220px;
  text-align: right;
  font-size: 13px;
  line-height: 1.6;
  color: #3a3000;
  font-weight: 600;
}

#kill-feed .feed-item {
  opacity: 0.95;
  animation: fadeFeed 2.5s forwards;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.7);
}

#kill-feed .feed-item em {
  color: #cc0033;
  font-style: normal;
}

@keyframes fadeFeed {
  0% { opacity: 1; transform: translateX(0); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateX(12px); }
}

/* All menus: start, pause, game over — same yellow theme */
#overlay,
#pause-overlay,
#gameover-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at center, rgba(255, 240, 160, 0.96), rgba(240, 200, 60, 0.98));
  cursor: default;
  pointer-events: auto;
  overflow: hidden;
  box-sizing: border-box;
}

#overlay.hidden,
#pause-overlay.hidden,
#gameover-overlay.hidden {
  display: none;
}

/* Scroll region — centers the card; card never exceeds the viewport */
.menu-scroll {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  touch-action: pan-y;
}

/* Pause / game over: same — card stays fully on-screen */
#pause-overlay,
#gameover-overlay {
  overflow: hidden;
  align-items: center;
  justify-content: center;
  padding: 16px;
  touch-action: pan-y;
}

#pause-overlay .panel,
#gameover-overlay .panel {
  margin-top: 0;
  margin-bottom: 0;
  flex-shrink: 1;
}

/* Concept art backdrop (start + game over) — fixed so it doesn't scroll away */
.menu-art {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(40, 28, 0, 0.55), rgba(255, 220, 80, 0.72)),
    url("arena-art.jpg") center / cover no-repeat;
  pointer-events: none;
  z-index: 0;
}

.menu-art-dim {
  filter: saturate(0.85) brightness(0.75);
}

.panel {
  position: relative;
  z-index: 1;
  text-align: center;
  /* Tall portrait card — always fully on-screen; content scrolls inside if needed */
  padding: 22px 26px 26px;
  border: 2px solid rgba(180, 140, 0, 0.55);
  background: rgba(255, 250, 210, 0.96);
  box-shadow:
    0 0 40px rgba(255, 200, 40, 0.4),
    inset 0 0 60px rgba(255, 230, 100, 0.18);
  max-width: 360px;
  width: min(360px, calc(100vw - 32px));
  /* Hard cap so top + bottom borders are never clipped by the window */
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  flex-shrink: 1;
  margin-top: 0;
  margin-bottom: 0;
  box-sizing: border-box;
}

.panel-hero {
  display: block;
  width: 100%;
  max-height: 100px;
  object-fit: cover;
  object-position: center 42%;
  border-radius: 6px;
  margin: 0 auto 12px;
  border: 1px solid rgba(180, 140, 0, 0.4);
  box-shadow:
    0 0 24px rgba(255, 80, 40, 0.25),
    0 8px 20px rgba(80, 50, 0, 0.2);
  flex-shrink: 0;
}

.panel h1 {
  font-size: clamp(26px, 4.2vw, 36px);
  letter-spacing: 0.12em;
  font-weight: 800;
  line-height: 1.05;
  background: linear-gradient(135deg, #c99000, #ffcc00, #ff8800);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 4px;
}

.panel h2 {
  font-size: 28px;
  letter-spacing: 0.2em;
  margin-bottom: 16px;
  color: #a07000;
}

.tagline {
  color: #6a5500;
  margin-bottom: 4px;
  font-size: 13px;
}

.controls {
  list-style: none;
  text-align: left;
  margin: 4px auto 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  color: #4a3a00;
  font-size: 13px;
  line-height: 1.45;
  width: 100%;
  max-width: 260px;
  padding: 10px 12px;
  border: 1px solid rgba(180, 140, 0, 0.35);
  border-radius: 8px;
  background: rgba(255, 240, 160, 0.35);
  box-sizing: border-box;
  flex-shrink: 0;
}

/* Tall single-column key list — readable portrait block */
.controls-desktop {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  max-width: 260px;
  margin: 4px auto 14px;
  text-align: left;
  font-size: 13px;
  line-height: 1.45;
  padding: 10px 12px;
  border: 1px solid rgba(180, 140, 0, 0.35);
  border-radius: 8px;
  background: rgba(255, 240, 160, 0.35);
  box-sizing: border-box;
  flex-shrink: 0;
}

.controls-desktop li {
  white-space: nowrap;
  width: 100%;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.menu-actions .donate-btn {
  margin-top: 0;
}

.controls kbd {
  display: inline-block;
  min-width: 28px;
  padding: 2px 8px;
  margin-right: 4px;
  border: 1px solid rgba(180, 140, 0, 0.55);
  border-radius: 4px;
  background: rgba(255, 220, 60, 0.4);
  color: #6a4a00;
  font-family: inherit;
  font-size: 12px;
  text-align: center;
  font-weight: 700;
}

button {
  appearance: none;
  border: 2px solid #c99000;
  background: linear-gradient(180deg, #ffe066, #ffcc00);
  color: #3a2800;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.2em;
  padding: 14px 36px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  box-shadow: 0 0 20px rgba(255, 200, 40, 0.5);
}

button:hover {
  transform: scale(1.04);
  background: linear-gradient(180deg, #fff088, #ffd633);
  box-shadow: 0 0 30px rgba(255, 200, 40, 0.75);
}

.hint {
  margin-top: 10px;
  margin-bottom: 0;
  font-size: 12px;
  color: #7a6500;
  flex-shrink: 0;
}

#gameover-overlay .panel p {
  margin-bottom: 8px;
  color: #5a4800;
}

#gameover-overlay .panel p strong {
  color: #a07000;
  font-size: 1.2em;
}

#gameover-overlay button {
  margin-top: 0;
}

.byline {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: #a07000;
  margin: 0 0 10px;
  font-weight: 600;
}

.also {
  margin-top: 10px;
  margin-bottom: 0;
  padding-bottom: 2px;
  font-size: 12px;
  flex-shrink: 0;
}

.also a {
  color: #8a6000;
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid rgba(160, 120, 0, 0.45);
}

.also a:hover {
  color: #5a4000;
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}

button.btn-secondary {
  background: transparent;
  border-color: rgba(160, 120, 0, 0.5);
  color: #6a5000;
  box-shadow: none;
  font-weight: 700;
}

button.btn-secondary:hover {
  background: rgba(255, 220, 80, 0.35);
  box-shadow: none;
}

/* PayPal donate — secondary accent, visible on all menus */
a.donate-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 10px 26px;
  border: 2px solid #cc3366;
  border-radius: 4px;
  background: linear-gradient(180deg, #ff6b9d, #e6396b);
  color: #fff8f0;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-decoration: none;
  box-shadow: 0 0 18px rgba(230, 57, 107, 0.45);
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  cursor: pointer;
}

a.donate-btn:hover {
  transform: scale(1.04);
  background: linear-gradient(180deg, #ff8ab0, #f04a7a);
  box-shadow: 0 0 28px rgba(230, 57, 107, 0.7);
  color: #ffffff;
}

.btn-row a.donate-btn {
  margin-top: 4px;
}

body.is-mobile .desktop-only { display: none !important; }
body:not(.is-mobile) .mobile-only { display: none !important; }

/* ─── Mobile touch UI ─────────────────────────────────────────────────────── */
#touch-ui {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
}

#touch-ui.hidden {
  display: none;
}

#joy-zone {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 130px;
  height: 130px;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 16;
}

#joy-base {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: 2px solid rgba(160, 120, 0, 0.55);
  background: rgba(255, 245, 180, 0.4);
  position: relative;
  box-shadow: inset 0 0 16px rgba(120, 90, 0, 0.15);
}

#joy-stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(255, 200, 40, 0.75);
  border: 2px solid rgba(140, 100, 0, 0.6);
  box-shadow: 0 2px 10px rgba(80, 60, 0, 0.35);
  will-change: transform;
}

.touch-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: rgba(80, 60, 0, 0.75);
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.6);
}

#look-hint {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(220px, calc(env(safe-area-inset-bottom) + 200px));
  text-align: right;
  max-width: 100px;
  line-height: 1.3;
  pointer-events: none;
  opacity: 0.65;
}

#touch-actions {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: auto;
  z-index: 16;
}

.touch-btn {
  appearance: none;
  min-width: 0 !important;
  width: 72px;
  height: 72px;
  padding: 0 !important;
  border-radius: 50% !important;
  font-size: 10px !important;
  letter-spacing: 0.08em !important;
  font-weight: 800 !important;
  background: rgba(255, 240, 160, 0.55) !important;
  border: 2px solid rgba(160, 120, 0, 0.55) !important;
  color: #4a3800 !important;
  box-shadow: 0 3px 12px rgba(80, 60, 0, 0.25) !important;
  touch-action: none;
  line-height: 1.1;
}

.touch-btn-sm {
  width: 64px;
  height: 64px;
}

.touch-btn-fire {
  width: 86px !important;
  height: 86px !important;
  font-size: 13px !important;
  background: rgba(255, 80, 60, 0.55) !important;
  border-color: rgba(180, 40, 20, 0.7) !important;
  color: #3a1008 !important;
  box-shadow: 0 4px 16px rgba(200, 40, 20, 0.35) !important;
}

.touch-btn:active,
.touch-btn.active {
  transform: scale(0.95);
  background: rgba(255, 210, 60, 0.85) !important;
}

.touch-btn-fire:active,
.touch-btn-fire.active {
  background: rgba(255, 60, 40, 0.8) !important;
}

.fab {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 16;
  pointer-events: auto;
  min-width: 0 !important;
  width: 44px;
  height: 44px;
  padding: 0 !important;
  border-radius: 10px !important;
  font-size: 12px !important;
  letter-spacing: 0 !important;
  line-height: 40px;
  text-align: center;
  background: rgba(255, 245, 180, 0.85) !important;
  border: 2px solid rgba(160, 120, 0, 0.5) !important;
  color: #5a4000 !important;
  box-shadow: 0 2px 10px rgba(80, 60, 0, 0.25) !important;
}

.fab.hidden {
  display: none !important;
}

/* Desktop: portrait card stays fully in view */
body:not(.is-mobile) .panel-hero {
  max-height: 100px;
}

body:not(.is-mobile) .panel {
  padding: 22px 26px 24px;
}

body:not(.is-mobile) .hint {
  margin-top: 10px;
}

body:not(.is-mobile) .also {
  margin-top: 10px;
}

body:not(.is-mobile) button {
  padding: 12px 28px;
  font-size: 15px;
}

@media (max-width: 700px), (pointer: coarse) {
  .menu-scroll {
    padding: 12px 10px;
  }

  #pause-overlay,
  #gameover-overlay {
    padding: 12px 10px;
  }

  .panel {
    max-width: min(340px, calc(100vw - 20px));
    width: min(340px, calc(100vw - 20px));
    max-height: calc(100dvh - 24px);
    padding: 18px 14px 20px;
  }

  .panel-hero {
    max-height: min(90px, 14vh);
    margin-bottom: 10px;
  }

  .panel h1 {
    font-size: 28px;
    letter-spacing: 0.1em;
  }

  .panel h2 {
    font-size: 24px;
  }

  .controls {
    margin-bottom: 16px;
    font-size: 12px;
    line-height: 1.75;
  }

  .controls-desktop {
    max-width: 100%;
    padding: 10px 12px;
    gap: 6px;
    margin-bottom: 16px;
  }

  #top-bar {
    top: max(10px, env(safe-area-inset-top));
    gap: 18px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    max-width: calc(100% - 100px);
  }

  .stat span:last-child {
    font-size: 18px;
  }

  .stat .label {
    font-size: 9px;
  }

  #bottom-bar {
    bottom: max(150px, calc(env(safe-area-inset-bottom) + 130px));
    left: 12px;
    right: 12px;
  }

  .bar-track {
    width: 100px;
    height: 10px;
  }

  #ammo {
    font-size: 28px;
  }

  #health-text {
    font-size: 16px;
  }

  #weapon-name {
    bottom: max(130px, calc(env(safe-area-inset-bottom) + 110px));
    font-size: 10px;
  }

  #kill-feed {
    top: 70px;
    right: 10px;
    width: 140px;
    font-size: 11px;
  }

  button {
    min-width: min(200px, 70vw);
    padding: 14px 22px;
    font-size: 14px;
  }

  #overlay .panel,
  #pause-overlay .panel,
  #gameover-overlay .panel {
    touch-action: pan-y;
  }
}

/* Short desktop windows: tighten so the full card + footer fit without clipping */
@media (max-height: 780px) {
  body:not(.is-mobile) .panel-hero {
    max-height: 72px;
  }

  body:not(.is-mobile) .panel {
    padding: 16px 22px 18px;
  }

  body:not(.is-mobile) .panel h1 {
    font-size: 26px;
    margin-bottom: 2px;
  }

  body:not(.is-mobile) .byline {
    margin-bottom: 8px;
  }

  body:not(.is-mobile) .controls-desktop {
    margin-bottom: 10px;
    gap: 4px;
    padding: 8px 10px;
    font-size: 12px;
  }

  body:not(.is-mobile) .menu-actions {
    gap: 6px;
  }

  body:not(.is-mobile) button {
    padding: 10px 24px;
    font-size: 14px;
  }

  body:not(.is-mobile) a.donate-btn {
    padding: 8px 22px;
    font-size: 13px;
  }

  body:not(.is-mobile) .hint {
    margin-top: 8px;
  }

  body:not(.is-mobile) .also {
    margin-top: 8px;
  }
}

@media (max-height: 640px) {
  body:not(.is-mobile) .panel-hero {
    max-height: 52px;
  }

  body:not(.is-mobile) .panel {
    padding: 12px 18px 14px;
  }

  body:not(.is-mobile) .controls-desktop {
    gap: 3px;
    padding: 6px 8px;
    margin-bottom: 8px;
  }
}
