/* ==========================================================================
   Act 3: Letter Reading Paper & Comfortable Mobile Typography
   ========================================================================== */

.scene--letter {
  z-index: var(--z-letter);
  display: flex;
  justify-content: center;
  align-items: stretch;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.scene--letter.is-active {
  visibility: visible;
  pointer-events: auto;
}

.letter-scroll {
  position: relative;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: calc(56px + var(--safe-top)) calc(14px + var(--safe-right))
    calc(56px + var(--safe-bottom)) calc(14px + var(--safe-left));
}

.letter-scroll::-webkit-scrollbar {
  width: 4px;
}

.letter-scroll::-webkit-scrollbar-thumb {
  background: rgba(154, 134, 110, 0.25);
  border-radius: 4px;
}

.letter-sheet {
  position: relative;
  width: min(92vw, 560px);
  min-height: calc(var(--app-h) - 110px);
  background: linear-gradient(180deg, #FDFBF7 0%, #FAF5EC 58%, #F8F1E5 100%);
  border-radius: 6px;
  border: 1px solid rgba(198, 180, 152, 0.34);
  box-shadow:
    0 22px 54px -18px rgba(78, 60, 42, 0.22),
    0 4px 14px rgba(78, 60, 42, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.85);
  overflow: hidden;
  transform-origin: center top;
  will-change: transform, opacity;
  user-select: text;
  -webkit-user-select: text;
}

.letter-paper-texture {
  position: absolute;
  inset: 0;
  background-image: url("../assets/textures/paper-grain.svg");
  background-repeat: repeat;
  background-size: 240px 240px;
  opacity: 0.55;
  pointer-events: none;
}

/* Delicate inner hairline border for stationery refinement */
.letter-sheet::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(196, 178, 150, 0.22);
  border-radius: 3px;
  pointer-events: none;
}

.letter-inner {
  position: relative;
  z-index: 1;
  padding: clamp(32px, 8vw, 52px) clamp(24px, 7vw, 46px) clamp(36px, 8vw, 54px);
}

.letter-header {
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.letter-header:empty,
.letter-salutation:empty,
.letter-title:empty {
  display: none;
}

.letter-salutation {
  margin: 0;
  font-size: clamp(17.5px, 4.7vw, 21px);
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0.08em;
  color: var(--ink-primary);
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(190, 168, 138, 0.32);
  align-self: flex-start;
  padding-right: 14px;
}

.letter-title {
  margin: 4px 0 0;
  font-size: clamp(18px, 4.9vw, 22px);
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0.1em;
  color: var(--ink-secondary);
}

.letter-body {
  display: flex;
  flex-direction: column;
  gap: 1.15em;
}

.letter-paragraph {
  margin: 0;
  font-size: clamp(15.5px, 4.1vw, 17px);
  line-height: 1.95;
  letter-spacing: 0.04em;
  color: var(--ink-primary);
  text-indent: 2em;
  word-break: break-word;
  overflow-wrap: break-word;
}

.char-unit {
  display: inline;
  opacity: 0;
  transition: opacity 0.36s cubic-bezier(0.22, 1, 0.36, 1);
}

.char-unit.is-shown {
  opacity: 1;
}

.letter-paragraph--placeholder {
  text-indent: 0;
  text-align: center;
  color: var(--ink-muted);
  font-size: 14px;
  padding: 28px 0;
  letter-spacing: 0.08em;
}

.letter-signoff {
  margin-top: 34px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.letter-signoff.is-empty {
  display: none;
}

/* Casually taped tilted printed photos attached below the letter text */
.letter-snapshots {
  margin: 34px 0 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px 18px;
  align-items: center;
  justify-items: center;
  padding: 10px 4px 12px;
}

.letter-snapshots.is-empty {
  display: none;
}

.snapshot-card {
  position: relative;
  width: min(100%, 195px);
  padding: 7px 7px 22px;
  background: #FEFDF9;
  border-radius: 2px;
  border: 1px solid rgba(196, 180, 156, 0.42);
  box-shadow:
    0 10px 22px -10px rgba(72, 54, 34, 0.28),
    0 2px 6px rgba(72, 54, 34, 0.1);
  transform: translate3d(0, 16px, 0) rotate(var(--snap-rot, 0deg)) scale(0.95);
  opacity: 0;
  transition:
    opacity 0.78s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.78s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform, opacity;
}

.snapshot-card.is-revealed {
  opacity: 1;
  transform: translate3d(var(--snap-ox, 0px), var(--snap-oy, 0px), 0) rotate(var(--snap-rot, 0deg)) scale(1);
}

/* Semi-translucent warm washi tape holding the tilted photo onto the letter paper */
.snapshot-card::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 50%;
  width: 54px;
  height: 18px;
  transform: translateX(-50%) rotate(var(--tape-rot, -3deg));
  background: linear-gradient(
    90deg,
    rgba(234, 218, 192, 0.68) 0%,
    rgba(244, 232, 210, 0.82) 50%,
    rgba(232, 214, 186, 0.66) 100%
  );
  border-left: 1px dashed rgba(178, 154, 122, 0.35);
  border-right: 1px dashed rgba(178, 154, 122, 0.35);
  box-shadow: 0 1px 3px rgba(96, 76, 52, 0.12);
  pointer-events: none;
  z-index: 2;
}

.snapshot-frame {
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #EFE7DA;
  border-radius: 1px;
}

.snapshot-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 38%;
  display: block;
  pointer-events: none;
}

.letter-signature {
  margin: 0;
  font-size: clamp(15.5px, 4vw, 17px);
  letter-spacing: 0.14em;
  color: var(--ink-primary);
}

.letter-date {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
}

.letter-signature:empty,
.letter-date:empty {
  display: none;
}

/* Action button at the end of the letter (below dual filmstrip) */
.letter-action {
  margin-top: 34px;
  display: flex;
  justify-content: center;
  opacity: 0;
  transform: translate3d(0, 12px, 0);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.letter-action.is-revealed {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.send-letter-btn {
  position: relative;
  min-width: 176px;
  min-height: 48px;
  padding: 12px 34px 11px;
  border-radius: 999px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0.2em;
  color: var(--ink-primary);
  background: linear-gradient(180deg, #FBF6EC 0%, #F1E5D2 100%);
  border: 1px solid rgba(186, 160, 126, 0.56);
  box-shadow:
    0 8px 22px -8px rgba(96, 74, 48, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  transition: transform 0.28s ease, box-shadow 0.28s ease, background-color 0.28s ease;
}

.send-letter-btn:active {
  transform: scale(0.96);
  box-shadow: 0 4px 12px -4px rgba(96, 74, 48, 0.2);
}

.send-letter-btn__text {
  padding-left: 0.2em; /* optical balance for letter-spacing */
}

.send-letter-btn__line {
  width: 24px;
  height: 1px;
  background: rgba(164, 134, 98, 0.48);
  transition: width 0.35s ease;
}

/* Soft bottom fade hint matching starry night backdrop */
.letter-scroll-fade {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(52px + var(--safe-bottom));
  background: linear-gradient(to top, rgba(10, 17, 36, 0.72) 0%, rgba(10, 17, 36, 0) 100%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s ease;
}

.letter-scroll-fade.is-visible {
  opacity: 1;
}

@media (max-width: 375px) {
  .letter-inner {
    padding: 28px 22px 34px;
  }
  .letter-sheet::after {
    inset: 9px;
  }
}
