:root {
  color-scheme: light;
  --ink: #372318;
  --paper: #f4e5c9;
  --accent: #355433;
  font-family: Georgia, 'Times New Roman', serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: #ab8a61; color: var(--ink); }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid currentColor; outline-offset: 5px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.shelf { position: relative; min-height: 100svh; overflow: hidden; display: grid; place-items: center; background: #aa8a60 url('assets/shelf.png') center / cover; }
.shelf::before { content: ''; position: absolute; inset: 0; background: rgba(82, 48, 20, .13); backdrop-filter: blur(12px); }
.shelf-scene { position: relative; width: min(100vw, 177.7778svh); aspect-ratio: 16 / 9; background: url('assets/shelf.png') center / 100% 100%; }
.shelf-row { position: absolute; inset-inline: 0; display: flex; align-items: end; justify-content: center; }
.shelf-row-top { top: 4.5%; height: 37.5%; gap: 1.8%; }
.shelf-row-bottom { top: 51.7%; height: 36.5%; gap: 5.8%; }
.shelf-row-extra { display: none; }
.menu-book { position: relative; display: block; flex: 0 0 19.5%; height: 100%; text-decoration: none; color: #f9dfa2; transform-origin: 50% 100%; transition: transform 260ms ease, filter 260ms ease; will-change: transform; }
.menu-book:hover { transform: translateY(-2.5%) rotate(-1deg) scale(1.025); filter: brightness(1.08) drop-shadow(3px 10px 7px rgba(43, 20, 6, .24)); z-index: 2; }
.menu-book:focus-visible { outline: 3px solid #fff0c8; outline-offset: 0; border-radius: 9px; }
.book-art { position: absolute; inset: 0; background-image: url('assets/covers.png'); background-size: 557% 139.2%; background-repeat: no-repeat; background-position: calc(2% + var(--cover) * 23.87%) 46%; clip-path: polygon(10% 1%, 98% 1%, 99% 99%, 4% 99%, 2% 96%, 2% 7%); pointer-events: none; }
.book-title { position: absolute; inset: 0; display: flex; justify-content: center; align-items: center; padding: 0 5% 36% 14%; font-size: clamp(1rem, 2.6vw, 2.8rem); text-shadow: 0 1px 2px #3a210a; white-space: nowrap; letter-spacing: -.035em; pointer-events: none; }
.reader { position: fixed; width: 100vw; height: 100svh; max-width: none; max-height: none; inset: 0; border: 0; margin: 0; padding: 0; background: transparent; overflow: hidden; color: var(--ink); }
.reader::backdrop { background: rgba(29, 21, 12, .26); backdrop-filter: blur(3px); }
.open-book { position: absolute; inset: 0; margin: auto; width: min(96vw, 170svh); height: min(94svh, 61vw); display: grid; grid-template-columns: 1fr 1fr; padding: 5% 7%; background: url('assets/open-book.png') center / 104% 103% no-repeat; border-radius: 8px; filter: drop-shadow(0 15px 18px rgba(45, 28, 10, .24)); transform-origin: center; }
.contents-page { min-height: 0; padding: 0 15% 0 5%; display: flex; flex-direction: column; }
.back-link { border: 0; padding: 6px 0; background: transparent; align-self: start; font-size: 1rem; text-align: left; text-decoration: none; }
.back-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 5px; }
.contents-body { padding-top: clamp(16px, 3.8svh, 52px); overflow: auto; scrollbar-width: thin; }
#book-title { font-size: clamp(1.9rem, 4.4vw, 4.5rem); line-height: 1.06; margin: 0; font-weight: normal; letter-spacing: -.045em; overflow-wrap: anywhere; }
.small-rule { width: 45px; height: 1px; background: #ae8849; margin: 25px 0 30px; }
.contents-label { font-size: clamp(1.1rem, 1.65vw, 1.55rem); font-weight: normal; margin: 0 0 17px; }
#chapter-nav { display: flex; flex-direction: column; align-items: start; gap: clamp(12px, 2.1svh, 26px); padding-left: 0; padding-bottom: 12px; }
.chapter-nav-link { color: var(--ink); font-size: clamp(1.125rem, 2vw, 1.85rem); line-height: 1.25; text-decoration: none; padding: 3px 0; border-bottom: 1px solid transparent; overflow-wrap: anywhere; }
.chapter-nav-link:hover { color: var(--accent); }
.chapter-nav-link[aria-current='page'] { color: var(--accent); border-color: currentColor; }
.reading-page { min-width: 0; min-height: 0; padding: 4% 3% 3% 14%; display: flex; flex-direction: column; }
.chapter-scroll { min-height: 0; height: 100%; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #ac8a53 transparent; overscroll-behavior: contain; padding: 0 9px 12px 0; }
#chapter { outline: none; }
#chapter h2 { font-weight: normal; font-size: clamp(2rem, 4.1vw, 4.1rem); line-height: 1.08; letter-spacing: -.04em; margin: 0 0 clamp(18px, 3.5svh, 36px); overflow-wrap: anywhere; }
#chapter h3 { font-size: clamp(1.3rem, 2.05vw, 1.9rem); line-height: 1.2; font-weight: normal; margin: 1.4em 0 .45em; }
#chapter p { font-size: clamp(1rem, 1.4vw, 1.3rem); line-height: 1.62; margin: 0 0 1em; }
#chapter .lead { line-height: 1.55; }
.chapter-link { color: var(--accent); text-underline-offset: 5px; font-size: clamp(1rem, 1.4vw, 1.3rem); line-height: 1.7; }
.chapter-link:hover { text-decoration-thickness: 2px; }
.chapter-divider { height: 1px; background: #b7955d; opacity: .65; margin: 1.6em 0; }
.mobile-toolbar { display: none; }
.flight-layer { position: fixed; inset: 0; pointer-events: none; perspective: 1600px; }
.flight-book { position: absolute; transform-origin: left center; }
.flight-book .book-title { font-size: clamp(1rem, 2.6vw, 2.8rem); }
.no-script { position: fixed; inset-inline: 15%; bottom: 20px; background: var(--paper); padding: 20px; border-radius: 4px; text-align: center; }
@media (min-width: 701px) and (max-height: 550px) {
  .open-book { height: 98svh; width: min(98vw, 205svh); padding: 4% 7%; }
  .contents-body { padding-top: 10px; }
  .small-rule { margin: 12px 0; }
  #book-title, #chapter h2 { font-size: 2rem; }
  #chapter p { font-size: 1rem; }
}
@media (max-width: 700px) {
  .shelf { min-height: 100svh; background: #b89568 url('assets/shelf-mobile.png') center / cover; }
  .shelf-scene { width: 100%; aspect-ratio: 941 / 1672; background: url('assets/shelf-mobile.png') center / 100% auto no-repeat; }
  /* One portrait painting: every book rests on its actual painted shelf.
     Keep width-driven proportions even when the viewport height changes. */
  .shelf-row { position: absolute; display: flex; align-items: flex-end; justify-content: center; gap: 2%; padding: 0; background: none; }
  .shelf-row-top { top: 0; height: 30.4%; }
  .shelf-row-bottom { top: 35%; height: 26.5%; }
  .shelf-row-extra { top: 65%; height: 25.3%; }
  .menu-book { flex: 0 0 30%; width: 30%; height: auto; aspect-ratio: 3 / 4; margin: 0; }
  .book-title { font-size: clamp(1rem, 4.45vw, 2rem); }
  .reader { height: 100dvh; }
  .reader::backdrop { background: rgba(46, 28, 9, .34); }
  .open-book { width: 100%; height: 100%; padding: 0; display: block; background-size: 215% 103%; background-position: 95% center; border-radius: 0; }
  .reading-page { position: absolute; inset: 0; padding: max(20px, env(safe-area-inset-top)) 9% max(32px, env(safe-area-inset-bottom)) 9%; }
  .mobile-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 7svh; }
  .contents-toggle { border: 0; background: transparent; padding: 12px 0; font-size: 1rem; color: var(--accent); display: flex; align-items: center; gap: 10px; }
  .chapter-scroll { flex: 1; height: auto; padding-right: 3px; }
  #chapter h2 { font-size: clamp(2rem, 9vw, 3.25rem); margin-bottom: 26px; }
  #chapter h3 { font-size: 1.65rem; }
  #chapter p, .chapter-link { font-size: 1.125rem; }
  .contents-page { display: none; position: absolute; z-index: 3; inset: 0; padding: max(28px, env(safe-area-inset-top)) 11% 38px; background: var(--paper) url('assets/open-book.png') 5% center / 215% 103%; }
  .open-book.contents-visible .contents-page { display: flex; }
  .contents-body { padding-top: 35px; }
  #book-title { font-size: 2.8rem; }
  .chapter-nav-link { font-size: 1.6rem; }
  #chapter-nav { gap: 23px; }
  .contents-label { font-size: 1.2rem; }
  .flight-book .book-title { font-size: clamp(1rem, 4.45vw, 2rem); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Separate day/night paintings share layout coordinates and crossfade in place. */
:root { --scene-image: url('assets/shelf.png'); --night-scene-image: url('assets/shelf-night.png'); --night-opacity: 0; --page-grade: brightness(1) sepia(0); }
:root[data-theme='dark'] { color-scheme: dark; --ink: #ecdbb8; --paper: #30271d; --night-opacity: 1; --page-grade: brightness(.19) sepia(.35); }
.shelf, .shelf-scene { background-image: none; }
.shelf-scene { z-index: 1; }
.shelf-row { z-index: 1; }
.shelf::before, .shelf::after { content: ''; position: absolute; inset: 0; background: var(--scene-image) center / cover; backdrop-filter: none; filter: blur(12px); pointer-events: none; }
.shelf::after { background-image: var(--night-scene-image); opacity: var(--night-opacity); transition: opacity 650ms ease; }
.shelf-scene::before, .shelf-scene::after { content: ''; position: absolute; inset: 0; background: var(--scene-image) center / 100% 100% no-repeat; pointer-events: none; }
.shelf-scene::after { background-image: var(--night-scene-image); opacity: var(--night-opacity); transition: opacity 650ms ease; }
.book-art::after { content: ''; position: absolute; inset: 0; background-image: url('assets/covers-night.png'); background-size: inherit; background-position: inherit; background-repeat: no-repeat; opacity: var(--night-opacity); transition: opacity 650ms ease; }
.open-book { background-image: none; isolation: isolate; }
.open-book::before { content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit; background: url('assets/open-book.png') center / 104% 103% no-repeat; filter: var(--page-grade); transition: filter 650ms ease; pointer-events: none; }
:root[data-theme='dark'] body { background: #24190f; }
:root[data-theme='dark'] .reader { --accent: #d3b36b !important; }
:root[data-theme='dark'] .reader::backdrop { background: rgba(10, 7, 4, .58); }
.scene-tools { position: absolute; z-index: 5; bottom: 1%; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; }
.object-button { display: block; position: relative; width: clamp(44px, 5vw, 64px); aspect-ratio: 1; padding: 0; border: 1px solid #ad834b; border-radius: 50%; background: #21150d; box-shadow: 0 3px 8px #21150d66; transition: box-shadow 300ms ease, transform 200ms ease; }
.object-art { position: absolute; inset: 0; border-radius: inherit; background: url('assets/controls.png') left center / 200% 100% no-repeat; pointer-events: none; }
.lantern-button .object-art { background-position: right center; }
.object-button:hover { transform: translateY(-2px); box-shadow: 0 0 14px #e9bf6680; }
.object-button:focus-visible { outline: 3px solid #fce0a2; outline-offset: 4px; }
.lantern-button[aria-pressed='true'] { box-shadow: 0 0 12px #efac47a0, 0 0 32px #ed9b3a55; }
.language-badge { position: absolute; bottom: -3px; right: -5px; min-width: 27px; padding: 2px 3px; border-radius: 4px; border: 1px solid #ac834a; background: #312115; color: #ffe2a4; font: 12px/1.2 Georgia, serif; }
.language-control { position: relative; }
.language-menu { position: absolute; bottom: calc(100% + 12px); left: 50%; transform: translateX(-50%); min-width: 135px; padding: 7px; border: 1px solid #af884c; border-radius: 6px; background: var(--paper); box-shadow: 0 7px 24px #130b0766; }
.language-menu button { display: block; width: 100%; min-height: 44px; border: 0; border-radius: 3px; padding: 8px 12px; text-align: left; background: transparent; font-size: 1rem; }
.language-menu button:hover, .language-menu button[aria-pressed='true'] { background: #ae88492b; }
.reader > .scene-tools { position: fixed; left: auto; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); transform: none; }
.reader > .scene-tools .object-button { width: 44px; }
.reader > .scene-tools .language-menu { left: auto; right: 0; transform: none; }
.flight-book { transform-origin: left top; will-change: transform; }
.flight-cover { position: absolute; inset: 0; transform-origin: left center; backface-visibility: hidden; will-change: transform, opacity; }
.flight-book .book-art::after { transition: none; }
@media (max-width: 700px) {
  .shelf { --scene-image: url('assets/shelf-mobile.png'); --night-scene-image: url('assets/shelf-mobile-night.png'); }
  .open-book::before { background-size: 215% 103%; background-position: 95% center; }
  :root[data-theme='dark'] .contents-page { background-color: #30271d; background-blend-mode: multiply; }
  .reading-page { padding-bottom: max(78px, calc(env(safe-area-inset-bottom) + 66px)); }
  .contents-page { padding-bottom: 78px; }
  .scene-tools { gap: 10px; }
}
