.photo-edit {
  --photo-color: #ddd8ce;
  --photo-x: 50%;
  --photo-y: 35%;
  --photo-zoom: 1;
  display: grid;
  gap: 12px;
  min-width: 0;
  padding-bottom: 4px;
  color: var(--ink, #26231e);
}

.photo-edit [hidden] { display: none !important; }

.photo-edit .photo-edit-picker {
  position: relative;
  display: grid;
  min-height: 54px;
  gap: 3px;
  margin: 0;
  padding: 9px 12px;
  place-items: center;
  border: 1px dashed var(--border, #b9b1a4);
  border-radius: var(--radius, 10px);
  background: var(--panel, #fff);
  text-align: center;
  cursor: pointer;
}

.photo-edit .photo-edit-picker input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.photo-edit .photo-edit-picker:focus-within {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.photo-edit small,
.photo-edit .photo-edit-empty,
.photo-edit .photo-edit-message {
  color: var(--text-secondary, #605a51);
  font-size: .875rem;
}

.photo-edit .photo-edit-empty,
.photo-edit .photo-edit-message { margin: 0; }
.photo-edit .photo-edit-message.photo-edit-error { color: var(--error, #9d321f); }

.photo-edit :is(.photo-edit-work,.photo-edit-controls) { display: grid; gap: 12px; }
.photo-edit [data-photo-read-only] { margin: 0; color: var(--text-secondary); font-size: .875rem; }
body #dialog .photo-edit [data-remove-photo] { color: var(--error); padding-inline: 0; }
.photo-edit .photo-edit-stage[aria-disabled="true"] { cursor: default; touch-action: auto; }

.photo-edit .photo-edit-active {
  display: grid;
  place-items: center;
  min-height: clamp(140px, 26dvh, 240px);
  background: var(--panel-2, #f1ede6);
  border-radius: var(--radius, 10px);
}

.photo-edit .photo-edit-frame {
  position: relative;
  display: block;
  overflow: hidden;
  isolation: isolate;
  aspect-ratio: var(--photo-ratio);
  width: 100%;
  min-width: 0;
  border-radius: 6px;
  background: var(--photo-color);
}

.photo-edit .photo-edit-round { border-radius: 50%; }

.photo-edit .photo-edit-stage {
  width: min(100%, calc(clamp(140px, 26dvh, 240px) * var(--photo-ratio)));
  cursor: grab;
  touch-action: none;
}

.photo-edit .photo-edit-stage:active { cursor: grabbing; }
.photo-edit.photo-edit-contain .photo-edit-stage { cursor: initial; touch-action: auto; }

.photo-edit-avatar .photo-edit-active {
  min-height: 0;
  padding: 8px;
}
.photo-edit-avatar .photo-edit-stage {
  width: min(100%, clamp(120px, calc(var(--sheet-visual-height, 100dvh) * .38), 240px));
}
.photo-edit.photo-edit-avatar .photo-edit-stage:not([aria-disabled="true"]) { cursor: grab; touch-action: none; }
.photo-edit-avatar .photo-edit-stage:focus-visible {
  outline: 2px solid var(--accent-ink, #75510b);
  outline-offset: 3px;
}
.photo-edit-avatar .photo-edit-instructions {
  margin: 0;
  color: var(--text-secondary);
  text-align: center;
  font-size: .875rem;
}
@media (max-width: 760px) {
  body.tonmio-keyboard-open #dialog[open]:has([data-avatar-editor]) {
    --avatar-sheet-top: max(var(--sheet-keyboard-top), env(safe-area-inset-top));
    inset-block: var(--avatar-sheet-top) auto;
    margin-block: 0;
    height: calc(var(--sheet-visual-height) + var(--sheet-keyboard-top) - var(--avatar-sheet-top));
    max-height: none;
  }
  body.tonmio-keyboard-open #dialog:has([data-avatar-editor]) #dialog-footer:not([hidden]) {
    padding-bottom: var(--space-3, 12px);
  }
}

.photo-edit .photo-edit-frame img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  pointer-events: none;
  user-select: none;
}

.photo-edit .photo-edit-frame .photo-edit-image {
  object-fit: cover;
  object-position: var(--photo-x) var(--photo-y);
  transform-origin: var(--photo-x) var(--photo-y);
  transform: scale(var(--photo-zoom));
}

.photo-edit .photo-edit-frame .photo-edit-backdrop { display: none; }
.photo-edit.photo-edit-contain .photo-edit-frame .photo-edit-image {
  object-fit: contain;
  object-position: center;
  transform: none;
}
.photo-edit.photo-edit-contain .photo-edit-frame .photo-edit-backdrop {
  display: block;
  object-fit: cover;
  filter: blur(16px) brightness(.72);
  transform: scale(1.16);
}

.photo-edit .photo-edit-views {
  display: grid;
  align-items: stretch;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.photo-edit .photo-edit-views button {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  min-width: 0;
  min-height: 64px;
  gap: 5px;
  margin: 0;
  padding: 4px;
  border: 1px solid var(--border, #b9b1a4);
  border-radius: 8px;
  color: inherit;
  background: var(--panel, #fff);
  font: inherit;
  font-size: .6875rem;
  cursor: pointer;
}

.photo-edit .photo-edit-views button[aria-pressed='true'] {
  border-color: var(--hair);
  background: var(--gold-soft);
  box-shadow: none;
  font-weight: 700;
}

.photo-edit .photo-edit-sliders {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.photo-edit .photo-edit-sliders label,
.photo-edit .photo-edit-alt {
  display: block;
  margin: 0;
  color: var(--ink, #26231e);
  font-size: .8125rem;
}
.photo-edit .photo-edit-sliders input[type='range'] {
  display: block;
  width: 100%;
  height: 32px;
  min-height: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--ink, #26231e);
}
.photo-edit output { white-space: nowrap; }
.photo-edit .photo-edit-options {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.photo-edit .photo-edit-options label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  margin: 0;
  color: inherit;
}
.photo-edit .photo-edit-options input[type='checkbox'] {
  width: auto;
  min-height: auto;
  margin: 0;
  accent-color: var(--ink, #26231e);
}
.photo-edit .photo-edit-options button {
  min-height: 44px;
  padding-inline: 4px;
  border: 0;
  color: inherit;
  background: none;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.photo-edit .photo-edit-alt input {
  display: block;
  width: 100%;
  margin-top: 4px;
}
.photo-edit .photo-edit-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}
.photo-edit .photo-edit-actions button { min-height: 44px; }
.photo-edit .photo-edit-actions .primary {
  color: var(--on-accent, #241b06);
  background: var(--accent, #d1b66a);
}

.photo-edit .photo-edit-sliders label { white-space: nowrap; }
.photo-edit .photo-edit-camera {
  position: relative;
  display: grid;
  min-height: 44px;
  margin: 0;
  padding-inline: 12px;
  place-items: center;
  border: 1px solid var(--border, #b9b1a4);
  border-radius: var(--radius, 10px);
  background: var(--surface, #fff);
  color: var(--ink, #26231e);
  cursor: pointer;
}
.photo-edit .photo-edit-camera input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
}
.photo-edit .photo-edit-camera:focus-within { outline: 2px solid currentColor; }
