:root {
    --background-color: #121212;
    --surface-color: #1e1e1e;
    --primary-color: #007bff;
    --primary-variant-color: #0056b3;
    --text-color: #e0e0e0;
    --user-bubble-color: #005c4b;
    --ai-bubble-color: #2a2a2a;
    --font-family: 'Poppins', sans-serif;
}

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

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

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
}

#app-container {
    width: 100%;
    height: 100%;
    max-width: 800px;
    max-height: 100vh; /* Changed from 900px */
    background-color: var(--surface-color);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    position: relative;
}

.screen {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease-in-out, visibility 0.5s;
    display: flex;
    flex-direction: column;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* Personality Screen */
#personality-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px;
}

.personality-content {
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.bot-icon-large {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007bff, #c300ff);
    padding: 10px;
}

h1 {
    font-size: 2rem;
    font-weight: 600;
}

#personality-screen p {
    font-size: 1rem;
    color: #b0b0b0;
}

#personality-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#personality-input {
    width: 100%;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #444;
    background-color: #2a2a2a;
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: 1rem;
    resize: none;
}

#personality-form button {
    padding: 15px;
    border-radius: 8px;
    border: none;
    background-color: var(--primary-color);
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 54px; /* Set a fixed height */
}

#personality-form button:hover {
    background-color: var(--primary-variant-color);
}

#personality-form button:disabled {
    background-color: #555;
    cursor: not-allowed;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 4px solid #fff;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Chat Screen */
header {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    background-color: #2a2a2a;
    border-bottom: 1px solid #333;
}

.bot-icon-small {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    margin-right: 15px;
    background: linear-gradient(135deg, #007bff, #c300ff);
    padding: 4px;
    object-fit: cover;
}

.header-info {
    flex-grow: 1;
}

.header-info h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

#ai-status {
    font-size: 0.8rem;
    color: #00e676; /* Green for online */
}

#leave-chat-button {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
    opacity: 0.7;
}

#leave-chat-button:hover {
    background-color: #444;
    opacity: 1;
}

#leave-chat-button svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

#messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    max-width: 75%;
    padding: 12px 18px;
    border-radius: 18px;
    line-height: 1.5;
    word-wrap: break-word;
    opacity: 0;
    transform: translateY(20px);
    animation: slideIn 0.4s forwards;
}

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

.user-message {
    background-color: var(--user-bubble-color);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.assistant-message {
    background-color: var(--ai-bubble-color);
    color: var(--text-color);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

#chat-input-container {
    padding: 15px 20px;
    background-color: #2a2a2a;
    border-top: 1px solid #333;
}

#chat-form {
    display: flex;
    align-items: center;
    gap: 10px;
}

#message-input {
    flex-grow: 1;
    padding: 12px 18px;
    border: none;
    border-radius: 25px;
    background-color: #3c3c3c;
    color: var(--text-color);
    font-size: 1rem;
    font-family: var(--font-family);
}

#message-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--primary-color);
}

#send-button {
    background-color: var(--primary-color);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.3s;
}

#send-button:hover {
    background-color: var(--primary-variant-color);
}

#send-button svg {
    fill: white;
}

#typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 18px;
    background-color: var(--ai-bubble-color);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.dot {
    width: 8px;
    height: 8px;
    background-color: #8e8e8e;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

@media (max-width: 600px) {
    #app-container {
        border-radius: 0;
        max-height: 100vh;
    }
    h1 {
        font-size: 1.8rem;
    }
    #personality-screen p {
        font-size: 0.9rem;
    }
}