@import url("https://fonts.googleapis.com/css2?family=Cairo:wght@400;700;800&display=swap");

:root {
  --bg1: #fff8fc;
  --bg2: #f7f0ff;
  --pink: #ff78b2;
  --pink-dark: #e25595;
  --purple: #9b7bff;
  --text: #3b2d52;
  --muted: #7d6f92;
  --card: rgba(255, 255, 255, 0.88);
  --shadow: 0 18px 45px rgba(110, 74, 146, 0.14);
  --shadow-soft: 0 10px 24px rgba(110, 74, 146, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow: hidden;
  height: 100%;
  width: 100%;
  position: relative;
  font-family: "Cairo", sans-serif;
  background:
    radial-gradient(circle at top right, rgba(255, 203, 227, 0.6), transparent 26%),
    radial-gradient(circle at bottom left, rgba(209, 216, 255, 0.8), transparent 34%),
    linear-gradient(135deg, var(--bg1), var(--bg2));
  color: var(--text);
}

#container {
  width: 100%;
  height: 100%;
  position: relative;
}

#game {
  position: absolute;
  inset: 0;
}

.topbar {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.back-link,
.brand {
  pointer-events: auto;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-soft);
  font-weight: 800;
  text-decoration: none;
}

.back-link {
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
}

.brand {
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--purple));
}

#hud {
  position: absolute;
  top: 74px;
  left: 0;
  width: 100%;
  z-index: 20;
  text-align: center;
  pointer-events: none;
}

.title {
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
}

#score {
  font-size: clamp(42px, 12vw, 76px);
  line-height: 1;
  font-weight: 800;
  color: var(--text);
  transition: transform 0.5s ease;
  transform: translateY(-180px) scale(1);
}

#instructions {
  width: min(92%, 440px);
  margin: 14px auto 0;
  padding: 12px 16px;
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 15px;
  line-height: 1.8;
  transition: opacity 0.5s ease, transform 0.5s ease;
  opacity: 0;
}

#instructions.hide {
  opacity: 0 !important;
  transform: translateY(-10px);
}

.game-over,
.game-ready {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 25;
  pointer-events: none;
  text-align: center;
  padding: 20px;
}

.game-over * {
  transition: opacity 0.5s ease, transform 0.5s ease;
  opacity: 0;
  transform: translateY(-40px);
  color: var(--text);
}

.game-over h2 {
  margin: 0 0 8px;
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 800;
}

.game-over p {
  margin: 4px 0;
  font-size: 16px;
  color: var(--muted);
  font-weight: 700;
}

.game-ready #start-button {
  pointer-events: auto;
  transition: opacity 0.5s ease, transform 0.5s ease, background 0.25s ease;
  opacity: 0;
  transform: translateY(-40px);
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: #fff;
  font-size: clamp(20px, 4vw, 28px);
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.game-ready #start-button:hover {
  filter: brightness(1.04);
}

#container.playing #score,
#container.resetting #score {
  transform: translateY(0) scale(1);
}

#container.playing #instructions {
  opacity: 1;
}

#container.ready .game-ready #start-button {
  opacity: 1;
  transform: translateY(0);
}

#container.ended #score {
  transform: translateY(20px) scale(1.35);
}

#container.ended .game-over * {
  opacity: 1;
  transform: translateY(0);
}

#container.ended .game-over p {
  transition-delay: 0.2s;
}

footer {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  width: calc(100% - 20px);
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
}

canvas {
  display: block;
}

@media (max-width: 600px) {
  .topbar {
    top: 10px;
    left: 10px;
    right: 10px;
  }

  .back-link,
  .brand {
    min-height: 38px;
    padding: 0 12px;
    font-size: 13px;
  }

  #hud {
    top: 64px;
  }

  #instructions {
    font-size: 14px;
    padding: 10px 14px;
  }

  footer {
    font-size: 12px;
  }
}