/* ===== Design tokens ===== */
:root {
  --denim-deep: #163a66;
  --denim: #1f4f86;
  --denim-light: #2f68a8;
  --ink: #f4f7ff;
  --ink-soft: rgba(244, 247, 255, 0.72);
  --glass: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.22);
  --blush: #ffd9e6;
  --font-script: "Great Vibes", "Brush Script MT", cursive;
  --font-serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --ease-soft: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font-serif);
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(173, 205, 255, 0.35), transparent 60%),
    radial-gradient(90% 60% at 50% 110%, rgba(10, 25, 55, 0.6), transparent 70%),
    linear-gradient(170deg, var(--denim-light), var(--denim) 45%, var(--denim-deep));
  -webkit-font-smoothing: antialiased;
}

/* Woven denim texture + vignette */
.denim {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.06) 0 1px, transparent 1px 4px),
    radial-gradient(ellipse at center, transparent 55%, rgba(5, 15, 35, 0.45));
}

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

/* ===== Layout ===== */
.stage {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100svh;
  padding: max(16px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

.flower-wrap {
  position: relative;
  flex: 1 1 auto;
  align-self: stretch;
  min-width: 0;
  min-height: 0;
  max-width: 620px;
}

#lily {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.message-wrap {
  flex: 0 0 auto;
  width: 0;
  overflow: hidden;
  opacity: 0;
  transition: width 1.4s var(--ease-soft), opacity 1.2s ease 0.3s;
}

.show .message-wrap {
  width: min(480px, 44vw);
  opacity: 1;
}

/* ===== Card ===== */
.card {
  width: min(480px, 44vw);
  max-height: min(78vh, 680px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 30px 22px;
  border-radius: 28px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.14), var(--glass));
  border: 1px solid var(--glass-border);
  box-shadow: 0 30px 60px -25px rgba(5, 15, 40, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  transform: translateY(18px);
  transition: transform 1.4s var(--ease-soft);
  cursor: pointer;
}

.show .card { transform: none; }

.title {
  font-family: var(--font-script);
  font-weight: 400;
  font-size: clamp(2.2rem, 4vw, 3rem);
  line-height: 1.1;
  text-shadow: 0 0 18px rgba(255, 255, 255, 0.45), 0 0 40px rgba(255, 217, 230, 0.35);
}

.ornament {
  margin: 4px 0 12px;
  font-size: 0.8rem;
  color: var(--blush);
  opacity: 0.85;
  letter-spacing: 0.4em;
}

.message-scroll {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 14px, #000 calc(100% - 14px), transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 14px, #000 calc(100% - 14px), transparent);
}

.message {
  padding: 8px 0;
  font-size: clamp(1.05rem, 1.35vw, 1.2rem);
  line-height: 1.75;
  white-space: pre-line;
  color: var(--ink);
  text-shadow: 0 1px 10px rgba(5, 20, 50, 0.35);
}

.caret {
  display: inline-block;
  width: 1px;
  height: 1.1em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--ink);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.9);
  animation: blink 1s steps(1) infinite;
}

.done .caret { opacity: 0; animation: none; transition: opacity 0.6s; }

.signature {
  font-family: var(--font-script);
  font-size: 1.6rem;
  text-align: right;
  padding: 4px 4px 10px;
  color: var(--blush);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1.2s ease, transform 1.2s var(--ease-soft);
}

.done .signature { opacity: 1; transform: none; }

.replay {
  margin-top: 12px;
  padding: 9px 22px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 1rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease, background 0.3s ease, box-shadow 0.3s ease;
}

.done .replay { opacity: 1; pointer-events: auto; }
.replay:hover, .replay:focus-visible {
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 0 22px rgba(255, 255, 255, 0.25);
  outline: none;
}

/* ===== Flower parts ===== */
.stem {
  fill: none;
  stroke: url(#stemGrad);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-dasharray: var(--len, 600);
  stroke-dashoffset: var(--len, 600);
}

.vein {
  fill: none;
  stroke: rgba(150, 175, 120, 0.45);
  stroke-width: 0.8;
  stroke-linecap: round;
}

.leaf-rib {
  fill: none;
  stroke: rgba(220, 240, 200, 0.55);
  stroke-width: 1;
  stroke-linecap: round;
}

.petal-body {
  stroke: rgba(175, 195, 225, 0.55);
  stroke-width: 0.6;
}

.petal-fold {
  fill: rgba(150, 175, 215, 0.16);
}

.petal-vein {
  fill: none;
  stroke: rgba(170, 190, 150, 0.35);
  stroke-width: 0.7;
  stroke-linecap: round;
}

.filament {
  fill: none;
  stroke: #b9d18a;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.style-line {
  fill: none;
  stroke: #d3e5a8;
  stroke-width: 2.6;
  stroke-linecap: round;
}

.leaf, .petal, .stamen, .bud { transform-origin: 0 0; }

.leaf, .petal, .stamen, .bud, .glow, .throat { opacity: 0; }

/* ===== Timeline (triggered by .play on <body>) ===== */
.play .stem { animation: draw 2.6s cubic-bezier(0.45, 0.05, 0.3, 1) 0.3s forwards; }
.play .leaf { animation: leafIn 1.3s var(--ease-soft) var(--d) forwards; }
.play .bud {
  animation: budIn 0.9s var(--ease-soft) 2.5s both, fadeOut 0.9s ease-in 3.4s forwards;
}
.play .petal { animation: bloom 1.7s cubic-bezier(0.25, 1.1, 0.4, 1) var(--d) forwards; }
.play .throat { animation: fadeIn 1.4s ease 3.4s forwards; }
.play .stamen { animation: stamenIn 1.2s var(--ease-soft) var(--d) forwards; }
.play .glow { animation: fadeIn 2s ease 4s forwards, pulse 5s ease-in-out 6s infinite; }
.play .sway {
  transform-origin: 200px 660px;
  animation: sway 8s ease-in-out 7s infinite;
}

@keyframes draw { to { stroke-dashoffset: 0; } }

@keyframes leafIn {
  0% { opacity: 0; transform: scale(0.05, 0.2) rotate(18deg); }
  30% { opacity: 1; }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes budIn {
  0% { opacity: 0; transform: scale(0.1); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes bloom {
  0% { opacity: 0; transform: rotate(-14deg) scale(0.15, 0.32); }
  25% { opacity: 1; }
  70% { transform: rotate(2deg) scale(1.03, 1.02); }
  100% { opacity: 1; transform: rotate(0) scale(1); }
}

@keyframes stamenIn {
  0% { opacity: 0; transform: scale(0.1); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes fadeIn { to { opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; } }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes sway {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(1.4deg); }
}

@keyframes blink { 50% { opacity: 0; } }

/* ===== Mobile / portrait ===== */
@media (max-width: 760px), (orientation: portrait) and (max-width: 1024px) {
  .stage {
    flex-direction: column;
    justify-content: flex-start;
  }

  .flower-wrap {
    width: 100%;
    max-width: none;
  }

  .message-wrap {
    width: 100%;
    height: 0;
    display: flex;
    justify-content: center;
    transition: height 1.4s var(--ease-soft), opacity 1.2s ease 0.3s;
  }

  .show .message-wrap {
    width: 100%;
    height: 52vh;
    height: 52svh;
  }

  .card {
    width: min(560px, 100%);
    height: 100%;
    max-height: none;
    padding: 20px 20px 16px;
    border-radius: 22px;
  }

  .title { font-size: 2.2rem; }
  .message { font-size: 1.06rem; line-height: 1.65; }
  .signature { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  .play .sway, .play .glow { animation-iteration-count: 1; }
}
