/* =========================================================
   STYLE TỔNG THỂ - PHONG CÁCH TỐI GIẢN, HIỆN ĐẠI & TINH TẾ
   ========================================================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Quicksand', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  /* Nền kem ấm chuyển sắc pastel dịu dàng */
  background: radial-gradient(circle at 50% 38%, #fff7f5 0%, #f9e6e6 55%, #efd3d8 100%);
  user-select: none;
  -webkit-user-select: none;
}

/* Three.js Canvas Container */
#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none; /* Ngăn chặn giật lag vuốt trang trên iPhone / Android */
  cursor: grab;
}

#canvas-container:active {
  cursor: grabbing;
}

/* Lớp phủ cánh hoa rơi nhẹ */
#petals-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

.falling-petal {
  position: absolute;
  top: -30px;
  background: radial-gradient(circle at 35% 35%, #ffe4e9, #f7b4c2);
  border-radius: 60% 0 60% 60%;
  opacity: 0.6;
  filter: drop-shadow(0 2px 4px rgba(220, 160, 170, 0.25));
  animation: petalFall linear infinite;
}

@keyframes petalFall {
  0% {
    transform: translateY(0) rotate(0deg) scale(0.8);
    opacity: 0;
  }
  15% {
    opacity: 0.7;
  }
  85% {
    opacity: 0.7;
  }
  100% {
    transform: translateY(105vh) rotate(360deg) scale(1.05);
    opacity: 0;
  }
}

/* Bảng gợi ý chạm mở thiệp (Đơn giản, không rườm rà) */
.guide-badge {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 10px 22px;
  border-radius: 25px;
  border: 1px solid rgba(238, 205, 214, 0.7);
  box-shadow: 0 8px 24px rgba(160, 130, 110, 0.12);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  transition: opacity 0.5s ease;
  animation: floatBounce 2.6s ease-in-out infinite;
}

.guide-badge .guide-icon {
  font-size: 16px;
}

.guide-badge span {
  font-size: 13.5px;
  font-weight: 600;
  color: #7a4f5c;
  letter-spacing: 0.2px;
}

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

/* Nút đặt lại góc nhìn nhỏ xinh ở góc */
.subtle-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 10;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(238, 205, 214, 0.7);
  color: #9a6b7b;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  transition: all 0.25s ease;
}

.subtle-btn:hover {
  background: #ffffff;
  transform: rotate(45deg);
}

/* =========================================================
   MODAL THIỆP CHÚC MỪNG (MINIMALIST & SANG TRỌNG)
   ========================================================= */
.card-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.45s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.45s ease;
  padding: 20px;
}

.card-modal.active {
  opacity: 1;
  visibility: visible;
}

.card-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(80, 45, 60, 0.32);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.card-container {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 440px;
  background: #fffafa;
  border-radius: 20px;
  border: 1px solid rgba(240, 205, 214, 0.9);
  box-shadow: 0 24px 50px rgba(110, 50, 70, 0.16), 0 4px 12px rgba(0,0,0,0.03);
  padding: 36px 30px 28px;
  transform: scale(0.92) translateY(18px);
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  box-sizing: border-box;
}

.card-modal.active .card-container {
  transform: scale(1) translateY(0);
}

/* Nút đóng thiệp */
.close-card-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: #fbe9ed;
  color: #9a6b7b;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.close-card-btn:hover {
  background: #f4d6de;
  color: #5d3b48;
}

.card-decor-top {
  position: absolute;
  top: -16px;
  left: 32px;
  font-size: 26px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.card-header {
  border-bottom: 1px dashed #f0d6dc;
  padding-bottom: 12px;
  margin-bottom: 18px;
}

.card-date {
  font-size: 11.5px;
  letter-spacing: 2px;
  font-weight: 700;
  color: #c08a99;
  text-transform: uppercase;
}

.card-recipient {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 23px;
  color: #5d3b48;
  font-weight: 600;
  margin-top: 4px;
}

.card-body {
  min-height: 140px;
  font-size: 15px;
  line-height: 1.75;
  color: #6a4e57;
}

.typing-text {
  white-space: pre-line;
  word-wrap: break-word;
}

/* Con trỏ nhấp nháy hiệu ứng đánh máy */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1.15em;
  background-color: #d98aa0;
  vertical-align: middle;
  margin-left: 2px;
  animation: blink 0.8s infinite;
}

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

.card-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px dashed #f0d6dc;
  text-align: right;
}

.card-sender {
  font-family: 'Caveat', cursive, sans-serif;
  font-size: 22px;
  color: #b5677e;
}

/* Responsive tối ưu cho điện thoại nhỏ (iPhone 7/8/SE...) */
@media (max-width: 420px) {
  .card-container {
    padding: 28px 20px 20px;
    max-width: 92%;
  }
  .card-recipient {
    font-size: 20px;
  }
  .card-body {
    font-size: 14.5px;
    line-height: 1.65;
    min-height: 120px;
  }
  .guide-badge {
    bottom: 24px;
    padding: 8px 18px;
  }
  .guide-badge span {
    font-size: 12.5px;
  }
}

/* Gợi ý hiện sau khi hoa nở xong */
.guide-badge { opacity: 0; }
.guide-badge.visible { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .falling-petal, .guide-badge { animation: none; } }

/* Bó hoa 2D */
#bouquet { position: absolute; left: 50%; top: 46%; z-index: 3; cursor: pointer;
  width: min(88vw, 400px, calc(72vh * 0.833)); transform: translate(-50%, -50%);
  filter: drop-shadow(0 18px 16px rgba(150, 70, 95, 0.18)); }
#bouquet svg { display: block; width: 100%; height: auto; overflow: visible; }
.sway { transform-box: view-box; transform-origin: 200px 460px; animation: sway 5s ease-in-out infinite; }
@keyframes sway { 0%, 100% { transform: rotate(-1.4deg); } 50% { transform: rotate(1.4deg); } }
.fl { transform-box: fill-box; transform-origin: center; animation: bloom 1.1s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes bloom { from { transform: scale(.1) rotate(-40deg); opacity: 0; } to { transform: none; opacity: 1; } }
.pp { animation: fadeIn 1s ease both; }
@keyframes fadeIn { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sway, .fl, .pp { animation: none; } }

/* =========================================================
   MÀN HÌNH KHOÁ
   ========================================================= */
.lock { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: radial-gradient(circle at 50% 30%, #fff7f5 0%, #f9e6e6 55%, #efd3d8 100%);
  transition: opacity .7s ease, visibility .7s ease; }
.lock.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.lock-inner { width: 100%; max-width: 320px; text-align: center; opacity: 0; transition: opacity .5s ease; }
.lock.ready .lock-inner { opacity: 1; }
.lock-flower { font-size: 38px; margin-bottom: 6px; animation: lockFloat 3s ease-in-out infinite; }
@keyframes lockFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.lock-title { font-family: 'Playfair Display', Georgia, serif; font-size: 22px; font-weight: 600; color: #5d3b48; }
.lock-sub { margin-top: 8px; min-height: 40px; font-size: 13.5px; line-height: 1.5; color: #9a6b7b; font-weight: 500; }
.dots { display: flex; justify-content: center; gap: 14px; margin: 10px 0 26px; }
.dots i { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid #d98aa0; transition: background .15s, transform .15s; }
.dots i.on { background: #d98aa0; transform: scale(1.1); }
.dots.shake { animation: lockShake .4s ease; }
@keyframes lockShake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-9px); } 40%, 80% { transform: translateX(9px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; justify-items: center; }
.key { width: 70px; height: 70px; border-radius: 50%; border: none; background: rgba(255, 255, 255, .85);
  font-family: inherit; font-size: 25px; font-weight: 500; color: #7a4f5c; cursor: pointer;
  box-shadow: 0 4px 12px rgba(160, 100, 120, .12); transition: transform .12s, background .12s; }
.key:active { background: #fbe0e7; transform: scale(.93); }
.key:focus-visible { outline: 2px solid #d98aa0; outline-offset: 2px; }
.key.ghost { visibility: hidden; }

/* =========================================================
   HỒI ÂM TRONG THIỆP
   ========================================================= */
.card-content { max-height: calc(100vh - 120px); max-height: calc(100dvh - 120px); overflow-y: auto; }
.reply-wrap { display: none; margin-top: 16px; }
.reply-wrap.show { display: block; animation: fadeIn .6s ease both; }
.reply-toggle { width: 100%; padding: 10px; border-radius: 22px; border: 1px solid #f0cdd6; background: #fff;
  color: #b5677e; font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.reply-form { display: none; margin-top: 10px; }
.reply-form.open { display: block; }
.reply-form textarea { width: 100%; min-height: 84px; padding: 10px 12px; border: 1px solid #f0d6dc; border-radius: 12px;
  background: #fff; resize: none; font-family: inherit; font-size: 16px; line-height: 1.5; color: #6a4e57;
  user-select: text; -webkit-user-select: text; }
.reply-form textarea:focus { outline: 2px solid #f0cdd6; }
.reply-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.reply-note { font-size: 12.5px; color: #c08a99; min-height: 18px; }
.reply-send { padding: 8px 22px; border: none; border-radius: 20px; background: #d98aa0; color: #fff;
  font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer; }
.reply-send:disabled { opacity: .6; }
@media (prefers-reduced-motion: reduce) { .lock-flower, .dots.shake { animation: none; } }
