/* BgRemove — background-remover widget + content polish.
   Theme colors come from site.config.json (--primary emerald / --accent pink). */

.bg {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.25rem;
  margin: 1.4rem 0 2rem;
}

/* ---- dropzone ---- */

.bg-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  text-align: center;
  padding: 2rem 1.25rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.bg-drop strong {
  font-size: 1.1rem;
}
.bg-drop span {
  font-size: 0.92rem;
  color: var(--text-dim);
}
.bg-drop u {
  color: var(--primary);
  text-decoration: none;
  font-weight: 650;
}
.bg-drop:hover,
.bg-drop:focus-visible,
.bg-drop-hot {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 6%, var(--bg));
  outline: none;
}
.bg-drop-hot {
  transform: scale(1.005);
}

/* ---- editor stage ---- */

.bg-work:not([hidden]) {
  margin-top: 1rem;
}
.bg-stage {
  position: relative;
  height: min(62vh, 34rem);
  min-height: 20rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background:
    repeating-conic-gradient(#d8dce6 0% 25%, #f4f6fa 0% 50%) 0 0 / 18px 18px;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
}
.bg-stack {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}
.bg-canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.bg-c-res {
  /* transparency shows through to the stage checkerboard */
  background: transparent;
}
.bg-c-orig {
  background: transparent;
}
.bg-split {
  position: absolute;
  width: 2px;
  background: var(--accent);
  cursor: ew-resize;
  z-index: 3;
}
.bg-split::before {
  content: '◂ ▸';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--accent);
  color: #fff;
  font-size: 0.62rem;
  line-height: 1;
  padding: 0.35rem 0.4rem;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.bg-split::after {
  /* widen the hit area to ~28px */
  content: '';
  position: absolute;
  inset: 0 -13px;
}
.bg-pick {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid #fff;
  outline: 2px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
}

/* ---- stage toolbar ---- */

.bg-tools {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-top: 0.6rem;
}
.bg-zoom {
  display: inline-flex;
  gap: 0.3rem;
}
.bg-zoom button {
  font: inherit;
  font-weight: 650;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 0.6);
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  min-width: 2.2rem;
}
.bg-zoom button:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.bg-compare-toggle[aria-pressed='true'] {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.bg-hint {
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* ---- options grid ---- */

.bg-opts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 0.7rem;
  margin-top: 0.8rem;
}
/* :not([hidden]) — mode fields toggle via the hidden attribute (P015). */
.bg-opts label:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
}
.bg-opts select {
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 0.6);
  padding: 0.45rem 0.55rem;
}
.bg-opts select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.bg-opts input[type='range'] {
  accent-color: var(--primary);
  margin-top: 0.5rem;
}
.bg-opts input[type='color'] {
  width: 100%;
  height: 2.2rem;
  padding: 0.15rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 0.6);
  background: var(--bg);
  cursor: pointer;
}
.bg-opts .bg-f-all {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  align-self: end;
  padding-bottom: 0.55rem;
}
.bg-opts .bg-f-all input {
  accent-color: var(--primary);
  width: 1.05rem;
  height: 1.05rem;
}

/* ---- action bar (AI + reset) ---- */

.bg-bar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
  margin-top: 0.9rem;
}
.bg-bar button {
  font: inherit;
  font-weight: 650;
  border: none;
  border-radius: calc(var(--radius) * 0.6);
  padding: 0.5rem 1rem;
  cursor: pointer;
}
.bg-ai {
  color: #fff;
  background: var(--accent);
}
.bg-ai:hover {
  filter: brightness(1.08);
}
.bg-reset {
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border) !important;
}
.bg-ainote {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ---- status + result list ---- */

.bg-status {
  min-height: 1.2rem;
  margin-top: 0.9rem;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.bg-list {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-top: 0.4rem;
}

.bg-item {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem;
  background: var(--bg);
  cursor: pointer;
}
.bg-item[data-state='working'] {
  opacity: 0.65;
}
.bg-item[data-active] {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.bg-item[data-state='error'] {
  border-color: color-mix(in srgb, #dc2626 55%, var(--border));
  cursor: default;
}
.bg-cell {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}
.bg-thumb {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: calc(var(--radius) * 0.5);
  border: 1px solid var(--border);
  background:
    repeating-conic-gradient(#e5e7eb 0% 25%, #f8fafc 0% 50%) 0 0 / 16px 16px;
  flex: none;
}
.bg-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.bg-meta b {
  font-size: 0.95rem;
}
.bg-meta i {
  font-style: normal;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.bg-arrow {
  font-size: 1.3rem;
  color: var(--primary);
  font-weight: 700;
}
.bg-dl {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.85rem;
  font-weight: 650;
  color: #fff;
  background: var(--primary);
  border-radius: calc(var(--radius) * 0.6);
  padding: 0.4rem 0.8rem;
  text-decoration: none;
  align-self: flex-start;
}
.bg-dl:hover {
  filter: brightness(1.08);
}
.bg-line {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.bg-item[data-state='done'] .bg-note {
  color: var(--primary);
}
.bg-err {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.85rem;
  color: #dc2626;
}

/* ---- footer actions ---- */

.bg-foot:not([hidden]) {
  display: flex;
  gap: 0.7rem;
  margin-top: 1rem;
}
.bg-foot button {
  font: inherit;
  font-weight: 650;
  border: none;
  border-radius: calc(var(--radius) * 0.6);
  padding: 0.5rem 1rem;
  cursor: pointer;
}
.bg-all {
  color: #fff;
  background: var(--primary);
}
.bg-all:hover {
  filter: brightness(1.08);
}
.bg-clear {
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border) !important;
}

@media (max-width: 540px) {
  .bg {
    padding: 0.9rem;
  }
  .bg-stage {
    height: min(52vh, 24rem);
    min-height: 15rem;
  }
  .bg-item {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
  .bg-arrow {
    transform: rotate(90deg);
  }
  .bg-cell {
    flex-direction: column;
    text-align: center;
  }
  .bg-dl {
    align-self: center;
  }
}
