dialog.ec-dialog {
  --ec-bg: var(--paper, var(--surface, #fffdfa));
  --ec-ink: var(--ink, var(--text, #47313d));
  --ec-muted: var(--muted, #6d6267);
  --ec-line: var(--line, #e6dce0);
  --ec-accent: var(--accent, #815166);
  --ec-preview-height: min(54vh, 520px);
  --ec-preview-height: min(54dvh, 520px);
  position: fixed;
  inset: 0;
  box-sizing: border-box;
  width: min(620px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--ec-line);
  border-radius: 16px;
  background: var(--ec-bg);
  color: var(--ec-ink);
  box-shadow: 0 16px 64px rgb(33 23 31 / 22%);
  font: inherit;
  text-align: start;
}

dialog.ec-dialog[open] { display: flex; flex-direction: column; }
dialog.ec-dialog::backdrop { background: rgb(33 23 31 / 55%); }

.ec-header, .ec-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: none;
  padding: 10px 14px;
}

.ec-header { border-bottom: 1px solid var(--ec-line); }
.ec-title { margin: 0; color: inherit; font: inherit; font-size: 17px; font-weight: 700; line-height: 1.4; }
.ec-main { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 10px 14px 12px; }
.ec-hint, .ec-status { margin: 0 0 9px; color: var(--ec-muted); font-size: 13px; line-height: 1.5; }
.ec-status { margin: 7px 0 0; }
.ec-status:empty { display: none; }

.ec-stage {
  display: grid;
  place-items: center;
  padding: 8px;
  overflow: hidden;
  border-radius: 10px;
  background: #262227;
}

.ec-stage[hidden] { display: none; }
.ec-picture {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(100%, calc(var(--ec-preview-height) * var(--ec-image-ratio)));
  aspect-ratio: var(--ec-image-ratio);
  min-width: 1px;
  min-height: 1px;
  background: #f6f3f4;
  user-select: none;
  -webkit-user-select: none;
}

.ec-image { position: absolute; inset: 0; display: block; width: 100%; height: 100%; pointer-events: none; }
.ec-frame {
  position: absolute;
  inset: 0;
  outline: 0;
  border: 1px solid #fff;
  box-shadow: 0 0 0 120vmax rgb(24 19 24 / 62%), inset 0 0 0 1px rgb(31 21 27 / 30%);
  touch-action: none;
  cursor: move;
}

.ec-frame:focus-visible { border: 2px solid #fff; }
.ec-frame, .ec-grip { -webkit-tap-highlight-color: transparent; }
.ec-dialog .ec-grip {
  position: absolute;
  box-sizing: border-box;
  width: min(32px, 45%);
  height: min(32px, 45%);
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.ec-grip::before {
  content: '';
  position: absolute;
  inset: 2px;
  width: 13px;
  height: 13px;
  border: solid #fff;
  border-width: 3px 0 0 3px;
  filter: drop-shadow(0 0 2px #29202a);
}

.ec-grip-nw { top: 0; left: 0; cursor: nwse-resize; }
.ec-grip-ne { top: 0; right: 0; cursor: nesw-resize; transform: rotate(90deg); }
.ec-grip-sw { bottom: 0; left: 0; cursor: nesw-resize; transform: rotate(270deg); }
.ec-grip-se { bottom: 0; right: 0; cursor: nwse-resize; transform: rotate(180deg); }
.ec-grip:focus-visible { outline: 2px solid #fff; outline-offset: -3px; }

.ec-footer { justify-content: flex-end; border-top: 1px solid var(--ec-line); }
.ec-dialog :is(.ec-reset, .ec-cancel, .ec-confirm) {
  min-height: 40px;
  min-width: 0;
  padding: 5px 13px;
  border: 1px solid var(--ec-line);
  border-radius: 8px;
  background: transparent;
  color: var(--ec-ink);
  font: inherit;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}

.ec-dialog .ec-reset { padding-inline: 8px; border-color: transparent; color: var(--ec-accent); }
.ec-dialog .ec-confirm { border-color: var(--ec-accent); background: var(--ec-accent); color: #fff; }
.ec-dialog :is(.ec-reset, .ec-cancel, .ec-confirm):disabled { opacity: .5; cursor: default; }
.ec-dialog :is(.ec-reset, .ec-cancel, .ec-confirm):focus-visible { outline: 2px solid var(--ec-accent); outline-offset: 2px; }

@media (max-height: 520px) {
  dialog.ec-dialog { --ec-preview-height: 49vh; --ec-preview-height: 49dvh; }
  .ec-header, .ec-footer { padding-block: 6px; }
}
