/* Reply — a sealed envelope that opens into a letter.
   Drawn in the site's own ink: hairline strokes, flat paper, one blue for
   the wax. Phones first: everything sits in one screen, the password field
   stays clear of the keyboard, and type is at least 16px where it is typed. */

:root { --rp-bad: #c4372b; --rp-w: min(86vw, 25rem, calc((100svh - 23rem) * 1.5)); }
html.dark { --rp-bad: #ff6b5e; }
@media (prefers-color-scheme: dark) { html:not(.light):not(.dark) { --rp-bad: #ff6b5e; } }

html[lang="zh"] [data-en], html:not([lang="zh"]) [data-zh] { display: none !important; }

body.rp { background: var(--bg); color: var(--ink); min-height: 100svh; overflow-x: hidden; }
.rp [hidden] { display: none !important; }

/* ── bar ─────────────────────────────────────────────────── */
.rp-bar { align-items: center; display: flex; font: 600 .7rem/1 var(--mono); justify-content: space-between; left: 0; letter-spacing: .02em; padding: max(1rem, env(safe-area-inset-top)) var(--gutter) 1rem; position: absolute; right: 0; text-transform: uppercase; top: 0; z-index: 5; }
.rp-home { color: var(--ink); text-decoration: none; }
.rp-home:hover { color: var(--accent); }
.rp-lang { display: flex; }
.rp-lang button { background: none; border: 0; color: var(--ink-faint); cursor: pointer; font: inherit; min-height: 2.6rem; min-width: 2.6rem; }
.rp-lang button[aria-pressed="true"] { color: var(--ink); text-decoration: underline 2px var(--accent); text-underline-offset: .35rem; }
.rp-home:focus-visible, .rp-lang button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── stage ───────────────────────────────────────────────── */
.rp-stage { align-items: center; display: flex; flex-direction: column; justify-content: center; min-height: 100svh; padding: 4.5rem var(--gutter) 2.5rem; }
.rp-stage[data-state="opening"] { inset: 0; overflow: hidden; pointer-events: none; position: fixed; z-index: 1; }
.rp-kicker { color: var(--accent); font: 600 .72rem/1.4 var(--mono); letter-spacing: .08em; margin-bottom: clamp(2.6rem, 9svh, 5rem); text-transform: uppercase; transition: opacity .4s; }
.rp-kicker::before, .rp-kicker::after { background: currentColor; content: ''; display: inline-block; height: 1px; margin: 0 .7em; vertical-align: .3em; width: 1.6em; }

/* ── envelope ────────────────────────────────────────────── */
.rp-envelope { aspect-ratio: 3 / 2; max-width: 100%; min-width: 15rem; perspective: 1100px; position: relative; transition: transform .7s var(--ease-out), opacity .5s, filter .5s; width: var(--rp-w); }
.rp-envelope::before { background: var(--ink); content: ''; inset: 0; position: absolute; transform: translate(8px, 8px); }
.rp-layer { height: 100%; inset: 0; overflow: visible; position: absolute; width: 100%; }
.rp-layer path, .rp-layer rect { stroke: var(--ink); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.rp-back { z-index: 0; }
.rp-back rect { fill: var(--surface-soft); }
.rp-pocket { z-index: 3; }
.rp-pocket .rp-fill { fill: var(--surface); stroke-linejoin: round; }

.rp-paper { background: var(--surface); border: 1px solid var(--border-strong); bottom: 5%; display: flex; flex-direction: column; gap: 9%; left: 7%; padding: 9% 9%; position: absolute; right: 7%; top: 5%; transition: transform .8s var(--ease-out); z-index: 2; }
.rp-paper i { background: var(--border); display: block; height: 2px; width: 100%; }
.rp-paper i:nth-child(1) { background: var(--accent); width: 34%; }
.rp-paper i:nth-child(3) { width: 86%; }
.rp-paper i:nth-child(5) { width: 70%; }
.rp-paper i:nth-child(6) { margin-left: auto; width: 26%; }

.rp-flap-wrap { inset: 0; position: absolute; transform-origin: 50% 0; transition: transform .62s cubic-bezier(.55, 0, .25, 1), z-index 0s linear .31s; z-index: 4; }
.rp-flap { filter: drop-shadow(0 2px 0 color-mix(in srgb, var(--ink) 10%, transparent)); }
.rp-flap path { fill: var(--surface); stroke-linejoin: round; }

.rp-address { align-items: baseline; border-bottom: 1px solid var(--ink); bottom: 13%; display: flex; gap: .6em; left: 8%; position: absolute; width: 50%; z-index: 3; }
.rp-to { color: var(--ink-faint); flex: none; font: 600 .6rem/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.rp-to-name { clip-path: inset(0 100% 0 0); color: var(--ink); flex: 1; font: 400 clamp(.95rem, 4.2vw, 1.15rem)/1.5 var(--serif); min-height: 1.5em; min-width: 0; overflow: hidden; text-overflow: ellipsis; transition: clip-path .5s steps(12, end); white-space: nowrap; }
.rp-stamp { align-items: center; background: var(--accent-soft); bottom: 11%; color: var(--accent); display: flex; flex-direction: column; justify-content: center; outline: 1px solid var(--accent); outline-offset: 3px; position: absolute; right: 8%; transform: rotate(4deg); width: 15%; aspect-ratio: 4 / 5; z-index: 3; }
.rp-stamp span { font: 800 clamp(.8rem, 3.6vw, 1.05rem)/1 var(--display); font-stretch: 75%; }
.rp-stamp small { font: 500 .5rem/1.6 var(--mono); }

/* the seal: a blob of wax pressed with 涵. It never breaks: opening the
   letter lifts it off whole */
.rp-seal { aspect-ratio: 1; filter: drop-shadow(0 3px 0 color-mix(in srgb, var(--accent) 45%, #000)) drop-shadow(0 7px 10px rgb(0 0 0 / .2)); left: 50%; position: absolute; top: 57%; transform: translate(-50%, -50%); width: clamp(3.1rem, 19%, 4.6rem); z-index: 5; }
.rp-wax { background: var(--accent); background: radial-gradient(circle at 34% 28%, color-mix(in srgb, var(--accent) 62%, #fff) 0, var(--accent) 42%, color-mix(in srgb, var(--accent) 66%, #000) 100%); border-radius: 48% 52% 46% 54% / 53% 47% 55% 45%; color: color-mix(in srgb, var(--accent) 55%, #000); display: grid; font: 600 clamp(1.2rem, 7vw, 1.75rem)/1 var(--serif); inset: 0; place-items: center; position: absolute; text-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 55%, #fff); user-select: none; }
.rp-wax::after { border: 1.5px solid rgb(0 0 0 / .2); border-radius: 50%; box-shadow: 0 1px 0 rgb(255 255 255 / .22), inset 0 1px 0 rgb(255 255 255 / .12); content: ''; inset: 15%; position: absolute; }
/* a ring of light where the wax let go */
.rp-seal::after { border: 1.5px solid var(--accent); border-radius: 50%; content: ''; inset: 0; opacity: 0; position: absolute; }

/* waiting on the password: the wax glows a little */
.is-warming .rp-wax { animation: rp-warm .9s ease-in-out infinite alternate; }
@keyframes rp-warm { to { filter: brightness(1.18) saturate(1.1); transform: scale(1.05); } }
.is-wrong { animation: rp-shake .46s cubic-bezier(.36, .07, .19, .97); }
@keyframes rp-shake { 15%, 85% { transform: translateX(-3px) rotate(-.4deg); } 30%, 70% { transform: translateX(6px) rotate(.6deg); } 45% { transform: translateX(-8px) rotate(-.8deg); } 60% { transform: translateX(8px); } }

/* opening, in order: name, seal, flap, paper */
.rp-stage[data-state="opening"] .rp-kicker { opacity: 0; }
.rp-stage[data-state="opening"] .rp-envelope { transform: translateY(14%); }
.is-named .rp-to-name { clip-path: inset(0 0 0 0); }
/* the seal is pressed once, then lifts away whole, turning to show its face */
.is-lifted .rp-wax { animation: rp-lift 1s cubic-bezier(.3, 0, .2, 1) forwards; }
.is-lifted .rp-seal::after { animation: rp-ring .55s .2s ease-out forwards; }
@keyframes rp-lift {
  0% { transform: none; }
  20% { opacity: 1; transform: scale(.93); }
  55% { opacity: 1; transform: translateY(-22%) scale(1.12); }
  100% { opacity: 0; transform: translateY(-150%) scale(1.04) rotate(-10deg); }
}
@keyframes rp-ring { 0% { opacity: .7; transform: scale(.9); } 100% { opacity: 0; transform: scale(1.9); } }
.is-open .rp-flap-wrap { transform: rotateX(180deg); z-index: 1; }
.is-out .rp-paper { transform: translateY(-64%); }
.rp-stage.is-leaving .rp-envelope { opacity: 0; transform: translateY(30%); transition-duration: .55s; }

/* the form below */
.rp-lock { margin-top: clamp(1.8rem, 6svh, 3rem); transition: opacity .35s, transform .35s; width: min(100%, var(--rp-w)); min-width: 15rem; }
.rp-stage[data-state="opening"] .rp-lock { opacity: 0; transform: translateY(.8rem); }
.rp-label { color: var(--ink-faint); display: block; font: 600 .64rem/1 var(--mono); letter-spacing: .06em; margin-bottom: .5rem; text-transform: uppercase; }
.rp-field { background: var(--surface); border: 1px solid var(--ink); display: flex; transition: border-color .15s, box-shadow .15s; }
.rp-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rp-field input { background: transparent; border: 0; border-radius: 0; color: var(--ink); flex: 1; font: 500 1.05rem/1.2 var(--mono); letter-spacing: .08em; min-width: 0; outline: none; padding: .9rem .9rem; }
.rp-field button { background: var(--accent); border: 0; border-radius: 0; color: var(--accent-ink); cursor: pointer; flex: none; font: 600 .8rem/1 var(--mono); letter-spacing: .04em; min-width: 5.6rem; padding: 0 1.1rem; text-transform: uppercase; transition: background .2s; }
html[lang="zh"] .rp-field button { font-family: var(--sans); font-size: .95rem; letter-spacing: .2em; padding-left: 1.3rem; }
.rp-field button:hover { background: var(--ink); color: var(--bg); }
.rp-field button:focus-visible { outline: 2px solid var(--ink); outline-offset: -4px; }
.rp-field input:disabled, .rp-field button:disabled { cursor: default; opacity: .5; }
.rp-field button:disabled:hover { background: var(--accent); color: var(--accent-ink); }
.rp-msg { color: var(--ink-soft); font-size: .85rem; line-height: 1.5; margin-top: .7rem; min-height: 1.5em; }
.rp-msg.is-bad { color: var(--rp-bad); }
.rp-hint { color: var(--ink-faint); font-size: .76rem; line-height: 1.5; }
.rp-stage[data-state="loading"] .rp-lock { opacity: .6; }
.rp-stage[data-state="missing"] .rp-envelope { filter: grayscale(1); opacity: .45; }
.rp-stage[data-state="missing"] :is(.rp-label, .rp-field, .rp-hint) { display: none; }
.rp-stage[data-mode="password"] .rp-for-receipt, .rp-stage[data-mode="receipt"] .rp-for-pass { display: none; }
.rp-stage[data-mode="receipt"] .rp-field input { text-transform: uppercase; }
.rp-stage[data-found] .rp-hint { display: none; }
.rp-stage[data-state="missing"] .rp-msg { text-align: center; }

/* ── the letter ──────────────────────────────────────────── */
.rp-letter { margin: 0 auto; max-width: 42rem; padding: 4.6rem var(--gutter) calc(3rem + env(safe-area-inset-bottom)); position: relative; z-index: 2; }
.rp-sheet { background: var(--surface); border: 1px solid var(--ink); box-shadow: 8px 8px 0 var(--ink); padding: clamp(1.5rem, 6.5vw, 3.4rem) clamp(1.3rem, 6vw, 3.4rem) clamp(2rem, 7vw, 3.6rem); transform-origin: 0 0; }
.rp-sheet-head { border-bottom: 1px solid var(--border); color: var(--ink-faint); display: flex; font: 600 .64rem/1.4 var(--mono); gap: 1rem; justify-content: space-between; letter-spacing: .05em; margin-bottom: clamp(1.6rem, 6vw, 2.6rem); padding-bottom: .8rem; text-transform: uppercase; }
.rp-sheet-head > span { color: var(--accent); }
.rp-salute { font: 400 clamp(1.45rem, 6.2vw, 2.1rem)/1.4 var(--serif); letter-spacing: 0; margin-bottom: 1.3rem; overflow-wrap: anywhere; }
.rp-body p, .rp-their-body p { font-family: var(--serif); overflow-wrap: anywhere; text-wrap: pretty; white-space: pre-line; }
.rp-body p { font-size: clamp(1.06rem, 4.3vw, 1.2rem); line-height: 1.8; margin-bottom: 1.15em; }
html[lang="zh"] .rp-body p { line-height: 2; }
.rp-sign { font: italic 400 clamp(1.08rem, 4.4vw, 1.25rem)/1.6 var(--serif); margin-top: 2.2rem; text-align: right; }
.rp-theirs { border-top: 1px dashed var(--border-strong); margin-top: 2.8rem; }
.rp-theirs summary { align-items: center; color: var(--ink-soft); cursor: pointer; display: flex; font: 600 .66rem/1.4 var(--mono); gap: 1rem; justify-content: space-between; letter-spacing: .05em; list-style: none; min-height: 3rem; padding: .8rem 0; text-transform: uppercase; }
.rp-theirs summary::-webkit-details-marker { display: none; }
.rp-theirs summary > span::before { color: var(--accent); content: '+'; display: inline-block; font-size: .9rem; margin-right: .6rem; transition: transform .3s var(--ease-out); }
.rp-theirs[open] summary > span::before { transform: rotate(45deg); }
.rp-theirs summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rp-their-body { border-left: 2px solid var(--accent-soft); color: var(--ink-soft); padding: .3rem 0 .3rem 1rem; }
.rp-their-body p { font-size: 1rem; line-height: 1.85; margin-bottom: .9em; }
.rp-end { font: 600 .68rem/1 var(--mono); letter-spacing: .04em; margin-top: 2.6rem; text-align: center; text-transform: uppercase; }
.rp-end a { color: var(--ink-faint); display: inline-block; padding: .8rem; text-decoration: none; }
.rp-end a:hover { color: var(--accent); }

/* lines of the letter settle in after the sheet lands */
.is-arriving .rp-sheet-head, .is-arriving .rp-salute, .is-arriving .rp-body p, .is-arriving .rp-sign, .is-arriving .rp-theirs { animation: rp-line .9s var(--ease-out) both; }
.is-arriving .rp-sheet-head { animation-delay: .3s; }
.is-arriving .rp-salute { animation-delay: .4s; }
.is-arriving .rp-body p { animation-delay: calc(.5s + var(--n, 0) * 90ms); }
.is-arriving .rp-sign, .is-arriving .rp-theirs { animation-delay: 1.1s; }
@keyframes rp-line { from { opacity: 0; transform: translateY(.7em); } }

.rp-noscript { font-family: var(--sans); padding: 6rem var(--gutter); text-align: center; }

@media (max-width: 480px) {
  .rp-envelope::before { transform: translate(5px, 5px); }
  .rp-sheet { box-shadow: 5px 5px 0 var(--ink); }
}
@media (max-height: 560px) {
  .rp-kicker { margin-bottom: 1.6rem; }
  :root { --rp-w: min(86vw, 25rem, calc((100svh - 15rem) * 1.5)); }
}
@media (prefers-reduced-motion: reduce) {
  .rp-envelope, .rp-paper, .rp-flap-wrap, .rp-to-name, .rp-lock, .rp-kicker { transition: none; }
  .is-warming .rp-wax, .is-wrong, .is-arriving * { animation: none !important; }
}

/* ── photos ──────────────────────────────────────────────── */
.rp-photos { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); margin: 1.6rem 0 .4rem; }
.rp-photos:empty { display: none; }
.rp-photos figure { aspect-ratio: 4 / 3; background: var(--surface-soft); border: 1px solid var(--border-strong); cursor: zoom-in; margin: 0; overflow: hidden; position: relative; }
.rp-photos figure::after { animation: rp-shimmer 1.4s ease-in-out infinite; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent); content: ''; inset: 0; position: absolute; }
.rp-photos figure.is-loaded::after, .rp-photos figure.is-missing::after { content: none; }
.rp-photos img { display: block; height: 100%; object-fit: cover; opacity: 0; transition: opacity .6s var(--ease-out); width: 100%; }
.rp-photos figure.is-loaded img { opacity: 1; }
.rp-photos figure:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rp-their-photos { margin-top: 1rem; }
@keyframes rp-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.is-arriving .rp-photos { animation: rp-line .9s var(--ease-out) 1s both; }

.rp-zoom { align-items: center; background: rgb(8 9 11 / .94); cursor: zoom-out; display: flex; inset: 0; justify-content: center; padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom)); position: fixed; z-index: 10; }
.rp-zoom img { max-height: 100%; max-width: 100%; object-fit: contain; }
.rp-zoom:not([hidden]) img { animation: rp-zoom .35s var(--ease-out); }
@keyframes rp-zoom { from { opacity: 0; transform: scale(.96); } }
@media (prefers-reduced-motion: reduce) { .rp-photos figure::after { animation: none; } .rp-zoom img, .is-arriving .rp-photos { animation: none !important; } }
