:root {
  --bg-1: #fbf6ef;
  --bg-2: #efe4d6;
  --card: #fffdfa;
  --ink: #3a2f2a;
  --muted: #8a7d74;
  --accent: #9a7b5c;
  --accent-soft: #f1e9e1;
  --line: #e7ded5;
  --error: #a2554a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
  min-height: 100svh;
  font-family: "Manrope", system-ui, sans-serif; color: var(--ink);
  background: radial-gradient(ellipse at 50% 30%, var(--bg-1) 0%, var(--bg-2) 100%) fixed;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.script { font-family: "Marck Script", cursive; font-weight: 400; }
.caps { text-transform: uppercase; letter-spacing: .28em; font-size: 11px; font-weight: 500; color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.5; }
.mono { font-family: ui-monospace, Consolas, monospace; white-space: nowrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.error { color: var(--error); font-size: 14px; min-height: 1.2em; }
.warn { color: var(--error); }

/* ---------- Кнопки ---------- */
.btn-primary {
  border: 0; border-radius: 16px; padding: 15px 22px; cursor: pointer; font-size: 16px;
  background: var(--accent); color: #fff; transition: filter .2s, transform .1s;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-primary.wide { width: 100%; }
.btn-ghost {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 10px 16px;
  cursor: pointer; font-size: 14px; text-decoration: none; text-align: center; transition: border-color .2s;
  color: var(--ink);
}
.btn-ghost:hover { border-color: var(--accent); }

/* ---------- Ключ и результат ---------- */
.wrap {
  min-height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 24px; padding: 24px 16px;
}
.brand { font-size: 28px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.card {
  width: min(460px, 100%); background: var(--card); border-radius: 28px; padding: 34px 24px;
  box-shadow: 0 20px 50px rgba(90,65,40,.1); display: grid; gap: 14px; text-align: center;
}
.card h1 { font-size: 46px; line-height: 1.05; }
.lead { line-height: 1.6; color: var(--muted); font-size: 15px; }
.hint { font-size: 13px; }
.terms { display: flex; gap: 10px; align-items: flex-start; text-align: left; font-size: 14px; line-height: 1.5; color: var(--muted); cursor: pointer; }
.terms input { width: 18px; height: 18px; flex: none; margin-top: 2px; accent-color: var(--accent); }
.terms a { color: var(--accent); }
.terms.invalid { color: var(--error); }
.key-input {
  width: 100%; margin-top: 6px; padding: 16px; border-radius: 14px; border: 1px solid var(--line); background: #fff;
  font-family: ui-monospace, Consolas, monospace; font-size: 22px; letter-spacing: .12em; text-align: center;
  text-transform: uppercase; outline: 2px solid transparent; transition: outline-color .2s;
}
.key-input:focus { outline-color: var(--accent); }
.key-input.invalid { outline-color: var(--error); }
.key-input::placeholder { color: #c9bdb2; }

.link-box { text-align: left; display: grid; gap: 8px; padding: 16px; border-radius: 18px; background: var(--accent-soft); }
.link-box.secret { background: #fbefe9; border: 1px solid #ecd2c7; }
.link-box input { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 14px; }
.link-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Мастер ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 12px max(16px, calc((100% - 1160px) / 2)); background: rgba(251,246,239,.92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.progress { list-style: none; display: flex; gap: 6px; flex: 1; justify-content: center; counter-reset: s; }
.progress li {
  font-size: 12px; color: var(--muted); padding: 6px 10px; border-radius: 999px; white-space: nowrap;
  cursor: pointer; transition: background .2s;
}
.progress li::before { counter-increment: s; content: counter(s) ". "; }
.progress li.done { color: var(--ink); }
.progress li.current { background: var(--ink); color: #fff; }

.layout {
  max-width: 1160px; margin: 0 auto; padding: 24px 16px 60px;
  display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 32px; align-items: start;
}
.steps { background: var(--card); border-radius: 28px; padding: 30px 26px; box-shadow: 0 20px 50px rgba(90,65,40,.08); }
.step { display: grid; gap: 14px; }
.step h2 { font-size: 40px; line-height: 1.1; margin-bottom: 4px; }

.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.field em { font-style: normal; opacity: .8; }
.field input, .field select, .field textarea, .item input, .item textarea {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff;
  font-size: 16px; color: var(--ink); outline: 2px solid transparent; transition: outline-color .2s;
}
.field input:focus, .field select:focus, .item input:focus, .item textarea:focus { outline-color: var(--accent); }
.field input.invalid { outline-color: var(--error); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.occasions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.occasion {
  border: 1px solid var(--line); background: #fff; border-radius: 18px; padding: 16px 10px; cursor: pointer;
  display: grid; gap: 6px; justify-items: center; text-align: center; transition: border-color .2s, transform .1s;
}
.occasion:hover { border-color: var(--accent); }
.occasion.selected { border: 2px solid var(--accent); background: var(--accent-soft); }
.occasion .ico { font-size: 26px; line-height: 1; }
.occasion b { font-size: 14px; }

.subhead { font-size: 16px; font-weight: 700; margin-top: 10px; }

/* Образцы дизайнов: мини-конверт, раскрашенный той же темой (themes.css), что и приглашение */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.swatch {
  /* значения кремовой темы — остальные переопределяет [data-theme] из themes.css */
  --env-screen: radial-gradient(ellipse at 50% 40%, #fffaf2 0%, #f3e9dc 70%, #eadcca 100%);
  --motif: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cg fill='%23c9a560' opacity='.55'%3E%3Cpath d='M20 14l1.6 4.4L26 20l-4.4 1.6L20 26l-1.6-4.4L14 20l4.4-1.6z'/%3E%3Cpath d='M86 70l1 2.8 2.8 1-2.8 1-1 2.8-1-2.8-2.8-1 2.8-1z'/%3E%3C/g%3E%3C/svg%3E");
  --paper-bg: linear-gradient(160deg, #f8efe0, #ecdfc9);
  --seal: radial-gradient(circle at 35% 30%, #f0d593, #c79a45 55%, #9c7430);
  --env-name: #5c4a35; --font-script: "Marck Script"; --script-scale: 1;
  position: relative; cursor: pointer; border: 2px solid transparent; border-radius: 18px; padding: 0;
  background: var(--env-screen); overflow: hidden; text-align: center; transition: transform .15s, border-color .2s;
}
.swatch:hover { transform: translateY(-2px); }
.swatch[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 0 0 3px #fff inset; }
.swatch .mini {
  display: block; margin: 14px auto 6px; width: 62%; aspect-ratio: 4 / 5; border-radius: 8px; position: relative;
  background: var(--motif), var(--paper-bg); background-size: 60px, cover;
  box-shadow: 0 6px 14px rgba(0,0,0,.18);
}
.swatch .mini::before {
  /* клапан конверта */
  content: ""; position: absolute; inset: 0 0 42% 0; background: inherit; filter: brightness(1.06);
  clip-path: polygon(0 0, 100% 0, 50% 100%); border-radius: 8px 8px 0 0;
}
.swatch .mini::after {
  /* печать */
  content: ""; position: absolute; left: 50%; top: 58%; width: 22%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%; background: var(--seal);
}
.swatch .label {
  display: block; padding: 2px 6px 10px; color: var(--ink);
  font-style: var(--script-style, normal);
  font-family: var(--font-script), cursive; font-size: calc(19px * var(--script-scale)); line-height: 1.2;
}
.swatch .fit {
  position: absolute; top: 6px; right: 6px; font-size: 10px; padding: 2px 7px; border-radius: 999px;
  background: rgba(255,255,255,.85); color: #3a2f2a;
}

/* Своя обложка */
.cover-pick { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: start; }
.cover-thumb {
  width: 96px; aspect-ratio: 4 / 5; border-radius: 999px 999px 12px 12px; overflow: hidden;
  border: 1px solid var(--line); background: var(--accent-soft);
}
.cover-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-actions { display: grid; gap: 8px; justify-items: start; }
.file-btn { cursor: pointer; }
.file-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.cover-pick.busy .file-btn { opacity: .6; pointer-events: none; }

.list { display: grid; gap: 10px; }
.item { position: relative; display: grid; gap: 8px; padding: 14px; border-radius: 16px; background: var(--accent-soft); }
.item .item-row { display: grid; grid-template-columns: 96px 1fr; gap: 8px; }
.item textarea { resize: vertical; min-height: 60px; font-size: 15px; }
.item .remove {
  position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1;
}
.item .remove:hover { color: var(--error); border-color: var(--error); }
.item .item-title { padding-right: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; cursor: pointer; font-size: 14px;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.summary { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; padding: 16px; border-radius: 16px; background: var(--accent-soft); font-size: 14px; }
.summary dt { color: var(--muted); }
.summary dd { overflow-wrap: anywhere; }

.nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); }

/* ---------- Предпросмотр в «телефоне» ---------- */
.preview { position: sticky; top: 84px; }
.phone {
  width: 380px; height: min(780px, calc(100svh - 110px)); margin: 0 auto; border-radius: 42px; overflow: hidden;
  border: 10px solid #2c2522; box-shadow: 0 30px 60px rgba(60,40,25,.25); background: #fff;
}
.phone iframe { width: 100%; height: 100%; border: 0; display: block; }
.close-preview {
  position: absolute; top: 12px; right: 12px; z-index: 2; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.2); font-size: 22px; cursor: pointer;
}
.only-mobile { display: none; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .only-mobile { display: inline-block; }
  .progress { display: none; }
  .topbar { justify-content: space-between; }
  .preview {
    position: fixed; inset: 0; z-index: 20; display: none; place-items: center;
    background: rgba(40,30,25,.55); backdrop-filter: blur(4px); padding: 16px;
  }
  .preview.open { display: grid; }
  .phone { width: min(380px, 100%); height: min(760px, calc(100svh - 32px)); }
}
@media (max-width: 520px) {
  .steps { padding: 24px 16px; border-radius: 22px; }
  .step h2 { font-size: 34px; }
  .occasions { grid-template-columns: repeat(2, 1fr); }
  .swatches { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .swatch .mini { width: 54%; margin-top: 10px; }
  .swatch .label { font-size: calc(15px * var(--script-scale)); padding-bottom: 8px; }
  .row { grid-template-columns: 1fr; }
  .item .item-row { grid-template-columns: 84px 1fr; }
}
