:root {
  --bg: #f8fafc; --card: #fff; --fg: #0f172a; --muted: #475569; --line: #e2e8f0; --line-strong: #cbd5e1; --soft: #f1f5f9;
  --accent: #2563eb; --accent-hover: #1d4ed8; --accent-ink: #1d4ed8; --on-accent: #fff;
  --warn: #9a3412; --warn-bg: #fff7ed; --danger: #dc2626;
  --shadow: 0 1px 2px rgb(15 23 42 / .04), 0 8px 24px -8px rgb(15 23 42 / .08);
  --radius: .625rem;
  color-scheme: light dark;
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --card: #111827; --fg: #f1f5f9; --muted: #94a3b8; --line: #1f2937; --line-strong: #334155; --soft: #1e293b;
    --accent: #60a5fa; --accent-hover: #93c5fd; --accent-ink: #93c5fd; --on-accent: #0b1120;
    --warn: #fdba74; --warn-bg: #2a1a0e; --danger: #f87171;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px -8px rgb(0 0 0 / .5);
  }
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); min-height: 100vh; display: flex; flex-direction: column; }
.wrap { width: 100%; max-width: 64rem; margin: 0 auto; padding: 0 1rem; }
@media (min-width: 40rem) { .wrap { padding: 0 1.5rem; } }
main { flex: 1; padding-bottom: 4rem !important; }

a { color: var(--accent); text-underline-offset: .2em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { line-height: 1.2; letter-spacing: -.015em; text-wrap: balance; }
h1 { font-size: clamp(1.875rem, 3vw + 1rem, 2.75rem); font-weight: 800; letter-spacing: -.025em; margin: 2rem 0 .75rem; }
h2 { font-size: 1.375rem; margin: 2.5rem 0 .75rem; }
p, li { text-wrap: pretty; }
.lede { font-size: 1.125rem; color: var(--muted); max-width: 42rem; margin: 0 0 1.75rem; }
.hero .lede { margin: 0; }
.hint { color: var(--muted); font-size: .875rem; }
.warn { color: var(--warn); background: var(--warn-bg); padding: .625rem .875rem; border-radius: var(--radius); font-size: .9375rem; }
.notice { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent-ink); padding: .625rem .875rem; border-radius: var(--radius); }
code { font: .875em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--soft); padding: .1em .35em; border-radius: .3rem; overflow-wrap: anywhere; }
pre { overflow-x: auto; padding: 1rem; background: var(--soft); border: 1px solid var(--line); border-radius: var(--radius); font: .875rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre code { background: none; padding: 0; }
table { border-collapse: collapse; width: 100%; font-size: .9375rem; }
td, th { text-align: left; padding: .625rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8125rem; font-weight: 600; color: var(--muted); }

/* Header / footer */
header.site { background: var(--card); border-bottom: 1px solid var(--line); }
header.site .wrap { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3.75rem; }
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.0625rem; letter-spacing: -.01em; color: var(--fg); text-decoration: none; }
.brand:hover { color: var(--fg); }
.brand svg { color: var(--accent); }
.brand .tld { color: var(--muted); font-weight: 600; }
header.site nav { display: flex; gap: .25rem; }
header.site nav a, footer.site nav a { color: var(--muted); text-decoration: none; font-size: .9375rem; font-weight: 500; padding: .5rem .625rem; border-radius: .5rem; }
header.site nav a:hover { color: var(--fg); background: var(--soft); }
footer.site { border-top: 1px solid var(--line); color: var(--muted); font-size: .875rem; padding: 1.5rem 0 2rem; }
footer.site nav { display: flex; flex-wrap: wrap; gap: .25rem 0; margin-left: -.625rem; }
footer.site nav a { font-size: .875rem; }
footer.site nav a:hover { color: var(--fg); }
footer.site p { margin: .75rem 0 0; }

/* Forms */
label { display: block; margin: 0 0 1rem; font-size: .9375rem; font-weight: 500; }
label.check { display: flex; gap: .625rem; align-items: flex-start; font-weight: 400; cursor: pointer; }
label.check input { margin: .25rem 0 0; flex: none; }
input:not([type=checkbox], [type=radio], [type=color]), select, textarea {
  display: block; width: 100%; margin-top: .375rem; padding: .625rem .75rem; min-height: 2.75rem;
  font: inherit; font-weight: 400; color: inherit; background: var(--card);
  border: 1px solid var(--line-strong); border-radius: var(--radius); transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 6rem; }
form > textarea { margin-bottom: 1rem; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: 1px solid var(--line); border-radius: .375rem; }
input[type=color] { display: block; width: 100%; height: 2.75rem; margin-top: .375rem; padding: .3125rem; background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius); cursor: pointer; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 1.125rem; height: 1.125rem; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 1rem; padding: .75rem 1rem .25rem; }
legend { font-size: .875rem; font-weight: 600; padding: 0 .375rem; }
fieldset label.check { margin-bottom: .75rem; }

button {
  display: inline-flex; align-items: center; justify-content: center; gap: .375rem; min-height: 2.75rem; padding: .5rem 1rem;
  font: inherit; font-weight: 600; font-size: .9375rem; white-space: nowrap; cursor: pointer;
  color: var(--fg); background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius);
  transition: background-color .15s, border-color .15s, color .15s;
}
button:hover { background: var(--soft); }
button:disabled { opacity: .6; cursor: progress; }
button.primary, form > button:not([type=button]) { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover, form > button:not([type=button]):hover { background: var(--accent-hover); border-color: var(--accent-hover); }
form.danger > button { background: var(--danger); border-color: var(--danger); color: #fff; }
form.danger > button:hover { background: var(--danger); border-color: var(--danger); filter: brightness(.92); }

details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after {
  content: ""; display: inline-block; width: .5rem; height: .5rem; margin-left: .5rem; vertical-align: .2em;
  border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .15s; opacity: .6;
}
details[open] > summary::after { transform: rotate(-135deg); vertical-align: -.05em; }

/* Hero */
.hero { padding: .5rem 0 1.75rem; }
.trust { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; list-style: none; padding: 0; margin: 1rem 0 0; font-size: .875rem; font-weight: 500; color: var(--muted); }
.trust li { display: inline-flex; align-items: center; gap: .375rem; }
.trust li::before {
  content: ""; width: 1rem; height: 1rem; background: #16a34a;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 0a10 10 0 110 20 10 10 0 010-20zm4.3 6.3L8.5 12 5.7 9.3l-1.4 1.4 4.2 4.2 7.2-7.2z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 0a10 10 0 110 20 10 10 0 010-20zm4.3 6.3L8.5 12 5.7 9.3l-1.4 1.4 4.2 4.2 7.2-7.2z'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Generator card */
#generator {
  display: grid; gap: 1.5rem; padding: 1.25rem; background: var(--card);
  border: 1px solid var(--line); border-radius: 1rem; box-shadow: var(--shadow);
}
#generator > * { min-width: 0; }
@media (min-width: 48rem) {
  #generator { grid-template-columns: minmax(0, 1fr) 17.5rem; gap: 2rem; padding: 1.75rem; }
  #generator .chips { grid-column: 1 / -1; }
  .output { position: sticky; top: 1.5rem; align-self: start; }
}

.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0; padding-bottom: 1.25rem; border-bottom: 1px solid var(--line); align-items: center; }
.chips a, .chips summary {
  display: inline-flex; align-items: center; min-height: 2.5rem; padding: .375rem 1rem; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--fg); text-decoration: none; font-size: .9375rem; font-weight: 500;
  transition: background-color .15s, border-color .15s, color .15s;
}
.chips a:hover, .chips summary:hover { background: var(--soft); color: var(--fg); }
.chips a[aria-current] { background: var(--fg); border-color: var(--fg); color: var(--card); }
.chips details { display: contents; }
.chips details[open] summary { display: none; }

#customize { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: .25rem; }
#customize > summary { font-weight: 600; font-size: .9375rem; color: var(--muted); padding: .25rem 0; }
#customize > summary:hover { color: var(--fg); }
#customize .grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; margin-top: 1rem; }
[data-action=locate] { margin-bottom: 1rem; }

#preview { margin: 0; }
#preview svg { display: block; width: 100%; max-width: 20rem; height: auto; margin: 0 auto; border: 1px solid var(--line); border-radius: .75rem; transition: opacity .2s; }
#preview.pending svg { opacity: .3; }
#preview .qr-wrap { position: relative; max-width: 20rem; margin: 0 auto; }
#preview .badge {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; gap: .5rem; min-height: 2.75rem; padding: .5rem 1.25rem; border: 0; border-radius: 999px; white-space: nowrap;
  background: var(--fg); color: var(--card); font-weight: 600; font-size: .875rem; box-shadow: var(--shadow);
}
#preview .badge:hover { background: var(--fg); filter: brightness(1.25); }
#preview.pending .qr-wrap { cursor: pointer; }
#preview.busy .badge::before {
  content: ""; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#preview figcaption { margin-top: .75rem; text-align: center; }
#preview > p.hint {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem;
  aspect-ratio: 1; max-width: 20rem; margin: 0 auto; padding: 1.5rem; text-align: center;
  border: 2px dashed var(--line-strong); border-radius: .75rem; background: var(--soft);
}
#preview > p.hint::before {
  content: ""; width: 3rem; height: 3rem; background: var(--line-strong);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7'%3E%3Cpath d='M0 0h3v3H0zm4 0h3v3H4zM0 4h3v3H0zm4 0h1v1H4zm2 0h1v1H6zM5 5h1v1H5zm-1 1h1v1H4zm2 0h1v1H6z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7'%3E%3Cpath d='M0 0h3v3H0zm4 0h3v3H4zM0 4h3v3H0zm4 0h1v1H4zm2 0h1v1H6zM5 5h1v1H5zm-1 1h1v1H4zm2 0h1v1H6z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.output > .warn { margin: 1rem 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.actions > button { flex: 1 1 0; }
.actions > .primary { flex-basis: 100%; }
.actions .print { display: flex; flex: 1 1 100%; gap: .5rem; }
.actions .print select { flex: 1; margin: 0; }

.row { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.row input { margin: 0 !important; flex: 1 1 100%; }
.row button { flex: 1; }
#editable { margin-top: 1rem; padding: 1rem; border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); background: color-mix(in srgb, var(--accent) 6%, var(--card)); border-radius: .75rem; }
#editable h2 { margin: 0 0 .25rem; font-size: 1.0625rem; }
#editable p { margin: .5rem 0; font-size: .9375rem; }

#my-codes { margin-top: 2.5rem; }
#my-codes ul { list-style: none; padding: 0; margin: 0; border: 1px solid var(--line); border-radius: .75rem; background: var(--card); overflow: hidden; }
#my-codes li { padding: .75rem 1rem; border-top: 1px solid var(--line); overflow-wrap: anywhere; font-size: .9375rem; color: var(--muted); }
#my-codes li:first-child { border-top: 0; }
#my-codes li a { font-weight: 600; }

@media (max-width: 30rem) {
  #generator { padding: 1rem; }
  .chips { gap: .375rem; }
  .chips a, .chips summary { padding: .375rem .625rem; font-size: .875rem; }
  #preview > p.hint { aspect-ratio: auto; min-height: 9rem; }
}

/* FAQ */
.faq { margin-top: 3.5rem; max-width: 46rem; }
.faq details { border-bottom: 1px solid var(--line); }
.faq details:first-of-type { border-top: 1px solid var(--line); }
.faq summary { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 0; font-weight: 600; }
.faq summary:hover { color: var(--accent); }
.faq details p { margin: 0 0 1rem; color: var(--muted); }

/* Worker pages (edit, notices) and small forms */
.qr ~ form { max-width: 36rem; }
.qr svg { width: 15rem; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: .75rem; display: block; }
.warning { border-left: 4px solid var(--warn); padding-left: 1rem; }
.stack { max-width: 32rem; }
.live { padding: 1.25rem; background: var(--card); border: 1px solid var(--line); border-radius: .75rem; margin: 1.5rem 0; }
.live img { border: 1px solid var(--line); border-radius: .5rem; }

/* Legal pages */
.legal { max-width: 44rem; }
.legal h2 { margin-top: 2.5rem; font-size: 1.25rem; scroll-margin-top: 1rem; }
.legal .summary { background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); padding: .25rem 1.5rem 1rem; border-radius: .75rem; }
.legal .summary h2 { margin-top: 1.25rem; }
.legal .summary li { margin: .375rem 0; }
.legal .toc { margin-top: 2rem; }
.legal .toc ol { columns: 2; font-size: .9375rem; padding-left: 1.25rem; }
.legal .toc li { margin: .25rem 0; }
.legal table { font-size: .9rem; }
.legal dt { font-weight: 600; margin-top: .75rem; }
.legal dd { margin: 0; }
@media (max-width: 40rem) {
  .legal .toc ol { columns: 1; }
  .legal table, .legal tbody, .legal tr, .legal td, .legal th { display: block; }
  .legal tr { border-bottom: 1px solid var(--line); padding: .5rem 0; }
  .legal tr:first-child { display: none; }
  .legal td { border: 0; padding: .15rem 0; }
  .legal td:nth-child(2)::before { content: "Why: "; font-weight: 600; }
  .legal td:nth-child(3)::before { content: "Kept: "; font-weight: 600; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* Print: only the code, at the chosen preset size. */
@media print {
  header.site, footer.site, main > :not(#generator), #generator > :not(.output), .output > :not(#preview), figcaption { display: none !important; }
  body { background: #fff; }
  #generator { border: 0; box-shadow: none; padding: 0; background: none; display: block; }
  #preview svg { border: 0; border-radius: 0; max-width: none; margin: 0 auto; }
  body[data-print=sticker] #preview svg { width: 5cm; }
  body[data-print=a6] #preview svg { width: 9cm; }
  body[data-print=a4] #preview svg { width: 17cm; }
}
