/* =========================
   GAME: SPACE BATTLE
========================= */

.spacebattle-game {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 20%, rgba(123, 97, 255, 0.35), transparent 28%),
    radial-gradient(circle at 80% 30%, rgba(34, 216, 255, 0.22), transparent 24%),
    radial-gradient(circle at 55% 70%, rgba(255, 4, 90, 0.18), transparent 30%),
    linear-gradient(180deg, #120a32 0%, #07061a 55%, #030411 100%);
  border: 7px solid #000;
  border-radius: 26px;
  box-shadow: 8px 8px 0 rgba(0,0,0,0.28);
  font-family: "Fredoka", Arial, sans-serif;
  color: #fff;
  touch-action: none;
  user-select: none;
}

.spacebattle-stars,
.spacebattle-stars::before,
.spacebattle-stars::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.95) 0 2px, transparent 3px),
    radial-gradient(circle, rgba(255,255,255,0.7) 0 1px, transparent 2px);
  background-size: 98px 98px, 57px 57px;
  background-position: 0 0, 22px 31px;
  animation: spacebattle-stars-move 14s linear infinite;
  opacity: 0.75;
}

.spacebattle-stars::before {
  background-size: 140px 140px;
  animation-duration: 21s;
  opacity: 0.45;
}

.spacebattle-stars::after {
  background-size: 210px 210px;
  animation-duration: 32s;
  opacity: 0.32;
}

@keyframes spacebattle-stars-move {
  from { transform: translateY(-40px); }
  to { transform: translateY(80px); }
}

.spacebattle-nebula {
  position: absolute;
  inset: -25%;
  background:
    radial-gradient(circle at 25% 45%, rgba(255, 4, 90, 0.16), transparent 24%),
    radial-gradient(circle at 70% 35%, rgba(0, 255, 201, 0.13), transparent 28%);
  filter: blur(18px);
  animation: spacebattle-nebula-drift 8s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes spacebattle-nebula-drift {
  from { transform: translate(-2%, -1%) rotate(-2deg); }
  to { transform: translate(2%, 2%) rotate(2deg); }
}

.spacebattle-error {
  background: #fff0a8;
  border: 7px solid #000;
  border-radius: 24px;
  padding: 28px;
  color: #000;
  font-family: "Fredoka", Arial, sans-serif;
}

.spacebattle-error button,
.spacebattle-start-btn,
.spacebattle-fire-btn,
.spacebattle-small-btn {
  border: 5px solid #000;
  border-radius: 16px;
  font-weight: 950;
  cursor: pointer;
  box-shadow: 5px 5px 0 rgba(0,0,0,0.32);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  touch-action: manipulation;
}

.spacebattle-error button:active,
.spacebattle-start-btn:active,
.spacebattle-fire-btn:active,
.spacebattle-small-btn:active {
  transform: translate(4px, 4px);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.32);
}

.spacebattle-setup {
  display: grid;
  place-items: center;
  padding: 24px;
}

.spacebattle-setup-card {
  position: relative;
  z-index: 2;
  width: min(980px, 94%);
  background: rgba(244, 229, 255, 0.96);
  color: #000;
  border: 7px solid #000;
  border-radius: 28px;
  padding: 24px;
  box-shadow: 12px 12px 0 rgba(0,0,0,0.35);
}

.spacebattle-setup-title-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px;
  align-items: center;
}

.spacebattle-big-icon {
  width: 94px;
  height: 94px;
  display: grid;
  place-items: center;
  background: #23d8ff;
  border: 6px solid #000;
  border-radius: 24px;
  font-size: 54px;
  box-shadow: 6px 6px 0 rgba(0,0,0,0.28);
}

.spacebattle-setup-card h2 {
  margin: 0 0 6px;
  font-size: clamp(32px, 5vw, 58px);
  line-height: 0.95;
}

.spacebattle-setup-card p {
  margin: 0;
  font-size: 20px;
  font-weight: 850;
}

.spacebattle-settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin: 22px 0;
}

.spacebattle-setting-box {
  background: #bff1ea;
  border: 5px solid #000;
  border-radius: 22px;
  padding: 16px;
  display: grid;
  gap: 10px;
}

.spacebattle-setting-box > span {
  font-size: 24px;
  font-weight: 950;
}

.spacebattle-dual-input {
  display: flex;
  align-items: center;
  gap: 10px;
}

.spacebattle-dual-input input {
  width: 125px;
  height: 52px;
  border: 4px solid #000;
  border-radius: 14px;
  font-size: 26px;
  font-weight: 950;
  padding: 0 10px;
  font-family: inherit;
}

.spacebattle-dual-input strong {
  font-size: 18px;
}

.spacebattle-setting-box input[type="range"] {
  width: 100%;
  accent-color: #ff045a;
}

.spacebattle-setting-box small {
  font-size: 14px;
  font-weight: 850;
  opacity: 0.75;
}

.spacebattle-howto {
  background: #fff0a8;
  border: 5px solid #000;
  border-radius: 18px;
  padding: 12px 16px;
  display: grid;
  gap: 5px;
  font-size: 17px;
  font-weight: 850;
}

.spacebattle-start-btn {
  width: 100%;
  margin-top: 18px;
  min-height: 76px;
  background: #d3ff00;
  font-size: clamp(24px, 4vw, 42px);
}

.spacebattle-hud {
  position: absolute;
  z-index: 10;
  top: 14px;
  left: 14px;
  right: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  pointer-events: none;
}

.spacebattle-hud-card {
  background: rgba(255,255,255,0.94);
  color: #000;
  border: 4px solid #000;
  border-radius: 16px;
  padding: 8px 10px;
  min-height: 62px;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.25);
  display: grid;
  align-content: center;
}

.spacebattle-hud-card span {
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
  opacity: 0.65;
}

.spacebattle-hud-card strong {
  display: block;
  font-size: clamp(19px, 2vw, 30px);
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spacebattle-arena {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.spacebattle-path-line {
  position: absolute;
  left: 50%;
  top: 11%;
  bottom: 19%;
  width: 10px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.55), rgba(255,255,255,0.08));
  border-radius: 999px;
  opacity: 0.35;
}

.spacebattle-planet-zone {
  position: absolute;
  inset: 96px 0 130px;
  z-index: 3;
}

.spacebattle-planet {
  position: absolute;
  width: 150px;
  height: 150px;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  transform-origin: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.spacebattle-planet-glow {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 4, 90, 0.5), transparent 68%);
  animation: spacebattle-planet-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes spacebattle-planet-pulse {
  from { opacity: 0.45; transform: scale(0.95); }
  to { opacity: 0.95; transform: scale(1.08); }
}

.spacebattle-planet-image {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 7px solid #000;
  background:
    radial-gradient(circle at 33% 25%, rgba(255,255,255,0.95), transparent 18%),
    radial-gradient(circle at 65% 75%, rgba(0,0,0,0.16), transparent 28%),
    linear-gradient(135deg, #fff0a8, #ff9bdf 55%, #23d8ff);
  overflow: hidden;
  box-shadow: 8px 8px 0 rgba(0,0,0,0.32);
}

.spacebattle-planet-image img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(3px 3px 0 rgba(0,0,0,0.2));
}

.spacebattle-planet-letter {
  font-size: 76px;
  font-weight: 950;
  color: #000;
}

.spacebattle-planet-name {
  position: absolute;
  left: 50%;
  bottom: -20px;
  transform: translateX(-50%);
  max-width: 190px;
  background: #fff;
  color: #000;
  border: 4px solid #000;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 16px;
  font-weight: 950;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.25);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spacebattle-ship-wrap {
  position: absolute;
  left: 50%;
  bottom: 30px;
  width: 150px;
  height: 150px;
  transform: translateX(-50%);
  z-index: 5;
  display: grid;
  place-items: center;
  animation: spacebattle-ship-float 1.2s ease-in-out infinite alternate;
}

@keyframes spacebattle-ship-float {
  from { transform: translateX(-50%) translateY(0); }
  to { transform: translateX(-50%) translateY(-8px); }
}

.spacebattle-ship {
  position: relative;
  z-index: 2;
  width: 110px;
  height: 126px;
  display: grid;
  place-items: center;
}

.spacebattle-ship-body {
  font-size: 96px;
  filter: drop-shadow(7px 7px 0 rgba(0,0,0,0.35));
  transform: rotate(-45deg);
}

.spacebattle-ship-window {
  position: absolute;
  width: 38px;
  height: 38px;
  border: 5px solid #000;
  border-radius: 50%;
  background: #23d8ff;
  z-index: 4;
  transform: translate(15px, -17px);
  display: none;
}

.spacebattle-ship-flame {
  position: absolute;
  bottom: -3px;
  left: 50%;
  width: 46px;
  height: 72px;
  transform: translateX(-50%);
  background: radial-gradient(circle at 50% 20%, #fff, #ffe066 34%, #ff6b35 63%, transparent 66%);
  border-radius: 50% 50% 65% 65%;
  filter: blur(1px);
  animation: spacebattle-flame 0.18s ease-in-out infinite alternate;
  opacity: 0.9;
}

@keyframes spacebattle-flame {
  from { transform: translateX(-50%) scaleY(0.82); opacity: 0.75; }
  to { transform: translateX(-50%) scaleY(1.2); opacity: 1; }
}

.spacebattle-control-dock {
  position: absolute;
  z-index: 20;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
}

.spacebattle-fire-btn {
  min-height: 78px;
  background: #ff045a;
  color: #fff;
  font-size: clamp(28px, 4vw, 52px);
  text-shadow: 2px 2px 0 #000;
}

.spacebattle-small-btn {
  min-height: 58px;
  background: #23d8ff;
  color: #000;
  padding: 0 20px;
  font-size: 18px;
}

.spacebattle-bomb {
  position: absolute;
  z-index: 8;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  font-size: 34px;
  transform: translate(-50%, -50%);
  animation: spacebattle-bomb-fly 0.52s ease-in forwards;
  pointer-events: none;
}

@keyframes spacebattle-bomb-fly {
  from { transform: translate(-50%, -50%) scale(0.75) rotate(0); }
  to { transform: translate(calc(-50% + var(--bomb-x)), calc(-50% + var(--bomb-y))) scale(1.25) rotate(720deg); }
}

.spacebattle-explosion {
  position: absolute;
  z-index: 9;
  width: 120px;
  height: 120px;
  display: grid;
  place-items: center;
  font-size: 96px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: spacebattle-explosion-pop 0.65s ease-out forwards;
}

@keyframes spacebattle-explosion-pop {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  35% { transform: translate(-50%, -50%) scale(1.45); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.9); opacity: 0; }
}

.spacebattle-planet-hit {
  animation: spacebattle-planet-hit 0.55s ease-in forwards !important;
}

@keyframes spacebattle-planet-hit {
  to { transform: translate(-50%, -50%) scale(0.2) rotate(380deg) !important; opacity: 0; }
}

.spacebattle-planet-crash {
  animation: spacebattle-planet-crash 0.55s ease-in forwards !important;
}

@keyframes spacebattle-planet-crash {
  0% { opacity: 1; }
  100% { opacity: 0; filter: brightness(1.8) saturate(1.8); }
}

.spacebattle-red-alert {
  position: absolute;
  z-index: 30;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle, transparent 38%, rgba(255, 0, 0, 0.75) 100%),
    rgba(255, 0, 0, 0.18);
  opacity: 0;
  transition: opacity 0.12s linear;
  mix-blend-mode: screen;
}

.spacebattle-danger .spacebattle-hud-card {
  box-shadow: 0 0 0 3px #ff045a, 4px 4px 0 rgba(0,0,0,0.25);
}

.spacebattle-shoot-shake {
  animation: spacebattle-shoot-shake 0.26s ease-out;
}

.spacebattle-hit-shake {
  animation: spacebattle-hit-shake 0.33s ease-out;
}

.spacebattle-damage-shake {
  animation: spacebattle-damage-shake 0.58s ease-out;
}

@keyframes spacebattle-shoot-shake {
  0%, 100% { transform: translate(0, 0); }
  35% { transform: translate(-4px, 2px); }
  70% { transform: translate(4px, -2px); }
}

@keyframes spacebattle-hit-shake {
  0%, 100% { transform: translate(0, 0) scale(1); }
  30% { transform: translate(5px, 0) scale(1.01); }
  60% { transform: translate(-5px, 0) scale(1.01); }
}

@keyframes spacebattle-damage-shake {
  0%, 100% { transform: translate(0, 0); }
  12% { transform: translate(-13px, 7px); }
  26% { transform: translate(14px, -5px); }
  40% { transform: translate(-10px, 4px); }
  58% { transform: translate(8px, -3px); }
  76% { transform: translate(-4px, 2px); }
}

.spacebattle-finish-screen {
  display: grid;
  place-items: center;
  padding: 22px;
}

.spacebattle-finish-card {
  position: relative;
  z-index: 2;
  width: min(860px, 94%);
  background: rgba(255, 255, 255, 0.96);
  color: #000;
  border: 7px solid #000;
  border-radius: 30px;
  padding: 26px;
  text-align: center;
  box-shadow: 12px 12px 0 rgba(0,0,0,0.35);
}

.spacebattle-finish-icon {
  font-size: clamp(58px, 9vw, 120px);
  animation: spacebattle-finish-bounce 0.8s ease-in-out infinite alternate;
}

@keyframes spacebattle-finish-bounce {
  from { transform: translateY(0) rotate(-4deg); }
  to { transform: translateY(-10px) rotate(4deg); }
}

.spacebattle-finish-card h2 {
  margin: 4px 0 8px;
  font-size: clamp(36px, 6vw, 72px);
}

.spacebattle-finish-card p {
  margin: 0 0 18px;
  font-size: 22px;
  font-weight: 850;
}

.spacebattle-final-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.spacebattle-final-stats div {
  background: #bff1ea;
  border: 4px solid #000;
  border-radius: 16px;
  padding: 12px 8px;
}

.spacebattle-final-stats span {
  display: block;
  font-size: 13px;
  font-weight: 950;
  opacity: 0.65;
  text-transform: uppercase;
}

.spacebattle-final-stats strong {
  display: block;
  font-size: 34px;
  line-height: 1;
}

.spacebattle-finish-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

@media (max-width: 900px) {
  .spacebattle-settings-grid,
  .spacebattle-final-stats {
    grid-template-columns: 1fr 1fr;
  }

  .spacebattle-hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .spacebattle-planet-zone {
    inset: 154px 0 132px;
  }
}

@media (max-width: 640px) {
  .spacebattle-setup-card {
    padding: 16px;
  }

  .spacebattle-setup-title-row,
  .spacebattle-settings-grid,
  .spacebattle-final-stats,
  .spacebattle-finish-actions {
    grid-template-columns: 1fr;
  }

  .spacebattle-big-icon {
    width: 72px;
    height: 72px;
    font-size: 40px;
  }

  .spacebattle-hud-card {
    min-height: 54px;
    padding: 6px 8px;
  }

  .spacebattle-control-dock {
    grid-template-columns: 1fr;
  }

  .spacebattle-small-btn {
    min-height: 46px;
  }
}
