:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --border: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --accent: #ea580c;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.05);
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f12;
    --surface: #17191d;
    --surface-2: #1f2228;
    --border: #2a2d34;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.4; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 16px; letter-spacing: -0.2px; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:focus-visible, .icon-btn:focus-visible, .plug:focus-visible, .txt:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.more { position: relative; }
.more summary { list-style: none; }
.more summary::-webkit-details-marker { display: none; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  display: grid; gap: 2px;
}
.menu button, .menu-file { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.menu button:hover, .menu-file:hover { background: var(--surface-2); }
.menu .danger { color: var(--danger); }
.menu-file input { display: none; }

/* layout */
.layout { display: grid; grid-template-columns: minmax(340px, 420px) 1fr; gap: 20px; padding: 20px; align-items: start; }
.panel { display: grid; gap: 14px; }
.stage { position: sticky; top: 76px; display: grid; gap: 10px; }
.preview { border-radius: var(--radius); overflow: hidden; box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25); background: #0b0c0f; aspect-ratio: 16 / 9; }
.preview svg { display: block; width: 100%; height: auto; }
.hint { margin: 0; color: var(--muted); font-size: 12px; text-align: center; }
.warnings { background: #fef3c7; color: #78350f; border: 1px solid #fcd34d; border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.warnings p { margin: 2px 0; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .stage { position: static; order: -1; }
  .topbar { padding: 10px 16px; }
}

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 10px; font-size: 15px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.card h2 small { flex-basis: 100%; font-size: 12px; font-weight: 400; color: var(--muted); }
.count { font-size: 12px; color: var(--muted); font-weight: 600; }
.count:empty { display: none; }

.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.field-row + .field-row { margin-top: 8px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

.txt, select {
  width: 100%; min-width: 0; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface-2);
}
select { width: auto; max-width: 46%; padding: 5px 6px; font-size: 12px; }
.grow { flex: 1; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 6px 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg input:checked + span { background: var(--text); color: var(--bg); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* picker */
.picker { position: relative; margin-bottom: 10px; }
.picker-input { width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px dashed var(--muted); background: var(--surface); }
.picker-input:focus { outline: 2px solid var(--accent); border-style: solid; border-color: transparent; }
.picker-menu {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 340px; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2); padding: 4px;
}
.picker-group { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 8px 8px 4px; }
.picker-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 5px 8px; border-radius: 7px; cursor: pointer; text-align: left; }
.picker-item svg { flex: none; width: 24px; height: 24px; }
.picker-item span { flex: 1; }
.picker-item em { font-style: normal; font-size: 11px; color: var(--muted); }
.picker-item.is-active, .picker-item:hover { background: var(--surface-2); }
.picker-item.is-added { opacity: 0.55; }
.picker-custom .plus { flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; border: 1px dashed var(--muted); }
.picker-empty { padding: 10px; color: var(--muted); }

/* rows */
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.row { border: 1px solid var(--border); border-radius: 10px; padding: 7px; display: grid; gap: 6px; background: var(--surface); }
.row-main, .row-sub { display: flex; align-items: center; gap: 6px; }
.row-sub { padding-left: 34px; flex-wrap: wrap; }
.row .txt { padding: 5px 7px; }
.chip svg, .swatch svg { display: block; }
.swatch { position: relative; cursor: pointer; flex: none; }
.swatch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.icon-btn { flex: none; width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-size: 13px; line-height: 1; color: var(--muted); }
.icon-btn:hover { color: var(--text); border-color: var(--muted); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }
.empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }
.muted { color: var(--muted); font-size: 12px; }

.plugs { display: flex; flex-wrap: wrap; gap: 4px; }
.plug {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px 3px 6px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); background: none; cursor: pointer; color: var(--muted);
}
.plug i { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--c); }
.plug.on { background: var(--c); border-color: var(--c); color: #fff; }
.plug.on i { background: #fff; border-color: #fff; }

.fineprint { color: var(--muted); font-size: 11px; margin: 0 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: #18181b; color: #fafafa; padding: 10px 16px; border-radius: 10px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.toast.err { background: var(--danger); }
