/* 나의 엄마에게 — 봉투가 열리고, 편지지가 나오고, 글씨가 떠오르는 애니메이션
   순서와 시간은 letter-animation.js 가 맡고, 여기에는 각 장면의 모양만 적습니다.
   --intro-t : 봉투 장면 빠르기 배수 (letter-content.js 의 envelopeSeconds 로 정해짐)
   --line-dur: 글씨 한 줄이 떠오르는 시간 (letter-content.js 의 lineDuration) */
:root { --intro-t: 1; --line-dur: 1.1s; }

/* style.css 의 기본 등장 효과 대신 아래 paper-rise 를 씁니다 */
.postcard { animation: none; }

/* ── 1. 봉투 장면 (화면 전체를 덮는 막) ───────────────────── */
.intro { display: none; }
html.has-intro { overflow: hidden; }
html.has-intro .intro {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 40;
  display: grid; place-items: center;
  background: var(--paper);
  transition: opacity calc(.9s * var(--intro-t)) ease;
  /* 스크립트가 멈춰도 편지를 볼 수 있도록, 한참 뒤에는 스스로 걷힙니다 */
  animation: intro-failsafe .6s 14s forwards;
}
@keyframes intro-failsafe { to { opacity: 0; visibility: hidden; } }

.intro-stage {
  position: relative; width: 74vw; width: min(74vw, 340px); aspect-ratio: 3 / 2; margin-top: 14vh;
  filter: drop-shadow(0 18px 20px rgba(120, 50, 60, .26));
  animation: intro-in calc(.6s * var(--intro-t)) ease-out both;
}
@keyframes intro-in { from { opacity: 0; transform: translateY(18px); } }

.intro-stage > * { position: absolute; }
.intro-back, .intro-front, .intro-flap {
  transition: translate calc(.8s * var(--intro-t)) ease-in, transform calc(.8s * var(--intro-t)) ease-in, opacity calc(.7s * var(--intro-t)) ease;
}
/* aspect-ratio 를 모르는 예전 휴대폰(iOS 14 이하)에서도 봉투 높이가 잡히도록 */
@supports not (aspect-ratio: 1 / 1) {
  .intro-stage { height: 49.33vw; height: calc(min(74vw, 340px) * 2 / 3); }
}

/* 봉투 안쪽 */
.intro-back { top: 0; right: 0; bottom: 0; left: 0; z-index: 1; background: #dc9fab; border-radius: 6px; }

/* 봉투 속 편지지 */
.intro-paper {
  left: 7%; right: 7%; top: 7%; height: 90%; z-index: 2;
  background:
    repeating-linear-gradient(to bottom, transparent 0, transparent 21px, #e2d6d1 21px, #e2d6d1 22px) 0 46px / 100% 100% no-repeat,
    #fffaf8;
  border-radius: 2px; box-shadow: 0 2px 8px -3px rgba(90, 40, 40, .5);
  padding: 8px 16px; overflow: hidden;
  font-family: var(--font-hand); font-size: 26px; line-height: 1.3; color: var(--rose-deep); white-space: nowrap;
  transition: transform calc(1.2s * var(--intro-t)) cubic-bezier(.3, .1, .2, 1), opacity calc(.8s * var(--intro-t)) ease;
}

/* 봉투 앞면 (편지지를 가리는 주머니) */
.intro-front { top: 0; right: 0; bottom: 0; left: 0; z-index: 3; }
.intro-front::before, .intro-front::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; }
.intro-front::before { background: #ecb5be; clip-path: polygon(0 0, 50% 57%, 100% 0, 100% 100%, 0 100%); }
.intro-front::after { background: #e6a8b3; clip-path: polygon(0 100%, 50% 45%, 100% 100%); }

/* 봉투 뚜껑 */
.intro-flap {
  top: 0; left: 0; right: 0; height: 61%; z-index: 4;
  transform-origin: top center;
  filter: drop-shadow(0 2px 2px rgba(120, 50, 60, .22));
}
.intro-flap i { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: #f0c3ca; clip-path: polygon(0 0, 100% 0, 50% 100%); }

/* 하트 봉인 */
.intro-seal {
  left: 50%; top: 61%; z-index: 5; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  border-radius: 50%; background: var(--rose); color: #fff; display: grid; place-items: center;
  box-shadow: 0 3px 6px -2px rgba(120, 40, 60, .6);
  transition: opacity calc(.35s * var(--intro-t)) ease, transform calc(.35s * var(--intro-t)) ease;
}
.intro-seal svg { width: 20px; height: 20px; }

.intro-skip {
  position: absolute; left: 50%; bottom: max(28px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  font: inherit; font-size: 14px; color: var(--ink-soft); background: none; border: 0; padding: 10px 16px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--line);
}
.intro-skip:hover { color: var(--rose-deep); }

/* 장면 ① 봉인이 풀리고 뚜껑이 열린다 */
.intro.is-open .intro-seal { opacity: 0; transform: scale(1.35); }
.intro.is-open .intro-flap { animation: flap-open calc(.9s * var(--intro-t)) ease-in-out forwards; }
.intro.is-open .intro-flap i { animation: flap-face calc(.9s * var(--intro-t)) ease-in-out forwards; }
@keyframes flap-open {
  0% { transform: perspective(900px) rotateX(0); z-index: 4; }
  50% { z-index: 4; }
  50.01% { z-index: 1; }   /* 뚜껑이 세워진 순간 편지지 뒤로 넘어갑니다 */
  100% { transform: perspective(900px) rotateX(180deg); z-index: 1; }
}
@keyframes flap-face { 0%, 50% { background: #f0c3ca; } 50.01%, 100% { background: #e3a9b4; } }

/* 장면 ② 편지지가 봉투에서 올라온다 */
.intro.is-out .intro-paper { transform: translateY(-58%); }

/* 장면 ③ 편지지가 다가오며 실제 편지로 바뀌고, 봉투는 아래로 물러난다 */
.intro.is-leaving { opacity: 0; pointer-events: none; }
.intro.is-leaving .intro-paper { transform: translateY(-34%) scale(2.3); opacity: 0; transition-timing-function: ease-in; }
.intro.is-leaving .intro-back,
.intro.is-leaving .intro-front { transform: translateY(45%); opacity: 0; }
.intro.is-leaving .intro-flap { translate: 0 45%; opacity: 0; }   /* 뚜껑은 transform 을 여는 동작에 쓰고 있어 translate 로 내립니다 */
.intro.is-leaving .intro-skip { opacity: 0; }

/* ── 2. 실제 편지지가 자리 잡는다 ─────────────────────────── */
html.has-intro .postcard { opacity: 0; }
html.intro-reveal .postcard { animation: paper-rise calc(1.2s * var(--intro-t)) cubic-bezier(.2, .7, .2, 1) both; }
@keyframes paper-rise { from { opacity: 0; transform: translateY(70px) scale(.97); } to { opacity: 1; transform: none; } }

/* ── 3. 글씨가 한 줄씩 떠오른다 ───────────────────────────── */
.postcard .w { display: inline-block; }
html.writing .postcard .w { opacity: 0; transform: translateY(.6em); }
html.writing .postcard .w.on {
  opacity: 1; transform: none;
  transition: opacity var(--line-dur) ease, transform var(--line-dur) cubic-bezier(.2, .7, .2, 1);
}

/* 편지 내용을 읽지 못했을 때 보이는 안내 */
.letter-error { font-family: var(--font-body); font-size: 15px; line-height: 1.7; color: var(--rose-deep); background: #fff; border: 1px dashed var(--rose); border-radius: 8px; padding: 12px 14px; }

@media (max-width: 640px) {
  .intro-stage { width: min(78vw, 300px); margin-top: 10vh; }
  .intro-paper { font-size: 23px; }
}

/* 휴대폰을 가로로 눕혔을 때: 화면 높이가 낮으니 봉투를 줄이고, 건너뛰기는 구석으로 옮깁니다 */
@media (max-height: 500px) and (orientation: landscape) {
  .intro-stage { width: min(74vw, 340px, 60vh); margin-top: 26vh; }
  .intro-paper { font-size: 20px; padding: 6px 12px; }
  .intro-seal { width: 36px; height: 36px; margin: -18px 0 0 -18px; }
  .intro-skip { left: auto; right: max(12px, env(safe-area-inset-right)); bottom: 8px; transform: none; }
  @supports not (aspect-ratio: 1 / 1) {
    .intro-stage { height: calc(min(74vw, 340px, 60vh) * 2 / 3); }
  }
}
