/* ==========================================================================
   GIAO DIỆN NỀN ĐEN TOÀN MÀN HÌNH THUẦN TÚY & CHIẾC THIỆP TRI ÂN SANG TRỌNG
   ========================================================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #f8fafc;
  user-select: none;
  touch-action: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: #0f172a;
  transition: background-color 1.2s ease, color 1.2s ease;
}

/* Canvas toàn màn hình siêu mượt */
#network-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  cursor: grab;
}

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

/* ==========================================================================
   NÚT MỞ THIỆP NỔI BẬT Ở DƯỚI CÙNG (DẠNG KÍNH MỜ - GLASSMORPHISM)
   ========================================================================== */
.envelope-trigger-btn {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 10px 24px;
  border-radius: 40px;
  /* Kính mờ nền sáng mặc định */
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(15, 23, 42, 0.16);
  color: #0f172a;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.envelope-trigger-btn.visible {
  display: inline-flex;
}

.envelope-trigger-btn:hover {
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(15, 23, 42, 0.38);
  color: #0f172a;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.14);
  transform: translateX(-50%) translateY(-2px);
}

.envelope-trigger-btn:active {
  transform: translateX(-50%) translateY(1px);
  background: rgba(241, 245, 249, 0.9);
}

/* Giao diện nền tối dải ngân hà (Galaxy Blue) */
body.dark-mode {
  background-color: #060e1d;
}

/* Kính mờ nền tối vũ trụ (Khi chuyển sang cảnh đêm dải ngân hà) */
body.dark-mode .envelope-trigger-btn {
  background: rgba(12, 28, 52, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #ffffff;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

body.dark-mode .envelope-trigger-btn:hover {
  background: rgba(30, 41, 69, 0.85);
  border-color: rgba(255, 255, 255, 0.55);
  color: #ffffff;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55), 0 0 20px rgba(255, 255, 255, 0.14);
  transform: translateX(-50%) translateY(-2px);
}

body.dark-mode .envelope-trigger-btn:active {
  transform: translateX(-50%) translateY(1px);
  background: rgba(20, 28, 48, 0.7);
}

/* ==========================================================================
   MODAL CHIẾC THIỆP TRI ÂN SANG TRỌNG (LUXURY ENVELOPE MODAL)
   ========================================================================== */
.envelope-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.envelope-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.envelope-backdrop {
  position: absolute;
  inset: 0;
  background: url('../img/backgourd.png') no-repeat center center;
  background-size: cover;
}

/* Sân khấu 3D cho Chiếc Thiệp & Phong Bì */
.envelope-stage {
  position: relative;
  z-index: 10;
  width: 92%;
  max-width: 440px;
  height: 540px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 25px;
  perspective: 1200px;
}



/* KHỐI PHONG BÌ CHÍNH (Vỏ phong bì vật lý - Màu trắng ngọc trai sang trọng) */
.envelope-wrapper {
  position: relative;
  width: 380px;
  height: 240px;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  transform-style: preserve-3d;
}

/* Hiệu ứng rê chuột khi phong bì đang đóng */
.envelope-wrapper:not(.is-open) {
  cursor: pointer;
}

.envelope-wrapper:not(.is-open):hover {
  transform: translateY(-6px) scale(1.015);
}

/* ==========================================================================
   LÁ THƯ TRI ÂN (MÀU TRẮNG TINH KHÔI, GÁC LÊN MỘT GÓC PHONG BÌ)
   ========================================================================== */
.letter-card {
  position: absolute;
  bottom: 8px;
  left: 18px;
  right: 18px;
  height: 240px;
  z-index: 2;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 14px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.06);
  padding: 20px 22px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  justify-content: center;
  transform: translate(0, 0) rotate(0deg);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease, z-index 0.01s 0.25s;
}

/* KHI PHONG BÌ MỞ: Lá thư rút ra và nằm đè lên góc bên phải phong bì */
.envelope-wrapper.is-open .letter-card {
  transform: translate(32px, -78px) rotate(3.2deg);
  opacity: 1;
  pointer-events: auto;
  z-index: 10;
  box-shadow: -10px 22px 50px rgba(15, 23, 42, 0.16), 0 4px 15px rgba(0, 0, 0, 0.05);
  transition: transform 0.75s cubic-bezier(0.16, 1, 0.3, 1) 0.28s, opacity 0.35s ease 0.18s, z-index 0.01s 0.28s;
}

.card-header-icon {
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-header-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.12));
}

.card-title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
  color: #0f172a;
}

.card-subtitle {
  font-size: 0.82rem;
  color: #64748b;
  margin-bottom: 18px;
  line-height: 1.4;
}

.card-form {
  display: flex;
  flex-direction: column;
  gap: 11px;
  width: 100%;
}

.card-input {
  width: 100%;
  padding: 12px 18px;
  border-radius: 25px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
  text-align: center;
  transition: all 0.25s ease;
}

.card-input:focus {
  border-color: #0f172a;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.08);
}

.card-input::placeholder {
  color: #94a3b8;
}

.card-submit-btn {
  padding: 12px 20px;
  border-radius: 25px;
  border: 1px solid #0f172a;
  background: #0f172a;
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.22);
}

.card-submit-btn:hover {
  background: #1e293b;
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.32);
}

.card-submit-btn:active {
  transform: translateY(1px);
}

.card-feedback {
  margin-top: 8px;
  font-size: 0.82rem;
  min-height: 18px;
  color: #0f172a;
  font-weight: 500;
  transition: color 0.2s;
}

/* ==========================================================================
   THÂN PHONG BÌ VẬT LÝ TRẮNG (NẰM Ở PHÍA DƯỚI)
   ========================================================================== */
.envelope-body {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: translate(0, 0) rotate(0deg);
  transition: transform 0.65s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Khi mở: Thân phong bì hơi dịch xuống góc dưới bên trái */
.envelope-wrapper.is-open .envelope-body {
  transform: translate(-30px, 30px) rotate(-2.8deg);
}

/* 1. Mặt sau bên trong phong bì trắng */
.envelope-back {
  position: absolute;
  inset: 0;
  border-radius: 0 0 14px 14px;
  background: linear-gradient(165deg, #ffffff 0%, #f1f5f9 100%);
  border: 1px solid rgba(15, 23, 42, 0.09);
  box-shadow: 0 25px 60px rgba(15, 23, 42, 0.12), 0 2px 10px rgba(0, 0, 0, 0.04);
  z-index: 1;
  transition: border-top-color 0.4s ease;
}

/* Khi mở: viền trên của thân phong bì hòa vào nếp gấp tự nhiên */
.envelope-wrapper.is-open .envelope-back {
  border-top-color: transparent;
}

/* 2. Nắp gập phong bì (Lật mở 180 độ theo trục ngang) */
.envelope-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 125px;
  transform-origin: top center;
  z-index: 5;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1), z-index 0.1s 0.28s;
  pointer-events: none;
}

.flap-svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 6px 14px rgba(15, 23, 42, 0.12)) drop-shadow(0 2px 4px rgba(15, 23, 42, 0.08));
  transition: filter 0.4s ease;
}

/* Khi mở: Nắp phong bì lật ngược 180 độ ra phía sau, liền mạch với thân phong bì */
.envelope-wrapper.is-open .envelope-flap {
  transform: rotateX(180deg);
  z-index: 0;
}

.envelope-wrapper.is-open .flap-svg {
  filter: drop-shadow(0 -5px 14px rgba(15, 23, 42, 0.06));
}

/* 3. Con dấu niêm phong phong bì (Seal) */
.envelope-seal {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.envelope-wrapper.is-open .envelope-seal {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) scale(0.6);
}

.seal-star {
  width: 62px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}

.seal-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.14));
}

.seal-title {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: #0f172a;
  margin-bottom: 2px;
  text-transform: uppercase;
}

.seal-instruction {
  font-size: 0.76rem;
  color: #64748b;
  letter-spacing: 0.5px;
}

/* 4. Túi mặt trước của phong bì trắng */
.envelope-pocket {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 155px;
  z-index: 4;
  pointer-events: none;
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 14px;
  overflow: hidden;
}

/* Cánh gấp bên trái */
.pocket-fold-left {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #f8fafc 0%, #edf2f7 100%);
  clip-path: polygon(0 0, 0 100%, 65% 100%);
  border-left: 1px solid rgba(15, 23, 42, 0.08);
}

/* Cánh gấp bên phải */
.pocket-fold-right {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(225deg, #edf2f7 0%, #e2e8f0 100%);
  clip-path: polygon(100% 0, 35% 100%, 100% 100%);
  border-right: 1px solid rgba(15, 23, 42, 0.08);
}

/* Cánh gập đáy chữ V ở mặt trước */
.pocket-fold-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
  clip-path: polygon(0 100%, 50% 32%, 100% 100%);
  border-bottom: 1px solid rgba(15, 23, 42, 0.1);
  filter: drop-shadow(0 -4px 10px rgba(15, 23, 42, 0.07));
}

/* Dải nhãn vinh danh ở giữa đáy phong bì */
.pocket-label {
  position: absolute;
  bottom: 12px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 0.7rem;
  letter-spacing: 2px;
  color: #94a3b8;
  font-weight: 600;
  text-transform: uppercase;
}

/* ==========================================================================
   RESPONSIVE CHO MÀN HÌNH NHỎ
   ========================================================================== */
@media (max-width: 480px) {
  .envelope-trigger-btn {
    bottom: 20px;
    padding: 10px 18px;
    font-size: 0.85rem;
  }
  
  .envelope-stage {
    width: 95%;
    height: 480px;
    padding-bottom: 20px;
  }

  .envelope-wrapper {
    width: 320px;
    height: 215px;
  }

  .envelope-flap {
    height: 120px;
  }

  .envelope-pocket {
    height: 140px;
  }

  .envelope-seal {
    top: 66px;
  }

  .seal-star {
    width: 54px;
    height: 54px;
    margin-bottom: 5px;
  }

  .seal-title {
    font-size: 0.82rem;
    letter-spacing: 1.5px;
    margin-bottom: 2px;
    line-height: 1.2;
  }

  .seal-instruction {
    font-size: 0.7rem;
    line-height: 1.2;
  }

  .pocket-label {
    bottom: 8px;
    font-size: 0.62rem;
    letter-spacing: 1.5px;
  }

  .envelope-wrapper.is-open .envelope-body {
    transform: translate(-14px, 18px) rotate(-1.8deg);
  }

  .envelope-wrapper.is-open .letter-card {
    transform: translate(16px, -62px) rotate(2deg);
  }

  .letter-card {
    height: 245px;
    padding: 18px 16px 14px;
  }

  .card-title {
    font-size: 1.18rem;
  }

  .card-subtitle {
    font-size: 0.78rem;
    margin-bottom: 14px;
  }
}
