/* QR Generator. Self-contained stylesheet: no framework, no web fonts. */

:root {
  --bg: #f4f3ef;
  --panel: #ffffff;
  --panel-2: #f8f7f4;
  --line: #e3e0d8;
  --text: #1b1a17;
  --muted: #6c685f;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --accent-soft: #e6ecfd;
  --ok: #15803d;
  --warn: #b45309;
  --fail: #b91c1c;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.05);
  --focus: 0 0 0 3px rgb(29 78 216 / 0.35);
  --topbar: 56px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #121212;
  --panel: #1b1b1d;
  --panel-2: #232326;
  --line: #313136;
  --text: #ecebe7;
  --muted: #a19e96;
  --accent: #7aa2ff;
  --accent-ink: #0b1020;
  --accent-soft: #1e2a4a;
  --ok: #4ade80;
  --warn: #fbbf24;
  --fail: #f87171;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  --focus: 0 0 0 3px rgb(122 162 255 / 0.45);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
svg { fill: currentColor; }

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

:focus-visible { outline: none; box-shadow: var(--focus); }

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; margin-right: auto; }
.brand img { border-radius: 6px; }
.brand__name { font-weight: 700; letter-spacing: -0.01em; }
.brand__by { color: var(--muted); font-size: 13px; }
.privacy-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--ok);
  padding: 4px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}
.privacy-pill svg { width: 13px; height: 13px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; padding: 0;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--text); cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#themeToggle svg { fill: currentColor; stroke: none; }
.icon-btn--sm { width: 32px; height: 32px; align-self: end; margin-bottom: 4px; }
.icon-btn:hover { border-color: var(--muted); }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout {
  max-width: 1180px; margin: 0 auto;
  padding: 24px 20px 48px;
  display: grid; gap: 24px;
  grid-template-columns: minmax(0, 1fr) 400px;
  grid-template-areas: "editor stage";
  align-items: start;
}
.editor { grid-area: editor; display: grid; gap: 16px; min-width: 0; }
.stage {
  grid-area: stage;
  position: sticky; top: calc(var(--topbar) + 24px);
  display: grid; gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

/* ── Preview ─────────────────────────────────────────────────────────────── */
.stage__canvas {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  display: grid; place-items: center;
  overflow: hidden;
}
.is-transparent .stage__canvas, .stage__canvas {
  background-color: var(--panel-2);
}
.is-transparent .stage__canvas {
  background-image:
    linear-gradient(45deg, var(--line) 25%, transparent 25%),
    linear-gradient(-45deg, var(--line) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--line) 75%),
    linear-gradient(-45deg, transparent 75%, var(--line) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
#preview { width: 100%; height: 100%; display: block; }
.stage__empty {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 8px;
  padding: 24px; text-align: center; color: var(--muted);
}
.stage__empty svg { width: 48px; height: 48px; opacity: 0.35; }

/* ── Status ──────────────────────────────────────────────────────────────── */
.status { display: grid; gap: 6px; font-size: 13.5px; }
.status__row { display: flex; gap: 8px; align-items: baseline; }
.status__row .dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--line); transform: translateY(1px); }
.status__row[data-state="ok"] { color: var(--ok); }
.status__row[data-state="ok"] .dot { background: var(--ok); }
.status__row[data-state="warn"] { color: var(--warn); }
.status__row[data-state="warn"] .dot { background: var(--warn); }
.status__row[data-state="fail"] { color: var(--fail); }
.status__row[data-state="fail"] .dot { background: var(--fail); }
.status__row[data-state="idle"] { color: var(--muted); }
.status__row[data-state="busy"] { color: var(--muted); }
.status__row[data-state="busy"] .dot { background: var(--accent); animation: pulse 0.9s ease-in-out infinite alternate; }
.status__row[data-state="idle"]:has(.status__text:empty) { display: none; }
@keyframes pulse { from { opacity: 0.25; } to { opacity: 1; } }

.capacity { display: grid; gap: 4px; }
.capacity__bar { height: 4px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.capacity__bar span { display: block; height: 100%; width: 0; background: var(--ok); transition: width 0.2s; }
.capacity[data-level="high"] .capacity__bar span { background: var(--warn); }
.capacity[data-level="over"] .capacity__bar span { background: var(--fail); }
.capacity__text { font-size: 12.5px; color: var(--muted); }

/* ── Export ──────────────────────────────────────────────────────────────── */
.export { display: grid; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.export__size { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13.5px; }
.export__buttons { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; }
.export__note { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px;
  font: inherit; font-weight: 600; font-size: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel); color: var(--text);
  cursor: pointer;
}
.btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--accent); }
.btn--ghost { min-height: 34px; font-weight: 500; justify-self: start; }

/* ── Panels ──────────────────────────────────────────────────────────────── */
.panel {
  background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
  display: grid; gap: 16px;
  min-width: 0;
}
.panel__title {
  margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 10px;
}
.step {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 13px; font-weight: 700;
}
.optional { color: var(--muted); font-weight: 400; font-size: 13px; }
.panel--details { gap: 0; }
.panel--details[open] { gap: 16px; }
.panel--details summary { cursor: pointer; list-style: none; }
.panel--details summary::-webkit-details-marker { display: none; }
.panel--details summary::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform 0.2s; }
.panel--details[open] summary::after { transform: rotate(180deg); }

.group { display: grid; gap: 10px; }
.group--split { grid-template-columns: 1fr 1fr; gap: 16px; }
.group__label { font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.sub { display: grid; gap: 12px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--panel-2); }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }

/* ── Content type chips ─────────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip span {
  display: inline-block; padding: 6px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
  font-size: 14px; font-weight: 500; cursor: pointer; user-select: none;
}
.chip span:hover { border-color: var(--muted); }
.chip input:checked + span { background: var(--text); color: var(--panel); border-color: var(--text); }
.chip input:focus-visible + span { box-shadow: var(--focus); }

/* ── Form fields ────────────────────────────────────────────────────────── */
.form { border: 0; margin: 0; padding: 0; display: grid; gap: 12px; min-width: 0; }
.field { display: grid; gap: 4px; font-size: 13.5px; font-weight: 500; min-width: 0; }
.field > span { color: var(--muted); }
.field--inline { grid-auto-flow: row; }
.field--wide { grid-column: 1 / -1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row { display: flex; flex-wrap: wrap; align-items: end; gap: 16px; }

input[type="text"], input[type="url"], input[type="email"], input[type="tel"], textarea, select {
  width: 100%;
  font: inherit; font-size: 15px; font-weight: 400;
  color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 11px;
  min-height: 40px;
}
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible { border-color: var(--accent); }
select { width: auto; max-width: 100%; }
input:disabled { opacity: 0.5; }

.more summary { cursor: pointer; font-size: 13.5px; color: var(--accent); margin-bottom: 8px; }

.warnings { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.warnings li { font-size: 13px; color: var(--warn); padding-left: 18px; position: relative; }
.warnings li::before { content: "!"; position: absolute; left: 0; font-weight: 700; }

.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; user-select: none; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }
.toggles { display: flex; flex-wrap: wrap; gap: 8px 20px; }

/* ── Colours ────────────────────────────────────────────────────────────── */
.colours { display: flex; flex-wrap: wrap; align-items: end; gap: 10px 12px; }
.colour { display: grid; gap: 4px; font-size: 13.5px; }
.colour label { color: var(--muted); font-weight: 500; }
.colour.is-disabled { opacity: 0.45; }
.colour__pair {
  display: inline-flex; align-items: center; gap: 0;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel); padding: 3px;
}
input[type="color"] {
  width: 34px; height: 32px; padding: 0; border: 0; border-radius: 6px;
  background: none; cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 1px solid rgb(0 0 0 / 0.15); border-radius: 6px; }
input[type="color"]::-moz-color-swatch { border: 1px solid rgb(0 0 0 / 0.15); border-radius: 6px; }
.hex {
  width: 92px !important; min-height: 32px !important;
  border: 0 !important; padding: 4px 8px !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace !important; font-size: 14px !important;
  text-transform: uppercase;
}
.hex.is-invalid { color: var(--fail); }

/* ── Tiles (styled radio buttons) ───────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.tiles--sm { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); }
.tile { position: relative; display: grid; justify-items: center; align-content: center; gap: 4px;
  min-height: 64px; padding: 8px 4px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel); cursor: pointer; user-select: none;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
}
.tiles--sm .tile { min-height: 48px; }
.tile svg { width: 26px; height: 26px; color: var(--text); }
.tile:hover { border-color: var(--muted); }
.tile:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tile:has(input:checked) svg { color: var(--accent); }
.tile:has(input:focus-visible) { box-shadow: var(--focus); }

/* ── Presets ────────────────────────────────────────────────────────────── */
.presets { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.preset {
  display: grid; justify-items: center; gap: 4px;
  padding: 10px 6px 8px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel); color: var(--text);
  font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer;
}
.preset canvas { width: 52px; height: 52px; }
.preset:hover { border-color: var(--accent); }

/* ── Range inputs ───────────────────────────────────────────────────────── */
.range { display: grid; gap: 2px; font-size: 13.5px; }
.range > span { display: flex; gap: 6px; align-items: baseline; color: var(--muted); font-weight: 500; }
.range output { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0; }

/* ── Logo drop zone ─────────────────────────────────────────────────────── */
.drop { border: 1.5px dashed var(--line); border-radius: var(--radius); background: var(--panel-2); transition: border-color 0.15s, background 0.15s; }
.drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop__label { display: grid; justify-items: center; gap: 4px; padding: 20px; text-align: center; cursor: pointer; font-size: 14px; }
.drop__label svg { width: 26px; height: 26px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.drop:has(input:focus-visible) { box-shadow: var(--focus); }
.drop__loaded { display: flex; align-items: center; gap: 12px; padding: 10px 12px; }
.drop__loaded img { width: 48px; height: 48px; object-fit: contain; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); }
.drop__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }

/* ── Footer, toast ──────────────────────────────────────────────────────── */
.foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 8px 0; font-size: 13px; color: var(--muted); }
.foot a { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  transform: translateX(-50%);
  max-width: min(92vw, 480px);
  padding: 10px 16px; border-radius: var(--radius-sm);
  background: var(--text); color: var(--panel);
  font-size: 14px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
}

/* ── Tablet and mobile ──────────────────────────────────────────────────── */
@media (max-width: 899px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "stage" "editor";
    padding: 12px 12px 120px;
    gap: 12px;
  }
  .stage {
    top: var(--topbar);
    z-index: 20;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 0 0 var(--radius) var(--radius);
    margin: -12px -12px 0;
    border-top: 0;
  }
  .stage__canvas { width: min(36vw, 26vh, 200px); }
  .stage__empty svg { width: 28px; height: 28px; }
  .stage__empty { font-size: 12px; padding: 8px; }
  .export {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgb(0 0 0 / 0.08);
    gap: 8px;
  }
  .export__note { display: none; }
  .privacy-pill { display: none; }
  .panel { padding: 16px; }
  .presets { grid-template-columns: repeat(5, minmax(56px, 1fr)); overflow-x: auto; }
}

@media (max-width: 520px) {
  .grid2, .group--split { grid-template-columns: 1fr; }
  .brand__by { display: none; }
  .capacity__text { font-size: 11.5px; }
}

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