:root {
  color-scheme: light;
  --bg: #f4efe6;
  --surface: #fffdf8;
  --ink: #2f2319;
  --muted: #74665a;
  --line: #e2d8c8;
  --line-strong: #cdbfa9;
  --gold: #a8874a;
  --gold-deep: #6a4d1f;
  --danger: #a3372b;
  --radius: 14px;
  --topbar: 64px;
  --display: 'Cormorant Garamond', Georgia, serif;
  --sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(.22, .61, .36, 1);
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 300px; color: var(--ink); font: 400 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
h1, h2 { margin: 0; font-family: var(--display); font-weight: 600; line-height: 1.1; letter-spacing: -.01em; }
p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--gold-deep); }

/* ---------- top bar with the step tracker ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: var(--topbar); padding: 10px clamp(16px, 4vw, 40px); background: #f4efe6eb; border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-size: 22px; font-weight: 600; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--gold); color: var(--gold-deep); font-size: 20px; line-height: 1; }
.steps { display: flex; gap: 4px; }
.steps button {
  display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px 0 8px; border: 0; border-radius: 999px;
  background: none; color: var(--muted); font: 500 14px var(--sans); cursor: pointer;
}
.steps b { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line-strong); font-size: 12px; font-weight: 600; }
.steps button:hover { color: var(--ink); }
.steps button[aria-current] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px #2f23191f; }
.steps button[aria-current] b { background: var(--ink); border-color: var(--ink); color: #fbf6ec; }
.steps button.is-done b { background: #e9dcc2; border-color: #d8c5a0; color: var(--gold-deep); }
.steps button:focus-visible { outline: 2px solid var(--gold); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 20px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--ink);
  font: 600 14px/1 var(--sans); text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease), transform .1s;
}
.btn:hover { border-color: var(--gold); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fbf6ec; }
.btn-primary:hover { background: #4a3a2f; border-color: #4a3a2f; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); border-color: var(--line); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small { min-height: 36px; padding: 0 14px; font-size: 13px; }
.btn-big { min-width: 220px; min-height: 54px; font-size: 15px; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.is-busy::after { content: ''; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
.link-btn { padding: 0; border: 0; background: none; color: var(--gold-deep); font: 600 13px var(--sans); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---------- layout: steps on the left, live preview on the right ---------- */
.builder { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 42%); min-height: calc(100svh - var(--topbar)); }
.panel { display: flex; flex-direction: column; width: 100%; max-width: 820px; justify-self: center; padding: clamp(24px, 4vw, 44px) clamp(16px, 4vw, 48px) 0; }
.step { flex: 1; padding-bottom: 32px; }
.step h1 { margin: 6px 0 8px; font-size: clamp(32px, 5vw, 44px); }
.lede { max-width: 620px; color: var(--muted); font-size: 16px; }
.subhead { margin: 30px 0 12px; font-size: 24px; }
.load-error, .form-error { margin: 0 0 18px; padding: 12px 14px; border-radius: 10px; background: #a3372b14; color: var(--danger); font-weight: 500; }
.step-nav {
  position: sticky; bottom: 0; z-index: 5; display: flex; justify-content: space-between; gap: 12px;
  margin: 0 calc(-1 * clamp(16px, 4vw, 48px)); padding: 14px clamp(16px, 4vw, 48px) max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.step-nav #next-btn { margin-left: auto; min-width: 150px; }

/* ---------- choice cards (designs, covers) ---------- */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: 16px; margin-top: 24px; }
.choice-grid--covers { margin-top: 0; grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); }
.choice {
  display: flex; flex-direction: column; padding: 0; overflow: hidden; text-align: left; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: inherit; font: inherit;
  box-shadow: 0 1px 2px #2f23190d; transition: border-color .2s var(--ease), box-shadow .2s var(--ease), transform .2s var(--ease);
}
.choice:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.choice[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink), 0 12px 30px -16px #2f231966; }
.choice:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
/* A 390-px-wide page scaled into the card (--s set by app.js). */
.thumb { position: relative; display: block; aspect-ratio: 390 / 560; overflow: hidden; background: #ece6dc; pointer-events: none; }
.thumb--cover { aspect-ratio: 390 / 640; }
.thumb iframe { position: absolute; top: 0; left: 0; width: 390px; height: 700px; border: 0; transform-origin: 0 0; transform: scale(var(--s, .5)); }
.thumb--cover iframe { height: 800px; }
.choice-body { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px 14px; }
.choice-name { font-family: var(--display); font-size: 21px; font-weight: 600; line-height: 1.15; }
.choice-desc { font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.choice[aria-pressed="true"] .choice-name::after { content: ' ✓'; color: var(--gold-deep); }
.swatches { display: flex; gap: 4px; margin-top: 6px; }
.swatches i { width: 16px; height: 16px; border-radius: 50%; box-shadow: inset 0 0 0 1px #0000001f; }

/* Openings */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  min-height: 40px; padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface);
  color: var(--ink); font: 500 14px var(--sans); cursor: pointer; transition: background-color .2s var(--ease), border-color .2s var(--ease);
}
.chip:hover { border-color: var(--gold); }
.chip[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: #fbf6ec; }
.chip--universal { border-style: dashed; }
.chip--universal[aria-checked="true"] { border-style: solid; }
.chip:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.chip--color { display: inline-flex; align-items: center; gap: 8px; padding-left: 8px; }
.chip--color i { width: 24px; height: 24px; border-radius: 50%; background: var(--swatch); box-shadow: inset 0 0 0 1px #0000002e; }

/* ---------- form ---------- */
.group { margin: 26px 0 0; padding: 22px 22px 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.group legend { padding: 0 8px; margin-left: -8px; font-family: var(--display); font-size: 22px; font-weight: 600; }
.stack, .pair { display: grid; gap: 0 16px; }
.pair { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; min-width: 0; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field label { font-size: 13px; font-weight: 600; }
.field input:not([type="color"]):not([type="range"]), .field textarea, .field select {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 10px;
  background: #fff; color: var(--ink); font: 400 16px/1.4 var(--sans); transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.field textarea { resize: vertical; min-height: 88px; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px #a8874a33; }
.hint { min-height: 1em; font-size: 12.5px; color: var(--muted); }
.has-error input, .has-error textarea, .has-error select { border-color: var(--danger) !important; }
.has-error .hint { color: var(--danger); font-weight: 500; }

/* "Aa": font, colour and size of one text */
.aa, .aa-inline {
  display: inline-grid; place-items: center; min-width: 34px; height: 28px; padding: 0 8px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--gold-deep); font: italic 600 15px/1 var(--display);
}
.aa { cursor: pointer; }
.aa:hover, .aa[aria-expanded="true"] { border-color: var(--gold); background: #f6efdf; }
.aa:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.aa-inline { height: 22px; min-width: 28px; font-size: 13px; vertical-align: 1px; }
.style-panel { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px solid #e6d6b5; border-radius: 12px; background: #fbf6ea; }
.mini { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.mini select { min-height: 40px !important; padding: 6px 10px !important; font-size: 15px !important; }
.font-sample { padding: 4px 6px; font-size: 26px; line-height: 1.2; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; }
.mini--color input { width: 54px; height: 36px; padding: 2px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; cursor: pointer; }
.mini--size { flex: 1; min-width: 160px; }
.mini--size input { width: 100%; accent-color: var(--gold-deep); }
.mini--size output { font-weight: 600; color: var(--ink); }
.mini-row .btn { margin-left: auto; }

/* Card colours */
.color-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.color-field { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 13px; font-weight: 500; cursor: pointer; }
.color-field input { width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; }
.color-field input::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input::-webkit-color-swatch { border: 1px solid #0000002e; border-radius: 50%; }

/* ---------- publish ---------- */
.summary { display: grid; grid-template-columns: auto 1fr; gap: 10px 20px; margin: 22px 0 6px; padding: 18px 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.summary dt { font-size: 13px; font-weight: 600; color: var(--muted); }
.summary dd { display: flex; justify-content: space-between; gap: 12px; margin: 0; font-weight: 500; }
.slug-input { display: flex; align-items: stretch; border: 1px solid var(--line-strong); border-radius: 10px; background: #fff; overflow: hidden; }
.slug-input:focus-within { border-color: var(--gold); box-shadow: 0 0 0 3px #a8874a33; }
.has-error .slug-input { border-color: var(--danger); }
.slug-prefix { display: flex; align-items: center; padding: 0 4px 0 12px; color: var(--muted); font-size: 14px; white-space: nowrap; background: #faf6ef; border-right: 1px solid var(--line); max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.slug-input input { border: 0 !important; border-radius: 0 !important; box-shadow: none !important; }
.slug-input input:disabled { background: #faf6ef; color: var(--muted); }
#turnstile { margin-bottom: 16px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 22px; }

/* ---------- live preview: a phone (390 × 844) scaled to fit the pane ---------- */
.preview-pane {
  position: sticky; top: var(--topbar); height: calc(100svh - var(--topbar)); display: flex; flex-direction: column; align-items: center;
  padding: 16px 12px 18px; background: linear-gradient(#ebe4d8, #e4dccd); border-left: 1px solid var(--line);
}
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: min(100%, 420px); margin-bottom: 14px; }
.preview-title { font-family: var(--display); font-size: 20px; font-weight: 600; }
.segmented { display: inline-flex; padding: 3px; border-radius: 999px; background: #d9cfbe80; }
.segmented button { min-height: 34px; padding: 0 14px; border: 0; border-radius: 999px; background: none; color: var(--muted); font: 600 13px var(--sans); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px #2f23191f; }
.segmented button:focus-visible { outline: 2px solid var(--gold); }
.preview-close { display: none; }
.phone {
  --scale: .7; flex: none; width: calc(410px * var(--scale)); height: calc(864px * var(--scale));
  padding: calc(10px * var(--scale)); border-radius: calc(46px * var(--scale)); background: #1d1712;
  box-shadow: 0 30px 60px -24px #2f231966, inset 0 0 0 1px #ffffff1a;
}
.phone-screen { position: relative; width: 100%; height: 100%; overflow: hidden; border-radius: calc(36px * var(--scale)); background: #ece6dc; }
.phone-screen iframe { position: absolute; top: 0; left: 0; width: 390px; height: 844px; border: 0; transform-origin: 0 0; transform: scale(var(--scale)); background: #ece6dc; transition: opacity .25s var(--ease); }
.phone-screen iframe.is-back { opacity: 0; pointer-events: none; }
.preview-play { margin-top: 12px; }
.preview-fab { display: none; }

@media (max-width: 960px) {
  .steps span { display: none; }
  .steps button { padding: 0 6px; }
}
@media (max-width: 900px) {
  .builder { grid-template-columns: 1fr; }
  .preview-pane { position: fixed; inset: 0; z-index: 40; height: auto; display: none; border: 0; padding-top: max(16px, env(safe-area-inset-top)); }
  .preview-pane.is-open { display: flex; }
  .preview-close { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--line-strong); border-radius: 50%; background: var(--surface); font-size: 22px; line-height: 1; cursor: pointer; }
  .preview-fab { display: inline-flex; position: fixed; z-index: 30; right: 16px; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 66px); box-shadow: 0 10px 30px #2f231959; }
}
@media (max-width: 520px) {
  .brand { font-size: 0; gap: 0; }
  .choice-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .choice-desc { display: none; }
}

/* ---------- dialogs ---------- */
.dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100svh - 32px); padding: 28px; border: 0; border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px #2f231966; }
.dialog::backdrop { background: #2f231966; -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dialog[open] { animation: pop .3s var(--ease); }
.dialog h2 { margin: 6px 0 8px; font-size: 32px; }
.link-box { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 8px 8px 8px 14px; border: 1px solid var(--line-strong); border-radius: 12px; background: #fff; }
.link-box a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--gold-deep); font-weight: 600; text-decoration: none; }
.share-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.edit-box { margin-top: 22px; padding: 16px; border-radius: 12px; background: #f6efdf; border: 1px solid #e6d6b5; font-size: 14px; }
.edit-box .link-box a { font-weight: 500; font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin: 20px 0 0; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 24px; translate: -50% 20px; max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 12px; background: var(--ink); color: #fbf6ec; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .25s var(--ease), translate .25s var(--ease); }
.toast.is-shown { opacity: 1; translate: -50% 0; }

/* ---------- 404 (served by the Worker) ---------- */
.notfound { display: grid; place-items: center; min-height: 100svh; padding: 24px; text-align: center; }
.notfound main { max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.notfound h1 { font-size: 40px; }
.notfound .btn { margin-top: 8px; }

@keyframes spin { to { rotate: 360deg; } }
@keyframes pop { from { opacity: 0; scale: .96; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Photos: square thumbnails, a remove button on each, and an add tile. */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.photo-slot, .photo-add { position: relative; aspect-ratio: 4 / 5; border-radius: 10px; overflow: hidden; }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-remove {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; border: 0; cursor: pointer;
  background: #000000a6; color: #fff; font-size: 18px; line-height: 1;
}
.photo-add {
  border: 1.5px dashed var(--gold); background: #a8874a12; color: var(--gold); cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600;
}
.photo-add:hover, .photo-add:focus-visible { background: #a8874a26; outline: none; }
