:root {
  --bg: #02040b;
  --panel: rgba(5, 9, 19, 0.72);
  --line: rgba(125, 249, 255, 0.18);
  --text: #eef4ff;
  --muted: #8ea3c8;
  --laser: #7df9ff;
  --ember: #ff8c3a;
  --danger: #ff5370;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 0%, rgba(125, 249, 255, 0.11), transparent 30%),
    linear-gradient(180deg, #050817 0%, var(--bg) 100%);
}

button,
a {
  font: inherit;
}

.galaga-shell {
  width: 100vw;
  height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 5px;
  padding: 5px;
}

.galaga-hud {
  min-height: 50px;
  display: grid;
  grid-template-columns: auto repeat(4, minmax(74px, 1fr)) auto;
  align-items: stretch;
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(5, 9, 20, 0.86), rgba(3, 5, 12, 0.62));
}

.hud-back,
.hud-button,
.control-button {
  min-width: 0;
  border: 1px solid rgba(125, 249, 255, 0.18);
  color: var(--text);
  background: rgba(8, 15, 31, 0.92);
  cursor: pointer;
  text-decoration: none;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.hud-back {
  width: 46px;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  color: var(--laser);
}

.hud-button {
  min-height: 40px;
  padding: 0 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hud-button.primary {
  color: #130800;
  border-color: transparent;
  background: linear-gradient(135deg, #ffb463, var(--ember));
}

.hud-back:hover,
.hud-button:hover,
.control-button:hover {
  transform: translateY(-1px);
  border-color: rgba(125, 249, 255, 0.38);
}

.hud-back:focus-visible,
.hud-button:focus-visible,
.control-button:focus-visible {
  outline: 2px solid rgba(125, 249, 255, 0.78);
  outline-offset: 2px;
}

.hud-stat {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 1px;
  padding: 5px 9px;
  border-left: 1px solid rgba(125, 249, 255, 0.11);
  background: rgba(255, 255, 255, 0.02);
}

.hud-stat span,
.overlay-kicker {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.hud-stat strong {
  min-width: 0;
  overflow: hidden;
  color: var(--laser);
  font-size: clamp(1.05rem, 2.6vw, 1.7rem);
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-actions {
  display: flex;
  gap: 6px;
}

.playfield {
  min-height: 0;
  display: grid;
  place-items: center;
}

.screen-frame {
  position: relative;
  width: min(100%, calc((100svh - 132px) * 0.75));
  max-width: min(100%, 820px);
  height: min(calc(100svh - 132px), calc(100vw * 1.333333));
  max-height: calc(100svh - 132px);
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(125, 249, 255, 0.22);
  background: #01030a;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.035),
    0 26px 90px rgba(0, 0, 0, 0.58);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #030611;
  image-rendering: auto;
  touch-action: none;
}

.screen-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: linear-gradient(180deg, rgba(2, 4, 11, 0.18), rgba(2, 4, 11, 0.82));
  transition: opacity 160ms ease, visibility 160ms ease;
}

.screen-overlay.hidden {
  opacity: 0;
  visibility: hidden;
}

.screen-overlay h2 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 4.2rem);
  line-height: 0.92;
}

.screen-overlay p {
  max-width: 420px;
  margin: 0;
  color: #d7e4ff;
}

.status-line {
  min-height: 22px;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 0 10px;
  color: #c9d7f4;
  text-align: center;
}

.status-line h2,
.status-line p {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
}

.status-line h2 {
  color: var(--laser);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.mobile-controls {
  display: none;
  grid-template-columns: 1fr 1.1fr 1fr;
  gap: 6px;
  min-height: 52px;
}

.control-button {
  min-height: 52px;
  padding: 0 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.control-button-fire {
  color: #150400;
  border-color: transparent;
  background: linear-gradient(135deg, var(--danger), var(--ember));
}

@media (pointer: coarse), (max-width: 760px) {
  .galaga-shell {
    gap: 6px;
    padding: 6px;
  }

  .galaga-hud {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-height: 54px;
    padding: 5px;
  }

  .hud-back {
    display: none;
  }

  .hud-actions {
    grid-column: 1 / -1;
  }

  .hud-button {
    flex: 1 1 0;
    min-height: 38px;
    padding: 0 8px;
    font-size: 0.76rem;
  }

  .hud-stat {
    padding: 5px 6px;
  }

  .hud-stat span {
    font-size: 0.56rem;
    letter-spacing: 0.1em;
  }

  .hud-stat strong {
    font-size: 0.98rem;
  }

  .screen-frame {
    width: min(100%, calc((100svh - 168px) * 0.75));
    height: min(calc(100svh - 168px), calc(100vw * 1.333333));
    max-height: calc(100svh - 168px);
  }

  .status-line {
    min-height: 22px;
  }

  .status-line p {
    display: none;
  }

  .mobile-controls {
    display: grid;
  }
}

@media (max-height: 620px) {
  .galaga-shell {
    gap: 5px;
    padding: 5px;
  }

  .galaga-hud {
    min-height: 46px;
  }

  .hud-button {
    min-height: 34px;
  }

  .screen-frame {
    width: min(100%, calc((100svh - 102px) * 0.75));
    height: min(calc(100svh - 102px), calc(100vw * 1.333333));
    max-height: calc(100svh - 102px);
  }

  .status-line {
    display: none;
  }

  .mobile-controls {
    min-height: 42px;
  }

  .control-button {
    min-height: 42px;
  }
}

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