:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5d6878;
  --line: #dde2ea;
  --field: #f5f7fa;
  --accent: #2f6fdb;
  --accent-ink: #ffffff;
  --accent-soft: #e6eefc;
  --stage: #e3e7ed;
  --shadow: 0 1px 2px rgba(20, 30, 50, .08), 0 8px 28px rgba(20, 30, 50, .12);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --panel: #181d25;
    --card: #1d232c;
    --text: #e6eaf0;
    --muted: #9aa5b4;
    --line: #2c3440;
    --field: #232a35;
    --accent: #5b8ff0;
    --accent-ink: #0d1420;
    --accent-soft: #233552;
    --stage: #0e1116;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
button, input, select { font: inherit; color: inherit; }

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.tagline { margin: 0; color: var(--muted); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Layout ──────────────────────────────────────────── */
.layout { flex: 1; display: grid; grid-template-columns: 380px 1fr; min-height: 0; }
.panel {
  overflow-y: auto;
  padding: 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--stage); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { margin: 0 0 10px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.blurb { margin: -4px 0 10px; color: var(--muted); }
.privacy { color: var(--muted); font-size: 12px; text-align: center; margin: 4px 0 8px; }

/* ── Type tiles ──────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px 4px 7px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--field); cursor: pointer;
  font-size: 12px; line-height: 1.2; text-align: center;
  transition: border-color .12s, background .12s, transform .12s;
}
.tile:hover { border-color: var(--accent); }
.tile:active { transform: scale(.98); }
.tile[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
.tile .thumb { width: 64px; height: 64px; border-radius: 4px; overflow: hidden; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
.tile .thumb svg { display: block; width: 100%; height: 100%; }

/* ── Form ────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 8px; }
.form h3 { margin: 8px 0 0; font-size: 12px; font-weight: 600; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
.row { display: grid; grid-template-columns: 1fr 160px; align-items: center; gap: 10px; min-height: 32px; }
.row > span:first-child { color: var(--text); }
.row small { display: block; color: var(--muted); font-size: 11px; }
.row[hidden] { display: none; }
input[type="text"], input[type="number"], select {
  width: 100%; height: 32px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--field);
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.num { position: relative; display: block; }
.num input { padding-right: 34px; }
.num .u { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 12px; pointer-events: none; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.color { display: flex; align-items: center; gap: 8px; }
.color input { width: 40px; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); cursor: pointer; }
.color code { color: var(--muted); font-size: 12px; }

/* switches */
.row.check { cursor: pointer; }
.row.check input { position: absolute; opacity: 0; pointer-events: none; }
.sw { justify-self: end; width: 38px; height: 22px; border-radius: 11px; background: var(--line); position: relative; transition: background .15s; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.row.check input:checked + .sw { background: var(--accent); }
.row.check input:checked + .sw::after { transform: translateX(16px); }
.row.check input:focus-visible + .sw { outline: 2px solid var(--accent); outline-offset: 2px; }

/* segmented */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: var(--field); }
.seg button { border: 0; background: transparent; padding: 5px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.row .seg { justify-self: stretch; }
.row .seg button { flex: 1; padding: 5px 4px; }

/* ── Stage ───────────────────────────────────────────── */
.toolbar, .exportbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; flex-wrap: wrap; }
.toolbar { justify-content: space-between; border-bottom: 1px solid var(--line); background: var(--panel); }
.info { color: var(--muted); font-variant-numeric: tabular-nums; }
.actions { display: flex; align-items: center; gap: 8px; }
.viewport { flex: 1; overflow: auto; display: grid; place-items: center; padding: 24px; min-height: 0; }
.viewport.actual { place-items: start center; }
.paper { background: #fff; box-shadow: var(--shadow); line-height: 0; }
.paper svg { display: block; width: 100%; height: 100%; }
.exportbar { justify-content: center; border-top: 1px solid var(--line); background: var(--panel); }
.export-group { display: inline-flex; align-items: center; gap: 6px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); cursor: pointer; font-weight: 600;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { height: 30px; padding: 0 10px; font-weight: 500; }
.btn[disabled] { opacity: .6; cursor: progress; }
.mini { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.mini input { width: 56px; height: 30px; }
select.mini { width: auto; height: 30px; color: var(--text); }

#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translate(-50%, 20px);
  background: #1c2430; color: #fff; padding: 9px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#print-area { display: none; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 860px) {
  body { height: auto; }
  .layout { display: flex; flex-direction: column-reverse; }
  .panel { border-right: 0; overflow: visible; padding: 12px 16px; }
  .stage { position: sticky; top: 0; z-index: 2; height: 58vh; border-bottom: 1px solid var(--line); }
  .viewport { padding: 14px; }
  .tagline { display: none; }
  .topbar { justify-content: space-between; padding: 10px 16px; }
  .toolbar, .exportbar { padding: 8px 12px; gap: 8px; }
  .zoom { display: none; }
  .btn { padding: 0 12px; }
}
@media (max-width: 420px) {
  .row { grid-template-columns: 1fr 140px; }
  .tiles { gap: 6px; }
  .tile .thumb { width: 54px; height: 54px; }
  .mini input { width: 46px; }
}

/* ── Print ───────────────────────────────────────────── */
@media print {
  body > *:not(#print-area) { display: none !important; }
  body { background: #fff; display: block; }
  #print-area { display: block; }
  #print-area svg { display: block; }
}
