html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #06121f;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  height: 100vh;
  height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  cursor: default;
  touch-action: none;             /* we handle all gestures ourselves */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

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

#hud .hidden {
  display: none;
}

/* Keep taps working on HUD controls but disable double-tap-to-zoom, so quickly
   tapping a button twice (e.g. launching two planes) doesn't zoom the page. */
#hud button,
#pause-btn,
#selection-panel,
#menu-screen,
#controls-screen,
#banner {
  touch-action: manipulation;
}

#messages {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  color: #cfe3f5;
  font-size: 14px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

#pause-indicator {
  position: absolute;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 18px;
  background: rgba(8, 22, 38, 0.85);
  border: 1px solid #3b6591;
  border-radius: 6px;
  color: #eef6ff;
  font-size: 16px;
  letter-spacing: 1px;
  text-align: center;
}

#pause-indicator span {
  display: block;
  font-size: 11px;
  letter-spacing: 0;
  opacity: 0.6;
}

#selection-panel {
  position: absolute;
  left: 12px;
  bottom: 12px;
  min-width: 220px;
  padding: 10px 14px;
  background: rgba(8, 22, 38, 0.88);
  border: 1px solid #2a4a6b;
  border-radius: 6px;
  color: #cfe3f5;
  font-size: 13px;
  pointer-events: auto;
}

#selection-panel button {
  margin: 4px 6px 2px 0;
  padding: 4px 10px;
  background: #17324f;
  border: 1px solid #3b6591;
  border-radius: 4px;
  color: #cfe3f5;
  font-size: 12px;
  cursor: pointer;
}

#selection-panel button:hover:not(:disabled) {
  background: #21446b;
}

#selection-panel button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Per-unit chips in a group selection. Bounded height so the panel can never take
   over the screen: seven unit types on screen at once would still allow 56 chips. */
.chip-groups {
  max-height: 42vh;
  overflow-y: auto;
  margin-top: 6px;
}

.chip-group + .chip-group {
  margin-top: 6px;
}

.chip-label {
  font-size: 11px;
  opacity: 0.65;
  letter-spacing: 0.02em;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 3px;
  max-width: 264px; /* ~6 chips per row before wrapping */
}

/* Overrides the generic #selection-panel button rules above. */
#selection-panel button.unit-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 0;
  padding: 3px;
  width: 40px;
  background: rgba(23, 50, 79, 0.7);
  border: 1px solid #2a4a6b;
  border-radius: 4px;
}

#selection-panel button.unit-chip:hover {
  background: #21446b;
  border-color: #5b8fc4;
}

.unit-chip img {
  display: block;
  width: 30px;
  height: 30px;
}

.chip-hp {
  display: block;
  width: 28px;
  height: 3px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 1px;
  overflow: hidden;
}

.chip-hp i {
  display: block;
  height: 100%;
}

/* Same thresholds as the HP bar drawn over the unit on the map. */
.chip-hp .hp-ok { background: #4dd05a; }
.chip-hp .hp-warn { background: #e0c040; }
.chip-hp .hp-bad { background: #e04a3a; }

.chip-more {
  align-self: center;
  font-size: 11px;
  opacity: 0.6;
  padding: 0 4px;
}

#banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 24px 48px;
  background: rgba(8, 22, 38, 0.92);
  border: 1px solid #3b6591;
  border-radius: 8px;
  color: #eef6ff;
  font-size: 28px;
  text-align: center;
  pointer-events: auto;
}

/* Full-screen menu / controls overlays */
#menu-screen,
#controls-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 18, 31, 0.82);
  pointer-events: auto;
}

.menu-card,
.controls-card {
  background: rgba(8, 22, 38, 0.9);
  border: 1px solid #3b6591;
  border-radius: 10px;
  color: #cfe3f5;
  text-align: center;
}

.menu-card {
  padding: 40px 56px;
}

.menu-card h1 {
  margin: 0 0 6px;
  font-size: 42px;
  letter-spacing: 1px;
  color: #eef6ff;
}

.menu-card .subtitle {
  margin: 0 0 28px;
  font-size: 14px;
  opacity: 0.7;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.menu-buttons button {
  min-width: 220px;
  padding: 12px 24px;
  font-size: 17px;
  cursor: pointer;
  background: #17324f;
  border: 1px solid #3b6591;
  border-radius: 6px;
  color: #eef6ff;
}

.menu-buttons button:hover {
  background: #21446b;
}

.controls-card {
  max-width: 620px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 28px 36px;
  text-align: left;
}

.controls-card h2 {
  margin: 0 0 18px;
  font-size: 26px;
  color: #eef6ff;
  text-align: center;
}

.controls-card h3 {
  margin: 22px 0 10px;
  font-size: 16px;
  color: #9fc6ee;
  border-bottom: 1px solid #2a4a6b;
  padding-bottom: 4px;
}

.controls-card dl {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(160px, auto) 1fr;
  gap: 6px 18px;
  font-size: 14px;
}

.controls-card dt {
  font-weight: 600;
  color: #eef6ff;
}

.controls-card dd {
  margin: 0;
  opacity: 0.85;
}

.controls-card ul {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.5;
}

.controls-card li {
  margin-bottom: 8px;
}

.controls-card .note {
  margin: 12px 0 0;
  font-size: 13px;
  opacity: 0.7;
}

.controls-card .menu-buttons {
  margin-top: 24px;
}

/* On-screen pause button (needed on touch; handy on desktop too) */
#pause-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 16px;
  line-height: 44px;
  text-align: center;
  background: rgba(23, 50, 79, 0.9);
  border: 1px solid #3b6591;
  border-radius: 8px;
  color: #eef6ff;
  cursor: pointer;
  pointer-events: auto;
}

#pause-btn:hover {
  background: #21446b;
}

/* Controls screen: show the input list matching the device.
   Scoped under .controls-card to outrank the base `.controls-card dl` rule. */
.controls-card .controls-touch {
  display: none;
}

@media (pointer: coarse) {
  .controls-card .controls-desktop {
    display: none;
  }
  .controls-card .controls-touch {
    display: grid;
  }

  /* Bigger tap targets on touch devices */
  #selection-panel {
    max-width: calc(100vw - 24px);
  }
  #selection-panel button {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 14px;
  }
  /* Chips need to be tappable, but not so tall the panel eats the map. */
  #selection-panel button.unit-chip {
    width: 50px;
    padding: 4px;
  }
  .unit-chip img {
    width: 40px;
    height: 40px;
  }
  .chip-hp {
    width: 38px;
    height: 4px;
  }
  /* Flow the type groups across the width rather than stacking them. On a short
     landscape screen stacking scrolls a four-type task force out of view; in
     portrait it gives two columns instead of one tall list. Either way the panel
     stays shorter, which matters most on a phone. */
  .chip-groups {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 14px;
    max-height: 34vh;
  }
  .chip-group + .chip-group {
    margin-top: 0;
  }
  .chip-row {
    max-width: 166px; /* 3 chips per row inside a group */
  }
}
