:root {
  color-scheme: light;
  --paper: #e9e6de;
  --sheet: #f1ece2;
  --ink: #423f37;
  --muted: #858177;
  --red: #ae3a2d;
  --ease: cubic-bezier(.22, .61, .36, 1);
}
* { box-sizing: border-box; }
body { margin: 0; overflow: hidden; background: var(--paper); color: var(--ink); font-family: Georgia, 'Songti SC', SimSun, serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 1px solid #a27d63; outline-offset: 6px; }
#sky, #world, #contour { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#sky { z-index: 0; }
#scene-viewport { position: fixed; inset: 0; z-index: 3; mask: url(#reveal-mask); -webkit-mask: url(#reveal-mask); pointer-events: none; }
#world { z-index: 1; }
#world canvas { display: block; width: 100%; height: 100%; }
#contour { z-index: 4; overflow: visible; }
#contour path { fill: none; stroke: #8d7961; stroke-width: .75; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
body[data-state=sealed] #scene-viewport, body[data-state=opening] #scene-viewport, body[data-state=ready] #scene-viewport { visibility: hidden; }
.grain { position: fixed; inset: 0; z-index: 8; pointer-events: none; opacity: .045; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.87' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Cpath fill='%23000' filter='url(%23n)' opacity='.5' d='M0 0h180v180H0z'/%3E%3C/svg%3E"); }
header { position: fixed; top: 34px; left: 42px; right: 42px; z-index: 9; display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; letter-spacing: .22em; pointer-events: none; opacity: .72; transition: opacity 1.5s var(--ease), color 2s; }
header > span:last-child { font: 9px Georgia, serif; letter-spacing: .18em; color: var(--muted); }
body[data-state=lantern] header, body[data-state=dimming] header, body[data-state=ship] header, body[data-state=zooming] header { opacity: .36; }
#letter-stage { position: fixed; inset: 0; z-index: 2; transform: translateZ(0); pointer-events: none; }
body[data-state=lantern] #letter-stage { mask: url(#outside-mask); -webkit-mask: url(#outside-mask); }
body[data-state=dimming] #letter-stage, body[data-state=embers] #letter-stage, body[data-state=ship] #letter-stage, body[data-state=zooming] #letter-stage, body[data-state=ended] #letter-stage { visibility: hidden; }
#intro { position: fixed; left: 50%; top: 46%; width: min(630px, 78vw); height: min(440px, 68vh); transform: translate(-50%, -50%); perspective: 1800px; z-index: 2; pointer-events: none; }
.envelope-shell { transform: translateY(0); visibility: visible; }
.envelope-back { position: absolute; inset: 0; background: #d8cdbb; z-index: 0; }
.envelope { position: absolute; inset: 0; z-index: 2; filter: drop-shadow(0 12px 24px #5b49340c); }
.envelope-front { position: absolute; inset: 0; background: linear-gradient(145deg, #ece3d4, #e2d6c2); clip-path: polygon(0 0, 50% 53%, 100% 0, 100% 100%, 0 100%); }
.envelope-front::after { content: ''; position: absolute; inset: 0; background: linear-gradient(10deg, #e8ddcb, #eee5d6); clip-path: polygon(0 100%, 50% 45%, 100% 100%); }
.flap-shell { position: absolute; inset: 0; z-index: 4; transform-style:preserve-3d; }
body:not([data-state=sealed]) .flap-shell { z-index: 0; }
.flap-fold { position:absolute; inset:0 0 auto; height:57%; transform-origin:center top; transform-style:preserve-3d; }
.flap { position: absolute; inset: 0; z-index: 3; background: linear-gradient(#eee5d7, #d9c9af); clip-path: polygon(0 0, 100% 0, 50% 100%); }
body:not([data-state=sealed]) .flap-fold { animation: flap-open 1.3s cubic-bezier(.45, 0, .55, 1) both paused; }
@keyframes flap-open { from { transform:rotateX(0deg); } to { transform:rotateX(180deg); } }
#seal { position: absolute; left: calc(50% - 33px); top: calc(92.982456% - 33px); width: 66px; height: 66px; border: 0; border-radius: 50%; z-index: 5; pointer-events: auto; transform:translateZ(2px); backface-visibility:hidden; background: radial-gradient(circle at 35% 28%, #bd4a39, #a43328 72%, #8e2a23); box-shadow: 0 3px 5px #642c2028, inset 0 0 0 2px #ae4030, inset 0 0 0 4px #912e2226; }
#seal span { position: absolute; inset: 12px; border: 1px solid #dd765333; border-radius: 50%; box-shadow: inset 1px 1px 2px #6b1d1924; }
body:not([data-state=sealed]) #seal { pointer-events: none; }
.address { position: absolute; bottom: 21%; left: 0; right: 0; text-align: center; font-size: 15px; letter-spacing: .35em; color: #817463; }
#open-hint { position: absolute; bottom: 8%; width: 100%; text-align: center; font-size: 10px; letter-spacing: .16em; color: #928675; transition: opacity .3s; }
body:not([data-state=sealed]) #open-hint { opacity: 0; }
body:not([data-state=sealed]) .envelope-shell { animation: envelope-drop 1.85s 1.35s cubic-bezier(.45, 0, .7, 1) both paused; }
@keyframes envelope-drop { 0% { transform: translateY(0); visibility: visible; } 99.9% { visibility: visible; } 100% { transform: translateY(180vh); visibility: hidden; } }
.letter { position: absolute; z-index: 1; inset: 16px; padding: 42px 46px; background: #f1ece2; box-shadow: 0 6px 24px #57472e09; text-align: left; opacity: 1; }
h1 { font-size: 28px; font-weight: 400; line-height: 1.5; letter-spacing: .12em; margin: 0 0 25px; }
#opening p { font-size: 14px; line-height: 2.15; letter-spacing: .075em; margin: 0; }
.signature { display: block; text-align: right; font-size: 11px; letter-spacing: .1em; margin-top: 22px; color: #968c7e; }
.paper-igniter, .desk-igniter { position: absolute; left: 50%; width: 10px; height: 20px; transform: translate(-50%, -50%); border-radius: 2px; background: linear-gradient(90deg, #69513b, #b29770, #795b40); pointer-events: none; }
.paper-igniter { top: calc(75% + 8px); }
.desk-igniter { display: none; top: 50%; }
.paper-igniter::after, .desk-igniter::after { content: ''; position: absolute; left: -4px; bottom: -3px; width: 18px; height: 5px; border-radius: 50%; background: #8a6f4c; }
.paper-igniter i, .desk-igniter i { position: absolute; left: 4px; top: -3px; width: 2px; height: 4px; background: #943e25; }
.paper-igniter.model-candle, .desk-igniter.model-candle { width:64px; height:80px; background:none; transform:translate(-50%,-8%); }
.model-candle::after { display:none; }
.model-candle img { display:block; width:100%; height:100%; object-fit:contain; }
body[data-model=letter] #paper-prompt, body[data-model=letter] .opening-prompt { top:calc(75% + 88px); }
body[data-model=letter][data-state=embers] #prompt { margin-top:42px; }
#paper-prompt { position: absolute; left: 0; right: 0; top: calc(75% + 39px); margin: 0; text-align: center; font-size: 11px; letter-spacing: .1em; color: #85847e; pointer-events: none; }
#interaction { position: fixed; z-index: 5; transform: translate(-50%, -50%); width: 80px; height: 80px; opacity: 0; pointer-events: none; transition:opacity .5s var(--ease); }
body[data-state=ready] #interaction, body[data-state=embers] #interaction { opacity: 1; pointer-events: auto; }
body[data-state=embers] .desk-igniter, body[data-state=ship] .desk-igniter { display: block; }
#ignite { position: relative; width: 80px; height: 80px; display: block; border: 0; background: transparent; }
#ignite:hover { background: transparent; box-shadow: none; }
#ignite:focus:not(:focus-visible) { outline: none; }
#ignite:disabled { pointer-events: none; }
#prompt { position: fixed; z-index: 5; transform: translateX(-50%); white-space: nowrap; font-size: 11px; letter-spacing: .1em; margin: 0; color: #85847e; pointer-events: none; opacity:0; transition:opacity .7s var(--ease); }
body[data-state=embers] #prompt { opacity:1; }
#story { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.words { position: static; }
.words p { position: absolute; top: 0; left: 0; white-space: nowrap; font-size: 16px; line-height: 1.8; margin: 0; }
.flying-glyph { position: absolute; left: 0; top: 0; display: block; width: 1em; height: 1em; line-height: 1; text-align: center; opacity: 0; transform-origin: center; will-change: transform, opacity; }
.words p:first-child { font-size: inherit; }
body[data-state=lantern] .words p, body[data-state=dimming] .words p { color:#e2d9c9; }
body[data-state=lantern] .words p:first-child, body[data-state=dimming] .words p:first-child { font-size:16px; color:#e2d9c9; }
#study-copy { position:absolute; top:9%; right:8%; width:min(440px,36vw); font-size:14px; line-height:2.15; color:#665b50; visibility:hidden; }
body[data-state=dimming] #study-copy, body[data-state=embers] #study-copy, body[data-state=ship] #study-copy { visibility:visible; }
#study-copy p { margin:0; }
#ending-copy { position:fixed; left:10%; bottom:20%; z-index:5; max-width:420px; font-size:16px; line-height:2; color:#e2d9c9; opacity:0; visibility:hidden; pointer-events:none; transition:opacity 1.2s var(--ease); }
#ending-copy p { margin:0; }
body[data-state=ended] #ending-copy { opacity:1; visibility:visible; }
body[data-state=zooming] #story, body[data-state=zooming] #study-copy, body[data-state=zooming] #prompt { visibility:hidden; }
.address { font-size:20px; letter-spacing:0; }
#study-stage { position: fixed; inset: 0; z-index: 1; pointer-events: none; transform: translateZ(0); mask: url(#outside-mask); -webkit-mask: url(#outside-mask); }
#study { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; visibility: hidden; }
body[data-state=dimming] #study, body[data-state=embers] #study, body[data-state=ship] #study { visibility: visible; }
#cursor-fire { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 10; pointer-events: none; }
#star { position: fixed; z-index: 7; transform: translate(-50%, -50%); width: 52px; height: 52px; border: 0; border-radius: 50%; background:transparent; color:transparent; font-size:0; text-shadow:none; }
#star:hover { background:transparent; text-shadow:none; }
@keyframes starlight { 50% { box-shadow: 0 0 22px #ffedb517; } }
body[data-state=zooming] #star, body[data-state=ended] #star, body.sky-still #star { animation: none; }
#star:disabled { pointer-events: none; cursor: default; }
#star[hidden], #return-letter[hidden] { display: none; }
footer { position: fixed; bottom: 30px; left: 42px; right: 42px; display: flex; justify-content: space-between; align-items: center; font-size: 10px; letter-spacing: .09em; z-index: 9; color: #92897c; transition: color 2s, opacity 1.5s var(--ease); }
body[data-state=lantern] footer, body[data-state=ship] footer, body[data-state=zooming] footer { opacity: .65; }
#chapter { min-width: 220px; }
#replay { border: 0; background: transparent; color: inherit; font-size: 10px; padding: 10px 0 10px 16px; opacity: .6; transition: opacity .3s; }
#replay:hover, #replay:focus-visible { opacity: 1; }
#replay span { margin-left: 9px; }
.progress { display: flex; gap: 8px; position: absolute; left: 50%; transform: translateX(-50%); }
.progress b { height: 1px; width: 15px; background: #bcb5a7; opacity: .5; transition: opacity .8s, background .8s; }
.progress b.active { background: #9d7962; opacity: 1; }
.night header { color: #e3d8c1; }
.night header > span:last-child, .night footer { color: #a99f8f; }
.night .progress b.active { background: #d4bfa0; }
#error { position: fixed; top: 80px; left: 50%; transform: translateX(-50%); background: #f3eee4; padding: 15px; font-size: 13px; z-index: 10; }
#transition-veil { position: fixed; inset: 0; z-index: 20; background: var(--paper); opacity: 0; pointer-events: none; transition: opacity .45s var(--ease); }
body.restarting #transition-veil { opacity: 1; transition-duration: .25s; pointer-events: auto; }
@media (max-height: 760px) { .letter { padding: 27px 38px; } h1 { font-size: 25px; margin-bottom: 18px; } .signature { margin-top: 16px; } .words p { font-size: 14px; } }
@media (max-width: 900px) { header, footer { left: 26px; right: 26px; } header > span:last-child { font-size: 8px; letter-spacing: .1em; } #intro { width: min(610px, 82vw); } .letter { padding-left: 32px; padding-right: 32px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition-duration: .01s !important; } body:not([data-state=sealed]) .envelope-shell { transform: translateY(180vh); visibility: hidden; } body:not([data-state=sealed]) .flap-shell { z-index: 0; } body:not([data-state=sealed]) .flap-fold { transform:rotateX(180deg); } }

footer { justify-content: flex-end; }
#return-letter { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 6; border: 0; padding: 0; background: transparent; cursor: pointer; }
#return-letter:focus-visible { outline: 1px solid #d4bfa04d; outline-offset: -24px; }
body[data-state=returning] #scene-viewport { visibility:hidden; }
body[data-state=returning] #letter-stage { visibility: visible; }
body[data-state=returning] #contour { visibility: hidden; }

body[data-state=paper] #scene-viewport,body[data-state=paper] #contour { visibility:hidden; }
/* Stable page slots keep the sheet connected while each face bends at its fold. */
body.bound-pages #letter-stage { overflow-y:auto; overflow-x:hidden; pointer-events:auto; padding:10vh 0; overscroll-behavior:contain; scrollbar-width:thin; scrollbar-color:#bcb3a444 transparent; }
body.bound-pages #intro { position:relative; left:auto; top:auto!important; margin:0 auto; width:min(740px,86vw); height:auto; transform:none; perspective:none; }
body.bound-pages .letter { position:relative; inset:auto; padding:0; background:none; box-shadow:none; }
body.bound-pages .letter > :not(#paper-pages) { display:none; }
#paper-pages { display:none; }
body.bound-pages #paper-pages { display:block; pointer-events:auto; perspective:3000px; transform-style:preserve-3d; }
.paper-panel { position:relative; min-height:80vh; transform-style:preserve-3d; }
.paper-face { position:relative; display:flex; flex-direction:column; justify-content:center; gap:28px; min-height:inherit; padding:clamp(30px,4.4vh,48px) 46px; background:var(--sheet); transform:translate3d(0,var(--fold-y,0px),var(--fold-z,0px)) rotateX(var(--fold-angle,0deg)); transform-origin:center top; backface-visibility:hidden; box-shadow:0 8px 24px #57472e08; }
.paper-panel + .paper-panel .paper-face { box-shadow:inset 0 1px #90795a21,0 8px 24px #57472e08; }
.paper-face::before, .paper-face::after { content:''; position:absolute; inset:0; pointer-events:none; }
.paper-face::before { background:#77634b; opacity:var(--fold-shade,0); }
.paper-face::after { background:linear-gradient(180deg,#9c886609,transparent 18px,transparent calc(100% - 18px),#fff8e82b); }
.paper-panel:nth-child(even) .paper-face::after { background:linear-gradient(180deg,#fff8e83b,transparent 20px,transparent calc(100% - 18px),#9c886609); }
body.paper-turning .paper-face { will-change:transform; }
#paper-pages h2 { font-size:18px; font-weight:400; letter-spacing:.14em; margin:0; }
.page-art { display:block; width:100%; height:auto; max-height:40vh; object-fit:contain; }
.page-lines { display:flex; justify-content:space-between; gap:28px; font-size:12px; line-height:2.25; letter-spacing:.035em; }
.page-lines:empty { display:none; }
.page-lines p { margin:0; }
.page-lines > div:last-child:not(:first-child) { text-align:right; }
.paper-panel[data-page="0"] .page-lines { font-size:14px; line-height:2.3; }
body.bound-pages .envelope-shell { display:none; }
body.bound-pages #letter-stage:focus { outline:none; }
body[data-state=returning] #letter-stage { overflow:hidden; }
#paper-landing { position:fixed; inset:0; z-index:8; pointer-events:none; overflow:hidden; background:transparent; }
#paper-landing[hidden] { display:none; }
#paper-landing .landing-background, #paper-landing .landing-star { position:absolute; inset:0; width:100%; height:100%; }
#paper-landing .landing-background { will-change:opacity; }
#paper-landing .landing-chart { position:absolute; }
.paper-panel[data-page="4"] .paper-face { height:80vh; min-height:80vh; padding:0; align-items:center; }
.paper-panel[data-page="4"] h2 { position:absolute; top:28px; left:46px; font-size:14px; color:#8b8072; }
.paper-panel[data-page="4"] .page-art { width:min(520px,64vh,70vw); height:min(520px,64vh,70vw); max-height:none; flex:none; }
body[data-state=returning] footer { opacity:.35; }
body[data-state=paper] footer { opacity:.6; }
@media(max-height:720px) { .paper-face { padding:28px 38px; gap:20px; } .page-lines { font-size:11px; } }

.paper-panel[data-fold="valley"] .paper-face::after { background:linear-gradient(180deg,#6e5a4112,transparent 22px,transparent calc(100% - 18px),#fff9ec45); }
.paper-panel:not([data-page="4"]) .page-art { border-radius:0; }

/* A folded letter held through the story, then set down for reading. */
body.bound-pages { --book-height:min(408px,calc(68vh - 32px)); }
body.bound-pages #letter-stage { padding:calc((100vh - var(--book-height))/2) 0; scrollbar-width:none; }
body.bound-pages #letter-stage::-webkit-scrollbar { display:none; }
body.bound-pages #intro { width:min(598px,calc(78vw - 32px)); }
.paper-panel { min-height:var(--book-height); }
.paper-face { display:grid; grid-template-columns:1.1fr 1fr; align-items:center; gap:28px; min-height:var(--book-height); height:var(--book-height); padding:42px 46px; }
.page-copy h2 { margin:0 0 20px!important; }
.page-lines { flex-direction:column; gap:14px; font-size:12px; line-height:2; letter-spacing:.025em; }
.page-lines > div:last-child:not(:first-child) { text-align:left; }
.page-art { width:100%; max-height:240px; }
.paper-panel[data-page="1"] .page-art { order:-1; }
.paper-panel[data-page="1"] .paper-face { grid-template-columns:1fr 1.1fr; }
.paper-panel[data-page="4"] .paper-face { display:grid; grid-template-columns:.8fr 1.4fr; height:var(--book-height); min-height:var(--book-height); padding:42px 46px; }
.paper-panel[data-page="4"] h2 { position:static; font-size:18px; color:var(--ink); }
.paper-panel[data-page="4"] .page-art, .page-star-continuation { position:absolute; inset:0; display:block; width:100%; height:100%; max-height:none; object-fit:fill; pointer-events:none; }
.paper-panel[data-page="4"] .page-copy { position:relative; z-index:1; }
.paper-face.opening-page { display:block; }
.opening-copy p { font-size:14px; line-height:2.15; letter-spacing:.075em; margin:0; }
.opening-prompt { position:absolute; left:0; right:0; top:calc(75% + 39px); margin:0; text-align:center; font-size:11px; letter-spacing:.1em; color:#85847e; pointer-events:none; }
body[data-state=returning] .paper-face { box-shadow:0 12px 28px #57472e10; }
@media(max-height:760px) { .paper-face,.paper-panel[data-page="4"] .paper-face { padding:27px 38px; } }
