* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; overflow: hidden; background: #9fc9d3; }
html.reading-page { background: #9b7040; }
body.reading-frontispiece { overflow-x: hidden; overflow-y: auto; background: #9b7040; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.cover { position: relative; width: 100%; height: 100svh; min-height: 100%; overflow: hidden; isolation: isolate; }
.cover__picture, .cover__art, .cover__characters, .falling-leaves { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.cover__art, .cover__characters { object-fit: cover; object-position: center center; image-rendering: auto; }
.cover__characters { z-index: 2; pointer-events: none; }
.falling-leaves { z-index: 1; pointer-events: none; }
.dialogue[hidden] { display: none !important; }
.dialogue { position: absolute; z-index: 3; left: clamp(24px, 4vw, 72px); bottom: max(22px, env(safe-area-inset-bottom)); width: min(450px, calc(100% - 32px)); padding: 23px 26px 22px; color: #51312b; background: #fff2ce; border: 4px solid #643e31; box-shadow: 0 0 0 4px #df9e62, 8px 8px 0 #463024; font-family: "Microsoft YaHei", "Noto Sans CJK SC", monospace; text-align: center; animation: dialogue-appear 500ms steps(4, end) both; }
.dialogue__question { margin: 0 0 20px; font-size: clamp(17px, 2vw, 25px); font-weight: 700; line-height: 1.55; letter-spacing: .035em; }
.dialogue__choices { display: flex; justify-content: center; gap: 16px; }
.dialogue__choice { min-width: 130px; min-height: 49px; padding: 8px 15px; border: 3px solid #643e31; border-radius: 0; color: #51312b; background: #ffd995; box-shadow: 4px 4px 0 #a35b42; font: inherit; font-size: clamp(16px, 1.6vw, 21px); font-weight: 700; cursor: pointer; touch-action: manipulation; }
.dialogue__choice:hover, .dialogue__choice:focus-visible { background: #ffe8b6; outline: 3px solid #fff8e6; outline-offset: 3px; }
.dialogue__choice:active { box-shadow: 1px 1px 0 #a35b42; transform: translate(3px, 3px); }
.cover__continue { position: absolute; z-index: 4; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: transparent; cursor: pointer; }
.cover__continue:focus-visible { outline: 4px dashed #fff2ce; outline-offset: -12px; }
.cover.is-leaving { opacity: 0; transform: scale(1.018); transition: opacity 620ms ease, transform 760ms ease; }

.frontispiece[hidden], .journal[hidden] { display: none !important; }
.frontispiece, .journal { position: absolute; z-index: 10; inset: 0 0 auto; display: block; width: 100%; min-height: 100svh; overflow: visible; opacity: 0; background:
  radial-gradient(circle at 72% 18%, rgba(255, 221, 139, .36) 0 2px, transparent 3px),
  radial-gradient(circle at 18% 78%, rgba(255, 232, 169, .24) 0 2px, transparent 3px),
  linear-gradient(165deg, #d49c50 0%, #9b7040 44%, #5c5b3c 100%);
  transition: opacity 560ms ease;
}
.frontispiece::before, .journal::before { content: ""; position: absolute; inset: 0; opacity: .33; background:
  repeating-linear-gradient(0deg, rgba(78, 48, 29, .10) 0 1px, transparent 1px 4px),
  repeating-linear-gradient(90deg, rgba(255, 232, 175, .08) 0 1px, transparent 1px 5px);
  pointer-events: none;
}
.frontispiece.is-visible, .journal.is-visible { opacity: 1; }
.frontispiece__glow { position: fixed; width: 34vmax; aspect-ratio: 1; border-radius: 50%; filter: blur(45px); opacity: .25; pointer-events: none; }
.frontispiece__glow--one { top: -15vmax; right: -8vmax; background: #ffe2a2; }
.frontispiece__glow--two { bottom: -22vmax; left: -12vmax; background: #d06e37; }
.frontispiece__back { position: fixed; z-index: 30; top: max(16px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); width: 42px; height: 42px; padding: 0 0 5px; border: 3px solid #5d3a2a; color: #5d3a2a; background: #f6d99b; box-shadow: 4px 4px 0 rgba(69, 45, 29, .45); font: 700 34px/1 Georgia, serif; cursor: pointer; }
.frontispiece__back:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 rgba(69, 45, 29, .45); }
.frontispiece__back:focus-visible { outline: 3px solid #fff6d7; outline-offset: 3px; }
.page-nav { position: fixed; z-index: 30; top: max(16px, env(safe-area-inset-top)); width: 42px; height: 42px; padding: 0 0 5px; border: 3px solid #5d3a2a; color: #5d3a2a; background: #f6d99b; box-shadow: 4px 4px 0 rgba(69, 45, 29, .45); font: 700 34px/1 Georgia, serif; cursor: pointer; }
.page-nav--next { right: max(16px, env(safe-area-inset-right)); }
.page-nav--back { left: max(16px, env(safe-area-inset-left)); }
.page-nav:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 rgba(69, 45, 29, .45); }
.page-nav:focus-visible { outline: 3px solid #fff6d7; outline-offset: 3px; }
.book-shell { position: relative; z-index: 2; width: min(720px, calc(100vw - 80px)); min-height: calc(100svh - 54px); margin: 27px auto; filter: drop-shadow(0 24px 24px rgba(53, 32, 21, .38)); }
.memory-book { width: 100%; min-height: inherit; }
.book-page { position: relative; width: 100%; min-height: calc(100svh - 54px); overflow: hidden; color: #594031; background-color: #ead09b; background-image:
  radial-gradient(ellipse at center, rgba(255, 244, 207, .78) 0%, rgba(239, 213, 164, .46) 58%, rgba(133, 79, 39, .30) 100%),
  radial-gradient(circle at 8% 17%, rgba(113, 65, 32, .10) 0 2px, transparent 3px),
  radial-gradient(circle at 91% 72%, rgba(113, 65, 32, .08) 0 3px, transparent 4px),
  repeating-linear-gradient(14deg, rgba(101, 65, 35, .035) 0 1px, transparent 1px 6px),
  repeating-linear-gradient(98deg, rgba(255, 248, 220, .08) 0 1px, transparent 1px 8px);
  border: 1px solid #b77a43;
  box-shadow: inset 0 0 46px rgba(91, 51, 25, .23), inset 0 0 9px rgba(91, 51, 25, .16);
}
.book-page::after { content: ""; position: absolute; inset: 0; opacity: .20; pointer-events: none; background:
  repeating-linear-gradient(37deg, rgba(105, 67, 34, .10) 0 1px, transparent 1px 7px),
  repeating-linear-gradient(131deg, rgba(255, 255, 255, .16) 0 1px, transparent 1px 9px);
}
.book-page--frontispiece { border-left: 5px solid #81532f; border-right: 1px solid #a96c3b; }
.frontispiece__text { position: relative; z-index: 3; display: block; width: calc(100% - 122px); min-height: calc(100svh - 184px); height: auto; margin: 72px 46px 58px 76px; padding: 0 4px; resize: none; overflow: hidden; border: 0; outline: 0; color: #51392d; background: transparent; font: 20px/34px "KaiTi", "STKaiti", "Microsoft YaHei", serif; letter-spacing: .045em; text-align: left; caret-color: #9b3f2f; }
.frontispiece__text::placeholder { color: rgba(90, 64, 48, .45); }
.frontispiece__text:focus { text-shadow: 0 0 .01px currentColor; }
.paper-stitch { display: none; }
.paper-stitch--top { top: 22px; }
.paper-stitch--bottom { bottom: 22px; }
.pixel-corner { position: absolute; z-index: 2; width: 7px; height: 7px; background: #c06c35; box-shadow: 7px 0 #e4a53c, 14px 0 #6f793d, 21px 7px #c85531, 14px 14px #d98a39, 7px 21px #7f7439, 0 14px #e7b952, -7px 7px #ae5232; opacity: .82; }
.pixel-corner--top { top: 36px; right: 38px; }
.pixel-corner--bottom { right: 52px; bottom: 42px; transform: rotate(180deg); }

.journal { transition: opacity 560ms ease; }
.journal__shell { width: min(900px, calc(100vw - 80px)); }
.journal__paper { min-height: calc(100svh - 54px); padding: 82px 62px 100px; }
.journal-flow { position: relative; z-index: 3; display: flex; flex-wrap: wrap; align-items: flex-start; gap: clamp(18px, 3.4vw, 42px) clamp(12px, 2.5vw, 30px); width: 100%; min-height: calc(100svh - 236px); }
.journal-empty { flex: 1 0 100%; align-self: center; margin: 0; color: rgba(81, 57, 45, .48); font: 18px/1.8 "KaiTi", "STKaiti", "Microsoft YaHei", serif; text-align: center; }
.journal-flow.has-content .journal-empty { display: none; }
.journal-text { flex: 1 0 100%; margin: 2px 0 16px; color: #51392d; font: 20px/1.72 "KaiTi", "STKaiti", "Microsoft YaHei", serif; letter-spacing: .045em; white-space: pre-wrap; overflow-wrap: anywhere; }
.media-window { position: relative; flex: 0 0 var(--media-width, 48%); margin-top: var(--media-rise, 0); margin-left: var(--media-offset, 0); transform: rotate(var(--media-tilt, 0deg)); transform-origin: center; }
.media-window button { font: inherit; }
.photo-window, .video-window { display: block; width: 100%; padding: 0; overflow: hidden; border: 0; color: inherit; background: transparent; filter: drop-shadow(5px 7px 6px rgba(74, 42, 23, .27)); cursor: zoom-in; }
.photo-window img, .video-window__poster { display: block; width: 100%; height: auto; }
.video-window { position: relative; cursor: pointer; }
.video-window::after { content: "▶"; position: absolute; top: 50%; left: 50%; display: grid; place-items: center; width: clamp(44px, 7vw, 64px); aspect-ratio: 1; border: 3px solid rgba(255, 244, 211, .92); color: #fff4d3; background: rgba(75, 43, 27, .68); box-shadow: 0 4px 12px rgba(40, 21, 12, .30); transform: translate(-50%, -50%); font-size: clamp(20px, 3vw, 29px); }
.audio-window { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 10px 14px; border: 2px solid #9a6337; color: #51392d; background: rgba(244, 218, 166, .78); box-shadow: 4px 5px 0 rgba(90, 52, 27, .20); cursor: pointer; }
.audio-window__play { flex: 0 0 34px; width: 34px; height: 34px; padding: 0; border: 2px solid #75462d; border-radius: 50%; color: #75462d; background: #f6dda8; cursor: pointer; }
.audio-window__meta { min-width: 0; flex: 1; text-align: left; }
.audio-window__name { display: block; overflow: hidden; font-size: 14px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.audio-window__time { display: block; margin-top: 3px; font-size: 12px; opacity: .62; }
.link-window { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 13px; width: 100%; min-height: 92px; padding: 10px; border: 2px solid #956139; color: #51392d; background: rgba(247, 221, 170, .82); box-shadow: 5px 6px 0 rgba(90, 52, 27, .20); text-decoration: none; }
.link-window:hover, .link-window:focus-visible { background: #f6dda8; outline: 3px solid rgba(255, 246, 215, .8); outline-offset: 3px; }
.link-window__cover { display: grid; place-items: center; width: 74px; aspect-ratio: 1; overflow: hidden; color: #f9e8bd; background: linear-gradient(145deg, #b9573b, #e0a04a 52%, #647844); font-size: 30px; }
.link-window__cover img { width: 100%; height: 100%; object-fit: cover; }
.link-window__copy { min-width: 0; align-self: center; }
.link-window__title { display: block; overflow: hidden; font-size: 15px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.link-window__host { display: block; margin-top: 6px; overflow: hidden; font-size: 12px; opacity: .66; text-overflow: ellipsis; white-space: nowrap; }
.journal-tools { position: fixed; z-index: 31; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); display: flex; gap: 10px; }
.journal-tools__button { min-height: 42px; padding: 8px 14px; border: 3px solid #5d3a2a; color: #51392d; background: #f6d99b; box-shadow: 4px 4px 0 rgba(69, 45, 29, .45); font: 700 14px/1 "Microsoft YaHei", sans-serif; cursor: pointer; }
.journal-tools__button:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 rgba(69, 45, 29, .45); }

.link-dialog { width: min(440px, calc(100vw - 28px)); padding: 0; border: 3px solid #6f472e; color: #51392d; background: #ead09b; box-shadow: 9px 11px 0 rgba(53, 31, 19, .42); }
.link-dialog::backdrop, .media-viewer::backdrop { background: rgba(35, 22, 15, .78); }
.link-dialog__form { display: grid; gap: 14px; padding: 24px; }
.link-dialog h2 { margin: 0 0 3px; font: 700 21px/1.3 "KaiTi", "STKaiti", serif; }
.link-dialog label { display: grid; gap: 6px; font-size: 14px; font-weight: 700; }
.link-dialog input { min-width: 0; padding: 10px; border: 2px solid #98633b; color: #51392d; background: #fff0c9; font: inherit; }
.link-dialog__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.link-dialog__actions button { min-width: 82px; padding: 9px 12px; border: 2px solid #70462d; color: #51392d; background: #f4d292; font-weight: 700; cursor: pointer; }
.media-viewer { width: 100vw; max-width: none; height: 100vh; max-height: none; padding: 0; border: 0; overflow: hidden; background: rgba(24, 16, 12, .94); }
.media-viewer__close { position: fixed; z-index: 2; top: 15px; right: 18px; width: 44px; height: 44px; border: 2px solid #f4ddb0; color: #f4ddb0; background: rgba(67, 42, 29, .72); font-size: 30px; cursor: pointer; }
.media-viewer__content { display: grid; place-items: center; width: 100%; height: 100%; padding: 24px; }
.media-viewer__content img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.media-viewer__content video { display: block; width: min(100%, 1400px); max-height: 100%; background: #000; }
@keyframes dialogue-appear { from { opacity: 0; transform: translateY(15px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@media (max-width: 620px) {
  .dialogue { left: 14px; bottom: max(18px, env(safe-area-inset-bottom)); width: calc(100% - 28px); padding: 18px 13px 17px; border-width: 3px; box-shadow: 0 0 0 3px #df9e62, 6px 6px 0 #463024; }
  .dialogue__question { margin-bottom: 17px; }
  .dialogue__choices { gap: 10px; }
  .dialogue__choice { min-width: 0; flex: 1; min-height: 45px; }
  .frontispiece__back { width: 38px; height: 38px; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); font-size: 30px; }
  .page-nav { width: 38px; height: 38px; top: max(10px, env(safe-area-inset-top)); font-size: 30px; }
  .page-nav--next { right: max(10px, env(safe-area-inset-right)); }
  .page-nav--back { left: max(10px, env(safe-area-inset-left)); }
  .book-shell { width: calc(100vw - 24px); min-height: calc(100svh - 42px); margin: 21px auto; }
  .book-page { min-height: calc(100svh - 42px); }
  .frontispiece__text { width: calc(100% - 87px); min-height: calc(100svh - 150px); height: auto; margin: 62px 30px 46px 57px; font-size: 16px; line-height: 29px; }
  .pixel-corner--top { top: 29px; right: 30px; }
  .pixel-corner--bottom { right: 39px; bottom: 34px; }
  .journal__shell { width: calc(100vw - 24px); }
  .journal__paper { padding: 68px 28px 94px; }
  .journal-flow { gap: 24px 10px; min-height: calc(100svh - 204px); }
  .journal-empty { font-size: 15px; }
  .journal-text { font-size: 16px; line-height: 1.72; }
  .media-window { flex-basis: min(var(--media-mobile-width, 86%), 94%); margin-left: min(var(--media-mobile-offset, 0%), 22%); }
  .audio-window { min-height: 54px; padding: 8px 10px; }
  .journal-tools { right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); gap: 7px; }
  .journal-tools__button { min-height: 39px; padding: 7px 10px; border-width: 2px; font-size: 13px; box-shadow: 3px 3px 0 rgba(69, 45, 29, .42); }
  .link-dialog__form { padding: 20px 16px; }
}
@media (prefers-reduced-motion: reduce) { .dialogue { animation: none; } .cover.is-leaving, .frontispiece, .journal { transition: none; } }
