* {
  box-sizing: border-box;
}

:root {
  --bg: #040712;
  --panel: rgba(11, 18, 42, 0.66);
  --panel-strong: rgba(8, 14, 32, 0.86);
  --line: rgba(130, 170, 255, 0.16);
  --text: #f6f9ff;
  --muted: #9aa7c5;
  --cyan: #58f7e8;
  --blue: #5f84ff;
  --violet: #a855f7;
  --pink: #ff63b6;
  --gold: #ffd166;
  --danger: #ff5f86;
}

*::selection {
  background: rgba(88, 247, 232, 0.26);
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  background:
    radial-gradient(circle at 12% 10%, rgba(95, 132, 255, 0.22), transparent 24%),
    radial-gradient(circle at 88% 12%, rgba(255, 99, 182, 0.14), transparent 20%),
    radial-gradient(circle at 50% 110%, rgba(88, 247, 232, 0.16), transparent 30%),
    linear-gradient(180deg, #060a18 0%, #040712 100%);
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  border-radius: 50%;
  filter: blur(55px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.8;
}

body::before {
  width: 260px;
  height: 260px;
  left: -60px;
  top: 110px;
  background: rgba(95, 132, 255, 0.18);
  animation: floatBlob 12s ease-in-out infinite;
}

body::after {
  width: 320px;
  height: 320px;
  right: -80px;
  top: 80px;
  background: rgba(255, 99, 182, 0.16);
  animation: floatBlob 16s ease-in-out infinite reverse;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(104, 136, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(104, 136, 255, 0.06) 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: linear-gradient(to bottom, black, rgba(0,0,0,0.22));
  animation: driftGrid 16s linear infinite;
}

.app {
  width: min(1120px, 94%);
  margin: 0 auto;
  padding: 32px 0 24px;
  position: relative;
  z-index: 1;
}

.topbar,
.hud,
footer,
.top-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.8rem, 7vw, 5.2rem);
  letter-spacing: -0.075em;
  line-height: 0.9;
  background: linear-gradient(90deg, #fff, #a1b2ff 38%, #79fef3 74%, #ffd166 100%);
  -webkit-background-clip: text;
  color: transparent;
  text-shadow: 0 0 26px rgba(95, 132, 255, 0.18);
}

.top-actions {
  gap: 10px;
}

button {
  border: 0;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0px) scale(0.98);
}

.ghost {
  border: 1px solid rgba(142, 174, 255, 0.18);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.025));
  padding: 10px 14px;
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 10px 30px rgba(0,0,0,0.18);
}

.ghost:hover {
  border-color: rgba(88, 247, 232, 0.42);
  box-shadow: 0 0 0 1px rgba(88, 247, 232, 0.12), 0 14px 28px rgba(12, 22, 54, 0.34);
}

.hud {
  gap: 14px;
  margin: 22px 0 14px;
}

.hud-card {
  flex: 1;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(142, 174, 255, 0.14);
  background: linear-gradient(180deg, rgba(16, 24, 54, 0.78), rgba(8, 15, 36, 0.74));
  backdrop-filter: blur(16px);
  border-radius: 18px;
  padding: 15px 16px;
  min-width: 0;
  box-shadow: 0 20px 50px rgba(4, 8, 24, 0.35);
}

.hud-card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--blue), var(--cyan), var(--pink), var(--gold));
  opacity: 0.9;
}

.hud-card::after {
  content: "";
  position: absolute;
  width: 140px;
  height: 140px;
  top: -80px;
  right: -60px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(88, 247, 232, 0.16), transparent 70%);
}

.hud-card span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.hud-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.45rem;
  text-shadow: 0 0 18px rgba(95, 132, 255, 0.12);
  transform-origin: left center;
}

.hud-card strong.pop {
  animation: scorePop 0.28s ease;
}

.game-shell {
  position: relative;
  border: 1px solid rgba(142, 174, 255, 0.16);
  background: linear-gradient(180deg, rgba(7, 12, 30, 0.88), rgba(4, 7, 18, 0.9));
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 35px 110px rgba(0, 0, 0, 0.42), 0 0 0 1px rgba(88, 247, 232, 0.03);
}

.game-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(88, 247, 232, 0.09), transparent 30%, transparent 70%, rgba(255, 99, 182, 0.08));
}

.game-shell::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.03);
  pointer-events: none;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 900 / 560;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(rgba(5, 8, 22, 0.16), rgba(5, 8, 22, 0.78));
  backdrop-filter: blur(3px);
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(580px, 92%);
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: 34px 28px;
  border-radius: 24px;
  border: 1px solid rgba(88, 247, 232, 0.16);
  background: linear-gradient(180deg, rgba(10, 18, 42, 0.88), rgba(8, 12, 30, 0.9));
  backdrop-filter: blur(18px);
  box-shadow: 0 25px 80px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.05);
  isolation: isolate;
}

.panel::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(120deg, rgba(95,132,255,0.9), rgba(88,247,232,0.8), rgba(255,99,182,0.8), rgba(255,209,102,0.8), rgba(95,132,255,0.9));
  background-size: 250% 250%;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: gradientShift 7s linear infinite, panelPulse 2.6s ease-in-out infinite;
  pointer-events: none;
  opacity: 0.85;
}

.panel::after {
  content: "";
  position: absolute;
  width: 220px;
  height: 220px;
  right: -90px;
  top: -90px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(88,247,232,0.20), rgba(255,99,182,0.10) 40%, transparent 70%);
  filter: blur(10px);
  animation: floatBlob 9s ease-in-out infinite;
  pointer-events: none;
}

.panel > * {
  position: relative;
  z-index: 1;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 5vw, 3.8rem);
  letter-spacing: -0.05em;
}

.panel p {
  color: var(--muted);
  line-height: 1.65;
}

.primary {
  margin-top: 12px;
  padding: 13px 22px;
  border-radius: 14px;
  background: linear-gradient(120deg, var(--blue), var(--cyan), var(--pink));
  background-size: 200% 200%;
  color: #08111b;
  font-weight: 900;
  box-shadow: 0 12px 32px rgba(88, 247, 232, 0.16);
  animation: gradientShift 7s ease infinite;
}

.primary:hover {
  box-shadow: 0 14px 34px rgba(255, 99, 182, 0.18);
}

.hint {
  margin: 14px 0 0 !important;
  font-size: 0.82rem;
}

.mobile-controls {
  display: none;
  gap: 12px;
  margin-top: 14px;
}

.mobile-controls button {
  flex: 1;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid rgba(142, 174, 255, 0.14);
  background: linear-gradient(180deg, rgba(16, 24, 54, 0.82), rgba(8, 15, 36, 0.8));
  font-size: 1.4rem;
  user-select: none;
  touch-action: manipulation;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.22);
}

footer {
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  color: #7080a0;
  font-size: 0.82rem;
}

@keyframes driftGrid {
  from { transform: translate3d(0,0,0); }
  to { transform: translate3d(20px, 20px, 0); }
}

@keyframes floatBlob {
  0%, 100% { transform: translate3d(0,0,0) scale(1); }
  50% { transform: translate3d(30px, -12px, 0) scale(1.06); }
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes panelPulse {
  0%, 100% { opacity: 0.6; filter: brightness(1); }
  50% { opacity: 1; filter: brightness(1.18); }
}

@keyframes scorePop {
  0% { transform: scale(1); text-shadow: 0 0 18px rgba(95, 132, 255, 0.12); }
  45% { transform: scale(1.16); text-shadow: 0 0 26px rgba(88, 247, 232, 0.6), 0 0 16px rgba(255, 99, 182, 0.34); }
  100% { transform: scale(1); text-shadow: 0 0 18px rgba(95, 132, 255, 0.12); }
}

@media (max-width: 720px) {
  .app {
    width: min(96%, 680px);
    padding-top: 20px;
  }

  .topbar {
    align-items: flex-end;
  }

  .top-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .ghost {
    padding: 8px 10px;
    font-size: 0.78rem;
  }

  .hud {
    gap: 8px;
  }

  .hud-card {
    padding: 10px;
  }

  .mobile-controls {
    display: flex;
  }

  footer {
    flex-direction: column;
    text-align: center;
  }
}
