.chat-container {
    display: flex;
    flex-direction: column;  /* Layout in a column */
    justify-content: center;
    align-items: center;  /* Center all items */
    text-align: center;
    width: 100%;
    max-width: 800px;
    position: relative;
    margin: 20px auto;
    box-sizing: border-box;
}

.controls-area {
    display: flex;
    flex-direction: column; /* Stack button and toggle vertically */
    align-items: center;    /* Center them horizontally */
    width: 100%;
    gap: 12px;             /* Space between button and checkbox */
    margin-top: 10px;
    position: relative;
}

.chat-area {
    display: flex; 
    width: 100%; 
    margin-top: 10px;
    align-items: flex-start; /
}

.avatar-container {
    position: relative;
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
    width: 100%;
}

.avatar {
    width: 300px; 
    height: 300px; 
    background-size: cover;      /* Scales image to fill the div */
    background-position: center;  /* Centers Lily's face */
    background-repeat: no-repeat;
    border-radius: 50%;
    margin: 5px auto;
    transition: transform 0.3s ease;
    cursor: pointer; 
}
.avatar:hover {
    transform: scale(1.04); 
    transition: all 0.6s ease-in-out;
}

.avatar-sidebar-indicator {
    position: absolute;
    top: 43%;
    right: 30%;          
    display: flex;
    align-items: center;
    justify-content: center;
    
    color: white;
    font-size: 26px;
    font-weight: bold;
    line-height: 1;
    
    cursor: pointer;
    transition: all 0.18s ease;
    box-shadow: -2px 0 8px rgba(0,0,0,0.15);
    z-index: 10;
    background: linear-gradient(
        to bottom,
        rgba(172, 172, 172, 0.98) 0%,
        rgba(126, 162, 127, 0.97) 50%,
        rgba(161, 161, 161, 0.98) 100%
    );
    width: 20px;
    height: 68px;
    border-radius: 0 8px 8px 0;
}

.avatar-sidebar-indicator:hover,
.avatar-sidebar-indicator:active {
    background: rgba(67, 162, 46, 0.92);
    box-shadow: -4px 0 12px rgba(0,0,0,0.22);
}

.avatar-sidebar-indicator:not(.has-interacted) {
    animation: sidebar-hint 2s ease-in-out 1.5s 2; /* gentle hint after page load */
}

.avatar-popup {
    position: absolute;
    top: 20%; 
    left: 82%;
    transform: translateX(-50%);
    background: rgb(252, 255, 249);
    border: 1px solid #3936369c;
    border-radius: 6px;
    padding: 10px;
    display: none; 
    z-index: 1000; 
    box-shadow: 0 4px 8px rgba(11, 19, 8, 0.1);
}
.avatar-list {
    margin-bottom: 3px;
    min-width: 150px;
    width: auto;
}
.avatar-option {
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 3px;
}
.avatar-option:hover {
    background: #f0f0f0;
}

.avatar.speaking {
    animation: talk 0.4s infinite alternate;
}@keyframes talk {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); }
}

#questionmark-popup {
    position: absolute;
    bottom: 8%;
    right: 26%;
    width: 80px;
    height: auto;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

.language-selection #popup-language { /* language choice box */
    padding: 5px 5px;
    font-size: 16px;
    border: 0px solid #000000;
    border-radius: 4px;
    cursor: pointer;
    background-color: #d9f2d5;
    transition: all 0.2s ease;
}

.chat-box-container {
    width: 100%;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;;
    overflow: hidden; 
    transition: height 0.3s ease-in-out, padding 0.3s ease-in-out, border-width 0.3s ease-in-out; /* Added border-width */
}
.chat-box {
    height: 200px; 
    max-width: 100%;
    overflow-y: auto;   
    padding: 10px;
    border: 2px solid #ccc;
    border-radius: 5px;
    margin: 10px 10px 10px 0; 
    background: #fbfffa;
    font-size: 14px;
    font-family: Arial, Helvetica, sans-serif;
    color: #333;
    text-align: center;
    display: center;
    flex-direction: column;
    flex-grow: 1;
    justify-content:flex-start;
}

.chat-box-collapsed {
    height: 3px;
    padding: 0;
    border-width: 0; 
}

.translation-text {
    font-style: italic;
    color: #555;
    margin-top: 5px; 
    margin-left: 20px; 
    padding: 5px;
    background-color: #f9f9f9;
}

.ai-message-container {
    margin-bottom: 10px; 
}

.translate-toggle-btn {
    display: inline-block; 
    margin-left: 10px; 
    padding: 2px 6px;
    font-size: 0.8em;
    cursor: pointer;
    border: 1px solid #ccc;
    background-color: #eee;
    border-radius: 3px;
}
.translate-toggle-btn:hover {
    background-color: #ddd;
}
.translate-toggle-btn:disabled {
    cursor: default;
    opacity: 0.6;
}

#transcript-toggle-container {
    white-space: nowrap; 
    text-align: center;
    font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
    /* Removed absolute positioning to let it sit naturally below the button */
    position: static; 
}

#show-transcript-toggle {
    margin-right: 5px;
    transform: scale(1.3);
}

.toggle-label {
    display:inline-block;
    align-items: center;
    cursor: pointer;
    font-size: large;
    padding-left: 10px;
}

.ai-response {
    color: #a5af4c;
    font-weight: bold;
    margin-bottom: 8px;
}

.disabled-talk-btn {
    opacity: 0.4 !important;
    cursor: not-allowed !important;
    pointer-events: none;
    background-color: #ccc !important;
    color: #555 !important;
    border: 1px solid #aaa;
}

#quota-msg {
    position: absolute;
    top: 95%; /* position below the avatar */
    left: 50%;
    transform: translate(-50%, -30%); /* pull it up a bit and center */
    background-color: rgba(222, 222, 222, 0.85);
    color: rgb(208, 12, 12);
    padding: 8px 12px;
    font-weight: bold;
    border-radius: 6px;
    z-index: 9299;
    white-space: nowrap;
}

#talk-btn {
    width: fit-content; 
    height: 50px;    
    box-sizing: border-box; 
    display: flex;
    justify-content: center; 
    overflow: hidden;   
    white-space: nowrap;
    align-items: center;     
    text-align: center; 
    padding: 20px 20px;
    border: none;
    background: #249d08;
    color: white;
    border-radius: 33px;
    cursor: pointer;
    font-size: 22px;
    font-family: Georgia, 'Times New Roman', Times, serif;
    position: static; 
    margin: 0; 
    margin-top: 10px;
    transition: background-color 0.1s ease, color 0.1s ease; 
}

#talk-btn:hover {
    background: #4bd654;
    transform: scale(1.04);
}

@media (max-width: 768px) {
    .chat-container * {
        position: relative !important;     
    }
    .avatar-container {
        width: 100%;
        display: flex;
        justify-content: center;
        margin: 20px 0 24px; 
        position: static;
    }
    .avatar-container.open {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        width: 100%;
        position: relative;
        gap: 2%;
    }
    .avatar-container.open .avatar {
        width: 40vw;
        height: 40vw;
        min-width: 140px;
        min-height: 140px;
        transition: all 0.15s ease;
    }

    .avatar {
        width:  clamp(180px, 52vw, 240px);
        height: clamp(180px, 52vw, 240px);   /* enforce 1:1 ratio */
        min-width: 180px;               /* prevent becoming too tiny */
        min-height: 180px;
        background-size: cover;
        background-position: center;
        border-radius: 50%;
        flex-shrink: 0;                 /* very important – prevents squish in flex */
        box-shadow: 0 4px 16px rgba(0,0,0,0.12);
        position: relative;
    }

    .avatar-sidebar-indicator {
        position: absolute !important;
        top: 23% !important;
        right: 20% !important;          
        display: flex;
        align-items: center;
        justify-content: center;
        
        color: white;
        font-size: 26px;
        font-weight: bold;
        line-height: 1;
        
        cursor: pointer;
        transition: all 0.18s ease;
        box-shadow: -2px 0 8px rgba(0,0,0,0.15);
        z-index: 10;
        background: linear-gradient(
            to bottom,
            rgba(172, 172, 172, 0.98) 0%,
            rgba(126, 162, 127, 0.97) 50%,
            rgba(161, 161, 161, 0.98) 100%
        );
        width: 20px;
        height: 68px;
        border-radius: 0 8px 8px 0;
    }
    
    .avatar-sidebar-indicator:hover,
    .avatar-sidebar-indicator:active {
        background: rgba(67, 162, 46, 0.92);
        box-shadow: -4px 0 12px rgba(0,0,0,0.22);
    }
    
    .avatar-sidebar-indicator:not(.has-interacted) {
        animation: sidebar-hint 1s ease-in-out 1s 2; /* gentle hint after page load */
    }
    /* Make sure popup doesn't fight for space */
    .avatar-popup {
        position: fixed;
        inset: 0;
        margin: auto;
        width: 88%;
        max-width: 360px;
        max-height: 82vh;
        overflow-y: auto;
        transform: none;               /* reset previous transform */
        border-radius: 12px;
        padding: 20px;
    }

    /* ── Controls area – give more vertical breathing room ──────────────── */
    .controls-area {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 20px;                      /* ← increased from previous suggestions */
        margin: 0 0 28px;
        width: 100%;
        padding: 0 12px;
    }

    #talk-btn {
        width: 100%;
        max-width: 340px;
        min-height: 58px;
        font-size: 1.22rem;
        padding: 0 28px;
        border-radius: 999px;
        box-shadow: 0 4px 14px rgba(36, 157, 8, 0.32);
    }

    #transcript-toggle-container {
        margin-top: 4px;               /* tiny nudge if needed */
        padding: 8px 16px;
        background: rgba(240,248,240,0.6);
        border-radius: 12px;
        width: auto;
    }

    .toggle-label {
        font-size: 1.08rem;
        display: flex;
        align-items: center;
        gap: 12px;
    }

    #show-transcript-toggle {
        transform: scale(1.45);
    }

    /* ── Chat box – prevent feeling crammed ─────────────────────────────── */
    .chat-box-container {
        width: 100%;
        padding: 0 10px;
        box-sizing: border-box;
    }

    .chat-box {
        min-height: 160px;
        max-height: 44vh;
        padding: 16px 18px;
        font-size: 15.5px;
        line-height: 1.48;
        border-radius: 12px;
        border: 1px solid #d8e0d2;
        background: #fcfff8;
        margin: 0;
    }

    #quota-msg {
        position: fixed;
        bottom: 96px;                    /* above floating mic button if any */
        left: 50%;
        transform: translateX(-50%);
        width: 90%;
        max-width: 360px;
        text-align: center;
        padding: 12px 18px;
        border-radius: 12px;
        font-size: 0.98rem;
        z-index: 100;
    }

    #questionmark-popup {
        position: absolute;
        bottom: 24%;
        right: 28%;
        width: auto;
        height: 16vw;
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
}