:root {
  --bg: #fbf7f4;
  --surface: #ffffff;
  --surface-2: #f5eee9;
  --ink: #2b1d26;
  --muted: #7a6a72;
  --line: #eadfd8;
  --brand: #5b2245;
  --brand-2: #8e3b6b;
  --brand-soft: #f6e6ef;
  --gold: #c9a05a;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(43, 29, 38, .06), 0 8px 24px rgba(43, 29, 38, .08);
  --shadow-lg: 0 20px 60px rgba(43, 29, 38, .18);
  --font: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
  --topbar-h: 60px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
main { outline: none; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
img, canvas { display: block; max-width: 100%; }
[hidden] { display: none !important; }

/* ───────── Top bar ───────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: rgba(251, 247, 244, .86);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand span { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; letter-spacing: .01em; }
.nav { display: flex; align-items: center; gap: 4px; }
.nav a {
  text-decoration: none; color: var(--muted); font-weight: 500; padding: 8px 12px; border-radius: 999px; font-size: .92rem;
}
.nav a.active { color: var(--brand); background: var(--brand-soft); }

/* ───────── Buttons ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 10px 18px; border-radius: 999px; font-weight: 500; cursor: pointer; text-decoration: none;
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-small { padding: 6px 14px; font-size: .86rem; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--danger); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: inline-grid; place-items: center; cursor: pointer; font-size: .95rem; flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* ───────── Home ───────── */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.hero {
  text-align: center; padding: 56px 0 28px;
}
.hero h1 {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2rem, 6vw, 3.4rem); line-height: 1.1; margin: 0 0 14px; letter-spacing: -.01em;
}
.hero h1 em { font-style: normal; color: var(--brand-2); }
.hero p { color: var(--muted); max-width: 560px; margin: 0 auto 24px; font-size: 1.05rem; }
.hero .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.features {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 22px; margin: 26px 0 0; padding: 0; list-style: none;
  color: var(--muted); font-size: .88rem;
}
.features li::before { content: '✓ '; color: var(--brand-2); font-weight: 600; }

.section-title { font-family: var(--font-display); font-size: 1.6rem; margin: 28px 0 12px; }
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 14px; scrollbar-width: none;
  position: sticky; top: var(--topbar-h); z-index: 5; background: var(--bg);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px;
  font-size: .88rem; cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  padding-bottom: 48px;
}
@media (min-width: 720px) { .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 24px; } }
.tcard { text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 8px; }
.thumb {
  background: var(--surface-2); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow);
  display: grid; place-items: center; aspect-ratio: 5 / 7; transition: transform .2s ease, box-shadow .2s ease;
}
.thumb canvas { width: 100%; height: 100%; object-fit: contain; }
.tcard:hover .thumb { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.tname { font-weight: 600; font-size: .95rem; line-height: 1.3; }
.tmeta { color: var(--muted); font-size: .8rem; }
.blank-thumb {
  border: 2px dashed var(--line); background: transparent; box-shadow: none; color: var(--muted);
  flex-direction: column; gap: 6px; font-size: .9rem;
}
.blank-thumb .plus { font-size: 2.2rem; color: var(--brand-2); line-height: 1; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.empty {
  text-align: center; padding: 64px 16px; color: var(--muted);
}
.empty h2 { font-family: var(--font-display); color: var(--ink); }

.footer { text-align: center; color: var(--muted); font-size: .82rem; padding: 24px 16px 40px; }

/* ───────── Editor ───────── */
.editor {
  display: grid; grid-template-columns: 1fr 400px;
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
}
.ed-stage {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background:
    radial-gradient(circle at 1px 1px, rgba(91, 34, 69, .07) 1px, transparent 0) 0 0 / 18px 18px,
    var(--surface-2);
}
.ed-bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.ed-name {
  flex: 1; min-width: 60px; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 6px 10px;
  font-weight: 600; font-size: 1rem;
}
.ed-name:hover, .ed-name:focus { border-color: var(--line); background: var(--surface); outline: none; }
.save-state { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.ed-canvas-wrap {
  flex: 1; min-height: 0; display: grid; place-items: center; padding: 24px; overflow: hidden;
}
.ed-canvas-wrap canvas {
  max-width: 100%; max-height: 100%; width: auto; height: auto;
  box-shadow: var(--shadow-lg); border-radius: 4px; cursor: pointer; background: #fff;
}
.ed-panel {
  border-left: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}
.tabs {
  display: flex; border-bottom: 1px solid var(--line); padding: 0 6px; overflow-x: auto; scrollbar-width: none; flex: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1; border: 0; background: none; padding: 13px 8px 11px; cursor: pointer; color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent; font-size: .88rem; white-space: nowrap;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.panel-body { overflow-y: auto; padding: 16px; flex: 1; overscroll-behavior: contain; }
.panel-body h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 10px; font-weight: 600; }
.panel-body h3:first-child { margin-top: 0; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: .82rem; color: var(--muted); font-weight: 500; }
.field small { color: var(--muted); font-size: .76rem; }
input[type=text], input[type=tel], input[type=url], input[type=date], input[type=time], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: var(--surface);
  font-size: .93rem; min-height: 40px;
}
textarea { resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand-2); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input[type=range] { width: 100%; accent-color: var(--brand); }
input[type=color] {
  width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--surface); cursor: pointer;
}

.block {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.block.sel { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
.block-head { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.block-head select { flex: 1; min-height: 34px; padding: 5px 8px; font-size: .85rem; }
.block-head .icon-btn { width: 32px; height: 32px; font-size: .8rem; }
.block-foot { display: grid; grid-template-columns: 1fr 150px; gap: 8px; align-items: center; margin-top: 8px; }
.block-foot label { display: flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); }
.block-foot select { min-height: 34px; padding: 5px 8px; font-size: .85rem; }
.color-row { display: flex; gap: 6px; }
.color-row input[type=color] { width: 40px; flex: none; height: 34px; }
.linked {
  font-size: .76rem; color: var(--brand-2); background: var(--brand-soft); padding: 5px 9px; border-radius: 8px; margin-top: 6px;
}
.add-row { display: flex; gap: 8px; margin-top: 4px; }
.add-row select { flex: 1; }

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.swatch {
  aspect-ratio: 1; border-radius: 50%; border: 2px solid var(--surface); cursor: pointer; position: relative;
  box-shadow: 0 0 0 1px var(--line);
}
.swatch::after {
  content: ''; position: absolute; right: 2px; bottom: 2px; width: 34%; height: 34%; border-radius: 50%; background: var(--acc);
  border: 2px solid #fff;
}
.swatch:hover { box-shadow: 0 0 0 2px var(--brand-2); }
.opt-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.opt {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 6px; cursor: pointer;
  font-size: .8rem; text-align: center;
}
.opt.active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.size-opt { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; }
.size-opt i { display: block; border: 2px solid currentColor; border-radius: 3px; opacity: .6; }

.photo-drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 22px; text-align: center; cursor: pointer; color: var(--muted);
  display: block;
}
.photo-drop:hover { border-color: var(--brand-2); color: var(--brand); }
.photo-drop input { display: none; }
.photo-prev { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.photo-prev img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; }
.hint { color: var(--muted); font-size: .8rem; margin: 8px 0 0; }

/* ───────── Share sheet ───────── */
dialog.sheet {
  border: 0; padding: 0; border-radius: 20px; width: min(520px, calc(100vw - 24px)); box-shadow: var(--shadow-lg);
  background: var(--surface); color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(30, 15, 25, .45); backdrop-filter: blur(2px); }
.sheet-inner { padding: 18px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-family: var(--font-display); font-size: 1.35rem; }
.share-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.share-opt {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; text-align: left;
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px; cursor: pointer; align-items: center;
}
.share-opt:hover { border-color: var(--brand-2); background: var(--brand-soft); }
.share-opt .i { grid-row: span 2; font-size: 1.4rem; }
.share-opt b { font-size: .9rem; font-weight: 600; }
.share-opt small { color: var(--muted); font-size: .75rem; }
.share-opt.busy { opacity: .55; pointer-events: none; }

/* ───────── Shared view ───────── */
.shared {
  max-width: 980px; margin: 0 auto; padding: 24px 16px 48px;
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 32px; align-items: start;
}
.shared-card canvas { width: 100%; height: auto; box-shadow: var(--shadow-lg); border-radius: 6px; }
.shared-info h1 { font-family: var(--font-display); font-size: 1.9rem; margin: 6px 0 16px; line-height: 1.2; }
.kicker { text-transform: uppercase; letter-spacing: .14em; font-size: .75rem; color: var(--brand-2); font-weight: 600; }
.facts { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 12px; }
.facts li { display: flex; gap: 12px; align-items: flex-start; }
.facts .i { width: 36px; height: 36px; border-radius: 10px; background: var(--brand-soft); display: grid; place-items: center; flex: none; }
.facts b { display: block; font-weight: 600; }
.facts span { color: var(--muted); font-size: .9rem; }
.stack { display: grid; gap: 10px; }
.rsvp { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ───────── Toast ───────── */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; max-width: calc(100vw - 32px);
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner {
  width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 60px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── Mobile ───────── */
@media (max-width: 880px) {
  .editor {
    grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr);
  }
  .ed-stage { max-height: 52vh; max-height: 52dvh; }
  .ed-canvas-wrap { padding: 14px; }
  .ed-panel { border-left: 0; border-top: 1px solid var(--line); }
  .shared { grid-template-columns: 1fr; gap: 20px; }
  .ed-bar .btn-label { display: none; }
}
@media (max-width: 520px) {
  .brand span { font-size: 1.15rem; }
  .nav a { padding: 7px 9px; }
  .hero { padding-top: 36px; }
  .share-grid { grid-template-columns: 1fr; }
  .swatches { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  dialog.sheet { margin: auto auto 0; border-radius: 20px 20px 0 0; width: 100vw; max-width: 100vw; }
  .sheet-inner { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
