:root {
  --bg: #f4f5fb; --card: #fff; --text: #111827; --muted: #5b6474; --line: #dfe3ec;
  --accent: #4f46e5; --on-accent: #fff; --ok: #047857; --warn: #b45309;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1020; --card: #151b2e; --text: #e7eaf2; --muted: #a3acbd; --line: #2a3350; --accent: #818cf8; --on-accent: #0b1020; --ok: #34d399; --warn: #fbbf24; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 16px/1.5 system-ui, sans-serif; background: var(--bg); color: var(--text); }
main { max-width: 1000px; margin: 0 auto; padding: 24px 16px 64px; display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 820px) {
  main { grid-template-columns: minmax(0, 1fr) 400px; align-items: start; }
  header { grid-column: 1 / -1; }
  #controls { grid-area: 2 / 1; }
  #preview { grid-area: 2 / 2; position: sticky; top: 16px; }
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
h1 { margin: 0; font-size: 1.9rem; letter-spacing: -0.02em; background: linear-gradient(90deg, var(--accent), #db2777); -webkit-background-clip: text; background-clip: text; color: transparent; width: fit-content; }
h2 { margin: 0 0 12px; font-size: 1.1rem; }
p { margin: 4px 0 12px; }
.muted { color: var(--muted); font-size: 0.92rem; }
label[for="url"] { display: block; font-weight: 600; margin-bottom: 6px; }

input, select, button { font: inherit; color: inherit; }
input[type="text"], select { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
#url { width: 100%; font-size: 1.15rem; padding: 14px 16px; border-width: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input[type="color"] { width: 44px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer; }
input[type="range"], input[type="checkbox"] { accent-color: var(--accent); }
button { cursor: pointer; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; font-weight: 600; transition: transform 0.1s, border-color 0.1s; }
button:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); flex: 1 1 100%; padding: 12px; font-size: 1.05rem; }

.chips, .actions { display: flex; flex-wrap: wrap; gap: 8px; }
#recent { margin-top: 12px; }
.chips button { font-weight: 500; font-size: 0.92rem; padding: 6px 12px; display: inline-flex; align-items: center; gap: 8px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips button.swatch::before { content: ""; flex: none; width: 16px; height: 16px; border-radius: 50%; background: linear-gradient(135deg, var(--a), var(--b)); box-shadow: 0 0 0 1px var(--line); }

details { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.row input[type="text"], .row select, .row input[type="range"], .row input[type="file"] { flex: 0 1 55%; min-width: 0; } /* min-width lets wide controls (the file picker) shrink on phones */

#stage { display: grid; place-items: center; aspect-ratio: 1; border-radius: 12px; background: var(--bg); padding: 16px; }
#qr { max-width: 100%; max-height: 100%; width: auto; height: auto; border-radius: 10px; box-shadow: 0 6px 24px rgb(0 0 0 / 0.18); }
#empty { color: var(--muted); text-align: center; margin: 0; }
#empty span { display: block; font-size: 3rem; }
#status { font-weight: 700; margin: 14px 0 2px; min-height: 1.5em; }
#status.ok { color: var(--ok); }
#status.warn { color: var(--warn); }
#dest { color: var(--accent); overflow-wrap: anywhere; }
#notes { margin: 0 0 14px; padding-left: 20px; font-size: 0.92rem; color: var(--warn); }
#notes:empty { display: none; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 80px); background: var(--text); color: var(--card); padding: 10px 18px; border-radius: 999px; font-weight: 600; opacity: 0; transition: transform 0.25s, opacity 0.25s; pointer-events: none; max-width: calc(100vw - 32px); }
#toast.show { transform: translate(-50%, 0); opacity: 1; }
.confetti { position: fixed; width: 10px; height: 10px; border-radius: 2px; pointer-events: none; z-index: 10; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  body { background: none; }
  body * { visibility: hidden; }
  #qr { visibility: visible; position: fixed; inset: 0; margin: auto; width: 70vmin; max-width: none; max-height: none; box-shadow: none; }
}
