.product-custom-image {
  display: grid;
  grid-template-rows: 0fr;
  min-width: 0;
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  transition:
    grid-template-rows 200ms ease,
    opacity 200ms ease,
    visibility 0s linear 200ms;
}

.product-custom-image[data-active="true"] {
  grid-template-rows: 1fr;
  visibility: visible;
  opacity: 1;
  transition-delay: 0s;
}

.product-custom-image__inner {
  min-height: 0;
  overflow: hidden;
  padding-block-start: 18px;
}

.product-custom-image__header {
  margin-block-end: 14px;
}

.product-custom-image__title,
.product-custom-image__intro,
.product-custom-image__help,
.product-custom-image__filename,
.product-custom-image__status,
.product-custom-image__dialog-title,
.product-custom-image__dialog-help,
.product-custom-image__dialog-error,
.product-custom-image__upload-error {
  margin: 0;
}

.product-custom-image__intro,
.product-custom-image__help,
.product-custom-image__status,
.product-custom-image__dialog-help {
  color: rgba(var(--color-text), 0.68);
}

.product-custom-image__intro {
  margin-block-start: 4px;
}

.product-custom-image__fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.product-custom-image__field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
}

.product-custom-image__input-shell,
.product-custom-image__dialog-input-shell {
  display: flex;
  min-width: 0;
  align-items: center;
  color: rgb(var(--color-text));
  background: rgb(var(--color-background));
  border: 1px solid rgba(var(--color-text), 0.24);
  border-radius: var(--variant-selector-border-radius, 0);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.product-custom-image__input-shell:focus-within,
.product-custom-image__dialog-input-shell:focus-within {
  border-color: rgb(var(--color-text));
  box-shadow: 0 0 0 1px rgb(var(--color-text));
}

.product-custom-image__field[data-invalid="true"] .product-custom-image__input-shell {
  border-color: rgb(var(--color-tag-background));
  box-shadow: 0 0 0 1px rgb(var(--color-tag-background));
}

.product-custom-image__input,
.product-custom-image__dialog-input-shell input {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  color: inherit;
  appearance: textfield;
  background: transparent;
  border: 0;
  outline: 0;
}

.product-custom-image__input::-webkit-inner-spin-button,
.product-custom-image__input::-webkit-outer-spin-button,
.product-custom-image__dialog-input-shell input::-webkit-inner-spin-button,
.product-custom-image__dialog-input-shell input::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
}

.product-custom-image__unit,
.product-custom-image__dialog-input-shell span {
  flex: 0 0 auto;
  padding-inline: 10px 12px;
  color: rgba(var(--color-text), 0.62);
  border-inline-start: 1px solid rgba(var(--color-text), 0.16);
}

.product-custom-image__error {
  display: none;
  color: rgb(var(--color-tag-background));
}

.product-custom-image__field[data-invalid="true"] .product-custom-image__error {
  display: block;
}

.product-custom-image__upload {
  margin-block-start: 14px;
  padding: 16px;
  border: 1px dashed rgba(var(--color-text), 0.3);
  border-radius: 8px;
  background: rgba(var(--color-text), 0.025);
}

.product-custom-image__file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.product-custom-image__empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.product-custom-image__select-button,
.product-custom-image__button {
  min-height: 44px;
  color: rgb(var(--color-text));
  background: rgb(var(--color-background));
  border: 1px solid rgb(var(--color-text));
  cursor: pointer;
}

.product-custom-image__select-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 16px;
}

.product-custom-image__select-icon {
  font-size: 22px;
  line-height: 1;
}

.product-custom-image__preview {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.product-custom-image__preview[hidden],
.product-custom-image__modal[hidden] {
  display: none !important;
}

.product-custom-image__preview-image {
  width: 92px;
  height: 92px;
  object-fit: cover;
  background: rgba(var(--color-text), 0.06);
  border: 1px solid rgba(var(--color-text), 0.12);
}

.product-custom-image__preview-copy {
  min-width: 0;
}

.product-custom-image__filename {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-custom-image__status {
  margin-block-start: 3px;
}

.product-custom-image__preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-block-start: 10px;
}

.product-custom-image__text-button {
  padding: 0;
  color: rgb(var(--color-text));
  text-decoration: underline;
  text-underline-offset: 3px;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.product-custom-image__upload-error,
.product-custom-image__dialog-error {
  min-height: 1.3em;
  margin-block-start: 8px;
  color: rgb(var(--color-tag-background));
}

.product-custom-image__modal {
  --product-custom-image-mobile-top-gap: max(48px, env(safe-area-inset-top));

  position: fixed;
  z-index: 10001;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}

.product-custom-image__modal[data-modal-state="closing"] {
  pointer-events: none;
}

.product-custom-image__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  will-change: opacity;
}

.product-custom-image__dialog {
  position: relative;
  display: flex;
  width: min(920px, 100%);
  max-height: calc(100vh - 48px);
  flex-direction: column;
  padding: 24px;
  overflow: auto;
  color: rgb(var(--color-text));
  background: rgb(var(--color-background));
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  will-change: opacity, transform;
}

.product-custom-image__dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.product-custom-image__dialog-help {
  margin-block-start: 4px;
}

.product-custom-image__close {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  font-size: 30px;
  line-height: 1;
  color: rgb(var(--color-text));
  background: transparent;
  border: 0;
  cursor: pointer;
}

.product-custom-image__dialog-size-fields {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 10px;
  margin-block: 18px 14px;
}

.product-custom-image__dialog-size-field {
  display: flex;
  width: min(180px, 42%);
  min-width: 0;
  flex-direction: column;
  flex: 0 1 180px;
  gap: 5px;
}

.product-custom-image__ratio-mark {
  padding-block-end: 12px;
  color: rgba(var(--color-text), 0.62);
}

.product-custom-image__workspace {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 300px;
  height: min(52vh, 480px);
  place-items: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background-color: #171717;
  background-image:
    linear-gradient(45deg, #222 25%, transparent 25%),
    linear-gradient(-45deg, #222 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #222 75%),
    linear-gradient(-45deg, transparent 75%, #222 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.product-custom-image__image-stage {
  position: relative;
  overflow: hidden;
  touch-action: none;
  background: #111;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.product-custom-image__crop-image {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  pointer-events: none;
  user-select: none;
  object-fit: contain;
}

.product-custom-image__frame {
  position: absolute;
  z-index: 1;
  touch-action: none;
  cursor: grab;
  background: transparent;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.52);
}

.product-custom-image__frame[data-dragging="true"] {
  cursor: grabbing;
}

.product-custom-image__frame:focus-visible {
  outline: 2px solid rgb(var(--color-background));
  outline-offset: 3px;
}

.product-custom-image__frame-label {
  position: absolute;
  z-index: 3;
  top: -6px;
  left: 50%;
  padding: 3px 7px;
  color: #fff;
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.76);
  border-radius: 2px;
  pointer-events: none;
  transform: translate(-50%, -100%);
}

.product-custom-image__frame[data-label-inside="true"] .product-custom-image__frame-label {
  top: 6px;
  transform: translateX(-50%);
}

.product-custom-image__grid {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, transparent 33.1%, rgba(255, 255, 255, 0.48) 33.3%, rgba(255, 255, 255, 0.48) 33.7%, transparent 33.9%, transparent 66.1%, rgba(255, 255, 255, 0.48) 66.3%, rgba(255, 255, 255, 0.48) 66.7%, transparent 66.9%),
    linear-gradient(to bottom, transparent 33.1%, rgba(255, 255, 255, 0.48) 33.3%, rgba(255, 255, 255, 0.48) 33.7%, transparent 33.9%, transparent 66.1%, rgba(255, 255, 255, 0.48) 66.3%, rgba(255, 255, 255, 0.48) 66.7%, transparent 66.9%);
}

.product-custom-image__dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-block-start: 10px;
}

.product-custom-image__button {
  min-width: 128px;
  padding: 10px 18px;
}

.product-custom-image__button--primary {
  color: rgb(var(--color-background));
  background: rgb(var(--color-text));
}

.product-custom-image__button[disabled] {
  cursor: wait;
  opacity: 0.6;
}

.pay-button-buy-now.custom-image-buy-now-hidden {
  display: none !important;
}

.product-custom-image-app-bridge-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
  pointer-events: none !important;
}

body.custom-image-modal-open {
  overflow: hidden;
}

@media (max-width: 749px) {
  .product-custom-image__modal {
    padding: var(--product-custom-image-mobile-top-gap) 0 0;
    place-items: end stretch;
  }

  .product-custom-image__dialog {
    width: 100%;
    max-height: calc(100dvh - var(--product-custom-image-mobile-top-gap));
    min-height: calc(100dvh - var(--product-custom-image-mobile-top-gap));
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    border-radius: 14px 14px 0 0;
  }

  .product-custom-image__dialog-size-fields {
    gap: 6px;
  }

  .product-custom-image__workspace {
    min-height: 260px;
    height: min(48dvh, 420px);
  }

  .product-custom-image__dialog-actions {
    margin-block-start: auto;
  }

  .product-custom-image__button {
    flex: 1 1 0;
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .product-custom-image,
  .product-custom-image__input-shell,
  .product-custom-image__dialog-input-shell {
    transition: none;
  }

  .product-custom-image__backdrop,
  .product-custom-image__dialog {
    will-change: auto;
  }
}
