/* Space Invaders: ship selection, showcase motion and staged launch. */
body.is-playing .hangar,
body.is-playing .ship-roster,
body.is-playing .launch-button {
  display: none;
}

body.is-selecting #game-canvas,
body.is-selecting .hud {
  visibility: hidden;
}

body.is-selecting .playfield-wrap {
  position: relative;
  pointer-events: none;
}

body.is-selecting .game-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border: 0;
  aspect-ratio: auto;
  background: var(--screen);
  box-shadow: none;
  clip-path: none;
}

body.is-selecting .cabinet-status {
  visibility: hidden;
}

.hangar {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  height: 100%;
  border: 0;
  padding: clamp(16px, 3vh, 28px) clamp(16px, 4vw, 48px) 28px;
  background: #050a19;
  box-shadow: inset 0 3px 0 var(--cyan), inset 0 -3px 0 #173d5c;
  pointer-events: auto;
}

.hangar-heading {
  display: grid;
  place-content: center;
  gap: 8px;
  min-width: 0;
  text-align: center;
}

.hangar h2 {
  margin: 0;
  color: #b0c6dc;
  font-size: clamp(8px, 1vw, 11px);
  line-height: 1.4;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.selected-ship-name {
  color: var(--selected-ship-color, var(--cyan));
  font: clamp(17px, 2.5vw, 28px)/1.4 var(--pixel-font);
  text-align: center;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #030713;
}

.ship-picker {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr) 68px;
  align-items: center;
  gap: clamp(10px, 1.6vw, 20px);
  width: min(100%, 700px);
  min-width: 0;
  min-height: 0;
  margin-inline: auto;
}

.ship-cycle {
  width: 58px;
  height: 58px;
  border: 0;
  color: var(--cyan);
  background: #07152c;
  box-shadow:
    inset 4px 4px 0 #1c4d70,
    inset -4px -4px 0 #01040d,
    5px 5px 0 #01040d;
  font: 18px/1 var(--pixel-font);
  cursor: pointer;
}

.ship-cycle:focus-visible {
  outline: 0;
  color: #160711;
  background: var(--gold);
  box-shadow:
    inset 4px 4px 0 #fff0a8,
    inset -4px -4px 0 #b65d2e,
    5px 5px 0 #6b2440;
  transform: translate(-2px, -2px);
}

@media (hover: hover) and (pointer: fine) {
  .ship-cycle:hover {
    outline: 0;
    color: #160711;
    background: var(--gold);
    box-shadow:
      inset 4px 4px 0 #fff0a8,
      inset -4px -4px 0 #b65d2e,
      5px 5px 0 #6b2440;
    transform: translate(-2px, -2px);
  }
}

.ship-cycle:active {
  color: var(--cyan);
  background: #07152c;
  box-shadow: inset 3px 3px 0 #01040d, 2px 2px 0 #01040d;
  transform: translate(5px, 5px);
}

.ship-cycle:disabled {
  opacity: 0.45;
  cursor: default;
}

.ship-roster {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  touch-action: pan-y;
}

.ship-skin-option {
  display: none;
}

.ship-skin-option[aria-checked='true'] {
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
  cursor: grab;
}

.ship-skin-option[aria-checked='true']:focus-visible {
  outline: 0;
  box-shadow: none;
}

.ship-skin-option[aria-checked='true']:focus-visible .ship-preview {
  filter: brightness(1.16) drop-shadow(0 0 6px rgba(113, 245, 255, 0.72));
}

.ship-roster.is-swipe-tracking .ship-skin-option[aria-checked='true'] {
  transform: translateX(var(--ship-swipe-x, 0));
}

.ship-roster.is-sliding-left .ship-skin-option[aria-checked='true'] {
  animation: ship-card-out-left 150ms steps(6, end) both;
}

.ship-roster.is-sliding-right .ship-skin-option[aria-checked='true'] {
  animation: ship-card-out-right 150ms steps(6, end) both;
}

.ship-roster.is-entering-right .ship-skin-option[aria-checked='true'] {
  animation: ship-card-in-right 180ms steps(7, end) both;
}

.ship-roster.is-entering-left .ship-skin-option[aria-checked='true'] {
  animation: ship-card-in-left 180ms steps(7, end) both;
}

.ship-demo {
  --demo-travel: clamp(32px, 8vw, 88px);
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: repeating-linear-gradient(0deg, transparent 0 39px, #102034 39px 40px);
  border-bottom: 2px solid var(--ship-color);
  overflow: hidden;
  image-rendering: pixelated;
}

.ship-demo-runner {
  position: absolute;
  bottom: 12%;
  left: 50%;
  width: 92px;
  height: 0;
  transform: translateX(-50%);
  animation: ship-demo-strafe var(--demo-travel-duration) steps(14, end) infinite alternate;
}

.ship-demo .ship-preview {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: var(--demo-ship-width, 112px);
  max-width: none;
  height: auto;
  filter: drop-shadow(0 0 6px var(--ship-color, var(--cyan)));
  image-rendering: pixelated;
  transform: translateX(-50%);
}

.ship-demo-shot {
  position: absolute;
  bottom: var(--demo-shot-bottom, 73px);
  left: 50%;
  width: 4px;
  height: 14px;
  background: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 211, 106, 0.18);
  opacity: 0;
  animation: var(--demo-shot-animation) var(--demo-shot-duration) var(--shot-delay) linear infinite;
}

.ship-demo[data-demo-pattern='auto'] .ship-demo-shot {
  width: 3px;
  height: 8px;
  background: #ff9a47;
}

.ship-demo[data-demo-pattern='rail'] .ship-demo-shot {
  width: 3px;
  height: 28px;
  background: #e6c5ff;
  box-shadow: 0 0 0 2px rgba(200, 144, 255, 0.2), 0 -10px 0 rgba(200, 144, 255, 0.35);
}

.ship-demo[data-demo-pattern='piercing'] .ship-demo-shot {
  width: 5px;
  height: 18px;
  background: #d4ff4d;
  box-shadow: 0 0 0 2px rgba(212, 255, 77, 0.2);
}

.ship-demo[data-demo-pattern='heavy'] .ship-demo-shot {
  width: 12px;
  height: 12px;
  background: #d7f3ff;
  box-shadow: 0 0 0 4px #6bc8ff, 0 0 0 6px rgba(107, 200, 255, 0.18);
}

.ship-demo[data-demo-pattern='twin'] .ship-demo-shot {
  background: #ff8da2;
}

.launch-button {
  position: relative;
  z-index: 12;
  display: grid;
  place-items: center;
  width: clamp(210px, 26vw, 320px);
  min-width: 0;
  min-height: 58px;
  border: 4px solid #020510;
  padding: clamp(14px, 1.8vw, 20px) clamp(24px, 3.2vw, 42px);
  color: #03101b;
  background: var(--cyan);
  box-shadow:
    inset 6px 6px 0 #d8fbff,
    inset -6px -6px 0 #238196,
    8px 8px 0 #071727,
    12px 12px 0 #092d49,
    0 0 0 4px rgba(113, 245, 255, 0.16),
    0 0 18px rgba(113, 245, 255, 0.32);
  clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 8px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 8px 100%, 0 calc(100% - 8px), 0 8px);
  font: clamp(12px, 2vw, 22px)/1.35 var(--pixel-font);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  animation: attract-button-idle 1800ms steps(1, end) infinite;
}

.launch-button:focus-visible {
  outline: 0;
  color: #160711;
  background: var(--gold);
  box-shadow:
    inset 6px 6px 0 #fff0a8,
    inset -6px -6px 0 #b65d2e,
    8px 8px 0 #071727,
    12px 12px 0 #6b2440,
    0 0 24px rgba(255, 90, 79, 0.48);
  transform: translate(-3px, -3px);
  animation: none;
}

@media (hover: hover) and (pointer: fine) {
  .launch-button:hover {
    outline: 0;
    color: #160711;
    background: var(--gold);
    box-shadow:
      inset 6px 6px 0 #fff0a8,
      inset -6px -6px 0 #b65d2e,
      8px 8px 0 #071727,
      12px 12px 0 #6b2440,
      0 0 24px rgba(255, 90, 79, 0.48);
    transform: translate(-3px, -3px);
    animation: none;
  }
}

.launch-button:active {
  color: #03101b;
  background: #d8fbff;
  box-shadow: inset 6px 6px 0 #238196, inset -3px -3px 0 #fff, 4px 4px 0 #071727;
  transform: translate(8px, 8px);
  animation: none;
}

.launch-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.ship-roster.is-launch-locked,
.ship-roster.is-launch-locked .ship-skin-option {
  pointer-events: none;
}

body.is-launching .hangar-heading,
body.is-launching .ship-choices,
body.is-launching .ship-cycle,
body.is-launching .launch-button,
body.is-launching .ship-demo-shot {
  opacity: 0;
  pointer-events: none;
}

body.is-launching .ship-demo-shot {
  visibility: hidden;
}

body.is-launching .ship-demo-runner {
  /* The simulation sequence seeks these authored frames; CSS owns no launch clock. */
  animation: selected-ship-depart 1s steps(12, end) both;
  animation-delay: calc(var(--launch-departure-progress, 0) * -1s);
  animation-play-state: paused;
}

.launch-sequence {
  position: absolute;
  inset: 0;
  z-index: 15;
  overflow: hidden;
  background: transparent;
  pointer-events: none;
}

.launch-sequence-level {
  position: absolute;
  top: 42%;
  left: 50%;
  z-index: 2;
  color: var(--gold);
  font-size: clamp(18px, 4vw, 42px);
  text-transform: uppercase;
  text-shadow: 4px 4px 0 #7b2f45;
  opacity: 0;
  transform: translate(-50%, -50%);
}

.launch-sequence.is-level-visible .launch-sequence-level {
  opacity: 1;
  animation: level-card-arrive 180ms steps(4, end);
}

@keyframes ship-demo-strafe {
  from { transform: translateX(calc(-50% - var(--demo-travel))); }
  to { transform: translateX(calc(-50% + var(--demo-travel))); }
}

@keyframes selected-ship-depart {
  from { transform: translateX(-50%); }
  to { transform: translate(-50%, -360px); }
}

@keyframes level-card-arrive {
  from { transform: translate(-50%, -50%) scale(0.6); }
  to { transform: translate(-50%, -50%) scale(1); }
}

@keyframes ship-card-out-left { to { opacity: 0; transform: translateX(-112%); } }
@keyframes ship-card-out-right { to { opacity: 0; transform: translateX(112%); } }
@keyframes ship-card-in-right { from { opacity: 0; transform: translateX(112%); } to { opacity: 1; transform: translateX(0); } }
@keyframes ship-card-in-left { from { opacity: 0; transform: translateX(-112%); } to { opacity: 1; transform: translateX(0); } }
