/* 试卷考试模式 */
:root {
    --pex-bg: #eef2f7;
    --pex-top: #1e293b;
    --pex-primary: #1677ff;
    --pex-done: #22c55e;
    --pex-line: #e5e7eb;
    --pex-text: #0f172a;
    --pex-muted: #64748b;
}

* { box-sizing: border-box; }

html, body.paper-exam-body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--pex-bg);
    color: var(--pex-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.pex-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-height: 100%;
    overflow: hidden;
}

.pex-top {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 56px;
    padding: 0 18px;
    background: var(--pex-top);
    color: #fff;
}

.pex-top-title {
    flex: 1;
    min-width: 0;
    font-size: 16px;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pex-top-timer {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
}

.pex-timer-label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
}

.pex-timer-value {
    font-size: 20px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.04em;
    color: #fff;
}

.pex-top-timer.is-warn .pex-timer-value { color: #fbbf24; }
.pex-top-timer.is-danger .pex-timer-value { color: #fb7185; }

.pex-top-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.pex-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 400;
    cursor: pointer;
    text-decoration: none;
}

.pex-btn-primary {
    background: var(--pex-primary);
    border-color: var(--pex-primary);
    color: #fff;
}

.pex-btn-primary:hover { filter: brightness(1.05); }

.pex-btn-ghost {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.28);
    color: #fff;
}

.pex-btn-ghost:hover { background: rgba(255, 255, 255, 0.08); }

.pex-btn-muted {
    background: #f1f5f9;
    border-color: #e2e8f0;
    color: #475569;
}

.pex-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
}

.pex-body.is-program-mode {
    display: block;
    position: relative;
}

.pex-body.is-program-mode .pex-sheet {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 220px;
    z-index: 2;
}

.pex-body.is-program-mode .pex-main {
    position: absolute;
    left: 220px;
    top: 0;
    bottom: 0;
    width: calc(42% - 92px);
    min-width: 280px;
    overflow: hidden;
    padding: 0;
    background: #fff;
    border-right: 1px solid var(--pex-line);
    display: flex;
    flex-direction: column;
    z-index: 1;
}

.pex-body.is-program-mode .pex-editor-pane {
    position: absolute !important;
    left: calc(42% + 128px);
    right: 0;
    top: 0;
    bottom: 0;
    width: auto !important;
    display: flex !important;
    background: #0b1220;
    z-index: 1;
}

.pex-sheet {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #fff;
    border-right: 1px solid var(--pex-line);
}

.pex-sheet-head {
    padding: 16px 16px 10px;
    border-bottom: 1px solid #f1f5f9;
}

.pex-sheet-head h2 {
    margin: 0 0 4px;
    font-size: 16px;
}

.pex-sheet-head p {
    margin: 0;
    font-size: 12px;
    color: #f59e0b;
}

.pex-sheet-scroll {
    flex: 1;
    overflow: auto;
    padding: 8px 12px 16px;
}

.pex-sheet-group {
    padding: 10px 0;
    border-bottom: 1px solid #f1f5f9;
}

.pex-sheet-group-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 4px;
    border: 0;
    background: transparent;
    cursor: pointer;
    text-align: left;
}

.pex-radio {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #cbd5e1;
    flex-shrink: 0;
}

.pex-sheet-group.is-active .pex-radio {
    border-color: var(--pex-primary);
    box-shadow: inset 0 0 0 3px var(--pex-primary);
}

.pex-sheet-group-title {
    flex: 1;
    font-size: 14px;
    font-weight: 650;
    color: var(--pex-text);
}

.pex-sheet-group-progress {
    font-size: 12px;
    color: var(--pex-muted);
}

.pex-sheet-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    padding: 8px 4px 4px;
    min-height: 40px;
}

.pex-sheet-no {
    height: 32px;
    border-radius: 6px;
    border: 1px solid #dbe3ee;
    background: #fff;
    color: #334155;
    font-size: 13px;
    font-weight: 400;
    cursor: pointer;
}

.pex-sheet-no:hover { border-color: #93c5fd; color: var(--pex-primary); }

.pex-sheet-no.is-active {
    border-color: var(--pex-primary);
    color: var(--pex-primary);
    box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.15);
}

.pex-sheet-no.is-done {
    background: var(--pex-done);
    border-color: var(--pex-done);
    color: #fff;
}

.pex-sheet-no.is-done.is-active {
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}

.pex-sheet-legend {
    display: flex;
    gap: 16px;
    padding: 12px 16px;
    border-top: 1px solid #f1f5f9;
    font-size: 12px;
    color: var(--pex-muted);
}

.pex-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-right: 6px;
    border-radius: 3px;
    vertical-align: -2px;
}

.pex-dot.is-todo {
    background: #fff;
    border: 1px solid #dbe3ee;
}

.pex-dot.is-done {
    background: var(--pex-done);
}

.pex-main {
    min-width: 0;
    min-height: 0;
    overflow: auto;
    padding: 16px 18px 12px;
    background: var(--pex-bg);
}

.pex-body.is-program-mode .pex-main {
    overflow: hidden;
    padding: 0;
    background: #fff;
    border-right: 1px solid var(--pex-line);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.pex-editor-pane {
    display: none;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    background: #0b1220;
    overflow: hidden;
    align-self: stretch;
}

.pex-body.is-program-mode .pex-editor-pane {
    display: flex !important;
}

.pex-editor-pane .sg-ch-workspace {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: 100% !important;
    border-radius: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
}

.pex-editor-pane .sg-ch-ed-body {
    flex: 1 1 auto !important;
    min-height: 0 !important;
}

html.pex-ed-focus .pex-top,
html.pex-ed-focus .pex-sheet,
html.pex-ed-focus .pex-main,
html.pex-ed-focus .pex-foot {
    display: none !important;
}

html.pex-ed-focus .pex-body,
html.pex-ed-focus .pex-body.is-program-mode {
    grid-template-columns: 1fr;
}

html.pex-ed-focus .pex-editor-pane {
    position: fixed;
    inset: 0;
    z-index: 80;
}

.pex-foot {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 10px 16px;
    background: #fff;
    border-top: 1px solid var(--pex-line);
}

.pex-section {
    margin-bottom: 18px;
    background: #fff;
    border: 1px solid var(--pex-line);
    border-radius: 12px;
    overflow: hidden;
}

.pex-section.is-hidden,
.pex-q.is-hidden {
    display: none !important;
}

.pex-section-bar {
    flex: 0 0 auto;
    padding: 10px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #eef2f7;
    font-size: 14px;
    font-weight: 650;
    color: #334155;
}

.pex-q {
    padding: 18px 18px 8px;
    border-top: 1px solid #f1f5f9;
}

.pex-q:first-of-type { border-top: none; }

.pex-body.is-program-mode .pex-section {
    margin: 0;
    border: 0;
    border-radius: 0;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
}

.pex-body.is-program-mode .pex-q {
    flex: 1 1 auto;
    min-height: 0;
    padding: 14px 16px 20px;
    border-top: none;
    overflow: auto;
    align-self: stretch;
}

.pex-q.is-current {
    background: linear-gradient(180deg, #f8fbff 0%, #fff 48px);
}

.pex-body.is-program-mode .pex-q.is-current {
    background: #fff;
}

.pex-q-layout {
    display: block;
}

.pex-q-title {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.pex-q-no {
    flex: 0 0 auto;
    font-weight: 450;
    line-height: 1.7;
}

.pex-q-stem {
    flex: 1;
    min-width: 0;
    line-height: 1.7;
    font-size: 15px;
}

.pex-q-stem > p {
    margin: 0 0 8px;
}

.pex-q-stem > p:last-child {
    margin-bottom: 0;
}

.pex-q-stem hr,
.pex-opt-body hr {
    display: none;
}

.pex-q-stem img,
.pex-opt-body img {
    max-width: 100%;
    height: auto;
}

.pex-q-stem pre,
.pex-q-stem code,
.ub-html pre,
.ub-html code {
    font-family: Consolas, "Courier New", monospace;
}

.pex-q-stem pre,
.ub-html pre {
    background: #f8fafc;
    border: 1px solid #eef2f7;
    border-radius: 8px;
    padding: 10px 12px;
    overflow: auto;
    margin: 8px 0;
}

.pex-q-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0 4px 22px;
    max-width: 760px;
}

.pex-opt {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid #e8edf3;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.pex-opt:hover {
    border-color: #bfdbfe;
    background: #f8fbff;
}

.pex-opt:has(input:checked) {
    border-color: #93c5fd;
    background: #eff6ff;
}

.pex-opt input {
    flex: 0 0 auto;
    margin: 0;
}

.pex-opt-key {
    flex: 0 0 auto;
    min-width: 1.1em;
    font-weight: 450;
    color: #475569;
    line-height: 1.5;
}

.pex-opt-body {
    flex: 1;
    min-width: 0;
    line-height: 1.55;
    font-size: 14px;
}

.pex-opt-body p {
    display: inline;
    margin: 0;
    padding: 0;
}

.pex-opt-body p + p {
    display: block;
    margin-top: 4px;
}

.pex-opt-body img {
    display: inline-block;
    vertical-align: middle;
}

.pex-fill {
    margin: 12px 0 8px 22px;
}

.pex-fill-input,
.pex-code,
.pex-io-input,
.pex-io-output {
    width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    resize: vertical;
    outline: none;
}

.pex-fill-input:focus,
.pex-code:focus,
.pex-io-input:focus {
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.12);
}

.pex-program-meta {
    display: none;
}

.pex-scratch-box {
    margin: 14px 0 8px 22px;
    padding: 14px 16px;
    border-radius: 10px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
}

.pex-scratch-tip {
    margin: 0 0 12px;
    font-size: 13px;
    line-height: 1.6;
    color: #9a3412;
}

.pex-scratch-mark.is-marked {
    opacity: 0.85;
}

.pex-modal[hidden] { display: none !important; }

.pex-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.42);
    /* 不用 backdrop-filter，避免编辑器页全屏重绘卡顿 */
    contain: layout paint;
}

.pex-modal-card {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 16px;
    padding: 24px 24px 20px;
    border: 1px solid #e8edf3;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    text-align: left;
    transform: translateZ(0);
}

.pex-modal-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    margin-bottom: 14px;
    display: grid;
    place-items: center;
    font-size: 22px;
    font-weight: 450;
    line-height: 1;
}

.pex-modal-icon.is-primary {
    background: #e8f3ff;
    color: #1677ff;
}

.pex-modal-icon.is-primary::before {
    content: "✓";
    font-size: 20px;
}

.pex-modal-icon.is-warn {
    background: #fff7ed;
    color: #d97706;
}

.pex-modal-icon.is-warn::before {
    content: "!";
}

.pex-modal-card h3 {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 750;
    color: var(--pex-text);
    letter-spacing: -0.02em;
}

.pex-modal-card p {
    margin: 0 0 20px;
    color: var(--pex-muted);
    line-height: 1.7;
    font-size: 14px;
}

.pex-modal-tip {
    margin: -8px 0 18px;
    padding: 12px 14px;
    border-radius: 10px;
    background: #f8fafc;
    border: 1px solid #e8edf3;
}

.pex-modal-tip p {
    margin: 0;
    font-size: 13px;
    line-height: 1.65;
    color: #475569;
}

.pex-modal-tip-link {
    display: inline-block;
    margin-top: 8px;
    font-size: 13px;
    font-weight: 650;
    color: #1677ff;
    text-decoration: none;
}

.pex-modal-tip-link:hover {
    text-decoration: underline;
}

.pex-modal-tip-link[hidden] {
    display: none !important;
}

.pex-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.pex-grading-card {
    text-align: center;
}

.pex-grading-bar {
    height: 6px;
    margin-top: 8px;
    border-radius: 999px;
    background: #e2e8f0;
    overflow: hidden;
}

.pex-grading-bar i {
    display: block;
    width: 40%;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #60a5fa, #1677ff);
    animation: pex-grading-slide 1.1s ease-in-out infinite;
    will-change: transform;
}

@keyframes pex-grading-slide {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(280%); }
}

@media (max-width: 900px) {
    .pex-body {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .pex-body.is-program-mode {
        display: flex;
        flex-direction: column;
        position: relative;
    }

    .pex-body.is-program-mode .pex-sheet,
    .pex-body.is-program-mode .pex-main,
    .pex-body.is-program-mode .pex-editor-pane {
        position: relative !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        bottom: auto !important;
        width: 100% !important;
    }

    .pex-body.is-program-mode .pex-sheet {
        max-height: 180px;
        border-right: 0;
        border-bottom: 1px solid var(--pex-line);
    }

    .pex-body.is-program-mode .pex-main {
        min-height: 200px;
        max-height: 34vh;
        border-right: 0;
        border-bottom: 1px solid var(--pex-line);
    }

    .pex-body.is-program-mode .pex-editor-pane {
        flex: 1 1 auto;
        min-height: 320px;
    }

    .pex-top {
        flex-wrap: wrap;
        padding: 10px 12px;
        gap: 10px;
    }

    .pex-top-title {
        width: 100%;
        white-space: normal;
    }
}
