:root {
    --canvas: #f6f8fb;
    --surface: #ffffff;
    --text: #18243b;
    --text-secondary: #607087;
    --primary: #275dde;
    --primary-dark: #1c4bbd;
    --primary-pale: #edf3ff;
    --border: #e4eaf2;
    --success: #16785b;
    --success-pale: #eaf6f2;
    --danger: #ba3446;
    --danger-pale: #fceff1;
    --warning: #9a6215;
    --warning-pale: #fdf5e7;
    --radius-card: 12px;
    --radius-control: 8px;
    --shadow-card: 0 1px 3px rgba(24, 36, 59, 0.04), 0 1px 2px rgba(24, 36, 59, 0.02);
    --sidebar-width: 224px;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--canvas);
    color: var(--text);
    font-family: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

:focus-visible {
    outline: 3px solid rgba(39, 93, 222, 0.45);
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    top: -100px;
    left: 16px;
    z-index: 300;
    padding: 10px 16px;
    border-radius: var(--radius-control);
    background: var(--primary);
    color: #fff;
}

.skip-link:focus {
    top: 16px;
}

.icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Authenticated portal shell */
.portal-layout {
    display: flex;
    min-height: 100vh;
}

.portal-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 120;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.sidebar-brand-block {
    position: relative;
    padding: 24px 20px 18px;
}

.sidebar-brand {
    margin: 0;
    color: var(--text);
    font-size: 20px;
    font-weight: 750;
    letter-spacing: -0.02em;
}

.sidebar-brand:hover {
    text-decoration: none;
}

.sidebar-tagline {
    margin: 2px 0 0;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
}

.sidebar-close {
    position: absolute;
    top: 16px;
    right: 12px;
    display: none;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: var(--radius-control);
    background: transparent;
    color: var(--text-secondary);
    font-size: 22px;
    line-height: 1;
}

.sidebar-close:hover {
    background: var(--canvas);
}

.sidebar-nav {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-control);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 550;
}

.sidebar-link:hover {
    background: var(--canvas);
    color: var(--text);
    text-decoration: none;
}

.sidebar-link.is-active {
    background: var(--primary-pale);
    color: var(--primary);
}

.sidebar-divider {
    height: 1px;
    margin: 12px 14px;
    background: var(--border);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 10px;
    border-radius: var(--radius-control);
    background: var(--canvas);
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
}

.user-card-copy {
    min-width: 0;
}

.user-name {
    margin: 0;
    overflow: hidden;
    color: var(--text);
    font-size: 13px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-meta {
    margin: 0;
    overflow: hidden;
    color: var(--text-secondary);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-link {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-control);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 550;
}

.logout-link:hover {
    background: var(--canvas);
    color: var(--text);
    text-decoration: none;
}

.portal-main {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    margin-left: var(--sidebar-width);
}

.portal-topbar {
    position: sticky;
    top: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 64px;
    padding: 12px 28px;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    background: var(--surface);
    color: var(--text);
}

.topbar-context {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--text-secondary);
    font-size: 13px;
}

.topbar-context .context-current {
    overflow: hidden;
    color: var(--text);
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-context .context-separator {
    color: var(--border);
}

.topbar-account {
    margin-left: auto;
    color: var(--text-secondary);
    font-size: 13px;
}

.page-content {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding: 36px 32px 56px;
}

/* Page headings and shared surfaces */
.page-heading {
    margin: 0 0 24px;
}

.page-title {
    margin: 0;
    color: var(--text);
    font-size: 28px;
    font-weight: 750;
    letter-spacing: -0.025em;
    line-height: 1.3;
}

.page-subtitle {
    margin: 6px 0 0;
    color: var(--text-secondary);
    font-size: 15px;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 28px 0 14px;
}

.section-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
}

/* Messages */
.messages {
    display: grid;
    gap: 8px;
    margin: 0 0 20px;
    padding: 0;
    list-style: none;
}

.messages:focus {
    outline: 3px solid rgba(39, 93, 222, 0.45);
    outline-offset: 2px;
}

.message {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: var(--radius-control);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
}

.message-error,
.message-danger {
    border-color: #f3c8ce;
    border-left-color: var(--danger);
    background: var(--danger-pale);
    color: #8e2434;
}

.message-success {
    border-color: #c7e7dc;
    border-left-color: var(--success);
    background: var(--success-pale);
    color: var(--success);
}

.message-warning {
    border-color: #f0dfbc;
    border-left-color: var(--warning);
    background: var(--warning-pale);
    color: var(--warning);
}

.message-info {
    border-color: #cfdcfb;
    border-left-color: var(--primary);
    background: var(--primary-pale);
    color: var(--primary-dark);
}

/* Home */
.summary-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin: 0 0 28px;
    padding: 18px 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
}

.summary-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 0 20px;
    border-right: 1px solid var(--border);
}

.summary-item:last-child {
    border-right: 0;
}

.summary-label {
    color: var(--text-secondary);
    font-size: 13px;
}

.summary-value {
    color: var(--text);
    font-size: 17px;
    font-weight: 750;
}

.course-list {
    display: grid;
    gap: 12px;
}

.course-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 20px 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
}

.course-main {
    min-width: 0;
}

.course-term {
    margin: 0 0 4px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 650;
    letter-spacing: 0.02em;
}

.course-title {
    margin: 0;
    color: var(--text);
    font-size: 17px;
    font-weight: 700;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.course-meta {
    margin: 6px 0 0;
    color: var(--text-secondary);
    font-size: 13px;
}

.course-action {
    flex: 0 0 auto;
}

.info-panel {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-top: 28px;
    padding: 14px 16px;
    border: 1px solid #cfdcfb;
    border-radius: var(--radius-card);
    background: var(--primary-pale);
    color: var(--primary-dark);
    font-size: 13px;
}

/* Published student results */

.info-panel p {
    margin: 0;
}

.info-panel .icon {
    margin-top: 1px;
}

/* Empty states */
.empty-state {
    padding: 48px 24px;
    background: var(--surface);
    border: 1px dashed #cfd8e6;
    border-radius: var(--radius-card);
    text-align: center;
}

.empty-state-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin-bottom: 14px;
    border-radius: 50%;
    background: var(--canvas);
    color: var(--text-secondary);
}

.empty-state h2 {
    margin: 0 0 6px;
    font-size: 18px;
    font-weight: 700;
}

.empty-state p {
    max-width: 460px;
    margin: 0 auto;
    color: var(--text-secondary);
    font-size: 14px;
}

.empty-state .btn {
    margin-top: 18px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 40px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    font-size: 13px;
    font-weight: 650;
    line-height: 1.3;
    text-align: center;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover {
    text-decoration: none;
}

.btn-primary,
.btn-primary-custom {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover,
.btn-primary-custom:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #fff;
}

.btn-secondary,
.btn-secondary-custom {
    background: var(--surface);
    border-color: #cbd7e8;
    color: var(--text);
}

.btn-secondary:hover,
.btn-secondary-custom:hover {
    background: var(--canvas);
    border-color: #b8c7dd;
    color: var(--text);
}

.btn-block {
    width: 100%;
}

/* Grade report */
.report-list {
    display: grid;
    gap: 16px;
}

.report-card {
    padding: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
}

.report-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.report-title {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.report-term {
    margin: 4px 0 0;
    color: var(--text-secondary);
    font-size: 13px;
}

.report-count {
    flex: 0 0 auto;
    padding: 4px 9px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--canvas);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.report-scores {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.score-block {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    background: #fbfcfe;
}

.score-label {
    margin: 0;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 650;
}

.score-value {
    margin: 4px 0 2px;
    color: var(--text);
    font-size: 26px;
    font-weight: 750;
    line-height: 1.2;
}

.score-detail {
    margin: 0;
    color: var(--text-secondary);
    font-size: 12px;
}

.report-back {
    margin-top: 24px;
}

/* CSV import screens (kept usable with the shared theme) */
.upload-card {
    max-width: 620px;
    padding: 28px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
}

.file-input-wrapper {
    position: relative;
    margin-bottom: 20px;
    padding: 40px 20px;
    border: 2px dashed #cfd8e6;
    border-radius: var(--radius-card);
    background: #fbfcfe;
    text-align: center;
}

.file-input-wrapper:hover {
    border-color: var(--primary);
}

.file-input-wrapper input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.file-input-label {
    color: var(--text-secondary);
    font-size: 14px;
}

.file-input-label p {
    margin: 0;
}

/* Authentication layout */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    background:
        radial-gradient(circle at 50% 0%, #eef3ff 0, rgba(238, 243, 255, 0) 340px),
        var(--canvas);
}

.auth-shell {
    width: 100%;
    max-width: 430px;
}

.auth-brand {
    margin-bottom: 20px;
    text-align: center;
}

.auth-brand .brand {
    margin: 0;
    color: var(--text);
    font-size: 23px;
    font-weight: 750;
    letter-spacing: -0.025em;
}

.auth-brand .brand:hover {
    text-decoration: none;
}

.auth-brand p {
    margin: 3px 0 0;
    color: var(--text-secondary);
    font-size: 12px;
}

.auth-card {
    padding: 30px 30px 26px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 10px 32px rgba(24, 36, 59, 0.07);
}

.auth-heading {
    margin-bottom: 22px;
}

.auth-heading h1 {
    margin: 0;
    color: var(--text);
    font-size: 22px;
    font-weight: 750;
    letter-spacing: -0.02em;
}

.auth-heading p {
    margin: 6px 0 0;
    color: var(--text-secondary);
    font-size: 13px;
}

.auth-form {
    display: grid;
    gap: 16px;
}

.field {
    display: grid;
    gap: 6px;
}

.field label {
    color: var(--text);
    font-size: 13px;
    font-weight: 650;
}

.field input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #cfd8e6;
    border-radius: var(--radius-control);
    background: #fff;
    color: var(--text);
    font-size: 15px;
}

.field input::placeholder {
    color: #9aa8bd;
}

.field input:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(39, 93, 222, 0.16);
    outline-offset: 0;
}

.field-hint {
    margin: 0;
    color: var(--text-secondary);
    font-size: 12px;
}

.auth-submit {
    margin-top: 2px;
}

.auth-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 18px;
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
    font-size: 13px;
}

.auth-links a {
    font-weight: 600;
}

.auth-notice {
    margin: 0 0 18px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    background: var(--canvas);
    color: var(--text-secondary);
    font-size: 13px;
}

.auth-footer {
    margin: 18px 0 0;
    color: var(--text-secondary);
    font-size: 11px;
    text-align: center;
}

/* Responsive navigation */
.sidebar-overlay {
    display: none;
}

@media (max-width: 900px) {
    .portal-sidebar {
        width: min(86vw, 280px);
        visibility: hidden;
        transform: translateX(-102%);
        transition: transform 0.2s ease, visibility 0s linear 0.2s;
        box-shadow: 0 20px 40px rgba(24, 36, 59, 0.16);
    }

    body.nav-open .portal-sidebar {
        visibility: visible;
        transition: transform 0.2s ease, visibility 0s;
    }

    .portal-main {
        margin-left: 0;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .sidebar-close {
        display: block;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 110;
        display: block;
        width: 100%;
        height: 100%;
        border: 0;
        background: rgba(24, 36, 59, 0.36);
    }

    .sidebar-overlay[hidden] {
        display: none;
    }

    body.nav-open {
        overflow: hidden;
    }

    body.nav-open .portal-sidebar {
        transform: translateX(0);
    }

    .portal-topbar {
        padding: 10px 16px;
    }

    .topbar-account {
        display: none;
    }

    .page-content {
        padding: 24px 18px 44px;
    }

    .page-title {
        font-size: 24px;
    }
}

@media (max-width: 560px) {
    .summary-strip {
        display: grid;
        gap: 12px;
        padding: 18px;
    }

    .summary-item {
        padding: 0;
        border-right: 0;
    }

    .course-card {
        align-items: stretch;
        flex-direction: column;
        gap: 14px;
        padding: 18px;
    }

    .course-action .btn {
        width: 100%;
    }

    .report-scores {
        grid-template-columns: 1fr;
    }

    .report-header {
        flex-direction: column;
        gap: 8px;
    }

    .auth-body {
        align-items: flex-start;
        padding: 26px 16px 40px;
    }

    .auth-card {
        padding: 24px 20px 22px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .portal-sidebar {
        transition: none;
    }
}

/* Exam problem source */
.exam-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--warning-pale);
    color: var(--warning);
    font-size: 12px;
    font-weight: 700;
}

.notebook {
    display: grid;
    gap: 16px;
}

.notebook-cell {
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
}

.notebook-cell-type {
    margin: 0;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--canvas);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.notebook-source {
    margin: 0;
    padding: 18px 20px;
    overflow-x: auto;
    color: var(--text);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 13px;
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.exam-actions {
    margin-top: 22px;
}

@media (max-width: 560px) {
    .notebook-source {
        padding: 14px;
        font-size: 12px;
    }
}

.result-heading {
    margin-bottom: 18px;
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface, #fff);
}

.result-table th,
.result-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border, #e3e8ef);
    text-align: left;
    vertical-align: top;
}

.result-table th {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.result-table .feedback-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Mobile: long headings wrap inside the card, adjacent course actions keep a gap. */
.page-title,
.course-title,
.student-dashboard__heading h1 {
    overflow-wrap: anywhere;
}

.course-action {
    flex-wrap: wrap;
    gap: 8px;
}
