*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  font-family: "Nunito", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.game-wrapper {
  position: relative;
  width: 100%;
  max-width: min(480px, 95vw);
  min-width: 320px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 4px rgba(255, 255, 255, 0.06);
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 480 / 600;
  max-height: 70vh;
  height: auto;
  background: linear-gradient(180deg, #87ceeb 0%, #e0f6ff 40%, #98d8aa 70%, #7bc67e 100%);
  cursor: pointer;
  touch-action: none;
}

.game-ui {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.35), transparent);
}

.score-label,
.high-score-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.85);
  margin-right: 4px;
}

.score-value,
.high-score-value {
  font-family: "Fredoka One", cursive;
  font-size: 22px;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.high-score-value {
  color: #ffd93d;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  padding: 24px;
  text-align: center;
}

.overlay.hidden {
  display: none;
}

/* Loading Overlay */
.overlay-loading {
  background: url('images/loading_bg.png') center/cover no-repeat, #87ceeb;
  z-index: 100;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.logo-3d {
  font-family: "Fredoka One", cursive;
  font-size: clamp(2.5rem, 10vw, 3.5rem);
  line-height: 1.1;
  text-align: center;
  margin: 0 0 20px;
}

.logo-3d .word1 {
  color: #ff6b6b;
  text-shadow:
    0 1px 0 #cc5555, 0 2px 0 #b34a4a, 0 3px 0 #993f3f,
    0 4px 10px rgba(0, 0, 0, 0.4);
}

.logo-3d .word2 {
  color: #4ade80;
  font-size: clamp(3rem, 12vw, 4rem);
  text-shadow:
    0 1px 0 #3baf66, 0 2px 0 #339955, 0 3px 0 #287a44,
    0 4px 10px rgba(0, 0, 0, 0.4);
}

.progress-bar-container {
  width: 260px;
  max-width: 90vw;
  height: 28px;
  background-color: #fff;
  border: 4px solid #333;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2);
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(180deg, #ff9f43 0%, #ff793f 100%);
  transition: width 0.1s linear;
  border-radius: 10px;
}

.loading-text {
  font-family: "Fredoka One", cursive;
  font-size: 1.25rem;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  animation: pulse 1s infinite alternate;
  margin: 0;
}

@keyframes pulse {
  0% {
    transform: scale(0.95);
    opacity: 0.8;
  }

  100% {
    transform: scale(1.05);
    opacity: 1;
  }
}

.overlay-start h1 {
  font-family: "Fredoka One", cursive;
  font-size: 2.5rem;
  color: #fff;
  margin: 0 0 16px;
  text-shadow: 0 4px 0 #6bcb77, 0 6px 12px rgba(0, 0, 0, 0.4);
}

.overlay-start p {
  color: rgba(255, 255, 255, 0.9);
  margin: 8px 0;
  font-size: 1rem;
}

.overlay-start kbd {
  display: inline-block;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9em;
}

.btn-start {
  margin-top: 24px;
  padding: 14px 40px;
  font-family: "Fredoka One", cursive;
  font-size: 1.25rem;
  color: #1a1a2e;
  background: linear-gradient(180deg, #6bcb77 0%, #4ade80 100%);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 0 #2d8a3e, 0 8px 20px rgba(0, 0, 0, 0.3);
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #2d8a3e, 0 10px 24px rgba(0, 0, 0, 0.35);
}

.btn-start:active {
  transform: translateY(2px);
  box-shadow: 0 4px 0 #2d8a3e, 0 6px 16px rgba(0, 0, 0, 0.3);
}

.overlay-gameover h2 {
  font-family: "Fredoka One", cursive;
  font-size: 2rem;
  color: #ff6b6b;
  margin: 0 0 8px;
}

.overlay-gameover p {
  color: rgba(255, 255, 255, 0.95);
  font-size: 1.1rem;
  margin: 8px 0;
}

.overlay-gameover #finalScoreEl {
  font-family: "Fredoka One", cursive;
  color: #ffd93d;
}

/* Mobile control buttons */
.mobile-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.mobile-controls .ctrl-btn {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.1s, background 0.1s;
}

.mobile-controls .ctrl-btn:active,
.mobile-controls .ctrl-btn.active {
  background: rgba(107, 203, 119, 0.8);
  transform: scale(0.95);
}

@media (hover: hover) {
  .mobile-controls .ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.35);
  }
}

.overlay-start .mobile-hint {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.75);
}