/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    width: 100%;
    max-width: 1200px;
    height: 95vh;
    margin: 10px;
}

.screen {
    width: 100%;
    height: 100%;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.hidden {
    display: none;
}

/* Username screen styles */
#username-screen {
    display: flex;
    justify-content: center;
    align-items: center;
}

.username-card {
    display: flex;
    flex-direction: column;
    padding: 40px;
    height: 100%;
    text-align: center;
}

.card-footer {
    margin-top: auto;  /* Pushes footer to the bottom */
    font-size: 0.8em;
    color: #999;
}



.username-card h1 {
    font-size: 3em;
    margin-bottom: 10px;
    color: #667eea;
}

.username-card p {
    color: #666;
    margin-bottom: 30px;
    font-size: 1.1em;
}

.info-text {
    margin-top: 15px;
    font-size: 0.85em !important;
    color: #999 !important;
}

.error-text {
    color: #e74c3c;
    font-size: 0.9em;
    margin: 10px 0;
    padding: 8px;
    background: rgba(231, 76, 60, 0.1);
    border-radius: 5px;
    display: none;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#username-input {
    width: 100%;
    padding: 15px;
    font-size: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    margin-bottom: 10px;
    transition: border-color 0.3s;
}

#username-input:focus {
    outline: none;
    border-color: #667eea;
}

#join-btn {
    width: 100%;
    padding: 15px;
    font-size: 16px;
    font-weight: bold;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

#join-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

#join-btn:active {
    transform: translateY(0);
}

#join-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Chat screen styles */
#chat-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h2 {
    font-size: 1.5em;
}

.user-info {
    display: flex;
    gap: 10px;
    align-items: center;
}

.current-user {
    font-size: 0.9em;
    opacity: 0.9;
    display: block;
    margin-top: 5px;
}

.user-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.85em;
}

.leave-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.2s;
}

.leave-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

/* Main chat area with sidebar */
.chat-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chat messages area */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f5f5f5;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Custom scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Message styles */
.message {
    padding: 12px 16px;
    border-radius: 10px;
    background: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    animation: slideIn 0.3s ease-out;
    max-width: 80%;
    align-self: flex-start;
}

/* Own message (from current user) */
.message.own-message {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    align-self: flex-end;
}

.message.own-message .message-username {
    color: rgba(255, 255, 255, 0.9);
}

.message.own-message .message-time {
    color: rgba(255, 255, 255, 0.7);
}

.message.own-message .message-text {
    color: white;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.message-username {
    font-weight: bold;
    color: #667eea;
    font-size: 0.9em;
}

.message-time {
    font-size: 0.75em;
    color: #999;
}

.message-emoji {
    font-size: 3em;
    text-align: center;
}

.message-text {
    font-size: 1em;
    color: #333;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* Reaction buttons area */
.message-reactions {
    margin-top: 8px;
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.reaction-picker {
    display: flex;
    gap: 5px;
    margin-top: 0;
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
}

.message:hover .reaction-picker {
    opacity: 1;
    max-height: 50px;
    margin-top: 8px;
}

.reaction-btn {
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 15px;
    padding: 3px 8px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.reaction-btn:hover {
    background: rgba(102, 126, 234, 0.2);
    transform: scale(1.05);
}

.reaction-count {
    font-size: 0.75em;
    font-weight: bold;
    color: #667eea;
}

.add-reaction-btn {
    background: #f0f0f0;
    border: 1px dashed #ccc;
    border-radius: 15px;
    padding: 3px 10px;
    font-size: 1.1em;
    cursor: pointer;
    transition: all 0.2s;
}

.add-reaction-btn:hover {
    background: #e0e0e0;
    transform: scale(1.1);
}

/* System messages (user joined/left) */
.system-message {
    text-align: center;
    padding: 8px;
    background: #e8f4f8;
    border-radius: 5px;
    color: #666;
    font-size: 0.9em;
    font-style: italic;
}

/* Typing indicator */
.typing-indicator {
    padding: 10px 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    font-size: 0.85em;
    color: #666;
    font-style: italic;
    min-height: 35px;
}

/* Message input area */
.message-input-area {
    display: flex;
    gap: 10px;
    padding: 15px;
    background: white;
    border-top: 2px solid #e0e0e0;
}

#text-input {
    flex: 1;
    padding: 12px 15px;
    font-size: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    transition: border-color 0.3s;
}

#text-input:focus {
    outline: none;
    border-color: #667eea;
}

.send-btn {
    padding: 12px 25px;
    font-size: 15px;
    font-weight: bold;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.send-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.send-btn:active {
    transform: translateY(0);
}

/* Emoji palette */
.emoji-palette {
    background: white;
    border-top: 2px solid #e0e0e0;
    padding: 15px;
}

.emoji-palette h3 {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 10px;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 8px;
    max-height: 150px;
    overflow-y: auto;
}

.emoji-btn {
    background: #f5f5f5;
    border: 2px solid transparent;
    border-radius: 10px;
    padding: 10px;
    font-size: 2em;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.emoji-btn:hover {
    background: #667eea;
    transform: scale(1.1);
    border-color: #667eea;
}

.emoji-btn:active {
    transform: scale(0.95);
}

/* Online users sidebar */
.online-users-sidebar {
    width: 250px;
    background: #f9f9f9;
    border-left: 2px solid #e0e0e0;
    padding: 20px;
    overflow-y: auto;
}

.online-users-sidebar h3 {
    font-size: 1em;
    color: #667eea;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

.online-users-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.online-user-item {
    padding: 10px;
    background: white;
    border-radius: 8px;
    border-left: 3px solid #667eea;
    font-size: 0.9em;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.online-user-item:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.online-user-item.current-user-item {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    font-weight: bold;
}

.user-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4caf50;
}

.user-emoji-count {
    margin-left: auto;
    font-size: 0.75em;
    color: #667eea;
    font-weight: bold;
}

/* Emoji category tabs */
.emoji-category-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.emoji-category-tab {
    padding: 8px 12px;
    background: #f0f0f0;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.75em;
    white-space: nowrap;
    transition: all 0.2s;
}

.emoji-category-tab:hover {
    background: #e0e0e0;
}

.emoji-category-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

/* Emoji leaderboard */
.emoji-leaderboard {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #e0e0e0;
}

.emoji-leaderboard h4 {
    font-size: 0.9em;
    color: #667eea;
    margin-bottom: 10px;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: white;
    border-radius: 8px;
    font-size: 0.85em;
    transition: all 0.2s;
}

.leaderboard-item:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.leaderboard-rank {
    font-size: 1.2em;
}

.leaderboard-name {
    flex: 1;
    font-weight: bold;
}

.leaderboard-count {
    background: rgba(102, 126, 234, 0.1);
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: bold;
    color: #667eea;
    font-size: 0.9em;
}

.no-data {
    text-align: center;
    color: #999;
    font-size: 0.85em;
    padding: 10px;
    font-style: italic;
}

/* Responsive design */
@media (max-width: 900px) {
    .online-users-sidebar {
        display: none;
    }
}

@media (max-width: 600px) {
    .container {
        margin: 10px;
        height: 95vh;
    }

    .username-card {
        padding: 20px;
    }

    .username-card h1 {
        font-size: 2em;
    }

    .chat-header {
        padding: 15px;
    }

    .emoji-grid {
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    }

    .message-emoji {
        font-size: 2em;
    }

    .message {
        max-width: 90%;
    }

    .emoji-category-tabs {
        font-size: 0.7em;
    }
}