* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: #0a0c11;
  color: #eef0f6;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: rgba(179, 139, 255, 0.4);
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 20;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(8, 10, 16, 0.62), rgba(8, 10, 16, 0.28) 60%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: hud-in 0.35s ease both;
}

@keyframes hud-in {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

#hud.hidden {
  display: none;
}

#btn-back {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.08);
  color: #eef0f6;
  cursor: pointer;
  pointer-events: auto;
  position: relative;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#btn-back:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, 0.6);
  transform: translateY(-1px) rotate(-8deg);
}

#btn-back:active {
  transform: scale(0.92);
}

#btn-back::before {
  content: "";
  position: absolute;
  top: 14px;
  left: 15px;
  width: 13px;
  height: 13px;
  border-left: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
  transform: rotate(45deg);
  border-radius: 1px;
}

#hud-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 1px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

#hud-stat {
  margin-left: auto;
  font-size: 16px;
  font-weight: 700;
  color: #ffd27a;
  background: linear-gradient(135deg, rgba(255, 210, 122, 0.18), rgba(255, 143, 163, 0.14));
  border: 1px solid rgba(255, 210, 122, 0.32);
  padding: 7px 16px;
  border-radius: 22px;
  min-width: 84px;
  text-align: center;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 14px -6px rgba(255, 180, 90, 0.5);
}

/* ---------- Main Menu ---------- */
#menu {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(94, 76, 255, 0.22), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(255, 92, 138, 0.18), transparent 60%),
    linear-gradient(180deg, #11131c, #090b10);
}

/* floating aurora blobs */
#menu::before,
#menu::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  z-index: -1;
}

#menu::before {
  width: 42vw;
  height: 42vw;
  min-width: 320px;
  min-height: 320px;
  background: radial-gradient(circle, rgba(120, 92, 255, 0.55), transparent 70%);
  top: -12%;
  left: -6%;
  animation: float-a 16s ease-in-out infinite;
}

#menu::after {
  width: 38vw;
  height: 38vw;
  min-width: 300px;
  min-height: 300px;
  background: radial-gradient(circle, rgba(255, 92, 138, 0.5), transparent 70%);
  bottom: -14%;
  right: -6%;
  animation: float-b 19s ease-in-out infinite;
}

@keyframes float-a {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(8%, 10%) scale(1.12); }
}

@keyframes float-b {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-9%, -8%) scale(1.1); }
}

#menu.fade-out {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.menu-inner {
  width: 100%;
  max-width: 940px;
  padding: 48px 24px;
  text-align: center;
}

.menu-title {
  font-size: clamp(36px, 6.4vw, 56px);
  font-weight: 800;
  letter-spacing: 5px;
  background: linear-gradient(110deg, #ffd27a, #ff8fa3, #9db6ff, #ffd27a);
  background-size: 250% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shine 6s linear infinite;
  filter: drop-shadow(0 6px 22px rgba(160, 130, 255, 0.25));
}

@keyframes shine {
  to { background-position: 250% center; }
}

.menu-sub {
  margin: 14px 0 40px;
  color: #9aa3b5;
  font-size: 15px;
  letter-spacing: 1px;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
}

.mode-card {
  --glow: rgba(255, 255, 255, 0.5);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 16px 22px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #eef0f6;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
  animation: card-in 0.5s ease backwards;
}

.mode-card[data-mode="bubble"]   { --glow: rgba(179, 139, 255, 0.55); animation-delay: 0.05s; }
.mode-card[data-mode="slicer"]   { --glow: rgba(255, 138, 76, 0.55);  animation-delay: 0.13s; }
.mode-card[data-mode="smash"]    { --glow: rgba(111, 182, 255, 0.55); animation-delay: 0.21s; }
.mode-card[data-mode="physics"]  { --glow: rgba(94, 224, 200, 0.55);  animation-delay: 0.29s; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* sheen sweep on hover */
.mode-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 32%, rgba(255, 255, 255, 0.14) 50%, transparent 68%);
  transform: translateX(-130%);
  transition: transform 0.65s ease;
  pointer-events: none;
}

.mode-card:hover {
  transform: translateY(-7px);
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 18px 40px -16px var(--glow), 0 8px 20px -12px rgba(0, 0, 0, 0.7);
}

.mode-card:hover::after {
  transform: translateX(130%);
}

.mode-card:active {
  transform: scale(0.96) translateY(-2px);
}

.card-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
}

.card-desc {
  font-size: 13px;
  color: #9aa3b5;
  line-height: 1.5;
}

/* card icons drawn in pure CSS */
.card-icon {
  width: 84px;
  height: 84px;
  border-radius: 20px;
  display: block;
  margin-bottom: 4px;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.mode-card:hover .card-icon {
  transform: scale(1.1) rotate(-4deg);
}

.card-icon-bubble {
  background-image: radial-gradient(circle 9px at 24px 24px, rgba(255,255,255,0.9) 0, rgba(255,255,255,0.9) 55%, rgba(255,255,255,0.2) 62%, transparent 72%),
                    radial-gradient(circle 9px at 60px 24px, rgba(255,255,255,0.9) 0, rgba(255,255,255,0.9) 55%, rgba(255,255,255,0.2) 62%, transparent 72%),
                    radial-gradient(circle 9px at 24px 60px, rgba(255,255,255,0.9) 0, rgba(255,255,255,0.9) 55%, rgba(255,255,255,0.2) 62%, transparent 72%),
                    radial-gradient(circle 9px at 60px 60px, rgba(255,255,255,0.9) 0, rgba(255,255,255,0.9) 55%, rgba(255,255,255,0.2) 62%, transparent 72%),
                    linear-gradient(135deg, #c0acff, #7a6bff);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25), 0 8px 20px -8px rgba(122, 107, 255, 0.8);
}

.card-icon-slicer {
  position: relative;
  background: radial-gradient(circle at 35% 30%, #fff3c4, #ffb347 45%, #e8590c 75%);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25), 0 8px 20px -8px rgba(232, 89, 12, 0.8);
}
.card-icon-slicer::after {
  content: "";
  position: absolute;
  left: -14%;
  top: 8%;
  width: 130%;
  height: 9px;
  transform: rotate(-28deg);
  background: rgba(255, 255, 255, 0.92);
  border-radius: 6px;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.6);
}

.card-icon-smash {
  background: conic-gradient(from 30deg, #8ab8ff, #5a7cff, #9b6bff, #ff7ab0, #8ab8ff);
  clip-path: polygon(50% 0%, 90% 20%, 100% 60%, 72% 100%, 28% 100%, 0 60%, 10% 20%);
  filter: drop-shadow(0 8px 16px rgba(120, 130, 255, 0.6));
}

.card-icon-physics {
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.16);
  position: relative;
  overflow: hidden;
}
.card-icon-physics::before {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fff, #7be0ff 60%, #2ea8e0);
  top: 14px;
  left: 16px;
  animation: bounce-icon 1.6s ease-in-out infinite;
  box-shadow: 0 0 14px rgba(123, 224, 255, 0.7);
}
.card-icon-physics::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fff, #ffd27a 60%, #ff9d2e);
  bottom: 14px;
  right: 18px;
  animation: bounce-icon 1.9s ease-in-out infinite reverse;
  box-shadow: 0 0 12px rgba(255, 210, 122, 0.7);
}

@keyframes bounce-icon {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.menu-tip {
  margin-top: 36px;
  color: #5d6679;
  font-size: 13px;
  letter-spacing: 0.5px;
}

@media (max-width: 640px) {
  .menu-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .card-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
  }
  .mode-card {
    padding: 18px 12px 16px;
  }
  .menu-inner {
    padding: 32px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .menu-title,
  #menu::before,
  #menu::after,
  .card-icon-physics::before,
  .card-icon-physics::after {
    animation: none;
  }
  .mode-card {
    animation: none;
  }
}
