:root {
  color-scheme: light;
  --bg: #f3f4f2;
  --panel: #ffffff;
  --ink: #212934;
  --muted: #6d7a93;
  --line: #d7dce3;
  --accent: #193f66;
  --accent-strong: #102f4f;
  --warm: #b28b4c;
  --warn: #b45309;
  --error: #b91c1c;
  --soft: #edf2f7;
  --stone: #e2e2e2;
  --code-bg: #15283d;
  --code-ink: #f2f6fb;
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

.intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
  border-top: 6px solid var(--accent);
  border-bottom: 1px solid var(--line);
  padding: 22px 0 18px;
}

.brand-panel {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  align-items: center;
  gap: 28px;
}

.brand-logo {
  width: 210px;
  height: auto;
  display: block;
  background: #ffffff;
  border: 1px solid #d5dbe3;
  padding: 8px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--warm);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 1.02;
  color: var(--accent);
}

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

.lead {
  max-width: 780px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.55;
}

.status-pill {
  min-width: 148px;
  border: 1px solid #c2cbd6;
  border-radius: 4px;
  padding: 10px 14px;
  background: #ffffff;
  color: var(--accent);
  text-align: center;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.ok {
  background: #edf2f7;
  color: var(--accent);
  border-color: #9fb1c5;
}

.status-pill.error {
  background: #fff1f2;
  color: var(--error);
  border-color: #fecdd3;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 34px rgba(25, 63, 102, 0.08);
}

.instructions {
  padding: 18px 20px;
  margin-bottom: 18px;
  border-left: 6px solid var(--accent);
}

.instructions ol {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.45;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(360px, 500px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.settings-panel,
.output-panel {
  padding: 18px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 14px;
}

.section-head span {
  color: var(--muted);
  font-size: 0.86rem;
}

.dropzone {
  display: grid;
  gap: 8px;
  min-height: 128px;
  align-content: center;
  border: 1px dashed #9fb1c5;
  border-radius: 8px;
  margin-bottom: 18px;
  padding: 22px;
  background: #f9f9fb;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: var(--soft);
}

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

.drop-title {
  color: var(--accent);
  font-weight: 800;
}

.drop-copy,
.label-text,
label span,
.preview-label {
  color: var(--muted);
  font-size: 0.88rem;
}

.field-group {
  margin-bottom: 16px;
}

.settings-section {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 16px;
}

.settings-section:first-of-type {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.settings-section h3 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  color: var(--accent);
}

.label-text {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

.help-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.seg-button {
  min-height: 40px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #f9f9fb;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.seg-button:last-child {
  border-right: 0;
}

.seg-button.active {
  background: var(--accent);
  color: #ffffff;
}

.grid-2,
.grid-3 {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 6px;
}

.field-card {
  align-content: start;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f9f9fb;
}

.field-card span,
.check-row > span {
  color: var(--accent-strong);
  font-weight: 800;
}

.field-card small,
.check-row small,
.metrics small {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 11px;
  background: #ffffff;
  color: var(--ink);
}

input:focus,
textarea:focus,
button:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(25, 63, 102, 0.18);
  outline-offset: 2px;
}

.advanced {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 16px;
}

summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 800;
}

.advanced-summary {
  margin-bottom: 2px;
}

.advanced-grid {
  margin-top: 14px;
}

.check-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f9f9fb;
}

.check-row input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
  color: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

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

button:hover:not(:disabled) {
  filter: brightness(0.98);
}

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

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metrics div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f9f9fb;
}

.metrics span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.metrics strong {
  display: block;
  min-height: 24px;
  margin-bottom: 4px;
  font-size: 1rem;
}

.messages {
  display: grid;
  gap: 8px;
  min-height: 82px;
  margin-bottom: 14px;
}

.messages p {
  margin: 0;
  border-left: 4px solid var(--line);
  padding: 9px 10px;
  background: #f9f9fb;
  color: var(--muted);
  line-height: 1.42;
}

.messages p.ok {
  border-color: var(--accent);
  color: var(--accent);
}

.messages p.warn {
  border-color: var(--warm);
  color: #7a5a25;
}

.messages p.error {
  border-color: var(--error);
  color: var(--error);
  background: #fff5f5;
}

.preview-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 800;
}

textarea {
  min-height: 520px;
  resize: vertical;
  background: var(--code-bg);
  color: var(--code-ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre;
}

.toolpath-viewer {
  margin-top: 24px;
  border-top: 6px solid var(--accent);
  padding-top: 18px;
}

.viewer-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.viewer-head h2 {
  margin: 0;
  color: var(--accent);
  font-size: 1.4rem;
}

.viewer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.viewer-actions button {
  min-height: 36px;
  padding: 0 12px;
  background: #ffffff;
}

.viewer-stage {
  position: relative;
  min-height: 520px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f3f4f2;
  overflow: hidden;
}

#toolpathCanvas {
  display: block;
  width: 100%;
  height: 520px;
  touch-action: none;
}

.viewer-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  background: rgba(243, 244, 242, 0.84);
  text-align: center;
  font-weight: 800;
}

.viewer-empty[hidden] {
  display: none;
}

.viewer-legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  border: 1px solid rgba(25, 63, 102, 0.16);
  background: rgba(255, 255, 255, 0.9);
  padding: 8px 10px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

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

.viewer-legend i {
  width: 18px;
  height: 4px;
  display: inline-block;
}

.legend-cut {
  background: var(--accent);
}

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

.legend-stock {
  background: #9fb1c5;
}

.viewer-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding-top: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.viewer-stats span {
  border-left: 4px solid var(--accent);
  background: #f9f9fb;
  padding: 8px 10px;
}

@media (max-width: 1100px) {
  .instructions ol {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  textarea {
    min-height: 420px;
  }

  .viewer-stage {
    min-height: 420px;
  }

  #toolpathCanvas {
    height: 420px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 18px;
  }

  .intro {
    display: grid;
    align-items: start;
  }

  .brand-panel {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .brand-logo {
    width: min(210px, 100%);
  }

  .status-pill {
    justify-self: start;
  }

  .instructions ol,
  .grid-2,
  .grid-3,
  .metrics,
  .viewer-stats,
  .actions {
    grid-template-columns: 1fr;
  }

  .viewer-head {
    display: grid;
  }

  .viewer-stage {
    min-height: 360px;
  }

  #toolpathCanvas {
    height: 360px;
  }
}
