:root {
  --bg: #f7f1ea;
  --panel: #fffdfa;
  --ink: #2b1d24;
  --muted: #8a7a80;
  --line: #eadfd6;
  --accent: #b0405c;
  --accent-dark: #8e2f48;
  --gold: #c9a45c;
  --radius: 16px;
  --shadow: 0 20px 60px rgba(60, 30, 40, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  font-family: 'Montserrat', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #fbe3e6 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #f6e7cf 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

/* ---------- header ---------- */

.top {
  display: flex;
  align-items: baseline;
  gap: 24px;
  flex-wrap: wrap;
  padding: 22px clamp(16px, 4vw, 48px) 8px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  text-decoration: none;
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-weight: 600;
  font-size: 34px;
  line-height: 1;
}

.logo svg {
  width: 32px;
  height: 32px;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- layout ---------- */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 460px;
  gap: clamp(16px, 3vw, 40px);
  padding: 16px clamp(16px, 4vw, 48px) 24px;
  align-items: start;
}

.preview {
  position: sticky;
  top: 16px;
  display: flex;
  justify-content: center;
}

.stage {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: calc(100vh - 120px);
  min-height: 420px;
}

#canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: var(--shadow);
  background: #fff;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 8px 22px 22px;
  box-shadow: 0 10px 40px rgba(60, 30, 40, 0.06);
}

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 14px 0 2px;
  padding: 5px;
  border-radius: 14px;
  background: #f3ebe4;
}

.modes button {
  padding: 12px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.modes button[aria-selected='true'] {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 2px 10px rgba(60, 30, 40, 0.12);
}

.step {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.step h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 26px;
}

.step h2 span {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: 'Montserrat', sans-serif;
  font-size: 13px;
  font-weight: 600;
}

/* ---------- templates ---------- */

.templates {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.tpl {
  position: relative;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 12px;
  background: none;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.tpl:hover {
  transform: translateY(-2px);
}

.tpl canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 10px;
  background: #eee;
}

.tpl span {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  padding: 4px 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tpl[aria-checked='true'] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(176, 64, 92, 0.18);
}

/* ---------- fields ---------- */

.field {
  display: block;
  margin-bottom: 14px;
}

.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.field > span.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

input,
textarea,
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
  resize: vertical;
  min-height: 84px;
  line-height: 1.4;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(176, 64, 92, 0.15);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -4px 0 16px;
}

.chip {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.chip:hover {
  border-color: var(--accent);
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: #f3ebe4;
}

.segmented button {
  padding: 10px 6px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.segmented button small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.segmented button[aria-checked='true'] {
  background: #fff;
  box-shadow: 0 2px 8px rgba(60, 30, 40, 0.12);
  font-weight: 600;
}

/* ---------- actions ---------- */

.actions {
  padding-top: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  width: 100%;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-size: 17px;
  box-shadow: 0 10px 30px rgba(176, 64, 92, 0.35);
}

.btn.primary:hover {
  box-shadow: 0 14px 36px rgba(176, 64, 92, 0.45);
}

.btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.actions-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.actions-row .btn {
  flex: 1;
}

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.bottom {
  padding: 8px 16px 28px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 100;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px);
  transition: opacity 0.25s, transform 0.25s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- viewer (surprise link) ---------- */

#viewer {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 20px;
  background: radial-gradient(circle at 50% 30%, #3a2430, #140a10);
  overflow: hidden;
}

.viewer-card {
  display: flex;
  justify-content: center;
  min-height: 0;
  flex: 0 1 auto;
  max-height: calc(100vh - 150px);
}

#view-canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 150px);
  width: auto;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: rise 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.96);
  }
}

.viewer-answer {
  display: flex;
  gap: 14px;
  animation: rise 0.9s 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.btn.big {
  min-width: 140px;
  padding: 16px 28px;
  font-size: 18px;
}

.viewer-answer .btn.primary {
  width: auto;
}

#no {
  transition: left 0.25s ease, top 0.25s ease, transform 0.1s;
}

#no.runaway {
  position: fixed;
  z-index: 5;
}

.viewer-done {
  color: #fff;
  text-align: center;
}

.viewer-done p {
  margin: 0 0 12px;
}

.done-title {
  font-family: 'Great Vibes', cursive;
  font-size: 64px;
  line-height: 1;
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
  }

  .preview {
    position: static;
  }

  .stage {
    height: auto;
    min-height: 0;
  }

  #canvas {
    max-height: 62vh;
  }

  .panel {
    padding: 4px 16px 16px;
  }

  .actions {
    position: sticky;
    bottom: 0;
    margin: 0 -16px -16px;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--panel) 75%, rgba(255, 253, 250, 0));
    border-radius: 0 0 22px 22px;
  }

  .hint {
    display: none;
  }
}

@media (min-width: 600px) and (max-width: 960px) {
  .templates {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (max-width: 420px) {
  .top {
    padding-top: 16px;
  }

  .logo {
    font-size: 28px;
  }

  .tagline {
    display: none;
  }

  .grid-2 {
    grid-template-columns: 1fr;
    gap: 0;
  }
}
