:root {
  --bg: #0a0a0a;
  --panel: #141414;
  --panel-2: #1c1c1c;
  --ink: #ffffff;
  --muted: #8e8e8e;
  --accent: #c46a3a;       /* corten orange */
  --accent-2: #e08550;     /* hover */
  --accent-deep: #8a4423;
  --chrome-1: #f0f0f0;
  --chrome-2: #9a9a9a;
  --chrome-3: #5a5a5a;
  --line: #262626;
  --steel: #161616;
  --cut: #e8e4d8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", "Segoe UI", sans-serif;
  font-feature-settings: "ss01", "cv11";
}

header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #050505 0%, #0a0a0a 100%);
  position: relative;
}
header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%, var(--accent-deep) 15%,
    var(--accent) 50%, var(--accent-deep) 85%, transparent 100%);
  opacity: 0.5;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 46px; height: 46px; flex-shrink: 0;
  object-fit: contain; display: block;
}
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand-text h1 {
  font-size: 18px;
  font-weight: 900;
  margin: 0;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: #fff;
  line-height: 1;
}
.brand-text .tagline {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

main {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 64px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;  /* sharper, more industrial */
  padding: 14px;
  overflow-y: auto;
}

.panel.controls h2 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
  margin: 18px 0 8px;
  font-weight: 700;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.panel.controls h2:first-of-type { margin-top: 0; }

.muted-inline {
  color: var(--muted); font-size: 10px; font-weight: 400;
  text-transform: none; letter-spacing: 0; margin-left: 6px;
}

.row { margin: 6px 0; display: flex; flex-direction: column; gap: 4px; }
.row label {
  font-size: 11px;
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: center;
  letter-spacing: 0.3px;
}
.row output { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11px; }
.row.checkbox label { flex-direction: row; gap: 8px; justify-content: flex-start; }
.row.dims { flex-direction: row; gap: 8px; }
.row.dims label { flex: 1; flex-direction: column; align-items: stretch; }

input[type="number"] {
  background: #0a0a0a;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 6px 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
}
input[type="range"] { width: 100%; accent-color: var(--accent); }

button {
  background: #0a0a0a;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-2);
}
button:disabled { opacity: 0.35; cursor: not-allowed; }

button.primary {
  background: linear-gradient(180deg, var(--accent-2) 0%, var(--accent) 50%, var(--accent-deep) 100%);
  color: #fff;
  border-color: var(--accent-deep);
  text-shadow: 0 1px 0 rgba(0,0,0,0.3);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.15);
}
button.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #f0996a 0%, var(--accent-2) 50%, var(--accent) 100%);
  color: #fff;
}

.row:has(button:not(.seg-btn)) { flex-direction: row; gap: 8px; }
.row:has(button:not(.seg-btn)) button { flex: 1; }

.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
  background: #0a0a0a;
}
.seg-btn {
  flex: 1; background: transparent; border: 0; border-radius: 0;
  color: var(--muted); padding: 7px 4px; font-size: 10px; cursor: pointer;
  letter-spacing: 1px;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

.dropzone {
  display: flex; align-items: center; justify-content: center;
  height: 56px; border: 1.5px dashed var(--line); border-radius: 3px;
  color: var(--muted); font-size: 11px; cursor: pointer; text-align: center;
  padding: 0 12px; transition: border-color 0.15s, color 0.15s;
  text-transform: uppercase; letter-spacing: 1px; font-weight: 600;
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--accent);
  color: var(--accent-2);
  border-style: solid;
}

.generate-box {
  margin-top: 8px;
  padding: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.generate-box input[type="text"] {
  background: #0a0a0a;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 7px 9px;
  font-size: 12px;
  width: 100%;
}
.generate-box input[type="text"]:focus { outline: none; border-color: var(--accent); }
.generate-row {
  display: flex; align-items: center; gap: 8px;
}
.generate-row .checkbox { flex: 1; font-size: 11px; color: var(--muted); }
.generate-row .checkbox label { font-size: 11px; gap: 6px; }
.generate-row button { padding: 7px 14px; }
.generate-box.busy { opacity: 0.6; pointer-events: none; }

.layer-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.layer-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 3px; padding: 6px;
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.layer-row.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.layer-row:hover { background: #232323; }
.layer-row .thumb {
  width: 32px; height: 32px; border-radius: 2px; object-fit: cover;
  background: #000; border: 1px solid var(--line); flex-shrink: 0;
}
.layer-row .layer-name {
  flex: 1; font-size: 12px; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 500;
}
.layer-row .icon-btn {
  background: transparent; border: 0; color: var(--muted);
  padding: 2px 6px; font-size: 14px; line-height: 1;
  text-transform: none; letter-spacing: 0;
}
.layer-row .icon-btn:hover { color: var(--accent-2); border: 0; }
.layer-row.hidden-layer .thumb,
.layer-row.hidden-layer .layer-name { opacity: 0.4; }

.layer-editor.hidden { display: none; }
.layer-editor {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 3px; padding: 10px 12px; margin-top: 8px;
}
.layer-editor h2 { margin-top: 0 !important; }
.layer-cutsize {
  margin: 8px 0 0;
  padding: 6px 8px;
  background: #0a0a0a;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
  min-height: 1.2em;
}
.layer-cutsize strong { color: var(--accent-2); font-weight: 600; }

.status {
  margin-top: 10px; font-size: 10px;
  color: var(--muted); min-height: 1em;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.status.error { color: #ff6b6b; }

.warnings {
  margin-top: 6px; padding: 8px 10px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 3px; font-size: 11px; min-height: 36px;
}
.warnings-empty { margin: 0; color: var(--muted); }
.warning-item {
  display: flex; gap: 7px; align-items: flex-start;
  padding: 5px 0; border-bottom: 1px solid var(--line);
}
.warning-item:last-child { border-bottom: 0; }
.warning-item .dot {
  width: 7px; height: 7px; border-radius: 50%;
  margin-top: 5px; flex-shrink: 0;
}
.warning-item .dot.high { background: #ff5f5f; box-shadow: 0 0 6px rgba(255,95,95,0.6); }
.warning-item .dot.medium { background: var(--accent); box-shadow: 0 0 6px rgba(196,106,58,0.5); }
.warning-item .text { flex: 1; line-height: 1.4; color: var(--ink); }
.warning-item .meta { color: var(--muted); font-size: 10px; margin-top: 2px; }
.warnings.clean p { margin: 0; color: #58c97c; font-weight: 500; }

.panel.canvas { display: flex; flex-direction: column; gap: 8px; padding: 10px; }

.stage {
  position: relative; flex: 1;
  background:
    radial-gradient(circle at 50% 50%, #1a1a1a 0%, #0a0a0a 100%);
  border: 1px solid var(--line);
  border-radius: 3px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.stage-inner {
  position: relative;
  background: #b8b8b8;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.05) inset,
    0 4px 24px rgba(0,0,0,0.6);
}
.stage.steel .stage-inner {
  background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 50%, #1a1a1a 100%);
}

.stage-inner .layer-preview {
  position: absolute;
  pointer-events: auto;
  user-select: none;
  -webkit-user-drag: none;
  cursor: grab;
  outline: 1px dashed transparent;
  outline-offset: 2px;
}
.stage-inner .layer-preview.selected {
  outline-color: var(--accent);
}
/* Layer preview reflects polarity so the canvas tells the truth at a glance:
   - CUT (subtract): cream fill = this area will become a hole.
   - KEEP (add): dark fill blending into the steel bg, green outline marks
     the boundary. = this area will stay as steel. */

.stage.steel .stage-inner .layer-preview.polarity-add img {
  filter: brightness(0.18) saturate(0);
}
.stage:not(.steel) .stage-inner .layer-preview.polarity-add img {
  /* In non-steel ("schematic") mode, KEEP layers show as a light gray fill
     so they read as steel against the gray panel background. */
  filter: brightness(0) saturate(0) invert(1) opacity(0.5);
}
.stage-inner .layer-preview.polarity-add {
  outline-color: #58c97c;
  outline-width: 2px;
  outline-style: solid;
}
.stage-inner .layer-preview.polarity-add.selected {
  outline-color: var(--accent);
}

.stage-inner .layer-preview.polarity-add::before {
  content: "KEEP";
  position: absolute;
  top: -10px; left: 0;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #58c97c;
  background: rgba(0,0,0,0.85);
  padding: 1px 5px;
  border-radius: 2px;
  pointer-events: none;
}
.stage-inner .layer-preview.polarity-subtract::before {
  content: "CUT";
  position: absolute;
  top: -10px; left: 0;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--accent-2);
  background: rgba(0,0,0,0.85);
  padding: 1px 5px;
  border-radius: 2px;
  pointer-events: none;
}
.stage-inner .layer-preview.dragging { cursor: grabbing; }
.stage-inner .layer-preview img {
  width: 100%; height: 100%;
  display: block; pointer-events: none;
}
.stage:not(.steel) .stage-inner .layer-preview img {
  /* Tint cream cutouts to corten when in cutouts mode */
  filter: brightness(0) saturate(100%) invert(43%) sepia(46%) saturate(923%) hue-rotate(347deg) brightness(91%) contrast(89%);
}

#traceSvg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
#traceSvg path { fill: var(--accent); fill-rule: evenodd; }
.stage.steel #traceSvg path { fill: var(--cut); }

#warningOverlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  image-rendering: pixelated;
}
.stage.show-warnings #warningOverlay { opacity: 0.85; }

#measureSvg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
  display: none;
}
.stage.measuring #measureSvg { display: block; }
#measureSvg line {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  filter: drop-shadow(0 0 4px rgba(196,106,58,0.7));
}
#measureSvg circle {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 1.5;
}
.stage.measuring { cursor: crosshair; }
.stage.measuring .layer-preview { pointer-events: none; }

.measure-label {
  position: absolute;
  background: rgba(0,0,0,0.85);
  color: var(--accent-2);
  border: 1px solid var(--accent);
  padding: 4px 8px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
  pointer-events: none;
  display: none;
  transform: translate(8px, -50%);
  white-space: nowrap;
  z-index: 5;
}
.stage.measuring .measure-label { display: block; }

#measureBtn.active {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff;
  border-color: var(--accent-deep);
  text-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

/* Crop modal */
.crop-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  padding: 24px;
  gap: 12px;
}
.crop-modal.hidden { display: none; }
.crop-title {
  color: var(--ink); margin: 0 0 4px;
  font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 2px;
}
.crop-help {
  color: var(--muted); margin: 0 0 12px;
  font-size: 11px; letter-spacing: 0.5px;
  text-transform: uppercase;
}
.crop-area {
  position: relative;
  background: #000;
  cursor: crosshair;
  user-select: none;
  border: 1px solid var(--line);
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.crop-area img {
  display: block;
  max-width: 80vw; max-height: 65vh;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.crop-rect {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(196,106,58,0.12);
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.6);
  pointer-events: none;
  display: none;
}
.crop-rect.visible { display: block; }
.crop-dim {
  position: absolute;
  background: rgba(0,0,0,0.85);
  color: var(--accent-2);
  border: 1px solid var(--accent);
  padding: 4px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  display: none;
  transform: translate(8px, 8px);
}
.crop-rect.visible + .crop-dim,
.crop-area.has-rect .crop-dim { display: block; }
.crop-actions { display: flex; gap: 12px; }

#emptyHint {
  position: absolute; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 2px;
}
.stage.has-layers #emptyHint { display: none; }

.layer-preview .handle {
  position: absolute; right: -7px; bottom: -7px;
  width: 14px; height: 14px;
  background: var(--accent); border: 1px solid #000;
  border-radius: 1px; cursor: nwse-resize;
  box-shadow: 0 0 0 1px var(--chrome-1) inset;
}
.layer-preview:not(.selected) .handle { display: none; }

.stage-meta {
  font-size: 10px; color: var(--muted);
  display: flex; justify-content: flex-end;
  padding: 0 4px; font-variant-numeric: tabular-nums;
  letter-spacing: 1px; text-transform: uppercase;
}
