.px-app {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.px-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}

.px-demos {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.px-demo-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.px-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.px-chip:hover {
  border-color: var(--primary);
}

.px-chip.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--surface);
}

.px-chip-sm {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.px-top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.px-dropzone {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px dashed var(--border);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.px-dropzone:hover,
.px-dropzone.is-dragover {
  background: var(--surface-alt);
  border-color: var(--primary);
}

.px-drop-copy {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--ink);
}

.px-drop-sub {
  font-size: 13px;
  color: var(--muted);
}

.px-error {
  margin: 12px 16px 0;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--warn);
  background: var(--surface-alt);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

.px-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 1fr);
  align-items: start;
}

.px-stage-col {
  padding: 16px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.px-stage-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.px-view-tabs,
.px-zoom-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.px-region-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--ink);
}

.px-stage-wrap {
  position: relative;
  width: 100%;
  min-height: 360px;
  max-height: 540px;
  overflow: auto;
  border-radius: var(--radius);
  background-color: var(--stage);
  border: 1px solid var(--stage-panel);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  user-select: none;
  touch-action: pan-y;
}

.px-stage-wrap.is-checker {
  background-image:
    linear-gradient(45deg, var(--stage-panel) 25%, transparent 25%),
    linear-gradient(-45deg, var(--stage-panel) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--stage-panel) 75%),
    linear-gradient(-45deg, transparent 75%, var(--stage-panel) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.px-canvas-frame {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
}

.px-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 4px;
  cursor: ew-resize;
}

.px-canvas.is-region-cursor {
  cursor: crosshair;
  touch-action: none;
}

.px-canvas.is-result-cursor {
  cursor: crosshair;
}

.px-split-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--stage);
  pointer-events: none;
  z-index: 4;
}

.px-split-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--surface);
  border: 2px solid var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--shadow-md);
}

.px-stage-badges {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 3;
}

.px-stage-tag {
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--stage-panel);
  color: var(--stage-ink);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--muted);
}

.px-status-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
}

.px-hover-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--border);
  vertical-align: -2px;
  margin-right: 4px;
}

.px-export-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.px-export-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.px-export-btn:hover {
  border-color: var(--primary);
}

.px-export-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--surface);
}

.px-export-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.px-select {
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
}

.px-counts-details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.px-counts-summary {
  padding: 12px 14px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.px-counts-body {
  padding: 0 14px 14px;
  border-top: 1px solid var(--border);
}

.px-counts-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  font-size: 13px;
  color: var(--muted);
}

.px-counts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.px-count-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
}

.px-count-swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.px-count-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.px-count-name {
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.px-count-val {
  font-family: var(--font-mono);
  color: var(--muted);
}

/* Right Controls Column */
.px-controls-col {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.px-group:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.px-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.px-group-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.px-val-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
}

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

.px-palette-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.px-pal-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.px-pal-btn:hover {
  border-color: var(--primary);
}

.px-pal-btn.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--surface);
}

.px-pal-dots {
  display: flex;
  gap: 3px;
}

.px-pal-dot {
  width: 12px;
  height: 8px;
  border-radius: 2px;
  border: 1px solid rgba(17, 24, 39, 0.2);
}

.px-slider-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.px-slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.px-range {
  width: 100%;
  height: 28px;
  accent-color: var(--primary);
  cursor: pointer;
}

.px-check-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--ink);
}

.px-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-height: 36px;
  font-weight: 600;
}

.px-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.px-color-input {
  width: 36px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

@media (max-width: 900px) {
  .px-workspace {
    grid-template-columns: 1fr;
  }
  .px-stage-col {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 640px) {
  .px-topbar,
  .px-dropzone,
  .px-stage-col,
  .px-controls-col {
    padding: 12px;
  }
  .px-stage-wrap {
    min-height: 280px;
    padding: 10px;
  }
  .px-export-primary {
    width: 100%;
  }
  .px-export-btn {
    flex: 1 1 auto;
  }
  .px-range {
    height: 36px;
  }
}