.background-editor {
  display: grid;
  gap: 22px;
  margin-top: 24px;
}

.background-input-limit {
  margin: 0;
  color: var(--text);
  font-weight: 600;
}

.background-stage-wrap,
.background-controls {
  min-width: 0;
}

.background-stage-wrap h3,
.background-controls legend {
  margin: 0 0 8px;
  padding: 0;
  font-size: 1rem;
  font-weight: 700;
}

.background-controls {
  margin: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--soft);
}

.background-stage,
.background-result-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 220px;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
}

.background-stage canvas,
.background-result-stage canvas {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 520px;
}

.background-stage canvas {
  cursor: crosshair;
  touch-action: manipulation;
}

.background-marker {
  position: absolute;
  width: 12px;
  height: 12px;
  transform: translate(-50%, -50%);
  border: 2px solid #fff;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 0 0 1px #111827;
  pointer-events: none;
}

.background-marker::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 3px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #ef4444;
  content: "";
}

.background-selection-key {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.background-selection-key span {
  width: 16px;
  height: 16px;
  border: 1px solid #fca5a5;
  border-radius: 4px;
  background: #ef4444;
}

.background-controls .tool-field + .background-check {
  margin-top: 18px;
}

.background-controls input[type="range"] {
  width: 100%;
  accent-color: var(--brand);
}

.background-controls output {
  color: var(--brand);
  font-weight: 800;
}

.background-check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  cursor: pointer;
}

.background-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.background-check-note {
  margin: 6px 0 18px;
}

.background-control-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

.background-mode-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.background-mode-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
}

.background-mode-options label:has(input:checked) {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 10%, var(--bg));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 14%, transparent);
}

.background-mode-options label span {
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.background-coordinate-grid {
  margin-top: 18px;
}

.background-result-stage {
  margin-top: 12px;
}

.background-controls:disabled {
  opacity: 0.7;
}

.background-controls .tool-note {
  margin-top: 8px;
}

.background-selection-actions {
  margin-top: 14px;
}

@media (min-width: 768px) {
  .background-editor {
    grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.72fr);
    align-items: start;
  }

  .background-controls {
    margin-top: 32px;
  }
}

@media (max-width: 575px) {
  .background-mode-options {
    grid-template-columns: 1fr;
  }

  .background-stage,
  .background-result-stage {
    min-height: 180px;
  }
}
