:root {
  color-scheme: dark;
  --bg: #05070d;
  --panel: #0b1020;
  --panel-strong: #10182b;
  --line: rgba(119, 201, 255, 0.22);
  --text: #f5fbff;
  --muted: #9fb4c8;
  --player: #47d7ff;
  --accent: #ffd166;
  --danger: #ff5d73;
  --shadow: rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(32, 72, 125, 0.28), transparent 34rem),
    linear-gradient(180deg, #060915 0%, var(--bg) 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: 100vw;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: minmax(0, auto) auto;
  align-content: center;
  justify-items: center;
  gap: 8px;
}

.game-card {
  width: min(100%, 1120px);
  height: min(100dvh - 56px, 720px);
  min-height: 360px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(14, 23, 43, 0.94), rgba(6, 9, 17, 0.98));
  box-shadow: 0 24px 60px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  touch-action: none;
}

.site-attribution {
  max-width: min(100%, 1120px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 8px;
  color: rgba(245, 251, 255, 0.72);
  font-size: clamp(0.68rem, 1.6vw, 0.78rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.35;
  text-align: center;
}

.hud {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.hud-group,
.hud-pill,
.icon-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(9, 14, 26, 0.72);
  color: var(--text);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

.hud-group {
  padding: 0 12px;
  gap: 8px;
}

.lives-icon {
  color: var(--danger);
  font-size: 1.05rem;
  line-height: 1;
  filter: drop-shadow(0 0 7px rgba(255, 93, 115, 0.42));
}

.lives-count {
  min-width: 2ch;
  color: var(--text);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-align: center;
}

.hud-pill {
  min-width: 58px;
  padding: 0 14px;
  gap: 8px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.hud-pill:first-of-type span:first-child {
  color: var(--accent);
}

.mode-button {
  min-width: 58px;
  cursor: pointer;
  pointer-events: auto;
}

.mode-button span {
  color: var(--player);
  font-size: 1.45rem;
  line-height: 1;
  text-shadow: 0 0 12px rgba(71, 215, 255, 0.8);
}

.tier-pill,
.level-pill,
.stage-pill,
.weapon-progress-pill,
.top-pill {
  min-width: 56px;
  color: var(--accent);
}

.level-pill {
  min-width: 92px;
  color: var(--player);
}

.stage-pill,
.weapon-progress-pill {
  min-width: 116px;
  color: var(--text);
  font-size: 0.84rem;
}

.stage-pill {
  border-color: rgba(71, 215, 255, 0.2);
}

.weapon-progress-pill {
  border-color: rgba(255, 209, 102, 0.2);
  color: var(--accent);
}

.stage-pill span,
.weapon-progress-pill span,
.level-pill span:last-child {
  max-width: 112px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-pill span:first-child {
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
}

.level-pill span:last-child {
  max-width: 76px;
}

.top-pill {
  max-width: 180px;
}

.top-pill span:last-child {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tier-pill span:first-child {
  font-size: 0.9rem;
  filter: drop-shadow(0 0 8px rgba(255, 209, 102, 0.58));
}

.tier-pill span:last-child {
  min-width: 1ch;
}

.icon-button {
  width: 44px;
  padding: 0;
  cursor: pointer;
  pointer-events: auto;
}

#muteButton {
  margin-left: auto;
}

#pauseButton[disabled],
#fullscreenButton[disabled],
#helpButton[disabled] {
  opacity: 0.52;
  cursor: not-allowed;
}

.icon-button:hover,
.icon-button:focus-visible,
.mode-button:hover,
.mode-button:focus-visible,
.overlay-restart:hover,
.overlay-restart:focus-visible,
.pause-resume:hover,
.pause-resume:focus-visible,
.help-close:hover,
.help-close:focus-visible,
.name-submit:hover,
.name-submit:focus-visible,
.touch-button:hover,
.touch-button:focus-visible,
.difficulty-option:hover,
.difficulty-option:focus-visible,
.start-button:hover,
.start-button:focus-visible,
.start-help-button:hover,
.start-help-button:focus-visible {
  outline: none;
  border-color: rgba(71, 215, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(71, 215, 255, 0.14), 0 10px 24px rgba(0, 0, 0, 0.18);
}

button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.start-overlay,
.pause-overlay,
.game-over,
.help-overlay {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 6, 13, 0.54);
  backdrop-filter: blur(6px);
}

.start-overlay {
  z-index: 4;
  background:
    radial-gradient(circle at 50% 30%, rgba(71, 215, 255, 0.12), transparent 22rem),
    rgba(3, 6, 13, 0.72);
}

.start-overlay.is-hidden,
.pause-overlay.is-hidden,
.game-over.is-hidden,
.help-overlay.is-hidden {
  display: none;
}

.pause-overlay {
  background: rgba(3, 6, 13, 0.36);
  backdrop-filter: blur(4px);
}

.help-overlay {
  z-index: 6;
  background: rgba(3, 6, 13, 0.62);
}

.start-overlay:not(.is-hidden) .start-card,
.pause-overlay:not(.is-hidden) .pause-card,
.game-over:not(.is-hidden) .game-over-card,
.help-overlay:not(.is-hidden) .help-card {
  animation: overlay-in 180ms ease-out both;
}

.start-card,
.pause-card {
  width: min(320px, 86vw);
  padding: 24px;
  display: grid;
  justify-items: center;
  gap: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(16, 24, 43, 0.92), rgba(8, 12, 22, 0.96));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

.start-card {
  width: min(520px, 92vw);
  justify-items: stretch;
  gap: 16px;
}

.start-header {
  min-height: 44px;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
}

.start-help-button {
  width: 44px;
  height: 44px;
  display: inline-grid;
  grid-column: 3;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(9, 14, 26, 0.72);
  color: var(--text);
  cursor: pointer;
  font-weight: 950;
}

.start-kicker,
.start-title,
.start-hint {
  margin: 0;
  text-align: center;
}

.start-kicker {
  grid-column: 2;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.start-title {
  color: var(--text);
  font-size: clamp(1.35rem, 5vw, 2.25rem);
  font-weight: 950;
  letter-spacing: 0.04em;
}

.start-hint {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.difficulty-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.difficulty-option {
  min-height: 86px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  background: rgba(4, 8, 17, 0.72);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}

.difficulty-option::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.34);
  border-radius: 999px;
}

.difficulty-option.is-selected {
  border-color: rgba(255, 209, 102, 0.92);
  background: rgba(255, 209, 102, 0.12);
  box-shadow: inset 0 0 0 2px rgba(255, 209, 102, 0.16), 0 0 24px rgba(255, 209, 102, 0.12);
}

.difficulty-option.is-selected::before {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(255, 209, 102, 0.68);
}

.difficulty-label {
  font-size: 1rem;
  font-weight: 950;
  letter-spacing: 0.04em;
}

.difficulty-description {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.start-how-to,
.pause-how-to {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
}

.start-how-to {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
}

.start-how-to p,
.pause-how-to h2 {
  margin: 0;
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 950;
  letter-spacing: 0.04em;
}

.start-how-to ul,
.pause-how-to ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.start-how-to li,
.pause-how-to li {
  color: rgba(245, 251, 255, 0.86);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.32;
}

.pause-how-to {
  display: grid;
  gap: 8px;
  padding: 12px;
  text-align: left;
}

.pause-how-to h2 {
  text-align: center;
}

.start-button {
  min-height: 52px;
  border: 1px solid rgba(71, 215, 255, 0.52);
  border-radius: 999px;
  background: rgba(71, 215, 255, 0.16);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  touch-action: manipulation;
}

.pause-icon {
  color: var(--player);
  font-size: 2rem;
  line-height: 1;
  filter: drop-shadow(0 0 14px rgba(71, 215, 255, 0.54));
}

.pause-title {
  margin: 0;
  color: var(--text);
  font-size: clamp(1.1rem, 4vw, 1.45rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}

.pause-resume {
  width: 56px;
  height: 56px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(71, 215, 255, 0.12);
  color: var(--text);
  cursor: pointer;
  font-size: 1.25rem;
}

.help-card {
  width: min(430px, 92vw);
  max-height: min(88dvh, 640px);
  position: relative;
  overflow: auto;
  padding: 28px;
  display: grid;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(16, 24, 43, 0.96), rgba(8, 12, 22, 0.98));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.help-close {
  width: 40px;
  height: 40px;
  position: absolute;
  top: 14px;
  right: 14px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(9, 14, 26, 0.72);
  color: var(--text);
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
}

.help-kicker,
.help-title,
.help-summary {
  margin: 0;
  text-align: center;
}

.help-kicker {
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 950;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.help-title {
  padding: 0 34px;
  color: var(--text);
  font-size: clamp(1.3rem, 5vw, 2rem);
  font-weight: 950;
  letter-spacing: 0.04em;
}

.help-summary {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.help-list {
  display: grid;
  gap: 8px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.help-list li {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.045);
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.35;
}

.help-list strong {
  color: var(--accent);
}

.game-over-card {
  width: min(380px, 90vw);
  max-height: min(92dvh, 680px);
  overflow: auto;
  padding: 28px;
  display: grid;
  justify-items: stretch;
  gap: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(16, 24, 43, 0.96), rgba(8, 12, 22, 0.98));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.game-over-icon {
  color: var(--danger);
  font-size: 2.3rem;
  line-height: 1;
  filter: drop-shadow(0 0 14px rgba(255, 93, 115, 0.54));
}

.game-over-title,
.game-over-score {
  margin: 0;
  color: var(--text);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-align: center;
}

.game-over-title {
  font-size: clamp(1.25rem, 4vw, 2rem);
}

.game-over-score {
  color: var(--accent);
  font-size: 1.15rem;
}

.celebration-message {
  margin: 0;
  border: 1px solid rgba(255, 209, 102, 0.32);
  border-radius: 16px;
  background: rgba(255, 209, 102, 0.1);
  color: var(--accent);
  padding: 10px 12px;
  font-size: 0.94rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-align: center;
  box-shadow: 0 0 24px rgba(255, 209, 102, 0.1);
}

.celebration-message.is-hidden {
  display: none;
}

.name-entry,
.leaderboard {
  width: 100%;
  display: grid;
  gap: 10px;
}

.name-entry.is-hidden {
  display: none;
}

.name-label,
.leaderboard-title {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.name-row {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 8px;
}

.name-row input {
  min-width: 0;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: rgba(4, 8, 17, 0.78);
  color: var(--text);
  padding: 0 14px;
  outline: none;
}

.name-row input:focus,
.name-row input:focus-visible {
  border-color: rgba(71, 215, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(71, 215, 255, 0.14);
}

.name-submit {
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: rgba(71, 215, 255, 0.14);
  color: var(--text);
  cursor: pointer;
  font-weight: 900;
}

.name-message {
  min-height: 1.1rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.name-message.is-error {
  color: var(--danger);
}

.leaderboard ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard li {
  min-height: 38px;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.045);
  padding: 0 12px;
  color: var(--text);
  font-weight: 800;
}

.leaderboard-rank {
  color: var(--accent);
}

.leaderboard-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  color: var(--accent);
}

.leaderboard-source {
  color: rgba(245, 251, 255, 0.66);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: none;
}

.touch-controls {
  position: absolute;
  z-index: 2;
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: none;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.touch-stick {
  width: 112px;
  height: 112px;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  background: rgba(9, 14, 26, 0.45);
  box-shadow: inset 0 0 30px rgba(71, 215, 255, 0.08);
  pointer-events: auto;
  touch-action: none;
}

.touch-stick span {
  width: 46px;
  height: 46px;
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 999px;
  background: rgba(71, 215, 255, 0.78);
  box-shadow: 0 0 18px rgba(71, 215, 255, 0.45);
  transform: translate(-50%, -50%);
}

.touch-actions {
  display: grid;
  grid-template-columns: 58px 72px;
  gap: 12px;
  align-items: end;
  pointer-events: auto;
}

.touch-button {
  min-width: 58px;
  min-height: 58px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(9, 14, 26, 0.68);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  backdrop-filter: blur(12px);
  touch-action: manipulation;
}

.shoot-button {
  min-width: 72px;
  min-height: 72px;
  color: var(--accent);
  font-size: 1.7rem;
  box-shadow: 0 0 24px rgba(255, 209, 102, 0.16);
}

.overlay-restart {
  width: 56px;
  height: 56px;
  display: inline-grid;
  place-items: center;
  justify-self: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(71, 215, 255, 0.12);
  color: var(--text);
  cursor: pointer;
  font-size: 1.35rem;
}

.game-card:fullscreen,
.game-card.is-fullscreen {
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
  border-radius: 0;
}

.game-card:fullscreen .hud,
.game-card.is-fullscreen .hud {
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
}

@keyframes overlay-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 760px), (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .game-card {
    height: calc(100dvh - 48px);
    border-radius: 18px;
  }

  .site-attribution {
    max-width: 96vw;
    font-size: 0.68rem;
    gap: 3px 6px;
  }

  .hud {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .hud-group {
    max-width: 42vw;
    overflow: hidden;
    padding: 0 10px;
    gap: 6px;
  }

  .hud-pill {
    min-width: 48px;
    padding: 0 10px;
  }

  .level-pill {
    min-width: 78px;
  }

  .stage-pill,
  .weapon-progress-pill {
    min-width: 74px;
    font-size: 0.76rem;
  }

  .stage-pill span,
  .weapon-progress-pill span {
    max-width: 78px;
  }

  .level-pill span:first-child {
    font-size: 0.7rem;
  }

  .level-pill span:last-child {
    max-width: 58px;
  }

  .top-pill {
    max-width: 128px;
  }

  .help-card {
    width: min(430px, 94vw);
    padding: 24px 18px 18px;
  }

  .help-list li {
    padding: 9px 10px;
    font-size: 0.84rem;
  }

  .start-how-to,
  .pause-how-to {
    padding: 10px;
  }

  .start-how-to li,
  .pause-how-to li {
    font-size: 0.78rem;
  }

  .difficulty-options {
    grid-template-columns: 1fr;
  }

  .difficulty-option {
    min-height: 64px;
    grid-template-columns: auto 1fr auto;
    align-content: center;
    justify-items: start;
    text-align: left;
    padding: 0 14px;
  }

  .difficulty-description {
    justify-self: end;
  }

  .touch-stick {
    width: 96px;
    height: 96px;
  }

  .touch-actions {
    grid-template-columns: 54px 66px;
  }

  .touch-button {
    min-width: 54px;
    min-height: 54px;
  }

  .shoot-button {
    min-width: 66px;
    min-height: 66px;
  }
}

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