/* ═══════════════════════════════════════════
   Song We Sang / Letter Page
   ═══════════════════════════════════════════ */

/* ── Brittany Signature (self-hosted) ── */
@font-face {
  font-family: 'Brittany Signature';
  src: url('../fonts/BrittanySignature.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* ── Page shell ── */
html.sws-page,
html.sws-page body {
  overflow-x: hidden;
  overflow-y: auto;
  max-width: 100vw;
  background: var(--bg-primary);
}

.sws-page-body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-height: 100vh;
  background: var(--bg-primary);
  color: var(--text-primary, #f4f4f6);
  overflow-x: hidden;
}

/* ── Top nav ── */
.sws-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.sws-nav__back,
.sws-nav__replay {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-muted, #8a8e9a);
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.2s ease, color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

.sws-nav__back:hover,
.sws-nav__back:focus-visible,
.sws-nav__replay:hover,
.sws-nav__replay:focus-visible {
  color: var(--text-primary, #f4f4f6);
  background: var(--border-subtle);
  outline: none;
}

.sws-nav__replay.is-playing svg {
  animation: swsReplaySpin 0.6s ease;
}

@keyframes swsReplaySpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.sws-nav__title-wrap {
  text-align: center;
  line-height: 1.2;
}

.sws-nav__title {
  margin: 0;
  font-family: var(--font-sans, Inter, sans-serif);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-primary, #f4f4f6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sws-nav__subtitle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 3px 0 0;
}

.sws-nav__line {
  flex: 1;
  max-width: 28px;
  height: 1px;
  background: var(--text-muted, #8a8e9a);
  opacity: 0.55;
  display: block;
}

.sws-nav__subtitle-text {
  font-family: var(--font-sans, Inter, sans-serif);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted, #8a8e9a);
  white-space: nowrap;
}

/* ── Main content area ── */
.sws-main {
  flex: 1 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px 12px 12px;
  box-sizing: border-box;
  overflow-x: hidden;
}

/* ── Paper wrap: image + text overlay together ── */
.sws-paper-wrap {
  position: relative;   /* text overlay is absolute inside this */
  width: 100%;
  max-width: 480px;
  border-radius: 8px;
  /* Keep rounded clip on the image; do not clip signature underline/heart. */
  overflow: visible;
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.7),
    0 2px 8px rgba(0, 0, 0, 0.5);
  /* establish a formatting context so % sizing works for children */
  display: block;
}

.sws-paper-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  /* image is the sizing reference — text overlays on top */
}

/* ── Letter text overlay (absolutely positioned over the image) ──
   Image is 1024×1536 (aspect ratio 2:3).
   Writing area starts at approx 19% from top, left/right margins ~13%.
   Closing/signature sit around 82–90% from top.
   These % values scale perfectly as the image scales. */
.sws-letter {
  position: absolute;
  top: 45px;
  left: 13%;
  right: 13%;
  bottom: 8%;
  overflow: visible;
  color: #2a1f0e;          /* dark ink colour that reads on the parchment */
  /* No background — text sits directly on the image */
}

/* ── Per-segment typography ── */

/* 1. "Dear John," — Brittany Signature 32px */
.sws-letter__greeting {
  margin: 0 0 0.45em;
  padding: 0.18em 0 0.22em;
  font-family: 'Brittany Signature', cursive;
  font-size: 15px;
  font-weight: normal;
  font-style: normal;
  line-height: 1.45;
  overflow: visible;
  color: #2a1f0e;
}

/* 2. Main body paragraphs — Special Elite 15px */
.sws-letter__p {
  margin: 0 0 0.80em;
  padding: 0;
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 8px;
  font-weight: 400;
  line-height: 1.55;
  color: #2a1f0e;
}

/* 3. Short standalone lines (Different countries. etc.) — same as body */
.sws-letter__line {
  margin: 0 0 0.15em;
  padding: 0;
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 8px;
  font-weight: 400;
  line-height: 1.45;
  color: #2a1f0e;
}

/* 4. Emphasis / bold phrases */
.sws-letter__emphasis {
  margin: 0.4em 0;
  padding: 0;
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 8px;
  font-weight: 400;   /* Special Elite has no bold; italic adds weight */
  line-height: 1.55;
  color: #1a110a;
}

.sws-letter__emphasis em {
  font-style: italic;
  font-weight: 400;
  color: #1a110a;
}

/* 5. "With love and gratitude," — Caveat 20px */
.sws-letter__closing {
  margin: 0.85em 0 0.95em;
  padding: 0;
  font-family: 'Caveat', cursive;
  font-size: 10px;
  font-weight: 400;
  line-height: 1.3;
  color: #2a1f0e;
}

/* 6. "The World We Live In" — Brittany Signature 30px */
.sws-letter__signature {
  margin: 0.7em 0 0;
  padding: 0;
  font-family: 'Brittany Signature', cursive;
  font-size: 20px;
  font-weight: normal;
  font-style: normal;
  line-height: 1.15;
  color: #2a1f0e;
  transform: rotate(-2.5deg);
  transform-origin: left center;
  overflow: visible;
}

.sws-letter__signature span {
  font-family: 'Brittany Signature', cursive;
  font-weight: normal;
  font-style: normal;
  display: inline-block;
}

.sws-letter__flourish {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 2.1em;
  /* Clear of Brittany descenders so the ink line stays visible */
  margin-top: 6px;
  overflow: visible;
  pointer-events: none;
}

.sws-letter__underline,
.sws-letter__heart {
  fill: none;
  stroke: #2a1f0e;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 1;
}

.sws-letter__underline {
  /* Subtle hand-ink stroke (SVG user units, scales with viewBox) */
  stroke-width: 0.75;
}

.sws-letter__heart {
  stroke-width: 0.7;
}

/* ── Stamp (bottom-right of paper) ── */
.sws-stamp {
  position: absolute;
  right: calc(7% + 10px);
  bottom: 6.5%;
  z-index: 3;
  width: 45px;
  height: 42px;
  object-fit: contain;
  opacity: 0;
  transform: scale(1.2) rotate(-1.5deg);
  transform-origin: center center;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform, opacity;
}

.sws-stamp.is-stamping {
  animation: swsStampPress 400ms cubic-bezier(0.16, 0.84, 0.24, 1) forwards;
}

.sws-stamp.is-stamped {
  opacity: 1;
  transform: scale(1) rotate(-1.5deg);
  animation: none;
}

@keyframes swsStampPress {
  0% {
    opacity: 0;
    transform: scale(1.2) rotate(-1.5deg);
  }
  28% {
    opacity: 0.92;
    transform: scale(1.04) rotate(-1.5deg);
  }
  58% {
    opacity: 1;
    transform: scale(0.96) rotate(-1.5deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(-1.5deg);
  }
}

/* ── Typing caret ── */
.sws-letter__caret {
  display: inline-block;
  width: 1px;
  height: 0.85em;
  margin-left: 1px;
  vertical-align: -0.05em;
  background: rgba(42, 31, 14, 0.5);
  animation: swsCaretPulse 1.1s ease-in-out infinite;
}

@keyframes swsCaretPulse {
  0%, 100% { opacity: 0.15; }
  50%       { opacity: 0.6;  }
}

/* Hide caret once letter is complete */
.sws-letter--complete .sws-letter__caret {
  display: none;
}

/* ── Screen-reader only ── */
.sws-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Responsive ── */
@media (min-width: 520px) {
  .sws-nav__title {
    font-size: 0.82rem;
  }

  .sws-main {
    padding: 24px 20px 16px;
  }

  /* On wider screens the image is bigger, so keep font sizes proportional.
     At 480px image width these are the natural sizes; scale them gently. */
  .sws-letter__greeting  { font-size: 15px; }
  .sws-letter__signature { font-size: 20px; }
  .sws-letter__closing   { font-size: 10px; }
  .sws-letter__p,
  .sws-letter__line,
  .sws-letter__emphasis  { font-size: 8px; }
}

/* On very small phones, scale down slightly to avoid overflow */
@media (max-width: 360px) {
  .sws-letter__greeting  { font-size: 15px; }
  .sws-letter__signature { font-size: 20px; }
  .sws-letter__closing   { font-size: 10px; }
  .sws-letter__p,
  .sws-letter__line,
  .sws-letter__emphasis  { font-size: 8px; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .sws-letter__caret {
    animation: none;
    opacity: 0.35;
  }

  .sws-nav__replay.is-playing svg {
    animation: none;
  }

  .sws-letter__underline,
  .sws-letter__heart {
    transition: none !important;
  }

  .sws-stamp.is-stamping {
    animation: none;
    opacity: 1;
    transform: scale(1) rotate(-1.5deg);
  }
}
