:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f1eee7;
  --ink: #15120f;
  --ink-2: #57514a;
  --ink-3: #8d867d;
  --line: #e4dfd5;
  --accent: #5b2cff;
  --accent-ink: #ffffff;
  --accent-soft: #ece6ff;
  --pop: #ffcf33;
  --ok: #10a35a;
  --err: #e5373a;
  --radius: 14px;
  --display: 'Bricolage Grotesque', 'Inter', system-ui, sans-serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --shadow: 0 1px 2px rgba(21, 18, 15, .05), 0 8px 24px rgba(21, 18, 15, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--body);
  display: grid;
  grid-template-rows: auto 1fr auto;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--pop);
  font: 800 24px/1 var(--display);
  transform: rotate(-6deg);
  box-shadow: 3px 3px 0 var(--ink);
}
.brand strong { display: block; font: 800 22px/1.05 var(--display); letter-spacing: -.02em; }
.brand small { color: var(--ink-2); font-size: 13px; }
.privacy {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: #e5f7ec; color: #0b7a43; font-weight: 600; font-size: 13px;
}

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.panel {
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 8px 20px 24px;
}
.group { padding: 18px 0; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group h2 {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 14px;
  font: 800 19px/1 var(--display); letter-spacing: -.01em;
}
.step {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--ink); color: var(--pop);
  font: 800 13px/1 var(--display);
}
.sub { margin-top: 14px; }
.row { display: flex; gap: 14px; align-items: flex-start; }
.grow { flex: 1; min-width: 0; }

.field { margin-bottom: 12px; }
.field > label {
  display: flex; justify-content: space-between;
  margin-bottom: 6px; font-weight: 600; font-size: 13px; color: var(--ink-2);
}
.field output { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.hint { margin: 8px 0 12px; color: var(--ink-3); font-size: 12.5px; }

input[type=text], select {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: inherit;
}
input[type=text]:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=color] {
  width: 48px; height: 38px; padding: 3px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer;
}
input[type=range] { width: 100%; accent-color: var(--accent); }

.checks { display: flex; gap: 18px; margin-bottom: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; margin-bottom: 10px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Segmented control */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; background: var(--surface-2); border-radius: 12px; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block; text-align: center; padding: 8px 4px; border-radius: 9px;
  font-weight: 600; color: var(--ink-2); transition: background .15s, color .15s;
}
.segmented input:checked + span { background: var(--ink); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

/* Logo picker */
.logo-pick { display: flex; align-items: center; gap: 14px; }
.logo-box {
  width: 84px; height: 84px; flex: none;
  display: grid; place-items: center; border-radius: 12px;
  border: 1.5px dashed var(--line);
  background: repeating-conic-gradient(#eeeae2 0% 25%, #fff 0% 50%) 0 0 / 14px 14px;
  color: var(--ink-3); font-size: 12px; overflow: hidden;
}
.logo-box img { max-width: 90%; max-height: 90%; }
.logo-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

/* Position grid */
.posgrid { display: grid; grid-template-columns: repeat(3, 28px); gap: 5px; padding: 8px; background: var(--surface-2); border-radius: 12px; }
.posgrid button {
  width: 28px; height: 22px; border-radius: 6px; border: 0;
  background: var(--surface); cursor: pointer; box-shadow: inset 0 0 0 1.5px var(--line);
}
.posgrid button:hover { box-shadow: inset 0 0 0 1.5px var(--accent); }
.posgrid button.active { background: var(--accent); box-shadow: none; }
.tile-on .posgrid { opacity: .4; pointer-events: none; }

/* Visibility driven by body classes */
body:not(.show-logo) [data-show=logo],
body:not(.show-text) [data-show=text],
body:not(.show-tile) [data-show=tile] { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 10px;
  border: 1.5px solid var(--ink); background: var(--surface); color: var(--ink);
  font: 600 14px/1 var(--body); cursor: pointer; white-space: nowrap;
  transition: transform .08s, box-shadow .15s, background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 48px; padding: 0 24px; font: 700 16px/1 var(--display); border-radius: 12px; }
.btn-primary { background: var(--accent); border-color: var(--ink); color: var(--accent-ink); box-shadow: 3px 3px 0 var(--ink); }
.btn-primary:hover { background: #4a1ee6; }
.btn-primary:active { box-shadow: 1px 1px 0 var(--ink); transform: translate(2px, 2px); }
.btn-primary:disabled { background: #c9c3ba; color: #fff; box-shadow: none; cursor: not-allowed; border-color: #c9c3ba; }
.btn-ghost { border-color: transparent; color: var(--ink-2); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--line);
  background: var(--surface); font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink);
}
.icon-btn:hover { border-color: var(--ink); }

/* ---------- Stage ---------- */
.stage { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: 20px; }
.dropzone {
  flex: 1; display: grid; place-items: center;
  border: 2.5px dashed #cfc8bc; border-radius: 24px; background: var(--surface);
  text-align: center; padding: 24px;
}
.dz-icon {
  width: 84px; height: 84px; margin: 0 auto 20px; border-radius: 24px;
  display: grid; place-items: center;
  background: var(--pop); color: var(--ink); transform: rotate(4deg);
  box-shadow: 4px 4px 0 var(--ink);
}
.dropzone h1 {
  margin: 0 0 10px; font: 800 clamp(30px, 4vw, 52px)/1.02 var(--display);
  letter-spacing: -.035em; max-width: 14ch; margin-inline: auto;
}
.dropzone h1 em {
  font-style: normal; color: var(--accent);
  background: linear-gradient(transparent 62%, var(--pop) 62%, var(--pop) 92%, transparent 92%);
}
.dropzone p { margin: 0 0 26px; color: var(--ink-2); font-size: 16px; }
.dz-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.viewer { flex: 1; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.viewer-bar { display: flex; align-items: center; gap: 10px; }
.viewer-name { font-weight: 600; max-width: 40ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-name b { font: 800 16px/1 var(--display); margin-right: 6px; }
.spacer { flex: 1; }
.canvas-wrap {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  background: repeating-conic-gradient(#ebe7df 0% 25%, #f4f1eb 0% 50%) 0 0 / 20px 20px;
  border-radius: var(--radius); border: 1px solid var(--line); padding: 16px; overflow: hidden;
}
#preview { max-width: 100%; max-height: 100%; min-width: 0; min-height: 0; object-fit: contain; border-radius: 6px; box-shadow: var(--shadow); }
.strip {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px;
  max-height: 180px; overflow-y: auto; padding: 2px;
}
.thumb {
  position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 10px; overflow: hidden;
  background: var(--surface-2); cursor: pointer; outline: 2px solid transparent; outline-offset: 2px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.current { outline-color: var(--accent); }
.thumb::after {
  content: ''; position: absolute; top: 5px; right: 5px; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; font: 700 11px/18px var(--body); text-align: center; color: #fff;
}
.thumb.working::after { content: ''; background: var(--pop); box-shadow: 0 0 0 2px #fff; }
.thumb.done::after { content: '✓'; background: var(--ok); }
.thumb.error::after { content: '!'; background: var(--err); }

.drop-overlay {
  position: absolute; inset: 12px; display: none; place-items: center; z-index: 5;
  border: 3px dashed var(--accent); border-radius: 24px; background: rgba(236, 230, 255, .92);
  font: 800 32px/1 var(--display); color: var(--accent);
}
body.dragging .drop-overlay { display: grid; }

/* ---------- Action bar ---------- */
.actionbar {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 24px; background: var(--surface); border-top: 1px solid var(--line);
}
.summary { flex: 1; color: var(--ink-2); }
.summary strong { color: var(--ink); font: 800 20px/1 var(--display); margin-right: 4px; }
.progress { flex: 1; min-width: 0; }
.bar { height: 12px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1.5px solid var(--ink); }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-text { margin-top: 6px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dest { display: flex; align-items: center; gap: 8px; }
.dest label { font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.dest select { width: auto; }
body.running .panel, body.running .dest, body.running .viewer-bar label, body.running #clearBtn { pointer-events: none; opacity: .55; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px);
  max-width: min(560px, calc(100% - 32px));
  padding: 12px 18px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
  body { display: block; }
  .layout { grid-template-columns: 1fr; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); padding: 4px 16px 8px; }
  .stage { padding: 16px; min-height: 70vh; }
  .topbar { padding: 12px 16px; }
  .privacy { display: none; }
  .actionbar { position: sticky; bottom: 0; flex-wrap: wrap; padding: 12px 16px; gap: 10px; }
  .actionbar .btn-lg { flex: 1; }
  .summary, .progress { flex-basis: 100%; }
  .viewer-name { max-width: 16ch; }
}
