/* ═══════════════════════════════════════════════════════
   Gửi Thương ❤️ — thiết kế ưu tiên màn hình điện thoại
   Bảng màu: đêm tím thẫm · hồng phấn · vàng nến · giấy thư
   ═══════════════════════════════════════════════════════ */

:root {
  --night-1: #160b2e;   /* đỉnh trời đêm */
  --night-2: #43203f;   /* chân trời ửng hồng */
  --rose:    #ff8fa3;   /* hồng phấn — màu nhấn */
  --rose-2:  #ff5c8a;
  --blush:   #ffc2d1;   /* hồng nhạt */
  --gold:    #ffd6a5;   /* vàng nến — sao, viền */
  --paper:   #fff8f0;   /* giấy thư */
  --ink:     #463a50;   /* mực viết */
  --ink-soft:#7d6b86;

  /* Font dự phòng phải hỗ trợ đủ dấu tiếng Việt:
     Palatino Linotype / Times New Roman / Segoe UI đều đạt */
  --font-hand: "Dancing Script", "Palatino Linotype", cursive;
  --font-body: "Lora", "Palatino Linotype", "Times New Roman", serif;
  --font-ui:   "Be Vietnam Pro", "Segoe UI", Arial, sans-serif;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  color: var(--paper);
  background: linear-gradient(180deg, var(--night-1) 0%, #2b1740 55%, var(--night-2) 100%);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

/* ── Bầu trời ────────────────────────────────────────── */
.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }

.aurora {
  position: absolute; inset: -20%;
  background:
    radial-gradient(42% 30% at 22% 24%, rgba(255, 143, 163, .16), transparent 70%),
    radial-gradient(46% 34% at 80% 12%, rgba(120, 90, 200, .22), transparent 70%),
    radial-gradient(50% 36% at 55% 90%, rgba(255, 214, 165, .10), transparent 70%);
  animation: aurora-drift 16s ease-in-out infinite alternate;
}

@keyframes aurora-drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to   { transform: translate3d(2%, 1.5%, 0) scale(1.06); }
}

.stars {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 25px 35px,  var(--gold),  transparent),
    radial-gradient(1px 1px     at 120px 90px, var(--paper), transparent),
    radial-gradient(1.5px 1.5px at 200px 160px,var(--blush), transparent),
    radial-gradient(1px 1px     at 300px 60px, var(--paper), transparent),
    radial-gradient(1px 1px     at 80px 210px, var(--gold),  transparent);
  background-size: 340px 260px;
  opacity: .8;
}

.stars-twinkle {
  background-position: 170px 130px;
  animation: twinkle 3.4s ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { opacity: .15; }
  to   { opacity: .85; }
}

.moon {
  position: absolute;
  top: calc(9% + var(--safe-top));
  right: 10%;
  width: clamp(52px, 14vw, 84px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #fff6e6, #ffe1b8 58%, #f3c489);
  box-shadow:
    0 0 34px rgba(255, 224, 178, .55),
    0 0 90px rgba(255, 214, 165, .28);
  animation: moon-glow 5.5s ease-in-out infinite alternate;
}

@keyframes moon-glow {
  from { box-shadow: 0 0 26px rgba(255,224,178,.4),  0 0 70px  rgba(255,214,165,.2); }
  to   { box-shadow: 0 0 40px rgba(255,224,178,.65), 0 0 110px rgba(255,214,165,.35); }
}

.shooting-star {
  position: absolute;
  top: 16%; left: -12%;
  width: 120px; height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #fff8f0);
  filter: drop-shadow(0 0 6px rgba(255, 248, 240, .8));
  opacity: 0;
  transform: rotate(16deg);
  animation: shoot 9s ease-in 3s infinite;
}

@keyframes shoot {
  0%    { opacity: 0; transform: rotate(16deg) translateX(0); }
  3%    { opacity: 1; }
  10%   { opacity: 0; transform: rotate(16deg) translateX(130vw); }
  100%  { opacity: 0; transform: rotate(16deg) translateX(130vw); }
}

/* ── Tim bay lên ─────────────────────────────────────── */
.hearts span {
  position: absolute;
  bottom: -12vh;
  font-size: 1.1rem;
  opacity: 0;
  animation: float-up linear infinite;
}

.hearts span:nth-child(1) { left: 6%;  animation-duration: 11s;   animation-delay: 0s;   font-size: 1.3rem; }
.hearts span:nth-child(2) { left: 17%; animation-duration: 14s;   animation-delay: 2.5s; font-size: .9rem; }
.hearts span:nth-child(3) { left: 29%; animation-duration: 10s;   animation-delay: 5s;   font-size: 1.6rem; }
.hearts span:nth-child(4) { left: 41%; animation-duration: 15s;   animation-delay: 1s;   font-size: 1rem; }
.hearts span:nth-child(5) { left: 55%; animation-duration: 12s;   animation-delay: 6s;   font-size: 1.4rem; }
.hearts span:nth-child(6) { left: 66%; animation-duration: 13s;   animation-delay: 3.5s; font-size: .95rem; }
.hearts span:nth-child(7) { left: 78%; animation-duration: 10.5s; animation-delay: 7s;   font-size: 1.5rem; }
.hearts span:nth-child(8) { left: 88%; animation-duration: 14.5s; animation-delay: .8s;  font-size: 1.1rem; }
.hearts span:nth-child(9) { left: 95%; animation-duration: 12.5s; animation-delay: 4.2s; font-size: .85rem; }

@keyframes float-up {
  0%   { transform: translateY(0) rotate(-8deg);      opacity: 0; }
  8%   { opacity: .75; }
  85%  { opacity: .55; }
  100% { transform: translateY(-118vh) rotate(10deg); opacity: 0; }
}

/* ── Cảnh chính ──────────────────────────────────────── */
.scene {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: calc(1.5rem + var(--safe-top)) 1.5rem calc(1.5rem + var(--safe-bottom));
  text-align: center;
}

.eyebrow {
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--blush);
}

.name {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(3.2rem, 14vw, 5.5rem);
  line-height: 1.15;
  color: var(--rose);
  text-shadow: 0 0 26px rgba(255, 143, 163, .45);
  margin-bottom: 1.4rem;
}

/* ── Phong thư ───────────────────────────────────────── */
.envelope {
  position: relative;
  width: min(330px, 84vw);
  aspect-ratio: 8 / 5;
  transition: transform .35s ease;
  animation: env-bob 3.6s ease-in-out infinite;
}

@keyframes env-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-7px); }
}

.envelope:active { transform: scale(.97); }

.envelope > span { position: absolute; display: block; }

.env-back {
  inset: 0;
  background: linear-gradient(160deg, #e0637f, #b2405f);
  border-radius: 10px;
  box-shadow: 0 22px 55px rgba(0, 0, 0, .45);
}

.letter-peek {
  left: 8%; right: 8%; top: 9%; bottom: 14%;
  background: var(--paper);
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 2rem;
}

.env-front {
  inset: 0;
  background: linear-gradient(200deg, #f2879f, #d05a78);
  border-radius: 10px;
  clip-path: polygon(0 0, 50% 52%, 100% 0, 100% 100%, 0 100%);
}

.env-flap {
  left: 0; right: 0; top: 0;
  height: 54%;
  background: linear-gradient(180deg, #f8a5b8, #e0637f);
  border-radius: 10px 10px 0 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform .55s ease, opacity .3s ease .25s;
}

.seal {
  left: 50%; top: 46%;
  translate: -50% -50%;
  width: 52px; height: 52px;
  background: radial-gradient(circle at 35% 30%, #9c2b4d, #6e1533);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--gold);
  box-shadow: inset 0 2px 5px rgba(255,255,255,.25), 0 4px 10px rgba(0,0,0,.35);
  transition: transform .45s ease, opacity .3s ease;
}

.hint {
  margin-top: 1.4rem;
  font-family: var(--font-ui);
  font-size: .9rem;
  color: var(--blush);
  animation: pulse 2.2s ease-in-out infinite;
}

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

/* Mở phong thư: nắp lật, dấu sáp mờ đi */
body.is-letter .env-flap { transform: rotateX(180deg); opacity: 0; }
body.is-letter .seal     { transform: scale(.4); opacity: 0; }
body.is-letter .envelope { animation: none; }

/* ── Bức thư ─────────────────────────────────────────── */
.letter-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(1rem + var(--safe-top)) 1rem calc(1rem + var(--safe-bottom));
  background: rgba(20, 10, 36, .72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .5s ease .3s, visibility 0s linear .8s;
  z-index: 5;
}

body.is-letter .letter-overlay {
  opacity: 1;
  visibility: visible;
  transition: opacity .5s ease .3s, visibility 0s;
}

.letter {
  width: min(560px, 100%);
  max-height: 86vh;
  max-height: 86dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background:
    linear-gradient(180deg, rgba(255, 214, 165, .16), transparent 120px),
    var(--paper);
  color: var(--ink);
  border-radius: 14px;
  padding: clamp(1.5rem, 5vw, 2.6rem);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
  transform: translateY(26px);
  transition: transform .55s cubic-bezier(.2, .9, .3, 1.2) .3s;
}

body.is-letter .letter { transform: translateY(0); }

.letter-to {
  font-family: var(--font-hand);
  font-size: 1.9rem;
  color: #b2405f;
  margin-bottom: 1.1rem;
}

.letter-body p {
  font-size: 1.02rem;
  line-height: 1.75;
  max-width: 60ch;
}

.letter-body p + p { margin-top: .9rem; }

.letter-body em { color: #b2405f; font-style: italic; }

.question {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(1.6rem, 6.5vw, 2.1rem);
  text-align: center;
  color: #9c2b4d;
  margin: 1.6rem 0 1.1rem;
  text-wrap: balance;
}

/* ── Nút trả lời ─────────────────────────────────────── */
.answers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .9rem;
  margin-bottom: 1.7rem;
}

.btn {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 1rem;
  min-height: 48px;
  padding: .72rem 1.5rem;
  border-radius: 999px;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .3s ease, box-shadow .3s ease;
}

.btn-yes {
  background: linear-gradient(135deg, #ff8fa3, #d05a78);
  color: #fff;
  box-shadow: 0 8px 22px rgba(208, 90, 120, .45);
  animation: yes-beat 1.8s ease-in-out infinite;
}

@keyframes yes-beat {
  0%, 100% { transform: scale(1); }
  12%      { transform: scale(1.06); }
  24%      { transform: scale(1); }
}

.btn-yes:active { transform: scale(.95); animation: none; }

/* Nút "suy nghĩ" nhút nhát: chạm vào là né đi 😝 (JS di chuyển) */
.btn-no {
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px dashed var(--ink-soft);
  transition: transform .28s cubic-bezier(.2, .9, .3, 1.3), opacity .28s ease;
}

/* ── Polaroid ảnh kỷ niệm ────────────────────────────── */
.polaroids {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1.1rem;
  margin-bottom: 1.6rem;
}

.polaroid {
  background: #fff;
  padding: .5rem .5rem 1.9rem;
  border-radius: 4px;
  box-shadow: 0 8px 20px rgba(70, 58, 80, .25);
  position: relative;
}

.tilt-l { transform: rotate(-4deg); }
.tilt-r { transform: rotate(3.5deg); }

.polaroid .ph,
.polaroid img {
  width: clamp(110px, 30vw, 155px);
  height: clamp(110px, 30vw, 155px);
  display: block;
  object-fit: cover;
  background: linear-gradient(145deg, #ffe3ea, #ffd6a5);
  border-radius: 2px;
}

.polaroid figcaption {
  position: absolute;
  left: 0; right: 0; bottom: .45rem;
  text-align: center;
  font-family: var(--font-hand);
  font-size: .95rem;
  color: var(--ink-soft);
}

.sign {
  font-family: var(--font-hand);
  font-size: 1.5rem;
  text-align: right;
  color: #b2405f;
}

.close-letter {
  display: block;
  width: fit-content;
  margin: 1.4rem auto 0;
  font-family: var(--font-ui);
  font-size: .82rem;
  color: var(--ink-soft);
  border-bottom: 1px dashed var(--ink-soft);
  padding: .4rem 0 2px;
}

.close-letter:active { color: #b2405f; border-color: #b2405f; }

/* ── Màn ăn mừng: pháo hoa tim chạy mãi ──────────────── */
.party {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 143, 163, .22), transparent 60%),
    rgba(16, 8, 32, .96);
  opacity: 0;
  visibility: hidden;
  transition: opacity .5s ease, visibility 0s linear .5s;
  z-index: 10;
}

body.is-party .party {
  opacity: 1;
  visibility: visible;
  transition: opacity .5s ease, visibility 0s;
}

#fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Vignette tối 4 góc — chất điện ảnh, làm pháo hoa nổi khối */
.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 45%,
    transparent 55%, rgba(8, 3, 18, .5) 100%);
}

/* Ảnh polaroid của người ấy rơi nhẹ giữa màn pháo hoa */
.photo-rain {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.photo-float {
  position: absolute;
  top: 0;
  width: 22vw;              /* JS đặt lại theo làn; đây là dự phòng */
  max-width: 200px;
  padding: 6px 6px 20px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .5), 0 0 26px rgba(255, 143, 163, .35);
  animation: photo-fall linear forwards;
  will-change: transform, opacity;
}

.photo-float img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 2px;
}

@keyframes photo-fall {
  0%   { transform: translateY(-40vh) rotate(var(--r0)) scale(.92); opacity: 0; }
  7%   { opacity: 1; }
  86%  { opacity: 1; }
  100% { transform: translateY(112vh) rotate(var(--r1)) scale(1); opacity: 0; }
}

/* Nút bật / tắt tiếng nổ pháo hoa */
.btn-sound {
  position: absolute;
  top: calc(.9rem + var(--safe-top));
  right: .9rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  background: rgba(28, 14, 48, .5);
  border: 1px solid rgba(255, 194, 209, .25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* Chớp sáng khoảnh khắc bấm Đồng ý */
.flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 40%,
    rgba(255, 255, 255, .95), rgba(255, 143, 163, .5) 45%, transparent 75%);
}

body.is-party .flash { animation: flash-out 1s ease-out both; }

@keyframes flash-out {
  0%   { opacity: .95; }
  100% { opacity: 0; }
}

/* Câu chữ — hiện khi lời cảm ơn tạm ẩn, ánh kim chạy qua như dát vàng */
.duo {
  position: absolute;
  left: 50%;
  top: 68%;
  transform: translate(-50%, -50%) scale(.85);
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(1.9rem, 8.5vw, 3.4rem);
  white-space: nowrap;
  background: linear-gradient(100deg,
    var(--paper) 20%, var(--rose) 38%, var(--gold) 50%, var(--rose) 62%, var(--paper) 80%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 20px rgba(255, 143, 163, .5));
  animation: duo-shine 3.6s linear infinite;
  opacity: 0;
  transition: opacity .8s ease .3s, transform .8s ease .3s;
  pointer-events: none;
}

@keyframes duo-shine {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.duo .beat { -webkit-text-fill-color: var(--rose-2); color: var(--rose-2); }

.duo .beat {
  display: inline-block;
  color: var(--rose-2);
  animation: heart-beat 1.1s ease-in-out infinite;
}

@keyframes heart-beat {
  0%, 100% { transform: scale(1); }
  14%      { transform: scale(1.35); }
  28%      { transform: scale(1); }
  42%      { transform: scale(1.2); }
  56%      { transform: scale(1); }
}

.party-hint {
  position: absolute;
  left: 50%;
  bottom: calc(1.6rem + var(--safe-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: 90vw;
  font-family: var(--font-ui);
  font-size: .88rem;
  color: var(--blush);
  opacity: 0;
  transition: opacity .8s ease .5s;
  animation: pulse 2.2s ease-in-out infinite;
  pointer-events: none;
}

.party.card-hidden .duo        { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.party.card-hidden .party-hint { opacity: 1; }

/* Thẻ lời cảm ơn */
.thanks {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(1.5rem + var(--safe-top)) 1.5rem calc(1.5rem + var(--safe-bottom));
  text-align: center;
  transition: opacity .6s ease, visibility 0s;
}

.party.card-hidden .thanks {
  opacity: 0;
  visibility: hidden;
  transition: opacity .6s ease, visibility 0s linear .6s;
}

.thanks-card {
  position: relative;
  max-width: 34rem;
  padding: clamp(1.6rem, 6vw, 2.4rem) clamp(1.2rem, 5vw, 2rem);
  border-radius: 22px;
  background: rgba(28, 14, 48, .58);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
  transform: scale(.9);
  opacity: 0;
  transition: transform .6s cubic-bezier(.2, .9, .3, 1.3) .25s, opacity .5s ease .25s;
}

/* Viền gradient chuyển động quanh thẻ */
.thanks-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1.5px;
  background: linear-gradient(120deg,
    rgba(255, 143, 163, .85), rgba(255, 214, 165, .7) 30%,
    rgba(201, 165, 255, .7) 60%, rgba(255, 143, 163, .85));
  background-size: 300% 300%;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
          mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
          mask-composite: exclude;
  animation: border-flow 6s linear infinite;
  pointer-events: none;
}

@keyframes border-flow {
  from { background-position: 0% 50%; }
  to   { background-position: 300% 50%; }
}

body.is-party .thanks-card { transform: scale(1); opacity: 1; }

.thanks h2 {
  font-family: var(--font-hand);
  font-size: clamp(2.6rem, 12vw, 4rem);
  color: var(--rose);
  text-shadow: 0 0 30px rgba(255, 143, 163, .5);
  margin-bottom: .8rem;
}

.thanks p {
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--paper);
  max-width: 34ch;
  margin-inline: auto;
}

.thanks .small {
  font-family: var(--font-ui);
  font-size: .86rem;
  color: var(--blush);
  margin-top: .6rem;
}

.btn-again {
  display: block;
  width: fit-content;
  margin: 1.5rem auto 0;
  background: transparent;
  color: var(--gold);
  border: 1.5px solid var(--gold);
}

.btn-again:active { background: rgba(255, 214, 165, .12); transform: scale(.96); }

/* ── Tôn trọng người dùng tắt hiệu ứng ───────────────── */
@media (prefers-reduced-motion: reduce) {
  .stars-twinkle, .hint, .party-hint, .btn-yes,
  .aurora, .moon, .shooting-star, .envelope, .duo .beat,
  .duo, .flash, .thanks-card::before { animation: none; }
  .hearts { display: none; }
  *, *::before, *::after { transition-duration: .01s !important; }
}

/* ── Màn hình rất hẹp ────────────────────────────────── */
@media (max-width: 420px) {
  .answers .btn { width: 100%; text-align: center; }
}

/* ── Máy tính: thêm hiệu ứng hover ───────────────────── */
@media (hover: hover) {
  .envelope:hover { animation-play-state: paused; transform: translateY(-5px) scale(1.02); }
  .btn-yes:hover  { transform: scale(1.08); box-shadow: 0 10px 28px rgba(208, 90, 120, .6); }
  .btn-again:hover { background: rgba(255, 214, 165, .12); transform: scale(1.05); }
  .close-letter:hover { color: #b2405f; border-color: #b2405f; }
}
