:root {
  --bg: #f6f1ea;
  --surface: #fffdf9;
  --ink: #2b2320;
  --muted: #7a6c64;
  --line: #e6ddd2;
  --red: #b3261e;
  --red-dark: #8e1d17;
  --green: #1e5a3a;
  --gold: #c99a2e;
  --radius: 14px;
}

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

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

h1, h2 { font-family: 'Cormorant Garamond', Georgia, serif; font-weight: 600; line-height: 1.15; }

/* ---------- Kopfzeile ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  background: var(--red);
  color: #fff;
  font-family: 'Great Vibes', cursive;
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
}
.logo { color: var(--gold); font-family: system-ui, sans-serif; font-size: 22px; }

/* ---------- Layout ---------- */
.editor {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 28px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 60px;
  align-items: start;
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }

.preview {
  position: sticky;
  top: 20px;
  order: 2;
  padding: 18px;
  --page-bg: #1c2630;
  --page-bg2: #3a4b5c;
  /* gleicher Hintergrund wie auf der Empfängerseite, Farben setzt editor.js je nach Design */
  background: radial-gradient(ellipse at 50% 25%, var(--page-bg2), var(--page-bg) 75%);
  background-color: var(--page-bg);
  border: none;
  color: #fff;
  overflow: hidden;
  isolation: isolate;
}
.preview > :not(.preview-snow) { position: relative; z-index: 1; }
.preview-snow { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.preview-head { display: flex; align-items: center; justify-content: space-between; }
.preview-head h2 { margin: 0; font-size: 24px; }
.preview-stage { height: min(calc(100vh - 170px), 760px); min-height: 380px; margin-top: 8px; }
.preview-tip { margin: 6px 0 0; font-size: 13px; opacity: .7; text-align: center; }
.preview .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, .4); }
.preview .btn-ghost:hover { background: rgba(255, 255, 255, .12); }

.form-panel { order: 1; padding: 28px 30px; }
.form-panel h1 { margin: 0 0 6px; font-size: 36px; color: var(--red-dark); }

fieldset { border: none; padding: 0; margin: 26px 0 0; min-width: 0; }
legend {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  margin-bottom: 12px;
  font-weight: 800;
  font-size: 18px;
}
.step {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 14px;
}

/* ---------- Auswahl: Motive ---------- */
.motif-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; }
.motif-option {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  transition: border-color .2s, transform .2s;
}
.motif-option img { width: 100%; aspect-ratio: 5 / 7; border-radius: 6px; box-shadow: 0 3px 10px rgba(0, 0, 0, .18); background: var(--line); display: block; }
.motif-option:hover { transform: translateY(-2px); }
.motif-option[aria-pressed="true"] { border-color: var(--red); background: #fbecea; font-weight: 700; }

/* ---------- Auswahl: Farben ---------- */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 6px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
}
.swatch-color { position: relative; width: 28px; height: 28px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.swatch-color::after { content: ""; position: absolute; right: -2px; bottom: -2px; width: 11px; height: 11px; border-radius: 50%; background: var(--dot); border: 2px solid #fff; }
.swatch[aria-pressed="true"] { border-color: var(--red); background: #fbecea; font-weight: 700; }

/* ---------- Felder ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; position: relative; }
.field > span:first-child { font-weight: 700; font-size: 14px; }
.field em { font-weight: 400; font-style: normal; color: var(--muted); }
input:not([type="radio"]):not([type="checkbox"]), textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font: inherit;
  color: var(--ink);
  transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; min-height: 54px; }
input:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(30, 90, 58, .15); }
.counter { position: absolute; right: 10px; bottom: 8px; font-size: 12px; color: var(--muted); pointer-events: none; }

.suggestions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -6px 0 18px; font-size: 13px; color: var(--muted); }
.chip {
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}
.chip:hover { border-color: var(--green); color: var(--green); }

.font-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.font-option {
  padding: 10px 8px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  line-height: 1.2;
}
.font-option[aria-pressed="true"] { border-color: var(--red); background: #fbecea; }

.segmented { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); margin-bottom: 16px; }
.segmented label { position: relative; padding: 8px 16px; border-radius: 999px; cursor: pointer; font-weight: 700; font-size: 14px; color: var(--muted); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--green); }

.check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 18px; font-size: 14px; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--green); width: 17px; height: 17px; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.error { margin: 0 0 14px; padding: 10px 14px; border-radius: 10px; background: #fdecea; color: var(--red-dark); font-weight: 700; font-size: 14px; }
.privacy { margin: 12px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
  transition: background .2s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn-large { width: 100%; padding: 15px 22px; font-size: 17px; }

/* ---------- Ergebnis ---------- */
.result { text-align: center; padding: 20px 0; }
.result-icon { font-size: 44px; color: var(--gold); line-height: 1; }
.result h2 { font-size: 34px; margin: 10px 0; color: var(--green); }
.result p { color: var(--muted); }
.result p.warn { color: var(--red-dark); font-weight: 700; }
.linkbox { display: flex; gap: 8px; }
.linkbox input { font-family: ui-monospace, monospace; font-size: 13px; min-width: 0; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 20px; }
.result-list { list-style: none; padding: 0; margin: 18px 0 0; display: flex; flex-direction: column; gap: 12px; text-align: left; }
.result-list li { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.rl-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 14px; }
.rl-who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rl-status { flex: none; font-weight: 700; }
.rl-status.ok { color: var(--green); }
.rl-status.fail { color: var(--red-dark); }

/* ---------- Empfängerliste ---------- */
.recipients { display: flex; flex-direction: column; gap: 8px; }
.recipient-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px; gap: 8px; align-items: center; }
.r-remove {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: #fff;
  font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer;
}
.r-remove:hover { color: var(--red); border-color: var(--red); }
.btn-small { padding: 7px 14px; font-size: 14px; align-self: flex-start; margin-top: 4px; }
.field-hint { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
@media (max-width: 560px) {
  .recipient-row { grid-template-columns: minmax(0, 1fr) 36px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
  .recipient-row .r-greeting { grid-row: 2; grid-column: 1; }
  .recipient-row .r-remove { grid-row: 1 / span 2; grid-column: 2; }
}

/* ---------- 404 ---------- */
body.plain { min-height: 100vh; display: grid; place-items: center; }
.notfound { text-align: center; max-width: 440px; padding: 24px; }
.notfound-star { font-size: 56px; color: var(--gold); }
.notfound h1 { font-size: 38px; margin: 8px 0; color: var(--red-dark); }
.notfound p { color: var(--muted); margin-bottom: 24px; }

/* ---------- Mobil ---------- */
@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; padding: 16px 16px 48px; gap: 16px; }
  .preview { position: relative; top: 0; order: 0; padding: 14px; }
  .preview-stage { height: 52svh; min-height: 320px; }
  .form-panel { padding: 22px 18px; }
  .form-panel h1 { font-size: 30px; }
  .topbar { padding: 12px 16px; font-size: 26px; }
}
