*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: var(--color-page-background, #06101c);
  color: var(--color-text, #e8eef8);
  font-family: var(--font-family, "VT323", monospace);
}

body {
  min-height: 100%;
}

.loading {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4vw;
  font-size: clamp(1rem, 2.4vw, 1.5rem);
  letter-spacing: 0.04em;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1vh 1vw;
}

.app[hidden],
[hidden] {
  display: none !important;
}

.stage {
  position: relative;
  container-type: size;
  --caption-band: 8.2%;
  width: min(100vw, calc(var(--stage-max-vh, 82vh) * var(--aspect-width, 16) / var(--aspect-height, 9)));
  max-width: 100%;
  aspect-ratio: var(--aspect-width, 16) / var(--aspect-height, 9);
  max-height: var(--stage-max-vh, 82vh);
  background: var(--color-sky-top, #06101c);
  overflow: hidden;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#background-canvas {
  z-index: 0;
}

.cannon-bubbles {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

#game-canvas {
  z-index: 2;
}

.cannon-labels {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

#hud-canvas {
  z-index: 4;
  pointer-events: none;
}

.stage-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--caption-band);
  padding: 0.7% 8%;
  background: linear-gradient(180deg, rgba(2, 8, 16, 0) 0%, rgba(2, 8, 16, 0.72) 48%, rgba(2, 8, 16, 0.88) 100%);
  pointer-events: none;
}

.stage-caption__text {
  margin: 0;
  max-width: 86%;
  font-family: var(--font-family, "VT323", monospace);
  font-size: clamp(16px, 3.4cqh, 30px);
  letter-spacing: 0.06em;
  line-height: 1.15;
  text-align: center;
  color: #f4f7fb;
  text-shadow: 0 0 0.35em rgba(0, 0, 0, 0.55);
  opacity: 0;
}

.hud-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 8.4%;
  padding: 0 1.7%;
  border-bottom: 1px solid rgba(232, 238, 248, 0.38);
  pointer-events: none;
}

.hud-level,
.hud-score {
  font-family: var(--font-family, "VT323", monospace);
  font-size: clamp(15px, 3.15cqh, 30px);
  letter-spacing: 0.08em;
  line-height: 1;
  color: #f4f7fb;
  text-shadow: 0 0 0.35em rgba(0, 0, 0, 0.55);
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 0.7em;
}

.stage-menu {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: auto;
}

.menu-button {
  display: grid;
  place-items: center;
  width: 3.35cqh;
  height: 3.35cqh;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 999px;
  color: #f7fbff;
  font: inherit;
  font-size: 1.35em;
  line-height: 1;
  cursor: pointer;
}

.menu-button[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.28);
}

.menu-button:focus-visible {
  outline: 0.15em solid var(--color-focus, #7ee0ff);
  outline-offset: 0.15em;
}

.menu-panel {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem;
  border-radius: 1.15rem;
}

.glass {
  color: #f7fbff;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.42);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 -10px 18px rgba(255, 255, 255, 0.06),
    0 10px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px) saturate(1.55);
  -webkit-backdrop-filter: blur(18px) saturate(1.55);
}

.glass--circle {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.glass--pill {
  border-radius: 999px;
}

.cannon-label {
  position: absolute;
  transform: translate(-50%, 0);
  padding: 0.45cqh 1.15cqh;
  font-family: system-ui, sans-serif;
  font-size: clamp(10px, 1.55cqh, 18px);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.15;
  white-space: nowrap;
  color: #f7fbff;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass {
    background: rgba(52, 72, 64, 0.82);
    border-color: rgba(255, 255, 255, 0.28);
  }
}

.player-action,
.menu-button,
.control-button {
  appearance: none;
  -webkit-appearance: none;
}

.player-action {
  position: absolute;
  top: 50%;
  right: 2%;
  z-index: 5;
  transform: translateY(-50%);
  min-width: 44px;
  min-height: 44px;
  padding: 0.7em 1.1em;
  border-radius: 999px;
  color: #f7fbff;
  font: inherit;
  cursor: pointer;
}

.player-action:focus-visible,
.control-button:focus-visible {
  outline: 0.15em solid var(--color-focus, #7ee0ff);
  outline-offset: 0.15em;
}

.control-group {
  display: flex;
  gap: 0.4rem;
}

.control-button {
  min-width: 44px;
  min-height: 44px;
  padding: 0.55em 1em;
  border-radius: 999px;
  color: #f7fbff;
  font: inherit;
  cursor: pointer;
}

.control-button.is-active {
  background: rgba(255, 255, 255, 0.28);
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
  }
}
