:root {
  color-scheme: light dark;
  --color-bg: #ffffff;
  --color-bg-elevated: #f8fafc;
  --color-text: #1e293b;
  --color-muted: #64748b;
  --color-accent: #2563eb;
  --color-accent-text: #ffffff;
  --color-border: #e2e8f0;
  --color-error-bg: #fef2f2;
  --color-error-border: #fca5a5;
  --color-error-text: #991b1b;
  --color-ok-bg: #f0fdf4;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-bg-elevated: #111827;
    --color-text: #e2e8f0;
    --color-muted: #94a3b8;
    --color-accent: #60a5fa;
    --color-accent-text: #0f172a;
    --color-border: #1e293b;
    --color-error-bg: #2a1212;
    --color-error-border: #7f1d1d;
    --color-error-text: #fecaca;
    --color-ok-bg: #0a2218;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

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

.site-header,
.site-footer {
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-elevated);
}
.site-footer {
  border-top: 1px solid var(--color-border);
  border-bottom: none;
  margin-top: 3rem;
  padding: 1.5rem 0;
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
  padding-bottom: 1rem;
}
.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-text);
}
.site-header nav a {
  margin-left: 1rem;
}

/* ------------- Intro ------------- */

.intro {
  padding: 2rem 0 1rem;
}
.intro h1 {
  margin: 0 0 0.5rem;
  font-size: 1.8rem;
}
.intro .lede {
  color: var(--color-muted);
  max-width: 60ch;
  margin: 0 0 1rem;
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 380px);
  gap: 2rem;
  align-items: start;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

/* ------------- Form ------------- */

.form fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin: 0 0 1.25rem;
  padding: 1rem 1.25rem 1.25rem;
  background: var(--color-bg-elevated);
}
.form legend {
  padding: 0 0.5rem;
  font-weight: 600;
}
.form legend .legend-button {
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 0;
}
.form legend .legend-button .chev {
  display: inline-block;
  width: 1em;
}

.field {
  margin: 0.75rem 0;
}
.field > label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
  font: inherit;
}
.field textarea {
  resize: vertical;
  min-height: 4.5em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  border-color: var(--color-accent);
}
.field .hint {
  margin: 0.25rem 0 0;
  font-size: 0.82rem;
  color: var(--color-muted);
}
.field.narrow { max-width: 12rem; }

.row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.row .field { flex: 1 1 12rem; }
.row .field.narrow { flex: 0 0 12rem; }

.req { color: var(--color-error-text); }
.muted { color: var(--color-muted); font-weight: normal; }

button,
.link-button {
  cursor: pointer;
}
button {
  background: var(--color-accent);
  color: var(--color-accent-text);
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-weight: 600;
}
button:hover { filter: brightness(0.95); }
.link-button {
  background: none;
  border: none;
  color: var(--color-accent);
  text-decoration: underline;
  padding: 0;
  font: inherit;
  margin-top: 0.25rem;
}

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

.preview {
  position: sticky;
  top: 1rem;
}
.preview h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}
.qr-frame {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg-elevated);
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 22rem;
}
#qr-preview svg {
  width: 100%;
  max-width: 18rem;
  height: auto;
  display: block;
}
.placeholder {
  color: var(--color-muted);
  text-align: center;
  margin: 0;
}

.downloads {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.downloads button { flex: 1 1 auto; }

.errors {
  margin: 0.75rem 0 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-error-border);
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.errors ul {
  margin: 0.4rem 0 0;
  padding-left: 1.2rem;
}

.payload-block {
  margin-top: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  background: var(--color-bg-elevated);
}
.payload-block summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}
.payload-block textarea {
  width: 100%;
  margin-top: 0.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem;
  resize: vertical;
}

.small { font-size: 0.85rem; }

/* ------------- About page ------------- */

.about main { max-width: 70ch; }
.about h1 { margin-top: 0; }
.about h2 { margin-top: 2rem; }
