/* --- Matching Game Styles --- */

.game-container-override {
  margin-top: -1rem; /* Pull the container up */
}

#game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* Explicitly set height to prevent overflow on desktop */
  height: 88vh;
  width: 100%;
  max-width: 1200px; /* Limit width on very wide screens */
  margin: auto;
}

#game-board {
  width: 100%;
  height: 100%;
  margin: 0;
  display: flex;
  gap: 1rem;
  justify-content: center;
}

#words-column,
#images-column {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.5vh, 15px);
    height: 100%;
    flex: 1 1 45%;
    max-width: 480px; /* Prevent tiles from being too wide */
}

.tile-slot {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Distribute vertical space evenly on desktop */
  flex: 1 1 0;
  min-height: 0; /* Allow slots to shrink properly */
}

.game-tile {
  background-color: #fff;
  border: 2px solid #e5e5e5;
  border-bottom-width: 4px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: all 0.2s ease;
  padding: clamp(5px, 1vh, 10px);
  width: 100%;
  height: 100%;
}

.word-tile {
  font-size: clamp(0.9rem, 3vh, 1.7rem);
  font-weight: bold;
  color: #4c4c4c;
  text-align: center;
  line-height: 1.2;
  
  /* Graceful Word Wrapping */
  overflow-wrap: break-word;
}

.image-tile img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.game-tile:hover {
  background-color: #f7f7f7;
}

.game-tile.active {
  background-color: #ddf4ff;
  border-color: #84d8ff;
}

.game-tile.incorrect {
  background-color: #ffdddd;
  border-color: #ff8484;
  animation: shake 0.4s;
}

.game-tile.is-correct {
  background-color: #d4edda;
  border-color: #28a745;
}

.game-tile.disappearing {
  opacity: 0;
  transition: opacity 0.6s ease-in-out;
}

.game-tile.matched {
  background-color: #eee;
  color: #afafaf;
  border-color: #e5e5e5;
  cursor: default;
}

.game-tile.matched img {
  opacity: 0.5;
}

.game-tile.is-revealing {
  animation: reveal 0.4s ease;
}

@keyframes reveal {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Container for the success message animation */
.game-feedback-container {
    position: relative;
    width: 100%;
    max-width: 28rem; /* max-w-md */
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    animation: fadeIn 0.5s 0.2s ease-out forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Confetti animation styles */
.confetti {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: #93c5fd; /* blue-300 */
    opacity: 0.9;
    animation: fall 5s linear infinite;
    border-radius: 50%;
    z-index: 20; /* Ensure confetti is on top */
}

@keyframes fall {
    0% {
        transform: translateY(-10vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(110vh) rotate(720deg);
        opacity: 0;
    }
}

/* --- Responsive Adjustments for Mobile --- */
@media (max-width: 767px) {
    #game-wrapper {
        height: 88vh;
        padding: 0 10px;
    }

    #game-board {
        height: 100%;
        gap: 10px;
    }

    #words-column,
    #images-column {
        flex: 1 1 calc(50% - 5px);
        max-width: calc(50% - 5px);
        height: 100%;
        gap: 10px;
    }

    .tile-slot {
        /* Distribute vertical space like on desktop */
        flex: 1 1 0;
        min-height: 0;
    }

    .game-tile {
        /* The tile is now sized by the slot, not self-sized */
        width: 100%;
        height: 100%;
    }

    .word-tile {
        /* Font size now scales with viewport height, which is more reliable on mobile */
        font-size: clamp(0.8rem, 2.2vh, 1.2rem);
        line-height: 1.2;

        /* Graceful Word Wrapping */
        overflow-wrap: break-word;
    }
}

/* --- Adjustments for Extra Small/Short Screens (e.g., iPhone SE) --- */
@media (max-width: 767px) and (max-height: 670px) {
    #game-wrapper {
        /* Reduce height significantly to fit on short screens */
        height: 75vh;
    }

    #words-column,
    #images-column {
        /* Reduce vertical gap between tiles to save space */
        gap: 8px;
    }

    .word-tile {
        /* Slightly reduce font size for the smaller space */
        font-size: clamp(0.8rem, 2vh, 1.2rem);
        line-height: 1.15;
    }
}