* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
}

/* =============================================
   WIDGET CONTENEDOR — cuadrado, autocontenido
   ============================================= */
#puzzle-widget {
  width: 100%;
  height: 900px;
  margin: 20px auto;
  border-radius: 24px;
  overflow: hidden;
  background: #111;
  position: relative;
  font-family: 'Comic Sans MS', cursive;
  color: #333;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

/* Pantallas */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 15px;
  position: absolute;
  top: 0;
  left: 0;
}
.screen.active {
  display: flex;
}

/* --- Pantalla inicio --- */
#screen-start h1 {
  font-family: 'Cherry Bomb One', cursive;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  color: #fff;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3);
  margin-bottom: 10px;
}

#cover-img {
  width: 85%;
  max-height: 65%;
  object-fit: cover;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  margin-bottom: 12px;
}

.start-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

#image-options {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.image-thumb {
  width: 55px;
  height: 55px;
  border-radius: 10px;
  border: 3px solid transparent;
  cursor: pointer;
  object-fit: cover;
  transition:
    transform 0.2s,
    border-color 0.2s;
}
.image-thumb:hover,
.image-thumb.selected {
  border-color: #667eea;
  transform: scale(1.1);
}

#file-input {
  display: none;
}

/* Botones */
.btn {
  border: none;
  border-radius: 50px;
  padding: 8px 20px;
  font-size: 1rem;
  font-weight: normal;
  cursor: pointer;
  transition: transform 0.15s;
  touch-action: manipulation;
  font-family: 'Baloo 2', 'Comic Sans MS', cursive;
}
.btn:active {
  transform: scale(0.95);
}

.btn-play {
  background: linear-gradient(135deg, #f093fb, #f5576c);
  color: #fff;
  font-size: 1.3rem;
  padding: 10px 36px;
  margin-top: 10px;
  box-shadow: 0 3px 12px rgba(245, 87, 108, 0.4);
}

.btn-upload {
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  color: #fff;
  display: inline-block;
  padding: 6px 16px;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-diff {
  background: transparent;
  border: 3px solid #444;
  color: #666;
  width: 52px;
  height: 52px;
  min-width: 0;
  padding: 0;
  border-radius: 50%;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.btn-diff.active {
  background: linear-gradient(135deg, #4facfe, #00c6fb);
  border-color: transparent;
  color: #fff;
}

.difficulty-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.btn-small {
  background: rgba(255, 255, 255, 0.9);
  color: #555;
  padding: 6px 14px;
  font-size: 0.9rem;
  border-radius: 10px;
}

/* --- Pantalla juego --- */
#screen-game {
  justify-content: flex-start;
  padding: 8px;
}

#game-header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 4px;
  flex-shrink: 0;
}

#puzzle-board {
  display: grid;
  gap: 3px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 4px;
  flex-shrink: 0;
}

.puzzle-slot {
  background: rgba(255, 255, 255, 0.12);
  border: 3px dashed rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}
.puzzle-slot.hover {
  background: rgba(255, 255, 200, 0.5);
  border-color: #ffd700;
}
.puzzle-slot.filled {
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: none;
}

#pieces-tray {
  display: flex;
  gap: 8px;
  padding: 10px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  align-content: center;
  width: 100%;
  flex: 1;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  margin-top: 6px;
  overflow-y: auto;
  min-height: 0;
}

.puzzle-piece {
  border-radius: 6px;
  cursor: grab;
  box-shadow: 2px 3px 8px rgba(0, 0, 0, 0.4);
  touch-action: none;
  transition: transform 0.1s;
  display: block;
}
.puzzle-piece:hover {
  transform: scale(1.05);
}
.puzzle-piece.dragging {
  opacity: 0.9;
  z-index: 1000;
  cursor: grabbing;
  box-shadow: 4px 6px 16px rgba(0, 0, 0, 0.6);
}
.puzzle-piece.placed {
  cursor: default;
  box-shadow: none;
  width: 100% !important;
  height: 100% !important;
}

/* Shake para error */
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-8px);
  }
  40% {
    transform: translateX(8px);
  }
  60% {
    transform: translateX(-5px);
  }
  80% {
    transform: translateX(5px);
  }
}
.puzzle-piece.shake {
  animation: shake 0.4s ease;
}

/* Preview */
#preview-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  cursor: pointer;
  border-radius: 24px;
}
#preview-overlay.hidden {
  display: none;
}
#preview-img {
  max-width: 80%;
  max-height: 80%;
  border-radius: 12px;
}

/* --- Pantalla victoria --- */
#screen-win {
  background: linear-gradient(135deg, #f6d365, #fda085);
  border-radius: 24px;
  text-align: center;
}
#screen-win h1 {
  font-size: clamp(2rem, 6vw, 3rem);
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.15);
  animation: bounce 0.6s ease;
}
#win-stars {
  font-size: 2.5rem;
  margin: 8px 0;
}
.star {
  display: inline-block;
  animation: starPop 0.4s ease both;
}
.star:nth-child(2) {
  animation-delay: 0.15s;
}
.star:nth-child(3) {
  animation-delay: 0.3s;
}

#win-image {
  max-width: 55%;
  max-height: 35%;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.win-buttons {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

/* Feedback visual */
.slot-correct {
  animation: slotGlow 0.5s ease;
}

/* Confetti */
.confetti {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  z-index: 200;
  animation: confettiFall linear forwards;
  pointer-events: none;
}

@keyframes bounce {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
}
@keyframes starPop {
  0% {
    transform: scale(0) rotate(-30deg);
    opacity: 0;
  }
  70% {
    transform: scale(1.3) rotate(10deg);
  }
  100% {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}
@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(500px) rotate(720deg);
    opacity: 0;
  }
}
@keyframes slotGlow {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.8);
  }
  50% {
    box-shadow: 0 0 15px 8px rgba(255, 215, 0, 0.5);
  }
  100% {
    box-shadow: none;
  }
}
