/* =========================================================================
 * Kips Template — Background Eraser Modal
 *
 * Full-screen modal that hosts the interactive cutout flow. Mobile-first
 * layout (top bar, stage, sliders, bottom toolbar) — same skeleton as
 * the popular Background Eraser apps so the IA is familiar to users.
 * ========================================================================= */

.kips-cutout {
  position: fixed; inset: 0;
  z-index: 240;
  pointer-events: none;
  opacity: 0;
  transition: opacity 220ms ease;
}
.kips-cutout.is-open { pointer-events: auto; opacity: 1; }

.kips-cutout__backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.85);
}

.kips-cutout__panel {
  position: absolute; inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background: var(--kt-surface-0, #0E1018);
  color: var(--kt-text-1, #E9ECF3);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

[data-theme="stellar"] .kips-cutout__panel { background: #FAFBFF; color: #0E1018; }

/* ---- top bar ---- */
.kips-cutout__top {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
[data-theme="stellar"] .kips-cutout__top { border-bottom-color: rgba(0, 0, 0, 0.08); }

.kips-cutout__title {
  flex: 1;
  font-weight: 700; font-size: 15px;
  text-align: center;
}
.kips-cutout__top-actions { display: flex; gap: 6px; }

/* ---- iconbutton ---- */
.kips-cutout__btn {
  appearance: none; border: 0; background: transparent;
  width: 38px; height: 38px;
  border-radius: 10px;
  color: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 140ms ease, transform 80ms ease;
}
.kips-cutout__btn svg { width: 20px; height: 20px; fill: currentColor; }
.kips-cutout__btn:hover { background: rgba(255, 255, 255, 0.06); }
[data-theme="stellar"] .kips-cutout__btn:hover { background: rgba(0, 0, 0, 0.05); }
.kips-cutout__btn:active { transform: scale(0.94); }
.kips-cutout__btn[disabled] { opacity: 0.35; pointer-events: none; }

.kips-cutout__btn--save {
  width: auto; padding: 0 14px; gap: 6px;
  background: var(--kt-accent, #6E5BFF);
  color: white;
  font-weight: 600; font-size: 13px;
}
.kips-cutout__btn--save:hover { filter: brightness(1.08); background: var(--kt-accent, #6E5BFF); }
[data-theme="stellar"] .kips-cutout__btn--save:hover { background: var(--kt-accent, #6E5BFF); }
.kips-cutout__btn--save.is-busy { opacity: 0.7; }
.kips-cutout__btn--save svg { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---- stage (canvas area) ---- */
.kips-cutout__stage {
  position: relative;
  overflow: hidden;
  touch-action: none;       /* swallow native pinch-zoom; we do our own */
  user-select: none;
  -webkit-user-select: none;
  background: #0a0a10;
}
.kips-cutout__canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
}
.kips-cutout__overlay {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  pointer-events: none;
}

/* ---- sliders ---- */
.kips-cutout__sliders {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
[data-theme="stellar"] .kips-cutout__sliders { border-top-color: rgba(0, 0, 0, 0.08); }

.kips-cutout__slider {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 12px;
  font-size: 12px;
}
.kips-cutout__slider span { color: var(--kt-text-2, rgba(255, 255, 255, 0.6)); }
.kips-cutout__slider b {
  font-weight: 600;
  color: var(--kt-text-1, white);
  font-variant-numeric: tabular-nums;
}
.kips-cutout__slider input[type="range"] {
  width: 100%;
  accent-color: var(--kt-accent, #6E5BFF);
}

/* ---- bottom toolbar ---- */
.kips-cutout__bottom {
  display: flex; align-items: center; justify-content: flex-start;
  gap: 4px;
  /* Generous start/end padding so the very first tool ("Wand") and the
     very last button ("Zoom in") never get clipped against the screen
     edge — even on narrow phones with a horizontal-scroll fallback. */
  padding: 8px 14px env(safe-area-inset-bottom, 8px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Hide native scrollbar but keep the swipe gesture. */
  scrollbar-width: none;
}
.kips-cutout__bottom::-webkit-scrollbar { display: none; }
[data-theme="stellar"] .kips-cutout__bottom { border-top-color: rgba(0, 0, 0, 0.08); }

.kips-cutout__tool {
  appearance: none; border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  min-width: 60px;
  /* flex-shrink: 0 keeps every tool at its full width even when the row
     overflows — the row scrolls horizontally instead of squeezing the
     first / last button into invisibility. */
  flex: 0 0 auto;
  padding: 6px 8px;
  border-radius: 10px;
  color: var(--kt-text-2, rgba(255, 255, 255, 0.65));
  font-size: 11px; font: inherit; font-size: 11px;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
  white-space: nowrap;
}
.kips-cutout__tool svg { width: 22px; height: 22px; fill: currentColor; }
.kips-cutout__tool:hover { background: rgba(255, 255, 255, 0.06); color: var(--kt-text-1, white); }
[data-theme="stellar"] .kips-cutout__tool:hover { background: rgba(0, 0, 0, 0.05); }
.kips-cutout__tool.is-active {
  background: rgba(110, 91, 255, 0.18);
  color: var(--kt-accent, #6E5BFF);
}
.kips-cutout__tool span { font-size: 10px; letter-spacing: 0.02em; }

.kips-cutout__sep {
  width: 1px; height: 28px;
  margin: 0 4px;
  background: rgba(255, 255, 255, 0.10);
}
[data-theme="stellar"] .kips-cutout__sep { background: rgba(0, 0, 0, 0.10); }

/* ---- tablet / desktop layout tweaks ---- */
@media (min-width: 720px) {
  .kips-cutout__sliders {
    flex-direction: row; gap: 24px;
    padding: 10px 24px;
  }
  .kips-cutout__slider { grid-template-columns: 140px 200px; }
  .kips-cutout__title { font-size: 16px; }
  .kips-cutout__btn { width: 42px; height: 42px; }
  .kips-cutout__bottom { justify-content: center; padding-left: 16px; padding-right: 16px; }
  .kips-cutout__tool { min-width: 70px; padding: 8px 10px; font-size: 12px; }
  .kips-cutout__tool svg { width: 24px; height: 24px; }
}

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  .kips-cutout { transition: none; }
}
