.image-crop-dialog {
    box-sizing: border-box;
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    margin: auto;
    padding: 0;
    overflow: auto;
    border: 1px solid var(--theme-border, var(--border-color));
    border-radius: 6px;
    background: var(--theme-surface, var(--body-bg));
    color: var(--theme-text, var(--body-fg));
    box-shadow: 0 14px 38px var(--theme-shadow, var(--body-quiet-color));
    font: inherit;
}

.image-crop-dialog::backdrop {
    background: var(--theme-overlay-strong, var(--darkened-bg));
}

.image-crop-panel {
    display: grid;
    gap: 12px;
    padding: 12px;
}

.image-crop-header h2,
.image-crop-header p,
.image-crop-instructions,
.image-crop-status {
    margin: 0;
}

.image-crop-header h2 {
    color: inherit;
    font-size: 1.1em;
    line-height: 1.3;
}

.image-crop-header p,
.image-crop-instructions,
.image-crop-status {
    color: var(--theme-text-secondary, var(--body-quiet-color));
    font-size: 0.85em;
    line-height: 1.5;
}

.image-crop-header p {
    margin-top: 4px;
}

.image-crop-stage {
    display: flex;
    position: relative;
    min-width: 0;
    min-height: 160px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid var(--theme-divider-standard, var(--hairline-color));
    background: var(--theme-media-bg, var(--darkened-bg));
}

.image-crop-stage.is-background-white,
.image-crop-stage.is-background-white video {
    background: #fff;
}

.image-crop-stage canvas {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: 54dvh;
    cursor: grab;
    touch-action: none;
}

.image-crop-stage canvas.is-dragging {
    cursor: grabbing;
}

.image-crop-stage video {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 54dvh;
    aspect-ratio: 16 / 9;
    background: #000;
    object-fit: cover;
}

.image-crop-stage video.is-contain {
    object-fit: contain;
}

.image-crop-video-position-handle {
    position: absolute;
    z-index: 1;
    inset: 0;
    cursor: ns-resize;
    touch-action: none;
}

.image-crop-video-position-handle.is-dragging {
    cursor: grabbing;
}

.image-crop-stage :is(
    canvas,
    video,
    .image-crop-video-position-handle,
    .image-crop-video-unavailable
)[hidden],
.image-crop-video-playback[hidden],
.image-crop-zoom-row[hidden] {
    display: none;
}

.image-crop-video-playback {
    display: flex;
    justify-content: flex-start;
}

.image-crop-video-playback button {
    box-sizing: border-box;
    min-height: 26px;
    padding: 3px 6px;
    border: 0;
    background: transparent;
    color: var(--theme-text, var(--body-fg));
    font: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.image-crop-video-playback button:hover {
    color: var(--theme-link-hover, var(--link-hover-color));
}

.image-crop-video-unavailable {
    box-sizing: border-box;
    width: 100%;
    min-height: 180px;
    margin: 0;
    padding: 12px;
    align-content: center;
    color: var(--theme-text-secondary, var(--body-quiet-color));
    font-size: 0.85em;
    line-height: 1.5;
    text-align: center;
}

.image-crop-stage canvas:focus-visible,
.image-crop-stage video:focus-visible,
.image-crop-video-position-handle:focus-visible,
.image-crop-dialog :is(input, button):focus-visible {
    outline: 2px solid var(--theme-focus-ring, var(--primary));
    outline-offset: 2px;
}

.image-crop-zoom-row {
    display: grid;
    grid-template-columns: max-content minmax(80px, 1fr) 44px;
    gap: 8px;
    align-items: center;
}

.image-crop-zoom-row input {
    width: 100%;
    margin: 0;
    accent-color: var(--theme-primary-action, var(--primary));
}

.image-crop-zoom-row output {
    color: var(--theme-text-secondary, var(--body-quiet-color));
    font-size: 0.85em;
    text-align: right;
}

.image-crop-status {
    min-height: 1.5em;
}

.image-crop-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.image-crop-actions button {
    box-sizing: border-box;
    min-height: 26px;
    margin: 0;
    padding: 3px 6px;
    border: 1px solid var(--theme-border, var(--border-color));
    border-radius: 4px;
    background: var(--theme-control-bg, var(--body-bg));
    color: var(--theme-text, var(--body-fg));
    font: inherit;
    cursor: pointer;
}

.image-crop-actions button:hover {
    background: var(--theme-control-hover, var(--darkened-bg));
}

.image-crop-actions .image-crop-apply {
    border-color: var(--theme-primary-action, var(--primary));
    background: var(--theme-primary-action, var(--primary));
    color: var(--theme-primary-action-text, var(--button-fg));
}

.image-crop-actions .image-crop-apply:hover {
    background: var(--theme-primary-action-hover, var(--secondary));
}

.image-crop-actions button:disabled {
    cursor: wait;
    opacity: 0.6;
}

.image-crop-feedback {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    color: var(--theme-text-secondary, var(--body-quiet-color));
    font-size: 0.85em;
    line-height: 1.4;
}

.image-crop-feedback.is-error {
    color: var(--theme-error-text, var(--error-fg));
}

.image-crop-feedback-preview {
    display: block;
    width: 64px;
    height: 64px;
    flex: 0 0 auto;
    border: 1px solid var(--theme-border-soft, var(--hairline-color));
    border-radius: 4px;
    object-fit: cover;
}

.image-crop-feedback-preview.is-contain {
    object-fit: contain;
    background: #000;
}

.image-crop-feedback-preview.is-contain.is-background-white {
    background: #fff;
}

.image-crop-feedback-preview.is-video {
    width: 112px;
    height: 63px;
}

@media (max-width: 600px) {
    .image-crop-dialog {
        width: calc(100vw - 24px);
        max-height: calc(100dvh - 24px);
    }

    .image-crop-stage :is(canvas, video) {
        max-height: 48dvh;
    }

    .image-crop-instructions {
        font-size: 0.8em;
    }
}

@media (prefers-reduced-motion: reduce) {
    .image-crop-dialog {
        scroll-behavior: auto;
    }
}
