@font-face {
  font-family: 'WenKai';
  src: url('/fonts/wenkai.woff2') format('woff2');
  font-display: swap;
}

:root {
  --paper: #e9e2d2;
  --paper-hi: #f4efe4;
  --ink: #1e1a16;
  --ink-2: #4a433b;
  --ink-3: #7d746a;
  --red: #a8291f;
  --red-hi: #c0392b;
  --kai: 'WenKai', 'Kaiti SC', 'STKaiti', 'KaiTi', '楷体', serif;
  --sb: env(safe-area-inset-bottom, 0px);
  --st: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--kai);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.safe-probe { position: fixed; top: 0; left: 0; width: 0; height: var(--st); visibility: hidden; pointer-events: none; }

/* ---------- the poem page ---------- */

.poem-page { overflow: hidden; overscroll-behavior: none; touch-action: none; }
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.home {
  position: fixed; z-index: 5;
  top: calc(14px + var(--st)); left: 14px;
  display: grid; grid-template-columns: 1fr; place-items: center;
  width: 34px; padding: 5px 0; gap: 0;
  background: var(--red); color: var(--paper-hi);
  font-size: 15px; line-height: 1.15; text-decoration: none;
  border-radius: 3px; box-shadow: 0 0 0 1px rgba(168, 41, 31, .25);
  opacity: .9; transition: opacity .6s;
}
.home:hover, .home:focus-visible { opacity: 1; }

.sub {
  position: fixed; z-index: 3; left: 50%;
  bottom: calc(118px + var(--sb));
  transform: translateX(-50%);
  width: max-content; max-width: min(92vw, 34em);
  margin: 0; padding: .55em 2.2em;
  font-size: clamp(15px, 2.1vw, 21px); letter-spacing: .14em; line-height: 1.6; text-align: center;
  color: rgba(30, 26, 22, .88);
  background: radial-gradient(closest-side, rgba(243, 238, 228, .82), rgba(243, 238, 228, .55) 60%, rgba(243, 238, 228, 0));
  opacity: 0; pointer-events: none;
  transition: opacity .9s ease, bottom .6s ease;
}
.sub.on { opacity: 1; }
.hud-off .sub { bottom: calc(34px + var(--sb)); }

.hud {
  position: fixed; z-index: 4; left: 50%; bottom: calc(14px + var(--sb));
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: opacity .7s ease, transform .7s ease;
}
.hud-off .hud, .hud-off .home { opacity: 0; pointer-events: none; }
.hud-off .hud { transform: translate(-50%, 10px); }
body:not(.unrolled) .hud, body:not(.unrolled) .home, body:not(.unrolled) .sub { opacity: 0; pointer-events: none; }

.dots { display: flex; gap: 2px; align-items: center; }
.dot {
  width: 26px; height: 22px; padding: 0; border: 0; background: none; position: relative;
}
.dot::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px;
  border-radius: 50%; background: rgba(30, 26, 22, .28); transition: background .4s, transform .4s;
}
.dot.minor::after { width: 4px; height: 4px; margin: -2px 0 0 -2px; }
.dot.cur::after { background: var(--red); transform: scale(1.35); }

.bar {
  display: flex; align-items: center; gap: 2px;
  padding: 4px 6px;
  background: rgba(240, 234, 222, .72);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid rgba(30, 26, 22, .1);
  border-radius: 999px;
  box-shadow: 0 6px 24px -12px rgba(30, 26, 22, .35);
}
.bar button {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 42px; padding: 0 12px; border: 0; background: none; border-radius: 999px; white-space: nowrap;
  font-size: 15px; letter-spacing: .08em; color: var(--ink-2);
  transition: background .25s, color .25s;
}
.bar button:hover { background: rgba(30, 26, 22, .07); color: var(--ink); }
.bar button:focus-visible, .opts button:focus-visible, .end button:focus-visible, .home:focus-visible, .dot:focus-visible, .sheet .close:focus-visible, .seal-btn:focus-visible {
  outline: 2px solid var(--red); outline-offset: 2px;
}
.bar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#play { color: var(--ink); }
#play svg { width: 22px; height: 22px; }
#play .i-play { fill: currentColor; stroke-width: 1.2; }
#play[data-state='playing'] .i-play, #play[data-state='paused'] .i-pause { display: none; }
#play .lbl { display: none; }
.bar .txt { color: var(--ink-2); }
@media (max-width: 520px) {
  .bar .lbl { display: none; }
  .bar button { padding: 0 11px; }
}

.opts {
  position: fixed; z-index: 6; left: 50%; bottom: calc(112px + var(--sb));
  transform: translateX(-50%);
  width: min(92vw, 360px);
  padding: 14px 16px 16px;
  background: rgba(244, 239, 228, .94);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid rgba(30, 26, 22, .12); border-radius: 14px;
  box-shadow: 0 16px 40px -18px rgba(30, 26, 22, .45);
  display: grid; gap: 10px;
}
.opts .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; }
.opts .row.stack { flex-direction: column; align-items: stretch; }
.opts .k { font-size: 15px; color: var(--ink-2); letter-spacing: .06em; }
.seg { display: inline-flex; background: rgba(30, 26, 22, .07); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 999px; font-size: 14px; color: var(--ink-3); }
.seg button[aria-pressed='true'] { background: var(--paper-hi); color: var(--ink); box-shadow: 0 1px 3px rgba(30, 26, 22, .15); }
.sw { width: 46px; height: 28px; border-radius: 999px; border: 0; background: rgba(30, 26, 22, .16); position: relative; transition: background .25s; }
.sw::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--paper-hi); box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .25s; }
.sw[aria-pressed='true'] { background: var(--red); }
.sw[aria-pressed='true']::after { transform: translateX(18px); }
.voices { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 6px; }
.voices button {
  display: grid; gap: 1px; padding: 8px 6px; text-align: center;
  border: 1px solid rgba(30, 26, 22, .14); border-radius: 10px; background: none;
}
.voices b { font-weight: normal; font-size: 16px; }
.voices small { font-size: 12px; color: var(--ink-3); }
.voices button[aria-pressed='true'] { border-color: var(--red); background: rgba(168, 41, 31, .07); }
.voices button[aria-pressed='true'] b { color: var(--red); }

.end {
  position: fixed; z-index: 4; left: 50%; bottom: calc(120px + var(--sb)); transform: translateX(-50%);
  display: flex; gap: 10px;
  animation: rise 1.2s ease both;
}
.end button {
  padding: 10px 22px; border-radius: 999px; font-size: 16px; letter-spacing: .12em;
  border: 1px solid rgba(30, 26, 22, .25); background: rgba(244, 239, 228, .85);
}
.end #replay { background: var(--ink); color: var(--paper-hi); border-color: var(--ink); }
.end:not([hidden]) ~ .sub { opacity: 0 !important; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- notes & appreciation ---------- */

.sheet {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(30, 26, 22, .28);
  display: flex; justify-content: flex-end;
  animation: fade .35s ease both;
}
.sheet .leaf {
  position: relative;
  width: min(100%, 460px); height: 100%;
  overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  background: var(--paper-hi);
  box-shadow: -18px 0 40px -24px rgba(30, 26, 22, .5);
  padding: calc(28px + var(--st)) 28px calc(40px + var(--sb));
  animation: slide .45s cubic-bezier(.2, .7, .2, 1) both;
}
@media (max-width: 640px) {
  .sheet { align-items: flex-end; }
  .sheet .leaf { width: 100%; height: 86%; border-radius: 18px 18px 0 0; padding: 26px 22px calc(36px + var(--sb)); animation-name: slideup; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
.sheet .close {
  position: sticky; top: 0; float: right; margin: -8px -8px 0 0;
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(30, 26, 22, .06);
  font-size: 24px; line-height: 1; color: var(--ink-2);
}
.sheet header h2 { margin: 0; font-size: 34px; font-weight: normal; letter-spacing: .3em; }
.sheet .by { margin: 6px 0 22px; color: var(--ink-3); letter-spacing: .2em; }
.sheet .orig { padding: 14px 0 6px; border-top: 1px solid rgba(30, 26, 22, .12); border-bottom: 1px solid rgba(30, 26, 22, .12); }
.ruby-line { margin: 0 0 6px; font-size: 26px; letter-spacing: .32em; }
.ruby-line rt { font-size: 11px; letter-spacing: 0; color: var(--ink-3); font-family: -apple-system, system-ui, sans-serif; }
.sheet section { margin: 0 0 22px; }
.sheet h3 { margin: 22px 0 8px; font-size: 15px; font-weight: normal; color: var(--red); letter-spacing: .3em; }
.sheet h4 { margin: 14px 0 4px; font-size: 17px; font-weight: normal; }
.sheet p { margin: 0 0 8px; font-size: 16px; line-height: 1.9; color: var(--ink-2); }
.sheet dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.sheet dt { font-size: 16px; color: var(--ink); }
.sheet dd { margin: 0; font-size: 15px; line-height: 1.8; color: var(--ink-2); }

/* ---------- the closed scroll ---------- */

.cover { position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; }
.cover .half {
  position: absolute; top: 0; bottom: 0; width: 50.5%;
  background: radial-gradient(120% 90% at 50% 40%, rgba(244, 239, 228, .86), rgba(233, 226, 210, .9));
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  transition: transform 1.5s cubic-bezier(.65, .05, .25, 1);
}
.cover .half.a { left: 0; }
.cover .half.b { right: 0; }
.cover .rod {
  position: absolute; top: -2%; bottom: -2%; width: 14px;
  background: linear-gradient(90deg, #3a2a1f, #6b4d36 40%, #2c2018);
  border-radius: 7px; box-shadow: 0 0 16px rgba(0, 0, 0, .25);
  opacity: 0; transition: opacity .4s;
}
.cover .half.a .rod { right: -7px; }
.cover .half.b .rod { left: -7px; }
.unrolled .cover .rod { opacity: 1; }
.unrolled .cover .half.a { transform: translateX(-102%); }
.unrolled .cover .half.b { transform: translateX(102%); }
@media (orientation: portrait) {
  .cover .half { width: auto; left: 0; right: 0; height: 50.5%; }
  .cover .half.a { top: 0; bottom: auto; }
  .cover .half.b { top: auto; bottom: 0; }
  .cover .rod { top: auto; bottom: auto; left: -2%; right: -2%; width: auto; height: 14px; background: linear-gradient(180deg, #3a2a1f, #6b4d36 40%, #2c2018); }
  .cover .half.a .rod { right: -2%; bottom: -7px; }
  .cover .half.b .rod { left: -2%; top: -7px; }
  .unrolled .cover .half.a { transform: translateY(-102%); }
  .unrolled .cover .half.b { transform: translateY(102%); }
}

.cover-inner {
  position: relative; display: flex; flex-direction: row-reverse; align-items: flex-start; gap: clamp(18px, 4vw, 40px);
  transition: opacity .5s ease;
}
.unrolled .cover-inner { opacity: 0; }
.vtitle {
  margin: 0; writing-mode: vertical-rl; font-weight: normal;
  font-size: clamp(64px, 13vmin, 120px); letter-spacing: .25em; line-height: 1; color: var(--ink);
}
.vby { margin: 0; writing-mode: vertical-rl; font-size: clamp(16px, 2.6vmin, 22px); letter-spacing: .4em; color: var(--ink-2); padding-top: .4em; }
.go { align-self: flex-end; display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 2em; }
.seal-btn {
  display: none; width: 76px; height: 76px; padding: 0;
  grid-template-columns: 1fr 1fr; place-items: center; direction: rtl;
  border: 0; border-radius: 4px; background: var(--red); color: var(--paper-hi);
  font-size: 28px; line-height: 1;
  box-shadow: 0 6px 20px -8px rgba(168, 41, 31, .7);
  transition: transform .2s, background .2s;
}
.seal-btn:hover { background: var(--red-hi); }
.seal-btn:active { transform: scale(.96); }
.ready .seal-btn { display: grid; animation: fade .8s ease both; }
.hint { margin: 0; writing-mode: vertical-rl; font-size: 13px; letter-spacing: .25em; color: var(--ink-3); }
.loading { margin: 0; writing-mode: vertical-rl; font-size: 14px; letter-spacing: .3em; color: var(--ink-3); position: relative; }
.loading::after {
  content: ''; position: absolute; right: -8px; top: 0; width: 2px; height: calc(var(--p, 0) * 100%);
  background: var(--ink-2); transition: height .3s;
}
.ready .loading { display: none; }
.failed .loading span { font-size: 0; }
.failed .loading span::after { content: '加载失败，请刷新重试'; font-size: 14px; color: var(--red); }
.noscript { position: fixed; inset: auto 0 20px; text-align: center; z-index: 9; }

@media (prefers-reduced-motion: reduce) {
  .cover .half { transition-duration: .01s; }
}

/* ---------- home ---------- */

.home-page {
  min-height: 100%;
  background: var(--paper) radial-gradient(90% 60% at 70% 0%, rgba(120, 110, 96, .18), rgba(120, 110, 96, 0)) no-repeat;
  background-size: 100% 100vh;
  padding: calc(48px + var(--st)) 20px calc(48px + var(--sb));
}
.home-page main { max-width: 880px; margin: 0 auto; }
.masthead { display: flex; align-items: flex-start; gap: 18px; flex-direction: row-reverse; justify-content: flex-end; }
.masthead h1 { margin: 0; writing-mode: vertical-rl; font-weight: normal; font-size: clamp(56px, 10vw, 88px); letter-spacing: .2em; line-height: 1; }
.masthead p { margin: 0; writing-mode: vertical-rl; color: var(--ink-2); letter-spacing: .4em; font-size: 16px; padding-top: .3em; }
.masthead .stamp { width: 30px; padding: 4px 0; display: grid; place-items: center; background: var(--red); color: var(--paper-hi); font-size: 13px; line-height: 1.2; border-radius: 3px; align-self: flex-end; }
.shelf { list-style: none; padding: 0; margin: 48px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 22px; }
.card a {
  display: block; text-decoration: none; color: inherit;
  background: var(--paper-hi); border: 1px solid rgba(30, 26, 22, .12); border-radius: 6px; overflow: hidden;
  box-shadow: 0 10px 30px -22px rgba(30, 26, 22, .6);
  transition: transform .3s, box-shadow .3s;
}
.card a:hover { transform: translateY(-3px); box-shadow: 0 16px 34px -22px rgba(30, 26, 22, .7); }
.card a:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }
.card img { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; background: #ddd5c4; }
.card .meta { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 16px 14px; }
.card h2 { margin: 0; font-size: 24px; font-weight: normal; letter-spacing: .2em; }
.card .by { color: var(--ink-3); font-size: 14px; letter-spacing: .15em; }
.card .line { margin: 0; padding: 0 16px 16px; color: var(--ink-2); font-size: 15px; letter-spacing: .12em; }
.card.soon { border: 1px dashed rgba(30, 26, 22, .22); border-radius: 6px; display: grid; place-items: center; min-height: 200px; color: var(--ink-3); letter-spacing: .3em; font-size: 15px; }
.foot { margin-top: 56px; color: var(--ink-3); font-size: 13px; line-height: 1.9; letter-spacing: .05em; }
.foot a { color: inherit; }
