:root {
  color-scheme: dark;
  --void: #090b0f;
  --panel: rgba(18, 22, 27, 0.76);
  --panel-strong: rgba(21, 24, 28, 0.94);
  --steel: #88949c;
  --text: #f7f4e8;
  --muted: #b8c0bd;
  --cyan: #42f2df;
  --amber: #f9b94b;
  --red: #ff5b5f;
  --green: #75f08f;
  --magenta: #eb4dd2;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 52% 45%, rgba(66, 242, 223, 0.12), transparent 28%),
    linear-gradient(145deg, #090b0f 0%, #14100d 46%, #080a0d 100%);
  color: var(--text);
  overflow: hidden;
}

button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid rgba(247, 244, 232, 0.24);
  border-radius: 8px;
  background: rgba(247, 244, 232, 0.08);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  letter-spacing: 0;
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease,
    box-shadow 120ms ease;
}

button:hover,
button:focus-visible {
  border-color: rgba(66, 242, 223, 0.72);
  background: rgba(66, 242, 223, 0.14);
  box-shadow: 0 0 0 3px rgba(66, 242, 223, 0.18);
  outline: none;
}

button:active {
  transform: translateY(1px) scale(0.98);
}

button[aria-disabled="true"] {
  cursor: progress;
  opacity: 0.76;
}

.game-shell {
  display: grid;
  width: 100vw;
  height: 100svh;
  min-height: 100svh;
  padding: 0;
  place-items: center;
}

.stage {
  position: relative;
  width: 100vw;
  height: 100svh;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #050608;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.stage.is-game-over-shake {
  animation: gameOverStageShake 880ms cubic-bezier(0.16, 1, 0.3, 1) both;
  transform-origin: 50% 50%;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  inset:
    max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    auto
    max(14px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  pointer-events: none;
}

.mission-hint {
  position: absolute;
  top: calc(max(14px, env(safe-area-inset-top)) + 78px);
  left: 50%;
  max-width: min(720px, calc(100% - 28px));
  transform: translateX(-50%);
  border: 1px solid rgba(66, 242, 223, 0.3);
  border-radius: 8px;
  background: rgba(8, 10, 12, 0.72);
  box-shadow: 0 0 28px rgba(66, 242, 223, 0.14);
  color: var(--text);
  padding: 8px 12px;
  font-size: 0.86rem;
  font-weight: 850;
  letter-spacing: 0;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 0 12px rgba(66, 242, 223, 0.35);
  transition:
    opacity 160ms ease,
    transform 160ms ease,
    visibility 160ms ease;
}

.mission-hint.is-hidden {
  opacity: 0;
  transform: translate(-50%, -6px);
  visibility: hidden;
}

.hud-group {
  min-width: 0;
  border: 1px solid rgba(247, 244, 232, 0.14);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px 10px;
  backdrop-filter: blur(10px);
}

.hud-group.is-critical {
  border-color: rgba(255, 91, 95, 0.72);
  background: rgba(64, 14, 20, 0.78);
  box-shadow: 0 0 24px rgba(255, 91, 95, 0.22);
  animation: shieldCriticalPulse 820ms ease-in-out infinite alternate;
}

.hud-label {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud strong.is-critical {
  color: var(--red);
  text-shadow: 0 0 14px rgba(255, 91, 95, 0.72);
}

@keyframes shieldCriticalPulse {
  from {
    box-shadow: 0 0 16px rgba(255, 91, 95, 0.18);
  }

  to {
    box-shadow: 0 0 30px rgba(255, 91, 95, 0.36);
  }
}

@keyframes gameOverStageShake {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg) scale(1);
  }

  10% {
    transform: translate3d(-12px, 7px, 0) rotate(-0.45deg) scale(1.012);
  }

  22% {
    transform: translate3d(13px, -9px, 0) rotate(0.52deg) scale(1.014);
  }

  36% {
    transform: translate3d(-10px, -5px, 0) rotate(-0.34deg) scale(1.01);
  }

  52% {
    transform: translate3d(8px, 6px, 0) rotate(0.24deg) scale(1.007);
  }

  68% {
    transform: translate3d(-5px, 3px, 0) rotate(-0.14deg) scale(1.004);
  }

  84% {
    transform: translate3d(2px, -2px, 0) rotate(0.08deg) scale(1.002);
  }

  100% {
    transform: translate3d(0, 0, 0) rotate(0deg) scale(1);
  }
}

.center-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(460px, calc(100% - 28px));
  transform: translate(-50%, -50%);
  border: 1px solid rgba(247, 244, 232, 0.16);
  border-radius: 8px;
  background: rgba(8, 10, 12, 0.78);
  padding: clamp(18px, 4vw, 30px);
  text-align: center;
  backdrop-filter: blur(12px);
  transition:
    opacity 160ms ease,
    transform 160ms ease,
    visibility 160ms ease;
}

.center-panel.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -48%) scale(0.98);
  visibility: hidden;
}

.center-panel h1 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: clamp(2rem, 5vw, 4.1rem);
  letter-spacing: 0;
  line-height: 0.95;
  text-wrap: balance;
}

.center-panel p {
  margin: 0 auto 18px;
  max-width: 34ch;
  color: var(--muted);
  font-weight: 650;
  line-height: 1.45;
}

#launchButton {
  min-width: 148px;
  border-color: rgba(249, 185, 75, 0.54);
  background: linear-gradient(180deg, rgba(249, 185, 75, 0.96), rgba(235, 77, 210, 0.72));
  color: #100907;
  box-shadow: 0 16px 36px rgba(249, 185, 75, 0.18);
}

.command-row {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
}

.touch-controls {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: max(14px, env(safe-area-inset-left));
  display: none;
  align-items: end;
  gap: 12px;
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(2, 44px);
  gap: 6px;
}

.touch-pad [data-control="up"] {
  grid-column: 2;
}

.touch-pad [data-control="left"] {
  grid-column: 1;
  grid-row: 2;
}

.touch-pad [data-control="down"] {
  grid-column: 2;
  grid-row: 2;
}

.touch-pad [data-control="right"] {
  grid-column: 3;
  grid-row: 2;
}

.touch-button {
  display: grid;
  padding: 0;
  place-items: center;
}

.fire-button {
  width: 62px;
  height: 62px;
  border-color: rgba(255, 91, 95, 0.46);
  background: rgba(255, 91, 95, 0.16);
  color: var(--red);
  font-size: 1.55rem;
}

@media (hover: none), (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
}

@media (max-width: 720px) {
  .game-shell {
    align-items: stretch;
    padding: 0;
  }

  .stage {
    width: 100%;
    height: 100svh;
  }

  .hud {
    inset:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      auto
      max(8px, env(safe-area-inset-left));
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mission-hint {
    top: calc(max(8px, env(safe-area-inset-top)) + 142px);
    max-width: calc(100% - 16px);
    font-size: 0.78rem;
  }

  .hud-group {
    padding: 6px 8px;
  }

  .center-panel {
    padding: 16px;
  }

  .command-row {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
