:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #202b3b;
  background: #f4f3ef;
}
* { box-sizing: border-box; }
body, h1, h2, p { margin: 0; }
img { display: block; }
a, button { font: inherit; color: inherit; }
a { text-decoration: none; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #4984be; outline-offset: 4px; }
.rail { width: min(1220px, 88%); margin: 0 auto; }
header .rail, footer .rail, nav, .actions { display: flex; align-items: center; }
header .rail, footer .rail { justify-content: space-between; }
header .rail { min-height: 64px; border-bottom: 1px solid #26374729; }
h1 { font-size: 1rem; font-weight: 650; letter-spacing: .05em; }
nav { gap: clamp(16px, 2.5vw, 38px); }
nav a { padding-block: 14px; font-size: .875rem; }
nav a:hover, .secondary:hover { text-decoration: underline; text-underline-offset: 5px; }
#library { overflow: clip; }
.spread { display: grid; grid-template-columns: .88fr 1.12fr; align-items: center; gap: 4%; min-height: clamp(490px, 46vw, 640px); padding: 52px 0 64px; }
.copy { position: relative; z-index: 1; }
.kind { font-size: .875rem; font-weight: 600; letter-spacing: .18em; color: #516076; }
h2 { font-size: clamp(3.1rem, 6.1vw, 6.15rem); font-weight: 620; line-height: 1.23; letter-spacing: -.065em; margin: 12px 0 18px; }
#library h2, .lines, .source { font-family: "Songti SC", "Noto Serif CJK SC", "STSong", "SimSun", serif; }
.description { font-size: clamp(1rem, 1.35vw, 1.18rem); line-height: 1.8; color: #495565; }
.actions { gap: 20px; flex-wrap: wrap; }
.actions { margin-top: 28px; }
.primary, .secondary { display: inline-flex; min-height: 44px; align-items: center; font-size: .9375rem; }
.primary { padding: 0 23px; background: #25354a; color: white; border-radius: 26px; font-weight: 600; }
.primary:hover { background: #394e67; }
.secondary { padding: 0; border: none; background: none; color: #47566c; }
.book-stage { width: 100%; perspective: 1200px; padding: 4% 1%; }
.book-tilt { transform: rotate(-6deg) skewY(1deg); }
.book {
  width: 100%; position: relative;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  font-size: clamp(.875rem, 1.45vw, 1.5rem);
  isolation: isolate; perspective: 1000px;
  border-radius: 3px 6px 7px 3px;
  background: #eeeae1;
  box-shadow: 0 2px #c7c6bf, 0 4px #edeae1, 0 5px #c9c5bc, 0 7px #344657, 5px 25px 28px -14px #38352d50, 10px 42px 55px -26px #524a393d;
}
.book::before { content: ""; grid-area: 1 / 2; width: 100%; aspect-ratio: .715; align-self: start; }
.leaf, .turning-leaf, .opening-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% 100%,50% 84%,0 100%); }
.lines { place-self: center; writing-mode: vertical-rl; white-space: nowrap; line-height: 1.8; letter-spacing: .13em; }
.lines span { display: block; }
.source { justify-self: start; line-height: 1.4; color: #676e73; font-size: .8rem; letter-spacing: .18em; }
.preview-leaf, .turning-leaf, .opening-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: auto; }
.turning-leaf { transform-style: preserve-3d; }
.illustration, .reverse { position: absolute; inset: 0; 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 { transform: rotateY(180deg); background: url("/assets/reading-small.webp") center 78% / 84% auto no-repeat, linear-gradient(95deg,#ece7db,#faf7ed 30%,#f2eee3); }
.book-stage.is-turned .turning-leaf { transform: rotateY(-178deg); }
.opening-leaf { display: none; background: linear-gradient(90deg,#dfdcd2,#faf7ed 15%,#f2eee3); pointer-events: none; }
#game { position: relative; overflow: hidden; isolation: isolate; background: #191b30; color: #fff4df; }
.night-content { min-height: clamp(420px, 40vw, 580px); display: flex; align-items: center; padding-block: 58px; }
#game .kind { color: #efc289; }
#game .description { color: #e3d4c6; }
#game .primary { color: #39291e; background: #f7d7a5; }
#game .primary:hover { background: #ffe4bc; }
footer { background: #191b30; color: #c0b6b0; }
footer .rail { border-top: 1px solid #ffffff26; min-height: 60px; font-size: .8125rem; }
@media (max-width: 720px) {
  .rail { width: 88%; }
  header .rail { min-height: 54px; }
  .spread { grid-template-columns: 1fr; gap: 25px; padding: 32px 0 40px; }
  h2 { margin: 7px 0 10px; font-size: clamp(2.95rem, 10vw, 4.2rem); }
  .actions { margin-top: 15px; }
  .book-stage { width: min(88%, 400px); justify-self: end; padding: 3% 1%; margin-right: 2%; }
  .book { font-size: clamp(.83rem, 3.1vw, 1rem); }
  .source { font-size: .74rem; }
  .night-content { align-items: flex-start; min-height: 500px; padding-block: 32px; }
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
  .opening-leaf { display: block; animation: open-page 1.15s cubic-bezier(.23,.7,.2,1) both; }
  @keyframes open-page {
    0% { opacity: 1; transform: rotateY(-4deg); }
    67% { opacity: 1; }
    100% { opacity: 0; transform: rotateY(-179deg); visibility: hidden; }
  }
  .turning-leaf { transition: transform .85s cubic-bezier(.22,.68,.22,1); }
  .book-tilt { transform: translateY(var(--drift, 0px)) rotate(var(--tilt, -6deg)) skewY(1deg); }
}

@font-face {
  font-family: "Night Desk";
  src: url("/assets/night-title.woff2") format("woff2");
  font-style: normal; font-weight: 400; font-display: swap;
}
#library { background: radial-gradient(ellipse at 82% 33%, #e5eaf0 0%, transparent 55%), #f6f4ef; }
.kind { display: flex; align-items: center; gap: 10px; }
.paper-mark { background: #ad483d; width: 9px; height: 17px; clip-path: polygon(0 0,100% 0,100% 100%,50% 76%,0 100%); }
.ink-heading { position: relative; max-width: 485px; width: 108%; margin: 12px 0 25px -3%; }
.ink-type { display: block; width: 100%; height: auto; }
.red-line { position: absolute; width: 61%; height: 19%; left: 30%; bottom: -2%; overflow: visible; transform: rotate(-2deg); }
.red-line path { fill: none; stroke: #b64b3c; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 350; }
@media (prefers-reduced-motion:no-preference) {
  .red-line path { animation: underline .55s 1.9s ease-out both; }
  @keyframes underline { from { stroke-dashoffset: 350; } to { stroke-dashoffset: 0; } }
}
#game h2 { font-family: "Night Desk", sans-serif; color: #ffdda4; font-weight: 400; font-size: clamp(3rem,5.5vw,5.7rem); line-height: 1.2; letter-spacing: -.055em; text-shadow: 3px 4px 0 #8b4b48; }
#game .kind { color: #f2c28c; }
.pixel-mark { width: 12px; height: 12px; background: #ffbf68; clip-path: polygon(33% 0,66% 0,66% 25%,100% 25%,100% 70%,66% 70%,66% 100%,33% 100%,33% 70%,0 70%,0 25%,33% 25%); }
#game .secondary { color: #f8d3a0; border-bottom: 1px dotted #b18f6b; min-height: 36px; }
#game .primary { border-radius: 6px; box-shadow: 0 3px 0 #a67855; }
.night-scene { position: absolute; inset: 3% 0 2% 40%; z-index: 0; }
.night-content { position: relative; pointer-events: none; }
.night-content a, .night-content button { pointer-events: auto; }
.game-still, #lamp-scene { position: absolute; inset: 0; width: 100%; height: 100%; }
.game-still { object-fit: cover; mask-image: linear-gradient(to right,transparent,#000 26%); }
#lamp-scene { display: none; object-fit: contain; image-rendering: pixelated; touch-action: pan-y; cursor: pointer; }
.night-scene.is-live .game-still { visibility: hidden; }
.night-scene.is-live #lamp-scene { display: block; }
@media (max-width:720px) {
  .ink-heading { width: min(100%,360px); margin: 5px 0 18px -2%; }
  .spread { gap: 14px; }
  .night-content { min-height: clamp(460px, 107vw, 590px); }
  .night-scene { inset: auto 0 2%; height: 54%; }
  .game-still { mask-image: linear-gradient(transparent,#000 35%); }
  #game h2 { margin: 9px 0 13px; }
}

.library-label { display: flex; align-items: center; gap: 7px; }
#replay { display: inline-grid; place-items: center; width: 36px; height: 36px; border: none; border-radius: 50%; background: transparent; color: #956057; }
#replay:hover { background: #b64b3c12; color: #883d32; }
@media (prefers-reduced-motion: reduce) { #replay { display: none; } }

#typeset { background: #eaf0e7; color: #203e31; }
.typeset-layout { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); align-items: center; gap: 6%; padding-block: clamp(45px,7vw,94px); }
#typeset .primary { background:#254f3c; }
#typeset h2 { font-size:clamp(2.5rem,4.6vw,4.5rem); }
#typeset h2 span { font-family: Georgia,serif; font-weight:500; }
.formula-sheet { margin:0; background:#fffef9; padding:clamp(18px,4vw,52px); box-shadow:0 12px 26px #2e47381a; }
.formula-sheet code { display:block; border-bottom:1px solid #d5dfd3; color:#46594c; font:1rem/2 ui-monospace,monospace; padding-bottom:8px; }
.equation { padding-block:22px 7px; font-size:clamp(2.1rem,5vw,4.6rem); }
@media(max-width:720px) {
  .typeset-layout { grid-template-columns:minmax(0,1fr); gap:28px; }
  .formula-sheet { width:min(100%,410px); justify-self:center; }
  header nav { display: none; }
  .spread { grid-template-columns:minmax(0,1fr); }
  #game { display:grid; }
  .night-content { grid-row:1; min-height:0; padding-bottom:0; }
  .night-scene { grid-row:2; position:relative; inset:auto; width:100%; height:auto; aspect-ratio:400/236; max-height:340px; }
}
/* Mobile visitors can open any work before reaching the illustrated sections. */
.quick-works { display: none; }
@media (max-width: 720px), (max-width: 960px) and (max-height: 540px) {
  header .rail { min-height: 52px; border-bottom: 0; }
  header nav { display: none; }
  .quick-works {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 18px;
    border-block: 1px solid #26374729;
  }
  .quick-works a {
    --work-color: #8d463e;
    display: grid;
    align-content: center;
    gap: 5px;
    min-height: 74px;
    padding: 10px 8px;
    padding-left: clamp(8px, 3vw, 20px);
    line-height: 1.3;
    overflow-wrap: anywhere;
  }
  .quick-works a:first-child { padding-left: 0; }
  .quick-works a + a { border-left: 1px solid #26374729; }
  .quick-works a:nth-child(2) { --work-color: #785129; }
  .quick-works a:nth-child(3) { --work-color: #2f614a; }
  .quick-works a:hover { background: #fff9; }
  .quick-works span { color: var(--work-color); font-size: .875rem; }
  .quick-works strong { font-size: .95rem; font-weight: 650; }
}
@media (max-width: 340px) {
  .quick-works { width: 92%; }
  .quick-works a { padding-inline: 6px; }
}
