:root {
    --bg-main: #ffffff;
    --bg-surface: #f0f4f8;
    --primary: #003366;
    /* Deep Blue */
    --accent: #d90429;
    /* Red */
    --text-main: #1a1a24;
    --text-muted: #6b7280;
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(0, 51, 102, 0.15);
    --shadow-main: rgba(0, 51, 102, 0.1);
    --blur: 24px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Space Grotesk', sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
    overscroll-behavior: none;
}

#app {
    width: 100%;
    height: 100dvh;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.screen.active {
    display: flex;
    opacity: 1;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 15px 35px var(--shadow-main);
}

.main-panel {
    padding: 4rem 3rem;
    text-align: center;
    max-width: 500px;
    width: 90%;
    animation: slideUp 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from {
        transform: translateY(40px);
        opacity: 0;
    }

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

.lock-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--primary);
}

h1 {
    font-size: 2.8rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
}

p {
    color: var(--accent);
    font-size: 0.95rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 3rem;
}

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

.glow-btn {
    cursor: pointer;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1.1rem;
    padding: 1.2rem;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.create-btn {
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 5px 15px rgba(0, 51, 102, 0.2);
}

.create-btn:hover {
    box-shadow: 0 8px 20px rgba(0, 51, 102, 0.3);
    transform: translateY(-2px);
}

.join-btn {
    background: var(--accent);
    color: #ffffff;
    padding: 1.2rem 2rem;
}

.join-btn:hover {
    box-shadow: 0 8px 20px rgba(217, 4, 41, 0.3);
    transform: translateY(-2px);
}

.divider {
    position: relative;
    height: 1px;
    background: var(--glass-border);
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 1rem 0;
}

.divider span {
    background: var(--bg-main);
    padding: 0 15px;
    color: var(--text-muted);
    font-size: 0.75rem;
    letter-spacing: 2px;
}

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

input {
    flex: 1;
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem 1.2rem;
    color: var(--text-main);
    outline: none;
    font-size: 16px;
    transition: all 0.3s ease;
    font-family: inherit;
}

input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.1);
}

/* Chat Container */
.chat-container {
    width: 100%;
    height: 100dvh;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
}

@media (min-width: 768px) {
    .chat-container {
        height: 85vh;
        border-radius: 20px;
    }
}

.chat-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(240, 244, 248, 0.5);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
}

.room-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #ffffff;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    border: 1px solid var(--glass-border);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
}

#current-room-id {
    font-family: monospace;
    font-size: 1.1rem;
    letter-spacing: 2px;
    color: var(--primary);
    font-weight: bold;
}

.e2ee-badge {
    font-size: 0.8rem;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 0.3rem 0.8rem;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: rgba(0, 51, 102, 0.05);
}

.header-actions {
    display: flex;
    gap: 10px;
}

.icon-btn {
    background: #ffffff;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--bg-surface);
}

.leave-btn:hover {
    background: rgba(217, 4, 41, 0.1);
    border-color: var(--accent);
    color: var(--accent);
}

.messages-area {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    background: #fafbfc;
}

.messages-area::-webkit-scrollbar {
    width: 6px;
}

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

.messages-area::-webkit-scrollbar-thumb {
    background: #c3c5c8;
    border-radius: 3px;
}

.e2ee-notice {
    text-align: center;
    background: rgba(0, 51, 102, 0.05);
    border: 1px solid rgba(0, 51, 102, 0.1);
    color: var(--text-muted);
    padding: 1rem;
    border-radius: 12px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.e2ee-notice strong {
    color: var(--primary);
}

.message {
    max-width: 80%;
    padding: 1rem 1.5rem;
    border-radius: 18px;
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-size: 1rem;
    line-height: 1.5;
    position: relative;
    word-break: break-word;
}

@keyframes popIn {
    from {
        transform: scale(0.9) translateY(10px);
        opacity: 0;
    }

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

.message.my-message {
    align-self: flex-end;
    background: var(--primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 10px rgba(0, 51, 102, 0.15);
}

.message.other-message {
    align-self: flex-start;
    background: #ffffff;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.message.system-message {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.message.audio-message {
    padding: 1rem 1.2rem;
    min-width: 250px;
}

/* Image Message Styling */
.message.image-message {
    padding: 0.5rem;
    background: transparent;
    border: none;
    box-shadow: none;
}

.message.image-message .chat-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 12px;
    object-fit: contain;
    box-shadow: 0 4px 15px var(--shadow-main);
    display: block;
}

.my-message.image-message .chat-image {
    margin-left: auto;
}

/* Hide native audio */
audio {
    display: none;
}

.custom-audio-player {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.play-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: #ffffff;
    color: var(--primary);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    outline: none;
    padding-left: 4px;
}

.my-message .play-btn {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    box-shadow: none;
}

.play-btn:active {
    transform: scale(0.9);
}

.play-btn.playing {
    padding-left: 0;
    background: var(--accent);
    color: white;
}

.my-message .play-btn.playing {
    background: rgba(217, 4, 41, 0.8);
}

.progress-container {
    flex: 1;
    height: 6px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
    position: relative;
    overflow: hidden;
}

.my-message .progress-container {
    background: rgba(255, 255, 255, 0.3);
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.1s linear;
}

.my-message .progress-bar {
    background: #ffffff;
}

.time-display {
    font-size: 0.85rem;
    min-width: 40px;
    text-align: right;
    font-family: inherit;
    font-weight: 600;
}

.my-message .time-display {
    color: #ffffff;
}

.chat-input-area {
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 1rem;
    background: #ffffff;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    align-items: center;
}

.input-wrapper {
    flex: 1;
}

.input-wrapper input {
    width: 100%;
    border-radius: 20px;
    padding: 1rem 1.2rem;
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
}

.action-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.attach-btn {
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    color: var(--primary);
    font-size: 1.2rem;
}

.attach-btn:hover {
    background: #e2e8f0;
}

.record-btn {
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    color: var(--primary);
    font-size: 1.2rem;
}

.record-btn:active,
.record-btn.recording {
    background: rgba(217, 4, 41, 0.1);
    border-color: var(--accent);
    color: var(--accent);
    transform: scale(1.1);
}

.send-btn {
    background: var(--primary);
    color: #ffffff;
    font-size: 1.2rem;
    box-shadow: 0 4px 10px rgba(0, 51, 102, 0.2);
}

.send-btn:hover {
    transform: scale(1.05);
    background: #004488;
}

/* Mobile Responsiveness */
@media (max-width: 767px) {
    .main-panel {
        padding: 2rem 1.5rem;
    }

    h1 {
        font-size: 2rem;
    }

    .chat-header {
        padding: 1rem;
        gap: 0.5rem;
    }

    .e2ee-badge {
        display: none;
    }

    .chat-input-area {
        padding: 1rem;
        gap: 0.5rem;
    }

    .input-wrapper input {
        padding: 0.8rem 1rem;
    }

    .action-btn {
        width: 44px;
        height: 44px;
    }

    .room-pill {
        padding: 0.4rem 0.8rem;
    }

    .header-actions .icon-btn {
        width: 38px;
        height: 38px;
    }

    .join-room-form {
        flex-direction: column;
    }

    .message {
        max-width: 90%;
        padding: 0.8rem 1.2rem;
    }

    .messages-area {
        padding: 1rem;
    }

    /* Let the inner elements fill width for column form */
    .join-room-form input,
    .join-room-form button {
        width: 100%;
    }
}