/* The closing inscription extends the existing locally bundled Ma Shan Zheng (OFL). */
@font-face {
  font-family: BrushFinal; font-style: normal; font-weight: 400; font-display: swap;
  src: url("assets/fonts/closing-brush.woff2") format("woff2");
  unicode-range: U+3002,U+5B64,U+6696,U+77E3,U+FF0C;
}
@font-face {
  font-family: EpilogueBrush; font-style: normal; font-weight: 400; font-display: swap;
  src: url("assets/fonts/epilogue-brush.woff2") format("woff2");
}
:root {
  color-scheme: dark;
  --paper: #edddc7;
  --ivory: #f6efdf;
  --dim: #c8c2b3;
  --gold: #d0b27b;
  --song: "Songti SC", "STSong", "Noto Serif CJK SC", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft Yahei", sans-serif;
  --edge: clamp(18px, 3.8vw, 72px);
}
* { box-sizing: border-box }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #171b1a }
body { font-family: var(--sans); color: var(--ivory); -webkit-font-smoothing: antialiased }
button, input { font: inherit }
button { padding: 0; border: 0; background: transparent; color: inherit; cursor: pointer }
button:disabled { cursor: wait; opacity: .65 }
button:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px }
[hidden], .symbols { display: none !important }
svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; flex: none }

.theater { position: fixed; inset: 0; width: 100%; height: 100vh; height: 100dvh; overflow: hidden; isolation: isolate; background: #171b1a; outline: 0 }
#film, #titles, #cover { position: absolute; inset: 0; width: 100%; height: 100% }
#film, #titles { display: block }
#titles { pointer-events: none }
#cover {
  --cover-x: 0; --cover-y: 0;
  color: #272a25; background: var(--paper); isolation: isolate; overflow: hidden;
}
#cover-stage {
  position: absolute; inset: 0; display: flex; align-items: center;
  padding: 0 max(6.6vw, env(safe-area-inset-left));
  perspective: 1400px; isolation: isolate;
}
.cover-plate {
  position: absolute; inset: -32px; width: calc(100% + 64px); height: calc(100% + 64px);
  object-fit: cover; object-position: 56% 48%; pointer-events: none; user-select: none;
  backface-visibility: hidden;
}
.cover-depth-back { z-index: 0; transform: translate3d(calc(var(--cover-x) * -8px), calc(var(--cover-y) * -8px), 0) }
#cover-stage::before {
  content: ""; position: absolute; z-index: 1; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, rgb(244 230 202 / .66), rgb(243 229 202 / .24) 30%, transparent 54%);
}
.cover-mid {
  position: absolute; z-index: 1; inset: -20px; pointer-events: none;
  transform: translate3d(calc(var(--cover-x) * 14px), calc(var(--cover-y) * 14px), 0);
}
.cover-mist {
  position: absolute; inset: 42% -6% -12%; opacity: .28;
  background: radial-gradient(ellipse at 50% 62%, #f6e8d5a8, #ede2d766 28%, transparent 68%);
  animation: cover-mist-drift 13s ease-in-out infinite alternate;
}
.cover-gold { position: absolute; inset: 0; width: 100%; height: 100%; transform-origin: 25% 0; animation: cover-silk-drift 10s ease-in-out infinite alternate }
.cover-depth-front {
  z-index: 3; transform-origin: 65% 45%;
  transform: translate3d(calc(var(--cover-x) * 26px), calc(var(--cover-y) * 26px), 0) rotateX(calc(var(--cover-y) * -.28deg)) rotateY(calc(var(--cover-x) * .35deg));
}
.cover-copy {
  position: relative; z-index: 2; align-self: flex-start; width: min(37vw, 620px); margin: 5vh 0 0;
  transform: translate3d(calc(var(--cover-x) * 14px), calc(var(--cover-y) * 14px), 0) rotateY(calc(var(--cover-x) * .18deg));
}
#film-title { position: relative; margin: 0 0 0 -.055em; width: 100%; font-size: inherit }
.cover-calligraphy { display: block; width: 100%; height: auto; overflow: visible; filter: drop-shadow(0 3px 3px #5a452d1c) }
.cover-seal {
  position: absolute; right: -3%; top: 27%; display: grid; grid-template-columns: 1fr 1fr; place-items: center;
  width: clamp(26px, 2.7vw, 45px); height: clamp(29px, 3vw, 49px); padding: 3px;
  transform: rotate(3deg); color: #f8e3c6; background: #a04432;
  border: 1px solid #873322; outline: 1px solid #c6896e99; outline-offset: -4px;
  box-shadow: 0 1px 3px #602b2029; font: 400 clamp(14px, 1.45vw, 24px)/1 BrushTitle, "Kaiti SC", var(--song);
}
.cover-seal span:first-child { transform: translateY(-3px) }
.cover-seal span:last-child { transform: translateY(4px) }
.cover-poem { display: flex; align-items: center; gap: .75em; margin: 0 0 0 4%; color: #705e47; font: 400 clamp(12px, 1.06vw, 18px)/1.7 var(--song); letter-spacing: .28em }
.cover-poem::before { content: ""; width: 32px; border-top: 1px solid #9b805a80 }
.cover-poem span { color: #a04432 }
.artists { margin: 17px 0 0 4%; color: #51483c; font: 400 clamp(15px, 1.28vw, 22px)/1.5 var(--song); letter-spacing: .16em }
.artists span { padding: 0 .45em; color: #967b58; font-size: .8em }
.start {
  display: inline-flex; align-items: center; gap: 12px;
  min-height: 46px; margin: clamp(22px, 3.8vh, 40px) 0 0 4%; padding: 0 24px 0 21px;
  background: #883d30; color: #fff5dc; border: 1px solid #733628; border-radius: 2px;
  font: 500 14px var(--song); letter-spacing: .18em; transition: background .22s, box-shadow .22s;
}
.start:hover { background: #723326; box-shadow: 0 3px 14px #64342924 }
.start svg { width: 14px; height: 14px }
.start:focus-visible { outline-color: #512c22 }
@keyframes cover-mist-drift { from { transform: translate3d(-8px, 0, 0); opacity: .21 } to { transform: translate3d(10px, -5px, 0); opacity: .30 } }
@keyframes cover-silk-drift { from { transform: rotate(-.18deg) } to { transform: rotate(.22deg) } }
@media (prefers-reduced-motion: reduce), (hover: none), (pointer: coarse) {
  .cover-depth-back, .cover-depth-front, .cover-mid, .cover-copy { transform: none }
  .cover-mist, .cover-gold { animation: none }
}

.tools {
  position: absolute; z-index: 3; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(env(safe-area-inset-top) + clamp(11px, 2.6vh, 30px)) max(var(--edge), env(safe-area-inset-right)) 16px max(var(--edge), env(safe-area-inset-left));
  pointer-events: none; transition: opacity .38s;
}
.title-mark, .side-actions, .side-actions button { display: flex; align-items: center }
.title-mark { pointer-events: auto; text-decoration: none; gap: 10px; color: #fff6e5; white-space: nowrap; line-height: 1; text-shadow: 0 1px 6px #0f100feb, 0 0 2px #0b0c0b }
.title-mark .seal { width: 29px; height: 29px; stroke: none; color: #9a4130 }
.title-mark b { font: 600 18px var(--song); letter-spacing: .07em }
#chapter-name { font-size: 11px; letter-spacing: .1em }
#chapter-name::before { content: ""; display: inline-block; vertical-align: middle; height: .9em; margin: 0 10px 0 0; border-left: 1px solid #d4c7af }
.theater:not(.started) .title-mark b, .theater:not(.started) #chapter-name { display: none }
.theater.started .tools { background: linear-gradient(to bottom, #10151452, transparent) }
.side-actions { display: none !important }
#controls { display: none !important }
.theater.quiet { cursor: none }
#epilogue {
  --epilogue-brush: EpilogueBrush, "Xingkai SC", "STXingkai", "Kaiti SC", "STKaiti", BrushTitle, serif;
  position: absolute; inset: 0; z-index: 2; isolation: isolate; overflow: hidden;
  background: #edddc7; color: #1f1b16; color-scheme: light;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .9s ease-in-out, visibility 0s linear .9s;
}
.epilogue-painting {
  position: absolute; inset: 0; width: 130%; height: 130%;
  object-fit: cover; object-position: left top; pointer-events: none; user-select: none;
}
.theater.ended { cursor: auto }
.theater.ended #epilogue { visibility: visible; opacity: 1; pointer-events: auto; transition-delay: 0s }
.theater.ended #titles, .theater.ended #controls { visibility: hidden; opacity: 0; pointer-events: none }
.theater.ended .tools { opacity: 1; background: none }
.theater.ended .title-mark { color: #45382a; text-shadow: none }
.theater.ended #chapter-name::before { border-color: #8b7459 }
.epilogue-reader {
  position: relative; width: 100%; height: 100%; overflow: auto;
  display: flex; align-items: center; justify-content: flex-start;
  padding: max(68px, 8vh) max(28px, 4.5vw) max(64px, 8vh);
  padding-top: max(68px, 8vh, env(safe-area-inset-top));
  scroll-behavior: smooth; overscroll-behavior: contain;
}
.epilogue-reader:focus-visible { outline: 1px solid #9a7757; outline-offset: -5px }
.epilogue-sheet {
  writing-mode: vertical-rl; text-orientation: upright;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  flex: none; height: min(76vh, 660px); margin: 0 auto 0 0;
}
.epilogue-heading {
  display: flex; flex-direction: row; align-items: flex-start; gap: 22px;
  padding-left: clamp(18px, 2.2vw, 32px);
  margin-left: clamp(18px, 2.2vw, 32px);
  border-left: 1px solid #9c78434d; height: 100%;
}
.epilogue-inscription { display: flex; flex-direction: row; align-items: center; gap: 20px }
.epilogue-seal {
  order: 2; width: 32px; height: 34px; color: #a33f2d; stroke: none;
  transform: rotate(-3deg);
}
#epilogue-title {
  order: 1; margin: 0; color: #1f1b16;
  font: 400 clamp(48px, 7.2vh, 72px)/1.15 BrushTitle, var(--epilogue-brush);
  letter-spacing: .2em;
}
.epilogue-heading p {
  margin: 0; padding-top: .4em; color: #66503a;
  font: 400 clamp(15px, 1.9vh, 19px)/1.6 var(--epilogue-brush); letter-spacing: .12em;
  text-orientation: mixed;
}
#epilogue-story {
  height: 100%; margin: 0; text-align: start; color: #1f1b16;
  font: 400 clamp(19px, 2.45vh, 25px)/1.9 var(--epilogue-brush);
  letter-spacing: .12em; line-break: strict;
}
#epilogue-story p { margin: 0; text-indent: 2em }
#epilogue-story p + p { margin-right: .25em }
#epilogue-story p:last-child { padding-top: 1.2em }
#epilogue-story p:last-child span {
  display: block; margin-right: .3em; padding-top: .5em;
  color: #1f1b16; font-family: BrushFinal, BrushTitle, var(--epilogue-brush);
  font-size: 1.65em; letter-spacing: .16em; line-height: 1.2; text-indent: 0;
}
#epilogue-replay {
  writing-mode: horizontal-tb; position: absolute;
  left: max(28px, 4.5vw, env(safe-area-inset-left));
  bottom: max(18px, 3vh, env(safe-area-inset-bottom));
  display: grid; place-items: center; width: 48px; height: 48px; padding: 4px;
  font: 400 17px/1.05 var(--epilogue-brush); letter-spacing: .08em;
  border: 1px solid #873322; outline: 1px solid #e7b38f; outline-offset: -4px; border-radius: 1px;
  background: #a33f2d; color: #fff0d8; transform: rotate(-2deg);
  transition: background .2s;
}
#epilogue-replay span { display: block; white-space: nowrap }
#epilogue-replay:hover { background: #843224 }
#epilogue-replay:focus-visible { outline: 2px solid #713a28; outline-offset: 4px }
@media (max-width: 760px), (max-aspect-ratio: 1/1), (max-height: 520px) {
  .epilogue-reader { align-items: flex-start; padding: max(76px, env(safe-area-inset-top)) 7vw 94px }
  .epilogue-painting { object-position: left top; width: 170%; height: 130% }
  .epilogue-sheet { writing-mode: horizontal-tb; text-orientation: mixed; height: auto; width: 100%; max-width: 740px; margin: 0 auto; align-items: flex-start }
  .epilogue-heading { flex-direction: column; align-items: flex-start; gap: 10px; padding: 0 0 18px; margin: 0 0 22px; border-left: 0; border-bottom: 1px solid #9c78434d; height: auto }
  .epilogue-inscription { flex-direction: row; gap: 12px }
  #epilogue-title { letter-spacing: .1em }
  .epilogue-heading p { padding-top: 0 }
  #epilogue-story { height: auto; font-size: clamp(19px, 2.45vh, 25px); line-height: 1.9 }
  #epilogue-story p + p { margin-right: 0; margin-top: .75em }
  #epilogue-story p:last-child { padding-top: .4em }
  #epilogue-story p:last-child span { margin: .2em 0 0; padding-top: .2em; font-size: 1.65em }
}
.error { position: absolute; z-index: 5; bottom: 15%; left: 50%; transform: translateX(-50%); font: 14px/1.6 var(--sans); width: max-content; max-width: min(88%, 520px); margin: 0; padding: 9px 15px; border: 1px solid #9a7f55; background: #262923ed; border-radius: 3px }

dialog { color: var(--ivory); background: #282b26; border: 1px solid #84775d; border-radius: 5px; width: min(88vw, 560px); max-height: 84vh; max-height: 84dvh; overflow: auto; padding: 0; box-shadow: 0 18px 90px #08090677 }
dialog::backdrop { background: #080b09a8; backdrop-filter: blur(3px) }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 23px; border-bottom: 1px solid #d8caa52c }
.dialog-close { display: grid; place-items: center; width: 34px; height: 34px }
.dialog-close svg { width: 17px; height: 17px }
dialog article { padding: 10px 25px 23px }
h2 { margin: 0; font: 600 21px/1.5 var(--song); letter-spacing: .08em }
dialog article p { font: 15px/1.95 var(--song); color: #e6e1d2 }
.byline { font: 12px var(--sans); color: var(--dim) }
.chapter-row { display: flex; gap: 14px; align-items: center; padding: 13px 3px; width: 100%; border-bottom: 1px solid #d8caa522; text-align: left }
.chapter-row small { font: 12px var(--song); color: #bcad90 }
.chapter-row strong { font: 600 17px var(--song); letter-spacing: .06em }
.chapter-row time { margin-left: auto; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: #bfb9a9 }
.chapter-row[aria-current=true] strong, .chapter-row:hover strong { color: #ebcc92 }
.track-current, .track-actions, #track-form, .url-row { display: flex; gap: 10px }
.track-current { flex-direction: column; font: 13px var(--sans) }
.track-actions { margin-bottom: 20px; flex-wrap: wrap }
.outline-button { padding: 7px 12px; border: 1px solid #b3a57a70; border-radius: 3px; font: 13px var(--sans); cursor: pointer }
#track-form { flex-direction: column; font-size: 13px }
.url-row input { min-width: 28px; flex: 1; background: #33372d; color: var(--ivory); border: 1px solid #b3a57a70; padding: 8px }
.url-row button { flex: none }
#track-status { font: 13px/1.65 var(--sans); color: var(--gold) }

/* Use the same crop for both painted planes at each aspect ratio. */
@media (min-aspect-ratio: 1/1) and (max-aspect-ratio: 8/5) {
  .cover-plate { left: calc(12% - 32px); width: calc(88% + 64px); object-position: 61% 47%; -webkit-mask-image: linear-gradient(90deg, transparent, #000 29%); mask-image: linear-gradient(90deg, transparent, #000 29%) }
  .cover-copy { width: 37vw }
}
@media (max-aspect-ratio: 1/1) {
  #cover { background: linear-gradient(115deg, #f0dfc6, #e6cfaf) }
  #cover-stage { align-items: flex-end; padding: 0 7vw max(6.5vh, env(safe-area-inset-bottom)) }
  .cover-plate { inset: 0; width: 100%; height: 72%; object-position: 67% 45%; -webkit-mask-image: linear-gradient(#000 60%, transparent 100%); mask-image: linear-gradient(#000 60%, transparent 100%) }
  #cover-stage::before { display: none }
  .cover-mid { inset: 0; opacity: .45 }
  .cover-copy { align-self: auto; width: min(83vw, 600px); margin: 0; z-index: 4 }
  .cover-depth-back, .cover-depth-front, .cover-mid, .cover-copy { transform: none }
  .cover-mist, .cover-gold { animation: none }
  .cover-poem { margin-top: -4px; font-size: clamp(11px, 2.8vw, 15px) }
  .cover-poem::before { width: 24px }
  .cover-seal { right: -1%; top: 25%; width: 30px; height: 34px; font-size: 17px }
  .artists { margin-top: 9px; font-size: clamp(14px, 3.7vw, 19px) }
  .start { margin-top: 19px }
}
@media (max-width: 620px) {
  :root { --edge: 15px }
  .title-mark { gap: 6px }
  .title-mark b { font-size: 15px }
  .title-mark .seal { width: 25px; height: 25px }
  #chapter-name { font-size: 10px; letter-spacing: 0 }
  #chapter-name::before { margin-right: 6px }
  .side-actions button { gap: 4px; min-height: 36px; padding: 0 9px; font-size: 12px }
  .side-actions svg { width: 14px; height: 14px }
  #controls { padding-top: 18px }
  .transport { gap: 1px }
  .time { gap: 5px; font-size: 11px }
  dialog article { padding: 8px 19px 16px }
  .dialog-head { padding: 10px 17px }
}
@media (max-height: 500px) and (orientation: landscape) {
  .cover-copy { width: min(40vw, 78vh) }
  .cover-poem { font-size: 11px }
  .artists { font-size: 13px; margin-top: 5px }
  .cover-copy { margin-top: 7vh }
  .start { min-height: 36px; margin-top: 14px }
  .tools { padding-top: max(6px, env(safe-area-inset-top)) }
  #controls { padding-top: 7px; padding-bottom: max(3px, env(safe-area-inset-bottom)) }
}
@media (pointer: coarse) {
  .side-actions button, .icon-button { min-height: 44px; min-width: 44px }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important } }
