/* =============================================================
   APOLOGY CARD CSS — Clean & Complete
   Scene: 680px × 440px
   Letter Card: 420px × 520px
   Envelope: fills scene (680 × 440)
   ============================================================= */

/* =============================================================
   RESET
   ============================================================= */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

img, button, .envelope, .letter-card {
  -webkit-user-drag: none;
  user-select: none;
}

/* =============================================================
   PAGE
   overflow: hidden clips the letter card that initially
   extends below the envelope, and also clips the envelope
   as it slides off-screen downward.
   ============================================================= */
body {
  min-height: 100vh;
  background-color: #f5ebe5;
  font-family: 'Lato', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}

/* =============================================================
   SCENE
   Sized to match the envelope exactly. The letter card is
   taller (520px) and 'overflows' below — hidden by body
   overflow until it peeks up on click.
   ============================================================= */
.scene {
  position: relative;
  --scene-w: min(92vw, 680px);
  --scene-h: clamp(250px, calc(var(--scene-w) * 0.6470588235), 440px);
  --envelope-h: var(--scene-h);
  --peek-h: clamp(14px, 2.8vw, 24px);
  --card-w: min(88vw, 550px);
  --card-h: min(86vh, 780px);
  width: var(--scene-w);
  height: var(--scene-h);
  animation: sceneIn 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes sceneIn {
  from { opacity: 0; transform: scale(0.9) translateY(18px); }
  to   { opacity: 1; transform: scale(1)   translateY(0);    }
}

/* =============================================================
   LETTER CARD  (z-index: 1 — behind envelope)

   Created by JS on envelope click. Starts at translateY(0):
   top aligned with scene top, extending 160px below scene —
   completely hidden because body clips that overflow.

   .peek adds translateY(-80px): card rises 80px, its top
   peeks 80px above the envelope (and above the scene).
   This 80px gap is well within the viewport so it's visible.
   ============================================================= */
.letter-card {
  position: absolute;
  top: 0;
  left: 50%;
  width: var(--card-w);
  height: var(--card-h);
  background-color: #ffb3c6;
  border-radius: 3px;
  z-index: 1;
  overflow: hidden;
  transform: translateX(-50%) translateY(0);
  /* Keep only envelope-height visible until reveal starts. */
  clip-path: inset(0 0 calc(100% - var(--envelope-h)) 0 round 16px);
  transition:
    transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1),
    clip-path 0.55s ease;
}

.letter-card.peek {
  /* Only a slight top part peeks out while bottom stays clipped. */
  transform: translateX(-50%) translateY(calc(-2 * var(--peek-h)));
}

.letter-card.reveal {
  /* As envelope falls, reveal full card and center it in viewport. */
  transform: translateX(-50%) translateY(calc((var(--envelope-h) - var(--card-h)) / 2));
  clip-path: inset(0 0 0 0 round 16px);
  transition:
    transform 1.1s cubic-bezier(0.4, 0, 0.2, 1),
    clip-path 1.1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =============================================================
   CARD INNER — content wrapper, animated on state transitions
   ============================================================= */
.card-inner {
  width: 100%;
  height: 100%;
  padding: clamp(28px, 7vh, 64px) clamp(16px, 4vw, 28px) clamp(28px, 7vh, 64px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-inner.fade-out {
  animation: cFadeOut 0.2s ease forwards;
}

.card-inner.fade-in {
  animation: cFadeIn 0.28s ease both;
}

@keyframes cFadeOut {
  to { opacity: 0; transform: scale(0.97); }
}

@keyframes cFadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1);    }
}

/* =============================================================
   CARD CONTENT
   ============================================================= */
.card-gif {
  width: 100%;
  height: clamp(160px, 32vw, 220px);
  object-fit: contain;
  border-radius: 2px;
  display: block;
  background-color: rgba(192, 57, 43, 0.07); /* placeholder tint */
  flex-shrink: 0;
}

.card-heading {
  font-family: 'Poppins', sans-serif;
  font-size: clamp(1.9rem, 6.4vw, 3.5rem);
  font-weight: 700;
  line-height: 1.2;
  color: #c0392b;
  text-align: left;
  padding-left: clamp(14px, 5vw, 48px);
  padding-right: clamp(14px, 5vw, 48px);
  max-width: 100%;
  word-break: break-word;
}

/* button group */
.card-btns {
  position: relative;   /* anchor for runaway .btn-no */
  flex: 1;              /* fills remaining card height */
  min-height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding-bottom: 4px;
}

.btn-yes {
  padding: clamp(10px, 2.4vw, 13px) clamp(22px, 6.5vw, 34px);
  background-color: #c0392b;
  color: #ffffff;
  font-family: 'Poppins', sans-serif;
  font-size: clamp(0.95rem, 2.6vw, 1rem);
  font-weight: 700;
  letter-spacing: 0.07em;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.btn-yes:hover {
  background-color: #a93226;
  transform: scale(1.06);
}

.btn-no {
  padding: clamp(7px, 1.9vw, 9px) clamp(16px, 4.8vw, 24px);
  background-color: #ffffff;
  color: #c0392b;
  font-family: 'Poppins', sans-serif;
  font-size: clamp(0.78rem, 2.2vw, 0.85rem);
  font-weight: 600;
  border: 1.5px solid rgba(192, 57, 43, 0.3);
  border-radius: 2px;
  cursor: pointer;
}

/* runaway mode — switched to absolute by JS, moves on hover */
.btn-no.runaway {
  position: absolute;
  transition: top 0.18s ease, left 0.18s ease;
}

.btn-no.pong-no,
.btn-no.evade-no {
  z-index: 25;
  transition: none;
}

.yes-clone {
  position: absolute;
  z-index: 30;
  pointer-events: auto;
  cursor: pointer;
  opacity: 0.95;
  border-radius: 999px;
  box-shadow: 0 6px 14px rgba(192, 57, 43, 0.2);
  animation: yesClonePop 0.26s ease-out both;
}

@keyframes yesClonePop {
  from { transform: translate(-50%, -50%) scale(0.7); opacity: 0.2; }
  to   { transform: translate(-50%, -50%) scale(1); opacity: 0.95; }
}

/* YES response */
.yes-response {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 18px;
  padding: 24px;
  text-align: center;
}

.yes-response .card-gif    { height: clamp(180px, 34vw, 250px); }
.yes-response .card-heading { font-size: clamp(2rem, 6.8vw, 3.5rem); text-align: center; }

/* =============================================================
   ENVELOPE  (z-index: 10 — in front of letter card)
   ============================================================= */
.envelope {
  position: absolute;
  inset: 0;              /* fills the exact 540 × 360 scene */
  background-color: #f04543;
  border-radius: 2px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 22px 60px rgba(180, 60, 55, 0.28),
    0 4px 18px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  user-select: none;
  will-change: transform;
  /* slide-down transition — uses 150vh so it always exits
     the viewport regardless of screen size */
  transition: transform 1.1s cubic-bezier(0.4, 0, 0.2, 1);
}

.envelope.open {
  /* 150vh guarantees the envelope travels past the bottom
     of any viewport height */
  transform: translateY(150vh);
  pointer-events: none;
}

.envelope-text {
  font-family: 'Caveat', cursive;
  font-size: clamp(2.1rem, 6.6vw, 3.8rem);
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.16);
}

/* =============================================================
   MINI POSTAGE STAMP  (top-right corner of envelope)
   ============================================================= */
.mini-stamp {
  position: absolute;
  top: clamp(10px, 2.2vw, 16px);
  right: clamp(10px, 2.6vw, 18px);
  width: clamp(68px, 13vw, 100px);
  height: clamp(68px, 13vw, 100px);
  background-color: #fdf6ee;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  
  /* Rectangular zigzag perforated edge for realistic stamp look */
  clip-path: polygon(
    /* Top edge */
    0% 8%, 5% 4%, 10% 8%, 15% 4%, 20% 8%, 25% 4%, 30% 8%, 35% 4%, 40% 8%, 45% 4%, 50% 8%, 55% 4%, 60% 8%, 65% 4%, 70% 8%, 75% 4%, 80% 8%, 85% 4%, 90% 8%, 95% 4%, 100% 8%,
    /* Right edge */
    96% 15%, 100% 20%, 96% 25%, 100% 30%, 96% 35%, 100% 40%, 96% 45%, 100% 50%, 96% 55%, 100% 60%, 96% 65%, 100% 70%, 96% 75%, 100% 80%, 96% 85%, 100% 90%,
    /* Bottom edge */
    95% 96%, 90% 92%, 85% 96%, 80% 92%, 75% 96%, 70% 92%, 65% 96%, 60% 92%, 55% 96%, 50% 92%, 45% 96%, 40% 92%, 35% 96%, 30% 92%, 25% 96%, 20% 92%, 15% 96%, 10% 92%, 5% 96%, 0% 92%,
    /* Left edge */
    4% 85%, 0% 80%, 4% 75%, 0% 70%, 4% 65%, 0% 60%, 4% 55%, 0% 50%, 4% 45%, 0% 40%, 4% 35%, 0% 30%, 4% 25%, 0% 20%, 4% 15%
  );
}

.mini-stamp .stamp-icon { font-size: 1.6rem; line-height: 1; }

.mini-stamp .stamp-year {
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #c0392b;
}

@media (max-width: 900px) {
  .card-btns {
    min-height: 68px;
  }
}

@media (max-width: 640px) {
  body {
    padding: 10px;
  }

  .scene {
    --scene-w: min(96vw, 560px);
    --card-w: min(92vw, 500px);
    --card-h: min(88vh, 700px);
  }
}

@media (max-height: 760px) {
  .scene {
    --card-h: min(84vh, 680px);
  }
}
