:root {
  --pink: #FFB6D1;
  --pink-deep: #FF6B9D;
  --mint: #7FD8BE;
  --mint-deep: #58C4A0;
  --yellow: #FFD93D;
  --sky: #B9E6FF;
  --cream: #FFF8E7;
  --text: #5A4B7A;
  --text-soft: #9788b2;
  --shadow: 0 12px 32px rgba(120, 90, 150, 0.18);
  --shadow-soft: 0 6px 20px rgba(120, 90, 150, 0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'Fredoka', 'ZCOOL KuaiLe', -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, #FFE6F0 0%, #E8F4FF 50%, #F0FFE8 100%);
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px 24px;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body::before, body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  filter: blur(20px);
}
body::before {
  width: 320px; height: 320px;
  background: radial-gradient(circle, rgba(255,182,209,0.55), transparent 70%);
  top: -110px; left: -110px;
  animation: float1 14s ease-in-out infinite;
}
body::after {
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(185,230,255,0.55), transparent 70%);
  bottom: -150px; right: -150px;
  animation: float2 18s ease-in-out infinite;
}
@keyframes float1 {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(30px, 40px); }
}
@keyframes float2 {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(-40px, -30px); }
}

.game-container {
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-radius: 28px;
  padding: 22px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  border: 2px solid rgba(255, 255, 255, 0.6);
}

.game-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.back-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: white;
  color: var(--pink-deep);
  font-size: 22px;
  font-weight: 700;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s ease;
}
.back-btn:hover { transform: translateX(-3px); }
.back-btn:active { transform: scale(0.92); }

.game-header h1 {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  background: linear-gradient(135deg, #FF6B9D, #6BCFBF);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}

.scores {
  display: flex;
  gap: 6px;
}

.score {
  background: white;
  padding: 6px 12px;
  border-radius: 14px;
  font-size: 11px;
  font-weight: 500;
  box-shadow: var(--shadow-soft);
  text-align: center;
  min-width: 54px;
}
.score .label {
  display: block;
  font-size: 10px;
  color: var(--text-soft);
  margin-bottom: 2px;
}
.score span:last-child {
  font-size: 16px;
  font-weight: 700;
  color: var(--pink-deep);
}
.score.best span:last-child { color: var(--yellow); }

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 20px;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 3px rgba(127,216,190,0.4),
    0 4px 16px rgba(120,90,150,0.1);
  background: #E8F6E0;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 248, 231, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 1;
  transition: opacity 0.3s ease;
}
.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  background: white;
  padding: 28px 32px 24px;
  border-radius: 24px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 90%;
  border: 2px solid rgba(255, 182, 209, 0.4);
  animation: pop 0.45s cubic-bezier(.34,1.56,.64,1);
}
@keyframes pop {
  from { transform: scale(0.75); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.overlay-emoji {
  font-size: 52px;
  line-height: 1;
  margin-bottom: 8px;
  display: inline-block;
  animation: wave 2s ease-in-out infinite;
}
@keyframes wave {
  0%, 100% { transform: rotate(-8deg); }
  50%      { transform: rotate(8deg); }
}
.overlay-card h2 {
  font-size: 22px;
  margin-bottom: 10px;
  color: var(--pink-deep);
  font-weight: 600;
}
.overlay-card p {
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 18px;
  line-height: 1.6;
}
#start-btn {
  background: linear-gradient(135deg, #FF6B9D, #FFB6D1);
  border: none;
  color: white;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 30px;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(255,107,157,0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
  letter-spacing: 0.5px;
}
#start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(255,107,157,0.5);
}
#start-btn:active { transform: translateY(0); }

.dpad {
  margin-top: 18px;
  display: none;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 6px;
  justify-content: center;
}
.dpad-btn {
  background: white;
  border: none;
  border-radius: 14px;
  font-size: 18px;
  color: var(--pink-deep);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s ease, background 0.1s ease;
  touch-action: manipulation;
}
.dpad-btn:active {
  background: #FFE0EC;
  transform: scale(0.92);
}
.dpad-btn.up    { grid-column: 2; grid-row: 1; }
.dpad-btn.left  { grid-column: 1; grid-row: 2; }
.dpad-btn.down  { grid-column: 2; grid-row: 3; }
.dpad-btn.right { grid-column: 3; grid-row: 2; }

@media (hover: none) and (pointer: coarse) {
  .dpad { display: grid; }
}

.hints {
  margin-top: 14px;
  text-align: center;
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.6;
}
.hints p + p { margin-top: 2px; }

.shake {
  animation: shake 0.45s cubic-bezier(.36,.07,.19,.97);
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-6px); }
  20%, 40%, 60%, 80% { transform: translateX(6px); }
}

@media (max-width: 520px) {
  .game-container { padding: 16px; border-radius: 22px; }
  .game-header h1 { font-size: 18px; }
  .back-btn { width: 36px; height: 36px; font-size: 20px; }
  .score { padding: 5px 10px; min-width: 48px; }
  .score span:last-child { font-size: 14px; }
  .overlay-card { padding: 24px 24px 20px; }
  .overlay-emoji { font-size: 44px; }
  .overlay-card h2 { font-size: 20px; }
}
