:root {
  --bg: #0f1115;
  --bg-raised: #161922;
  --bg-inset: #0b0d12;
  --line: #262b38;
  --line-soft: #1c202b;
  --text: #e8eaf1;
  --text-dim: #9299ac;
  --text-faint: #5c637a;
  --accent: #ff7a45;
  --accent-dim: #ff7a4533;
  --accent-strong: #ffa172;
  --anchor: #ffd166;
  --control: #5ec6ff;
  --ok: #6fd18a;
  --danger: #ff6b6b;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg-raised), var(--bg));
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  color: var(--accent);
  flex: none;
}
.brand-mark circle { fill: var(--anchor); }

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-text p {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-faint);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  flex: 1;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.tool-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool-btn svg circle { fill: currentColor; stroke: none; }

.tool-btn:hover { color: var(--text); background: var(--line-soft); }
.tool-btn.active { color: #1a1305; background: var(--accent); }
.tool-btn.active svg circle { fill: #1a1305; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 7px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
}
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--line-soft); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn.text-btn { width: auto; padding: 0 8px; font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }

.toggles { gap: 12px; padding: 0 10px; background: transparent; border-color: transparent; }

.chk {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.chk input { accent-color: var(--accent); width: 14px; height: 14px; }
.chk.small { font-size: 11.5px; }

/* ---------- workspace ---------- */

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

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

.stage-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  border-right: 1px solid var(--line);
}

@media (max-width: 900px) {
  .stage-wrap { flex: none; border-right: none; border-bottom: 1px solid var(--line); height: 56vh; }
}

.stage-scroll {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.stage {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg-inset);
  touch-action: none;
  cursor: default;
}

.stage.tool-move, .stage.tool-line { cursor: crosshair; }
.stage.tool-curve { cursor: crosshair; }
.stage.panning { cursor: grabbing; }

.stage-hint {
  position: absolute;
  left: 14px;
  bottom: 12px;
  font-size: 11px;
  color: var(--text-faint);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  pointer-events: none;
  max-width: calc(100% - 200px);
}

.stage-corner {
  position: absolute;
  right: 14px;
  top: 12px;
}

.mini-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-faint);
}

.mini-field input[type="text"], .mini-field select {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 11.5px;
  font-family: var(--mono);
  width: 118px;
}

.mini-field input[type="color"] {
  width: 26px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: none;
  cursor: pointer;
}

.mini-field input[type="range"] {
  accent-color: var(--accent);
  width: 70px;
}

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

.panel {
  width: 380px;
  flex: none;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--bg-raised);
}

@media (max-width: 900px) {
  .panel { width: 100%; flex: 1; min-height: 0; }
}

.panel-block {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
}

.panel-block-head h2 {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 700;
}

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

#presetSelect {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 11.5px;
}

.ghost-btn {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-faint); }
.ghost-btn.copied { color: var(--ok); border-color: var(--ok); }

#pathInput {
  width: 100%;
  resize: vertical;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 9px 10px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
}
#pathInput:focus { outline: none; border-color: var(--accent); }
#pathInput.invalid { border-color: var(--danger); }

.path-status {
  min-height: 15px;
  font-size: 11px;
  margin-top: 6px;
  color: var(--text-faint);
}
.path-status.error { color: var(--danger); }

.output-row { margin-top: 8px; }

.commands-block { flex: 1; min-height: 160px; display: flex; flex-direction: column; }

.count-pill {
  font-size: 10.5px;
  font-family: var(--mono);
  color: var(--text-faint);
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}

.commands-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 2px;
}

.cmd-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 11.5px;
}
.cmd-row:hover { background: var(--line-soft); }
.cmd-row.selected { background: var(--accent-dim); border-color: var(--accent); }

.cmd-badge {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 11px;
  background: var(--bg-inset);
  color: var(--text-dim);
  border: 1px solid var(--line);
}
.cmd-row.selected .cmd-badge { color: var(--accent-strong); border-color: var(--accent); }

.cmd-coords {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmd-row.selected .cmd-coords { color: var(--text); }

.cmd-arc-fields {
  display: flex;
  gap: 4px;
  align-items: center;
}
.cmd-arc-fields input[type="number"] {
  width: 42px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 10.5px;
  font-family: var(--mono);
}
.cmd-arc-fields label {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 9.5px;
  color: var(--text-faint);
}
.cmd-arc-fields input[type="checkbox"] { accent-color: var(--accent); width: 11px; height: 11px; }

.cmd-del {
  flex: none;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.cmd-del:hover { color: var(--danger); background: var(--line-soft); }
.cmd-del:disabled { visibility: hidden; }

.empty-note {
  color: var(--text-faint);
  font-size: 11.5px;
  padding: 10px 4px;
}

.style-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.style-grid .mini-field { justify-content: space-between; }
.style-grid select {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11.5px;
}

/* ---------- footer ---------- */

.site-foot {
  padding: 12px 20px;
  text-align: center;
  font-size: 12px;
  border-top: 1px solid var(--line);
  color: var(--text-faint);
}
.site-foot a { color: var(--text-dim); text-decoration: none; }
.site-foot a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(12px);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- SVG stage contents (drawn by app.js) ---------- */

.pw-grid-minor { stroke: var(--line-soft); stroke-width: 1; }
.pw-grid-major { stroke: var(--line); stroke-width: 1; }
.pw-axis { stroke: var(--text-faint); stroke-width: 1.2; opacity: 0.5; }

.pw-render-path {
  transition: fill 0.1s, stroke 0.1s;
}

.pw-handle-line {
  stroke: var(--control);
  stroke-width: 1;
  opacity: 0.55;
  fill: none;
  pointer-events: none;
}

.pw-anchor {
  fill: var(--anchor);
  stroke: #1a1305;
  stroke-width: 1.5;
  cursor: grab;
}
.pw-anchor:hover { fill: var(--accent-strong); }
.pw-anchor.selected { fill: var(--accent); stroke: #fff; }
.pw-anchor.m-type { fill: var(--ok); }
.pw-anchor.m-type.selected { fill: var(--ok); stroke: #fff; }

.pw-control {
  fill: var(--control);
  stroke: #06121c;
  stroke-width: 1.2;
  cursor: grab;
  opacity: 0.9;
}
.pw-control.selected { stroke: #fff; }

.pw-midpoint {
  fill: var(--bg-inset);
  stroke: var(--text-faint);
  stroke-width: 1;
  opacity: 0.55;
  cursor: copy;
}
.pw-midpoint:hover { opacity: 1; fill: var(--accent); stroke: var(--accent); }
.pw-midpoint-plus {
  stroke: var(--text-dim);
  stroke-width: 1.3;
  pointer-events: none;
}
.pw-midpoint:hover + .pw-midpoint-plus,
.pw-midpoint-group:hover .pw-midpoint-plus { stroke: #1a1305; }

.pw-arc-hint {
  fill: none;
  stroke: var(--control);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.5;
  pointer-events: none;
}
