:root {
  --bg:#16120E; --surface:#1f1a15; --surface2:#2a231b;
  --border:rgba(200,169,110,0.18); --border-strong:rgba(200,169,110,0.45);
  --gold:#C8A96E; --gold-dark:#a8894e;
  --cream:#F5E6C8; --text:#F5E6C8; --text-muted:#a89070; --text-faint:#6b5a42;
  --danger-bg:#2a1212; --danger:#e06060;
  --radius:10px; --radius-sm:6px;
}

*{box-sizing:border-box;margin:0;padding:0;}

body {
  background:var(--bg); color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  min-height:100vh; display:flex; align-items:flex-start;
  justify-content:center; padding:2rem 1rem 4rem;
}

.container { width:100%; max-width:720px; }

/* ── Brand ── */
.brand { display:flex; align-items:center; gap:12px; margin-bottom:1.75rem; }
.brand-icon { width:36px; height:36px; border-radius:8px; background:var(--gold); display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.brand-name { font-size:15px; font-weight:600; color:var(--cream); }
.brand-sub  { font-size:12px; color:var(--text-muted); margin-top:1px; }

/* ── Phases ── */
.phase { display:none; }
.phase.active { display:block; }
h3 { font-size:12px; font-weight:600; letter-spacing:.07em; text-transform:uppercase; color:var(--gold); margin-bottom:10px; }

/* ── Upload ── */
.upload-zone {
  border:0.5px dashed var(--border-strong); border-radius:var(--radius-sm);
  padding:3rem 1rem; text-align:center; cursor:pointer;
  background:var(--surface2); transition:border-color .15s, background .15s;
}
.upload-zone:hover { border-color:var(--gold); background:#231d16; }
.upload-title { font-size:14px; font-weight:500; color:var(--text-muted); margin-bottom:4px; }
.upload-hint  { font-size:12px; color:var(--text-faint); }
#fileInput { display:none; }

/* ── Canvas wrap ── */
.canvas-wrap {
  position:relative; border-radius:var(--radius-sm); overflow:hidden;
  border:0.5px solid var(--border-strong); background:#000; line-height:0;
}
.canvas-wrap canvas { display:block; width:100%; height:auto; touch-action:none; }

/* ── Reference image panel ── */
.ref-image-panel {
  background:var(--surface2); border:.5px solid var(--border);
  border-radius:var(--radius-sm); overflow:hidden; margin-bottom:16px;
}
.ref-image-label {
  font-size:11px; color:var(--text-faint); padding:8px 12px;
  border-bottom:.5px solid var(--border);
}
.ref-image { width:100%; display:block; }

/* ── Controls ── */
.ctrl-row { display:flex; align-items:center; gap:10px; margin-top:12px; flex-wrap:wrap; }
.spacer { flex:1; }

.link-btn {
  font-size:12px; color:var(--text-faint); background:none; border:none;
  cursor:pointer; text-decoration:underline; font-family:inherit; white-space:nowrap;
}
.link-btn:hover { color:var(--text-muted); }

/* ── Hint ── */
.hint {
  background:var(--surface2); border:.5px solid var(--border);
  border-radius:var(--radius-sm); padding:10px 14px;
  font-size:12px; color:var(--text-faint); line-height:1.7; margin-top:12px;
}
.hint strong { color:var(--text-muted); font-weight:500; }

/* ── Count ── */
.count-row { font-size:12px; color:var(--text-muted); margin-top:10px; }
.count-row span { color:var(--gold); font-weight:600; }

/* ── Buttons ── */
.primary-btn {
  flex:1; padding:12px; background:var(--gold); color:#16120E;
  border:none; border-radius:var(--radius-sm); font-size:14px; font-weight:600;
  cursor:pointer; font-family:inherit; margin-top:14px;
  transition:background .15s, opacity .15s;
}
.primary-btn:hover:not(:disabled) { background:var(--gold-dark); }
.primary-btn:disabled { opacity:.4; cursor:not-allowed; }

.secondary-btn {
  display:inline-block; font-size:12px; color:var(--text-faint);
  background:none; border:none; cursor:pointer;
  text-decoration:underline; font-family:inherit; margin-bottom:10px;
}
.secondary-btn:hover { color:var(--text-muted); }

.check-btn {
  padding:7px 16px; background:transparent; color:var(--gold);
  border:.5px solid var(--border-strong); border-radius:var(--radius-sm);
  font-size:12px; font-weight:500; cursor:pointer; font-family:inherit;
  transition:background .15s; white-space:nowrap;
}
.check-btn:hover:not(:disabled) { background:rgba(200,169,110,.1); }
.check-btn:disabled { opacity:.4; cursor:not-allowed; }

/* ── Loading / Error ── */
.loading { display:flex; align-items:center; gap:10px; padding:1rem 0; }
.spinner {
  width:18px; height:18px;
  border:2px solid var(--border-strong); border-top-color:var(--gold);
  border-radius:50%; animation:spin .7s linear infinite; flex-shrink:0;
}
@keyframes spin { to { transform:rotate(360deg); } }
.loading-text { font-size:13px; color:var(--text-muted); }

.error-box {
  font-size:13px; color:var(--danger); padding:10px 14px;
  background:var(--danger-bg); border-radius:var(--radius-sm);
  border:.5px solid rgba(224,96,96,.2); line-height:1.5; margin-top:10px;
}

/* ── Output card ── */
.output-card { background:var(--surface); border:.5px solid var(--border); border-radius:var(--radius); padding:1.25rem; }
.output-header { font-size:11px; font-weight:600; letter-spacing:.08em; text-transform:uppercase; color:var(--text-muted); margin-bottom:16px; display:flex; align-items:center; gap:8px; }
.output-dot { width:6px; height:6px; border-radius:50%; background:var(--gold); }

.section-header {
  font-size:11px; font-weight:600; letter-spacing:.08em; text-transform:uppercase;
  color:var(--gold); margin:20px 0 12px; padding-bottom:6px;
  border-bottom:.5px solid var(--border);
}
.section-header:first-child { margin-top:0; }

/* ── Step cards ── */
.step {
  display:flex; gap:10px; margin-bottom:12px; align-items:flex-start;
  background:var(--surface2); border-radius:var(--radius-sm);
  padding:10px; border:.5px solid var(--border);
}
.step:last-child { margin-bottom:0; }

.step-left { display:flex; flex-direction:column; align-items:center; gap:5px; flex-shrink:0; width:34px; }
.step-num  { width:26px; height:26px; border-radius:50%; background:var(--gold); color:#16120E; font-size:12px; font-weight:700; display:flex; align-items:center; justify-content:center; }
.step-ref  { font-size:10px; color:var(--text-faint); background:var(--surface); border:.5px solid var(--border); border-radius:4px; padding:2px 5px; white-space:nowrap; }
.parts-badge { font-size:8px; letter-spacing:-.3px; background:rgba(80,130,220,.7); color:#fff; width:26px; height:26px; border-radius:50%; display:flex; align-items:center; justify-content:center; }

/* Crop column */
.step-crop-col { flex-shrink:0; display:flex; align-items:flex-start; }

.crop-draw-btn {
  width:28px; height:28px; border-radius:var(--radius-sm);
  background:var(--surface); border:.5px solid var(--border);
  color:var(--text-faint); font-size:14px; cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  transition:border-color .15s, color .15s; font-family:inherit;
  flex-shrink:0;
}
.crop-draw-btn:hover { border-color:var(--gold); color:var(--gold); }

.step-snippet-wrap { position:relative; }
.step-snippet-img {
  display:block; width:80px; height:auto;
  border-radius:4px; border:.5px solid var(--border-strong);
}
.crop-clear-btn {
  position:absolute; top:2px; right:2px; width:16px; height:16px;
  background:rgba(22,14,8,.8); color:var(--text-faint);
  border:.5px solid var(--border); border-radius:3px;
  font-size:9px; cursor:pointer; display:flex;
  align-items:center; justify-content:center;
  opacity:0; transition:opacity .15s; font-family:inherit; padding:0;
}
.step-snippet-wrap:hover .crop-clear-btn { opacity:1; }

.step-content { flex:1; min-width:0; }
.step-title   { font-weight:600; font-size:14px; color:var(--cream); margin-bottom:3px; }
.step-body    { font-size:13px; line-height:1.7; color:var(--text-muted); }
.step-note    { font-size:11px; color:var(--text-faint); font-style:italic; margin-top:3px; }

/* ── Issue flags ── */
.issue-flag { display:flex; align-items:flex-start; gap:7px; margin-top:8px; padding:7px 10px; border-radius:var(--radius-sm); font-size:12px; line-height:1.5; }
.issue-flag.high   { background:rgba(224,96,96,.12); border:.5px solid rgba(224,96,96,.3);   color:#e08080; }
.issue-flag.medium { background:rgba(200,150,50,.1);  border:.5px solid rgba(200,150,50,.3);  color:#c8a050; }
.issue-flag.low    { background:rgba(100,140,100,.1); border:.5px solid rgba(100,140,100,.3); color:#80a880; }
.issue-icon { font-size:13px; flex-shrink:0; margin-top:1px; }
