:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #24201d;
  --bar-height: 62px;
  --serif: "Songti SC", "Noto Serif CJK SC", "STSong", "SimSun", serif;
}

* { box-sizing: border-box; }
body, h1, h2, p, figure { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
img { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid currentColor; outline-offset: 5px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.rail { width: min(1320px, calc(100% - 112px)); margin-inline: auto; }

.masthead {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: var(--bar-height);
  background: #24201df7;
  color: #f7f0e1;
}

.masthead-inner {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 26px;
  min-height: var(--bar-height);
}

.identity { flex: none; font: 700 1rem/1.3 ui-monospace, SFMono-Regular, Consolas, monospace; }
.identity span { color: #e3bc7e; }
.project-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0 clamp(12px, 3vw, 44px); }
.project-nav a {
  display: grid;
  align-items: center;
  min-height: 42px;
  color: #d5ccbd;
  font-size: .925rem;
  font-weight: 600;
  text-align: center;
  text-underline-offset: .35em;
}

.project-nav a:hover, .project-nav a[aria-current] { color: #ffe1a8; text-decoration: underline; }
.reading-progress {
  position: absolute;
  inset: auto 0 0;
  height: 2px;
  background: #dfad65;
  transform: scaleX(var(--site-progress, 0));
  transform-origin: left;
}

.chapter-track { scroll-margin-top: var(--header-height, var(--bar-height)); }

.chapter {
  --ink: #252e36;
  --muted: #494d4c;
  --button: #283e4e;
  --on-button: #fff9ed;
  --scene-height: calc(100svh - var(--header-height, var(--bar-height)));
  --tilt-x: 0deg;
  --tilt-y: 0deg;
  --look-x: 0px;
  --look-y: 0px;
  --camera-x: 0px;
  --camera-y: 0px;
  --camera-scale: 1;
  --disc-shift: 0px;
  --disc-scale: 1;
  position: relative;
  min-height: var(--scene-height);
  overflow: clip;
  isolation: isolate;
  color: var(--ink);
}

.chapter-track[data-pin] { min-height: calc(100svh - var(--header-height, var(--bar-height)) + var(--runway)); }
.chapter-track[data-pin] .chapter { position: sticky; top: var(--header-height, var(--bar-height)); }
.chapter-layout {
  display: grid;
  position: relative;
  grid-template-columns: minmax(270px,.78fr) minmax(0,1.22fr);
  grid-template-rows: minmax(0,1fr) auto minmax(0,1fr);
  grid-template-areas: "copy visual" "actions visual" "hint visual";
  align-items: center;
  min-height: inherit;
  padding-block: 30px;
}

.project-copy { grid-area: copy; align-self: end; z-index: 2; padding: 18px 0 22px; }
.project-actions { grid-area: actions; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; z-index: 2; }
.project-kind { color: var(--muted); display: flex; align-items: center; gap: .7em; font-size: .875rem; font-weight: 650; letter-spacing: .14em; }
.project-kind::before { content: ""; width: 1.25em; height: 1px; background: currentColor; }
.project-description { max-width: 23em; color: var(--muted); font-size: clamp(1rem, 1.45vw, 1.24rem); line-height: 1.7; }
.project-copy h1, .project-copy h2 { margin-block: 12px 24px; line-height: 1.1; }
.project-copy h2 { font-size: clamp(2.6rem, 5vw, 5.2rem); letter-spacing: -.064em; }

.primary, .secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  font-size: .9375rem;
  font-weight: 650;
}

.primary { padding: 8px 18px; background: var(--button); color: var(--on-button); border-radius: 4px; }
.primary:hover { box-shadow: 0 0 0 2px var(--on-button), 0 0 0 3px var(--button); }
.secondary {
  padding: 5px 1px;
  color: var(--ink);
  background: none;
  border: 0;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--ink) 48%, transparent);
  text-underline-offset: .35em;
}

.secondary:hover { text-decoration-color: currentColor; }
.project-visual {
  grid-area: visual;
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  align-self: stretch;
  min-width: 0;
  min-height: 0;
}

.chapter-library {
  background:
    radial-gradient(ellipse at 71% 36%, #fff7db 0%, transparent 56%),
    linear-gradient(114deg, #f7f1e6 5%, #eadcc5 55%, #c4a17a);
}

.chapter-library::before {
  position: absolute;
  content: "";
  z-index: -1;
  inset: 0;
  background:
    linear-gradient(106deg, transparent 55%, #645b5b1f 55.5%, #645b5b11 65%, transparent 66%),
    linear-gradient(164deg, transparent 27%, #ffedbd60 32%, #ffedbd00 56%);
}

.library-visual::before {
  content: "";
  position: absolute;
  z-index: -1;
  width: min(88%, 660px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 44% 42%, #fff9dfb0 10%, #ffefbb65 59%, #ffe4ac12 69%, transparent 70%);
  transform: translate(calc(var(--look-x) + var(--disc-shift)), var(--look-y)) scale(var(--disc-scale));
  pointer-events: none;
}

.project-copy .ink-heading { position: relative; width: min(101%, 500px); margin-left: -1.5%; }
.ink-type { display: block; width: 100%; height: auto; }
.red-line { position: absolute; width: 63%; height: 19%; left: 29%; bottom: -3%; }
.red-line path { fill: none; stroke: #aa493d; stroke-width: 3; stroke-linecap: round; }

.book-stage { cursor: pointer; width: min(89%, 660px); padding: 30px 0; perspective: 1300px; }
.book-tilt {
  transform: translate(var(--camera-x), var(--camera-y)) scale(var(--camera-scale))
    rotateX(calc(7deg + var(--tilt-x))) rotateY(calc(-9deg + var(--tilt-y))) rotateZ(-8deg);
  transform-style: preserve-3d;
}
.book {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  width: 100%;
  font-size: clamp(.93rem,1.36vw,1.46rem);
  color: #25354a;
  perspective: 1000px;
  border-radius: 3px 6px 7px 3px;
  background: #eeeae1;
  box-shadow: 0 2px #c7c6bf, 0 4px #edeae1, 0 5px #c9c5bc, 0 7px #344657,
    10px 17px 20px -9px #31251c6a, 28px 57px 85px -20px #46301c70;
}

.book::before { content: ""; grid-area: 1 / 2; width: 100%; aspect-ratio: .715; align-self: start; }
.leaf, .turning-leaf, .cover-leaf { position: absolute; top: 0; width: 50%; height: 100%; }
.leaf.verse {
  grid-area: 1 / 1;
  position: relative;
  width: auto;
  height: auto;
  display: grid;
  grid-template-rows: 1fr auto;
  row-gap: 1.15em;
  padding: 1.9em min(1.4em,8%) 1em;
  border-radius: 4px 0 0 4px;
  background: linear-gradient(92deg,#f6f2e8,#fdfbf5 75%,#dad7ce);
}

.ribbon { position: absolute; top: 0; left: 16%; width: 5%; height: min(16%,1.65em); background: #b5493e; clip-path: polygon(0 0,100% 0,100% 84%,50% 100%,0 84%); }
.lines { place-self: center; writing-mode: vertical-rl; white-space: nowrap; line-height: 1.8; letter-spacing: .13em; font-family: var(--serif); }
.lines span { display: block; }
.source { justify-self: start; color: #5d636a; font: .8em/1.4 var(--serif); letter-spacing: .14em; }

.preview-leaf, .turning-leaf, .cover-leaf { left: 50%; transform-origin: left center; }
.preview-leaf { overflow: hidden; border-radius: 0 4px 4px 0; background: #fbfaf8; }
.preview-leaf img { width: 100%; height: 100%; object-fit: contain; }
.turning-leaf { transform: rotateY(calc(-178deg * var(--page-turn,0))); transform-style: preserve-3d; }
.illustration, .reverse {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 0 4px 4px 0;
}

.illustration { overflow: hidden; display: grid; place-items: end center; background: linear-gradient(92deg,#dadbd9,#edf0f0 12%,#e9eff2); }
.illustration picture { width: 124%; }
.illustration img { width: 100%; height: auto; }
.reverse {
  /* Choose the painted face explicitly as the sheet passes edge-on in WebKit. */
  visibility: hidden;
  transform: rotateY(180deg);
  background: url("/assets/reading-small.webp") center 78% / 84% auto no-repeat,
    linear-gradient(95deg,#ece7db,#faf7ed 30%,#f2eee3);
}

.turning-leaf[data-back] .illustration { visibility: hidden; }
.turning-leaf[data-back] .reverse { visibility: visible; }

.cover-leaf {
  display: none;
  place-items: center;
  pointer-events: none;
  border-radius: 0 5px 5px 0;
  border: 1px solid #e0b67876;
  color: #ebcb8e;
  background:
    radial-gradient(circle at 63% 24%,#ecd19a 0 4%,#eed9a035 4.5%,transparent 22%),
    linear-gradient(110deg,#192832,#304c55 55%,#182e39);
}

.motion-ready .cover-leaf.skip-cover { display: none; }
.cover-leaf::before { position: absolute; inset: 7%; border: 1px solid #e0b67866; content: ""; }
.cover-title { writing-mode: vertical-rl; letter-spacing: .22em; font: 600 1.25em/1.4 var(--serif); }

.scroll-hint {
  grid-area: hint;
  display: none;
  align-self: end;
  align-items: center;
  gap: 9px;
  padding-block: 12px;
  color: #53524b;
  font-size: .875rem;
}

/* Reserve the same space before and after pinning, since pinning measures the chapter. */
.motion-ready .scroll-hint { display: flex; visibility: hidden; }
.chapter-track[data-pin] .scroll-hint { visibility: visible; opacity: var(--hint,1); }
.scroll-hint i { width: 18px; height: 27px; border: 1px solid currentColor; border-radius: 10px; position: relative; }
.scroll-hint i::after { content: ""; position: absolute; left: 7px; top: 5px; width: 2px; height: 6px; background: currentColor; border-radius: 2px; }

.chapter-game {
  --ink: #fff0d7;
  --muted: #e6cbb2;
  --button: #f5d6a1;
  --on-button: #38291e;
  background:
    radial-gradient(ellipse at 73% 51%, #3e2b48 0%, #211d36 39%, transparent 70%),
    #141525;
}

@font-face {
  font-family: "Night Desk";
  src: url("/assets/night-title.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

.chapter-game h2 { font-family: "Night Desk",sans-serif; font-weight: 400; color: #ffdda4; text-shadow: 3px 4px #8b4b48; }
.night-scene { margin-inline: -10% -4%; transform: translateY(var(--camera-y)) scale(var(--camera-scale)); }
.game-still, #lamp-scene {
  width: 100%;
  height: auto;
  object-fit: contain;
  mask-image: radial-gradient(ellipse 53% 51% at 51% 54%, #000 54%, #000d 75%, transparent 100%);
}
#lamp-scene { display: none; image-rendering: pixelated; touch-action: pan-y; cursor: crosshair; }
.night-scene.is-live .game-still { display: none; }
.night-scene.is-live #lamp-scene { display: block; }

.chapter-typeset {
  --ink: #142f26;
  --muted: #355147;
  --button: #244b39;
  --on-button: #fefff7;
  background: radial-gradient(ellipse at 71% 46%,#f3f5e9 4%,transparent 60%), linear-gradient(115deg,#e7ecdf,#bfcfbb);
}

.chapter-typeset h2 span { font-family: Georgia,serif; font-weight: 500; }
.typeset-visual {
  padding: 58px 5%;
  background:
    linear-gradient(90deg,#476b4820 1px,transparent 1px) 50% 50% / 32px 32px,
    linear-gradient(#476b4820 1px,transparent 1px) 50% 50% / 32px 32px;
  mask-image: radial-gradient(ellipse at 50% 50%,#000 59%,transparent 82%);
}

.formula-sheet {
  display: grid;
  width: min(100%,550px);
  padding-block: 17px;
  position: relative;
}

.formula-source, .formula-result {
  grid-area: 1 / 1;
  position: relative;
  width: 86%;
}

.formula-source {
  z-index: 2;
  align-self: start;
  padding: clamp(13px,2vw,25px);
  border: 1px solid #476257;
  border-radius: 6px;
  box-shadow: 0 19px 36px -21px #132b24ae;
  background: #203e34;
  color: #f5f7ed;
  transform: translate(-3%,-24%) rotate(-6deg);
}

.formula-result {
  justify-self: end;
  padding: clamp(18px,3vw,42px);
  margin-block: 26% 0;
  border: 1px solid #fff;
  background: #fffef6;
  box-shadow: 0 25px 42px -18px #314b3c82, 0 0 0 1px #29483318;
  transform: translate(var(--paper-x,0px), var(--paper-y,0px))
    scale(var(--paper-scale,1)) rotate(var(--paper-rotation,5deg));
  opacity: var(--paper-opacity,1);
}

.formula-sheet span { display: block; font: .875rem/1.4 ui-monospace,SFMono-Regular,Consolas,monospace; }
.formula-source span { color: #d6e1d5; padding-bottom: .75em; border-bottom: 1px solid #7195846e; }
.formula-source code { display: block; margin-top: .8em; font: .94rem/1.5 ui-monospace,SFMono-Regular,Consolas,monospace; overflow-wrap: anywhere; }
.formula-source b { color: #f2ce89; font-weight: 600; }
.formula-result span { color: #4d5c50; }
.equation { margin-block: 23px 12px; font-size: clamp(1.7rem,4vw,4.1rem); color: #203e34; }

.site-footer { background: #24201d; color: #d2c9b9; font: .8125rem/1.5 ui-monospace,SFMono-Regular,Consolas,monospace; }
.site-footer .rail { padding-block: 22px; }

@media (prefers-reduced-motion: no-preference) {
  .motion-ready .library-visual::before { animation: desk-light 1.7s ease-out both; }
  .motion-ready .chapter-library .book-stage { animation: arrive 1.5s cubic-bezier(.16,1,.3,1) both; }
  .motion-ready .cover-leaf {
    display: grid;
    animation: open-cover 1.25s .16s cubic-bezier(.37,.08,.23,.98) both;
  }
  .chapter-track[data-pin] .scroll-hint i::after { animation: nudge 2s ease-in-out infinite; }

  @keyframes arrive {
    from { transform: translate3d(10%,12%,0) rotateZ(12deg) scale(.72); opacity: .84; }
    to { transform: translate3d(0,0,0) rotateZ(0) scale(1); opacity: 1; }
  }
  @keyframes desk-light {
    from { opacity: .16; filter: brightness(.82); }
    to { opacity: 1; filter: brightness(1); }
  }
  @keyframes open-cover {
    0% { transform: rotateY(-2deg); opacity: 1; }
    75% { opacity: 1; }
    100% { transform: rotateY(-175deg); opacity: 0; visibility: hidden; }
  }
  @keyframes nudge {
    0%,100% { transform: translateY(0); opacity: .55; }
    45%,60% { transform: translateY(9px); opacity: 1; }
  }
}

@media (max-width: 920px) {
  .rail { width: calc(100% - 60px); }
}

@media (max-width: 700px) {
  :root { --bar-height: 54px; }
  .rail { width: calc(100% - 36px); }
  .masthead-inner { column-gap: 14px; }
  .identity { font-size: .875rem; }
  .project-nav { column-gap: clamp(8px,3vw,18px); }
  .project-nav a { font-size: .875rem; }
  .chapter-layout {
    grid-template-columns: minmax(0,1fr);
    grid-template-rows: auto auto minmax(0,1fr) auto;
    grid-template-areas: "copy" "actions" "visual" "hint";
    padding-block: 28px 12px;
  }
  .project-copy { align-self: start; padding: 0 0 12px; }
  .project-copy h1, .project-copy h2 { margin-block: 10px 13px; }
  .project-copy .ink-heading { width: min(84%,340px); }
  .project-copy h2 { font-size: clamp(2.15rem,9.4vw,4rem); }
  .project-description { font-size: 1rem; }
  .project-actions { gap: 5px 14px; }
  .book-stage { cursor: pointer; width: min(82%,420px); padding-block: 37px; }
  .book { font-size: clamp(.86rem,3.35vw,1.3rem); }
  .library-visual::before { width: min(90%,440px); }
  .scroll-hint { padding-block: 4px 12px; }
  .night-scene { margin-inline: -13%; }
  .typeset-visual { padding: 42px 4% 29px; }
  .formula-sheet { width: min(91%,460px); }
  .formula-source code { font-size: .875rem; }
  .equation { font-size: clamp(1.8rem,7.8vw,3.8rem); margin-block: 14px 4px; }
}

@media (max-width: 350px) {
  .masthead-inner { column-gap: 8px; }
  .project-nav { column-gap: 8px; }
  .project-nav a { font-size: .8125rem; }
}

@media (max-height: 590px) {
  .chapter { min-height: 0; }
  .chapter-layout { padding-block: 26px; }
}
