/* === Variables === */
:root {
  --red-envelope: #c41e3a;
  --red-envelope-dark: #9e1830;
  --red-envelope-light: #e63950;
  --gold: #d4af37;
  --gold-light: #f4e4a6;
  --gold-dark: #b8860b;
  --paper: #faf8f0;
  --paper-shadow: rgba(0, 0, 0, 0.15);
  --text-dark: #2c1810;
}

/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Be Vietnam Pro', -apple-system, sans-serif;
  min-height: 100vh;
  overflow: hidden;
  background: linear-gradient(160deg, #1a0a0a 0%, #2d1515 50%, #1a0a0a 100%);
  color: var(--text-dark);
  user-select: none;
  -webkit-user-select: none;
}

/* === Background === */
.bg-pattern {
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(ellipse at 20% 80%, rgba(212, 175, 55, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(212, 175, 55, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(196, 30, 58, 0.03) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* === Container === */
.container {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.hint {
  position: absolute;
  bottom: 25%;
  color: rgba(212, 175, 55, 0.6);
  font-size: 0.9rem;
  animation: hint-pulse 2s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* === Envelope === */
.envelope-wrapper {
  position: relative;
  cursor: pointer;
  touch-action: manipulation;
  perspective: 800px;
  transition: transform 0.5s cubic-bezier(0.55, 0.06, 0.68, 0.19);
}

.envelope-wrapper.taken {
  transform: translateY(-120vh);
  pointer-events: none;
}

.container:has(.envelope-wrapper.taken) .hint {
  opacity: 0;
  pointer-events: none;
}

.envelope-img {
  width: min(260px, 65vw);
  height: auto;
  object-fit: contain;
  transition: transform 0.2s ease;
  filter: drop-shadow(0 25px 50px rgba(0, 0, 0, 0.4));
}

.envelope-img:active {
  transform: scale(0.98);
}

.envelope-wrapper.open .envelope-img {
  animation: envelope-open 0.6s ease forwards;
}

@keyframes envelope-open {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 1;
  }
  100% {
    transform: scale(0.55) translateY(60px);
    opacity: 1;
  }
}

/* Bụp - bao từ mở "bụp" lại thành chưa mở */
.envelope-wrapper.bup .envelope-img {
  animation: envelope-bup 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes envelope-bup {
  0% {
    transform: scale(0.55) translateY(60px);
    opacity: 1;
  }
  70% {
    transform: scale(1.08) translateY(0);
    opacity: 1;
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* Hold progress ring */
.hold-progress {
  position: absolute;
  inset: -20px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--gold);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  animation: hold-spin 0.8s linear infinite;
}

.hold-progress.visible {
  opacity: 0.6;
}

.hold-progress::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  border-right-color: var(--gold-light);
  opacity: 0.5;
  animation: hold-spin 0.8s linear infinite reverse;
}

@keyframes hold-spin {
  to { transform: rotate(360deg); }
}


/* === Message Paper === */
.message-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  padding-top: env(safe-area-inset-top);
}

.message-overlay.visible {
  pointer-events: auto;
  opacity: 1;
}

/* Khối: tờ giấy + ảnh bên dưới, chệch lên để thấy bao đã mở; margin-top đẩy cả khối xuống */
.message-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 6vh;
  margin-bottom: 12vh;
}

/* Trên phone: thêm khoảng trống phía trên để câu chúc không bị mất chữ (notch, status bar) */
@media (max-height: 700px), (max-width: 480px) {
  .message-overlay {
    padding-top: max(2.5rem, env(safe-area-inset-top));
  }
  .message-block {
    margin-top: 4vh;
    margin-bottom: 4vh;
  }
}

.message-footer-img {
  width: min(260px, 78vw);
  height: auto;
  margin-top: 0.75rem;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.message-paper {
  max-width: min(260px, 78vw);
  padding: 1.35rem 1.5rem;
  background: linear-gradient(180deg, var(--paper) 0%, #f5f0e6 100%);
  border-radius: 8px;
  box-shadow:
    0 25px 50px -12px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(212, 175, 55, 0.2);
  transform: scale(0.8) translateY(20px);
  opacity: 0;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
  cursor: pointer;
}

.message-block .message-footer-img {
  transform: scale(0.9);
  opacity: 0;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s, opacity 0.4s ease 0.1s;
}

.message-overlay.visible .message-block .message-footer-img {
  transform: scale(1);
  opacity: 1;
}

.message-overlay.visible .message-paper {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* Tờ giấy biến mất */
.message-paper.closing {
  animation: paper-fade-out 0.3s ease forwards;
  pointer-events: none;
}

@keyframes paper-fade-out {
  to {
    transform: scale(0.95);
    opacity: 0;
  }
}

.message-text {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text-dark);
  white-space: pre-wrap;
  text-align: center;
}

/* === Smoke === */
.smoke-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}

.smoke-particle {
  position: absolute;
  width: 80px;
  height: 80px;
  left: 50%;
  top: 50%;
  margin-left: -40px;
  margin-top: -40px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0) 70%);
  border-radius: 50%;
  animation: smoke-disperse 1.5s ease-out forwards;
  opacity: 0;
}

@keyframes smoke-disperse {
  0% {
    transform: scale(0.3);
    opacity: 0.8;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    transform: scale(2) translate(var(--tx), var(--ty));
    opacity: 0;
  }
}

/* Vệt khói khi bao bị kéo lên */
.trail-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  overflow: hidden;
}

.trail-particle {
  position: absolute;
  left: 50%;
  width: 60px;
  height: 60px;
  margin-left: -30px;
  margin-top: -30px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0.12) 40%, transparent 70%);
  border-radius: 50%;
  animation: trail-fade 1.4s ease-out forwards;
  --dx: 0px;
}

@keyframes trail-fade {
  0% {
    transform: translate(calc(-50% + var(--dx, 0)), 0) scale(0.5);
    opacity: 0.85;
  }
  100% {
    transform: translate(calc(-50% + var(--dx, 0)), 0) scale(1.6);
    opacity: 0;
  }
}

/* === Hand overlay === */
.hand-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.3s ease;
  overflow: visible;
}

.hand-overlay.visible {
  pointer-events: auto;
  opacity: 1;
}

.hand-overlay.no-dialog .dialog-bubble {
  display: none;
}

.hand {
  position: absolute;
  left: 48%;
  top: -120vh;
  transform: translateX(-50%);
  transition: top 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.hand-paw {
  width: min(520px, 96vw);
  height: auto;
  object-fit: contain;
  object-position: top center;
  filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.35));
  /* Nền đen do tool xuất ảnh: dùng screen để chỉ hiện phần sáng (chân mèo) */
  mix-blend-mode: screen;
}

.hand-overlay.visible .hand {
  top: -26%;
}

/* Rút lên đủ cao (ra hẳn khỏi màn hình) rồi mới ẩn — dùng vh lớn để mọi thiết bị đều hết ảnh */
.hand-overlay.retracting .hand {
  top: -220vh;
  transition: top 0.6s cubic-bezier(0.55, 0.06, 0.68, 0.19);
}

/* Dialog bubble - dùng ảnh */
.dialog-bubble {
  position: absolute;
  left: 58%;
  top: -8%;
  transform: translateX(-50%) translateY(-20px);
  opacity: 0;
  transition: opacity 0.3s ease 0.3s, transform 0.3s ease 0.3s;
  overflow: visible;
}

.dialog-bubble-img {
  width: min(280px, 80vw);
  height: auto;
  display: block;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.25));
  /* Ảnh đuôi chỉ xuống → xoay 180deg cho đuôi chỉ lên (về phía bàn chân) */
  transform: rotate(180deg);
}

.dialog-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.1rem;
  color: var(--text-dark);
  text-align: center;
  padding: 0.5rem 1rem;
  max-width: 220px;
}

.hand-overlay.visible .dialog-bubble {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* === Create modal === */
.create-btn {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.6rem 1rem;
  max-width: min(320px, calc(100vw - 2rem));
  background: rgba(212, 175, 55, 0.2);
  border: 1px solid rgba(212, 175, 55, 0.5);
  border-radius: 999px;
  color: var(--gold-light);
  font-size: 0.9rem;
  cursor: pointer;
  z-index: 100;
  transition: all 0.2s ease;
  text-align: center;
  line-height: 1.3;
}

.create-btn:hover {
  background: rgba(212, 175, 55, 0.3);
  transform: scale(1.02);
}

/* Chỉ hiện khi chạy trên localhost */
.dev-clear-btn {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.5);
  color: #999;
  border: 1px solid #555;
  border-radius: 6px;
  cursor: pointer;
  z-index: 100;
}
body.dev-mode .dev-clear-btn {
  display: block;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: linear-gradient(180deg, #2d1515 0%, #1a0a0a 100%);
  padding: 2rem;
  border-radius: 16px;
  max-width: 420px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid rgba(212, 175, 55, 0.3);
}

.modal h2 {
  color: var(--gold-light);
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.modal-label {
  display: block;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.modal-label .optional {
  color: rgba(255, 255, 255, 0.5);
  font-weight: 400;
}

.modal-char-hint {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.85em;
  font-weight: 400;
}

.modal-input {
  width: 100%;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid rgba(212, 175, 55, 0.3);
  background: rgba(0, 0, 0, 0.3);
  color: white;
  font-family: inherit;
  font-size: 1rem;
  margin-bottom: 1rem;
}

.modal-input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.modal-textarea {
  width: 100%;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid rgba(212, 175, 55, 0.3);
  background: rgba(0, 0, 0, 0.3);
  color: white;
  font-family: inherit;
  font-size: 1rem;
  resize: vertical;
  margin-bottom: 1rem;
}

.modal textarea.modal-textarea::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-bottom: 1.25rem;
}

.pool-section {
  border-top: 1px solid rgba(212, 175, 55, 0.2);
  padding-top: 1rem;
}

.pool-title {
  color: var(--gold-light);
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.pool-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 180px;
  overflow-y: auto;
}

.pool-list li {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.9rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.pool-list .pool-name {
  color: var(--gold-light);
}

.pool-list .pool-censor {
  color: rgba(255, 255, 255, 0.5);
  font-style: italic;
}

.btn {
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-primary {
  background: var(--gold);
  color: var(--text-dark);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--gold-light);
  transform: scale(1.02);
}
