@import url('https://cdn.jsdelivr.net/npm/lxgw-wenkai-webfont@1.7.0/style.css');
@import url('https://cdn.jsdelivr.net/npm/@fontsource/instrument-serif@5.1.0/400-italic.css');
@import url('https://cdn.jsdelivr.net/npm/@fontsource/instrument-serif@5.1.0/400.css');

:root {
  --ink: #2a2622;
  --paper: #f8f2e4;
  --paper-2: #efe6d2;
  --warm: #ffd79a;
  --glow: #ffb86b;
  --red: #d7323a;
  --line: rgba(80, 60, 30, 0.14);
  --hand: 'LXGW WenKai', 'Kaiti SC', 'STKaiti', 'KaiTi', serif;
  --serif: 'Instrument Serif', 'Songti SC', serif;
  --ui: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #07121a; color: #fff; font-family: var(--ui); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, textarea { font: inherit; color: inherit; }

/* ---------- stage / scene ---------- */
.stage { position: fixed; inset: 0; overflow: hidden; }
.halo {
  position: absolute; pointer-events: none; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 190, 110, 0.12), rgba(255, 170, 90, 0.05) 55%, transparent);
  filter: blur(6px);
}
.topper { position: absolute; pointer-events: none; filter: drop-shadow(0 0 8px rgba(255, 220, 140, 0.9)) drop-shadow(0 0 22px rgba(255, 180, 90, 0.6)); animation: topper 4s ease-in-out infinite; }
@keyframes topper { 50% { filter: drop-shadow(0 0 12px rgba(255, 230, 160, 1)) drop-shadow(0 0 34px rgba(255, 180, 90, 0.75)); } }

.gifts { position: absolute; inset: 0; pointer-events: none; }
.gift { position: absolute; pointer-events: auto; cursor: pointer; transition: transform 0.3s; filter: drop-shadow(0 6px 6px rgba(0,0,0,0.45)); }
.gift svg { display: block; }
.gift:hover { transform: translateY(-3px) rotate(-1deg); }
.gift.main { animation: giftnudge 4s ease-in-out infinite; }
@keyframes giftnudge { 0%, 86%, 100% { transform: none; } 90% { transform: rotate(-3deg); } 94% { transform: rotate(2.5deg); } 97% { transform: rotate(-1deg); } }
.gift-tag { position: absolute; right: -6px; top: 34%; transform: rotate(8deg); background: #fbf6ea; color: #5a3b1d; font-family: var(--hand); font-size: 12px; padding: 2px 8px 2px 12px;
  border-radius: 2px 4px 4px 2px; box-shadow: 0 2px 4px rgba(0,0,0,0.3); white-space: nowrap; clip-path: polygon(8px 0, 100% 0, 100% 100%, 8px 100%, 0 50%); }
.ground-shadow { position: absolute; pointer-events: none; border-radius: 50%; background: radial-gradient(closest-side, rgba(0,0,0,0.55), rgba(0,0,0,0.25) 60%, transparent); }

/* backgrounds: a centred photo column; on wide screens the sides are a blurred extension */
.bg, .bg-set { position: absolute; inset: 0; }
.bg { background: #0a1016; }
.bg-set { opacity: 0; transition: opacity 1.3s ease; }
.bg-set.on { opacity: 1; }
.bg-blur { position: absolute; inset: -40px; background-size: cover; background-position: center; filter: blur(28px) brightness(0.8); }
.bg-main { position: absolute; top: 0; bottom: 0; left: 50%; height: 100%; aspect-ratio: 2 / 3; transform: translateX(-50%);
  background-size: cover; background-position: center bottom;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); }
@media (max-aspect-ratio: 2/3) { .bg-main { -webkit-mask-image: none; mask-image: none; } }
/* (no ken-burns: animating a masked full-screen photo is too heavy on phones) */
@keyframes kenburns { from { transform: translateX(-50%) scale(1); } to { transform: translateX(-50%) scale(1.04); } }
.ambient { position: absolute; inset: 0; pointer-events: none; }
.bg-set[data-s=home] .ambient { background: radial-gradient(28% 18% at 6% 50%, rgba(255, 150, 60, 0.35), transparent 70%); animation: firelight 0.9s ease-in-out infinite alternate; mix-blend-mode: screen; }
@keyframes firelight { from { opacity: 0.55; } 40% { opacity: 0.9; } to { opacity: 0.7; } }
.bg-set[data-s=nordic] .ambient { background: linear-gradient(115deg, transparent 20%, rgba(255, 248, 225, 0.22) 30%, transparent 44%); animation: sunmove 12s ease-in-out infinite alternate; }
@keyframes sunmove { from { transform: translateX(-3%); } to { transform: translateX(3%); } }

.scene-title { position: absolute; left: 0; right: 0; top: 40%; text-align: center; pointer-events: none; opacity: 0; z-index: 5; text-shadow: 0 2px 20px rgba(0,0,0,0.6); }
.scene-title i { display: block; font-family: var(--serif); font-size: 18px; letter-spacing: 2px; color: var(--warm); }
.scene-title b { display: block; font-family: var(--hand); font-size: 30px; font-weight: 600; color: #fff; letter-spacing: 4px; margin-top: 4px; }
.scene-title.show { animation: titlecard 2.6s ease forwards; }
@keyframes titlecard { 0% { opacity: 0; transform: translateY(8px); filter: blur(4px); } 20%, 70% { opacity: 1; transform: none; filter: none; } 100% { opacity: 0; filter: blur(4px); } }
.stage[data-scene=nordic] .scene-title { text-shadow: 0 1px 12px rgba(255,255,255,0.8); }
.stage[data-scene=nordic] .scene-title b { color: #2a2622; }
.stage[data-scene=nordic] .scene-title i { color: #9b4a22; }

/* film */
.grain {
  position: absolute; inset: -50%; pointer-events: none; opacity: 0.16; mix-blend-mode: overlay;
  animation: grain 0.9s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-3%, 2%); } 40% { transform: translate(2%, -3%); }
  60% { transform: translate(-1%, 3%); } 80% { transform: translate(3%, 1%); } 100% { transform: translate(0, 0); }
}
.vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.55)); }

/* ---------- ornaments ---------- */
.ornaments { position: absolute; inset: 0; }
.orn {
  position: absolute; transform-origin: 50% 0; padding: 0 6px;
  animation: sway var(--sway-d, 5s) ease-in-out var(--sway-delay, 0s) infinite alternate;
  cursor: pointer;
}
.orn::before {
  content: ''; position: absolute; left: 50%; top: 0; width: 1px; height: var(--thread); margin-left: -0.5px;
  background: linear-gradient(rgba(255, 240, 210, 0.15), rgba(255, 240, 210, 0.6));
}
.orn svg { display: block; margin-top: var(--thread); filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45)); transition: transform 0.25s; }
.orn:hover svg, .orn:focus-visible svg { transform: scale(1.12); }
.orn:focus-visible { outline: none; }
.orn.fresh svg { animation: fresh 2.2s ease-in-out infinite; }
@keyframes fresh {
  0%, 100% { filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 0 rgba(255, 230, 160, 0)); }
  50% { filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 10px rgba(255, 230, 160, 0.95)); }
}
.orn.mine::after {
  content: '我的'; position: absolute; left: 50%; bottom: -14px; transform: translateX(-50%);
  font-size: 10px; letter-spacing: 1px; padding: 1px 5px; border-radius: 6px;
  background: rgba(255, 240, 210, 0.85); color: #5a3b1d; white-space: nowrap;
}
@keyframes sway { from { transform: rotate(calc(var(--sway) * -1)); } to { transform: rotate(var(--sway)); } }
.orn.drop { animation: drop 1.4s cubic-bezier(0.3, 1.3, 0.5, 1) both, sway var(--sway-d, 5s) ease-in-out 1.4s infinite alternate; }
@keyframes drop {
  0% { transform: translateY(-110vh) rotate(-30deg); opacity: 0; }
  10% { opacity: 1; }
  70% { transform: translateY(6px) rotate(8deg); }
  100% { transform: translateY(0) rotate(0); }
}
.spark-burst { position: absolute; width: 4px; height: 4px; border-radius: 50%; background: #fff3c4; box-shadow: 0 0 8px 2px #ffd27a; pointer-events: none; animation: burst 0.9s ease-out forwards; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; } }

/* ---------- top / bottom ui ---------- */
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; padding: max(18px, env(safe-area-inset-top)) 20px 0;
  text-align: center; pointer-events: none; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
.eyebrow { font-family: var(--serif); font-style: italic; font-size: 15px; letter-spacing: 3px; color: var(--warm); opacity: 0.9; }
.title { font-family: var(--hand); font-size: clamp(24px, 6.6vw, 36px); margin: 4px 0 2px; font-weight: 600; letter-spacing: 1px; }
.sub { font-size: 12.5px; opacity: 0.78; letter-spacing: 0.5px; }
.hud-menu { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px; pointer-events: auto; width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,0.1); backdrop-filter: blur(6px); font-size: 18px; line-height: 36px; }
.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 0 20px max(22px, env(safe-area-inset-bottom));
  display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 26px; border-radius: 26px; font-size: 16px; font-weight: 600; letter-spacing: 1px;
  background: linear-gradient(180deg, #fff6e2, #f3dfb8); color: #3b2414;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4) inset, 0 8px 30px rgba(255, 170, 80, 0.45);
  transition: transform 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.red { background: linear-gradient(180deg, #e6474c, #c22a32); color: #fff; box-shadow: 0 8px 30px rgba(215, 50, 58, 0.45); }
.btn.ghost { background: rgba(255, 255, 255, 0.1); color: #fff; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25) inset; backdrop-filter: blur(8px); }
.btn.small { height: 40px; padding: 0 18px; font-size: 14px; }
.btn[disabled] { opacity: 0.55; pointer-events: none; }
.hint { position: absolute; left: 0; right: 0; text-align: center; font-family: var(--hand); font-size: 15px; color: rgba(255, 236, 200, 0.85); pointer-events: none; text-shadow: 0 2px 8px rgba(0,0,0,0.6); }
.demo-flag { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(max(22px, env(safe-area-inset-bottom)) + 58px); font-size: 11px; padding: 3px 10px; border-radius: 10px; background: rgba(0,0,0,0.35); color: rgba(255,255,255,0.7); white-space: nowrap; }

/* ---------- sheets & cards ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 35; background: rgba(4, 10, 16, 0.55); backdrop-filter: blur(6px);
  display: flex; align-items: flex-end; justify-content: center; opacity: 0; transition: opacity 0.3s;
}
.backdrop.show { opacity: 1; }
.backdrop.center { align-items: center; padding: 18px; }
.sheet {
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--paper); color: var(--ink); border-radius: 22px 22px 0 0;
  padding: 22px 20px max(22px, env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1);
  background-image: radial-gradient(rgba(120, 90, 40, 0.06) 1px, transparent 1px); background-size: 4px 4px;
}
.backdrop.show .sheet { transform: none; }
.sheet h2 { font-family: var(--hand); font-size: 24px; margin: 0 0 4px; }
.sheet .lead { font-size: 13px; color: #6d6153; margin: 0 0 18px; line-height: 1.6; }
.close { position: absolute; right: 14px; top: 12px; width: 34px; height: 34px; border-radius: 50%; font-size: 22px; color: #8a7c69; line-height: 34px; }
.sheet, .card { position: relative; }

.field { margin-bottom: 18px; }
.label { font-size: 12px; letter-spacing: 2px; color: #8a7a64; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.input {
  width: 100%; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: #fffaf0;
  padding: 0 14px; font-size: 16px; font-family: var(--hand); color: var(--ink); outline: none;
}
.input:focus { border-color: #c9a46b; }
.seg { display: flex; background: var(--paper-2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; height: 38px; border-radius: 10px; font-size: 14px; color: #7a6c5a; }
.seg button.on { background: #fffaf0; color: var(--ink); font-weight: 600; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08); }

.photo-drop {
  display: block; position: relative; width: 62%; margin: 0 auto; aspect-ratio: 4 / 4.6; background: #fff; padding: 10px 10px 40px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); transform: rotate(-1.5deg); cursor: pointer;
}
.photo-drop .ph { width: 100%; height: 100%; background: #ebe4d6; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #9b8b74; font-size: 13px; gap: 6px; overflow: hidden; }
.photo-drop .ph b { font-size: 30px; font-weight: 300; }
.photo-drop img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-drop .rm { position: absolute; right: -8px; top: -8px; width: 26px; height: 26px; border-radius: 50%; background: #3b2a1c; color: #fff; font-size: 14px; line-height: 26px; text-align: center; }
.tape { position: absolute; left: 50%; top: -10px; width: 74px; height: 22px; margin-left: -37px; background: rgba(240, 200, 120, 0.55); transform: rotate(-4deg); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

.letter {
  width: 100%; min-height: 200px; border: 0; outline: none; resize: vertical; border-radius: 12px; padding: 6px 14px;
  font-family: var(--hand); font-size: 18px; line-height: 32px; color: var(--ink);
  background: #fffaf0 repeating-linear-gradient(180deg, transparent 0 31px, rgba(160, 120, 70, 0.22) 31px 32px);
  background-attachment: local; box-shadow: inset 0 0 0 1px var(--line);
}
.pad-wrap { position: relative; }
.pad {
  display: block; width: 100%; aspect-ratio: 1 / 1.05; border-radius: 12px; touch-action: none; cursor: crosshair;
  background: #fffaf0 repeating-linear-gradient(180deg, transparent 0 39px, rgba(160, 120, 70, 0.22) 39px 40px);
  box-shadow: inset 0 0 0 1px var(--line);
}
.pad-tools { display: flex; gap: 8px; align-items: center; margin-top: 8px; font-size: 13px; color: #7a6c5a; }
.pad-tools button { padding: 6px 12px; border-radius: 10px; background: var(--paper-2); }
.pad-tools .inks { display: flex; gap: 6px; margin-left: auto; }
.pad-tools .ink { width: 22px; height: 22px; border-radius: 50%; padding: 0; box-shadow: 0 0 0 2px #fffaf0, 0 0 0 3px transparent; }
.pad-tools .ink.on { box-shadow: 0 0 0 2px #fffaf0, 0 0 0 3px #3b2a1c; }
.pad-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; font-family: var(--hand); color: #b5a58c; font-size: 15px; text-align: center; padding: 20px; }

.shapes { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: none; }
.shapes::-webkit-scrollbar { display: none; }
.shape {
  flex: 0 0 auto; width: 62px; height: 72px; border-radius: 14px; background: #24323a;
  display: flex; align-items: center; justify-content: center; box-shadow: inset 0 0 0 2px transparent;
}
.shape.on { box-shadow: inset 0 0 0 2px #f3c977, 0 4px 14px rgba(0,0,0,0.18); }
.shape svg { max-width: 46px; max-height: 60px; }
.colors { display: flex; gap: 10px; flex-wrap: wrap; padding: 4px 2px; }
.color { width: 30px; height: 30px; border-radius: 50%; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.12), 0 0 0 2px var(--paper), 0 0 0 3px transparent; }
.color.on { box-shadow: inset 0 -3px 0 rgba(0,0,0,0.12), 0 0 0 2px var(--paper), 0 0 0 4px #3b2a1c; }
.err { color: var(--red); font-size: 13px; min-height: 18px; margin: 4px 0 8px; text-align: center; }

/* letter card (opened ornament) */
.card {
  width: 100%; max-width: 440px; max-height: 88vh; overflow-y: auto; background: var(--paper); color: var(--ink);
  border-radius: 6px; padding: 26px 22px 24px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  transform: translateY(30px) scale(0.92) rotate(-1deg); opacity: 0; transition: transform 0.5s cubic-bezier(0.2, 1.2, 0.3, 1), opacity 0.3s;
  background-image: radial-gradient(rgba(120, 90, 40, 0.07) 1px, transparent 1px); background-size: 4px 4px;
}
.backdrop.show .card { transform: none; opacity: 1; }
.card .from { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.card .from .mini { width: 46px; height: 56px; display: flex; align-items: center; justify-content: center; background: #1c2a32; border-radius: 10px; flex: 0 0 auto; }
.card .from .mini svg { max-width: 34px; max-height: 46px; }
.card .from .who { font-family: var(--hand); font-size: 20px; font-weight: 600; }
.card .from .meta { font-size: 12px; color: #8a7a64; margin-top: 2px; letter-spacing: 1px; }
.polaroid { position: relative; background: #fff; padding: 10px 10px 34px; margin: 6px auto 22px; width: 82%; transform: rotate(1.6deg); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); }
.polaroid img { display: block; width: 100%; max-height: 52vh; object-fit: cover; background: #ebe4d6; }
.polaroid .cap { position: absolute; left: 0; right: 0; bottom: 7px; text-align: center; font-family: var(--hand); font-size: 14px; color: #6b5d4b; }
.card .text {
  font-family: var(--hand); font-size: 19px; line-height: 34px; white-space: pre-wrap; word-break: break-word; min-height: 34px;
  background: repeating-linear-gradient(180deg, transparent 0 33px, rgba(160, 120, 70, 0.2) 33px 34px);
}
.card .text .caret { display: inline-block; width: 1px; height: 20px; background: #3b2a1c; vertical-align: -3px; animation: caret 0.8s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.card canvas.replay { display: block; width: 100%; border-radius: 6px; background: repeating-linear-gradient(180deg, transparent 0 39px, rgba(160, 120, 70, 0.2) 39px 40px); }
.card .actions { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; font-size: 13px; color: #8a7a64; }
.card .actions button { padding: 6px 4px; color: #8a7a64; }
.card .sign { text-align: right; font-family: var(--hand); font-size: 17px; margin-top: 10px; color: #4a3a2a; }
.locked { text-align: center; padding: 10px 6px 4px; }
.locked .big { font-family: var(--hand); font-size: 21px; margin: 10px 0 6px; }
.locked p { font-size: 13.5px; color: #7a6c5a; line-height: 1.7; margin: 0 0 16px; }

.share-box { display: flex; gap: 8px; margin-bottom: 10px; }
.share-box .input { font-family: var(--ui); font-size: 13px; color: #5a4c3a; }
.note { font-size: 12px; color: #8a7a64; line-height: 1.7; }

.toast {
  position: fixed; left: 50%; top: 20%; transform: translate(-50%, -10px); z-index: 40; padding: 12px 20px; border-radius: 24px;
  background: rgba(20, 16, 12, 0.85); color: #ffe9c4; font-family: var(--hand); font-size: 16px; opacity: 0; transition: all 0.35s; pointer-events: none;
  max-width: 86vw; text-align: center; backdrop-filter: blur(6px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- landing ---------- */
.landing-panel {
  position: absolute; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(420px, calc(100% - 32px)); padding: 18px; border-radius: 22px;
  background: rgba(10, 18, 24, 0.55); backdrop-filter: blur(14px); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}
.landing-panel p { margin: 0 0 14px; font-size: 13.5px; line-height: 1.7; color: rgba(255, 245, 228, 0.86); text-align: center; }
.landing-panel .row { display: flex; gap: 8px; }
.landing-panel .input { background: rgba(255, 255, 255, 0.92); }
.landing-panel .btn { flex: 0 0 auto; height: 46px; padding: 0 18px; border-radius: 14px; }
.landing-panel .mine { margin-top: 12px; text-align: center; font-size: 13px; }
.landing-panel .mine a { color: var(--warm); margin: 0 6px; }
.big-title { font-family: var(--hand); font-size: clamp(30px, 9vw, 46px); margin: 4px 0; letter-spacing: 2px; font-weight: 600; }

/* ---------- scenes ---------- */
.stage[data-scene=nordic] .halo { opacity: 0.25; }
.stage[data-scene=nordic] canvas.tree { filter: brightness(1.12) saturate(0.95); }
.stage[data-scene=nordic] .vignette { background: radial-gradient(120% 90% at 50% 45%, transparent 60%, rgba(60, 40, 20, 0.22)); }
.stage[data-scene=nordic] .grain { opacity: 0.07; }
.stage[data-scene=nordic] .topper { filter: drop-shadow(0 3px 4px rgba(0,0,0,0.3)); animation: none; }
.stage[data-scene=nordic] .ground-shadow { opacity: 0.6; }
.stage[data-scene=nordic] ~ #hud .hud-top, .stage[data-scene=nordic] ~ .hud-top { color: #2a2622; text-shadow: 0 1px 10px rgba(255,255,255,0.7); }
.stage[data-scene=nordic] ~ #hud .eyebrow, .stage[data-scene=nordic] ~ .hud-top .eyebrow { color: #9b4a22; }
.stage[data-scene=nordic] ~ #hud .hint { color: #4a3626; text-shadow: none; }
.stage[data-scene=nordic] ~ #hud .hud-menu, .stage[data-scene=nordic] ~ #hud .tool { background: rgba(255, 255, 255, 0.55); color: #2a2622; box-shadow: 0 0 0 1px rgba(0,0,0,0.06); }

/* flashlight: lights off, your finger is the torch */
.flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.6s;
  --mx: 50%; --my: 55%;
  background: radial-gradient(circle 120px at var(--mx) var(--my), rgba(255, 240, 200, 0.05), rgba(0, 0, 0, 0.35) 55%, rgba(3, 5, 8, 0.94) 100%); }
.stage.dark .flash { opacity: 1; }
.stage.dark canvas.lights { z-index: 3; }
.stage.dark .flash { z-index: 2; }

/* toolbar */
.tools { position: absolute; right: 14px; top: calc(max(14px, env(safe-area-inset-top)) + 46px); display: flex; flex-direction: column; gap: 10px; }
.tool, .hud-menu { width: 38px; height: 38px; border-radius: 50%; background: rgba(12, 18, 24, 0.38); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center; position: relative; color: #fff; box-shadow: 0 0 0 1px rgba(255,255,255,0.14) inset; transition: background .2s, color .2s; }
.tool svg, .hud-menu svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tool.on { background: #fbe6b8; color: #3b2414; box-shadow: 0 0 16px rgba(255, 210, 130, 0.6); }
.tool::after { content: attr(data-tip); position: absolute; right: 46px; top: 50%; transform: translateY(-50%); font-size: 11px; white-space: nowrap; padding: 3px 8px; border-radius: 8px; background: rgba(0,0,0,0.55); color: #fff; opacity: 0; transition: opacity .2s; pointer-events: none; }
.tool:hover::after { opacity: 1; }

/* scene picker: a strip of real thumbnails that slides out next to the button */
.scene-strip { position: absolute; right: 60px; display: flex; gap: 8px; padding: 8px; border-radius: 16px; background: rgba(12, 18, 24, 0.45); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.12) inset; transform-origin: right center; animation: strip .3s cubic-bezier(.2,1,.3,1); z-index: 6; }
@keyframes strip { from { opacity: 0; transform: translateX(10px) scale(.96); } }
.scene-strip button { width: 64px; padding: 0; border-radius: 10px; overflow: hidden; position: relative; box-shadow: 0 0 0 2px transparent; transition: transform .2s; }
.scene-strip button img { display: block; width: 64px; height: 92px; object-fit: cover; }
.scene-strip button span { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 0 5px; font-size: 11px; color: #fff; text-align: center; background: linear-gradient(transparent, rgba(0,0,0,0.65)); }
.scene-strip button.on { box-shadow: 0 0 0 2px #fbe6b8; }
.scene-strip button:active { transform: scale(.96); }

/* 3d photo wall */
.wall3d { position: fixed; inset: 0; z-index: 30; background: radial-gradient(80% 60% at 50% 50%, #1a2630, #05080b); display: flex; align-items: center; justify-content: center;
  perspective: 1100px; opacity: 0; transition: opacity 0.4s; touch-action: none; user-select: none; }
.wall3d.show { opacity: 1; }
.wall3d .ring { position: relative; width: 150px; height: 190px; transform-style: preserve-3d; }
.wall3d .pc { position: absolute; inset: 0; background: #fbf7ef; padding: 8px 8px 30px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); backface-visibility: hidden; cursor: pointer; }
.wall3d .pc img, .wall3d .pc .tx { width: 100%; height: 100%; object-fit: cover; display: block; background: #e9e1d2; }
.wall3d .pc .tx { padding: 10px; font-family: var(--hand); font-size: 13px; line-height: 1.6; color: #3b2a1c; overflow: hidden; background: repeating-linear-gradient(180deg, #fffaf0 0 21px, rgba(160,120,70,.2) 21px 22px); }
.wall3d .pc .cap { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-family: var(--hand); font-size: 13px; color: #6b5d4b; }
.wall3d .w-title { position: absolute; top: max(24px, env(safe-area-inset-top)); left: 0; right: 0; text-align: center; font-family: var(--hand); font-size: 22px; }
.wall3d .w-sub { position: absolute; bottom: max(30px, env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; font-size: 12px; opacity: 0.6; }
.wall3d .close { color: #fff; top: max(18px, env(safe-area-inset-top)); }

/* ---------- write in the air ---------- */
.aw { display: grid; grid-template-columns: 1.15fr 1fr; gap: 10px; align-items: start; }
.aw-cam { position: relative; background: #fff; padding: 8px 8px 26px; box-shadow: 0 4px 14px rgba(0,0,0,0.15); transform: rotate(-2deg); }
.aw-cam video, .aw-cam .aw-ink { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.aw-cam video { transform: scaleX(-1); filter: sepia(0.45) contrast(1.05) saturate(0.8) brightness(1.05); background: #d9d0c0; }
.aw-cam .aw-ink { position: absolute; left: 8px; top: 8px; width: calc(100% - 16px); touch-action: none; cursor: crosshair; }
.aw-cam.flash-snap::after { content: ''; position: absolute; inset: 0; background: #fff; animation: snapflash 0.4s ease-out forwards; }
@keyframes snapflash { from { opacity: 1; } to { opacity: 0; } }
.aw-status { position: absolute; left: 8px; right: 8px; bottom: 32px; text-align: center; font-size: 12px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.6); transition: opacity 0.6s; pointer-events: none; }
.aw-cursor { position: absolute; left: 2px; top: 2px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 6px rgba(0,0,0,0.4); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.aw-cursor.on { background: #c22a32; border-color: #c22a32; }
.aw-paper { position: relative; background: #fffaf0; padding: 10px; min-height: 100%; box-shadow: 0 4px 14px rgba(0,0,0,0.1); transform: rotate(1.5deg);
  background-image: repeating-linear-gradient(180deg, transparent 0 38px, rgba(160,120,70,0.2) 38px 39px); background-position: 0 10px; }
.aw-paper canvas { display: block; width: 100%; }
.aw-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; font-family: var(--hand); color: #b5a58c; font-size: 13px; padding: 10px; }
.aw-tip { font-size: 12px; color: #7a6c5a; line-height: 1.7; margin: 10px 0 0; }
.aw-tools { flex-wrap: wrap; }
.aw-ghost { position: fixed; z-index: 60; pointer-events: none; transform-origin: 50% 50%; transition: transform 0.6s cubic-bezier(0.5, 0, 0.3, 1), opacity 0.6s; }

/* ---------- envelopes ---------- */
.env { --w: 280px; --c: #f3eee3; --c2: #e6dfd0; --seal: #9b1c24; position: relative; width: var(--w); height: calc(var(--w) * 0.64); perspective: 800px; }
.env-cream { --c: #f4efe4; --c2: #e7dfcf; --seal: #9b1c24; }
.env-sage { --c: #aab79e; --c2: #97a58a; --seal: #4d6638; }
.env-floral { --c: #f3e7e0; --c2: #e7d6cc; --seal: #c7868c; }
.env-mist { --c: #dde5ec; --c2: #c9d4de; --seal: #56739f; }
.env-kraft { --c: #caa77b; --c2: #b8935f; --seal: #8e2a1d; }
.env > div { position: absolute; inset: 0; }
.env-back { background: var(--c2); border-radius: 4px; box-shadow: 0 10px 30px rgba(0,0,0,0.25); }
.env-letter { left: 7% !important; right: 7% !important; top: 6% !important; bottom: 6% !important; background: #fffdf7;
  background-image: repeating-linear-gradient(180deg, transparent 0 13px, rgba(160,120,70,0.15) 13px 14px); background-position: 0 20px;
  transition: transform 0.7s cubic-bezier(0.3, 0.8, 0.3, 1); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.env.letter-out .env-letter { transform: translateY(-62%); }
.env-front { background: var(--c); clip-path: polygon(0 0, 50% 52%, 100% 0, 100% 100%, 0 100%); border-radius: 4px;
  box-shadow: inset 0 -20px 30px rgba(0,0,0,0.04); }
.env-floral .env-front, .env-floral .env-flap { background-color: var(--c);
  background-image: radial-gradient(circle at 20% 30%, #e8b4b8 0 3px, transparent 4px), radial-gradient(circle at 70% 60%, #c9d3b0 0 3px, transparent 4px), radial-gradient(circle at 45% 80%, #efc7a9 0 2px, transparent 3px);
  background-size: 34px 30px, 40px 36px, 28px 26px; }
.env-kraft .env-front { background-image: repeating-linear-gradient(35deg, rgba(0,0,0,0.03) 0 2px, transparent 2px 6px); }
.env-flap { background: var(--c); clip-path: polygon(0 0, 100% 0, 50% 56%); transform-origin: 50% 0; transition: transform 0.5s ease-in-out, z-index 0s 0.25s;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.15)); z-index: 3; }
.env.open .env-flap { transform: rotateX(180deg); z-index: 0; filter: brightness(0.93); }
.env.open .env-letter { z-index: 1; }
.env.open .env-back { z-index: 0; }
.env .env-letter { z-index: 1; }
.env .env-front { z-index: 2; }
.env-seal { inset: auto !important; left: 50% !important; top: 56% !important; width: calc(var(--w) * 0.17); height: calc(var(--w) * 0.17); margin: calc(var(--w) * -0.085) 0 0 calc(var(--w) * -0.085);
  border-radius: 46% 54% 50% 50% / 52% 46% 54% 48%; background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.35), transparent 40%), var(--seal);
  box-shadow: 0 0 0 calc(var(--w) * 0.012) var(--seal), inset 0 -3px 6px rgba(0,0,0,0.3), 0 3px 6px rgba(0,0,0,0.3);
  color: rgba(255,255,255,0.55); font-size: calc(var(--w) * 0.075); display: flex; align-items: center; justify-content: center; z-index: 4;
  opacity: 0; transform: scale(2.2); transition: transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1), opacity 0.2s; }
.env.sealed .env-seal { opacity: 1; transform: scale(1); }
.env.broken .env-seal { transform: scale(1.3) rotate(25deg); opacity: 0; transition: transform 0.35s, opacity 0.35s; }
.env.open .env-seal { opacity: 0; }

.envs { display: flex; gap: 10px; overflow-x: auto; padding: 6px 2px 10px; scrollbar-width: none; }
.envs::-webkit-scrollbar { display: none; }
.envs button { flex: 0 0 auto; padding: 8px; border-radius: 12px; }
.envs button .env { pointer-events: none; }
.envs button .env-seal { opacity: 1; transform: none; }
.envs button.on { background: #efe3c8; box-shadow: inset 0 0 0 2px #c9a46b; }

.env-stage { position: fixed; inset: 0; z-index: 45; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: rgba(4, 10, 16, 0.6); backdrop-filter: blur(6px); transition: opacity 0.35s, transform 0.7s cubic-bezier(0.5, 0, 0.6, 1); }
.env-stage.tap { opacity: 0; cursor: pointer; }
.env-stage.tap.show { opacity: 1; }
.env-stage.tap .env { animation: envin 0.7s cubic-bezier(0.2, 1.2, 0.3, 1); }
@keyframes envin { from { transform: translateY(40px) rotate(-6deg) scale(0.8); opacity: 0; } }
.env-stage.tap .env-seal { animation: sealpulse 1.6s ease-in-out infinite 0.8s; }
@keyframes sealpulse { 50% { box-shadow: 0 0 0 calc(var(--w) * 0.012) var(--seal), 0 0 0 10px rgba(255, 220, 150, 0.35), 0 3px 6px rgba(0,0,0,0.3); } }
.env-stage.fade { opacity: 0; }
.env-stage.fly { opacity: 0; }
.env-stage.fly .env { transform: translateY(-60vh) scale(0.15) rotate(20deg); transition: transform 0.7s cubic-bezier(0.5, 0, 0.6, 1); }
.env-caption { font-family: var(--hand); font-size: 16px; color: #ffe9c4; text-shadow: 0 2px 8px rgba(0,0,0,0.5); }
.env-from { font-family: var(--hand); font-size: 20px; color: #fff; }

/* crumple an unsent letter */
.sheet.crumpling { transition: transform 0.45s cubic-bezier(0.6, 0, 0.8, 0.4), border-radius 0.45s, opacity 0.45s !important;
  transform: scale(0.12) rotate(200deg) !important; border-radius: 50% !important; opacity: 0.3; }
.paper-ball { position: fixed; z-index: 50; width: 56px; height: 56px; border-radius: 48% 52% 45% 55%;
  background: radial-gradient(circle at 35% 30%, #fffaf0, #e2d6bf 55%, #b9a888);
  box-shadow: inset -6px -8px 10px rgba(0,0,0,0.15), inset 4px 4px 0 rgba(255,255,255,0.4), 0 6px 10px rgba(0,0,0,0.35);
  background-image: linear-gradient(130deg, transparent 40%, rgba(0,0,0,0.12) 41%, transparent 43%), linear-gradient(40deg, transparent 55%, rgba(0,0,0,0.1) 56%, transparent 58%), radial-gradient(circle at 35% 30%, #fffaf0, #e2d6bf 55%, #b9a888); }
.paper-ball.drop { animation: balldrop 1.5s cubic-bezier(0.4, 0, 0.6, 1) forwards; }
@keyframes balldrop {
  0% { transform: translate(0, 0) rotate(0); }
  55% { transform: translate(30px, calc(100vh - 100%)) rotate(240deg); }
  70% { transform: translate(44px, calc(100vh - 100% - 40px)) rotate(300deg); }
  85% { transform: translate(56px, calc(100vh - 100% - 4px)) rotate(350deg); opacity: 1; }
  100% { transform: translate(64px, calc(100vh - 100% - 4px)) rotate(380deg); opacity: 0; }
}

/* burn a letter */
.card.burning { overflow: hidden; }
.card.burning::after { content: ''; position: absolute; inset: -40%; pointer-events: none;
  background: radial-gradient(circle at 85% 95%, transparent 0 var(--burn), #2a1a10 calc(var(--burn) + 1%), #ff8a2a calc(var(--burn) + 3%), rgba(255,180,80,0.6) calc(var(--burn) + 5%), transparent calc(var(--burn) + 9%));
  -webkit-mask: none; animation: burn 2.2s ease-in forwards; }
.card.burning { -webkit-mask-image: radial-gradient(circle at 92% 98%, transparent 0 var(--burn), #000 calc(var(--burn) + 2%)); mask-image: radial-gradient(circle at 92% 98%, transparent 0 var(--burn), #000 calc(var(--burn) + 2%)); animation: burnmask 2.2s ease-in forwards; }
@property --burn { syntax: '<percentage>'; inherits: true; initial-value: 0%; }
@keyframes burnmask { from { --burn: 0%; } to { --burn: 140%; } }
@keyframes burn { from { --burn: 0%; } to { --burn: 140%; } }
.match { position: absolute; right: 10px; bottom: 6px; font-size: 26px; animation: matchflick 0.2s infinite alternate; filter: drop-shadow(0 0 8px #ff9a3a); }
@keyframes matchflick { to { transform: scale(1.12) rotate(-6deg); } }
.label .seg button { padding: 0 12px; white-space: nowrap; flex: 0 0 auto; }
.aw-snap { display: inline-flex; align-items: center; gap: 5px; } .aw-snap svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.bg { z-index: 0; }
.stage > canvas.layer, .stage > .halo, .stage > .ground-shadow, .stage > .topper, .stage > .gifts, .stage > .ornaments { z-index: 1; will-change: transform; }
.stage > .grain, .stage > .vignette, .stage > .flash { z-index: 2; }
.stage > .scene-title { z-index: 3; }
.hud-menu { position: absolute; }
@media (max-aspect-ratio: 2/3) { .bg-blur { display: none; } }
.orn.decor { cursor: default; pointer-events: none; }
.stage .topper { opacity: calc(0.25 + 0.75 * var(--glow, 1)); }
.stage .halo { opacity: var(--glow, 1); }

/* ---------- delivered gift page ---------- */
#hud { transition: opacity 0.8s; }
.gift-hint { font-family: var(--hand); font-size: 15px; color: rgba(255, 240, 215, 0.9); text-shadow: 0 2px 8px rgba(0,0,0,0.6); padding: 10px 18px; border-radius: 20px; background: rgba(10, 16, 22, 0.35); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.stage[data-scene=nordic] ~ #hud .gift-hint { color: #3a2a1c; background: rgba(255,255,255,0.55); text-shadow: none; }
.intro { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: radial-gradient(80% 60% at 50% 55%, rgba(10, 14, 20, 0.55), rgba(3, 5, 8, 0.92)); transition: opacity 0.9s; }
.intro.go { opacity: 0; pointer-events: none; }
.intro-card { text-align: center; padding: 24px; animation: introin 1.2s ease both; }
@keyframes introin { from { opacity: 0; transform: translateY(12px); filter: blur(6px); } }
.intro-to { font-family: var(--hand); font-size: clamp(34px, 10vw, 52px); font-weight: 600; letter-spacing: 3px; margin: 8px 0 12px; }
.intro-sub { font-family: var(--hand); font-size: 16px; line-height: 1.9; color: rgba(255, 240, 215, 0.85); margin-bottom: 26px; }
.letter-card .dear { font-family: var(--hand); font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.gate { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(80% 60% at 50% 50%, #18242d, #05080b); }
.gate-card { width: min(340px, 100%); background: var(--paper); color: var(--ink); border-radius: 18px; padding: 26px 22px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,0.6); }
.gate-icon svg { width: 34px; height: 34px; fill: none; stroke: #9b1c24; stroke-width: 1.6; }
.gate-title { font-family: var(--hand); font-size: 22px; margin: 8px 0 4px; }
.gate-sub { font-size: 13px; color: #7a6c5a; margin-bottom: 16px; }
.gate .input { text-align: center; margin-bottom: 4px; }
.stage > .gifts { z-index: 2; }
canvas.layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* backgrounds come from --img / --img-wide set in scene.js */
.bg-blur, .bg-main { background-image: var(--img); }
@media (min-aspect-ratio: 1/1) {
  .bg-blur { display: none; }
  .bg-main { left: 0; width: 100%; aspect-ratio: auto; transform: none; background-image: var(--img-wide); background-position: center 70%;
    -webkit-mask-image: none; mask-image: none; }
  .hud-top .title { font-size: 34px; }
  .hud-top .sub { font-size: 14px; }
  .tools { right: 22px; }
  .vcap { bottom: 96px; }
}
@media (min-aspect-ratio: 1/1) and (min-width: 1200px) {
  .card { max-width: 540px; padding: 32px 30px 28px; }
  .card .text { font-size: 21px; line-height: 38px; background: repeating-linear-gradient(180deg, transparent 0 37px, rgba(160, 120, 70, 0.2) 37px 38px); }
  .polaroid img { max-height: 46vh; }
}

/* ---------- photographed tree and gifts: grade them to each scene's light ---------- */
.gift { filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.45)); }
.gift img { display: block; width: 100%; height: auto; -webkit-user-drag: none; }
.ground-shadow { background: radial-gradient(closest-side, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.28) 55%, transparent); }
.stage[data-scene=beach] canvas.tree, .stage[data-scene=beach] .gifts { filter: brightness(0.7) saturate(0.8) contrast(1.08) sepia(0.12); }
.stage[data-scene=beach] .ornaments { filter: brightness(0.86) saturate(0.92); }
.stage[data-scene=home] canvas.tree, .stage[data-scene=home] .gifts { filter: brightness(0.9) sepia(0.2) saturate(1.05); }
.stage[data-scene=nordic] canvas.tree, .stage[data-scene=nordic] .gifts { filter: brightness(1.02) saturate(0.95); }
.stage[data-scene=nordic] .ground-shadow { opacity: 0.55; }

.gift::before { content: ""; position: absolute; left: -10%; right: -10%; bottom: -7%; height: 20%; z-index: -1; border-radius: 50%; background: radial-gradient(closest-side, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.3) 60%, transparent); }
.stage[data-scene=beach] canvas.tree { filter: brightness(0.7) saturate(0.8) contrast(1.08) sepia(0.12) drop-shadow(0 0 14px rgba(255, 130, 60, 0.28)); }
.stage[data-scene=home] canvas.tree { filter: brightness(0.9) sepia(0.2) saturate(1.05) drop-shadow(-10px 0 24px rgba(255, 140, 50, 0.22)); }
