:root {
  --bg: #0a0618;
  --bg2: #120a28;
  --neon-pink: #ff4fd8;
  --neon-cyan: #3df0ff;
  --neon-yellow: #ffe566;
  --neon-purple: #a78bfa;
  --text: #f5eefc;
  --muted: #b8a8d4;
  --panel: rgba(20, 12, 40, 0.85);
  --danger: #ff6b9d;
  --ok: #5dffb0;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at 50% 0%, #1a0f3a 0%, var(--bg) 55%, #05030c 100%);
  color: var(--text);
  overflow-x: hidden;
  touch-action: manipulation;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 560px;
  margin: 0 auto;
  padding: 0.5rem 0.75rem 1rem;
}

.hud {
  width: 100%;
  background: var(--panel);
  border: 1px solid rgba(61, 240, 255, 0.35);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  box-shadow: 0 0 16px rgba(61, 240, 255, 0.15);
}

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

.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 700;
}

.hud-row + .hud-row {
  margin-top: 0.25rem;
}

#timerLabel {
  color: var(--neon-cyan);
  text-shadow: 0 0 8px rgba(61, 240, 255, 0.7);
}

#keysLabel {
  color: var(--neon-yellow);
  text-shadow: 0 0 8px rgba(255, 229, 102, 0.6);
}

.icon-btn {
  background: transparent;
  border: 1px solid rgba(255, 79, 216, 0.5);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  padding: 0.15rem 0.45rem;
  cursor: pointer;
}

.icon-btn:hover {
  box-shadow: 0 0 10px rgba(255, 79, 216, 0.4);
}

#screens {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  position: relative;
  width: 100%;
  padding: 1rem 0;
}

.screen.active {
  display: flex;
}

.glow-bg {
  position: absolute;
  inset: 10% 15%;
  background: radial-gradient(circle, rgba(255, 79, 216, 0.18), transparent 70%);
  pointer-events: none;
  filter: blur(8px);
  z-index: 0;
}

.title {
  position: relative;
  z-index: 1;
  font-size: clamp(2rem, 9vw, 2.8rem);
  line-height: 1.2;
  margin: 0 0 0.5rem;
  color: var(--neon-pink);
  text-shadow:
    0 0 10px rgba(255, 79, 216, 0.9),
    0 0 28px rgba(61, 240, 255, 0.45);
  letter-spacing: 0.04em;
  animation: titlePulse 2.4s ease-in-out infinite;
}

@keyframes titlePulse {
  0%,
  100% {
    filter: brightness(1);
    transform: scale(1);
  }
  50% {
    filter: brightness(1.15);
    transform: scale(1.02);
  }
}

.tagline {
  position: relative;
  z-index: 1;
  color: var(--neon-cyan);
  margin: 0 0 1.25rem;
  text-shadow: 0 0 8px rgba(61, 240, 255, 0.5);
}

.records {
  position: relative;
  z-index: 1;
  background: var(--panel);
  border: 1px solid rgba(167, 139, 250, 0.4);
  border-radius: 12px;
  padding: 0.75rem 1.25rem;
  margin-bottom: 1.25rem;
  min-width: min(100%, 280px);
}

.records p {
  margin: 0.35rem 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.records strong {
  color: var(--neon-yellow);
}

.primary-btn,
.secondary-btn {
  position: relative;
  z-index: 1;
  border: none;
  border-radius: 999px;
  padding: 0.85rem 2.2rem;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.primary-btn {
  background: linear-gradient(135deg, var(--neon-pink), #7c3aed);
  color: #fff;
  box-shadow: 0 0 20px rgba(255, 79, 216, 0.45);
  margin-bottom: 0.75rem;
}

.primary-btn:hover,
.primary-btn:focus-visible {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 0 28px rgba(61, 240, 255, 0.55);
}

.secondary-btn {
  background: transparent;
  color: var(--neon-cyan);
  border: 1px solid rgba(61, 240, 255, 0.55);
  margin-top: 0.35rem;
}

.secondary-btn:hover,
.secondary-btn:focus-visible {
  box-shadow: 0 0 14px rgba(61, 240, 255, 0.35);
}

.hint {
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.6;
  margin-top: 0.5rem;
}

.stage-announce {
  font-size: clamp(1.8rem, 8vw, 2.4rem);
  color: var(--neon-cyan);
  text-shadow: 0 0 16px rgba(61, 240, 255, 0.8);
  margin: 0 0 0.5rem;
  animation: stageIn 0.6s ease-out;
}

.stage-sub {
  color: var(--muted);
  animation: stageIn 0.6s ease-out 0.1s both;
}

@keyframes stageIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.canvas-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 0.75rem;
}

#gameCanvas {
  width: min(100%, 480px);
  height: auto;
  aspect-ratio: 1;
  border-radius: 12px;
  border: 2px solid rgba(61, 240, 255, 0.4);
  box-shadow:
    0 0 24px rgba(255, 79, 216, 0.25),
    inset 0 0 40px rgba(10, 6, 24, 0.5);
  background: #08041a;
  display: block;
  max-height: min(62vh, 480px);
}

.dpad {
  display: grid;
  grid-template-rows: auto auto auto;
  justify-items: center;
  gap: 0.35rem;
  user-select: none;
  margin-top: 0.25rem;
}

.dpad-mid {
  display: flex;
  gap: 2.5rem;
}

.dpad-btn {
  width: 3.4rem;
  height: 3.4rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 79, 216, 0.55);
  background: rgba(30, 16, 55, 0.9);
  color: var(--neon-pink);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(255, 79, 216, 0.25);
  touch-action: none;
}

.dpad-btn:active,
.dpad-btn.active {
  background: rgba(255, 79, 216, 0.35);
  color: #fff;
  box-shadow: 0 0 18px rgba(61, 240, 255, 0.45);
}

#resultTitle {
  font-size: clamp(1.6rem, 7vw, 2.2rem);
  margin: 0 0 0.75rem;
  text-shadow: 0 0 14px rgba(255, 79, 216, 0.7);
}

#resultTitle.win {
  color: var(--ok);
  text-shadow: 0 0 16px rgba(93, 255, 176, 0.7);
}

#resultTitle.lose {
  color: var(--danger);
}

#resultMessage {
  color: var(--muted);
  margin: 0 0 1rem;
  line-height: 1.5;
}

.result-stats {
  margin-bottom: 1.25rem;
}

@media (min-width: 700px) {
  .dpad {
    opacity: 0.85;
  }
}

@media (max-width: 480px) {
  .dpad-btn {
    width: 3.1rem;
    height: 3.1rem;
  }

  #gameCanvas {
    max-height: min(52vh, 400px);
  }
}
