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

:root {
    /* Default Theme (Purple) */
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    --primary-color: #667eea;
    --primary-hover: #764ba2;
    --container-bg: #ffffff;
    --text-color: #333333;
    --text-secondary: #555555;
    --text-tertiary: #666666;
    --border-color: #e2e8f0;
    --surface-bg: #f7fafc;
    --pulse-active: #ff6b6b;
    --pulse-shadow: rgba(255, 107, 107, 0.6);
    --message-own-bg: #667eea;
    --message-own-color: #ffffff;
    --message-other-bg: #f0f0f0;
    --message-other-color: #333333;
}

body.theme-light {
    --bg-gradient-start: #97B22D;
    --bg-gradient-end: #89751B;
    --primary-color: #97B22D;
    --primary-hover: #89751B;
    --container-bg: #FEFCAD;
    --text-color: #2d3748;
    --text-secondary: #4a5568;
    --text-tertiary: #718096;
    --border-color: #E3DE81;
    --surface-bg: #f1ff72;
    --pulse-active: #89751B;
    --pulse-shadow: rgba(137, 117, 27, 0.6);
    --message-own-bg: #97B22D;
    --message-own-color: #ffffff;
    --message-other-bg: #E3DE81;
    --message-other-color: #2d3748;
}

body.theme-dark {
    --bg-gradient-start: #2d3d0f;
    --bg-gradient-end: #1a2208;
    --primary-color: #97B22D;
    --primary-hover: #E3DE81;
    --container-bg: #1f2d0a;
    --text-color: #E3DAB2;
    --text-secondary: #E3DE81;
    --text-tertiary: #97B22D;
    --border-color: #3d4d1f;
    --surface-bg: #2a3a12;
    --pulse-active: #E3DE81;
    --pulse-shadow: rgba(227, 222, 129, 0.6);
    --message-own-bg: #97B22D;
    --message-own-color: #ffffff;
    --message-other-bg: #3d4d1f;
    --message-other-color: #E3DAB2;
}

body.theme-warm-light {
    --bg-gradient-start: #C6BE28;
    --bg-gradient-end: #97B22D;
    --primary-color: #E49A32;
    --primary-hover: #C6BE28;
    --container-bg: #FEFCAD;
    --text-color: #3d3d1f;
    --text-secondary: #5d5d3f;
    --text-tertiary: #7d7d5f;
    --border-color: #E3DAB2;
    --surface-bg: #faedb6;
    --pulse-active: #E49A32;
    --pulse-shadow: rgba(228, 154, 50, 0.6);
    --message-own-bg: #E49A32;
    --message-own-color: #ffffff;
    --message-other-bg: #E3DAB2;
    --message-other-color: #3d3d1f;
}

body.theme-warm-dark {
    --bg-gradient-start: #2a2510;
    --bg-gradient-end: #1a1808;
    --primary-color: #E49A32;
    --primary-hover: #C6BE28;
    --container-bg: #2d2815;
    --text-color: #FEFCAD;
    --text-secondary: #E3DAB2;
    --text-tertiary: #C6BE28;
    --border-color: #4a3f1a;
    --surface-bg: #3a3220;
    --pulse-active: #E49A32;
    --pulse-shadow: rgba(228, 154, 50, 0.6);
    --message-own-bg: #E49A32;
    --message-own-color: #ffffff;
    --message-other-bg: #4a3f1a;
    --message-other-color: #FEFCAD;
}

body.theme-red {
    --bg-gradient-start: #dc2626;
    --bg-gradient-end: #991b1b;
    --primary-color: #ef4444;
    --primary-hover: #dc2626;
    --container-bg: #ffffff;
    --text-color: #1f2937;
    --text-secondary: #374151;
    --text-tertiary: #4b5563;
    --border-color: #fecaca;
    --surface-bg: #fef2f2;
    --pulse-active: #b91c1c;
    --pulse-shadow: rgba(185, 28, 28, 0.6);
    --message-own-bg: #ef4444;
    --message-own-color: #ffffff;
    --message-other-bg: #fecaca;
    --message-other-color: #1f2937;
}

body.theme-pink {
    --bg-gradient-start: #ec4899;
    --bg-gradient-end: #be185d;
    --primary-color: #f472b6;
    --primary-hover: #ec4899;
    --container-bg: #ffffff;
    --text-color: #1f2937;
    --text-secondary: #374151;
    --text-tertiary: #4b5563;
    --border-color: #fbcfe8;
    --surface-bg: #fdf2f8;
    --pulse-active: #be185d;
    --pulse-shadow: rgba(190, 24, 93, 0.6);
    --message-own-bg: #f472b6;
    --message-own-color: #ffffff;
    --message-other-bg: #fbcfe8;
    --message-other-color: #1f2937;
}

body.theme-red-dark {
    --bg-gradient-start: #7f1d1d;
    --bg-gradient-end: #450a0a;
    --primary-color: #ef4444;
    --primary-hover: #f87171;
    --container-bg: #1a0505;
    --text-color: #fecaca;
    --text-secondary: #fca5a5;
    --text-tertiary: #f87171;
    --border-color: #7f1d1d;
    --surface-bg: #450a0a;
    --pulse-active: #f87171;
    --pulse-shadow: rgba(248, 113, 113, 0.6);
    --message-own-bg: #ef4444;
    --message-own-color: #ffffff;
    --message-other-bg: #7f1d1d;
    --message-other-color: #fecaca;
}

body.theme-pink-dark {
    --bg-gradient-start: #831843;
    --bg-gradient-end: #500724;
    --primary-color: #f472b6;
    --primary-hover: #f9a8d4;
    --container-bg: #1a050f;
    --text-color: #fce7f3;
    --text-secondary: #fbcfe8;
    --text-tertiary: #f9a8d4;
    --border-color: #831843;
    --surface-bg: #500724;
    --pulse-active: #f9a8d4;
    --pulse-shadow: rgba(249, 168, 212, 0.6);
    --message-own-bg: #f472b6;
    --message-own-color: #ffffff;
    --message-other-bg: #831843;
    --message-other-color: #fce7f3;
}

body.theme-black {
    --bg-gradient-start: #1f2937;
    --bg-gradient-end: #111827;
    --primary-color: #6b7280;
    --primary-hover: #9ca3af;
    --container-bg: #0f172a;
    --text-color: #f3f4f6;
    --text-secondary: #d1d5db;
    --text-tertiary: #9ca3af;
    --border-color: #374151;
    --surface-bg: #1e293b;
    --pulse-active: #e5e7eb;
    --pulse-shadow: rgba(229, 231, 235, 0.6);
    --message-own-bg: #6b7280;
    --message-own-color: #ffffff;
    --message-other-bg: #374151;
    --message-other-color: #f3f4f6;
}

body.theme-blue {
    --bg-gradient-start: #3b82f6;
    --bg-gradient-end: #1e40af;
    --primary-color: #60a5fa;
    --primary-hover: #3b82f6;
    --container-bg: #ffffff;
    --text-color: #1f2937;
    --text-secondary: #374151;
    --text-tertiary: #4b5563;
    --border-color: #bfdbfe;
    --surface-bg: #eff6ff;
    --pulse-active: #1e40af;
    --pulse-shadow: rgba(30, 64, 175, 0.6);
    --message-own-bg: #60a5fa;
    --message-own-color: #ffffff;
    --message-other-bg: #bfdbfe;
    --message-other-color: #1f2937;
}

body.theme-blue-dark {
    --bg-gradient-start: #0c4a6e;
    --bg-gradient-end: #082f49;
    --primary-color: #38bdf8;
    --primary-hover: #0ea5e9;
    --container-bg: #0a1929;
    --text-color: #e0f2fe;
    --text-secondary: #7dd3fc;
    --text-tertiary: #38bdf8;
    --border-color: #0e7490;
    --surface-bg: #164e63;
    --pulse-active: #0ea5e9;
    --pulse-shadow: rgba(14, 165, 233, 0.6);
    --message-own-bg: #38bdf8;
    --message-own-color: #0a1929;
    --message-other-bg: #0e7490;
    --message-other-color: #e0f2fe;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    transition: background 0.3s ease;
}

.container {
    background: var(--container-bg);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 100%;
    height: 90vh;
    max-height: 700px;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: background 0.3s ease;
}

/* Header Row */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    margin-bottom: 15px;
    flex-shrink: 0;
}

h1 {
    text-align: center;
    color: var(--text-color);
    font-size: 1.6em;
    flex: 1;
    transition: color 0.3s ease;
}

.header-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Theme Picker */
.theme-picker {
    position: relative;
    margin-right: 10px;
}

.theme-btn-active {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.theme-btn-active:hover {
    transform: scale(1.1);
}

.theme-btn-active.theme-default {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.theme-btn-active.theme-light {
    background: linear-gradient(135deg, #97B22D 0%, #E3DE81 100%);
}

.theme-btn-active.theme-dark {
    background: linear-gradient(135deg, #2d3d0f 0%, #97B22D 100%);
}

.theme-btn-active.theme-warm-light {
    background: linear-gradient(135deg, #E49A32 0%, #FEFCAD 100%);
}

.theme-btn-active.theme-warm-dark {
    background: linear-gradient(135deg, #2a2510 0%, #E49A32 100%);
}

.theme-btn-active.theme-red {
    background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
}

.theme-btn-active.theme-pink {
    background: linear-gradient(135deg, #ec4899 0%, #be185d 100%);
}

.theme-btn-active.theme-red-dark {
    background: linear-gradient(135deg, #7f1d1d 0%, #ef4444 100%);
}

.theme-btn-active.theme-pink-dark {
    background: linear-gradient(135deg, #831843 0%, #f472b6 100%);
}

.theme-btn-active.theme-black {
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
}

.theme-btn-active.theme-blue {
    background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
}

.theme-btn-active.theme-blue-dark {
    background: linear-gradient(135deg, #0c4a6e 0%, #38bdf8 100%);
}

.theme-dropdown {
    position: absolute;
    top: 40px;
    left: 0;
    background: var(--container-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 10px;
    display: none;
    grid-template-columns: 32px 32px;
    gap: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    z-index: 1000;
}

.theme-dropdown[style*="display: grid"] {
    display: grid !important;
}

.theme-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-btn:hover {
    transform: scale(1.1);
    border-color: var(--primary-color);
}

.theme-btn.theme-default {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.theme-btn.theme-light {
    background: linear-gradient(135deg, #97B22D 0%, #E3DE81 100%);
}

.theme-btn.theme-dark {
    background: linear-gradient(135deg, #2d3d0f 0%, #97B22D 100%);
}

.theme-btn.theme-warm-light {
    background: linear-gradient(135deg, #E49A32 0%, #FEFCAD 100%);
}

.theme-btn.theme-warm-dark {
    background: linear-gradient(135deg, #2a2510 0%, #E49A32 100%);
}

.theme-btn.theme-red {
    background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
}

.theme-btn.theme-pink {
    background: linear-gradient(135deg, #ec4899 0%, #be185d 100%);
}

.theme-btn.theme-red-dark {
    background: linear-gradient(135deg, #7f1d1d 0%, #ef4444 100%);
}

.theme-btn.theme-pink-dark {
    background: linear-gradient(135deg, #831843 0%, #f472b6 100%);
}

.theme-btn.theme-black {
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
}

.theme-btn.theme-blue {
    background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
}

.theme-btn.theme-blue-dark {
    background: linear-gradient(135deg, #0c4a6e 0%, #38bdf8 100%);
}

/* Connection Status */
.connection-status {
    font-size: 1.2em;
    transition: color 0.3s ease;
}

.connection-status.connected {
    color: #48bb78;
}

.connection-status.disconnected {
    color: #e53e3e;
}

.connection-status.connecting {
    color: #ecc94b;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.user-count {
    font-size: 0.85em;
    color: var(--text-tertiary);
    background: var(--surface-bg);
    padding: 4px 10px;
    border-radius: 12px;
    transition: all 0.3s ease;
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 15px;
    background: var(--surface-bg);
    transition: all 0.3s ease;
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Messages */
.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.own {
    align-self: flex-end;
}

.message.other {
    align-self: flex-start;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.message.own .message-header {
    flex-direction: row-reverse;
}

.message-username {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--primary-color);
}

.message-time {
    font-size: 0.7em;
    color: var(--text-tertiary);
}

.message-content {
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.own .message-content {
    background: var(--message-own-bg);
    color: var(--message-own-color);
    border-bottom-right-radius: 4px;
}

.message.other .message-content {
    background: var(--message-other-bg);
    color: var(--message-other-color);
    border-bottom-left-radius: 4px;
}

.system-message {
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.85em;
    font-style: italic;
    padding: 10px;
    background: var(--surface-bg);
    border-radius: 8px;
    margin: 5px 0;
}

/* Input Container */
.input-container {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.message-input {
    flex: 1;
    padding: 12px 16px;
    font-size: 1em;
    border: 2px solid var(--border-color);
    border-radius: 24px;
    background: var(--container-bg);
    color: var(--text-color);
    outline: none;
    transition: all 0.3s ease;
}

.message-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--pulse-shadow);
}

.message-input::placeholder {
    color: var(--text-tertiary);
}

/* Buttons */
.btn {
    padding: 12px 20px;
    font-size: 1em;
    font-weight: 600;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--pulse-shadow);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.send-btn {
    min-width: 80px;
}

/* Modal */
.modal {
    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: 2000;
    padding: 20px;
}

.modal-content {
    background: var(--container-bg);
    border-radius: 20px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 20px;
    background: var(--primary-color);
    color: white;
    text-align: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.4em;
}

.modal-body {
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal-body p {
    color: var(--text-secondary);
    text-align: center;
    margin: 0;
}

.username-input,
.server-input {
    width: 100%;
    padding: 14px 16px;
    font-size: 1.1em;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--container-bg);
    color: var(--text-color);
    outline: none;
    transition: all 0.3s ease;
    text-align: center;
}

.username-input:focus,
.server-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--pulse-shadow);
}

.join-btn,
.connect-btn {
    width: 100%;
    padding: 14px;
    font-size: 1.1em;
}

.server-hint {
    font-size: 0.85em;
    color: var(--text-tertiary);
    text-align: center;
}

.server-hint code {
    background: var(--surface-bg);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: monospace;
}

/* Scrollbar Styling */
.messages-area::-webkit-scrollbar {
    width: 6px;
}

.messages-area::-webkit-scrollbar-track {
    background: var(--surface-bg);
    border-radius: 3px;
}

.messages-area::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.messages-area::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Responsive Design */
@media (max-width: 480px) {
    .container {
        padding: 15px;
        border-radius: 15px;
        height: 95vh;
        max-height: none;
    }

    h1 {
        font-size: 1.3em;
    }

    .message-input {
        padding: 10px 14px;
        font-size: 0.95em;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.95em;
    }

    .send-btn {
        min-width: 70px;
    }

    .message-content {
        padding: 8px 12px;
        font-size: 0.95em;
    }

    .user-count {
        font-size: 0.75em;
        padding: 3px 8px;
    }
}
