:root {
  --blue: #1e90ff;
  --blue-dark: #0a63c2;
  --pink: #ff5ca8;
  --yellow: #ffd23f;
  --green: #2ecc71;
  --purple: #8b5cf6;
  --bg: #11142b;
  --bg-2: #1b1f4b;
  --card: #ffffff;
  --text: #1b1f3b;
  --radius: 22px;
  font-size: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', system-ui, sans-serif;
  overflow-x: hidden;
}

h1, h2, h3, .welcome-title {
  font-family: 'Baloo 2', 'Nunito', system-ui, sans-serif;
}

/* ---------- HERO ---------- */
.hero {
  position: relative;
  min-height: 62vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1rem 3rem;
  background: radial-gradient(circle at 50% 0%, var(--bg-2), var(--bg) 70%);
  overflow: hidden;
  text-align: center;
}

.stars-bg {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 10% 20%, #fff, transparent),
    radial-gradient(2px 2px at 80% 30%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 30% 70%, #fff, transparent),
    radial-gradient(2px 2px at 60% 80%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 90% 60%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 45% 15%, #fff, transparent);
  opacity: 0.5;
  pointer-events: none;
}

.welcome-title {
  color: #fff;
  font-size: clamp(2rem, 7vw, 3.4rem);
  line-height: 1.15;
  margin: 0 0 0.5rem;
  letter-spacing: 1px;
  text-shadow: 0 0 18px rgba(63, 180, 255, 0.6);
  z-index: 2;
}
.welcome-title span {
  display: inline-block;
  background: linear-gradient(90deg, var(--blue), var(--pink), var(--yellow));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.mouse-wrap {
  position: relative;
  width: min(42vw, 220px);
  margin: 0.5rem auto 1rem;
  z-index: 2;
}

.gaming-mouse {
  width: 100%;
  display: block;
  filter: drop-shadow(0 10px 25px rgba(0, 0, 0, 0.45));
  animation: mouseFloat 6s ease-in-out infinite;
}

@keyframes mouseFloat {
  0%   { transform: translate(0, 0) rotate(0deg); }
  25%  { transform: translate(18px, -14px) rotate(2deg); }
  50%  { transform: translate(0, -26px) rotate(0deg); }
  75%  { transform: translate(-18px, -14px) rotate(-2deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

.glow-pulse {
  animation: glowPulse 1.6s ease-in-out infinite;
}
@keyframes glowPulse {
  0%, 100% { opacity: 0.45; r: 26; }
  50% { opacity: 0.85; r: 34; }
}

.sound-btn {
  z-index: 2;
  border: none;
  border-radius: 999px;
  padding: 0.8rem 1.4rem;
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg, var(--blue), var(--purple));
  box-shadow: 0 6px 18px rgba(30, 144, 255, 0.45);
  cursor: pointer;
}
.sound-btn:active { transform: scale(0.97); }

/* ---------- GAMES ---------- */
.section-title {
  text-align: center;
  color: #fff;
  background: var(--bg);
  margin: 0;
  padding: 2rem 1rem 0.5rem;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
}

main { background: var(--bg); padding-bottom: 2rem; }

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.2rem 2.5rem;
}

.game-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.2rem 1.2rem 1.4rem;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border: 3px solid transparent;
}
.game-card:hover, .game-card:focus-visible {
  transform: translateY(-6px) scale(1.02);
  border-color: var(--yellow);
  outline: none;
}
.game-card h3 {
  margin: 0.6rem 0 0.3rem;
  font-size: 1.4rem;
}
.game-card p {
  margin: 0 0 0.6rem;
  font-size: 0.95rem;
  color: #51566e;
}
.play-tag {
  display: inline-block;
  font-weight: 800;
  color: var(--blue-dark);
  font-family: 'Baloo 2', sans-serif;
}

.thumb {
  height: 110px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 2.8rem;
  position: relative;
  overflow: hidden;
}
.thumb-factory { background: linear-gradient(135deg, #2b2f4a, #4b2d63); }
.thumb-factory .ghost { position: absolute; right: 18px; bottom: 10px; font-size: 1.8rem; opacity: 0.9; }
.thumb-pets { background: linear-gradient(135deg, #ffe29a, #ff9ac4); }
.thumb-blocks { background: linear-gradient(135deg, #8fd3f4, #84fab0); gap: 6px; }

.block { width: 28px; height: 28px; border-radius: 6px; border: 2px solid rgba(0,0,0,0.15); }
.b1 { background: #6ec46e; }
.b2 { background: #a9744f; }
.b3 { background: #7f7f7f; }

footer {
  text-align: center;
  color: #8a8fb8;
  padding: 1.5rem 1rem 2.5rem;
  background: var(--bg);
  font-size: 0.9rem;
}

/* ---------- MODAL ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 30, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 0.75rem;
}
.modal.hidden { display: none; }

.modal-inner {
  background: #0f1230;
  border-radius: var(--radius);
  width: min(96vw, 900px);
  height: min(92vh, 720px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.modal-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  background: #171a3d;
}
.modal-topbar h2 {
  color: #fff;
  margin: 0;
  font-size: 1.3rem;
}
.close-btn {
  border: none;
  background: var(--pink);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.modal-game-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
}

@media (max-width: 640px) {
  .modal-inner { width: 100vw; height: 100vh; border-radius: 0; }
}

/* ---------- GAME STAGES (shared) ---------- */
.factory-stage, .blocks-stage, .pets-stage {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: relative;
  overflow: auto;
  box-sizing: border-box;
  padding: 10px;
}

.game-canvas {
  display: block;
  touch-action: none;
  background: #10121f;
  border-radius: 10px;
  flex-shrink: 0;
}

/* ---------- FACTORY GAME: D-pad ---------- */
.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  user-select: none;
}
.dpad-mid { display: flex; gap: 60px; }
.dpad button {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 1.3rem;
  touch-action: none;
}
.dpad button:active { background: rgba(255, 255, 255, 0.3); }

/* ---------- PETS GAME ---------- */
.pets-stage {
  overflow-y: auto;
  padding: 1rem;
  gap: 0.6rem;
  color: #fff;
  align-items: center;
  justify-content: flex-start;
  background: #10121f;
}
.pets-hatch { text-align: center; padding-top: 0.5rem; }
.egg { font-size: 4rem; line-height: 1; }
.egg.cracking { animation: eggShake 0.5s ease; }
@keyframes eggShake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-14deg); }
  40% { transform: rotate(12deg); }
  60% { transform: rotate(-10deg); }
  80% { transform: rotate(8deg); }
}
.hatch-btn {
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.4rem;
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg, var(--pink), var(--purple));
  box-shadow: 0 6px 16px rgba(139, 92, 246, 0.45);
  cursor: pointer;
  margin-top: 0.4rem;
}
.hatch-btn:active { transform: scale(0.97); }
.pet-count { margin: 0.6rem 0 0; font-weight: 700; }
.free-note { color: var(--yellow); font-weight: 800; margin: 0.2rem 0 0; }
.pet-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  width: 100%;
  padding-bottom: 1rem;
}
.pet-card {
  background: #1e2147;
  border-radius: 14px;
  padding: 0.6rem 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 84px;
  border: 2px solid #333a6b;
}
.pet-emoji { font-size: 2rem; }
.pet-name { font-size: 0.8rem; font-weight: 700; margin-top: 2px; }
.pet-rarity { font-size: 0.7rem; opacity: 0.8; }
.pet-rare { border-color: #3aa0ff; box-shadow: 0 0 10px rgba(58, 160, 255, 0.4); }
.pet-epic { border-color: #b06bff; box-shadow: 0 0 10px rgba(176, 107, 255, 0.5); }
.pet-legendary { border-color: #ffd23f; box-shadow: 0 0 14px rgba(255, 210, 63, 0.7); }

/* ---------- BLOCKS GAME ---------- */
.blocks-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0.6rem;
  background: #171a3d;
  flex-shrink: 0;
  align-self: stretch;
  justify-content: center;
  width: 100%;
  order: -1;
}
.palette-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
}
.palette-btn.active { border-color: var(--yellow); box-shadow: 0 0 0 2px var(--yellow); }
.clear-btn {
  width: auto;
  padding: 0 0.9rem;
  background: var(--pink);
  color: #fff;
  font-weight: 700;
  font-family: 'Baloo 2', sans-serif;
}
