:root {
  --bg-body: #111;
  --bg-box: #252525;
  --bg-input: #0e0e0e;
  --bg-panel: #1a1a2a;
  --bg-button: #222;
  --bg-button-hover: #2a2a2a;
  --bg-accent: #1a3a5a;
  --text-primary: #eee;
  --text-secondary: #aab;
  --text-muted: #888;
  --border-color: #333;
  --border-light: #444;
  --accent: #6cf;
  --accent-hover: #9df;
  --accent-green: #4a4;
  --accent-green-hover: #6c6;
  --link-color: #7af;
  --overlay-bg: rgba(0,0,0,0.6);
}

:root.light-theme {
  --bg-body: #f6f8fa;
  --bg-box: #ffffff;
  --bg-input: #ffffff;
  --bg-panel: #f0f3f6;
  --bg-button: #f3f4f6;
  --bg-button-hover: #e5e7eb;
  --bg-accent: #ddf4ff;
  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-muted: #8b949e;
  --border-color: #d1d9e0;
  --border-light: #b8c0c8;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --accent-green: #1a7f37;
  --accent-green-hover: #2da44e;
  --link-color: #0969da;
  --overlay-bg: rgba(0,0,0,0.5);
}

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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 1rem 1.5rem;
}

h1 { font-size: 1.4rem; letter-spacing: 0.02em; }
h1 .subtitle { font-size: 0.75rem; font-weight: 400; color: var(--text-muted); margin-left: 0.5rem; }
h2 { font-size: 0.85rem; font-weight: 500; margin-bottom: 0.4rem; color: var(--text-primary); text-transform: uppercase; letter-spacing: 0.05em; }

/* --- Top bar --- */

#top-bar { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.75rem; width: 100%; max-width: 900px; }

#theme-toggle {
  margin-left: auto;
  width: 36px; height: 36px;
  min-width: 36px; min-height: 36px;
  aspect-ratio: 1;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: var(--bg-button);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  transition: background 0.15s, border-color 0.15s;
}
#theme-toggle::before {
  content: '\263E';
  color: #f0e68c;
  text-shadow:
    0 0 3px #000,
    1px 1px 1px #000;
}
#theme-toggle:hover {
  background: var(--bg-button-hover);
  border-color: var(--accent);
}

.light-theme #theme-toggle::before {
  content: '\2600';
  color: #f59e0b;
  text-shadow:
    0 0 3px #fff,
    1px 1px 1px rgba(0,0,0,0.3);
}

#clear-all-btn {
  margin-left: auto; padding: 0.2rem 0.5rem; border: 1px solid #733; border-radius: 4px;
  font-size: 0.65rem; color: #f99; background: #252525; cursor: pointer; vertical-align: middle;
}
#clear-all-btn:hover { background: #3a1a1a; border-color: #f55; }

/* --- Error banner --- */

#error-banner {
  width: 100%; max-width: 900px; margin-bottom: 0.75rem; padding: 0.5rem 1rem;
  background: #3a1a1a; border: 1px solid #f55; border-radius: 6px;
  color: #fcc; font-size: 0.85rem; text-align: center; cursor: pointer;
}

/* --- Info panel --- */

#info-panel {
  width: 100%; max-width: 900px; margin-bottom: 0.75rem; padding: 0.6rem 1rem;
  background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 6px;
  font-size: 0.8rem; color: var(--text-secondary); text-align: center;
}
#info-panel p { margin: 0.2rem 0; }
#info-panel .privacy-note { color: #8b8; }
#info-panel .repo-link { margin-top: 0.3rem; }
#info-panel a { color: var(--link-color); text-decoration: none; }
#info-panel a:hover { text-decoration: underline; }

/* --- Images section --- */

#images-section {
  width: 100%;
  max-width: 900px;
  margin-bottom: 0.75rem;
}
#images-details > :not(summary) {
  padding: 0 0.75rem;
}
#images-details > :last-child {
  padding-bottom: 0.75rem;
}

.section-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* Output section */
#output-section {
  width: 100%;
  max-width: 900px;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-box);
  padding: 0.75rem;
}

/* --- Pose box --- */

.pose-box {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border: 2px dashed var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-box);
  transition: border-color 0.2s, background 0.2s;
}

.pose-box.dragover { border-color: var(--accent); background: var(--bg-panel); }
.pose-box.has-image { border-style: solid; border-color: var(--border-color); }

.pose-box canvas {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none;
}

.pose-box .status {
  position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%);
  font-size: 0.7rem; color: #fff; background: rgba(0,0,0,0.6);
  padding: 2px 8px; border-radius: 4px; pointer-events: none; white-space: nowrap;
}
.pose-box .status:empty { display: none; }

/* Upload prompt */

.upload-prompt {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  color: var(--text-primary); pointer-events: none;
}

.upload-label {
  pointer-events: auto; cursor: pointer; padding: 0.35rem 0.9rem;
  border: 1px solid var(--border-light); border-radius: 6px; font-size: 0.8rem;
  color: var(--text-primary); background: var(--bg-button); transition: background 0.15s, border-color 0.15s;
}
.upload-label:hover { background: var(--bg-button-hover); border-color: var(--accent); }

.file-input { display: none; }

/* Image display */

.pose-img { display: none; width: 100%; height: 100%; object-fit: contain; }
.pose-box.has-image .upload-prompt { display: none; }
.pose-box.has-image .pose-img { display: block; }

/* Metadata */

.img-meta {
  position: absolute; bottom: 6px; right: 6px; font-size: 0.6rem;
  color: #fff; background: rgba(0,0,0,0.5); padding: 2px 5px; border-radius: 3px; pointer-events: none;
}
.img-meta:empty { display: none; }

/* Clear button */

.clear-btn {
  display: none; position: absolute; top: 5px; right: 5px;
  width: 24px; height: 24px; border: none; border-radius: 50%;
  background: rgba(0,0,0,0.5); color: #fff; font-size: 0.9rem;
  cursor: pointer; line-height: 1; backdrop-filter: blur(4px); z-index: 2;
}
.clear-btn:hover { background: rgba(200,50,50,0.7); }
.pose-box.has-image .clear-btn { display: block; }

/* Output GIF + progress */

.output-gif {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%; object-fit: contain;
  z-index: 5;
}

#output-box.empty .output-gif,
#output-box.empty #output-gif,
#output-box.empty #output-video,
#output-box.empty #overlay-canvas {
  display: none !important;
  visibility: hidden !important;
}

#output-box { aspect-ratio: unset; }
#output-box.empty { height: 80px; }

/* Progress container */
.progress-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--bg-box);
}

.progress-container.idle .spinner,
.progress-container.idle .progress-bar-wrapper {
  display: none;
}

.progress-container.idle .progress-text {
  color: var(--text-muted);
  text-align: center;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

.progress-info {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
  max-width: 300px;
}

.progress-text {
  font-size: 0.8rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-bar-wrapper {
  width: 100%;
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4a4, #6c6);
  border-radius: 3px;
  transition: width 0.15s ease-out;
}

.progress-bar.indeterminate {
  width: 30%;
  animation: indeterminate 1.2s ease-in-out infinite;
}

@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

/* Model loading spinner */
.model-loading {
  width: 100%;
  max-width: 900px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.model-loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-light);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: model-spin 0.8s linear infinite;
}
@keyframes model-spin {
  to { transform: rotate(360deg); }
}
.model-loading-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Section header with inline button */

.section-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.section-header h2 { margin-bottom: 0; }
@media (min-width: 641px) {
  .section-header.generate-only h2 { flex: 1; }
  .section-header.generate-only::after { content: ''; flex: 1; }
}

#save-btn {
  padding: 0.2rem 0.75rem; border: 1px solid #555; border-radius: 5px;
  font-size: 0.75rem; color: #eee; background: #383838;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
#save-btn:hover { background: #4a4a4a; border-color: #888; }

#output-size {
  font-size: 0.75rem;
  color: #888;
  margin-left: 0.5rem;
}

/* --- Action bar (Options) --- */

#action-bar {
  width: 100%;
  max-width: 900px;
  margin-bottom: 0.75rem;
}

/* Images */

#images-details {
  border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-box);
}
#images-details summary {
  cursor: pointer; padding: 0.5rem 0.75rem; font-size: 0.85rem;
  color: var(--text-primary); user-select: none; list-style: none;
  letter-spacing: 0.05em; font-weight: 500; text-transform: uppercase;
  display: flex; align-items: center;
}
#images-details summary::before { content: '\25b8  '; }
#images-details[open] summary::before { content: '\25be  '; }
#images-details[open] summary { border-bottom: 1px solid var(--border-color); }

/* Options */

#options-details {
  border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-box);
}

#options-details summary {
  cursor: pointer; padding: 0.5rem 0.75rem; font-size: 0.85rem;
  color: var(--text-primary); user-select: none; list-style: none;
  letter-spacing: 0.05em; font-weight: 500; text-transform: uppercase;
  display: flex; align-items: center;
}
#options-details summary::before { content: '\25b8  '; }
#options-details[open] summary::before { content: '\25be  '; }
#options-details[open] summary { border-bottom: 1px solid var(--border-color); }

.options-body {
  padding: 0.5rem 0.75rem 0.6rem;
  display: flex; flex-direction: column; gap: 0.1rem;
}

/* Mode selector */

.mode-selector {
  display: flex; gap: 0.5rem; padding: 0.5rem 0; margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--border-color);
}
.mode-option {
  flex: 1; display: flex; align-items: center; justify-content: center;
  gap: 0.4rem; padding: 0.5rem 0.75rem;
  background: var(--bg-button); border: 2px solid var(--border-color); border-radius: 6px;
  font-size: 0.85rem; font-weight: 500; color: var(--text-muted); cursor: pointer;
  transition: all 0.15s;
}
.mode-option:hover { border-color: var(--border-light); color: var(--text-primary); }
.mode-option:has(input:checked) {
  background: var(--bg-accent); border-color: var(--accent); color: var(--text-primary);
  font-weight: 600;
}
.mode-option input { display: none; }

/* Option groups */

.opt-group {
  padding: 0.35rem 0.5rem;
  margin: 0 -0.5rem;
  border-radius: 4px;
}
.opt-group:nth-of-type(even) {
  background: var(--bg-panel);
}
.opt-group-title {
  font-size: 0.65rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-primary); margin-bottom: 0.25rem;
}

/* Compact settings */

.setting-compact {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; padding: 0.35rem 0.5rem; font-size: 0.78rem; color: var(--text-primary);
  border-radius: 4px; margin: 0 -0.5rem;
}
.setting-compact > label { white-space: nowrap; }
.label-hint { font-size: 0.7rem; color: var(--text-muted); font-weight: normal; }
.setting-hint { font-size: 0.7rem; color: var(--text-muted); margin: -0.2rem 0 0.3rem; text-align: right; }

.setting-compact input[type="number"] {
  width: 60px; padding: 4px 6px; border: 1px solid var(--border-color); border-radius: 4px;
  background: var(--bg-input); color: var(--text-primary); font-size: 0.8rem; text-align: right;
}
.setting-compact input[type="number"]:focus {
  border-color: var(--accent); outline: none;
}
.setting-compact select {
  padding: 4px 6px; border: 1px solid var(--border-color); border-radius: 4px;
  background: var(--bg-input); color: var(--text-primary); font-size: 0.8rem;
}
.setting-compact select:focus {
  border-color: var(--accent); outline: none;
}
.setting-compact input[type="checkbox"] {
  accent-color: var(--accent); margin: 0;
  width: 18px; height: 18px; cursor: pointer;
}
.setting-compact input[type="range"] { width: 80px; accent-color: var(--accent); }

/* Inline sub-controls (checkbox + dropdown on same line, or number + unit) */

.inline-sub {
  display: flex; align-items: center; gap: 0.35rem;
  font-size: 0.78rem; color: var(--text-primary); font-variant-numeric: tabular-nums;
  margin-left: auto;
}
.inline-sub span {
  min-width: 2em; text-align: right; color: var(--text-primary);
}

/* Hide dropdown when its toggle is unchecked */
.inline-sub input[type="checkbox"]:not(:checked) ~ select {
  display: none;
}
.toggle-right:has(input[type="checkbox"]:not(:checked)) select {
  display: none;
}

/* Lock button */
.lock-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.15s, background 0.15s;
}
.lock-btn:hover { opacity: 1; background: var(--bg-tertiary); }
.lock-btn.locked { opacity: 1; background: var(--bg-tertiary); }

/* Row of small toggles side by side */

.setting-row-pair, .setting-row-triple {
  display: flex; gap: 0.75rem; padding: 0.35rem 0.5rem; margin: 0 -0.5rem;
  border-radius: 4px;
}
.setting-row-pair .setting-compact,
.setting-row-triple .setting-compact {
  flex: 1; gap: 0.4rem; padding: 0; margin: 0;
  justify-content: center;
}

/* Dim inputs */

.dim-inputs { display: flex; align-items: center; gap: 0.25rem; font-size: 0.78rem; color: var(--text-primary); margin-left: auto; }
.dim-inputs input { width: 58px; }

/* Size hint inline */
.size-hint-inline { font-size: 0.7rem; color: var(--text-muted); }
.setting-size-row { flex-wrap: wrap; }
.setting-size-row .dim-inputs { margin-left: auto; }
.setting-size-row .lock-btn { margin-left: 0.25rem; }
.setting-size-row .size-hint-inline {
  order: 4;
  flex: 1 1 100%;
  text-align: right;
  margin-top: 0.2rem;
}

/* Text button (customize / use single) */

.text-btn {
  font-size: 0.7rem; color: var(--accent); cursor: pointer;
  border: none; background: none; padding: 0;
  text-decoration: underline; text-underline-offset: 2px;
}
.text-btn:hover { color: var(--accent-hover); }

/* --- Comparisons --- */

#compare-grid {
  display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.5rem;
}

.cmp-card {
  position: relative; width: 160px; height: 213px; flex-shrink: 0;
  border: 2px solid var(--border-color); border-radius: 8px; overflow: hidden;
  background: var(--bg-box); cursor: pointer; transition: border-color 0.15s;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.cmp-card:hover { border-color: var(--border-light); }
.cmp-card.selected { border-color: var(--accent); }
.cmp-card:first-child { border-color: var(--accent-green); }
.cmp-card:first-child .card-number { background: var(--accent-green); }
.cmp-card.dragging { opacity: 0.4; touch-action: none; }
#compare-grid.touch-dragging {
  overflow: hidden;
  touch-action: none;
  -webkit-overflow-scrolling: auto;
}

.drop-indicator {
  flex-shrink: 0;
  width: 4px;
  height: 160px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 10px rgba(102, 204, 255, 0.7);
  align-self: center;
  pointer-events: none;
}

.cmp-card img {
  width: 100%; height: 100%; object-fit: contain;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  pointer-events: none;
}
.cmp-img {
  width: 100%; height: 100%;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
}
.cmp-card canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
.cmp-card .img-meta { position: absolute; bottom: 3px; right: 3px; font-size: 0.5rem; }
.cmp-card .clear-btn {
  display: flex; align-items: center; justify-content: center;
  top: 5px; right: 5px; width: 24px; height: 24px;
  font-size: 1.2rem; line-height: 1;
}
.card-number {
  position: absolute; top: 5px; left: 5px;
  min-width: 24px; height: 24px; padding: 0 5px;
  background: rgba(0,0,0,0.7); color: #fff;
  font-size: 0.85rem; font-weight: bold;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
}

#compare-upload { display: block; width: 100%; }

/* When grid has images, collapse to small button */
#compare-grid:not(:empty) + #compare-upload .upload-prompt-cmp {
  padding: 0.5rem;
  min-height: auto;
  border: none;
  background: transparent;
}
#compare-grid:not(:empty) + #compare-upload .prompt-main,
#compare-grid:not(:empty) + #compare-upload .prompt-sub {
  display: none;
}
#compare-grid:not(:empty) + #compare-upload .upload-label-lg {
  padding: 0.25rem 0.7rem;
  font-size: 0.78rem;
}

#images-section.dragover #images-details { outline: 2px dashed var(--accent); outline-offset: -2px; }

/* --- Person selection modal --- */

.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.8); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}

.modal-content {
  background: var(--bg-box); border: 1px solid var(--border-light); border-radius: 10px;
  padding: 1rem; max-width: 90vw; max-height: 90vh;
  display: flex; flex-direction: column; gap: 0.5rem;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
}

.modal-header h3 { font-size: 1rem; color: var(--text-primary); }

#modal-close {
  border: none; background: none; color: var(--text-primary); font-size: 1.4rem;
  cursor: pointer; line-height: 1;
}
#modal-close:hover { color: var(--text-primary); }

#modal-canvas {
  max-width: 100%; max-height: 70vh; border-radius: 6px; cursor: pointer;
}

.modal-hint { font-size: 0.75rem; color: var(--text-primary); text-align: center; }

/* --- Generate buttons --- */

#generate-btn-desktop {
  padding: 0.3rem 0.9rem;
  border: 1px solid #4a4;
  border-radius: 5px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #2a5a2a 0%, #1a3a1a 100%);
  cursor: pointer;
  transition: all 0.2s;
}
#generate-btn-desktop:hover {
  background: linear-gradient(135deg, #3a7a3a 0%, #2a5a2a 100%);
  border-color: #6c6;
}

#generate-section-mobile {
  display: none;
  width: 100%;
  max-width: 900px;
  margin-bottom: 0.75rem;
}

#generate-btn-mobile {
  width: 100%;
  padding: 0.9rem 1.5rem;
  border: 2px solid #4a4;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #2a5a2a 0%, #1a3a1a 100%);
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
#generate-btn-mobile:hover {
  background: linear-gradient(135deg, #3a7a3a 0%, #2a5a2a 100%);
  border-color: #6c6;
}

/* --- Comparison upload styling --- */

.upload-prompt-cmp {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1rem;
  border: 2px dashed var(--border-light);
  border-radius: 10px;
  background: var(--bg-box);
  min-height: 100px;
  width: 100%;
  justify-content: center;
  transition: border-color 0.2s, background 0.2s;
  box-sizing: border-box;
}
.upload-prompt-cmp:hover {
  border-color: var(--accent);
  background: var(--bg-panel);
}

.upload-label-lg {
  padding: 0.5rem 1.2rem;
  font-size: 0.95rem;
}

.prompt-main {
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 500;
}
.prompt-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Reference upload prompt styling */
.upload-prompt .prompt-main {
  font-size: 0.85rem;
}
.upload-prompt .prompt-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 200px;
}

.upload-warning {
  font-size: 0.7rem;
  color: #a90;
  margin-top: 0.5rem;
  text-align: center;
}

.upload-hint {
  font-size: 0.75rem;
  color: var(--accent);
  margin-top: 0.4rem;
  text-align: center;
}

/* --- Restore defaults button --- */

.restore-btn {
  margin-left: auto;
  padding: 0.2rem 0.5rem;
  border: 1px solid #733;
  border-radius: 4px;
  font-size: 0.65rem;
  color: #f99;
  background: #252525;
  cursor: pointer;
}
.restore-btn:hover {
  background: #3a1a1a;
  border-color: #f55;
}

.redetect-btn {
  width: 150px;
  margin-top: 0.4rem;
  margin-left: auto;
  display: block;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border-light);
  border-radius: 5px;
  font-size: 0.75rem;
  color: var(--text-primary);
  background: var(--bg-button);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.redetect-btn:hover:not(:disabled) {
  background: var(--bg-button-hover);
  border-color: var(--accent);
}
.redetect-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --- Mobile layout --- */

@media (max-width: 640px) {
  body {
    display: flex;
    flex-direction: column;
  }

  #top-bar { order: 0; }
  #error-banner { order: 1; }
  #info-panel { order: 2; text-align: center; }

  #images-section {
    order: 3;
    width: 100%;
  }

  .cmp-card {
    width: calc(33.333% - 0.34rem);
    height: auto;
    aspect-ratio: 3 / 4;
  }

  #action-bar {
    order: 4;
  }

  #generate-section-mobile {
    display: block;
    order: 5;
  }
  #generate-btn-desktop {
    display: none;
  }

  #output-section {
    order: 6;
    width: 100%;
    max-width: 100%;
    margin-bottom: 0.75rem;
  }

  /* Mobile-friendly inputs */
  .setting-compact {
    padding: 0.5rem;
    flex-wrap: wrap;
  }
  .setting-compact > label {
    flex: 1 1 100%;
    margin-bottom: 0.25rem;
  }
  .setting-compact input[type="number"] {
    width: 70px;
    padding: 8px 10px;
    font-size: 1rem;
  }
  .setting-compact select {
    padding: 8px 10px;
    font-size: 1rem;
    margin-left: auto;
  }
  .setting-compact input[type="checkbox"] {
    width: 24px;
    height: 24px;
  }
  .setting-compact input[type="range"] {
    flex: 1;
    height: 24px;
  }
  .inline-sub {
    flex: 1;
    justify-content: flex-end;
  }
  .setting-hint {
    text-align: right;
  }

  /* Size row: label + hint + lock on first line, inputs on second */
  .setting-size-row > label {
    flex: 0 0 auto;
    margin-bottom: 0;
    order: 0;
  }
  .setting-size-row .size-hint-inline {
    flex: 1;
    text-align: right;
    margin-left: 0.5rem;
    margin-top: 0;
    order: 1;
  }
  .setting-size-row .lock-btn {
    order: 2;
  }
  .setting-size-row .dim-inputs {
    flex: 1 1 100%;
    margin-top: 0.35rem;
    margin-left: 0;
    justify-content: flex-end;
    order: 3;
  }

  /* Checkbox on right for mobile */
  .setting-compact > input[type="checkbox"] {
    margin-left: auto;
  }

  /* Toggle rows stay horizontal on mobile */
  .setting-row-pair, .setting-row-triple {
    flex-wrap: nowrap;
    padding: 0.5rem;
    justify-content: space-around;
  }
  .setting-row-pair .setting-compact,
  .setting-row-triple .setting-compact {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    padding: 0;
    gap: 0.3rem;
  }
  .setting-row-pair .setting-compact > label,
  .setting-row-triple .setting-compact > label {
    flex: none;
    margin-bottom: 0;
  }

  /* Custom stepper buttons for mobile */
  .stepper-wrap {
    display: flex;
    align-items: stretch;
  }
  .stepper-wrap input[type="number"] {
    border-radius: 0;
    -moz-appearance: textfield;
    text-align: center;
  }
  .stepper-wrap input[type="number"]::-webkit-inner-spin-button,
  .stepper-wrap input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
  .stepper-btn {
    width: 36px;
    border: 1px solid var(--border-color);
    background: var(--bg-button);
    color: var(--text-primary);
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .stepper-btn:first-child {
    border-radius: 4px 0 0 4px;
    border-right: none;
  }
  .stepper-btn:last-child {
    border-radius: 0 4px 4px 0;
    border-left: none;
  }
  .stepper-btn:active {
    background: var(--bg-button-hover);
  }
}

/* --- Debug panel --- */

.debug-toggle {
  position: fixed;
  bottom: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-light);
  border-radius: 50%;
  background: var(--bg-button);
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
}
.debug-toggle:hover {
  background: var(--bg-button-hover);
  border-color: var(--accent);
}
.debug-toggle.has-crash {
  border-color: #f55;
  animation: pulse-crash 2s infinite;
}
@keyframes pulse-crash {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 85, 85, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(255, 85, 85, 0); }
}

.debug-panel {
  position: fixed;
  bottom: 60px;
  right: 12px;
  width: min(400px, calc(100vw - 24px));
  max-height: 60vh;
  background: var(--bg-box);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

.debug-actions {
  display: flex;
  gap: 0.4rem;
}

.debug-actions button {
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  background: var(--bg-button);
  color: var(--text-secondary);
  font-size: 0.7rem;
  cursor: pointer;
}
.debug-actions button:hover {
  background: var(--bg-button-hover);
  color: var(--text-primary);
}

.debug-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 0.7rem;
  line-height: 1.4;
}

.debug-session {
  margin-bottom: 0.75rem;
  border: 1px solid #333;
  border-radius: 4px;
  overflow: hidden;
}

.debug-session-header {
  padding: 0.4rem 0.6rem;
  background: var(--bg-panel);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
}
.debug-session-header:hover {
  background: var(--bg-button-hover);
}

.debug-session.crashed .debug-session-header {
  background: #3a1a1a;
  border-left: 3px solid #f55;
}

.debug-session.running .debug-session-header {
  background: #1a2a1a;
  border-left: 3px solid #4a4;
}

.debug-session-logs {
  padding: 0.4rem 0.6rem;
  background: var(--bg-body);
  max-height: 200px;
  overflow-y: auto;
}

.debug-log {
  padding: 0.15rem 0;
  border-bottom: 1px solid var(--border-color);
  word-break: break-word;
}
.debug-log:last-child {
  border-bottom: none;
}

.debug-log .time {
  color: var(--text-muted);
  margin-right: 0.4rem;
}

.debug-log.info .level { color: var(--accent); }
.debug-log.warn .level { color: #fc6; }
.debug-log.error .level { color: #f66; }

.debug-log .msg { color: var(--text-primary); }
.debug-log .data { color: var(--text-secondary); font-size: 0.65rem; }

/* --- Light mode overrides --- */

.light-theme #clear-all-btn {
  background: #fff;
  border-color: #e5534b;
  color: #cf222e;
}
.light-theme #clear-all-btn:hover {
  background: #ffebe9;
  border-color: #cf222e;
}
.light-theme .restore-btn {
  background: #fff;
  border-color: #e5534b;
  color: #cf222e;
}
.light-theme .restore-btn:hover {
  background: #ffebe9;
  border-color: #cf222e;
}
.light-theme #error-banner {
  background: #ffebe9;
  border-color: #cf222e;
  color: #82071e;
}
.light-theme #info-panel .privacy-note { color: #1a7f37; }
.light-theme .pose-box .status {
  background: rgba(255,255,255,0.9);
  color: #1f2328;
}
.light-theme .clear-btn {
  background: rgba(255,255,255,0.9);
  color: #1f2328;
}
.light-theme .clear-btn:hover { background: rgba(207,34,46,0.9); color: #fff; }
.light-theme .card-number {
  background: rgba(255,255,255,0.9);
  color: #1f2328;
}
.light-theme .cmp-card:first-child .card-number {
  background: #1a7f37;
  color: #fff;
}
.light-theme .img-meta {
  background: rgba(255,255,255,0.85);
  color: #1f2328;
}
.light-theme #generate-btn-desktop {
  background: linear-gradient(135deg, #2da44e 0%, #1a7f37 100%);
  border-color: #1a7f37;
}
.light-theme #generate-btn-desktop:hover {
  background: linear-gradient(135deg, #3fb950 0%, #2da44e 100%);
  border-color: #2da44e;
}
.light-theme #generate-btn-mobile {
  background: linear-gradient(135deg, #2da44e 0%, #1a7f37 100%);
  border-color: #1a7f37;
}
.light-theme #generate-btn-mobile:hover {
  background: linear-gradient(135deg, #3fb950 0%, #2da44e 100%);
  border-color: #2da44e;
}
.light-theme .progress-bar {
  background: linear-gradient(90deg, #1a7f37, #2da44e);
}
.light-theme .debug-log.warn .level { color: #9a6700; }
.light-theme .debug-log.error .level { color: #cf222e; }
.light-theme .debug-session.crashed .debug-session-header {
  background: #ffebe9;
  border-left-color: #cf222e;
}
.light-theme .debug-session.running .debug-session-header {
  background: #dafbe1;
  border-left-color: #1a7f37;
}
