:root {
  --bg: #0b0b0f;
  --panel: #13131a;
  --panel-2: #1a1a23;
  --line: #262632;
  --text: #f5f5f5;
  --muted: #8b8b9a;
  --accent: #e4572e;
  --danger: #ff3b5c;
  --radius: 6px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font: 13px/1.4 system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
}

/* ---------- panel ---------- */

.panel {
  width: 280px;
  flex: none;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 14px 14px 24px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.brand strong {
  font-size: 16px;
}

.brand span {
  color: var(--muted);
}

section {
  display: grid;
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

section:last-of-type {
  border-bottom: 0;
}

h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.field {
  display: grid;
  grid-template-columns: 78px 1fr 64px;
  align-items: center;
  gap: 8px;
}

.field label {
  color: var(--muted);
}

.field select,
.field input[type='text']:only-of-type {
  grid-column: 2 / 4;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}

input[type='number'],
input[type='text'],
select {
  width: 100%;
  min-width: 0;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 6px;
  font: inherit;
}

input[type='color'] {
  width: 100%;
  height: 28px;
  padding: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn,
.seg button,
.hud button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  font: inherit;
  cursor: pointer;
}

.btn:hover:not(:disabled),
.seg button:hover,
.hud button:hover {
  border-color: #3a3a4a;
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn.small {
  padding: 5px 8px;
  font-size: 12px;
}

.row {
  display: flex;
  gap: 6px;
}

.row .btn {
  flex: 1;
}

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

.seg button.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, var(--panel-2));
}

kbd {
  font: 10px ui-monospace, monospace;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
  margin-left: 4px;
}

/* ---------- viewport ---------- */

.viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  touch-action: none;
  background-color: #1b1b22;
  background-image:
    linear-gradient(45deg, #202029 25%, transparent 25%),
    linear-gradient(-45deg, #202029 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #202029 75%),
    linear-gradient(-45deg, transparent 75%, #202029 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  cursor: crosshair;
  user-select: none;
}

.viewport.space {
  cursor: grab;
}

.viewport.panning {
  cursor: grabbing;
}

.viewport.dragging {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  display: none;
}

.viewport.has-image .stage {
  display: block;
}

.stage img,
.stage svg,
.preview,
.preview svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.stage svg {
  overflow: visible;
}

#lines path.hover {
  fill: var(--danger);
}

#hits path {
  pointer-events: stroke;
}

.viewport:not([data-tool='erase']) #hits,
.viewport.space #hits {
  display: none;
}

.preview {
  pointer-events: none;
}

.viewport.previewing #draw {
  visibility: hidden;
}

.empty {
  position: absolute;
  inset: 24px;
  display: grid;
  place-content: center;
  gap: 6px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.empty strong {
  color: var(--text);
  font-size: 16px;
}

.viewport.has-image .empty {
  display: none;
}

.hud {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.hud button {
  padding: 3px 8px;
}

#zoom-label {
  min-width: 48px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.hint {
  position: absolute;
  left: 12px;
  bottom: 12px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.viewport:not(.has-image) .hud,
.viewport:not(.has-image) .hint {
  display: none;
}
