/* =========================================================================================
 * GIAO DIỆN TỪNG CẢNH (theo thứ tự xuất hiện)
 * ========================================================================================= */

/* ---------------------------------------------------------------- 1. Phong bì: xem css/stationery.css */
.envelope {
  margin: 150px 0 18px;
}

/* ---------------------------------------------------------------- 2. Cắm bó hoa */
.bouquet-stage {
  position: relative;
  flex: 1;
  min-height: 300px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.bouquet {
  width: 100%;
  display: flex;
  justify-content: center;
}

.bouquet svg {
  width: 100%;
  max-width: 360px;
  max-height: 52vh;
  overflow: visible;
}

/* Cả bó hoa đung đưa nhẹ như đang cầm trên tay; dải ruy băng phất phơ */
.bouquet .sway {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: sway 5.5s ease-in-out infinite;
}

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

.bouquet .tail {
  transform-box: fill-box;
  transform-origin: 50% 0;
  animation: flutter 2.6s ease-in-out infinite;
}

@keyframes flutter {
  0%,
  100% {
    transform: skewX(0deg);
  }
  50% {
    transform: skewX(5deg);
  }
}

/* Lấp lánh khi vừa cắm một bông */
.spark {
  position: absolute;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(circle, #fffbe6 0%, #ffd56b 45%, rgba(255, 200, 80, 0) 70%);
  border-radius: 50%;
  animation: spark 0.9s ease-out forwards;
}

.spark.star {
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 0;
  background: #fff6d6;
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
}

@keyframes spark {
  from {
    opacity: 1;
    transform: translate(0, 0) scale(0.6);
  }
  to {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(1.1);
  }
}

/* Bông vừa cắm: thân mọc dài ra, cả bông nhô lên */
.bouquet .grow {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: growIn 0.7s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}

.bouquet .grow .stem {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: drawStem 0.5s ease-out forwards;
}

@keyframes growIn {
  from {
    opacity: 0;
    transform: translateY(26px) scale(0.85);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

.bouquet .wrap-front {
  transform-box: fill-box;
  transform-origin: 50% 100%;
}

.wrapping .wrap-front {
  animation: wrapUp 0.8s cubic-bezier(0.2, 1.2, 0.4, 1) both;
}

@keyframes wrapUp {
  from {
    opacity: 0;
    transform: translateY(40px) scaleY(0.8);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.note-pop {
  position: absolute;
  top: 0;
  left: 50%;
  width: min(92%, 340px);
  margin-left: max(-46%, -170px);
  padding: 12px 16px;
  border-radius: 16px;
  background: rgba(255, 253, 251, 0.96);
  box-shadow: var(--shadow);
  text-align: center;
  z-index: 2;
}

.note-pop strong {
  display: block;
  font-family: var(--font-hand);
  font-size: 1.45rem;
  color: var(--rose-deep);
}

.note-pop span {
  display: block;
  margin-top: 2px;
  font-size: 0.95rem;
  line-height: 1.45;
}

.progress {
  margin: 0;
  text-align: center;
  font-weight: 600;
  color: var(--rose-deep);
}

.shelf {
  display: flex;
  gap: 10px;
  padding: 6px 4px 10px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  transition: opacity 0.4s ease;
}

.shelf::-webkit-scrollbar {
  display: none;
}

.shelf.done {
  opacity: 0.45;
  pointer-events: none;
}

.shelf-item {
  position: relative;
  flex: 0 0 82px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 8px;
  border: 0;
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  font: 600 0.78rem var(--font-body);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.shelf-item:active {
  transform: scale(0.94);
}

.shelf-art svg {
  display: block;
  width: 58px;
  height: 58px;
}

.shelf-item.picked {
  box-shadow: inset 0 0 0 2px var(--rose), var(--shadow-sm);
}

.shelf-item.picked::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--rose);
  color: #fff;
  font-size: 0.7rem;
  line-height: 18px;
}

/* ---------------------------------------------------------------- 3. Ảnh lấy liền */
.photo-stack {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 430px;
}

.polaroid {
  grid-area: 1 / 1;
  width: min(76vw, 300px);
  margin: 0;
  padding: 12px 12px 0;
  border-radius: 6px;
  background: #fffdf8;
  box-shadow: 0 14px 30px rgba(80, 40, 60, 0.22);
  transform: rotate(var(--tilt));
  transition: transform 0.5s ease, opacity 0.5s ease;
}

.polaroid.fly-away {
  transform: translateX(130%) rotate(18deg);
  opacity: 0;
}

.photo-frame {
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 2px;
  background: #1c1a21;
}

.photo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  /* Độ hiện hình do js/scenes/photos.js đặt mỗi khung hình (tối, ngả nâu, nhoè -> rõ nét) */
  filter: brightness(0.12) sepia(0.7) saturate(0.3) blur(5px);
}

/* Vệt sáng loang (light leak) và hạt phim như ảnh lấy liền thật */
.leak,
.grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.leak {
  opacity: 0;
  mix-blend-mode: screen;
  background: radial-gradient(60% 45% at 100% 0%, rgba(255, 150, 80, 0.85), transparent 70%),
    radial-gradient(50% 40% at 0% 100%, rgba(255, 90, 150, 0.55), transparent 70%);
}

.grain {
  opacity: 0.16;
  mix-blend-mode: overlay;
  background-image: radial-gradient(rgba(255, 255, 255, 0.7) 0.5px, transparent 0.7px),
    radial-gradient(rgba(0, 0, 0, 0.6) 0.5px, transparent 0.7px);
  background-size: 3px 3px, 4px 4px;
  background-position: 0 0, 1px 2px;
}

/* Đang được lắc: tấm ảnh rung nhẹ theo */
.polaroid.shaking {
  animation: jiggle 0.18s linear infinite;
}

@keyframes jiggle {
  0%,
  100% {
    transform: rotate(var(--tilt)) translateX(0);
  }
  25% {
    transform: rotate(calc(var(--tilt) - 1.5deg)) translateX(-2px);
  }
  75% {
    transform: rotate(calc(var(--tilt) + 1.5deg)) translateX(2px);
  }
}

.develop-hint {
  margin: 0;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--rose-deep);
  animation: blink 1.6s ease-in-out infinite;
}

.develop-hint[hidden] {
  display: none;
}

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

.film {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 16px;
  background: linear-gradient(180deg, #2c2831, #1c1a21 62%, #141218);
  touch-action: none;
  cursor: grab;
  transform-origin: 50% 0;
  transition: transform 0.5s ease, opacity 0.5s ease;
}

.film.dragging {
  transition: none;
  cursor: grabbing;
}

/* Ánh sáng ở mép phim đang bị bóc lên */
.film::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 46px;
  background: linear-gradient(to top, rgba(255, 255, 255, calc(var(--curl, 0) * 0.55)), transparent);
  pointer-events: none;
}

.film.peeled {
  transform: translateY(-115%) rotate(-6deg);
  opacity: 0;
  pointer-events: none;
}

.film-grain {
  position: absolute;
  inset: 0;
  opacity: 0.18;
  background-image: radial-gradient(rgba(255, 255, 255, 0.5) 0.6px, transparent 0.8px);
  background-size: 5px 5px;
  pointer-events: none;
}

.film-tab {
  position: relative;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #f7e9ef;
  font-size: 0.85rem;
  font-weight: 600;
  animation: nudge 1.6s ease-in-out infinite;
}

@keyframes nudge {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.polaroid figcaption {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.6em;
  padding: 8px 6px 12px;
  font-family: var(--font-hand);
  font-size: 1.32rem;
  line-height: 1.2;
  text-align: center;
  color: #5a3a48;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.polaroid.captioned figcaption {
  opacity: 1;
  transform: none;
}

.counter {
  margin: 0;
  text-align: center;
  font-weight: 600;
  color: var(--muted);
}

/* ---------------------------------------------------------------- 4. Vé cào */
.ticket {
  position: relative;
  width: min(88vw, 340px);
  aspect-ratio: 16 / 10;
  margin: 22px 0;
  border-radius: 18px;
  background: linear-gradient(135deg, #fff4f7, #ffe0ea);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Hai vết khuyết hai bên như vé thật */
.ticket::before,
.ticket::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 26px;
  height: 26px;
  margin-top: -13px;
  border-radius: 50%;
  background: var(--bg);
  z-index: 3;
}

.ticket::before {
  left: -13px;
}

.ticket::after {
  right: -13px;
}

.ticket-body {
  position: absolute;
  inset: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: 2px dashed #f2b5c6;
  border-radius: 12px;
  text-align: center;
}

.ticket-heading {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--rose-deep);
}

.ticket-text {
  margin: 8px 0;
  font-family: var(--font-hand);
  font-size: 1.45rem;
  line-height: 1.25;
}

.ticket-note {
  font-size: 0.74rem;
  color: var(--muted);
}

.scratch {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  touch-action: none;
  cursor: crosshair;
  transition: opacity 0.8s ease;
}

.scratch.gone {
  opacity: 0;
  pointer-events: none;
}

.ticket.revealed {
  animation: glow 1.4s ease-out;
}

@keyframes glow {
  0% {
    box-shadow: var(--shadow);
  }
  40% {
    box-shadow: 0 0 0 8px rgba(255, 170, 200, 0.45), var(--shadow);
  }
  100% {
    box-shadow: var(--shadow);
  }
}

/* Lớp canvas cánh hoa xếp chữ (cảnh Bầu trời lời chúc) */
.petal-text {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  pointer-events: auto;
}

.petal-text[hidden] {
  display: none;
}

.mini-bouquet {
  display: flex;
  justify-content: center;
}

.mini-bouquet svg {
  width: 100%;
  max-width: 300px;
  max-height: 36vh;
}

.save-status {
  margin: 0;
  min-height: 1.3em;
  text-align: center;
  font-size: 0.9rem;
}

/* ---------------------------------------------------------------- Trời đêm (cảnh 5 và 6) */
body[data-current="sky"],
body[data-current="finale"] {
  background: radial-gradient(120% 80% at 50% 0%, #2a1238 0%, #150a22 55%, #0a0510 100%) fixed;
  color: #fbe9f1;
}

body[data-current="sky"] #petals,
body[data-current="finale"] #petals {
  opacity: 0.35;
}

.night h2,
.scene-head.night h2 {
  color: #ffd1e3;
  text-shadow: 0 0 18px rgba(255, 90, 170, 0.6);
}

.hint.night,
.scene-head.night .hint {
  color: #e9c3d6;
}

.btn.ghost.night {
  color: #ffd1e3;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1.5px rgba(255, 190, 220, 0.45);
}

/* ---------------------------------------------------------------- 5. Bầu trời lời chúc */
.sky-scene {
  position: relative;
  min-height: 100dvh;
}

.wish-sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

.sky-ui {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(24px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  pointer-events: none;
  z-index: 60;
}

.sky-ui .btn {
  pointer-events: auto;
}

.sky-ui .scene-head {
  transition: opacity 1.2s ease;
}

.sky-ui .scene-head.faded {
  opacity: 0;
}

/* ---------------------------------------------------------------- 6. Lá thư & lưu ảnh */
.finale-scene {
  justify-content: flex-start;
}

.letter-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.envelope-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 18vh; /* Chừa chỗ phía trên cho mép thư trượt ra khi mở */
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.envelope-wrap[hidden] {
  display: none;
}

.envelope-wrap.away {
  opacity: 0;
  transform: translateY(60px) scale(0.92);
}

.letter-paper.rise {
  animation: rise 0.9s cubic-bezier(0.2, 1.1, 0.4, 1) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(70px) scale(0.9) rotate(-2deg);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.after-letter {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.after-letter[hidden] {
  display: none;
}

.finale-scene .save-status {
  color: #e9c3d6;
}
