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

    --p1-color: #A7C7E7;
    /* Pastel Blue */
    --p1-dark: #769ECB;
    --p2-color: #B4F8C8;
    /* Pastel Green */
    --p2-dark: #88D8A0;

    --highlight: #B4F8C8;
    /* Selection Green */
    --found: #EEEEEE;

    --shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
    --radius: 20px;
}

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

/* Screens */
.screen {
    display: none;
    position: fixed;
    width: 100%;
    height: 100%;
    background: rgba(255, 251, 240, 0.95);
    z-index: 50;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.screen.active {
    display: flex;
}

.game-layer {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
    max-width: 800px;
    padding: 10px;
    box-sizing: border-box;
}

.game-layer.active {
    display: flex;
}

/* Components */
.card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    width: 90%;
    max-width: 400px;
}

h1 {
    margin: 0;
    color: #FFDAC1;
    font-size: 2.5rem;
    text-shadow: 2px 2px 0 #FFB7B2;
}

.subtitle {
    color: #87CEEB;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 20px;
}

button {
    border: none;
    padding: 12px 20px;
    border-radius: 50px;
    font-family: inherit;
    font-weight: 800;
    cursor: pointer;
    font-size: 1rem;
    transition: transform 0.1s;
    width: 100%;
    margin: 5px 0;
}

button:active {
    transform: scale(0.98);
}

.btn-primary {
    background: #B5EAD7;
    color: #555;
}

.btn-secondary {
    background: #E2F0CB;
    color: #666;
}

.btn-small {
    width: auto;
    padding: 10px 20px;
}

/* Lobby Styles matched to Wordplay */
input,
select {
    width: 100%;
    padding: 15px;
    border: 3px solid #EEE;
    border-radius: 12px;
    font-size: 1.2rem;
    box-sizing: border-box;
    font-family: inherit;
    font-weight: bold;
    color: #555;
    outline: none;
    text-align: center;
    margin-bottom: 10px;
    transition: border-color 0.3s;
}

input:focus,
select:focus {
    border-color: #B5EAD7;
}

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

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

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

.join-section button {
    flex: 1;
    margin: 0;
    /* Remove default margin */
}

/* Remove label styles if no longer used or keep for safety */
label {
    display: none;
    /* Hide labels as we use placeholders now */
}

.divider {
    display: none;
    /* Removed */
}

/* Game CSS */
.game-header {
    display: flex;
    justify-content: center;
    /* Center scores */
    align-items: center;
    width: 100%;
    padding: 10px 0;
}

.game-title-header {
    font-size: 2.5rem;
    color: #FFDAC1;
    text-shadow: 2px 2px 0 #FFB7B2;
    margin-bottom: 10px;
    margin-top: 0;
    text-align: center;
    width: 100%;
}

.btn-icon {
    width: auto;
    padding: 8px 15px;
    margin: 0;
    background: #FFF;
    box-shadow: var(--shadow);
}

.game-info {
    text-align: center;
    font-weight: 800;
    color: #AAA;
}

#categoryDisplay {
    color: var(--text-color);
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 5px;
    text-align: center;
}

.scores {
    display: flex;
    gap: 10px;
}

.p-badge {
    padding: 8px 15px;
    border-radius: 20px;
    background: #FFF;
    font-weight: 800;
    opacity: 1;
    /* Always visible */
    transition: 0.3s;
    box-shadow: var(--shadow);
}

.p1 {
    color: var(--p1-dark);
}

.p2 {
    color: var(--p2-dark);
}

.game-layout {
    flex: 1;
    display: flex;
    flex-direction: row;
    /* Side by side */
    gap: 20px;
    overflow: hidden;
    justify-content: center;
    align-items: center;
    /* Vertically center grid and list */
    width: 100%;
}

.board-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.grid-container {
    background: #FFF;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    /* Stack score and grid */
    gap: 15px;
    align-items: center;
    justify-content: center;
    position: relative;
    touch-action: none;
    /* Prevent scroll on drag */
}

.word-grid {
    display: grid;
    gap: 4px;
    user-select: none;
}

.cell {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #777;
    border-radius: 8px;
    font-size: 1.1rem;
    transition: background 0.2s;
    cursor: pointer;
}

.cell.selected {
    background: var(--highlight);
    color: #444;
    transform: scale(1.1);
}

.cell.found-p1 {
    background: var(--p1-color);
    color: #FFF;
}

.cell.found-p2 {
    background: var(--p2-color);
    color: #FFF;
}

.cell.temp-selected {
    background: #FFD1DC;
    /* Light Pink for dragging */
    color: #444;
    transform: scale(1.05);
}

.sidebar {
    width: 200px;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--radius);
    padding: 15px;
}

.word-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.word-item {
    padding: 5px 10px;
    border-radius: 8px;
    background: #FFF;
    font-size: 0.9rem;
    font-weight: 700;
    color: #888;
    transition: 0.3s;
}

.word-item.found {
    text-decoration: line-through;
    opacity: 0.5;
    background: transparent;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #FFF;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    animation: popUp 0.3s;
}

@keyframes popUp {
    from {
        transform: scale(0.8);
    }

    to {
        transform: scale(1);
    }
}

@media (max-width: 600px) {
    .game-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 120px;
    }

    .word-list {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .cell {
        width: 28px;
        height: 28px;
        font-size: 0.9rem;
    }
}