/* =========================================================
   Basic page and 9:16 card frame
   ========================================================= */

:root {
  --cream: #fff4d4;
  --gold: #f4d28a;
  --deep-brown: #24150d;
  --transition-time: 850ms;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  min-height: 100svh;
  place-items: center;
  overflow: hidden;
  color: var(--cream);
  background:
    radial-gradient(circle at 50% 20%, #59402b 0, #241a14 46%, #0d0a08 100%);
  font-family: Georgia, "Times New Roman", serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.card-shell {
  position: relative;
  width: min(100vw, calc(100svh * 9 / 16));
  height: min(100svh, calc(100vw * 16 / 9));
  max-width: 540px;
  max-height: 960px;
}

.card {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #17100c;
  box-shadow: 0 24px 80px rgb(0 0 0 / 55%);
  isolation: isolate;
}

/* Every scene occupies exactly the same full-card area. */
.scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity var(--transition-time) ease,
    visibility 0s linear var(--transition-time);
}

.scene.is-active {
  z-index: 2;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.scene-media {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/*
  Static artwork contains important text and composition, so it is always
  shown in full and centered. When its aspect ratio leaves extra space,
  ::before fills that space with a darker, softly blurred copy.
*/
.scene-1,
.scene-2,
.scene-3,
.scene-final {
  background-color: #17100c;
}

.scene-1::before,
.scene-2::before,
.scene-3::before,
.scene-final::before {
  content: "";
  position: absolute;
  inset: -5%;
  z-index: 0;
  background-image: var(--scene-background);
  background-position: center center;
  background-size: cover;
  background-repeat: no-repeat;
  filter: blur(18px) brightness(0.48) saturate(0.82);
  transform: scale(1.08);
  pointer-events: none;
}

.scene-1 { --scene-background: url("assets/scene1.png"); }
.scene-2 { --scene-background: url("assets/scene2.png"); }
.scene-3 { --scene-background: url("assets/scene3_state_000.png"); }
.scene-final { --scene-background: url("assets/final.png"); }

.scene-1 .scene-media,
.scene-2 .scene-media,
.scene-3 .scene-media,
.scene-final .scene-media {
  object-fit: contain;
  object-position: center center;
}

/* The flight video intentionally continues to fill the frame. */
.scene-4 .scene-media {
  object-fit: cover;
  object-position: center center;
}

/* =========================================================
   Shared controls
   ========================================================= */

.utility-button {
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid rgb(255 244 212 / 48%);
  border-radius: 999px;
  color: #fff9e9;
  background: rgb(32 20 13 / 58%);
  box-shadow: 0 3px 14px rgb(0 0 0 / 22%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  letter-spacing: 0.025em;
  text-shadow: 0 1px 3px rgb(0 0 0 / 50%);
  transition: background 220ms ease, transform 220ms ease, opacity 500ms ease;
}

.utility-button:active {
  transform: scale(0.96);
}

.utility-button:focus-visible {
  outline: 2px solid #fff7d6;
  outline-offset: 3px;
}

.bud:focus-visible {
  outline: none;
}

.bud:focus-visible .bud-halo {
  opacity: 0.58;
  transform: scale(0.9);
}

.music-toggle {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 20;
  font-size: clamp(12px, 3.1vw, 15px);
}

.music-toggle[aria-pressed="true"] {
  background: rgb(77 53 27 / 68%);
}

.demo-badge {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  z-index: 21;
  padding: 8px 12px;
  border: 1px solid rgb(255 244 212 / 52%);
  border-radius: 999px;
  color: #fff9e9;
  background: rgb(73 42 21 / 72%);
  box-shadow: 0 3px 14px rgb(0 0 0 / 25%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(11px, 2.8vw, 14px);
  font-weight: 750;
  letter-spacing: 0.08em;
  line-height: 1.25;
  pointer-events: none;
}

.continue-prompt {
  position: absolute;
  z-index: 8;
  left: 50%;
  padding: 8px 17px 9px;
  border: 1px solid rgb(255 241 195 / 35%);
  border-radius: 999px;
  color: #fff4cf;
  background: rgb(25 14 8 / 42%);
  box-shadow: 0 5px 20px rgb(0 0 0 / 25%);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  font-size: clamp(14px, 3.8vw, 19px);
  letter-spacing: 0.04em;
  text-shadow: 0 2px 6px rgb(0 0 0 / 80%);
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 900ms ease, transform 900ms ease;
}

.continue-prompt.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  animation: gentle-breathe 2.8s 1s ease-in-out infinite;
}

/* =========================================================
   Scene 1
   ========================================================= */

.envelope-glow {
  position: absolute;
  left: 13%;
  right: 13%;
  top: 46%;
  height: 36%;
  border-radius: 44%;
  background: radial-gradient(ellipse, rgb(255 240 193 / 0%) 25%, transparent 70%);
  pointer-events: none;
  transition: background 500ms ease, filter 500ms ease;
}

.scene-1.is-opening .envelope-glow {
  background: radial-gradient(ellipse, rgb(255 240 193 / 32%) 10%, transparent 72%);
  filter: brightness(1.15);
}

/* =========================================================
   Scene 3 flower-bud interaction
   Coordinates are percentages, so they scale with the card.
   ========================================================= */

.bud {
  position: absolute;
  z-index: 5;
  width: 23%;
  aspect-ratio: 1;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--cream);
  background: transparent;
  cursor: pointer;
  transform: translate(-50%, -50%);
  touch-action: manipulation;
}

/*
  FLOWER POSITION SETTINGS — adjust these percentages if the artwork changes.
  leftBudPosition:   left 34%, top 45%
  bottomBudPosition: left 43%, top 70%
  rightBudPosition:  left 65%, top 60%
*/
.bud-left   { left: 34%; top: 45%; }
.bud-center { left: 43%; top: 70%; }
.bud-right  { left: 65%; top: 60%; }

.bud-halo {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  opacity: 0;
  background: radial-gradient(circle,
    rgb(255 239 174 / 68%) 0,
    rgb(255 210 100 / 20%) 38%,
    transparent 72%);
  filter: blur(2px);
  transform: scale(0.55);
}

.scene3-state-image {
  transition: opacity 220ms ease;
}

.scene3-state-image.is-changing {
  opacity: 0.42;
}

.bud-word {
  position: absolute;
  left: 50%;
  width: max-content;
  max-width: 150%;
  color: #fff1c2;
  font-family: "Snell Roundhand", "Apple Chancery", "Segoe Script", cursive;
  font-size: clamp(22px, 6vw, 34px);
  line-height: 1;
  text-shadow:
    0 2px 8px rgb(29 12 4 / 90%),
    0 0 16px rgb(255 218 128 / 50%);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px) scale(0.94);
  transition: opacity 850ms ease, transform 850ms ease;
}

/* Place each word in open space near, rather than over, its flower. */
.bud-left .bud-word   { bottom: 82%; }
.bud-center .bud-word { top: 84%; }
.bud-right .bud-word  { bottom: 82%; }

.bud.is-revealed .bud-halo {
  animation: bud-glow 1.8s ease-out both;
}

.bud.is-revealed .bud-word {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.bud.is-revealed {
  cursor: default;
}

.scene3-continue {
  bottom: 14.5%;
}

/* =========================================================
   Scene 4 video and overlay wording
   ========================================================= */

.video-shade {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(to bottom,
      rgb(12 18 24 / 34%) 0%,
      rgb(12 18 24 / 8%) 38%,
      rgb(12 14 16 / 10%) 65%,
      rgb(10 8 7 / 38%) 100%);
}

.scene4-message {
  position: absolute;
  z-index: 5;
  top: 18%;
  left: 10%;
  right: 10%;
  height: 43%;
  overflow: hidden;
  color: #fff5d7;
  text-align: center;
  font-size: clamp(27px, 7vw, 42px);
  line-height: 1.27;
  letter-spacing: 0.012em;
  text-wrap: balance;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-shadow:
    0 3px 14px rgb(0 0 0 / 75%),
    0 0 28px rgb(0 0 0 / 28%);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 1.5s ease, transform 1.5s ease;
}

.scene4-message.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.scene4-continue {
  bottom: max(5.5%, calc(env(safe-area-inset-bottom) + 12px));
}

/* =========================================================
   Final scene signature and Replay
   ========================================================= */

.signature-area {
  position: absolute;
  z-index: 5;
  top: 76%;
  left: 34%;
  width: 58%;
  min-height: 9%;
  pointer-events: none;
}

.signature-name {
  position: absolute;
  top: 0;
  left: 50%;
  width: 76%;
  max-width: 76%;
  min-height: 100%;
  padding: 0.22em 0.18em 0.38em;
  color: #392316;
  font-family: "Snell Roundhand", "Apple Chancery", "Segoe Script", cursive;
  font-size: clamp(21px, 6vw, 31px);
  line-height: 1.35;
  text-align: center;
  white-space: nowrap;
  overflow: visible;
  opacity: 0;
  transform: translate(-50%, 10px);
  text-shadow: 0 1px 1px rgb(255 255 255 / 30%);
  transition:
    opacity 1.2s var(--signature-delay, 850ms) ease,
    transform 1.2s var(--signature-delay, 850ms) ease;
}

.scene-final.is-active .signature-name {
  opacity: 1;
  transform: translate(-50%, 0);
}

.replay-button {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  font-size: clamp(13px, 3.5vw, 17px);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 700ms 1.8s ease, transform 700ms 1.8s ease;
}

.scene-final.is-active .replay-button {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

/* =========================================================
   Animation and accessibility helpers
   ========================================================= */

@keyframes bud-glow {
  0%   { opacity: 0; transform: scale(0.5); }
  35%  { opacity: 1; transform: scale(1.2); }
  100% { opacity: 0.42; transform: scale(1); }
}

@keyframes gentle-breathe {
  0%, 100% { box-shadow: 0 5px 20px rgb(0 0 0 / 25%); }
  50% { box-shadow: 0 5px 24px rgb(255 220 139 / 24%); }
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (min-width: 700px) {
  .card {
    border-radius: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --transition-time: 250ms;
  }

  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 250ms !important;
    transition-delay: 0ms !important;
  }
}

/* =========================================================
   Buyer customization page
   ========================================================= */

body.customize-page {
  display: block;
  min-height: 100svh;
  overflow: auto;
  padding: 24px 16px 48px;
  color: #352217;
  background: #f5ead8;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.customize-container {
  width: min(100%, 760px);
  margin: 0 auto;
}

.customize-panel {
  padding: clamp(20px, 5vw, 38px);
  border: 1px solid #dbc5a5;
  border-radius: 20px;
  background: rgb(255 252 245 / 96%);
  box-shadow: 0 18px 55px rgb(67 41 24 / 15%);
}

.customize-panel h1,
.customize-panel h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
}

.customize-panel h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 7vw, 42px);
  overflow-wrap: anywhere;
}

.customize-intro {
  margin: 0 0 12px;
  color: #6d5543;
  line-height: 1.6;
}

.flower-instruction {
  margin: 0 0 28px;
  color: #604324;
  font-weight: 650;
  line-height: 1.5;
}

.customize-field {
  margin-bottom: 22px;
}

.customize-label-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
}

.customize-field label {
  font-weight: 650;
}

.field-note,
.character-count {
  color: #806b59;
  font-size: 13px;
}

.customize-field input,
.customize-field textarea,
.generated-url {
  width: 100%;
  border: 1px solid #bda78b;
  border-radius: 10px;
  color: #352217;
  background: #fffdfa;
  font: inherit;
  font-size: 16px;
}

.customize-field input,
.customize-field textarea {
  padding: 12px 13px;
}

.customize-field textarea {
  min-height: 130px;
  resize: vertical;
  line-height: 1.5;
}

.customize-field input:focus,
.customize-field textarea:focus,
.generated-url:focus {
  outline: 3px solid rgb(173 121 56 / 24%);
  border-color: #9b6f37;
}

.customize-field [aria-invalid="true"] {
  border-color: #a6342d;
}

.field-error {
  min-height: 1.3em;
  margin: 5px 0 0;
  color: #a6342d;
  font-size: 13px;
}

.text-preview {
  margin: 30px 0;
  padding: 18px;
  border-radius: 14px;
  background: #f2e4cd;
}

.text-preview h2 {
  margin: 0 0 14px;
  font-size: 21px;
}

.preview-row {
  margin: 9px 0;
  line-height: 1.5;
}

.preview-message {
  white-space: pre-wrap;
}

.customize-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.customize-action {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 11px 15px;
  border: 1px solid #8b6334;
  border-radius: 999px;
  color: #fffaf0;
  background: #70491f;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  overflow-wrap: anywhere;
}

#resetButton {
  grid-column: 1 / -1;
  justify-self: center;
  width: min(100%, 340px);
}

.customize-action.secondary {
  color: #604324;
  background: #fffaf0;
}

.customize-action:focus-visible {
  outline: 3px solid rgb(139 99 52 / 32%);
  outline-offset: 2px;
}

.url-result {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid #dfcdb4;
}

.url-result[hidden] {
  display: none;
}

.generated-url {
  min-height: 92px;
  padding: 11px;
  resize: vertical;
  line-height: 1.4;
}

.url-actions {
  margin-top: 10px;
}

.form-status {
  min-height: 1.5em;
  margin: 14px 0 0;
  color: #765327;
  font-weight: 600;
}

@media (max-width: 520px) {
  body.customize-page {
    padding: 0;
    background: #fffaf1;
  }

  .customize-panel {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .customize-actions {
    grid-template-columns: 1fr;
  }
}
