:root {
  color-scheme: light;
  --ink: #11202f;
  --muted: #506174;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-strong: rgba(255, 255, 255, 0.94);
  --border: rgba(25, 54, 82, 0.18);
  --yellow: #ffce3a;
  --green: #19a974;
  --red: #ea4d3d;
  --blue: #2072d8;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  background: #97d6ff;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(146, 214, 255, 0.92) 0%, rgba(221, 244, 255, 0.9) 54%, rgba(132, 203, 122, 0.94) 100%);
}

.topbar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: min(1180px, calc(100vw - 28px));
  margin: 14px auto 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(40, 77, 107, 0.14);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 42px);
  line-height: 1;
  letter-spacing: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(72px, 1fr));
  gap: 8px;
  min-width: min(780px, 64vw);
}

.stat {
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid rgba(17, 32, 47, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: clamp(18px, 2.4vw, 26px);
  line-height: 1.05;
  white-space: nowrap;
}

.stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: block;
  overflow: hidden;
  cursor: pointer;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.power-panel {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  width: min(520px, calc(100vw - 160px));
  min-width: 180px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 14px 34px rgba(20, 45, 68, 0.18);
}

.meter {
  position: relative;
  flex: 1;
  height: 18px;
  border-radius: 999px;
  background: rgba(17, 32, 47, 0.12);
  overflow: hidden;
}

.meter-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--yellow) 56%, var(--green));
  transition: width 80ms linear;
}

.safe-line {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: 72%;
  width: 3px;
  border-radius: 999px;
  background: rgba(17, 32, 47, 0.55);
}

#hintText {
  width: 108px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.launch-button,
.reset-button {
  position: absolute;
  z-index: 5;
  bottom: calc(22px + env(safe-area-inset-bottom));
  height: 50px;
  border: 0;
  border-radius: 8px;
  color: white;
  font-size: 16px;
  font-weight: 900;
  box-shadow: 0 12px 26px rgba(17, 32, 47, 0.2);
  cursor: pointer;
}

.launch-button {
  display: none;
  right: max(18px, calc((100vw - 1180px) / 2));
  min-width: 122px;
  padding: 0 18px;
  background: #176ad6;
}

.launch-button:active,
.launch-button.is-pressed {
  transform: translateY(2px);
  background: #0e55b2;
}

.reset-button {
  left: max(18px, calc((100vw - 1180px) / 2));
  bottom: calc(88px + env(safe-area-inset-bottom));
  min-width: 104px;
  padding: 0 16px;
  background: #334155;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.reset-button.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.flight-controls {
  position: absolute;
  z-index: 5;
  left: max(18px, calc((100vw - 1180px) / 2));
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-areas:
    ". up ."
    "left down right";
  align-items: center;
  justify-items: center;
  gap: 8px;
}

.control-button {
  width: 64px;
  height: 58px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: rgba(17, 32, 47, 0.82);
  color: white;
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 12px 26px rgba(17, 32, 47, 0.2);
  cursor: pointer;
}

.control-button span {
  display: block;
  line-height: 0.95;
}

.control-button small {
  display: block;
  margin-top: 1px;
  font-size: 12px;
  line-height: 1;
}

.control-button:nth-child(1) {
  grid-area: left;
}

.control-button:nth-child(2) {
  grid-area: right;
}

.control-button.fire {
  grid-area: up;
  background: #176ad6;
  font-size: 24px;
}

.control-button.shield {
  grid-area: down;
  background: #19a974;
  font-size: 24px;
}

.control-button:active,
.control-button.is-held {
  transform: translateY(2px);
  filter: brightness(0.92);
}

.control-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
}

.end-overlay {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(17, 32, 47, 0.18);
  backdrop-filter: blur(3px);
}

.end-overlay.is-visible {
  display: grid;
}

.end-panel {
  width: min(460px, calc(100vw - 36px));
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 22px 58px rgba(17, 32, 47, 0.26);
  text-align: center;
}

.end-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  font-weight: 800;
}

.end-panel #endKicker {
  color: var(--blue);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.end-panel h2 {
  margin: 8px 0 8px;
  color: var(--ink);
  font-size: clamp(34px, 6vw, 54px);
  line-height: 1.05;
  letter-spacing: 0;
}

.end-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.end-actions button {
  min-width: 132px;
  height: 52px;
  border: 0;
  border-radius: 8px;
  color: white;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}

#retryButton {
  background: #176ad6;
}

#restartButton {
  background: #334155;
}

@media (max-width: 940px) {
  .topbar {
    width: calc(100vw - 18px);
    gap: 10px;
  }

  h1 {
    font-size: clamp(25px, 3.4vw, 32px);
  }

  .stats {
    min-width: 0;
    flex: 1;
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .stat {
    min-height: 54px;
    padding: 7px 8px;
  }

  .stat strong {
    font-size: clamp(16px, 2.3vw, 23px);
  }

  .power-panel {
    bottom: calc(86px + env(safe-area-inset-bottom));
    width: min(520px, calc(100vw - 220px));
  }

  .flight-controls {
    left: 10px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .launch-button {
    right: 10px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .topbar {
    width: calc(100vw - 18px);
    margin-top: 9px;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }

  .stats {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stat {
    min-height: 52px;
    padding: 7px;
  }

  .stat span {
    font-size: 11px;
  }

  .stat strong {
    font-size: 17px;
  }

  .power-panel {
    bottom: calc(82px + env(safe-area-inset-bottom));
    width: calc(100vw - 28px);
  }

  .flight-controls {
    left: 12px;
    right: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .control-button {
    width: 58px;
    height: 54px;
    padding: 0 8px;
  }

  .launch-button {
    right: 10px;
    width: min(150px, 32vw);
  }

  .launch-button:active,
  .launch-button.is-pressed {
    transform: translateY(2px);
  }
}

@media (max-width: 430px) {
  .launch-button {
    display: none;
  }

  .control-button.fire,
  .control-button.shield {
    font-size: 22px;
  }

  .control-button small {
    font-size: 10px;
  }

  .end-actions {
    flex-direction: column;
  }

  .end-actions button {
    width: 100%;
  }

  h1 {
    font-size: 25px;
  }

  .stats {
    gap: 6px;
  }

  .power-panel {
    gap: 8px;
  }

  #hintText {
    width: 86px;
    font-size: 12px;
  }

  .reset-button {
    min-width: 88px;
    font-size: 14px;
  }
}
