.section {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.exam-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

section {
    margin: 0 auto;
    max-width: 900px;
    padding: 2.5em 2rem 2.5em;
}

.exam-generator-container {
    width: 100%;
}

.exam-header {
    text-align: center;
    margin-bottom: 2.5em;
}

.exam-header h1 {
    font-size: 2.2rem;
    margin-bottom: 0.5em;
    color: var(--info-font-color);
}

.exam-header .description {
    font-size: 1.05rem;
    line-height: 1.6;
    color: var(--input-font-color);
    max-width: 520px;
    margin: 0 auto;
}

.form-section {
    margin-bottom: 2.5em;
}

.form-section h2 {
    font-size: 1.2rem;
    margin-bottom: 1em;
    color: var(--info-font-color);
    display: flex;
    align-items: center;
    gap: 0.5em;
}

.subjects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75em;
}

.subject-option {
    display: flex;
    align-items: center;
    gap: 0.6em;
    padding: 0.9em 1em;
    border: 2px solid #e0e0e0;
    border-radius: 0.85em;
    cursor: pointer;
    background: white;
    font-weight: 600;
    color: #23303c;
    transition:
        border-color 0.15s ease,
        background-color 0.15s ease,
        transform 0.1s ease;
}

.subject-option::before {
    content: '\2b';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 0.75em;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #eef1f0;
    color: var(--input-font-color);
    transition:
        background-color 0.15s ease,
        color 0.15s ease;
}

@media (hover: hover) {
    .subject-option:hover {
        border-color: var(--primary-color);
        background: #f6faf8;
    }

    .subject-option:hover::before {
        background: var(--primary-color);
        color: white;
    }
}

.subject-option:active {
    transform: scale(0.98);
}

.subject-option.selected {
    border-color: var(--primary-color);
    background: #ecf7f1;
}

.subject-option.selected::before {
    content: '\f00c';
    background: var(--primary-color);
    color: white;
}

.total-badge {
    padding: 0.15em 0.6em;
    border-radius: 9999px;
    background: var(--primary-color);
    color: white;
    font-size: 0.8rem;
    font-weight: 700;
}

.total-badge:empty {
    display: none;
}

.selected-items-list {
    display: flex;
    flex-direction: column;
    gap: 0.6em;
}

.selected-item {
    padding: 0.85em 1em;
    background: #f6faf8;
    border: 1px solid #dbe7e1;
    border-radius: 0.75em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75em;
}

.selected-item.child-item {
    margin-left: 1.5em;
}

.selected-item.grandchild-item {
    margin-left: 3em;
}

.selected-item .item-info {
    display: flex;
    align-items: center;
    gap: 0.75em;
    flex: 1;
    min-width: 0;
}

.selected-item .category-path {
    font-weight: 600;
    color: #23303c;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quantity-badges {
    display: flex;
    gap: 0.4em;
    flex-shrink: 0;
}

.selected-item .quantity-badge {
    background: var(--primary-color);
    color: white;
    padding: 0.2em 0.6em;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.selected-item .quantity-badge.random {
    background: var(--warn-background-color);
    color: var(--warn-font-color);
}

.selected-item .remove-item {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--input-font-color);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        background-color 0.15s ease,
        color 0.15s ease;
}

.selected-item .remove-item:hover {
    background: var(--error-background-color);
    color: white;
}

.empty-hint {
    text-align: center;
    color: var(--input-font-color);
    font-size: 0.95rem;
    padding: 1.5em 1em;
    border: 1px dashed #d1d9d5;
    border-radius: 0.85em;
}

.exam-actionbar {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5em;
    padding: 14px 20px;
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.form-error {
    color: var(--error-background-color);
    font-size: 0.9rem;
    text-align: center;
    margin: 0;
    display: none;
}

.form-error.show {
    display: block;
}

.generate-btn {
    width: 100%;
    max-width: 760px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6em;
    padding: 14px 20px;
    font-size: 1.05rem;
    font-weight: 700;
    border-radius: 12px;
}

.generate-count {
    padding: 0.1em 0.6em;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.25);
    font-size: 0.85rem;
    font-weight: 700;
}

.generate-count:empty {
    display: none;
}

@media (max-width: 600px) {
    section {
        padding: 1.5em 1.2em;
    }

    .exam-header h1 {
        font-size: 1.8rem;
    }

    .subjects-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }
}

@media (prefers-reduced-motion: reduce) {
    .subject-option,
    .subject-option::before,
    .remove-item {
        transition: none;
    }
}
