:root {
    --green: #6aaa64;
    --yellow: #c9b458;
    --gray: #787c7e;
    --dark-gray: #3a3a3c;
    --white: #ffffff;
    --black: #121213;
    --light-gray: #818384;
    --modal-bg: #121213;
    --border-color: #3a3a3c;
    --key-bg: #818384;
    --key-text: #ffffff;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--black);
    color: var(--white);
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

.container {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 50px;
    border-bottom: 1px solid var(--border-color);
    padding: 0 16px;
}

header h1 {
    font-weight: 700;
    font-size: 36px;
    letter-spacing: 0.2rem;
    text-align: center;
    flex-grow: 1;
}

button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--white);
}

#game-board {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 10px;
    box-sizing: border-box;
    flex-grow: 1;
    width: 100%;
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-gap: 5px;
    width: 100%;
    max-width: 350px;
    margin-bottom: 5px;
}

.tile {
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid var(--dark-gray);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    text-transform: uppercase;
    user-select: none;
    background-color: transparent;
}

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

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

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

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

@keyframes pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes flip {
    0% {
        transform: rotateX(0);
        border-color: var(--light-gray);
    }

    50% {
        transform: rotateX(90deg);
        border-color: var(--light-gray);
    }

    100% {
        transform: rotateX(0);
    }
}

.shake {
    animation: shake 0.5s;
}

@keyframes shake {
    0% {
        transform: translateX(0);
    }

    10% {
        transform: translateX(-5px);
    }

    20% {
        transform: translateX(5px);
    }

    30% {
        transform: translateX(-5px);
    }

    40% {
        transform: translateX(5px);
    }

    50% {
        transform: translateX(-5px);
    }

    60% {
        transform: translateX(5px);
    }

    70% {
        transform: translateX(-5px);
    }

    80% {
        transform: translateX(5px);
    }

    90% {
        transform: translateX(-5px);
    }

    100% {
        transform: translateX(0);
    }
}

#keyboard {
    height: 200px;
    margin: 0 8px;
    user-select: none;
}

.keyboard-row {
    display: flex;
    width: 100%;
    margin: 0 auto 8px;
    touch-action: none;
}

.key {
    font-family: inherit;
    font-weight: bold;
    border: 0;
    padding: 0;
    margin: 0 6px 0 0;
    height: 58px;
    border-radius: 4px;
    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;
}

.key:last-of-type {
    margin: 0;
}

.key.large {
    flex: 1.5;
    font-size: 12px;
}

.key[data-state='correct'] {
    background-color: var(--green);
}

.key[data-state='present'] {
    background-color: var(--yellow);
}

.key[data-state='absent'] {
    background-color: var(--dark-gray);
}

/* Modals */
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--modal-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    z-index: 1000;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 23px 0 rgba(0, 0, 0, 0.2);
}

.hidden {
    display: none !important;
}

#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 900;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.close-btn {
    font-size: 24px;
    font-weight: bold;
}

#leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

#leaderboard-table th,
#leaderboard-table td {
    text-align: left;
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
}

#submission-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

#player-name {
    padding: 10px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background-color: var(--dark-gray);
    color: var(--white);
}

#submit-score-btn {
    padding: 10px;
    background-color: var(--green);
    color: var(--white);
    border-radius: 4px;
    font-weight: bold;
}

#stats-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 20px 0;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-size: 30px;
    font-weight: bold;
}

.stat-label {
    font-size: 12px;
}

#toast-container {
    position: fixed;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background-color: var(--white);
    color: var(--black);
    padding: 10px 20px;
    border-radius: 4px;
    font-weight: bold;
    opacity: 1;
    transition: opacity 0.3s;
}