/* ── Layout ── */
#upload-section {
  flex: 1;
}
#editor-section {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

/* ── Progress ── */
.progress-wrap {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 64px 24px;
  text-align: center;
  flex: 1;
}

.progress-wrap.show {
  display: flex;
}

.progress-bar-track {
  width: min(360px, 100%);
  height: 6px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Result toolbar ── */
.result-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

.toolbar-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

.bg-label {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.bg-swatch-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.bg-swatch {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
  flex-shrink: 0;
}

.bg-swatch.active {
  border-color: var(--accent);
}
.bg-swatch.transparent {
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Crect width='5' height='5' fill='%23ccc'/%3E%3Crect x='5' y='5' width='5' height='5' fill='%23ccc'/%3E%3Crect x='5' width='5' height='5' fill='%23eee'/%3E%3Crect y='5' width='5' height='5' fill='%23eee'/%3E%3C/svg%3E");
}
.bg-swatch.white {
  background: #fff;
}
.bg-swatch.black {
  background: #111;
}

.bg-color-input {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 2px solid var(--border);
  padding: 0;
  cursor: pointer;
  background: none;
}

.bg-color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}
.bg-color-input::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

/* ── Bg image button ── */
.bg-img-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 2px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface2);
  transition: border-color 0.15s;
  flex-shrink: 0;
  overflow: hidden;
  padding: 0;
}

.bg-img-btn.active {
  border-color: var(--accent);
}

.bg-img-btn canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Brush bar ── */
.brush-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.brush-bar.show {
  display: flex;
}

.brush-mode-btn {
  padding: 5px 12px;
  font-size: 0.82rem;
}
.brush-mode-btn.active {
  background: rgba(var(--accent-rgb), 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Split panel ── */
.panels {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.panel + .panel {
  border-left: 1px solid var(--border);
}

.panel-label {
  padding: 8px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-canvas {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 24px;
  background: var(--bg);
}

.panel-canvas.checkerboard {
  background-color: #2a2a2a;
  background-image:
    linear-gradient(45deg, #333 25%, transparent 25%),
    linear-gradient(-45deg, #333 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #333 75%),
    linear-gradient(-45deg, transparent 75%, #333 75%);
  background-size: 20px 20px;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0px;
}

.panel-canvas img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

/* Result canvas has a coloured background layer */
.result-wrapper {
  position: relative;
  display: inline-block;
  max-width: 100%;
  max-height: 100%;
}

#result-bg-canvas {
  position: absolute;
  inset: 0;
  border-radius: 4px;
}

#result-canvas {
  position: relative;
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
}

@media (max-width: 700px) {
  .panels {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .panel + .panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .result-toolbar {
    gap: 4px;
  }
}
