@font-face {
  font-family: "Iansui";
  src: url("assets/fonts/Iansui-Letter.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
:root {
  color-scheme: dark;
  --bg: #17151b;
  --text: #f2e9de;
  --muted: #b9aea3;
  --accent: #d9ae77;
  --paper: #eddfc7;
  --ink: #40332e;
  --font: "Microsoft JhengHei", "PingFang TC", sans-serif;
  --serif: "Noto Serif TC", "PMingLiU", serif;
  --handwriting: "Iansui", "DFKai-SB", "BiauKai", var(--serif);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.75; }
button, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* Empty first screen, then a closed envelope that waits for a second click. */
.letter-page { --envelope-width: min(70vw,500px,calc((100svh - 160px) * 1.58)); height: 100svh; overflow: hidden; }
.opening-screen { position: fixed; inset: 0; display: grid; place-items: center; }
.mailbox { width: 160px; height: 160px; display: grid; place-items: center; padding: 15px; background: transparent; border: 0; border-radius: 28px; color: var(--accent); transition: opacity .24s; }
.mailbox-symbol { position: relative; display: block; width: 115px; height: 115px; transform-origin: 50% 60%; animation: mailbox-sway 2.8s ease-in-out infinite; filter: drop-shadow(0 0 20px rgba(217,174,119,.12)); }
.mailbox-symbol svg { width: 100%; height: 100%; stroke-width: 1.25; }
.unread-dot { position: absolute; right: 1px; top: 16px; width: 23px; height: 23px; display: grid; place-items: center; border-radius: 50%; background: #9a5553; box-shadow: 0 0 0 5px var(--bg); color: #f6e1c4; font-size: 12px; line-height: 1; }
.mailbox:hover .mailbox-symbol { filter: drop-shadow(0 0 24px rgba(217,174,119,.32)); }
.is-delivering .mailbox { opacity: 0; pointer-events: none; }
.is-delivering .mailbox-symbol { animation: none; }
@keyframes mailbox-sway { 0%,50%,100% { transform: translateY(0) rotate(-5deg); } 25%,75% { transform: translateY(-4px) rotate(5deg); } }
.envelope-flight { position: absolute; left: calc(50% - var(--envelope-width) * .5); top: calc(50% - var(--envelope-width) * .3164556962); width: var(--envelope-width); aspect-ratio: 1.58; }
.envelope-whisper { position: fixed; left: 50%; top: calc(50% - var(--envelope-width) * .3164556962 - 62px); width: min(620px,calc(100vw - 40px)); margin: 0; transform: translateX(-50%); color: #c7b9a9; font-family: var(--serif); font-size: 15px; line-height: 1.8; letter-spacing: 1.2px; text-align: center; pointer-events: none; z-index: 2; opacity: .9; animation: whisper-appear 1.5s ease both,whisper-float 3.8s ease-in-out 1.5s infinite; }
@keyframes whisper-appear { from { opacity: 0; } to { opacity: .9; } }
@keyframes whisper-float { 0%,100% { transform: translate(-50%,0); } 50% { transform: translate(-50%,-4px); } }
.envelope-back, .envelope-pocket, .envelope-flap::before, .envelope-flap::after { background-color: #d7bc96; background-image: url('assets/parchment-paper.png'); background-blend-mode: multiply; background-size: 100% 100%; }
.envelope-back { position: absolute; inset: 0; border-radius: 5px; z-index: 1; box-shadow: 0 20px 30px rgba(0,0,0,.3), inset 0 1px 0 rgba(112,79,45,.3); }
/* The uncut carrier rotates at the envelope's top edge. Only its two faces
   are clipped, so the fold retains its depth and attached edge while turning. */
.envelope-flap { position: absolute; inset: 0 0 auto; height: 58%; transform-origin: 50% 0; transform-style: preserve-3d; z-index: 5; }
.envelope-flap::before, .envelope-flap::after { content: ""; position: absolute; inset: 0; clip-path: polygon(0 0,100% 0,50% 100%); backface-visibility: hidden; }
.envelope-flap::before { transform: translateZ(.2px); background-image: linear-gradient(180deg,rgba(255,245,224,.06),rgba(92,65,36,.07)),url('assets/parchment-paper.png'); }
.envelope-flap::after { transform: rotateY(180deg) translateZ(.2px); background-image: linear-gradient(180deg,rgba(85,58,30,.16),transparent 12%),url('assets/parchment-paper.png'); }
/* A narrow paper bridge covers subpixel raster seams without detaching from
   either surface. It travels with the back, using exactly the same timeline. */
.envelope-back::after { content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 2px; background: #c4a87f; }
.envelope-pocket { position: absolute; inset: 0; clip-path: polygon(0 0,50% 55%,100% 0,100% 100%,0 100%); border-radius: 5px; z-index: 4; }
.wax-seal { position: absolute; top: 43%; left: 50%; transform: translateX(-50%) rotate(-9deg); width: 15%; aspect-ratio: 1; border-radius: 44% 51% 43% 48% / 49% 44% 53% 46%; background: radial-gradient(ellipse at 29% 21%,#a75755 0%,#873b41 38%,#6c2932 78%,#58202b 100%); border: 0; color: #57252c; display: grid; place-items: center; z-index: 6; box-shadow: inset 2px 3px 2px rgba(226,142,125,.4),inset -3px -4px 3px rgba(53,12,26,.48),0 3px 2px rgba(65,28,23,.27),0 7px 9px rgba(67,31,20,.17); }
.wax-seal::before { content: ""; position: absolute; inset: 9%; border-radius: 50%; border: 1px solid rgba(73,20,30,.7); box-shadow: inset 0 1px 2px rgba(51,12,25,.45),0 1px 1px rgba(225,144,129,.38); }
.wax-seal::after { content: ""; position: absolute; width: 23%; height: 8%; top: 5%; left: 24%; border-radius: 50%; background: rgba(243,159,139,.16); filter: blur(2px); transform: rotate(-17deg); }
.seal-emblem { width: 70%; height: 70%; stroke-width: 1.5; filter: drop-shadow(0 1px 0 rgba(218,126,113,.7)); }
.envelope-label { position: absolute; bottom: 13%; left: 0; right: 0; text-align: center; font-size: clamp(8px,1.2vw,11px); letter-spacing: 3px; color: #7c6254; z-index: 6; }
.envelope-hint { position: absolute; left: 0; right: 0; bottom: -49px; font-size: 12px; letter-spacing: 3px; color: var(--muted); opacity: 0; text-align: center; z-index: 6; }
.envelope-ready .envelope-hint { opacity: 1; }
.envelope-open { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 5px; background: transparent; z-index: 7; }
.envelope-open:focus-visible { outline-offset: 12px; }
.is-opening .envelope-open { visibility: hidden; pointer-events: none; }
.is-delivering .envelope-flight { animation: envelope-arrival .8s cubic-bezier(.2,.7,.2,1) both; }
@keyframes envelope-arrival { 0% { opacity: 0; transform: translate(0,0) scale(.15) rotate(-18deg); } 15% { opacity: 1; } 55% { transform: translate(45px,-75px) scale(.75) rotate(7deg); } 100% { opacity: 1; transform: translate(0,0) scale(1) rotate(0); } }

/* Portrait A4 (210:297), scaled to fit the screen; text remains readable. */
.letter-paper { position: fixed; left: 50%; top: 50%; width: min(680px,calc(100vw - 32px - env(safe-area-inset-left) - env(safe-area-inset-right)),calc((100svh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .7070707071)); aspect-ratio: 210 / 297; container-type: inline-size; display: grid; grid-template-rows: auto minmax(0,1fr) auto; transform: translate(-50%,-50%); background-color: var(--paper); background-image: url('assets/parchment-paper.png'); background-size: 100% 100%; background-position: center; background-repeat: no-repeat; color: var(--ink); border: 1px solid rgba(164,126,79,.25); box-shadow: 0 1px 2px rgba(0,0,0,.3),0 14px 34px rgba(0,0,0,.24),0 30px 95px rgba(0,0,0,.22); z-index: 3; border-radius: 1px; overflow: hidden; }
.letter-paper::before { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 12px rgba(120,87,45,.12); background: linear-gradient(90deg,rgba(118,78,38,.035),transparent 3%,transparent 97%,rgba(118,78,38,.055)); }
.is-opening .letter-text, .is-opening .paper-footer, .is-opening .close-letter { opacity: 0; }
.letter-open .letter-paper { transform: translate(-50%,-50%); opacity: 1; }
.paper-header { position: relative; height: max(44px,8.2cqw); }
.close-letter { position: absolute; right: 1.8cqw; top: .4cqw; display: grid; place-items: center; background: none; border: 0; border-radius: 50%; width: 44px; height: 44px; color: #7d5e50; font-size: clamp(16px,4.3cqw,25px); line-height: 1; }
.close-letter:hover { background: #e1cdb0; }
.close-letter:focus-visible { outline-color: #845047; }
.paper-body { min-height: 0; overflow: hidden; padding: 1.4cqw 5.3cqw 3cqw; }
.paper-body:focus-visible { outline: 1px dashed #9d7b5e; outline-offset: -6px; }
.letter-text { font-family: var(--handwriting); font-size: 16px; line-height: 1.75; letter-spacing: .012em; overflow-wrap: anywhere; }
.letter-text p { margin: 0 0 .75em; }
.letter-text .salutation { font-size: .8em; letter-spacing: .06em; margin-bottom: .95em; color: #775f52; }
.distress-ink { color: #884548; }
.letter-text .final-warning { margin-bottom: 0; padding-top: .2em; }
.paper-footer { display: flex; align-items: center; justify-content: space-between; gap: 2.5cqw; margin: 0 5.3cqw; padding: 2.7cqw 0; border-top: 1px solid #bda88d; }
.letter-signature { font-family: var(--handwriting); font-size: clamp(9px,2.7cqw,16px); letter-spacing: .25cqw; white-space: nowrap; }
.letter-signature i { font-family: var(--serif); font-style: normal; color: #92584c; margin-left: 5px; }
.letter-entry { display: flex; align-items: center; justify-content: space-between; gap: 4cqw; min-height: 44px; padding: 1.8cqw 3cqw; background: #71463f; color: #f4e2c7; border: 1px solid #71463f; border-radius: 2px; font-size: clamp(9px,2.2cqw,14px); letter-spacing: .06em; transition: background .2s; }
.letter-entry:hover { background: #8a5548; }
.letter-entry:focus-visible { outline-color: #77413b; }
.no-script { padding: 40px; font-size: 16px; max-width: 700px; margin: auto; }
@container(max-width:420px) { .letter-signature { display: none; } .letter-entry { width: 100%; } }

/* Six quiet choices; descriptions exist only inside the closed native dialog. */
.trials-minimal-header { height: 70px; padding: 20px 32px; display: flex; align-items: center; }
.back-link { font-size: 12px; letter-spacing: 1px; color: var(--muted); padding: 7px 0; }
.back-link:hover { color: var(--accent); }
.trial-home { min-height: calc(100svh - 70px); display: grid; place-items: center; padding: 18px 28px 70px; }
.trial-icons { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 40px 54px; width: min(100%,850px); }
.trial-choice { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 22px 12px; min-height: 188px; border: 0; border-radius: 12px; background: transparent; color: var(--text); }
.trial-choice-icon { width: 82px; height: 82px; color: var(--accent); stroke-width: 1.2; transition: transform .25s,filter .25s; }
.trial-choice-name { font-family: var(--serif); font-size: 17px; line-height: 1.8; letter-spacing: 1.3px; text-align: center; }
.trial-choice:hover .trial-choice-icon { transform: translateY(-5px); filter: drop-shadow(0 0 14px rgba(217,174,119,.22)); }
.trial-choice:hover .trial-choice-name { color: var(--accent); }
.trial-modal { width: min(470px,calc(100vw - 36px)); max-height: calc(100svh - 40px); padding: 39px 35px 34px; border: 1px solid #665045; border-radius: 5px; background: #251f29; color: var(--text); box-shadow: 0 20px 80px rgba(0,0,0,.35); overflow-y: auto; }
.trial-modal::backdrop { background: rgba(10,8,14,.7); backdrop-filter: blur(5px); }
.trial-modal[open] { animation: intro-appear .22s ease-out; }
.close-trial { position: absolute; top: 9px; right: 9px; width: 44px; height: 44px; background: transparent; border: 0; border-radius: 50%; color: var(--muted); font-size: 25px; line-height: 1; }
.close-trial:hover { background: #352a33; color: var(--accent); }
.modal-trial-icon { display: block; width: 67px; height: 67px; color: var(--accent); stroke-width: 1.3; margin-bottom: 23px; }
.trial-modal h2 { font-family: var(--serif); font-weight: 400; font-size: 27px; line-height: 1.5; letter-spacing: 1px; margin: 0 0 17px; overflow-wrap: anywhere; }
.trial-modal p { font-size: 15px; line-height: 2; color: #d0c2b5; margin: 0; }
.trial-modal #modal-description { white-space: pre-line; }
.modal-trial-meta { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; margin: 0 0 22px; padding-bottom: 17px; border-bottom: 1px solid #51414b; font-size: 12px; line-height: 1.8; }
.modal-trial-meta dt { color: var(--muted); }
.modal-trial-meta dd { color: var(--accent); margin: 0; }
@keyframes intro-appear { from { opacity: 0; transform: translateY(7px) scale(.98); } to { opacity: 1; transform: none; } }

@media(max-width:650px) {
  .trial-icons { gap: 27px 15px; grid-template-columns: repeat(2,minmax(0,1fr)); max-width: 430px; }
  .trial-home { padding: 10px 20px 38px; }
  .trials-minimal-header { padding-left: 23px; }
  .trial-choice { min-height: 164px; padding: 17px 4px; gap: 20px; }
  .trial-choice-icon { width: 66px; height: 66px; }
  .trial-choice-name { font-size: 15px; letter-spacing: .5px; }
  .trial-modal { padding: 34px 27px 28px; }
  .trial-modal h2 { font-size: 25px; }
}
@media(max-width:480px) {
  .letter-paper { width: min(calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)),calc((100svh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .7070707071)); }
  .letter-page { --envelope-width: min(82vw,500px,calc((100svh - 160px) * 1.58)); }
  .mailbox { width: 150px; height: 150px; }
  .mailbox-symbol { width: 108px; height: 108px; }
}
@media(max-height:600px) and (min-width:600px) {
  .trial-home { padding-top: 0; padding-bottom: 20px; }
  .trial-icons { gap: 8px 30px; }
  .trial-choice { min-height: 155px; gap: 15px; }
  .trial-choice-icon { width: 60px; height: 60px; }
}
@media(max-height:700px) and (max-width:650px) {
  .trials-minimal-header { height: 56px; padding-top: 12px; padding-bottom: 12px; }
  .trial-home { min-height: calc(100svh - 56px); padding: 0 20px 20px; }
  .trial-icons { gap: 12px 15px; }
  .trial-choice { min-height: 136px; padding: 10px 4px; gap: 14px; }
  .trial-choice-icon { width: 54px; height: 54px; }
  .trial-choice-name { font-size: 14px; }
}
@media(prefers-reduced-motion:reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .trial-choice:hover .trial-choice-icon { transform: none; }
}
