/* =========================================
   BY RASOUL — GIRLS' DAY LETTER
   Main stylesheet
   ========================================= */

/* ---------- Local fonts ---------- */

@font-face {
  font-family: "Vazirmatn";
  src: url("./fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Vazirmatn";
  src: url("./fonts/Vazirmatn-Medium.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Vazirmatn";
  src: url("./fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: "Allura";
  src: url("./fonts/allura-latin-400-normal.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

/* ---------- Design tokens ---------- */

:root {
  color-scheme: light;

  --ivory: #f8f4ec;
  --sand: #e8d5c4;
  --sand-dark: #d9c0ac;
  --dusty-rose: #c98585;
  --blush: #f1e5dc;
  --charcoal: #51483f;
  --muted: #948579;
  --paper: #fffdf8;
  --paper-edge: #ede3d6;

  --shadow-soft:
    0 24px 70px rgba(81, 72, 63, 0.1), 0 5px 18px rgba(81, 72, 63, 0.06);

  --ease-gentle: cubic-bezier(0.22, 0.75, 0.25, 1);
  --ease-envelope: cubic-bezier(0.2, 0.7, 0.2, 1);

  --page-padding: clamp(16px, 5vw, 36px);
}

/* ---------- Reset ---------- */

* {
  box-sizing: border-box;
}

html {
  min-width: 280px;
  min-height: 100%;
  background: var(--ivory);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: clip;
  background-color: var(--ivory);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='132' height='156' viewBox='0 0 132 156'%3E%3Cg fill='none' stroke='%23C98585' stroke-width='0.85' stroke-linecap='round' stroke-linejoin='round' opacity='0.19'%3E%3Cpath d='M25 55 C25 72 27 83 30 99 C33 111 32 120 31 126'/%3E%3Cpath d='M29 91 C17 87 13 79 15 72 C25 74 30 82 29 91Z'/%3E%3Cpath d='M30 104 C41 96 48 98 51 103 C46 111 38 112 30 104Z'/%3E%3Cpath d='M25 66 C17 61 17 55 21 51 C27 55 29 60 25 66Z'/%3E%3Cpath d='M91 124 C91 110 94 100 98 91'/%3E%3Cpath d='M95 105 C83 101 80 94 84 89 C94 92 98 98 95 105Z'/%3E%3Cpath d='M97 95 C105 85 112 87 114 92 C110 99 103 100 97 95Z'/%3E%3C/g%3E%3Cg fill='%23C98585' opacity='0.22'%3E%3Cpath d='M30 42 C20 37 23 28 29 30 C33 22 43 28 40 34 C48 36 43 45 36 43 L33 48Z'/%3E%3Cpath d='M31 37 C28 32 34 29 37 34 C39 38 34 40 31 37Z' fill='%23F8F4EC'/%3E%3Ccircle cx='101' cy='28' r='2'/%3E%3Cpath d='M99 28 l2 -3 l2 3 l-2 3Z'/%3E%3C/g%3E%3C/svg%3E"),
    radial-gradient(
      ellipse at 50% 42%,
      rgba(255, 255, 255, 0.7) 0%,
      rgba(248, 244, 236, 0) 63%
    );
  background-repeat: repeat, no-repeat;
  background-size:
    132px 156px,
    auto;

  color: var(--charcoal);
  font-family: "Vazirmatn", Tahoma, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(201, 133, 133, 0.8);
  outline-offset: 6px;
}

/* ---------- Main layout ---------- */

.page {
  min-height: 100vh;
  min-height: 100svh;
  padding: max(24px, env(safe-area-inset-top)) var(--page-padding)
    max(20px, env(safe-area-inset-bottom));

  display: flex;
  align-items: center;
  justify-content: center;
}

.experience {
  width: 100%;
  max-width: 760px;
  min-width: 0;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.intro {
  width: 100%;
  text-align: center;
  position: relative;
  z-index: 10;
  margin-bottom: 2px;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--dusty-rose);
  font-family: Georgia, serif;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 3px;
  line-height: 1.7;
  direction: ltr;
}

.invitation {
  max-width: 520px;
  margin: 0 auto;
  font-size: clamp(19px, 3.2vw, 25px);
  line-height: 1.9;
  font-weight: 500;
  letter-spacing: -0.3px;
  text-wrap: balance;
}

.instruction {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: clamp(12px, 2.6vw, 13px);
  line-height: 1.9;
  transition:
    opacity 450ms ease,
    transform 450ms ease;
}

.experience.is-open .instruction {
  opacity: 0;
  transform: translateY(-5px);
  pointer-events: none;
}

/* ---------- Envelope scene ---------- */

.scene {
  position: relative;
  width: min(100%, 460px);

  /* Reduced height brings the envelope closer to the heading */
  height: clamp(330px, 48svh, 440px);
  min-height: 330px;

  isolation: isolate;
  overflow: visible;
  perspective: 1200px;
}

/* ---------- Envelope group ---------- */

.envelope-group {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  width: min(86%, 360px);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.envelope-instruction {
  width: 100%;
  margin: 0 0 14px;
  font-family: "Vazirmatn", Tahoma, sans-serif;
  font-size: clamp(14px, 3.8vw, 16px);
  font-weight: 500;
  line-height: 1.9;
  color: #51483f;
  text-align: center;
  opacity: 1;
}

.envelope-button {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  padding: 0;
  background: transparent;

  position: relative;
  width: 100%;
  aspect-ratio: 1.48;
  flex-shrink: 0;

  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;

  transition:
    transform 700ms var(--ease-gentle),
    opacity 600ms ease;
}

.envelope-button:active {
  transform: scale(0.985);
}

.envelope {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: 4px 4px 8px 8px;
  filter: drop-shadow(0 16px 18px rgba(81, 72, 63, 0.12));
  transform-style: preserve-3d;
}

.envelope-back {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #ebd9c9;
  border-radius: 4px 4px 8px 8px;
  box-shadow: inset 0 0 0 1px rgba(120, 92, 72, 0.08);
}

/* The small piece of paper visible inside the envelope */

.envelope-letter-peek {
  position: absolute;
  z-index: 1;
  left: 8%;
  right: 8%;
  top: 5%;
  bottom: 7%;
  border-radius: 3px;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 25px,
      rgba(160, 139, 117, 0.08) 26px,
      transparent 27px
    ),
    var(--paper);
  transform: translateY(0);
  transition: transform 1000ms var(--ease-envelope);
}

/* Envelope front */

.envelope-front {
  position: absolute;
  z-index: 3;
  inset: 0;
  overflow: hidden;
  border-radius: 4px 4px 8px 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.13), transparent 54%),
    var(--sand);
}

.envelope-front::before,
.envelope-front::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.envelope-front::before {
  background:
    linear-gradient(
      32deg,
      transparent 49.6%,
      rgba(159, 123, 97, 0.13) 50%,
      transparent 50.5%
    ),
    linear-gradient(
      -32deg,
      transparent 49.6%,
      rgba(159, 123, 97, 0.13) 50%,
      transparent 50.5%
    );
}

.envelope-front::after {
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.1),
    transparent 65%
  );
}

/* Envelope flap */

.envelope-flap {
  position: absolute;
  z-index: 4;
  left: 0;
  right: 0;
  top: 0;
  height: 58%;
  background: #e3cdbb;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transform: rotateX(0deg);
  backface-visibility: visible;
  transition:
    transform 900ms var(--ease-envelope),
    filter 900ms ease;
  filter: brightness(1);
}

/* Small heart pressed into the envelope */

.envelope-seal {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 47%;
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--dusty-rose);
  background: rgba(255, 253, 248, 0.35);
  border: 1px solid rgba(201, 133, 133, 0.18);
  box-shadow:
    0 2px 3px rgba(81, 72, 63, 0.04),
    inset 0 1px 1px rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
  transition:
    opacity 350ms ease,
    transform 550ms var(--ease-gentle);
}

.heart-icon {
  width: 13px;
  height: 13px;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.5));
}

/* ---------- Letter / paper ---------- */

.letter {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 12%;
  width: min(90%, 390px);
  max-height: min(68svh, 510px);
  min-height: 300px;

  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(201, 133, 133, 0.35) transparent;

  background:
    linear-gradient(
      90deg,
      rgba(184, 157, 128, 0.035),
      transparent 10%,
      transparent 90%,
      rgba(184, 157, 128, 0.035)
    ),
    var(--paper);

  border: 1px solid rgba(177, 151, 126, 0.23);
  border-radius: 3px;
  box-shadow: var(--shadow-soft);

  opacity: 0;
  visibility: hidden;
  pointer-events: none;

  transform: translate(-50%, 45%) scale(0.88);
  transform-origin: center bottom;

  transition:
    transform 1050ms var(--ease-envelope),
    opacity 650ms ease,
    visibility 0s linear 1050ms;

  -webkit-overflow-scrolling: touch;
}

.letter::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(192, 166, 139, 0.15);
  pointer-events: none;
}

.paper-grain {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.2;
  pointer-events: none;
  background-image:
    radial-gradient(
      circle at 20% 30%,
      rgba(128, 104, 79, 0.12) 0 0.5px,
      transparent 0.9px
    ),
    radial-gradient(
      circle at 70% 60%,
      rgba(128, 104, 79, 0.09) 0 0.5px,
      transparent 0.9px
    );
  background-size:
    9px 11px,
    13px 15px;
}

.letter-inner {
  position: relative;
  z-index: 1;
  min-height: 100%;
  padding: clamp(24px, 5.5vw, 34px);
  display: flex;
  flex-direction: column;
}

.letter-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(177, 151, 126, 0.2);
}

.letter-label {
  direction: ltr;
  font-family: Georgia, serif;
  color: #b7a493;
  font-size: 9px;
  letter-spacing: 2px;
  line-height: 1.8;
}

.letter-date {
  color: var(--dusty-rose);
  font-size: 17px;
  line-height: 1;
}

.letter-content {
  min-width: 0;
  min-height: 170px;
  padding-block: 23px 16px;
  color: var(--charcoal);
  font-family: "Vazirmatn", Tahoma, sans-serif;
  font-size: clamp(14px, 3.6vw, 16px);
  font-weight: 400;
  line-height: 2.25;
  letter-spacing: -0.1px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  text-align: right;
}

/* The cursor is hidden by default and only used while typing */

.letter-content.is-typing::after {
  content: "";
  display: inline-block;
  width: 1px;
  height: 1.05em;
  margin-inline-start: 3px;
  vertical-align: -0.12em;
  background: var(--dusty-rose);
  animation: cursorBlink 900ms step-end infinite;
}

.signature-wrap {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  min-height: 48px;
  margin-top: auto;
  padding-top: 4px;
  direction: ltr;
}

.signature {
  display: inline-block;
  color: var(--dusty-rose);
  font-family: "Allura", cursive;
  font-size: clamp(31px, 8vw, 38px);
  font-weight: 400;
  line-height: 1.3;
  white-space: nowrap;

  opacity: 0.08;
  filter: blur(1.5px);
  transform: translateY(3px);

  transition:
    opacity 900ms ease,
    filter 900ms ease,
    transform 900ms var(--ease-gentle);
}

.signature-wrap.is-revealed .signature {
  opacity: 1;
  filter: blur(0);
  transform: translateY(0);
}

.letter-bottom {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
  color: #d8b4a8;
}

.letter-bottom > span:not(.bottom-heart) {
  width: 35px;
  height: 1px;
  background: rgba(201, 133, 133, 0.28);
}

.bottom-heart {
  font-size: 11px;
  line-height: 1;
}

/* ---------- Open state ---------- */

.experience.is-open .envelope-button {
  cursor: default;
  transform: translateY(20px);
}

.experience.is-open .envelope-flap {
  transform: rotateX(180deg);
  filter: brightness(0.97);
}

.experience.is-open .envelope-letter-peek {
  transform: translateY(-16%);
}

.experience.is-open .envelope-seal {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.65);
}

.experience.is-open .letter {
  z-index: 8;
  top: 0;
  bottom: auto;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;

  transform: translate(-50%, 0) scale(1);

  transition:
    top 1050ms var(--ease-envelope),
    transform 1050ms var(--ease-envelope),
    opacity 650ms ease,
    visibility 0s;
}

/* ---------- Footer ---------- */

.page-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  margin-top: 2px;
  color: #b1a294;
  position: relative;
  z-index: 9;
  transition:
  opacity 350ms ease,
  transform 350ms ease,
  visibility 0s linear 0s;
}

.page-footer p {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 11px;
  letter-spacing: 1.2px;
  direction: ltr;
}

.footer-line {
  width: 29px;
  height: 1px;
  background: rgba(177, 151, 126, 0.35);
}

.footer-line {
  width: 25px;
  height: 1px;
  background: rgba(177, 151, 126, 0.35);
}

.experience.is-open .page-footer {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px);

  transition:
    opacity 250ms ease,
    transform 250ms ease,
    visibility 0s linear 250ms;
}

/* ---------- No JavaScript message ---------- */

.noscript-message {
  max-width: 420px;
  margin: 20px auto 0;
  color: var(--charcoal);
  text-align: center;
  font-size: 14px;
  line-height: 2;
}

/* ---------- Animations ---------- */

@keyframes cursorBlink {
  0%,
  48% {
    opacity: 1;
  }

  49%,
  100% {
    opacity: 0;
  }
}

/* ---------- Tablet and desktop ---------- */

@media (min-width: 600px) {
  .intro {
    margin-bottom: 0;
  }

  .scene {
    height: clamp(390px, 55svh, 500px);
    min-height: 390px;
  }

  .envelope-group {
    width: min(78%, 360px);
    bottom: 12%;
  }

  .envelope-button {
    width: 100%;
  }

  .letter {
    width: min(86%, 390px);
    max-height: min(66svh, 520px);
  }

  .letter-content {
    font-size: 16px;
    line-height: 2.35;
  }
}

/* ---------- Small phones ---------- */

@media (max-width: 380px) {
  :root {
    --page-padding: 14px;
  }

  .page {
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  .eyebrow {
    font-size: 10px;
    letter-spacing: 2.4px;
    margin-bottom: 9px;
  }

  .invitation {
    font-size: clamp(17px, 5vw, 19px);
    line-height: 1.8;
  }

  .instruction {
    font-size: 12px;
    margin-top: 5px;
  }

  .scene {
    height: clamp(310px, 43svh, 370px);
    min-height: 310px;
  }

  .envelope-group {
    width: 90%;
    bottom: 11%;
  }

  .envelope-button {
    width: 100%;
  }

  .letter {
    width: 94%;
    min-height: 280px;
    max-height: 66svh;
    bottom: 10%;
  }

  .letter-inner {
    padding: 22px 20px;
  }

  .letter-content {
    min-height: 145px;
    padding-top: 18px;
    font-size: 14px;
    line-height: 2.1;
  }

  .letter-label {
    font-size: 8px;
    letter-spacing: 1.5px;
  }

  .signature {
    font-size: 32px;
  }

  .letter-bottom {
    margin-top: 18px;
  }
}

/* ---------- Short screens / landscape phones ---------- */

@media (max-height: 620px) {
  .page {
    align-items: flex-start;
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .intro {
    margin-bottom: 0;
  }

  .eyebrow {
    margin-bottom: 5px;
  }

  .invitation {
    font-size: clamp(16px, 2.8vw, 21px);
    line-height: 1.6;
  }

  .instruction {
    margin-top: 2px;
  }

  .scene {
    height: 300px;
    min-height: 300px;
  }

  .envelope-group {
    bottom: 10%;
  }

  .envelope-button {
    width: 100%;
  }

  .letter {
    max-height: 65svh;
    min-height: 270px;
  }

  .experience.is-open .letter {
    max-height: 58svh;
    min-height: 0;
  }

  .experience.is-open .envelope-button {
    transform: translateY(8px);
  }

  .page-footer {
    margin-top: 0;
  }
}

/* ---------- Return letter button ---------- */

.return-letter-button {
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;

  margin-top: 18px;
  padding: 9px 16px;

  border: 1px solid rgba(201, 133, 133, 0.28);
  border-radius: 999px;
  background: rgba(241, 229, 220, 0.48);

  color: var(--muted);
  font-family: "Vazirmatn", Tahoma, sans-serif;
  font-size: 12px;
  line-height: 1.8;

  cursor: pointer;
  -webkit-tap-highlight-color: transparent;

  transition:
    background 250ms ease,
    border-color 250ms ease,
    color 250ms ease,
    transform 250ms ease;
}

.return-letter-button:hover {
  background: var(--blush);
  border-color: rgba(201, 133, 133, 0.55);
  color: var(--charcoal);
}

.return-letter-button:active {
  transform: scale(0.97);
}

/* ---------- Minimal return-letter icon ---------- */

.return-letter-button {
  align-self: center;
  display: inline-grid;
  place-items: center;

  width: 44px;
  height: 44px;
  margin: 14px auto 0;
  padding: 0;

  border: 0;
  border-radius: 50%;
  background: transparent;

  color: var(--dusty-rose);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;

  transition:
    color 220ms ease,
    transform 220ms ease,
    opacity 220ms ease;
}

.return-letter-icon {
  display: block;
  width: 21px;
  height: 21px;
  overflow: visible;
  pointer-events: none;
}

.return-letter-button:hover {
  color: var(--charcoal);
  transform: translateY(-1px);
}

.return-letter-button:active {
  transform: scale(0.88);
}

.return-letter-button:focus-visible {
  outline: 2px solid rgba(201, 133, 133, 0.75);
  outline-offset: 2px;
}

/* ---------- Closing animation ---------- */

.experience.is-closing .letter {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 45%) scale(0.88);

  transition:
    transform 850ms var(--ease-envelope),
    opacity 500ms ease,
    visibility 0s linear 850ms;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .return-letter-button {
    transition: none;
  }
}

/* ---------- Reduced motion accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
