:root {
  --bg: #f6f7f9;
  --fg: #1d2330;
  --muted: #667085;
  --border: #d0d5dd;
  --accent: #2f6fed;
  --card: #ffffff;
  --pos: 50%;
  --ratio: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --fg: #e6e8ec;
    --muted: #98a2b3;
    --border: #3a414d;
    --card: #1d2128;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 24px 16px 48px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

header, main {
  max-width: 1100px;
  margin: 0 auto;
}

h1 { margin: 0 0 4px; font-size: 1.6rem; }
.subtitle { margin: 0 0 20px; color: var(--muted); }

/* ---------- Pickers ---------- */
.pickers {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: stretch;
}

.drop {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  min-width: 0;
}
.drop:hover, .drop:focus-within { border-color: var(--accent); }
.drop.dragover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--card)); }
.drop.loaded { border-style: solid; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop-title { font-weight: 600; }
.drop-hint { color: var(--muted); font-size: .9rem; }
.drop-name { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.swap {
  align-self: center;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
.swap:hover:not(:disabled) { border-color: var(--accent); }
.swap:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 600px) {
  .pickers { grid-template-columns: 1fr; }
}

.message { min-height: 1.2em; margin: 12px 0; color: var(--muted); font-size: .9rem; }
.message.error { color: #d92d20; }

.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

/* ---------- Stage ---------- */
.stage {
  position: relative;
  /* Keep the image's aspect ratio while fitting within 100% width and 80vh height */
  width: min(100%, calc(80vh * var(--ratio)));
  aspect-ratio: var(--ratio);
  margin: 0 auto;
  overflow: hidden;
  border-radius: 12px;
  background: #000;
  user-select: none;
  touch-action: none;
  cursor: ew-resize;
}

.img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.img-after { clip-path: inset(0 0 0 var(--pos)); }

.tag {
  position: absolute;
  top: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: .8rem;
  pointer-events: none;
}
.tag-before { left: 12px; }
.tag-after { right: 12px; }

.handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pos);
  width: 3px;
  margin-left: -1.5px;
  background: #fff;
  box-shadow: 0 0 6px rgba(0, 0, 0, .5);
  outline: none;
}

.grip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  color: #1d2330;
  font-size: 11px;
  letter-spacing: -1px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}
.handle:focus-visible .grip { outline: 3px solid var(--accent); outline-offset: 2px; }
