/* --- General Styling & Best Practices --- */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --light-color: #ecf0f1;
    --dark-color: #34495e;
    --correct-color: #2ecc71;
    --incorrect-color: #e74c3c;
    --warning-color: #f1c40f;
    --border-radius: 12px;
    --box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Poppins', sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: var(--primary-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

/* --- Main Quiz Container --- */
#quiz-container {
    width: 100%;
    max-width: 800px;
    background: #ffffff;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* --- Screens (Course Selection, Start, Quiz, Results) --- */
.screen {
    padding: 40px;
    text-align: center;
}

.hidden {
    display: none;
}

h1,
h2 {
    margin-bottom: 20px;
    color: var(--dark-color);
}

h1 {
    font-size: 2.5rem;
}

h2 {
    font-size: 1.8rem;
    line-height: 1.4;
}

p {
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 30px;
}

/* --- Top Bar (Language Selector + Home Button) --- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background-color: var(--light-color);
    border-bottom: 1px solid #ddd;
    position: relative;
    z-index: 100;
}

.home-btn {
    background: none;
    border: 2px solid var(--dark-color);
    color: var(--dark-color);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 1.1rem;
}

.home-btn:hover {
    background-color: var(--dark-color);
    color: white;
}

.home-btn.hidden {
    visibility: hidden;
}

/* --- Current Course Title in Top Bar --- */
.current-course-title {
    flex: 1;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--dark-color);
    padding: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.current-course-title.hidden {
    display: none;
}

.language-selector {
    display: flex;
    gap: 8px;
}

.lang-btn {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lang-btn .flag-icon {
    width: 32px;
    height: 24px;
    display: block;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    opacity: 0.4;
    filter: grayscale(30%);
    transform: scale(0.9);
}

/* Active state - full visibility */
.lang-btn.active .flag-icon {
    opacity: 1;
    filter: grayscale(0%);
    transform: scale(1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Hover state - reveal inactive flags */
.lang-btn:hover .flag-icon {
    opacity: 1;
    filter: grayscale(0%);
    transform: scale(1.05);
}

/* Subtle lift effect on hover for all */
.lang-btn:hover {
    transform: translateY(-2px);
}

.lang-btn.active:hover .flag-icon {
    transform: scale(1.08);
}

/* --- Filter Controls --- */
#filter-controls {
    margin-bottom: 25px;
}

#search-filter {
    margin-bottom: 15px;
}

#search-input {
    width: 100%;
    padding: 12px 18px;
    font-size: 1rem;
    font-family: inherit;
    border: 2px solid var(--light-color);
    border-radius: 50px;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#search-input:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

#search-input::placeholder {
    color: #95a5a6;
}

#group-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.group-filter-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    border: 2px solid var(--light-color);
    border-radius: 50px;
    background-color: white;
    color: var(--dark-color);
    cursor: pointer;
    transition: all 0.3s ease;
}

.group-filter-btn:hover {
    border-color: var(--secondary-color);
    background-color: #f1f8fe;
}

.group-filter-btn.active {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
    color: white;
}

.group-filter-btn.active:hover {
    filter: brightness(0.9);
}

/* --- Course Selection Screen --- */
#course-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

.course-card {
    background: var(--light-color);
    border: 2px solid transparent;
    border-left: 5px solid var(--secondary-color);
    border-radius: var(--border-radius);
    padding: 20px;
    text-align: left;
    cursor: pointer;
    transition: all 0.3s ease;
}

.course-card:hover {
    border-color: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: var(--box-shadow);
}

.course-card.hidden-by-filter {
    display: none;
}

.course-card h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1.4rem;
}

.course-card .course-meta {
    font-size: 0.9rem;
    color: #555;
    margin-bottom: 10px;
    font-weight: 500;
}

.course-card .course-description {
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 0;
    color: #333;
}

.start-btn,
.restart-btn,
.back-btn {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.2rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    margin: 5px;
}

.start-btn:hover,
.restart-btn:hover,
.back-btn:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
}

.back-btn {
    background-color: var(--dark-color);
}

.back-btn:hover {
    background-color: var(--primary-color);
}

/* --- Progress Wizard --- */
#progress-wizard {
    display: flex;
    justify-content: space-around;
    padding: 20px 0;
    background-color: var(--light-color);
    border-bottom: 1px solid #bdc3c7;
}

.wizard-step {
    flex: 1;
    text-align: center;
    font-size: 0.8rem;
    color: #7f8c8d;
    position: relative;
    padding: 0 5px;
}

.wizard-step.active {
    color: var(--secondary-color);
    font-weight: 700;
}

.wizard-step.completed {
    color: var(--correct-color);
}

.wizard-step::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #bdc3c7;
}

.wizard-step.active::before {
    background-color: var(--secondary-color);
}

.wizard-step.completed::before {
    background-color: var(--correct-color);
}

/* --- Quiz Progress Bar --- */
#quiz-progress-bar {
    width: 100%;
    height: 4px;
    background-color: var(--light-color);
    overflow: hidden;
}

#quiz-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--secondary-color), var(--correct-color));
    transition: width 0.3s ease;
}


/* --- Quiz Screen Specifics --- */
#quiz-screen {
    padding: 0;
}

#question-area {
    padding: 40px;
    text-align: center;
}

#question-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

#question-text {
    margin-bottom: 0;
}

#info-btn {
    background: none;
    border: 2px solid var(--secondary-color);
    color: var(--secondary-color);
    width: 30px;
    height: 30px;
    min-width: 30px;
    min-height: 30px;
    max-width: 30px;
    max-height: 30px;
    border-radius: 50%;
    font-size: 1rem;
    font-weight: bold;
    font-style: italic;
    font-family: Georgia, 'Times New Roman', Times, serif;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

#info-btn:hover {
    background: var(--secondary-color);
    color: white;
}

#info-btn.hidden {
    display: none;
}

#question-counter {
    font-size: 1rem;
    color: #7f8c8d;
    margin-bottom: 25px;
}

#options-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 30px;
}

.option-btn {
    background-color: #ffffff;
    color: var(--primary-color);
    border: 2px solid var(--light-color);
    padding: 15px;
    font-size: 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    text-align: left;
    transition: all 0.3s ease;
}

.option-btn:hover:not(:disabled) {
    border-color: var(--secondary-color);
    background-color: #f1f8fe;
}

.option-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.option-btn.correct {
    background-color: var(--correct-color);
    border-color: var(--correct-color);
    color: white;
}

.option-btn.incorrect {
    background-color: var(--incorrect-color);
    border-color: var(--incorrect-color);
    color: white;
}

#navigation {
    padding: 0 40px 40px 40px;
    text-align: right;
}

#next-btn {
    background-color: var(--dark-color);
    color: white;
    border: none;
    padding: 10px 25px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#next-btn:hover {
    background-color: var(--primary-color);
}

/* --- Results Screen --- */
#results-summary {
    list-style: none;
    padding: 0;
    margin-bottom: 30px;
    text-align: left;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 8px;
    background-color: var(--light-color);
}

.result-item .topic-name {
    font-weight: 600;
}

.result-item .score {
    font-weight: 700;
    font-size: 1.2rem;
    padding: 5px 10px;
    border-radius: 5px;
    color: white;
}

.score.pass {
    background-color: var(--correct-color);
}

.score.warn {
    background-color: var(--warning-color);
}

.score.fail {
    background-color: var(--incorrect-color);
}

#overall-score {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 30px;
}

/* --- Info Modal --- */
#info-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#info-modal.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 600px;
    position: relative;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

#info-modal.visible .modal-content {
    transform: scale(1);
}

#close-modal-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem;
    color: #7f8c8d;
    cursor: pointer;
    line-height: 1;
}

#modal-explanation {
    font-size: 1rem;
    text-align: left;
}

/* --- Loading Indicator --- */
.loading {
    text-align: center;
    padding: 40px;
}

.spinner {
    border: 4px solid var(--light-color);
    border-top: 4px solid var(--secondary-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* --- Group Headers --- */
.group-header {
    color: white;
    padding: 12px 20px;
    border-radius: var(--border-radius);
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1.2rem;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.group-header:first-child {
    margin-top: 0;
}

.group-header.hidden-by-filter {
    display: none;
}

/* --- Group Course Container --- */
.group-courses-container {
    background-color: var(--group-color, rgba(52, 152, 219, 0.1));
    border-radius: var(--border-radius);
    padding: 15px;
    margin-bottom: 20px;
}

.group-courses-container .course-card {
    background: rgba(255, 255, 255, 0.9);
    margin-bottom: 10px;
}

.group-courses-container .course-card:last-child {
    margin-bottom: 0;
}

.group-courses-container.hidden-by-filter {
    display: none;
}

/* --- No Results Message --- */
.no-results-message {
    text-align: center;
    padding: 40px 20px;
    color: #7f8c8d;
    font-size: 1.1rem;
}

.no-results-message .no-results-icon {
    font-size: 3rem;
    margin-bottom: 15px;
    opacity: 0.5;
}

/* --- History Section --- */
.history-section {
    margin-top: 40px;
    padding-top: 30px;
    border-top: 2px solid var(--light-color);
}

.history-section h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--dark-color);
}

.history-toggle-btn {
    background: none;
    border: 2px solid var(--secondary-color);
    color: var(--secondary-color);
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 20px;
}

.history-toggle-btn:hover {
    background-color: var(--secondary-color);
    color: white;
}

.history-list {
    display: none;
    flex-direction: column;
    gap: 15px;
}

.history-list.visible {
    display: flex;
}

.history-item {
    background: var(--light-color);
    border-radius: var(--border-radius);
    padding: 15px 20px;
    text-align: left;
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.history-item-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--primary-color);
}

.history-item-date {
    font-size: 0.85rem;
    color: #7f8c8d;
}

.history-item-score {
    display: flex;
    align-items: center;
    gap: 10px;
}

.history-item-score .score-value {
    font-weight: 700;
    font-size: 1.3rem;
}

.history-item-score .score-value.pass {
    color: var(--correct-color);
}

.history-item-score .score-value.warn {
    color: var(--warning-color);
}

.history-item-score .score-value.fail {
    color: var(--incorrect-color);
}

.history-item-details {
    font-size: 0.9rem;
    color: #555;
}

.history-compare {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #ddd;
}

.history-compare-label {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-bottom: 5px;
}

.history-trend {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
}

.history-trend.improving {
    color: var(--correct-color);
}

.history-trend.declining {
    color: var(--incorrect-color);
}

.history-trend.stable {
    color: var(--warning-color);
}

.clear-history-btn {
    background: none;
    border: 1px solid var(--incorrect-color);
    color: var(--incorrect-color);
    padding: 8px 16px;
    font-size: 0.9rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 15px;
}

.clear-history-btn:hover {
    background-color: var(--incorrect-color);
    color: white;
}

.no-history-message {
    text-align: center;
    padding: 20px;
    color: #7f8c8d;
    font-style: italic;
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    .top-bar {
        padding: 10px 12px;
    }

    .home-btn {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }

    .lang-btn .flag-icon {
        width: 28px;
        height: 20px;
    }

    #progress-wizard {
        flex-wrap: wrap;
        justify-content: flex-start;
        padding: 10px;
    }

    .wizard-step {
        flex-basis: 33.33%;
        margin-bottom: 10px;
        font-size: 0.7rem;
    }

    #options-container {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    .screen {
        padding: 25px;
    }

    #question-area,
    #navigation {
        padding: 25px;
    }

    #group-filter {
        gap: 6px;
    }

    .group-filter-btn {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    .history-item-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
}