/* =========================
   GAME: WORD MAGNET MATCH
========================= */

.wordmagnet-game {
  height: 100%;
  min-height: 0;
  position: relative;
  font-family: "Fredoka", Arial, sans-serif;
  color: #000;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.wordmagnet-board {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  background:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,.6) 0 3px, transparent 4px),
    radial-gradient(circle at 78% 22%, rgba(255,255,255,.55) 0 4px, transparent 5px),
    radial-gradient(circle at 88% 78%, rgba(255,255,255,.45) 0 3px, transparent 4px),
    linear-gradient(135deg, #fff3aa 0%, #bff1ea 46%, #f7d3ff 100%);
  border: 8px solid #000;
  border-radius: 28px;
  padding: 16px;
  box-shadow: 10px 10px 0 rgba(0,0,0,.24);
  overflow: hidden;
}

.wordmagnet-topbar {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255,255,255,.84);
  border: 6px solid #000;
  border-radius: 22px;
  padding: 12px 16px;
  box-shadow: 6px 6px 0 rgba(0,0,0,.18);
}

.wordmagnet-topbar h2 {
  margin: 0;
  font-size: 34px;
  line-height: 1;
  font-weight: 900;
}

.wordmagnet-topbar p {
  margin: 5px 0 0;
  font-size: 17px;
  font-weight: 800;
}

.wordmagnet-score-box {
  min-width: 130px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: center;
}

.wordmagnet-score-box span,
.wordmagnet-score-box strong {
  min-height: 54px;
  display: grid;
  place-items: center;
  background: #d3ff00;
  border: 5px solid #000;
  border-radius: 16px;
  font-size: 22px;
  font-weight: 900;
  box-shadow: 4px 4px 0 rgba(0,0,0,.2);
}

.wordmagnet-score-box strong {
  background: #23d8ff;
}

.wordmagnet-main {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  gap: 10px;
  overflow: hidden;
}

.wordmagnet-target-card {
  width: min(640px, 96%);
  max-height: 100%;
  display: grid;
  grid-template-rows: minmax(150px, 1fr) auto;
  gap: 14px;
  background: #fff;
  border: 8px solid #000;
  border-radius: 30px;
  padding: 16px;
  box-shadow: 10px 10px 0 rgba(0,0,0,.22);
}

.wordmagnet-picture-frame {
  min-height: 200px;
  max-height: min(38vh, 360px);
  display: grid;
  place-items: center;
  background: #dffaff;
  border: 7px solid #000;
  border-radius: 24px;
  overflow: hidden;
}

.wordmagnet-picture-frame img {
  width: 100%;
  height: 100%;
  max-height: min(34vh, 310px);
  object-fit: contain;
  -webkit-user-drag: none;
  pointer-events: none;
}

.wordmagnet-letter-picture {
  width: 180px;
  height: 180px;
  display: grid;
  place-items: center;
  background: #d3ff00;
  border: 8px solid #000;
  border-radius: 36px;
  font-size: 110px;
  font-weight: 900;
}

.wordmagnet-drop-zone {
  min-height: 92px;
  display: grid;
  place-items: center;
  background: #fff0a8;
  border: 7px dashed #000;
  border-radius: 24px;
  font-size: 28px;
  font-weight: 900;
  text-align: center;
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}

.wordmagnet-drop-zone span {
  opacity: .65;
}

.wordmagnet-drop-zone strong {
  display: block;
  background: #d3ff00;
  border: 5px solid #000;
  border-radius: 18px;
  padding: 12px 26px;
  font-size: clamp(30px, 4vw, 48px);
  box-shadow: 5px 5px 0 rgba(0,0,0,.2);
}

.wordmagnet-drop-hover {
  background: #d3ff00 !important;
  border-style: solid !important;
  transform: scale(1.04);
  box-shadow: 0 0 0 8px rgba(255, 255, 255, .8), 0 0 0 15px rgba(35, 216, 255, .75);
  animation: wordmagnetReadyPulse .55s ease infinite alternate;
}

.wordmagnet-drop-correct {
  background: #b7ff9a !important;
  border-style: solid !important;
  animation: wordmagnetCorrectPulse .45s ease both;
}

.wordmagnet-status {
  min-height: 42px;
  background: rgba(255,255,255,.9);
  border: 4px solid #000;
  border-radius: 16px;
  padding: 8px 16px;
  font-size: 22px;
  font-weight: 900;
  text-align: center;
  box-shadow: 4px 4px 0 rgba(0,0,0,.16);
}

.wordmagnet-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 48px;
}

.wordmagnet-top-actions {
  justify-content: flex-end;
  max-width: 560px;
}

.wordmagnet-action-btn {
  min-height: 46px;
  padding: 7px 16px;
  border: 5px solid #000;
  border-radius: 16px;
  background: #23d8ff;
  color: #000;
  font-size: 18px;
  font-weight: 900;
  box-shadow: 5px 5px 0 rgba(0,0,0,.22);
  cursor: pointer;
}

.wordmagnet-read-btn {
  background: #ffcef0;
}

.wordmagnet-read-toggle {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: #fff;
  border: 5px solid #000;
  border-radius: 16px;
  padding: 7px 12px;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 5px 5px 0 rgba(0,0,0,.16);
  cursor: pointer;
}

.wordmagnet-read-toggle input {
  width: 22px;
  height: 22px;
  accent-color: #23d8ff;
}

.wordmagnet-tray {
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  background: rgba(0,0,0,.12);
  border: 6px solid #000;
  border-radius: 24px;
  padding: 12px;
}

.wordmagnet-word-card {
  min-width: 140px;
  min-height: 66px;
  padding: 10px 18px;
  background: #fff;
  border: 6px solid #000;
  border-radius: 18px;
  font-size: clamp(20px, 2.4vw, 34px);
  font-weight: 900;
  color: #000;
  box-shadow: 6px 6px 0 rgba(0,0,0,.22);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.wordmagnet-word-card:nth-child(2n) { background: #ffcef0; }
.wordmagnet-word-card:nth-child(3n) { background: #d3ff00; }
.wordmagnet-word-card:nth-child(4n) { background: #bff1ea; }
.wordmagnet-word-card:nth-child(5n) { background: #fff0a8; }

.wordmagnet-word-card:active {
  cursor: grabbing;
}

.wordmagnet-disabled {
  opacity: .55;
  pointer-events: none;
}

.wordmagnet-card-dragging {
  opacity: .38;
}

.wordmagnet-drag-layer {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}

.wordmagnet-floating-card {
  position: absolute !important;
  z-index: 80;
  transform: translate(-50%, -50%) rotate(-2deg) scale(1.06);
  pointer-events: none !important;
  opacity: .96;
  cursor: grabbing;
  box-shadow: 12px 12px 0 rgba(0,0,0,.24) !important;
}

.wordmagnet-wrong-shake {
  animation: wordmagnetWrongShake .46s ease both;
}

.wordmagnet-success-pop {
  animation: wordmagnetSuccessPop .58s ease both;
}

.wordmagnet-final-wrap {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #bff1ea, #f7d3ff, #fff0a8);
  border: 8px solid #000;
  border-radius: 28px;
  box-shadow: 10px 10px 0 rgba(0,0,0,.24);
}

.wordmagnet-final-card {
  width: min(620px, 90%);
  background: #fff;
  border: 8px solid #000;
  border-radius: 32px;
  padding: 34px;
  text-align: center;
  box-shadow: 12px 12px 0 rgba(0,0,0,.24);
}

.wordmagnet-final-icons {
  font-size: 56px;
  margin-bottom: 8px;
  animation: wordmagnetCorrectPulse .8s ease infinite alternate;
}

.wordmagnet-final-card h2 {
  font-size: 46px;
  margin: 0 0 12px;
}

.wordmagnet-final-card p {
  font-size: 26px;
  font-weight: 900;
}

#wordmagnet-play-again {
  background: #23d8ff;
  min-width: 190px;
  font-size: 24px;
}

.wordmagnet-error-box {
  max-width: 560px;
  margin: 80px auto;
  background: #fff0a8;
  border: 7px solid #000;
  border-radius: 26px;
  padding: 28px;
  text-align: center;
  font-family: "Fredoka", Arial, sans-serif;
  box-shadow: 8px 8px 0 rgba(0,0,0,0.25);
}

.wordmagnet-error-box h2 {
  font-size: 36px;
  margin-top: 0;
}

.wordmagnet-error-box p {
  font-size: 22px;
  font-weight: 800;
}

.hidden {
  display: none !important;
}

@keyframes wordmagnetReadyPulse {
  0% { filter: brightness(1); }
  100% { filter: brightness(1.08); }
}

@keyframes wordmagnetWrongShake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-10px) rotate(-1deg); }
  30% { transform: translateX(10px) rotate(1deg); }
  45% { transform: translateX(-8px) rotate(-1deg); }
  60% { transform: translateX(8px) rotate(1deg); }
  75% { transform: translateX(-4px); }
}

@keyframes wordmagnetSuccessPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.035) rotate(-1deg); }
  100% { transform: scale(1); }
}

@keyframes wordmagnetCorrectPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}


@media (max-width: 1120px) {
  .wordmagnet-topbar {
    grid-template-columns: 1fr auto;
  }

  .wordmagnet-top-actions {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: center;
    max-width: none;
  }

  .wordmagnet-score-box {
    grid-column: 2;
    grid-row: 1;
  }
}

@media (max-width: 900px) {
  .wordmagnet-board {
    padding: 12px;
    gap: 10px;
  }

  .wordmagnet-topbar {
    padding: 10px 12px;
  }

  .wordmagnet-topbar h2 {
    font-size: 28px;
  }

  .wordmagnet-topbar p {
    font-size: 14px;
  }

  .wordmagnet-picture-frame {
    min-height: 150px;
  }

  .wordmagnet-drop-zone {
    min-height: 78px;
    font-size: 22px;
  }

  .wordmagnet-word-card {
    min-width: 120px;
    min-height: 58px;
  }
}

@media (max-width: 620px) {
  .wordmagnet-topbar {
    display: grid;
    grid-template-columns: 1fr;
    text-align: center;
  }

  .wordmagnet-top-actions {
    width: 100%;
    max-width: none;
    justify-content: center;
  }

  .wordmagnet-score-box {
    width: 100%;
    min-width: 0;
  }

  .wordmagnet-tray {
    max-height: 190px;
    overflow: auto;
  }

  .wordmagnet-actions {
    align-items: stretch;
  }

  .wordmagnet-action-btn,
  .wordmagnet-read-toggle {
    width: 100%;
    justify-content: center;
  }
}
