.tool-head { display: grid; gap: 14px; justify-items: start; margin-bottom: 26px; }
.tool-head h1 { font-size: clamp(2.3rem, 7vw, 4rem); }

/* ---- drop zone ---- */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  min-height: clamp(220px, 34vh, 320px);
  padding: 24px;
  border: 2.5px dashed color-mix(in srgb, var(--foreground) 40%, transparent);
  border-radius: 24px;
  background: color-mix(in srgb, var(--card) 70%, transparent);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, min-height .2s ease;
}
.drop:hover, .drop:focus-within { border-color: var(--tools); background: var(--tools-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop-icon {
  display: grid; place-items: center;
  width: 64px; height: 64px;
  border: 2px solid var(--ink); border-radius: 18px;
  background: var(--tools); color: var(--ink);
  box-shadow: 3px 4px 0 var(--ink);
}
.drop-icon svg { width: 30px; height: 30px; }
.drop-copy { display: grid; gap: 6px; }
.drop-copy strong { font-size: 1.12rem; }
.drop-copy u { text-decoration-color: var(--tools); text-decoration-thickness: 3px; text-underline-offset: 3px; }
.drop-copy small { color: var(--muted-foreground); font-weight: 600; }
kbd {
  font: 700 .78em var(--font-mono), monospace;
  padding: 1px 5px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--muted);
}
.drop.is-compact { flex-direction: row; min-height: 0; padding: 12px 16px; justify-content: flex-start; text-align: left; border-radius: 16px; }
.drop.is-compact .drop-icon { width: 40px; height: 40px; border-radius: 12px; box-shadow: 2px 2px 0 var(--ink); }
.drop.is-compact .drop-icon svg { width: 20px; height: 20px; }
.drop.is-compact .drop-copy strong { font-size: .98rem; }

/* ---- workspace ---- */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 22px;
  margin-top: 18px;
  align-items: start;
}
@media (max-width: 820px) { .workspace { grid-template-columns: 1fr; } }
.stage-col { display: grid; gap: 12px; min-width: 0; }

.stage {
  --split: 50%;
  --ar: 1.5;
  display: grid; place-items: center;
  padding: 14px;
  border: 2px solid var(--ink); border-radius: 22px;
  background: var(--card);
  box-shadow: 5px 6px 0 var(--ink);
}
.dark .stage { border-color: #000; box-shadow: 5px 6px 0 #000; }
.frame {
  position: relative;
  width: min(100%, calc(62vh * var(--ar)));
  aspect-ratio: var(--ar);
  border-radius: 12px;
  overflow: hidden;
  user-select: none;
}
.layer { position: absolute; inset: 0; }
.layer img { width: 100%; height: 100%; object-fit: contain; display: block; }
.stage.is-filled .after-layer { background: var(--fill); }
.before-layer { clip-path: inset(0 calc(100% - var(--split)) 0 0); }
.stage:not(.is-done) .before-layer { clip-path: none; }

.handle {
  position: absolute; top: 0; bottom: 0; left: var(--split);
  width: 3px; margin-left: -1.5px;
  background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35);
  pointer-events: none;
}
.handle span {
  position: absolute; top: 50%; left: 50%;
  width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border: 2px solid var(--ink); border-radius: 50%;
  background: #fff;
  box-shadow: 2px 3px 0 var(--ink);
}
.handle span::before, .handle span::after {
  content: ""; position: absolute; top: 50%; width: 0; height: 0; margin-top: -5px;
  border: 5px solid transparent;
}
.handle span::before { left: 3px; border-right-color: var(--ink); }
.handle span::after { right: 3px; border-left-color: var(--ink); }
.corner {
  position: absolute; top: 10px;
  padding: 3px 9px; border-radius: 999px;
  background: rgba(0,0,0,.6); color: #fff;
  font-size: .72rem; font-weight: 800; letter-spacing: .03em;
  pointer-events: none;
}
.corner-l { left: 10px; }
.corner-r { right: 10px; }
.stage:not(.is-done) .handle, .stage:not(.is-done) .corner { display: none; }
.frame input[type="range"] {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  opacity: 0; cursor: ew-resize;
}
.frame input[type="range"]:disabled { cursor: default; }
.frame:has(input:focus-visible) { outline: 3px solid var(--ring); outline-offset: 3px; }

/* "working" shimmer over the original */
.scan { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .2s ease; }
.stage.is-working .scan {
  opacity: 1;
  background: linear-gradient(100deg, transparent 30%, rgba(114, 211, 154, .38) 50%, transparent 70%);
  background-size: 250% 100%;
  animation: scan 1.6s linear infinite;
}
.stage.is-working .before-layer img { filter: saturate(.6) brightness(.85); }
@keyframes scan { from { background-position: 120% 0; } to { background-position: -120% 0; } }

/* ---- status ---- */
.status {
  display: grid; gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--card);
  font-weight: 700; font-size: .92rem;
}
.status.is-error { border-color: var(--destructive); color: var(--destructive); }
.status.is-error .bar { display: none; }
.bar { --p: 0; position: relative; height: 8px; border-radius: 999px; background: var(--muted); overflow: hidden; }
.bar i {
  position: absolute; inset: 0 auto 0 0;
  width: calc(var(--p) * 100%);
  border-radius: inherit;
  background: var(--tools);
  transition: width .2s ease;
}
.bar.is-indeterminate i { width: 35%; animation: indeterminate 1.1s ease-in-out infinite; }
@keyframes indeterminate { from { left: -35%; } to { left: 100%; } }

/* ---- thumbnails ---- */
.strip { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 8px; }
.thumb {
  position: relative; flex: 0 0 auto;
  width: 72px; height: 72px; padding: 0;
  border: 2px solid var(--border); border-radius: 12px;
  background: var(--muted); overflow: hidden; cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb[aria-current="true"] { border-color: var(--tools); box-shadow: 0 0 0 2px var(--tools); }
.thumb::after {
  content: ""; position: absolute; right: 4px; bottom: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--ink); background: var(--muted-foreground);
}
.thumb[data-state="done"]::after { background: var(--tools); }
.thumb[data-state="working"]::after { background: #ffc844; animation: pulse 1s ease-in-out infinite; }
.thumb[data-state="error"]::after { background: var(--destructive); }
@keyframes pulse { 50% { transform: scale(.7); } }

/* ---- side panel ---- */
.panel {
  display: grid; gap: 18px;
  padding: 18px;
  border: 1px solid var(--border); border-radius: 20px;
  background: color-mix(in srgb, var(--card) 85%, transparent);
}
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 9px; font-weight: 800; font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-foreground); }
.hint { margin: 8px 0 0; color: var(--muted-foreground); font-size: .8rem; line-height: 1.45; font-weight: 500; }

.swatches { display: flex; gap: 9px; flex-wrap: wrap; }
.swatch {
  position: relative;
  width: 40px; height: 40px; padding: 0;
  border: 2px solid var(--border); border-radius: 12px;
  cursor: pointer;
  display: grid; place-items: center;
  background-size: 12px 12px; background-position: 0 0, 6px 6px;
}
.swatch[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 3px var(--tools); }
.dark .swatch[aria-pressed="true"] { border-color: #fff; }
.swatch:focus-visible, .swatch:focus-within { outline: 3px solid var(--ring); outline-offset: 2px; }
.swatch.custom { background: conic-gradient(#ff6b6b, #ffc844, #72d39a, #69a7ff, #b69cff, #ff6b6b); color: var(--ink); }
.swatch.custom svg { width: 18px; height: 18px; position: relative; pointer-events: none; }
.swatch.custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }

.actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.actions.secondary { grid-template-columns: 1fr 1fr; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: grid; gap: 2px; padding: 10px 12px;
  border: 2px solid var(--border); border-radius: 12px;
  transition: border-color .12s ease, background .12s ease;
}
.segmented small { color: var(--muted-foreground); font-weight: 600; font-size: .76rem; }
.segmented input:checked + span { border-color: var(--tools); background: var(--tools-soft); }
.segmented input:focus-visible + span { outline: 3px solid var(--ring); outline-offset: 2px; }

.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 700; font-size: .9rem; }
.toggle small { color: var(--muted-foreground); font-weight: 600; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.track {
  position: relative; flex: 0 0 auto;
  width: 40px; height: 24px; border-radius: 999px;
  background: var(--muted); border: 2px solid var(--border);
  transition: background .15s ease;
}
.track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--foreground);
  transition: transform .15s ease;
}
.toggle input:checked + .track { background: var(--tools); border-color: var(--ink); }
.toggle input:checked + .track::after { transform: translateX(16px); background: var(--ink); }
.toggle input:focus-visible + .track { outline: 3px solid var(--ring); outline-offset: 2px; }

/* ---- explainer ---- */
.how { margin-top: clamp(36px, 6vw, 60px); }
.how h2 { font-family: "Space Grotesk", sans-serif; letter-spacing: -.03em; font-size: 1.5rem; margin: 0 0 14px; }
.how ol {
  margin: 0; padding: 0; list-style: none;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 14px;
  counter-reset: how;
}
.how li {
  counter-increment: how;
  position: relative;
  padding: 16px 16px 16px 56px;
  border: 1px solid var(--border); border-radius: 16px;
  background: color-mix(in srgb, var(--card) 70%, transparent);
  color: var(--muted-foreground); line-height: 1.55; font-size: .9rem; font-weight: 500;
}
.how li b { color: var(--foreground); display: block; margin-bottom: 2px; font-size: .98rem; }
.how li::before {
  content: counter(how);
  position: absolute; left: 14px; top: 15px;
  width: 30px; height: 30px; display: grid; place-items: center;
  border: 2px solid var(--ink); border-radius: 9px;
  background: var(--tools); color: var(--ink);
  font-weight: 800;
}

/* ---- full-page drag veil ---- */
.drag-veil {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--background) 72%, transparent);
  backdrop-filter: blur(4px);
  pointer-events: none;
  opacity: 0; transition: opacity .12s ease;
}
.drag-veil span {
  padding: 18px 26px;
  border: 2.5px dashed var(--ink); border-radius: 20px;
  background: var(--tools); color: var(--ink);
  font-weight: 800; font-size: 1.2rem;
}
body.is-dragging .drag-veil { opacity: 1; }
