:root {
  color-scheme: dark;
  --room: #26212f;
  --paper: #fff8ec;
  --ink: #433d43;
  --quiet: #c5bac8;
  --cloth: #8c5354;
  --gold: #ebc796;
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--room); }
body {
  margin: 0; color: var(--ink);
  font: 16px/1.45 'Avenir Next', Avenir, ui-rounded, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: radial-gradient(ellipse at 52% 35%, #67505b88, #302837 60%, var(--room) 95%);
}
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .3; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 5px; }
[hidden] { display: none !important; }
.reading-room { max-width: 1260px; min-height: 100svh; padding: 23px 28px 20px; margin: auto; }
.masthead { max-width: 1060px; margin: 0 auto 22px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 15px; color: #f9eddb; }
.dedication { font: italic 16px/1.3 Georgia, 'Times New Roman', serif; color: #dbc8c5; }
h1 { margin: 0; font: 400 clamp(23px, 2.7vw, 32px)/1.25 Georgia, 'Times New Roman', serif; letter-spacing: -.03em; text-align: center; }
h1 em { display: inline-block; font-style: normal; font-size: .9em; font-weight: 700; transform: rotate(-5deg); color: #f3cea0; }
.sound-control { justify-self: end; display: inline-flex; align-items: center; gap: 7px; border: 0; background: transparent; color: var(--quiet); font-size: 14px; min-height: 44px; padding: 5px 0 5px 10px; }
.sound-control[aria-pressed=true] { color: var(--gold); }
.sound-control > span:first-child { font-size: 22px; }
main { width: min(1060px, calc((100svh - 330px) * 1.5)); min-width: min(100%, 640px); max-width: 100%; margin: 0 auto; }
.book { position: relative; isolation: isolate; padding: 7px 8px 11px; border-radius: 6px 11px 11px 6px; background: var(--cloth); box-shadow: 0 2px 1px #08051144, 0 6px 9px #08051133, 0 26px 55px -10px #120c1c99; }
.paper-edges { position: absolute; z-index: -1; inset: 8px 4px 0 5px; border-radius: 4px 8px 10px 4px; background: repeating-linear-gradient(to bottom, #c3ae98 0, #c3ae98 1px, #f4e6d1 1px, #f4e6d1 3px); box-shadow: 0 5px 0 -2px var(--cloth); }
.spread { position: relative; padding: 10px 11px 0; border-radius: 2px 6px 5px 2px; background: var(--paper); box-shadow: inset 1px 0 2px #93775b22, inset -2px 0 2px #93775b18; }
.art { position: relative; aspect-ratio: 3 / 2; background: var(--paper); perspective: 1700px; isolation: isolate; touch-action: pan-y; }
#poster { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }
#scene { position: relative; display: block; width: 100%; height: 100%; background: transparent; }
.art:not(.ready) #scene { opacity: 0; }
.binding { position: absolute; z-index: 4; inset-block: 0; left: 50%; width: 24px; transform: translateX(-50%); pointer-events: none; opacity: .58; background: linear-gradient(90deg, transparent, #74614916 34%, #44332326 48%, #fffdf588 54%, #fffdf510 77%, transparent); }
.story-paper { position: relative; min-height: 138px; display: flex; align-items: center; padding: 14px 25px 21px; background: var(--paper); }
.story { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 28px; align-items: center; font: 400 clamp(18px, 1.8vw, 22px)/1.43 Georgia, 'Times New Roman', serif; text-align: center; text-wrap: pretty; }
.story p { margin: 0; }
.story .babyfoot { color: #815128; font-weight: 600; }
.story .max { color: #604353; }
.story .dad { color: #48564a; }
.flomp { display: inline-block; margin-left: .3em; color: #805042; font-size: 1.1em; letter-spacing: .025em; transform: rotate(-3deg); }
.folio { position: absolute; bottom: 8px; font: 12px/1 Georgia, serif; color: #8a7d73; }
.folio-left { left: 3px; }
.folio-right { right: 3px; }
.navigation { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center; margin: 20px 1px 0; color: var(--quiet); }
.page-button { min-height: 48px; display: inline-flex; align-items: center; gap: 11px; width: max-content; border: 0; background: transparent; color: #f0e1d6; font-size: 15px; padding: 5px 8px; border-radius: 5px; }
.page-button > span[aria-hidden] { font: 32px/1 Georgia, serif; }
#previous { justify-self: start; padding-left: 0; }
#next { justify-self: end; padding-right: 0; }
.page-button:hover:not(:disabled), .replay-button:hover:not(:disabled), .quiet-controls button:hover { color: var(--gold); }
.middle-controls { display: flex; align-items: center; gap: 17px; }
.page-position { font-size: 13px; font-variant-numeric: tabular-nums; color: #c0afbd; white-space: nowrap; }
.replay-button { min-height: 44px; display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; font-size: 14px; padding: 5px; color: #ded0d2; }
.replay-button > span[aria-hidden] { font-size: 19px; }
.quiet-controls { display: flex; justify-content: space-between; align-items: center; gap: 15px; min-height: 40px; padding: 0 0 0 3px; color: #bcaebd; }
.quiet-controls button { min-height: 44px; border: 0; background: transparent; color: #c9b8c5; padding: 3px 8px 3px 0; font-size: 14px; }
.quiet-controls button[aria-pressed=true] { color: var(--gold); }
.reading-hint { font: italic 14px/1.4 Georgia, serif; }
.loading { position: absolute; z-index: 8; left: 50%; bottom: 5%; transform: translateX(-50%); background: #fff8eced; border-radius: 20px; padding: 8px 20px; max-width: 90%; width: max-content; text-align: center; color: #665451; font: italic 16px/1.3 Georgia, serif; }
.page-error { position: absolute; z-index: 9; inset: 0; display: grid; place-content: center; justify-items: center; text-align: center; padding: 25px; background: #fff8ecf5; color: var(--ink); }
.page-error p { margin: 0 0 8px; }
.page-error button { border: 0; color: #765146; background: transparent; text-decoration: underline; min-height: 44px; padding: 8px 18px; }
.no-script { color: #f5e7d6; text-align: center; }
.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; }
.turn-leaf { position: absolute; z-index: 3; inset: 0 0 0 50%; transform-origin: left center; transform-style: preserve-3d; pointer-events: none; will-change: transform; }
.turn-leaf.backward { inset: 0 50% 0 0; transform-origin: right center; }
.leaf-front, .leaf-back { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: var(--paper); overflow: hidden; }
.leaf-front { box-shadow: -5px 0 14px #44352326; }
.leaf-back { transform: rotateY(180deg); box-shadow: 5px 0 14px #44352326; }
.leaf-front canvas, .leaf-back canvas { display: block; width: 100%; height: 100%; }
.leaf-front::after, .leaf-back::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, #51452f16, transparent 18%, #fffcf210); }
@media (max-width: 700px) {
  .reading-room { padding: 16px 17px max(20px, env(safe-area-inset-bottom)); }
  .masthead { grid-template-columns: 1fr 1fr; margin-bottom: 13px; gap: 3px 12px; }
  .masthead h1 { grid-column: 1 / -1; grid-row: 1; font-size: clamp(25px, 5.3vw, 32px); margin-bottom: 1px; }
  .dedication { grid-column: 1; grid-row: 2; font-size: 14px; }
  .sound-control { grid-column: 2; grid-row: 2; }
  main { width: 100%; min-width: 0; }
  .book { margin-inline: -7px; padding: 5px 5px 8px; border-radius: 4px 8px 8px 4px; }
  .spread { padding: 6px 6px 0; }
  .binding { width: 17px; opacity: .5; }
  .story-paper { min-height: 180px; padding: 18px 14px 24px; }
  .story { display: block; font-size: 19px; line-height: 1.42; }
  .story p + p { margin-top: 10px; }
  .navigation { margin-top: 13px; gap: 7px; }
  .middle-controls { flex-direction: column; gap: 0; }
  .page-position { font-size: 12px; }
  .replay-button { font-size: 14px; min-height: 37px; padding: 0 3px; }
  .page-button { font-size: 14px; gap: 6px; }
  .quiet-controls { margin-top: 5px; }
  .reading-hint { font-size: 14px; }
}
@media (max-width: 365px) {
  .reading-room { padding-inline: 13px; }
  .story { font-size: 18px; }
  .story-paper { padding-inline: 10px; }
  .navigation { gap: 3px; }
  .page-button { gap: 3px; }
  .quiet-controls { flex-direction: column; gap: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; }
}
