@font-face {
  font-family: "Book Kuaile";
  src: url("assets/kuaile.woff2") format("woff2");
  font-display: swap;
}

:root {
  color-scheme: light;
  --background: #f8f6f0;
  --ink: #312e2b;
  --quiet: #6b6562;
  --line: #ded7cd;
  --accent: #81503e;
  --accent-hover: #6a4032;
  --tint: #f4e7dc;
  --display: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-width: 300px;
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  background: var(--background);
  font: 15px/1.55 var(--body);
}
body[data-edition="god"] {
  --background: #f6f3f7;
  --ink: #302935;
  --accent: #57466f;
  --accent-hover: #47365e;
  --tint: #eee8f1;
  --line: #ddd5df;
}

button, input, textarea, a { font: inherit; }
button, a { touch-action: manipulation; }
button { cursor: pointer; color: inherit; }
[tabindex="-1"]:focus { outline: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.frame { width: min(calc(100% - 100px), 1180px); margin-inline: auto; }
.stage { min-height: max(0px, calc(100svh - 83px)); display: grid; align-items: center; }
.spark { display: inline-block; width: 14px; aspect-ratio: 1; flex: none; background: currentColor; clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); }

.masthead { height: 68px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.masthead-actions { display: flex; align-items: center; gap: 12px; }
.remaining-turns { color: var(--accent); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.voucher-panel { padding-block: 9px 5px; text-align: center; }
.voucher-panel p { margin: 0; color: var(--quiet); }
.voucher-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.voucher-actions:not(:has(a:not([hidden]))) { display: none; }
.voucher-actions a { color: var(--accent); }
.text-button, .quiet-button, .primary { display: inline-flex; justify-content: center; align-items: center; gap: 9px; min-height: 44px; text-decoration: none; }
.text-button, .quiet-button { border: 0; border-radius: 100px; background: transparent; }
.quiet-button { padding: 0 15px; border: 1px solid #bdac9e9e; background: #fffaf271; }
.quiet-button:hover, .text-button:hover { color: var(--accent); }
.quiet-button:active, .primary:active { transform: translateY(1px); }
.brand { padding: 0 4px 0 0; gap: 10px; font: 650 17px/1 var(--display); letter-spacing: .035em; }
.brand-mark {
  display: grid;
  place-items: center;
  color: #fff6e9;
  width: 26px;
  height: 30px;
  border-radius: 5px 10px 9px 4px;
  background: #7a629f;
  box-shadow: 2px 2px #584572, inset 4px 0 #ffffff25;
  transform: rotate(-8deg);
}
.brand-mark .spark { width: 13px; }
.bookmark-count { min-width: 20px; display: inline-grid; place-items: center; padding: 0 4px; border-radius: 30px; background: var(--tint); color: var(--accent); font-size: 11px; }
.icon { position: relative; display: inline-block; width: 16px; height: 17px; flex: none; color: currentColor; }
.icon-bookmark { background: currentColor; clip-path: polygon(13% 0, 87% 0, 87% 100%, 50% 75%, 13% 100%, 13% 0, 22% 9%, 22% 82%, 50% 63%, 78% 82%, 78% 9%, 22% 9%); }
[aria-pressed="true"] .icon-bookmark { clip-path: polygon(13% 0, 87% 0, 87% 100%, 50% 75%, 13% 100%); }
.icon-share { font: 16px/.78 var(--body); text-align: center; }
.icon-share::after { content: ""; position: absolute; inset: 6px 2px 0; border: 1px solid currentColor; border-top: 0; border-radius: 0 0 3px 3px; }

body[data-scene="desk"] { background: radial-gradient(ellipse at 36% 38%, #faf3e5 2%, #f3eee4 68%); }
.home-scene {
  position: relative;
  width: min(100%, 930px);
  margin: 0 auto;
  padding: clamp(20px, 6vh, 65px) 0 clamp(34px, 9vh, 90px);
  isolation: isolate;
  overflow: clip;
}
.desk-books {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  padding: 0 clamp(0px, 2.9vw, 33px);
}
.desk-book {
  --angle: -7deg;
  --offset: -16px;
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 22%;
  background: none;
  transform: translateY(var(--offset)) rotate(var(--angle));
  transition: transform .31s var(--ease);
}
.desk-book[data-open-book="god"] { --angle: 9deg; --offset: 20px; }
.desk-book img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(10px 18px 12px #47352840);
  pointer-events: none;
}
.cover-name {
  position: absolute;
  top: 29%;
  left: 23%;
  width: 55%;
  color: #654d34;
  text-align: center;
  white-space: nowrap;
  font: 530 clamp(15px, 2.2vw, 31px)/1.1 "Songti SC", "STSong", "Noto Serif SC", serif;
  letter-spacing: .11em;
  text-shadow: 0 1px 0 #f6ddb77a;
  transform: rotate(-4deg);
}
.cover-name[lang="en"] { color: #fae2af; font-family: Georgia, serif; font-size: clamp(14px, 2vw, 29px); letter-spacing: -.025em; text-shadow: 0 1px 2px #372146b8; }
.desk-book:active { transform: translateY(calc(var(--offset) - 2px)) rotate(var(--angle)) scale(.982); }
@media (hover: hover) and (pointer: fine) {
  .desk-book:hover { transform: translateY(calc(var(--offset) - 9px)) rotate(var(--angle)); }
}

.question-page { width: 100%; display: grid; justify-items: stretch; gap: 4px; padding: 5px 0; text-align: left; }
#question {
  display: block;
  width: 100%;
  min-height: 105px;
  padding: 0 1px;
  border: 0;
  margin: 0;
  border-radius: 0;
  color: #483735;
  background: repeating-linear-gradient(180deg, transparent 0 33px, #94775550 33px 34px);
  caret-color: var(--accent);
  font-size: clamp(16px, 1.75vw, 22px);
  line-height: 34px;
  resize: none;
  overflow-wrap: anywhere;
}
#question::placeholder { color: #79675b; opacity: 1; }
#question:focus { outline: 0; }
#question:focus-visible { box-shadow: 0 2px 0 #8c7153; }
#question[aria-invalid="true"] { box-shadow: 0 2px 0 #a24a40; }
.quiet-note { margin: 0; color: #755f57; font-size: 10px; }
.quiet-note[lang="en"] { font: italic 14px/1.3 Georgia, serif; color: #70557f; }
.page-submit { justify-self: end; min-width: 74px; min-height: 44px; padding: 0 3px 0 7px; color: var(--accent); font-size: 14px; }
.page-submit span:first-child { border-bottom: 1px solid currentColor; padding-bottom: 1px; }
.page-submit span:last-child { font-size: 17px; }
.page-submit:disabled { opacity: .5; cursor: default; }

.primary {
  min-height: 47px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 100px;
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 630;
  transition: background-color 160ms, transform 160ms var(--ease);
}
.primary:hover { background: var(--accent-hover); }
.primary span[aria-hidden] { font-size: 18px; line-height: 1; }
.primary:disabled { opacity: .62; cursor: default; transform: none; }

.result-scene { width: min(100%, 1000px); margin-inline: auto; padding: 22px 0 36px; }
.result-top { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 10px 20px; min-height: 42px; margin: 0 1.5% -10px; }
.close-book { justify-self: start; padding: 0 7px; color: var(--accent); font-size: 14px; white-space: nowrap; }
.close-book span:first-child { font-size: 20px; line-height: 1; }
.open-book {
  --cover-accent: #785586;
  position: relative;
  isolation: isolate;
  width: min(100%, 1000px);
  aspect-ratio: 1.62;
  margin: 0 auto 12px;
  perspective: 1600px;
  --cover-cloth: #786587;
}
body[data-edition="plain"] .open-book { --cover-accent: #a65c47; --cover-cloth: #b69b78; }
.book-object { position: absolute; z-index: -1; width: 100%; height: auto; inset: -3% 0 auto; filter: drop-shadow(0 12px 13px #50313c30); pointer-events: none; }
.paper-left, .paper-right { display: grid; place-items: center; position: absolute; min-width: 0; }
.paper-left { inset: 14% 54% 18% 7%; }
.paper-right { inset: 13% 7% 17% 54%; text-align: center; }
.book-plate { position: relative; display: grid; place-items: center; width: min(63%, 220px); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(ellipse, #dbb9df55, #dbb9df15 54%, transparent 70%); color: var(--cover-accent); }
.book-plate .spark { width: 37%; }
.book-plate span { position: absolute; inset: 14%; border: 1px solid currentColor; border-radius: 50%; opacity: .43; transform: rotate(35deg) scaleY(.5); }
.book-plate span:nth-of-type(2) { transform: rotate(-32deg) scaleY(.48); }
.book-plate b { position: absolute; width: 6%; aspect-ratio: 1; top: 29%; right: 23%; border-radius: 50%; background: currentColor; opacity: .67; }
body[data-edition="plain"] .book-plate { background: radial-gradient(ellipse, #e9ae9038, transparent 71%); }
body[data-edition="plain"] .book-plate span { border-style: dotted; }
.page-content { width: 100%; min-width: 0; padding: 10px 0; overflow-wrap: anywhere; }
.page-star { width: clamp(16px, 2.4vw, 29px); margin-bottom: 12px; color: var(--cover-accent); }
.page-content h2, .waiting-page strong { display: block; margin: 0; font: 650 clamp(27px, 3.5vw, 46px)/1.24 var(--display); color: #3c343a; text-wrap: balance; }
.waiting-page strong { font-size: clamp(27px, 3.5vw, 42px); }
.page-content p { margin: 14px auto 0; max-width: 28em; color: #5d4c50; font-size: clamp(13px, 1.23vw, 16px); line-height: 1.83; text-wrap: pretty; }
.page-number { position: absolute; right: 0; bottom: -7px; color: #67565b; font-size: 11px; font-variant-numeric: tabular-nums; }
.result-actions { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px; min-height: 47px; }
.secondary-actions { display: flex; gap: 8px; }
.result-actions .primary { min-width: 136px; justify-content: space-between; }

/* The same book stays put while the slip and cover move around its spine. */
.book-object, .paper-left, .paper-right { transition: opacity .23s ease; }
[data-phase="closed"] :is(.book-object, .paper-left, .paper-right) { opacity: 0; }
[data-phase="closing"] :is(.book-object, .paper-left, .paper-right) { animation: spread-closes .49s ease both; }
[data-phase="reopening"] :is(.book-object, .paper-left, .paper-right), .open-book.intake .book-object { animation: spread-opens .61s var(--ease) both; }
@keyframes spread-closes { 0%, 40% { opacity: 1; } 100% { opacity: 0; } }
@keyframes spread-opens { 0% { opacity: .15; } 38% { opacity: 1; } }

.written-slip {
  display: none;
  position: absolute;
  z-index: 2;
  top: 36%;
  right: 7%;
  width: 36%;
  padding: 13px 25px 15px 27px;
  color: #54413a;
  background: linear-gradient(104deg, #f8e6b9, #f4ddb1);
  box-shadow: 3px 5px 8px #775d3a33;
  clip-path: polygon(0 0, 100% 0, 96% 50%, 100% 100%, 0 100%);
  overflow-wrap: anywhere;
  transform: rotate(-3deg);
}
.written-slip::before { position: absolute; left: 9px; top: 50%; width: 7px; aspect-ratio: 1; border-radius: 50%; background: #ac8c695e; content: ""; }
.written-slip span { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 3; -webkit-box-orient: vertical; font: 500 clamp(13px, 1.55vw, 19px)/1.54 "Kaiti SC", "KaiTi", var(--body); }
[data-phase="writing"] .written-slip, [data-phase="closing"] .written-slip { display: block; }
[data-phase="writing"] .written-slip span { animation: write-slip .44s .035s steps(15, end) both; }
[data-phase="closing"] .written-slip { animation: tuck-slip .48s var(--ease) both; }
[data-phase="answer"]:has(.written-slip span:not(:empty)) .written-slip,
[data-phase="reopening"]:has(.written-slip span:not(:empty)) .written-slip {
  display: block;
  top: auto;
  right: auto;
  left: 10%;
  bottom: 23%;
  width: 32%;
  transform: rotate(-3deg);
}
[data-phase="reopening"] .written-slip { animation: question-returns .68s var(--ease) both; }
@keyframes write-slip { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0); } }
@keyframes tuck-slip {
  from { transform: rotate(-3deg); }
  57% { opacity: 1; transform: translate(-74%, -12px) rotate(7deg) scale(.86); }
  to { opacity: 0; transform: translate(-117%, -23px) rotate(11deg) scale(.72); }
}
@keyframes question-returns { 0%, 55% { opacity: 0; } to { opacity: 1; } }

.book-hinge {
  position: absolute;
  z-index: 4;
  inset: 9% 50% 15% 3%;
  transform-origin: right 50%;
  transform-style: preserve-3d;
  opacity: 0;
  pointer-events: none;
}
.book-hinge span {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 6% 0 0 5% / 3% 0 0 3%;
  background: linear-gradient(90deg, #b49a6880, #f6e8ca 9%, #faeecf 88%, #b79a5c82);
  box-shadow: 3px 7px 15px #4c382f33;
}
.book-hinge span:last-child {
  transform: rotateY(180deg);
  background: repeating-linear-gradient(83deg, #ffffff0c 0 1px, transparent 1px 3px), var(--cover-cloth);
  border: 1px solid #6d4a5238;
  box-shadow: 2px 4px 10px #3f293d43, inset 0 0 0 7px #edd3a431;
}
.open-book.intake .book-hinge, [data-phase="reopening"] .book-hinge { animation: hinge-opens .55s cubic-bezier(.28,.05,.32,1) both; }
[data-phase="closing"] .book-hinge { animation: hinge-closes .49s .01s cubic-bezier(.39,.06,.32,1) both; }
.open-book.intake .paper-right { animation: question-returns .54s var(--ease) both; }
@keyframes hinge-closes {
  0% { opacity: .93; transform: rotateY(0); }
  78% { opacity: 1; }
  100% { opacity: .7; transform: rotateY(177deg); }
}
@keyframes hinge-opens {
  0% { opacity: 1; transform: rotateY(178deg); }
  57% { opacity: 1; }
  100% { opacity: 0; transform: rotateY(0); }
}

.closed-volume {
  position: absolute;
  z-index: 3;
  top: 6%;
  left: 72.5%;
  height: 89%;
  aspect-ratio: 1;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
}
.closed-volume img { display: none; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(9px 17px 10px #4535443d); }
.listening-caption { display: none; position: absolute; left: 72.5%; bottom: 2%; margin: 0; transform: translateX(-50%); white-space: nowrap; font: italic 15px/1.15 Georgia, serif; color: #70557f; pointer-events: none; }
body[data-edition="god"] [data-phase="closed"] .listening-caption { display: block; animation: bound-arrive .42s ease-out both; }
body[data-edition="plain"] .bound-plain, body[data-edition="god"] .bound-god { display: block; }
[data-phase="closed"] .closed-volume { opacity: 1; animation: bound-arrive .2s ease-out both; }
[data-phase="reopening"] .closed-volume { animation: bound-depart .27s ease-out both; }
@keyframes bound-arrive { from { opacity: .53; } to { opacity: 1; } }
@keyframes bound-depart { from { opacity: 1; } to { opacity: 0; } }

.page-turn { position: absolute; z-index: 3; inset: 10% 3.8% 14% 49.9%; perspective: 2300px; pointer-events: none; }
.leaf, .leaf-shadow { position: absolute; inset: 0; opacity: 0; transform-origin: left 50%; }
.leaf { transform-style: preserve-3d; }
.leaf span {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 2% 6% 4% 1% / 3% 4% 3% 1%;
  background: linear-gradient(90deg, #7c5e4d58, #fffde625 28%, #fff4e436 64%, #5c3e3238),
    url("assets/open-book.webp") 94% 43% / 224% 143%, #f4e9d4;
  box-shadow: 3px 1px 7px #624a4a1a;
}
.leaf span:last-child { transform: rotateY(180deg); background-image: linear-gradient(270deg, #c3a17c66, #f6ecdc4d 26%, #fff5e869 79%, #7e53644d), url("assets/open-book.webp"); }
.leaf-shadow { background: linear-gradient(90deg, #644d5bb3, transparent 73%); }
[data-phase="reopening"] .turning-leaf { animation: leaf-over .49s .13s cubic-bezier(.35,.05,.31,1) both; }
[data-phase="reopening"] .leaf-shadow { animation: page-shadow .49s .13s ease-out both; }
[data-phase="reopening"] #finished-page { animation: ink-arrives .64s var(--ease) both; }
@keyframes leaf-over {
  0% { opacity: 0; transform: rotateY(-3deg) skewY(-.5deg); }
  23% { opacity: .9; transform: rotateY(-53deg) skewY(-3deg) translateZ(4px); }
  60% { opacity: 1; transform: rotateY(-133deg) skewY(2.5deg) translateZ(2px); }
  100% { opacity: 0; transform: rotateY(-182deg) skewY(0); }
}
@keyframes page-shadow { 0%, 100% { opacity: 0; transform: scaleX(.22); } 35% { opacity: .48; transform: scaleX(.83); } }
@keyframes ink-arrives { 0%, 39% { opacity: 0; transform: translateY(5px); } 100% { opacity: 1; transform: none; } }

.panel {
  width: min(calc(100% - 24px), 470px);
  max-height: min(90svh, 780px);
  padding: 20px 23px;
  border: 1px solid #dfcfbf;
  border-radius: 24px;
  color: var(--ink);
  background: #fff8ed;
  box-shadow: 0 22px 70px #4c344340;
}
.panel[open] { animation: panel-in .23s var(--ease) both; }
.panel::backdrop { background: #3d304a69; }
@keyframes panel-in { from { opacity: 0; transform: translateY(8px) scale(.975); } }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 11px; }
.panel-heading h2 { font: 34px/1 var(--display); margin: 0; }
.icon-button { display: grid; place-items: center; width: 40px; height: 40px; font: 26px/1 var(--body); border: 0; border-radius: 50%; background: #f3e8dd; color: var(--accent); }
.icon-button:hover { background: var(--tint); }
.dialog-note { color: var(--quiet); font-size: 14px; margin-block: 8px; }
.saved-list { margin: 0; padding: 0; list-style: none; }
.saved-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; padding-block: 7px; border-top: 1px solid var(--line); }
.saved-entry { display: grid; gap: 3px; min-height: 48px; width: 100%; text-align: left; padding: 5px 9px 5px 0; border: 0; background: transparent; }
.saved-entry strong { font: 22px/1.23 var(--display); }
.saved-entry small { color: var(--quiet); font-size: 12px; overflow-wrap: anywhere; }
.saved-entry:hover { color: var(--accent); }

.share-panel { width: min(calc(100% - 24px), 405px); }
.poster-preview { display: grid; place-items: center; min-height: 130px; padding: 1px 0; background: #f2e8de; border-radius: 12px; }
.poster-preview img { width: auto; height: auto; max-height: min(49svh, 390px); max-width: 100%; border-radius: 4px; box-shadow: 0 3px 11px #54394629; }
.poster-preview p { padding: 10px; margin: 0; color: var(--quiet); font-size: 13px; }
.include-question { display: flex; gap: 7px; align-items: center; padding-block: 9px; color: var(--quiet); font-size: 13px; }
.include-question input { accent-color: var(--accent); width: 16px; height: 16px; }
.share-actions { display: flex; gap: 8px; padding-top: 6px; }
.share-actions .primary { flex: 1; justify-content: space-between; }
.toast { position: fixed; z-index: 4; right: 20px; bottom: 20px; max-width: calc(100vw - 40px); padding: 10px 16px; margin: 0; background: #fff8ed; box-shadow: 0 5px 18px #4c34432e; border-radius: 12px; color: var(--ink); pointer-events: none; opacity: 0; transform: translateY(6px); transition: opacity .15s, transform .15s; }
.toast.visible { opacity: 1; transform: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 1000px) {
  .frame { width: min(calc(100% - 62px), 1180px); }
}
@media (max-width: 710px) {
  .frame { width: calc(100% - 36px); }
  .masthead { height: 61px; }
  .brand { font-size: 16px; }
  .masthead .quiet-button { min-height: 37px; padding-inline: 12px; font-size: 13px; }
  .stage { min-height: 0; }
  .home-scene { min-height: calc(100svh - 61px); display: grid; align-content: center; padding: 24px 0 52px; }
  .desk-books { padding: 0; gap: 0; margin-inline: -7px; }
  .desk-book { --angle: -5deg; --offset: -11px; }
  .desk-book[data-open-book="god"] { --angle: 6deg; --offset: 13px; }
  .result-scene { padding: 13px 0 25px; width: 100%; }
  .result-top { margin: 0 0 6px; gap: 3px 10px; }
  .result-actions .primary { min-width: 110px; }
  .result-actions .quiet-button { padding-inline: 11px; font-size: 13px; }
}
@media (max-width: 530px) {
  .open-book { overflow: hidden; aspect-ratio: .98; width: min(100%, 440px); margin-bottom: 13px; }
  .book-object { width: 201%; max-width: none; inset: -14% auto auto -100%; }
  .paper-left { display: none; }
  .paper-right { inset: 11% 11% 14% 12%; }
  .page-turn { inset: 2% 6% 4% 0; }
  .book-hinge { inset: 2% 99% 4% -92%; }
  .closed-volume, .listening-caption { left: 50%; }
  .written-slip { top: 36%; right: 10%; width: 76%; }
  [data-phase="answer"] .written-slip, [data-phase="reopening"] .written-slip { display: none !important; }
  .page-content p { margin-top: 10px; }
  .page-star { margin-bottom: 8px; }
  .page-number { bottom: -11px; }
}
@media (max-width: 360px) {
  .frame { width: calc(100% - 28px); }
  .page-content h2 { font-size: 25px; }
  .page-content p { font-size: 12px; line-height: 1.65; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
