* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a0a1e;
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

#game-wrapper {
  position: fixed;
  inset: 0;
  z-index: 300;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #2d1b4e 0%, #ff9ecf 40%, #ffb6d9 100%);
}

#game-wrapper:not(.hidden) {
  pointer-events: auto;
}

#game-wrapper.hidden {
  visibility: hidden;
  pointer-events: none;
  z-index: 0;
}

#gameCanvas {
  display: block;
  position: relative;
  z-index: 1;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(255, 105, 180, 0.4);
  max-width: 100%;
  max-height: calc(100vh - 40px);
  background: #3d1f5c;
}

#hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 40;
}

.hud-left, .hud-right {
  background: rgba(255, 182, 217, 0.85);
  border: 2px solid #ff69b4;
  border-radius: 12px;
  padding: 8px 16px;
  color: #5a1a4a;
  font-weight: 700;
  font-size: clamp(12px, 2.5vw, 16px);
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 8px rgba(255, 105, 180, 0.3);
}

.hud-left span {
  display: block;
  margin: 2px 0;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(26, 10, 30, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.overlay.hidden {
  display: none;
}

.panel {
  background: linear-gradient(145deg, #ffb6d9, #ff9ecf);
  border: 4px solid #ff69b4;
  border-radius: 24px;
  padding: clamp(24px, 5vw, 48px);
  max-width: 90vw;
  width: 480px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(255, 105, 180, 0.5),
              inset 0 2px 0 rgba(255, 255, 255, 0.4);
}

.panel h1 {
  color: #5a1a4a;
  font-size: clamp(24px, 5vw, 36px);
  margin-bottom: 8px;
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.3);
}

.panel h2 {
  color: #5a1a4a;
  font-size: clamp(20px, 4vw, 28px);
  margin-bottom: 12px;
}

.subtitle {
  color: #8b3a7a;
  font-size: clamp(14px, 2.5vw, 18px);
  margin-bottom: 16px;
  font-style: italic;
}

.desc {
  color: #5a1a4a;
  font-size: clamp(13px, 2vw, 15px);
  line-height: 1.6;
  margin-bottom: 24px;
}

.controls-info {
  margin-top: 20px;
  text-align: left;
  font-size: clamp(11px, 2vw, 13px);
  color: #6b2a5a;
  line-height: 1.8;
}

.hint {
  margin: 12px 0 16px;
  font-size: clamp(12px, 2vw, 14px);
  color: #6b2a5a;
}

.btn-primary {
  background: linear-gradient(180deg, #ff69b4, #e0409a);
  color: white;
  border: none;
  border-radius: 16px;
  padding: 14px 40px;
  font-size: clamp(16px, 3vw, 20px);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 #b03070, 0 6px 16px rgba(255, 105, 180, 0.4);
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #b03070;
}

.victory-panel h1 {
  font-size: clamp(28px, 6vw, 42px);
  color: #ffd700;
  text-shadow: 2px 2px 0 #ff69b4;
}

.stats {
  margin: 16px 0;
  font-size: 15px;
  color: #5a1a4a;
}

#touchControls {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 40;
  pointer-events: none;
}

.dpad, .action-btns {
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.touch-btn {
  width: clamp(56px, 14vw, 72px);
  height: clamp(56px, 14vw, 72px);
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 182, 217, 0.75);
  color: #5a1a4a;
  font-size: clamp(16px, 4vw, 22px);
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 12px rgba(255, 105, 180, 0.4);
  touch-action: manipulation;
}

.touch-btn.action {
  background: rgba(255, 105, 180, 0.85);
  color: white;
  width: clamp(64px, 16vw, 80px);
  height: clamp(64px, 16vw, 80px);
}

.touch-btn:active {
  background: rgba(255, 69, 180, 0.95);
  transform: scale(0.95);
}

@media (min-width: 1024px) and (hover: hover) and (pointer: fine) {
  #touchControls {
    opacity: 0.55;
  }
}

@media (hover: none), (pointer: coarse) {
  #touchControls {
    opacity: 1;
  }
  .touch-btn {
    width: clamp(64px, 16vw, 84px);
    height: clamp(64px, 16vw, 84px);
    background: rgba(255, 105, 180, 0.92);
    border-color: #fff;
    color: #fff;
    font-size: clamp(18px, 4.5vw, 24px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.35);
  }
  .touch-btn.action {
    width: clamp(72px, 18vw, 92px);
    height: clamp(72px, 18vw, 92px);
    background: rgba(255, 40, 140, 0.95);
  }
}

.overlay.tap-anywhere {
  cursor: pointer;
}

.overlay.anim-death .splat-blob {
  animation: splatPop 0.6s ease-out;
}

@keyframes splatPop {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 0.85; }
}

.splat-blob {
  width: 120px;
  height: 120px;
  margin: 0 auto 16px;
  background: radial-gradient(circle, #ff69b4 30%, #ff1493 70%, transparent 72%);
  border-radius: 50% 40% 55% 45%;
}

.overlay.anim-win .star-icon,
.star-burst .star-icon {
  font-size: 64px;
  color: gold;
  animation: starSpin 1s ease infinite alternate;
  text-shadow: 0 0 20px gold;
}

@keyframes starSpin {
  from { transform: scale(1) rotate(-10deg); }
  to { transform: scale(1.2) rotate(10deg); }
}

@media (max-width: 480px) {
  #hud {
    top: 6px;
    left: 6px;
    right: 6px;
  }
  .hud-left, .hud-right {
    padding: 6px 10px;
  }
}
