.selection-screen { position: fixed; z-index: 9999; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,.7); justify-content: center; align-items: center; transition: opacity .5s ease; backdrop-filter: blur(5px); display: none; opacity: 0; }
.selection-screen.active { display: flex; opacity: 1; }
.selection-box { background: #fff; padding: 30px 40px; border-radius: 20px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); max-width: 90vw; position: relative; display: flex; flex-direction: column; gap: 25px; box-sizing: border-box; }
.selection-box h1 { font-size: 1.7em; margin: 0; margin-top: 50px; color: #3c3c3c; }
.login-box { max-width: 420px; }
.character-box { max-width: 680px; padding: 35px 45px; }
@media (max-width: 480px) {
    .character-box {
        padding: 15px 8px;
        max-width: 85vw;
        margin: 10px auto;
        box-sizing: border-box;
    }
    .character-box h2 {
        font-size: 1.1em;
        margin-bottom: 20px;
        font-weight: 700;
    }
    .character-box h1 {
        font-size: 2em;
        margin-bottom: 10px;
        font-weight: 900;
    }
    .character-box p {
        font-size: 0.95em;
        font-weight: 600;
    }
}
.character-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; justify-items: center; }
.character-card { border: none; border-radius: 18px; padding: 18px 12px; background: #f8f9ff; display: flex; flex-direction: column; align-items: center; gap: 12px; cursor: pointer; transition: transform 0.25s ease, box-shadow 0.25s ease; box-shadow: 0 8px 20px rgba(142, 130, 255, 0.1); }
.character-card:hover { transform: translateY(-6px); box-shadow: 0 15px 35px rgba(142, 130, 255, 0.25); }
.character-avatar { width: 110px; height: 110px; border-radius: 50%; border: 4px solid rgba(255, 117, 171, 0.8); padding: 4px; background: linear-gradient(135deg, rgba(255, 117, 171, 0.4), rgba(142, 130, 255, 0.4)); display: flex; align-items: center; justify-content: center; }
.character-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.character-name { font-size: 1.1em; font-weight: 700; color: #3c3c3c; }
.character-role { font-size: 0.85em; color: #777; font-weight: 600; }
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap');
:root { 
    --primary-color: #8e82ff; 
    --secondary-color: #ff75ab; 
    --text-light: #fff; 
    --text-dark: #3c3c3c; 
    --border-color-light: #e0e0e0; 
    --background-color: #fdfcff; 
    --mera-bubble-color: #f3f4f6; 
    /* Background image cho chat - Thay đổi URL này để đặt hình ảnh nền */
    --chat-background-image: none; /* Ví dụ: url('images/chat-background.jpg') */
    --chat-background-overlay: rgba(255, 255, 255, 0); /* Overlay mặc định: không mờ (0 = trong suốt) */
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Nunito', sans-serif; margin: 0; overflow: hidden; background-color: #e3e8f2; }
#appContainer { position: relative; width: 100vw; height: 100vh; }
.chat-container { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 95vw; max-width: 450px; height: 95vh; max-height: 800px; background: var(--background-color); border-radius: 30px; display: flex; flex-direction: column; z-index: 10; overflow: hidden; box-shadow: 0 0 25px 8px rgba(255, 117, 171, .5); border: 1px solid var(--secondary-color); }
@media (max-width: 480px) {
    .chat-container {
        position: fixed;
        top: 0;
        left: 0;
        transform: none;
    }
}
.chat-header { display: flex; align-items: center; padding: 15px 20px; border-bottom: 1px solid var(--border-color-light); flex-shrink: 0; }
.avatar-container { display: flex; align-items: center; cursor: pointer; }
.avatar { width: 50px; height: 50px; border-radius: 50%; border: 2px solid var(--primary-color); object-fit: cover; margin-right: 15px; }
.header-info .name { font-size: 1.2em; font-weight: 700; color: var(--text-dark); }
.status-bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 20px; flex-shrink: 0; border-bottom: 1px solid var(--border-color-light); background-color: #f9f9f9; }
.relationship-status { font-size: .9em; font-weight: 600; color: #555; padding: 6px 12px; border-radius: 15px; background-color: #eee; cursor: pointer; }
.status-actions { display: flex; align-items: center; gap: 5px; }
.status-btn { width: 44px; height: 44px; border-radius: 50%; border: none; background: 0 0; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #888; transition: transform 0.2s ease; }
.status-btn:hover { transform: scale(1.05); }
.status-btn img { width: 30px; height: 30px; object-fit: contain; }
.relationship-menu { position: absolute; top: 140px; left: 20px; background: #fff; border: 1px solid #eee; border-radius: 10px; box-shadow: 0 10px 25px rgba(0,0,0,.15); display: none; overflow: hidden; z-index: 50; }
.relationship-menu .relationship-option { padding: 8px 12px; font-size: 0.95em; cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 8px; transition: background-color 0.2s ease; }
.relationship-menu .relationship-option:hover { background-color: #f5f5f5; }
.relationship-menu .relationship-option.locked { opacity: .65; cursor: not-allowed; }
.relationship-menu .relationship-option.active { background-color: #eef2ff; font-weight: 700; }
.chat-box { 
    flex-grow: 1; 
    overflow-y: auto; 
    padding: 10px 20px; 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
    /* Background image cho chat box - sẽ được set bằng JavaScript */
    background-image: var(--chat-background-image, none);
    background-size: var(--chat-background-size, cover);
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    position: relative;
    /* Đảm bảo background được render */
    will-change: background-image;
}
/* Overlay để làm mờ nền nếu cần - mặc định trong suốt */
.chat-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--chat-background-overlay, rgba(255, 255, 255, 0));
    z-index: 0;
    pointer-events: none;
}
.chat-box > * {
    position: relative;
    z-index: 1;
}
.message { padding: 12px 18px; border-radius: 20px; max-width: 80%; line-height: 1.5; font-size: 1em; position: relative; }
.message.user { background: var(--primary-color); color: var(--text-light); align-self: flex-end; border-bottom-right-radius: 5px; }
.message.mera { background: var(--mera-bubble-color); color: var(--text-dark); align-self: flex-start; border-bottom-left-radius: 5px; }
.message .replay-btn { position: absolute; bottom: 5px; right: -48px; width: 38px; height: 38px; border-radius: 50%; border: 1px solid #ddd; background-color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .3s, background-color .3s; padding: 0; }
.message .replay-btn img { width: 22px; height: 22px; }
.message:hover .replay-btn { opacity: .8; }
.message .replay-btn.playing { background-color: #e3f2fd; border-color: #2196f3; opacity: 1; }
.message .replay-btn.playing img { filter: brightness(0) saturate(100%) invert(48%) sepia(79%) saturate(2476%) hue-rotate(194deg) brightness(98%) contrast(92%); }
.input-area { 
    display: flex; 
    padding: 20px; 
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); 
    gap: 10px; 
    flex-shrink: 0; 
    background: var(--background-color);
    position: relative;
    z-index: 10;
}
#userInput { flex: 1; padding: 15px 20px; border: 1px solid #ddd; border-radius: 25px; font-family: 'Nunito', sans-serif; font-size: 1em; }
#sendBtn, .mic-btn, .image-btn { width: 70px; height: 70px; border-radius: 50%; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background-color: #fff; transition: transform 0.2s ease, background-color 0.3s ease; position: relative; z-index: 1; }
#sendBtn:hover, .mic-btn:hover, .image-btn:hover { transform: scale(1.05); }
.mic-btn img, .image-btn img, .image-btn svg { width: 38px; height: 38px; object-fit: contain; }
.mic-btn.listening { background-color: #ff6b6b; animation: pulse-mic 1.5s ease-in-out infinite; }
.mic-btn.listening img { filter: brightness(0) invert(1); }
@keyframes pulse-mic {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.7);
    }
    50% { 
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(255, 107, 107, 0);
    }
}
.send-btn img { width: 38px; height: 38px; }
.mic-btn:disabled, #sendBtn:disabled { opacity: .5; cursor: not-allowed; }
.chat-image { max-width: 100%; border-radius: 15px; margin-top: 10px; cursor: pointer; }
.chat-video { max-width: 100%; border-radius: 15px; margin-top: 10px; max-height: 400px; }
.lightbox { position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, .85); display: none; justify-content: center; align-items: center; opacity: 0; transition: opacity .3s; }
body.lightbox-active .lightbox { display: flex; opacity: 1; }
.lightbox-content { max-width: 90%; max-height: 90%; }
.lightbox-close { position: absolute; top: 15px; right: 35px; color: #f1f1f1; font-size: 40px; font-weight: 700; cursor: pointer; }
.modal { position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, .6); display: none; justify-content: center; align-items: center; opacity: 0; transition: opacity .3s; }
body.memories-active .modal#memoriesModal { display:flex; opacity: 1; }
body.premium-features-active .modal#premiumFeaturesModal { display:flex; opacity: 1; }
.modal-content { background: #fff; width: 95vw; max-width: 600px; max-height: 80vh; border-radius: 15px; box-shadow: 0 5px 25px rgba(0, 0, 0, .2); display: flex; flex-direction: column; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; border-bottom: 1px solid #eee; flex-shrink: 0; }
.close-btn { color: #aaa; font-size: 28px; font-weight: 700; cursor: pointer; }
.memories-grid { flex-grow: 1; overflow-y: auto; padding: 15px; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.google-login-button { display: inline-flex; align-items: center; justify-content: center; padding: 12px 24px; border-radius: 8px; background-color: #4285F4; color: white; font-size: 1em; font-weight: 600; text-decoration: none; border: none; cursor: pointer; transition: background-color .3s; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.google-login-button:hover { background-color: #357ae8; }
.google-login-button img { width: 20px; height: 20px; margin-right: 15px; }
.user-profile-area { position: absolute; top: 20px; right: 25px; display: flex; align-items: center; gap: 10px; text-align: right; }
.user-profile-area .user-avatar { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--secondary-color); }
.user-profile-area p { margin: 0; font-size: 0.9em; font-weight: 600; }
.user-profile-area a { font-size: 0.8em; color: #888; text-decoration: none; }
.message.premium-prompt-message p { background-color: #fff8e1; padding: 15px; border-radius: 10px; border-left: 5px solid var(--secondary-color); box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.premium-prompt-button { display: block; width: 100%; text-align: center; margin-top: 15px; padding: 12px; background: linear-gradient(45deg, var(--primary-color), var(--secondary-color)); color: white; border: none; border-radius: 8px; font-weight: 700; cursor: pointer; font-family: 'Nunito', sans-serif; font-size: 1em; }
.payment-box { background: #fff; padding: 20px 25px; border-radius: 20px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); max-width: 480px; width: 90vw; max-height: 90vh; overflow-y: auto; position: relative; }
.payment-box .close-btn { position: absolute; top: 10px; right: 20px; font-size: 30px; }
.payment-box h2 { font-size: 1.6em; margin-bottom: 8px; }
.payment-box p { margin-bottom: 12px; font-size: 0.95em; }
.package-details { display: flex; justify-content: space-between; align-items: center; background-color: #f7f7f9; padding: 12px 15px; border-radius: 12px; margin-bottom: 15px; }
.package-name { font-weight: 600; }
.package-price { font-size: 1.5em; font-weight: 700; color: var(--secondary-color); }
.package-price small { font-size: 0.5em; font-weight: normal; }
.qr-code-area { min-height: 200px; max-height: 220px; display: flex; justify-content: center; align-items: center; margin-bottom: 10px; }
#qrCodeImage { width: 200px; height: 200px; border-radius: 10px; border: 1px solid #eee; display: none; }
.qr-loading { font-style: italic; color: #888; }
.bank-info { margin-top: 10px; font-size: 0.9em; color: #555; text-align: left; line-height: 1.4; }
.bank-info p { margin: 2px 0; }
.payment-instructions { font-size: 0.9em; margin-top: 15px; color: #777; }
.payment-method-selection { margin-bottom: 15px; }
.payment-method-selection h3 { font-size: 1em; margin-bottom: 10px; }
.payment-methods { display: flex; gap: 10px; justify-content: center; }
.payment-method-btn { flex: 1; padding: 15px 20px; border: 2px solid #ddd; border-radius: 12px; background: #fff; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px; transition: all 0.3s; font-family: 'Nunito', sans-serif; font-size: 0.9em; font-weight: 600; color: #555; }
.payment-method-btn:hover { border-color: var(--primary-color); background: #f8f9ff; transform: translateY(-2px); }
.payment-method-btn.active { border-color: var(--primary-color); background: linear-gradient(45deg, var(--primary-color), var(--secondary-color)); color: white; box-shadow: 0 4px 12px rgba(142, 130, 255, 0.3); }
.payment-method-btn svg { width: 28px; height: 28px; }
.vnpay-area { min-height: 100px; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.vnpay-loading { font-style: italic; color: #888; margin-bottom: 15px; }
.vnpay-redirect-btn { padding: 15px 30px; background: linear-gradient(45deg, var(--primary-color), var(--secondary-color)); color: white; border: none; border-radius: 12px; font-size: 1.1em; font-weight: 700; cursor: pointer; font-family: 'Nunito', sans-serif; box-shadow: 0 4px 12px rgba(142, 130, 255, 0.3); transition: transform 0.3s; }
.vnpay-redirect-btn:hover { transform: scale(1.05); }
.premium-btn { width: 48px; height: 48px; border-radius: 50%; border: none; background-color: #fff8e1; cursor: pointer; display: flex; align-items: center; justify-content: center; margin-left: auto; transition: all 0.3s; box-shadow: 0 2px 5px rgba(0,0,0,0.1); padding: 0; }
.premium-btn img { width: 28px; height: 28px; object-fit: contain; }
.premium-btn:hover { transform: scale(1.1); background-color: #fef3c7; }
.premium-btn.is-premium { background: linear-gradient(45deg, var(--primary-color), var(--secondary-color)); cursor: default; }
.premium-btn.is-premium img { filter: none; }

@media (max-width: 480px) {
    body {
        overflow: hidden;
        margin: 0;
        padding: 0;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
    }
    #appContainer {
        padding: 0;
        margin: 0;
        height: 100vh;
        height: 100dvh;
    }
    .chat-container {
        width: 100vw;
        max-width: 100%;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height */
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        transform: none;
        display: flex;
        flex-direction: column;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }
    .chat-header {
        padding: 8px 12px;
        flex-shrink: 0;
    }
    .avatar {
        width: 40px;
        height: 40px;
        margin-right: 12px;
    }
    .header-info .name {
        font-size: 1em;
    }
    .status-bar {
        padding: 4px 12px;
        flex-shrink: 0;
    }
    .status-btn {
        width: 36px;
        height: 36px;
    }
    .status-btn img {
        width: 20px;
        height: 20px;
    }
    .message .replay-btn {
        right: -38px;
        width: 30px;
        height: 30px;
    }
    .message .replay-btn img {
        width: 16px;
        height: 16px;
    }
    .chat-box {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        padding: 10px 12px;
    }
    .input-area {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        gap: 8px;
        flex-shrink: 0;
        background: var(--background-color);
        border-top: 1px solid var(--border-color-light);
        /* Không dùng position fixed - để browser tự xử lý */
    }
    #userInput {
        padding: 10px 14px;
        font-size: 0.95em;
    }
    #sendBtn, .mic-btn, .image-btn {
        width: 55px;
        height: 55px;
        min-width: 55px;
        flex-shrink: 0;
    }
    .mic-btn img, .send-btn img, .image-btn svg {
        width: 28px;
        height: 28px;
    }
    .premium-btn {
        width: 38px;
        height: 38px;
    }
    .premium-btn img {
        width: 22px;
        height: 22px;
    }
    .relationship-status {
        font-size: 0.8em;
        padding: 4px 8px;
    }
    .message {
        font-size: 0.9em;
        padding: 8px 12px;
        margin-bottom: 6px;
    }
    .chat-video {
        max-height: 250px;
    }
    .character-box {
        padding: 15px 8px;
        max-width: 85vw;
        margin: 10px auto;
        box-sizing: border-box;
    }
    .selection-box h1 {
        margin-top: 40px;
        font-size: 1.5em;
    }
    .character-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 0;
        margin: 0;
        width: 100%;
        box-sizing: border-box;
    }
    .character-card {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 14px 8px;
        min-height: 150px;
    }
    .character-avatar {
        width: 85px;
        height: 85px;
        flex-shrink: 0;
    }
    .character-name {
        font-size: 0.95em;
        margin-top: 4px;
        font-weight: 700;
    }
    .character-role {
        font-size: 0.75em;
        text-align: center;
        line-height: 1.3;
        font-weight: 600;
    }
    .character-name {
        font-size: 1.05em;
    }
    .character-role {
        font-size: 0.8em;
    }
    .payment-box {
        max-height: 95vh;
        padding: 15px 20px;
    }
}