:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #657386;
  --line: #d9e0e8;
  --primary: #1164d8;
  --primary-dark: #0b4da8;
  --source: #8b98aa;
  --toolpath: #0f9f75;
  --rapid: #d16522;
  --shadow: 0 16px 48px rgba(22, 33, 47, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 76px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1;
}

h2 {
  font-size: 14px;
  margin-bottom: 12px;
}

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

.compact-control {
  min-width: 82px;
  margin: 0;
}

.compact-control span {
  font-size: 11px;
}

.compact-control select {
  height: 36px;
  padding: 0 8px;
}

button,
.file-button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 750;
}

.primary {
  color: #ffffff;
  background: var(--primary);
}

.primary:hover {
  background: var(--primary-dark);
}

.ghost {
  background: #e9eef5;
  color: #223044;
}

.ghost:hover {
  background: #dde5ef;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.workspace {
  flex: 1;
  min-height: 0;
  height: calc(100vh - 76px);
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
}

.panel {
  border-right: 1px solid var(--line);
  background: var(--panel);
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.controls section {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.drop-zone {
  min-height: 96px;
  border: 1px dashed #aeb9c8;
  border-radius: 8px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  color: var(--muted);
  background: #f8fafc;
  text-align: center;
}

.drop-zone.dragover {
  border-color: var(--primary);
  background: #edf5ff;
}

.drop-zone strong {
  color: var(--ink);
}

.file-meta {
  margin: 14px 0 0;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.file-meta div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid #eef2f6;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
}

label {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid #cfd8e3;
  border-radius: 8px;
  padding: 0 10px;
  background: #ffffff;
  color: var(--ink);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 10px;
}

.control-group {
  border-top: 1px solid #eef2f6;
  padding: 8px 0 4px;
}

.control-group:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.control-group summary {
  cursor: pointer;
  color: #223044;
  font-size: 13px;
  font-weight: 850;
  list-style-position: outside;
  padding: 6px 0;
}

.full {
  width: 100%;
  margin-top: 10px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.stage {
  min-width: 0;
  min-height: 0;
  padding: 18px;
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr) minmax(160px, 28vh);
  gap: 14px;
}

.stage-toolbar {
  min-height: 56px;
  padding: 0 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

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

.view-actions button {
  min-width: 40px;
  min-height: 34px;
}

.stage-toolbar span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  white-space: nowrap;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #344054;
}

.legend i {
  width: 22px;
  height: 3px;
  border-radius: 999px;
  display: inline-block;
}

.legend .source {
  background: var(--source);
}

.legend .toolpath {
  background: var(--toolpath);
}

.legend .entry {
  background: #7c3aed;
}

.legend .rapid {
  background: var(--rapid);
}

.preview-wrap {
  min-width: 0;
  min-height: 0;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

textarea {
  width: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  resize: none;
  color: #132238;
  background: #ffffff;
  font: 12px/1.45 "Cascadia Mono", Consolas, monospace;
}

@media (max-width: 900px) {
  .topbar,
  .stage-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .legend {
    width: 100%;
    flex-wrap: wrap;
  }

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

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

  .stage {
    grid-template-rows: auto 55vh 260px;
  }
}
