@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;700&display=swap');

:root {
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --background-color: #f0f2f5;
    --card-background: #fff;
    --text-color: #333;
    --muted-color: #606770;
    --border-color: #dddfe2;
    --input-focus: #007bff;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Sarabun', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    margin-bottom: 50px;
}

.container {
    max-width: 700px;
    width: 100%;
    min-height: 1000px;
    background: var(--card-background);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .1);
    text-align: center;
    margin-top: 20px;
}

.hidden {
    display: none !important;
}

strong {
    font-weight: 700;
}

/* --- Topic Selection Dropdown Styles --- */
#topic-selection h2 {
    margin-bottom: 8px;
}

.dropdown {
    position: relative;
    display: inline-block;
    width: 100%;
    max-width: 400px;
    margin: 15px auto;
}

.dropdown-toggle {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 13px 28px;
    border-radius: 8px;
    font-size: 1.1em;
    cursor: pointer;
    transition: all 0.25s ease;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dropdown-toggle:hover {
    background: var(--primary-hover);
}

.dropdown-toggle::after {
    content: '▼';
    font-size: 0.8em;
    margin-left: 10px;
    transition: transform 0.3s ease;
}

.dropdown.open .dropdown-toggle::after {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-top: 5px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    z-index: 100;
    max-height: 40vh;
    overflow-y: auto;
    text-align: left;
    display: none;
}

.dropdown.open .dropdown-menu {
    display: block;
}

.topic-button {
    display: block;
    width: 100%;
    background: white;
    color: var(--text-color);
    border: none;
    border-bottom: 1px solid #f0f2f5;
    padding: 12px 20px;
    font-size: 1.05em;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.topic-button:last-child {
    border-bottom: none;
}

.topic-button:hover {
    background: #f7f8fa;
    color: var(--primary-hover);
    transform: none;
}

/* Quiz Interface */
#progress-text {
    color: var(--muted-color);
    margin-bottom: 12px;
    font-size: 1em;
}

#prompt-area {
    background: #f7f8fa;
    border: 1px solid var(--border-color);
    padding: 18px;
    border-radius: 8px;
    margin-bottom: 18px;
    font-size: 1.15em;
    min-height: 66px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.4;
    gap: 15px;
}

#question-image-container {
    max-width: 100%;
    display: none; /* Hidden by default */
}

#question-image-container img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    object-fit: contain;
}

/* Dynamic Inputs Styling */
.dynamic-inputs-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    width: 100%;
    margin-bottom: 15px;
}

.multi-answer-input {
    flex: 1 1 200px; /* Grow, shrink, base width */
    padding: 13px;
    font-size: 1.08em;
    border: 2px solid #ccc;
    border-radius: 8px;
    text-align: center;
    transition: border-color 0.3s ease;
    font-family: 'Sarabun', sans-serif;
}

.multi-answer-input:focus {
    border-color: var(--input-focus);
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

.multi-answer-input:disabled {
    background-color: #f8f9fa;
    cursor: not-allowed;
    border-color: #e2e6ee;
    color: var(--muted-color);
}

/* State classes for inputs */
.multi-answer-input.correct-input {
    border-color: var(--success-color);
    background-color: #f0fff4;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.18);
}

.multi-answer-input.incorrect-input {
    border-color: var(--danger-color);
    background-color: #fff5f5;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.18);
}

#submit-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1em;
    transition: all 0.2s ease;
    margin: 18px auto 0;
    width: fit-content;
    display: block;
    max-width: 250px;
}

#submit-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

#submit-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Navigation Controls */
.navigation-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
    gap: 10px;
}

.nav-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s ease;
    min-width: 100px;
}

.nav-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

.nav-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

.question-counter {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 1.1em;
}

/* Feedback */
#feedback-text {
    margin-top: 8px;
    font-size: 1.15em;
    min-height: 28px;
    font-weight: 500;
}

.correct {
    color: var(--success-color);
}

.incorrect {
    color: var(--danger-color);
}

.partial {
    color: #b58900;
}

/* Summary Card shown after answer */
.summary-feedback-card {
    text-align: left;
    padding: 15px;
    margin-top: 15px;
    border-radius: 8px;
    animation: fadeIn 0.4s ease;
    font-size: 1em;
    background-color: #f8f9fa;
    border-left: 5px solid var(--primary-color);
}

.summary-feedback-card p {
    margin: 5px 0;
    line-height: 1.5;
}

/* Controls */
.control-buttons {
    margin-top: 25px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.action-btn {
    padding: 8px 18px;
    font-size: 1em;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    background: #e9ecef;
    transition: all 0.18s ease;
}

.action-btn:hover {
    background: #dde2e8;
    transform: translateY(-1px);
}

/* Results Section */
.results-section {
    margin-top: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.results-header {
    font-size: 1.2em;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 15px;
}

.question-result {
    margin-bottom: 20px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    text-align: left;
    border-left: 4px solid transparent;
}

.question-result.completed {
    border-left-color: var(--success-color);
}

.question-result.partial {
    border-left-color: var(--warning-color);
}

.question-result.incorrect {
    border-left-color: var(--danger-color);
}

.final-message {
    font-size: 1.3em;
    margin: 18px 0;
    font-weight: 700;
    color: var(--success-color);
}

/* Score and Summary */
#score-summary {
    margin: 18px 0 6px 0;
    font-size: 1em;
    font-weight: 500;
    padding: 10px;
    background: #e9ecef;
    border-radius: 8px;
}

@media (max-width: 600px) {
    .container {
        padding: 20px;
        margin: 10px;
    }
    .dynamic-inputs-container {
        flex-direction: column;
    }
    .multi-answer-input {
        width: 100%;
        flex: 0 0 auto;
        height: 48px;
        min-height: 48px;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
