/* --- Base Layout & Background --- */
html,
body {
    overflow-x: hidden; /* ป้องกันการเลื่อนแนวนอน */
    /* **NEW** Apply overflow hidden to html as well for robust scroll prevention */
}


body {
    background-color: #3ba3d0;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    color: #fff;
    position: relative;
    overflow-y: hidden; /* <--- แก้ไขหรือเพิ่มบรรทัดนี้ */
    overflow-x: hidden;
}

/* --- NEW: Language Selection Overlay --- */
#language-selection-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    color: #333;
}

.selection-box {
    background-color: white;
    padding: 2rem 3rem;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.selection-box h2 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.selection-box button {
    background-color: #4CAF50;
    color: white;
    padding: 15px 30px;
    border: none;
    border-radius: 50px;
    font-size: 1.2rem;
    cursor: pointer;
    margin: 0 0.5rem;
    transition: background-color 0.3s;
}

.selection-box button:hover {
    background-color: #45a049;
}


.background-image {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 100%;
    height: auto;
    z-index: -1;
    animation: float-cloud 20s ease-in-out infinite;
}

.main-layout {
    min-height: 100vh;
    display: flex;
    padding: 5%;
    /* Adjusted default padding */
    padding-left: 10%;
    padding-right: 10%;
    gap: 1rem;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
    align-items: stretch;
    /* Make columns equal height */
}

/* --- General Box Styling --- */
.box,
.box-b {
    background-color: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    display: flex;
    font-weight: bold;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
}

/* --- Left Section (Box A) --- */
.box-a {
    flex: 0 0 170px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    justify-content: flex-start;
    align-items: center;
}

.box-a-image {
    width: 140px;
    height: auto;
    border: 7px solid rgba(144, 238, 144, 0.5);
    border-radius: 18px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* --- Right Section --- */
.right-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    /* Allow this section to grow */
    min-width: 0;
    /* Important for flexbox shrinking */
}

.box-b {
    flex: 1;
    width: 100%;
    /* Changed from fixed width to 100% */
    display: flex;
    flex-direction: column;
    position: relative;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    margin: 0;
    padding: 1.5rem;
    justify-content: space-between;
}


.box-b-upper {
    flex: 1;
    width: 100%;
    border-radius: 20px;
    /* The background-color below is overridden by the inline style in the HTML */
    background-color: rgba(255, 255, 255, 0.1);
    padding: 1.5rem;
    margin: 0;
    color: white;
    /* Added for better text visibility on the blue background */
    /* max-width: 800px; Added for better layout preview on wide screens */
    box-sizing: border-box;
    /* Added styles for vertical positioning */
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* Pushes content to the bottom */
}

/* --- Question Progress Indicator --- */
.question-number-dot {
    transition: all 0.3s ease-in-out;
    border-width: 2px;
    border-style: solid;
}

.progress-box.completed {
    border-color: #4CAF50;
    /* Green */
    background-color: #e8f5e9;
    color: #2e7d32;
    animation: none;
    /* Stop any active animation */
}

.question-number-dot.active {
    animation: pulse-border 1.5s infinite ease-in-out;
}

@keyframes pulse-border {
    0% {
        border-color: transparent;
    }

    50% {
        border-color: #FFA500;
    }

    100% {
        border-color: transparent;
    }
}

/* --- Conversation & Controls --- */
.message {
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
    text-align: center;
}

#ai-response {
    background-color: #e1f5fe;
    color: #000;
    max-height: 40vh;
    /* Set a max height to prevent overflow */
    overflow-y: auto;
    /* Allow scrolling */
}

#user-input {
    background-color: #c8e6c9;
    color: #000;
}

#talk-button {
    background-color: #4CAF50;
    color: white;
    padding: 15px 30px;
    border: none;
    border-radius: 50px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 20px;
}

#talk-button:hover {
    background-color: #45a049;
}

#status {
    font-size: small;
    margin-top: 15px;
    color: #fff;
}

/* --- Blinking Effect for User Input Box --- */
@keyframes blinking-effect {
    0% {
        background-color: #c8e6c9;
    }

    50% {
        background-color: #e8f5e9;
    }

    100% {
        background-color: #c8e6c9;
    }
}

.listening {
    animation: blinking-effect 2s infinite;
}

/* --- Evaluation Box --- */
#evaluation-box {
    display: none;
    opacity: 0;
    margin-top: 20px;
    padding: 15px;
    border: 2px solid #4CAF50;
    border-radius: 8px;
    background-color: #f1f8e9;
    color: #000;
    text-align: left;
    transition: opacity 0.5s ease-in-out;
}

#evaluation-box.visible {
    display: block;
    opacity: 1;
}

#evaluation-box h3 {
    margin-top: 0;
    color: #2e7d32;
    border-bottom: 1px solid #a5d6a7;
    padding-bottom: 5px;
}


/* --- =================================== --- */
/* ---      Responsive Adjustments       --- */
/* --- =================================== --- */

/* For Tablets and smaller desktops */
@media (max-width: 1024px) {
    .main-layout {
        padding: 2rem;
        /* Reduce padding */
    }

    .box-a {
        flex-basis: 150px;
        /* Make sidebar slightly smaller */
    }

    .box-a-image {
        width: 120px;
    }
}


/* For Mobile Phones */
@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
        /* Stack main sections vertically */
        padding: 1rem;
        /* Further reduce padding for small screens */
        height: auto;
        /* Allow layout to grow vertically */
    }

    .box-a {
        flex-basis: auto;
        /* Allow sidebar to have auto height */
        width: 100%;
        flex-direction: column;
        align-items: center;
        gap: 1rem;
        padding: 1rem;
    }

    .box-a-image {
        width: 120px;
        /* Adjust image size for mobile */
    }

    .box-a .text-center.font-semibold {
        display: none;
    }

    .box-a .text-base {
        display: none;
    }

    .box-a hr {
        display: none;
        /* Hide the divider line */
    }

    /* ** THIS IS THE CORRECTED RULE ** */
    /* It now specifically targets only the container for the dots */
    .box-a>.w-full>.flex.flex-col {
        flex-direction: row !important;
        justify-content: center !important;
        width: 100%;
        gap: 0.75rem !important;
    }

    #ai-response {
        max-height: 50vh;
        /* Give more vertical space for chat on mobile */
    }
}



@keyframes float-cloud {
    0% {
        transform: translateX(-50%) translateY(0);
    }

    50% {
        transform: translateX(-50%) translateY(50px);
        /* Moves the image 15px up */
    }

    100% {
        transform: translateX(-50%) translateY(0);
    }
}


/* For Mobile Phones */
@media (max-width: 768px) {

    /* ... โค้ดสำหรับมือถือส่วนอื่นๆ ... */

    /* **NEW** - Styles to make the background image larger on mobile */
    .background-image {
        width: 200%;
        /* Make the image twice the screen width */
        max-width: 200%;
        /* Allow it to be larger than the screen */
        bottom: -10%;
        /* Adjust position to show more of the cloud */
    }
}

/* --- Blinking Effect for AI Response Box --- */
@keyframes blinking-ai-response {
    0% {
        background-color: #e1f5fe;
        /* Original light blue */
    }

    50% {
        background-color: #b3e5fc;
        /* A slightly darker, more noticeable light blue */
    }

    100% {
        background-color: #e1f5fe;
        /* Back to original light blue */
    }
}

.ai-speaking {
    /* Apply the new background color animation at a SLOWER speed */
    animation: blinking-ai-response 2.5s infinite ease-in-out;
}

/* --- Page Footer --- */
#page-footer {
    position: fixed;
    bottom: 5px; /* Adjust to be closer to the bottom edge */
    left: 50%;
    /* This is the default style for mobile (always centered) */
    transform: translateX(-50%);
    width: 100%;
    text-align: center;
    color: white;
    font-size: 12px;
    z-index: 5;
    /* Add a shadow to make text visible on any background */
    text-shadow: 0px 1px 3px rgba(0, 0, 0, 0.6);
}

/* --- NEW: Media Query for Desktop/Tablet Screens --- */
@media (min-width: 769px) {
    #page-footer {
        /* On wide screens, we override the transform to shift the footer
           to the center of the right content area. */
        /* The calculation shifts it right by half of the left sidebar's width (170px / 2 = 85px)
           and half of the gap's width (1rem / 2 = 0.5rem) */
        transform: translateX(calc(-50% + 85px + 0.5rem));
    }
}

/* เพิ่มโค้ดส่วนนี้เข้าไป */
#talk-button:disabled {
    background-color: #cccccc; /* เปลี่ยนสีพื้นหลังเป็นสีเทา */
    color: #666666;           /* เปลี่ยนสีตัวอักษรเป็นเทาเข้ม */
    cursor: not-allowed;       /* เปลี่ยน cursor เป็นเครื่องหมายห้าม */
}