html:has(.texture-dialog[open]) {
  overflow: hidden;
}

.texture-dialog {
  position: fixed;
  inset: 0;
  width: min(76rem, calc(100% - 3rem));
  height: min(56rem, calc(100% - 3rem));
  max-width: none;
  max-height: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  box-sizing: border-box;
  border: 1px solid #453e37;
  border-radius: 1rem;
  background: #242321;
  color: #f9f5ed;
  box-shadow: 0 1.25rem 5rem rgb(20 16 12 / 40%);
}

.texture-dialog::backdrop {
  background: rgb(25 21 17 / 72%);
}

.texture-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
}

.texture-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid #4c4640;
}

.texture-toolbar h2 {
  margin: 0;
  color: inherit;
  font: inherit;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.2;
}

.texture-controls {
  display: flex;
  flex: none;
  gap: 0.375rem;
}

.texture-controls button {
  display: grid;
  box-sizing: border-box;
  place-items: center;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.3rem;
  border: 1px solid #6c645a;
  border-radius: 0.45rem;
  background: #302d29;
  color: #f9f5ed;
  font: inherit;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.texture-controls button:hover {
  border-color: #d1c2af;
  background: #4b443a;
}

.texture-controls button:focus-visible,
.texture-stage:focus-visible {
  outline: 2px solid #fde0b7;
  outline-offset: -3px;
}

.texture-controls button[aria-disabled='true'] {
  opacity: 0.54;
  cursor: default;
}

.texture-controls button[data-texture='reset'] {
  min-width: 3.15rem;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.texture-controls button[data-texture='close'] {
  margin-left: 0.3rem;
  border-color: #f6efe3;
  background: #f6efe3;
  color: #211f1c;
}

.texture-controls button[data-texture='close']:focus-visible {
  outline-color: #211f1c;
}

.texture-stage {
  position: relative;
  min-height: 0;
  margin: 0.75rem 1rem 0;
  overflow: hidden;
  border-radius: 0.25rem;
  background: #1b1a18;
  cursor: zoom-in;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.texture-stage.is-zoomed {
  cursor: grab;
}

.texture-stage.is-zoomed.is-dragging {
  cursor: grabbing;
}

.texture-stage img {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  width: var(--texture-width, 100%);
  height: var(--texture-height, 100%);
  max-width: none;
  max-height: none;
  object-fit: contain;
  transform: translate(-50%, -50%) translate(var(--texture-x, 0), var(--texture-y, 0)) scale(var(--texture-scale, 1));
  pointer-events: none;
  -webkit-user-drag: none;
}

.texture-original,
.texture-stage.has-original .texture-preview {
  visibility: hidden;
}

.texture-stage.has-original .texture-original {
  visibility: visible;
}

.texture-status {
  position: absolute;
  left: 50%;
  bottom: 0.5rem;
  width: max-content;
  max-width: calc(100% - 1rem);
  margin: 0;
  padding: 0.45rem 0.65rem;
  box-sizing: border-box;
  transform: translateX(-50%);
  border-radius: 0.3rem;
  background: #242321;
  color: #f9f5ed;
  font-size: 0.875rem;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}

.texture-instructions {
  margin: 0;
  padding: 0.75rem 1rem 0.9rem;
  color: #ddd5c8;
  font-size: 0.875rem;
  line-height: 1.35;
  text-align: center;
}

.texture-touch-instructions {
  display: none;
}

.texture-lens-target {
  position: relative;
  overflow: hidden;
}

.texture-lens {
  display: none;
  position: absolute;
  z-index: 1;
  width: clamp(4.5rem, 8vw, 7rem);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 1px solid rgb(255 255 255 / 90%);
  border-radius: 50%;
  background-repeat: no-repeat;
  background-origin: padding-box;
  box-shadow: 0 0.2rem 1rem rgb(25 20 16 / 30%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease-out;
}

@media (any-hover: hover) and (any-pointer: fine) {
  .texture-lens {
    display: block;
  }

  .texture-lens.is-visible {
    opacity: 1;
  }
}

@media (max-width: 42rem), (pointer: coarse) and (max-height: 38rem) {
  .texture-dialog {
    width: 100%;
    height: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .texture-toolbar {
    padding-top: max(0.5rem, env(safe-area-inset-top));
    padding-right: max(0.5rem, env(safe-area-inset-right));
    padding-bottom: 0.5rem;
    padding-left: max(0.65rem, env(safe-area-inset-left));
  }

  .texture-stage {
    margin-top: 0.5rem;
    margin-right: max(0.4rem, env(safe-area-inset-right));
    margin-left: max(0.4rem, env(safe-area-inset-left));
  }

  .texture-instructions {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}

@media (hover: none), (pointer: coarse) {
  .texture-touch-instructions {
    display: inline;
  }

  .texture-desktop-instructions {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .texture-lens {
    transition: none;
  }
}
