:root {
  --paper: #fffffb;
  --paper-edge: #f3efe6;
  --postcard-cream: #fffcf7;
  --desk: #f4f1ea;
  --ink: #33322c;
  --ink-soft: #5c574e;
  --muted: #8a8478;
  --sage: #71905f;
  --blush: #e8a0a0;
  --sky-ink: #8fb0c4;
  --gold: #d9a441;
  --stamp: #4a5f8c;
  --accent: #4a5f8c;
  --accent-dark: #33322c;
  --font-display: "Homemade Apple", "Caveat", cursive;
  --font-brand: "Fraunces", "Newsreader", Georgia, serif;
  --font-script: "Caveat", cursive;
  --font-note: "Reenie Beanie", "Caveat", cursive;
  --font-ui: "DM Sans", "Segoe UI", sans-serif;
  --font-body: "Newsreader", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

html {
  position: relative;
}

/* Soft paper grain */
html::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0.035;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 160px 160px;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  /* Soft sky: pale blue → cream → pastel pink */
  background-color: #d0e8f6;
  background-image:
    radial-gradient(ellipse 55% 42% at 18% 18%, rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0.26) 42%, transparent 72%),
    radial-gradient(ellipse 48% 38% at 78% 16%, rgba(255, 255, 255, 0.58) 0%, rgba(215, 238, 252, 0.22) 48%, transparent 74%),
    radial-gradient(ellipse 62% 44% at 48% 36%, rgba(255, 252, 248, 0.38) 0%, transparent 70%),
    radial-gradient(ellipse 56% 40% at 88% 52%, rgba(200, 232, 250, 0.24) 0%, transparent 72%),
    radial-gradient(ellipse 70% 48% at 24% 72%, rgba(255, 236, 242, 0.32) 0%, rgba(255, 228, 236, 0.14) 45%, transparent 75%),
    radial-gradient(ellipse 58% 40% at 72% 82%, rgba(255, 234, 240, 0.32) 0%, transparent 70%),
    radial-gradient(ellipse 90% 55% at 50% 100%, rgba(255, 230, 238, 0.36) 0%, transparent 60%),
    linear-gradient(
      180deg,
      #abd4f0 0%,
      #bee0f5 18%,
      #d4ebf9 38%,
      #f6eef2 58%,
      #f8e4ec 78%,
      #f6dde8 100%
    );
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 36px 16px 64px;
  position: relative;
  isolation: isolate;
}

@media (max-width: 700px) {
  body {
    background-attachment: scroll;
  }
}

/* Soft watercolor bloom layer (extra cloudy edges) */
body::before {
  content: "";
  display: block;
  position: fixed;
  inset: -8%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 48% 36% at 12% 40%, rgba(255, 255, 255, 0.62), transparent 72%),
    radial-gradient(ellipse 42% 32% at 56% 12%, rgba(255, 255, 255, 0.5), transparent 70%),
    radial-gradient(ellipse 50% 38% at 92% 58%, rgba(190, 228, 250, 0.3), transparent 72%),
    radial-gradient(ellipse 52% 40% at 40% 90%, rgba(255, 255, 255, 0.5), transparent 70%);
  filter: blur(24px);
  opacity: 1;
}

/* Distinct fluffy clouds — clustered soft bumps */
body::after {
  content: "";
  display: block;
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 1;
  background-image:
    /* cloud — upper left */
    radial-gradient(ellipse 16vw 9vw at 14% 16%, #fff 0%, rgba(255, 255, 255, 0.92) 42%, transparent 78%),
    radial-gradient(ellipse 11vw 8vw at 6% 18%, #fff 0%, transparent 76%),
    radial-gradient(ellipse 12vw 8vw at 23% 17%, #fffcf8 0%, transparent 76%),
    radial-gradient(ellipse 18vw 7vw at 14% 23%, #fff 0%, transparent 78%),
    /* cloud — top center */
    radial-gradient(ellipse 14vw 8vw at 48% 10%, #fff 0%, rgba(255, 255, 255, 0.85) 45%, transparent 78%),
    radial-gradient(ellipse 10vw 7vw at 42% 12%, #fff 0%, transparent 76%),
    radial-gradient(ellipse 11vw 7vw at 55% 11%, #fffcf8 0%, transparent 76%),
    radial-gradient(ellipse 16vw 6vw at 48% 16%, rgba(255, 255, 255, 0.95) 0%, transparent 78%),
    /* cloud — upper right */
    radial-gradient(ellipse 17vw 9.5vw at 84% 15%, #fff 0%, rgba(245, 250, 255, 0.9) 42%, transparent 78%),
    radial-gradient(ellipse 11vw 8vw at 76% 17%, #fff 0%, transparent 76%),
    radial-gradient(ellipse 12vw 8.5vw at 92% 16%, #fffcf8 0%, transparent 76%),
    radial-gradient(ellipse 19vw 7vw at 84% 22%, #fff 0%, transparent 78%),
    /* cloud — mid left */
    radial-gradient(ellipse 14vw 8vw at 18% 40%, #fff 0%, transparent 76%),
    radial-gradient(ellipse 10vw 7.5vw at 11% 42%, rgba(255, 250, 245, 0.98) 0%, transparent 76%),
    radial-gradient(ellipse 11vw 7vw at 26% 41%, #fff 0%, transparent 76%),
    radial-gradient(ellipse 16vw 6vw at 18% 47%, #fff 0%, transparent 78%),
    /* cloud — mid right */
    radial-gradient(ellipse 15vw 8.5vw at 72% 38%, #fff 0%, transparent 76%),
    radial-gradient(ellipse 10vw 7.5vw at 64% 40%, rgba(248, 252, 255, 0.98) 0%, transparent 76%),
    radial-gradient(ellipse 11vw 7.5vw at 80% 39%, #fff 0%, transparent 76%),
    radial-gradient(ellipse 17vw 6.5vw at 72% 45%, #fff 0%, transparent 78%),
    /* cloud — lower mid (white so they show on pink) */
    radial-gradient(ellipse 18vw 10vw at 46% 68%, #fff 0%, rgba(255, 255, 255, 0.88) 42%, transparent 76%),
    radial-gradient(ellipse 12vw 8vw at 36% 70%, #fff 0%, transparent 76%),
    radial-gradient(ellipse 13vw 8.5vw at 56% 69%, #fffcf8 0%, transparent 76%),
    radial-gradient(ellipse 20vw 7.5vw at 46% 76%, rgba(255, 255, 255, 0.95) 0%, transparent 78%),
    /* cloud — lower left */
    radial-gradient(ellipse 15vw 9vw at 14% 78%, #fff 0%, rgba(255, 255, 255, 0.9) 42%, transparent 76%),
    radial-gradient(ellipse 10vw 7.5vw at 6% 80%, #fff 0%, transparent 76%),
    radial-gradient(ellipse 12vw 7vw at 22% 79%, #fffcf8 0%, transparent 76%),
    radial-gradient(ellipse 17vw 6.5vw at 14% 85%, #fff 0%, transparent 78%),
    /* cloud — far lower right */
    radial-gradient(ellipse 16vw 9vw at 86% 74%, #fff 0%, rgba(255, 252, 250, 0.9) 42%, transparent 76%),
    radial-gradient(ellipse 11vw 7.5vw at 78% 76%, #fff 0%, transparent 76%),
    radial-gradient(ellipse 12vw 8vw at 94% 75%, #fffcf8 0%, transparent 76%),
    radial-gradient(ellipse 18vw 6.5vw at 86% 82%, rgba(255, 255, 255, 0.92) 0%, transparent 78%);
  background-repeat: no-repeat;
  filter: blur(2.5px);
}

@media (prefers-reduced-motion: no-preference) {
  body::before {
    animation: cloud-drift-slow 70s ease-in-out infinite alternate;
  }

  body::after {
    animation: cloud-drift 48s ease-in-out infinite alternate;
  }
}

@keyframes cloud-drift {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(-4.5%, 2%, 0);
  }
}

@keyframes cloud-drift-slow {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(3%, -1.5%, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after {
    animation: none;
  }
}

.page {
  width: 100%;
  max-width: 640px;
  position: relative;
  z-index: 1;
}

.brand {
  text-align: center;
  margin-bottom: 18px;
  padding-top: 18px;
}

.brand-mark {
  margin: 0 0 6px;
  font-size: 22px;
  opacity: 0.85;
}

.brand h1 {
  font-family: var(--font-brand);
  font-size: clamp(1.7rem, 5.5vw, 2.4rem);
  font-weight: 400;
  margin: 0 0 10px;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1.15;
  text-shadow: 0 1px 0 rgba(255, 252, 248, 0.55);
}

.brand p {
  margin: 0 auto;
  max-width: 28rem;
  font-family: var(--font-body);
  color: var(--ink-soft);
  font-size: 14px;
  font-style: italic;
  line-height: 1.45;
  text-shadow: 0 1px 0 rgba(255, 252, 248, 0.4);
  white-space: nowrap;
}

@media (max-width: 480px) {
  .brand p {
    white-space: normal;
    font-size: 13px;
  }
}

/* ---------- Create flow ---------- */

.card {
  background: var(--postcard-cream);
  border-radius: 16px;
  padding: 18px 20px 16px;
  border: 1px solid rgba(120, 100, 75, 0.2);
  overflow: visible;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.65) inset,
    0 -1px 0 rgba(120, 95, 70, 0.06) inset,
    0 1px 2px rgba(51, 50, 44, 0.04),
    0 8px 20px rgba(51, 50, 44, 0.07),
    0 22px 56px rgba(90, 70, 45, 0.12);
}

label.field-label {
  display: block;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.title-field {
  position: relative;
  overflow: visible;
  margin: 0 0 10px;
}

.title-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 0;
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 4.5vw, 2.15rem);
  font-weight: 400;
  line-height: 1.55;
  padding: 0.2em 2.6em 0.35em 0.15em;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  margin: 0;
  box-shadow: none;
  letter-spacing: 0;
  outline: none;
  overflow: visible;
  word-break: break-word;
  white-space: pre-wrap;
  -webkit-user-select: text;
  user-select: text;
}

.title-input:empty::before,
.title-input[data-empty="true"]::before {
  content: attr(data-placeholder);
  font-family: var(--font-display);
  color: var(--muted);
  opacity: 0.55;
  pointer-events: none;
}

.title-input:focus {
  outline: none;
}

.char-count {
  position: absolute;
  top: 0.55em;
  right: 0;
  margin: 0;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  line-height: 1;
  pointer-events: none;
  white-space: nowrap;
}

.photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 8px;
  margin-bottom: 14px;
}

@media (min-width: 700px) {
  .photo-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px 6px;
  }
}

.photo-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  overflow: visible;
}

.photo-subtitle {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 0;
  font-family: var(--font-note);
  font-size: 18px;
  font-weight: 400;
  line-height: 1.35;
  color: var(--ink);
  background: transparent;
  border: none;
  padding: 0.15em 0.1em 0.25em;
  text-align: center;
  outline: none;
  overflow: visible;
  word-break: break-word;
  white-space: pre-wrap;
  -webkit-user-select: text;
  user-select: text;
}

.photo-subtitle:empty::before,
.photo-subtitle[data-empty="true"]::before {
  content: attr(data-placeholder);
  color: var(--muted);
  opacity: 0.7;
  pointer-events: none;
}

.photo-subtitle:focus {
  outline: none;
}

.photo-slot {
  position: relative;
  /* Match postcard window frame (viewBox 100×150) */
  aspect-ratio: 100 / 150;
  border-radius: 10px;
  border: 1.5px dashed rgba(51, 50, 44, 0.35);
  background: #faf7f0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  box-shadow: none;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.photo-slot:active {
  transform: scale(0.98);
}

.photo-slot.filled {
  border-style: solid;
  border-color: rgba(51, 50, 44, 0.28);
}

.photo-slot input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.photo-slot .placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  pointer-events: none;
}

.photo-slot .placeholder svg {
  width: 26px;
  height: 26px;
}

.photo-slot .placeholder span {
  font-family: var(--font-note);
  font-size: 18px;
  font-weight: 400;
}

.photo-slot img.preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
  pointer-events: auto;
  border-radius: 0;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
}

.photo-slot.filled input[type="file"] {
  pointer-events: none;
}

.photo-slot.filled.is-panning img.preview {
  cursor: grabbing;
}

.photo-slot.filled.is-panning {
  transform: none;
}

.photo-slot .slot-number {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  box-shadow: none;
}

.create-actions {
  display: flex;
  gap: 10px;
  margin-top: 2px;
}

.create-actions button {
  flex: 1;
  padding: 11px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.create-actions #generate-btn {
  color: var(--paper);
  background: var(--ink);
  border: none;
  box-shadow: 0 2px 0 rgba(51, 50, 44, 0.2);
}

.create-actions #generate-btn:disabled,
.create-actions #preview-btn:disabled {
  background: #c7c2b6;
  color: var(--paper);
  border: none;
  box-shadow: none;
  cursor: not-allowed;
  filter: none;
}

.create-actions #preview-btn:not(:disabled) {
  color: var(--ink);
  background: transparent;
  border: 1.5px solid rgba(51, 50, 44, 0.35);
  box-shadow: none;
}

.create-actions #generate-btn:not(:disabled):active,
.create-actions #preview-btn:not(:disabled):active {
  transform: translateY(1px);
  box-shadow: none;
}

.error-banner {
  background: #fff5f2;
  border: 1px solid #e8a0a0;
  color: #8f4a4a;
  padding: 12px 14px;
  border-radius: 2px;
  font-size: 14px;
  font-style: italic;
  margin-bottom: 16px;
  display: none;
}

.error-banner.visible {
  display: block;
}

/* ---------- Success / share panel ---------- */

.share-panel {
  text-align: center;
}

.share-panel .check {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #eef4ea;
  color: var(--sage);
  border: 1.5px solid var(--sage);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 26px;
  box-shadow: none;
}

.share-panel h2 {
  font-family: var(--font-ui);
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.share-panel p {
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
  font-weight: 400;
  margin: 0 0 20px;
}

.link-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.link-row input {
  flex: 1;
  padding: 11px 12px;
  border-radius: 2px;
  border: 1px solid rgba(51, 50, 44, 0.2);
  font-family: var(--font-body);
  font-size: 13px;
  background: #faf7f0;
  color: var(--ink);
}

.link-row button,
.share-panel .primary-actions button {
  font-family: var(--font-ui);
  padding: 10px 16px;
  border-radius: 999px;
  border: none;
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  box-shadow: none;
}

.share-panel .secondary,
button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid rgba(51, 50, 44, 0.35);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: none;
}

/* Keep mail invite title above create-page chrome during preview delivery */
body.preview-delivery .mail-invite {
  z-index: 65;
}

body.preview-delivery .page-preview {
  position: relative;
  z-index: 1;
}

/* Match the generated viewer postcard width while previewing */
.page.page-preview {
  max-width: 820px;
}

.preview-panel {
  width: 100%;
}

.preview-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 22px;
}

.preview-actions button,
button.secondary {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 999px;
  cursor: pointer;
}

.preview-actions #confirm-create-btn {
  background: var(--ink);
  color: var(--paper);
  border: none;
  box-shadow: none;
}

.preview-actions #confirm-create-btn:disabled {
  background: #c7c2b6;
  box-shadow: none;
  cursor: not-allowed;
}

.preview-actions .secondary,
button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid rgba(51, 50, 44, 0.35);
  box-shadow: none;
}

.preview-actions .secondary:active,
button.secondary:active {
  transform: translateY(1px);
}

#preview-error {
  margin-top: 16px;
}

/* ---------- Postcard shell ---------- */

.postcard {
  position: relative;
  background-color: var(--postcard-cream);
  background-image: none;
  border: 1px solid rgba(120, 100, 75, 0.2);
  border-radius: 16px;
  padding: 28px 22px 24px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.65) inset,
    0 -1px 0 rgba(120, 95, 70, 0.06) inset,
    0 1px 2px rgba(51, 50, 44, 0.04),
    0 8px 20px rgba(51, 50, 44, 0.07),
    0 22px 56px rgba(90, 70, 45, 0.12);
  overflow: hidden;
}

.postcard-stamp {
  position: absolute;
  top: 28px;
  right: 14px;
  width: 58px;
  height: 70px;
  background: #fffffb;
  border: 1.5px solid var(--stamp);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transform: rotate(2deg);
  box-shadow: 1px 2px 0 rgba(51, 50, 44, 0.06);
  z-index: 2;
}

.postcard-stamp::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px dashed rgba(74, 95, 140, 0.45);
  pointer-events: none;
}

.stamp-emoji,
.stamp-plane {
  width: 34px;
  height: 22px;
  color: var(--stamp);
  display: block;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}

.stamp-plane {
  transform: rotate(-6deg);
}

.stamp-date {
  font-family: var(--font-note);
  font-size: 13px;
  color: var(--stamp);
  transform: rotate(-8deg);
  position: relative;
  z-index: 1;
}

/* ---------- Viewer ---------- */

.viewer-body {
  padding-left: 12px;
  padding-right: 12px;
  padding-top: 24px;
  padding-bottom: 24px;
  /* inherits watercolor sky from body */
}

/* ---------- Mail invite (open your mail) ---------- */

.mail-invite {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  padding: 72px 16px 24px;
  min-height: min(70vh, 560px);
  position: relative;
  z-index: 65;
  pointer-events: none;
}

.mail-invite-kicker {
  margin: 0 0 8px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.mail-invite-title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 400;
  color: var(--ink);
  line-height: 1.15;
}

.mail-invite-sub {
  margin: 0 0 12px;
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-style: italic;
  color: var(--ink-soft);
  max-width: 22em;
}

.mail-invite-hint {
  margin: 0;
  position: absolute;
  /* Same center as .mail-delivery-letter, then lift just above the card */
  left: 50%;
  top: 54%;
  transform: translate(-50%, calc(-50% - 113px));
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  z-index: 5;
  white-space: nowrap;
}

.mail-invite-hint.is-visible {
  opacity: 1;
}

@media (max-width: 700px) {
  .mail-invite-hint {
    /* Card is min-height 168px → half ≈ 84px + small gap */
    transform: translate(-50%, calc(-50% - 105px));
  }
}

/* Plane flies in on the invite screen and drops the mail card */
.mail-delivery {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  overflow: hidden;
}

.mail-delivery-plane {
  position: absolute;
  top: 34%;
  left: 50%;
  width: min(92vw, 520px);
  height: auto;
  opacity: 0;
  filter: drop-shadow(0 16px 28px rgba(51, 50, 44, 0.28));
  will-change: transform, opacity;
  backface-visibility: hidden;
  z-index: 3;
  transform: translate(-50%, -50%);
}

.mail-delivery-trail {
  position: absolute;
  top: calc(34% + 2.2vw);
  left: 50%;
  width: min(48vw, 240px);
  height: 0;
  border-top: 2px dashed rgba(74, 95, 140, 0.38);
  opacity: 0;
  transform-origin: left center;
  will-change: transform, opacity;
  z-index: 1;
}

.mail-delivery-letter {
  position: absolute;
  /* Same anchor as the floating rest state, so the handoff doesn't snap */
  top: 54%;
  left: 50%;
  width: min(72vw, 280px);
  height: auto;
  min-height: 168px;
  padding: 18px 18px 16px;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  box-sizing: border-box;
  background: var(--postcard-cream, #fffcf7);
  border: 1.5px solid rgba(120, 100, 75, 0.24);
  border-radius: 14px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.75) inset,
    0 12px 28px rgba(51, 50, 44, 0.18);
  opacity: 0;
  /* Under the plane while emerging from the belly */
  z-index: 2;
  will-change: transform, opacity;
  overflow: hidden;
  cursor: default;
  pointer-events: none;
  font: inherit;
  color: inherit;
  text-align: left;
  appearance: none;
  -webkit-appearance: none;
  transform-origin: center center;
  transform: translate3d(-50%, -50%, 0);
  backface-visibility: hidden;
  contain: layout style;
}

.mail-mini-stamp {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 34px;
  border: 1px solid rgba(74, 95, 140, 0.5);
  border-radius: 1px;
  background: #fffffb;
}

.mail-mini-kicker {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 36px;
}

.mail-mini-windows {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
  justify-content: flex-start;
}

.mail-mini-windows span {
  width: 28px;
  height: 46px;
  border-radius: 999px;
  background: #c8d7e6;
  border: 1.5px solid rgba(51, 50, 44, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  flex: 0 0 auto;
}

.mail-delivery.is-flying .mail-delivery-plane {
  animation: mail-plane-fly 4s linear forwards;
}

.mail-delivery.is-flying .mail-delivery-trail {
  animation: mail-trail-fly 4s linear forwards;
}

.mail-delivery.is-flying .mail-delivery-letter {
  animation: mail-letter-drop 4s forwards;
}

.mail-delivery.is-delivered {
  pointer-events: none;
}

.mail-delivery.is-delivered .mail-delivery-plane,
.mail-delivery.is-delivered .mail-delivery-trail {
  display: none;
}

.mail-delivery.is-delivered .mail-delivery-letter {
  animation: mail-card-float 4.8s ease-in-out infinite;
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
  z-index: 4;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 18px 40px rgba(51, 50, 44, 0.18),
    0 4px 12px rgba(90, 70, 45, 0.1);
}

.mail-delivery.is-delivered .mail-delivery-letter:hover {
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 22px 48px rgba(51, 50, 44, 0.22),
    0 6px 16px rgba(90, 70, 45, 0.12);
}

.mail-delivery.is-delivered .mail-delivery-letter:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(74, 95, 140, 0.35),
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 18px 40px rgba(51, 50, 44, 0.18);
}

@keyframes mail-plane-fly {
  0% {
    transform: translate(-50%, -50%) translate3d(-105vw, 10px, 0) rotate(-5deg);
    opacity: 0;
  }
  8% {
    opacity: 1;
  }
  84% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) translate3d(105vw, -22px, 0) rotate(5deg);
    opacity: 0;
  }
}

@keyframes mail-trail-fly {
  0% {
    transform: translate(-10%, -50%) translate3d(-105vw, 18px, 0) rotate(-4deg) scaleX(0.25);
    opacity: 0;
  }
  10% {
    opacity: 0.4;
  }
  84% {
    opacity: 0.18;
  }
  100% {
    transform: translate(-10%, -50%) translate3d(100vw, -16px, 0) rotate(4deg) scaleX(1.4);
    opacity: 0;
  }
}

@keyframes mail-letter-drop {
  /*
    Plane x(t) = -105 + t * 210 (vw).
    Tuck under the belly, then drift in one continuous arc to page center.
  */
  0% {
    transform: translate3d(-50%, -50%, 0) translate3d(-105vw, -16vh, 0) rotate(-3deg) scale(0.22);
    opacity: 0;
    animation-timing-function: linear;
  }
  40% {
    transform: translate3d(-50%, -50%, 0) translate3d(-21vw, -15vh, 0) rotate(-2deg) scale(0.24);
    opacity: 0;
    animation-timing-function: linear;
  }
  /* Appear under the airplane belly */
  44% {
    transform: translate3d(-50%, -50%, 0) translate3d(-17vw, -14vh, 0) rotate(-2deg) scale(0.3);
    opacity: 1;
    /* Single smooth drift all the way to center — no mid-waypoint kinks */
    animation-timing-function: cubic-bezier(0.22, 0.1, 0.25, 1);
  }
  100% {
    transform: translate3d(-50%, -50%, 0) rotate(-2.5deg) scale(1);
    opacity: 1;
  }
}

@keyframes mail-card-float {
  0%,
  100% {
    transform: translate3d(-50%, -50%, 0) rotate(-2.5deg) translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(-50%, -50%, 0) rotate(-1deg) translate3d(0, -12px, 0);
  }
}

.postcard.postcard-arrive.is-waiting {
  opacity: 0;
  transform: translate3d(0, 24px, 0) scale(0.96);
  pointer-events: none;
}

.postcard.postcard-arrive.is-landed {
  animation: postcard-land 0.85s cubic-bezier(0.22, 1.15, 0.36, 1) forwards;
}

@keyframes postcard-land {
  0% {
    opacity: 0;
    transform: translate3d(0, 20px, 0) scale(0.94);
  }
  70% {
    opacity: 1;
    transform: translate3d(0, -3px, 0) scale(1.01);
  }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

.viewer-footer.is-waiting {
  opacity: 0;
}

.viewer-footer.is-visible {
  animation: footer-fade-in 0.55s ease forwards;
}

@keyframes footer-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .mail-delivery-plane,
  .mail-delivery-trail {
    display: none;
  }

  .mail-delivery,
  .mail-delivery.is-delivered {
    pointer-events: none;
  }

  .mail-delivery .mail-delivery-letter {
    animation: none !important;
    opacity: 1;
    pointer-events: auto;
    cursor: pointer;
    top: 54%;
    left: 50%;
    width: min(72vw, 280px);
    height: auto;
    min-height: 168px;
    padding: 18px;
    border-radius: 14px;
    transform: translate(-50%, -50%) rotate(-2deg);
  }

  .postcard.postcard-arrive.is-waiting,
  .postcard.postcard-arrive.is-landed {
    opacity: 1;
    transform: none;
    animation: none;
  }

  .viewer-footer.is-waiting,
  .viewer-footer.is-visible {
    opacity: 1;
    animation: none;
  }
}

.page-viewer {
  max-width: 820px;
  margin-top: auto;
  margin-bottom: auto;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

.viewer-masthead {
  text-align: left;
  margin: 0 70px 14px 0;
  max-width: none;
  position: relative;
  z-index: 1;
}

.viewer-kicker {
  margin: 0 0 14px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  font-style: normal;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-shadow: none;
}

.viewer-title {
  font-family: var(--font-display);
  text-align: left;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 400;
  line-height: 1.2;
  color: var(--ink);
  margin: 0;
  word-break: break-word;
  letter-spacing: 0;
  text-shadow: none;
}

.window-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: flex-start;
  gap: 10px;
  overflow-x: auto;
  padding: 6px 2px 10px;
  -webkit-overflow-scrolling: touch;
  position: relative;
  z-index: 1;
}

.window-cell {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(24vw, 178px);
  min-width: 132px;
  overflow: visible;
}

.window-cell .window {
  width: 100%;
  min-width: 0;
}

.window {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: 100 / 150;
  background: transparent;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  filter: none;
  transition: transform 0.18s ease;
}

.window:hover {
  transform: translateY(-2px);
}

@media (prefers-reduced-motion: reduce) {
  .window:hover {
    transform: none;
  }
}

.window::after {
  display: none;
}

.window-sketch-root {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.window-sketch-root > .window-sketch {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.window-inner {
  /* sketch root doubles as inner; keep cascade hooks */
}

.window-frame {
  display: none;
}

.window-sketch .shade {
  transform-box: view-box;
  transform-origin: 0 0;
}

.window-sketch .photo {
  pointer-events: none;
}

/* Legacy HTML photo/shade styles (unused by SVG windows, kept harmless) */
.window-inner img.photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.window-inner .glow {
  pointer-events: none;
}

.window-inner.is-open .glow {
  opacity: 1;
}

.shade {
  touch-action: none;
  cursor: grab;
  will-change: transform;
}

.shade:active {
  cursor: grabbing;
}

.shade-image,
.shade .shade-sketch {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  user-select: none;
}

.window-caption {
  display: block;
  width: 100%;
  margin: 0;
  text-align: center;
  font-family: var(--font-note);
  font-size: 20px;
  line-height: 1.45;
  color: var(--ink-soft);
  word-break: break-word;
  min-height: 1.45em;
  padding: 0.15em 0.1em 0.25em;
  overflow: visible;
}

.window-caption.is-empty {
  visibility: hidden;
}

@media (max-width: 700px) {
  /* Match create-page card width / padding so windows size the same */
  .page-viewer,
  .page.page-preview {
    max-width: 640px;
  }

  body.viewer-body {
    padding: 24px 16px 48px;
  }

  .window-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 8px;
    overflow-x: visible;
    justify-items: stretch;
    padding: 0;
  }

  .window-cell {
    width: 100%;
    max-width: none;
    min-width: 0;
    gap: 0;
  }

  .postcard {
    padding: 18px 20px 16px;
  }

  .postcard-stamp {
    top: 18px;
  }

  .viewer-masthead {
    margin: 0 58px 10px 0;
  }

  .viewer-kicker {
    margin: 0 0 8px;
    font-size: 11px;
  }

  .viewer-title {
    font-size: clamp(1.55rem, 4.5vw, 2.15rem);
    line-height: 1.55;
  }

  .window-caption {
    font-size: 18px;
    line-height: 1.25;
    min-height: 0;
    padding: 0 0.1em 0.1em;
    margin-top: -2px;
  }

  .photo-cell {
    gap: 0;
  }

  .photo-subtitle {
    padding: 0 0.1em 0.15em;
    margin-top: -2px;
  }
}

.expired-state {
  text-align: center;
  padding: 60px 20px;
}

.expired-state .icon {
  font-size: 36px;
  margin-bottom: 12px;
  filter: none;
}

.expired-state h2 {
  font-family: var(--font-display);
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 400;
  color: var(--ink);
}

.expired-state p {
  color: var(--muted);
  font-style: italic;
  font-weight: 400;
  margin: 0;
}

.loading-state {
  text-align: center;
  padding: 60px 20px;
  font-family: var(--font-note);
  font-size: 24px;
  font-weight: 400;
  color: var(--muted);
}

footer.app-footer {
  margin-top: 40px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.footer-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--paper);
  text-decoration: none;
  padding: 11px 20px;
  border: none;
  border-radius: 999px;
  background: var(--ink);
  box-shadow: none;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.footer-cta:hover {
  filter: none;
  opacity: 0.9;
}

.footer-cta:active {
  transform: translateY(1px);
  box-shadow: none;
}

.built-by {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 400;
  font-style: italic;
  letter-spacing: 0.01em;
  color: var(--muted);
  opacity: 0.75;
}

.built-by a {
  color: inherit;
  text-decoration: none;
}

.built-by a:hover {
  opacity: 1;
  text-decoration: underline;
  color: var(--ink);
}

a.plain {
  color: var(--stamp);
  text-decoration: none;
  font-weight: 400;
  font-style: italic;
}
