:root {
  --bg: #0c0d0f;
  --panel: #17191d;
  --raised: #22252b;
  --line: #2c3037;
  --text: #ebe8e4;
  --muted: #9b9da5;
  --accent: #f0a04b;
  --accent-ink: #1d1206;
  --danger: #ff8f7a;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl, dd, ol, ul { margin: 0; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted, .hint { color: var(--muted); }
.hint { font-size: 13px; text-wrap: pretty; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- top */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
  justify-self: start;
}
.mark {
  width: 18px; height: 18px;
  border-radius: 4px;
  background:
    linear-gradient(135deg, #f0a04b 0 50%, transparent 50%) 0 0 / 9px 9px,
    linear-gradient(225deg, #d7643a 0 50%, transparent 50%) 9px 0 / 9px 9px,
    linear-gradient(45deg, #6fa8dc 0 50%, transparent 50%) 0 9px / 9px 9px,
    linear-gradient(315deg, #8fbf6a 0 50%, transparent 50%) 9px 9px / 9px 9px,
    var(--raised);
  background-repeat: no-repeat;
}
.steps { display: flex; gap: 4px; }
.step-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.step-tab b {
  display: grid;
  place-items: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--raised);
  font-size: 12px;
  font-weight: 600;
}
.step-tab:disabled { cursor: default; opacity: .55; }
.step-tab.done { color: var(--text); }
.step-tab.done b { background: color-mix(in srgb, var(--accent) 30%, var(--raised)); color: var(--text); }
.step-tab.current { color: var(--text); border-color: var(--line); background: var(--panel); }
.step-tab.current b { background: var(--accent); color: var(--accent-ink); }
.engine { justify-self: end; color: var(--muted); font-size: 12.5px; white-space: nowrap; }

/* ---------------------------------------------------------------- steps */
main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.wrap {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 36px 20px 120px;
}
.step-head { max-width: 680px; margin-bottom: 28px; }
.kicker { color: var(--accent); font-size: 12.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
h1 { font-size: clamp(28px, 4vw, 40px); font-weight: 700; letter-spacing: -0.025em; line-height: 1.1; margin: 6px 0 12px; }
.lead { color: var(--muted); font-size: 17px; text-wrap: pretty; }
.label {
  margin: 26px 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.setcard {
  position: relative;
  display: grid;
  grid-template-rows: 120px auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: left;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.setcard:hover { border-color: #454a54; transform: translateY(-1px); }
.setcard.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.setcard .cover { background: var(--raised) center / cover; }
.setcard .cover.blank { display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.setcard .body { padding: 10px 12px 12px; }
.setcard .name { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.setcard .name small { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; white-space: nowrap; }
.setcard .note { color: var(--muted); font-size: 12.5px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.setcard .tools { display: flex; gap: 10px; margin-top: 8px; }
.setcard .tools button { padding: 0; border: 0; background: none; color: var(--muted); font-size: 12.5px; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.setcard .tools button:hover { color: var(--text); }
.setcard .badge { position: absolute; top: 8px; left: 8px; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(6px); font-size: 11.5px; color: var(--text); }
.setcard progress { position: absolute; left: 0; right: 0; top: 118px; height: 3px; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.center { justify-content: center; }
.spacer { flex: 1; }

.btn {
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--raised);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #454a54; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); border-color: var(--accent); }
.btn.accent { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); color: var(--accent); }
.btn.big { padding: 12px 22px; font-size: 16px; }
.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.link:hover { color: var(--text); }
label.text { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
label.text input, label.text select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  min-width: 200px;
}
label.check { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
label.check input { accent-color: var(--accent); }

progress {
  appearance: none;
  width: 100%;
  height: 4px;
  border: 0;
  border-radius: 2px;
  background: var(--raised);
  overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--raised); }
progress::-webkit-progress-value { background: var(--accent); transition: width .15s; }
progress::-moz-progress-bar { background: var(--accent); }

.step-foot {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 36px -20px -120px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}
.step-foot .status { flex: 1; min-width: 0; color: var(--muted); font-size: 13.5px; }
.step-foot .status p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-foot .status progress { margin-top: 6px; }
.step-foot > .btn:last-child { margin-left: auto; }

/* ---------------------------------------------------------------- builder */
.builder {
  margin-top: 18px;
  padding: 20px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  border-radius: var(--radius);
  background: var(--panel);
}
.builder-head { display: flex; flex-wrap: wrap; align-items: end; gap: 14px 18px; margin-bottom: 16px; }
.builder-head h2 { flex-basis: 100%; font-size: 18px; letter-spacing: -0.01em; }
.dropzone {
  display: grid;
  place-content: center;
  gap: 8px;
  min-height: 190px;
  padding: 24px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.dropzone .hint { max-width: 460px; margin: 6px auto 0; }
.build-progress { display: grid; gap: 12px; }
.sheet-wrap { max-height: 300px; overflow: hidden; border-radius: 8px; background: var(--bg); }
#build-sheet { display: block; width: 100%; height: auto; image-rendering: auto; }

/* ---------------------------------------------------------------- picture */
.picture-row { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 28px; align-items: start; }
.dropzone.picture { position: relative; min-height: 360px; overflow: hidden; padding: 20px; }
.dropzone.picture img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--bg); }
.target-info {
  position: relative;
  z-index: 1;
  align-self: end;
  justify-self: start;
  margin: auto 0 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(8px);
  text-align: left;
}
.target-info p:first-child { font-weight: 600; overflow-wrap: anywhere; }
.samples-col .label { margin-top: 0; }
.samples { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: start; }
.sample {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 6px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  overflow: hidden;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.sample:hover { border-color: #454a54; transform: translateY(-1px); }
.sample.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.sample img { width: 100%; height: auto; align-self: start; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--raised); }
.sample span { display: block; padding: 0 10px 10px; font-size: 12.5px; line-height: 1.35; }
.sample span b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sample span small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* ---------------------------------------------------------------- size */
.presets { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.preset {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.preset:hover { border-color: #454a54; transform: translateY(-1px); }
.preset.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.preset .name { font-weight: 600; font-size: 16px; }
.preset .blurb { color: var(--muted); font-size: 13px; }
.preset .dims { margin-top: 8px; font-variant-numeric: tabular-nums; font-size: 13px; }
.preset .dims small { display: block; color: var(--muted); }
.preset .ratio { position: absolute; top: 14px; right: 14px; border: 1px solid var(--line); border-radius: 3px; background: var(--raised); }
.advanced { margin-top: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.advanced summary { padding: 12px 16px; cursor: pointer; color: var(--muted); }
.advanced[open] summary { border-bottom: 1px solid var(--line); color: var(--text); }
.advanced .controls { padding: 16px; max-width: 520px; }
#estimate { text-align: center; }

.controls { display: grid; gap: 14px; }
.field { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13.5px; }
.field output { color: var(--muted); font-variant-numeric: tabular-nums; }
.field input { grid-column: 1 / -1; width: 100%; margin: 0; accent-color: var(--accent); }
#controls:not(.placed) { display: none; }

/* ---------------------------------------------------------------- mosaic */
.step.mosaic {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  min-height: calc(100vh - 56px);
  min-height: calc(100dvh - 56px);
}
.side {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 20px 20px 16px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  font-size: 14px;
}
.side section { display: flex; flex-direction: column; gap: 10px; }
.side h2 { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.side footer { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); display: flex; gap: 14px; }
#stats { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; }
#stats dt { color: var(--muted); }
#stats dd { font-variant-numeric: tabular-nums; }
.inspect { display: grid; grid-template-columns: 72px 1fr; gap: 10px; min-height: 72px; align-items: start; }
.inspect .hint { grid-column: 1 / -1; }
.inspect .thumb { width: 72px; height: 72px; border-radius: 8px; background: var(--raised); display: block; }
.inspect .t { font-size: 13px; line-height: 1.35; min-width: 0; }
.inspect .t b { display: block; font-weight: 600; text-wrap: pretty; overflow-wrap: anywhere; }
.inspect .t span { display: block; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.inspect .t a { color: var(--accent); font-size: 12.5px; }
.inspect.pinned { outline: 1px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 6px; border-radius: 4px; }

.stage {
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  cursor: grab;
  background: var(--bg);
}
.stage.dragging { cursor: grabbing; }
body.drop .stage::after, .dropzone.over::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  pointer-events: none;
}
.sheet { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.sheet canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.sheet canvas.crisp { image-rendering: pixelated; }
.sheet .cell { position: absolute; border: 2px solid var(--accent); box-shadow: 0 0 0 1px rgba(0,0,0,.6); pointer-events: none; }
.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  cursor: default;
}
.chip {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(8px);
  cursor: default;
}
.zoom { right: 14px; bottom: 14px; }
.zoom button { min-width: 30px; height: 28px; padding: 0 8px; border: 0; border-radius: 6px; background: none; cursor: pointer; }
.zoom button:hover { background: var(--raised); }
.zoom output { min-width: 48px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.busy { left: 14px; bottom: 14px; padding: 6px 12px 6px 10px; gap: 8px; color: var(--muted); }
.busy::before {
  content: "";
  width: 12px; height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.term {
  left: 14px; top: 14px;
  display: block;
  padding: 0;
  max-width: min(520px, calc(100% - 28px));
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.term summary { display: flex; gap: 8px; padding: 6px 10px; color: var(--muted); white-space: nowrap; list-style: none; cursor: pointer; }
.term summary::-webkit-details-marker { display: none; }
.term summary:hover { color: var(--text); }
.term .prompt { color: var(--accent); }
#term-last { overflow: hidden; text-overflow: ellipsis; }
.term[open] summary { border-bottom: 1px solid var(--line); }
#term-log { max-height: 240px; padding: 8px 10px; overflow-y: auto; white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; cursor: text; }
#term-log .t { color: var(--muted); }
#term-log .err { color: var(--danger); }
.toast {
  left: 50%; top: 54px;
  max-width: min(560px, calc(100% - 28px));
  padding: 8px 14px;
  transform: translateX(-50%);
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  color: var(--danger);
}
.toast.warn { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .busy::before { animation: none; }
  .setcard, .sample, .preset { transition: none; }
}
@media (max-width: 860px) {
  .top { grid-template-columns: auto 1fr; }
  .engine { display: none; }
  .step-tab span { display: none; }
  .step-tab { padding: 4px; }
  .picture-row { grid-template-columns: 1fr; }
  .step.mosaic { grid-template-columns: minmax(0, 1fr); grid-template-rows: 55vh minmax(0, 1fr); min-height: 0; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
}
