:root {
  color-scheme: dark;
  --ink: #f3eee4;
  --ink-soft: rgba(243, 238, 228, 0.72);
  --ink-faint: rgba(243, 238, 228, 0.48);
  --night: #10252a;
  --night-deep: #09191e;
  --green: #73928a;
  --paper: #eee5d5;
  --paper-ink: #2c3a39;
  --amber: #d7a765;
  --line: rgba(240, 235, 223, 0.22);
  --content: min(1180px, calc(100vw - 48px));
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--night-deep);
  color: var(--ink);
  overflow-x: hidden;
  --journey: 0;
}
button, textarea { font: inherit; }
button { cursor: pointer; }

.world {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  background: #0e2227;
  transition: filter 2.8s ease, transform 2.8s ease;
}

.world__scene {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0.92;
  transform: scale(1.08) translate3d(calc(var(--journey) * -2.2vw), calc(var(--journey) * -1.4vh), 0);
  transition: transform 0.15s linear, filter 2.8s ease;
}

.world__veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(5, 17, 21, 0.54) 0%, rgba(6, 18, 22, 0.2) 48%, rgba(12, 32, 34, 0.38) 100%);
  transition: background 3s ease;
}

.rain {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.58;
  transition: opacity 2s ease;
  pointer-events: none;
}

.water-shimmer {
  position: absolute;
  left: 9%; right: 8%; bottom: 10%; height: 15%;
  background: repeating-linear-gradient(0deg, transparent 0 9px, rgba(216, 190, 141, 0.035) 10px 11px);
  mask-image: linear-gradient(90deg, transparent, #000 20%, #000 78%, transparent);
  animation: shimmer 7s ease-in-out infinite alternate;
}
@keyframes shimmer { to { transform: translateY(8px); opacity: 0.55; } }

.topbar {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  width: 100%;
  height: 76px;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(8, 22, 26, 0.68), transparent);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: rgba(246, 240, 228, 0.82);
  text-decoration: none;
  font-size: 13px;
}
.brand__stamp {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border: 1px solid rgba(237, 199, 139, 0.58);
  border-radius: 50%;
  color: #edc78b;
  font-family: SimSun, serif;
  transform: rotate(-8deg);
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(242, 236, 224, 0.24);
  border-radius: 50%;
  background: rgba(10, 27, 31, 0.32);
  color: var(--ink);
  transition: background 0.25s, border-color 0.25s, transform 0.25s;
}
.icon-button:hover { background: rgba(238, 228, 208, 0.12); border-color: rgba(242, 236, 224, 0.48); transform: translateY(-2px); }
.icon-button.is-on { color: #f1c57c; border-color: rgba(241, 197, 124, 0.64); }
.icon-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.chapter {
  width: 100%;
  min-height: 100svh;
  padding: 120px max(24px, calc((100vw - 1180px) / 2)) 88px;
  display: flex;
  align-items: center;
  position: relative;
  transition: opacity 0.8s ease, filter 0.8s ease;
}
.chapter::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(7, 22, 26, 0.22), rgba(7, 22, 26, 0.34));
  z-index: -1;
}
.chapter:nth-of-type(even)::before { background: linear-gradient(180deg, rgba(7, 22, 26, 0.34), rgba(7, 22, 26, 0.22)); }
.chapter.is-locked { display: none; }
.chapter.is-entering { animation: chapterIn 0.9s ease both; }
@keyframes chapterIn { from { opacity: 0; transform: translateY(24px); } }

.chapter--opening { align-items: flex-end; padding-bottom: 12vh; }
.chapter--opening::before { background: linear-gradient(90deg, rgba(6, 18, 22, 0.5), rgba(6, 18, 22, 0.08) 70%); }
.opening-copy { max-width: 680px; }
.reveal-on-load { animation: openingIn 1.5s 0.25s ease both; }
@keyframes openingIn { from { opacity: 0; transform: translateY(22px); } }

.eyebrow {
  margin: 0 0 22px;
  color: #d9bd8e;
  font-family: SimSun, serif;
  font-size: 13px;
  letter-spacing: 0;
}
h1, h2 {
  margin: 0;
  font-family: STKaiti, KaiTi, SimSun, serif;
  font-weight: 400;
  letter-spacing: 0;
  text-wrap: balance;
}
h1 { font-size: clamp(45px, 6.2vw, 88px); line-height: 1.13; }
h2 { font-size: clamp(36px, 4.4vw, 64px); line-height: 1.25; }
.lead {
  margin: 30px 0 36px;
  color: var(--ink-soft);
  font-size: clamp(16px, 1.5vw, 19px);
  line-height: 2;
}
.opening-note {
  position: absolute;
  right: max(24px, calc((100vw - 1180px) / 2));
  bottom: 11vh;
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--ink-faint);
  font-size: 12px;
  writing-mode: vertical-rl;
}
.opening-note__line { width: 1px; height: 72px; background: rgba(243, 238, 228, 0.32); }

.text-button {
  min-height: 0;
  padding: 0 0 10px;
  border: 0;
  border-bottom: 1px solid currentColor;
  border-radius: 0;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  justify-self: start;
  width: max-content;
  max-width: 100%;
  gap: 18px;
  background: transparent;
  font-size: 14px;
  letter-spacing: 0;
  white-space: nowrap;
  transition: color 0.25s, border-color 0.25s;
}
.text-button:hover { color: #f0ca8b; border-color: #f0ca8b; }
.text-button:focus-visible,
.text-link:focus-visible,
.choice-row:focus-visible,
.icon-button:focus-visible { outline: 1px solid rgba(240, 202, 139, 0.82); outline-offset: 6px; }
.text-button:hover svg { transform: translateX(5px); }
.text-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; transition: transform .25s ease; }
.text-button--primary { color: var(--ink); }
.text-button--light { color: var(--ink); border-color: rgba(243, 238, 228, 0.5); }

.chapter-copy { max-width: 650px; }
.chapter-copy--narrow { max-width: 760px; }
.section-intro { margin: 24px 0 0; color: var(--ink-soft); line-height: 1.9; font-size: 16px; }

.choice-list { width: min(720px, 100%); margin-top: 54px; border-top: 1px solid var(--line); }
.choice-row {
  width: 100%;
  min-height: 82px;
  padding: 0 6px;
  border: 0;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 58px 1fr 28px;
  align-items: center;
  background: transparent;
  color: var(--ink);
  text-align: left;
  transition: padding 0.25s, background 0.25s;
}
.choice-row:hover { padding-left: 15px; background: rgba(238, 228, 208, 0.055); }
.choice-row__index { color: #c6a979; font-family: Georgia, serif; font-size: 12px; }
.choice-row__label { font-family: STKaiti, KaiTi, serif; font-size: clamp(21px, 2.2vw, 28px); }
.choice-row svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; }

.quiet-space, .path-response { margin-top: 46px; animation: fadeUp 0.8s ease both; }
.quiet-space { position: relative; padding-left: 72px; }
.quiet-space__light {
  position: absolute;
  left: 4px; top: 5px;
  width: 42px; height: 42px;
  border: 1px solid rgba(235, 196, 126, 0.55);
  border-radius: 50%;
  box-shadow: 0 0 36px rgba(232, 180, 100, 0.22);
  animation: breathe 5.5s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: scale(1.28); box-shadow: 0 0 55px rgba(232, 180, 100, 0.36); } }
.quiet-space p, .path-response p { margin: 0 0 10px; font-family: STKaiti, KaiTi, serif; font-size: 28px; }
.quiet-space span, .path-response span { color: var(--ink-soft); line-height: 1.8; }
.text-link {
  border: 0;
  border-bottom: 1px solid rgba(40, 61, 58, 0.32);
  padding: 3px 0 5px;
  background: none;
  color: #344d49;
  font-size: 14px;
}
.quiet-space .text-link { display: block; margin-top: 26px; color: #e4c18b; border-color: rgba(228, 193, 139, 0.4); }
.text-link--light { color: #e7c68f; border-color: rgba(231, 198, 143, 0.42); }

.chapter--score::before { background: linear-gradient(180deg, rgba(7, 21, 25, 0.38), rgba(7, 21, 25, 0.5)); }
.score-layout { width: 100%; display: grid; grid-template-columns: 1fr 0.85fr; column-gap: 8vw; align-items: center; }
.score-layout .chapter-copy { grid-row: span 2; }
.score-stage { position: relative; height: 330px; display: grid; place-items: center; overflow: visible; }
.score-stage.is-doodling { touch-action: none; cursor: crosshair; }
.score-paper {
  position: relative;
  z-index: 1;
  width: 250px;
  height: 170px;
  padding: 30px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr;
  align-items: end;
  background: #e7ddca;
  color: #2c3b3a;
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.3);
  transform: rotate(-2deg);
  transition: opacity 0.45s, transform 0.7s;
}
.score-paper::after { content: ""; position: absolute; inset: 9px; border: 1px solid rgba(45, 59, 57, 0.18); }
.score-paper__label { grid-column: span 2; align-self: start; color: rgba(44, 59, 58, 0.62); font-size: 13px; }
.score-paper strong { font-family: Georgia, serif; font-size: 64px; font-weight: 400; line-height: 1; }
.score-paper__unit { padding-bottom: 8px; font-size: 14px; }
.score-stage.is-doodling .score-paper { transform: rotate(-1deg) scale(1.03); box-shadow: 0 28px 70px rgba(0,0,0,.38); }
.score-stage.is-scribbled .score-paper { opacity: 0.72; transform: rotate(1.5deg) scale(.98); }
.doodle-canvas {
  position: absolute;
  z-index: 4;
  width: 292px;
  height: 215px;
  touch-action: none;
  opacity: 0;
  pointer-events: none;
  cursor: crosshair;
  transition: opacity .35s ease;
}
.score-stage.is-doodling .doodle-canvas,
.score-stage.is-scribbled .doodle-canvas { opacity: 1; }
.doodle-pen {
  position: absolute;
  z-index: 5;
  right: 12%;
  bottom: 12%;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(238,229,213,.5);
  border-radius: 50%;
  color: #ead7b6;
  font-size: 24px;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity .35s, transform .35s;
}
.score-stage.is-doodling .doodle-pen { opacity: 1; transform: translateY(0); animation: penNudge 1.2s ease-in-out infinite alternate; }
@keyframes penNudge { to { transform: translate(-8px, -6px) rotate(-8deg); } }
.score-stage.is-scribbled .doodle-pen { opacity: 0; }
.score-ripple { position: absolute; width: 285px; height: 225px; border: 1px solid rgba(207,222,215,.1); opacity: 0; }
.score-stage.is-scribbled .score-ripple { animation: inkRelease 1.8s ease-out; }
@keyframes inkRelease { from { opacity:.5; transform:scale(.75) rotate(-2deg); } to { opacity:0; transform:scale(1.25) rotate(3deg); } }
.score-message { grid-column: 2; margin: 28px 0 0; padding: 0; border: 0; animation: fadeUp 0.9s ease both; }
.score-message p { margin: 0 0 22px; font-family: STKaiti, KaiTi, serif; font-size: clamp(25px, 2.6vw, 36px); line-height: 1.55; }

.chapter--letters::before { background: linear-gradient(180deg, rgba(12, 31, 34, 0.45), rgba(17, 36, 38, 0.55)); }
.chapter--letters { align-items: flex-start; padding-top: 150px; padding-bottom: 180px; }
.letters-layout { width: 100%; padding-bottom: 30px; }
.letter-dock { margin-top: 78px; min-height: 440px; display: grid; grid-template-columns: 260px minmax(0, 760px); gap: 70px; align-items: center; }
.drifting-envelope { position: relative; width: 230px; height: 150px; animation: envelopeFloat 4s ease-in-out infinite alternate; filter: drop-shadow(0 18px 25px rgba(0,0,0,.25)); }
@keyframes envelopeFloat { to { transform: translateY(9px) rotate(1.5deg); } }
.drifting-envelope__paper { position: absolute; inset: 0; background: #d9ccb4; clip-path: polygon(0 10%, 50% 45%, 100% 10%, 100% 92%, 0 92%); }
.drifting-envelope__flap { position: absolute; inset: 0; background: #eee3cf; clip-path: polygon(0 8%, 100% 8%, 50% 62%); transition: transform .6s; transform-origin: top; }
.drifting-envelope.is-open .drifting-envelope__flap { transform: rotateX(150deg); }
.drifting-envelope__seal { position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; margin: -5px 0 0 -17px; display: grid; place-items: center; border-radius: 50%; background: #7e8e79; color: #eee4cf; font-family: SimSun, serif; }
.stranger-letter { min-height: 390px; padding: 52px 56px; background: rgba(237, 229, 213, 0.96); color: var(--paper-ink); box-shadow: 0 24px 65px rgba(0,0,0,.18); transform: rotate(.4deg); }
.stranger-letter__meta { margin: 0 0 30px; padding-bottom: 15px; border-bottom: 1px solid rgba(54, 72, 69, 0.14); display: flex; justify-content: space-between; gap: 20px; color: #74827d; font-size: 12px; }
.stranger-letter__meta span:last-child { color: #9b7652; text-align: right; }
.stranger-letter #strangerLetterContent { font-family: STKaiti, KaiTi, serif; font-size: clamp(18px, 1.7vw, 23px); line-height: 2; }
.stranger-letter #strangerLetterContent p { margin: 0; }
.stranger-letter #strangerLetterContent p + p { margin-top: 1.3em; }
.stranger-letter.is-changing { animation: paperChange .55s ease; }
@keyframes paperChange { 45% { opacity: 0; transform: translateY(9px) rotate(.4deg); } }
.letter-actions { display: flex; align-items: center; gap: 26px; margin: 40px 0 0 330px; }
.letter-count { color: var(--ink-faint); font-size: 12px; }
.section-next { display: block; margin: 46px 0 0; color: #e4c18b; border-color: rgba(228,193,139,.4); }
.chapter--letters .section-next { margin: 76px 0 0 330px; }

.chapter--personal::before { background: linear-gradient(180deg, rgba(8, 23, 27, 0.5), rgba(8, 23, 27, 0.58)); }
.chapter--personal { padding-top: 150px; padding-bottom: 170px; }
.personal-layout { width: min(900px, 100%); margin: 0 auto; }
.personal-heading { margin-bottom: 54px; display: flex; align-items: end; justify-content: space-between; gap: 30px; }
.personal-heading .eyebrow { margin-bottom: 10px; }
.personal-letter { padding: clamp(32px, 6vw, 72px); background: #eee5d5; color: var(--paper-ink); box-shadow: 0 30px 90px rgba(0,0,0,.3); }
.personal-letter p { margin: 0 0 1.4em; font-family: STKaiti, KaiTi, serif; font-size: clamp(18px, 2vw, 24px); line-height: 1.9; }
.personal-letter footer { margin-top: 48px; padding-top: 25px; border-top: 1px solid rgba(43,58,56,.16); display: flex; justify-content: space-between; gap: 20px; color: #71807a; font-size: 13px; }
.personal-letter footer strong { color: #405651; font-weight: 500; }

.chapter--future::before { background: linear-gradient(180deg, rgba(20, 43, 43, 0.52), rgba(25, 46, 45, 0.6)); }
.chapter--future { padding-top: 150px; padding-bottom: 170px; }
.future-layout { width: min(820px, 100%); }
.future-letter { margin-top: 62px; padding: clamp(32px, 5vw, 58px); background: rgba(239, 230, 213, 0.96); color: var(--paper-ink); box-shadow: 0 28px 70px rgba(0,0,0,.22); transition: transform .7s, opacity .7s; }
.future-letter label { display: block; margin-bottom: 18px; font-family: STKaiti, KaiTi, serif; font-size: 22px; }
.future-letter textarea { width: 100%; min-height: 190px; resize: vertical; border: 0; border-bottom: 1px solid rgba(44,59,58,.2); outline: none; background: repeating-linear-gradient(to bottom, transparent 0 38px, rgba(44,59,58,.09) 39px 40px); color: #2c3b3a; font-family: STKaiti, KaiTi, serif; font-size: 21px; line-height: 40px; }
.future-letter textarea::placeholder { color: rgba(44,59,58,.38); }
.future-letter__footer { margin-top: 18px; display: flex; justify-content: flex-end; color: rgba(44,59,58,.48); font-size: 12px; }
.future-actions { margin-top: 30px; display: flex; align-items: center; flex-wrap: wrap; gap: 20px 24px; }
.future-actions .text-link { color: #e6c38b; border-color: rgba(230,195,139,.45); }
.future-save-status { flex-basis: 100%; color: var(--ink-soft); font-size: 12px; line-height: 1.6; }
.future-letter.is-sealed { transform: scale(.82) translateY(24px); opacity: 0; pointer-events: none; position: absolute; }
.sealed-message { margin-top: 42px; min-height: 270px; padding: 50px; display: grid; place-items: center; align-content: center; background: #ddd0b9; color: #34433f; box-shadow: 0 28px 70px rgba(0,0,0,.22); text-align: center; animation: fadeUp .8s ease both; }
.sealed-message__stamp { width: 60px; height: 60px; display: grid; place-items: center; border: 2px solid rgba(93,110,102,.55); border-radius: 50%; font-family: SimSun, serif; font-size: 22px; transform: rotate(-8deg); }
.sealed-message p { margin: 22px 0 7px; font-family: STKaiti, KaiTi, serif; font-size: 28px; }
.sealed-message small { color: rgba(52,67,63,.6); }

.chapter--dawn { justify-content: center; text-align: center; }
.chapter--dawn::before { background: rgba(31, 58, 56, 0.35); }
.dawn-copy h2 { font-size: clamp(42px, 6vw, 78px); }
.dawn-copy > p:not(.eyebrow) { margin: 30px 0 18px; color: rgba(255,250,237,.78); font-family: STKaiti, KaiTi, serif; font-size: clamp(21px, 2.2vw, 29px); line-height: 1.9; }
.dawn-signature { display: block; margin-top: 42px; color: #f0ca8b; font-family: STKaiti, KaiTi, serif; font-size: 20px; }
.icon-button--restart { margin: 45px auto 0; }
body.is-dawn .world { filter: brightness(1.42) saturate(.94) sepia(.08); }
body.is-dawn .world__scene { transform: scale(1.04) translate3d(-3vw, -1vh, 0); }
body.is-dawn .world__veil { background: linear-gradient(90deg, rgba(13,30,31,.18), rgba(143,126,92,.03) 55%, rgba(235,185,111,.09)); }
body.is-dawn .rain { opacity: .05; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } }
[hidden] { display: none !important; }

@media (max-width: 860px) {
  :root { --content: calc(100vw - 36px); }
  .chapter.is-entering,
  .score-message { animation: mobileFadeIn .45s ease both; }
  .topbar { height: 64px; padding: 0 18px; }
  .brand span:last-child { display: none; }
  .chapter { min-height: auto; padding: 104px 22px 90px; }
  .chapter--opening { min-height: 100svh; padding-bottom: 86px; }
  .opening-note { display: none; }
  .lead br { display: none; }
  .score-layout { grid-template-columns: 1fr; gap: 28px; }
  .score-layout .chapter-copy { grid-row: auto; }
  .score-stage { height: 270px; }
  .score-message { grid-column: auto; }
  body.score-ready .chapter--score { padding-bottom: 170px; }
  body.score-ready #toLetters {
    position: fixed;
    z-index: 45;
    left: 18px;
    right: 18px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: auto;
    padding: 14px 16px;
    border: 0;
    border-left: 2px solid #e4c18b;
    background: rgba(8, 24, 28, 0.86);
    color: #f3eee4;
    backdrop-filter: blur(14px);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.24);
    text-align: left;
  }
  .letter-dock { grid-template-columns: 1fr; gap: 15px; }
  .drifting-envelope { width: 160px; height: 104px; margin: 0 auto; }
  .chapter--letters { padding-top: 110px; padding-bottom: 130px; }
  .letter-dock { margin-top: 52px; gap: 34px; }
  .stranger-letter { min-height: 280px; padding: 36px 28px; }
  .stranger-letter__meta { align-items: flex-start; }
  .letter-actions { margin: 34px 0 0; flex-wrap: wrap; }
  body.is-reading-letters .chapter--letters { padding-bottom: 210px; }
  body.is-reading-letters .letter-actions {
    position: fixed;
    z-index: 45;
    left: 18px;
    right: 18px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    margin: 0;
    padding: 13px 16px;
    display: flex;
    justify-content: space-between;
    flex-wrap: nowrap;
    background: rgba(8, 24, 28, 0.86);
    backdrop-filter: blur(14px);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.24);
  }
  body.is-reading-letters .letter-actions .text-button { flex: 0 1 auto; }
  body.is-reading-letters .letter-count { flex: 0 0 auto; color: rgba(243, 238, 228, 0.64); }
  .chapter--letters .section-next { margin: 58px 0 0; }
  .personal-heading { display: block; }
  .personal-letter { padding: 32px 24px; }
  .personal-letter footer { flex-direction: column; }
}

@keyframes mobileFadeIn { from { opacity: 0; } }

@media (max-width: 500px) {
  h1 { font-size: 46px; }
  h2 { font-size: 36px; }
  .chapter { padding-left: 18px; padding-right: 18px; }
  .choice-row { grid-template-columns: 42px 1fr 20px; min-height: 76px; }
  .choice-row__label { font-size: 21px; }
  .quiet-space { padding-left: 0; padding-top: 65px; }
  .score-paper { width: 215px; height: 150px; }
  .score-paper strong { font-size: 55px; }
  .doodle-canvas { width: 250px; height: 190px; }
  .text-button { width: auto; gap: 15px; }
  .future-actions { align-items: stretch; flex-direction: column; }
  .future-letter { padding: 28px 20px; }
  .sealed-message { padding: 35px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
