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

html, body {
  height: 100%;
  background: radial-gradient(circle at 50% 0%, #2e4c1e, #16240e 70%);
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #fff;
  overflow-x: hidden;
  image-rendering: pixelated;
}

.cabinet {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 12px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100%;
}

.marquee {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  padding: 10px 20px;
  background: linear-gradient(180deg, #5d9c3f, #3f7d2c);
  border: 3px solid #2e4c1e;
  border-radius: 6px;
  box-shadow: 0 0 20px rgba(93, 156, 63, 0.5), inset 0 -4px 0 rgba(0,0,0,0.25);
  margin-bottom: 10px;
  letter-spacing: 1px;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.35);
}

.hud {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: space-between;
  background: rgba(0,0,0,0.35);
  border: 2px solid #ffb703;
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  font-size: 1.1rem;
  font-weight: 700;
}

.hud-item .label {
  font-size: 0.65rem;
  font-weight: 500;
  color: #ffd166;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.viewport {
  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 4 / 3;
  background: linear-gradient(180deg, #bfe8ff 0%, #dff3ff 40%, #eaf8ff 100%);
  border: 10px solid #6e4620;
  border-radius: 6px;
  box-shadow:
    0 0 0 4px #3f2c14,
    0 0 30px rgba(62, 44, 20, 0.6),
    inset 0 0 40px rgba(255,255,255,0.4);
  overflow: hidden;
  perspective: 900px;
  perspective-origin: 50% 15%;
}

.scene {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.floor {
  position: absolute;
  left: 8%;
  top: 42%;
  width: 84%;
  height: 50%;
  background: linear-gradient(180deg, #6e4620, #5c3a18);
  border-radius: 4px;
  transform: rotateX(58deg);
  transform-style: preserve-3d;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.25);
  border: 3px solid #3f2c14;
}

.pit-wall {
  position: absolute;
  background: linear-gradient(180deg, rgba(255,255,255,0.22), rgba(255,255,255,0.02) 60%);
  border: 1px solid rgba(255,255,255,0.25);
  box-shadow: inset 0 -20px 30px rgba(0,0,0,0.25);
}

.wall-back {
  left: 0;
  top: 0;
  width: 100%;
  height: 85px;
  transform-origin: top center;
  transform: rotateX(90deg);
}

.wall-left {
  left: 0;
  top: 0;
  width: 85px;
  height: 100%;
  transform-origin: left center;
  transform: rotateY(-90deg);
}

.wall-right {
  right: 0;
  top: 0;
  width: 85px;
  height: 100%;
  transform-origin: right center;
  transform: rotateY(90deg);
}

.chute-hole {
  position: absolute;
  right: 4%;
  top: 4%;
  width: 22%;
  height: 22%;
  background: radial-gradient(circle at 50% 50%, #0a0a0a, #2e4c1e);
  border-radius: 50%;
  box-shadow: inset 0 0 12px rgba(0,0,0,0.8), 0 0 8px rgba(93, 156, 63, 0.4);
  transform: translateZ(1px);
}

.items {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.item {
  --depth-scale: 1;
  position: absolute;
  line-height: 0;
  transform-style: preserve-3d;
  perspective: 220px;
  transform: translate(-50%, -50%) translateZ(2px) rotateX(-58deg) scale3d(var(--depth-scale), var(--depth-scale), var(--depth-scale));
  transition: opacity 0.25s, transform 0.25s;
  image-rendering: pixelated;
}

.cube {
  position: relative;
  width: 26px;
  height: 26px;
  transform-style: preserve-3d;
  transform: rotateX(-25deg) rotateY(35deg);
}

.face {
  position: absolute;
  inset: 0;
  width: 26px;
  height: 26px;
  backface-visibility: hidden;
}

.face svg {
  display: block;
  width: 100%;
  height: 100%;
}

.face-front { transform: translateZ(13px); filter: drop-shadow(3px 6px 3px rgba(0,0,0,0.4)); }
.face-top { transform: rotateX(90deg) translateZ(13px); filter: brightness(1.3); }
.face-side { transform: rotateY(90deg) translateZ(13px); filter: brightness(0.65); }

.item.grabbed {
  z-index: 5;
}

.item.falling {
  opacity: 0;
  transform: translate(-50%, -50%) translateZ(2px) rotateX(-58deg) scale3d(0.3, 0.3, 0.3);
}

.item.held {
  position: absolute;
  left: 50%;
  top: 2px;
  transform-style: preserve-3d;
  transform: translate(-50%, 0) scale(0.8);
  z-index: 6;
}

.item.held .cube {
  width: 22px;
  height: 22px;
}

.item.held .face { width: 22px; height: 22px; }
.item.held .face-front { transform: translateZ(11px); }
.item.held .face-top { transform: rotateX(90deg) translateZ(11px); }
.item.held .face-side { transform: rotateY(90deg) translateZ(11px); }

.item.held.falling {
  transform: translate(-50%, 0) scale(0.15);
  opacity: 0;
}

.claw-shadow {
  position: absolute;
  width: 15%;
  height: 8%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) translateZ(1px);
  background: radial-gradient(ellipse at center, rgba(20, 5, 30, 0.4) 0%, rgba(20, 5, 30, 0.18) 55%, transparent 75%);
  filter: blur(5px);
  pointer-events: none;
  transition: width 0.4s ease, height 0.4s ease, opacity 0.4s ease;
}

.claw-rig {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  z-index: 4;
}

.cable {
  position: absolute;
  left: 0;
  top: -130px;
  width: 4px;
  height: 130px;
  background: linear-gradient(180deg, #444, #999);
  transform-origin: top center;
  transform: translateX(-2px);
}

.claw {
  position: absolute;
  bottom: -6px;
  left: -18px;
  width: 40px;
  height: 30px;
}

.prong {
  position: absolute;
  width: 8px;
  height: 26px;
  background: linear-gradient(180deg, #d8d8d8, #8c8c8c);
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.5);
  transform-origin: top center;
  transition: transform 0.3s ease;
}

.prong-left { left: 2px; transform: rotate(-18deg); }
.prong-right { right: 2px; transform: rotate(18deg); }
.prong-back { left: 16px; transform: rotate(0deg); }

.claw.closed .prong-left { transform: rotate(6deg); }
.claw.closed .prong-right { transform: rotate(-6deg); }
.claw.closed .prong-back { transform: rotate(0deg) scaleY(0.85); }

.prize-tray {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 15%;
  background: linear-gradient(180deg, #3a1d5c, #241040);
  border-top: 3px solid #ffb703;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  overflow-x: auto;
}

.tray-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #ffd166;
  white-space: nowrap;
}

.tray-items {
  display: flex;
  gap: 4px;
  align-items: center;
}

.tray-items svg {
  width: 22px;
  height: 22px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.coin-slot {
  position: absolute;
  top: 6px;
  right: 10px;
  width: 34px;
  height: 34px;
  background: #222;
  border: 2px solid #ffb703;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  perspective: 160px;
}

.coin {
  font-size: 1.2rem;
  transform: translateY(-70px);
  opacity: 0;
  transform-style: preserve-3d;
  filter: drop-shadow(0 0 2px rgba(255, 219, 112, 0.8));
}

.coin.drop {
  animation: coinDrop 0.75s cubic-bezier(0.4, 0, 0.7, 1) forwards;
}

@keyframes coinDrop {
  0% { transform: translateY(-70px) rotateY(0deg) rotateX(0deg) scale(1); opacity: 1; }
  35% { transform: translateY(-24px) rotateY(360deg) rotateX(160deg) scale(1.05); opacity: 1; }
  65% { transform: translateY(2px) rotateY(680deg) rotateX(340deg) scale(1); opacity: 1; }
  100% { transform: translateY(28px) rotateY(900deg) rotateX(430deg) scale(0.55); opacity: 0; }
}

.message-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 4, 20, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  border-radius: 8px;
}

.message-overlay.hidden {
  display: none;
}

.message-box {
  text-align: center;
  padding: 24px 20px;
  max-width: 90%;
}

.message-box h1 {
  font-size: 1.6rem;
  margin-bottom: 10px;
  color: #ffd166;
}

.message-box p {
  margin-bottom: 18px;
  line-height: 1.4;
}

#startBtn {
  font-size: 1.1rem;
  font-weight: 800;
  padding: 12px 22px;
  border: none;
  border-radius: 30px;
  background: linear-gradient(180deg, #ffd166, #ffb703);
  color: #3a1d5c;
  cursor: pointer;
  box-shadow: 0 4px 0 #b5820a, 0 6px 12px rgba(0,0,0,0.4);
  transition: transform 0.1s;
}

#startBtn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #b5820a, 0 2px 6px rgba(0,0,0,0.4);
}

.controls {
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  gap: 16px;
}

.dpad {
  position: relative;
  width: 120px;
  height: 120px;
  flex-shrink: 0;
}

.dbtn {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: none;
  background: #4a2678;
  color: #fff;
  font-size: 1.1rem;
  box-shadow: 0 3px 0 #2c1650;
  cursor: pointer;
}

.dbtn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #2c1650;
}

.dup { top: 0; left: 40px; }
.ddown { bottom: 0; left: 40px; }
.dleft { top: 40px; left: 0; }
.dright { top: 40px; right: 0; }

.grab-btn {
  flex: 1;
  max-width: 220px;
  padding: 18px 10px;
  font-size: 1.2rem;
  font-weight: 800;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, #ff5f6d, #d81159);
  color: #fff;
  box-shadow: 0 5px 0 #8a0c3a, 0 8px 14px rgba(0,0,0,0.4);
  cursor: pointer;
}

.grab-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #8a0c3a, 0 4px 8px rgba(0,0,0,0.4);
}

.hint {
  margin-top: 10px;
  font-size: 0.75rem;
  color: #b9a6d9;
  text-align: center;
}

@media (max-width: 480px) {
  .marquee { font-size: 1.2rem; }
  .hud-item { font-size: 0.9rem; }
  .dpad { width: 100px; height: 100px; }
  .dbtn { width: 34px; height: 34px; }
  .dup, .ddown { left: 33px; }
  .dleft, .dright { top: 33px; }
}
