html, body {
  margin: 0;
  height: 100%;
  background: #15171c;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* The game is authored at 720x540 and uniformly scaled to fit the window (scale = 1 in Storyline). */
#game {
  position: relative;
  flex: none;
  width: 720px;
  height: 540px;
  overflow: hidden;
  background: #fff;
  transform-origin: center center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  font-family: "Trebuchet MS", "Comic Sans MS", Verdana, sans-serif;
}

#game img { display: block; user-select: none; -webkit-user-drag: none; }
#bg, #digital, #hands, #fx { position: absolute; left: 0; top: 0; width: 720px; height: 540px; }
#hands, #fx { pointer-events: none; }
#hub { position: absolute; pointer-events: none; }

/* ---------- hands ---------- */
.hand {
  position: absolute;
  cursor: grab;
  pointer-events: auto;
  will-change: transform;
  transition: transform 0.14s ease-out;
  outline: none;
}
.hand.dragging { cursor: grabbing; transition: transform 0.06s linear; }
.hand:focus-visible { filter: drop-shadow(0 0 5px #fff) drop-shadow(0 0 4px #7b3ff2); }
.hand.locked { cursor: default; }

/* ---------- replay hotspot (sits over the speaker icon baked into the artwork) ---------- */
#replay {
  position: absolute;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s;
}
#replay:hover { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.85), 0 0 14px 4px rgba(123, 63, 242, 0.7); }
#replay:active { transform: scale(0.92); }
#replay:focus-visible { outline: 3px solid #fff; box-shadow: 0 0 12px 4px rgba(123, 63, 242, 0.8); }
#replay.speaking { animation: speaking 0.9s ease-in-out infinite; }
@keyframes speaking {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.9), 0 0 0 0 rgba(123, 63, 242, 0.6); }
  50%      { box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.9), 0 0 16px 8px rgba(123, 63, 242, 0.6); }
}

/* ---------- overlays (game artwork stays visible behind) ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.35s ease, visibility 0.35s;
}
.overlay.dim {
  background: rgba(18, 28, 60, 0.45);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.overlay.hidden, #controls.hidden { opacity: 0; pointer-events: none; visibility: hidden; }
.overlay button {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.overlay button.round {
  background: #fff;
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.55), 0 10px 26px rgba(0, 0, 0, 0.45);
  line-height: 0;
}
.overlay button:hover { transform: scale(1.07); }
.overlay button:active { transform: scale(0.96); }
.overlay button:focus-visible { outline: 4px solid #ffd400; outline-offset: 8px; }
.overlay .pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.55), 0 10px 26px rgba(0, 0, 0, 0.45); }
  50%      { box-shadow: 0 0 0 14px rgba(255, 255, 255, 0.25), 0 10px 26px rgba(0, 0, 0, 0.45); }
}
.caption {
  margin: 18px 0 0;
  font-size: 26px;
  font-weight: bold;
  color: #fff;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}
#end h1 { margin: 0 0 6px; font-size: 64px; color: #ffe14a; text-shadow: 0 3px 8px rgba(0, 0, 0, 0.6); }
#end p#endScore { margin: 0 0 22px; font-size: 26px; color: #fff; font-weight: bold; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6); }

/* ---------- in-game controls (match the purple speaker button) ---------- */
#controls {
  position: absolute;
  top: 24px; right: 18px;
  z-index: 30;
  display: flex;
  gap: 10px;
  transition: opacity 0.2s;
}
.ctl {
  width: 40px; height: 40px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #9b6bff, #5b2ad6 70%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
}
.ctl svg { width: 22px; height: 22px; fill: #fff; display: block; margin: auto; }
.ctl:hover { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.8), 0 0 12px 4px rgba(123, 63, 242, 0.7); }
.ctl:active { transform: scale(0.92); }
.ctl:focus-visible { outline: 3px solid #ffd400; outline-offset: 2px; }
.ctl .i-play { display: none; }
.ctl.is-paused .i-play { display: block; }
.ctl.is-paused .i-pause { display: none; }

/* ---------- feedback ---------- */
.ring {
  position: absolute;
  left: 0; top: 0;
  border-radius: 50%;
  border: 12px solid #3ccf4e;
  box-sizing: border-box;
  opacity: 0;
  animation: ring 0.9s ease-out forwards;
}
@keyframes ring {
  0%   { transform: scale(0.55); opacity: 0.95; }
  100% { transform: scale(1.12); opacity: 0; }
}
.spark {
  position: absolute;
  width: 26px; height: 26px;
  margin: -13px 0 0 -13px;
  background: #ffd400;
  clip-path: polygon(50% 0, 62% 36%, 100% 38%, 70% 60%, 80% 100%, 50% 76%, 20% 100%, 30% 60%, 0 38%, 38% 36%);
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.35));
  animation: spark 0.95s cubic-bezier(0.15, 0.7, 0.3, 1) forwards;
}
@keyframes spark {
  0%   { transform: translate(0, 0) scale(0.3) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(200deg); opacity: 0; }
}
#hands.shake, #digital.shake { animation: shake 0.45s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .hand, .hand.dragging { transition: none; }
  .ring, .spark, #hands.shake, #digital.shake, #replay.speaking { animation: none; }
}
