:root {
  --bg: #0f1115;
  --bg-2: #161a21;
  --bg-3: #1d222b;
  --line: #2a3140;
  --line-2: #384254;
  --ink: #e8ecf3;
  --ink-2: #a7b1c2;
  --ink-3: #6d7789;
  --accent: #5aa9ff;
  --accent-ink: #06213d;
  --good: #3fbf7f;
  --warn: #e0a03a;
  --bad: #e2564d;
  --brush: #ff45a8;
  --radius: 10px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

/* ---------------------------------------------------------------- header */
.top {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand h1 { font-size: 15px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 3px rgba(90,169,255,.16);
}
.tagline { margin: 0; color: var(--ink-3); font-size: 12.5px; flex: 1; }

/* ---------------------------------------------------------------- stepper */
.steps {
  display: flex; gap: 6px; overflow-x: auto;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.chip {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px 6px 8px; border: 1px solid var(--line);
  border-radius: 100px; background: var(--bg-2);
  color: var(--ink-3); font-size: 12.5px; white-space: nowrap;
  cursor: default;
}
.chip.clickable { cursor: pointer; }
.chip.clickable:hover { border-color: var(--line-2); color: var(--ink-2); }
.chip .n {
  display: grid; place-items: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--bg-3); color: var(--ink-3);
  font-size: 11px; font-variant-numeric: tabular-nums;
}
.chip.done { color: var(--ink-2); border-color: var(--line-2); }
.chip.done .n { background: rgba(63,191,127,.16); color: var(--good); }
.chip.active {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
  font-weight: 600;
}
.chip.active .n { background: rgba(6,33,61,.22); color: var(--accent-ink); }

/* ---------------------------------------------------------------- layout */
.layout {
  display: grid; grid-template-columns: 340px minmax(0, 1fr);
  gap: 1px; background: var(--line);
  min-height: calc(100vh - 108px);
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.panel { background: var(--bg-2); padding: 18px 20px 28px; }
.stage { background: var(--bg); display: flex; flex-direction: column; min-width: 0; }

.stage-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.stage-head h2 { font-size: 13px; color: var(--ink-2); }
.stage-tools { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stage-body { padding: 20px; overflow: auto; flex: 1; min-width: 0; }
.empty { color: var(--ink-3); font-size: 13px; }

/* ---------------------------------------------------------------- forms */
.field { margin-bottom: 16px; }
.field > label {
  display: block; margin-bottom: 6px;
  font-size: 12px; font-weight: 600; color: var(--ink-2);
}
.hint { margin: 6px 0 0; font-size: 11.5px; color: var(--ink-3); }

input[type=text], input[type=number], textarea, select {
  width: 100%; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  color: var(--ink); font: inherit;
}
textarea { resize: vertical; min-height: 130px; font: 12.5px/1.55 var(--mono); }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(90,169,255,.14);
}

.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }

.seg { display: flex; gap: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1; padding: 7px 4px; border: 0; background: var(--bg);
  color: var(--ink-2); font: inherit; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.btn {
  display: inline-block; text-align: center; text-decoration: none;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--bg-3); color: var(--ink); font: inherit; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-ink); font-weight: 600;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.wide { width: 100%; }
button.ghost {
  padding: 6px 11px; border-radius: 7px; border: 1px solid var(--line);
  background: transparent; color: var(--ink-3); font: inherit; cursor: pointer;
}
button.ghost:hover { color: var(--ink); border-color: var(--line-2); }

.file {
  display: block; padding: 22px 14px; text-align: center;
  border: 1px dashed var(--line-2); border-radius: var(--radius);
  background: var(--bg); color: var(--ink-2); cursor: pointer;
}
.file:hover { border-color: var(--accent); color: var(--ink); }
.file input { display: none; }
.file b { display: block; font-size: 13px; color: var(--ink); margin-bottom: 3px; }
.file span { font-size: 11.5px; color: var(--ink-3); }

.actions { display: flex; gap: 8px; margin-top: 18px; }
.actions .btn { flex: 1; }

.divider { height: 1px; background: var(--line); margin: 20px 0; }
.sub { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); margin: 0 0 10px; }

/* ---------------------------------------------------------------- canvas */
.canvas-wrap {
  position: relative; display: inline-block; max-width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: #0b0d11;
  background-image: linear-gradient(45deg, #14171d 25%, transparent 25%, transparent 75%, #14171d 75%),
                    linear-gradient(45deg, #14171d 25%, transparent 25%, transparent 75%, #14171d 75%);
  background-size: 18px 18px; background-position: 0 0, 9px 9px;
}
.canvas-wrap img, .canvas-wrap canvas { display: block; max-width: 100%; height: auto; }
.canvas-wrap canvas { position: absolute; inset: 0; touch-action: none; cursor: crosshair; }

.brushbar { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink-2); }
.brushbar input[type=range] { width: 110px; accent-color: var(--accent); }

/* ---------------------------------------------------------------- grids */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-2); overflow: hidden; cursor: pointer; padding: 0;
  text-align: left; color: inherit; font: inherit;
}
.card:hover { border-color: var(--line-2); }
.card.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(90,169,255,.2); }
.card img { display: block; width: 100%; height: auto; background: #0b0d11; }
.card figcaption {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 8px 10px; font-size: 11.5px; color: var(--ink-3);
  border-top: 1px solid var(--line);
}

.compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.compare figure { margin: 0; }
.compare figcaption { margin-top: 7px; font-size: 11.5px; color: var(--ink-3); }
.compare img {
  display: block; width: 100%; border: 1px solid var(--line);
  border-radius: var(--radius); background: #0b0d11;
}

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 100px;
  font-size: 11.5px; font-weight: 600;
}
.badge.pass { background: rgba(63,191,127,.15); color: var(--good); }
.badge.warn { background: rgba(224,160,58,.15); color: var(--warn); }
.badge.fail { background: rgba(226,86,77,.15); color: var(--bad); }
.badge.info { background: var(--bg-3); color: var(--ink-2); }

.gate {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-2); padding: 16px; margin-top: 18px;
}
.gate h3 { font-size: 13px; margin-bottom: 10px; }
.gate dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0 0; font-size: 12.5px; }
.gate dt { color: var(--ink-3); }
.gate dd { margin: 0; }
.gate pre {
  margin: 6px 0 0; padding: 10px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
  font: 11.5px/1.5 var(--mono); white-space: pre-wrap; color: var(--ink-2);
  max-height: 180px; overflow: auto;
}
.warnbox {
  border: 1px solid rgba(224,160,58,.35); background: rgba(224,160,58,.08);
  border-radius: 8px; padding: 11px 13px; font-size: 12.5px; color: #f0cd97;
  margin-top: 14px;
}

/* ---------------------------------------------------------------- overlay */
.busy {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(9,11,15,.74); backdrop-filter: blur(3px);
}
/* An author `display` declaration beats the UA's [hidden] { display: none },
   so the attribute alone does not hide this. Must be stated explicitly. */
.busy[hidden] { display: none; }
.busy-card {
  text-align: center; padding: 26px 34px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px;
}
.busy-card p { margin: 14px 0 0; font-size: 13px; }
.busy-hint { color: var(--ink-3); font-size: 11.5px !important; margin-top: 5px !important; }
.spinner {
  width: 26px; height: 26px; margin: 0 auto;
  border: 2.5px solid var(--line-2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  z-index: 50; max-width: min(560px, 90vw);
  padding: 11px 16px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: var(--good); color: #06251a; }

a { color: var(--accent); }

/* ============================================================ v2 additions */
.crumb { margin: 0; flex: 1; color: var(--ink-3); font-size: 12.5px; }

/* ---- collapsible sidebar */
.layout { transition: grid-template-columns .18s ease; }
/* The panel must stay IN the grid when collapsed. display:none removes it from
   flow, so the stage slides into the zero-width first track and the whole page
   renders as a sliver. Collapse its box instead. */
body.collapsed .layout { grid-template-columns: 0 minmax(0, 1fr); }
body.collapsed .panel {
  padding: 0; border: 0; min-width: 0; overflow: hidden; visibility: hidden;
}
#collapse { min-width: 30px; font-size: 15px; line-height: 1; }

/* ---- gallery */
.cards.sm { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.cards.md { grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); }
.card { display: flex; flex-direction: column; }
.card-pic {
  display: block; padding: 0; border: 0; background: #0b0d11;
  cursor: pointer; width: 100%;
}
.card-pic img { display: block; width: 100%; height: auto; }
.card figcaption { align-items: center; }
.cap-text { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.cap-text strong { color: var(--ink-2); font-weight: 600; font-size: 11.5px; }
.cap-text span { color: var(--ink-3); font-size: 10.5px; }
.cap-acts { display: flex; gap: 2px; margin-left: auto; }
.icon {
  display: grid; place-items: center; width: 24px; height: 24px;
  border: 1px solid transparent; border-radius: 6px;
  background: transparent; color: var(--ink-3);
  font-size: 13px; cursor: pointer; text-decoration: none;
}
.icon:hover { background: var(--bg-3); color: var(--ink); border-color: var(--line-2); }
.icon.danger:hover { color: var(--bad); border-color: var(--bad); }
.card-badges {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 0 10px 10px; margin-top: -2px;
}
.card-badges .badge { font-size: 10px; padding: 2px 7px; }

/* ---- side by side */
.sbs { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.sbs figure { margin: 0; min-width: 0; }
.sbs img {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: var(--radius); background: #0b0d11;
}
.sbs figcaption { margin-top: 7px; font-size: 11.5px; color: var(--ink-3); }

/* ---- wipe slider */
.wipe {
  position: relative; display: block; width: 100%; max-width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: #0b0d11;
  cursor: ew-resize; touch-action: none; user-select: none;
}
.wipe img { display: block; width: 100%; height: auto; pointer-events: none; }
.wipe-over { position: absolute; inset: 0; }
.wipe-over img { width: 100%; height: 100%; object-fit: fill; }
.wipe-bar {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--accent); pointer-events: none; transform: translateX(-1px);
}
.wipe-grip {
  position: absolute; top: 50%; left: 50%;
  width: 30px; height: 30px; margin: -15px;
  border: 2px solid var(--accent); border-radius: 50%;
  background: rgba(9,11,15,.6);
}
.wipe-tag {
  position: absolute; bottom: 10px; padding: 3px 9px;
  border-radius: 100px; background: rgba(9,11,15,.72);
  font-size: 11px; color: var(--ink-2); pointer-events: none;
}
.wipe-tag.left { left: 10px; }
.wipe-tag.right { right: 10px; }

/* ---- lightbox */
.lb {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column;
  background: rgba(9,11,15,.93); backdrop-filter: blur(4px);
}
.lb-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.lb-head h3 { font-size: 13px; color: var(--ink-2); flex: 1; }
.lb-body { flex: 1; min-height: 0; overflow: auto; padding: 18px; }
/* In the lightbox the media should use the height available, not the width. */
.lb-body .sbs { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
.lb-body .sbs img, .lb-body .wipe { max-height: calc(100vh - 130px); width: auto; margin: 0 auto; }
.lb-body .wipe { max-width: 100%; }
/* Breathing room before each section header in the stage (not the first). */
.stage-body > * + .sub { margin-top: 26px; }
.stage-body > .gate { margin-top: 22px; }

/* ---- independent zoom panes (step 3 / 7 enlarge) */
.zoom-pair {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  height: calc(100vh - 150px);
}
@media (max-width: 820px) { .zoom-pair { grid-template-columns: 1fr; height: auto; }
                            .zp { height: 45vh; } }
.zp {
  position: relative; overflow: hidden; min-height: 220px;
  background: #0b0d11; border: 1px solid var(--line); border-radius: var(--radius);
  cursor: grab; touch-action: none;
}
.zp.grabbing { cursor: grabbing; }
.zp img {
  display: block; transform-origin: 0 0; will-change: transform;
  max-width: none; user-select: none; -webkit-user-drag: none;
}
.zp-hud {
  position: absolute; top: 8px; left: 8px; padding: 3px 9px;
  border-radius: 100px; background: rgba(9,11,15,.78);
  font-size: 11px; color: var(--ink-2); pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.zp-reset {
  position: absolute; top: 8px; right: 8px; padding: 3px 10px;
  border: 1px solid var(--line-2); border-radius: 100px;
  background: rgba(9,11,15,.78); color: var(--ink-2);
  font: inherit; font-size: 11px; cursor: pointer;
}
.zp-reset:hover { color: var(--ink); border-color: var(--accent); }
