:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e2e4ec;
  --text: #14161f;
  --text-muted: #666b7a;
  --accent: #4338ca;
  --accent-hover: #372dab;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h2 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 12px;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

input,
select,
textarea,
button {
  font-family: inherit;
  font-size: 0.95rem;
}

/* ---------------------------- Header ---------------------------- */

.site-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 28px 16px 18px;
  text-align: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #4338ca, #0ea5e9);
  display: inline-block;
}

.brand-name {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

/* ---------------------------- Layout ---------------------------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 40px;
  align-items: start;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.hint {
  margin: -6px 0 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ---------------------------- Content tabs ---------------------------- */

.content-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.content-tab {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
}

.content-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.content-panel {
  display: none;
  flex-direction: column;
  gap: 8px;
}

.content-panel.active {
  display: flex;
}

.content-panel input,
.content-panel textarea,
.content-panel select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
}

.content-panel textarea {
  resize: vertical;
  font-family: inherit;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  margin: 10px 0;
  cursor: pointer;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
}

/* ---------------------------- Templates ---------------------------- */

.template-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}

.template-swatch {
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.template-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(67, 56, 202, 0.18);
}

.swatch-preview {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
}

.swatch-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---------------------------- Field rows ---------------------------- */

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

.field-row label {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-weight: 500;
}

.field-row select,
.field-row input[type="range"] {
  flex: 1;
  min-width: 0;
}

.field-row select {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.field-row input[type="color"] {
  width: 44px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  background: var(--surface);
  cursor: pointer;
}

.size-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.gradient-row {
  border-top: 1px dashed var(--border);
  padding-top: 12px;
  margin-top: 4px;
}

/* ---------------------------- Logo ---------------------------- */

.logo-dropzone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  background: var(--bg);
}

.logo-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(67, 56, 202, 0.06);
}

.logo-dropzone.has-logo {
  border-style: solid;
}

.logo-dropzone img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.dropzone-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.link-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

/* ---------------------------- Preview pane ---------------------------- */

.preview-pane {
  position: sticky;
  top: 20px;
}

.preview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-surface {
  aspect-ratio: 1;
  border-radius: 12px;
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%) -10px 0/ 20px 20px,
    linear-gradient(-45deg, #eee 25%, transparent 25%) -10px 0/ 20px 20px,
    linear-gradient(45deg, transparent 75%, #eee 75%) -10px 0/ 20px 20px,
    linear-gradient(-45deg, transparent 75%, #eee 75%) -10px 0/ 20px 20px,
    #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.qr-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.qr-preview svg,
.qr-preview canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
}

.empty-notice {
  position: absolute;
  inset: auto 16px 16px 16px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  padding: 6px;
}

.download-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  flex: 1;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  min-width: 100px;
}

.btn:hover {
  filter: brightness(0.97);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.tip {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---------------------------- Footer ---------------------------- */

/* ---------------------------- Responsive ---------------------------- */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .preview-pane {
    position: static;
    order: -1;
  }

  .preview-surface {
    aspect-ratio: auto;
    height: 320px;
  }
}
