:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #fafafb;
  --border: #e3e5ea;
  --text: #17181c;
  --text-muted: #6b7280;
  --text-faint: #9aa0ac;
  --accent: #6e5bff;
  --accent-hover: #5a46f0;
  --accent-soft: #ece9ff;
  --danger: #ef4444;
  --danger-soft: #fde8e8;
  --success: #16a34a;
  --success-soft: #e3f6e9;
  --canvas-bg: #2a2b30;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.04), 0 10px 28px -12px rgba(20, 20, 30, 0.16);
  --shadow-sm: 0 1px 2px rgba(20, 20, 30, 0.08);
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --surface: #1a1b1f;
    --surface-2: #222328;
    --border: #2d2e35;
    --text: #f3f4f6;
    --text-muted: #9ca3af;
    --text-faint: #6b7280;
    --accent: #7c6ffc;
    --accent-hover: #8f85fc;
    --accent-soft: #252438;
    --danger: #f87171;
    --danger-soft: #3b2222;
    --success: #4ade80;
    --success-soft: #1e3324;
    --canvas-bg: #17181c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 10px 28px -12px rgba(0, 0, 0, 0.5);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

kbd {
  font-family: inherit;
  font-size: 0.85em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.05em 0.45em;
}

a {
  color: var(--accent);
}

/* ---------- App shell ---------- */

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.brand svg {
  color: var(--accent);
}

.engine-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 5px 12px 5px 9px;
  border-radius: 999px;
}

.engine-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}

.engine-status.loading .dot {
  background: #f59e0b;
  animation: pulse 1.2s ease-in-out infinite;
}

.engine-status.ready .dot {
  background: var(--success);
}

.engine-status.error .dot {
  background: var(--danger);
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.5;
    transform: scale(0.8);
  }
}

.layout {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
}

.hidden {
  display: none !important;
}

/* ---------- Dropzone ---------- */

.dropzone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.dropzone-inner {
  width: min(560px, 100%);
  text-align: center;
  padding: 56px 40px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.dropzone.drag-over .dropzone-inner {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.01);
}

.dropzone-icon {
  color: var(--accent);
  margin-bottom: 10px;
}

.dropzone-inner h1 {
  font-size: 22px;
  margin: 6px 0 6px;
}

.dropzone-inner p {
  color: var(--text-muted);
  font-size: 14.5px;
  margin: 0 0 20px;
}

.dropzone-inner .hint {
  margin-top: 18px;
  font-size: 12.5px;
  color: var(--text-faint);
}

.dropzone-error {
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}

.dropzone-error[hidden] {
  display: none;
}

/* ---------- Buttons ---------- */

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  background: var(--text-faint);
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-block {
  width: 100%;
}

/* ---------- Workspace ---------- */

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 76px 1fr 280px;
  min-height: 0;
  width: 100%;
}

/* Queue rail */

.queue {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 10px;
  min-height: 0;
}

.queue-add {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  border: 1.5px dashed var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
  transition: border-color 0.12s ease, color 0.12s ease;
}

.queue-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  width: 100%;
  align-items: center;
  padding-bottom: 8px;
}

.queue-item {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  flex: none;
  background: repeating-conic-gradient(var(--border) 0% 25%, var(--surface-2) 0% 50%) 50% / 10px 10px;
}

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

.queue-item.active {
  border-color: var(--accent);
}

.queue-item .queue-item-remove {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--text);
  color: var(--surface);
  font-size: 11px;
  line-height: 17px;
  text-align: center;
  border: 1.5px solid var(--surface);
  opacity: 0;
  transition: opacity 0.12s ease;
  cursor: pointer;
}

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

.queue-item .queue-item-spinner {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 26, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}

.queue-item .queue-item-spinner .mini-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

.queue-item .queue-item-error {
  position: absolute;
  inset: 0;
  background: rgba(239, 68, 68, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

/* Canvas area */

.canvas-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--canvas-bg);
}

.canvas-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 5px;
  padding-right: 14px;
  border-right: 1px solid var(--border);
}

.tool-group:last-child {
  border-right: none;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.12s ease, color 0.12s ease;
}

.tool-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tool-btn.active {
  background: var(--accent);
  color: #fff;
}

.tool-btn[data-tool="erase"].active {
  background: var(--danger);
}

.tool-btn[data-tool="restore"].active {
  background: var(--success);
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

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

.icon-btn.text-btn {
  width: auto;
  padding: 0 10px;
  font-size: 12.5px;
}

.brush-size-group {
  gap: 8px;
}

.brush-size-group label {
  font-size: 12.5px;
  color: var(--text-muted);
}

.brush-size-group input[type="range"] {
  width: 90px;
}

.value-chip {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 34px;
  text-align: center;
}

.zoom-group {
  gap: 2px;
}

.compare-btn {
  margin-left: auto;
  user-select: none;
}

.compare-btn.active {
  background: var(--accent);
  color: #fff;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: pointer;
  margin-top: -5.5px;
}

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

.panel input[type="range"] {
  background: var(--border);
}

.canvas-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
  cursor: crosshair;
}

.canvas-viewport.panning {
  cursor: grab;
}

.canvas-viewport.grabbing {
  cursor: grabbing;
}

.canvas-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.04) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: var(--canvas-bg);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 12px 40px rgba(0, 0, 0, 0.45);
}

.canvas-stage canvas {
  display: block;
}

.brush-cursor {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, -50%);
  display: none;
  z-index: 5;
}

.brush-cursor.erase {
  border-color: var(--danger);
}

.brush-cursor.restore {
  border-color: var(--success);
}

.viewport-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.5);
  padding: 5px 12px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.3s ease;
}

.processing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 24, 0.72);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #fff;
  z-index: 10;
  text-align: center;
  padding: 20px;
}

.processing-overlay.hidden {
  display: none;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

.processing-overlay p {
  margin: 0;
  font-size: 13.5px;
}

.processing-overlay .progress-sub {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.55);
}

.progress-bar {
  width: 220px;
  height: 6px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* ---------- Side panel ---------- */

.panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 18px 16px;
  overflow-y: auto;
  min-height: 0;
}

.panel-section {
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.panel-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin: 0 0 12px;
  font-weight: 700;
}

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

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  background: var(--c, transparent);
  padding: 0;
  position: relative;
}

.swatch.checker {
  background-image:
    linear-gradient(45deg, var(--border) 25%, transparent 25%),
    linear-gradient(-45deg, var(--border) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--border) 75%),
    linear-gradient(-45deg, transparent 75%, var(--border) 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
  background-color: var(--surface);
}

.swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.custom-swatch {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: conic-gradient(from 0deg, red, yellow, lime, cyan, blue, magenta, red);
}

.custom-swatch input[type="color"] {
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border: none;
  padding: 0;
}

.slider-row {
  display: grid;
  grid-template-columns: 84px 1fr 46px;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.slider-row:last-child {
  margin-bottom: 0;
}

.slider-row output {
  text-align: right;
  font-size: 12px;
  color: var(--text-faint);
}

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

.hint.small {
  font-size: 12px;
  color: var(--text-faint);
  margin: 10px 0 0;
  line-height: 1.5;
}

.about-section {
  border-bottom: none;
}

/* ---------- Footer ---------- */

.footer {
  flex: 0 0 auto;
  text-align: center;
  padding: 8px 12px;
  font-size: 11.5px;
  color: var(--text-faint);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.footer p {
  margin: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 880px) {
  .workspace {
    grid-template-columns: 60px 1fr;
    grid-template-rows: 1fr auto;
  }

  .panel {
    grid-column: 1 / -1;
    border-left: none;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    max-height: 220px;
  }

  .panel-section {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
    flex: 1 1 200px;
  }

  .canvas-toolbar {
    gap: 8px;
  }

  .tool-group {
    padding-right: 8px;
  }

  .brush-size-group input[type="range"] {
    width: 60px;
  }
}
