/* Global Variables */
:root {
    --bg-dark: #0f172a;
    --bg-glass: rgba(15, 23, 42, 0.6);
    --bg-glass-hover: rgba(15, 23, 42, 0.8);
    --border-glass: rgba(255, 255, 255, 0.1);

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;

    --primary: #3b82f6;
    --primary-hover: #2563eb;

    --secondary: #ec4899;
    --secondary-hover: #db2777;

    --success: #10b981;
    --error: #ef4444;

    --cell-size: 38px;
    --grid-gap: 2px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(135deg, #020617 0%, #1e1b4b 100%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

h1,
h2,
h3 {
    font-family: 'Outfit', sans-serif;
}

/* Typography Helpers */
.highlight {
    background: linear-gradient(to right, var(--primary), var(--secondary));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.monospaced {
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    letter-spacing: 2px;
}

/* Layout classes */
.screen {
    width: 100%;
    max-width: 1200px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.hidden {
    display: none !important;
}

/* Glassmorphism panel base */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
    padding: 2rem;
}

/* Button Styling */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    color: white;
}

.btn.primary {
    background-color: var(--primary);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

.btn.primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.6);
}

.btn.secondary {
    background-color: var(--secondary);
    box-shadow: 0 0 15px rgba(236, 72, 153, 0.4);
}

.btn.secondary:hover {
    background-color: var(--secondary-hover);
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(236, 72, 153, 0.6);
}

/* Input Styling */
input[type="text"] {
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border-glass);
    background: rgba(255, 255, 255, 0.05);
    color: white;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 2px;
}

input[type="text"]:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
}

/* Lobby Styles */
#lobbyScreen {
    max-width: 500px;
}

.title {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    color: var(--text-secondary);
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-glass);
}

.divider span {
    padding: 0 10px;
}

.join-action {
    display: flex;
    gap: 0.5rem;
}

.join-action input {
    flex: 1;
}

.error-msg {
    color: var(--error);
    font-size: 0.875rem;
    text-align: center;
    min-height: 20px;
}

/* Game Header */
.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    margin-bottom: 2rem;
    border-radius: 12px;
}

.room-info,
.words-info,
.timer-info,
.players-info {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Copy Room Code Tooltip */
.room-info {
    position: relative;
    cursor: pointer;
    transition: color 0.2s;
}

.room-info:hover {
    color: var(--primary);
}

.copyable {
    text-decoration: underline;
    text-underline-offset: 4px;
    text-decoration-color: rgba(255, 255, 255, 0.3);
}

.copy-feedback {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.copy-feedback.show {
    opacity: 1;
}

/* Game Layout Grid */
.game-content {
    display: flex;
    gap: 2rem;
    width: 100%;
    align-items: flex-start;
}

/* Wordsearch Grid */
.grid-container {
    display: grid;
    /* 20 columns */
    grid-template-columns: repeat(20, var(--cell-size));
    /* 16 rows */
    grid-template-rows: repeat(16, var(--cell-size));
    gap: var(--grid-gap);
    padding: 1rem;
    user-select: none;
    flex-shrink: 0;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.1s;
    touch-action: none;
    /* Prevent scrolling on touch */
}

.cell:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Selected cell state during drag */
.cell.selected {
    background: rgba(255, 255, 255, 0.3) !important;
    transform: scale(1.05);
}

@keyframes hintPulse {

    0%,
    100% {
        transform: scale(1);
        box-shadow: none;
    }

    50% {
        background-color: var(--error) !important;
        color: white !important;
        box-shadow: 0 0 20px var(--error);
        transform: scale(1.3);
        z-index: 10;
    }
}

.hint-pulse {
    animation: hintPulse 0.5s ease-in-out 6;
    position: relative;
}

/* Word List aside */
.word-list-container {
    flex: 2;
    /* Take up more space compared to the grid */
    min-width: 280px;
    padding: 1.5rem;
}

.word-list-container h3 {
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 0.5rem;
}

.word-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.word-item {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.3s ease;
    /* Removed truncation properties so full word is always visible */
}

/* Strike through style for found words */
.word-item.found {
    text-decoration: line-through;
    opacity: 0.7;
    font-weight: 600;
    /* Color set inline via JS based on assigned color */
}

/* Modal Styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--success);
}

.modal-content p {
    font-size: 1.25rem;
    margin-bottom: 2rem;
}

.leaderboard-list {
    list-style: none;
    margin-bottom: 2rem;
    text-align: left;
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.leaderboard-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    justify-content: space-between;
}

/* Leaderboard Button */
.btn.leaderboard-btn {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.3);
    margin-top: 0.5rem;
    width: 100%;
}

.btn.leaderboard-btn:hover {
    background: linear-gradient(135deg, #d97706, #b45309);
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.5);
}

/* Player name should not be forced uppercase */
#playerNameInput {
    text-transform: none;
    letter-spacing: normal;
}

/* Utilities */
.mt-4 {
    margin-top: 1rem;
}

/* Scrollbar styling for word list / leaderboard */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Responsive constraints */
@media (max-width: 900px) {
    .game-content {
        flex-direction: column;
        align-items: center;
    }

    .word-list-container {
        width: 100%;
        max-height: none;
    }

    .word-list {
        justify-content: center;
    }

    .grid-container {
        --cell-size: 30px;
        /* Shrink cells slightly on smaller screens */
        margin: 0 auto;
    }
}