:root { color-scheme: dark; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
  background: #0e0e10; color: #e8e8ea;
  font-family: system-ui, -apple-system, sans-serif;
}
header, .panel, #toolbar, #status, #paletteWrap { flex-shrink: 0; }
header {
  padding: 10px 20px; border-bottom: 1px solid #26262b;
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
}
header h1 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: .3px; }
.badge { font-size: 11px; padding: 2px 7px; background: #26262b; border-radius: 4px; color: #999; }
.badge.on { background: #1e3a1e; color: #8f8; }
.hdr-label {
  font-size: 11px; display: flex; align-items: center; gap: 5px; color: #b8b8c0;
}
.hdr-select {
  background: #1c1c22; color: #e8e8ea; border: 1px solid #33333a;
  border-radius: 4px; padding: 2px 6px; font-size: 11px;
}

.panel {
  padding: 10px 20px; display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end;
  border-bottom: 1px solid #26262b; background: #131318;
}
.panel label {
  font-size: 12px; color: #b8b8c0;
  display: flex; flex-direction: column; gap: 3px;
}
.panel label.inline-label {
  flex-direction: row; align-items: center; gap: 6px; padding-bottom: 3px;
}
.panel input[type=range] { width: 120px; }
.panel input[type=number] {
  width: 60px; background: #1c1c22; color: #e8e8ea;
  border: 1px solid #33333a; border-radius: 4px; padding: 3px 6px; font-size: 12px;
}
.panel input[type=color] {
  width: 40px; height: 24px; background: #1c1c22; border: 1px solid #33333a;
  border-radius: 4px; padding: 0; cursor: pointer;
}
.panel select {
  background: #1c1c22; color: #e8e8ea; border: 1px solid #33333a;
  border-radius: 4px; padding: 4px 8px; font-size: 12px;
}
.accent { accent-color: #2d6cdf; }
.val { color: #8fd; font-variant-numeric: tabular-nums; }

.denoiseGroup {
  display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap;
  border-left: 1px solid #33333a; padding-left: 14px;
}
.denoiseGroup.off > label:not(:first-child) { opacity: .45; pointer-events: none; }
.gradientGroup {
  display: none; gap: 14px; align-items: flex-end; flex-wrap: wrap;
  border-left: 1px solid #2d6cdf; padding-left: 14px;
  background: rgba(45, 108, 223, 0.06); border-radius: 6px;
  padding: 8px 14px 8px 14px;
}
.gradientGroup.on { display: flex; }

button {
  padding: 6px 13px; font-size: 12px; cursor: pointer;
  background: #2a2a32; color: #e8e8ea;
  border: 1px solid #3a3a44; border-radius: 5px;
}
button:hover:not(:disabled) { background: #33333d; }
button:disabled { opacity: .5; cursor: default; }

#toolbar {
  padding: 8px 20px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  border-bottom: 1px solid #26262b; background: #101015; font-size: 12px;
}
#toolbar button { padding: 4px 10px; font-size: 12px; }
#toolbar button.active { background: #2d6cdf; border-color: #2d6cdf; }
#toolbar .caps { padding: 2px 8px; background: #26262b; border-radius: 4px; color: #b8b8c0; }
#toolbar .caps b { color: #8fd; }
#toolbar label { display: flex; align-items: center; gap: 5px; color: #b8b8c0; }
#toolbar input[type=range] { width: 80px; }
.hex-input {
  width: 76px; background: #1c1c22; color: #e8e8ea;
  border: 1px solid #33333a; border-radius: 4px; padding: 2px 6px;
  font-size: 11px; font-family: ui-monospace, monospace;
}

#drop {
  flex: 1 1 auto; display: flex; align-items: center; justify-content: center;
  margin: 20px; border: 2px dashed #33333a; border-radius: 8px;
  color: #888; cursor: pointer; transition: .15s; font-size: 15px;
}
#drop.over { border-color: #2d6cdf; background: #141a2b; color: #cde; }

.stage { flex: 1 1 auto; min-height: 0; display: flex; gap: 14px; padding: 14px 20px; overflow: hidden; }
.stage > div { flex: 1 1 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.stage h3 { flex-shrink: 0; margin: 0 0 6px 0; font-size: 12px; color: #b8b8c0; font-weight: 500; }
.canvasBox {
  flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center;
  background: #08080a; border: 1px solid #26262b; border-radius: 6px;
  overflow: hidden; position: relative;
}
.cmpWrap { position: relative; display: inline-block; width: fit-content; height: fit-content; }
.canvasBox canvas, .cmpWrap canvas {
  display: block; image-rendering: pixelated; cursor: zoom-in;
  background-color: #1a1a1a;
  background-image:
    linear-gradient(45deg, #2a2a2a 25%, transparent 25%),
    linear-gradient(-45deg, #2a2a2a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2a2a 75%),
    linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}
body.tool-erase #src, body.tool-restore #src, body.tool-pick #src, body.tool-wand #src { cursor: crosshair; }
#cmp { position: absolute; inset: 0; width: 100%; height: 100%; display: none; image-rendering: pixelated; pointer-events: none; }
#cmpSplit {
  position: absolute; top: 0; bottom: 0; width: 2px; background: #fff;
  display: none; pointer-events: none; box-shadow: 0 0 4px #000;
}
body.compare #cmp, body.compare #cmpSplit { display: block; }
#cmpRange { display: none; margin-top: 4px; width: 100%; }
body.compare #cmpRange { display: block; }
.canvasBox.zoomed {
  position: fixed; inset: 0; z-index: 1000; background: #000;
  border: none; border-radius: 0; padding: 20px; cursor: zoom-out;
}
.canvasBox.zoomed canvas { cursor: zoom-out; }

.fill-swatch {
  display: inline-block; width: 22px; height: 22px;
  border: 1px solid #3a3a44; border-radius: 3px; vertical-align: middle;
  background-color: #1a1a1a;
  background-image:
    linear-gradient(45deg, #2a2a2a 25%, transparent 25%),
    linear-gradient(-45deg, #2a2a2a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2a2a 75%),
    linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
}

#paletteWrap {
  padding: 6px 20px 10px; border-top: 1px solid #1c1c22;
  overflow-x: auto; white-space: nowrap;
}
#paletteWrap h3 { margin: 0 0 5px 0; font-size: 11px; color: #b8b8c0; font-weight: 500; }
#palette { display: inline-flex; gap: 3px; align-items: center; }
#palette div {
  width: 20px; height: 20px; border-radius: 3px; border: 1px solid #2a2a32;
  flex-shrink: 0; cursor: pointer;
}
#palette div:hover { border-color: #8fd; }

#statusBar { height: 3px; background: #26262b; flex-shrink: 0; }
#progress { height: 100%; width: 0%; background: #2d6cdf; transition: width .1s; }
#status { padding: 5px 20px 9px; color: #8f8; font-size: 12px; min-height: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 700px) { .stage { flex-direction: column; } }