:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --text: #18181b;
  --muted: #71717a;
  --line: #e7e7e4;
  --soft: #f1f1ef;
  --accent: #18181b;
  --ok: #16a34a;
  --bad: #dc2626;
  --radius: 10px;
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
}

/* ---------- Panel ---------- */
.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 20px 22px 40px;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 15px; letter-spacing: -0.01em;
  margin-bottom: 22px;
}
.logo {
  width: 18px; height: 18px; border-radius: 5px;
  background:
    linear-gradient(var(--text) 0 0) 0 0 / 7px 7px no-repeat,
    linear-gradient(var(--text) 0 0) 100% 0 / 7px 7px no-repeat,
    linear-gradient(var(--text) 0 0) 0 100% / 7px 7px no-repeat,
    linear-gradient(var(--text) 0 0) 100% 100% / 4px 4px no-repeat;
}

.group {
  padding: 18px 0;
  border-top: 1px solid var(--line);
  display: grid; gap: 12px;
}
.group:first-of-type { border-top: 0; padding-top: 0; }

.label {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.row-between { display: flex; justify-content: space-between; align-items: center; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }

.input, .select {
  width: 100%;
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 8px; padding: 9px 11px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.select { width: auto; padding: 6px 28px 6px 10px; cursor: pointer;
  appearance: none;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2371717a' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
}
.input:focus, .select:focus { border-color: #a1a1aa; box-shadow: 0 0 0 3px #18181b0f; }

.link-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 12px; }
.link-btn:hover { color: var(--text); }

.drop {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 64px; padding: 10px;
  border: 1px dashed #d4d4d0; border-radius: var(--radius);
  color: var(--muted); cursor: pointer; text-align: center;
  transition: background .15s, border-color .15s;
}
.drop:hover, .drop.over { background: var(--soft); border-color: #a1a1aa; }
#dropText { display: flex; align-items: center; gap: 10px; min-width: 0; }
#dropText span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.drop img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.drop u { color: var(--text); text-underline-offset: 2px; }

/* segmented */
.segmented {
  display: flex; background: var(--soft); border-radius: 8px; padding: 3px; gap: 2px;
}
.segmented button {
  flex: 1; border: 0; background: transparent; border-radius: 6px;
  padding: 6px 8px; cursor: pointer; color: var(--muted); white-space: nowrap;
}
.segmented button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px #0000001a; }
.segmented.small button { padding: 4px 8px; font-size: 12.5px; }

/* sliders */
.slider { display: grid; grid-template-columns: 1fr auto; row-gap: 6px; align-items: center; }
.slider > span:first-child { color: var(--text); }
.slider output { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12.5px; }
.slider input { grid-column: 1 / -1; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; margin: 0;
}
input[type=range]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: linear-gradient(var(--text) 0 0) 0 / var(--p, 50%) 100% no-repeat, #e4e4e1; }
input[type=range]::-moz-range-track { height: 3px; border-radius: 3px; background: #e4e4e1; }
input[type=range]::-moz-range-progress { height: 3px; border-radius: 3px; background: var(--text); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; margin-top: -5.5px;
  background: var(--panel); border: 1.5px solid var(--text); cursor: grab;
}
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--panel); border: 1.5px solid var(--text); cursor: grab; }

.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.colors { display: flex; gap: 8px; }
.swatch {
  width: 30px; height: 30px; border-radius: 8px; overflow: hidden; cursor: pointer;
  border: 1px solid var(--line); position: relative;
}
.swatch input { position: absolute; inset: -8px; width: 46px; height: 46px; border: 0; padding: 0; cursor: pointer; }

body.mode-logo .bg-only, body.mode-background .logo-only { display: none; }
body.no-image #positionGroup { opacity: .45; pointer-events: none; }

/* ---------- Stage ---------- */
.stage {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; padding: 32px; min-width: 0; min-height: 0;
}
.canvas-wrap {
  width: min(560px, 100%, calc(100vh - 160px));
  aspect-ratio: 1;
  background: var(--panel);
  border-radius: 18px;
  box-shadow: 0 1px 2px #0000000d, 0 12px 40px -12px #00000026;
  overflow: hidden;
  touch-action: none;
}
.canvas-wrap canvas { width: 100%; height: 100%; display: block; }
body:not(.no-image) .canvas-wrap { cursor: grab; }
.canvas-wrap.dragging { cursor: grabbing !important; }
.stage.over .canvas-wrap { outline: 2px dashed #a1a1aa; outline-offset: 6px; }

.toolbar {
  width: min(560px, 100%);
  display: flex; align-items: center; gap: 10px;
}
.spacer { flex: 1; }

.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: #d4d4d0; }
.status.ok i { background: var(--ok); }
.status.ok { color: var(--text); }
.status.bad i { background: var(--bad); }
.status.bad { color: var(--bad); }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 500;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #27272a; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .stage { order: -1; padding: 20px 16px; }
  .canvas-wrap { width: min(100%, 480px); }
  .panel { border-right: 0; border-top: 1px solid var(--line); }
}
