#cropDialog {
  box-sizing: border-box; width: min(1120px, calc(100vw - 24px));
  height: min(880px, calc(100dvh - 24px)); max-width: none; max-height: none;
  margin: auto; padding: 0; border: 1px solid var(--border, #3c3c3c);
  border-radius: 16px; color: var(--text, #eee); background: var(--panel, #202020);
  font: inherit; overflow: hidden;
}
#cropDialog[open] { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }
#cropDialog::backdrop { background: rgba(0, 0, 0, .8); }
#cropDialog button, #cropDialog select { min-height: 44px; box-sizing: border-box; font: inherit; }
#cropDialog button:focus-visible, #cropDialog select:focus-visible, #cropFrame:focus-visible { outline: 2px solid var(--accent, #dda958); outline-offset: 3px; }
.crop-header, .crop-controls, .crop-footer { display: flex; align-items: center; gap: 12px; padding: 10px 20px; }
.crop-header { justify-content: space-between; border-bottom: 1px solid var(--border, #383838); }
.crop-header h2 { font-size: 16px; margin: 0; font-weight: 500; }
#cropClose { width: 44px; padding: 0; display: grid; place-items: center; }
.crop-controls { flex-wrap: wrap; }
.crop-controls label { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.crop-controls select { min-width: 120px; padding: 0 12px; color: inherit; background: var(--panel2, #292929); border: 1px solid var(--border, #444); border-radius: 8px; }
.crop-stage { display: flex; align-items: center; justify-content: center; min-height: 0; overflow: hidden; background: #101010; }
.crop-picture { position: relative; flex: none; }
.crop-picture > canvas { display: block; width: 100%; height: 100%; }
#cropFrame { position: absolute; box-sizing: border-box; border: 2px solid var(--accent, #dda958); box-shadow: 0 0 0 2000px rgba(0, 0, 0, .58); cursor: move; touch-action: none; }
#cropGuides { width: 100%; height: 100%; display: block; pointer-events: none; }
#cropDialog .crop-handle { position: absolute; width: 44px; height: 44px; min-width: 44px; padding: 0; background: transparent; border: none; border-radius: 0; box-shadow: none; touch-action: none; }
.crop-handle::before { content: ''; position: absolute; width: 12px; height: 12px; border: 3px solid #fff; background: var(--accent, #dda958); border-radius: 3px; left: 14px; top: 14px; }
.crop-handle[data-handle=nw] { left: -23px; top: -23px; cursor: nwse-resize; }
.crop-handle[data-handle=ne] { right: -23px; top: -23px; cursor: nesw-resize; }
.crop-handle[data-handle=sw] { left: -23px; bottom: -23px; cursor: nesw-resize; }
.crop-handle[data-handle=se] { right: -23px; bottom: -23px; cursor: nwse-resize; }
.crop-footer { flex-wrap: wrap; justify-content: space-between; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.crop-status { flex: 1; min-width: 160px; color: var(--muted, #aaa); font-size: 12px; line-height: 1.5; }
.crop-status p { margin: 0; }
.crop-actions { display: flex; gap: 8px; }
.crop-actions button { padding: 0 18px; }
@media (max-width: 600px) {
  #cropDialog { width: calc(100vw - 12px); height: calc(100dvh - 12px); border-radius: 12px; }
  .crop-header, .crop-controls, .crop-footer { padding-left: 12px; padding-right: 12px; }
  .crop-controls { gap: 8px; }
  .crop-controls label { flex: 1; min-width: 130px; flex-direction: column; align-items: stretch; gap: 4px; }
  .crop-footer { gap: 8px; }
  .crop-status { flex-basis: 100%; }
  .crop-actions { width: 100%; }
  .crop-actions button { flex: 1; padding: 0 8px; }
}
@media (max-height: 500px) {
  .crop-header, .crop-controls, .crop-footer { padding-top: 3px; padding-bottom: 3px; }
  .crop-header h2 { font-size: 14px; }
  .crop-status #cropHelp { display: none; }
}
@media (max-height: 500px) and (min-width: 600px) {
  #cropDialog[open] { grid-template-columns: minmax(0, 1fr) 240px; grid-template-rows: 50px minmax(0, 1fr) auto; }
  .crop-header { grid-column: 1 / -1; }
  .crop-stage { grid-column: 1; grid-row: 2 / 4; }
  .crop-controls { grid-column: 2; grid-row: 2; flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 8px; padding: 8px 12px; }
  .crop-controls label { justify-content: space-between; font-size: 12px; gap: 6px; }
  .crop-controls select { min-width: 0; width: 124px; padding: 0 6px; }
  .crop-footer { grid-column: 2; grid-row: 3; padding: 8px 12px; gap: 8px; }
  .crop-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; gap: 6px; }
  .crop-actions button { padding: 0 6px; }
  #cropApply { grid-column: 1 / -1; }
}
