:root {
  color-scheme: dark;
  --bg: #050816;
  --panel: rgba(10, 14, 30, 0.8);
  --text: #eaf2ff;
  --muted: #7d8cb4;
  --accent: #00f0ff;
  --accent-2: #ff2ef9;
  --danger: #ff5f7a;
  --success: #54ffb0;
  --gold: #ffd76a;
  --shadow: 0 0 22px rgba(0, 240, 255, 0.30);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(0, 240, 255, 0.16), transparent 22%),
    radial-gradient(circle at bottom right, rgba(255, 46, 249, 0.18), transparent 24%),
    var(--bg);
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  padding: 0.75rem;
}

.hud {
  flex: 0 0 auto;
  width: min(100%, 1100px);
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.6rem;
}

.hud-item {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.9rem;
  padding: 0.7rem 0.8rem;
  box-shadow: inset 0 0 12px rgba(0, 240, 255, 0.08), 0 0 12px rgba(0, 240, 255, 0.08);
  text-align: center;
}

.hud-item span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.hud-item strong {
  display: block;
  margin-top: 0.25rem;
  font-size: 1rem;
}

.hud-item.gold {
  border-color: rgba(255, 215, 106, 0.55);
  box-shadow: 0 0 18px rgba(255, 215, 106, 0.35);
  animation: goldPulse 1.2s ease-in-out infinite;
}

.game-wrap {
  position: relative;
  flex: 1 1 0;
  width: min(100%, 1100px);
  min-height: 0;
  height: auto;
  border-radius: 1.4rem;
  overflow: hidden;
  border: 1px solid rgba(0, 240, 255, 0.22);
  box-shadow: var(--shadow);
  background: #070b1d;
  isolation: isolate;
}

canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  outline: none;
  background: transparent;
  cursor: crosshair;
}

.fx-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
}

.fx-layer.flash {
  background: radial-gradient(circle, rgba(0, 240, 255, 0.55), rgba(255, 46, 249, 0.18) 46%, transparent 70%);
  animation: neonFlash 0.7s ease-out;
}

.fx-layer.level-pulse {
  box-shadow: inset 0 0 80px rgba(0, 240, 255, 0.45);
  animation: glowPulse 0.9s ease-out;
}

.fx-layer.game-over {
  background: rgba(2, 4, 12, 0.55);
  animation: dramaticFade 0.8s ease-out forwards;
}

.banner {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%) scale(0.8);
  z-index: 7;
  pointer-events: none;
  opacity: 0;
  color: var(--accent);
  font-size: clamp(1.4rem, 4vw, 2.6rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-shadow: 0 0 22px rgba(0, 240, 255, 0.8);
}

.banner.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
  animation: levelPop 0.8s ease-out;
}

.banner.gold {
  color: var(--gold);
  text-shadow: 0 0 24px rgba(255, 215, 106, 0.9);
}

.pause-fab {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  z-index: 8;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  color: white;
  background: rgba(8, 12, 28, 0.78);
  cursor: pointer;
}

.pause-fab[hidden] {
  display: none !important;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 18, 0.72);
  backdrop-filter: blur(8px);
  z-index: 50;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.overlay:not(.active) {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  z-index: 0 !important;
}

.overlay.active {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  z-index: 80 !important;
}

.overlay.active .overlay-card,
.overlay.active .btn,
.overlay.active button {
  pointer-events: auto !important;
  cursor: pointer;
  position: relative;
  z-index: 81;
}

.game-wrap:has(.overlay.active) canvas {
  pointer-events: none;
}

.launch-hud {
  position: absolute;
  left: 50%;
  top: 58%;
  transform: translate(-50%, -50%);
  z-index: 25;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  pointer-events: none;
  text-align: center;
}

.launch-hud.visible {
  display: flex !important;
  pointer-events: auto !important;
}

.launch-hud p {
  margin: 0;
  color: var(--text);
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-shadow: 0 0 12px rgba(0, 240, 255, 0.45);
}

.launch-hud .btn {
  min-width: 200px;
  min-height: 56px;
  font-size: 1.15rem;
  font-weight: 700;
  pointer-events: auto !important;
  box-shadow: 0 0 24px rgba(0, 240, 255, 0.45);
}

.overlay-card {
  width: min(92%, 560px);
  max-height: 92%;
  overflow: auto;
  padding: 2rem;
  border-radius: 1.3rem;
  background: rgba(8, 12, 28, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 35px rgba(0, 240, 255, 0.15);
  text-align: center;
}

.overlay-card.wide {
  width: min(94%, 720px);
}

.overlay-card.flash-card {
  animation: glowPulse 1.2s ease-in-out infinite;
}

.kicker {
  margin: 0 0 0.4rem;
  color: var(--accent-2);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.overlay-card h1,
.overlay-card h2 {
  margin: 0 0 0.8rem;
  color: var(--accent);
  text-shadow: 0 0 16px rgba(0, 240, 255, 0.4);
}

.overlay-card h3 {
  margin: 0 0 0.7rem;
  color: var(--text);
}

.overlay-card p,
.overlay-card li,
.hint {
  color: var(--muted);
  line-height: 1.6;
}

.button-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.2rem;
}

.button-row.compact {
  margin-top: 0.4rem;
}

.button-row.stacked {
  flex-direction: column;
  align-items: stretch;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.8rem 1.1rem;
  color: white;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.22), rgba(255, 46, 249, 0.16));
  border: 1px solid rgba(255, 255, 255, 0.14);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.btn:hover,
.btn:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.2);
}

.btn.primary {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.9), rgba(255, 46, 249, 0.72));
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.08);
}

.btn.danger {
  background: rgba(255, 95, 122, 0.22);
}

.btn.toggle.active,
.btn.difficulty.active {
  background: linear-gradient(135deg, rgba(84, 255, 176, 0.26), rgba(0, 240, 255, 0.18));
  box-shadow: 0 0 16px rgba(255, 46, 249, 0.25);
  border-color: rgba(255, 46, 249, 0.38);
}

.btn.difficulty {
  min-width: 96px;
  pointer-events: auto;
  position: relative;
  z-index: 2;
}

.loading-bar {
  width: 100%;
  height: 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  margin-top: 1rem;
  overflow: hidden;
}

.loading-bar span {
  display: block;
  width: 30%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  animation: loadingPulse 1.2s ease-in-out infinite;
}

.settings-grid {
  display: grid;
  gap: 1rem;
  text-align: left;
}

.settings-grid section {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1rem;
}

.slider-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.slider-row input {
  width: 46%;
}

.leaderboard-list,
.stats-list {
  margin: 1rem 0;
  padding: 0;
  text-align: left;
}

.leaderboard-list {
  list-style: none;
  counter-reset: rank;
}

.leaderboard-list li {
  counter-increment: rank;
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.7rem 0.4rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.leaderboard-list li::before {
  content: counter(rank) ".";
  color: var(--accent);
  min-width: 1.6rem;
}

.stats-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem 1rem;
}

.stats-list dt {
  color: var(--muted);
}

.stats-list dd {
  margin: 0;
  color: var(--text);
  text-align: right;
}

.high-score-banner {
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-shadow: 0 0 18px rgba(255, 215, 106, 0.7);
  animation: goldPulse 1s ease-in-out infinite;
}

.name-entry {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  color: var(--muted);
  margin-top: 0.8rem;
}

.name-entry input {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 0.8rem;
  background: rgba(255, 255, 255, 0.06);
  color: white;
  padding: 0.7rem 0.8rem;
  font-size: 1rem;
  text-align: center;
}

.touch-controls {
  position: absolute;
  left: 0.7rem;
  right: 0.7rem;
  bottom: 0.7rem;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  z-index: 12;
  pointer-events: none;
}

.touch-controls.visible {
  display: flex !important;
}

.touch-controls[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.touch-center {
  display: flex;
  gap: 0.5rem;
  pointer-events: auto;
}

.touch-btn {
  pointer-events: auto;
  flex: 0 0 auto;
  min-height: 52px;
  min-width: 64px;
  border: none;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  color: white;
  font-size: 1.05rem;
  font-weight: 700;
  background: rgba(8, 12, 28, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.12);
  cursor: pointer;
}

.touch-btn.arrow {
  min-width: 64px;
  font-size: 1.4rem;
  line-height: 1;
}

.touch-btn.primary {
  min-width: 120px;
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.9), rgba(255, 46, 249, 0.72));
}

@keyframes loadingPulse {
  0%, 100% { transform: translateX(-100%); }
  50% { transform: translateX(260%); }
}

@keyframes neonFlash {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

@keyframes glowPulse {
  0% { opacity: 0.15; }
  50% { opacity: 1; }
  100% { opacity: 0.2; }
}

@keyframes levelPop {
  0% { transform: translateX(-50%) scale(0.4); opacity: 0; }
  60% { transform: translateX(-50%) scale(1.08); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

@keyframes goldPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}

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

@media (max-width: 900px) {
  .hud {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

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

  .app-shell {
    padding: 0.5rem;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .overlay-card {
    padding: 1.3rem;
  }

  .launch-hud {
    top: 52%;
  }

  .touch-controls {
    inset: auto 0.55rem 0.55rem 0.55rem;
  }
}
