:root {
  color-scheme: dark;
  --bg: #0f1013;
  --panel: #191c21;
  --line: #323742;
  --text: #eceff4;
  --muted: #a8b0bf;
  --accent: #56a8ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: grid;
  grid-template-columns: 340px 1fr;
}

.panel {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: .7rem .8rem;
  overflow: auto;
  height: 100vh;
}

h1 { font-size: 1.08rem; margin: 0 0 .42rem; }
.hint { margin: 0 0 .58rem; color: var(--muted); font-size: .82rem; }
.hidden { display: none !important; }
.group {
  margin: 0;
  padding: .55rem 0;
  border-top: 1px solid #2b3039;
}
.group:first-of-type {
  border-top: 0;
  padding-top: 0;
}
label { display: block; font-size: .82rem; margin-bottom: .25rem; }

button,
input[type='file'],
input[type='number'],
input[type='color'],
input[type='range'],
select {
  width: 100%;
  border-radius: .5rem;
  border: 1px solid #474f60;
  background: #15181d;
  color: var(--text);
  padding: .46rem .52rem;
}

input[type='range'] { padding: .2rem; }
input[type='color'] { padding: .25rem; min-height: 40px; }
.subLabel { margin-bottom: .2rem; color: var(--muted); }
.sectionHeader {
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: .76rem;
  color: #9db5d1;
  font-weight: 700;
  margin-bottom: 0;
}
button { cursor: pointer; transition: background-color .16s ease, border-color .16s ease; }
button:hover { border-color: var(--accent); }
button.active {
  border-color: #82c6ff;
  background: #1f4f82;
  color: #f5fbff;
}
button:disabled { opacity: .45; cursor: not-allowed; }

.row { display: flex; gap: .36rem; align-items: center; }
.stack { flex-direction: column; align-items: stretch; }
.checkRow {
  display: flex;
  align-items: center;
  gap: .36rem;
  font-size: .81rem;
}
.checkRow input[type='checkbox'] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.palette {
  display: flex;
  gap: .24rem;
  flex-wrap: wrap;
}

.colorControl {
  display: flex;
  align-items: center;
  gap: .4rem;
}

.colorControl .palette {
  flex: 1;
}

#replaceColor,
#mergeColorA,
#mergeColorB {
  display: none;
}

input[type='color'].color-block {
  appearance: none;
  -webkit-appearance: none;
  width: 34px;
  min-width: 34px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: .35rem;
  overflow: hidden;
}

input[type='color'].color-block::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type='color'].color-block::-webkit-color-swatch {
  border: 0;
}

input[type='color'].color-block::-moz-color-swatch {
  border: 0;
}

.mergePickers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .42rem;
  margin-bottom: .4rem;
}

.mergeGroup > summary {
  list-style: none;
  cursor: pointer;
  font-size: .82rem;
  line-height: 1.2;
  font-weight: 600;
}

.mergeGroup > summary::-webkit-details-marker {
  display: none;
}

.mergeGroup > summary::after {
  content: '+';
  float: right;
  color: var(--muted);
}

.mergeGroup[open] > summary::after {
  content: '-';
}

.mergeGroup .groupBody {
  margin-top: .45rem;
}

.mergeGroup .groupBody > button + button {
  margin-top: .35rem;
}

.cmykTool {
  margin-top: .2rem;
}

.cmykTool select {
  margin-bottom: .35rem;
}

.cmykGrid {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: .12rem .45rem;
  margin: .25rem 0 .35rem;
}

.cmykGrid .subLabel {
  margin: 0;
  align-self: center;
}

.cmykGrid input[type='range'] {
  --track-gradient: linear-gradient(90deg, #f3f3f3, #1a1a1a);
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  height: 14px;
}

.cmykGrid input[type='range']::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 999px;
  background: var(--track-gradient);
}

.cmykGrid input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  margin-top: -2px;
  border: 1px solid #f6f8fb;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(9, 13, 19, .45);
}

.cmykGrid input[type='range']::-moz-range-track {
  height: 10px;
  border-radius: 999px;
  border: 0;
  background: var(--track-gradient);
}

.cmykGrid input[type='range']::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid #f6f8fb;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(9, 13, 19, .45);
}

.cmykPreviewRow {
  display: flex;
  align-items: center;
  justify-content: stretch;
  gap: .5rem;
  margin: .15rem 0 .45rem;
}

.previewPair {
  flex: 1;
}

.previewPair .subLabel {
  margin-bottom: .2rem;
}
.currentPreviewContainer{
  margin-right: 5px;
  margin-left: auto;
  text-align: right;
}

#cmykPreview,
#workingColorPreview {
  width: 100%;
  height: 68px;
  border-radius: .25rem;
  border: 1px solid #8894a8;
  background: #111111;
}


#workingColorPreview {
  background: #111111;
  width: 50%;
  margin-right: 5px;
  margin-left: auto;
}

.swatch {
  width: 22px;
  height: 22px;
  border: 2px solid #5b6477;
  border-radius: .35rem;
  padding: 0;
}

.swatch.add-swatch {
  display: grid;
  place-items: center;
  background: #000000;
  border-style: dotted;
  border-color: #c9d4e5;
  color: #f6f8fb;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.swatch.add-swatch:hover {
  border-color: #ffffff;
  background: #0b0b0b;
}

.swatch.active {
  outline: 2px solid var(--accent);
  border-color: #fff;
  width: 30px;
  height: 30px;
}

.swatch.multi-active {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .3) inset;
}

.swatch.locked {
  opacity: .55;
  border-style: dashed;
}

.palette-context-menu {
  position: fixed;
  display: none;
  min-width: 140px;
  padding: .3rem;
  background: rgba(16, 20, 27, .98);
  border: 1px solid rgba(157, 181, 214, .25);
  border-radius: .5rem;
  box-shadow: 0 16px 32px rgba(0, 0, 0, .35);
  z-index: 120;
}

.palette-context-menu.active {
  display: grid;
  gap: .2rem;
}

.palette-context-menu button {
  width: 100%;
  min-width: 0;
  padding: .45rem .55rem;
  text-align: left;
  background: rgba(31, 39, 52, .92);
}

.color-dialog {
  border: 1px solid rgba(157, 181, 214, .28);
  border-radius: .8rem;
  padding: 0;
  background: #161a20;
  color: var(--text);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
}

.color-dialog::backdrop {
  background: rgba(6, 8, 11, .68);
}

.color-dialog-body {
  min-width: 240px;
  padding: .85rem;
}

.color-dialog-body .row {
  margin-top: .65rem;
}

.inlineValue {
  color: #bfd9ff;
  font-size: .79rem;
}

.status {
  position: fixed;
  top: 1rem;
  right: 1rem;
  margin: 0;
  max-width: min(620px, calc(100vw - 2rem));
  padding: .55rem .7rem;
  color: #d9ecff;
  font-size: .86rem;
  line-height: 1.3;
  border-radius: .5rem;
  border: 1px solid rgba(95, 156, 218, .55);
  background: rgba(13, 20, 31, .92);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .36);
  z-index: 140;
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.status.show {
  opacity: 1;
  transform: translateY(0);
}

.workspace {
  position: relative;
  min-width: 0;
}

#stageViewport {
  position: absolute;
  inset: 1rem;
  border-radius: .85rem;
  border: 1px solid var(--line);
  overflow: auto;
  overscroll-behavior: contain;
  background: #11141a;
  user-select: none;
  -webkit-user-select: none;
}

#stageContent {
  min-width: 100%;
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 1rem;
}

#canvasWrap {
  --canvas-bg: #ffffff;
  --bg-overlay: none;
  --checker-layer: none;
  position: relative;
  border-radius: 0;
  border: 1px solid rgba(170, 192, 214, .55);
  overflow: hidden;
  background-color: var(--canvas-bg);
  background-image: var(--bg-overlay), var(--checker-layer);
  background-blend-mode: multiply, normal;
}

#canvasWrap.empty-state {
  min-width: min(76vw, 760px);
  min-height: min(76vh, 760px);
}

#canvasWrap.transparent-checker {
  --checker-layer: repeating-conic-gradient(
    rgba(255, 255, 255, .2) 0% 25%,
    rgba(0, 0, 0, .06) 0% 50%
  );
  background-size: 18px 18px;
}

#canvasWrap.strokes-bg {
  --bg-overlay: linear-gradient(rgba(0, 0, 0, .5), rgba(0, 0, 0, .5));
}

#stageViewport,
#stageViewport.pan-enabled,
#stageViewport.panning {
  cursor: default;
}

#svgStage {
  transform-origin: 0 0;
  display: inline-block;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

#emptyCanvasMessage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  text-align: center;
  color: #c8d8ef;
  font-size: 1.2rem;
  letter-spacing: .01em;
  pointer-events: none;
}

#emptyCanvasMessage.hidden {
  display: none;
}

#svgStage svg {
  width: auto;
  height: auto;
  display: block;
  max-width: none;
  box-shadow: 0 0 0 1px rgba(124, 176, 222, .55);
}

#svgStage svg.preview-strokes path,
#svgStage svg.preview-strokes rect,
#svgStage svg.preview-strokes circle,
#svgStage svg.preview-strokes ellipse,
#svgStage svg.preview-strokes polygon,
#svgStage svg.preview-strokes polyline,
#svgStage svg.preview-strokes line {
  fill: none !important;
  stroke: var(--preview-stroke, #4f8cff) !important;
  stroke-width: 1.6pt !important;
}

#svgStage svg .hold-dim {
  opacity: .28;
  filter: grayscale(1) brightness(.6);
}

#svgStage svg .hold-highlight {
  opacity: 1;
  filter: none;
}

#stageViewport.select-mode #svgStage svg .selected-path {
  filter: none;
  stroke: #4da7ff !important;
  stroke-width: 2.25px !important;
  stroke-opacity: 1 !important;
  stroke-linejoin: round !important;
  stroke-linecap: round !important;
  vector-effect: non-scaling-stroke;
  paint-order: stroke fill markers;
}

#stageViewport.select-mode #svgStage svg.preview-strokes .selected-path {
  stroke-width: 3px !important;
}

#cropPreview {
  position: absolute;
  border: 1.5px solid rgba(128, 207, 255, .95);
  background: transparent;
  border-radius: .15rem;
  pointer-events: none;
  display: none;
}

#cropPreview.active { display: block; }

#rotationPivot {
  position: absolute;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  margin-top: -8px;
  border-radius: 999px;
  border: 2px solid #9fd9ff;
  background: rgba(17, 24, 36, .55);
  box-shadow: 0 0 0 1px rgba(10, 14, 21, .8), 0 0 10px rgba(84, 177, 255, .35);
  display: none;
  pointer-events: none;
  z-index: 5;
}

#rotationPivot::before,
#rotationPivot::after {
  content: '';
  position: absolute;
  background: #bde6ff;
}

#rotationPivot::before {
  left: 50%;
  top: -5px;
  width: 2px;
  height: 24px;
  transform: translateX(-50%);
}

#rotationPivot::after {
  top: 50%;
  left: -5px;
  height: 2px;
  width: 24px;
  transform: translateY(-50%);
}

#rotationPivot.active {
  display: block;
}

#selectionMarquee {
  position: absolute;
  border: 1.5px dashed rgba(137, 199, 247, .95);
  background: rgba(127, 187, 234, .15);
  border-radius: .1rem;
  pointer-events: none;
  display: none;
}

#selectionMarquee.active {
  display: block;
}

#selectionLasso {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: none;
  overflow: visible;
}

#selectionLasso.active {
  display: block;
}

#selectionLassoPath {
  fill: rgba(127, 187, 234, .14);
  stroke: rgba(137, 199, 247, .98);
  stroke-width: 1.5;
  stroke-dasharray: 6 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#nodeOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: none;
  overflow: visible;
}

#nodeOverlay.active {
  display: block;
}

#nodeOverlay .node-connector {
  fill: none;
  stroke: rgba(77, 167, 255, .28);
  stroke-width: 1.2;
  stroke-dasharray: 3 3;
}

#nodeOverlay .node-guide {
  fill: none;
  stroke: rgba(77, 167, 255, .42);
  stroke-width: 1.15;
}

#nodeOverlay .node-handle {
  pointer-events: all;
  fill: #ffffff;
  stroke: #4da7ff;
  stroke-width: 2;
  cursor: move;
}

#nodeOverlay .node-handle.anchor {
  rx: 1.5px;
}

#nodeOverlay .node-handle.control {
  fill: rgba(77, 167, 255, .18);
  rx: 999px;
}

#nodeOverlay .node-handle.active {
  fill: #4da7ff;
  stroke: #ffffff;
}

#nodeOverlay .node-handle.anchor.selected {
  fill: #4da7ff;
  stroke: #ffffff;
}

#artboardTransform {
  position: absolute;
  border: 2px solid rgba(130, 205, 255, .95);
  border-radius: .15rem;
  display: none;
  pointer-events: auto;
}

#artboardTransform.active {
  display: block;
}

#artboardTransform .artboard-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid #d7efff;
  background: #2a90d8;
  box-shadow: 0 0 0 1px rgba(10, 14, 21, .7);
}

#artboardTransform .artboard-handle[data-handle='nw'] { left: -6px; top: -6px; cursor: nwse-resize; }
#artboardTransform .artboard-handle[data-handle='n'] { left: calc(50% - 5px); top: -6px; cursor: ns-resize; }
#artboardTransform .artboard-handle[data-handle='ne'] { right: -6px; top: -6px; cursor: nesw-resize; }
#artboardTransform .artboard-handle[data-handle='e'] { right: -6px; top: calc(50% - 5px); cursor: ew-resize; }
#artboardTransform .artboard-handle[data-handle='se'] { right: -6px; bottom: -6px; cursor: nwse-resize; }
#artboardTransform .artboard-handle[data-handle='s'] { left: calc(50% - 5px); bottom: -6px; cursor: ns-resize; }
#artboardTransform .artboard-handle[data-handle='sw'] { left: -6px; bottom: -6px; cursor: nesw-resize; }
#artboardTransform .artboard-handle[data-handle='w'] { left: -6px; top: calc(50% - 5px); cursor: ew-resize; }

#dropOverlay {
  position: absolute;
  inset: 1rem;
  display: none;
  place-items: center;
  background: rgba(8, 10, 14, .75);
  border: 2px dashed var(--accent);
  border-radius: .85rem;
  font-size: 1.4rem;
  font-weight: 600;
}

#dropOverlay.active { display: grid; }

.despeckle-hud {
  position: fixed;
  left: calc(340px + 1.2rem);
  bottom: 4.65rem;
  width: min(360px, calc(100vw - 2rem));
  display: none;
  padding: .45rem .6rem;
  border-radius: .6rem;
  border: 1px solid #4a5669;
  background: rgba(21, 24, 29, .97);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .38);
  z-index: 68;
}

.despeckle-hud.active {
  display: block;
}

.despeckle-hud label {
  margin-bottom: .25rem;
}

.viewport-controls {
  position: fixed;
  left: calc(340px + 1.2rem);
  bottom: 1.3rem;
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  z-index: 50;
}

.viewport-controls button {
  width: auto;
  min-width: 52px;
  background: rgba(21, 24, 29, .92);
  user-select: none;
  -webkit-user-select: none;
}

.viewport-controls #modePanBtn {
  min-width: 48px;
}

.viewport-controls #modeSelectBtn {
  min-width: 48px;
}

.viewport-controls #modeNodeBtn {
  min-width: 48px;
}

.viewport-controls #modeLassoBtn {
  min-width: 48px;
}

.viewport-controls #modeFloodFillBtn {
  min-width: 48px;
}

.viewport-controls #modeColorSwapBtn {
  min-width: 48px;
}

.viewport-controls #deselectAllBtn {
  min-width: 92px;
}

.viewport-controls .iconBtn {
  width: 48px;
  min-width: 48px;
  min-height: 44px;
  padding: .35rem;
  display: inline-grid;
  place-items: center;
}

.viewport-controls .iconGlyphBtn {
  color: #f4f7fb;
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1;
}

.viewport-controls .iconGlyphBtn span {
  pointer-events: none;
}

.viewport-controls .iconBtn img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  pointer-events: none;
}

.viewport-controls .iconBtn.active {
  background: #edf5ff;
  border-color: #1c2d42;
}

.viewport-controls .iconBtn.active img {
  filter: invert(1) brightness(.22);
}

.viewport-controls .iconGlyphBtn.active {
  color: #1c2d42;
}

.viewport-controls #zoomFitBtn {
  min-width: 70px;
}

.rotation-popup {
  position: fixed;
  left: calc(340px + 1.2rem);
  bottom: 5.25rem;
  width: min(320px, calc(100vw - 2rem));
  display: none;
  background: rgba(21, 24, 29, .97);
  border: 1px solid #4a5669;
  border-radius: .6rem;
  padding: .55rem .65rem;
  z-index: 70;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .45);
  user-select: none;
  -webkit-user-select: none;
}

.rotation-popup.active {
  display: block;
}

.rotation-popup label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .55rem;
  margin-bottom: .35rem;
}

.rotation-popup .row {
  margin-top: .45rem;
  justify-content: flex-end;
}

.rotation-popup .row button {
  width: auto;
  min-width: 84px;
}

.floating-download {
  width: auto;
  min-width: 170px;
  z-index: 50;
  box-shadow: 0 12px 26px rgba(0, 0, 0, .42);
  border-color: var(--accent);
}

.floating-actions {
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
  align-items: flex-end;
  z-index: 50;
}

.floating-save {
  background: #1f4f82;
  border-color: #82c6ff;
}

.topControls {
  padding-top: 0;
}

.canvasBlock {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
}

.canvasBgRow {
  display: flex;
  align-items: center;
  gap: .45rem;
  width: 100%;
}

.canvasBgRow .canvasToggle {
  margin: 0;
  width: auto;
  white-space: nowrap;
}

.canvasBgRow button {
  flex: 1;
  width: auto;
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 42vh;
  }

  .mergePickers {
    grid-template-columns: 1fr;
  }

  .viewport-controls {
    left: 1rem;
  }

  .despeckle-hud {
    left: 1rem;
  }

  .rotation-popup {
    left: 1rem;
    bottom: 5.45rem;
  }
}


