:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --text: #15171c;
  --muted: #5f6672;
  --line: #e2e5ea;
  --line-strong: #cfd4dc;
  --accent: #4f46e5;
  --accent-soft: #eceafd;
  --accent-ink: #ffffff;
  --ok: #157f3b;
  --ok-soft: #e6f5ec;
  --warn: #9a5b00;
  --warn-soft: #fdf3e1;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --check-a: #ffffff;
  --check-b: #eceef2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .05);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --panel: #171a20;
    --panel-2: #1d2128;
    --text: #eceef2;
    --muted: #9aa2ae;
    --line: #2a2f38;
    --line-strong: #3a404b;
    --accent: #8b85ff;
    --accent-soft: #26244a;
    --accent-ink: #0f1115;
    --ok: #4cc27a;
    --ok-soft: #13291c;
    --warn: #f0b44c;
    --warn-soft: #2d2413;
    --bad: #ff7b6e;
    --bad-soft: #321816;
    --check-a: #22262e;
    --check-b: #1b1e24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #171a20; --panel-2: #1d2128; --text: #eceef2; --muted: #9aa2ae;
  --line: #2a2f38; --line-strong: #3a404b; --accent: #8b85ff; --accent-soft: #26244a; --accent-ink: #0f1115;
  --ok: #4cc27a; --ok-soft: #13291c; --warn: #f0b44c; --warn-soft: #2d2413; --bad: #ff7b6e; --bad-soft: #321816;
  --check-a: #22262e; --check-b: #1b1e24; --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}
[hidden] { display: none !important; }
h3 { margin: 0; font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.wordmark { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.logo-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  background-image:
    radial-gradient(circle at 30% 30%, var(--accent-ink) 0 18%, transparent 19%),
    radial-gradient(circle at 70% 30%, var(--accent-ink) 0 18%, transparent 19%),
    radial-gradient(circle at 30% 70%, var(--accent-ink) 0 18%, transparent 19%);
}

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 24px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px;
  align-items: start;
}
.controls { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.preview-col { position: sticky; top: 16px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; gap: 16px; }
  .preview-col { position: static; order: -1; }
  .topbar { padding: 12px 16px; }
}

/* ---------- cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card > summary {
  list-style: none;
  cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  font-weight: 650; font-size: 15.5px;
  user-select: none;
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary::after {
  content: ""; margin-left: auto; width: 8px; height: 8px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform .15s;
}
.card[open] > summary::after { transform: rotate(-135deg); }
.step {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 700;
}
.card-body { padding: 2px 18px 18px; display: flex; flex-direction: column; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.sub { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }
.sub + .sub { border-top: 1px solid var(--line); padding-top: 14px; }
.sub-head { display: flex; flex-direction: column; gap: 2px; }
.label { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; }
.hint { margin: 0; color: var(--muted); font-size: 13px; text-wrap: pretty; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 560px) {
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
}
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row > input, .row > select { flex: 1 1 180px; min-width: 0; }

/* ---------- fields ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span, .range > span, .cf-label { font-size: 13px; font-weight: 550; color: var(--muted); }
input:not([type]), input[type=text], input[type=url], input[type=email], input[type=tel], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--panel);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; align-items: center; gap: 9px; cursor: pointer; font-size: 14px; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }
.range { display: flex; flex-direction: column; gap: 4px; }
.range output { color: var(--text); font-variant-numeric: tabular-nums; margin-left: 4px; }
.range input { width: 100%; accent-color: var(--accent); }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  border-radius: 9px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 7px 12px; font-size: 13.5px; }
.btn.big { padding: 11px 18px; font-size: 15px; flex: 1 1 0; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.file-btn { display: inline-flex; align-items: center; }

/* ---------- segmented ---------- */
.seg {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px;
  max-width: 100%;
}
.seg.wrap { flex-wrap: wrap; }
.seg button {
  appearance: none; border: 0; background: transparent;
  padding: 6px 11px; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; font-weight: 550; color: var(--muted);
  white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--line); }

/* ---------- thumbnails ---------- */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.thumbs.small { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
.thumb {
  appearance: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 6px 8px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--panel-2);
  font-size: 12.5px; font-weight: 550; color: var(--muted);
}
.thumb:hover { border-color: var(--line-strong); color: var(--text); }
.thumb.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); color: var(--text); }
.thumb .art { width: 64px; height: 64px; border-radius: 6px; overflow: hidden; background: #fff; display: grid; place-items: center; }
.thumbs.small .thumb .art { width: 52px; height: 52px; }
.thumb .art svg, .thumb .art canvas { width: 100%; height: 100%; display: block; }

/* ---------- colors ---------- */
.color-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cf-row { display: flex; gap: 8px; align-items: center; }
.cf-swatch {
  position: relative; flex: none;
  width: 38px; height: 38px; border-radius: 9px;
  border: 1px solid var(--line-strong);
  overflow: hidden; cursor: pointer;
  background: conic-gradient(var(--check-b) 0 25%, var(--check-a) 0 50%, var(--check-b) 0 75%, var(--check-a) 0) 0 0 / 10px 10px;
}
.cf-swatch input[type=color] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.cf-swatch .fill { position: absolute; inset: 0; pointer-events: none; }
.cf-hex, .hex-in { font-family: ui-monospace, Menlo, Consolas, monospace; text-transform: uppercase; flex: 1 1 auto; }
.hex-in { flex: 0 1 120px !important; }
.cf-palette { display: flex; flex-wrap: wrap; gap: 5px; min-height: 0; }
.cf-palette:empty { display: none; }
.mini-sw {
  appearance: none; cursor: pointer;
  width: 22px; height: 22px; border-radius: 6px;
  border: 1px solid rgba(0,0,0,.14); padding: 0;
}
.mini-sw.active { outline: 2px solid var(--accent); outline-offset: 1px; }

.palette { display: flex; flex-wrap: wrap; gap: 8px; }
.pal-item {
  position: relative; display: flex; align-items: center; gap: 7px;
  padding: 4px 8px 4px 4px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2);
  font: 12.5px ui-monospace, Menlo, Consolas, monospace;
}
.pal-item .chip { width: 24px; height: 24px; border-radius: 6px; border: 1px solid rgba(0,0,0,.14); }
.pal-item button {
  appearance: none; border: 0; background: transparent; cursor: pointer; color: var(--muted);
  font-size: 15px; line-height: 1; padding: 0 2px;
}
.pal-item button:hover { color: var(--bad); }
.palette-empty { color: var(--muted); font-size: 13px; }

.contrast { margin: 0; font-size: 13px; padding: 8px 10px; border-radius: 9px; }
.contrast.ok { background: var(--ok-soft); color: var(--ok); }
.contrast.warn { background: var(--warn-soft); color: var(--warn); }
.contrast.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- logo ---------- */
.dropzone {
  display: flex; align-items: center; gap: 14px;
  padding: 16px;
  border: 1.5px dashed var(--line-strong); border-radius: 12px;
  background: var(--panel-2);
  cursor: pointer; color: var(--muted); font-size: 13.5px;
  transition: border-color .12s, background .12s;
}
.dropzone strong { color: var(--text); font-size: 14.5px; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone img {
  width: 64px; height: 64px; object-fit: contain; border-radius: 8px; flex: none;
  background: conic-gradient(var(--check-b) 0 25%, var(--check-a) 0 50%, var(--check-b) 0 75%, var(--check-a) 0) 0 0 / 12px 12px;
}

/* ---------- preview ---------- */
.preview-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
}
.stage {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  display: grid; place-items: center;
  padding: 22px;
  background: conic-gradient(var(--check-b) 0 25%, var(--check-a) 0 50%, var(--check-b) 0 75%, var(--check-a) 0) 0 0 / 22px 22px;
  border: 1px solid var(--line);
  overflow: hidden;
}
.stage img { max-width: 100%; max-height: 100%; display: block; filter: drop-shadow(0 4px 14px rgba(0,0,0,.12)); }
.stage .empty, .stage .error {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 30px; color: var(--muted); font-size: 14.5px; background: var(--panel-2);
}
.stage .error { color: var(--bad); background: var(--bad-soft); }

.status { font-size: 13.5px; font-weight: 550; padding: 9px 12px; border-radius: 9px; display: flex; gap: 8px; align-items: flex-start; }
.status:empty { display: none; }
.status.ok { background: var(--ok-soft); color: var(--ok); }
.status.warn { background: var(--warn-soft); color: var(--warn); }
.status.bad { background: var(--bad-soft); color: var(--bad); }
.status.pending { background: var(--panel-2); color: var(--muted); }

.encoded { display: flex; gap: 8px; font-size: 12.5px; color: var(--muted); align-items: baseline; min-width: 0; }
.encoded code {
  flex: 1; min-width: 0;
  font: 12px ui-monospace, Menlo, Consolas, monospace; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.export { display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--line); padding-top: 14px; }
.export .seg { display: flex; }
.export .seg button { flex: 1; }
.actions { flex-wrap: nowrap; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 550;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- shared brands account line ---------- */
.account { margin: 0; font-size: 13px; color: var(--muted); padding: 8px 10px; border-radius: 9px; background: var(--panel-2); text-wrap: pretty; }
.linkish { appearance: none; border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- sign-in dialog ---------- */
.login {
  width: min(400px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 16px;
  background: var(--panel); color: var(--text); padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login::backdrop { background: rgba(10, 12, 16, .45); }
.login h2 { margin: 0 32px 6px 0; font-size: 18px; text-wrap: balance; }
.login .hint { margin-bottom: 16px; }
.login .btn.big { width: 100%; }
.login-close { position: absolute; top: 12px; right: 12px; margin: 0; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; margin: 14px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.login-err { margin: 0; color: var(--bad); font-size: 13px; }
