/* bgremovetools: the tool itself
   1 shared bits (overlay, toasts, notices)   2 processing page
   3 editor layout   4 editor controls   5 crop box                 */

/* ---------- 1. Shared ---------- */

body[data-view="process"] .site-nav,
body[data-view="download"] .site-nav { display: none; }

/* Inside the tool the page's own button is the main action, so the header one steps back. */
body[data-view="process"] .site-header .btn--primary,
body[data-view="download"] .site-header .btn--primary {
  background: var(--surface); border-color: var(--line-strong); color: var(--text);
}
body[data-view="process"] .site-header .btn--primary:hover,
body[data-view="download"] .site-header .btn--primary:hover { background: var(--surface-2); border-color: var(--text-3); }
body[data-view="download"] .site-header { border-bottom-color: var(--line); }
body[data-view="download"] .site-header .wrap { width: auto; margin-inline: 20px; }
@media (max-width: 980px) {
  body[data-view="download"] .site-header .wrap { margin-inline: var(--gutter); }
}

.drop-overlay {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  pointer-events: none;
}
.drop-overlay__in {
  display: grid; justify-items: center; gap: 14px; width: min(520px, 100%); padding: 56px 24px;
  border: 2px dashed var(--accent-text); border-radius: 24px; background: var(--accent-soft);
  font-size: 1.25rem; font-weight: 640; letter-spacing: -.02em;
}
.drop-overlay__in .icon { width: 40px; height: 40px; stroke-width: 1.5; color: var(--accent-text); }

.toasts {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 90;
  display: grid; gap: 8px; justify-items: center; width: min(92vw, 460px);
  transform: translateX(-50%); pointer-events: none;
}
.toast {
  padding: 11px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  font-size: .9375rem; font-weight: 540; box-shadow: var(--shadow-m);
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s;
}
.toast.is-in { opacity: 1; transform: none; }
.toast--error { background: var(--danger); color: #fff; }
[data-theme="dark"] .toast--error { color: #2a0d09; }

.notice {
  display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--r-m);
  border: 1px solid var(--line); background: var(--surface-2);
}
.notice .icon { margin-top: 1px; }
.notice--error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.notice--error .icon { color: var(--danger); }
.notice__title { font-weight: 640; }
.notice__text { margin-top: 2px; color: var(--text-2); font-size: .9375rem; }

/* ---------- 2. Processing page ---------- */

.view--process { background: var(--bg-soft); min-height: calc(100dvh - var(--header-h)); display: grid; }
.process {
  display: grid; align-items: center;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: clamp(28px, 5vw, 72px);
  padding-block: clamp(24px, 5vw, 64px);
}

.preview {
  padding: 10px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 22px; box-shadow: var(--shadow-l);
}
.preview__stage {
  --ratio: 1.3333;
  --max-h: min(62dvh, 600px);
  position: relative; overflow: hidden; margin-inline: auto;
  width: 100%; max-width: calc(var(--max-h) * var(--ratio));
  aspect-ratio: var(--ratio);
  border-radius: 13px; background: var(--surface-2);
}
.preview__img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.preview__scan {
  position: absolute; left: 0; right: 0; top: 0; height: 34%;
  background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--accent) 30%, transparent) 88%, var(--accent) 100%);
  border-bottom: 2px solid var(--accent);
  animation: scan 1.9s cubic-bezier(.45, 0, .55, 1) infinite;
  will-change: transform;
}
@keyframes scan {
  from { transform: translateY(-100%); }
  to { transform: translateY(296%); }
}
.preview .compare { position: absolute; inset: 0; border-radius: 0; }
.preview .compare__layer { position: absolute; inset: 0; }
.preview .compare__layer img { width: 100%; height: 100%; object-fit: cover; }

.process__file {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px;
  margin-top: 14px; color: var(--text-3); font-size: .875rem;
}
.process__file span:first-child { color: var(--text-2); font-weight: 540; overflow-wrap: anywhere; }

.process__title { font-size: clamp(1.75rem, 1.3rem + 1.8vw, 2.5rem); letter-spacing: -.028em; outline: none; }
.process__sub { margin-top: 10px; color: var(--text-2); max-width: 30em; }

.steps { margin-top: 30px; display: grid; gap: 4px; }
.step { position: relative; display: flex; gap: 14px; padding-bottom: 18px; min-height: 52px; }
.step:last-child { padding-bottom: 0; min-height: 0; }
.step:not(:last-child)::before {
  content: ""; position: absolute; left: 12.25px; top: 28px; bottom: 2px; width: 1.5px;
  background: var(--line-strong); transition: background-color .3s;
}
.step.is-done:not(:last-child)::before { background: var(--accent-text); }
.step__mark {
  flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  border: 1.5px solid var(--line-strong); background: var(--bg-soft); color: transparent;
  transition: background-color .25s, border-color .25s, color .25s;
}
.step__mark .icon { width: 14px; height: 14px; stroke-width: 3; }
.step__name { font-weight: 560; color: var(--text-3); line-height: 26px; transition: color .25s; }
.step__detail { color: var(--text-3); font-size: .875rem; line-height: 1.45; font-variant-numeric: tabular-nums; }
.step:not(.is-active):not(.is-done):not(.is-error) .step__detail { display: none; }

.step.is-active .step__mark {
  border-color: var(--line-strong); border-top-color: var(--text);
  animation: spin .8s linear infinite;
}
.step.is-active .step__name { color: var(--text); font-weight: 640; }
.step.is-active .step__detail { color: var(--text-2); }
.step.is-done .step__mark { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.step.is-done .step__name { color: var(--text); }
.step.is-error .step__mark { border-color: var(--danger); background: var(--danger-soft); }
.step.is-error .step__name { color: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  --p: 0%;
  margin-top: 26px; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden;
}
.progress span {
  display: block; height: 100%; width: var(--p); border-radius: inherit; background: var(--accent);
  transition: width .5s cubic-bezier(.3, .7, .3, 1);
}
.process .notice { margin-top: 24px; }
.process__actions { margin-top: 26px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

@media (max-width: 900px) {
  .view--process { align-items: start; }
  .process { grid-template-columns: minmax(0, 1fr); gap: 26px; padding-block: 20px 40px; }
  .preview__stage { --max-h: 44dvh; }
  .process__actions .btn--lg { flex: 1 1 100%; }
  /* Once finished, the list folds up so the button to continue is on screen. */
  .view--process.is-done .step { min-height: 0; padding-bottom: 12px; }
  .view--process.is-done .step__detail { display: none; }
  .view--process.is-done .steps { margin-top: 22px; }
}

/* ---------- 3. Editor layout ---------- */

.view--download { background: var(--bg-soft); }
.editor {
  display: grid; grid-template-columns: minmax(0, 1fr) 376px;
  height: calc(100dvh - var(--header-h)); min-height: 560px;
}
.editor__main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.editor__bar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 52px; padding: 0 14px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.editor__bar-group { display: flex; align-items: center; gap: 2px; }
.editor__dims { color: var(--text-3); font-size: .875rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.editor__stage {
  flex: 1; min-height: 0; display: grid; place-items: center;
  padding: clamp(16px, 3vw, 36px); overflow: hidden;
}
.editor__frame {
  position: relative; line-height: 0;
  box-shadow: 0 0 0 1px var(--line-strong), var(--shadow-m);
  background-size: 16px 16px;
}
.editor__canvas { display: block; width: 100%; height: 100%; }
.editor [data-peek][aria-pressed="true"] { background: var(--text); color: var(--bg); }
.editor [data-peek] { touch-action: none; -webkit-user-select: none; user-select: none; }
.editor.is-cropping [data-peek] { visibility: hidden; }

.editor__side {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg); border-left: 1px solid var(--line);
}
.tabs { flex: none; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 6px 8px 0; border-bottom: 1px solid var(--line); }
.tab {
  display: grid; justify-items: center; gap: 5px; padding: 10px 2px 11px;
  border: 0; border-bottom: 2px solid transparent; background: none;
  color: var(--text-3); font-size: .75rem; font-weight: 560;
  transition: color .15s, border-color .15s;
}
.tab .icon { width: 20px; height: 20px; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }

.panels { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 20px; overscroll-behavior: contain; }
.panel { display: grid; gap: 24px; align-content: start; }

.export {
  flex: none; display: grid; gap: 12px; padding: 16px 20px 20px;
  border-top: 1px solid var(--line); background: var(--bg);
}
.export__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.export__meta { color: var(--text-3); font-size: .875rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.export__note { color: var(--text-3); font-size: .8125rem; }
.export__more { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 4px; }
.btn[aria-busy="true"] { opacity: .7; pointer-events: none; }

@media (max-width: 980px) {
  .editor { display: block; height: auto; min-height: 0; }
  .editor__stage { flex: none; height: min(48dvh, 440px); padding: 14px; }
  .editor__side { border-left: 0; border-top: 1px solid var(--line); }
  .panels { overflow: visible; padding: 20px var(--gutter) 24px; min-height: 236px; }
  .tabs { padding-inline: calc(var(--gutter) - 8px); }
  .export {
    position: sticky; bottom: 0; z-index: 20; padding: 12px var(--gutter) max(14px, env(safe-area-inset-bottom));
    box-shadow: 0 -10px 24px -18px rgba(13, 21, 18, .35);
  }
  /* On small screens the bar keeps to the essentials; "New image" is in the header. */
  .export { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
  .export > * { grid-column: 1 / -1; }
  .export__more { display: none; }
  .export.has-share > [data-download] { grid-column: 1; }
  .export.has-share > .export__more { display: flex; grid-column: 2; }
  .export__more [data-copy], .export__more [data-new-image] { display: none; }
  .export__more [data-share] { width: 54px; height: 54px; padding: 0; border: 1px solid var(--line-strong); border-radius: 14px; color: var(--text); }
  .export__more [data-share] span { display: none; }
  .export__more [data-share] .icon { width: 22px; height: 22px; }
  .editor__bar { padding-inline: calc(var(--gutter) - 8px); }
  .editor [data-peek] span { display: none; }
}
@media (max-width: 420px) {
  .editor__dims { display: none; }
}

/* ---------- 4. Editor controls ---------- */

.field { display: grid; gap: 10px; }
.field__label { font-size: .8125rem; font-weight: 620; color: var(--text-2); }
.field__row { display: flex; align-items: center; gap: 10px; }
.field__group { display: grid; gap: 14px; padding-top: 4px; }
.hint { color: var(--text-3); font-size: .8125rem; line-height: 1.45; }

.input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-size: .9375rem; font-variant-numeric: tabular-nums;
}
.input:hover { border-color: var(--text-3); }
.input:focus-visible { outline-offset: 0; border-color: var(--accent-text); }
.input--hex { width: 104px; text-transform: lowercase; }
input[type="number"].input { -moz-appearance: textfield; appearance: textfield; }
input[type="number"].input::-webkit-outer-spin-button,
input[type="number"].input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 8px; }
.swatch {
  --swatch: #fff;
  aspect-ratio: 1; width: 100%; padding: 0; border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--text) 16%, transparent);
  background: var(--swatch); background-clip: padding-box;
  transition: transform .1s;
}
.swatch:hover { transform: scale(1.06); }
.swatch--none {
  background:
    conic-gradient(var(--checker-b) 25%, transparent 0 50%, var(--checker-b) 0 75%, transparent 0) 0 0 / 12px 12px,
    var(--checker-a);
}
.swatch--wide { aspect-ratio: 1.5; }
.swatch[aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 2px; }
[data-bg-gradients] { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.color-field {
  flex: 1; display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 12px 0 6px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface);
  font-size: .9375rem; cursor: pointer;
}
.color-field:hover { border-color: var(--text-3); }
.color-field input[type="color"] {
  -webkit-appearance: none; appearance: none; width: 28px; height: 28px; padding: 0;
  border: 1px solid color-mix(in srgb, var(--text) 16%, transparent); border-radius: 7px; background: none; cursor: pointer;
}
.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 6px; }
.color-field input[type="color"]::-moz-color-swatch { border: 0; border-radius: 6px; }

.choice-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.choice, .tile {
  display: grid; justify-items: center; gap: 8px; padding: 14px 8px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface);
  color: var(--text); font-size: .875rem; font-weight: 540; text-align: center; line-height: 1.25;
  transition: border-color .15s, background-color .15s;
}
.choice .icon, .tile .icon { width: 22px; height: 22px; color: var(--text-2); }
.choice:hover, .tile:hover { border-color: var(--text-3); background: var(--surface-2); }
.choice[aria-pressed="true"], .tile[aria-pressed="true"] {
  border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text);
}
.tile-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { padding-block: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 34px; padding: 0 13px; border-radius: 99px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-size: .875rem; font-weight: 540; font-variant-numeric: tabular-nums;
  transition: border-color .15s, background-color .15s, color .15s;
}
.chip:hover { border-color: var(--text-3); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

.size-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 4px; }
.num { position: relative; display: block; }
.num span {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); font-size: .8125rem; font-weight: 620; pointer-events: none;
}
.num .input { padding-left: 32px; }
.icon-btn--toggle { color: var(--text-3); }
.icon-btn--toggle[aria-pressed="true"] { color: var(--accent-text); background: var(--accent-soft); }

.select { position: relative; }
.select select {
  -webkit-appearance: none; appearance: none; width: 100%; height: 40px; padding: 0 38px 0 12px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--text);
  font-size: .9375rem; cursor: pointer;
}
.select select:hover { border-color: var(--text-3); }
.select .icon { position: absolute; right: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }

.slider { display: grid; gap: 8px; }
.slider__label { display: flex; justify-content: space-between; font-size: .8125rem; font-weight: 620; color: var(--text-2); }
.slider output { color: var(--text-3); font-weight: 500; font-variant-numeric: tabular-nums; }
.slider input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 22px; margin: 0; background: none; cursor: pointer;
}
.slider input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 99px; background: var(--line-strong); }
.slider input[type="range"]::-moz-range-track { height: 4px; border-radius: 99px; background: var(--line-strong); }
.slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--line-strong);
}
.slider input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--line-strong);
}

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track {
  flex: none; position: relative; width: 40px; height: 24px; border-radius: 99px; background: var(--line-strong);
  transition: background-color .15s;
}
.switch__track::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s;
}
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.switch__label { font-weight: 600; }

.segmented {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 3px; gap: 2px;
  border-radius: 11px; background: var(--surface-2); border: 1px solid var(--line);
}
.segmented button {
  height: 32px; padding: 0 14px; border: 0; border-radius: 8px; background: none;
  color: var(--text-2); font-size: .875rem; font-weight: 600;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"] { background: var(--bg); color: var(--text); box-shadow: var(--shadow-s), 0 0 0 1px var(--line); }

/* ---------- 5. Crop box ---------- */

.crop { position: absolute; inset: 0; touch-action: none; -webkit-user-select: none; user-select: none; }
.crop__shade { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.crop__shade span { position: absolute; box-shadow: 0 0 0 9999px rgba(8, 12, 10, .62); }
.crop__box { position: absolute; cursor: move; outline: 1.5px solid #fff; }
.crop__box:focus-visible { outline: 2px solid var(--accent); }
.crop__grid {
  position: absolute; inset: 0; pointer-events: none; opacity: .55;
  background:
    linear-gradient(#fff, #fff) 33.33% 0 / 1px 100% no-repeat,
    linear-gradient(#fff, #fff) 66.66% 0 / 1px 100% no-repeat,
    linear-gradient(#fff, #fff) 0 33.33% / 100% 1px no-repeat,
    linear-gradient(#fff, #fff) 0 66.66% / 100% 1px no-repeat;
}
.crop__h { position: absolute; width: 32px; height: 32px; display: grid; place-items: center; }
.crop__h::after {
  content: ""; width: 12px; height: 12px; border-radius: 3px; background: #fff;
  box-shadow: 0 0 0 1.5px rgba(8, 12, 10, .7);
}
.crop__h[data-handle="nw"] { left: -16px; top: -16px; cursor: nwse-resize; }
.crop__h[data-handle="ne"] { right: -16px; top: -16px; cursor: nesw-resize; }
.crop__h[data-handle="sw"] { left: -16px; bottom: -16px; cursor: nesw-resize; }
.crop__h[data-handle="se"] { right: -16px; bottom: -16px; cursor: nwse-resize; }
.crop__h[data-handle="n"] { left: calc(50% - 16px); top: -16px; cursor: ns-resize; }
.crop__h[data-handle="s"] { left: calc(50% - 16px); bottom: -16px; cursor: ns-resize; }
.crop__h[data-handle="w"] { left: -16px; top: calc(50% - 16px); cursor: ew-resize; }
.crop__h[data-handle="e"] { right: -16px; top: calc(50% - 16px); cursor: ew-resize; }
.crop__h[data-handle="n"]::after, .crop__h[data-handle="s"]::after { width: 22px; height: 8px; }
.crop__h[data-handle="w"]::after, .crop__h[data-handle="e"]::after { width: 8px; height: 22px; }
