@import url("https://fonts.googleapis.com/css?family=Comfortaa|Poppins:600&display=swap");

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: "Comfortaa", cursive;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

html { overscroll-behavior: none; }
body { overscroll-behavior: none; touch-action: manipulation; }

button, .menu-btn {
  touch-action: manipulation;
}

#game {
  touch-action: none;
}

::-webkit-scrollbar {
  display: none;
}

#scroll-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

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

#container #score {
  position: absolute;
  top: 20px;
  width: 100%;
  text-align: center;
  font-size: 10vh;
  transition: transform 0.5s ease;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.35), 0 4px 16px rgba(0,0,0,0.35);
  transform: translatey(-200px) scale(1);
  z-index: 10;
}

#container #game {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

#container .game-over {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 85%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#container .game-over * {
  transition: opacity 0.5s ease, transform 0.5s ease;
  opacity: 0;
  transform: translatey(-50px);
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.35), 0 4px 16px rgba(0,0,0,0.35);
}

#container .game-over h2 {
  margin: 0;
  padding: 0;
  font-size: 40px;
}

#container .game-ready {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
}

#container .game-ready #start-button {
  transition: opacity 0.5s ease, transform 0.5s ease;
  opacity: 0;
  transform: translatey(-50px);
  border: 3px solid rgba(255,255,255,0.5);
  padding: 10px 20px;
  background-color: transparent;
  color: #fff;
  font-size: 30px;
  border-radius: 12px;
  cursor: pointer;
  font-family: "Comfortaa", cursive;
  backdrop-filter: blur(5px);
}

#container #instructions {
  position: absolute;
  width: 100%;
  top: 16vh;
  left: 0;
  text-align: center;
  transition: opacity 0.5s ease, transform 0.5s ease;
  opacity: 0;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.35), 0 4px 16px rgba(0,0,0,0.35);
}

#container #instructions.hide {
  opacity: 0 !important;
}

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

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

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

#container.ended #score {
  transform: translatey(6vh) scale(1.5);
}

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

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

/* =================== MAIN MENU =================== */
.menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  animation: gradientShift 8s ease infinite alternate;
  background-size: 200% 200%;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.menu-bg {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  overflow: hidden;
  z-index: 0;
}

.cloud {
  position: absolute;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  backdrop-filter: blur(2px);
  animation: floatCloud 20s ease-in-out infinite;
}

.cloud-1 {
  width: 300px; height: 120px;
  top: 10%; left: -10%;
  animation-delay: 0s;
}

.cloud-2 {
  width: 400px; height: 140px;
  top: 25%; right: -15%;
  animation-delay: -5s;
  background: rgba(255,255,255,0.1);
}

.cloud-3 {
  width: 250px; height: 100px;
  top: 60%; left: 10%;
  animation-delay: -10s;
  background: rgba(255,255,255,0.12);
}

@keyframes floatCloud {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(60px); }
}

.menu-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 40px;
  margin: auto;
  animation: menuFadeIn 1s ease-out;
}

@keyframes menuFadeIn {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.menu-title {
  font-family: "Poppins", sans-serif;
  font-size: 3.5rem;
  font-weight: 600;
  color: #ffffff;
  text-shadow: 0 4px 20px rgba(0,0,0,0.35);
  letter-spacing: 2px;
}

.menu-subtitle {
  font-size: 1.1rem;
  color: #ffffff;
  font-weight: 600;
  text-shadow: 0 2px 10px rgba(0,0,0,0.3);
  letter-spacing: 1px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 280px;
}

.menu-btn {
  font-family: "Poppins", sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 14px 28px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 2px solid rgba(255,255,255,0.4);
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  letter-spacing: 1px;
  outline: none;
  position: relative;
  overflow: hidden;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.menu-btn:hover, .menu-btn:focus {
  background: rgba(0, 0, 0, 0.4);
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.3);
  border-color: rgba(255,255,255,0.8);
}

.menu-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.menu-btn::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 0; height: 0;
  background: rgba(255,255,255,0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.5s, height 0.5s;
}

.menu-btn:active::after {
  width: 200px;
  height: 200px;
}

.color-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  background: rgba(0, 0, 0, 0.25);
  padding: 8px 16px;
  border-radius: 20px;
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.3);
}

.color-label {
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.7);
  cursor: pointer;
  transition: all 0.3s ease;
  outline: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.color-swatch:hover, .color-swatch:focus {
  transform: scale(1.3);
  border-color: #fff;
  box-shadow: 0 0 12px rgba(255,255,255,0.8);
}

.color-swatch[data-theme="sunset"] { background: linear-gradient(135deg, #f093fb, #f5576c); }
.color-swatch[data-theme="ocean"] { background: linear-gradient(135deg, #4facfe, #00f2fe); }
.color-swatch[data-theme="forest"] { background: linear-gradient(135deg, #43e97b, #38f9d7); }
.color-swatch[data-theme="candy"] { background: linear-gradient(135deg, #fa709a, #fee140); }
.color-swatch[data-theme="neon"] { background: linear-gradient(135deg, #a18cd1, #fbc2eb); }

/* =================== HOW TO PLAY & PAUSE MODALS =================== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-content {
  background: rgba(255,255,255,0.98);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 40px;
  max-width: 420px;
  width: 90%;
  max-height: 90%;
  overflow-y: auto;
  margin: auto;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: modalPop 0.4s ease-out;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

.modal-content h2 {
  font-family: "Poppins", sans-serif;
  font-size: 1.8rem;
  color: #5b2c91;
  margin-bottom: 20px;
}

.modal-content p {
  font-size: 1rem;
  color: #333333;
  line-height: 1.8;
  margin-bottom: 12px;
}

.modal-content .menu-btn {
  color: #ffffff !important;
  background: linear-gradient(135deg, #764ba2 0%, #667eea 100%) !important;
  border: none !important;
  box-shadow: 0 4px 15px rgba(118, 75, 162, 0.4) !important;
  text-shadow: none !important;
  font-weight: 600;
}

.modal-content .menu-btn:hover,
.modal-content .menu-btn:focus {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
  box-shadow: 0 6px 20px rgba(118, 75, 162, 0.6) !important;
}

/* =================== PAUSE MENU =================== */
.pause-content .pause-score {
  color: #444444;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.pause-content .menu-btn {
  display: block;
  width: 220px;
  max-width: 100%;
  margin: 12px auto 0;
  text-align: center;
}

/* =================== SKY THEMES =================== */
.menu-overlay[data-sky="sunset"] {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 50%, #ffa751 100%);
  animation: gradientShift 6s ease infinite alternate;
}

.menu-overlay[data-sky="ocean"] {
  background: linear-gradient(135deg, #1c72b8 0%, #00f2fe 50%, #20b2aa 100%);
  animation: gradientShift 6s ease infinite alternate;
}

.menu-overlay[data-sky="forest"] {
  background: linear-gradient(135deg, #2b8a4f 0%, #38f9d7 50%, #1e6b7b 100%);
  animation: gradientShift 6s ease infinite alternate;
}

.menu-overlay[data-sky="candy"] {
  background: linear-gradient(135deg, #e05280 0%, #fee140 50%, #d850e0 100%);
  animation: gradientShift 6s ease infinite alternate;
}

.menu-overlay[data-sky="neon"] {
  background: linear-gradient(135deg, #6c41b8 0%, #fbc2eb 50%, #a18cd1 100%);
  animation: gradientShift 6s ease infinite alternate;
}

/* =================== GAME SKY THEMES =================== */
#container.game-sunset { --bg-top: #ff8a7a; --bg-bottom: #8ecff5; --block-glow: rgba(255,107,107,0.3); }
#container.game-ocean { --bg-top: #4facfe; --bg-bottom: #b8e0ff; --block-glow: rgba(79,172,254,0.3); }
#container.game-forest { --bg-top: #77e4a3; --bg-bottom: #c3ecdd; --block-glow: rgba(67,233,123,0.3); }
#container.game-candy { --bg-top: #fa9fce; --bg-bottom: #ffe9f3; --block-glow: rgba(250,112,154,0.3); }
#container.game-neon { --bg-top: #a18cd1; --bg-bottom: #e4dcf5; --block-glow: rgba(161,140,209,0.3); }

#container.game-sunset #game canvas { background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom)) !important; }
#container.game-ocean #game canvas { background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom)) !important; }
#container.game-forest #game canvas { background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom)) !important; }
#container.game-candy #game canvas { background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom)) !important; }
#container.game-neon #game canvas { background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom)) !important; }

/* =================== PAUSE BUTTON =================== */
#pause-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  z-index: 50;
  font-family: "Poppins", sans-serif;
  font-size: 1.2rem;
  font-weight: 600;
  padding: 8px 18px;
  border: 2px solid rgba(255,255,255,0.6);
  border-radius: 12px;
  cursor: pointer;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0,0,0,0.25);
  outline: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

#pause-btn:hover, #pause-btn:focus {
  background: rgba(0, 0, 0, 0.4);
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.9);
}

#pause-btn:active {
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

/* =================== RESPONSIVE =================== */
#scroll-container, #container, .menu-overlay, .modal-overlay {
  height: 100%;
}

@supports (height: 100dvh) {
  #scroll-container, #container, .menu-overlay, .modal-overlay {
    height: 100dvh;
  }
}

.menu-overlay {
  overflow-y: auto;
  padding: 20px;
}

.menu-content {
  max-height: 100%;
}

@media (max-width: 768px) {
  .menu-title { font-size: 2.4rem; }
  .menu-content { padding: 24px; gap: 18px; }
  .menu-buttons { width: 250px; }
  .menu-btn { min-height: 46px; }
  #score { font-size: 8vh; top: 12px; }
  #instructions { top: 14vh; font-size: 0.9rem; }
  #pause-btn { min-height: 44px; top: 12px; right: 12px; }
  .game-over h2 { font-size: 30px; }
}

@media (max-width: 480px) {
  .menu-title { font-size: 2rem; }
  .menu-subtitle { font-size: 0.9rem; }
  .menu-content { padding: 16px; gap: 14px; }
  .menu-buttons { width: 220px; gap: 10px; }
  .menu-btn { font-size: 0.95rem; padding: 11px 20px; min-height: 46px; }
  .color-picker { gap: 8px; }
  #score { font-size: 7vh; top: 8px; }
  #instructions { top: 12vh; font-size: 0.85rem; }
  #pause-btn { font-size: 0.9rem; padding: 6px 14px; top: 10px; right: 10px; }
  .game-over h2 { font-size: 26px; }
  .modal-content { padding: 24px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .menu-content {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
  }
  .menu-title { font-size: 1.6rem; flex-basis: 100%; text-align: center; margin: 0; }
  .menu-subtitle { display: none; }
  .menu-buttons { width: auto; flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 8px; }
  .menu-btn { padding: 9px 16px; font-size: 0.9rem; }
  .color-picker { margin-top: 0; }
  #score { font-size: 6vh; }
  #instructions { top: 9vh; font-size: 0.8rem; }
  .modal-content { padding: 16px; }
  .modal-content p { line-height: 1.5; margin-bottom: 8px; }
  #pause-btn { top: 8px; right: 8px; font-size: 0.85rem; padding: 5px 12px; }
}