:root {
  --bg1: #fdf1f4;
  --bg2: #f6dde6;
  --ink: #4a3540;
  --soft: #8a6f7b;
  --accent: #d46a8c;
  --petal: #f3b6c9;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--serif);
  background: radial-gradient(120% 80% at 50% 25%, var(--bg1), var(--bg2));
  background-attachment: fixed;
  transition: background 0.8s ease;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.page {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  max-width: 34rem;
  margin: 0 auto;
  padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem calc(5.5rem + env(safe-area-inset-bottom)); /* bottom: room for the cat */
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.day {
  margin: 0.25rem 0 0;
  font-size: 1.05rem;
  font-style: italic;
  letter-spacing: 0.04em;
  color: var(--soft);
}

.stage {
  width: 100%;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#flower {
  width: auto;
  height: min(46dvh, 30rem);
  max-width: 100%;
  overflow: visible;
  filter: drop-shadow(0 10px 18px rgba(80, 40, 60, 0.12));
}

.name {
  margin: 0.4rem 0 0;
  font-size: clamp(2rem, 8vw, 2.8rem);
  font-weight: 600;
  line-height: 1.05;
  color: var(--accent);
  transition: color 0.8s ease;
}

.kind {
  margin: 0.2rem 0 0;
  font-size: 1.1rem;
  font-style: italic;
  color: var(--soft);
}

.message {
  margin: 1.1rem 0 0;
  max-width: 26rem;
  min-height: 6.5rem;
}

.label {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  transition: color 0.8s ease;
}

.text {
  margin: 0.35rem 0 0;
  font-size: 1.3rem;
  line-height: 1.4;
}

.controls {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  margin: 1rem 0 0.25rem;
}

.controls button {
  font: inherit;
  font-size: 1.35rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  min-width: 3.2rem;
  height: 3.2rem;
  padding: 0 1rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(80, 40, 60, 0.08);
  backdrop-filter: blur(6px);
  transition: transform 0.15s ease, opacity 0.3s ease, background 0.3s ease;
}

.controls button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.85); }
.controls button:active:not(:disabled) { transform: scale(0.94); }
.controls button:disabled { opacity: 0.3; cursor: default; }
.controls button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.controls .share {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0 1.6rem;
  color: #fff;
  background: var(--accent);
  border-color: transparent;
}
.controls .share:hover:not(:disabled) { background: var(--accent); filter: brightness(1.06); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(5.5rem + env(safe-area-inset-bottom));
  transform: translate(-50%, 1rem);
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  background: rgba(60, 40, 50, 0.85);
  color: #fff;
  font-size: 1.05rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 3;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- Text entrance ---- */
.enter .day,
.enter .name,
.enter .kind,
.enter .message {
  animation: rise 0.9s ease both;
}
.enter .name { animation-delay: 1.1s; }
.enter .kind { animation-delay: 1.25s; }
.enter .message { animation-delay: 1.45s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---- Flower animation ---- */
#flower .sway {
  transform-box: view-box;
  transform-origin: 200px 560px;
  animation: sway 7s ease-in-out 2.4s infinite alternate;
}

#flower .stem {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 0.9s ease-out forwards;
}

#flower .grow,
#flower .petal {
  transform-box: view-box;
  transform-origin: 0 0;
  animation: bloom 0.9s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
  animation-delay: var(--d, 0ms);
}

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

@keyframes bloom {
  from { transform: scale(0.05) rotate(-25deg); opacity: 0; }
  60% { opacity: 1; }
  to { transform: none; opacity: 1; }
}

@keyframes sway {
  from { transform: rotate(-1.6deg); }
  to { transform: rotate(1.6deg); }
}

/* ---- Drifting petals in the background ---- */
.drift {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.drift span {
  position: absolute;
  top: -5vh;
  width: var(--s, 14px);
  height: calc(var(--s, 14px) * 0.75);
  background: var(--petal);
  border-radius: 150% 0 150% 0;
  opacity: 0.45;
  animation: fall var(--t, 16s) linear var(--delay, 0s) infinite;
  transition: background 0.8s ease;
}

@keyframes fall {
  0% { transform: translate(0, -5vh) rotate(0deg); }
  50% { transform: translate(var(--x, 30px), 55vh) rotate(200deg); }
  100% { transform: translate(0, 110vh) rotate(400deg); }
}

/* ---- The cat (see cat.js) ---- */
.cat-wrap {
  position: fixed;
  left: 0;
  bottom: calc(0.4rem + env(safe-area-inset-bottom));
  width: 112px;
  height: 76px;
  z-index: 2;
  will-change: transform;
}

.cat-wrap::before { /* soft shadow on the ground */
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -2px;
  height: 8px;
  border-radius: 50%;
  background: rgba(80, 40, 60, 0.12);
  filter: blur(2px);
}

.cat {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: url("cat.png") 0 0 / 2576px 76px no-repeat; /* 23 frames x 112px */
  cursor: pointer;
}
.cat:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

.cat-name {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(80, 40, 60, 0.12);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 6px) scale(0.9);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.cat-name::after { /* little tail pointing at the cat */
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  border: 6px solid transparent;
  border-top-color: #fff;
  transform: translateX(-50%);
}
.cat-name.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

.cat-wrap.sleeping::after {
  content: "z";
  position: absolute;
  top: -4px;
  left: 70%;
  font-size: 1.3rem;
  font-style: italic;
  color: var(--soft);
  animation: zz 2.4s ease-in-out infinite;
}

@keyframes zz {
  0% { opacity: 0; transform: translate(0, 6px) scale(0.7); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translate(14px, -22px) scale(1.2); }
}

.heart {
  position: absolute;
  left: 88%;
  top: 10px;
  font-size: 1.4rem;
  color: var(--accent);
  pointer-events: none;
  animation: heart 1.2s ease-out forwards;
}

@keyframes heart {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.6); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--hx, 0px)), -64px) scale(1.15); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  #flower .stem { stroke-dashoffset: 0; }
  .drift { display: none; }
}
