:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg-soft: #111721;
  --panel: #121924;
  --panel-2: #0e141c;
  --line: #1f2937;
  --line-soft: #18202c;
  --text: #e6edf6;
  --muted: #8b9bb0;
  --accent: #14b8a6;
  --accent-soft: rgba(20, 184, 166, 0.14);
  --danger: #f87171;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

/* Author display rules outrank the UA [hidden] rule, so make it explicit. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(20, 184, 166, 0.09), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(99, 102, 241, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(11, 15, 20, 0.72);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  text-decoration: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text strong {
  color: var(--text);
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand-text small {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 13px;
  min-height: 30px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(139, 155, 176, 0.12);
  flex: none;
}

.status.ready .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.status.busy .status-dot {
  background: #fbbf24;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.16);
  animation: pulse 1.2s ease-in-out infinite;
}

.status.error .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18);
}

.status progress {
  width: 72px;
  height: 4px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  appearance: none;
}

.status progress::-webkit-progress-bar {
  background: var(--line);
  border-radius: 999px;
}

.status progress::-webkit-progress-value {
  background: #fbbf24;
  border-radius: 999px;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

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

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr) 296px;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.panel-head h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.badge {
  font-size: 11px;
  color: var(--muted);
  background: var(--line-soft);
  border-radius: 999px;
  padding: 1px 8px;
  min-width: 22px;
  text-align: center;
}

/* ---------- queue ---------- */

/* ---------- progress bars ---------- */

.bar {
  height: 5px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #0f9c8d, var(--accent));
  transition: width 0.28s ease-out;
}

.bar-lg {
  height: 8px;
}

.batch-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px 0;
}

.batch-text {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.processing {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}

.processing-inner {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  animation: fade-in 0.2s ease-out;
}

.processing-title {
  font-size: 15px;
  color: var(--text);
}

.processing-sub {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.queue-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  background: transparent;
  color: inherit;
  width: 100%;
  text-align: left;
  font: inherit;
  position: relative;
}

.queue-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.queue-item.active {
  background: var(--accent-soft);
  border-color: rgba(20, 184, 166, 0.4);
}

.queue-thumb {
  width: 38px;
  height: 38px;
  border-radius: 7px;
  object-fit: cover;
  flex: none;
  background-color: #0a0e13;
  background-image:
    linear-gradient(45deg, #1b2431 25%, transparent 25%),
    linear-gradient(-45deg, #1b2431 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1b2431 75%),
    linear-gradient(-45deg, transparent 75%, #1b2431 75%);
  background-size: 10px 10px;
  background-position:
    0 0,
    0 5px,
    5px -5px,
    -5px 0;
  border: 1px solid var(--line);
}

.queue-meta {
  min-width: 0;
  flex: 1;
}

.queue-name {
  display: block;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.queue-sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.queue-sub.error {
  color: var(--danger);
}

.queue-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  border: 0;
  background: rgba(0, 0, 0, 0.55);
  color: var(--muted);
  border-radius: 50%;
  width: 18px;
  height: 18px;
  line-height: 1;
  font-size: 13px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.queue-item:hover .queue-remove,
.queue-item.active .queue-remove {
  opacity: 1;
}

.queue-remove:hover {
  color: var(--danger);
}

.spinner {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-soft);
}

.spinner::after {
  content: "";
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(20, 184, 166, 0.28);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

.queue-empty {
  margin: 0;
  padding: 16px 14px;
  font-size: 12px;
  color: var(--muted);
  flex: 1;
}

.queue-actions {
  padding: 10px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ---------- stage ---------- */

.stage-shell {
  background: linear-gradient(180deg, #0d131b, #0a0f15);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.dropzone {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
  border-radius: var(--radius);
  margin: 10px;
  border: 1.5px dashed #263141;
  transition:
    border-color 0.15s,
    background 0.15s;
}

.dropzone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-inner {
  text-align: center;
  max-width: 420px;
}

.dz-icon {
  color: var(--accent);
  opacity: 0.85;
  margin-bottom: 8px;
}

.dropzone h2 {
  margin: 4px 0 6px;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.dz-hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

kbd {
  background: var(--line-soft);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  font: inherit;
  font-size: 11.5px;
  color: var(--text);
}

.dz-note {
  margin: 14px 0 0;
  font-size: 11.5px;
  color: #66788f;
}

.samples {
  margin-top: 20px;
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
}

.samples-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.samples-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 9px;
  flex-wrap: wrap;
}

.sample-btn {
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: none;
  width: 78px;
  height: 78px;
  transition:
    transform 0.15s,
    border-color 0.15s;
}

.sample-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sample-btn:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.stage-canvas-wrap {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 18px;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.canvas-stack {
  position: relative;
  line-height: 0;
}

.checker {
  position: absolute;
  inset: 0;
  border-radius: 4px;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #d8dee6 25%, transparent 25%),
    linear-gradient(-45deg, #d8dee6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d8dee6 75%),
    linear-gradient(-45deg, transparent 75%, #d8dee6 75%);
  background-size: 18px 18px;
  background-position:
    0 0,
    0 9px,
    9px -9px,
    -9px 0;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
}

#preview {
  position: relative;
  z-index: 1;
  display: block;
  border-radius: 2px;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

.wipe-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.6);
  color: var(--text);
  padding: 3px 8px;
  border-radius: 999px;
  pointer-events: none;
}

.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}

.stage-info b {
  color: var(--text);
  font-weight: 500;
}

.compare {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
}

.compare input[type="range"] {
  width: 130px;
}

/* ---------- controls ---------- */

.controls-panel {
  overflow-y: auto;
}

.control-group {
  padding: 14px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-group:last-child {
  border-bottom: 0;
}

.control-group h3 {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 6px 4px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}

.seg button:hover {
  color: var(--text);
}

.seg button.active {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(20, 184, 166, 0.35);
}

.sub {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--c);
  cursor: pointer;
  padding: 0;
}

.swatch.active {
  box-shadow:
    0 0 0 2px var(--bg),
    0 0 0 4px var(--accent);
}

.row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  color: var(--muted);
}

.row > span {
  flex: none;
  min-width: 42px;
}

.row input[type="range"] {
  flex: 1;
  min-width: 0;
}

.row output {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-size: 11.5px;
  min-width: 26px;
  text-align: right;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 20px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #06131a;
  box-shadow: 0 0 0 1px rgba(20, 184, 166, 0.5);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #06131a;
}

input[type="color"] {
  width: 34px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-soft);
  cursor: pointer;
}

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

.btn {
  font: inherit;
  font-size: 12.5px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  padding: 8px 14px;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    transform 0.08s;
}

.btn:hover:not(:disabled) {
  border-color: #2c3a4d;
  background: #16202c;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #04221f;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: #1ecfba;
  border-color: transparent;
}

.btn-ghost {
  background: transparent;
}

.btn-block {
  width: 100%;
}

.hint {
  margin: 0;
  font-size: 11.5px;
  color: #66788f;
  line-height: 1.45;
}

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  pointer-events: none;
}

.toast {
  background: #16202c;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 9px;
  font-size: 12.5px;
  box-shadow: var(--shadow);
  max-width: min(90vw, 460px);
  animation: toast-in 0.18s ease-out;
}

.toast.error {
  border-left-color: var(--danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---------- responsive ---------- */

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 190px minmax(0, 1fr) 264px;
  }
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(340px, 1fr) auto;
  }

  .queue-panel {
    max-height: 168px;
  }

  .queue-list {
    flex-direction: row;
    overflow-x: auto;
  }

  .queue-item {
    min-width: 168px;
  }

  .controls-panel {
    max-height: none;
  }

  .control-group {
    border-bottom: 1px solid var(--line-soft);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- model picker ---------- */

.models {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.models button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s;
}

.models button strong {
  font-size: 12px;
  font-weight: 600;
}

.models button small {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}

.models button:hover:not(:disabled) {
  border-color: #2c3a4d;
}

.models button.active {
  background: var(--accent-soft);
  border-color: rgba(20, 184, 166, 0.55);
}

.models button.active strong {
  color: var(--accent);
}

.models button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- touch-up brush ---------- */

#preview.brush-active {
  cursor: crosshair;
  /* Keep the page from panning or selecting while painting on touch screens. */
  touch-action: none;
  user-select: none;
}

.brush-overlay {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  border-radius: 2px;
  pointer-events: none;
}

.refine-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--accent);
}

.refine-flag::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid rgba(20, 184, 166, 0.3);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

/* Blocks the stage and explains itself while one crop is re-segmented. */
.stage-veil {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 2px;
  background: rgba(9, 11, 15, 0.46);
  backdrop-filter: blur(1.5px);
  -webkit-backdrop-filter: blur(1.5px);
  color: #f4f6f9;
  font-size: 11px;
  line-height: 1.2;
  cursor: progress;
  animation: fade-in 0.12s ease-out;
}

.stage-veil[hidden] {
  display: none;
}

.stage-veil-spin {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

.brush-ring {
  position: absolute;
  z-index: 3;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.92);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.55),
    inset 0 0 0 1px rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -50%);
  pointer-events: none;
  will-change: left, top;
}
