:root {
    --bg-color: #FFFBF0;
    --text-color: #5D5D5D;
    --card-bg: #FFFFFF;

    /* Cozy Palette */
    --correct-color: #B5EAD7; /* Pastel Green */
    --present-color: #87CEEB; /* Sky Blue */
    --absent-color: #D3C4BE; /* Warm Gray */
    --default-border: #E0E0E0;
    --filled-border: #888;

    --key-bg: #EEE;
    --key-text: #555;

    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --radius: 8px;
}

body {
    margin: 0;
    font-family: 'Nunito', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    overflow-y: auto;
}

.game-container {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 10px;
    box-sizing: border-box;
}

header {
    text-align: center;
    margin-bottom: 15px;
}

h1 {
    margin: 10px 0 5px 0;
    color: #FFDAC1; /* Peach */
    font-size: 2.5rem;
    text-shadow: 2px 2px 0px #FFB7B2; /* Pastel Red/Pink Shadow */
    letter-spacing: 1px;
}

.subtitle {
    margin-top: 0;
    color: #B5EAD7;
    font-weight: bold;
    letter-spacing: 1px;
}

#boards-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-gap: 15px;
    margin-bottom: 20px;
    width: 100%;
    max-width: 500px;
}

.board {
    display: grid;
    grid-template-rows: repeat(9, 1fr);
    grid-gap: 4px;
    background: var(--card-bg);
    padding: 10px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    opacity: 1;
    transition: opacity 0.5s;
}

.board.solved {
    opacity: 0.6;
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-gap: 4px;
}

.tile {
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid var(--default-border);
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: bold;
    text-transform: uppercase;
    border-radius: var(--radius);
    background-color: var(--card-bg);
    transition: transform 0.2s, background-color 0.5s, border-color 0.5s;
    user-select: none;
    box-sizing: border-box;
}

/* Tile States */
.tile[data-state='active'] {
    border-color: var(--filled-border);
    animation: pop 0.1s;
}

.tile[data-state='correct'] {
    background-color: var(--correct-color);
    border-color: var(--correct-color);
    color: white;
}

.tile[data-state='present'] {
    background-color: var(--present-color);
    border-color: var(--present-color);
    color: white;
}

.tile[data-state='absent'] {
    background-color: var(--absent-color);
    border-color: var(--absent-color);
    color: white;
}

/* Animations */
@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes flip {
    0% {
        transform: rotateX(0);
        background-color: var(--card-bg);
        border-color: var(--filled-border);
    }
    50% {
        transform: rotateX(90deg);
        background-color: var(--card-bg);
        border-color: var(--filled-border);
    }
    100% {
        transform: rotateX(0);
    }
}

.tile.flip {
    animation: flip 0.5s ease forwards;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-3px); }
    20%, 40%, 60%, 80% { transform: translateX(3px); }
}

.board.shake {
    animation: shake 0.5s;
}

/* Keyboard */
#keyboard-container {
    width: 100%;
    margin-bottom: 20px;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
    touch-action: manipulation;
}

button {
    font-family: inherit;
    font-weight: bold;
    border: none;
    padding: 0;
    margin: 0 3px;
    height: 50px;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    background-color: var(--key-bg);
    color: var(--key-text);
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    font-size: 1.1rem;
    transition: transform 0.1s;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    /* CSS custom properties to hold quadrant colors, initialized to key-bg */
    --q1: var(--key-bg);
    --q2: var(--key-bg);
    --q3: var(--key-bg);
    --q4: var(--key-bg);
    /* 2x2 grid using linear gradient */
    background: 
        linear-gradient(to right, var(--q1) 50%, var(--q2) 50%) top / 100% 50% no-repeat,
        linear-gradient(to right, var(--q3) 50%, var(--q4) 50%) bottom / 100% 50% no-repeat;
}

button.wide-button {
    flex: 1.5;
    font-size: 0.9rem;
}

.spacer-half {
    flex: 0.5;
}

button:active {
    transform: translateY(2px);
    box-shadow: none;
}

/* Text color for button is white if any quadrant has a color */
button.has-color {
    color: white;
}

/* Message Container */
#message-container {
    position: fixed;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    pointer-events: none;
}

.message {
    background-color: #555;
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.3s;
}

.message.show {
    opacity: 1;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 251, 240, 0.8); /* Cream with opacity */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(2px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: var(--shadow);
    text-align: center;
    max-width: 80%;
    animation: popIn 0.3s ease;
}

.modal-content h2 {
    color: #B5EAD7; /* Pastel Green */
    font-size: 2.5rem;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0px #FFF;
}

#correct-words-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

.correct-word-box {
    background: var(--key-bg);
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: bold;
    text-transform: uppercase;
    color: var(--text-color);
}

#close-modal {
    background: #B5EAD7;
    color: #555;
    border: none;
    padding: 12px 25px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    margin: 0 auto;
}

#close-modal:hover {
    transform: scale(1.05);
    background: #A3D8C5;
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Lobby Styles */
input[type="text"] {
    padding: 15px;
    font-size: 1.2rem;
    border: 3px solid #EEE;
    border-radius: 12px;
    outline: none;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    color: #555;
    font-weight: bold;
    margin-bottom: 20px;
    transition: border-color 0.3s;
}

input[type="text"]:focus {
    border-color: #B5EAD7;
}

.lobby-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.join-section {
    display: flex;
    gap: 10px;
}

.join-section input {
    margin-bottom: 0;
    flex: 1;
    text-transform: uppercase;
}

.join-section button {
    flex: 1;
}

.btn-primary {
    background-color: #B5EAD7;
    color: #444;
    padding: 12px 20px;
    font-size: 1.1rem;
}

.btn-secondary {
    background-color: #EEE;
    color: #333;
    padding: 12px 20px;
    font-size: 1.1rem;
}

.hidden {
    display: none !important;
}

.game-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    backdrop-filter: blur(5px);
}

.game-overlay.hidden {
    display: none !important;
}

.overlay-content {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 20px;
    box-shadow: var(--shadow);
    text-align: center;
    max-width: 90%;
    width: 400px;
    animation: popIn 0.3s ease;
    box-sizing: border-box;
}

.online-section {
    background: var(--bg-color);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
    border: 2px solid var(--default-border);
}

.online-section h3 {
    margin: 0 0 5px 0;
    text-align: center;
    color: var(--text-color);
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    h1 {
        font-size: 1.8rem;
    }
    .game-container {
        padding: 10px 5px;
    }
    #boards-wrapper {
        grid-gap: 8px;
    }
    .board {
        padding: 5px;
        border-radius: 8px;
        grid-gap: 3px;
    }
    .row {
        grid-gap: 3px;
    }
    .tile {
        font-size: 1.2rem;
        border-width: 1.5px;
    }
    button {
        margin: 0 1.5px;
        height: 45px;
        font-size: 0.95rem;
        border-radius: 5px;
    }
    button.wide-button {
        font-size: 0.8rem;
    }
    .overlay-content {
        padding: 20px;
        width: 95%;
    }
    input[type="text"] {
        padding: 10px;
        font-size: 1rem;
    }
}
