* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', 'Vazirmatn', sans-serif;
    transition: background-color 0.3s, color 0.3s;
}

html[lang="fa"] * {
    font-family: 'Vazirmatn', 'Poppins', sans-serif;
    direction: rtl;
}

html[lang="fa"] #chat-input {
    margin-left: 0;
}

html[lang="fa"] .message.user {
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 15px;
}

html[lang="fa"] .message.bot {
    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 5px;
}

:root {
    --bg-color: #f0f2f5;
    --container-bg: white;
    --text-color: #333;
    --text-secondary: #666;
    --text-tertiary: #777;
    --header-bg: #f8f9fa;
    --border-color: #eee;
    --input-border: #ddd;
    --user-msg-bg: #2196f3;
    --bot-msg-bg: #f5f5f5;
    --button-bg: #0084ff;
    --button-hover: #0073e6;
    --card-bg: #ffffff;
}

body.dark-mode {
    --bg-color: #121212;
    --container-bg: #1e1e1e;
    --text-color: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-tertiary: #909090;
    --header-bg: #252525;
    --border-color: #333;
    --input-border: #444;
    --user-msg-bg: #0d47a1;
    --bot-msg-bg: #2d2d2d;
    --button-bg: #0084ff;
    --button-hover: #0073e6;
    --card-bg: #252525;
}

body {
    background: var(--bg-color);
    min-height: 100vh;
    height: 100vh;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    overflow: hidden;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0;
    background: var(--container-bg);
    border-radius: 20px;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.screen {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.screen.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    .screen.active {
        height: 100vh;
        max-height: -webkit-fill-available;
    }

    .chat-input-container {
        position: sticky;
        bottom: 0;
        padding: 10px;
        background: var(--header-bg);
        z-index: 100;
    }

    #send-button {
        padding: 8px 16px;
        min-width: 70px;
    }
}
/* Character Selection Screen */
#character-selection {
    padding: 2rem;
}

#selected-character {
    text-align: center;
    margin-bottom: 0.8rem;
    color: var(--text-color);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    justify-content: center;
}

#selected-character::before {
    content: '';
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    border: 1px solid var(--border-color);
}

#selected-character[data-character='sara']::before {
    background-image: url('https://uploader-oss-mili.milaadfarzian.workers.dev/download/AgACAgQAAxkBAAPQZ-n53wwAAcV5YAxgTGoOIsjII1Q2AAJ4xjEbxI5RU_yn1bXQhcqxAQADAgADeAADNgQ/photos/file_72.jpg');
}

#selected-character[data-character='alex']::before {
    background-image: url('https://uploader-oss-mili.milaadfarzian.workers.dev/download/AgACAgQAAxkBAAPSZ-n6CMY6EJSBQhnbh28thZ8EBqwAAnnGMRvEjlFTTOt40Pfy1SwBAAMCAAN5AAM2BA/photos/file_73.jpg');
}

#selected-character[data-character='jordan']::before {
    background-image: url('https://uploader-oss-mili.milaadfarzian.workers.dev/download/AgACAgQAAxkBAAPUZ-n6Hm_vUmzn6sS4_kZ1gVMFRiEAAnrGMRvEjlFTHpOCeK2WrYcBAAMCAAN5AAM2BA/photos/file_74.jpg');
}

#selected-character[data-character='maya']::before {
    background-image: url('https://uploader-oss-mili.milaadfarzian.workers.dev/download/AgACAgQAAxkBAAPWZ-n6OTNF874aAAF5YIuvbXExpjzMAAJ7xjEbxI5RU9pePez_IFawAQADAgADeQADNgQ/photos/file_75.jpg');
}

.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    padding: 0.75rem;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}

.character-card {
    background: var(--card-bg);
    border-radius: 6px;
    padding: 0.5rem;
    cursor: pointer;
    transition: transform 0.2s;
    border: 1px solid var(--border-color);
    text-align: center;
}

.character-image {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 0.6rem;
    border: 1px solid var(--border-color);
}

.character-card h2 {
    color: var(--text-color);
    margin-bottom: 0.3rem;
    font-size: 1.1rem;
}

.character-card .role {
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
}

.character-card .description {
    color: var(--text-tertiary);
    font-size: 0.8rem;
    line-height: 1.2;
}
/* Chat Interface */
#chat-interface {
    display: none;
    flex-direction: column;
    height: 100%;
}

#chat-interface.active {
    display: flex;
}

.chat-header {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1rem;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

#chat-interface.active .chat-header {
    display: flex;
}

#back-button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    position: absolute;
    left: 1rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#back-button i {
    font-size: 1.2rem;
    font-family: "Font Awesome 6 Free" !important;
}

#back-button {
    left: 1rem !important;
    right: auto !important;
}

.chat-messages {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
}

.message {
    margin-bottom: 0.75rem;
    max-width: 80%;
    padding: 0.6rem 0.8rem;
    border-radius: 15px;
    line-height: 1.3;
    min-height: 24px;
    min-width: 60px;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 0.9rem;
}

.message.user {
    background: var(--user-msg-bg);
    margin-left: auto;
    border-bottom-right-radius: 5px;
    color: #faf0f0;
}

.message.bot {
    background: var(--bot-msg-bg);
    margin-right: auto;
    border-bottom-left-radius: 5px;
    color: var(--text-color);
}

.chat-input-container {
    display: flex;
    padding: 0.75rem;
    background: var(--header-bg);
    border-top: 1px solid var(--border-color);
    align-items: center;
    gap: 0.75rem;
}

#chat-input {
    flex-grow: 1;
    padding: 0.6rem 1rem;
    border: 1px solid var(--input-border);
    border-radius: 20px;
    font-size: 0.95rem;
    background: var(--container-bg);
    color: var(--text-color);
    min-height: 40px;
    max-width: calc(100% - 60px);
}

#send-button {
    color: #12abf8;
    padding: 0;
    cursor: pointer;
    font-weight: 400;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
}

.header-controls {
    display: flex;
    margin-left: auto;
    gap: 10px;
    direction: ltr !important;
    font-family: 'Poppins', 'Vazirmatn', sans-serif !important;
}

#reset-button, #theme-toggle, #lang-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 6px 12px;
    cursor: pointer;
    min-width: 40px;
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s;
}

#reset-button:hover, #theme-toggle:hover, #lang-toggle:hover {
    background: var(--border-color);
    color: var(--text-color);
}

#theme-toggle, #lang-toggle {
    font-size: 1rem;
}

.fa-moon, .fa-sun, .fa-redo, .fa-language, .fa-paper-plane {
    font-size: 1.2rem;
    font-family: "Font Awesome 6 Free" !important;
}

.rtl {
    direction: rtl;
    text-align: right;
}

.rtl .message.user {
    margin-right: auto;
    margin-left: 0;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 15px;
}

.rtl .message.bot {
    margin-left: auto;
    margin-right: 0;
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 15px;
}

@media (max-width: 768px) {
    .container {
        margin: 0;
        border-radius: 0;
        height: 100vh;
        width: 100vw;
        max-width: none;
        position: fixed;
        top: 0;
        left: 0;
        display: flex;
        flex-direction: column;
    }

    .screen {
        height: 100%;
        max-height: none;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 70px;
    }

    #character-selection {
        padding: 1rem;
    }

    .character-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding-bottom: 2rem;
    }

    .message {
        max-width: 90%;
    }
    
    .chat-header {
        flex-wrap: wrap;
        position: sticky;
        top: 0;
        z-index: 10;
    }
    
    .header-controls {
        margin-top: 10px;
        margin-left: 0;
        width: 100%;
        justify-content: flex-end;
    }

    .chat-input-container {
        position: fixed;
        bottom: env(safe-area-inset-bottom, 0);
        left: 0;
        right: 0;
        z-index: 1000;
        background: var(--header-bg);
        padding: 0.75rem 1rem;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        margin-bottom: 0;
        backdrop-filter: blur(10px);
    }

    #chat-input {
        min-height: 40px;
        max-height: 120px;
        overflow-y: auto;
    }

    .chat-messages {
        padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0));
        margin-bottom: 0;
        -webkit-overflow-scrolling: touch;
    }
}

.typing-indicator {
    position: relative;
    padding: 10px;
    background: var(--bot-msg-bg);
    border-radius: 15px;
    margin-bottom: 1rem;
    margin-right: auto;
    border-bottom-left-radius: 5px;
    color: var(--text-color);
    font-size: 0.9rem;
    display: none;
    align-items: center;
    max-width: 150px;
}

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

.typing-indicator::after {
    content: "";
    width: 30px;
    height: 10px;
    margin-left: 5px;
    background-image: url("data:image/svg+xml,%3Csvg width='30' height='10' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='5' cy='5' r='3' fill='%23666'%3E%3Canimate attributeName='opacity' values='0.2;1;0.2' dur='1s' repeatCount='indefinite' begin='0s' /%3E%3C/circle%3E%3Ccircle cx='15' cy='5' r='3' fill='%23666'%3E%3Canimate attributeName='opacity' values='0.2;1;0.2' dur='1s' repeatCount='indefinite' begin='0.3s' /%3E%3C/circle%3E%3Ccircle cx='25' cy='5' r='3' fill='%23666'%3E%3Canimate attributeName='opacity' values='0.2;1;0.2' dur='1s' repeatCount='indefinite' begin='0.6s' /%3E%3C/circle%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
}