:root {
  font: 13px/1.35 system-ui, sans-serif;
  color: #253047;
  background: #f6f7fa;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; }
button { cursor: pointer; }

#workspace {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  outline: none;
  background-color: #fff;
  background-image:
    linear-gradient(to right, var(--grid-major-color, #f1f1f1) 2px, transparent 2px),
    linear-gradient(to bottom, var(--grid-major-color, #f1f1f1) 2px, transparent 2px),
    linear-gradient(to right, var(--grid-minor-color, #f1f1f1) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-minor-color, #f1f1f1) 1px, transparent 1px);
  background-size:
    var(--major-grid-size, 100px) var(--major-grid-size, 100px),
    var(--major-grid-size, 100px) var(--major-grid-size, 100px),
    var(--grid-size, 10px) var(--grid-size, 10px),
    var(--grid-size, 10px) var(--grid-size, 10px);
  background-position: var(--pan-x, 0px) var(--pan-y, 0px);
  touch-action: none;
  user-select: none;

  &.grid-off { background-image: none; }
  &.tool-box { cursor: crosshair; }
  &.panning { cursor: grab; }
  &.panning:active { cursor: grabbing; }
}

#canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  overflow: visible;
  transform-origin: 0 0;
}

.marquee {
  position: absolute;
  border: var(--screen-pixel, 1px) solid #0000ff;
  background: #0000ff18;
  pointer-events: none;
}

.box {
  position: absolute;
  display: flex;
  padding: 3px;
  overflow: visible;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: move;
  border-style: solid;
  user-select: none;

  &.selected {
    &::after {
      content: '';
      position: absolute;
      z-index: 1;
      inset: calc(-1 * var(--box-border-width));
      border: var(--screen-pixel, 1px) solid #0000ff;
      border-radius: inherit;
      pointer-events: none;
    }
  }

  &.drawing, &.placing { opacity: .75; }
  &.placing { z-index: 3; }
}

.box-label { width: 100%; max-height: 100%; overflow: hidden; pointer-events: none; }

#workspace.tool-box .box { cursor: crosshair; }
#workspace.tool-box.alt-move .box { cursor: move; }
#workspace.panning .box { cursor: grab; }
#workspace.panning:active .box { cursor: grabbing; }

.handle {
  position: absolute;
  z-index: 2;
  width: min(var(--handle-size, 9px), 100%);
  height: min(var(--handle-size, 9px), 100%);
  background: #fff;
  border: 1px solid #6746b7;
  border-radius: 2px;
}

.handle[data-handle="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.handle[data-handle="n"] { left: 50%; top: 0; transform: translateX(-50%); cursor: ns-resize; }
.handle[data-handle="ne"] { right: 0; top: 0; cursor: nesw-resize; }
.handle[data-handle="e"] { right: 0; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.handle[data-handle="se"] { right: 0; bottom: 0; cursor: nwse-resize; }
.handle[data-handle="s"] { left: 50%; bottom: 0; transform: translateX(-50%); cursor: ns-resize; }
.handle[data-handle="sw"] { left: 0; bottom: 0; cursor: nesw-resize; }
.handle[data-handle="w"] { left: 0; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

.corner, #inspector, #help-panel {
  background: rgba(255, 255, 255, .97);
  border: 1px solid #ccd2df;
  box-shadow: 0 6px 24px #2834511f;
}

.corner {
  position: fixed;
  z-index: 10;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-radius: 7px;

  & button { min-width: 32px; }
  & button.active { color: #fff; background: #6746b7; border-color: #6746b7; }
  & button:disabled { cursor: default; opacity: .5; }
}

.divider { width: 1px; height: 19px; margin: 0 3px; background: #d7dce7; }
.small-label { color: #69748a; padding: 0 3px; }

#placement-hint {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  margin: 0;
  padding: 7px 10px;
  border-radius: 5px;
  color: #fff;
  background: #253047;
  pointer-events: none;
}

button, select, input {
  border: 1px solid #cbd1de;
  border-radius: 4px;
  background: #fff;
  color: inherit;
}

button { padding: 5px 8px; }
button:hover { border-color: #7658bc; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid #7658bc; outline-offset: 1px; }
input, select { width: 100%; padding: 5px 6px; }

#inspector {
  position: fixed;
  z-index: 10;
  width: 230px;
  padding: 11px;
  border-radius: 7px;

  & header { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
  & header {
    margin: -11px -11px 10px;
    padding: 11px;
    background: #fff;
    border-bottom: 1px solid #e4e6ed;
    border-radius: 6px 6px 0 0;
  }
  & h2 { font-size: 13px; margin: 0 0 7px; }
  & .field { display: block; margin-bottom: 9px; color: #626d82; font-size: 11px; }
  & .field input, .field select { margin-top: 3px; color: #253047; font-size: 13px; }
  & :is(button, input, select):focus-visible { outline: none; border-color: #7658bc; box-shadow: 0 0 0 1px #7658bc; }
}

#help-panel {
  position: fixed;
  z-index: 10;
  top: 12px;
  right: 12px;
  width: 340px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding: 10px 12px;
  border-radius: 7px;
  font-size: 13px;

  & header { display: flex; align-items: center; justify-content: space-between; font-size: 15px; }
  & header button { border: 0; padding: 0 4px; font-size: 18px; line-height: 1; }
  & section { margin-top: 10px; }
  & h2 { margin: 0 0 4px; color: #253047; font-size: 13px; font-weight: 700; }
  & dl { margin: 0; }
  & dl > div { display: grid; grid-template-columns: 135px minmax(0, 1fr); gap: 7px; padding: 4px 0; }
  & dt, & dd { margin: 0; }
  & dd { color: #253047; font-weight: 600; }
  & kbd { font: inherit; color: #253047; }
  & footer { margin-top: 12px; padding-top: 9px; border-top: 1px solid #e4e6ed; color: #626d82; }
  & footer a { color: #6746b7; }
}

*::-webkit-scrollbar { width: 3px; height: 3px; }
*::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
*::-webkit-scrollbar-thumb { background: #9ca7bc; border-radius: 3px; }
*::-webkit-scrollbar-track { background: transparent; }

[hidden] { display: none !important; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.align-fields { margin-bottom: 9px; }
.align-group { min-width: 0; color: #626d82; font-size: 11px; }
.align-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; margin-top: 3px; }
.align-buttons button { display: grid; place-items: center; min-width: 0; height: 29px; padding: 3px; }
.align-buttons button.active { color: #6746b7; background: #f0ebfa; border-color: #6746b7; }
.align-buttons svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.color-fields { border-top: 1px solid #e4e6ed; padding-top: 7px; }
.color-field { display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 6px; margin: 5px 0; }
.canvas-color-field { grid-template-columns: 74px minmax(0, 1fr); }
.color-field button { display: flex; align-items: center; gap: 6px; min-width: 0; text-align: left; }
.swatch-name { overflow: hidden; min-width: 0; white-space: nowrap; text-overflow: ellipsis; }
.chip { flex: none; width: 15px; height: 15px; border: 1px solid #8992a3; border-radius: 3px; background: var(--chip-color); }
.chip.transparent { background: repeating-conic-gradient(#e7e7e7 0 25%, #fff 0 50%) 0 0 / 8px 8px; }
#color-back { padding: 3px 5px; border: 0; background: transparent; color: #6746b7; }
#delete-swatch { padding: 3px 5px; color: #852a34; }
#swatch-list { max-height: 245px; overflow: auto; }
.swatch-row { display: flex; gap: 4px; margin-bottom: 4px; }
#swatch-list > .swatch-choice { margin-bottom: 4px; }
.swatch-choice { display: flex; align-items: center; gap: 8px; width: 100%; min-width: 0; text-align: left; }
.swatch-row .swatch-choice { flex: 1; }
.swatch-edit { flex: none; color: #626d82; }
#new-swatch, #save-swatch { width: 100%; margin-top: 8px; color: #fff; background: #6746b7; border-color: #6746b7; }
.editor-field { display: grid; grid-template-columns: 38px minmax(0, 1fr); align-items: center; gap: 7px; margin: 7px 0; color: #626d82; font-size: 11px; }
.editor-field input, .editor-field select { min-width: 0; color: #253047; font-size: 13px; }
#color-hex { font-family: ui-monospace, monospace; letter-spacing: .06em; }
#color-preview { height: 36px; margin: 9px 0; border: 1px solid #8992a3; border-radius: 4px; background: var(--preview-color); }
.color-channel { display: grid; grid-template-columns: 14px minmax(0, 1fr) 52px; align-items: center; gap: 6px; margin: 8px 0; }
#swatch-editor.gray-mode .color-channel { grid-template-columns: 30px minmax(0, 1fr) 52px; }
.color-channel label { color: #626d82; font-size: 11px; }
.color-channel input[type="range"] { padding: 0; accent-color: #6746b7; }
.color-channel input[type="number"] { text-align: right; }
#color-error { margin: 8px 0 0; color: #852a34; font-size: 11px; }

#notice {
  position: fixed;
  z-index: 20;
  top: 63px;
  left: 12px;
  max-width: 360px;
  margin: 0;
  padding: 8px 10px;
  color: #852a34;
  background: #fff7f7;
  border: 1px solid #e8b5b9;
  border-radius: 5px;
}

.text-editor {
  min-height: 1em;
  outline: none;
  overflow: auto;
  cursor: text;
  pointer-events: auto;
  user-select: text;
}
