[data-background].nacre-bg-applied:not([data-background="hero"]) {
  position: relative;
  isolation: isolate;
  background-image: var(--nacre-bg-gradient, none);
}

[data-background].nacre-bg-applied:not([data-background="hero"])::before,
[data-background="hero"].nacre-bg-applied .hero-veil::after,
.nacre-bg-preview::before {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  background-image: var(--nacre-bg-texture, none);
  background-size: min(76%, 960px) auto;
  background-position: var(--nacre-bg-position, center);
  background-repeat: no-repeat;
  opacity: var(--nacre-bg-opacity, 0.24);
  filter: brightness(0.56);
}

[data-background].nacre-bg-applied:not([data-background="hero"])::before,
.nacre-bg-preview::before {
  z-index: -1;
}

[data-background][data-nacre-theme="light"]::before,
.nacre-bg-preview[data-nacre-theme="light"]::before {
  filter: contrast(0.55);
}

[data-background="hero"].nacre-bg-applied .hero-veil::before {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  background-image: var(--nacre-bg-gradient, none);
  opacity: var(--nacre-bg-hero-tint, 0);
}

[data-background="hero"].nacre-bg-applied .hero-veil::after {
  background-size: min(66%, 960px) auto;
}


.nacre-bg-editor {
  container: nacre-background-editor / inline-size;
  min-width: 0;
  color: #24211d;
}

.nacre-bg-editor [hidden] {
  display: none;
}

.nacre-bg-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "region" "preview" "settings" "actions";
  gap: 1.25rem;
  min-width: 0;
  margin: 0;
}

.nacre-bg-region {
  grid-area: region;
  width: min(100%, 22rem);
}

.nacre-bg-preview-pane {
  grid-area: preview;
  min-width: 0;
}

.nacre-bg-settings {
  grid-area: settings;
  display: grid;
  gap: 1.15rem;
  min-width: 0;
}

.nacre-bg-form-footer {
  grid-area: actions;
  display: grid;
  gap: 0.55rem;
  min-width: 0;
  padding-top: 1rem;
  border-top: 1px solid #d8d3ca;
}

.nacre-bg-editor label {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
  color: #49423b;
  font-size: 0.875rem;
  line-height: 1.4;
}

.nacre-bg-group {
  display: grid;
  gap: 0.85rem;
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.nacre-bg-editor .nacre-bg-group-title {
  margin: 0;
  padding: 0.75rem 0 0;
  border-top: 1px solid #d8d3ca;
  color: #26211d;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.4;
}

.nacre-bg-editor select {
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  border: 1px solid #c9c1b5;
  border-radius: 0;
  padding: 0.5rem 0.55rem;
  color: #24211c;
  background: #fffdfa;
  font-size: 1rem;
}

.nacre-bg-texture-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  align-items: end;
  min-width: 0;
}

.nacre-bg-color-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  gap: 0.7rem;
  min-width: 0;
}

.nacre-bg-color-stop {
  flex: 1 1 9.5rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.nacre-bg-color-stop legend {
  margin: 0 0 0.4rem;
  padding: 0;
  color: #49423b;
}

.nacre-bg-color-entry {
  display: grid;
  grid-template-columns: 2.75rem minmax(0, 1fr);
  align-items: center;
  gap: 0.35rem;
}

.nacre-bg-color-entry input[type="color"] {
  display: block;
  width: 100%;
  min-width: 0;
  height: 2.75rem;
  margin: 0;
  padding: 0.2rem;
  border: 1px solid #c9c1b5;
  border-radius: 0;
  background: #fffdfa;
  cursor: pointer;
}

.nacre-bg-color-entry .nacre-bg-color-code,
.nacre-bg-opacity-entry input {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  margin: 0;
  padding: 0.45rem 0.55rem;
  border: 1px solid #c9c1b5;
  border-radius: 0;
  background: #fffdfa;
  color: #24211c;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.nacre-bg-editor .nacre-bg-stop-opacity {
  grid-template-columns: minmax(0, 1fr) 4.75rem;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.nacre-bg-opacity-entry { position: relative; }
.nacre-bg-opacity-entry input { padding-inline-end: 1.65rem; }
.nacre-bg-opacity-entry input[type="number"] { appearance: textfield; }
.nacre-bg-opacity-entry input::-webkit-inner-spin-button,
.nacre-bg-opacity-entry input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.nacre-bg-opacity-entry > span {
  position: absolute;
  top: 50%;
  right: 0.55rem;
  transform: translateY(-50%);
  color: #635c52;
  pointer-events: none;
}

.nacre-bg-color-error {
  display: block;
  margin-top: 0.35rem;
  color: #932b25;
  font-size: 0.8125rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.nacre-bg-color-error:empty { display: none; }
.nacre-bg-color-controls input[aria-invalid="true"] { border-color: #932b25; }
.nacre-bg-direction { flex: 1 1 100%; }
.nacre-bg-direction select { max-width: 22rem; }

.nacre-bg-image-controls,
.nacre-bg-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.7rem;
  min-width: 0;
}

.nacre-bg-editor .nacre-bg-file-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid #c9c1b5;
  color: #24211c;
  background: #fffdfa;
  white-space: nowrap;
  cursor: pointer;
}

.nacre-bg-file-picker input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.nacre-bg-editor .nacre-bg-file-picker:hover {
  border-color: #9e9283;
  background: #efeae1;
}

.nacre-bg-formats {
  color: #635c52;
  font-size: 0.8125rem;
  line-height: 1.4;
}

.nacre-bg-texture-controls label:first-child {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.nacre-bg-texture-controls input {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  margin: 0;
  accent-color: #625143;
}

.nacre-bg-texture-controls output {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.nacre-bg-editor button {
  font-size: 0.875rem;
  line-height: 1.4;
}

.nacre-bg-link {
  min-height: 2.75rem;
  padding: 0.25rem 0.2rem;
  border: 0;
  background: transparent;
  color: #49423b;
  text-decoration: underline;
  text-underline-offset: 0.2rem;
  white-space: nowrap;
}

.nacre-bg-reset {
  min-height: 2.75rem;
  padding: 0.5rem 0.85rem;
  border: 1px solid #625143;
  white-space: nowrap;
  color: #3b3128;
  background: transparent;
}

.nacre-bg-reset:hover { background: #efeae1; }

.nacre-bg-editor :is(button, select, input):focus-visible,
.nacre-bg-file-picker:focus-within {
  outline: 2px solid #75604c;
  outline-offset: 2px;
}

.nacre-bg-status {
  min-height: 1.4em;
  margin: 0;
  color: #4c463d;
  font-size: 0.875rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.nacre-bg-status.error { color: #932b25; }
.nacre-bg-status:empty { display: none; }

.nacre-bg-preview-label {
  margin: 0 0 0.45rem;
  color: #49423b;
  font-size: 0.875rem;
  line-height: 1.4;
}

.nacre-bg-preview {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  min-height: 7.5rem;
  overflow: hidden;
  border: 1px solid #d8d3ca;
  padding: 0.8rem;
  background-color: #1b1814;
  background-image: var(--nacre-bg-gradient, none);
  color: #f4f1ea;
  font: 400 1.125rem/1.4 var(--serif, serif);
  text-align: center;
}

.nacre-bg-preview[data-nacre-theme="light"] { color: #29231f; }

.nacre-bg-preview[data-translucent="true"] {
  background-color: #ede8df;
  background-image: var(--nacre-bg-gradient, none),
    conic-gradient(#d9d0c2 25%, transparent 0 50%, #d9d0c2 0 75%, transparent 0);
  background-size: auto, 1.125rem 1.125rem;
}

.nacre-bg-preview[data-translucent="true"]:not([data-nacre-theme="light"]) > span {
  text-shadow: 0 1px 3px #201810a6, 0 0 7px #20181080;
}

@container nacre-background-editor (min-width: 43rem) {
  .nacre-bg-form {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    grid-template-areas: "region preview" "settings preview" "actions preview";
    column-gap: clamp(1.5rem, 4vw, 3rem);
  }

  .nacre-bg-preview-pane { align-self: start; }
  .nacre-bg-preview { min-height: 13rem; }
}

@media (max-width: 700px) {
  .nacre-bg-form { gap: 0.95rem; }
  .nacre-bg-region select { text-overflow: ellipsis; }
  .nacre-bg-preview { min-height: clamp(7.75rem, 34vw, 10rem); }
}
