:root {
    /* Default / Base Variables */
    --bg-color: #0a0a0f;
    --card-bg: #1e293b;
    --bubble-sent: #38bdf8;
    --bubble-received: #1e293b;
    --accent: #38bdf8;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --status-online: #10b981;
    --status-waiting: #f59e0b;
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    --bubble-radius: 1.2rem;
}

/* Theme: WhatsApp */
body.theme-whatsapp {
    --bg-color: #0a1a13;
    --card-bg: #1f2c34;
    --bubble-sent: #005c4b;
    --bubble-received: #1f2c34;
    --accent: #00a884;
    --bubble-radius: 8px;
}

/* Theme: Telegram */
body.theme-telegram {
    --bg-color: #17212b;
    --card-bg: #1c2733;
    --bubble-sent: #2b5278;
    --bubble-received: #1c2733;
    --accent: #3390ec;
    --bubble-radius: 12px;
}

/* Theme: Messenger */
body.theme-messenger {
    --bg-color: #1c1e21;
    --card-bg: #3a3b3c;
    --bubble-sent: linear-gradient(135deg, #a332ff, #ff26b9);
    --bubble-received: #3a3b3c;
    --accent: #0084ff;
    --bubble-radius: 18px;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-body);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.3s ease;
}

/* Theme Selector Screen */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

#theme-selector-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    background: #0a0a0f;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 1.5rem;
    text-align: center;
    gap: 1rem;
    overflow: hidden;
}

.selector-title {
    font-family: var(--font-heading);
    font-size: 36px;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: white;
}

#typing-logo {
    background: linear-gradient(to right, #00bfa5, #0088cc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: #00bfa5; /* Fallback */
    font-weight: 700;
    letter-spacing: -1px;
    display: inline-flex;
    align-items: center;
}

.logo-accent {
    font-weight: 900;
    -webkit-text-fill-color: #00bfa5; /* Brighter teal for I */
}

.cursor {
    display: inline-block;
    width: 3px;
    height: 32px;
    background-color: #00bfa5;
    margin-left: 2px;
    animation: blink 0.8s infinite;
}

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

.logo-icon {
    height: 36px;
    width: auto;
    border-radius: 8px;
}

.selector-tagline {
    font-size: 13px;
    color: #888;
    margin: 0;
    white-space: nowrap;
}

.feature-pills {
    display: flex;
    gap: 0.5rem;
    margin: 0;
    justify-content: center;
}

.pill {
    font-size: 11px;
    background: #ffffff08;
    border: 1px solid #ffffff15;
    padding: 6px 12px;
    border-radius: 20px;
    color: #aaa;
}

.theme-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 400px;
    margin: 0.5rem 0;
}

.theme-option {
    background: transparent;
    border: 1px solid #ffffff10;
    border-radius: 12px;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 1rem;
    text-align: left;
    position: relative;
}

.theme-option:hover {
    background: #ffffff08;
}

.theme-option.selected {
    background: #ffffff05;
    border-left: 3px solid var(--accent);
}

.theme-icon-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: white;
}

.theme-icon-circle.whatsapp { background: #00a884; }
.theme-icon-circle.telegram { background: #0088cc; }
.theme-icon-circle.messenger { background: #9b59b6; }

.theme-info {
    flex: 1;
}

.theme-name {
    font-weight: 700;
    font-size: 15px;
    display: block;
}

.theme-subtitle {
    font-size: 12px;
    color: #888;
    display: block;
}

.theme-indicator {
    width: 18px;
    height: 18px;
    border: 2px solid #ffffff30;
    border-radius: 50%;
    position: relative;
}

.theme-option.selected .theme-indicator {
    border-color: var(--accent);
}

.theme-option.selected .theme-indicator::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
}

#start-chat-btn {
    width: 100%;
    max-width: 400px;
    height: 48px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 0.5rem;
}

#start-chat-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.selector-footer {
    position: absolute;
    bottom: 1.5rem;
    width: 100%;
    color: #666;
    font-size: 10px;
    opacity: 0.5;
    padding: 0 2rem;
}

/* App Layout */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    background: var(--bg-color);
    position: relative;
}

#app.hidden {
    display: none;
}

header {
    height: 50px;
    padding: 0 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(15px);
    flex-shrink: 0;
    z-index: 1000;
    position: sticky;
    top: 0;
}

#current-theme-display {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--accent);
    text-transform: capitalize;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#find-new-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

#settings-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    position: relative;
    padding-bottom: 70px; /* Space for fixed input */
}

.waiting-state {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none; /* Controlled by JS */
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
}

.pulsing-dots {
    display: flex;
    gap: 6px;
    margin-bottom: 1rem;
}

.pulsing-dots span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 1.4s infinite ease-in-out both;
}

.pulsing-dots span:nth-child(1) { animation-delay: -0.32s; }
.pulsing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes pulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1.2); opacity: 1; }
}

.waiting-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.25rem;
    transition: opacity 0.3s ease;
}

.waiting-subtext {
    font-size: 0.8rem;
    color: var(--text-muted);
}

#messages {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.typing-indicator {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    position: absolute;
    bottom: 65px;
    left: 1rem;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 10px;
    backdrop-filter: blur(10px);
    z-index: 50;
    border: 1px solid var(--border);
    animation: fadeIn 0.2s ease-out;
}

.typing-indicator.visible {
    display: flex;
}

.typing-indicator .dots {
    display: flex;
    gap: 4px;
}

.typing-indicator .dots span {
    width: 4px;
    height: 4px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 1.4s infinite ease-in-out both;
}

.typing-indicator .dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator .dots span:nth-child(2) { animation-delay: -0.16s; }

.message {
    max-width: 80%;
    padding: 0.6rem 1rem;
    border-radius: var(--bubble-radius);
    line-height: 1.4;
    font-size: 0.95rem;
    animation: fadeIn 0.2s ease-out;
}

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

.message.you {
    align-self: flex-end;
    background: var(--bubble-sent);
    color: white;
}

.message.stranger {
    align-self: flex-start;
    background: var(--bubble-received);
    color: var(--text-main);
}

.system-msg {
    align-self: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin: 1rem 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.8rem;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.1);
}

footer {
    position: absolute;
    bottom: 0;
    width: 100%;
    min-height: 60px;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    z-index: 100;
}

.emoji-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    position: absolute;
    bottom: 70px;
    left: 10px;
    right: 10px;
    z-index: 1001;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.emoji-picker.hidden {
    display: none;
}

.emoji {
    font-size: 1.25rem;
    cursor: pointer;
    transition: transform 0.1s ease;
}

.emoji:hover {
    transform: scale(1.2);
}

#chat-form {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    align-items: center;
}

#emoji-toggle-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

#emoji-toggle-btn:hover {
    opacity: 1;
}

.input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 0 12px;
    gap: 4px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.75rem 0.5rem;
    color: var(--text-main);
    outline: none;
    font-size: 0.95rem;
}

#send-btn {
    background: var(--accent);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#send-btn:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: scale(1.02);
}

#send-btn:active:not(:disabled) {
    transform: scale(0.98);
}

#send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

@media (max-width: 600px) {
    #theme-selector-screen {
        padding: 1.25rem;
        justify-content: center;
        gap: 0.75rem;
    }

    .selector-title {
        font-size: 20px;
    }

    .selector-tagline {
        font-size: 12px;
    }

    .pill {
        font-size: 10px;
        padding: 5px 10px;
    }

    .theme-options {
        gap: 0.5rem;
    }

    .theme-option {
        padding: 0.6rem 0.8rem;
    }

    .theme-icon-circle {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
    }

    .theme-name {
        font-size: 14px;
    }

    .theme-subtitle {
        font-size: 11px;
    }

    #start-chat-btn {
        height: 44px;
        font-size: 14px;
        position: relative;
        bottom: 0;
        margin-top: 0.5rem;
    }

    .selector-footer {
        display: none;
    }

    #app { 
        border: none; 
        height: 100dvh;
    }
}

#theme-selector-screen.hidden {
    display: none;
}
