* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f1117;
  color: #e1e4e8;
  min-height: 100vh;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
}

header {
  text-align: center;
  margin-bottom: 1rem;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header h1 span { color: #58a6ff; }

header p {
  color: #8b949e;
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}

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

.panel {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 1rem;
}

.panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #8b949e;
  margin-bottom: 0.6rem;
}

/* ─── Dropzones ─── */
.dropzone {
  border: 1.5px dashed #30363d;
  border-radius: 6px;
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.dropzone:hover {
  border-color: #58a6ff;
  background: rgba(88,166,255,0.04);
}

.dropzone.dragover {
  border-color: #58a6ff;
  background: rgba(88,166,255,0.08);
}

.dropzone.has-files { padding: 0.5rem; }

.dropzone-icon {
  font-size: 1.3rem;
  opacity: 0.5;
  line-height: 1;
}

.dropzone-text {
  font-size: 0.78rem;
  color: #8b949e;
  margin-top: 0.2rem;
}

.dropzone-text strong { color: #58a6ff; }

.dropzone input[type="file"] { display: none; }

/* ─── Source face row ─── */
.source-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.source-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid #30363d;
  flex-shrink: 0;
}

.source-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.source-thumb .remove-btn {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.source-thumb:hover .remove-btn { opacity: 1; }

.source-thumb .label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.65);
  font-size: 0.55rem;
  text-align: center;
  padding: 1px 0;
  color: #ccc;
}

/* ─── Target preview ─── */
.target-preview-wrap {
  position: relative;
  width: 100%;
  max-height: 160px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid #30363d;
  display: flex;
  justify-content: center;
  background: #0d1117;
  margin-bottom: 0.5rem;
}

.target-preview-wrap img {
  max-width: 100%;
  max-height: 160px;
  object-fit: contain;
}

.target-preview-wrap .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─── Preset gallery ─── */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.preset-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 5px;
  overflow: hidden;
  border: 2px solid #30363d;
  cursor: pointer;
  transition: border-color 0.15s;
}

.preset-item:hover { border-color: #58a6ff; }
.preset-item.selected { border-color: #58a6ff; }

.preset-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preset-item .preset-name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.7);
  font-size: 0.55rem;
  text-align: center;
  padding: 1px 0;
  color: #ccc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Options ─── */
.options-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.6rem;
}

.opt-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.opt-group label {
  font-size: 0.78rem;
  color: #c9d1d9;
  white-space: nowrap;
}

.opt-group input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: #58a6ff;
  cursor: pointer;
}

.opt-group input[type="range"] {
  width: 90px;
  accent-color: #58a6ff;
  cursor: pointer;
}

.opt-group .range-val {
  font-size: 0.75rem;
  color: #58a6ff;
  font-weight: 600;
  min-width: 2.2rem;
  text-align: center;
}

/* ─── Buttons ─── */
.btn-swap {
  flex: 1;
  min-width: 120px;
  padding: 0.55rem 1rem;
  background: #238636;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-swap:hover { background: #2ea043; }

.btn-swap:disabled {
  background: #21262d;
  color: #484f58;
  cursor: not-allowed;
}

.btn-download {
  padding: 0.4rem 0.9rem;
  background: #21262d;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 5px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
}

.btn-download:hover { background: #30363d; }

/* ─── Result ─── */
.result-wrap {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #30363d;
  background: #0d1117;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.result-wrap.has-result { min-height: 0; }

.result-wrap img {
  max-width: 100%;
  max-height: 400px;
  object-fit: contain;
  display: block;
}

.result-placeholder {
  color: #484f58;
  font-size: 0.8rem;
  text-align: center;
  padding: 2rem;
}

.result-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
}

.result-time {
  font-size: 0.75rem;
  color: #8b949e;
}

/* ─── Spinner ─── */
.spinner {
  display: none;
  text-align: center;
  padding: 1.5rem 0;
}

.spinner.visible { display: block; }

.spinner-ring {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid #30363d;
  border-top-color: #58a6ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.spinner-text {
  margin-top: 0.4rem;
  color: #8b949e;
  font-size: 0.78rem;
}

/* ─── Error ─── */
.error-msg {
  display: none;
  background: #3d1418;
  border: 1px solid #f85149;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  color: #f85149;
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}

.error-msg.visible { display: block; }

/* ─── Section divider ─── */
.section-divider {
  border: none;
  border-top: 1px solid #21262d;
  margin: 0.6rem 0;
}
