:root {
  --bg: #0e0f12;
  --panel: #15171c;
  --panel-2: #1d2027;
  --border: #2a2e38;
  --text: #e6e8ee;
  --muted: #8a909c;
  --accent: #25d366;
  --accent-dim: #1a8649;
  --danger: #ff5470;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

header h1 {
  font-size: 28px;
  margin: 0 0 6px;
}
.tag {
  margin: 0 0 28px;
  color: var(--muted);
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  background: var(--panel);
  transition: border-color 120ms, background 120ms;
}
.dropzone.drag {
  border-color: var(--accent);
  background: var(--panel-2);
}
.dropzone p { margin: 6px 0; }
.dropzone .hint { color: var(--muted); font-size: 13px; }
.dropzone code { background: var(--panel-2); padding: 1px 6px; border-radius: 4px; font-family: var(--mono); font-size: 12px; }
.link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.thumbs {
  margin: 20px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
.thumb {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
  cursor: grab;
}
.thumb.dragging { opacity: 0.4; cursor: grabbing; }
.thumb.drop-target { outline: 2px solid var(--accent); }
.thumb img {
  display: block;
  width: 100%;
  height: 160px;
  object-fit: cover;
  object-position: top;
}
.thumb .meta {
  padding: 6px 8px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 6px;
}
.thumb .idx {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0,0,0,0.7);
  color: white;
  border-radius: 100px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}
.thumb .remove {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  border-radius: 100px;
  width: 22px;
  height: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.thumb .remove:hover { background: var(--danger); }

.controls {
  margin: 20px 0 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.controls details {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
}
.controls summary { cursor: pointer; color: var(--muted); }
.controls details[open] {
  padding-bottom: 14px;
}
.controls label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 10px 16px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.controls label.manual { display: none; }
.controls input[type=number] {
  width: 80px;
  padding: 4px 8px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--mono);
}
.controls input[type=number]:disabled { opacity: 0.4; }

.actions {
  display: flex;
  gap: 10px;
}

button, .btn {
  background: var(--accent);
  color: #0a0a0a;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover:not(:disabled), .btn:hover { background: var(--accent-dim); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
button.secondary:hover:not(:disabled) {
  background: var(--panel);
  color: var(--text);
}

.status {
  margin: 20px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  min-height: 1em;
}
.status .err { color: var(--danger); }

.result { margin: 28px 0 0; }
.result-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}
.result-head h2 { margin: 0; font-size: 20px; flex: 0 0 auto; }
.result-meta { color: var(--muted); font-size: 13px; flex: 1; }
.result-img {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  max-height: 80vh;
  overflow: auto;
  text-align: center;
}
.result-img img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.muted { color: var(--muted); }

[hidden] { display: none !important; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 600px;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.modal-head .muted { font-size: 12px; flex: 1; }
.modal-body {
  padding: 16px;
  overflow: auto;
  flex: 1 1 auto;
}
.mask-stage {
  position: relative;
  margin: 0 auto;
  width: fit-content;
  cursor: crosshair;
}
.mask-stage img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.mask-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

footer {
  margin-top: 40px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
footer a { color: var(--muted); }
