:root {
  color-scheme: light dark;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #0f172a;
  --color-muted: #64748b;
  --color-accent: #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;
  --color-error: #b91c1c;
  --color-error-bg: #fee2e2;
  --color-ok: #047857;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  --gap: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-text: #e2e8f0;
    --color-muted: #94a3b8;
    --color-accent: #60a5fa;
    --color-accent-hover: #93c5fd;
    --color-border: #334155;
    --color-border-strong: #475569;
    --color-error: #fca5a5;
    --color-error-bg: #450a0a;
    --color-ok: #6ee7b7;
  }
}

* { box-sizing: border-box; }

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

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

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

.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.site-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 0.6rem; color: inherit; font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem; height: 2rem;
  border-radius: 6px;
  background: var(--color-accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.brand-name { font-size: 1.05rem; }
nav a { margin-left: 1rem; }

.site-footer {
  margin-top: auto;
  padding: 1.5rem 1.25rem;
  text-align: center;
  color: var(--color-muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--color-border);
}

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

.layout {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); align-items: start; }
  .result-pane { position: sticky; top: 1.5rem; }
}

.form-pane h1 { margin: 0 0 0.5rem; font-size: 1.75rem; }
.lead { color: var(--color-muted); margin: 0 0 1.5rem; }

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

fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  padding: 1rem 1.25rem 1.25rem;
  margin: 0 0 1.25rem;
  box-shadow: var(--shadow-sm);
}
legend {
  font-weight: 600;
  padding: 0 0.35rem;
}

.field { display: flex; flex-direction: column; margin-bottom: 0.85rem; }
.field:last-child { margin-bottom: 0; }
.field.grow { flex: 1; }

label {
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
  font-weight: 500;
}
.req { color: var(--color-error); margin-left: 0.15rem; }

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  font: inherit;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  border-color: var(--color-accent);
}
input:disabled { opacity: 0.55; cursor: not-allowed; }
textarea { resize: vertical; min-height: 2.5rem; }

.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}
@media (min-width: 560px) {
  .row { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .row .field.grow { flex: 1 1 100%; min-width: 180px; }
}

.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-bottom: 0.85rem;
}
.radio { display: inline-flex; align-items: center; gap: 0.4rem; }
.radio input { width: auto; }

.actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 0.5rem; }

.muted { color: var(--color-muted); }
.small { font-size: 0.85rem; }

/* Hints / errors */
.hint {
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-top: 0.25rem;
  min-height: 1.1em;
}
.hint-ok { color: var(--color-ok); }
.hint-error { color: var(--color-error); }
.error {
  color: var(--color-error);
  font-size: 0.85rem;
  margin-top: 0.25rem;
  min-height: 1em;
}
.alert {
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.alert-error {
  background: var(--color-error-bg);
  color: var(--color-error);
  border: 1px solid var(--color-error);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0.55rem 1.05rem;
  border-radius: 6px;
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}
.btn:hover { border-color: var(--color-accent); color: var(--color-accent); }
.btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}
.btn-primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  color: #fff;
}
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

/* ---------- Result pane ---------- */

.result-pane h2 { margin: 0 0 1rem; font-size: 1.25rem; }

.canvas-frame {
  background: #ffffff;          /* QR always on white for scannability */
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
}
#qr-canvas { width: 100%; height: auto; max-width: 420px; }

.download-row {
  display: flex;
  gap: 0.6rem;
  margin: 1rem 0 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.payload-details { margin-top: 1rem; }
.payload-details summary { cursor: pointer; color: var(--color-muted); font-size: 0.9rem; }
#payload-output {
  width: 100%;
  margin-top: 0.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
}

/* ---------- Prose pages (About) ---------- */

.prose {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}
.prose h1 { font-size: 1.9rem; margin-top: 0; }
.prose h2 { margin-top: 2rem; font-size: 1.25rem; }
.prose p, .prose ul { font-size: 1rem; }
.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--color-surface);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  font-size: 0.92em;
}
