/* =========================================
   1. 全局變數與基礎設定
   ========================================= */
:root {
  --bg-gradient: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
  --paper-color: #fffcf5;
  --accent-color: #a93226;
  --wax-color-light: #c0392b;
  --wax-color-dark: #922b21;
  --text-color: #2c3e50;
  --shadow-color: rgba(0, 0, 0, 0.1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  /* 確保高度至少有螢幕高，但允許延伸 */
  min-height: 100vh;
}

body {
  font-family: "Noto Serif TC", serif;
  background: var(--bg-gradient);
  color: var(--text-color);

  /* 關鍵：允許垂直滑動，防止內容被切掉 */
  overflow-y: auto;
  overflow-x: hidden;

  /* 讓內容在視覺上置中 */
  display: flex;
  flex-direction: column;
}

/* =========================================
   2. 佈局容器 (Screen & Petals)
   ========================================= */

/* 花瓣容器：固定在視窗最上層，不隨捲軸移動 */
#petals-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none; /* 讓滑鼠穿透 */
  z-index: 100;
}

/* 頁面容器 */
.screen {
  /* 關鍵：使用 relative 佔據真實空間，而非 absolute */
  position: relative;
  width: 100%;
  min-height: 100vh; /* 至少要有螢幕高 */

  /* 使用 Flexbox 佈局 */
  display: flex;
  flex-direction: column;

  /* 使用 padding 和 auto margin 來控制位置 */
  padding: 40px 20px;
  transition: opacity 0.8s ease-in-out;
  z-index: 10;
}

/* 隱藏時的狀態 */
.hidden {
  display: none !important; /* 強制隱藏，避免佔位 */
  opacity: 0;
  pointer-events: none;
}

/* =========================================
   3. 信封畫面 (Page 1 之前)
   ========================================= */
.envelope-container {
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
  padding: 3rem 4rem;
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  border: 1px solid #e0d6d1;
  max-width: 500px;
  width: 100%;

  /* 萬能置中：上下左右自動推擠 */
  margin: auto;
}

.envelope-container h2 {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
  color: #555;
  font-weight: normal;
}

.sender-info {
  font-family: "Dancing Script", cursive;
  font-size: 1.8rem;
  margin-bottom: 2.5rem;
  color: var(--accent-color);
}

.hint-text {
  font-size: 0.85rem;
  color: #aaa;
  margin-bottom: 1.5rem;
  letter-spacing: 1px;
}

/* --- 擬真封蠟按鈕 --- */
.wax-seal-btn {
  width: 100px;
  height: 100px;
  margin: 0 auto;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  user-select: none;
  pointer-events: auto;
  border-radius: 50% 45% 55% 50% / 50% 55% 45% 50%;
  background: radial-gradient(
    circle at 30% 30%,
    var(--wax-color-light),
    var(--wax-color-dark)
  );
  box-shadow: inset 3px 3px 6px rgba(255, 255, 255, 0.3),
    inset -3px -3px 8px rgba(0, 0, 0, 0.4), 4px 8px 15px rgba(0, 0, 0, 0.25);
  transition: all 0.3s ease;
  animation: float-seal 3s ease-in-out infinite;
}

.wax-seal-btn:hover {
  transform: scale(1.05);
  box-shadow: inset 3px 3px 6px rgba(255, 255, 255, 0.4),
    inset -3px -3px 8px rgba(0, 0, 0, 0.4), 4px 12px 20px rgba(0, 0, 0, 0.3);
}

.wax-seal-btn:active {
  transform: scale(0.95);
}

.seal-content {
  font-family: "Dancing Script", cursive;
  font-size: 3.5rem;
  color: #7c241c;
  text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.2),
    -1px -1px 2px rgba(0, 0, 0, 0.5);
}

@keyframes float-seal {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

/* =========================================
   4. 信紙與內容 (Card)
   ========================================= */
.paper-card {
  background-color: var(--paper-color);
  width: 100%;
  max-width: 550px;

  /* 高度自動，隨內容撐開 */
  height: auto;
  min-height: 500px;
  padding: 2.5rem 2rem;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
  transform: rotate(-0.5deg);
  position: relative;
  transition: transform 0.3s ease;

  /* 萬能置中：解決手機版跑版的關鍵 */
  margin: auto;
}

.decorative-border {
  border: 2px solid rgba(169, 50, 38, 0.15);
  padding: 1.5rem;
  min-height: 100%; /* 讓邊框跟隨內容長高 */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* --- 分頁切換動畫 --- */
.letter-page {
  transition: opacity 0.5s ease;
}

.active-page {
  display: block;
  opacity: 1;
  animation: fadeIn 0.5s forwards;
}

.hidden-page {
  display: none;
  opacity: 0;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- 文字樣式 --- */
.letter-greeting {
  font-family: "Dancing Script", cursive;
  font-size: 2rem;
  color: var(--accent-color);
  margin-bottom: 1.5rem;
}

.highlight-name {
  border-bottom: 1px solid rgba(169, 50, 38, 0.3);
}

.letter-body p {
  font-size: 1.1rem;
  line-height: 2.2;
  margin-bottom: 1.2rem;
  text-align: justify;
  color: #444;
}

.important-vow {
  font-weight: 600;
  color: var(--accent-color);
  font-size: 1.2rem;
  text-align: center;
  margin-top: 2rem;
  padding: 1rem 0;
  border-top: 1px dashed rgba(0, 0, 0, 0.1);
  border-bottom: 1px dashed rgba(0, 0, 0, 0.1);
}

/* --- 照片樣式 --- */
.memory-photo {
  width: 100%;
  max-width: 400px;
  height: auto;
  display: block;
  margin: 1.5rem auto 2rem auto;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1),
    0 0 0 5px rgba(255, 255, 255, 0.8) inset;
  transform: rotate(2deg);
  transition: transform 0.3s ease;
}

.memory-photo:hover {
  transform: rotate(0deg) scale(1.02);
}

/* --- 簽名與日期 --- */
.signature {
  font-family: "Dancing Script", cursive;
  font-size: 1.8rem;
  text-align: right;
  margin: 2rem 0;
  color: var(--text-color);
  line-height: 1.5;
}

.date-text {
  font-size: 1rem;
  color: #7f8c8d;
  display: block;
  margin-top: 5px;
}

/* =========================================
   5. 導航按鈕 (Next/Back)
   ========================================= */
.nav-bar {
  display: flex;
  margin-top: 2rem;
  padding-bottom: 10px;
}

.right-align {
  justify-content: flex-end;
}
.space-between {
  justify-content: space-between;
}

.nav-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: "Noto Serif TC", serif;
  font-size: 1rem;
  color: #888;
  padding: 10px 15px; /* 加大觸控範圍 */
  transition: all 0.3s;
  border-bottom: 1px solid transparent;
}

.next-btn {
  color: var(--accent-color);
  font-weight: bold;
}
.next-btn:hover {
  letter-spacing: 2px;
}
.back-btn:hover,
.close-btn:hover {
  color: #555;
  border-bottom: 1px solid #ccc;
}

/* =========================================
   6. Hero Text 特效 (排版修復版)
   ========================================= */
.hero-text {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--accent-color);
  text-align: center;
  margin-top: 2rem;
  min-height: 4rem; /* 預留高度 */

  /* 關鍵修正：使用 block 讓文字自然流動 */
  display: block;
  line-height: 1.6;
  width: 100%;
}

.hero-char {
  display: inline-block;
  opacity: 0;
  transform: translateY(15px);
  transition: opacity 0.6s ease, transform 0.6s ease;
  margin: 0 1px;
  white-space: pre; /* 保留空白鍵 */
}

.hero-char.visible {
  opacity: 1;
  transform: translateY(0);
}

.hero-glow {
  animation: text-breathe 3s infinite ease-in-out;
}

@keyframes text-breathe {
  0%,
  100% {
    text-shadow: 0 0 5px rgba(192, 57, 43, 0);
    transform: scale(1);
  }
  50% {
    text-shadow: 0 0 15px rgba(192, 57, 43, 0.4);
    transform: scale(1.02);
  }
}

/* =========================================
   7. 花瓣雨特效動畫
   ========================================= */
.petal {
  position: absolute;
  background-color: #ffb7b2;
  border-radius: 150% 0 150% 0;
  animation: fall linear infinite;
  opacity: 0.8;
}

@keyframes fall {
  0% {
    transform: translateY(-10vh) translateX(0) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) translateX(20px) rotate(360deg);
    opacity: 0;
  }
}

/* =========================================
   8. 手機版特別優化 (RWD)
   ========================================= */
@media (max-width: 480px) {
  body {
    height: auto;
    overflow-y: scroll; /* 強制開啟捲軸 */
    -webkit-overflow-scrolling: touch;
  }

  .screen {
    position: relative;
    height: auto;
    min-height: 100vh;
    display: block; /* 取消 flex 置中，改為自然流動 */
    padding-top: 50px;
    padding-bottom: 50px;
  }

  .envelope-container {
    padding: 2rem;
    margin-top: 20vh;
  }

  .paper-card {
    padding: 1.5rem 1rem;
    min-height: 450px;
    transform: none !important; /* 手機上取消旋轉 */
    width: 95%; /* 左右留一點邊距 */
  }

  .letter-greeting {
    font-size: 1.6rem;
  }
  .letter-body p {
    font-size: 1rem;
    line-height: 1.8;
  }

  /* 照片在手機上的微調 */
  .memory-photo {
    width: 100%;
    transform: rotate(1deg);
  }

  /* ★★★ 修正 Hero Text 手機排版崩壞 (重要！) ★★★ */
  .hero-text {
    font-size: 1.15rem; /* 縮小字體以塞入一行 */
    margin-top: 2rem;
    padding: 0;
    white-space: nowrap; /* 強制不換行 */

    display: flex; /* 在小螢幕使用 flex 置中 */
    justify-content: center;
    width: 100%;
  }

  /* 移除手機上的字距，節省空間 */
  .hero-char {
    margin: 0 !important;
  }
}
