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

body {
  margin: 0;
  overflow: hidden;
  background: #0a0a0a;
  font-family: monospace;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;           /* prevent iOS scroll/zoom on the game canvas */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ---- Reset-zoom button ---- */
#reset-zoom-btn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 50;
  background: rgba(42, 74, 42, 0.85);
  border: 2px solid rgba(160, 200, 128, 0.8);
  border-radius: 10px;
  color: #a0e080;
  font-family: monospace;
  font-size: 13px;
  padding: 8px 12px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#reset-zoom-btn.hidden {
  display: none;
}

/* ---- On-screen touch controls ---- */
#touch-controls {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;   /* container is invisible; children opt-in */
  z-index: 20;
}

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

#tc-move-group {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 24px;
  display: flex;
  gap: 12px;
  pointer-events: all;
}

#tc-action-group {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom));
  right: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: all;
}

#tc-jump-row {
  display: flex;
  justify-content: center;
}

#tc-action-row {
  display: flex;
  gap: 12px;
}

#tc-pause {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  pointer-events: all;
}

.tc-btn {
  width: max(44px, 8vh);
  height: max(44px, 8vh);
  background: rgba(42, 74, 42, 0.45);
  border: 2px solid rgba(160, 200, 128, 0.55);
  border-radius: 12px;
  color: #a0e080;
  font-size: max(18px, 4vh);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.08s, border-color 0.08s;
}

.tc-btn:active {
  background: rgba(74, 122, 74, 0.70);
  border-color: rgba(160, 224, 128, 0.95);
}

.overlay {
  position: fixed;       /* fixed so it tracks the visual viewport, not the document */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;   /* allow scrolling up when keyboard shrinks viewport */
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;              /* scroll the overlay when keyboard is open */
  background: rgba(0, 0, 0, 0.85);
  color: #4a7a4a;
  font-family: monospace;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.menu-panel {
  background: #1a2e1a;
  border: 2px solid #4a7a4a;
  border-radius: 4px;
  padding: clamp(20px, 5vw, 40px) clamp(16px, 7vw, 60px);
  min-width: min(400px, 90vw);
  max-width: min(600px, 96vw);
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
}

.menu-title {
  font-size: clamp(28px, 8vw, 48px);
  color: #4a7a4a;
  text-shadow: 0 0 20px #2d4a2d;
  margin-bottom: 10px;
  letter-spacing: clamp(1px, 1vw, 4px);
}

.menu-subtitle {
  font-size: clamp(11px, 2.5vw, 14px);
  color: #6a9a6a;
  margin-bottom: clamp(20px, 5vw, 40px);
  letter-spacing: 2px;
}

/* ---- Small-screen prompts (portrait rotation + landscape too-small) ---- */
#rotate-prompt,
#small-screen-prompt {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #0a0a0a;
  color: #4a7a4a;
  font-family: monospace;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  text-align: center;
  padding: 32px;
}

#rotate-prompt .rotate-icon {
  font-size: 64px;
  animation: rotate-hint 2s ease-in-out infinite;
}

#rotate-prompt p,
#small-screen-prompt p {
  font-size: 16px;
  letter-spacing: 2px;
  color: #6a9a6a;
  max-width: 300px;
  line-height: 1.6;
}

@keyframes rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  40%       { transform: rotate(90deg); }
  60%       { transform: rotate(90deg); }
}

@media (orientation: portrait) and (max-width: 600px) {
  #rotate-prompt { display: flex; }
}

@media (orientation: landscape) and (max-height: 450px) {
  #small-screen-prompt { display: flex; }
}

.menu-btn {
  display: block;
  width: 100%;
  padding: 14px 20px;
  margin: 8px 0;
  background: #2d4a2d;
  color: #a0c8a0;
  border: 1px solid #4a7a4a;
  border-radius: 3px;
  font-family: monospace;
  font-size: 16px;
  cursor: pointer;
  letter-spacing: 2px;
  touch-action: manipulation;    /* remove 300ms tap delay on Android */
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.menu-btn:hover, .menu-btn.selected {
  background: #4a7a4a;
  color: #e0ffe0;
  border-color: #8aca8a;
}

.menu-btn.danger {
  border-color: #cc2222;
  color: #ff6666;
}

.menu-btn.danger:hover {
  background: #cc2222;
  color: #fff;
}

.menu-input {
  width: 100%;
  padding: 12px 16px;
  background: #0a0a0a;
  color: #4a7a4a;
  border: 1px solid #4a7a4a;
  border-radius: 3px;
  font-family: monospace;
  font-size: 18px;               /* ≥16px prevents Android auto-zoom on focus */
  text-align: center;
  outline: none;
  margin: 8px 0;
  letter-spacing: 2px;
  touch-action: manipulation;
}

.menu-input:focus {
  border-color: #8aca8a;
  box-shadow: 0 0 8px rgba(74, 122, 74, 0.5);
}

.menu-section-title {
  font-size: 12px;
  color: #6a9a6a;
  letter-spacing: 3px;
  margin: clamp(10px, 3vh, 20px) 0 clamp(6px, 1.5vh, 10px) 0;
  text-transform: uppercase;
}

.player-list {
  max-height: 200px;
  overflow-y: auto;
  margin: 8px 0;
}

.player-list::-webkit-scrollbar {
  width: 6px;
}

.player-list::-webkit-scrollbar-track {
  background: #0a0a0a;
}

.player-list::-webkit-scrollbar-thumb {
  background: #4a7a4a;
  border-radius: 3px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin: 10px 0;
}

.leaderboard-table th {
  color: #6a9a6a;
  font-size: 11px;
  letter-spacing: 2px;
  padding: 6px 8px;
  border-bottom: 1px solid #2d4a2d;
  text-align: left;
}

.leaderboard-table td {
  padding: 8px 8px;
  border-bottom: 1px solid #1a2e1a;
  color: #a0c8a0;
}

.leaderboard-table tr:nth-child(1) td {
  color: #ffd700;
}

.leaderboard-table tr:nth-child(2) td {
  color: #c0c0c0;
}

.leaderboard-table tr:nth-child(3) td {
  color: #cd7f32;
}

.back-btn {
  margin-top: 20px;
  font-size: 12px;
  padding: 8px 20px;
}

.list-group-header {
  font-size: 11px;
  color: #6a9a6a;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin: 16px 0 6px;
  padding: 0 4px;
  border-bottom: 1px solid #2d4a2d;
}

/* ---- Modifier banner (shown between game over and next round start) ---- */
#banner-skip {
  animation: pulse-green 0.9s ease-in-out infinite alternate;
  margin-top: 8px;
}

/* ---- Bonus mission countdown timer ---- */
#bonus-countdown-wrap {
  display: block;
  width: 100%;
  padding: 16px 20px 12px;
  margin: 0 0 16px;
  background: rgba(0, 80, 0, 0.35);
  border: 2px solid #44ff44;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  animation: pulse-border 0.9s ease-in-out infinite alternate;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#bonus-countdown-wrap:hover,
#bonus-countdown-wrap:active {
  background: rgba(0, 120, 0, 0.55);
  border-color: #88ff88;
}

#bonus-countdown {
  font-size: clamp(40px, 12vw, 64px);
  color: #44ff44;
  line-height: 1;
  margin-bottom: 6px;
}

#bonus-countdown-label {
  font-size: 15px;
  color: #c0ffc0;
  letter-spacing: 2px;
  font-weight: bold;
}

@keyframes pulse-border {
  from { border-color: #44ff44; box-shadow: 0 0 8px rgba(68,255,68,0.3); }
  to   { border-color: #88ff88; box-shadow: 0 0 22px rgba(68,255,68,0.7); }
}
