.custom-avatar-editor[hidden] {
  display: none;
}

.custom-avatar-editor {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow: auto;
  background: rgba(2, 7, 14, 0.86);
  backdrop-filter: blur(8px);
}

.custom-avatar-editor-open {
  overflow: hidden;
}

.custom-avatar-editor__panel {
  width: min(94vw, 520px);
  padding: 18px;
  border: 1px solid rgba(217, 184, 129, 0.72);
  border-radius: 12px;
  background:
    radial-gradient(circle at 50% 0%, rgba(63, 94, 128, 0.2), transparent 48%),
    linear-gradient(155deg, rgba(13, 27, 43, 0.99), rgba(5, 13, 24, 0.995));
  box-shadow:
    inset 0 1px 0 rgba(255, 246, 211, 0.08),
    0 24px 70px rgba(0, 0, 0, 0.74),
    0 0 0 1px rgba(7, 14, 23, 0.9);
  color: #eee5cf;
  font-family: var(--font-ui, sans-serif);
}

.custom-avatar-editor__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.custom-avatar-editor__eyebrow {
  margin-bottom: 3px;
  color: #d9b881;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.custom-avatar-editor__header h2 {
  margin: 0;
  color: #fff2cf;
  font-family: var(--font-serif, serif);
  font-size: clamp(23px, 4vw, 29px);
  line-height: 1.1;
}

.custom-avatar-editor__help {
  max-width: 410px;
  margin: 6px 0 0;
  color: #aebdca;
  font-size: 13px;
  line-height: 1.45;
}

.custom-avatar-editor__close {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(217, 184, 129, 0.52);
  border-radius: 7px;
  background: rgba(6, 14, 24, 0.86);
  color: #eadbb8;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.custom-avatar-editor__workspace {
  display: grid;
  grid-template-columns: minmax(220px, 340px) 92px;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.custom-avatar-editor__preview-column {
  display: grid;
  min-width: 0;
  gap: 9px;
}

.custom-avatar-editor__viewport {
  position: relative;
  aspect-ratio: 4 / 3;
  width: 100%;
  max-width: 340px;
  overflow: hidden;
  border: 2px solid rgba(217, 184, 129, 0.88);
  border-radius: 10px;
  background: #07111d;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.8),
    0 10px 28px rgba(0, 0, 0, 0.48);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.custom-avatar-editor__viewport.is-dragging {
  cursor: grabbing;
}

.custom-avatar-editor__image {
  position: absolute;
  left: 50%;
  top: 50%;
  width: auto;
  max-width: none;
  height: auto;
  max-height: none;
  transform: translate(-50%, -50%);
  transform-origin: 50% 50%;
  pointer-events: none;
  will-change: left, top, transform;
}

.custom-avatar-editor__guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent 33.1%, rgba(255, 242, 207, 0.13) 33.3%, transparent 33.6%, transparent 66.3%, rgba(255, 242, 207, 0.13) 66.6%, transparent 66.9%),
    linear-gradient(0deg, transparent 33.1%, rgba(255, 242, 207, 0.13) 33.3%, transparent 33.6%, transparent 66.3%, rgba(255, 242, 207, 0.13) 66.6%, transparent 66.9%),
    linear-gradient(180deg, transparent 64%, rgba(4, 9, 17, 0.38));
}

.custom-avatar-editor__guide::after {
  content: "";
  position: absolute;
  inset: 0 12.5%;
  border-inline: 1px dashed rgba(189, 235, 240, 0.38);
  box-shadow:
    -42px 0 28px rgba(2, 7, 14, 0.14),
    42px 0 28px rgba(2, 7, 14, 0.14);
}

.custom-avatar-editor__zoom-controls {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 48px 38px;
  align-items: center;
  gap: 7px;
}

.custom-avatar-editor__zoom-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(94, 173, 196, 0.48);
  border-radius: 7px;
  background: linear-gradient(150deg, rgba(20, 54, 74, 0.94), rgba(7, 21, 35, 0.98));
  color: #bdebf0;
  font-size: 19px;
  font-weight: 900;
  cursor: pointer;
}

.custom-avatar-editor__zoom-slider {
  width: 100%;
  accent-color: #70d9bd;
  cursor: pointer;
}

.custom-avatar-editor__zoom-output {
  color: #d9b881;
  font-family: var(--font-mono, monospace);
  font-size: 10px;
  text-align: center;
}

.custom-avatar-editor__direction-controls {
  display: grid;
  grid-template: repeat(3, 42px) / repeat(3, 42px);
  place-content: center;
  gap: 4px;
}

.custom-avatar-editor__direction {
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(94, 173, 196, 0.54);
  border-radius: 7px;
  background: linear-gradient(150deg, rgba(20, 54, 74, 0.94), rgba(7, 21, 35, 0.98));
  color: #bdebf0;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
}

.custom-avatar-editor__direction--up {
  grid-area: 1 / 2;
}

.custom-avatar-editor__direction--left {
  grid-area: 2 / 1;
}

.custom-avatar-editor__position {
  grid-area: 2 / 2;
  display: grid;
  place-items: center;
  border: 1px solid rgba(217, 184, 129, 0.32);
  border-radius: 7px;
  color: #d9b881;
  font-family: var(--font-mono, monospace);
  font-size: 9px;
}

.custom-avatar-editor__direction--right {
  grid-area: 2 / 3;
}

.custom-avatar-editor__direction--down {
  grid-area: 3 / 2;
}

.custom-avatar-editor__close:hover,
.custom-avatar-editor__close:focus-visible,
.custom-avatar-editor__zoom-button:hover,
.custom-avatar-editor__zoom-button:focus-visible,
.custom-avatar-editor__direction:hover,
.custom-avatar-editor__direction:focus-visible,
.custom-avatar-editor__button:hover,
.custom-avatar-editor__button:focus-visible {
  border-color: #fff0bd;
  filter: brightness(1.15);
  outline: none;
}

.custom-avatar-editor__footer {
  display: grid;
  grid-template-columns: 1fr 1fr 1.35fr;
  gap: 8px;
  margin-top: 16px;
}

.custom-avatar-editor__button {
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid rgba(217, 184, 129, 0.48);
  border-radius: 7px;
  font-family: var(--font-ui, sans-serif);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.custom-avatar-editor__button--secondary {
  background: rgba(6, 15, 26, 0.92);
  color: #d8cfba;
}

.custom-avatar-editor__button--confirm {
  border-color: rgba(100, 225, 177, 0.8);
  background: linear-gradient(145deg, #8fe3c7, #4bbf9d);
  color: #071c18;
  box-shadow: 0 0 18px rgba(74, 203, 159, 0.22);
}

.custom-avatar-editor__panel[aria-busy="true"] {
  cursor: wait;
}

.custom-avatar-editor__button:disabled {
  cursor: wait;
  opacity: 0.58;
}

@media (max-width: 560px) {
  .custom-avatar-editor {
    align-items: start;
    padding: 10px;
  }

  .custom-avatar-editor__panel {
    width: min(100%, 440px);
    margin-block: 8px;
    padding: 14px;
  }

  .custom-avatar-editor__workspace {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .custom-avatar-editor__viewport {
    width: min(76vw, 300px);
    justify-self: center;
  }

  .custom-avatar-editor__zoom-controls {
    width: min(76vw, 300px);
    justify-self: center;
  }

  .custom-avatar-editor__direction-controls {
    grid-template: repeat(2, 38px) / repeat(4, 48px);
  }

  .custom-avatar-editor__direction--up {
    grid-area: 1 / 2;
  }

  .custom-avatar-editor__direction--left {
    grid-area: 2 / 1;
  }

  .custom-avatar-editor__position {
    grid-area: 2 / 2 / 3 / 4;
  }

  .custom-avatar-editor__direction--right {
    grid-area: 2 / 4;
  }

  .custom-avatar-editor__direction--down {
    grid-area: 1 / 3;
  }

  .custom-avatar-editor__footer {
    grid-template-columns: 1fr 1fr;
  }

  .custom-avatar-editor__button--confirm {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .custom-avatar-editor *,
  .custom-avatar-editor *::before,
  .custom-avatar-editor *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
