:root {
  --ink: #7a2436;        /* 버건디 글씨 */
  --ink-soft: #b0607a;   /* 보조 글씨 */
  --bg-1: #fff1f4;
  --bg-2: #f9cdd8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: radial-gradient(ellipse at 50% 42%, var(--bg-1) 0%, #fde0e7 45%, var(--bg-2) 100%);
  color: var(--ink);
  font-family: "Cormorant Garamond", serif;
  overflow: hidden;
}

/* ---------- 배경 꽃 ---------- */
.bg-flowers {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.bg-flowers svg {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: calc(var(--s) * 1px);
  height: calc(var(--s) * 1px);
  margin-left: calc(var(--s) * -0.5px);
  margin-top: calc(var(--s) * -0.5px);
  opacity: 0.9;
  transform: rotate(var(--r, 0deg));
  animation: sway 6s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
@keyframes sway {
  0%, 100% { transform: rotate(var(--r, 0deg)); }
  50%      { transform: rotate(calc(var(--r, 0deg) + 5deg)); }
}

.stage {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 24px;
}

.subtitle {
  font-family: "Great Vibes", cursive;
  font-size: 3rem;
  color: var(--ink);
  text-align: center;
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.8);
}

/* ---------- 카운트다운 ---------- */
.countdown {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  transition: opacity 0.8s ease;
}
.countdown .unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 64px;
}
.countdown .unit span {
  font-size: 2.6rem;
  font-weight: 600;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}
.countdown .unit small {
  font-size: 0.85rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.countdown .sep { font-size: 2.2rem; line-height: 1.3; color: var(--ink-soft); }
.countdown.done { opacity: 0; pointer-events: none; }

/* ---------- 봉투 ---------- */
.envelope-wrap {
  position: relative;
  width: min(520px, 86vw);
  filter: drop-shadow(0 10px 16px rgba(120, 50, 70, 0.18));
}
.envelope { width: 100%; height: auto; display: block; }

/* 두근두근 하트 */
.seal {
  transform-box: fill-box;
  transform-origin: center;
  animation: heartbeat 1.4s ease-in-out infinite;
}
.seal.excited { animation-duration: 0.8s; }

@keyframes heartbeat {
  0%   { transform: scale(1); }
  14%  { transform: scale(1.14); }
  28%  { transform: scale(1); }
  42%  { transform: scale(1.1); }
  70%  { transform: scale(1); }
  100% { transform: scale(1); }
}

/* ---------- 하트 클릭 영역 & Open 라벨 ---------- */
/* viewBox 50 40 380 266 기준, 실링 중심 (240,192) → 50%, 57.1% */
.seal-hit {
  position: absolute;
  left: 50%;
  top: 57.1%;
  width: 20%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
}
.seal-label {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translate(-50%, 6px);
  white-space: nowrap;
  font-family: "Great Vibes", cursive;
  font-size: 2rem;
  line-height: 1;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(176, 96, 122, 0.45);
  border-radius: 30px;
  padding: 4px 20px 8px;
  box-shadow: 0 4px 14px rgba(140, 60, 80, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.label-wait { font-size: 1.5rem; }
.label-open { display: none; }

/* 카운트다운 중: hover 하면 "Em breve ♡" */
.seal-hit:hover .label-wait,
.seal-hit:focus-visible .label-wait { opacity: 1; transform: translate(-50%, 0); }
.seal-hit.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translate(-50%, -50%); }
  25% { transform: translate(-56%, -50%); }
  75% { transform: translate(-44%, -50%); }
}

/* 카운트다운 끝: hover 하면 "Open", 클릭 가능 */
.envelope-wrap.ready .seal-hit { cursor: pointer; }
.envelope-wrap.ready .label-wait { display: none; }
.envelope-wrap.ready .label-open { display: block; }
.envelope-wrap.ready .seal-hit:hover .label-open,
.envelope-wrap.ready .seal-hit:focus-visible .label-open {
  opacity: 1;
  transform: translate(-50%, 0);
  animation: glow 2.2s ease-in-out infinite;
}
/* 터치 기기(hover 없음)에서는 끝나면 Open 을 항상 보여줌 */
@media (hover: none) {
  .envelope-wrap.ready .label-open { opacity: 1; transform: translate(-50%, 0); animation: glow 2.2s ease-in-out infinite; }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 4px 14px rgba(140, 60, 80, 0.18); }
  50%      { box-shadow: 0 0 24px rgba(176, 96, 122, 0.55); }
}

/* ---------- 모바일 ---------- */
@media (max-width: 600px) {
  .stage { gap: 20px; }
  .subtitle { font-size: 2.3rem; }
  .countdown { gap: 4px; }
  .countdown .unit { min-width: 50px; }
  .countdown .unit span { font-size: 2rem; }
  .countdown .unit small { font-size: 0.7rem; letter-spacing: 2px; }
  .countdown .sep { font-size: 1.7rem; }
  .envelope-wrap { width: 90vw; }
  .seal-label { font-size: 1.7rem; }
  .label-wait { font-size: 1.3rem; }
  .bg-flowers svg { width: calc(var(--s) * 0.6px); height: calc(var(--s) * 0.6px);
    margin-left: calc(var(--s) * -0.3px); margin-top: calc(var(--s) * -0.3px); }
  .bg-flowers .pc-only { display: none; }
}

/* =========================================================
   봉투 열기 애니메이션
   ========================================================= */
.env-flap-back {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  overflow: visible;
}
.envelope { position: relative; z-index: 3; overflow: visible; }
.seal-hit { z-index: 4; }

/* 앞 뚜껑: 위쪽 모서리를 축으로 접혀 올라감 (앞 → 0) */
.flap {
  transform-box: fill-box;
  transform-origin: 50% 0%;
  transition: transform 0.45s ease-in;
}
.opening .flap { transform: scaleY(0); }

/* 뒤 뚜껑: 0 → 뒤집혀 위로 펼쳐짐 */
.flap-back {
  transform-box: fill-box;
  transform-origin: 50% 0%;
  transform: scaleY(0);
  transition: transform 0.45s ease-out 0.45s;
}
.opening .flap-back { transform: scaleY(-1); }

/* 실링: 톡 하고 떨어져 나감 */
.seal-pop {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.35s ease, opacity 0.35s ease;
}
.opening .seal-pop { transform: scale(1.35); opacity: 0; }
.opening .seal-label { opacity: 0 !important; }
.opening .seal-hit { pointer-events: none; }

/* 편지지: 봉투 뒤에 숨어 있다가 위로 올라옴 */
.letter-peek {
  position: absolute;
  z-index: 2;
  left: 10.5%;
  width: 79%;
  top: 9.8%;
  height: 76%;
  background: linear-gradient(180deg, #fffaf0, #f6ecd6);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(168, 128, 80, 0.25);
  padding: 9% 10%;
  display: flex;
  flex-direction: column;
  gap: 12%;
  transition: transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1) 0.95s;
}
.letter-peek span {
  display: block;
  height: 2px;
  background: rgba(122, 36, 54, 0.18);
  border-radius: 2px;
}
.letter-peek span:nth-child(2) { width: 80%; }
.letter-peek span:nth-child(3) { width: 60%; }
.opening .letter-peek { transform: translateY(-62%); }

/* 시작 화면 전체가 사라짐 */
.stage { transition: opacity 0.7s ease, transform 0.7s ease; }
.stage.leaving { opacity: 0; transform: scale(0.96); pointer-events: none; }

/* =========================================================
   편지 화면 (사진은 밖, 편지는 여러 장)
   ========================================================= */
.letter-view {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4vh 24px;
  background: rgba(255, 240, 244, 0.35);
}
.letter-view[hidden] { display: none; }

.letter-scene {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 60px;
  margin: auto 0;
}

/* ---------- 폴라로이드 사진 (2장) ---------- */
.photos {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
}
.polaroid {
  position: relative;
  width: min(250px, calc((100dvh - 230px) / 2));
  background: #fffdf8;
  padding: 12px 12px 0;
  box-shadow: 0 12px 28px rgba(90, 40, 30, 0.22);
  --rot: -6deg;
  transform: rotate(var(--rot));
  animation: photoIn 1s ease 0.2s backwards;
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}
.polaroid:nth-child(2) {
  --rot: 5deg;
  margin-top: -6px;
  margin-left: 80px;
  animation-delay: 0.5s;
}
@keyframes photoIn {
  from { opacity: 0; transform: rotate(calc(var(--rot) * 2.2)) translate(-30px, 20px); }
  to   { opacity: 1; transform: rotate(var(--rot)); }
}
.polaroid::before { /* 마스킹 테이프 */
  content: "";
  position: absolute;
  top: -13px;
  left: 50%;
  width: 84px;
  height: 26px;
  transform: translateX(-50%) rotate(3deg);
  background: rgba(240, 170, 190, 0.6);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.polaroid:nth-child(2)::before { background: rgba(190, 205, 175, 0.65); transform: translateX(-50%) rotate(-4deg); }
.photo-frame {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #eadfcf;
  overflow: hidden;
}
.photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: sepia(0.12) saturate(0.95);
  transition: opacity 0.8s ease;
}
.photo-frame img.fading { opacity: 0; }
.photo-frame img[hidden] { display: none; }
.photo-missing {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  font-family: "Caveat", "Nanum Pen Script", cursive;
  font-size: 1.4rem;
  color: #9c7a5a;
}
.photo-missing[hidden] { display: none; }
.polaroid figcaption {
  font-family: "Caveat", "Nanum Pen Script", cursive;
  font-size: 1.7rem;
  color: #5a3a30;
  text-align: center;
  padding: 10px 0 14px;
  min-height: 52px;
}

/* ---------- 편지지 묶음 ---------- */
.letter-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: paperIn 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
@keyframes paperIn {
  from { opacity: 0; transform: translateY(40px) scale(0.94); }
  to   { opacity: 1; transform: none; }
}

.letter-book {
  position: relative;
  width: min(540px, 52vw);
  height: min(700px, calc(100dvh - 140px));
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
/* 뒤에 겹쳐진 종이 (여러 장 느낌) */
.letter-book::before,
.letter-book::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 4px;
  background: #f1e4c8;
  box-shadow: 0 6px 18px rgba(120, 50, 70, 0.12);
}
.letter-book::before { transform: rotate(2.2deg) translate(6px, 4px); }
.letter-book::after  { transform: rotate(-1.4deg) translate(-4px, 6px); background: #f5eacf; }
.letter-book.single::before,
.letter-book.single::after { display: none; }

.page {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  padding: 52px 48px 60px;
  border-radius: 4px;
  background: radial-gradient(ellipse at 50% 40%, #fffaf0 0%, #f8eedb 70%, #efdfbf 100%);
  box-shadow:
    inset 0 0 60px rgba(199, 163, 109, 0.32),
    0 18px 40px rgba(120, 50, 70, 0.2);
}
.page.active,
.page.measuring { display: block; }
.page.measuring { visibility: hidden; }

.page-inner {
  height: 100%;
  overflow: hidden;
}
.page-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18px;
  text-align: center;
  font-family: "Cormorant Garamond", serif;
  font-size: 0.95rem;
  letter-spacing: 3px;
  color: #b08a6a;
}

/* 장 넘김 애니메이션 */
.page.in-next  { animation: pageInNext 0.5s ease both; }
.page.in-prev  { animation: pageInPrev 0.5s ease both; }
.page.out-next { animation: pageOutNext 0.45s ease both; z-index: 2; }
.page.out-prev { animation: pageOutPrev 0.45s ease both; z-index: 2; }
@keyframes pageInNext  { from { opacity: 0; transform: translateX(40px) rotate(1.5deg); } to { opacity: 1; transform: none; } }
@keyframes pageInPrev  { from { opacity: 0; transform: translateX(-40px) rotate(-1.5deg); } to { opacity: 1; transform: none; } }
@keyframes pageOutNext { to { opacity: 0; transform: translateX(-70px) rotate(-4deg); } }
@keyframes pageOutPrev { to { opacity: 0; transform: translateX(70px) rotate(4deg); } }

/* ---------- 편지 글씨 ---------- */
.page-inner {
  font-family: "Caveat", "Nanum Pen Script", cursive;
  font-size: 1.75rem;
  line-height: 1.65;
  color: #4a2a22;
}
.page-inner p { white-space: pre-line; margin-bottom: 0.9em; }
.page-inner p.split { margin-bottom: 0; }
.page-inner .greeting {
  font-family: "Great Vibes", "Nanum Pen Script", cursive;
  font-size: 2.8rem;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: 0.5em;
}
.page-inner .ending { margin-top: 1.2em; text-align: right; }
.page-inner .ending .closing { margin-bottom: 0.1em; }
.page-inner .ending .signature {
  font-family: "Great Vibes", "Nanum Pen Script", cursive;
  font-size: 2.5rem;
  line-height: 1.3;
  color: var(--ink);
  margin-bottom: 0;
}

/* 글이 하나씩 나타남 */
.reveal { opacity: 0; transform: translateY(10px); transition: opacity 0.9s ease, transform 0.9s ease; }
.reveal.shown { opacity: 1; transform: none; }

/* ---------- 넘김 버튼 ---------- */
.pager {
  display: flex;
  align-items: center;
  gap: 22px;
  position: relative;
  z-index: 3;
}
.pager[hidden] { display: none; }
.pager-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1.5px solid rgba(176, 96, 122, 0.5);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  font-family: "Cormorant Garamond", serif;
  font-size: 2rem;
  line-height: 1;
  padding-bottom: 4px;
  cursor: pointer;
  transition: opacity 0.3s, background 0.3s;
  -webkit-tap-highlight-color: transparent;
}
.pager-btn:hover { background: #fff; }
.pager-btn:disabled { opacity: 0.25; cursor: default; }
.pager-btn.hint { animation: glow 2s ease-in-out infinite; }
.page-num {
  min-width: 56px;
  text-align: center;
  font-size: 1.15rem;
  letter-spacing: 2px;
  color: var(--ink-soft);
}

/* 꽃잎 & 하트 */
.petals {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 20;
  pointer-events: none;
}

/* ---------- 편지 화면: 모바일 ---------- */
@media (max-width: 760px) {
  .letter-view { padding: 22px 14px 16px; align-items: flex-start; }
  .letter-scene { flex-direction: column; gap: 22px; width: 100%; }
  .photos { flex-direction: row; justify-content: center; align-items: flex-start; gap: 4px; }
  .polaroid { width: min(150px, 40vw); padding: 8px 8px 0; }
  .polaroid:nth-child(2) { margin: 18px 0 0 -6px; }
  .polaroid::before { width: 56px; height: 18px; top: -9px; }
  .polaroid figcaption { font-size: 1.3rem; min-height: 38px; padding: 6px 0 8px; }
  .photo-missing { font-size: 1rem; padding: 8px; }
  .letter-col { width: 100%; gap: 14px; }
  .letter-book {
    width: min(100%, 440px);
    height: max(340px, calc(100dvh - 350px));
  }
  .page { padding: 30px 22px 46px; }
  .page-footer { bottom: 12px; }
  .page-inner { font-size: 1.5rem; }
  .page-inner .greeting { font-size: 2.3rem; }
  .page-inner .ending .signature { font-size: 2.1rem; }
}

/* =========================================================
   hover: 올린 것만 살짝 떠올라서 겹친 부분이 구분되게
   ========================================================= */
.page { transition: transform 0.35s ease, box-shadow 0.35s ease; }
.letter-book::before,
.letter-book::after { transition: transform 0.35s ease; }

@media (hover: hover) {
  .polaroid:hover {
    z-index: 5;
    transform: rotate(0deg) scale(1.07);
    box-shadow: 0 22px 44px rgba(90, 40, 30, 0.3);
  }
  .letter-book:hover .page.active:not(.in-next):not(.in-prev) {
    transform: translateY(-6px);
    box-shadow:
      inset 0 0 60px rgba(199, 163, 109, 0.32),
      0 28px 56px rgba(120, 50, 70, 0.28);
  }
  /* 뒤에 겹친 종이도 살짝 벌어짐 */
  .letter-book:hover::before { transform: rotate(3.4deg) translate(10px, 6px); }
  .letter-book:hover::after  { transform: rotate(-2.4deg) translate(-8px, 8px); }
}

/* =========================================================
   카운트다운 아래 문구
   ========================================================= */
.cd-caption {
  margin-top: -14px;
  font-size: 1.15rem;
  font-style: italic;
  letter-spacing: 1px;
  color: var(--ink-soft);
  transition: opacity 0.8s ease;
}
.countdown.done + .cd-caption { opacity: 0; }

/* =========================================================
   엔딩 화면
   ========================================================= */
.ending-view {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  background: rgba(255, 236, 242, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: endingIn 0.9s ease both;
}
.ending-view[hidden] { display: none; }
.ending-view.closing { animation: endingOut 0.5s ease both; }
@keyframes endingIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes endingOut { to { opacity: 0; } }

.ending-title {
  font-family: "Great Vibes", "Nanum Pen Script", cursive;
  font-size: clamp(3.4rem, 9vw, 6.5rem);
  line-height: 1.1;
  color: var(--ink);
  text-shadow: 0 4px 18px rgba(255, 255, 255, 0.9);
  animation: fadeUp 1s ease 0.3s both;
}
.ending-sub {
  font-family: "Caveat", "Nanum Pen Script", cursive;
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  color: var(--ink);
  animation: fadeUp 1s ease 0.9s both;
}
.replay-btn {
  margin-top: 34px;
  font-family: "Cormorant Garamond", serif;
  font-size: 1.15rem;
  letter-spacing: 2px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.75);
  border: 1.5px solid rgba(176, 96, 122, 0.5);
  border-radius: 30px;
  padding: 10px 28px;
  cursor: pointer;
  animation: fadeUp 1s ease 1.6s both;
}
.replay-btn:hover { background: #fff; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* 마지막 장의 다음 버튼은 하트로 */
.pager-btn.to-ending { font-size: 1.3rem; padding-bottom: 0; }

/* 미리보기 이미지 촬영용 (내 컴퓨터에서 ?og 로 열 때만) */
body.og .countdown, body.og .cd-caption, body.og .seal-hit { display: none; }
body.og .subtitle { font-size: 3.6rem; }

/* 키가 작은 휴대폰: 사진을 줄여서 편지지 공간 확보 */
@media (max-width: 760px) and (max-height: 740px) {
  .letter-view { padding-top: 16px; }
  .letter-scene { gap: 14px; }
  .polaroid { width: min(112px, 32vw); padding: 6px 6px 0; }
  .polaroid figcaption { font-size: 1.05rem; min-height: 28px; padding: 4px 0 5px; }
  .polaroid::before { width: 44px; height: 14px; top: -7px; }
  .letter-col { gap: 10px; }
  .letter-book { height: max(280px, calc(100dvh - 270px)); }
}
