* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f0f2f5;
    height: 100vh;
    overflow: hidden;
}

/* Screen Management */
.screen {
    display: none;
    height: 100vh;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

/* Header */
.app-header {
    background: #4361ee;
    color: white;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.back-button {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

.character-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    margin-left: 1rem;
}

.status-bar {
    font-size: 0.875rem;
    opacity: 0.9;
}

/* Character Selection */
.character-selection {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.screen-title {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #333;
}

#charactersList {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.character-card {
    background: white;
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.character-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.character-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #4361ee;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 600;
    flex-shrink: 0;
}

.character-details {
    flex: 1;
}

.character-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.25rem;
}

.character-description {
    color: #666;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.character-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tag {
    background: #e3e8ff;
    color: #4361ee;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #e5ddd5;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Messages */
.message {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    position: relative;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    background: #dcf8c6;
    border-bottom-right-radius: 4px;
}

.message.ai {
    align-self: flex-start;
    background: white;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message-content {
    line-height: 1.4;
    color: #333;
}

.message-time {
    font-size: 0.7rem;
    color: #999;
    margin-top: 0.25rem;
    text-align: right;
}

/* Loading Animation */
.loading {
    background: white !important;
    padding: 1rem 1.5rem !important;
}

.loading-dots {
    display: flex;
    gap: 0.25rem;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Chat Input */
.chat-input-container {
    background: #f0f0f0;
    padding: 1rem;
    border-top: 1px solid #ddd;
}

.chat-input-wrapper {
    display: flex;
    gap: 0.5rem;
    background: white;
    border-radius: 24px;
    padding: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

#messageInput {
    flex: 1;
    border: none;
    outline: none;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    background: transparent;
}

#sendButton {
    background: #4361ee;
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#sendButton:hover:not(:disabled) {
    background: #3651d4;
}

#sendButton:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.send-icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.empty-state h2 {
    color: #333;
    margin-bottom: 0.5rem;
}

.start-chat-button {
    margin-top: 1.5rem;
    padding: 0.75rem 1.5rem;
    background: #4361ee;
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.start-chat-button:hover {
    background: #3651d4;
}

/* Network Status */
#networkStatus {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ff9800;
    color: white;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.875rem;
    z-index: 1000;
}

/* Install Prompt */
#installPrompt {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 1rem;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
}

#installButton {
    background: #4361ee;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
}

/* Loading State for Character List */
.loading {
    text-align: center;
    padding: 2rem;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.3);
}

/* Responsive */
@media (max-width: 600px) {
    .message {
        max-width: 85%;
    }
}