Skip to content
VibeCodeBench
Back to the app

The code

Love Letter by Gemini 4 Neon

Exactly as the AI wrote it. Shown as text, so nothing runs on this page.

index.html

works · auto-checked (Checked by an automated pass. Not hand-played yet.)126.4 KB · 3,433 lines · no libraries
Download
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>Petite Post — A Little Love Letter</title>
<style>
  :root {
    --desk-bg-center: #581b25;
    --desk-bg-mid: #310e15;
    --desk-bg-edge: #18060a;

    --crimson: #a92431;
    --crimson-deep: #7f1723;
    --crimson-bright: #cb3844;
    --cream: #fbf3e4;
    --cream-soft: #f5e8d1;
    --gold: #cfa049;
    --gold-light: #f1d38b;
    --gold-deep: #9d6f22;

    /* Active paper theme variables (default: Cream Linen) */
    --paper-bg: #fbf4e6;
    --paper-bg-2: #f4e8d2;
    --paper-edge: #e4d1b1;
    --paper-accent: #a92431;
    --paper-accent-soft: rgba(169, 36, 49, 0.14);
    --paper-gold: #c99438;
    --paper-gold-soft: rgba(201, 148, 56, 0.28);
    --paper-ink: #421c21;
    --paper-ink-muted: #7a4b50;
    --paper-rule: rgba(185, 134, 64, 0.24);
    --seal-bg-1: #cc313e;
    --seal-bg-2: #8c1722;
    --seal-rim: #f3d284;
    --env-flap-bg: #f6ebd6;
    --env-pocket-bg: #efe0c4;
    --env-inner-bg: #9f222f;

    --font-serif: 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, 'Times New Roman', serif;
    --font-hand: 'Segoe Script', 'Bradley Hand', 'Apple Chancery', 'Snell Roundhand', 'Comic Sans MS', Georgia, cursive, serif;
    --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  }

  /* Paper Style 1: Cream Linen */
  body.theme-linen {
    --paper-bg: #fbf4e6;
    --paper-bg-2: #f3e6ce;
    --paper-edge: #e2cfa9;
    --paper-accent: #a92431;
    --paper-accent-soft: rgba(169, 36, 49, 0.13);
    --paper-gold: #c99438;
    --paper-gold-soft: rgba(201, 148, 56, 0.28);
    --paper-ink: #421c21;
    --paper-ink-muted: #7c4d52;
    --paper-rule: rgba(186, 136, 66, 0.23);
    --seal-bg-1: #cd313e;
    --seal-bg-2: #8c1723;
    --seal-rim: #f3d284;
    --env-flap-bg: #f7ecd7;
    --env-pocket-bg: #eedfc2;
    --env-inner-bg: #9e212e;
  }

  /* Paper Style 2: Rose Velvet */
  body.theme-rose {
    --paper-bg: #fae9e4;
    --paper-bg-2: #f2d8d1;
    --paper-edge: #dfb8ae;
    --paper-accent: #8f1b30;
    --paper-accent-soft: rgba(143, 27, 48, 0.14);
    --paper-gold: #d29755;
    --paper-gold-soft: rgba(210, 151, 85, 0.30);
    --paper-ink: #461a27;
    --paper-ink-muted: #824b5b;
    --paper-rule: rgba(176, 95, 110, 0.22);
    --seal-bg-1: #a81e3a;
    --seal-bg-2: #690f22;
    --seal-rim: #f4d3b0;
    --env-flap-bg: #f6dfd9;
    --env-pocket-bg: #ecd0c8;
    --env-inner-bg: #7c182c;
  }

  /* Paper Style 3: Gilded Heirloom */
  body.theme-gilded {
    --paper-bg: #f5e6c8;
    --paper-bg-2: #ebd5ab;
    --paper-edge: #cfa862;
    --paper-accent: #b32a24;
    --paper-accent-soft: rgba(179, 42, 36, 0.14);
    --paper-gold: #b87e19;
    --paper-gold-soft: rgba(184, 126, 25, 0.34);
    --paper-ink: #442116;
    --paper-ink-muted: #7d5333;
    --paper-rule: rgba(184, 126, 25, 0.26);
    --seal-bg-1: #dc9f32;
    --seal-bg-2: #966212;
    --seal-rim: #fff0be;
    --env-flap-bg: #f0dcb4;
    --env-pocket-bg: #e6cb97;
    --env-inner-bg: #9f2520;
  }

  * {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
  }

  html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: radial-gradient(ellipse at 50% 34%, var(--desk-bg-center) 0%, var(--desk-bg-mid) 56%, var(--desk-bg-edge) 100%);
    color: var(--cream);
    font-family: var(--font-serif);
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
    user-select: none;
  }

  /* Ambient & FX Canvases */
  #ambient-canvas,
  #fx-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
  }
  #ambient-canvas { z-index: 1; }
  #fx-canvas { z-index: 40; }

  /* Subtle gold corner ornaments on the desk */
  .desk-ornament {
    position: fixed;
    width: clamp(64px, 14vw, 120px);
    height: clamp(64px, 14vw, 120px);
    pointer-events: none;
    z-index: 2;
    opacity: 0.24;
  }
  .desk-ornament.tl { top: 10px; left: 10px; }
  .desk-ornament.tr { top: 10px; right: 10px; transform: scaleX(-1); }
  .desk-ornament.bl { bottom: 10px; left: 10px; transform: scaleY(-1); }
  .desk-ornament.br { bottom: 10px; right: 10px; transform: scale(-1); }

  /* Top Floating Bar */
  #top-bar {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    left: 12px;
    right: 12px;
    z-index: 35;
    display: flex;
    align-items: center;
    justify-content: space-between;
    pointer-events: none;
  }

  .top-pill {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(34, 10, 15, 0.62);
    border: 1px solid rgba(241, 211, 139, 0.34);
    color: var(--cream);
    font-family: var(--font-serif);
    font-size: 14px;
    letter-spacing: 0.03em;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
    cursor: pointer;
    transition: transform 0.16s ease, background 0.2s ease, opacity 0.25s ease;
  }
  .top-pill:active {
    transform: scale(0.95);
    background: rgba(65, 20, 28, 0.8);
  }
  .top-pill.icon-only {
    width: 46px;
    height: 46px;
    padding: 0;
    justify-content: center;
  }
  .top-pill.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px);
  }

  #brand-pill {
    cursor: default;
    pointer-events: none;
    background: rgba(34, 10, 15, 0.42);
    border-color: rgba(241, 211, 139, 0.22);
    color: var(--gold-light);
    font-style: italic;
    font-size: 15px;
  }

  /* Main App Container */
  #app {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .view {
    position: absolute;
    inset: 0;
    min-height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: max(64px, calc(env(safe-area-inset-top) + 56px)) 16px max(24px, env(safe-area-inset-bottom));
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(14px) scale(0.985);
    transition: opacity 0.48s cubic-bezier(0.22, 1, 0.36, 1),
                transform 0.52s cubic-bezier(0.22, 1, 0.36, 1),
                visibility 0.48s;
  }
  .view.active {
    position: relative;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
  }

  /* Tactile paper surface helper */
  .paper-sheet {
    position: relative;
    background:
      linear-gradient(165deg, var(--paper-bg) 0%, var(--paper-bg-2) 100%);
    color: var(--paper-ink);
    box-shadow:
      0 22px 54px rgba(10, 2, 4, 0.55),
      0 4px 12px rgba(10, 2, 4, 0.32),
      inset 0 0 0 1px rgba(255, 255, 255, 0.58),
      inset 0 0 38px rgba(164, 114, 62, 0.13);
    transition: background 0.35s ease, box-shadow 0.35s ease, color 0.3s ease;
  }
  .paper-sheet::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    opacity: 0.42;
    background-image: var(--paper-grain, none);
    background-size: 160px 160px;
    mix-blend-mode: multiply;
  }

  /* Decorative Paper Frame per Theme */
  .paper-frame {
    position: absolute;
    inset: 10px;
    border-radius: 10px;
    border: 1.5px solid var(--paper-gold-soft);
    pointer-events: none;
    transition: border-color 0.35s ease, box-shadow 0.35s ease;
  }
  .paper-frame::after {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 7px;
    border: 1px solid var(--paper-accent-soft);
  }
  body.theme-rose .paper-frame {
    border-style: double;
    border-width: 3px;
    border-color: rgba(168, 56, 78, 0.24);
  }
  body.theme-gilded .paper-frame {
    border: 2px solid rgba(196, 138, 34, 0.52);
    box-shadow: inset 0 0 0 3px rgba(196, 138, 34, 0.12);
  }

  /* ==================== STAGE 1: COMPOSE VIEW ==================== */
  #compose-card {
    width: min(100%, 440px);
    border-radius: 18px;
    padding: 24px 22px 22px;
    overflow: hidden;
  }

  .compose-header {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
  }
  .compose-title-block h1 {
    margin: 0;
    font-family: var(--font-serif);
    font-size: clamp(22px, 5.6vw, 27px);
    font-weight: 600;
    font-style: italic;
    color: var(--paper-accent);
    line-height: 1.15;
    letter-spacing: 0.01em;
  }
  .compose-title-block p {
    margin: 4px 0 0;
    font-size: 13.5px;
    color: var(--paper-ink-muted);
    line-height: 1.35;
  }

  /* Cute miniature postage stamp in corner */
  .mini-stamp {
    flex-shrink: 0;
    width: 52px;
    height: 58px;
    background: var(--paper-bg);
    border: 2px dotted var(--paper-gold);
    border-radius: 4px;
    padding: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(68, 28, 32, 0.14);
    transform: rotate(4deg);
  }

  .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
  }
  @media (max-width: 350px) {
    .form-row { grid-template-columns: 1fr; }
  }

  .field {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 5px;
  }
  .field label {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.11em;
    font-family: var(--font-ui);
    font-weight: 600;
    color: var(--paper-ink-muted);
    padding-left: 2px;
  }

  .field input,
  .field textarea {
    width: 100%;
    border: 1.5px solid var(--paper-gold-soft);
    border-radius: 12px;
    background: rgba(255, 253, 248, 0.66);
    color: var(--paper-ink);
    font-family: var(--font-serif);
    font-size: 16px; /* Prevents iOS zoom on focus */
    padding: 11px 13px;
    outline: none;
    user-select: text;
    -webkit-user-select: text;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  }
  .field input:focus,
  .field textarea:focus {
    border-color: var(--paper-accent);
    background: rgba(255, 255, 252, 0.92);
    box-shadow: 0 0 0 3px var(--paper-accent-soft);
  }
  .field input::placeholder,
  .field textarea::placeholder {
    color: rgba(122, 75, 80, 0.48);
    font-style: italic;
  }

  .field textarea {
    resize: none;
    min-height: 92px;
    line-height: 28px;
    padding: 8px 13px;
    background-image: repeating-linear-gradient(
      to bottom,
      transparent 0px,
      transparent 27px,
      var(--paper-rule) 27px,
      var(--paper-rule) 28px
    );
    background-position: 0 8px;
    font-family: var(--font-hand);
    font-size: 16px;
  }

  .msg-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 6px;
    gap: 8px;
  }
  .idea-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;
  }
  .idea-chip {
    min-height: 34px;
    padding: 5px 10px;
    border-radius: 999px;
    border: 1px solid var(--paper-gold-soft);
    background: rgba(255, 252, 244, 0.65);
    color: var(--paper-ink-muted);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.14s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  }
  .idea-chip:active {
    transform: scale(0.94);
    background: var(--paper-accent-soft);
    color: var(--paper-accent);
    border-color: var(--paper-accent);
  }

  #char-count {
    font-family: var(--font-ui);
    font-size: 11px;
    color: var(--paper-ink-muted);
    opacity: 0.78;
    white-space: nowrap;
  }

  /* Paper Style Selector */
  .style-picker-wrap {
    margin: 14px 0 18px;
  }
  .style-picker-label {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.11em;
    font-family: var(--font-ui);
    font-weight: 600;
    color: var(--paper-ink-muted);
    margin-bottom: 8px;
    display: block;
    padding-left: 2px;
  }
  .style-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 9px;
  }
  .style-option {
    position: relative;
    min-height: 68px;
    padding: 9px 6px 8px;
    border-radius: 12px;
    border: 2px solid transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(56, 20, 24, 0.12), inset 0 0 0 1px rgba(155, 110, 56, 0.26);
    transition: transform 0.16s ease, border-color 0.22s ease, box-shadow 0.22s ease;
  }
  .style-option:active {
    transform: scale(0.95);
  }
  .style-option[data-style="linen"] {
    background: linear-gradient(155deg, #fbf4e6 0%, #f1e2c5 100%);
    color: #542329;
  }
  .style-option[data-style="rose"] {
    background: linear-gradient(155deg, #fae9e4 0%, #f0cfc7 100%);
    color: #5c1c2c;
  }
  .style-option[data-style="gilded"] {
    background: linear-gradient(155deg, #f6e7c6 0%, #e5c68a 100%);
    color: #4f2814;
  }
  .style-option.selected {
    border-color: var(--paper-accent);
    box-shadow: 0 6px 14px rgba(145, 29, 44, 0.22), 0 0 0 2px rgba(207, 160, 73, 0.4);
    transform: translateY(-1px);
  }
  .style-swatch-seal {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2), inset 0 1px 2px rgba(255, 255, 255, 0.45);
  }
  .style-option[data-style="linen"] .style-swatch-seal {
    background: radial-gradient(circle at 35% 30%, #d33a47, #8f1823);
    border: 1.5px solid #f2d184;
  }
  .style-option[data-style="rose"] .style-swatch-seal {
    background: radial-gradient(circle at 35% 30%, #b32340, #6a0f22);
    border: 1.5px solid #f4d3b0;
  }
  .style-option[data-style="gilded"] .style-swatch-seal {
    background: radial-gradient(circle at 35% 30%, #e7b044, #9b6612);
    border: 1.5px solid #fff0be;
  }
  .style-option span {
    font-family: var(--font-ui);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.01em;
    text-align: center;
    line-height: 1.15;
  }

  /* Primary Crimson & Gold Button */
  .btn-primary {
    position: relative;
    width: 100%;
    min-height: 54px;
    padding: 13px 22px;
    border-radius: 999px;
    border: 1.5px solid rgba(244, 214, 140, 0.72);
    background: linear-gradient(180deg, #c7323f 0%, #9b1c29 60%, #7d141f 100%);
    color: #fff8eb;
    font-family: var(--font-serif);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.03em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    overflow: hidden;
    box-shadow:
      0 10px 24px rgba(125, 20, 31, 0.42),
      0 2px 6px rgba(0, 0, 0, 0.24),
      inset 0 1px 1px rgba(255, 236, 192, 0.45);
    transition: transform 0.16s ease, box-shadow 0.2s ease, filter 0.2s ease;
  }
  .btn-primary::after {
    content: '';
    position: absolute;
    top: 0;
    left: -120%;
    width: 70%;
    height: 100%;
    background: linear-gradient(100deg, transparent 0%, rgba(255, 240, 195, 0.26) 50%, transparent 100%);
    transform: skewX(-18deg);
    animation: sheenSweep 4.8s ease-in-out infinite;
  }
  @keyframes sheenSweep {
    0%, 72% { left: -120%; }
    100% { left: 150%; }
  }
  .btn-primary:active {
    transform: scale(0.97);
    box-shadow: 0 5px 14px rgba(125, 20, 31, 0.42);
  }

  .btn-secondary {
    min-height: 50px;
    padding: 11px 18px;
    border-radius: 999px;
    border: 1.5px solid rgba(241, 211, 139, 0.44);
    background: rgba(45, 13, 19, 0.65);
    color: var(--cream);
    font-family: var(--font-serif);
    font-size: 15.5px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    transition: transform 0.15s ease, background 0.2s ease;
  }
  .btn-secondary:active {
    transform: scale(0.96);
    background: rgba(74, 22, 31, 0.85);
  }

  /* ==================== STAGE 2: CAT DELIVERY & ENVELOPE ==================== */
  #view-delivery {
    padding: 0;
    justify-content: center;
    overflow: hidden;
  }

  #delivery-stage {
    position: relative;
    width: 100%;
    height: 100dvh;
    min-height: 520px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  /* Soft tabletop horizon path for the cat postman */
  .delivery-path {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(50% + 92px);
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, rgba(241, 211, 139, 0.34) 20%, rgba(241, 211, 139, 0.5) 50%, rgba(241, 211, 139, 0.34) 80%, transparent 100%);
    pointer-events: none;
  }
  .delivery-path::after {
    content: '';
    position: absolute;
    inset: 2px 0 -140px 0;
    background: radial-gradient(ellipse at 50% 0%, rgba(207, 160, 73, 0.14) 0%, transparent 72%);
  }

  .delivery-status {
    position: absolute;
    top: max(74px, calc(env(safe-area-inset-top) + 66px));
    left: 20px;
    right: 20px;
    text-align: center;
    font-family: var(--font-serif);
    font-style: italic;
    font-size: clamp(17px, 4.5vw, 22px);
    color: var(--gold-light);
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.45s ease, transform 0.45s ease;
    pointer-events: none;
  }
  .delivery-status.visible {
    opacity: 1;
    transform: translateY(0);
  }

  /* Cat Postman Wrapper */
  #cat-postman-wrap {
    position: absolute;
    top: calc(50% - 46px);
    left: 0;
    width: 176px;
    height: 152px;
    z-index: 22;
    pointer-events: none;
    will-change: transform;
    filter: drop-shadow(0 12px 14px rgba(14, 3, 6, 0.55));
    opacity: 0;
  }
  #cat-postman-wrap svg {
    width: 100%;
    height: 100%;
    overflow: visible;
  }
  #cat-love-bubble {
    opacity: 0;
    transform-origin: 122px 18px;
    transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.22, 1.4, 0.36, 1);
    transform: translateY(8px) scale(0.5);
  }
  #cat-postman-wrap.saluting #cat-love-bubble {
    opacity: 1;
    transform: translateY(-4px) scale(1);
  }

  /* Waiting Interactive Envelope */
  #envelope-zone {
    position: relative;
    z-index: 18;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(18px) scale(0.68);
    pointer-events: none;
    transition: opacity 0.45s ease, transform 0.58s cubic-bezier(0.22, 1.24, 0.36, 1);
  }
  #envelope-zone.landed {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }

  #waiting-envelope {
    position: relative;
    width: min(85vw, 336px);
    aspect-ratio: 1.44 / 1;
    perspective: 1000px;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    display: block;
    outline: none;
    animation: envFloat 3.6s ease-in-out infinite;
    filter: drop-shadow(0 20px 32px rgba(8, 1, 3, 0.58));
  }
  #waiting-envelope.opening {
    animation: none;
    pointer-events: none;
  }
  @keyframes envFloat {
    0%, 100% { transform: translateY(0px) rotate(-0.6deg); }
    50% { transform: translateY(-7px) rotate(0.6deg); }
  }

  .env-body {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    background: var(--env-inner-bg);
    box-shadow: inset 0 0 0 1.5px rgba(244, 214, 140, 0.45);
    transform-style: preserve-3d;
  }

  /* Inner peeking folded card */
  #env-peek-card {
    position: absolute;
    left: 6%;
    right: 6%;
    top: 8%;
    bottom: 8%;
    border-radius: 8px;
    background: linear-gradient(170deg, var(--paper-bg), var(--paper-bg-2));
    border: 1.5px solid var(--paper-gold);
    box-shadow: 0 -4px 14px rgba(34, 8, 12, 0.25);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 16px;
    z-index: 2;
    transform: translateY(0);
    transition: transform 0.72s cubic-bezier(0.22, 1.08, 0.36, 1) 0.28s, opacity 0.35s ease;
  }
  #waiting-envelope.opening #env-peek-card {
    transform: translateY(-48%) scale(1.04);
  }

  .env-pocket-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 4;
    border-radius: 12px;
    pointer-events: none;
  }

  .env-front-details {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 0 22px 18px;
    pointer-events: none;
  }
  .env-for-tag {
    font-family: var(--font-ui);
    font-size: 10px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--paper-ink-muted);
    opacity: 0.8;
    margin-bottom: 2px;
  }
  #env-to-label {
    font-family: var(--font-hand);
    font-size: clamp(20px, 5.4vw, 25px);
    color: var(--paper-ink);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.25;
  }

  /* Hinged Top Flap */
  #env-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 60%;
    z-index: 6;
    transform-origin: top center;
    transform-style: preserve-3d;
    transition: transform 0.7s cubic-bezier(0.32, 1.05, 0.38, 1);
  }
  #waiting-envelope.opening #env-flap {
    transform: rotateX(174deg);
    z-index: 1;
  }
  #env-flap svg {
    width: 100%;
    height: 100%;
    display: block;
    filter: drop-shadow(0 5px 8px rgba(48, 14, 20, 0.22));
  }

  /* Wax Seal */
  #env-wax-seal {
    position: absolute;
    left: 50%;
    bottom: -14px;
    width: 58px;
    height: 58px;
    margin-left: -29px;
    border-radius: 50%;
    background: radial-gradient(circle at 34% 28%, var(--seal-bg-1) 0%, var(--seal-bg-2) 86%);
    border: 2.5px solid var(--seal-rim);
    box-shadow:
      0 6px 14px rgba(40, 8, 12, 0.45),
      inset 0 2px 5px rgba(255, 232, 198, 0.38),
      inset 0 -4px 7px rgba(45, 5, 10, 0.42);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.28s ease, opacity 0.26s ease;
  }
  #env-wax-seal::before {
    content: '';
    position: absolute;
    inset: -9px;
    border-radius: 50%;
    border: 1.5px solid rgba(243, 210, 132, 0.65);
    animation: sealPulse 2.1s ease-out infinite;
  }
  @keyframes sealPulse {
    0% { transform: scale(0.88); opacity: 0.78; }
    100% { transform: scale(1.48); opacity: 0; }
  }
  #waiting-envelope:active #env-wax-seal {
    transform: scale(0.9);
  }
  #waiting-envelope.opening #env-wax-seal {
    transform: scale(1.38);
    opacity: 0;
  }

  #env-tap-hint {
    margin-top: 26px;
    padding: 8px 18px;
    border-radius: 999px;
    background: rgba(34, 10, 15, 0.56);
    border: 1px solid rgba(241, 211, 139, 0.34);
    color: var(--gold-light);
    font-family: var(--font-serif);
    font-size: 15px;
    font-style: italic;
    letter-spacing: 0.02em;
    animation: hintBreathe 2.3s ease-in-out infinite;
    transition: opacity 0.3s ease;
  }
  @keyframes hintBreathe {
    0%, 100% { opacity: 0.72; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-2px); }
  }

  /* ==================== STAGE 3: POP-UP SCENE & LETTER ==================== */
  #view-letter {
    justify-content: flex-start;
    padding-top: max(62px, calc(env(safe-area-inset-top) + 54px));
    padding-bottom: max(26px, calc(env(safe-area-inset-bottom) + 18px));
  }

  #popup-card {
    width: min(100%, 468px);
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform-origin: center center;
  }

  /* Upper Pop-Up Diorama Stage */
  #popup-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 440 / 280;
    background: linear-gradient(180deg, #271021 0%, #441628 70%, #5a1d2d 100%);
    perspective: 920px;
    overflow: hidden;
    cursor: pointer;
    border-bottom: 2px solid rgba(207, 160, 73, 0.45);
    /* Paper crease inner shadow */
    box-shadow: inset 0 -10px 16px rgba(18, 4, 8, 0.38);
  }

  /* Decorative top scalloped card border overlay */
  .stage-paper-mat {
    position: absolute;
    inset: 0;
    z-index: 15;
    pointer-events: none;
    border: 8px solid var(--paper-bg);
    border-bottom-width: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: inset 0 0 0 1.5px var(--paper-gold);
    transition: border-color 0.35s ease;
  }

  #popup-parallax {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  }

  /* 3D Pop-Up Cutout Layers */
  .popup-layer {
    position: absolute;
    inset: 0;
    transform-origin: 50% 100%;
    transform-style: preserve-3d;
    opacity: 0;
    transform: rotateX(78deg) scaleY(0.25) translateZ(0px);
    transition:
      transform 0.95s cubic-bezier(0.2, 1.24, 0.32, 1),
      opacity 0.45s ease;
    pointer-events: none;
  }
  .popup-layer svg {
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
  }

  /* Folded-open target depths and staggered unfold timings */
  #popup-stage.unfolded .layer-sky {
    opacity: 1;
    transform: rotateX(0deg) scaleY(1) translateZ(0px);
    transition-delay: 0.04s;
  }
  #popup-stage.unfolded .layer-moon {
    opacity: 1;
    transform: rotateX(0deg) scaleY(1) translateZ(14px);
    transition-delay: 0.16s;
    filter: drop-shadow(0 6px 14px rgba(248, 220, 146, 0.25));
  }
  #popup-stage.unfolded .layer-hills {
    opacity: 1;
    transform: rotateX(0deg) scaleY(1) translateZ(22px);
    transition-delay: 0.24s;
    filter: drop-shadow(0 -3px 6px rgba(18, 4, 10, 0.38));
  }
  #popup-stage.unfolded .layer-cats {
    opacity: 1;
    transform: rotateX(0deg) scaleY(1) translateZ(38px);
    transition-delay: 0.34s;
    filter: drop-shadow(0 6px 10px rgba(14, 3, 8, 0.45));
  }
  #popup-stage.unfolded .layer-hearts {
    opacity: 1;
    transform: rotateX(0deg) scaleY(1) translateZ(50px);
    transition-delay: 0.46s;
    filter: drop-shadow(0 6px 8px rgba(24, 4, 10, 0.35));
  }
  #popup-stage.unfolded .layer-flowers-l {
    opacity: 1;
    transform: rotateX(0deg) scaleY(1) translateZ(58px);
    transition-delay: 0.40s;
    filter: drop-shadow(4px 6px 8px rgba(18, 4, 8, 0.42));
  }
  #popup-stage.unfolded .layer-flowers-r {
    opacity: 1;
    transform: rotateX(0deg) scaleY(1) translateZ(58px);
    transition-delay: 0.44s;
    filter: drop-shadow(-4px 6px 8px rgba(18, 4, 8, 0.42));
  }
  #popup-stage.unfolded .layer-front {
    opacity: 1;
    transform: rotateX(0deg) scaleY(1) translateZ(66px);
    transition-delay: 0.52s;
  }

  /* Gentle living motion inside the unfolded pop-up scene */
  @keyframes starTwinkle {
    0%, 100% { opacity: 0.45; transform: scale(0.86); }
    50% { opacity: 1; transform: scale(1.16); }
  }
  .twinkle-star {
    transform-box: fill-box;
    transform-origin: center;
    animation: starTwinkle 3.2s ease-in-out infinite;
  }
  .twinkle-star.d1 { animation-delay: 0.6s; animation-duration: 2.7s; }
  .twinkle-star.d2 { animation-delay: 1.4s; animation-duration: 3.6s; }
  .twinkle-star.d3 { animation-delay: 2.1s; animation-duration: 2.9s; }

  @keyframes moonHalo {
    0%, 100% { opacity: 0.28; transform: scale(0.98); }
    50% { opacity: 0.48; transform: scale(1.04); }
  }
  .moon-glow-ring {
    transform-box: fill-box;
    transform-origin: center;
    animation: moonHalo 4.8s ease-in-out infinite;
  }

  @keyframes heartSway {
    0%, 100% { transform: translateY(0px) rotate(-1.5deg); }
    50% { transform: translateY(-4px) rotate(2deg); }
  }
  .paper-heart-bob {
    transform-box: fill-box;
    transform-origin: center bottom;
    animation: heartSway 3.8s ease-in-out infinite;
  }
  .paper-heart-bob.h2 { animation-delay: 0.7s; animation-duration: 4.3s; }
  .paper-heart-bob.h3 { animation-delay: 1.5s; animation-duration: 3.4s; }

  @keyframes flowerBreath {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(1.4deg); }
  }
  .flower-cluster-l { transform-origin: 40px 280px; animation: flowerBreath 5.2s ease-in-out infinite; }
  .flower-cluster-r { transform-origin: 400px 280px; animation: flowerBreath 5.6s ease-in-out infinite reverse; }

  @keyframes catBreathe {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(1.018); }
  }
  #cats-couple {
    transform-origin: 220px 255px;
    animation: catBreathe 4.2s ease-in-out infinite;
    transition: transform 0.35s cubic-bezier(0.22, 1.4, 0.36, 1);
  }
  #popup-stage.cats-nuzzle #cats-couple {
    transform: scale(1.05) translateY(-2px);
  }

  .scene-tap-badge {
    position: absolute;
    bottom: 8px;
    right: 12px;
    z-index: 16;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(25, 7, 13, 0.52);
    border: 1px solid rgba(241, 211, 139, 0.32);
    color: rgba(251, 243, 228, 0.84);
    font-family: var(--font-ui);
    font-size: 10.5px;
    letter-spacing: 0.03em;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease 1.1s;
  }
  #popup-stage.unfolded .scene-tap-badge { opacity: 0.85; }

  /* Card Crease Fold Divider */
  .card-crease {
    height: 6px;
    width: 100%;
    background: linear-gradient(180deg, rgba(64, 24, 26, 0.24) 0%, rgba(255, 250, 240, 0.68) 45%, rgba(164, 114, 62, 0.08) 100%);
    flex-shrink: 0;
  }

  /* Lower Panel: Handwritten Letter Page */
  #letter-page {
    position: relative;
    padding: 20px 24px 24px;
    min-height: 218px;
    cursor: pointer;
  }

  #letter-body-wrap {
    position: relative;
    z-index: 2;
  }

  #letter-salutation {
    font-family: var(--font-hand);
    font-size: clamp(19px, 5vw, 23px);
    color: var(--paper-accent);
    margin: 0 0 10px;
    min-height: 1.4em;
    line-height: 1.4;
  }

  #letter-message {
    font-family: var(--font-hand);
    font-size: clamp(17px, 4.4vw, 20.5px);
    color: var(--paper-ink);
    line-height: 1.68;
    min-height: 74px;
    margin: 0 0 14px;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .hw-word {
    display: inline-block;
    white-space: pre;
  }
  .hw-char {
    display: inline-block;
    opacity: 0;
    transform: translateY(3px) scale(0.86) rotate(var(--r, 0deg));
    transition: opacity 0.22s ease, transform 0.28s cubic-bezier(0.22, 1.25, 0.36, 1);
    will-change: opacity, transform;
  }
  .hw-char.shown {
    opacity: 1;
    transform: translateY(var(--dy, 0px)) scale(1) rotate(var(--r, 0deg));
  }

  .letter-signoff {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-top: 8px;
  }
  #letter-closing {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 13.5px;
    color: var(--paper-ink-muted);
    margin-bottom: 2px;
    min-height: 1.3em;
  }
  #letter-signature {
    font-family: var(--font-hand);
    font-size: clamp(19px, 5vw, 23px);
    color: var(--paper-accent);
    min-height: 1.35em;
    line-height: 1.3;
  }
  .sig-flourish {
    width: 124px;
    height: 18px;
    margin-top: 2px;
    overflow: visible;
  }
  #sig-flourish-path {
    fill: none;
    stroke: var(--paper-gold);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 220;
    stroke-dashoffset: 220;
    transition: stroke-dashoffset 0.9s cubic-bezier(0.22, 1, 0.36, 1);
  }
  #sig-flourish-path.drawn {
    stroke-dashoffset: 0;
  }

  /* Animated Fountain Pen Nib */
  #ink-nib {
    position: absolute;
    top: 0;
    left: 0;
    width: 30px;
    height: 30px;
    z-index: 12;
    pointer-events: none;
    opacity: 0;
    transform: translate3d(0, 0, 0);
    transition: opacity 0.24s ease;
    filter: drop-shadow(0 3px 4px rgba(64, 20, 24, 0.26));
  }
  #ink-nib.writing {
    opacity: 1;
  }

  /* Bottom Controls Dock beneath the Open Card */
  #letter-actions {
    width: min(100%, 468px);
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.55s ease 0.5s, transform 0.55s ease 0.5s;
  }
  #view-letter.active #letter-actions {
    opacity: 1;
    transform: translateY(0);
  }

  .live-style-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(32, 9, 14, 0.58);
    border: 1px solid rgba(241, 211, 139, 0.25);
    backdrop-filter: blur(8px);
  }
  .live-style-label {
    font-family: var(--font-ui);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: rgba(241, 211, 139, 0.8);
    margin-right: 2px;
  }
  .mini-style-btn {
    min-height: 38px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1.5px solid transparent;
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  }
  .mini-style-btn:active { transform: scale(0.94); }
  .mini-style-btn[data-style="linen"] { background: #fbf4e6; color: #542329; }
  .mini-style-btn[data-style="rose"] { background: #fae9e4; color: #5c1c2c; }
  .mini-style-btn[data-style="gilded"] { background: #f5e5c4; color: #4f2814; }
  .mini-style-btn.selected {
    border-color: var(--gold-light);
    box-shadow: 0 0 0 2px rgba(207, 160, 73, 0.45);
  }

  .action-btn-row {
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    gap: 10px;
  }
  .action-btn-row .btn-primary {
    min-height: 50px;
    font-size: 16.5px;
    padding: 11px 16px;
  }

  /* ==================== DEMO MODE INDICATOR & SIMULATED TAP ==================== */
  #demo-banner {
    position: fixed;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    padding: 8px 16px;
    border-radius: 999px;
    background: rgba(24, 6, 10, 0.82);
    border: 1px solid rgba(241, 211, 139, 0.5);
    color: var(--gold-light);
    font-family: var(--font-ui);
    font-size: 12.5px;
    letter-spacing: 0.03em;
    display: none;
    align-items: center;
    gap: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    pointer-events: none;
    white-space: nowrap;
  }
  #demo-banner.visible {
    display: inline-flex;
  }
  .demo-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #e95360;
    box-shadow: 0 0 8px #e95360;
    animation: demoBlink 1.3s ease-in-out infinite;
  }
  @keyframes demoBlink {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
  }

  .sim-ripple {
    position: fixed;
    width: 54px;
    height: 54px;
    margin-left: -27px;
    margin-top: -27px;
    border-radius: 50%;
    border: 2.5px solid var(--gold-light);
    background: radial-gradient(circle, rgba(243, 210, 132, 0.45) 0%, transparent 70%);
    z-index: 48;
    pointer-events: none;
    animation: simRippleOut 0.72s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }
  @keyframes simRippleOut {
    0% { transform: scale(0.35); opacity: 1; }
    100% { transform: scale(1.9); opacity: 0; }
  }

  /* Compact adjustments for short mobile viewports */
  @media (max-height: 700px) {
    #compose-card { padding: 18px 18px 16px; }
    .compose-header { margin-bottom: 10px; }
    .field textarea { min-height: 78px; }
    .style-picker-wrap { margin: 10px 0 14px; }
    .style-option { min-height: 60px; }
    #letter-page { padding: 15px 18px 18px; min-height: 176px; }
  }
</style>
</head>
<body class="theme-linen">

<!-- Ambient Background Dust & Foreground Particle Canvases -->
<canvas id="ambient-canvas" aria-hidden="true"></canvas>
<canvas id="fx-canvas" aria-hidden="true"></canvas>

<!-- Desk Gold Corner Flourishes -->
<svg class="desk-ornament tl" viewBox="0 0 100 100" fill="none" aria-hidden="true">
  <path d="M8 92 V18 Q8 8 18 8 H92" stroke="#f1d38b" stroke-width="1.4"/>
  <path d="M16 74 V24 Q16 16 24 16 H74" stroke="#f1d38b" stroke-width="0.9" opacity="0.65"/>
  <path d="M8 38 C22 38 38 22 38 8" stroke="#f1d38b" stroke-width="1.1"/>
  <circle cx="24" cy="24" r="2.6" fill="#f1d38b"/>
</svg>
<svg class="desk-ornament tr" viewBox="0 0 100 100" fill="none" aria-hidden="true">
  <path d="M8 92 V18 Q8 8 18 8 H92" stroke="#f1d38b" stroke-width="1.4"/>
  <path d="M16 74 V24 Q16 16 24 16 H74" stroke="#f1d38b" stroke-width="0.9" opacity="0.65"/>
  <path d="M8 38 C22 38 38 22 38 8" stroke="#f1d38b" stroke-width="1.1"/>
  <circle cx="24" cy="24" r="2.6" fill="#f1d38b"/>
</svg>
<svg class="desk-ornament bl" viewBox="0 0 100 100" fill="none" aria-hidden="true">
  <path d="M8 92 V18 Q8 8 18 8 H92" stroke="#f1d38b" stroke-width="1.4"/>
  <path d="M16 74 V24 Q16 16 24 16 H74" stroke="#f1d38b" stroke-width="0.9" opacity="0.65"/>
  <path d="M8 38 C22 38 38 22 38 8" stroke="#f1d38b" stroke-width="1.1"/>
  <circle cx="24" cy="24" r="2.6" fill="#f1d38b"/>
</svg>
<svg class="desk-ornament br" viewBox="0 0 100 100" fill="none" aria-hidden="true">
  <path d="M8 92 V18 Q8 8 18 8 H92" stroke="#f1d38b" stroke-width="1.4"/>
  <path d="M16 74 V24 Q16 16 24 16 H74" stroke="#f1d38b" stroke-width="0.9" opacity="0.65"/>
  <path d="M8 38 C22 38 38 22 38 8" stroke="#f1d38b" stroke-width="1.1"/>
  <circle cx="24" cy="24" r="2.6" fill="#f1d38b"/>
</svg>

<!-- Top Bar -->
<header id="top-bar">
  <div style="display:flex;align-items:center;gap:8px;">
    <div id="brand-pill" class="top-pill">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true">
        <path d="M3 6.5A2.5 2.5 0 0 1 5.5 4h13A2.5 2.5 0 0 1 21 6.5v11a2.5 2.5 0 0 1-2.5 2.5h-13A2.5 2.5 0 0 1 3 17.5v-11Z" stroke="#f1d38b" stroke-width="1.7"/>
        <path d="M4 7l8 6 8-6" stroke="#f1d38b" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/>
      </svg>
      <span>Petite Post</span>
    </div>
    <button type="button" id="btn-back-edit" class="top-pill hidden" aria-label="Edit Letter">
      <svg width="15" height="15" viewBox="0 0 24 24" fill="none" aria-hidden="true">
        <path d="M15 5l4 4L8 20H4v-4L15 5Z" stroke="#f1d38b" stroke-width="1.9" stroke-linejoin="round"/>
      </svg>
      <span>Write</span>
    </button>
  </div>

  <button type="button" id="btn-sound" class="top-pill icon-only" aria-label="Toggle Sound" aria-pressed="true">
    <svg id="sound-icon-on" width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true">
      <path d="M11 5L6 9H3v6h3l5 4V5Z" stroke="#f1d38b" stroke-width="1.8" stroke-linejoin="round"/>
      <path d="M15.5 8.5a5 5 0 0 1 0 7" stroke="#f1d38b" stroke-width="1.8" stroke-linecap="round"/>
      <path d="M18.6 5.8a9 9 0 0 1 0 12.4" stroke="#f1d38b" stroke-width="1.8" stroke-linecap="round" opacity="0.72"/>
    </svg>
    <svg id="sound-icon-off" width="20" height="20" viewBox="0 0 24 24" fill="none" style="display:none;" aria-hidden="true">
      <path d="M11 5L6 9H3v6h3l5 4V5Z" stroke="#f1d38b" stroke-width="1.8" stroke-linejoin="round" opacity="0.65"/>
      <path d="M16 9l5 6M21 9l-5 6" stroke="#e97982" stroke-width="1.9" stroke-linecap="round"/>
    </svg>
  </button>
</header>

<main id="app">

  <!-- ==================== VIEW 1: COMPOSE LETTER ==================== -->
  <section id="view-compose" class="view active" aria-label="Write your love letter">
    <div id="compose-card" class="paper-sheet">
      <div class="paper-frame" aria-hidden="true"></div>

      <div class="compose-header">
        <div class="compose-title-block">
          <h1>Write a Love Letter</h1>
          <p>Our little cat postman will deliver it by hand.</p>
        </div>
        <div class="mini-stamp" aria-hidden="true">
          <!-- Tiny cat silhouette + heart stamp -->
          <svg width="36" height="40" viewBox="0 0 36 40" fill="none">
            <rect x="1.5" y="1.5" width="33" height="37" rx="2" fill="rgba(169,36,49,0.08)" stroke="rgba(169,36,49,0.28)" stroke-width="1"/>
            <path d="M18 11c-1.8-2.6-6-2-6 1.4 0 2.6 6 6.2 6 6.2s6-3.6 6-6.2c0-3.4-4.2-4-6-1.4Z" fill="#b82935"/>
            <path d="M11 32c0-4.2 3.1-7.2 7-7.2s7 3 7 7.2" stroke="#7d4a3a" stroke-width="1.7" stroke-linecap="round"/>
            <circle cx="18" cy="23.5" r="3.4" fill="#d99a5b"/>
            <path d="M15 21.5l-.8-2.6 2.5 1.3M21 21.5l.8-2.6-2.5 1.3" fill="#d99a5b"/>
            <path d="M14.5 21.4 Q18 18.8 21.5 21.4 L23 22 H14.5Z" fill="#2e659e"/>
          </svg>
        </div>
      </div>

      <div class="form-row">
        <div class="field">
          <label for="input-to">For</label>
          <input id="input-to" type="text" maxlength="32" placeholder="My love..." autocomplete="off">
        </div>
        <div class="field">
          <label for="input-from">From</label>
          <input id="input-from" type="text" maxlength="32" placeholder="Your name..." autocomplete="off">
        </div>
      </div>

      <div class="field">
        <label for="input-msg">Your Message</label>
        <textarea id="input-msg" rows="3" maxlength="220" placeholder="Write a few sweet words..."></textarea>
        <div class="msg-meta">
          <div class="idea-chips" aria-label="Quick note inspirations">
            <button type="button" class="idea-chip" data-msg="Meet me under the silver moon. My favorite place in the whole world is right beside you.">Moonlight</button>
            <button type="button" class="idea-chip" data-msg="Just a tiny note to remind you how deeply you brighten my ordinary days. Always yours.">Sweet Note</button>
            <button type="button" class="idea-chip" data-msg="Thank you for every warm laugh, gentle look, and quiet moment we share together.">Thank You</button>
          </div>
          <span id="char-count">0 / 220</span>
        </div>
      </div>

      <div class="style-picker-wrap">
        <span class="style-picker-label">Paper Style</span>
        <div class="style-grid" role="radiogroup" aria-label="Choose paper style">
          <button type="button" class="style-option selected" data-style="linen" role="radio" aria-checked="true">
            <div class="style-swatch-seal">
              <svg width="12" height="12" viewBox="0 0 24 24" fill="#f7dca0" aria-hidden="true">
                <path d="M12 20.5s-7.5-4.7-9.4-9.1C1 7.6 3.7 4 7.4 4c2.1 0 3.7 1.1 4.6 2.6C12.9 5.1 14.5 4 16.6 4c3.7 0 6.4 3.6 4.8 7.4-1.9 4.4-9.4 9.1-9.4 9.1Z"/>
              </svg>
            </div>
            <span>Cream Linen</span>
          </button>
          <button type="button" class="style-option" data-style="rose" role="radio" aria-checked="false">
            <div class="style-swatch-seal">
              <svg width="12" height="12" viewBox="0 0 24 24" fill="#f9dec2" aria-hidden="true">
                <path d="M12 20.5s-7.5-4.7-9.4-9.1C1 7.6 3.7 4 7.4 4c2.1 0 3.7 1.1 4.6 2.6C12.9 5.1 14.5 4 16.6 4c3.7 0 6.4 3.6 4.8 7.4-1.9 4.4-9.4 9.1-9.4 9.1Z"/>
              </svg>
            </div>
            <span>Rose Velvet</span>
          </button>
          <button type="button" class="style-option" data-style="gilded" role="radio" aria-checked="false">
            <div class="style-swatch-seal">
              <svg width="12" height="12" viewBox="0 0 24 24" fill="#fff5d4" aria-hidden="true">
                <path d="M12 20.5s-7.5-4.7-9.4-9.1C1 7.6 3.7 4 7.4 4c2.1 0 3.7 1.1 4.6 2.6C12.9 5.1 14.5 4 16.6 4c3.7 0 6.4 3.6 4.8 7.4-1.9 4.4-9.4 9.1-9.4 9.1Z"/>
              </svg>
            </div>
            <span>Gilded Gold</span>
          </button>
        </div>
      </div>

      <button type="button" id="btn-send" class="btn-primary">
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true">
          <path d="M3 6.8A2.8 2.8 0 0 1 5.8 4h12.4A2.8 2.8 0 0 1 21 6.8v10.4a2.8 2.8 0 0 1-2.8 2.8H5.8A2.8 2.8 0 0 1 3 17.2V6.8Z" stroke="#f7dca0" stroke-width="1.8"/>
          <path d="M4.2 7l7.8 5.8L19.8 7" stroke="#f7dca0" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
        </svg>
        <span>Send Letter</span>
      </button>
    </div>
  </section>

  <!-- ==================== VIEW 2: CAT POSTMAN DELIVERY ==================== -->
  <section id="view-delivery" class="view" aria-label="Cat postman delivering your envelope">
    <div id="delivery-stage">
      <div id="delivery-status" class="delivery-status">A little postman is on the way...</div>
      <div class="delivery-path" aria-hidden="true"></div>

      <!-- Animated Cat Postman in Blue Cap -->
      <div id="cat-postman-wrap" aria-hidden="true">
        <svg id="cat-postman-svg" viewBox="0 0 185 155" fill="none">
          <defs>
            <linearGradient id="catFur" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0%" stop-color="#f7d9b0"/>
              <stop offset="65%" stop-color="#eab67e"/>
              <stop offset="100%" stop-color="#d59457"/>
            </linearGradient>
            <linearGradient id="catFurDark" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0%" stop-color="#df9e62"/>
              <stop offset="100%" stop-color="#ba753c"/>
            </linearGradient>
            <linearGradient id="capBlue" x1="0" y1="0" x2="1" y2="1">
              <stop offset="0%" stop-color="#4e8ecc"/>
              <stop offset="55%" stop-color="#2e679f"/>
              <stop offset="100%" stop-color="#1e4873"/>
            </linearGradient>
            <linearGradient id="satchelLeather" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0%" stop-color="#9e4835"/>
              <stop offset="100%" stop-color="#6b281c"/>
            </linearGradient>
          </defs>

          <!-- Happy heart bubble when saluting -->
          <g id="cat-love-bubble">
            <circle cx="127" cy="15" r="12" fill="#fbf3e4" stroke="#d8a74a" stroke-width="1.4"/>
            <path d="M127 20.6s-5.4-3.4-6.7-6.5c-1.1-2.6.8-5.1 3.3-5.1 1.5 0 2.7.8 3.4 1.9.7-1.1 1.9-1.9 3.4-1.9 2.5 0 4.4 2.5 3.3 5.1-1.3 3.1-6.7 6.5-6.7 6.5Z" fill="#c42b38"/>
          </g>

          <!-- Soft ground shadow -->
          <ellipse cx="86" cy="141" rx="46" ry="7" fill="rgba(16, 3, 6, 0.36)"/>

          <!-- Tail -->
          <g id="cat-tail">
            <path d="M46 95 C22 89 15 58 31 48 C41 42 47 51 39 58" stroke="#d99457" stroke-width="11" stroke-linecap="round" fill="none"/>
            <path d="M27 65 C25 60 28 53 33 50" stroke="#f7e2c4" stroke-width="4.5" stroke-linecap="round" fill="none" opacity="0.72"/>
            <path d="M26 78 l7-2 M23 68 l7-1" stroke="#a66230" stroke-width="2.4" stroke-linecap="round" opacity="0.6"/>
          </g>

          <!-- Far legs (behind body) -->
          <g id="cat-paw-bl">
            <path d="M56 106 L53 133 C53 137 61 138 64 134 L65 107 Z" fill="url(#catFurDark)"/>
            <ellipse cx="59" cy="135" rx="6.5" ry="4" fill="#f9ebd6"/>
          </g>
          <g id="cat-paw-fl">
            <path d="M96 106 L95 133 C95 137 103 138 106 134 L105 107 Z" fill="url(#catFurDark)"/>
            <ellipse cx="101" cy="135" rx="6.5" ry="4" fill="#f9ebd6"/>
          </g>

          <!-- Plump cat body -->
          <ellipse cx="79" cy="98" rx="34" ry="22" fill="url(#catFur)"/>
          <!-- Soft cream belly -->
          <ellipse cx="84" cy="107" rx="22" ry="11" fill="#fdf1df" opacity="0.88"/>
          <!-- Gentle tabby back stripes -->
          <path d="M63 79 Q66 86 64 90 M74 77 Q77 85 75 89 M85 78 Q87 84 85 88" stroke="#ba763c" stroke-width="3" stroke-linecap="round" opacity="0.58"/>

          <!-- Postman's Crossbody Satchel -->
          <path d="M96 81 Q82 95 72 103" stroke="#7c2e20" stroke-width="4.5" stroke-linecap="round"/>
          <g transform="rotate(-7 74 99)">
            <!-- Little envelope peeking out -->
            <rect x="65" y="87" width="16" height="11" rx="1.5" fill="#fbf3e4" stroke="#cfa049" stroke-width="1"/>
            <path d="M66 88 l7 5 7-5" stroke="#b82935" stroke-width="1" fill="none"/>
            <!-- Leather bag -->
            <rect x="60" y="92" width="26" height="20" rx="4.5" fill="url(#satchelLeather)" stroke="#4f1b13" stroke-width="1.2"/>
            <path d="M60 95 Q73 105 86 95" fill="#b45640" stroke="#4f1b13" stroke-width="1.1"/>
            <rect x="70.5" y="99" width="5" height="5" rx="1.2" fill="#f2cf7e" stroke="#855a16" stroke-width="0.8"/>
          </g>

          <!-- Near legs (front of body) -->
          <g id="cat-paw-br">
            <path d="M63 107 L61 135 C61 139 69 140 72 135 L73 108 Z" fill="url(#catFur)"/>
            <ellipse cx="67" cy="136.5" rx="7" ry="4.2" fill="#fff4e4"/>
          </g>
          <g id="cat-paw-fr">
            <path d="M102 107 L101 135 C101 139 109 140 112 135 L112 108 Z" fill="url(#catFur)"/>
            <ellipse cx="107" cy="136.5" rx="7" ry="4.2" fill="#fff4e4"/>
          </g>

          <!-- Salute paw (visible when tipping blue cap!) -->
          <g id="cat-paw-salute" style="opacity:0; transition: opacity 0.25s ease, transform 0.35s cubic-bezier(0.22,1.3,0.36,1);">
            <path d="M107 95 C119 85 130 68 136 53" stroke="#eab67e" stroke-width="9" stroke-linecap="round" fill="none"/>
            <circle cx="136" cy="52" r="5.5" fill="#fff4e4"/>
          </g>

          <!-- Cat Head -->
          <g id="cat-head-group">
            <!-- Far ear -->
            <path d="M119 46 L128 29 L135 49 Z" fill="#df9e62" stroke="#b8743a" stroke-width="1" stroke-linejoin="round"/>
            <path d="M123 44 L128 34 L132 46 Z" fill="#f3b6b2"/>
            <!-- Main round head -->
            <ellipse cx="113" cy="69" rx="26.5" ry="23.5" fill="url(#catFur)"/>
            <!-- Cream muzzle & cheeks -->
            <ellipse cx="123" cy="76" rx="14" ry="10.5" fill="#fdf1df"/>
            <!-- Near ear -->
            <path d="M92 52 L88 31 L107 44 Z" fill="#efb982" stroke="#ba763c" stroke-width="1" stroke-linejoin="round"/>
            <path d="M93 48 L91 36 L102 44 Z" fill="#f3b6b2"/>

            <!-- Rosy blush cheeks -->
            <ellipse cx="106" cy="76" rx="4.6" ry="2.8" fill="#e9848c" opacity="0.52"/>
            <ellipse cx="134" cy="76" rx="3.8" ry="2.4" fill="#e9848c" opacity="0.46"/>

            <!-- Open bright eyes -->
            <g id="cat-eyes-open">
              <ellipse cx="111" cy="66" rx="3.7" ry="4.4" fill="#2c1718"/>
              <circle cx="112.4" cy="64.5" r="1.4" fill="#fff"/>
              <ellipse cx="128.5" cy="66" rx="3.4" ry="4.2" fill="#2c1718"/>
              <circle cx="129.8" cy="64.5" r="1.3" fill="#fff"/>
            </g>
            <!-- Happy crescent eyes when saluting -->
            <g id="cat-eyes-happy" style="display:none;">
              <path d="M107 67 Q111 61.5 115 67" stroke="#2c1718" stroke-width="2.4" stroke-linecap="round" fill="none"/>
              <path d="M125 67 Q128.5 61.5 132 67" stroke="#2c1718" stroke-width="2.4" stroke-linecap="round" fill="none"/>
            </g>

            <!-- Cute nose & mouth -->
            <path d="M120 71.5 L125.5 71.5 L122.8 75 Z" fill="#d96b75"/>
            <path d="M122.8 75 Q120 78.5 117.2 77.2 M122.8 75 Q125.5 78.5 128.2 77.2" stroke="#5c2f2a" stroke-width="1.5" stroke-linecap="round" fill="none"/>

            <!-- Delicate whiskers -->
            <g stroke="#7a4c38" stroke-width="1.2" stroke-linecap="round" opacity="0.65">
              <path d="M103 73 L91 71 M103 76.5 L90 78"/>
              <path d="M135 73 L146 71 M135 76.5 L146 78"/>
            </g>

            <!-- POSTMAN BLUE CAP (Crisp blue peaked cap with gold band & heart emblem) -->
            <g id="cat-cap-group">
              <!-- Cap crown -->
              <path d="M93 48 C94 31 124 27 134 45 L136 51 L93 52 Z" fill="url(#capBlue)" stroke="#183a5c" stroke-width="1.2" stroke-linejoin="round"/>
              <!-- Soft blue highlight -->
              <path d="M101 38 C108 33 119 33 126 38" stroke="#85bdf0" stroke-width="2" stroke-linecap="round" opacity="0.55"/>
              <!-- Gold ribbon band -->
              <path d="M93.5 48.5 Q115 44.5 136 48.5 L136 52 Q115 48.2 93.5 52 Z" fill="#ecc15d"/>
              <!-- Glossy peaked visor brim -->
              <path d="M108 50 Q131 45 148 53 Q133 58 111 53 Z" fill="#1a3f66" stroke="#122d4a" stroke-width="1"/>
              <path d="M119 50.5 Q133 49 143 52.5" stroke="#5a94c9" stroke-width="1.1" stroke-linecap="round" opacity="0.5"/>
              <!-- Gold postal badge on front of cap -->
              <circle cx="118" cy="42.5" r="4.8" fill="#f3d284" stroke="#9d6f22" stroke-width="1"/>
              <path d="M118 44.8s-2.2-1.4-2.7-2.6c-.4-1 .3-2 1.3-2 .6 0 1.1.3 1.4.8.3-.5.8-.8 1.4-.8 1 0 1.7 1 1.3 2-.5 1.2-2.7 2.6-2.7 2.6Z" fill="#b82935"/>
            </g>
          </g>

          <!-- Carried Sealed Envelope -->
          <g id="cat-held-envelope" transform="translate(128, 76) rotate(-7)">
            <rect id="cat-env-rect" x="0" y="0" width="44" height="30" rx="4" fill="#fbf4e6" stroke="#c99438" stroke-width="1.5"/>
            <path d="M1.5 2 L22 17 L42.5 2" stroke="#c99438" stroke-width="1.3" fill="rgba(220,192,150,0.28)" stroke-linejoin="round"/>
            <path d="M1.5 28 L16 14.5 M42.5 28 L28 14.5" stroke="#c99438" stroke-width="1" opacity="0.55"/>
            <circle id="cat-env-seal" cx="22" cy="16" r="4.4" fill="#b82935" stroke="#f3d284" stroke-width="1"/>
          </g>
        </svg>
      </div>

      <!-- Sealed Envelope Left in Front of You -->
      <div id="envelope-zone">
        <button type="button" id="waiting-envelope" aria-label="Tap to open your love letter">
          <div class="env-body">
            <!-- Peeking folded letter card -->
            <div id="env-peek-card" aria-hidden="true">
              <svg width="36" height="24" viewBox="0 0 36 24" fill="none">
                <path d="M18 19s-6.8-4.2-8.4-8.2C8.2 7.4 10.6 4.2 14 4.2c1.9 0 3.3 1 4 2.4.7-1.4 2.1-2.4 4-2.4 3.4 0 5.8 3.2 4.4 6.6-1.6 4-8.4 8.2-8.4 8.2Z" fill="var(--paper-accent)" opacity="0.88"/>
              </svg>
            </div>

            <!-- Envelope Pocket (left, right, bottom folds) -->
            <svg class="env-pocket-svg" viewBox="0 0 340 236" preserveAspectRatio="none" aria-hidden="true">
              <defs>
                <linearGradient id="envPocketGrad" x1="0" y1="0" x2="0" y2="1">
                  <stop offset="0%" stop-color="var(--paper-bg)"/>
                  <stop offset="100%" stop-color="var(--env-pocket-bg)"/>
                </linearGradient>
              </defs>
              <!-- Left side fold -->
              <polygon points="0,0 170,126 0,236" fill="var(--paper-bg-2)"/>
              <!-- Right side fold -->
              <polygon points="340,0 170,126 340,236" fill="var(--paper-bg-2)"/>
              <!-- Bottom fold pocket -->
              <path d="M0,236 L146,116 Q170,98 194,116 L340,236 Z" fill="url(#envPocketGrad)"/>
              <!-- Crisp gold seams -->
              <path d="M0,236 L146,116 Q170,98 194,116 L340,236" fill="none" stroke="var(--paper-gold)" stroke-width="1.4" opacity="0.62"/>
              <line x1="0" y1="0" x2="146" y2="116" stroke="var(--paper-gold)" stroke-width="1" opacity="0.38"/>
              <line x1="340" y1="0" x2="194" y2="116" stroke="var(--paper-gold)" stroke-width="1" opacity="0.38"/>
              <!-- Outer refined border -->
              <rect x="2" y="2" width="336" height="232" rx="11" fill="none" stroke="var(--paper-gold)" stroke-width="1.8" opacity="0.72"/>
              <!-- Tiny charming postal cat-paw postmark in bottom-right -->
              <g transform="translate(274, 174) rotate(-8)" opacity="0.46" stroke="var(--paper-accent)" fill="var(--paper-accent)">
                <circle cx="22" cy="22" r="20" fill="none" stroke-width="1.3" stroke-dasharray="3 2"/>
                <circle cx="22" cy="24" r="4.5" stroke="none"/>
                <circle cx="15.5" cy="17.5" r="2.2" stroke="none"/>
                <circle cx="22" cy="15.5" r="2.2" stroke="none"/>
                <circle cx="28.5" cy="17.5" r="2.2" stroke="none"/>
              </g>
            </svg>

            <!-- Recipient Name on Envelope -->
            <div class="env-front-details">
              <div class="env-for-tag">Specially Delivered For</div>
              <div id="env-to-label">My Love</div>
            </div>

            <!-- Top Hinged Flap + Wax Seal -->
            <div id="env-flap">
              <svg viewBox="0 0 340 142" preserveAspectRatio="none" aria-hidden="true">
                <path d="M0,10 Q0,0 10,0 L330,0 Q340,0 340,10 L186,128 Q170,140 154,128 Z" fill="var(--env-flap-bg)" stroke="var(--paper-gold)" stroke-width="1.6"/>
                <path d="M16,9 L170,122 L324,9" fill="none" stroke="var(--paper-gold)" stroke-width="1" opacity="0.48"/>
              </svg>
              <div id="env-wax-seal">
                <svg width="24" height="24" viewBox="0 0 24 24" fill="var(--seal-rim)" aria-hidden="true">
                  <path d="M12 20.5s-7.5-4.7-9.4-9.1C1 7.6 3.7 4 7.4 4c2.1 0 3.7 1.1 4.6 2.6C12.9 5.1 14.5 4 16.6 4c3.7 0 6.4 3.6 4.8 7.4-1.9 4.4-9.4 9.1-9.4 9.1Z"/>
                </svg>
              </div>
            </div>
          </div>
        </button>

        <div id="env-tap-hint">Tap the envelope to open</div>
      </div>
    </div>
  </section>

  <!-- ==================== VIEW 3: POP-UP SCENE & HANDWRITTEN LETTER ==================== -->
  <section id="view-letter" class="view" aria-label="Your pop-up love letter">
    <article id="popup-card" class="paper-sheet">

      <!-- Upper Half: 7-Layer 3D Paper Pop-Up Book Diorama -->
      <div id="popup-stage" role="button" tabindex="0" aria-label="Paper pop-up scene of two cats under the moon. Tap for floating hearts.">
        <div class="stage-paper-mat" aria-hidden="true"></div>
        <div id="popup-parallax">

          <!-- Layer 1: Twilight Sky Arch & Twinkling Gold Stars -->
          <div class="popup-layer layer-sky">
            <svg viewBox="0 0 440 280" preserveAspectRatio="xMidYMid meet">
              <defs>
                <linearGradient id="nightSkyGrad" x1="0" y1="0" x2="0" y2="1">
                  <stop offset="0%" stop-color="#1a0d22"/>
                  <stop offset="48%" stop-color="#3a162d"/>
                  <stop offset="100%" stop-color="#6b2436"/>
                </linearGradient>
                <radialGradient id="moonAmbientGlow" cx="50%" cy="42%" r="46%">
                  <stop offset="0%" stop-color="#ffe7ad" stop-opacity="0.34"/>
                  <stop offset="55%" stop-color="#d97b59" stop-opacity="0.12"/>
                  <stop offset="100%" stop-color="#2a0f22" stop-opacity="0"/>
                </radialGradient>
              </defs>
              <rect x="0" y="0" width="440" height="280" fill="url(#nightSkyGrad)"/>
              <rect x="0" y="0" width="440" height="280" fill="url(#moonAmbientGlow)"/>

              <!-- Gold Filigree Arch Frame -->
              <path d="M18 280 L18 112 C18 32 100 18 220 18 C340 18 422 32 422 112 L422 280" fill="none" stroke="#e9c16c" stroke-width="1.6" opacity="0.52"/>
              <path d="M26 280 L26 115 C26 42 104 26 220 26 C336 26 414 42 414 115 L414 280" fill="none" stroke="#e9c16c" stroke-width="0.9" stroke-dasharray="4 5" opacity="0.38"/>

              <!-- Gold-Foil Twinkling Stars -->
              <g fill="#f7de9c">
                <path class="twinkle-star" d="M68 54 L70 61 L77 63 L70 65 L68 72 L66 65 L59 63 L66 61 Z"/>
                <path class="twinkle-star d1" d="M366 50 L368 56 L374 58 L368 60 L366 66 L364 60 L358 58 L364 56 Z"/>
                <path class="twinkle-star d2" d="M114 40 L115.5 44.5 L120 46 L115.5 47.5 L114 52 L112.5 47.5 L108 46 L112.5 44.5 Z"/>
                <path class="twinkle-star d3" d="M322 44 L323.5 48.5 L328 50 L323.5 51.5 L322 56 L320.5 51.5 L316 50 L320.5 48.5 Z"/>
                <path class="twinkle-star d1" d="M52 116 L53.5 120 L57.5 121.5 L53.5 123 L52 127 L50.5 123 L46.5 121.5 L50.5 120 Z"/>
                <path class="twinkle-star d2" d="M388 112 L389.5 116 L393.5 117.5 L389.5 119 L388 123 L386.5 119 L382.5 117.5 L386.5 116 Z"/>
                <circle cx="94" cy="96" r="1.8" opacity="0.72"/>
                <circle cx="152" cy="58" r="1.5" opacity="0.68"/>
                <circle cx="290" cy="54" r="1.7" opacity="0.72"/>
                <circle cx="348" cy="96" r="1.9" opacity="0.65"/>
                <circle cx="78" cy="144" r="1.5" opacity="0.55"/>
                <circle cx="364" cy="140" r="1.6" opacity="0.58"/>
              </g>
            </svg>
          </div>

          <!-- Layer 2: Luminous Paper-Cut Moon & Drifting Cutout Clouds -->
          <div class="popup-layer layer-moon">
            <svg viewBox="0 0 440 280" preserveAspectRatio="xMidYMid meet">
              <defs>
                <radialGradient id="paperMoonFill" cx="42%" cy="38%" r="60%">
                  <stop offset="0%" stop-color="#fffdf4"/>
                  <stop offset="68%" stop-color="#fae4b0"/>
                  <stop offset="100%" stop-color="#e5b864"/>
                </radialGradient>
              </defs>
              <!-- Concentric cut-paper gold halo rings -->
              <circle class="moon-glow-ring" cx="220" cy="116" r="82" fill="none" stroke="#f5d58c" stroke-width="1.2" opacity="0.3"/>
              <circle class="moon-glow-ring" cx="220" cy="116" r="68" fill="#ffe7b0" opacity="0.14"/>
              <!-- Main layered cream-and-gold paper moon -->
              <circle cx="220" cy="116" r="56" fill="url(#paperMoonFill)" stroke="#fff4d6" stroke-width="1.5"/>
              <!-- Subtle embossed paper moon craters -->
              <circle cx="201" cy="98" r="9.5" fill="#e4be73" opacity="0.28"/>
              <circle cx="242" cy="108" r="12" fill="#e4be73" opacity="0.22"/>
              <circle cx="212" cy="134" r="6.5" fill="#e4be73" opacity="0.24"/>
              <circle cx="234" cy="85" r="5" fill="#e4be73" opacity="0.2"/>
              <!-- Soft cut-paper clouds -->
              <path d="M98 152 Q108 136 126 141 Q138 130 154 140 Q168 140 172 152 Z" fill="#f7e2c8" opacity="0.26"/>
              <path d="M276 138 Q288 124 306 129 Q319 120 334 130 Q346 131 350 138 Z" fill="#f7e2c8" opacity="0.24"/>
            </svg>
          </div>

          <!-- Layer 3: Rolling Paper-Cut Twilight Hills -->
          <div class="popup-layer layer-hills">
            <svg viewBox="0 0 440 280" preserveAspectRatio="xMidYMid meet">
              <defs>
                <linearGradient id="farHillGrad" x1="0" y1="0" x2="0" y2="1">
                  <stop offset="0%" stop-color="#5d2033"/>
                  <stop offset="100%" stop-color="#38111e"/>
                </linearGradient>
                <linearGradient id="midHillGrad" x1="0" y1="0" x2="0" y2="1">
                  <stop offset="0%" stop-color="#7c2839"/>
                  <stop offset="100%" stop-color="#481422"/>
                </linearGradient>
              </defs>
              <!-- Far paper hill -->
              <path d="M0 280 L0 210 Q108 172 224 198 Q336 222 440 184 L440 280 Z" fill="url(#farHillGrad)"/>
              <path d="M0 210 Q108 172 224 198 Q336 222 440 184" fill="none" stroke="#e4b765" stroke-width="1.2" opacity="0.35"/>
              <!-- Mid paper hill -->
              <path d="M0 280 L0 232 Q115 202 220 202 Q325 202 440 234 L440 280 Z" fill="url(#midHillGrad)"/>
              <path d="M0 232 Q115 202 220 202 Q325 202 440 234" fill="none" stroke="#f0cc7f" stroke-width="1.3" opacity="0.44"/>
            </svg>
          </div>

          <!-- Layer 4: Foreground Hill Crest & Two Cats Sitting Together Under the Moon -->
          <div class="popup-layer layer-cats">
            <svg viewBox="0 0 440 280" preserveAspectRatio="xMidYMid meet">
              <defs>
                <linearGradient id="hillFrontGrad" x1="0" y1="0" x2="0" y2="1">
                  <stop offset="0%" stop-color="#5a1828"/>
                  <stop offset="100%" stop-color="#2e0b15"/>
                </linearGradient>
                <linearGradient id="catLeftBody" x1="0" y1="0" x2="1" y2="1">
                  <stop offset="0%" stop-color="#f8d8a8"/>
                  <stop offset="55%" stop-color="#e5ae73"/>
                  <stop offset="100%" stop-color="#c6834b"/>
                </linearGradient>
                <linearGradient id="catRightBody" x1="1" y1="0" x2="0" y2="1">
                  <stop offset="0%" stop-color="#8b3b44"/>
                  <stop offset="55%" stop-color="#5d202b"/>
                  <stop offset="100%" stop-color="#3c111b"/>
                </linearGradient>
              </defs>

              <!-- Cozy central paper-cut mound -->
              <path d="M72 280 Q220 198 368 280 Z" fill="url(#hillFrontGrad)"/>
              <path d="M78 278 Q220 200 362 278" fill="none" stroke="#f1cf84" stroke-width="1.4" opacity="0.45"/>

              <!-- TWO CATS SITTING TOGETHER UNDER THE MOON -->
              <g id="cats-couple">
                <!-- Left Cat (Warm Cream-Ginger Tabby, leaning lovingly right) -->
                <g>
                  <!-- Seated body -->
                  <path d="M181 244 C178 219 187 199 203 199 C216 199 221 215 220 244 Z" fill="url(#catLeftBody)" stroke="#fff0cf" stroke-width="1.2"/>
                  <!-- Soft tabby back stripes -->
                  <path d="M185 215 Q194 213 200 216 M183 224 Q193 222 199 225 M184 233 Q193 231 198 234" stroke="#bd7a42" stroke-width="2" stroke-linecap="round" opacity="0.52"/>
                  <!-- Head leaning gently right -->
                  <g transform="rotate(8 202 186)">
                    <!-- Ears -->
                    <path d="M188 176 L186 160 L199 171 Z" fill="#efc088" stroke="#fff0cf" stroke-width="1.1" stroke-linejoin="round"/>
                    <path d="M204 170 L215 160 L216 177 Z" fill="#e6ae73" stroke="#fff0cf" stroke-width="1.1" stroke-linejoin="round"/>
                    <path d="M189.5 173 L188.5 164.5 L196 171 Z" fill="#e99a98" opacity="0.72"/>
                    <path d="M206.5 170.5 L213 164.5 L213.5 174 Z" fill="#e99a98" opacity="0.72"/>
                    <!-- Round head -->
                    <ellipse cx="202" cy="186" rx="16.5" ry="15" fill="url(#catLeftBody)" stroke="#fff0cf" stroke-width="1.2"/>
                    <!-- Soft happy face looking gently right -->
                    <path d="M198 186 Q201.5 182.5 205 186" stroke="#5c2a22" stroke-width="1.6" stroke-linecap="round" fill="none"/>
                    <path d="M208 186.5 Q211 183.2 214 186.5" stroke="#5c2a22" stroke-width="1.6" stroke-linecap="round" fill="none"/>
                    <ellipse cx="195" cy="190" rx="2.8" ry="1.7" fill="#e47c84" opacity="0.5"/>
                    <path d="M205.5 189.5 L208.5 189.5 L207 191.5 Z" fill="#cf6570"/>
                  </g>
                </g>

                <!-- Right Cat (Warm Velvet Cocoa-Rose Cat, leaning affectionately left) -->
                <g>
                  <!-- Seated body -->
                  <path d="M220 244 C219 216 226 201 239 201 C254 201 261 220 258 244 Z" fill="url(#catRightBody)" stroke="#f8d8be" stroke-width="1.2"/>
                  <!-- Delicate cream chest patch -->
                  <ellipse cx="235" cy="222" rx="7" ry="11" fill="#f5dfca" opacity="0.22"/>
                  <!-- Gold collar ribbon -->
                  <path d="M225 204 Q238 209 251 204" stroke="#ecc05f" stroke-width="2.3" stroke-linecap="round" fill="none"/>
                  <circle cx="236" cy="208" r="2.2" fill="#f7de9c"/>
                  <!-- Head leaning lovingly left onto Left Cat -->
                  <g transform="rotate(-10 238 189)">
                    <!-- Ears -->
                    <path d="M224 180 L224 164 L236 175 Z" fill="#7c313b" stroke="#f8d8be" stroke-width="1.1" stroke-linejoin="round"/>
                    <path d="M241 175 L252 165 L252 181 Z" fill="#6b2630" stroke="#f8d8be" stroke-width="1.1" stroke-linejoin="round"/>
                    <path d="M226 177 L226 168.5 L233 175 Z" fill="#d9878f" opacity="0.65"/>
                    <path d="M243 175 L249.5 169 L249.5 178 Z" fill="#d9878f" opacity="0.65"/>
                    <!-- Round head -->
                    <ellipse cx="238" cy="189" rx="15.5" ry="14.2" fill="url(#catRightBody)" stroke="#f8d8be" stroke-width="1.2"/>
                    <!-- Happy closed eyes -->
                    <path d="M227 189 Q230 185.6 233 189" stroke="#f8dcc4" stroke-width="1.6" stroke-linecap="round" fill="none"/>
                    <path d="M236 188.5 Q239.2 185.2 242.5 188.5" stroke="#f8dcc4" stroke-width="1.6" stroke-linecap="round" fill="none"/>
                    <ellipse cx="244.5" cy="192.5" rx="2.6" ry="1.6" fill="#eb8a94" opacity="0.48"/>
                    <path d="M232.5 192 L235.5 192 L234 193.8 Z" fill="#f2a2a8"/>
                  </g>
                </g>

                <!-- TWO TAILS CURLED TOGETHER FORMING A HEART -->
                <g stroke-linecap="round" fill="none">
                  <!-- Soft dark paper outline behind tails -->
                  <path d="M206 243 C194 233 172 237 176 252 C179 263 203 265 220 273" stroke="#2c0912" stroke-width="8.5" opacity="0.5"/>
                  <path d="M234 243 C246 233 268 237 264 252 C261 263 237 265 220 273" stroke="#2c0912" stroke-width="8.5" opacity="0.5"/>
                  <!-- Left cat's golden-cream tail -->
                  <path d="M206 243 C194 233 172 237 176 252 C179 263 203 265 220 273" stroke="#eab479" stroke-width="5.6"/>
                  <path d="M206 243 C194 233 172 237 176 252 C179 263 203 265 220 273" stroke="#fff1d1" stroke-width="1.4" opacity="0.72"/>
                  <!-- Right cat's warm cocoa-rose tail -->
                  <path d="M234 243 C246 233 268 237 264 252 C261 263 237 265 220 273" stroke="#7c303a" stroke-width="5.6"/>
                  <path d="M234 243 C246 233 268 237 264 252 C261 263 237 265 220 273" stroke="#f7d7bf" stroke-width="1.4" opacity="0.65"/>
                </g>
              </g>
            </svg>
          </div>

          <!-- Layer 5: Sculpted Folded-Paper Hearts Floating & Popping Up -->
          <div class="popup-layer layer-hearts">
            <svg viewBox="0 0 440 280" preserveAspectRatio="xMidYMid meet">
              <!-- Delicate thin gold stems / pop-up wires -->
              <path d="M220 176 Q220 162 220 151" stroke="#f3d284" stroke-width="1" stroke-dasharray="2 3" opacity="0.55" fill="none"/>

              <!-- Center Hero Folded-Paper Heart right above the two cats -->
              <g class="paper-heart-bob" transform="translate(220, 143)">
                <!-- Left bright folded half -->
                <path d="M0 15 C-11 8 -18 0 -17 -7 C-16 -14 -8 -17 -2 -11 L0 -8.5 Z" fill="#dc3d4b"/>
                <!-- Right shaded folded half -->
                <path d="M0 15 C11 8 18 0 17 -7 C16 -14 8 -17 2 -11 L0 -8.5 Z" fill="#a9212f"/>
                <!-- Gold paper rim & center fold highlight -->
                <path d="M0 15 C-11 8 -18 0 -17 -7 C-16 -14 -8 -17 -2 -11 L0 -8.5 L2 -11 C8 -17 16 -14 17 -7 C18 0 11 8 0 15 Z" fill="none" stroke="#f6d994" stroke-width="1.3"/>
                <line x1="0" y1="-8.5" x2="0" y2="14.5" stroke="#ffbec4" stroke-width="0.9" opacity="0.72"/>
              </g>

              <!-- Upper-left Gold Foil Folded Heart -->
              <g class="paper-heart-bob h2" transform="translate(132, 92) rotate(-14) scale(0.76)">
                <path d="M0 15 C-11 8 -18 0 -17 -7 C-16 -14 -8 -17 -2 -11 L0 -8.5 Z" fill="#f3d388"/>
                <path d="M0 15 C11 8 18 0 17 -7 C16 -14 8 -17 2 -11 L0 -8.5 Z" fill="#c99130"/>
                <line x1="0" y1="-8.5" x2="0" y2="14.5" stroke="#fff6d9" stroke-width="1" opacity="0.8"/>
              </g>

              <!-- Upper-right Crimson Folded Heart -->
              <g class="paper-heart-bob h3" transform="translate(309, 88) rotate(14) scale(0.82)">
                <path d="M0 15 C-11 8 -18 0 -17 -7 C-16 -14 -8 -17 -2 -11 L0 -8.5 Z" fill="#d43544"/>
                <path d="M0 15 C11 8 18 0 17 -7 C16 -14 8 -17 2 -11 L0 -8.5 Z" fill="#991a28"/>
                <path d="M0 15 C-11 8 -18 0 -17 -7 C-16 -14 -8 -17 -2 -11 L0 -8.5 L2 -11 C8 -17 16 -14 17 -7 C18 0 11 8 0 15 Z" fill="none" stroke="#f5d58c" stroke-width="1.2"/>
              </g>

              <!-- Mid-left Cream & Gold Folded Heart -->
              <g class="paper-heart-bob h3" transform="translate(94, 149) rotate(-18) scale(0.68)">
                <path d="M0 15 C-11 8 -18 0 -17 -7 C-16 -14 -8 -17 -2 -11 L0 -8.5 Z" fill="#fbf2df"/>
                <path d="M0 15 C11 8 18 0 17 -7 C16 -14 8 -17 2 -11 L0 -8.5 Z" fill="#e5cfa6"/>
                <path d="M0 15 C-11 8 -18 0 -17 -7 C-16 -14 -8 -17 -2 -11 L0 -8.5 L2 -11 C8 -17 16 -14 17 -7 C18 0 11 8 0 15 Z" fill="none" stroke="#cfa049" stroke-width="1.3"/>
              </g>

              <!-- Mid-right Rose-Gold Folded Heart -->
              <g class="paper-heart-bob h2" transform="translate(345, 148) rotate(16) scale(0.7)">
                <path d="M0 15 C-11 8 -18 0 -17 -7 C-16 -14 -8 -17 -2 -11 L0 -8.5 Z" fill="#f29d9b"/>
                <path d="M0 15 C11 8 18 0 17 -7 C16 -14 8 -17 2 -11 L0 -8.5 Z" fill="#c95b62"/>
                <path d="M0 15 C-11 8 -18 0 -17 -7 C-16 -14 -8 -17 -2 -11 L0 -8.5 L2 -11 C8 -17 16 -14 17 -7 C18 0 11 8 0 15 Z" fill="none" stroke="#f7dca0" stroke-width="1.2"/>
              </g>

              <!-- Tiny gold heart near moon -->
              <g class="paper-heart-bob" transform="translate(267, 121) rotate(11) scale(0.46)">
                <path d="M0 15 C-11 8 -18 0 -17 -7 C-16 -14 -8 -17 -2 -11 L0 -8.5 Z" fill="#f7de9c"/>
                <path d="M0 15 C11 8 18 0 17 -7 C16 -14 8 -17 2 -11 L0 -8.5 Z" fill="#cfa049"/>
              </g>
            </svg>
          </div>

          <!-- Layer 6A: Left Paper-Cut Flower Bouquet -->
          <div class="popup-layer layer-flowers-l">
            <svg viewBox="0 0 440 280" preserveAspectRatio="xMidYMid meet">
              <g class="flower-cluster-l">
                <!-- Botanical gold-veined paper leaves -->
                <path d="M18 280 Q44 218 82 184 Q78 232 38 280 Z" fill="#7c2837" stroke="#e4b765" stroke-width="1.1"/>
                <path d="M26 276 Q54 228 74 196" stroke="#f0cc7f" stroke-width="1" fill="none" opacity="0.65"/>
                <path d="M54 280 Q90 236 136 226 Q114 264 74 280 Z" fill="#9a3a44" stroke="#ecc06a" stroke-width="1.1"/>
                <path d="M4 262 Q22 198 46 168 Q56 218 24 274 Z" fill="#c9953e" stroke="#fae2a6" stroke-width="1"/>
                <path d="M16 254 Q30 206 42 179" stroke="#fff4d2" stroke-width="0.9" fill="none" opacity="0.6"/>

                <!-- Large Layered Paper Crimson Rose -->
                <g transform="translate(56, 224)">
                  <circle cx="-12" cy="-6" r="16" fill="#9b1a29" stroke="#f1cf86" stroke-width="0.9"/>
                  <circle cx="12" cy="-7" r="16" fill="#a82030" stroke="#f1cf86" stroke-width="0.9"/>
                  <circle cx="0" cy="-14" r="16" fill="#b92837" stroke="#f1cf86" stroke-width="0.9"/>
                  <circle cx="-10" cy="10" r="15" fill="#aa1f2f" stroke="#f1cf86" stroke-width="0.9"/>
                  <circle cx="11" cy="10" r="15" fill="#9c1b2a" stroke="#f1cf86" stroke-width="0.9"/>
                  <circle cx="0" cy="0" r="15" fill="#cf3947"/>
                  <circle cx="0" cy="0" r="9.5" fill="#e5636b"/>
                  <path d="M-5 -2 C-3 -7 6 -6 6 1 C6 6 -2 7 -4 2 C-5 -1 0 -4 2 -1" fill="none" stroke="#fce2c4" stroke-width="1.6" stroke-linecap="round"/>
                  <circle cx="0" cy="0" r="3" fill="#f3d284"/>
                </g>

                <!-- Cream Paper Blossom -->
                <g transform="translate(103, 250) scale(0.84)">
                  <circle cx="0" cy="-12" r="10.5" fill="#fbf2df" stroke="#d4a34a" stroke-width="1"/>
                  <circle cx="11.5" cy="-3.5" r="10.5" fill="#f5e4c6" stroke="#d4a34a" stroke-width="1"/>
                  <circle cx="7" cy="9.5" r="10.5" fill="#fbf2df" stroke="#d4a34a" stroke-width="1"/>
                  <circle cx="-7" cy="9.5" r="10.5" fill="#f5e4c6" stroke="#d4a34a" stroke-width="1"/>
                  <circle cx="-11.5" cy="-3.5" r="10.5" fill="#fbf2df" stroke="#d4a34a" stroke-width="1"/>
                  <circle cx="0" cy="0" r="5.6" fill="#cfa049"/>
                  <circle cx="0" cy="0" r="2.6" fill="#b52835"/>
                </g>

                <!-- Smaller Blush Rosebud higher up -->
                <g transform="translate(28, 182) rotate(-18) scale(0.62)">
                  <circle cx="-8" cy="-4" r="12" fill="#d95963" stroke="#f6d899" stroke-width="1"/>
                  <circle cx="8" cy="-4" r="12" fill="#e7787e" stroke="#f6d899" stroke-width="1"/>
                  <circle cx="0" cy="5" r="12" fill="#c73f4d" stroke="#f6d899" stroke-width="1"/>
                  <circle cx="0" cy="-1" r="6" fill="#fae2d4"/>
                  <circle cx="0" cy="-1" r="2.5" fill="#d6a03e"/>
                </g>
              </g>
            </svg>
          </div>

          <!-- Layer 6B: Right Paper-Cut Flower Bouquet -->
          <div class="popup-layer layer-flowers-r">
            <svg viewBox="0 0 440 280" preserveAspectRatio="xMidYMid meet">
              <g class="flower-cluster-r">
                <!-- Botanical gold-veined paper leaves -->
                <path d="M422 280 Q396 218 358 184 Q362 232 402 280 Z" fill="#7c2837" stroke="#e4b765" stroke-width="1.1"/>
                <path d="M414 276 Q386 228 366 196" stroke="#f0cc7f" stroke-width="1" fill="none" opacity="0.65"/>
                <path d="M386 280 Q350 236 304 226 Q326 264 366 280 Z" fill="#9a3a44" stroke="#ecc06a" stroke-width="1.1"/>
                <path d="M436 262 Q418 198 394 168 Q384 218 416 274 Z" fill="#c9953e" stroke="#fae2a6" stroke-width="1"/>
                <path d="M424 254 Q410 206 398 179" stroke="#fff4d2" stroke-width="0.9" fill="none" opacity="0.6"/>

                <!-- Large Layered Paper Crimson Rose -->
                <g transform="translate(384, 224)">
                  <circle cx="12" cy="-6" r="16" fill="#9b1a29" stroke="#f1cf86" stroke-width="0.9"/>
                  <circle cx="-12" cy="-7" r="16" fill="#a82030" stroke="#f1cf86" stroke-width="0.9"/>
                  <circle cx="0" cy="-14" r="16" fill="#b92837" stroke="#f1cf86" stroke-width="0.9"/>
                  <circle cx="10" cy="10" r="15" fill="#aa1f2f" stroke="#f1cf86" stroke-width="0.9"/>
                  <circle cx="-11" cy="10" r="15" fill="#9c1b2a" stroke="#f1cf86" stroke-width="0.9"/>
                  <circle cx="0" cy="0" r="15" fill="#cf3947"/>
                  <circle cx="0" cy="0" r="9.5" fill="#e5636b"/>
                  <path d="M5 -2 C3 -7 -6 -6 -6 1 C-6 6 2 7 4 2 C5 -1 0 -4 -2 -1" fill="none" stroke="#fce2c4" stroke-width="1.6" stroke-linecap="round"/>
                  <circle cx="0" cy="0" r="3" fill="#f3d284"/>
                </g>

                <!-- Cream Paper Blossom -->
                <g transform="translate(337, 250) scale(0.84)">
                  <circle cx="0" cy="-12" r="10.5" fill="#fbf2df" stroke="#d4a34a" stroke-width="1"/>
                  <circle cx="-11.5" cy="-3.5" r="10.5" fill="#f5e4c6" stroke="#d4a34a" stroke-width="1"/>
                  <circle cx="-7" cy="9.5" r="10.5" fill="#fbf2df" stroke="#d4a34a" stroke-width="1"/>
                  <circle cx="7" cy="9.5" r="10.5" fill="#f5e4c6" stroke="#d4a34a" stroke-width="1"/>
                  <circle cx="11.5" cy="-3.5" r="10.5" fill="#fbf2df" stroke="#d4a34a" stroke-width="1"/>
                  <circle cx="0" cy="0" r="5.6" fill="#cfa049"/>
                  <circle cx="0" cy="0" r="2.6" fill="#b52835"/>
                </g>

                <!-- Smaller Blush Rosebud higher up -->
                <g transform="translate(412, 182) rotate(18) scale(0.62)">
                  <circle cx="8" cy="-4" r="12" fill="#d95963" stroke="#f6d899" stroke-width="1"/>
                  <circle cx="-8" cy="-4" r="12" fill="#e7787e" stroke="#f6d899" stroke-width="1"/>
                  <circle cx="0" cy="5" r="12" fill="#c73f4d" stroke="#f6d899" stroke-width="1"/>
                  <circle cx="0" cy="-1" r="6" fill="#fae2d4"/>
                  <circle cx="0" cy="-1" r="2.5" fill="#d6a03e"/>
                </g>
              </g>
            </svg>
          </div>

          <!-- Layer 7: Foreground Crease Scalloped Paper Grass & Gold Buds -->
          <div class="popup-layer layer-front">
            <svg viewBox="0 0 440 280" preserveAspectRatio="xMidYMid meet">
              <path d="M0 280 L0 264 Q36 254 72 268 Q112 256 154 272 Q188 265 220 276 Q252 265 286 272 Q328 256 368 268 Q404 254 440 264 L440 280 Z" fill="#3a0d19"/>
              <path d="M0 264 Q36 254 72 268 Q112 256 154 272 Q188 265 220 276 Q252 265 286 272 Q328 256 368 268 Q404 254 440 264" fill="none" stroke="#e8bd62" stroke-width="1.1" opacity="0.52"/>
              <circle cx="144" cy="266" r="2.5" fill="#f4d489"/>
              <circle cx="296" cy="266" r="2.5" fill="#f4d489"/>
              <circle cx="168" cy="272" r="2" fill="#e65c67"/>
              <circle cx="272" cy="272" r="2" fill="#e65c67"/>
            </svg>
          </div>

        </div>
        <div class="scene-tap-badge">Tap scene ♥</div>
      </div>

      <!-- Fold Crease -->
      <div class="card-crease" aria-hidden="true"></div>

      <!-- Lower Half: Handwritten Message Page -->
      <div id="letter-page" title="Tap to reveal faster">
        <div class="paper-frame" aria-hidden="true"></div>
        <div id="letter-body-wrap">
          <div id="letter-salutation"></div>
          <div id="letter-message"></div>
          <div class="letter-signoff">
            <div id="letter-closing"></div>
            <div id="letter-signature"></div>
            <svg class="sig-flourish" viewBox="0 0 130 20" aria-hidden="true">
              <path id="sig-flourish-path" d="M8 12 Q42 18 76 9 Q94 4 102 10 C106 13 102 17 98 14 C94 11 101 5 112 8 Q120 10 125 6"/>
            </svg>
          </div>

          <!-- Gliding Fountain Pen Nib -->
          <svg id="ink-nib" viewBox="0 0 36 36" fill="none" aria-hidden="true">
            <g transform="rotate(-12 4 30)">
              <path d="M5 31 L14 14 L25 5 L31 11 L22 22 Z" fill="#a92431" stroke="#f3d284" stroke-width="1.3" stroke-linejoin="round"/>
              <path d="M5 31 L13 17 L19 23 Z" fill="#f3d284" stroke="#8c5f14" stroke-width="1" stroke-linejoin="round"/>
              <line x1="5.5" y1="30.5" x2="14.5" y2="21.5" stroke="#5e3a0a" stroke-width="1.1"/>
              <circle cx="15" cy="21" r="1.4" fill="#5e3a0a"/>
            </g>
          </svg>
        </div>
      </div>
    </article>

    <!-- Thumb-Friendly Bottom Controls -->
    <div id="letter-actions">
      <div class="live-style-bar" role="radiogroup" aria-label="Switch paper style">
        <span class="live-style-label">Paper</span>
        <button type="button" class="mini-style-btn selected" data-style="linen" role="radio" aria-checked="true">Cream</button>
        <button type="button" class="mini-style-btn" data-style="rose" role="radio" aria-checked="false">Rose</button>
        <button type="button" class="mini-style-btn" data-style="gilded" role="radio" aria-checked="false">Gilded</button>
      </div>

      <div class="action-btn-row">
        <button type="button" id="btn-replay" class="btn-primary">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden="true">
            <path d="M4 12a8 8 0 1 1 2.3 5.6" stroke="#f7dca0" stroke-width="2" stroke-linecap="round"/>
            <path d="M4 7v5h5" stroke="#f7dca0" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
          </svg>
          <span>Replay Delivery</span>
        </button>
        <button type="button" id="btn-edit" class="btn-secondary">
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true">
            <path d="M15 5l4 4L8 20H4v-4L15 5Z" stroke="#f1d38b" stroke-width="1.8" stroke-linejoin="round"/>
          </svg>
          <span>Edit Note</span>
        </button>
      </div>
    </div>
  </section>
</main>

<!-- Hands-free #demo Mode Pill -->
<div id="demo-banner" role="status" aria-live="polite">
  <span class="demo-dot" aria-hidden="true"></span>
  <span>Hands-free demo · Tap anywhere to write yours</span>
</div>

<script>
(function () {
  'use strict';

  /* ==================== PROCEDURAL PAPER GRAIN GENERATOR ==================== */
  function initPaperTexture() {
    try {
      const c = document.createElement('canvas');
      c.width = 160;
      c.height = 160;
      const g = c.getContext('2d');
      const img = g.createImageData(160, 160);
      const d = img.data;
      let seed = 4219;
      function rand() {
        seed = (seed * 16807) % 2147483647;
        return (seed - 1) / 2147483646;
      }
      for (let y = 0; y < 160; y++) {
        for (let x = 0; x < 160; x++) {
          const i = (y * 160 + x) * 4;
          const weave = ((x % 4 === 0) ? 7 : 0) + ((y % 4 === 0) ? 7 : 0);
          const n = 236 + Math.floor((rand() - 0.5) * 26) - weave;
          d[i] = Math.min(255, Math.max(195, n));
          d[i + 1] = Math.min(255, Math.max(185, n - 5));
          d[i + 2] = Math.min(255, Math.max(175, n - 12));
          d[i + 3] = 36;
        }
      }
      g.putImageData(img, 0, 0);
      document.documentElement.style.setProperty('--paper-grain', 'url(' + c.toDataURL('image/png') + ')');
    } catch (_) {}
  }

  /* ==================== SOFT WEB AUDIO SOUND ENGINE ==================== */
  const Sound = (() => {
    let ctx = null;
    let master = null;
    let noiseBuf = null;
    let muted = false;

    function ensure() {
      if (muted) return null;
      try {
        if (!ctx) {
          const AC = window.AudioContext || window.webkitAudioContext;
          if (!AC) return null;
          ctx = new AC();
          master = ctx.createGain();
          master.gain.value = 0.56;
          const warmFilter = ctx.createBiquadFilter();
          warmFilter.type = 'lowpass';
          warmFilter.frequency.value = 4600;
          master.connect(warmFilter);
          warmFilter.connect(ctx.destination);

          // Pre-compute gentle pink-ish noise buffer for paper & quill textures
          const len = Math.floor(ctx.sampleRate * 1.4);
          noiseBuf = ctx.createBuffer(1, len, ctx.sampleRate);
          const out = noiseBuf.getChannelData(0);
          let b0 = 0, b1 = 0, b2 = 0;
          for (let i = 0; i < len; i++) {
            const white = Math.random() * 2 - 1;
            b0 = 0.997 * b0 + white * 0.029;
            b1 = 0.985 * b1 + white * 0.032;
            b2 = 0.950 * b2 + white * 0.048;
            out[i] = (b0 + b1 + b2 + white * 0.16) * 0.65;
          }
        }
        if (ctx.state === 'suspended') {
          ctx.resume().catch(() => {});
        }
        return ctx.state === 'running' ? ctx : null;
      } catch (_) {
        return null;
      }
    }

    function unlock() {
      try {
        if (!ctx) ensure();
        if (ctx && ctx.state === 'suspended') {
          ctx.resume().catch(() => {});
        }
      } catch (_) {}
    }

    function setMuted(val) {
      muted = !!val;
      if (master && ctx) {
        try {
          master.gain.setTargetAtTime(muted ? 0.0001 : 0.56, ctx.currentTime, 0.03);
        } catch (_) {}
      }
    }

    function isMuted() { return muted; }

    function playBellNote(freq, delay, dur, vol) {
      const c = ensure();
      if (!c) return;
      try {
        const t = c.currentTime + (delay || 0);
        const g = c.createGain();
        g.gain.setValueAtTime(0.0001, t);
        g.gain.linearRampToValueAtTime(vol || 0.12, t + 0.014);
        g.gain.exponentialRampToValueAtTime(0.0001, t + (dur || 0.7));

        const o1 = c.createOscillator();
        o1.type = 'sine';
        o1.frequency.setValueAtTime(freq, t);

        const o2 = c.createOscillator();
        o2.type = 'triangle';
        o2.frequency.setValueAtTime(freq * 2, t);
        const g2 = c.createGain();
        g2.gain.value = 0.16;

        o1.connect(g);
        o2.connect(g2);
        g2.connect(g);
        g.connect(master);

        o1.start(t);
        o2.start(t);
        o1.stop(t + (dur || 0.7) + 0.04);
        o2.stop(t + (dur || 0.7) + 0.04);
      } catch (_) {}
    }

    function playPaperRustle(freqCenter, dur, vol) {
      const c = ensure();
      if (!c || !noiseBuf) return;
      try {
        const t = c.currentTime;
        const src = c.createBufferSource();
        src.buffer = noiseBuf;
        const offset = Math.random() * 0.7;

        const filt = c.createBiquadFilter();
        filt.type = 'bandpass';
        filt.frequency.setValueAtTime(freqCenter || 1150, t);
        filt.frequency.exponentialRampToValueAtTime((freqCenter || 1150) * 0.65, t + (dur || 0.18));
        filt.Q.value = 1.4;

        const g = c.createGain();
        g.gain.setValueAtTime(0.0001, t);
        g.gain.linearRampToValueAtTime(vol || 0.14, t + 0.025);
        g.gain.exponentialRampToValueAtTime(0.0001, t + (dur || 0.18));

        src.connect(filt);
        filt.connect(g);
        g.connect(master);
        src.start(t, offset, (dur || 0.18) + 0.04);
      } catch (_) {}
    }

    function playTap(freq) {
      playBellNote(freq || 523.25, 0, 0.24, 0.09);
    }

    function playSendWax() {
      playPaperRustle(880, 0.22, 0.16);
      playBellNote(440, 0.02, 0.35, 0.10);
      playBellNote(554.37, 0.09, 0.42, 0.09);
      playBellNote(659.25, 0.16, 0.55, 0.10);
    }

    function playPawStep(idx) {
      const c = ensure();
      if (!c) return;
      try {
        const t = c.currentTime;
        const o = c.createOscillator();
        const g = c.createGain();
        o.type = 'sine';
        const base = (idx % 2 === 0) ? 148 : 132;
        o.frequency.setValueAtTime(base, t);
        o.frequency.exponentialRampToValueAtTime(64, t + 0.045);
        g.gain.setValueAtTime(0.0001, t);
        g.gain.linearRampToValueAtTime(0.055, t + 0.008);
        g.gain.exponentialRampToValueAtTime(0.0001, t + 0.055);
        o.connect(g);
        g.connect(master);
        o.start(t);
        o.stop(t + 0.065);
      } catch (_) {}
    }

    function playEnvelopeDrop() {
      playPaperRustle(720, 0.2, 0.18);
      const c = ensure();
      if (!c) return;
      try {
        const t = c.currentTime;
        const o = c.createOscillator();
        const g = c.createGain();
        o.type = 'sine';
        o.frequency.setValueAtTime(128, t);
        o.frequency.exponentialRampToValueAtTime(52, t + 0.11);
        g.gain.setValueAtTime(0.0001, t);
        g.gain.linearRampToValueAtTime(0.14, t + 0.01);
        g.gain.exponentialRampToValueAtTime(0.0001, t + 0.12);
        o.connect(g);
        g.connect(master);
        o.start(t);
        o.stop(t + 0.14);
      } catch (_) {}
    }

    function playCatMeow() {
      const c = ensure();
      if (!c) return;
      try {
        const t = c.currentTime;
        const osc = c.createOscillator();
        osc.type = 'triangle';
        // Gentle friendly "mrrp-mew!" contour
        osc.frequency.setValueAtTime(510, t);
        osc.frequency.exponentialRampToValueAtTime(770, t + 0.11);
        osc.frequency.exponentialRampToValueAtTime(690, t + 0.21);
        osc.frequency.exponentialRampToValueAtTime(540, t + 0.35);

        const vib = c.createOscillator();
        const vibG = c.createGain();
        vib.frequency.value = 24;
        vibG.gain.value = 18;
        vib.connect(vibG);
        vibG.connect(osc.frequency);

        const formant = c.createBiquadFilter();
        formant.type = 'bandpass';
        formant.frequency.setValueAtTime(1150, t);
        formant.frequency.exponentialRampToValueAtTime(1620, t + 0.12);
        formant.frequency.exponentialRampToValueAtTime(1020, t + 0.35);
        formant.Q.value = 2.4;

        const g = c.createGain();
        g.gain.setValueAtTime(0.0001, t);
        g.gain.linearRampToValueAtTime(0.17, t + 0.05);
        g.gain.setValueAtTime(0.15, t + 0.19);
        g.gain.exponentialRampToValueAtTime(0.0001, t + 0.38);

        osc.connect(formant);
        formant.connect(g);
        g.connect(master);

        osc.start(t);
        vib.start(t);
        osc.stop(t + 0.40);
        vib.stop(t + 0.40);
      } catch (_) {}
    }

    function playSealBreakAndUnfold() {
      // Crisp tiny wax pop + velvety unfolding whoosh + dreamy Fmaj9 music-box chord
      playPaperRustle(2200, 0.055, 0.15);
      setTimeout(() => playPaperRustle(960, 0.42, 0.2), 70);
      const notes = [349.23, 440.0, 523.25, 659.25, 783.99, 880.0];
      notes.forEach((f, idx) => {
        playBellNote(f, 0.24 + idx * 0.088, 1.45, 0.095 - idx * 0.006);
      });
    }

    function playPenScratch(chCode) {
      const c = ensure();
      if (!c || !noiseBuf) return;
      try {
        const t = c.currentTime;
        const src = c.createBufferSource();
        src.buffer = noiseBuf;
        const filt = c.createBiquadFilter();
        filt.type = 'bandpass';
        filt.frequency.value = 1750 + ((chCode || 65) % 9) * 105;
        filt.Q.value = 3.2;

        const g = c.createGain();
        g.gain.setValueAtTime(0.0001, t);
        g.gain.linearRampToValueAtTime(0.036, t + 0.006);
        g.gain.exponentialRampToValueAtTime(0.0001, t + 0.034);

        src.connect(filt);
        filt.connect(g);
        g.connect(master);
        src.start(t, Math.random() * 0.9, 0.04);
      } catch (_) {}
    }

    function playSignatureChime() {
      playBellNote(523.25, 0.02, 0.9, 0.085);
      playBellNote(659.25, 0.14, 1.1, 0.085);
      playBellNote(783.99, 0.26, 1.3, 0.08);
    }

    let sparkleIdx = 0;
    const sparkleScale = [523.25, 587.33, 659.25, 783.99, 880.0, 1046.5];
    function playCatPurrAndSparkle() {
      const c = ensure();
      const note = sparkleScale[sparkleIdx % sparkleScale.length];
      sparkleIdx++;
      playBellNote(note, 0, 0.85, 0.09);
      playBellNote(note * 1.25, 0.09, 0.75, 0.055);
      if (!c) return;
      try {
        const t = c.currentTime;
        const osc = c.createOscillator();
        osc.type = 'triangle';
        osc.frequency.value = 92;

        const lfo = c.createOscillator();
        const lfoG = c.createGain();
        lfo.frequency.value = 25;
        lfoG.gain.value = 0.045;

        const lp = c.createBiquadFilter();
        lp.type = 'lowpass';
        lp.frequency.value = 210;

        const g = c.createGain();
        g.gain.setValueAtTime(0.0001, t);
        g.gain.linearRampToValueAtTime(0.07, t + 0.1);
        g.gain.exponentialRampToValueAtTime(0.0001, t + 0.65);

        lfo.connect(lfoG);
        lfoG.connect(g.gain);
        osc.connect(lp);
        lp.connect(g);
        g.connect(master);

        osc.start(t);
        lfo.start(t);
        osc.stop(t + 0.68);
        lfo.stop(t + 0.68);
      } catch (_) {}
    }

    return {
      unlock, setMuted, isMuted,
      playTap, playPaperRustle, playSendWax, playPawStep,
      playEnvelopeDrop, playCatMeow, playSealBreakAndUnfold,
      playPenScratch, playSignatureChime, playCatPurrAndSparkle
    };
  })();

  /* ==================== AMBIENT GOLD DUST & HEART FX CANVASES ==================== */
  const ambientCanvas = document.getElementById('ambient-canvas');
  const ambientCtx = ambientCanvas.getContext('2d');
  const fxCanvas = document.getElementById('fx-canvas');
  const fxCtx = fxCanvas.getContext('2d');

  let viewW = window.innerWidth;
  let viewH = window.innerHeight;
  let dpr = Math.min(window.devicePixelRatio || 1, 2);

  const motes = [];
  const fxParticles = [];

  function resizeCanvases() {
    viewW = window.innerWidth;
    viewH = window.innerHeight;
    dpr = Math.min(window.devicePixelRatio || 1, 2);
    [ambientCanvas, fxCanvas].forEach((cv) => {
      cv.width = Math.floor(viewW * dpr);
      cv.height = Math.floor(viewH * dpr);
      cv.style.width = viewW + 'px';
      cv.style.height = viewH + 'px';
    });
    ambientCtx.setTransform(dpr, 0, 0, dpr, 0, 0);
    fxCtx.setTransform(dpr, 0, 0, dpr, 0, 0);
  }

  function seedMotes() {
    motes.length = 0;
    const count = Math.min(40, Math.max(18, Math.floor((viewW * viewH) / 24000)));
    for (let i = 0; i < count; i++) {
      motes.push({
        x: Math.random() * viewW,
        y: Math.random() * viewH,
        r: 1.1 + Math.random() * 2.4,
        vy: -(0.12 + Math.random() * 0.25),
        vx: (Math.random() - 0.5) * 0.18,
        phase: Math.random() * Math.PI * 2,
        warm: Math.random() > 0.35
      });
    }
  }

  function drawMiniHeart(ctx, x, y, size, rot, color, alpha) {
    ctx.save();
    ctx.translate(x, y);
    ctx.rotate(rot);
    ctx.globalAlpha = Math.max(0, Math.min(1, alpha));
    ctx.fillStyle = color;
    ctx.beginPath();
    const s = size;
    ctx.moveTo(0, s * 0.38);
    ctx.bezierCurveTo(-s * 0.5, -s * 0.1, -s * 0.9, -s * 0.55, -s * 0.48, -s * 0.85);
    ctx.bezierCurveTo(-s * 0.16, -s * 1.05, 0, -s * 0.72, 0, -s * 0.56);
    ctx.bezierCurveTo(0, -s * 0.72, s * 0.16, -s * 1.05, s * 0.48, -s * 0.85);
    ctx.bezierCurveTo(s * 0.9, -s * 0.55, s * 0.5, -s * 0.1, 0, s * 0.38);
    ctx.closePath();
    ctx.fill();
    ctx.restore();
  }

  function spawnHeartBurst(x, y, count, spread) {
    const palette = ['#d63747', '#f3d284', '#f7b6b2', '#fbf3e4', '#c92434'];
    const n = count || 14;
    const sp = spread || 1;
    for (let i = 0; i < n; i++) {
      const ang = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI * 1.45;
      const spd = (1.1 + Math.random() * 2.8) * sp;
      fxParticles.push({
        kind: Math.random() > 0.36 ? 'heart' : 'spark',
        x: x + (Math.random() - 0.5) * 18,
        y: y + (Math.random() - 0.5) * 14,
        vx: Math.cos(ang) * spd,
        vy: Math.sin(ang) * spd - 0.7,
        size: 5 + Math.random() * 7.5,
        rot: (Math.random() - 0.5) * 0.7,
        vrot: (Math.random() - 0.5) * 0.05,
        color: palette[Math.floor(Math.random() * palette.length)],
        life: 0,
        maxLife: 56 + Math.random() * 44
      });
    }
  }

  function spawnPawPuff(x, y) {
    for (let i = 0; i < 3; i++) {
      fxParticles.push({
        kind: 'spark',
        x: x + (Math.random() - 0.5) * 10,
        y: y + (Math.random() - 0.5) * 4,
        vx: -(0.3 + Math.random() * 0.6),
        vy: -(0.2 + Math.random() * 0.5),
        size: 2.5 + Math.random() * 2.5,
        rot: 0,
        vrot: 0.04,
        color: '#f3d284',
        life: 0,
        maxLife: 28 + Math.random() * 14
      });
    }
  }

  function animateCanvases(now) {
    // 1. Ambient golden dust
    ambientCtx.clearRect(0, 0, viewW, viewH);
    for (let i = 0; i < motes.length; i++) {
      const m = motes[i];
      m.x += m.vx + Math.sin(now * 0.0007 + m.phase) * 0.14;
      m.y += m.vy;
      if (m.y < -12) { m.y = viewH + 12; m.x = Math.random() * viewW; }
      if (m.x < -12) m.x = viewW + 12;
      if (m.x > viewW + 12) m.x = -12;
      const alpha = 0.14 + 0.22 * (0.5 + 0.5 * Math.sin(now * 0.0014 + m.phase));
      ambientCtx.beginPath();
      ambientCtx.arc(m.x, m.y, m.r, 0, Math.PI * 2);
      ambientCtx.fillStyle = m.warm
        ? 'rgba(243, 210, 132, ' + alpha.toFixed(3) + ')'
        : 'rgba(248, 198, 186, ' + (alpha * 0.8).toFixed(3) + ')';
      ambientCtx.fill();
    }

    // 2. Active FX particles
    fxCtx.clearRect(0, 0, viewW, viewH);
    for (let i = fxParticles.length - 1; i >= 0; i--) {
      const p = fxParticles[i];
      p.life++;
      if (p.life >= p.maxLife) {
        fxParticles.splice(i, 1);
        continue;
      }
      p.x += p.vx;
      p.y += p.vy;
      p.vy += (p.kind === 'heart' ? -0.015 : 0.02);
      p.vx *= 0.985;
      p.rot += p.vrot;
      const progress = p.life / p.maxLife;
      const alpha = progress < 0.15 ? (progress / 0.15) : (1 - (progress - 0.15) / 0.85);
      if (p.kind === 'heart') {
        drawMiniHeart(fxCtx, p.x, p.y, p.size, p.rot, p.color, alpha * 0.92);
      } else {
        fxCtx.save();
        fxCtx.translate(p.x, p.y);
        fxCtx.rotate(p.rot);
        fxCtx.globalAlpha = Math.max(0, alpha);
        fxCtx.fillStyle = p.color;
        fxCtx.beginPath();
        const s = p.size * 0.65;
        fxCtx.moveTo(0, -s);
        fxCtx.quadraticCurveTo(0, 0, s, 0);
        fxCtx.quadraticCurveTo(0, 0, 0, s);
        fxCtx.quadraticCurveTo(0, 0, -s, 0);
        fxCtx.quadraticCurveTo(0, 0, 0, -s);
        fxCtx.fill();
        fxCtx.restore();
      }
    }

    requestAnimationFrame(animateCanvases);
  }

  /* ==================== APP STATE & DOM REFERENCES ==================== */
  const STORAGE_KEY = 'petite_post_love_letter_v1';
  const STYLES = {
    linen: { envFill: '#fbf4e6', envStroke: '#c99438', sealFill: '#b82935' },
    rose:  { envFill: '#fae9e4', envStroke: '#d29755', sealFill: '#8f1b30' },
    gilded:{ envFill: '#f5e6c8', envStroke: '#b87e19', sealFill: '#cf9328' }
  };

  const state = {
    view: 'compose',
    style: 'linen',
    to: '',
    from: '',
    message: '',
    deliveryToken: 0,
    writingToken: 0,
    writingFast: false,
    writingDone: false,
    envelopeReady: false,
    envelopeOpened: false,
    demoActive: false
  };

  // Elements
  const viewCompose = document.getElementById('view-compose');
  const viewDelivery = document.getElementById('view-delivery');
  const viewLetter = document.getElementById('view-letter');
  const brandPill = document.getElementById('brand-pill');
  const btnBackEdit = document.getElementById('btn-back-edit');
  const btnSound = document.getElementById('btn-sound');
  const soundIconOn = document.getElementById('sound-icon-on');
  const soundIconOff = document.getElementById('sound-icon-off');

  const inputTo = document.getElementById('input-to');
  const inputFrom = document.getElementById('input-from');
  const inputMsg = document.getElementById('input-msg');
  const charCount = document.getElementById('char-count');
  const btnSend = document.getElementById('btn-send');
  const ideaChips = Array.from(document.querySelectorAll('.idea-chip'));
  const styleOptions = Array.from(document.querySelectorAll('.style-option'));
  const miniStyleBtns = Array.from(document.querySelectorAll('.mini-style-btn'));

  const deliveryStage = document.getElementById('delivery-stage');
  const deliveryStatus = document.getElementById('delivery-status');
  const catWrap = document.getElementById('cat-postman-wrap');
  const catEyesOpen = document.getElementById('cat-eyes-open');
  const catEyesHappy = document.getElementById('cat-eyes-happy');
  const catPawSalute = document.getElementById('cat-paw-salute');
  const catPawFL = document.getElementById('cat-paw-fl');
  const catPawFR = document.getElementById('cat-paw-fr');
  const catPawBL = document.getElementById('cat-paw-bl');
  const catPawBR = document.getElementById('cat-paw-br');
  const catTail = document.getElementById('cat-tail');
  const catCapGroup = document.getElementById('cat-cap-group');
  const catHeldEnv = document.getElementById('cat-held-envelope');
  const catEnvRect = document.getElementById('cat-env-rect');
  const catEnvSeal = document.getElementById('cat-env-seal');

  const envelopeZone = document.getElementById('envelope-zone');
  const waitingEnvelope = document.getElementById('waiting-envelope');
  const envToLabel = document.getElementById('env-to-label');
  const envTapHint = document.getElementById('env-tap-hint');

  const popupStage = document.getElementById('popup-stage');
  const popupParallax = document.getElementById('popup-parallax');
  const letterPage = document.getElementById('letter-page');
  const letterBodyWrap = document.getElementById('letter-body-wrap');
  const letterSalutation = document.getElementById('letter-salutation');
  const letterMessage = document.getElementById('letter-message');
  const letterClosing = document.getElementById('letter-closing');
  const letterSignature = document.getElementById('letter-signature');
  const sigFlourishPath = document.getElementById('sig-flourish-path');
  const inkNib = document.getElementById('ink-nib');
  const btnReplay = document.getElementById('btn-replay');
  const btnEdit = document.getElementById('btn-edit');
  const demoBanner = document.getElementById('demo-banner');

  /* ==================== PERSISTENCE (SANDBOX SAFE) ==================== */
  function loadSaved() {
    try {
      const raw = window.localStorage.getItem(STORAGE_KEY);
      if (!raw) return;
      const obj = JSON.parse(raw);
      if (obj && typeof obj === 'object') {
        if (typeof obj.to === 'string') inputTo.value = obj.to.slice(0, 32);
        if (typeof obj.from === 'string') inputFrom.value = obj.from.slice(0, 32);
        if (typeof obj.message === 'string') inputMsg.value = obj.message.slice(0, 220);
        if (obj.style && STYLES[obj.style]) applyPaperStyle(obj.style, true);
      }
    } catch (_) {}
  }

  function saveDraft() {
    if (state.demoActive) return;
    try {
      window.localStorage.setItem(STORAGE_KEY, JSON.stringify({
        to: inputTo.value,
        from: inputFrom.value,
        message: inputMsg.value,
        style: state.style
      }));
    } catch (_) {}
  }

  /* ==================== PAPER STYLE SWITCHING ==================== */
  function applyPaperStyle(styleName, silent) {
    if (!STYLES[styleName]) styleName = 'linen';
    state.style = styleName;
    document.body.classList.remove('theme-linen', 'theme-rose', 'theme-gilded');
    document.body.classList.add('theme-' + styleName);

    // Sync cat's carried envelope swatch
    const s = STYLES[styleName];
    if (catEnvRect) {
      catEnvRect.setAttribute('fill', s.envFill);
      catEnvRect.setAttribute('stroke', s.envStroke);
    }
    if (catEnvSeal) {
      catEnvSeal.setAttribute('fill', s.sealFill);
    }

    styleOptions.forEach((btn) => {
      const on = btn.dataset.style === styleName;
      btn.classList.toggle('selected', on);
      btn.setAttribute('aria-checked', on ? 'true' : 'false');
    });
    miniStyleBtns.forEach((btn) => {
      const on = btn.dataset.style === styleName;
      btn.classList.toggle('selected', on);
      btn.setAttribute('aria-checked', on ? 'true' : 'false');
    });

    if (!silent) {
      Sound.playPaperRustle(styleName === 'gilded' ? 1420 : styleName === 'rose' ? 980 : 1180, 0.18, 0.14);
      saveDraft();
    }
  }

  function updateCharCount() {
    charCount.textContent = inputMsg.value.length + ' / 220';
  }

  /* ==================== VIEW SWITCHING ==================== */
  function showView(name) {
    state.view = name;
    viewCompose.classList.toggle('active', name === 'compose');
    viewDelivery.classList.toggle('active', name === 'delivery');
    viewLetter.classList.toggle('active', name === 'letter');

    // Top bar visibility
    const showBack = (name !== 'compose');
    btnBackEdit.classList.toggle('hidden', !showBack);
    brandPill.style.display = showBack ? 'none' : 'inline-flex';

    // Scroll to top cleanly
    const appEl = document.getElementById('app');
    if (appEl) appEl.scrollTop = 0;
  }

  function getResolvedLetter() {
    const rawTo = (inputTo.value || '').trim();
    const rawFrom = (inputFrom.value || '').trim();
    const rawMsg = (inputMsg.value || '').trim();
    return {
      to: rawTo || 'My Love',
      from: rawFrom || 'Yours Truly',
      message: rawMsg || 'Every quiet night under the moon feels warmer because of you.'
    };
  }

  /* ==================== STAGE 2: CAT POSTMAN CHOREOGRAPHY ==================== */
  function setCatPose(legAngle, tailAngle, bobY, leanDeg) {
    catPawFL.setAttribute('transform', 'rotate(' + legAngle.toFixed(1) + ' 100 107)');
    catPawBR.setAttribute('transform', 'rotate(' + (legAngle * 0.9).toFixed(1) + ' 67 108)');
    catPawFR.setAttribute('transform', 'rotate(' + (-legAngle).toFixed(1) + ' 106 108)');
    catPawBL.setAttribute('transform', 'rotate(' + (-legAngle * 0.9).toFixed(1) + ' 60 107)');
    catTail.setAttribute('transform', 'rotate(' + tailAngle.toFixed(1) + ' 46 95)');
    catWrap.style.marginTop = bobY.toFixed(1) + 'px';
    catCapGroup.setAttribute('transform', 'rotate(' + (leanDeg || 0).toFixed(1) + ' 114 48)');
  }

  function startDelivery() {
    const token = ++state.deliveryToken;
    state.writingToken++;
    state.envelopeReady = false;
    state.envelopeOpened = false;

    const letter = getResolvedLetter();
    state.to = letter.to;
    state.from = letter.from;
    state.message = letter.message;

    envToLabel.textContent = letter.to;

    // Reset envelope & cat state
    waitingEnvelope.classList.remove('opening');
    envelopeZone.classList.remove('landed');
    envTapHint.style.opacity = '';
    popupStage.classList.remove('unfolded', 'cats-nuzzle');

    catWrap.classList.remove('saluting');
    catWrap.style.opacity = '1';
    catEyesOpen.style.display = '';
    catEyesHappy.style.display = 'none';
    catPawSalute.style.opacity = '0';
    catHeldEnv.style.opacity = '1';
    catHeldEnv.setAttribute('transform', 'translate(128, 76) rotate(-7)');
    setCatPose(0, 0, 0, 0);

    deliveryStatus.textContent = 'A little postman is on the way...';
    deliveryStatus.classList.add('visible');

    showView('delivery');

    const catW = 176;
    const stageW = deliveryStage.clientWidth || window.innerWidth;
    const startX = -catW - 14;
    const stopX = Math.round(stageW * 0.5 - catW * 0.62);
    const exitX = stageW + 52;

    const tApproach = 2150;
    const tPlace = 560;
    const tSalute = 860;
    const tDepart = 1550;

    let lastStepCount = -1;
    let dropped = false;
    let saluted = false;
    const t0 = performance.now();

    function frame(now) {
      if (token !== state.deliveryToken || state.view !== 'delivery') return;
      const elapsed = now - t0;

      if (elapsed < tApproach) {
        // Phase 1: Trotting across from left to center
        const p = elapsed / tApproach;
        const ease = p < 0.85 ? (p / 0.85) * 0.94 : 0.94 + 0.06 * (1 - Math.pow(1 - (p - 0.85) / 0.15, 2));
        const x = startX + (stopX - startX) * ease;
        const stride = elapsed * 0.0155;
        const legAng = Math.sin(stride) * 24;
        const bob = -Math.abs(Math.sin(stride)) * 7;
        const tailAng = Math.sin(stride * 0.65) * 14;
        catWrap.style.transform = 'translate3d(' + x.toFixed(1) + 'px, 0, 0)';
        setCatPose(legAng, tailAng, bob, Math.sin(stride) * 2.5);

        const stepCount = Math.floor(stride / Math.PI);
        if (stepCount > lastStepCount && x > -40) {
          lastStepCount = stepCount;
          Sound.playPawStep(stepCount);
          const rect = catWrap.getBoundingClientRect();
          spawnPawPuff(rect.left + 64, rect.top + 134);
        }
        requestAnimationFrame(frame);
      } else if (elapsed < tApproach + tPlace) {
        // Phase 2: Bending gently to leave the envelope in front of you
        const p = (elapsed - tApproach) / tPlace;
        const dip = Math.sin(p * Math.PI);
        catWrap.style.transform = 'translate3d(' + stopX.toFixed(1) + 'px, ' + (dip * 8).toFixed(1) + 'px, 0) rotate(' + (dip * 5.5).toFixed(1) + 'deg)';
        setCatPose(0, Math.sin(p * Math.PI * 2) * 10, 0, dip * 6);
        catHeldEnv.setAttribute('transform', 'translate(' + (128 + p * 16).toFixed(1) + ', ' + (76 + p * 26).toFixed(1) + ') rotate(' + (-7 + p * 7).toFixed(1) + ')');

        if (p >= 0.55 && !dropped) {
          dropped = true;
          catHeldEnv.style.opacity = '0';
          envelopeZone.classList.add('landed');
          state.envelopeReady = true;
          deliveryStatus.textContent = 'A love letter arrived for ' + state.to;
          Sound.playEnvelopeDrop();
          const eRect = waitingEnvelope.getBoundingClientRect();
          spawnHeartBurst(eRect.left + eRect.width * 0.5, eRect.top + eRect.height * 0.5, 8, 0.72);
        }
        requestAnimationFrame(frame);
      } else if (elapsed < tApproach + tPlace + tSalute) {
        // Phase 3: Happy wink, blue cap tip salute, soft meow!
        const p = (elapsed - tApproach - tPlace) / tSalute;
        if (!saluted) {
          saluted = true;
          catWrap.classList.add('saluting');
          catEyesOpen.style.display = 'none';
          catEyesHappy.style.display = '';
          catPawSalute.style.opacity = '1';
          Sound.playCatMeow();
        }
        const nod = Math.sin(p * Math.PI) * 9;
        catWrap.style.transform = 'translate3d(' + (stopX - 48 * Math.min(1, p * 1.4)).toFixed(1) + 'px, 0, 0)';
        setCatPose(0, Math.sin(p * Math.PI * 3) * 16, 0, nod);
        requestAnimationFrame(frame);
      } else if (elapsed < tApproach + tPlace + tSalute + tDepart) {
        // Phase 4: Trotting happily off to the right
        const p = (elapsed - tApproach - tPlace - tSalute) / tDepart;
        catWrap.classList.remove('saluting');
        catEyesOpen.style.display = '';
        catEyesHappy.style.display = 'none';
        catPawSalute.style.opacity = '0';

        const ease = p * p * (3 - 2 * p);
        const departStart = stopX - 48;
        const x = departStart + (exitX - departStart) * ease;
        const stride = elapsed * 0.017;
        const legAng = Math.sin(stride) * 25;
        const bob = -Math.abs(Math.sin(stride)) * 7;
        const tailAng = Math.sin(stride * 0.7) * 16;
        catWrap.style.transform = 'translate3d(' + x.toFixed(1) + 'px, 0, 0)';
        setCatPose(legAng, tailAng, bob, Math.sin(stride) * 2);

        const stepCount = Math.floor(stride / Math.PI);
        if (stepCount > lastStepCount && x < stageW + 10) {
          lastStepCount = stepCount;
          Sound.playPawStep(stepCount);
        }
        requestAnimationFrame(frame);
      } else {
        catWrap.style.opacity = '0';
      }
    }

    requestAnimationFrame(frame);
  }

  /* ==================== STAGE 3: ENVELOPE OPEN, POP-UP & HANDWRITING ==================== */
  function openEnvelope() {
    if (!state.envelopeReady || state.envelopeOpened) return;
    state.envelopeOpened = true;
    const token = state.deliveryToken;

    Sound.playSealBreakAndUnfold();
    waitingEnvelope.classList.add('opening');
    envTapHint.style.opacity = '0';
    deliveryStatus.classList.remove('visible');

    const sealRect = document.getElementById('env-wax-seal').getBoundingClientRect();
    spawnHeartBurst(sealRect.left + sealRect.width / 2, sealRect.top + sealRect.height / 2, 20, 1.15);

    setTimeout(() => {
      if (token !== state.deliveryToken) return;
      showPopUpLetter();
    }, 680);
  }

  function buildHandwritingSpans(container, text, collector) {
    container.innerHTML = '';
    const lines = String(text).split('\n');
    lines.forEach((line, lineIdx) => {
      if (lineIdx > 0) {
        container.appendChild(document.createElement('br'));
      }
      // Split into tokens preserving spaces so lines never jump mid-word
      const tokens = line.split(/(\s+)/);
      tokens.forEach((tok) => {
        if (!tok) return;
        if (/^\s+$/.test(tok)) {
          // Whitespace span
          const sp = document.createElement('span');
          sp.className = 'hw-char';
          sp.textContent = tok;
          container.appendChild(sp);
          collector.push({ el: sp, ch: ' ', isSpace: true });
        } else {
          const wordWrap = document.createElement('span');
          wordWrap.className = 'hw-word';
          const chars = Array.from(tok);
          chars.forEach((ch, idx) => {
            const span = document.createElement('span');
            span.className = 'hw-char';
            const code = ch.codePointAt(0) || 65;
            const tilt = (((code * 17 + idx * 13) % 29) - 14) * 0.11;
            const dy = (((code * 11 + idx * 7) % 13) - 6) * 0.12;
            span.style.setProperty('--r', tilt.toFixed(2) + 'deg');
            span.style.setProperty('--dy', dy.toFixed(2) + 'px');
            span.textContent = ch;
            wordWrap.appendChild(span);
            collector.push({ el: span, ch: ch, isSpace: false });
          });
          container.appendChild(wordWrap);
        }
      });
    });
  }

  function positionNibAt(charEl, jitterPhase) {
    if (!charEl || !letterBodyWrap) return;
    const wrapRect = letterBodyWrap.getBoundingClientRect();
    const r = charEl.getBoundingClientRect();
    if (r.width === 0 && r.height === 0) return;
    const x = (r.right - wrapRect.left) - 4 + Math.sin(jitterPhase) * 1.4;
    const y = (r.bottom - wrapRect.top) - 29 + Math.cos(jitterPhase * 1.3) * 1.3;
    inkNib.style.transform = 'translate3d(' + x.toFixed(1) + 'px, ' + y.toFixed(1) + 'px, 0)';
  }

  function showPopUpLetter() {
    const wToken = ++state.writingToken;
    state.writingFast = false;
    state.writingDone = false;

    // Reset pop-up & flourish
    popupStage.classList.remove('unfolded', 'cats-nuzzle');
    popupParallax.style.transform = '';
    sigFlourishPath.classList.remove('drawn');
    inkNib.classList.remove('writing');

    // Prepare handwritten text nodes (zero layout reflow!)
    const queue = [];
    buildHandwritingSpans(letterSalutation, 'Dearest ' + state.to + ',', queue);
    queue.push({ pause: 260 });
    buildHandwritingSpans(letterMessage, state.message, queue);
    queue.push({ pause: 240 });
    buildHandwritingSpans(letterClosing, 'With all my love,', queue);
    queue.push({ pause: 160 });
    buildHandwritingSpans(letterSignature, state.from, queue);

    showView('letter');

    // Unfold the 3D paper pop-up scene right after view becomes visible
    requestAnimationFrame(() => {
      requestAnimationFrame(() => {
        if (wToken !== state.writingToken) return;
        popupStage.classList.add('unfolded');
      });
    });

    // Begin letter-by-letter handwriting as the pop-up blooms
    let idx = 0;
    function stepWrite() {
      if (wToken !== state.writingToken || state.view !== 'letter') return;
      if (idx >= queue.length) {
        inkNib.classList.remove('writing');
        sigFlourishPath.classList.add('drawn');
        state.writingDone = true;
        Sound.playSignatureChime();
        const cardRect = popupStage.getBoundingClientRect();
        spawnHeartBurst(cardRect.left + cardRect.width * 0.5, cardRect.top + cardRect.height * 0.52, 12, 0.9);
        return;
      }

      const item = queue[idx++];
      if (item.pause) {
        setTimeout(stepWrite, state.writingFast ? 30 : item.pause);
        return;
      }

      item.el.classList.add('shown');
      if (!item.isSpace) {
        inkNib.classList.add('writing');
        positionNibAt(item.el, idx * 0.9);
        if (!state.writingFast || idx % 4 === 0) {
          Sound.playPenScratch(item.ch.codePointAt(0));
        }
      }

      let delay = state.writingFast ? 9 : 46;
      if (!state.writingFast) {
        if (item.isSpace) delay = 26;
        else if (/[.!?;:]/.test(item.ch)) delay = 195;
        else if (/,/.test(item.ch)) delay = 120;
        else delay = 36 + ((idx * 19) % 24);
      }
      setTimeout(stepWrite, delay);
    }

    setTimeout(() => {
      if (wToken !== state.writingToken) return;
      stepWrite();
    }, 640);
  }

  /* ==================== INTERACTIVE POP-UP SCENE DELIGHT ==================== */
  let nuzzleTimer = null;
  function petPopUpScene(clientX, clientY) {
    Sound.playCatPurrAndSparkle();
    popupStage.classList.add('cats-nuzzle');
    clearTimeout(nuzzleTimer);
    nuzzleTimer = setTimeout(() => popupStage.classList.remove('cats-nuzzle'), 700);

    const rect = popupStage.getBoundingClientRect();
    const bx = typeof clientX === 'number' ? clientX : rect.left + rect.width * 0.5;
    const by = typeof clientY === 'number' ? clientY : rect.top + rect.height * 0.55;
    spawnHeartBurst(bx, by, 14, 0.95);

    // Subtle 3D paper-card gentle tilt toward the touch point
    const rx = ((by - rect.top) / rect.height - 0.5) * -6;
    const ry = ((bx - rect.left) / rect.width - 0.5) * 8;
    popupParallax.style.transform = 'rotateX(' + rx.toFixed(1) + 'deg) rotateY(' + ry.toFixed(1) + 'deg)';
    setTimeout(() => {
      popupParallax.style.transform = 'rotateX(0deg) rotateY(0deg)';
    }, 620);
  }

  /* ==================== EVENT BINDINGS (TOUCH + MOUSE, ONE-FINGER) ==================== */
  btnSound.addEventListener('click', () => {
    Sound.unlock();
    const nextMuted = !Sound.isMuted();
    Sound.setMuted(nextMuted);
    soundIconOn.style.display = nextMuted ? 'none' : '';
    soundIconOff.style.display = nextMuted ? '' : 'none';
    btnSound.setAttribute('aria-pressed', nextMuted ? 'false' : 'true');
    if (!nextMuted) Sound.playTap(587.33);
  });

  btnBackEdit.addEventListener('click', () => {
    Sound.unlock();
    Sound.playPaperRustle(1080, 0.16, 0.12);
    state.deliveryToken++;
    state.writingToken++;
    showView('compose');
  });

  [inputTo, inputFrom, inputMsg].forEach((el) => {
    el.addEventListener('input', () => {
      updateCharCount();
      saveDraft();
    });
  });

  ideaChips.forEach((chip) => {
    chip.addEventListener('click', () => {
      Sound.unlock();
      Sound.playTap(659.25);
      inputMsg.value = chip.dataset.msg || '';
      updateCharCount();
      saveDraft();
    });
  });

  styleOptions.forEach((opt) => {
    opt.addEventListener('click', () => {
      Sound.unlock();
      applyPaperStyle(opt.dataset.style, false);
    });
  });

  miniStyleBtns.forEach((btn) => {
    btn.addEventListener('click', () => {
      Sound.unlock();
      applyPaperStyle(btn.dataset.style, false);
    });
  });

  btnSend.addEventListener('click', () => {
    Sound.unlock();
    Sound.playSendWax();
    saveDraft();
    const r = btnSend.getBoundingClientRect();
    spawnHeartBurst(r.left + r.width * 0.5, r.top + r.height * 0.5, 16, 1.0);
    startDelivery();
  });

  waitingEnvelope.addEventListener('click', () => {
    Sound.unlock();
    openEnvelope();
  });

  popupStage.addEventListener('click', (e) => {
    Sound.unlock();
    petPopUpScene(e.clientX, e.clientY);
  });

  letterPage.addEventListener('click', () => {
    Sound.unlock();
    if (!state.writingDone) {
      state.writingFast = true;
      Sound.playPaperRustle(1320, 0.12, 0.08);
    } else {
      Sound.playTap(659.25);
      sigFlourishPath.classList.remove('drawn');
      void sigFlourishPath.offsetWidth;
      sigFlourishPath.classList.add('drawn');
    }
  });

  btnReplay.addEventListener('click', () => {
    Sound.unlock();
    Sound.playSendWax();
    startDelivery();
  });

  btnEdit.addEventListener('click', () => {
    Sound.unlock();
    Sound.playPaperRustle(1080, 0.16, 0.12);
    state.deliveryToken++;
    state.writingToken++;
    showView('compose');
  });

  /* ==================== #DEMO HANDS-FREE ~20s LOOP (RULE 5) ==================== */
  const DEMO_SCRIPTS = [
    {
      to: 'Luna',
      from: 'Milo',
      message: 'Meet me under the silver moon. My favorite place in the world is right beside you.',
      styles: ['linen', 'rose', 'gilded'],
      finalStyle: 'linen'
    },
    {
      to: 'Clara',
      from: 'Theo',
      message: 'Thank you for every warm laugh, gentle look, and quiet evening we share together.',
      styles: ['rose', 'gilded', 'linen'],
      finalStyle: 'rose'
    },
    {
      to: 'Sofia',
      from: 'Leo',
      message: 'Just a tiny letter to say you make every ordinary night feel like magic. Always yours.',
      styles: ['gilded', 'linen', 'rose'],
      finalStyle: 'gilded'
    }
  ];

  let demoTimers = [];
  let demoCycle = 0;

  function clearDemoTimers() {
    demoTimers.forEach((id) => clearTimeout(id));
    demoTimers = [];
  }

  function scheduleDemo(fn, ms) {
    const id = setTimeout(() => {
      if (!state.demoActive) return;
      fn();
    }, ms);
    demoTimers.push(id);
  }

  function showSimulatedTap(el) {
    if (!el || !state.demoActive) return;
    const rect = el.getBoundingClientRect();
    if (!rect.width && !rect.height) return;
    const dot = document.createElement('div');
    dot.className = 'sim-ripple';
    dot.style.left = (rect.left + rect.width * 0.5) + 'px';
    dot.style.top = (rect.top + rect.height * 0.5) + 'px';
    document.body.appendChild(dot);
    setTimeout(() => { if (dot.parentNode) dot.parentNode.removeChild(dot); }, 760);
  }

  function isDemoUrl() {
    return window.location.hash === '#demo' || window.location.href.endsWith('#demo');
  }

  function runDemoLoop() {
    if (!state.demoActive) return;
    clearDemoTimers();

    const script = DEMO_SCRIPTS[demoCycle % DEMO_SCRIPTS.length];
    demoCycle++;

    // 0.0s: Compose screen, clear fields and smoothly showcase typing + 3 paper styles
    state.deliveryToken++;
    state.writingToken++;
    showView('compose');
    applyPaperStyle(script.styles[0], true);
    inputTo.value = '';
    inputFrom.value = '';
    inputMsg.value = '';
    updateCharCount();

    // Auto-type To (0.3s -> 0.85s)
    const toChars = Array.from(script.to);
    toChars.forEach((ch, i) => {
      scheduleDemo(() => {
        inputTo.value += ch;
      }, 320 + i * 95);
    });

    // Auto-type From (0.95s -> 1.45s)
    const fromChars = Array.from(script.from);
    fromChars.forEach((ch, i) => {
      scheduleDemo(() => {
        inputFrom.value += ch;
      }, 950 + i * 95);
    });

    // Auto-type Message quickly (1.5s -> 3.0s)
    const msgChars = Array.from(script.message);
    const msgStep = Math.max(12, Math.floor(1450 / Math.max(1, msgChars.length)));
    msgChars.forEach((ch, i) => {
      scheduleDemo(() => {
        inputMsg.value += ch;
        updateCharCount();
      }, 1480 + i * msgStep);
    });

    // Showcase all 3 paper styles clearly (2.1s, 2.85s, 3.55s)
    scheduleDemo(() => {
      const btn = document.querySelector('.style-option[data-style="' + script.styles[1] + '"]');
      showSimulatedTap(btn);
      applyPaperStyle(script.styles[1], true);
    }, 2100);

    scheduleDemo(() => {
      const btn = document.querySelector('.style-option[data-style="' + script.styles[2] + '"]');
      showSimulatedTap(btn);
      applyPaperStyle(script.styles[2], true);
    }, 2850);

    scheduleDemo(() => {
      const btn = document.querySelector('.style-option[data-style="' + script.finalStyle + '"]');
      showSimulatedTap(btn);
      applyPaperStyle(script.finalStyle, true);
    }, 3550);

    // 4.15s: Tap Send -> Cat Postman Delivery!
    scheduleDemo(() => {
      showSimulatedTap(btnSend);
      const r = btnSend.getBoundingClientRect();
      spawnHeartBurst(r.left + r.width * 0.5, r.top + r.height * 0.5, 14, 0.95);
      startDelivery();
    }, 4150);

    // 8.85s: Cat has delivered & departed -> Tap Envelope wax seal!
    scheduleDemo(() => {
      const seal = document.getElementById('env-wax-seal');
      showSimulatedTap(seal || waitingEnvelope);
      openEnvelope();
    }, 8850);

    // 16.5s: Tap the pop-up moonlit cats to send up hearts & gentle parallax sway
    scheduleDemo(() => {
      const rect = popupStage.getBoundingClientRect();
      showSimulatedTap(popupStage);
      petPopUpScene(rect.left + rect.width * 0.5, rect.top + rect.height * 0.56);
    }, 16500);

    // 18.2s: Preview live style switch on the open card briefly
    scheduleDemo(() => {
      const altStyle = script.styles[1];
      const mini = document.querySelector('.mini-style-btn[data-style="' + altStyle + '"]');
      showSimulatedTap(mini);
      applyPaperStyle(altStyle, true);
    }, 18100);

    // 20.0s: Loop seamlessly!
    scheduleDemo(() => {
      runDemoLoop();
    }, 20000);
  }

  function startDemoMode() {
    if (state.demoActive) return;
    state.demoActive = true;
    demoBanner.classList.add('visible');
    runDemoLoop();
  }

  function endDemoMode() {
    if (!state.demoActive) return;
    state.demoActive = false;
    clearDemoTimers();
    demoBanner.classList.remove('visible');
    // Remove any active simulated ripples
    document.querySelectorAll('.sim-ripple').forEach((n) => n.remove());
  }

  // Any real user touch / pointer / key immediately ends #demo and unlocks audio
  function handleRealInteraction(e) {
    if (e && e.isTrusted === false) return;
    Sound.unlock();
    if (state.demoActive) {
      endDemoMode();
    }
  }

  window.addEventListener('pointerdown', handleRealInteraction, { capture: true, passive: true });
  window.addEventListener('touchstart', handleRealInteraction, { capture: true, passive: true });
  window.addEventListener('mousedown', handleRealInteraction, { capture: true, passive: true });
  window.addEventListener('keydown', handleRealInteraction, { capture: true, passive: true });

  window.addEventListener('hashchange', () => {
    if (isDemoUrl()) startDemoMode();
    else endDemoMode();
  });

  window.addEventListener('resize', () => {
    resizeCanvases();
    seedMotes();
  });

  /* ==================== BOOT ==================== */
  initPaperTexture();
  resizeCanvases();
  seedMotes();
  requestAnimationFrame(animateCanvases);

  if (isDemoUrl()) {
    startDemoMode();
  } else {
    loadSaved();
    updateCharCount();
    applyPaperStyle(state.style, true);
  }
})();
</script>
</body>
</html>