/* ------------------------------------------------------------------ */
/* Tokens                                                             */
/* ------------------------------------------------------------------ */

/* Registered so the 60 s sky updates glide instead of snapping. */
@property --sky-top    { syntax: "<color>"; inherits: true; initial-value: #0a0f2c; }
@property --sky-mid    { syntax: "<color>"; inherits: true; initial-value: #1c1f4d; }
@property --sky-bottom { syntax: "<color>"; inherits: true; initial-value: #3b2c5c; }
@property --lamp       { syntax: "<number>"; inherits: true; initial-value: 0; }
@property --clouds     { syntax: "<number>"; inherits: true; initial-value: 0; }

:root {
  /* Live sky values, written by js/ui/sky.js (defaults: night). */
  --sky-top: #0a0f2c;
  --sky-mid: #1c1f4d;
  --sky-bottom: #3b2c5c;
  --lamp: 0;
  --clouds: 0;

  /* Palette */
  --cloud-light: #fffaf4;
  --cloud-shade: #e9e4ef;
  --glow-white: #fff6ea;
  --lamp-warm: #ffb46b;
  --ink: #2b2230;
  /* Handwriting: one token everything written uses; :lang(zh) below swaps the hand. */
  --font-hand-en: "Caveat", "Bradley Hand", "Segoe Print", "Snell Roundhand", Georgia, serif;
  --font-hand-zh: "Long Cang", "Caveat", "Kaiti SC", "STKaiti", serif; /* Caveat: accents Long Cang lacks (você) */
  --font-hand: var(--font-hand-en);
  --graphite: #57534f; /* soft pencil, for notes in the margin */
  --pen: #1f2547; /* blue-black fountain-pen ink */
  --pen-wet: #141a3f;
  --paper: #fbf5e9;
  --print: #fdfbf6; /* photo paper, a touch whiter than the letter */
  --print-back: #f5f0e4;
  --album: #2a2320; /* old album photo corners */
  --crease-ink: 120 88 48; /* rgb triplet, used with an alpha */

  /* Envelope + wax */
  --envelope: #f2e6d1;
  --envelope-light: #f8f0e2;
  --envelope-shade: #e2d1b4;
  --liner: #1d2452;
  --liner-star: #e8cd93;
  --wax: #8e1821;
  --wax-deep: #5c0d14;
  --record: #1b1a1f;

  /* Paper sheet: the envelope's letter unfolds exactly onto this rect. */
  --paper-w: min(92vw, 560px);
  --paper-ratio: 1.4142;
  --paper-top: clamp(20px, 5svh, 64px);
  --paper-shadow:
    0 1px 1px rgb(40 24 10 / 0.12),
    0 8px 18px -6px rgb(20 12 40 / 0.32),
    0 30px 60px -18px rgb(10 6 30 / 0.5);

  --sky-ease: 24s linear;
}

@property --crease { syntax: "<number>"; inherits: true; initial-value: 1; }

/* Whatever is in Chinese is written in the Chinese hand: the letter, captions, the P.S.
   Re-declared on every element, so a lang="en" island inside Chinese gets its own hand. */
:lang(zh) { --font-hand: var(--font-hand-zh); }
:lang(en) { --font-hand: var(--font-hand-en); }

:root[data-sky-ready] {
  transition:
    --sky-top var(--sky-ease),
    --sky-mid var(--sky-ease),
    --sky-bottom var(--sky-ease),
    --lamp var(--sky-ease),
    --clouds var(--sky-ease);
}

/* ------------------------------------------------------------------ */
/* Base                                                               */
/* ------------------------------------------------------------------ */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  min-height: 100dvh;
  background: var(--sky-top);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ------------------------------------------------------------------ */
/* Living sky                                                         */
/* ------------------------------------------------------------------ */

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: var(--sky-top);
}

.sky > * {
  position: absolute;
  inset: 0;
}

/* Three-stop gradient, eased with two blended stops so it never bands. */
.sky__gradient {
  background: linear-gradient(
    180deg,
    var(--sky-top) 0%,
    color-mix(in srgb, var(--sky-top) 55%, var(--sky-mid)) 30%,
    var(--sky-mid) 62%,
    color-mix(in srgb, var(--sky-mid) 45%, var(--sky-bottom)) 80%,
    var(--sky-bottom) 100%
  );
  background: linear-gradient(
    in oklab 180deg,
    var(--sky-top) 0%,
    color-mix(in oklab, var(--sky-top) 55%, var(--sky-mid)) 30%,
    var(--sky-mid) 62%,
    color-mix(in oklab, var(--sky-mid) 45%, var(--sky-bottom)) 80%,
    var(--sky-bottom) 100%
  );
}

/* Soft light rising from the horizon, plus a hush of shade at the zenith. */
.sky__glow {
  background:
    radial-gradient(
      200% 42% at 50% 112%,
      color-mix(in srgb, var(--sky-bottom) 72%, var(--glow-white)) 0%,
      color-mix(in srgb, var(--sky-bottom) 55%, transparent) 45%,
      transparent 100%
    ),
    radial-gradient(
      90% 40% at 22% 100%,
      color-mix(in srgb, var(--sky-bottom) 60%, transparent) 0%,
      transparent 70%
    ),
    radial-gradient(
      160% 60% at 50% -12%,
      color-mix(in srgb, var(--sky-top) 70%, #000) 0%,
      transparent 70%
    );
  opacity: 0.85;
}

.sky__stars {
  width: 100%;
  height: 100%;
  display: block;
}

/* Clouds: clusters of feathered puffs drifting slowly across. */
/* --cloud-tint / --cloud-under are set by js/ui/sky.js once a minute (cloudTints()):
   mixing them here from the gliding sky colours repainted every blurred cloud each frame. */
.sky__clouds {
  opacity: var(--clouds);
  --cloud-tint: var(--cloud-light);
  --cloud-under: var(--cloud-shade);
}

.sky[data-clouds="off"] .sky__clouds { visibility: hidden; }
.sky[data-clouds="off"] .cloud { animation-play-state: paused; }

.cloud {
  position: absolute;
  left: 0;
  top: var(--y);
  width: var(--w);
  height: calc(var(--w) / 4);
  opacity: var(--o);
  filter: blur(var(--blur, 6px));
  will-change: transform;
  animation: cloud-drift var(--dur) linear var(--delay) infinite;
}

/* Each puff is a feathered ellipse: lit on top, faintly shaded beneath. */
.cloud i {
  position: absolute;
  left: var(--px);
  top: var(--py);
  width: var(--pw);
  height: var(--ph);
  border-radius: 50%;
  background:
    radial-gradient(
      ellipse closest-side at 50% 42%,
      var(--cloud-tint) 0%,
      color-mix(in srgb, var(--cloud-tint) 80%, transparent) 45%,
      transparent 100%
    ),
    radial-gradient(
      ellipse closest-side at 50% 70%,
      color-mix(in srgb, var(--cloud-under) 70%, transparent) 0%,
      transparent 100%
    );
}

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

/* Film grain: hides gradient banding and makes the sky feel like paper. A plain
   faint overlay (no blend mode), so it costs nothing over the drifting layers. */
.sky__grain {
  opacity: 0.05;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 1.4 -.2'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 180px 180px;
}

.sky-effects { overflow: hidden; contain: strict; }
.sky-effects.is-paused *,
.sky-effects.is-paused *::before,
.sky-effects.is-paused *::after { animation-play-state: paused !important; }

/* ---- Valentine's: rose petals drifting down ---------------------------- */
/* Layered motions so they read as real petals: the fall (with a breeze carrying it
   sideways) and a slow sway on the petal itself, and on its face a spin with a
   flutter that tips it edge-on now and then. Nearer petals are bigger, brighter and
   quicker. (Spin and flutter share one 3D keyframe set on purpose: an animated
   transform on the direct parent of a 3D-animated layer made Chrome repaint every
   petal on every frame.) */
.fx-petal {
  --petal: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><defs><radialGradient id='g' cx='46%' cy='96%' r='100%'><stop offset='0' stop-color='%23fff7f2'/><stop offset='.45' stop-color='%23f9c9d3'/><stop offset='1' stop-color='%23e793aa'/></radialGradient><linearGradient id='l' x1='0' y1='0' x2='1' y2='.3'><stop offset='0' stop-color='%23fff' stop-opacity='.34'/><stop offset='.45' stop-color='%23fff' stop-opacity='0'/><stop offset='1' stop-color='%23802040' stop-opacity='.14'/></linearGradient></defs><path d='M47 97C29 90 9 71 6 48C3 25 17 8 37 5C44 4 48 7.5 53 6.5C71 3 93 13 95.5 37C98 61 77 86 47 97Z' fill='url(%23g)'/><path d='M47 97C29 90 9 71 6 48C3 25 17 8 37 5C44 4 48 7.5 53 6.5C71 3 93 13 95.5 37C98 61 77 86 47 97Z' fill='url(%23l)'/><path d='M47 97C29 90 9 71 6 48C3 25 17 8 37 5C44 4 48 7.5 53 6.5C71 3 93 13 95.5 37C98 61 77 86 47 97Z' fill='none' stroke='%23802040' stroke-opacity='.12' stroke-width='1.6'/><path d='M47 93C43 70 44 40 52 12' stroke='%23fff' stroke-opacity='.26' stroke-width='1.2' fill='none'/><path d='M20 30C30 20 44 18 56 22' stroke='%23fff' stroke-opacity='.16' stroke-width='3' stroke-linecap='round' fill='none'/></svg>");
  position: absolute;
  left: var(--x);
  top: calc(var(--size) * -2);
  width: var(--size);
  height: var(--size);
  opacity: var(--o);
  will-change: transform;
  animation:
    petal-fall var(--fall) linear var(--delay) infinite,
    petal-sway var(--sway-dur) ease-in-out var(--delay) infinite alternate;
}
.fx-petal[data-tone="1"] {
  --petal: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><defs><radialGradient id='g' cx='46%' cy='96%' r='100%'><stop offset='0' stop-color='%23fde4e7'/><stop offset='.45' stop-color='%23f094ab'/><stop offset='1' stop-color='%23cf4d74'/></radialGradient><linearGradient id='l' x1='0' y1='0' x2='1' y2='.3'><stop offset='0' stop-color='%23fff' stop-opacity='.34'/><stop offset='.45' stop-color='%23fff' stop-opacity='0'/><stop offset='1' stop-color='%23601030' stop-opacity='.18'/></linearGradient></defs><path d='M47 97C29 90 9 71 6 48C3 25 17 8 37 5C44 4 48 7.5 53 6.5C71 3 93 13 95.5 37C98 61 77 86 47 97Z' fill='url(%23g)'/><path d='M47 97C29 90 9 71 6 48C3 25 17 8 37 5C44 4 48 7.5 53 6.5C71 3 93 13 95.5 37C98 61 77 86 47 97Z' fill='url(%23l)'/><path d='M47 97C29 90 9 71 6 48C3 25 17 8 37 5C44 4 48 7.5 53 6.5C71 3 93 13 95.5 37C98 61 77 86 47 97Z' fill='none' stroke='%23601030' stroke-opacity='.12' stroke-width='1.6'/><path d='M47 93C43 70 44 40 52 12' stroke='%23fff' stroke-opacity='.22' stroke-width='1.2' fill='none'/><path d='M20 30C30 20 44 18 56 22' stroke='%23fff' stroke-opacity='.16' stroke-width='3' stroke-linecap='round' fill='none'/></svg>");
}
.fx-petal[data-tone="2"] {
  --petal: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><defs><radialGradient id='g' cx='46%' cy='96%' r='100%'><stop offset='0' stop-color='%23f7b9c2'/><stop offset='.45' stop-color='%23db4f6c'/><stop offset='1' stop-color='%23a01a3e'/></radialGradient><linearGradient id='l' x1='0' y1='0' x2='1' y2='.3'><stop offset='0' stop-color='%23fff' stop-opacity='.34'/><stop offset='.45' stop-color='%23fff' stop-opacity='0'/><stop offset='1' stop-color='%23400818' stop-opacity='.22'/></linearGradient></defs><path d='M47 97C29 90 9 71 6 48C3 25 17 8 37 5C44 4 48 7.5 53 6.5C71 3 93 13 95.5 37C98 61 77 86 47 97Z' fill='url(%23g)'/><path d='M47 97C29 90 9 71 6 48C3 25 17 8 37 5C44 4 48 7.5 53 6.5C71 3 93 13 95.5 37C98 61 77 86 47 97Z' fill='url(%23l)'/><path d='M47 97C29 90 9 71 6 48C3 25 17 8 37 5C44 4 48 7.5 53 6.5C71 3 93 13 95.5 37C98 61 77 86 47 97Z' fill='none' stroke='%23400818' stroke-opacity='.12' stroke-width='1.6'/><path d='M47 93C43 70 44 40 52 12' stroke='%23fff' stroke-opacity='.18' stroke-width='1.2' fill='none'/><path d='M20 30C30 20 44 18 56 22' stroke='%23fff' stroke-opacity='.16' stroke-width='3' stroke-linecap='round' fill='none'/></svg>");
}

.fx-petal__flutter {
  position: absolute;
  inset: 0;
}
.fx-petal__flutter::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--petal) center / 100% 100% no-repeat;
  animation: petal-whirl var(--spin) linear var(--delay) infinite;
}
.fx-petal.is-soft .fx-petal__flutter::before { filter: blur(var(--blur)); }

@keyframes petal-fall {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(var(--drift), calc(100vh + var(--size) * 4), 0); }
}
@keyframes petal-sway {
  from { translate: calc(var(--sway) * -0.5) 0; }
  to   { translate: calc(var(--sway) * 0.5) 0; }
}
/* one full turn, fluttering twice on the way round (the second time a little differently) */
@keyframes petal-whirl {
  0%    { transform: perspective(90px) rotate(var(--tilt)) rotateX(0deg) rotateY(0deg); }
  12.5% { transform: perspective(90px) rotate(calc(var(--tilt) + 45deg * var(--dir))) rotateX(calc(var(--ay) * 64deg)) rotateY(calc(var(--ax) * 26deg)); }
  25%   { transform: perspective(90px) rotate(calc(var(--tilt) + 90deg * var(--dir))) rotateX(calc(var(--ay) * 14deg)) rotateY(calc(var(--ax) * -32deg)); }
  37.5% { transform: perspective(90px) rotate(calc(var(--tilt) + 135deg * var(--dir))) rotateX(calc(var(--ay) * -56deg)) rotateY(calc(var(--ax) * 12deg)); }
  50%   { transform: perspective(90px) rotate(calc(var(--tilt) + 180deg * var(--dir))) rotateX(0deg) rotateY(0deg); }
  62.5% { transform: perspective(90px) rotate(calc(var(--tilt) + 225deg * var(--dir))) rotateX(calc(var(--ay) * -48deg)) rotateY(calc(var(--ax) * -20deg)); }
  75%   { transform: perspective(90px) rotate(calc(var(--tilt) + 270deg * var(--dir))) rotateX(calc(var(--ay) * 22deg)) rotateY(calc(var(--ax) * 30deg)); }
  87.5% { transform: perspective(90px) rotate(calc(var(--tilt) + 315deg * var(--dir))) rotateX(calc(var(--ay) * 60deg)) rotateY(calc(var(--ax) * -10deg)); }
  100%  { transform: perspective(90px) rotate(calc(var(--tilt) + 360deg * var(--dir))) rotateX(0deg) rotateY(0deg); }
}

/* ---- Lanterns: sky lanterns rising slowly, lit from inside --------------- */
.fx-lantern {
  --body: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 52'><defs><linearGradient id='v' x1='0' y1='0' x2='0' y2='1'><stop offset='0' stop-color='%239a1427'/><stop offset='.42' stop-color='%23d93a2e'/><stop offset='.78' stop-color='%23ff9a4a'/><stop offset='1' stop-color='%23ffe2a0'/></linearGradient><linearGradient id='h' x1='0' y1='0' x2='1' y2='0'><stop offset='0' stop-color='%23400008' stop-opacity='.45'/><stop offset='.32' stop-color='%23400008' stop-opacity='0'/><stop offset='.55' stop-color='%23fff0c0' stop-opacity='.16'/><stop offset='.7' stop-color='%23400008' stop-opacity='0'/><stop offset='1' stop-color='%23400008' stop-opacity='.45'/></linearGradient></defs><path d='M4 10Q4 2 20 2Q36 2 36 10L31.5 46Q20 49.5 8.5 46Z' fill='url(%23v)'/><path d='M4 10Q4 2 20 2Q36 2 36 10L31.5 46Q20 49.5 8.5 46Z' fill='url(%23h)'/><path d='M14 3.2L13.2 47.4M26 3.2L26.8 47.4M4.6 18Q20 15.5 35.4 18' stroke='%23601008' stroke-opacity='.16' stroke-width='.6' fill='none'/><ellipse cx='20' cy='46.6' rx='11.4' ry='1.7' fill='%23702010' fill-opacity='.5'/><ellipse cx='20' cy='47.6' rx='3.2' ry='1.9' fill='%23fff4cc'/></svg>");
  --glow: 255 176 96;
  position: absolute;
  left: var(--x);
  bottom: calc(var(--size) * -2);
  width: var(--size);
  height: calc(var(--size) * 1.3);
  will-change: transform, opacity;
  animation: lantern-rise var(--rise) linear var(--delay) infinite;
}
.fx-lantern__sway {
  position: absolute;
  inset: 0;
  opacity: var(--o);
  rotate: var(--tilt);
  animation: lantern-sway var(--sway-dur) ease-in-out var(--delay) infinite alternate;
}
/* the warm light around it: brighter at night, flickering with the flame */
.fx-lantern__glow {
  position: absolute;
  left: 50%;
  top: 66%;
  width: 560%;
  aspect-ratio: 1;
  translate: -50% -50%;
  opacity: calc(0.4 + 0.6 * var(--stars, 1));
}
.fx-lantern__glow::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(
    closest-side,
    rgb(var(--glow) / 0.58) 0%,
    rgb(var(--glow) / 0.25) 22%,
    rgb(var(--glow) / 0.08) 50%,
    rgb(var(--glow) / 0) 100%
  );
  animation: lantern-flicker var(--flicker) ease-in-out var(--delay) infinite alternate;
}
.fx-lantern__body {
  position: absolute;
  inset: 0;
  background: var(--body) center / 100% 100% no-repeat;
}

@keyframes lantern-rise {
  0%   { transform: translate3d(-50%, 0, 0) scale(1); opacity: 0; }
  8%   { opacity: 1; }
  82%  { opacity: 1; }
  100% { transform: translate3d(-50%, calc(-100vh - var(--size) * 4), 0) scale(0.55); opacity: 0; }
}
@keyframes lantern-sway {
  from { translate: calc(var(--sway) * -1) 0; rotate: calc(var(--tilt) - 2.5deg); }
  to   { translate: var(--sway) 0; rotate: calc(var(--tilt) + 2.5deg); }
}
@keyframes lantern-flicker {
  0%   { opacity: 0.82; }
  35%  { opacity: 1; }
  60%  { opacity: 0.88; }
  100% { opacity: 0.97; }
}

/* Chinese New Year: a red and gold glow along the horizon, a hush of crimson above. */
.fx-accent {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(90% 18% at 50% 103%, rgb(255 200 104 / 0.42), rgb(255 176 84 / 0) 78%),
    radial-gradient(150% 42% at 50% 110%, rgb(214 34 44 / 0.58), rgb(170 20 44 / 0.24) 55%, rgb(150 18 48 / 0) 84%),
    radial-gradient(130% 34% at 50% -8%, rgb(150 16 40 / 0.34), rgb(140 16 40 / 0) 72%);
  opacity: calc(0.55 + 0.45 * var(--stars, 1));
}

/* ---- Mid-Autumn: a big full moon with a halo, and a few lanterns ---------- */
.sky-effects[data-effect="moon"] .fx-lantern {
  --body: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 52'><defs><linearGradient id='v' x1='0' y1='0' x2='0' y2='1'><stop offset='0' stop-color='%23a8501c'/><stop offset='.42' stop-color='%23e98a34'/><stop offset='.78' stop-color='%23ffc272'/><stop offset='1' stop-color='%23fff0c4'/></linearGradient><linearGradient id='h' x1='0' y1='0' x2='1' y2='0'><stop offset='0' stop-color='%23401800' stop-opacity='.42'/><stop offset='.32' stop-color='%23401800' stop-opacity='0'/><stop offset='.55' stop-color='%23fff4d0' stop-opacity='.18'/><stop offset='.7' stop-color='%23401800' stop-opacity='0'/><stop offset='1' stop-color='%23401800' stop-opacity='.42'/></linearGradient></defs><path d='M4 10Q4 2 20 2Q36 2 36 10L31.5 46Q20 49.5 8.5 46Z' fill='url(%23v)'/><path d='M4 10Q4 2 20 2Q36 2 36 10L31.5 46Q20 49.5 8.5 46Z' fill='url(%23h)'/><path d='M14 3.2L13.2 47.4M26 3.2L26.8 47.4M4.6 18Q20 15.5 35.4 18' stroke='%23603008' stroke-opacity='.16' stroke-width='.6' fill='none'/><ellipse cx='20' cy='46.6' rx='11.4' ry='1.7' fill='%23703010' fill-opacity='.5'/><ellipse cx='20' cy='47.6' rx='3.2' ry='1.9' fill='%23fff6d6'/></svg>");
  --glow: 255 196 120;
}

.fx-moon {
  position: absolute;
  top: clamp(30px, 7svh, 84px);
  right: 9vw;
  width: clamp(104px, 33vw, 220px);
  aspect-ratio: 1;
  opacity: calc(0.55 + 0.45 * var(--stars, 1));
}
.fx-moon__halo {
  position: absolute;
  inset: -100%;
  border-radius: 50%;
  background:
    radial-gradient(closest-side, rgb(255 244 222 / 0) 70%, rgb(255 244 222 / 0.045) 82%, rgb(255 244 222 / 0) 95%),
    radial-gradient(closest-side, rgb(255 238 206 / 0.36) 24%, rgb(255 232 196 / 0.15) 40%, rgb(255 226 186 / 0.05) 62%, rgb(255 226 186 / 0) 100%);
  opacity: calc(0.2 + 0.8 * var(--stars, 1));
  animation: moon-breathe 12s ease-in-out infinite alternate;
}
.fx-moon__disc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'><defs><radialGradient id='b' cx='42%' cy='38%' r='62%'><stop offset='0' stop-color='%23fffcf0'/><stop offset='.5' stop-color='%23fbf0cf'/><stop offset='.86' stop-color='%23f1da9e'/><stop offset='1' stop-color='%23e4c381'/></radialGradient><filter id='s' x='-20%' y='-20%' width='140%' height='140%'><feGaussianBlur stdDeviation='3.2'/></filter><filter id='t'><feTurbulence type='fractalNoise' baseFrequency='.045' numOctaves='4' seed='7'/><feColorMatrix values='0 0 0 0 .55  0 0 0 0 .47  0 0 0 0 .33  0 0 0 -1.6 .9'/></filter><clipPath id='c'><circle cx='100' cy='100' r='100'/></clipPath></defs><circle cx='100' cy='100' r='100' fill='url(%23b)'/><g clip-path='url(%23c)'><rect width='200' height='200' filter='url(%23t)' opacity='.35'/><g filter='url(%23s)' fill='%23b49c74' fill-opacity='.32'><path d='M34 62C24 84 24 114 36 138C46 154 62 146 66 124C70 102 64 82 58 66C52 54 40 50 34 62Z'/><ellipse cx='80' cy='62' rx='25' ry='19'/><ellipse cx='114' cy='70' rx='14' ry='13'/><ellipse cx='124' cy='98' rx='19' ry='14' transform='rotate(-18 124 98)'/><ellipse cx='159' cy='78' rx='9' ry='7.5'/><ellipse cx='150' cy='116' rx='10' ry='15'/><ellipse cx='88' cy='134' rx='17' ry='11'/><ellipse cx='133' cy='126' rx='7' ry='6'/><ellipse cx='60' cy='158' rx='10' ry='7'/></g><g stroke='%23fffdf2' stroke-opacity='.08' stroke-width='2.4' fill='none' filter='url(%23s)'><path d='M96 166L70 120M96 166L128 118M96 166L58 186M96 166L140 190'/></g><circle cx='96' cy='166' r='3' fill='%23fffdf2' fill-opacity='.55'/><circle cx='118' cy='40' r='2' fill='%23fffdf2' fill-opacity='.5'/></g></svg>") center / 100% 100% no-repeat;
  box-shadow:
    0 0 5px 1px rgb(255 248 226 / 0.75),
    0 0 32px 6px rgb(255 234 186 / 0.42),
    0 0 90px 22px rgb(255 222 166 / 0.16);
}

@keyframes moon-breathe {
  from { scale: 1; }
  to   { scale: 1.045; }
}

/* The paper is open and covers nearly all of the sky (a phone): only the few pieces
   marked .is-edge stay, drifting in the thin strips either side of the sheet. The
   rest are taken out entirely, so nothing animates unseen behind the paper. */
.sky-effects.is-thin .fx-petal:not(.is-edge),
.sky-effects.is-thin .fx-lantern:not(.is-edge) { display: none; }
/* small enough to drift whole inside a ~4vw strip, not half-hidden behind the sheet */
.sky-effects.is-thin .fx-petal.is-edge {
  --drift: 0vw;
  --sway: 6px;
  --edge: min(var(--size), 3.4vw, 15px);
  left: calc(2vw - var(--edge) / 2);
  width: var(--edge);
  height: var(--edge);
  opacity: max(var(--o), 0.85);
}
.sky-effects.is-thin .fx-petal.is-edge[data-side="right"] { left: calc(98vw - var(--edge) / 2); }
.sky-effects.is-thin .fx-petal.is-soft .fx-petal__flutter::before { filter: none; }
.sky-effects.is-thin .fx-lantern.is-edge {
  --sway: 2px;
  left: 2vw;
  width: min(3vw, 13px);
  height: calc(min(3vw, 13px) * 1.3);
}
.sky-effects.is-thin .fx-lantern.is-edge[data-side="right"] { left: 98vw; }
.sky-effects.is-thin .fx-moon__halo { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .sky-effects *,
  .sky-effects *::before,
  .sky-effects *::after { animation-play-state: paused !important; }
}

@media (prefers-reduced-motion: reduce) {
  .cloud { animation-play-state: paused; }
  :root[data-sky-ready] { transition: none; }
}

/* ------------------------------------------------------------------ */
/* Paper (shared by the letter sheet and the envelope's folded card)  */
/* ------------------------------------------------------------------ */

.paper,
.envelope__letter {
  --paper-lit: color-mix(in oklab, var(--paper), var(--lamp-warm) calc(var(--lamp) * 14%));
  --fold: calc(100% / 3);
  --fold2: calc(200% / 3);
  border-radius: 2px;
  background-color: var(--paper-lit);
  background-image:
    /* bedside lamp: a warm pool of light from the top-left, only at night */
    radial-gradient(
      130% 70% at 10% 0%,
      color-mix(in srgb, var(--lamp-warm) calc(var(--lamp) * 24%), transparent) 0%,
      transparent 70%
    ),
    /* tri-fold creases: a valley at 1/3, a mountain at 2/3 */
    linear-gradient(
      180deg,
      transparent calc(var(--fold) - 18px),
      rgb(var(--crease-ink) / calc(var(--crease) * 0.035)) calc(var(--fold) - 3px),
      rgb(var(--crease-ink) / calc(var(--crease) * 0.11)) var(--fold),
      rgb(255 255 255 / calc(var(--crease) * 0.38)) calc(var(--fold) + 1px),
      rgb(255 255 255 / 0) calc(var(--fold) + 14px),
      transparent calc(var(--fold2) - 14px),
      rgb(255 255 255 / calc(var(--crease) * 0.32)) calc(var(--fold2) - 1px),
      rgb(var(--crease-ink) / calc(var(--crease) * 0.1)) var(--fold2),
      rgb(var(--crease-ink) / calc(var(--crease) * 0.035)) calc(var(--fold2) + 3px),
      transparent calc(var(--fold2) + 18px)
    ),
    /* the middle panel sat inside the fold: a whisper darker */
    linear-gradient(
      180deg,
      transparent var(--fold),
      rgb(var(--crease-ink) / calc(var(--crease) * 0.025)) var(--fold) var(--fold2),
      transparent var(--fold2)
    ),
    /* aged edges */
    radial-gradient(130% 95% at 50% 45%, transparent 60%, rgb(150 110 60 / 0.1) 100%),
    /* tooth and soft mottling */
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='256' height='256'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' seed='9' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .45  0 0 0 0 .34  0 0 0 0 .2  0 0 0 -.5 .29'/></filter><filter id='f'><feTurbulence type='fractalNoise' baseFrequency='.0195' numOctaves='2' seed='4' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .55  0 0 0 0 .42  0 0 0 0 .25  0 0 0 -1 .6'/></filter><rect width='100%' height='100%' filter='url(%23n)'/><rect width='100%' height='100%' filter='url(%23f)' opacity='.2'/></svg>");
  background-size: auto, auto, auto, auto, 256px 256px;
  box-shadow: inset 0 0 0 1px rgb(var(--crease-ink) / 0.07), var(--paper-shadow);
}

/* ------------------------------------------------------------------ */
/* Letter container                                                   */
/* ------------------------------------------------------------------ */

.letter {
  position: fixed;
  inset: 0;
  z-index: 2;
  touch-action: manipulation; /* no double-tap zoom anywhere on the letter */
  overflow-y: auto;
  overflow-x: hidden; /* the sheet's near edge swells a little as it turns over */
  overscroll-behavior: contain;
  scrollbar-gutter: stable both-edges;
  padding: var(--paper-top) 0 calc(var(--paper-top) + 88px);
}

.letter[hidden] { display: none; }

.paper {
  position: relative;
  touch-action: manipulation; /* a quick double tap hurries the ink, never zooms the page */
  width: var(--paper-w);
  min-height: calc(var(--paper-w) * var(--paper-ratio));
  margin: 0 auto;
  padding: clamp(28px, 9vw, 64px) clamp(24px, 8vw, 60px);
  color: var(--ink);
}

.paper:focus { outline: none; }

/* ------------------------------------------------------------------ */
/* The letter, in ink                                                 */
/* ------------------------------------------------------------------ */

.paper {
  display: flex;
  flex-direction: column;
  font-family: var(--font-hand);
}

.paper__text {
  color: var(--pen);
  font-family: var(--font-hand); /* its own lang decides the hand */
  font-size: clamp(22px, 6.1vw, 28px);
  font-weight: 500;
  line-height: 1.42;
  letter-spacing: 0.004em;
  overflow-wrap: break-word;
  hyphens: manual;
  -webkit-text-size-adjust: 100%;
}

.paper__para { margin: 0 0 0.6em; text-indent: 1.1em; }

/* Long Cang fills the whole em box where Caveat's letters sit small in it: a smaller
   size with more air between the lines reads like the same pen, and Chinese
   paragraphs open with the customary two-character indent. */
.paper__text:lang(zh) {
  font-size: clamp(21px, 5.75vw, 26px);
  font-weight: 400;
  line-height: 1.68;
  letter-spacing: 0.03em;
}
.paper__text:lang(zh) .paper__para { margin-bottom: 0.5em; }
.ink__punct:lang(zh) { margin-inline-start: -0.16em; }
.paper__text:lang(zh) .paper__para:not(:first-child, :has(> .photo--left:not([hidden]))) { text-indent: 2em; }
.paper__para:first-child { text-indent: 0; }
.paper__para:last-child { margin-bottom: 0; }

/* "My love," on a line of its own, like the top of a real letter. */
.paper__greeting {
  display: block;
  margin-bottom: 0.18em;
  font-size: 1.1em;
}

/* One word (or one character) of ink. Unwritten ink is laid out but invisible,
   so the page never reflows while the letter writes itself. */
.ink {
  display: inline-block;
  text-indent: 0; /* inline-blocks would inherit the paragraph indent */
  visibility: hidden;
}

.ink.is-inked { visibility: visible; }

/* The pen draws it in left to right, slightly blurred and pale, then the ink
   settles: a darker, faintly bleeding wet line that dries to the final colour. */
.ink.is-wet {
  animation:
    ink-flow 380ms cubic-bezier(0.3, 0.55, 0.25, 1) backwards,
    ink-dry 1600ms cubic-bezier(0.2, 0.6, 0.3, 1) backwards;
}

@keyframes ink-flow {
  from {
    clip-path: inset(-0.35em 100% -0.35em -0.35em);
    opacity: 0.2;
    filter: blur(1.2px);
  }
  55% { opacity: 0.85; }
  to {
    clip-path: inset(-0.35em -0.35em -0.35em -0.35em);
    opacity: 1;
    filter: blur(0);
  }
}

@keyframes ink-dry {
  from {
    color: var(--pen-wet);
    text-shadow: 0 0 0.06em color-mix(in srgb, var(--pen-wet) 55%, transparent);
  }
}

/* Later tasks write the ending here; it waits until the letter is written. */
.paper__end:empty { display: none; }
.paper[data-ink="writing"] .paper__end { visibility: hidden; }

/* "Amo-te" and his signature (js/ui/signature.js): right-aligned under the last
   paragraph like a real sign-off, with room above, in the letter's own ink. Written
   in wet and dries like the words do. */
.signature {
  display: block;
  width: min(64%, 260px);
  margin: clamp(26px, 8vw, 46px) clamp(0px, 1.5vw, 10px) 0 auto;
  color: var(--pen);
  rotate: -2.5deg;
  transform-origin: right center;
  transition: color 1600ms cubic-bezier(0.2, 0.6, 0.3, 1), filter 1600ms cubic-bezier(0.2, 0.6, 0.3, 1);
}
.signature:empty { display: none; }
.signature.is-wet {
  color: var(--pen-wet);
  filter: drop-shadow(0 0 0.5px color-mix(in srgb, var(--pen-wet) 55%, transparent));
  transition: none;
}
.signature__svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Return visits: a small pencilled note at the foot of the page. */
.paper__again {
  align-self: flex-end;
  margin: auto 0 0;
  padding: 1.6em 0 0;
  border: 0;
  background: none;
  font: 400 clamp(17px, 4.8vw, 21px) / 1.2 var(--font-hand);
  color: color-mix(in srgb, var(--pen) 58%, transparent);
  text-decoration: underline 1px color-mix(in srgb, var(--pen) 22%, transparent);
  text-underline-offset: 0.22em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: soft-in 900ms ease-out backwards;
  transition: color 0.2s;
}

.paper__again:hover,
.paper__again:focus-visible { color: var(--pen); }
.paper__again:focus-visible { outline: 1px dashed color-mix(in srgb, var(--pen) 40%, transparent); outline-offset: 4px; }
.paper__again[hidden] { display: none; }

/* ------------------------------------------------------------------ */
/* P.S. and the late-night sticky note                                */
/* ------------------------------------------------------------------ */

/* Today's P.S., added under the letter (the signature goes between them). A size
   smaller and leaning a touch, like something added after the letter was signed. */
.ps {
  margin: 1.5em 0 0;
  min-height: 1.4em;
  color: var(--pen);
  font-family: var(--font-hand);
  font-size: clamp(20px, 5.4vw, 25px);
  font-weight: 500;
  line-height: 1.4;
  overflow-wrap: break-word;
  rotate: -0.6deg;
  transform-origin: left center;
}
.ps:lang(zh) { font-size: clamp(19px, 5.15vw, 23px); line-height: 1.6; }
.ps:lang(zh) .ink__punct { margin-inline-start: -0.16em; }
.ps__ghost { visibility: hidden; }

/* A yellow sticky note pressed onto the top-left, a strip of clear tape over it,
   its bottom corner curling up off the paper. The letter starts just below it
   (--note-room, measured by js/ui/surprises.js). */
.paper.has-note { padding-top: var(--note-room, 190px); }

.sticky {
  position: absolute;
  z-index: 2;
  top: clamp(14px, 4vw, 26px);
  left: clamp(-12px, -2.4vw, -8px);
  width: min(calc(var(--paper-w) * 0.47), 216px);
  min-height: calc(min(calc(var(--paper-w) * 0.47), 216px) * 0.9);
  padding: 24px 14px 18px 16px;
  display: flex;
  align-items: center;
  rotate: -3.5deg;
  border-radius: 1px 1px 64px 2px / 1px 1px 10px 2px; /* the curl, bottom-right */
  background:
    /* light catching the lifted corner */
    linear-gradient(146deg, rgb(255 255 255 / 0) 66%, rgb(255 255 255 / 0.3) 84%, rgb(255 255 255 / 0.12) 92%, rgb(150 110 0 / 0.14) 100%),
    /* the sticky strip along the top sits a little flatter and paler */
    linear-gradient(180deg, rgb(255 255 255 / 0.2), rgb(255 255 255 / 0) 16%),
    /* faint fibres */
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' seed='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .5  0 0 0 0 .4  0 0 0 0 .1  0 0 0 -.6 .3'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>") 0 0 / 160px 160px,
    linear-gradient(172deg, #fff3a6 0%, #fde97f 55%, #f8dd66 100%);
  box-shadow:
    0 1px 1px rgb(90 70 10 / 0.16),
    0 3px 6px -2px rgb(60 40 10 / 0.18),
    7px 13px 15px -8px rgb(40 26 6 / 0.42); /* deeper under the curled corner */
  color: var(--pen);
}
.sticky__text {
  margin: 0;
  font: 500 clamp(18px, 4.9vw, 22px) / 1.16 var(--font-hand);
  overflow-wrap: break-word;
}
.sticky:lang(zh) .sticky__text { font-size: clamp(18px, 5vw, 22px); line-height: 1.5; }

/* A short strip of clear tape, torn at both ends. */
.sticky__tape {
  position: absolute;
  left: 50%;
  top: 0;
  width: 46%;
  height: 19px;
  translate: -46% -52%;
  rotate: 5deg;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.5), rgb(255 255 255 / 0.18) 40%, rgb(255 255 255 / 0.3)),
    rgb(244 240 226 / 0.34);
  box-shadow: 0 0.5px 1px rgb(60 50 30 / 0.12);
  clip-path: polygon(
    2% 0, 98.5% 0, 100% 14%, 97% 28%, 99.5% 42%, 96.5% 58%, 99% 72%, 97% 86%, 99.5% 100%,
    1% 100%, 3.5% 84%, 0 70%, 3% 55%, 0.5% 40%, 3.5% 26%, 0 12%
  );
}

/* Pressed on a moment after the paper opens; the tape follows. */
.sticky.is-arriving { animation: sticky-on 850ms cubic-bezier(0.22, 0.7, 0.3, 1) 900ms backwards; }
.sticky.is-arriving .sticky__tape { animation: soft-in 380ms ease-out 1650ms backwards; }

@keyframes sticky-on {
  from { opacity: 0; translate: 6px -16px; rotate: -8deg; scale: 1.06; }
  60%  { opacity: 1; }
}

/* While the ink flows: a small "skip", mirrored across from the music player. */
.letter-skip {
  position: fixed;
  z-index: 4;
  left: calc(14px + env(safe-area-inset-left));
  bottom: calc(24px + env(safe-area-inset-bottom));
  min-height: 36px;
  padding: 2px 15px 4px;
  border: 1px solid rgb(var(--crease-ink) / 0.16);
  border-radius: 999px;
  background: rgb(251 245 233 / 0.78);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 16px -8px rgb(10 6 30 / 0.45);
  font: 500 19px / 1 var(--font-hand);
  color: color-mix(in srgb, var(--pen) 75%, transparent);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: soft-in 900ms ease-out 1.2s backwards;
}

.letter-skip::after { content: " \203A"; }
.letter-skip:focus-visible { outline: 1px dashed var(--pen); outline-offset: 3px; }
.letter-skip[hidden] { display: none; }

@keyframes soft-in {
  from { opacity: 0; }
}

/* ------------------------------------------------------------------ */
/* Language: "EN · 中文" pencilled in the top-right corner            */
/* ------------------------------------------------------------------ */

.lang-tab {
  position: absolute;
  z-index: 1;
  top: clamp(4px, 1.6vw, 14px);
  right: clamp(8px, 3.4vw, 26px);
  display: flex;
  align-items: center;
  color: var(--graphite);
  rotate: -2deg;
  transform-origin: right center;
}

.lang-tab__opt {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 40px;
  min-height: 40px;
  padding: 4px 7px;
  border: 0;
  background: none;
  color: inherit;
  font: 400 19px / 1 var(--font-hand);
  opacity: 0.55;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.3s;
}

.lang-tab__opt:lang(zh) { font-size: 16px; letter-spacing: 0.04em; }
.lang-tab__opt[aria-pressed="true"] { opacity: 0.9; cursor: default; }
.lang-tab__opt:hover { opacity: 0.85; }
.lang-tab__opt:focus-visible { outline: 1px dashed color-mix(in srgb, var(--graphite) 60%, transparent); outline-offset: -2px; }

.lang-tab__word { position: relative; translate: 0 -0.04em; }

.lang-tab__dot {
  font: 400 18px / 1 var(--font-hand-en);
  opacity: 0.6;
  margin: 0 1px;
}

/* the ring around the language she is reading, drawn with one stroke of the pencil */
.lang-tab__loop {
  position: absolute;
  top: 6px;
  left: 2px;
  width: calc(100% - 3px);
  height: calc(100% - 10px);
  overflow: visible;
  pointer-events: none;
  rotate: 3deg;
}

.lang-tab__loop path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.15;
  stroke-linecap: round;
  stroke-dasharray: 1 1;
  stroke-dashoffset: 1;
  opacity: 0.8;
}

.lang-tab__opt[aria-pressed="true"] .lang-tab__loop path {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 560ms cubic-bezier(0.45, 0.05, 0.3, 1) 140ms;
}

/* turning the sheet over: no taps land mid-turn */
.paper.is-turning { pointer-events: none; will-change: transform; }

@media (prefers-reduced-motion: reduce) {
  .lang-tab__opt,
  .lang-tab__opt[aria-pressed="true"] .lang-tab__loop path { transition: none; }
}

/* ------------------------------------------------------------------ */
/* Stuck-on photos                                                    */
/* ------------------------------------------------------------------ */

/* Each paragraph holds its own photos, so a print never drifts into the next memory. */
.paper__para { display: flow-root; }
/* beside a photo on the left, the indent would read as a stray gap */
.paper__para:has(> .photo--left:not([hidden])) { text-indent: 0; }

.photo {
  /* resting on the paper vs. just dropped onto it (same number of layers, so they tween) */
  --shadow-rest:
    0 0 0 0.5px rgb(90 64 36 / 0.12),
    0 1px 1px rgb(52 34 16 / 0.2),
    0 2px 4px -1px rgb(52 34 16 / 0.2),
    0 7px 12px -7px rgb(30 18 40 / 0.3);
  --shadow-lifted:
    0 0 0 0.5px rgb(90 64 36 / 0.06),
    0 10px 10px -4px rgb(52 34 16 / 0.08),
    0 18px 22px -6px rgb(52 34 16 / 0.12),
    0 34px 34px -14px rgb(30 18 40 / 0.22);
  position: relative;
  display: block;
  width: clamp(84px, 30%, 160px);
  margin-top: 0.3em;
  margin-bottom: 0.25em;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-indent: 0;
  cursor: zoom-in;
  rotate: var(--tilt, -4deg);
  /* under the bedside lamp the print warms with the paper */
  filter: sepia(calc(var(--lamp) * 0.22)) brightness(calc(1 - var(--lamp) * 0.07));
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

.photo--left  { float: left;  margin-left: -14px; margin-right: 15px; }
.photo--right { float: right; margin-right: -14px; margin-left: 15px; }
.photo[hidden] { display: none; }
.photo.is-lifted { opacity: 0; } /* off the paper while it is enlarged (still focusable) */

.photo:focus-visible {
  outline: 1.5px dashed color-mix(in srgb, var(--pen) 45%, transparent);
  outline-offset: 6px;
}

/* The print: a paper-white border, wider at the foot like an instant photo. */
.photo__print {
  position: relative;
  display: block;
  padding: 5.5% 5.5% 17%;
  border-radius: 1px;
  background:
    linear-gradient(160deg, rgb(255 255 255 / 0.7), rgb(255 255 255 / 0) 40%, rgb(120 96 60 / 0.06)),
    var(--print);
  box-shadow: var(--shadow-rest);
  transition: box-shadow 0.25s ease;
}

.photo:active .photo__print { box-shadow: var(--shadow-lifted); }

.photo__img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: #d8cdbf;
  box-shadow: 0 0 0 0.5px rgb(40 24 10 / 0.18);
}

/* A whisper of gloss across the emulsion. */
.photo__print::after {
  content: "";
  position: absolute;
  inset: 5.5% 5.5% 17%;
  background: linear-gradient(118deg, rgb(255 255 255 / 0.16), rgb(255 255 255 / 0) 38%, rgb(255 255 255 / 0) 72%, rgb(255 255 255 / 0.07));
  pointer-events: none;
}

/* Washi tape: translucent, torn at both ends, a faint printed pattern.
   The roll is picked per photo (data-washi); the same strip stays on the enlarged print. */
[data-washi] {
  --washi: rgb(226 160 160 / 0.7);
  --washi-print: radial-gradient(circle, rgb(255 255 255 / 0.55) 0 0.8px, transparent 1.2px) 0 0 / 5px 5px;
}
[data-washi="sage"] {
  --washi: rgb(150 186 140 / 0.68);
  --washi-print: repeating-linear-gradient(-55deg, rgb(255 255 255 / 0.34) 0 1.5px, transparent 1.5px 5px);
}
[data-washi="kraft"] {
  --washi: rgb(212 176 122 / 0.7);
  --washi-print:
    linear-gradient(90deg, rgb(255 255 255 / 0.3) 1px, transparent 1px) 0 0 / 6px 6px,
    linear-gradient(rgb(255 255 255 / 0.3) 1px, transparent 1px) 0 0 / 6px 6px;
}
[data-washi="sky"] {
  --washi: rgb(146 180 212 / 0.68);
  --washi-print: repeating-linear-gradient(90deg, rgb(255 255 255 / 0.3) 0 2px, transparent 2px 6px);
}

.photo--tape::before,
.photo-view--tape .photo-view__face--front::before {
  content: "";
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 0;
  width: 64%;
  height: var(--tape-h, 16px);
  translate: -50% -58%;
  rotate: var(--tape-tilt, 4deg);
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.32), rgb(255 255 255 / 0) 35%, rgb(255 255 255 / 0) 70%, rgb(60 40 20 / 0.08)),
    var(--washi-print),
    var(--washi);
  mix-blend-mode: multiply;
  clip-path: polygon(
    2% 0, 98.5% 0, 100% 11%, 96.5% 22%, 99.5% 34%, 96% 47%, 99% 60%, 96.5% 72%, 100% 85%, 98% 100%,
    1.5% 100%, 3.5% 88%, 0 76%, 3% 63%, 0.5% 50%, 4% 37%, 0.5% 24%, 3.5% 12%
  );
}

/* Old album corners: little black paper pockets with a pale folded rim. */
.photo--corners .photo__print { padding: 6%; }
.photo--corners .photo__print::after { inset: 6%; }

.photo__corners {
  position: absolute;
  inset: -2px;
  pointer-events: none;
  filter: drop-shadow(0 0.6px 0.6px rgb(30 18 10 / 0.45));
}

.photo__corner {
  position: absolute;
  width: 24%;
  aspect-ratio: 1;
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--album) 85%, #000) 0,
    var(--album) 30%,
    color-mix(in srgb, var(--album) 80%, #fff) 44%,
    color-mix(in srgb, var(--album) 55%, #fff) 47.5%,
    transparent 48.5%
  );
}

.photo__corner--tl { left: 0;  top: 0; }
.photo__corner--tr { right: 0; top: 0;    rotate: 90deg; }
.photo__corner--br { right: 0; bottom: 0; rotate: 180deg; }
.photo__corner--bl { left: 0;  bottom: 0; rotate: 270deg; }

/* Dropped in from a little above, then pressed flat; the tape follows. */
.photo.is-dropping { animation: photo-drop 500ms cubic-bezier(0.25, 0.6, 0.3, 1) backwards; }
.photo.is-dropping .photo__print { animation: photo-press 500ms cubic-bezier(0.3, 0.5, 0.3, 1) backwards; }
.photo.is-dropping::before,
.photo.is-dropping .photo__corners { animation: photo-attach 320ms ease-out 420ms backwards; }

@keyframes photo-drop {
  0%   { translate: 0 -30px; scale: 1.08; opacity: 0; }
  30%  { opacity: 1; }
  82%  { translate: 0 0; scale: 0.994; }
  100% { translate: 0 0; scale: 1; }
}

@keyframes photo-press {
  from { box-shadow: var(--shadow-lifted); }
  82%  { box-shadow: var(--shadow-rest); }
}

@keyframes photo-attach {
  from { opacity: 0; scale: 1.12; }
}

/* ---- enlarged, and turned over ---------------------------------------- */

.photo-view {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 24px;
  overscroll-behavior: contain;
  touch-action: none;
  cursor: zoom-out;
  -webkit-tap-highlight-color: transparent;
}

.photo-view__scrim {
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 45%, rgb(20 14 36 / 0.42), rgb(10 6 24 / 0.68));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.photo-view__card {
  position: relative;
  --w: min(78vw, 50svh, 380px);
  width: var(--w);
  height: calc(var(--w) * 1.3375); /* 5.5% + 4:5 image + 17% */
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  perspective: 1600px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.photo-view__card:focus { outline: none; }
.photo-view__card:focus-visible { outline: 1.5px dashed rgb(255 246 234 / 0.6); outline-offset: 10px; }

.photo-view__flipper {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 760ms cubic-bezier(0.35, 0.1, 0.2, 1);
}

.photo-view__card.is-flipped .photo-view__flipper { transform: rotateY(180deg); }

.photo-view__face {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: 2px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow:
    0 0 0 0.5px rgb(90 64 36 / 0.1),
    0 2px 3px rgb(20 10 30 / 0.2),
    0 22px 48px -14px rgb(6 4 20 / 0.6);
  filter: sepia(calc(var(--lamp) * 0.18)) brightness(calc(1 - var(--lamp) * 0.05));
}

.photo-view__face--front {
  --tape-h: calc(var(--w) * 0.16);
  padding: 5.5% 5.5% 17%;
  background:
    linear-gradient(160deg, rgb(255 255 255 / 0.7), rgb(255 255 255 / 0) 40%, rgb(120 96 60 / 0.06)),
    var(--print);
}

/* album prints have an even border */
.photo-view--corners .photo-view__card { height: calc(var(--w) * 1.22); } /* 6% + 4:5 image + 6% */
.photo-view--corners .photo-view__face--front { padding: 6%; }

.photo-view__img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: #d8cdbf;
  box-shadow: 0 0 0 0.5px rgb(40 24 10 / 0.2);
}

/* The back of the print: matte, faintly fibrous, written on in pen. */
.photo-view__face--back {
  transform: rotateY(180deg);
  display: grid;
  place-items: center;
  padding: 14% 12%;
  background:
    radial-gradient(120% 90% at 30% 20%, rgb(255 255 255 / 0.5), transparent 60%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' seed='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .5  0 0 0 0 .42  0 0 0 0 .3  0 0 0 -.6 .26'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    var(--print-back);
}

/* where the tape held it, a faint glossy residue */
.photo-view--tape .photo-view__face--back::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 60%;
  height: calc(var(--w) * 0.075);
  translate: -50% 0;
  rotate: calc(var(--tape-tilt, 4deg) * -1);
  background: linear-gradient(180deg, rgb(196 170 120 / 0.14), rgb(196 170 120 / 0.06));
  border-radius: 0 0 2px 2px;
}

.photo-view__caption {
  display: block;
  max-width: 100%;
  font-family: var(--font-hand);
  font-size: clamp(30px, 9.4vw, 44px);
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
  color: var(--pen);
  rotate: -4deg;
  text-wrap: balance;
  overflow-wrap: break-word;
}

.photo-view__caption:lang(zh) {
  font-size: clamp(26px, 8vw, 38px);
  font-weight: 400;
  line-height: 1.35;
  letter-spacing: 0.06em;
}

.photo-view__caption::after {
  content: "\2661";
  display: block;
  margin-top: 0.25em;
  font-size: 0.7em;
  color: color-mix(in srgb, var(--wax) 70%, transparent);
  rotate: 8deg;
}

/* For keyboards and screen readers; out of sight otherwise (tapping outside closes). */
.photo-view__close {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  padding: 4px 14px 6px;
  border: 1px solid rgb(255 246 234 / 0.4);
  border-radius: 999px;
  background: rgb(251 245 233 / 0.9);
  font: 500 19px / 1 var(--font-hand);
  color: var(--pen);
  cursor: pointer;
}

.photo-view__close:not(:focus-visible) {
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .photo.is-dropping,
  .photo.is-dropping .photo__print,
  .photo.is-dropping::before,
  .photo.is-dropping .photo__corners { animation: none; }
  .photo-view__flipper { transition: none; }
}

/* ------------------------------------------------------------------ */
/* Envelope                                                           */
/* ------------------------------------------------------------------ */

.envelope-scene {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.envelope-defs { position: absolute; }

/* Invisible: where the paper will sit, so the letter can unfold onto it. */
.envelope-scene__target {
  position: fixed;
  top: var(--paper-top);
  left: 50%;
  width: var(--paper-w);
  height: calc(var(--paper-w) * var(--paper-ratio));
  translate: -50% 0;
  box-shadow: inset 0 0 0 1px rgb(var(--crease-ink) / 0.07), var(--paper-shadow);
  visibility: hidden;
  pointer-events: none;
}

.envelope-wrap {
  margin-top: 14svh;
  animation: envelope-in 1.2s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.envelope {
  position: relative;
  width: min(84vw, 400px);
  aspect-ratio: 3 / 2;
  cursor: pointer;
  /* at night the lamp warms and dims the paper a touch */
  filter: sepia(calc(var(--lamp) * 0.2)) brightness(calc(1 - var(--lamp) * 0.08));
  animation: envelope-float 7s ease-in-out infinite alternate;
}

/* Soft shadow so the envelope floats in front of the sky. */
.envelope::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 3px;
  box-shadow:
    0 2px 3px rgb(20 10 30 / 0.16),
    0 22px 44px -12px rgb(10 6 30 / 0.55);
}

.envelope > svg,
.envelope__flap,
.envelope__face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.envelope__back { z-index: 1; }
.envelope__pocket { z-index: 3; }

.envelope__flap {
  z-index: 4;
  transform-origin: 50% 0;
  pointer-events: none;
}

.envelope__face--in { opacity: 0; }

/* The folded letter waiting inside: one third of the sheet. */
.envelope__letter {
  --crease: 0;
  position: absolute;
  z-index: 2;
  left: 6%;
  width: 88%;
  top: 6%;
  aspect-ratio: 3 / 1.4142;
  box-shadow: inset 0 0 0 1px rgb(var(--crease-ink) / 0.07), 0 1px 2px rgb(60 40 20 / 0.18);
}

@keyframes envelope-in {
  from { opacity: 0; transform: translateY(22px); }
}

@keyframes envelope-float {
  from { transform: translateY(0); }
  to   { transform: translateY(-6px); }
}

/* ------------------------------------------------------------------ */
/* Wax seal                                                           */
/* ------------------------------------------------------------------ */

.seal {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 53.5%;
  width: 25%;
  aspect-ratio: 1;
  translate: -50% -50%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.seal:focus-visible {
  outline: 2px solid var(--glow-white);
  outline-offset: 5px;
}

.seal:disabled { cursor: default; }

.seal__piece {
  position: absolute;
  inset: 0;
  filter:
    drop-shadow(0 1.5px 1px rgb(60 8 12 / 0.45))
    drop-shadow(0 5px 7px rgb(40 10 20 / 0.25));
}

.seal__piece svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Two halves split along a jagged crack; only shown once it breaks. */
.seal__piece--left,
.seal__piece--right { visibility: hidden; }

.seal__piece--left {
  transform-origin: 30% 92%;
  clip-path: polygon(0 0, 52% 0, 47% 17%, 54% 33%, 46% 49%, 53% 66%, 47% 83%, 51% 100%, 0 100%);
}

.seal__piece--right {
  transform-origin: 70% 92%;
  clip-path: polygon(52% 0, 100% 0, 100% 100%, 51% 100%, 47% 83%, 53% 66%, 46% 49%, 54% 33%, 47% 17%);
}

.seal.is-cracked .seal__piece--whole { visibility: hidden; }
.seal.is-cracked .seal__piece--left,
.seal.is-cracked .seal__piece--right { visibility: visible; }

/* A slow breath inviting the tap. */
.seal__piece--whole {
  animation: seal-breathe 3.6s ease-in-out 1.4s infinite;
  transition: scale 0.15s ease;
}

.seal:active .seal__piece--whole { scale: 0.95; }

.seal__crumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--size);
  height: var(--size);
  border-radius: 45% 55% 50% 40%;
  background: radial-gradient(circle at 35% 30%, #c8434b, var(--wax) 55%, var(--wax-deep));
  pointer-events: none;
}

@keyframes seal-breathe {
  0%, 100% { scale: 1; }
  50%      { scale: 1.04; }
}

/* ------------------------------------------------------------------ */
/* Music: a tiny turntable                                            */
/* ------------------------------------------------------------------ */

.player {
  position: fixed;
  z-index: 4;
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(14px + env(safe-area-inset-bottom));
  width: 60px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background:
    radial-gradient(120% 90% at 30% 0%, rgb(255 255 255 / 0.55), transparent 60%),
    linear-gradient(160deg, var(--envelope-light), var(--envelope-shade));
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.7),
    inset 0 -2px 3px rgb(var(--crease-ink) / 0.18),
    0 2px 3px rgb(20 10 30 / 0.18),
    0 10px 22px -8px rgb(10 6 30 / 0.55);
  filter: sepia(calc(var(--lamp) * 0.2)) brightness(calc(1 - var(--lamp) * 0.1));
  cursor: pointer;
  touch-action: manipulation;
  visibility: hidden;
  opacity: 0;
  translate: 0 10px;
  transition: opacity 0.8s ease, translate 0.8s ease, visibility 0s linear 0.8s;
}

:root[data-opened] .player {
  visibility: visible;
  opacity: 1;
  translate: 0 0;
  transition: opacity 0.9s ease 0.4s, translate 0.9s ease 0.4s, visibility 0s;
}

.player:focus-visible {
  outline: 2px solid var(--glow-white);
  outline-offset: 3px;
}

.player:active { scale: 0.96; }

.player__record,
.player__sheen {
  position: absolute;
  left: 6px;
  top: 7px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
}

.player__record {
  background:
    /* label with a small mark so the spin is visible */
    radial-gradient(circle at 50% 50%, var(--paper) 0 1.4px, transparent 1.9px),
    radial-gradient(circle at 50% 36%, rgb(255 236 210 / 0.85) 0 1.3px, transparent 1.8px),
    radial-gradient(circle, var(--wax) 0 7.5px, #2a1418 8px 8.6px, transparent 9px),
    repeating-radial-gradient(circle, var(--record) 0 1px, #2b2930 1.4px 2px),
    var(--record);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.35);
  animation: record-spin 2.4s linear infinite;
  animation-play-state: paused;
}

.player[aria-pressed="true"] .player__record { animation-play-state: running; }

/* Light stays put while the record turns under it. */
.player__sheen {
  background: conic-gradient(
    from 200deg,
    transparent 0 6%,
    rgb(255 255 255 / 0.2) 11%,
    transparent 17% 52%,
    rgb(255 255 255 / 0.14) 61%,
    transparent 67%
  );
  -webkit-mask: radial-gradient(circle, transparent 0 9px, #000 9.5px);
  mask: radial-gradient(circle, transparent 0 9px, #000 9.5px);
  pointer-events: none;
}

/* Tonearm: pivot at the top-right, swings onto the record when playing. */
.player__arm {
  position: absolute;
  right: 7px;
  top: 7px;
  width: 3px;
  height: 30px;
  border-radius: 2px;
  background: linear-gradient(90deg, #b9a98d, #efe6d4 50%, #a8987c);
  transform-origin: 50% 2.5px;
  rotate: -4deg;
  transition: rotate 0.6s cubic-bezier(0.3, 0.7, 0.3, 1);
}

.player__arm::before { /* pivot */
  content: "";
  position: absolute;
  left: 50%;
  top: 2.5px;
  width: 9px;
  height: 9px;
  translate: -50% -50%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff8ea, #b9a98d 70%);
  box-shadow: 0 1px 1.5px rgb(40 24 10 / 0.35);
}

.player__arm::after { /* headshell */
  content: "";
  position: absolute;
  left: 50%;
  bottom: -3px;
  width: 6px;
  height: 7px;
  translate: -60% 0;
  border-radius: 1.5px;
  background: #3a3438;
  rotate: 18deg;
}

.player[aria-pressed="true"] .player__arm { rotate: 24deg; }

@keyframes record-spin {
  to { transform: rotate(1turn); }
}

@media (prefers-reduced-motion: reduce) {
  .envelope-wrap,
  .envelope,
  .seal__piece--whole { animation: none; }
  .player__record { animation: none; }
  .ink.is-wet,
  .paper__again,
  .letter-skip { animation: none; }
  .player,
  :root[data-opened] .player,
  .signature { transition: none; }
}
