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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a1628;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #e8f4ff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

/* HUD */
.hud-top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(180deg, rgba(10, 22, 40, 0.85) 0%, transparent 100%);
}

.hud-block {
  display: flex;
  flex-direction: column;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7eb8d8;
}

.hud-block strong,
.hud-block span:last-child,
#hud-level,
#hud-wave,
#hud-score,
#hud-high {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}

.hud-score {
  margin-left: auto;
}

.hud-hp-wrap {
  margin: 0 1rem;
  height: 8px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  overflow: hidden;
}

.hud-hp {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff6b9d, #ff4081);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.hud-combo {
  position: absolute;
  top: 4.5rem;
  right: 1rem;
  padding: 0.35rem 0.75rem;
  background: rgba(255, 200, 50, 0.2);
  border: 1px solid rgba(255, 200, 50, 0.5);
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.875rem;
  color: #ffd54f;
  animation: pulse 0.4s ease;
}

.hud-combo.hidden {
  display: none;
}

@keyframes pulse {
  0% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Screens */
.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 22, 40, 0.92);
  backdrop-filter: blur(6px);
  padding: 1.5rem;
  animation: fadeIn 0.3s ease;
}

.screen.hidden {
  display: none;
}

.screen-inner {
  text-align: center;
  max-width: 520px;
  width: 100%;
}

.screen-banner {
  animation: bannerPop 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes bannerPop {
  0% { transform: scale(0.9); opacity: 0; }
  70% { transform: scale(1.03); }
  100% { transform: scale(1); opacity: 1; }
}

.eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #4dd0c8;
}

h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 800;
  background: linear-gradient(135deg, #ff9ec4, #4dd0c8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 700;
}

.tagline {
  margin: 0 0 1.5rem;
  color: #9ecae0;
  line-height: 1.5;
}

.menu-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 1.5rem;
}

.menu-stats div {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.menu-stats span {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7eb8d8;
}

.menu-stats strong {
  font-size: 1.25rem;
}

.hint {
  margin: 1.25rem 0 0;
  font-size: 0.8rem;
  color: #6a9bb5;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  min-width: 160px;
  padding: 0.75rem 1.5rem;
  margin: 0.35rem;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, #ff6b9d, #ff4081);
  color: #fff;
  box-shadow: 0 4px 20px rgba(255, 64, 129, 0.4);
}

.btn-ghost {
  background: transparent;
  color: #9ecae0;
  border: 2px solid rgba(158, 202, 224, 0.35);
}

/* Upgrade cards */
.upgrade-sub {
  margin: 0 0 1.25rem;
  color: #9ecae0;
}

.upgrade-cards {
  display: grid;
  gap: 0.75rem;
}

.upgrade-card {
  text-align: left;
  padding: 1rem 1.25rem;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(77, 208, 200, 0.3);
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.upgrade-card:hover,
.upgrade-card:focus-visible {
  border-color: #4dd0c8;
  background: rgba(77, 208, 200, 0.12);
  transform: translateY(-2px);
  outline: none;
}

.upgrade-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  color: #4dd0c8;
}

.upgrade-card p {
  margin: 0;
  font-size: 0.875rem;
  color: #9ecae0;
  line-height: 1.4;
}

/* Results */
.result-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 88px;
  height: 88px;
  margin: 1rem auto;
  border-radius: 50%;
  font-size: 2.5rem;
  font-weight: 900;
  border: 4px solid;
}

.rank-S {
  color: #ffd54f;
  border-color: #ffd54f;
  background: rgba(255, 213, 79, 0.15);
  box-shadow: 0 0 30px rgba(255, 213, 79, 0.35);
}

.rank-A {
  color: #4dd0c8;
  border-color: #4dd0c8;
  background: rgba(77, 208, 200, 0.15);
}

.rank-B {
  color: #81c784;
  border-color: #81c784;
  background: rgba(129, 199, 132, 0.15);
}

.rank-C {
  color: #90a4ae;
  border-color: #90a4ae;
  background: rgba(144, 164, 174, 0.15);
}

.result-score {
  margin: 0.5rem 0;
  font-size: 1.1rem;
}

.result-detail {
  margin: 0 0 1.25rem;
  color: #9ecae0;
  font-size: 0.9rem;
}

/* Touch controls */
.touch-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem calc(1rem + env(safe-area-inset-bottom));
  pointer-events: none;
}

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

.touch-btn {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  background: rgba(77, 208, 200, 0.25);
  border: 2px solid rgba(77, 208, 200, 0.5);
  color: #fff;
  font-size: 1.25rem;
  font-weight: 700;
  touch-action: manipulation;
}

.touch-btn:active,
.touch-btn.active {
  background: rgba(77, 208, 200, 0.5);
  transform: scale(0.95);
}

.touch-fire {
  width: 72px;
  height: 72px;
  background: rgba(255, 107, 157, 0.3);
  border-color: rgba(255, 107, 157, 0.6);
  font-size: 1.5rem;
}

.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block;
  }

  .desktop-only {
    display: none;
  }

  .touch-controls:not(.hidden) {
    display: flex;
  }

  .upgrade-cards {
    max-height: 50vh;
    overflow-y: auto;
  }
}

@media (min-width: 769px) {
  .touch-controls {
    display: none !important;
  }
}

@media (pointer: coarse) {
  .desktop-only {
    display: none;
  }

  .mobile-only {
    display: block;
  }
}
