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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Segoe UI', Arial, sans-serif;
  touch-action: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #000;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* ===================== HUD ===================== */

#hud {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 15;
}

#hud-top-left {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 220px;
  color: #bfe8ff;
  font-size: 11px;
  letter-spacing: 1px;
  text-shadow: 0 0 6px rgba(0,0,0,0.8);
}

#hud-top-right {
  position: absolute;
  top: 14px;
  right: 14px;
  text-align: right;
  color: #bfe8ff;
  font-size: 14px;
  text-shadow: 0 0 6px rgba(0,0,0,0.8);
}

.bar-label {
  margin-top: 6px;
  margin-bottom: 2px;
  opacity: 0.85;
}

.bar-track {
  width: 100%;
  height: 12px;
  background: rgba(10, 20, 30, 0.7);
  border: 1px solid rgba(120, 200, 255, 0.4);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 100%;
  transition: width 0.1s linear, background-color 0.2s linear;
}

.bar-fill.health {
  background: linear-gradient(90deg, #2ee6a0, #6bf5c4);
}

.bar-fill.heat {
  background: linear-gradient(90deg, #3fa9ff, #3fa9ff);
}

#heat-state-label {
  margin-top: 3px;
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 2px;
  color: #7fd4ff;
}

#overheat-banner {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  color: #ff5555;
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 3px;
  text-shadow: 0 0 12px rgba(255,60,60,0.9);
  animation: blink 0.5s infinite;
}

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.25; }
}

#score-label, #wave-label {
  font-size: 16px;
  margin-bottom: 4px;
}

#weapon-panel {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.weapon-button {
  min-width: 92px;
  height: 34px;
  border: 1px solid rgba(120, 200, 255, 0.45);
  border-radius: 6px;
  background: rgba(8, 18, 30, 0.78);
  color: #bfe8ff;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 0.5px;
  cursor: pointer;
}

.weapon-button.active {
  border-color: #ffffff;
  color: #ffffff;
  background: rgba(28, 74, 105, 0.9);
  box-shadow: 0 0 14px rgba(95, 208, 255, 0.42);
}

#boss-panel {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, 46vw);
  color: #f4d8ff;
  text-align: center;
  text-shadow: 0 0 8px rgba(0,0,0,0.85);
}

#boss-name {
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.bar-track.boss {
  height: 14px;
  border-color: rgba(218, 120, 255, 0.7);
}

.bar-fill.boss {
  background: linear-gradient(90deg, #ff4d8d, #c98bff);
}

#boss-phase {
  margin-top: 3px;
  font-size: 10px;
  letter-spacing: 2px;
}

/* ===================== Overlays ===================== */

.overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(8,14,28,0.92) 0%, rgba(2,4,10,0.97) 100%);
  z-index: 20;
  padding: 20px;
  text-align: center;
}

.title {
  color: #7fe9ff;
  font-size: 52px;
  letter-spacing: 8px;
  text-shadow: 0 0 20px rgba(90, 200, 255, 0.8), 0 0 60px rgba(120,80,255,0.4);
  margin-bottom: 10px;
}

.title.small {
  font-size: 28px;
  letter-spacing: 4px;
}

.subtitle {
  color: #9fb8d8;
  font-size: 15px;
  margin-bottom: 24px;
  letter-spacing: 1px;
}

#best-score-display, #final-score-display, #final-best-display, #victory-score-display {
  color: #c9a4ff;
  font-size: 18px;
  margin-bottom: 14px;
  letter-spacing: 1px;
}

.big-button {
  background: linear-gradient(180deg, #1c3a54, #0f2438);
  border: 2px solid #4fc3ff;
  color: #dff4ff;
  font-size: 20px;
  letter-spacing: 2px;
  padding: 14px 40px;
  margin: 8px;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 0 16px rgba(79, 195, 255, 0.35);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.big-button:hover, .big-button:active {
  transform: scale(1.04);
  box-shadow: 0 0 26px rgba(79, 195, 255, 0.6);
}

.big-button.secondary {
  border-color: #8888a0;
  color: #c8c8d8;
  box-shadow: none;
  background: linear-gradient(180deg, #24242e, #16161c);
}

.controls-hint {
  display: none;
  margin-top: 20px;
  color: #6f8aa8;
  font-size: 13px;
  letter-spacing: 0.5px;
}

#how-to-play {
  width: min(760px, 92vw);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 10px 0 18px;
}

.how-column {
  border: 1px solid rgba(127, 233, 255, 0.28);
  background: rgba(6, 18, 30, 0.72);
  border-radius: 8px;
  padding: 14px 16px;
  text-align: left;
}

.how-column h3 {
  color: #7fe9ff;
  font-size: 13px;
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.how-column p {
  color: #cfe9f8;
  font-size: 14px;
  line-height: 1.6;
}

.how-column span {
  display: inline-block;
  min-width: 118px;
  color: #ffffff;
  font-weight: bold;
}

/* ===================== Upgrade screen ===================== */

#upgrade-choices {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 900px;
}

.upgrade-card {
  width: 220px;
  background: linear-gradient(180deg, rgba(30,50,75,0.9), rgba(12,22,36,0.9));
  border: 2px solid rgba(100, 200, 255, 0.5);
  border-radius: 8px;
  padding: 18px 14px;
  color: #e4f4ff;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.upgrade-card:hover, .upgrade-card:active {
  transform: translateY(-4px) scale(1.03);
  border-color: #ffffff;
}

.upgrade-card .upgrade-name {
  font-size: 17px;
  font-weight: bold;
  margin-bottom: 8px;
  color: #7fe9ff;
  letter-spacing: 1px;
}

.upgrade-card .upgrade-desc {
  font-size: 13px;
  color: #b8cfe6;
  line-height: 1.4;
}

/* ===================== Mobile controls ===================== */

#mobile-controls {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 10;
}

.touch-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  pointer-events: auto;
}

#joystick-zone { left: 0; }
#aim-zone { right: 0; }

#joystick-base {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(60, 120, 180, 0.15);
  border: 2px solid rgba(120, 200, 255, 0.5);
  display: none;
}

#joystick-knob {
  position: absolute;
  width: 50px;
  height: 50px;
  left: 35px;
  top: 35px;
  border-radius: 50%;
  background: rgba(120, 200, 255, 0.55);
  border: 2px solid rgba(200, 240, 255, 0.9);
}

@media (max-width: 900px), (pointer: coarse) {
  .title { font-size: 34px; letter-spacing: 4px; }
  .subtitle { font-size: 13px; }
  #controls-hint-desktop { display: none; }
  #how-to-play {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 6px 0 10px;
  }
  .how-column {
    padding: 10px 11px;
  }
  .how-column h3 {
    font-size: 11px;
    margin-bottom: 5px;
  }
  .how-column p {
    font-size: 11px;
    line-height: 1.45;
  }
  .how-column span {
    min-width: 82px;
  }
  #hud-top-left { width: 170px; font-size: 10px; }
  #hud-top-right { font-size: 12px; }
  #score-label, #wave-label { font-size: 13px; }
  #boss-panel { top: 8px; width: min(330px, 48vw); }
  #weapon-panel { bottom: 8px; gap: 5px; }
  .weapon-button {
    min-width: 68px;
    height: 30px;
    font-size: 9px;
    letter-spacing: 0;
  }
}

@media (max-width: 560px) {
  #how-to-play {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 901px) and (pointer: fine) {
  #controls-hint-mobile { display: none; }
}


/* ===================== Mobile launch polish ===================== */
.mobile-only-button { display: none; }

@media (max-width: 900px), (pointer: coarse) {
  html, body, #game-container {
    width: 100%;
    height: 100%;
    height: 100dvh;
  }

  .mobile-only-button {
    display: inline-block;
    font-size: 13px;
    padding: 10px 18px;
    margin: 4px;
  }

  #hud-top-left {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
  }

  #hud-top-right {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
  }

  #weapon-panel {
    bottom: max(12px, env(safe-area-inset-bottom));
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    z-index: 30;
  }

  #btn-sound {
    right: max(8px, env(safe-area-inset-right)) !important;
    bottom: max(54px, calc(env(safe-area-inset-bottom) + 48px)) !important;
    padding: 7px 9px !important;
    font-size: 10px !important;
  }

  #aim-zone {
    right: 0;
    width: 50%;
    bottom: 48px;
  }

  #joystick-zone {
    left: 0;
    width: 50%;
    bottom: 48px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .overlay {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .title {
    font-size: 28px;
    margin-bottom: 4px;
  }

  .subtitle {
    margin-bottom: 6px;
  }

  #best-score-display {
    margin-bottom: 4px;
    font-size: 14px;
  }

  #how-to-play {
    margin: 3px 0 5px;
  }

  .how-column {
    padding: 6px 9px;
  }

  .how-column p {
    font-size: 10px;
    line-height: 1.3;
  }

  .big-button {
    font-size: 14px;
    padding: 9px 22px;
    margin: 3px;
  }

  .controls-hint {
    margin-top: 5px;
    font-size: 10px;
  }
}


/* ===================== Joystick mode selector ===================== */
.mobile-only-settings { display: none; }

@media (max-width: 900px), (pointer: coarse) {
  .mobile-only-settings {
    display: block;
    width: min(520px, 92vw);
    margin: 6px auto 2px;
    padding: 8px 10px;
    border: 1px solid rgba(127,233,255,.28);
    border-radius: 8px;
    background: rgba(6,18,30,.78);
    color: #cfe9f8;
  }

  .setting-title {
    color: #7fe9ff;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1.5px;
    margin-bottom: 6px;
  }

  .joystick-mode-buttons {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 6px;
  }

  .mode-button {
    min-width: 105px;
    padding: 7px 12px;
    border: 1px solid rgba(120,200,255,.45);
    border-radius: 6px;
    background: rgba(8,18,30,.9);
    color: #9fc8df;
    font-weight: 800;
    letter-spacing: .7px;
  }

  .mode-button.active {
    color: #fff;
    border-color: #fff;
    background: rgba(28,74,105,.95);
    box-shadow: 0 0 12px rgba(95,208,255,.4);
  }

  #joystick-mode-description {
    font-size: 10px;
    line-height: 1.35;
    color: #a9c5d8;
  }

  #aim-zone {
    left: 0;
    right: 0;
    width: 100%;
    bottom: 48px;
    z-index: 1;
  }

  body[data-joystick-mode="fixed"] #joystick-zone {
    left: max(8px, env(safe-area-inset-left));
    top: auto;
    bottom: max(50px, calc(env(safe-area-inset-bottom) + 50px));
    width: 170px;
    height: 170px;
    z-index: 3;
  }

  body[data-joystick-mode="floating"] #joystick-zone {
    left: 0;
    top: 0;
    bottom: 48px;
    width: 50%;
    height: auto;
    z-index: 3;
  }

  #joystick-base { z-index: 4; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .mobile-only-settings {
    width: min(560px, 88vw);
    padding: 5px 8px;
    margin: 2px auto;
  }
  .setting-title { margin-bottom: 3px; }
  .joystick-mode-buttons { margin-bottom: 3px; }
  .mode-button { padding: 5px 10px; font-size: 10px; }
  #joystick-mode-description { font-size: 9px; }
}


/* ===================== Final mobile control fixes ===================== */
#btn-mobile-menu {
  display: none;
}

@media (max-width: 900px), (pointer: coarse) {
  #btn-mobile-menu {
    display: block;
    position: absolute;
    top: max(62px, calc(env(safe-area-inset-top) + 58px));
    right: max(8px, env(safe-area-inset-right));
    z-index: 45;
    pointer-events: auto;
    min-width: 72px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid rgba(120, 220, 255, .7);
    border-radius: 7px;
    background: rgba(5, 15, 24, .88);
    color: #e8fbff;
    font: 800 11px/1 Arial, sans-serif;
    letter-spacing: .7px;
    touch-action: manipulation;
  }

  #weapon-panel {
    z-index: 50;
    pointer-events: auto;
  }

  .weapon-button {
    position: relative;
    z-index: 51;
    pointer-events: auto;
    touch-action: manipulation;
  }

  body[data-joystick-mode="fixed"] #joystick-zone {
    bottom: max(64px, calc(env(safe-area-inset-bottom) + 64px));
    width: 180px;
    height: 180px;
    z-index: 40;
  }

  body[data-joystick-mode="fixed"] #joystick-base {
    display: block;
  }

  #aim-zone {
    z-index: 2;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #btn-mobile-menu {
    top: max(54px, calc(env(safe-area-inset-top) + 50px));
  }
}
