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

body {
  background-color: #121212;
  color: #fff;
  font-family: 'Pretendard', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  height: auto;
  overflow: auto;
  touch-action: none;
}

#game-wrapper {
  position: relative;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 9 / 16;
  max-height: 90vh;
  min-width: 260px;
  min-height: 400px;
  background-color: #1e1e1e;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  border-radius: 12px;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 20px;
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.score-box {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 16px;
  border-radius: 20px;
  transition: transform 0.2s;
}

.new-best-anim {
  color: #ffd700 !important;
  animation: pulse-gold 0.8s infinite alternate;
}

@keyframes pulse-gold {
  0% {
    transform: scale(1);
    text-shadow: 0 0 5px #ffd700;
  }
  100% {
    transform: scale(1.1);
    text-shadow: 0 0 20px #ffd700, 0 0 30px #ffa500;
  }
}

#message-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 1;
  transition: opacity 0.3s ease;
  pointer-events: auto;
}

#message-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

h1 {
  font-size: 36px;
  margin-bottom: 10px;
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

p {
  color: #aaa;
  margin-bottom: 30px;
  font-size: 16px;
}

button {
  background: linear-gradient(90deg, #4ecdc4, #556270);
  border: none;
  padding: 15px 40px;
  color: white;
  font-size: 18px;
  font-weight: bold;
  border-radius: 30px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(78, 205, 196, 0.4);
  transition: transform 0.1s;
}

button:active {
  transform: scale(0.95);
}

.helper-text {
  position: absolute;
  bottom: 100px;
  width: 100%;
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
  font-size: 14px;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    opacity: 0.3;
  }
  50% {
    opacity: 0.8;
  }
  100% {
    opacity: 0.3;
  }
}

/* Very small screens: tighten paddings and font sizes */
@media (max-width: 360px) {
  .ui-layer {
    padding: 12px;
  }

  .header {
    font-size: 16px;
  }

  .score-box {
    padding: 4px 10px;
  }

  h1 {
    font-size: 28px;
  }

  p {
    font-size: 14px;
    margin-bottom: 20px;
  }

  button {
    padding: 10px 24px;
    font-size: 16px;
  }

  .helper-text {
    bottom: 70px;
    font-size: 12px;
  }
}

/* Very short viewports: allow wrapper to use full height */
@media (max-height: 500px) {
  #game-wrapper {
    max-height: 100vh;
  }
}