/* Scoped display safety for user-authored question content only. */
.question-content-images img,
img.question-image {
    display: block;
    width: auto;
    height: auto;
    max-width: min(100%, 760px);
    max-height: 70vh;
    object-fit: contain;
    margin: 12px auto;
}

.question-content-images img.question-image--small,
img.question-image--small {
    max-width: min(100%, 360px);
}

.question-content-images img.question-image--medium,
img.question-image--medium {
    max-width: min(100%, 560px);
}

.question-content-images img.question-image--large,
img.question-image--large {
    max-width: min(100%, 760px);
}

.question-content-images img.question-image--auto,
img.question-image--auto {
    max-width: 100%;
}

.question-content-images img.question-image--smart,
img.question-image--smart {
    max-width: min(100%, 760px);
}

/* 编辑和导入预览允许“缩小/放大”按钮控制图片，且与题干文字左对齐。 */
.preview-box.question-content-images img,
.import-preview-content.question-content-images img {
    max-width: min(100%, calc(420px * var(--preview-image-scale, 1)));
    max-height: calc(220px * var(--preview-image-scale, 1));
    margin: 0.85rem 0;
    border-radius: 18px;
    padding: 0.35rem;
    background: rgba(255, 255, 255, 0.72);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.question-image-inspection-thumb {
    display: block;
    width: 96px;
    height: 72px;
    object-fit: contain;
    border-radius: 10px;
    background: rgba(148, 163, 184, 0.12);
}

/* Only diagrams without a saved per-image size get the compact default. */
.question-content-images img.question-image--smart {
    max-width: min(100%, var(--question-image-natural-width, 100%), calc(420px * var(--preview-image-scale, 1)));
    max-height: calc(220px * var(--preview-image-scale, 1));
    padding: 0;
    box-shadow: none;
}

.question-content-images img.question-image-layout--center { margin-left: auto; margin-right: auto; }
.question-content-images img.question-image-layout--align_right { margin-left: auto; margin-right: 0; }

.question-content-images[data-image-size="small"] img.question-image--small {
    max-width: min(100%, 240px);
    max-height: 220px;
}

.question-content-images[data-image-size="medium"] img.question-image--medium {
    max-width: min(100%, 420px);
    max-height: 320px;
}

.question-content-images[data-image-size="large"] img.question-image--large {
    max-width: min(100%, 640px);
    max-height: 480px;
}

/* A saved percentage is a ceiling, never an instruction to upscale the source. */
.question-content-images img.question-image[data-question-image-width] {
    max-width: min(100%, var(--question-image-natural-width, 100%), var(--question-image-manual-width));
}

.question-image-flow {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 36%);
    gap: 18px;
    align-items: start;
    margin: 0.6rem 0;
}

.question-image-flow > p, .question-image-flow > blockquote { min-width: 0; margin: 0; }
.question-image-flow > p img { margin: 0 auto; }
.question-image-parallel {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 12px;
    margin: 0.6rem 0;
}
.question-image-parallel > p { flex: 0 1 auto; min-width: 0; margin: 0; }
.question-image-parallel > p img { margin: 0; }
.question-content-images .katex-display {
    max-width: 100%; overflow-x: auto; margin: 0.35em 0; padding: 0;
}
.question-content-images p { margin-block: 0.4em; }
.question-content-images :is(h2, h3, h4) { margin-block: 0.6em 0.35em; }
.math-fallback { display: inline-block; max-width: 100%; color: #9f1239; overflow-wrap: anywhere; }
.math-fallback code { white-space: pre-wrap; }
.math-diagnostic { display: block; font-size: 11px; line-height: 1.4; color: #92400e; }
.math-repaired { display: inline-block; max-width: 100%; }

.question-image-settings {
    display: grid;
    gap: 0.45rem;
    width: 100%;
    padding: 0.5rem 0.875rem 0.65rem;
    border-bottom: 1px solid rgb(226 232 240);
    background: rgb(248 250 252 / 0.72);
    font-size: 0.75rem;
}
.question-image-settings-title { color: rgb(71 85 105); font-weight: 700; }
.question-image-setting-card { display: grid; gap: 0.3rem; }
.question-image-setting-card > strong { overflow: hidden; color: rgb(71 85 105); text-overflow: ellipsis; white-space: nowrap; }
.question-image-setting-fields { display: flex; flex-wrap: wrap; gap: 0.35rem 0.5rem; }
.question-image-setting-field { display: inline-flex; align-items: center; gap: 0.2rem; color: rgb(100 116 139); }
.question-image-setting-field input { width: 4.1rem; }

.question-image-lightbox {
    position: fixed;
    z-index: 10000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 2rem;
    background: rgb(15 23 42 / 0.82);
}
.question-image-lightbox img { max-width: min(96vw, 1400px); max-height: 88vh; object-fit: contain; }
.question-image-lightbox-close { position: absolute; top: 0.8rem; right: 0.8rem; padding: 0.4rem 0.7rem; color: white; background: rgb(15 23 42 / 0.85); border: 1px solid rgb(255 255 255 / 0.5); border-radius: 0.5rem; }

@media (max-width: 540px) {
    .question-image-flow { grid-template-columns: minmax(0, 1fr); }
    .question-image-parallel > p { flex-basis: 100%; }
}

@media print {
    .question-content-images img,
    img.question-image {
        max-width: 100%;
        max-height: 90mm;
        object-fit: contain;
        break-inside: avoid;
    }
    .question-content-images img[data-question-image-role="full_question"],
    .question-content-images img[data-question-image-role="table"] { max-height: 145mm; }
    .question-image-parallel { gap: 6mm; }
}
