:root {
  --bg-base: #f4f7ff;
  --bg-accent: #e5f4ff;
  --ink: #0f172a;
  --ink-soft: #475569;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-strong: #eef3ff;
  --line: #dbe4f3;
  --line-strong: #b8c8e8;
  --primary: #0b5fff;
  --primary-strong: #0a49c5;
  --primary-soft: #dbe9ff;
  --danger: #dc2626;
  --success: #059669;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-1: 0 16px 50px rgb(25 60 130 / 0.12);
  --shadow-2: 0 12px 28px rgb(12 24 55 / 0.12);
}

body[data-theme="light"] {
  --bg-base: #f8fafc;
  --bg-accent: #eef2ff;
  --ink: #111827;
  --line: #d6deec;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
}

body[data-theme="contrast"] {
  --bg-base: #f7f7f7;
  --bg-accent: #f7f7f7;
  --ink: #000000;
  --line: #333333;
  --primary: #000000;
  --primary-strong: #000000;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  padding: 48px 16px;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  line-height: 1.55;
  background:
    radial-gradient(1200px 500px at -10% -15%, #d4e8ff 0%, transparent 55%),
    radial-gradient(800px 420px at 110% -10%, #d7f4ff 0%, transparent 58%),
    linear-gradient(170deg, var(--bg-base) 0%, var(--bg-accent) 100%);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 760px;
  margin: 0 auto;
}

.header {
  text-align: center;
  margin-bottom: 28px;
}

.header h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 5vw, 2.9rem);
  line-height: 1.12;
  letter-spacing: -0.03em;
  font-weight: 800;
  color: #0b1c46;
}

.subtitle {
  margin: 0;
  font-size: 1.05rem;
  color: #334155;
}

.card {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid rgb(255 255 255 / 0.8);
  background: linear-gradient(180deg, rgb(255 255 255 / 0.9), rgb(255 255 255 / 0.96));
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-1);
  padding: 28px;
}

.card::before {
  content: "";
  position: absolute;
  width: 240px;
  height: 240px;
  top: -120px;
  right: -80px;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(42 131 255 / 0.2), transparent 70%);
  pointer-events: none;
}

.form-section {
  margin-bottom: 30px;
}

.form-group {
  margin-bottom: 18px;
}

.label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #1d355e;
}

.select,
.input,
.textarea {
  width: 100%;
  display: block;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  padding: 11px 12px;
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.select:hover,
.input:hover,
.textarea:hover {
  border-color: var(--line-strong);
}

.select:focus,
.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(11 95 255 / 0.16);
}

.textarea {
  resize: vertical;
  min-height: 110px;
}

.input-fields {
  margin-bottom: 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fbfcff 0%, #f5f8ff 100%);
}

.enhancement-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
}

.enhancement-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chip-btn {
  border: 1px solid #b8caea;
  background: #f2f7ff;
  color: #18356b;
  border-radius: 999px;
  font-size: 0.83rem;
  font-weight: 700;
  padding: 7px 12px;
  cursor: pointer;
  transition: transform 170ms ease, border-color 170ms ease, background-color 170ms ease;
}

.chip-btn:hover {
  transform: translateY(-1px);
  border-color: #94b1e5;
  background: #e7f0ff;
}

.live-status {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: #334155;
}

.utm-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
  background: #f9fbff;
}

.utm-box h3 {
  margin: 0 0 8px;
  font-size: 0.96rem;
  color: #15325f;
}

.utm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.field-error {
  min-height: 1.05rem;
  margin: 5px 0 0;
  font-size: 0.77rem;
  color: #b42318;
}

#downloadFormat {
  font-weight: 600;
}

.color-input-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.color-input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(11 95 255 / 0.14);
}

.color-input {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 9px;
  padding: 0;
  background: none;
  cursor: pointer;
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-input::-webkit-color-swatch {
  border: none;
  border-radius: 9px;
}

.color-value {
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.btn {
  width: 100%;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 12px 14px;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  margin-bottom: 12px;
  transition: transform 170ms ease, box-shadow 170ms ease, background-color 170ms ease, border-color 170ms ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, #2575ff 100%);
  color: #fff;
  border-color: rgb(255 255 255 / 0.22);
  box-shadow: 0 10px 22px rgb(11 95 255 / 0.28);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-strong) 0%, var(--primary) 100%);
  transform: translateY(-1px);
  box-shadow: 0 14px 26px rgb(10 73 197 / 0.3);
}

.btn-secondary {
  background: linear-gradient(180deg, #ffffff 0%, #f4f8ff 100%);
  color: #173268;
  border-color: var(--line);
}

.btn-secondary:hover:not(:disabled) {
  border-color: #a8c0eb;
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgb(18 52 115 / 0.14);
}

.icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.qr-display {
  text-align: center;
  margin: 20px 0 6px;
  padding: 28px;
  border-radius: var(--radius);
  border: 1px dashed #b8cbed;
  background:
    radial-gradient(circle at top right, #eff6ff 0%, transparent 45%),
    linear-gradient(180deg, #fbfdff 0%, #f4f8ff 100%);
  min-height: 110px;
}

.qr-display img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow-2);
}

.qr-display:empty {
  display: none;
}

.qr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.qr-actions .btn {
  margin-bottom: 0;
  min-width: 140px;
  flex: 1;
}

.history-panel {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.history-head h2 {
  margin: 0;
  font-size: 1rem;
  color: #1a3563;
}

.text-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: #2b487a;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.text-btn:hover {
  background: #f4f7ff;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 10px;
  cursor: pointer;
  color: #173567;
}

.history-item:hover {
  border-color: #aec1e5;
  background: #f8fbff;
}

.history-open {
  font-size: 0.78rem;
  font-weight: 700;
  color: #0b5fff;
}

.history-empty {
  margin: 0;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: #4b5f82;
  font-size: 0.87rem;
}

.checkbox-wrap {
  margin-top: -4px;
}

.checkbox-label {
  text-transform: none;
  letter-spacing: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin-right: 8px;
  accent-color: var(--primary);
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.scanner-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  background: rgb(10 18 40 / 0.75);
  backdrop-filter: blur(7px);
}

.scanner-content {
  width: min(90%, 530px);
  max-height: 90vh;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgb(255 255 255 / 0.25);
  background: linear-gradient(180deg, #ffffff 0%, #f5f9ff 100%);
  box-shadow: 0 24px 50px rgb(7 22 48 / 0.35);
}

.scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.scanner-header h3 {
  margin: 0;
  font-size: 1.2rem;
  color: #10244d;
}

.close-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: #35507f;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: border-color 180ms ease, background-color 180ms ease, color 180ms ease;
}

.close-btn:hover {
  border-color: #9eb5de;
  background: #f0f5ff;
  color: #1d355e;
}

.close-btn svg {
  width: 1.05rem;
  height: 1.05rem;
}

.scanner-body {
  padding: 18px 20px;
}

.scanner-container {
  height: 310px;
  border-radius: 12px;
  border: 1px solid #bdd0ef;
  overflow: hidden;
  background: linear-gradient(180deg, #f8fbff 0%, #edf4ff 100%);
}

#scannerVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-result,
.scanner-error {
  text-align: center;
  padding: 20px 10px;
}

.result-success,
.result-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.result-success .icon,
.result-error .icon {
  width: 2.8rem;
  height: 2.8rem;
}

.result-success .icon {
  color: var(--success);
}

.result-error .icon {
  color: var(--danger);
}

.result-success h4,
.result-error h4 {
  margin: 0;
  font-size: 1.1rem;
}

.result-success p,
.result-error p {
  margin: 0;
  width: 100%;
  font-size: 0.9rem;
  color: #334155;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-soft);
  word-break: break-word;
}

.scanner-footer {
  padding: 18px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.scanner-footer .btn {
  margin-bottom: 0;
}

.select:focus-visible,
.input:focus-visible,
.textarea:focus-visible,
.btn:focus-visible,
.close-btn:focus-visible {
  outline: 2px solid #8db1ff;
  outline-offset: 2px;
}

.btn.loading {
  color: transparent;
  position: relative;
}

.btn.loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgb(255 255 255 / 0.85);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 720px) {
  body {
    padding: 24px 12px;
  }

  .card {
    padding: 18px;
    border-radius: 16px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .enhancement-grid,
  .utm-grid {
    grid-template-columns: 1fr;
  }

  .qr-actions {
    flex-direction: column;
  }

  .qr-actions .btn {
    min-width: 0;
    width: 100%;
  }

  .scanner-content {
    width: calc(100% - 20px);
  }

  .scanner-container {
    height: 250px;
  }
}
