:root {
  --bg-color: #f8fafc;
  --text-color: #334155;
  --board-bg: rgba(255, 255, 255, 0.7);
  --cell-bg: rgba(203, 213, 225, 0.4);
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --primary: #8b5cf6;
  --primary-hover: #7c3aed;
  --accent: #fbbf24;
  --gap: 12px;
  --radius: 12px;
}

@media (max-width: 520px) {
  :root {
    --gap: 10px;
  }
}

body {
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  color: var(--text-color);
  font-family: var(--font-family);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overscroll-behavior: none;
  overflow: auto; /* Permite scroll si el contenido es largo en móviles */
}

.container {
  width: 500px;
  margin: 0 auto;
}

@media (max-width: 520px) {
  .container {
    width: 100%;
    padding: 0 10px;
    box-sizing: border-box;
  }
}

.heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.title {
  font-size: 52px;
  font-weight: 800;
  margin: 0;
  background: linear-gradient(to right, #6366f1, #a855f7);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -1px;
}

.scores-container {
  display: flex;
  gap: 10px;
}

.score-container, .best-container {
  background: white;
  padding: 12px 24px;
  font-size: 22px;
  font-weight: 800;
  border-radius: var(--radius);
  color: var(--text-color);
  text-align: center;
  position: relative;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.score-container::after, .best-container::after {
  content: "PUNTOS";
  position: absolute;
  top: 5px;
  left: 0;
  width: 100%;
  font-size: 13px;
  color: #eee4da;
  font-weight: bold;
}

.best-container::after {
  content: "MEJOR";
}

.score-container, .best-container {
  padding-top: 25px;
  min-width: 40px;
}

.above-game {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.game-intro {
  font-size: 18px;
  margin: 0;
}

.restart-button, .retry-button, .keep-playing-button, .install-button {
  background: var(--primary);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  display: inline-block;
  margin: 0 5px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
  box-shadow: 0 4px 14px 0 rgba(139, 92, 246, 0.39);
}

.restart-button:hover, .retry-button:hover, .keep-playing-button:hover, .install-button:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.23);
}

.restart-button:active, .install-button:active {
  transform: translateY(0);
}

@media (max-width: 520px) {
  .install-button {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    text-align: center;
    font-size: 18px;
    padding: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    z-index: 1000;
  }
}

/* Animal Progression Bar */
.animal-progression-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(8px);
  padding: 12px 20px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow-x: auto;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.animal-item {
  font-size: 24px;
  opacity: 0.3; /* Grisáceos por defecto (bloqueados) */
  filter: grayscale(100%);
  transition: all 0.3s ease;
  position: relative;
}

/* Desbloqueados */
.animal-item.unlocked {
  opacity: 1;
  filter: grayscale(0%);
}

/* El próximo animal: resaltado o iluminado */
.animal-item.next-up {
  opacity: 1;
  filter: grayscale(0%);
  transform: scale(1.3);
  text-shadow: 0 0 10px rgba(237, 194, 46, 0.8);
  animation: pulse-next 1.5s infinite;
}

@keyframes pulse-next {
  0% { transform: scale(1.2); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1.2); }
}

@media (max-width: 520px) {
  .animal-item {
    font-size: 18px;
  }
}

.game-container {
  position: relative;
  background: var(--board-bg);
  backdrop-filter: blur(10px);
  padding: var(--gap);
  border-radius: 16px;
  width: 500px;
  height: 500px;
  box-sizing: border-box;
  touch-action: none;
  border: 4px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

@media (max-width: 520px) {
  .game-container {
    width: 100%;
    height: calc(100vw - 20px);
    max-height: 500px;
  }
}

.grid-container {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

.grid-row {
  display: flex;
  gap: var(--gap);
  height: calc((100% - 3 * var(--gap)) / 4);
  box-sizing: border-box;
}

.grid-cell {
  width: calc((100% - 3 * var(--gap)) / 4);
  height: 100%;
  border-radius: 8px;
  background: var(--cell-bg);
  box-sizing: border-box;
}

.tile-container {
  position: absolute;
  top: var(--gap);
  left: var(--gap);
  right: var(--gap);
  bottom: var(--gap);
  z-index: 2;
}

.tile {
  position: absolute;
  width: calc((100% - 3 * var(--gap)) / 4);
  height: calc((100% - 3 * var(--gap)) / 4);
  background: #fff;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 50px;
  font-weight: bold;
  color: #334155;
  transition: transform 100ms ease-in-out;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

@media (max-width: 520px) {
  .tile {
    font-size: 35px;
  }
}

/* Colors */
.tile-2 { background: linear-gradient(135deg, #fff 0%, #f1f5f9 100%); }
.tile-4 { background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%); }
.tile-8 { background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%); }
.tile-16 { background: linear-gradient(135deg, #fff1f2 0%, #ffe4e6 100%); }
.tile-32 { background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%); }
.tile-64 { background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%); }
.tile-128 { background: linear-gradient(135deg, #fdf4ff 0%, #fae8ff 100%); box-shadow: 0 0 15px rgba(232, 121, 249, 0.3); }
.tile-256 { background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%); box-shadow: 0 0 20px rgba(168, 85, 247, 0.4); }
.tile-512 { background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%); box-shadow: 0 0 25px rgba(251, 191, 36, 0.5); }
.tile-1024 { background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%); box-shadow: 0 0 30px rgba(248, 113, 113, 0.6); }
.tile-2048 { background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%); box-shadow: 0 0 40px rgba(251, 191, 36, 0.8); }

@media (max-width: 520px) {
  .tile-128, .tile-256, .tile-512 { font-size: 30px; }
  .tile-1024, .tile-2048 { font-size: 20px; }
}

/* Animations */
@keyframes appear {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

.tile-new .tile-inner {
  animation: appear 200ms ease 100ms;
  animation-fill-mode: backwards;
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.tile-merged .tile-inner {
  animation: pop 200ms ease 100ms;
  animation-fill-mode: backwards;
}

.tile-inner {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 3px;
}

.game-message {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(238, 228, 218, 0.73);
  z-index: 2000;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  animation: fade-in 800ms ease 500ms;
  animation-fill-mode: both;
  border-radius: 6px;
}

.game-message p {
  font-size: 60px;
  font-weight: bold;
  height: 60px;
  line-height: 60px;
  margin-top: 20px;
  margin-bottom: 20px;
  color: #776e65;
}

.game-message.game-won {
  display: flex !important;
  background: rgba(237, 194, 46, 0.5);
  color: #f9f6f2;
}
.game-message.game-won p {
  color: #f9f6f2;
}

.game-message.game-over {
  display: flex !important;
}

.game-message .lower {
  display: block;
  margin-top: 20px;
}

@keyframes fade-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.footer {
  text-align: center;
  margin: 50px auto;
  font-size: 18px;
  color: #334155;
  line-height: 1.6;
  max-width: 650px;
  padding: 0 20px;
}

.footer a {
  color: #6366f1;
  font-weight: 800;
  text-decoration: none;
  border-bottom: 2px solid #6366f1;
  transition: all 0.2s ease;
}

.footer a:hover {
  background: #6366f1;
  color: white;
  border-radius: 4px;
  padding: 2px 6px;
}

/* Celebration Content */
.celebration-content {
  padding: 20px;
  animation: pop 0.5s ease;
}
.celebration-content h2 {
  font-size: 32px;
  margin-bottom: 20px;
  color: #f9f6f2;
  text-shadow: 0px 2px 4px rgba(0,0,0,0.3);
}
.celebration-content p {
  font-size: 18px;
  margin: 5px 0;
  line-height: 1.4;
  color: #f9f6f2;
}
.promo-link {
  display: inline-block;
  color: #fcf9f2;
  background: rgba(0,0,0,0.2);
  padding: 10px 15px;
  border-radius: 6px;
  font-weight: bold;
  font-size: 16px;
  margin: 15px 0;
  text-decoration: none;
  word-break: break-all;
  transition: background 0.2s ease;
}
.promo-link:hover {
  background: rgba(0,0,0,0.4);
}
.promo-code {
  font-size: 20px !important;
  background: rgba(0,0,0,0.3);
  padding: 10px;
  border-radius: 8px;
  display: inline-block;
  margin-top: 5px !important;
}

/* Confetti */
.confetti {
  position: fixed;
  top: -20px;
  width: 10px;
  height: 20px;
  pointer-events: none;
  z-index: 9999;
  animation: fall linear forwards;
}

@keyframes fall {
  to {
    transform: translateY(110vh) translateX(var(--xOffset)) rotate(720deg);
  }
}

@media (max-width: 520px) {
  .celebration-content h2 { font-size: 24px; }
  .celebration-content p { font-size: 14px; }
  .promo-link { font-size: 14px; }
  .promo-code { font-size: 16px !important; padding: 6px; }
}
