@font-face { font-family: Mali; src: url("fonts/mali.ttf") format("truetype"); font-style: normal; font-weight: 400; font-display: swap; }
@font-face { font-family: Lora; src: url("fonts/lora.ttf") format("truetype"); font-style: normal; font-weight: 400 700; font-display: swap; }
@font-face { font-family: "Be Vietnam Pro"; src: url("fonts/be-vietnam-pro.ttf") format("truetype"); font-style: normal; font-weight: 400; font-display: swap; }

/* Phong bì màu mật ong, giấy ngà có thớ và nếp gấp; hoa lam tinh giữ sắc xanh. */
:root {
  --desk: #eeeee8;
  --paper: #faf7ef;
  --paper-light: #fffdf7;
  --paper-shade: #f1ede2;
  --paper-rim: #d4ccb9;
  --crease: #9b8a6a14;
  --paper-texture: url("paper-fibers.png");
  --ink: #293f45;
  --muted: #5f6d6d;
  --blue: #365c70;
  --edge: #d1d5cc;
  --envelope: hsl(38.297872 32.849462% 81.764706%);
  --envelope-light: hsl(38.823529 35.645161% 87.843137%);
  --envelope-shadow: hsl(37.777778 27.421875% 74.901961%);
  --lining: hsl(37.358491 22.516340% 70.000000%);
  --fold: #eee8da;
  --photo-frame: #ffffff;
  --seal: #6a3542;
  --seal-light: #935667;
  --seal-dark: #4c2732;
  --seal-ink: #e6b5be;
  --photo: #e1e8e5;
  --photo-line: #cdd7d2;
  --tape: #e2dcc1b8;
  --silver: #889795;
  --shadow: #253b4426;
  --deep-shadow: #253b4442;
  --clear: #0000;
  --hand: Mali, "Comic Sans MS", cursive;
  --serif: Lora, Georgia, serif;
  --ui: "Be Vietnam Pro", "Trebuchet MS", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; background: var(--desk); color: var(--ink); font: 400 0.85rem/1.6 var(--ui); }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
button:focus-visible, [tabindex="-1"]:focus-visible { outline: 2px solid var(--blue); outline-offset: 7px; }
button:disabled { cursor: default; }
h1, h2, p, figure { margin: 0; }
h1, h2 { font-weight: 400; text-wrap: balance; }
img { max-width: 100%; height: auto; }
[hidden] { display: none !important; }
.desk {
  width: 100%; max-width: 1080px; min-height: 100svh; margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: max(25px, env(safe-area-inset-top, 0px));
  padding-bottom: max(22px, env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 25px;
}
.arrival { flex: 1; display: grid; align-content: center; justify-items: center; padding-block: 18px 36px; min-width: 0; }
.arrival-heading { text-align: center; display: grid; gap: 14px; padding-inline: 10px; }
.eyebrow { font: 400 0.72rem/1.6 var(--ui); color: var(--muted); }
h1 { font: 400 clamp(1.5rem, 4.7vw, 2.05rem)/1.55 var(--hand); }
.stage { width: min(100%, 660px); position: relative; aspect-ratio: 1.38; perspective: 1300px; isolation: isolate; margin-block: 22px 4px; }
.envelope { position: absolute; width: 82%; height: 66%; left: 9%; top: 28%; transform: rotate(-3deg); transform-style: preserve-3d; }
.envelope-part { position: absolute; inset: 0; }
.envelope-back { z-index: 0; border-radius: 2px; background: var(--paper-texture), var(--lining); box-shadow: 0 23px 30px -17px var(--deep-shadow), 0 4px 7px var(--shadow); }
.envelope-back::before { content: ""; position: absolute; inset: 2px; border: 1px solid var(--envelope-shadow); }
.envelope-front { z-index: 3; filter: drop-shadow(0 -1px 0 var(--shadow)); pointer-events: none; }
.pocket-left, .pocket-right, .pocket-bottom { position: absolute; inset: 0; }
.pocket-left { background: var(--paper-texture), var(--envelope-light); clip-path: polygon(0 0, 58% 56%, 0 100%); }
.pocket-right { background: var(--paper-texture), var(--envelope-shadow); clip-path: polygon(100% 0, 42% 56%, 100% 100%); }
.pocket-bottom { background: var(--paper-texture), var(--envelope); clip-path: polygon(0 100%, 0 97%, 49% 44%, 51% 44%, 100% 97%, 100% 100%); }
.pocket-bottom::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--envelope-shadow); }
.address { position: absolute; left: 9%; bottom: 8%; display: grid; gap: 0; color: var(--ink); transform: rotate(1deg); }
.address > span { font: 400 clamp(1.2rem, 4.8vw, 2rem)/1.35 var(--hand); }
.address small { font: 400 clamp(0.65rem, 2.1vw, 0.85rem)/1.6 var(--hand); }
.flap { z-index: 4; transform-origin: 50% 0; height: 58%; filter: drop-shadow(0 3px 2px var(--shadow)); backface-visibility: visible; }
.flap > div { width: 100%; height: 100%; background: var(--paper-texture), var(--envelope-light); clip-path: polygon(0 0, 100% 0, 52% 100%, 48% 100%); }
.flap::after { content: ""; position: absolute; inset: 0 0 auto; height: 1px; background: var(--envelope-shadow); }
.folded-paper { position: absolute; width: 80%; height: 72%; left: 10%; top: 9%; z-index: 1; transform-style: preserve-3d; }
.paper-middle { position: absolute; inset: 0; background: var(--paper); padding: 10% 12%; box-shadow: 0 1px 4px var(--shadow); font-family: var(--hand); display: grid; align-content: center; gap: 7%; }
.paper-middle span { font-size: clamp(0.9rem, 3vw, 1.3rem); }
.paper-middle i { width: 80%; border-top: 1px solid var(--edge); }
.paper-middle i:nth-of-type(2) { width: 57%; }
.paper-middle small { justify-self: end; font-size: clamp(0.7rem, 2vw, 1rem); }
.paper-wing { position: absolute; inset: 0; background: var(--fold); backface-visibility: visible; border: 1px solid var(--edge); }
.paper-top { transform-origin: center top; background: var(--paper); }
.paper-bottom { transform-origin: center bottom; display: grid; place-content: center; background: linear-gradient(0deg, var(--fold), var(--paper)); }
.paper-bottom span { font: 400 0.62rem/1 var(--serif); color: var(--muted); }
.seal { position: absolute; z-index: 6; left: calc(50% - 31px); top: calc(51% - 31px); width: 62px; height: 62px; border: 0; padding: 0; background: none; border-radius: 50%; filter: drop-shadow(1px 5px 3px var(--shadow)); }
.seal::before { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 28% 20%, var(--seal-light) 0, var(--seal) 51%, var(--seal-dark) 100%); border-radius: 47% 53% 45% 55% / 55% 46% 54% 45%; box-shadow: inset 2px 2px 1px var(--seal-light), inset -2px -2px 1px var(--seal-dark); }
.seal-imprint { position: absolute; inset: 9px; border: 1px solid var(--seal-dark); border-radius: 50%; display: flex; align-items: center; justify-content: center; gap: 0.12em; font: 400 1.65rem/1 var(--serif); color: var(--seal-ink); box-shadow: inset 1px 1px 1px var(--seal-dark), 1px 1px 0 var(--seal-light); text-shadow: 1px 1px 0 var(--seal-dark); }
.seal-letter { flex: 0 0 0.32em; text-align: center; }
.seal-dot { flex: 0 0 0.18em; text-align: center; font-size: 0.6em; }
@media (hover: hover) { .seal:hover { filter: drop-shadow(1px 6px 4px var(--deep-shadow)) brightness(1.07); } .text-button:hover { color: var(--ink); text-decoration-color: var(--ink); } }
.tucked-photo { position: absolute; z-index: -1; width: 32%; top: 15%; right: 6%; background: var(--photo-frame); padding: 8px 8px 6px; box-shadow: 1px 4px 7px var(--shadow); transform: rotate(10deg); display: flex; flex-direction: column; gap: 3px; }
.tucked-photo > img { visibility: hidden; }
.tucked-photo > .tucked-back { position: absolute; inset: 0; display: grid; place-items: center; background: var(--paper-texture), var(--photo-frame); color: var(--muted); font: 400 1rem/1.4 var(--serif); }
.pressed-sprig { position: absolute; width: 23%; height: auto; bottom: -14%; right: -2%; transform: rotate(22deg); z-index: 7; pointer-events: none; filter: drop-shadow(1px 2px 1px var(--shadow)); }
.arrival-controls { display: grid; justify-items: center; gap: 5px; padding-top: 8px; }
.opening-hint { font: 400 0.95rem/1.6 var(--hand); color: var(--muted); text-align: center; }
.text-button { min-height: 44px; padding: 10px 8px; border: 0; background: none; font: 400 0.75rem/1.6 var(--ui); color: var(--blue); text-decoration: underline; text-decoration-color: var(--edge); text-underline-offset: 6px; }
.reading { width: 100%; max-width: 780px; margin-inline: auto; display: grid; gap: 54px; padding-block: 24px; min-width: 0; }
.letter { width: 100%; max-width: 650px; margin-inline: auto; padding: clamp(26px, 7vw, 64px); padding-bottom: 32px; position: relative; isolation: isolate; filter: drop-shadow(0 2px 1px var(--shadow)) drop-shadow(3px 12px 13px var(--shadow)); }
.letter::before, .letter::after { content: ""; position: absolute; z-index: 0; left: 1px; right: 1px; height: 12px; opacity: 0.45; pointer-events: none; background: linear-gradient(var(--clear), var(--crease) 45%, var(--paper-light) 51%, var(--clear)); }
.letter::before { top: 33%; transform: rotate(-0.15deg); }
.letter::after { top: 67%; transform: rotate(0.12deg); }
.paper-edge { position: absolute; inset: 0; z-index: -1; background: var(--paper-texture), linear-gradient(105deg, var(--paper-light), var(--paper) 35%, var(--paper-shade)); box-shadow: inset 0 1px 0 var(--paper-light), inset -1px -2px 0 var(--paper-rim); clip-path: polygon(0.2% 0.2%, 23% 0, 49% 0.2%, 76% 0, 99.8% 0.2%, 100% 24%, 99.8% 51%, 100% 77%, 99.7% 99.8%, 73% 100%, 45% 99.8%, 18% 100%, 0.2% 99.7%, 0 72%, 0.2% 43%, 0 18%); }
.letter-header { display: grid; gap: 34px; position: relative; }
.letter-date { justify-self: end; font: 400 0.73rem/1.7 var(--serif); color: var(--muted); }
.letter h2 { font: 400 clamp(1.75rem, 5vw, 2.35rem)/1.5 var(--hand); }
.letter-body { margin-top: 32px; min-height: 165px; position: relative; z-index: 1; font: 400 clamp(1.05rem, 3.4vw, 1.2rem)/1.9 var(--hand); max-width: 58ch; }
.letter-body p + p { margin-top: 1.2em; }
.letter-ending { display: flex; align-items: end; justify-content: space-between; gap: 20px; position: relative; z-index: 1; min-height: 155px; padding-top: 30px; padding-bottom: 12px; }
.signature { font: 400 1.7rem/1.5 var(--hand); padding-bottom: 12px; }
.letter-sprig { position: relative; z-index: 1; width: 84px; height: 160px; object-fit: contain; transform: rotate(13deg); margin-bottom: -20px; filter: drop-shadow(1px 2px 1px var(--shadow)); }
.letter-footer { position: relative; margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--crease); font: 400 0.92rem/1.8 var(--hand); color: var(--ink); }
.letter-footer span { color: var(--blue); margin-right: 0.3em; }
.scrapbook { display: grid; gap: 33px; }
.scrapbook-heading { padding-inline: 12px; display: grid; gap: 7px; }
.scrapbook-heading h2 { font: 400 1.8rem/1.5 var(--hand); }
.photo-layout { display: grid; grid-template-columns: 1.18fr 1fr; align-items: start; gap: 30px; padding: 15px 12px; min-width: 0; }
.memory { min-width: 0; position: relative; perspective: 1400px; }
.memory-card { display: grid; transform-style: preserve-3d; transform: rotateY(0deg); transition: transform 650ms cubic-bezier(.2, .65, .25, 1); }
.memory-front, .memory-back { grid-area: 1 / 1; padding: 12px 12px 15px; background: var(--photo-frame); box-shadow: 0 2px 4px var(--shadow); backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.memory-front { position: relative; min-width: 0; transform: rotateY(180deg); }
.memory-back { transform: rotateY(0deg); display: grid; place-content: center; justify-items: center; gap: 12px; background: var(--paper-texture), var(--photo-frame); border: 1px solid var(--edge); }
.memory-back > span { font: 400 1.3rem/1.4 var(--serif); color: var(--blue); }
.memory-back > small { font: 400 0.75rem/1.7 var(--hand); color: var(--muted); }
.memory-toggle { position: absolute; inset: 0; z-index: 2; min-width: 44px; min-height: 44px; border: 0; border-radius: 0; padding: 0; background: none; touch-action: pan-y pinch-zoom; }
.photo-layout[data-mode="deck"] { grid-template-columns: minmax(0, 340px); justify-content: center; padding-block: 18px 8px; }
.photo-layout[data-mode="deck"] .memory { width: 100%; grid-column: 1; margin: 0; transform: rotate(-2deg); }
.photo-layout[data-mode="deck"] .memory[data-current="true"] { animation: deal-photo 300ms ease-out both; }
.photo-layout[data-mode="deck"][data-moving="true"] .memory[data-current="true"] { animation: slide-photo 280ms ease-in both; pointer-events: none; }
.deck-controls { display: grid; justify-items: center; gap: 4px; margin-top: -17px; text-align: center; }
.deck-count { font: 400 0.72rem/1.6 var(--serif); color: var(--muted); }
.deck-hint { font: 400 0.9rem/1.7 var(--hand); color: var(--muted); }
.deck-next:disabled { opacity: 0.5; text-decoration: none; }
.photo-layout[data-mode="spread"] .memory { animation: place-photo 380ms ease-out both; }
@keyframes deal-photo { from { opacity: 0.2; transform: translateX(14px) rotate(1deg); } to { opacity: 1; transform: translateX(0) rotate(-2deg); } }
@keyframes slide-photo { from { opacity: 1; transform: translateX(0) rotate(-2deg); } to { opacity: 0; transform: translateX(-40px) rotate(-7deg); } }
@keyframes place-photo { from { opacity: 0.3; } to { opacity: 1; } }
.memory[data-revealed="true"] .memory-card { transform: rotateY(180deg); }
.memory-wide { transform: rotate(-3deg); margin-top: 7px; }
.memory-tall { transform: rotate(3deg); margin-top: 63px; }
.memory-last { grid-column: 1 / -1; width: 66%; margin-inline: 8% auto; transform: rotate(1deg); margin-top: -14px; }
.memory-front > img, .tucked-photo > img { display: block; width: 100%; height: auto; }
.memory figcaption { padding-top: 12px; font: 400 0.9rem/1.7 var(--hand); color: var(--muted); }
.tape { position: absolute; width: 38%; height: 24px; background: var(--tape); top: -12px; left: 32%; transform: rotate(4deg); clip-path: polygon(2% 0, 98% 0, 100% 15%, 98% 32%, 100% 58%, 98% 81%, 100% 100%, 0 100%, 2% 74%, 0 48%, 2% 24%); }
.paperclip { position: absolute; z-index: 1; top: -13px; right: 24px; height: 49px; width: 16px; border: 2px solid var(--silver); border-radius: 10px; transform: rotate(12deg); box-shadow: 1px 1px 1px var(--shadow); }
.paperclip::after { content: ""; position: absolute; top: 6px; left: 3px; width: 6px; height: 31px; border: 1.5px solid var(--silver); border-radius: 6px; }
.reading-actions { display: grid; justify-items: center; gap: 8px; }
.reading-actions p { font: 400 0.9rem/1.6 var(--hand); color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.no-script { font-size: 0.8rem; text-align: center; color: var(--muted); }

[data-state="opening"] .seal { animation: lift-seal 350ms ease-in both; pointer-events: none; }
[data-state="opening"] .flap { animation: open-flap 650ms 180ms cubic-bezier(.4, 0, .2, 1) both; }
[data-state="opening"] .folded-paper { animation: pull-letter 1100ms 650ms cubic-bezier(.4, 0, .2, 1) both; }
[data-state="opening"] .paper-top { animation: unfold-top 550ms 1350ms ease-in-out both; }
[data-state="opening"] .paper-bottom { animation: unfold-bottom 550ms 1470ms ease-in-out both; }
[data-state="opening"] .envelope-part { animation: pocket-away 450ms 1570ms ease-in both; }
[data-state="opening"] .flap { animation-name: open-flap, pocket-away; animation-duration: 650ms, 450ms; animation-delay: 180ms, 1570ms; animation-timing-function: cubic-bezier(.4, 0, .2, 1), ease-in; animation-fill-mode: both, both; }
[data-state="opening"] .tucked-photo, [data-state="opening"] .pressed-sprig { animation: clear-desk 500ms 1250ms ease-in both; }
[data-state="reading"] .reading.just-opened { animation: settle-letter 420ms cubic-bezier(.2, .7, .3, 1) both; }
@keyframes lift-seal { to { transform: translate(12px, -22px) rotate(15deg); opacity: 0; } }
@keyframes open-flap { 0% { z-index: 4; transform: rotateX(0); } 49% { z-index: 4; } 50%, 100% { z-index: 0; transform: rotateX(-180deg); } }
@keyframes pull-letter { 0% { transform: translateY(0); z-index: 1; } 55% { transform: translateY(-108%); z-index: 1; } 56% { z-index: 5; } 100% { transform: translateY(-30%) rotate(3deg); z-index: 5; } }
@keyframes unfold-top { to { transform: rotateX(180deg); } }
@keyframes unfold-bottom { to { transform: rotateX(-180deg); } }
@keyframes pocket-away { to { opacity: 0; } }
@keyframes clear-desk { to { opacity: 0; } }
@keyframes settle-letter { from { opacity: 0.4; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

@media (min-width: 750px) { .desk { padding-block: 32px 26px; } .arrival { padding-top: 12px; } .stage { max-width: 620px; margin-block: 18px 0; } .reading { padding-block: 25px 45px; } }
@media (max-width: 420px) {
  .desk { gap: 20px; }
  .arrival { padding-block: 20px; }
  .arrival-heading { padding-inline: 4px; }
  .stage { aspect-ratio: 1.05; margin-top: 12px; }
  .envelope { width: 86%; left: 7%; top: 31%; height: 53.9%; }
  .tucked-photo { top: 18%; right: 7%; }
  .seal { width: 54px; height: 54px; left: calc(50% - 27px); top: calc(51% - 27px); }
  .seal-imprint { inset: 8px; font-size: 1.4rem; }
  .letter { padding: 28px 24px 25px; }
  .letter-header { gap: 24px; }
  .letter-body { margin-top: 24px; }
  .reading { gap: 40px; padding-top: 5px; }
  .letter-ending { min-height: 130px; }
  .letter-sprig { height: 140px; width: 72px; }
  .photo-layout { gap: 22px; padding-inline: 9px; }
  .memory-front, .memory-back { padding: 8px 8px 12px; }
  .memory-tall { margin-top: 48px; }
  .memory-last { width: 78%; margin-top: 0; }
  .memory figcaption { font-size: 0.8rem; }
  .scrapbook-heading { padding-inline: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
