:root {
  --bg: #F6F7FB;
  --surface: #FFFFFF;
  --text: #0F172A;
  --muted: #5B6578;
  --border: #E4E7EF;
  --input-border: #CBD2E1;
  --accent: #4F46E5;
  --accent-strong: #4338CA;
  --accent-soft: #EEF2FF;
  --danger: #B91C1C;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 10px 30px rgba(15, 23, 42, .06);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

:focus-visible { outline: 3px solid rgba(79, 70, 229, .45); outline-offset: 2px; }

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: flex; align-items: baseline; gap: 8px; text-decoration: none; color: var(--text); min-width: 0; }
.wordmark { font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em; white-space: nowrap; }
.product { font-weight: 600; color: var(--accent-strong); font-size: .95rem; white-space: nowrap; }
.nav { display: flex; gap: 4px; }
.nav-link {
  display: inline-flex; align-items: center; min-height: 40px;
  padding: 8px 14px; border-radius: 999px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: .92rem;
}
.nav-link:hover { background: var(--accent-soft); color: var(--accent-strong); }

main { padding-top: 28px; padding-bottom: 24px; }
.page-head h1 { margin: 0; font-size: clamp(1.6rem, 3vw, 2.1rem); letter-spacing: -.02em; }
.page-head p { margin: 6px 0 24px; color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); align-items: start; }
  .panel-right { position: sticky; top: 84px; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card-title { font-size: 1rem; margin: 0 0 14px; font-weight: 700; }
.card-title:not(:first-child) { margin-top: 22px; }

.alert {
  background: #FEF2F2; border: 1px solid #FECACA; color: #7F1D1D;
  border-radius: 12px; padding: 12px 14px; margin-bottom: 18px; font-weight: 500;
}

/* ---------- Type selector ---------- */
.type-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .type-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 960px) { .type-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.type-btn {
  display: flex; align-items: center; gap: 10px;
  min-height: 52px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: #fff; color: var(--text);
  font: inherit; font-weight: 600; font-size: .88rem; text-align: left;
  cursor: pointer; transition: border-color .15s, background .15s, box-shadow .15s;
}
.type-btn:hover { border-color: #C7CCFF; }
.type-btn.is-active {
  border-color: var(--accent); background: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
.type-icon { font-size: 1.15rem; width: 26px; text-align: center; flex: none; }
.type-label { line-height: 1.2; }

/* ---------- Form ---------- */
.field { margin-bottom: 14px; }
.field > label, .field-label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
.field input:not([type="checkbox"]):not([type="color"]),
.field textarea,
.select {
  width: 100%; min-height: 46px; padding: 10px 14px;
  border: 1px solid var(--input-border); border-radius: 12px;
  font: inherit; font-size: 16px; color: var(--text); background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 84px; }
.field input:not([type="checkbox"]):not([type="color"]):focus,
.field textarea:focus,
.select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}
[aria-invalid="true"] { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(185, 28, 28, .12) !important; }

.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row input { flex: 1; min-width: 0; }
.hint { font-size: .8rem; color: var(--muted); margin: 6px 0 0; }

.check { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: .9rem; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px;
  font: inherit; font-weight: 700; font-size: .92rem; line-height: 1.2;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent-strong); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #3730A3; }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--input-border); }
.btn-ghost:hover:not(:disabled) { background: #F1F5F9; }
.btn-yes { background: #1E1B4B; color: #FFFFFF; }
.btn-yes:hover { background: #312E81; }
.btn-no { background: #E2E8F0; color: #0F172A; }
.btn-no:hover { background: #CBD5E1; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: .84rem; }
.btn-block { width: 100%; }
.btn-file { cursor: pointer; }

/* ---------- Customization ---------- */
.style-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .style-grid { grid-template-columns: 1fr; } }
.field input[type="color"] {
  width: 100%; height: 46px; padding: 4px; border: 1px solid var(--input-border);
  border-radius: 12px; background: #fff; cursor: pointer;
}
.preset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 560px) { .preset-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.preset-btn {
  display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 12px; background: #fff; color: var(--text);
  font: inherit; font-weight: 600; font-size: .86rem; cursor: pointer;
}
.preset-btn:hover { border-color: #C7CCFF; }
.swatch { width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(15, 23, 42, .12); flex: none; }

.logo-box {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  border: 1px dashed var(--input-border); border-radius: 14px; padding: 14px; background: #FAFBFF;
}
.logo-preview {
  width: 72px; height: 72px; border-radius: 12px; background: #fff; border: 1px solid var(--border);
  display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: .78rem; flex: none;
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.logo-actions { flex: 1; min-width: 200px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.logo-actions .hint { width: 100%; margin: 4px 0 0; }

.notice {
  font-size: .85rem; color: #334155; margin: 14px 0 0;
  background: #F8FAFC; border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 12px;
}
.warn {
  font-size: .85rem; color: #78350F; background: #FFFBEB; border: 1px solid #FDE68A;
  border-radius: 10px; padding: 10px 12px; margin: 0 0 12px;
}

/* ---------- Preview ---------- */
.preview-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.preview-head .card-title { margin: 0; }
.badge {
  font-size: .75rem; font-weight: 700; color: var(--accent-strong);
  background: var(--accent-soft); padding: 4px 10px; border-radius: 999px;
}
.qr-stage {
  display: grid; place-items: center; min-height: 300px; margin: 14px 0;
  background: #F8FAFC; border: 1px solid var(--border); border-radius: 14px; padding: 16px;
}
.qr-host { background: #fff; border-radius: 12px; padding: 6px; box-shadow: 0 1px 3px rgba(15, 23, 42, .08); max-width: 100%; }
.qr-host canvas, .qr-host svg { display: block; max-width: 100%; height: auto; }
.empty-state { text-align: center; color: var(--muted); padding: 24px; }
.empty-icon { font-size: 2.4rem; opacity: .45; margin-bottom: 6px; }
.empty-state p { margin: 0; font-size: .92rem; }
.form-error {
  color: var(--danger); background: #FEF2F2; border-radius: 10px;
  padding: 10px 12px; font-size: .88rem; font-weight: 600; margin-bottom: 14px;
}
.payload-box {
  width: 100%; min-height: 70px; resize: vertical; word-break: break-all;
  font: 500 .82rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #F8FAFC; border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; color: #1E293B;
}
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.download-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 480px) { .download-row { grid-template-columns: auto 1fr 1fr; } }
.download-row .select { width: auto; min-height: 44px; }

/* ---------- History ---------- */
.history-list { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 8px; }
.history-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
}
.h-main { min-width: 0; flex: 1 1 200px; }
.h-type { display: block; font-weight: 700; font-size: .9rem; }
.h-preview {
  display: block; max-width: 100%; font-size: .78rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.h-actions { display: flex; gap: 6px; }
.empty-history { color: var(--muted); font-size: .9rem; border: none; padding: 0; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: .86rem; cursor: pointer; min-height: 40px; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- Help & footer ---------- */
.help ol, .help ul { padding-left: 20px; margin: 0; }
.help li { margin-bottom: 8px; color: #334155; }
footer { color: var(--muted); font-size: .82rem; text-align: center; padding: 18px 0 36px; }

/* ---------- Modal & toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 23, 42, .45);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  background: #fff; border-radius: 18px; padding: 24px;
  max-width: 420px; width: 100%; box-shadow: 0 20px 60px rgba(15, 23, 42, .25);
}
.modal h3 { margin: 0 0 8px; font-size: 1.1rem; }
.modal p { margin: 0 0 20px; color: #334155; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.modal-actions .btn { min-width: 110px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 60; max-width: 90vw; text-align: center;
  background: #0F172A; color: #FFFFFF; padding: 12px 18px; border-radius: 12px;
  font-weight: 600; font-size: .9rem; box-shadow: 0 10px 30px rgba(15, 23, 42, .3);
}
.toast.is-error { background: #991B1B; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}