html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #1b1340;
  font-family: "Segoe UI", "Comic Sans MS", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: relative;
  width: 540px;
  height: 820px;
  margin: 0 auto;
  transform-origin: top center;
}

#game {
  display: block;
  width: 540px;
  height: 820px;
  touch-action: none;
  cursor: crosshair;
}

/* ===== overlay panels ===== */
.panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(20, 12, 60, 0.88);
  z-index: 10;
  text-align: center;
}

.hidden { display: none !important; }

.title {
  font-size: 64px;
  margin: 0 0 4px 0;
  color: #ffd32a;
  text-shadow: 0 4px 0 #b8860b, 0 8px 18px rgba(0,0,0,.5);
  letter-spacing: 1px;
}
.title span { color: #4ecdff; text-shadow: 0 4px 0 #1a6fa8, 0 8px 18px rgba(0,0,0,.5); }

.tagline {
  color: #cfc6ff;
  font-size: 18px;
  margin: 0 0 18px 0;
}

.panel h1 { color: #fff; font-size: 48px; margin: 0; }
.panel h2 { color: #cfc6ff; font-size: 22px; margin: 6px 0 0 0; font-weight: 600; }
.panel p  { color: #ffd32a; font-size: 26px; font-weight: 700; margin: 0; }

.bigbtn {
  font-family: inherit;
  font-size: 26px;
  font-weight: 800;
  padding: 16px 44px;
  border: 0;
  border-radius: 40px;
  cursor: pointer;
  color: #fff;
  min-width: 300px;
  transition: transform .16s ease, filter .16s ease, box-shadow .16s ease;
}
.bigbtn:hover { transform: translateY(-2px) scale(1.035); filter: brightness(1.08); }
.bigbtn:active { transform: scale(.97); }
.bigbtn.play { background: linear-gradient(#3ae374, #1fa84c); box-shadow: 0 6px 0 #157a36; }
.bigbtn.math { background: linear-gradient(#4ecdff, #1e90ff); box-shadow: 0 6px 0 #1362ad; }

.linkbtn {
  background: none;
  border: 0;
  color: #a99ee0;
  font-size: 17px;
  cursor: pointer;
  font-family: inherit;
}
.linkbtn:hover { color: #fff; }

.optrow { display: flex; gap: 10px; justify-content: center; }
.optrow.wrap { flex-wrap: wrap; max-width: 430px; gap: 8px; }

.optbtn.tiny { width: auto; height: auto; font-size: 14px; padding: 8px 12px; }

.opthint {
  color: #a99ee0;
  font-size: 14px;
  margin: -4px 0 0 0;
  line-height: 1.35;
}

.optbtn {
  font-family: inherit;
  font-size: 30px;
  font-weight: 800;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  border: 3px solid #5a4aa8;
  background: #2a1e6e;
  color: #cfc6ff;
  cursor: pointer;
}
.optbtn.small { width: auto; height: auto; font-size: 18px; padding: 10px 18px; }
.optbtn.selected {
  background: linear-gradient(#ffd32a, #f0a500);
  border-color: #fff;
  color: #4a3200;
}

#muteBtn, #homeBtn {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 20;
  width: 42px;
  height: 42px;
  font-size: 20px;
  border-radius: 50%;
  border: 0;
  background: rgba(255,255,255,.15);
  color: #fff;
  cursor: pointer;
}
#muteBtn:hover, #homeBtn:hover { background: rgba(255,255,255,.3); }
#homeBtn { right: auto; left: 14px; font-size: 24px; }

/* ===== polished result reveal ===== */
#overlay {
  background:
    radial-gradient(circle at 50% 38%, rgba(68, 48, 142, .92), rgba(12, 8, 38, .97) 64%);
  backdrop-filter: blur(5px);
}

#overlay:not(.hidden) {
  animation: resultBackdropIn .36s ease-out both;
}

#overlay:not(.hidden) > * {
  animation: resultCardIn .48s cubic-bezier(.2, .85, .25, 1.15) both;
}

#overlay:not(.hidden) > :nth-child(2) { animation-delay: .06s; }
#overlay:not(.hidden) > :nth-child(3) { animation-delay: .11s; }
#overlay:not(.hidden) > :nth-child(4) { animation-delay: .16s; }

#overlayTitle {
  color: #fff;
  text-shadow: 0 3px 0 #8f2639, 0 9px 26px rgba(255, 71, 87, .42);
}

#overlayScore {
  min-width: 280px;
  box-sizing: border-box;
  padding: 13px 22px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 18px;
  background: rgba(15, 10, 45, .56);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.1), 0 10px 30px rgba(0,0,0,.22);
}

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

@keyframes resultCardIn {
  from { opacity: 0; transform: translateY(22px) scale(.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  #overlay:not(.hidden), #overlay:not(.hidden) > * { animation: none; }
  .bigbtn { transition: none; }
}
