  :root {
    color-scheme: dark;
    font: 14px system-ui, sans-serif;
    --tool-rail-width: 52px;
    --active-accent: #55dce5;
  }

  * {
    box-sizing: border-box;
  }

  html,
  body {
    height: 100%;
  }

  body {
    margin: 0;
    display: flex;
    flex-direction: column;
    background: #181a20;
    color: #eee;
  }

  header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px 10px calc((var(--tool-rail-width) - 34px) / 2);
    border-bottom: 1px solid #444;
  }

  .app-icon {
    display: block;
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
  }

  h1 {
    font-size: 17px;
    margin: 0;
  }

  #app-tagline {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #aeb3bd;
    font-size: 12px;
  }

  #app-tagline::before {
    content: '—';
    margin-right: 8px;
    color: #7f8590;
  }

  #app-version {
    flex: none;
    margin-left: auto;
    color: #9da3af;
    font: 12px ui-monospace, monospace;
    white-space: nowrap;
  }

  p {
    margin: 3px 0;
    color: #bbb;
  }

  .toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 9px 14px 9px calc((var(--tool-rail-width) - 34px) / 2);
    border-bottom: 1px solid #444;
  }

  button,
  input[type=text],
  input[type=number] {
    font: inherit;
    color: inherit;
    background: #30343e;
    border: 1px solid #5b606b;
    border-radius: 5px;
    padding: 5px 8px;
  }

  button {
    cursor: pointer;
  }

  button:hover {
    background: #454b57;
  }

  button.active {
    background: #0b6572;
    border-color: var(--active-accent);
  }

  button:focus-visible {
    outline: 2px solid #84d7ff;
    outline-offset: 2px;
  }

  button:disabled {
    opacity: .45;
    cursor: default;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    padding: 6px;
    display: inline-grid;
    place-items: center;
    flex: none;
  }

  .icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
  }

  .group-gap {
    width: 14px;
    flex: none;
  }

  #text-preview {
    pointer-events: none;
  }

  #text-entry {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
  }

  .panel-section,
  .panel-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--panel-padding);
  }

  .panel-body {
    padding-inline: var(--panel-padding);
  }

  .panel-section {
    flex: none;
  }

  .panel-section[hidden],
  .panel-body:empty {
    display: none;
  }

  .panel-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    background: #202229;
    min-height: 27px;
    padding-inline: var(--panel-padding);
    padding-block: 5px;
  }

  .panel-actions {
    display: flex;
    gap: 4px;
    margin-left: auto;
  }

  .panel-actions[hidden] {
    display: none;
  }

  .panel-actions .icon-button {
    width: 27px;
    height: 27px;
    padding: 4px;
  }

  .panel-actions .icon {
    width: 17px;
    height: 17px;
  }

  .panel-list {
    gap: 4px;
  }

  .palette-row {
    display: grid;
    gap: 5px;
  }

  .panel-title {
    display: block;
    font-size: 16px;
    font-weight: 700;
  }

  .panel-subtitle {
    color: #c5c8d0;
    font-size: 12px;
    text-transform: uppercase;
  }

  .swatches {
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 3px;
  }

  .swatch {
    min-width: 0;
    height: 20px;
    padding: 0;
    border-radius: 3px;
  }

  #bright-swatches .swatch {
    border-color: #747985;
    box-shadow: inset 0 0 0 1px #0007;
  }

  #bright-swatches .swatch.active {
    outline: 2px solid var(--active-accent);
    outline-offset: 1px;
    border-color: #000;
  }

  .swatch.transparent {
    background: conic-gradient(#777 25%, #ddd 0 50%, #777 0 75%, #ddd 0) 0 0 / 10px 10px;
  }

  .swatch.no-color {
    background: linear-gradient(135deg, transparent 45%, #eee 46%, #eee 54%, transparent 55%), #000;
  }

  .bright-swatch {
    display: grid;
    place-items: center;
  }

  .bright-swatch.active {
    background: #30343e;
  }

  .bright-swatch .icon {
    width: 16px;
    height: 16px;
  }

  .workspace {
    --panel-default-width: 236px;
    --panel-width: var(--panel-default-width);
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: var(--tool-rail-width) minmax(0, 1fr) 6px var(--panel-width);
  }

  .tool-rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px 6px;
    border-right: 1px solid #444;
  }

  .rail-gap {
    height: 10px;
    flex: none;
  }

  .brush-shapes .icon {
    fill: currentColor;
    stroke: none;
  }

  #brush-size-settings>span {
    align-items: baseline;
  }

  .canvas-area {
    position: relative;
    min-width: 0;
    min-height: 0;
  }

  #panel-resizer {
    position: relative;
    cursor: col-resize;
    touch-action: none;
  }

  #panel-resizer::before {
    content: '';
    position: absolute;
    inset: 0 0 0 auto;
    width: 1px;
    background: #444;
  }

  #panel-resizer:hover::before,
  #panel-resizer.dragging::before,
  #panel-resizer:focus-visible::before {
    width: 2px;
    background: #55dce5;
  }

  #panel-resizer:focus-visible {
    outline: none;
  }

  body.resizing-panel {
    cursor: col-resize;
    user-select: none;
  }

  .canvas-controls {
    position: absolute;
    z-index: 6;
    right: 12px;
    bottom: 12px;
    display: flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid #555;
    border-radius: 7px;
    background: #20232cee;
  }

  .canvas-controls button {
    min-width: 34px;
    height: 28px;
    padding: 3px 6px;
  }

  .canvas-controls .icon {
    width: 18px;
    height: 18px;
    vertical-align: middle;
  }

  .navigator-panel {
    flex: none;
    padding: var(--panel-padding);
  }

  #navigator {
    position: relative;
    width: 100%;
    cursor: grab;
    touch-action: none;
    overflow: hidden;
  }

  #navigator[hidden] {
    display: none;
  }

  #navigator.dragging {
    cursor: grabbing;
  }

  #navigator-canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
  }

  #navigator-window {
    position: absolute;
    pointer-events: none;
    border: 1px solid #fff;
    background: #ffffff24;
    box-shadow: 0 0 0 1px #000, inset 0 0 0 1px #0008;
  }

  #viewport {
    width: 100%;
    height: 100%;
    overflow: auto;
    padding: 30px;
    overscroll-behavior: contain;
  }

  #layers-panel {
    --panel-padding: 10px;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  #layers-content {
    min-width: 0;
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--panel-padding);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
  }

  .layer-row {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    padding: 5px;
    border: 1px solid #4d515b;
    border-radius: 5px;
    cursor: grab;
    user-select: none;
    touch-action: none;
  }

  .layer-row.active {
    border-color: #55dce5;
    background: #123b45;
  }

  .layer-row.dragging {
    opacity: .45;
  }

  .layer-row.solo-muted {
    opacity: .24;
  }

  .layer-row.solo-muted:hover {
    opacity: .5;
  }

  .layer-row.solo-muted.dragging {
    opacity: .2;
  }

  .layer-row.drop-before {
    box-shadow: inset 0 3px #55dce5;
  }

  .layer-row.drop-after {
    box-shadow: inset 0 -3px #55dce5;
  }

  .layer-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .layer-eye,
  .layer-solo {
    width: 26px;
    height: 26px;
    padding: 4px;
    display: grid;
    place-items: center;
    flex: none;
  }

  .layer-eye .icon {
    width: 17px;
    height: 17px;
  }

  .layer-solo {
    font: 700 15px/1 ui-monospace, monospace;
  }

  .layer-row .layer-solo.active {
    background: #5a2057;
    border-color: #ff69ed;
    color: #fff;
  }

  .layer-row .icon-button {
    width: 26px;
    height: 26px;
    padding: 4px;
  }

  .layer-row .icon-button .icon {
    width: 16px;
    height: 16px;
  }

  .layer-coords {
    flex: none;
    color: #aeb6c4;
    font: 11px ui-monospace, monospace;
    white-space: nowrap;
  }

  #reference-file {
    display: none;
  }

  .reference-row {
    display: grid;
    grid-template-columns: 26px 32px minmax(0, 1fr) 26px;
    align-items: center;
    gap: 5px;
    padding: 5px;
    border: 1px solid #4d515b;
    border-radius: 5px;
    cursor: grab;
    user-select: none;
    touch-action: none;
  }

  .reference-row.active {
    border-color: #ff40ff;
    background: #3d263e;
  }

  .reference-row.dragging {
    opacity: .45;
  }

  .reference-row.drop-before {
    box-shadow: inset 0 3px #ff40ff;
  }

  .reference-row.drop-after {
    box-shadow: inset 0 -3px #ff40ff;
  }

  .reference-row img {
    width: 32px;
    height: 26px;
    object-fit: contain;
    background: #252830;
    image-rendering: auto;
  }

  .reference-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .reference-row .icon-button {
    width: 26px;
    height: 26px;
    padding: 4px;
  }

  .reference-row .icon {
    width: 16px;
    height: 16px;
  }

  .reference-opacity {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .reference-opacity input {
    width: 100%;
    min-width: 0;
    accent-color: #ff40ff;
  }

  .reference-opacity output {
    width: 4ch;
    text-align: right;
    font: 11px ui-monospace, monospace;
  }

  #text-local-fonts[hidden],
  .trace-toggle[hidden] {
    display: none;
  }

  #text-font {
    box-sizing: border-box;
    margin-top: 0;
    padding: 4px 5px;
    color: #eee;
    background: #30343e;
    border: 1px solid #5b606b;
    border-radius: 4px;
  }

  #text-local-fonts {
    padding: 5px 8px;
    font-size: 12px;
  }

  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .trace-actions {
    display: flex;
    gap: 6px;
  }

  .trace-actions button {
    flex: 1;
  }

  #trace-apply {
    background: #0b6572;
    border-color: #55dce5;
  }

  .trace-control {
    display: block;
  }

  .trace-control[hidden] {
    display: none;
  }

  .trace-control>span {
    display: flex;
    justify-content: space-between;
    gap: 5px;
  }

  .trace-control output {
    min-width: 4ch;
    color: #c5c8d0;
    text-align: right;
    font: 11px ui-monospace, monospace;
  }

  .trace-control input {
    display: block;
    width: 100%;
    margin: 4px 0 0;
    accent-color: #a6a6ff;
  }

  .trace-control select {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 3px 4px;
    color: #eee;
    background: #30343e;
    border: 1px solid #5b606b;
    border-radius: 4px;
  }

  .trace-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #c5c8d0;
    font-size: 12px;
  }

  .trace-toggle input {
    margin: 0;
    accent-color: #a6a6ff;
  }

  @media (max-width: 800px) {
    :root {
      --tool-rail-width: 48px;
    }

    .workspace {
      --panel-default-width: 188px;
    }

    #layers-panel {
      --panel-padding: 6px;
    }

    .panel-actions {
      gap: 3px;
    }

    .panel-actions .icon-button {
      width: 23px;
      height: 23px;
      padding: 3px;
    }

    .panel-actions .icon {
      width: 15px;
      height: 15px;
    }
  }

  #stage {
    position: relative;
    width: 1536px;
    height: 1152px;
    isolation: isolate;
    background: #30343c;
    box-shadow: 0 0 0 1px #666, 0 8px 25px #0008;
  }

  canvas,
  #pixel-overlay,
  #overlay {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100%;
    height: 100%;
  }

  canvas {
    image-rendering: pixelated;
  }

  #reference-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
  }

  #reference-layer img {
    position: absolute;
    display: block;
    max-width: none;
    pointer-events: none;
  }

  #screen {
    cursor: crosshair;
    touch-action: none;
  }

  .picking-paper #screen {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='m3 21 2-6 9-9 4 4-9 9-6 2Z M14.5 6.5 16 5a2.12 2.12 0 0 1 3 3l-1.5 1.5Z M13 5l6 6' fill='white' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") 3 21, crosshair;
  }

  .picking-paper #reference-frame,
  .picking-paper #reference-frame * {
    pointer-events: none;
  }

  #transparency {
    pointer-events: none;
  }

  #pixel-overlay,
  #overlay {
    pointer-events: none;
  }

  #reference-frame {
    position: absolute;
    z-index: 5;
    cursor: move;
    box-shadow: inset 0 0 0 1px #ff40ff;
  }

  #reference-frame[hidden] {
    display: none;
  }

  .reference-edge,
  .reference-handle {
    position: absolute;
    pointer-events: auto;
  }

  .reference-edge {
    cursor: move;
  }

  .reference-edge.top,
  .reference-edge.bottom {
    left: 7px;
    right: 7px;
    height: 6px;
  }

  .reference-edge.top {
    top: -3px;
  }

  .reference-edge.bottom {
    bottom: -3px;
  }

  .reference-edge.left,
  .reference-edge.right {
    top: 7px;
    bottom: 7px;
    width: 6px;
  }

  .reference-edge.left {
    left: -3px;
  }

  .reference-edge.right {
    right: -3px;
  }

  .reference-handle {
    width: 10px;
    height: 10px;
    background: #ff40ff;
    border: 1px solid #fff;
  }

  .reference-handle.nw {
    left: -5px;
    top: -5px;
    cursor: nwse-resize;
  }

  .reference-handle.ne {
    right: -5px;
    top: -5px;
    cursor: nesw-resize;
  }

  .reference-handle.se {
    right: -5px;
    bottom: -5px;
    cursor: nwse-resize;
  }

  .reference-handle.sw {
    left: -5px;
    bottom: -5px;
    cursor: nesw-resize;
  }

  #status-bar {
    height: 40px;
    flex: none;
    padding: 6px 14px;
    border-top: 1px solid #444;
    color: #bbb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    overflow: hidden;
    white-space: nowrap;
  }

  #status {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #document-info {
    display: flex;
    flex: none;
    align-items: center;
    gap: 16px;
    white-space: nowrap;
    font: 12px ui-monospace, monospace;
  }

  #cursor-info {
    display: flex;
    flex: none;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
  }

  #cursor-coords {
    display: inline-block;
    flex: none;
    width: 17ch;
    margin-right: 8px;
    font: 12px ui-monospace, monospace;
  }

  .cursor-swatch {
    display: inline-block;
    width: 15px;
    height: 15px;
    border: 1px solid #888;
    border-radius: 2px;
    box-shadow: 0 0 0 1px #111;
  }

  .cursor-swatch.transparent {
    background: conic-gradient(#777 25%, #ddd 0 50%, #777 0 75%, #ddd 0) 0 0 / 8px 8px;
  }

  #cursor-ink,
  #cursor-paper {
    margin-right: 9px;
  }

  #cursor-bright {
    width: 15px;
    height: 15px;
  }

  #shape-measure {
    display: none;
    position: fixed;
    z-index: 20;
    pointer-events: none;
    padding: 4px 7px;
    border: 1px solid #666;
    border-radius: 4px;
    background: #252a33ee;
    color: #fff;
    font: 12px ui-monospace, monospace;
    white-space: nowrap;
    box-shadow: 0 2px 8px #0008;
  }

  #file,
  #project-file {
    display: none;
  }

  .editor-dialog {
    width: min(390px, calc(100vw - 32px));
    padding: 18px;
    border: 1px solid #656c78;
    border-radius: 10px;
    background: #282c36;
    color: #eee;
    box-shadow: 0 16px 50px #0009;
  }

  .editor-dialog::backdrop {
    background: #0009;
  }

  .editor-dialog h2 {
    margin: 0 0 10px;
    font-size: 17px;
  }

  .editor-dialog p {
    margin: 0 0 18px;
  }

  .editor-dialog input[type=text] {
    width: 100%;
    height: 36px;
    margin-bottom: 8px;
  }

  .size-options {
    display: grid;
    gap: 10px;
    margin: 0 0 12px;
    padding: 10px;
    border: 1px solid #555;
    border-radius: 6px;
  }

  .size-options label {
    display: flex;
    align-items: center;
    gap: 7px;
  }

  .size-options input[type=number] {
    width: 66px;
  }

  .dialog-error {
    min-height: 19px;
    margin-bottom: 10px;
    color: #ff9292;
    font-size: 12px;
  }

  .dialog-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
  }

  .dialog-actions button {
    padding: 7px 10px;
  }

  #new-save,
  #name-accept {
    background: #0b6572;
    border-color: #55dce5;
  }
