/* ── Design tokens ── */
:root {
  --bg:        #1e1e2e;
  --surface0:  #181825;
  --surface1:  #313244;
  --surface2:  #45475a;
  --overlay:   #6c7086;
  --text:      #cdd6f4;
  --subtext:   #a6adc8;
  --accent:    #cba6f7;
  --red:       #f38ba8;
  --green:     #a6e3a1;
  --border:    #313244;
  --radius:    6px;
  --toolbar-h: 48px;
  --tools-w:   104px;
  --palette-w: 252px;
  --status-h:  28px;
  --shadow:    0 4px 16px rgba(0,0,0,.5);
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  user-select: none;
}

/* ── App shell ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ──────────────────────────────── TOOLBAR ──────────────────────────────── */
#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  height: var(--toolbar-h);
  background: var(--surface0);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}

.tb-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  border-right: 1px solid var(--border);
}
.tb-group:last-child { border-right: none; }

.brand { gap: 6px; padding-right: 12px; }
.brand-icon { font-size: 18px; }
.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .5px;
}

.tb-label { color: var(--subtext); font-size: 11px; margin-right: 2px; }
.tb-info  { display: inline-block; min-width: 34px; text-align: center; font-size: 12px; }

/* ── Toolbar buttons ── */
.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 10px;
  background: var(--surface1);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.tb-btn:hover  { background: var(--surface2); border-color: var(--overlay); }
.tb-btn.accent { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.tb-btn.accent:hover { filter: brightness(1.1); }
.tb-btn.icon   { width: 28px; padding: 0; font-size: 16px; }
.tb-btn.toggle.active { background: var(--surface2); border-color: var(--accent); color: var(--accent); }
.tb-btn.fw     { width: 100%; }
.tb-btn:disabled { opacity: .4; cursor: default; }

.tb-select {
  height: 28px;
  padding: 0 6px;
  background: var(--surface1);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.tb-select:focus { outline: 1px solid var(--accent); }

/* ──────────────────────────────── WORKSPACE ──────────────────────────────── */
#workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Tools panel (left) ── */
#tools-panel {
  width: var(--tools-w);
  background: var(--surface0);
  border-right: 1px solid var(--border);
  padding: 10px 8px;
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tool-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--overlay);
  padding: 2px 2px 4px;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 44px;
  background: var(--surface1);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 10px;
  font-family: inherit;
  transition: background .12s, border-color .12s, color .12s;
}
.tool-btn svg { width: 18px; height: 18px; fill: currentColor; }
.tool-btn:hover  { background: var(--surface2); }
.tool-btn.active { background: var(--surface2); border-color: var(--accent); color: var(--accent); }

/* Colour area */
.color-swap-area {
  position: relative;
  height: 58px;
  margin: 4px 0;
}
.color-swatch {
  position: absolute;
  width: 40px; height: 40px;
  border: 2px solid var(--surface2);
  border-radius: 4px;
  cursor: pointer;
}
.color-swatch.secondary { top: 16px; left: 44px; z-index: 1; }
.color-swatch.primary   { top: 2px;  left: 2px;  z-index: 2; }
.color-swatch:hover     { border-color: var(--accent); }

.swap-btn {
  position: absolute;
  top: 0; right: 0;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--surface1);
  border: 1px solid var(--surface2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 3;
}
.swap-btn:hover { background: var(--surface2); border-color: var(--accent); }

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.color-picker-row label { font-size: 11px; color: var(--subtext); flex: 1; }
.color-picker-row input[type="color"] {
  width: 32px; height: 24px;
  border: 1px solid var(--surface2);
  border-radius: 4px;
  background: none;
  cursor: pointer;
  padding: 1px;
}

.hex-row { display: flex; align-items: center; gap: 6px; }
.hex-row label { font-size: 11px; color: var(--subtext); }
.hex-field {
  flex: 1;
  height: 24px;
  padding: 0 6px;
  background: var(--surface1);
  border: 1px solid var(--surface2);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-family: monospace;
}
.hex-field:focus { outline: 1px solid var(--accent); }

/* ── Canvas area (centre) ── */
#canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

#canvas-container {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    linear-gradient(45deg, #2a2a3e 25%, transparent 25%),
    linear-gradient(-45deg, #2a2a3e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2a3e 75%),
    linear-gradient(-45deg, transparent 75%, #2a2a3e 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: #252535;
}

#canvas-wrapper {
  position: relative;
  cursor: crosshair;
  box-shadow: var(--shadow);
}

#bg-canvas, #ref-canvas, #main-canvas, #preview-canvas {
  position: absolute;
  top: 0; left: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
#ref-canvas  { image-rendering: auto; }   /* reference stays smooth */
#preview-canvas { cursor: crosshair; }

/* locked layer cursor override */
#canvas-area.layer-locked #preview-canvas { cursor: not-allowed; }

/* Status bar */
#status-bar {
  display: flex;
  align-items: center;
  height: var(--status-h);
  background: var(--surface0);
  border-top: 1px solid var(--border);
  padding: 0 8px;
  font-size: 11px;
  color: var(--subtext);
  flex-shrink: 0;
}
#status-bar span {
  padding: 0 10px;
  border-right: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#status-bar span:last-child { border-right: none; }

/* ── Right panel ── */
#palette-panel {
  width: var(--palette-w);
  background: var(--surface0);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--subtext);
}

.btn-row { display: flex; gap: 4px; }

.small-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  background: var(--surface1);
  border: 1px solid var(--surface2);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.small-btn:hover  { background: var(--surface2); border-color: var(--accent); color: var(--accent); }
.small-btn.active { border-color: var(--accent); color: var(--accent); }

/* ──────────────────────────────── REFERENCE IMAGE ──────────────────────────────── */
.ref-info {
  margin-top: 4px;
}
.ref-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--subtext);
}
#ref-filename {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ref-dims { color: var(--overlay); font-size: 10px; white-space: nowrap; }

.ref-empty {
  font-size: 11px;
  color: var(--overlay);
  text-align: center;
  padding: 8px 0;
  font-style: italic;
}

.ref-reset-btn {
  margin-top: 6px;
  height: 24px;
  font-size: 11px;
  width: 100%;
}

/* ──────────────────────────────── LAYERS ──────────────────────────────── */
#layer-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 4px;
  max-height: 280px;
  overflow-y: auto;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 5px;
  border-radius: 5px;
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 32px;
  transition: background .1s;
}
.layer-row:hover  { background: var(--surface1); }
.layer-row.active { background: var(--surface2); border-color: var(--accent); }
.layer-row.locked-layer .layer-thumb { opacity: .5; }

/* Layer thumbnail */
.layer-thumb {
  width: 24px; height: 24px;
  border-radius: 3px;
  border: 1px solid var(--surface2);
  flex-shrink: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Layer name input */
.layer-name-inp {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
  padding: 1px 3px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.layer-name-inp:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface1);
  cursor: text;
  white-space: normal;
}

/* Layer action buttons */
.lbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  background: transparent;
  border: none;
  border-radius: 3px;
  color: var(--subtext);
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .1s, color .1s;
  line-height: 1;
}
.lbtn:hover   { background: rgba(255,255,255,.08); color: var(--text); }
.lbtn:disabled{ opacity: .3; cursor: default; pointer-events: none; }
.lbtn.del:hover  { color: var(--red); }
.lbtn.vis-off { opacity: .35; }
.lbtn.locked  { color: var(--yellow, #f9e2af); }

/* Shared slider row used in both reference and layer sections */
.slider-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.slider-row label { font-size: 10px; color: var(--subtext); white-space: nowrap; }
.slider-row input[type="range"] {
  flex: 1;
  height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}
.slider-row span  { font-size: 10px; color: var(--subtext); min-width: 30px; text-align: right; }

/* ──────────────────────────────── PALETTE ──────────────────────────────── */
.color-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.palette-swatch {
  width: 20px; height: 20px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,.1);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .1s, border-color .1s;
}
.palette-swatch:hover {
  transform: scale(1.25);
  border-color: var(--accent);
  z-index: 1;
}

/* ── Palette lock indicator (C64 mode) ── */
.palette-lock-note {
  margin-top: 6px;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: .3px;
  text-align: center;
  padding: 3px 0;
  border-top: 1px solid var(--border);
}

/* ──────────────────────────────── LOSPEC ──────────────────────────────── */
.lospec-form { display: flex; flex-direction: column; gap: 4px; }
.lospec-input {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  background: var(--surface1);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}
.lospec-input:focus { outline: 1px solid var(--accent); }
.lospec-tip { font-size: 10px; color: var(--overlay); margin-top: 4px; line-height: 1.4; }

.lospec-results {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.lospec-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 7px;
  background: var(--surface1);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .12s;
}
.lospec-result-item:hover { border-color: var(--accent); }
.lospec-result-name  { font-size: 11px; color: var(--text); }
.lospec-result-count { font-size: 10px; color: var(--overlay); }
.lospec-result-preview { display: flex; gap: 2px; }
.lospec-result-preview span { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }

.lospec-loading { text-align: center; color: var(--overlay); font-size: 11px; padding: 8px 0; }
.lospec-error   { color: var(--red); font-size: 11px; padding: 4px 0; line-height: 1.4; }

/* ──────────────────────────────── MODAL ──────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
#modal-overlay.hidden { display: none; }

#modal {
  background: var(--surface0);
  border: 1px solid var(--surface2);
  border-radius: 10px;
  box-shadow: var(--shadow);
  width: 320px;
  overflow: hidden;
}

.modal-header {
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 600;
  background: var(--surface1);
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-field { display: flex; flex-direction: column; gap: 4px; }
.modal-field label { font-size: 12px; color: var(--subtext); }
.modal-input {
  height: 32px;
  padding: 0 10px;
  background: var(--surface1);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.modal-input:focus { outline: 1px solid var(--accent); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  background: var(--surface1);
  border-top: 1px solid var(--border);
}

/* ──────────────────────────────── TOAST ──────────────────────────────── */
#toast {
  position: fixed;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  background: var(--surface1);
  border: 1px solid var(--surface2);
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
  box-shadow: var(--shadow);
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
}
#toast.hidden  { display: none; }
#toast.error   { border-color: var(--red);   color: var(--red); }
#toast.success { border-color: var(--green); color: var(--green); }

/* ── Mini Preview Window ── */
#mini-preview-box {
  position: absolute;
  bottom: calc(var(--status-h) + 10px);
  right: 10px;
  background: var(--surface0);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 5px;
  box-shadow: var(--shadow);
  z-index: 10;
}
.mini-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 4px;
  cursor: grab;
  user-select: none;
}
.mini-preview-header:active { cursor: grabbing; }
.mini-preview-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--overlay);
  flex: 1;
}
.mini-preview-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}
.preview-scale-select {
  height: 17px;
  font-size: 10px;
  font-family: inherit;
  background: var(--surface1);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: 3px;
  padding: 0 2px;
  cursor: pointer;
}
.preview-scale-custom {
  width: 34px;
  height: 17px;
  font-size: 10px;
  font-family: inherit;
  background: var(--surface1);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: 3px;
  padding: 0 3px;
  text-align: right;
}
.preview-scale-custom:focus { outline: 1px solid var(--accent); }
.preview-close-btn {
  width: 17px;
  height: 17px;
  font-size: 10px;
  line-height: 1;
  background: none;
  color: var(--overlay);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-close-btn:hover { color: var(--text); background: var(--surface2); }
#mini-preview {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 1px solid var(--border);
}

/* ── C64 background colour picker ── */
.c64-palette-picker {
  position: relative;
  display: inline-flex;
}
.c64-picker-btn {
  width: 32px;
  height: 24px;
  border: 1px solid var(--surface2);
  border-radius: 4px;
  background: #000000;
  cursor: pointer;
  padding: 0;
  transition: border-color .15s;
}
.c64-picker-btn:hover { border-color: var(--overlay); }
.c64-picker-dropdown {
  position: fixed;
  display: grid;
  grid-template-columns: repeat(4, 22px);
  gap: 3px;
  padding: 5px;
  background: var(--surface0);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1000;
}
.c64-picker-cell {
  width: 22px;
  height: 22px;
  border: 1px solid var(--surface2);
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  transition: transform .1s, border-color .1s;
}
.c64-picker-cell:hover { transform: scale(1.15); border-color: var(--text); }
.c64-picker-cell.selected { border: 2px solid var(--accent); }

/* ── Modal checkbox / color ── */
.modal-check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.modal-check-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}
/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface0); }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--overlay); }

/* ═══════════════════════════════════════════════════════════
   TRACER MODAL
   ══════════════════════════════════════════════════════════ */

#tracer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#tracer-modal {
  background: var(--surface0);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  width: min(96vw, 1100px);
  height: min(90vh, 760px);
  overflow: hidden;
}

.tracer-header {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.tracer-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  flex: 1;
}
.tracer-close-btn {
  background: none;
  border: none;
  color: var(--subtext);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.tracer-close-btn:hover { background: var(--surface2); color: var(--text); }

.tracer-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Left panel ── */
.tracer-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

.tracer-preview-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tracer-src-info {
  font-size: 11px;
  color: var(--subtext);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

#tracer-canvas-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
  cursor: grab;
  background: #111;
}
#tracer-canvas-wrap.grabbing { cursor: grabbing; }
#tracer-canvas-wrap.no-image { cursor: default; }

#tracer-canvas {
  display: block;
  position: absolute;
  image-rendering: pixelated;
}

.tracer-hint {
  font-size: 10px;
  color: var(--overlay);
  text-align: center;
  padding: 3px;
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

/* ── Right panel ── */
.tracer-right {
  width: 248px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 10px 12px;
  gap: 2px;
}

.tracer-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--overlay);
  margin-bottom: 4px;
}

.tracer-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 6px;
}
.tracer-field label {
  font-size: 11px;
  color: var(--subtext);
}

.tracer-select {
  background: var(--surface1);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 4px 6px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.tracer-select:hover { border-color: var(--overlay); }

.tracer-wh-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tracer-number {
  width: 70px;
  background: var(--surface1);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 4px 6px;
  font-size: 12px;
  font-family: inherit;
}
.tracer-number:focus { outline: none; border-color: var(--accent); }

.tracer-check-field { flex-direction: row; align-items: center; }
.tracer-check-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}
.tracer-check-label input { accent-color: var(--accent); cursor: pointer; }

.tracer-result-box {
  margin-top: 10px;
  flex-shrink: 0;
}
/* Enhancement section */
.tracer-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tracer-enh-reset {
  background: none;
  border: none;
  color: var(--overlay);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
}
.tracer-enh-reset:hover { color: var(--text); }

.tracer-enh-slider {
  display: grid;
  grid-template-columns: 62px 1fr 28px;
  align-items: center;
  gap: 4px;
  margin-bottom: 3px;
}
.tracer-enh-slider label {
  font-size: 11px;
  color: var(--subtext);
  white-space: nowrap;
}
.tracer-enh-slider input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.tracer-enh-slider span {
  font-size: 10px;
  color: var(--subtext);
  text-align: right;
  min-width: 28px;
}
.tracer-enh-invert {
  margin: 4px 0 6px;
}

.tracer-palette-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: 6px;
  max-height: 60px;
  overflow-y: auto;
}
.tracer-palette-swatch {
  width: 16px;
  height: 16px;
  border-radius: 2px;
  border: 1px solid rgba(255,255,255,.12);
  flex-shrink: 0;
}
.tracer-lospec-row {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-bottom: 2px;
}
.tracer-lospec-row .lospec-input { flex: 1; }

#tracer-result-canvas {
  display: block;
  border: 1px solid var(--border);
  border-radius: 4px;
  image-rendering: pixelated;
  max-width: 100%;
  margin-top: 4px;
  background: #111;
}
