:root {
    --primary-color: #4a90e2;
    --secondary-color: #f5a623;
    --background-color: #f0f8ff;
    --text-color: #333;
    --correct-color: #50e3c2;
    --incorrect-color: #d0021b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
}

h1, h2, h3 {
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 20px;
}

.screen {
    display: none;
    width: 100%;
    max-width: 800px;
    padding: 20px;
    animation: fadeIn 0.5s ease-in-out;
}

.screen.active {
    display: block;
}

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

.score-container {
    font-size: 1.2rem;
    font-weight: bold;
    text-align: center;
    margin-bottom: 20px;
    padding: 10px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#reset-all-btn {
    display: block;
    margin: -10px auto 20px;
    background-color: var(--secondary-color);
}

#reset-all-btn:hover {
    background-color: #d8901f;
}

.game-options {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.game-option {
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.game-option:hover {
    transform: scale(1.05);
}

.game-option img {
    width: 150px;
    height: 150px;
    object-fit: cover;
    border-radius: 15px;
    border: 3px solid var(--primary-color);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.game-option h3 {
    display: none;
}

.game-option button {
    display: none; /* Hide button if it was missed in HTML */
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

button:hover {
    background-color: #357abd;
}

.game-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}
.game-controls .score-container {
    margin-bottom: 0;
    flex-grow: 1;
}

/* --- Game 1: Word Search --- */
#word-search-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}
#word-search-grid {
    display: grid;
    grid-template-columns: repeat(10, 35px);
    grid-template-rows: repeat(10, 35px);
    gap: 2px;
    user-select: none;
    touch-action: none;
}
.grid-cell {
    width: 35px;
    height: 35px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: white;
    border: 1px solid #ddd;
    font-size: 1.2rem;
    text-transform: uppercase;
}
.grid-cell.selected {
    background-color: var(--secondary-color);
    color: white;
}
.grid-cell.found {
    background-color: var(--correct-color);
    color: white;
}
#word-search-list {
    list-style: none;
}
#word-search-list li {
    padding: 5px;
    font-size: 1.2rem;
}
#word-search-list li.found {
    text-decoration: line-through;
    color: #888;
}

/* --- Game 2: Drag and Drop --- */
#words-to-drag {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
    min-height: 50px;
}
.draggable-word {
    padding: 10px 20px;
    background-color: var(--secondary-color);
    color: white;
    border-radius: 8px;
    cursor: grab;
    user-select: none;
    touch-action: none;
}
.draggable-word.dragging {
    opacity: 0.5;
    position: fixed; /* Allow moving over other elements */
    z-index: 1000;
    pointer-events: none; /* Let events pass through to elements below */
}
.drop-zones {
    display: flex;
    justify-content: space-around;
    gap: 20px;
    flex-wrap: wrap;
}
.drop-zone {
    flex: 1;
    min-width: 150px;
    min-height: 200px;
    border: 3px dashed var(--primary-color);
    border-radius: 10px;
    padding: 10px;
    background-color: #fff;
    transition: background-color 0.2s;
}
.drop-zone.over {
    background-color: #e0f0ff;
}
.drop-zone h3 {
    margin-bottom: 10px;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 5px;
}
.drop-zone .draggable-word {
    margin: 5px 0;
    cursor: auto;
}

.draggable-word.correct-drop {
    background-color: var(--correct-color);
    cursor: not-allowed;
}

.draggable-word.incorrect-drop {
    animation: shake 0.5s ease-in-out;
}

#check-game2-btn {
    display: block;
    margin: 20px auto 0;
    padding: 12px 25px;
    font-size: 1.2rem;
    font-weight: bold;
    background-color: var(--secondary-color);
}
#check-game2-btn:hover {
    background-color: #d8901f;
}

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

/* --- Game 3: Hangman --- */
#hangman-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}
#hangman-drawing p {
    font-size: 1.2rem;
    font-weight: bold;
}
#lives-container {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}
.heart {
    font-size: 2.5rem;
    color: var(--incorrect-color);
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.heart.lost {
    opacity: 0.2;
    transform: scale(0.9);
}
#word-display {
    display: flex;
    gap: 10px;
    font-size: 2rem;
    letter-spacing: 5px;
    min-height: 50px;
}
.letter-placeholder {
    border-bottom: 3px solid var(--text-color);
    width: 30px;
    height: 40px;
    text-align: center;
    line-height: 40px;
    text-transform: uppercase;
}
#keyboard {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    max-width: 100%;
}
.key {
    width: 40px;
    height: 40px;
    border-radius: 5px;
    background-color: #fff;
    border: 1px solid #ccc;
    font-size: 1rem;
    cursor: pointer;
    color: black; /* Set key text color to black */
}
.key:disabled {
    background-color: #ddd;
    color: #888;
    cursor: not-allowed;
}

#game3-feedback, #game2-feedback {
    font-size: 1.5rem;
    font-weight: bold;
    min-height: 30px;
    text-align: center;
    margin-top: 20px;
}
.feedback-correct { color: var(--correct-color); }
.feedback-incorrect { color: var(--incorrect-color); }

/* Mobile adjustments */
@media (max-width: 600px) {
    body {
        padding: 5px;
    }
    .screen {
        padding: 10px;
    }
    .game-options {
        flex-direction: column;
        align-items: center;
    }
    #word-search-grid {
        grid-template-columns: repeat(10, minmax(25px, 1fr));
        grid-template-rows: repeat(10, minmax(25px, 1fr));
        gap: 1px;
    }
    .grid-cell {
        width: auto;
        height: auto;
        font-size: 0.9rem;
    }
    #words-to-drag {
        margin-bottom: 20px;
    }
    .drop-zones {
        flex-direction: row; /* Ensure horizontal layout */
        flex-wrap: nowrap;   /* Prevent wrapping to the next line */
        gap: 5px;          /* Reduce gap between boxes */
    }
    .drop-zone {
        min-width: 0;
        min-height: 150px;
        padding: 5px;
    }
    .key {
        width: calc(100% / 9 - 8px); /* Adjust to fit more keys per row */
        height: 40px;
    }
}