*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    -webkit-text-size-adjust: 100%;
}

body {
    min-width: 320px;
    max-width: 100%;
    overflow-x: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 2px;
}

#back-to-top {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    width: 44px;
    height: 44px;
    border-radius: 9999px;
    background: #2563eb;
    color: #fff;
    font-size: 1.25rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 40;
}

#back-to-top.visible {
    opacity: 1;
    pointer-events: auto;
}

dialog {
    padding: 0;
    margin: auto;
    max-height: calc(100vh - 1rem);
    max-height: calc(100dvh - 1rem);
    overflow-y: auto;
    overscroll-behavior: contain;
}

dialog::backdrop {
    background: rgba(17, 24, 39, 0.55);
}

.pdf-page {
    display: block;
    width: 100%;
    height: auto;
    background: #fff;
    border: 1px solid #e5e7eb;
}

textarea,
input,
select {
    border-color: #d1d5db;
}

img,
canvas,
video {
    max-width: 100%;
}

input,
select,
textarea {
    max-width: 100%;
    font-size: 16px;
}

button,
input[type="submit"],
a[class*="bg-"] {
    min-height: 44px;
}

a[class*="bg-"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

nav > div {
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.overflow-x-auto,
.table-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
}

.table-scroll table,
.overflow-x-auto table {
    min-width: 34rem;
}

.page-btn {
    z-index: 2;
    touch-action: manipulation;
}

.bank-filters {
    grid-template-columns: minmax(0, 1fr);
}

.bank-filter-actions {
    grid-column: 1 / -1;
}

.bank-filters > .kp-picker {
    grid-column: 1 / -1;
}

.csv-header {
    white-space: normal;
    overflow-wrap: anywhere;
}

.kp-picker {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem;
    min-width: 0;
    width: 100%;
}

.kp-picker > label {
    display: grid;
    gap: 0.25rem;
    min-width: 0;
}

.kp-picker-status {
    grid-column: 1 / -1;
}

.kp-picker-status:empty {
    display: none;
}

.kp-picker select {
    min-height: 44px;
}

.kp-chips {
    overflow-wrap: anywhere;
}

@media (min-width: 640px) {
    .kp-picker {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .bank-filters {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .bank-filters {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

#progressModal,
#studentModal {
    padding: 0.5rem;
}

#progressModal > div,
#studentModal > div {
    max-height: calc(100vh - 1rem);
    max-height: calc(100dvh - 1rem);
    overflow-y: auto;
    overscroll-behavior: contain;
}

@media (max-width: 768px) {
    main {
        padding: 1rem !important;
    }

    .container {
        width: 100%;
        max-width: 100%;
    }

    .button-group {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .grading-workspace {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .score-panel {
        max-height: none !important;
    }

    #studentModal > div {
        width: 100%;
        max-width: 32rem;
    }
}

@media (max-width: 480px) {
    nav {
        padding: 0.75rem !important;
    }

    .question-row {
        grid-template-columns: 3.75rem 5rem minmax(0, 1fr) !important;
        gap: 0.35rem !important;
    }

    #progressModal > div {
        width: 100%;
        padding: 0.75rem;
    }

    .page-btn {
        width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
    }
}
