:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --text: #202124;
    --muted: #6b7280;
    --line: #d9dee6;
    --accent: #648eb5;
    --accent-dark: #456b8f;
    --warn: #b45309;
    --bad: #b42318;
    --ok: #207044;
    --markdown-image-height: 240px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5;
}

a {
    color: var(--accent-dark);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 24px;
    justify-content: space-between;
    min-height: 58px;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    color: var(--text);
    font-size: 18px;
    font-weight: 700;
}

.nav {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.logout-form {
    margin: 0;
}

.logout-form button,
.button,
button {
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 6px;
    color: #ffffff;
    cursor: pointer;
    display: inline-block;
    font: inherit;
    min-height: 38px;
    padding: 8px 12px;
}

.button:hover,
button:hover {
    text-decoration: none;
}

.secondary-button {
    background: #ffffff;
    border-color: var(--accent);
    color: var(--accent-dark);
}

.danger-button {
    background: #b42318;
    border-color: #b42318;
    color: #ffffff;
}

.disabled-button {
    background: #eef1f5;
    border-color: var(--line);
    color: var(--muted);
    cursor: default;
}

.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.page {
    margin: 0 auto;
    max-width: 1180px;
    padding: 28px;
}

.narrow {
    margin: 48px auto;
    max-width: 520px;
}

.page-head,
.section-head {
    align-items: center;
    display: flex;
    gap: 18px;
    justify-content: space-between;
    margin-bottom: 18px;
}

.page-head h1,
.section-head h2 {
    margin: 0;
}

.page-head p {
    color: var(--muted);
    margin: 4px 0 0;
}

.actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.page-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.page-actions form {
    margin: 0;
}

.panel,
.form-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 18px;
    padding: 20px;
}

.stats-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 18px;
}

.workflow {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 18px;
}

.workflow-step {
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 10px;
    padding: 12px;
}

.workflow-step span {
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 999px;
    display: inline-flex;
    font-weight: 700;
    height: 28px;
    justify-content: center;
    width: 28px;
}

.workflow-step.active {
    background: var(--surface);
}

.workflow-step.active span {
    background: var(--accent);
    color: #ffffff;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.stat span {
    color: var(--muted);
    display: block;
    font-size: 14px;
}

.stat strong {
    display: block;
    font-size: 28px;
    margin-top: 4px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    border-collapse: collapse;
    min-width: 760px;
    width: 100%;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 10px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.muted {
    color: var(--muted);
}

.muted-panel {
    background: #ffffff;
}

.student-card-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.student-test-card,
.student-attempt-card,
.empty-card {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.student-card-head {
    align-items: flex-start;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 14px;
}

.student-card-head h3,
.student-attempt-card h3 {
    font-size: 18px;
    margin: 0;
}

.student-card-head p,
.student-attempt-card p {
    color: var(--muted);
    margin: 4px 0 0;
}

.status-pill {
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    flex: 0 0 auto;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    padding: 6px 9px;
    white-space: nowrap;
}

.status-pill.done {
    border-color: #b7dcc7;
    color: var(--ok);
}

.status-pill.pending {
    border-color: #fed7aa;
    color: var(--warn);
}

.status-pill.new {
    border-color: #bdd3e8;
    color: var(--accent-dark);
}

.status-pill.locked {
    border-color: var(--line);
    color: var(--muted);
}

.student-card-meta {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 0 0 16px;
}

.student-card-meta div {
    min-width: 0;
}

.student-card-meta dt {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 2px;
}

.student-card-meta dd {
    font-weight: 700;
    margin: 0;
}

.student-card-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.attempt-card-list {
    display: grid;
    gap: 10px;
}

.student-attempt-card {
    align-items: center;
    display: flex;
    gap: 14px;
    justify-content: space-between;
}

.attempt-result {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
    text-align: right;
}

.empty-cell {
    padding: 18px 10px;
}

.empty-cell strong {
    display: block;
    margin-bottom: 10px;
}

.answer-preview {
    color: var(--muted);
    max-width: 220px;
}

.messages {
    margin-bottom: 18px;
}

.message {
    background: #ffffff;
    border: 1px solid #cce8d5;
    border-radius: 6px;
    margin-bottom: 8px;
    padding: 10px 12px;
}

.message.error,
.message.warning {
    background: #ffffff;
    border-color: #fed7aa;
    color: var(--warn);
}

form p {
    margin: 0 0 14px;
}

label {
    display: block;
    font-weight: 700;
    margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
select,
textarea {
    background: #ebeff4;
    border: 1px solid #cfd6c8;
    border-radius: 6px;
    color: var(--text);
    font: inherit;
    font-size: 16px;
    max-width: 100%;
    padding: 9px 10px;
    width: 100%;
}

textarea {
    resize: vertical;
}

.helptext {
    color: var(--muted);
    display: block;
    font-size: 13px;
    margin-top: 4px;
}

.random-task-form {
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(130px, 0.35fr) repeat(2, minmax(220px, 1fr));
}

.random-task-form p {
    margin: 0;
}

.random-task-form button {
    align-self: end;
    justify-self: start;
}

.category-form {
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.2fr) minmax(260px, 1.2fr) minmax(90px, 0.3fr);
}

.category-form p {
    margin: 0;
}

.category-form button {
    align-self: end;
    justify-self: start;
}

.category-list {
    display: grid;
    gap: 10px;
}

.category-row {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 14px;
    justify-content: space-between;
    padding: 12px;
}

.category-row h3 {
    margin: 0 0 4px;
}

.category-row p {
    margin: 0;
}

.danger-zone {
    border-color: #f3b3ad;
}

.danger-zone h2 {
    color: #8a1f17;
}

.confirm-form {
    display: grid;
    gap: 10px;
    max-width: 520px;
}

.confirm-form button {
    justify-self: start;
}

.errorlist {
    color: var(--bad);
    margin: 0 0 8px;
    padding-left: 18px;
}

.form-actions,
.submit-row {
    align-items: center;
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.submit-row {
    justify-content: flex-end;
}

.submit-row.is-hidden {
    display: none;
}

.submit-row .primary {
    font-weight: 700;
    min-height: 46px;
    min-width: 180px;
}

.two-columns {
    display: grid;
    gap: 18px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wide-left {
    grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
}

.small-input {
    max-width: 90px;
}

.question-card,
.question-result {
    border-bottom: 1px solid var(--line);
    padding: 18px 0;
}

.question-card:first-child,
.question-result:first-child {
    padding-top: 0;
}

.question-card header,
.question-result header {
    align-items: center;
    display: flex;
    gap: 14px;
    justify-content: space-between;
}

.question-card h2,
.question-result h2,
.question-result h3 {
    font-size: 20px;
    margin: 0 0 10px;
}

.markdown {
    max-width: 760px;
}

.question-card .markdown,
.question-result .markdown {
    max-width: 100%;
}

.question-card .markdown > :not(:has(img)),
.question-result .markdown > :not(:has(img)) {
    max-width: 100%;
}

.question-card .markdown > :has(img),
.question-result .markdown > :has(img) {
    max-width: 100%;
}

.markdown img,
.zoomable-image {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: zoom-in;
    display: block;
    height: var(--markdown-image-height);
    margin: 12px 0;
    max-width: 100%;
    object-fit: contain;
    object-position: center;
    padding: 8px;
    width: 100%;
}

.markdown {
    overflow-wrap: break-word;
    overflow-x: auto;
}

.markdown .katex-display {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
}

.markdown .katex-display > .katex {
    display: inline-block;
    min-width: max-content;
}

.markdown table,
.question-card .markdown table,
.question-result .markdown table {
    border: 1px solid var(--line);
    border-collapse: collapse;
    display: table;
    margin: 14px auto;
    max-width: none;
    min-width: 0;
    table-layout: auto;
    width: max-content;
}

.markdown th,
.markdown td,
.question-card .markdown th,
.question-card .markdown td,
.question-result .markdown th,
.question-result .markdown td {
    border: 1px solid var(--line);
    min-width: 44px;
    padding: 8px 12px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

.markdown th,
.question-card .markdown th,
.question-result .markdown th {
    background: #f6f8fb;
    color: var(--text);
    font-size: inherit;
}

.markdown table + p {
    margin-top: 14px;
}

body.lightbox-open {
    overflow: hidden;
}

.image-lightbox[hidden] {
    display: none;
}

.image-lightbox {
    align-items: center;
    background: rgba(20, 25, 34, 0.88);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 28px;
    position: fixed;
    z-index: 1000;
}

.image-lightbox:not(.is-open) {
    display: none;
}

.image-lightbox img {
    background: #ffffff;
    border-radius: 6px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
    max-height: calc(100vh - 80px);
    max-width: calc(100vw - 48px);
    object-fit: contain;
}

.image-lightbox-close {
    align-items: center;
    background: #ffffff;
    border: 1px solid #ffffff;
    border-radius: 999px;
    color: var(--text);
    display: inline-flex;
    font-size: 30px;
    height: 44px;
    justify-content: center;
    line-height: 1;
    min-height: 44px;
    padding: 0;
    position: fixed;
    right: 18px;
    top: 18px;
    width: 44px;
}

.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
}

.attachments a {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 10px;
}

.field-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(var(--field-count, 1), minmax(0, 1fr));
    max-width: 100%;
    width: 100%;
}

.field-grid label,
.answer-field {
    margin: 0;
    min-width: 0;
    width: 100%;
}

.multi-field-rows {
    display: grid;
    gap: 12px;
    max-width: 100%;
    width: 100%;
}

.answer-block {
    margin-top: 18px;
}

.multi-answer-block {
    max-width: 100%;
    width: 100%;
}

.answer-block-title {
    font-size: 16px;
    line-height: 1.3;
    margin: 0 0 8px;
}

.answer-field .answer-input {
    width: 100%;
}

.answer-input {
    min-height: 46px;
}

.visually-hidden {
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    height: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    width: 1px;
}

.test-step-controls {
    align-items: center;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(160px, 1fr) auto minmax(160px, 1fr);
    margin: 18px 0;
}

.test-step-controls button {
    justify-self: stretch;
}

.test-step-counter {
    color: var(--muted);
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
}

.choice-list {
    display: grid;
    gap: 10px;
    max-width: 760px;
}

.choice-option {
    align-items: flex-start;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 6px;
    display: flex;
    gap: 10px;
    margin: 0;
    min-height: 52px;
    padding: 12px;
    touch-action: manipulation;
}

.choice-option input {
    flex: 0 0 auto;
    height: 20px;
    margin-top: 2px;
    width: 20px;
}

.choice-option span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.file-picker {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    font-weight: 400;
    gap: 10px;
    margin: 12px 0 8px;
    max-width: 760px;
    min-height: 52px;
    position: relative;
    touch-action: manipulation;
}

.file-picker input[type="file"] {
    cursor: pointer;
    height: 100%;
    inset: 0;
    opacity: 0;
    padding: 0;
    position: absolute;
    width: 100%;
}

.file-picker-button {
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 6px;
    color: #ffffff;
    display: inline-flex;
    min-height: 46px;
    padding: 10px 14px;
    text-align: center;
}

.file-picker-name {
    color: var(--muted);
    overflow-wrap: anywhere;
}

.preview-options {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.preview-options label {
    align-items: center;
    display: flex;
    gap: 6px;
    margin: 0;
}

.answer-box,
.criteria-box,
.hint-box,
.solution-box {
    border-top: 1px solid var(--line);
    margin-top: 14px;
    padding-top: 14px;
}

.hint-details {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 14px 0;
    max-width: 100%;
    padding: 0;
}

.hint-details summary {
    cursor: pointer;
    font-weight: 700;
    list-style-position: inside;
    min-height: 44px;
    padding: 10px 12px;
    touch-action: manipulation;
}

.hint-details .markdown {
    border-top: 1px solid var(--line);
    padding: 12px;
}

.task-links {
    overflow-wrap: anywhere;
}

.task-list .question-card:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.sticky-head {
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    margin: -28px -28px 20px;
    padding: 18px 28px;
    position: sticky;
    top: 58px;
    z-index: 5;
}

.timer,
.result-badge {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-weight: 700;
    padding: 10px 14px;
}

.result-badge span {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 400;
}

.result-details h2 {
    margin: 0 0 12px;
}

.result-summary-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.result-summary-item {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.result-summary-item span {
    color: var(--muted);
    display: block;
    font-size: 13px;
    margin-bottom: 4px;
}

.result-summary-item strong {
    display: block;
    font-size: 20px;
}

.answer-detail-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 14px 0;
    max-width: 900px;
}

.answer-detail-grid div {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    min-width: 0;
    padding: 12px;
}

.answer-detail-grid dt {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 4px;
}

.answer-detail-grid dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.teacher-feedback {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 12px 0;
    max-width: 760px;
    padding: 12px;
}

.teacher-feedback p {
    margin: 4px 0 0;
}

.status {
    border-radius: 999px;
    font-size: 13px;
    padding: 4px 9px;
}

.status.ok {
    background: #ffffff;
    color: var(--ok);
}

.status.bad {
    background: #ffffff;
    color: var(--bad);
}

.status.pending {
    background: #ffffff;
    color: var(--warn);
}

.manual-review-form {
    border-top: 1px solid var(--line);
    margin-top: 14px;
    max-width: 520px;
    padding-top: 14px;
}

.self-review-form {
    display: grid;
    gap: 16px;
}

.self-review-task {
    border-top: 1px solid var(--line);
    padding-top: 14px;
}

.notification-list {
    display: grid;
    gap: 10px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.notification-item {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 14px;
    justify-content: space-between;
    padding: 12px;
}

.notification-item.unread {
    border-left: 4px solid var(--accent);
}

.notification-item p {
    margin: 4px 0;
}

pre {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow-x: auto;
    padding: 10px;
}

code {
    background: #ffffff;
    border-radius: 4px;
    padding: 2px 4px;
}

@media (max-width: 760px) {
    :root {
        --markdown-image-height: 180px;
    }

    .topbar,
    .page-head,
    .section-head,
    .page-actions,
    .notification-item {
        align-items: flex-start;
        flex-direction: column;
    }

    .page {
        padding: 18px;
    }

    .test-form {
        display: grid;
        gap: 14px;
    }

    .question-card {
        border: 1px solid var(--line);
        border-radius: 8px;
        padding: 16px;
    }

    .question-result {
        border: 1px solid var(--line);
        border-radius: 8px;
        margin-bottom: 14px;
        padding: 16px;
    }

    .question-card:first-child {
        padding-top: 16px;
    }

    .question-result:first-child {
        padding-top: 16px;
    }

    .question-card header,
    .question-result header {
        align-items: flex-start;
        gap: 8px;
    }

    .question-card h2,
    .question-result h2,
    .question-result h3 {
        font-size: 19px;
        line-height: 1.25;
    }

    .question-card .markdown,
    .question-result .markdown,
    .choice-list,
    .field-grid,
    .file-picker {
        max-width: 100%;
    }

    .result-summary-grid,
    .answer-detail-grid {
        grid-template-columns: 1fr;
    }

    .markdown img,
    .zoomable-image {
        height: auto;
        max-height: 220px;
        min-height: 140px;
    }

    .choice-option {
        align-items: center;
        min-height: 56px;
        padding: 14px;
    }

    .test-step-controls {
        grid-template-columns: 1fr;
    }

    .test-step-counter {
        order: -1;
    }

    .field-grid {
        grid-template-columns: 1fr;
    }

    .field-grid label {
        width: 100%;
    }

    .file-picker {
        align-items: stretch;
        flex-direction: column;
    }

    .file-picker-button {
        align-items: center;
        justify-content: center;
        width: 100%;
    }

    .submit-row {
        background: #ffffff;
        border-top: 1px solid var(--line);
        bottom: 0;
        justify-content: stretch;
        margin: 4px -18px -18px;
        padding: 12px 18px;
        position: sticky;
        z-index: 4;
    }

    .submit-row .primary {
        min-height: 52px;
        width: 100%;
    }

    .stats-grid,
    .student-card-grid,
    .workflow,
    .category-form,
    .random-task-form,
    .two-columns,
    .wide-left {
        grid-template-columns: 1fr;
    }

    .category-row {
        align-items: stretch;
        flex-direction: column;
    }

    .random-task-form button {
        justify-self: stretch;
    }

    .student-card-head,
    .student-attempt-card,
    .attempt-result {
        align-items: stretch;
        flex-direction: column;
        text-align: left;
    }

    .student-card-meta {
        grid-template-columns: 1fr;
    }

    .student-card-actions,
    .student-card-actions .button,
    .attempt-result .button {
        width: 100%;
    }

    .student-card-actions .button,
    .attempt-result .button {
        text-align: center;
    }

    .sticky-head {
        margin: -18px -18px 4px;
        padding: 14px 18px;
        position: static;
    }
}
