/* ============================================================
   QRaftr — iOS-style interface
   System (SF) typography, grouped inset cards, translucent
   bars, switch toggles, pull-down menus, bottom-sheet modal.
   ============================================================ */

:root {
  /* iOS system palette (light) */
  --bg:        #F2F2F7;   /* systemGroupedBackground */
  --elev:      #FFFFFF;   /* secondarySystemGroupedBackground */
  --label:     #1C1C1E;
  --label-2:   rgba(60,60,67,.60);
  --label-3:   rgba(60,60,67,.30);
  --separator: rgba(60,60,67,.24);
  --fill-1:    rgba(118,118,128,.12);
  --fill-2:    rgba(118,118,128,.16);
  --tint:      #5B2CF0;   /* brand violet, used as the app tint */
  --tint-press:#4a1fce;
  --green:     #34C759;   /* switch on */
  --red:       #FF3B30;
  --track-off: #E9E9EA;

  --r-card: 16px;
  --r-ctl:  12px;
  --r-field:10px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Monaco, "Cascadia Mono", monospace;

  --ease: cubic-bezier(.32,.72,0,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.35;
  letter-spacing: -.01em;
  color: var(--label);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Finder-pattern mark (About head) */
.finder {
  display: inline-block; width: 26px; height: 26px;
  border: 3px solid currentColor; border-radius: 7px;
  position: relative; flex: none;
}
.finder::after { content: ""; position: absolute; inset: 5px; background: currentColor; border-radius: 2px; }

/* ---------- Nav bar (translucent large title) ---------- */
header {
  position: sticky; top: 0; z-index: 30;
  padding: 10px clamp(16px, 5vw, 28px) 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(242,242,247,.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--separator);
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
}
.brand { display: flex; flex-direction: column; }
.brand .finder { display: none; }          /* large-title bars are text only */
.brand h1 {
  margin: 0; font-size: 32px; font-weight: 700;
  letter-spacing: -.022em; line-height: 1.05; color: var(--label);
}
.brand .kicker {
  margin-top: 2px; font-size: 13px; font-weight: 400;
  letter-spacing: -.006em; color: var(--label-2);
  text-transform: none;
}
.header-actions { display: flex; align-items: center; gap: 8px; padding-bottom: 4px; }

/* ---------- Layout ---------- */
main {
  flex: 1; width: 100%; max-width: 1120px; margin: 0 auto;
  padding: clamp(14px, 3vw, 26px) clamp(12px, 5vw, 28px) 40px;
  display: grid; grid-template-columns: minmax(0,1fr) 380px;
  gap: clamp(16px, 3vw, 30px); align-items: start;
}
.controls { min-width: 0; }

/* ---------- Grouped section cards ---------- */
.section {
  background: var(--elev);
  border-radius: var(--r-card);
  margin-bottom: 22px;
  overflow: hidden;
}
.section > .section-head,
details.section > summary {
  font-size: 13px; font-weight: 400; letter-spacing: -.006em;
  color: var(--label-2); text-transform: none;
  padding: 0; margin: 0 4px 7px 8px;
}
/* header sits ABOVE the card, iOS grouped-list style */
.section { position: relative; }
.section > .section-head {
  position: absolute; top: -27px; left: 4px; display: flex; align-items: center; gap: 8px;
}
.section > .section-head .idx { color: var(--tint); font-weight: 600; font-variant-numeric: tabular-nums; }
.section-body { padding: 16px; }

/* first card needs top clearance for its floating header */
.controls > .section:first-child { margin-top: 30px; }

/* Collapsible sections */
details.section { margin-top: 30px; }
details.section > summary {
  position: absolute; top: -27px; left: 4px;
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px; width: calc(100% - 8px);
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary .idx { color: var(--tint); font-weight: 600; }
details.section > summary .chev { margin-left: auto; color: var(--label-3); transition: transform .25s var(--ease); }
details.section[open] > summary .chev { transform: rotate(90deg); }
details.section:not([open]) { background: var(--elev); }
details.section > .section-body { padding-top: 16px; }

/* ---------- Type picker (selectable cells) ---------- */
.types { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px,1fr)); gap: 10px; }
.type-chip {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 13px 8px; border: none; border-radius: var(--r-ctl);
  background: var(--fill-1); color: var(--label-2);
  font-family: var(--font); font-size: 13px; font-weight: 500; letter-spacing: -.01em;
  cursor: pointer; transition: background .18s, color .18s, transform .1s var(--ease);
}
.type-chip svg { width: 22px; height: 22px; }
.type-chip:active { transform: scale(.95); }
.type-chip.active { background: var(--tint); color: #fff; box-shadow: 0 4px 12px color-mix(in srgb, var(--tint) 30%, transparent); }

/* ---------- Fields ---------- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.field.row .field { margin-bottom: 0; }

label.lbl {
  display: block; font-size: 13px; font-weight: 400; letter-spacing: -.006em;
  color: var(--label-2); margin: 0 0 7px 3px;
}
label.lbl .hint { color: var(--label-3); }

input[type="text"], input[type="url"], input[type="email"],
input[type="tel"], input[type="number"], input[type="password"], textarea {
  width: 100%; font-family: var(--font); font-size: 17px; letter-spacing: -.01em;
  color: var(--label); background: var(--fill-1);
  border: none; border-radius: var(--r-field);
  padding: 12px 14px; transition: box-shadow .18s, background .18s;
}
input::placeholder, textarea::placeholder { color: var(--label-3); }
textarea { resize: vertical; min-height: 84px; line-height: 1.4; }
input:focus, textarea:focus, select:focus {
  outline: none; background: #fff;
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--tint) 22%, transparent);
}

/* Pull-down menu (styled select) */
select {
  width: 100%; appearance: none; font-family: var(--font);
  font-size: 17px; font-weight: 500; letter-spacing: -.01em;
  color: var(--tint); background: var(--fill-1);
  border: none; border-radius: var(--r-field);
  padding: 12px 40px 12px 14px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='M4 5.5L7 3l3 2.5M4 8.5L7 11l3-2.5' fill='none' stroke='%235B2CF0' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}

/* ---------- iOS switch ---------- */
.checkline {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 17px; letter-spacing: -.01em; color: var(--label); cursor: pointer;
  min-height: 32px;
}
.cl-text { flex: 1; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; width: 51px; height: 31px; margin: 0; opacity: 0; cursor: pointer; z-index: 2; }
.switch .knob {
  display: block; width: 51px; height: 31px; border-radius: 31px;
  background: var(--track-off); transition: background .3s var(--ease);
}
.switch .knob::before {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 1px 1px rgba(0,0,0,.16);
  transition: transform .3s var(--ease);
}
.switch input:checked + .knob { background: var(--green); }
.switch input:checked + .knob::before { transform: translateX(20px); }

/* ---------- Colour swatches ---------- */
.swatch-row { display: flex; align-items: center; gap: 12px; }
.swatch {
  width: 44px; height: 34px; padding: 0; border: none; border-radius: 9px;
  background: none; cursor: pointer; flex: none;
  box-shadow: inset 0 0 0 1px var(--separator);
}
.swatch::-webkit-color-swatch-wrapper { padding: 3px; }
.swatch::-webkit-color-swatch { border: none; border-radius: 7px; }
.swatch::-moz-color-swatch { border: none; border-radius: 7px; }
.hexbox { font-family: var(--mono); font-size: 15px; text-transform: uppercase; max-width: 116px; }

/* ---------- Shape choice grids ---------- */
.choicegrid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }
.choice {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 12px 6px; border: none; border-radius: var(--r-ctl);
  background: var(--fill-1); color: var(--label-2);
  font-size: 12px; letter-spacing: -.006em; cursor: pointer;
  transition: background .18s, color .18s, transform .1s var(--ease);
}
.choice:active { transform: scale(.95); }
.choice svg { width: 30px; height: 30px; color: var(--label); }
.choice.active { background: color-mix(in srgb, var(--tint) 12%, #fff); color: var(--tint); box-shadow: inset 0 0 0 1.5px var(--tint); }
.choice.active svg { color: var(--tint); }

/* ---------- Presets ---------- */
.presets { display: flex; flex-wrap: wrap; gap: 9px; }
.preset {
  font-size: 15px; font-weight: 500; letter-spacing: -.01em;
  padding: 9px 15px; border: none; border-radius: 999px;
  background: var(--fill-1); color: var(--tint); cursor: pointer;
  transition: background .18s, transform .1s var(--ease);
}
.preset:active { transform: scale(.96); background: var(--fill-2); }

/* ---------- Sliders ---------- */
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  border-radius: 999px; background: var(--fill-2); outline: none; margin: 10px 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 28px; height: 28px; border-radius: 50%;
  background: #fff; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.18), 0 3px 8px rgba(0,0,0,.12);
}
input[type="range"]::-moz-range-thumb {
  width: 28px; height: 28px; border: none; border-radius: 50%; background: #fff;
  cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.18), 0 3px 8px rgba(0,0,0,.12);
}
.range-val { font-family: var(--mono); font-size: 15px; color: var(--label-2); float: right; }

/* ---------- Logo drop ---------- */
.logo-drop {
  border: 1.5px dashed var(--label-3); border-radius: var(--r-ctl);
  padding: 20px; text-align: center; font-size: 15px; color: var(--label-2);
  cursor: pointer; transition: border-color .18s, background .18s; line-height: 1.5;
}
.logo-drop:active { background: var(--fill-1); }
.logo-preview { display: flex; align-items: center; gap: 14px; }
.logo-preview img { width: 46px; height: 46px; object-fit: contain; border-radius: 10px; background: #fff; box-shadow: inset 0 0 0 1px var(--separator); }

/* ---------- Preview card ---------- */
.preview-col { position: sticky; top: 96px; }
.bed {
  background: var(--elev); border-radius: var(--r-card); padding: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 12px 30px rgba(0,0,0,.06);
  position: relative; overflow: hidden;
}
.bed::before, .bed::after { content: none; }   /* remove crop marks */
.bed-top {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; letter-spacing: -.006em; color: var(--label-2); margin-bottom: 14px;
}
.bed-top .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); display: inline-block; margin-right: 7px; vertical-align: middle; }
#bed-type-label { color: var(--tint); font-weight: 500; }

.qr-stage {
  position: relative; background: var(--bg); border-radius: var(--r-ctl);
  padding: 16px; display: grid; place-items: center; aspect-ratio: 1/1;
  min-height: 220px; overflow: hidden;
}
.qr-stage.empty::before {
  content: "Enter something to generate a code";
  font-size: 15px; color: var(--label-3); text-align: center; padding: 0 24px;
}
#qr-canvas { max-width: 100%; height: auto; display: block; }
#qr-canvas canvas, #qr-canvas svg { max-width: 100% !important; height: auto !important; display: block; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,.08); }

/* gentle fade/scale-in instead of a laser scan */
.scanline { display: none; }
.qr-stage.scanning #qr-canvas { animation: pop .4s var(--ease); }
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }

.readout {
  margin-top: 14px; font-size: 13px; letter-spacing: -.006em; color: var(--label-2);
  display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.readout b { color: var(--label); font-weight: 600; }

/* ---------- Buttons ---------- */
.exports { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.exports .btn.primary { grid-column: 1 / -1; }

.btn {
  font-family: var(--font); font-size: 17px; font-weight: 600; letter-spacing: -.01em;
  border: none; border-radius: var(--r-ctl); padding: 14px 16px;
  background: var(--fill-1); color: var(--tint); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .1s var(--ease), background .18s, opacity .18s;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { transform: scale(.97); background: var(--fill-2); }
.btn.primary { background: var(--tint); color: #fff; box-shadow: 0 6px 16px color-mix(in srgb, var(--tint) 30%, transparent); }
.btn.primary:active { background: var(--tint-press); opacity: .95; }
.btn.ghost { background: transparent; }
.btn.icon {
  padding: 0; width: 30px; height: 30px; border-radius: 50%;
  background: var(--fill-1); color: var(--tint);
}
.btn.icon svg { width: 22px; height: 22px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:disabled:active { transform: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(30px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(14px);
  background: rgba(28,28,30,.92); color: #fff; font-size: 15px; font-weight: 500;
  padding: 12px 20px; border-radius: 999px; letter-spacing: -.01em;
  backdrop-filter: blur(12px); box-shadow: 0 8px 30px rgba(0,0,0,.24);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s var(--ease); z-index: 70;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Footer ---------- */
footer {
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  display: flex; justify-content: center;
}
footer .made { display: none; }
.version-badge {
  font-family: var(--font); font-size: 13px; letter-spacing: -.006em;
  color: var(--label-3); background: none; border: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; padding: 6px;
}
.version-badge .pulse { display: none; }
#footer-version { font-variant-numeric: tabular-nums; }

/* ---------- About: bottom sheet ---------- */
.modal-scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center; z-index: 90;
  opacity: 0; pointer-events: none; transition: opacity .3s var(--ease);
}
.modal-scrim.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--bg); width: 100%; max-width: 500px;
  border-radius: 16px 16px 0 0; overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(100%); transition: transform .38s var(--ease);
  box-shadow: 0 -8px 40px rgba(0,0,0,.2);
}
.modal-scrim.open .modal { transform: translateY(0); }
.sheet-grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label-3); margin: 8px auto 4px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 12px 22px 0; color: var(--tint); }
.modal-head h2 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 0; color: var(--label); }
.modal-body { padding: 12px 22px 8px; font-size: 15px; color: var(--label-2); line-height: 1.5; }
.modal-body p { margin: 0 0 12px; }
.modal-body dl {
  display: grid; grid-template-columns: auto 1fr; gap: 0;
  background: var(--elev); border-radius: var(--r-ctl); overflow: hidden; margin: 16px 0;
}
.modal-body dt {
  padding: 13px 16px; font-size: 15px; color: var(--label); border-bottom: .5px solid var(--separator);
}
.modal-body dd {
  margin: 0; padding: 13px 16px; text-align: right; font-family: var(--mono); font-size: 14px;
  color: var(--label-2); border-bottom: .5px solid var(--separator);
}
.modal-body dl > dt:last-of-type, .modal-body dl > dd:last-of-type { border-bottom: none; }
.modal-body .about-ver { color: var(--tint); }
.modal-foot { padding: 8px 22px 22px; }
.modal-foot .btn { width: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  main { grid-template-columns: 1fr; }
  .preview-col { position: static; order: -1; }
}
@media (max-width: 420px) {
  .exports { grid-template-columns: 1fr; }
  .field.row { grid-template-columns: 1fr; }
  .brand h1 { font-size: 28px; }
}

/* ---------- A11y / motion ---------- */
:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
