:root {
  color-scheme: dark;
  --bg: #05060a;
  --panel: #11131b;
  --panel-strong: #171923;
  --line: #33384b;
  --text: #f6f7fb;
  --muted: #a9afc3;
  --cyan: #34d9ff;
  --yellow: #ffd65a;
  --pink: #ff4fa3;
  --green: #63ff96;
  --red: #ff655d;
}

* {
  box-sizing: border-box;
}

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

body {
  display: grid;
  place-items: start center;
  min-height: 100svh;
  padding: 18px;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, #05060a 0%, #0b0d12 48%, #090812 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.game-shell {
  width: min(100%, 900px);
  display: grid;
  grid-template-rows: auto auto;
  gap: 12px;
}

.topbar,
.statusbar,
.touch-toggle,
.touch-controls {
  width: 100%;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(17, 19, 27, 0.94);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 2px solid var(--cyan);
  transform: rotate(45deg);
  box-shadow: 0 0 18px rgba(52, 217, 255, 0.58), inset 0 0 12px rgba(255, 79, 163, 0.45);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2.4vw, 2rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 8px;
  min-width: min(100%, 420px);
}

.stat {
  display: grid;
  gap: 3px;
  min-height: 50px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #090a10;
}

.stat span {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1;
  text-transform: uppercase;
}

.stat strong {
  color: var(--yellow);
  font-size: 1.05rem;
  line-height: 1.1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.sound-button,
.primary-button,
.touch-toggle,
.touch-button {
  border: 0;
  color: var(--text);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.sound-button {
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
}

.sound-button.is-muted {
  color: var(--red);
}

.stage-panel {
  position: relative;
  width: 100%;
  margin-inline: auto;
  aspect-ratio: 9 / 16;
  min-height: 640px;
  border: 1px solid var(--line);
  overflow: hidden;
  background: #040408;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 6, 10, 0.54);
  transition: opacity 140ms ease, visibility 140ms ease;
}

.overlay.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.overlay-panel {
  width: min(440px, 100%);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(12, 13, 20, 0.82);
  text-align: center;
  backdrop-filter: blur(10px);
}

.overlay-panel h2 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.overlay-panel p {
  margin: 12px auto 18px;
  max-width: 32ch;
  color: var(--muted);
  line-height: 1.45;
}

.primary-button {
  min-width: 148px;
  height: 48px;
  padding: 0 22px;
  background: var(--pink);
  color: white;
  font-weight: 900;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.12), 0 12px 36px rgba(255, 79, 163, 0.34);
}

.primary-button:hover,
.touch-toggle:hover,
.touch-button:hover,
.sound-button:hover {
  filter: brightness(1.08);
}

.primary-button:active,
.touch-toggle:active,
.touch-button:active,
.touch-button.is-down,
.sound-button:active {
  transform: translateY(1px);
}

.key-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.key-row span {
  min-width: 58px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  background: #08090f;
  color: var(--muted);
  font-size: 0.74rem;
}

.touch-toggle {
  display: none;
  position: absolute;
  z-index: 6;
  right: 12px;
  bottom: 126px;
  width: auto;
  min-width: 56px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(52, 217, 255, 0.42);
  background: rgba(9, 10, 16, 0.88);
  color: var(--cyan);
  font-size: 0.68rem;
  font-weight: 900;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.34);
  pointer-events: auto;
}

.touch-controls {
  position: absolute;
  z-index: 5;
  left: 12px;
  right: 12px;
  bottom: 54px;
  width: auto;
  display: none;
  grid-template-columns: minmax(154px, 0.72fr) repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: stretch;
  pointer-events: none;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, 1fr);
  gap: 6px;
}

.dpad-spacer {
  min-height: 58px;
  visibility: hidden;
}

.touch-button {
  height: 58px;
  border: 1px solid var(--line);
  background: rgba(17, 19, 27, 0.84);
  color: var(--cyan);
  font-size: 0.96rem;
  font-weight: 900;
  touch-action: none;
  pointer-events: auto;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.28);
}

.touch-button.fire {
  color: #05060a;
  background: rgba(255, 214, 90, 0.88);
}

.touch-button.charge {
  color: #05060a;
  background: rgba(52, 217, 255, 0.86);
}

.touch-button.orbit {
  color: white;
  background: rgba(159, 123, 255, 0.88);
}

.touch-button.bomb {
  color: white;
  background: rgba(255, 79, 163, 0.88);
}

.statusbar {
  position: absolute;
  z-index: 5;
  left: 12px;
  right: 12px;
  bottom: 10px;
  width: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: rgba(17, 19, 27, 0.86);
  color: var(--muted);
  font-size: 0.86rem;
  overflow: hidden;
}

.statusbar > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-icons {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  gap: 6px;
  overflow: hidden;
}

.status-empty {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.status-icon {
  --accent: var(--cyan);
  --cooldown: 1;
  position: relative;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  color: var(--text);
  isolation: isolate;
}

.status-icon::before,
.status-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 8px;
}

.status-icon::before {
  background:
    conic-gradient(var(--accent) calc(var(--cooldown) * 1turn), rgba(255, 255, 255, 0.1) 0),
    rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 48%, transparent);
}

.status-icon::after {
  inset: 4px;
  border: 1px solid color-mix(in srgb, var(--accent) 54%, rgba(255, 255, 255, 0.16));
  background: rgba(6, 7, 12, 0.88);
  z-index: 0;
}

.status-icon-label,
.status-icon-value,
.status-icon-badge {
  position: relative;
  z-index: 1;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.status-icon-label {
  margin-top: 1px;
  color: var(--accent);
  font-size: 0.62rem;
  font-weight: 900;
}

.status-icon-value {
  margin-top: -6px;
  color: var(--text);
  font-size: 0.58rem;
  font-weight: 800;
}

.status-icon-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 15px;
  height: 15px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: var(--accent);
  color: #05060a;
  font-size: 0.56rem;
  font-weight: 900;
  z-index: 2;
}

@media (orientation: portrait) and (min-width: 761px) {
  .game-shell {
    width: min(100%, 900px, calc((100svh - 210px) * 9 / 16));
  }
}

@media (max-width: 760px) {
  body {
    padding: 8px;
  }

  .game-shell {
    gap: 9px;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 8px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .brand h1 {
    font-size: 1.2rem;
  }

  .brand p {
    display: none;
  }

  .hud {
    grid-column: 1 / -1;
    order: 3;
    min-width: 0;
  }

  .stage-panel {
    width: 100%;
    min-height: 0;
  }

  .overlay-panel {
    padding: 18px 14px;
  }

  .key-row {
    display: none;
  }

  .touch-toggle {
    display: block;
  }

  .stage-panel.are-touch-controls-hidden .touch-toggle {
    bottom: 54px;
  }

  .touch-controls {
    display: grid;
  }

  .touch-controls.is-hidden {
    display: none;
  }

  .touch-button {
    height: 56px;
    font-size: 0.82rem;
  }

  .dpad-spacer {
    min-height: 56px;
  }
}

@media (max-width: 420px) {
  .stat {
    padding-inline: 7px;
  }

  .stat strong {
    font-size: 0.94rem;
  }

  .touch-controls {
    gap: 7px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .touch-toggle {
    bottom: 180px;
  }

  .dpad {
    grid-column: 1 / -1;
  }
}
