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

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Fredoka", "Baloo 2", system-ui, sans-serif;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- escena compartida (cielo + sol) ---------- */

pantalla-temas,
pantalla-juego {
  position: relative;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  overflow: hidden;
  padding: clamp(1rem, 3vmin, 2.5rem);
  gap: clamp(0.75rem, 2vmin, 1.5rem);
  background: linear-gradient(180deg, #8fd3f4 0%, #bfe9ff 22%, #bfe9ff 100%);
}

pantalla-temas:not([hidden]),
pantalla-juego:not([hidden]) {
  display: flex;
}

pantalla-temas[hidden],
pantalla-juego[hidden] {
  display: none;
}

.sol-esquina {
  position: absolute;
  top: clamp(-40px, -4vmin, -20px);
  left: clamp(-40px, -4vmin, -20px);
  width: clamp(70px, 12vmin, 130px);
  height: clamp(70px, 12vmin, 130px);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff3b0, #ffcf3f 70%, #ffb703 100%);
  box-shadow: 0 0 0 10px rgba(255, 207, 63, 0.3);
  pointer-events: none;
}

/* ---------- barra superior ---------- */

.barra-superior {
  position: relative;
  z-index: 13;
  width: 100%;
  max-width: 1100px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.boton-circular {
  width: clamp(48px, 8vmin, 60px);
  height: clamp(48px, 8vmin, 60px);
  border-radius: 50%;
  background: #fff9ec;
  border: 4px solid #2f5233;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 0 #d9c48a, 0 10px 16px rgba(31, 50, 20, 0.25);
}

.boton-circular svg {
  width: 45%;
  height: 45%;
}

.boton-silencio {
  flex-shrink: 0;
}

.boton-silencio-esquina {
  position: absolute;
  z-index: 5;
  top: clamp(0.5rem, 2vmin, 1rem);
  right: clamp(0.5rem, 2vmin, 1rem);
}

.barra-tiempo {
  flex: 1;
  height: clamp(14px, 2.6vmin, 20px);
  margin: 0 16px;
  border-radius: 999px;
  background: #fff9ec;
  border: 3px solid #2f5233;
  box-shadow: 0 4px 0 #d9c48a, 0 6px 10px rgba(31, 50, 20, 0.2);
  overflow: hidden;
}

.barra-tiempo__relleno {
  height: 100%;
  width: 0%;
  background: linear-gradient(180deg, #8fdb63 0%, #5fb548 55%, #4a9e37 100%);
}

.chip-tema {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff9ec;
  border: 4px solid #2f5233;
  border-radius: 999px;
  padding: 8px 20px 8px 12px;
  box-shadow: 0 6px 0 #d9c48a, 0 10px 16px rgba(31, 50, 20, 0.25);
  font-size: clamp(1rem, 2.4vmin, 1.2rem);
  font-weight: 600;
  color: #4a2f12;
}

.chip-tema .chip-tema__emoji {
  font-size: clamp(1.2rem, 3vmin, 1.6rem);
  line-height: 1;
}

/* ---------- pantalla de temas ---------- */

.titulo-juego {
  position: relative;
  z-index: 3;
  margin: 0;
  font-size: clamp(1.6rem, 4.5vmin, 2.6rem);
  font-weight: 700;
  color: #1f5029;
  text-shadow: 0 3px 0 #fff9ec;
}

.instruccion {
  position: relative;
  z-index: 3;
  margin: 0;
  font-size: clamp(1rem, 2.6vmin, 1.4rem);
  font-weight: 500;
  color: #2f5233;
}

.rejilla-temas {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(0.5rem, 1.6vmin, 1rem);
  width: 100%;
  max-width: 640px;
}

.boton-tema {
  min-height: 3.6rem;
  font-size: clamp(0.9rem, 2vmin, 1.3rem);
  font-weight: 600;
  padding: 0.5rem;
  border-radius: 1rem;
  background: #fff9ec;
  border: 4px solid #2f5233;
  color: #4a2f12;
  box-shadow: 0 6px 0 #d9c48a, 0 10px 16px rgba(31, 50, 20, 0.25);
  transition: transform 0.1s ease-out;
}

.boton-tema:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #d9c48a, 0 6px 10px rgba(31, 50, 20, 0.25);
}

.boton-tema--apagado {
  background: #e4e0d4;
  border-color: #9a9484;
  color: #8b8474;
  box-shadow: 0 4px 0 #c9c3b2, 0 6px 10px rgba(31, 50, 20, 0.12);
  opacity: 0.6;
}

.fila-atajos-temas {
  position: relative;
  z-index: 3;
  display: flex;
  gap: 0.75rem;
}

.boton-atajo-tema {
  min-height: 2.4rem;
  min-width: 5.5rem;
  font-size: clamp(0.85rem, 1.8vmin, 1.05rem);
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  background: #fff9ec;
  border: 3px solid #2f5233;
  color: #4a2f12;
  box-shadow: 0 4px 0 #d9c48a, 0 6px 10px rgba(31, 50, 20, 0.2);
  transition: transform 0.1s ease-out;
}

.boton-atajo-tema:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #d9c48a, 0 4px 6px rgba(31, 50, 20, 0.2);
}

.fila-niveles {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.etiqueta-nivel {
  font-size: clamp(0.85rem, 1.8vmin, 1.05rem);
  font-weight: 600;
  color: #2f5233;
}

.boton-nivel {
  min-height: 2.2rem;
  min-width: 3.4rem;
  font-size: clamp(0.85rem, 1.8vmin, 1.05rem);
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: #fff9ec;
  border: 3px solid #2f5233;
  color: #4a2f12;
  box-shadow: 0 4px 0 #d9c48a, 0 6px 10px rgba(31, 50, 20, 0.2);
  transition: transform 0.1s ease-out;
}

.boton-nivel:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #d9c48a, 0 4px 6px rgba(31, 50, 20, 0.2);
}

.boton-nivel--apagado {
  background: #e4e0d4;
  border-color: #9a9484;
  color: #8b8474;
  box-shadow: 0 3px 0 #c9c3b2, 0 5px 8px rgba(31, 50, 20, 0.12);
  opacity: 0.6;
}

.boton-empezar {
  position: relative;
  z-index: 3;
  min-height: 4rem;
  min-width: 12rem;
  font-size: clamp(1.2rem, 2.8vmin, 1.75rem);
  font-weight: 700;
  border-radius: 999px;
  background: linear-gradient(180deg, #8fdb63 0%, #5fb548 55%, #4a9e37 100%);
  border: 5px solid #2f5233;
  color: #fff9ec;
  box-shadow: 0 8px 0 #3a6e26, 0 14px 20px rgba(20, 40, 10, 0.3);
  transition: transform 0.1s ease-out, opacity 0.15s ease-out;
}

.boton-empezar:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 #3a6e26, 0 8px 12px rgba(20, 40, 10, 0.3);
}

.boton-empezar:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- pantalla de juego: plataforma ---------- */

.plataforma-envoltorio {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 640px;
  flex: 1;
  display: flex;
}

.plataforma {
  width: 100%;
  flex: 1;
  border-radius: clamp(1rem, 3vmin, 2.1rem);
  background: linear-gradient(180deg, #8fdb63 0%, #5fb548 55%, #4a9e37 100%);
  border: 6px solid #2f5233;
  box-shadow: 0 12px 0 #3a6e26, 0 20px 28px rgba(20, 40, 10, 0.35);
  padding: clamp(0.75rem, 2.5vmin, 1.9rem);
}

.plataforma--fallo {
  animation: temblor 0.5s ease-in-out infinite;
}

.terreno {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: clamp(0.6rem, 2vmin, 1.4rem);
}

.celda-hoyo {
  position: relative;
  /* GameRhythm.TAMANO_TOQUE_MIN_PX: objetivo táctil de un topo */
  min-width: 96px;
  min-height: 96px;
  border: none;
  background: none;
  padding: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.grafico-hoyo {
  position: absolute;
  bottom: 4%;
  width: 78%;
  height: 68%;
  pointer-events: none;
}

.grafico-hoyo svg {
  display: block;
  width: 100%;
  height: 100%;
}

.topo-envoltorio {
  position: absolute;
  bottom: 0;
  left: 6%;
  right: 6%;
  height: 74%;
  z-index: 2;
  transition: transform 0.18s ease-out;
  animation: rebote-suave 2.6s ease-in-out infinite;
}

.topo-envoltorio svg {
  display: block;
  width: 100%;
  height: 100%;
}

.topo-envoltorio--aparece {
  animation: topo-aparece 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) both,
    rebote-suave 2.6s ease-in-out infinite 0.32s;
}

.topo-envoltorio--sale {
  animation: topo-sale 0.26s ease-in both;
}

.topo-envoltorio--aplastado {
  animation: none;
  transform: scaleY(0.42) translateY(30%);
}

.cartel-palabra {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  background: #fff6df;
  border: 3px solid #5a3a1e;
  border-radius: 12px;
  padding: 2px 10px;
  box-shadow: 0 4px 0 #c9a468;
  white-space: nowrap;
  font-size: clamp(0.8rem, 2.2vmin, 1.15rem);
  font-weight: 700;
  color: #4a2f12;
}

.chispas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.chispa {
  position: absolute;
  animation: chispa-anim 0.9s ease-out infinite;
}

/* ---------- HUD objetivo ---------- */

.hud-objetivo {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: clamp(0.75rem, 2vmin, 1.4rem);
  background: #fff9ec;
  border: 5px solid #2f5233;
  border-radius: clamp(1rem, 3vmin, 1.6rem);
  padding: clamp(0.8rem, 2.6vmin, 1.1rem) clamp(1.2rem, 3.4vmin, 2.3rem);
  box-shadow: 0 8px 0 #d9c48a, 0 14px 20px rgba(31, 50, 20, 0.28);
  cursor: pointer;
  user-select: none;
  transition: transform 0.1s ease-out;
}

.hud-objetivo:active {
  transform: scale(0.96);
}

.hud-etiqueta {
  font-size: clamp(0.9rem, 2.2vmin, 1.25rem);
  font-weight: 700;
  letter-spacing: 1px;
  color: #2f6f3e;
  text-transform: uppercase;
}

.hud-contenido {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: clamp(2.6rem, 6vmin, 4rem);
  min-height: clamp(2.6rem, 6vmin, 4rem);
  font-size: clamp(1.5rem, 4.5vmin, 2.5rem);
  font-weight: 700;
  color: #4a2f12;
  animation: rebote 1.8s ease-in-out infinite;
}

.hud-objetivo--presentacion {
  z-index: 20;
  animation: hud-presentacion 1.1s ease-in-out;
}

/* ---------- estado de fallo ---------- */

.velo-fallo {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(220, 40, 20, 0) 32%, rgba(210, 20, 10, 0.6) 100%);
  animation: destello 1.1s ease-in-out infinite;
}

/* ---------- animaciones ---------- */

@keyframes temblor {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  25% { transform: translateX(-10px) rotate(-0.6deg); }
  75% { transform: translateX(10px) rotate(0.6deg); }
}

@keyframes rebote-suave {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes rebote {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-6px) scale(1.05); }
}

@keyframes hud-presentacion {
  0% { transform: translate(0, 0) scale(1); }
  35% { transform: translate(var(--hud-dx), var(--hud-dy)) scale(1.7); }
  65% { transform: translate(var(--hud-dx), var(--hud-dy)) scale(1.7); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes destello {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.9; }
}

@keyframes chispa-anim {
  0% { transform: scale(0.3) rotate(0deg); opacity: 1; }
  100% { transform: scale(1.15) rotate(45deg); opacity: 0; }
}

@keyframes topo-aparece {
  0% { transform: scaleY(0.15) translateY(45%); opacity: 0; }
  60% { transform: scaleY(1.08) translateY(-4%); opacity: 1; }
  100% { transform: scaleY(1) translateY(0); opacity: 1; }
}

@keyframes topo-sale {
  0% { transform: scaleY(1) translateY(0); opacity: 1; }
  100% { transform: scaleY(0.15) translateY(45%); opacity: 0; }
}

/* ---------- popup de fin de ronda ---------- */

popup-fin-de-ronda {
  position: absolute;
  inset: 0;
  z-index: 12;
  align-items: center;
  justify-content: center;
  background: rgba(74, 47, 18, 0.45);
}

popup-fin-de-ronda:not([hidden]) {
  display: flex;
  animation: popup-fin-ronda-entra 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

popup-fin-de-ronda[hidden] {
  display: none;
}

.popup-fin-ronda__panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(1.2rem, 3.5vmin, 2rem);
  max-width: min(90vw, 520px);
  background: #fff9ec;
  border: 6px solid #2f5233;
  border-radius: clamp(1.4rem, 4vmin, 2.2rem);
  padding: clamp(1.6rem, 5vmin, 2.6rem);
  box-shadow: 0 10px 0 #d9c48a, 0 18px 26px rgba(31, 50, 20, 0.32);
  text-align: center;
}

.popup-fin-ronda__mensaje {
  margin: 0;
  font-size: clamp(1.4rem, 4.5vmin, 2.1rem);
  font-weight: 600;
  color: #4a2f12;
}

.popup-fin-ronda__recuento {
  margin: 0;
  font-size: clamp(1rem, 3vmin, 1.4rem);
  color: #4a2f12;
}

.popup-fin-ronda__boton {
  border: 4px solid #2f5233;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe58a 0%, #ffb703 100%);
  color: #4a2f12;
  font-family: inherit;
  font-size: clamp(1.1rem, 3.2vmin, 1.4rem);
  font-weight: 700;
  padding: clamp(0.7rem, 2vmin, 1rem) clamp(1.8rem, 5vmin, 2.6rem);
  box-shadow: 0 6px 0 #d9c48a, 0 10px 16px rgba(31, 50, 20, 0.25);
}

@keyframes popup-fin-ronda-entra {
  0% { opacity: 0; transform: scale(0.85); }
  100% { opacity: 1; transform: scale(1); }
}

/* ---------- ajuste vertical para móvil ---------- */

@media (max-width: 480px), (max-height: 700px) {
  pantalla-temas,
  pantalla-juego {
    padding: 0.6rem;
    gap: 0.5rem;
  }

  .titulo-juego {
    font-size: clamp(1.2rem, 5.5vmin, 1.6rem);
  }

  .instruccion {
    font-size: clamp(0.85rem, 3.2vmin, 1rem);
  }

  .rejilla-temas {
    gap: 0.4rem;
  }

  .boton-tema {
    min-height: 2.8rem;
    padding: 0.35rem;
  }

  .boton-atajo-tema {
    min-height: 2rem;
    min-width: 4.5rem;
  }

  .boton-nivel {
    min-height: 1.8rem;
    min-width: 2.8rem;
  }

  .boton-empezar {
    min-height: 3.2rem;
    min-width: 10rem;
  }

  .hud-objetivo {
    padding: 0.5rem 1rem;
  }

  .sol-esquina {
    width: 60px;
    height: 60px;
  }
}
