:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a28;
    --bg-card: rgba(20, 20, 35, 0.7);
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);
    --text-primary: #f0f0f5;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --success: #22c55e;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --glass: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100%;
    overflow: hidden;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 20% 40%, rgba(99, 102, 241, 0.08), transparent),
        radial-gradient(ellipse 60% 40% at 80% 60%, rgba(139, 92, 246, 0.06), transparent);
    pointer-events: none;
    z-index: 0;
}

.screen {
    display: none;
    height: 100%;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    padding: 16px;
}

.screen.active {
    display: flex;
}

/* Setup Card */
.card {
    width: 100%;
    max-width: 440px;
    padding: 36px 28px;
    border-radius: var(--radius-xl);
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow);
    animation: cardEnter 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.card.glass {
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
}

.card-brand {
    text-align: center;
    margin-bottom: 28px;
}

.logo {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 800;
    color: #fff;
    margin-bottom: 16px;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.card h1 {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 8px;
    letter-spacing: 0.2px;
}

.form-group input,
.form-group select {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: '';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

.form-group select {
    padding-right: 40px;
    cursor: pointer;
}

.btn-primary {
    width: 100%;
    min-height: 52px;
    padding: 14px;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    border: none;
    border-radius: var(--radius-lg);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 4px;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
}

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

.discord-badge {
    margin-top: 16px;
    padding: 12px;
    background: rgba(88, 101, 242, 0.15);
    border: 1px solid rgba(88, 101, 242, 0.25);
    border-radius: var(--radius-md);
    text-align: center;
    font-size: 13px;
    color: #c7d2fe;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

/* Chat Screen */
.chat-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    max-width: 960px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
}

.room-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.room-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.member-count {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

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

.lang-badge {
    padding: 3px 10px;
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    color: var(--success);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-name {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-leave {
    padding: 7px 14px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-leave:hover {
    background: var(--danger);
    color: #fff;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
    max-width: 85%;
    animation: messageSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.message.own {
    align-self: flex-end;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(124, 58, 237, 0.15));
    border-color: rgba(99, 102, 241, 0.25);
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: 4px;
}

.msg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.msg-author {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.msg-time {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

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

.msg-lang {
    font-size: 10px;
    padding: 2px 7px;
    background: rgba(0,0,0,0.25);
    border-radius: 6px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.message.own .msg-lang {
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.7);
}

.msg-body {
    font-size: 14.5px;
    color: var(--text-primary);
    line-height: 1.5;
    word-break: break-word;
}

.message.own .msg-body {
    color: #fff;
}

.msg-orig {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    line-height: 1.4;
}

.message.own .msg-orig {
    color: rgba(255,255,255,0.55);
    border-top-color: rgba(255,255,255,0.1);
}

.system-msg {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 20px;
    animation: fadeIn 0.3s ease;
}

.message.pending {
    opacity: 0.7;
}

.message.pending .msg-body::after {
    content: ' ...';
    font-size: 12px;
    color: var(--text-muted);
    animation: pulse 1.2s infinite;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    padding: 14px 20px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    align-items: center;
}

#message-input {
    flex: 1;
    min-height: 48px;
    padding: 12px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: all 0.2s ease;
}

#message-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#message-input::placeholder {
    color: var(--text-muted);
}

.btn-send {
    width: 48px;
    height: 48px;
    padding: 0;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    border: none;
    border-radius: 50%;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.btn-send:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

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

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 20px;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-overlay p {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 10px;
}

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

/* Animations */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes cardEnter {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* RTL support */
[dir="rtl"] .message {
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: 4px;
}

[dir="rtl"] .message.own {
    border-bottom-right-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
}

/* Mobile */
@media (max-width: 640px) {
    .screen {
        padding: 0;
    }

    .card {
        max-width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 24px 20px;
    }

    .chat-container {
        border-radius: 0;
        border: none;
        max-width: 100%;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .user-name {
        max-width: 80px;
    }

    .chat-messages {
        padding: 12px 16px;
    }

    .message {
        max-width: 92%;
        padding: 10px 14px;
    }

    .chat-input-area {
        padding: 10px 14px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

@media (max-width: 400px) {
    .card h1 {
        font-size: 22px;
    }

    .logo {
        width: 48px;
        height: 48px;
        font-size: 18px;
    }

    .btn-leave {
        padding: 6px 10px;
        font-size: 11px;
    }

    .lang-badge {
        padding: 2px 7px;
        font-size: 10px;
    }

    .user-name {
        display: none;
    }
}
