#tooltip {
  max-width: min(330px, 80vw);
  line-height: 1.8;
  box-shadow: 0 4px 16px #0003;
}
#room canvas {
  cursor: grab;
}
.room-transition::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 10000;
  cursor: wait;
}
.room-transition header,
.room-transition nav,
.room-transition footer,
.room-transition #panel,
.room-transition #pc-terminal,
.room-transition #playback-controls,
.room-transition #shelf-pages,
.room-transition #hint,
.room-transition #tooltip,
.room-transition #terminal-back {
  visibility: hidden !important;
  pointer-events: none;
}
@keyframes openBook {
  0% {
    opacity: 0;
    transform: translate(-50%, 120%) perspective(1200px) rotateX(40deg) scale(0.65);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, 0) perspective(1200px) rotateX(0) scale(1);
  }
}
#panel.book-mode {
  top: auto;
  bottom: 100px;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: 760px;
  max-width: 94vw;
  height: 510px;
  max-height: 70vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto 1fr;
  gap: 10px 50px;
  padding: 42px 38px;
  border-radius: 7px 14px 14px 7px;
  background: linear-gradient(
    90deg,
    #eee5cc 0%,
    #f6efd9 46%,
    #e0d2b5 49%,
    #b7a484 50%,
    #e0d2b5 51%,
    #f7efdc 54%,
    #f4ecd6 100%
  );
  border-bottom: 9px solid #93392f;
  box-shadow:
    0 25px 60px #0008,
    -9px 3px 0 #9a392f,
    8px 3px 0 #9a392f;
  animation: openBook 0.7s 0.25s both ease-out;
  overflow: auto;
  backdrop-filter: none;
}
#panel.book-mode[hidden] {
  display: none;
}
#panel.book-mode #object-name {
  grid-column: 1;
  grid-row: 1;
}
#panel.book-mode h2 {
  grid-column: 1;
  grid-row: 2;
  font-size: 32px;
  padding-top: 60px;
}
#panel.book-mode #choices {
  grid-column: 1;
  grid-row: 3;
  align-content: start;
}
#panel.book-mode #detail {
  grid-column: 2;
  grid-row: 1 / span 3;
  font-size: 12px;
}
#panel.book-mode #detail h3 {
  font-size: 18px;
}
#panel.book-mode .player-area {
  margin: 16px 0;
}
#panel.book-mode #close {
  z-index: 2;
}
#panel.book-mode::after {
  content: '高卒の話も聞いてほしい';
  position: absolute;
  left: 38px;
  bottom: 45px;
  font-size: 12px;
  color: #97846b;
  letter-spacing: 0.15em;
}
@media (max-width: 650px) {
  #panel.book-mode {
    bottom: 75px;
    height: 64vh;
    max-height: 70vh;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 28px 24px;
    background: #f6eed8;
    animation-duration: 0.5s;
  }
  #panel.book-mode h2 {
    padding: 0;
    font-size: 22px;
    margin: 4px 0;
  }
  #panel.book-mode #detail {
    grid-column: 1;
    grid-row: 4;
  }
  #panel.book-mode::after {
    display: none;
  }
  .hint {
    max-width: 90vw;
    white-space: nowrap;
    font-size: 10px;
  }
}

/* Text settles on the pages of the extracted physical volume. */
#panel.book-mode {
  background: transparent;
  border: 0;
  box-shadow: none;
  animation: none;
}
@media (prefers-reduced-motion: reduce) {
  #panel.book-mode {
    animation-duration: 0.01s;
  }
}

body.book-held #hint {
  visibility: hidden;
}
/* Fixed paper areas: overflow is paginated, never scrolled. */
#panel.book-mode {
  display: block;
  padding: 28px 28px 36px;
  overflow: hidden;
  touch-action: pan-y;
  perspective: 1100px;
}
#panel.book-mode > #object-name,
#panel.book-mode > #panel-title,
#panel.book-mode > #choices,
#panel.book-mode::after {
  display: none;
}
#panel.book-mode #detail {
  height: 100%;
  min-height: 0;
}
#panel.book-mode .book-spread {
  height: 100%;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 44px;
}
#panel.book-mode .book-spread,
#panel.book-mode .book-sheet {
  overflow: hidden;
}
.book-sheet {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}
.book-right {
  padding-top: 18px;
}
.book-copy {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  display: flow-root;
}
#panel.book-mode .book-title {
  font-size: 23px;
  line-height: 1.75;
  padding: 0;
  margin: 16px 0 20px;
}
#panel.book-mode #detail .episode-quote {
  font-size: 17px;
  line-height: 1.9;
  margin: 12px 0;
}
#panel.book-mode .episode-summary {
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 8px;
  white-space: pre-wrap;
}
.book-left .episode-number {
  margin-bottom: 6px;
}
.book-page-number {
  flex: none;
  text-align: center;
  font:
    11px/18px Georgia,
    serif;
  color: #897d66;
  margin-top: 10px;
}
.book-audio {
  flex: none;
  margin-top: 8px;
}
#panel.book-mode .player-area {
  padding: 8px 0;
  margin: 0 0 7px;
}
#panel.book-mode .audio-note {
  margin: 6px 0;
  font-size: 10px;
}
#panel.book-mode .progress {
  margin-top: 7px;
}
#panel.book-mode .full {
  font-size: 12px;
}
.book-corner {
  position: absolute;
  bottom: 4px;
  z-index: 3;
  width: 65px;
  height: 36px;
  background: transparent;
  color: #7d6b4e;
  font-size: 11px;
  padding: 0;
}
.book-next {
  right: 4px;
  text-align: center;
}
.book-prev {
  left: 4px;
  text-align: center;
}
.book-corner:disabled {
  visibility: hidden;
}
.book-page-status {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font:
    10px/18px Georgia,
    serif;
  color: #897d66;
}
.book-turn-sheet {
  position: absolute;
  top: 28px;
  bottom: 36px;
  width: calc(50% - 28px);
  z-index: 8;
  background: linear-gradient(90deg, #c9b994, #f3e8ce 12%, #fbf2df 85%, #e6d7b9);
  box-shadow: 0 10px 22px #47341640;
  pointer-events: none;
  transform-style: preserve-3d;
}
.book-turn-sheet.turn-forward {
  left: 50%;
  transform-origin: left center;
}
.book-turn-sheet.turn-back {
  right: 50%;
  transform-origin: right center;
}
.book-turn-face {
  padding: 0 22px;
  height: 100%;
  overflow: hidden;
  backface-visibility: hidden;
  color: #36382f;
}
@media (max-width: 650px) {
  #panel.book-mode {
    padding: 25px 14px 32px;
    height: 64vh;
    max-height: 70vh;
  }
  #panel.book-mode .book-spread {
    gap: 22px;
  }
  #panel.book-mode .book-title {
    font-size: 17px;
    line-height: 1.7;
    margin: 12px 0 16px;
  }
  #panel.book-mode #detail .episode-quote {
    font-size: 14px;
    line-height: 1.85;
  }
  #panel.book-mode .episode-summary {
    font-size: 12px;
    line-height: 1.6;
  }
  #panel.book-mode .play {
    font-size: 10px;
    padding: 8px 5px;
  }
  #panel.book-mode .stop {
    padding: 8px 5px;
  }
  .book-audio {
    margin-top: 5px;
  }
  .book-turn-sheet {
    top: 25px;
    bottom: 32px;
    width: calc(50% - 14px);
  }
  .book-turn-face {
    padding: 0 11px;
  }
}
@media (max-height: 500px) {
  #panel.book-mode {
    bottom: 12px;
    height: calc(100vh - 28px);
    max-height: none;
  }
}
/* Keep the extracted volume's physical aspect on every viewport, including phones. */
#panel.book-mode {
  width: min(760px, 94vw, calc((100svh - 120px) * 1.63943662));
  height: auto;
  aspect-ratio: 582/355;
  max-height: none;
  bottom: 100px;
}
@media (max-width: 650px) {
  #panel.book-mode {
    padding: 14px 12px 24px;
    bottom: 88px;
  }
  #panel.book-mode .book-spread {
    gap: 18px;
  }
  #panel.book-mode .book-right {
    padding-top: 0;
  }
  #panel.book-mode .book-title {
    font-size: 14px;
    line-height: 1.5;
    margin: 6px 0 8px;
  }
  #panel.book-mode #detail .episode-quote {
    font-size: 12px;
    line-height: 1.6;
    margin: 6px 0;
  }
  #panel.book-mode .episode-summary {
    font-size: 11px;
    line-height: 1.55;
    margin: 0 0 4px;
  }
  #panel.book-mode .book-page-number {
    line-height: 14px;
    margin-top: 4px;
  }
  #panel.book-mode .book-left .episode-published {
    margin: 2px 0;
    font-size: 9px;
  }
  #panel.book-mode .book-left .episode-number {
    margin-bottom: 2px;
  }
  #panel.book-mode .audio-note {
    font-size: 8px;
    line-height: 1.45;
    margin: 3px 0;
  }
  #panel.book-mode .player-area {
    padding: 4px 0;
    margin: 0 0 4px;
  }
  #panel.book-mode .play {
    font-size: 9px;
    padding: 6px 4px;
  }
  #panel.book-mode .stop {
    font-size: 9px;
    padding: 6px 4px;
  }
  #panel.book-mode .progress {
    margin-top: 4px;
  }
  #panel.book-mode .full {
    font-size: 10px;
  }
  #panel.book-mode .book-corner {
    height: 24px;
    font-size: 10px;
  }
  .book-turn-sheet {
    top: 14px;
    bottom: 24px;
    width: calc(50% - 12px);
  }
}
body.inspecting > header,
body.inspecting > nav,
body.inspecting > footer {
  visibility: hidden;
}
body.inspecting #hint {
  bottom: auto;
  white-space: nowrap;
}
body.inspecting #panel:not(.book-mode) {
  width: min(390px, 32vw);
}
@media (max-width: 900px) {
  body.inspecting #panel:not(.book-mode) {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: 43vh;
    padding: 32px 24px;
    border-radius: 14px 14px 0 0;
  }
}

/* A held book stays centred; turning paper bends in connected strips. */
#panel.book-mode {
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
}
#panel.book-mode #close {
  display: none;
}
.book-turn-sheet {
  background: none;
  box-shadow: none;
  overflow: visible;
  transform: none;
  transform-style: preserve-3d;
}
.book-curl-strip {
  position: absolute;
  top: 0;
  height: 100%;
  transform-style: preserve-3d;
}
.book-curl-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  background: linear-gradient(90deg, #eee5cc, #f7efdc);
  box-shadow: 0 8px 16px #47341618;
}
.book-curl-face.curl-back {
  transform: rotateY(180deg);
  background: #eee5cc;
}
.book-curl-face .book-sheet {
  display: flex;
  height: 100%;
  box-sizing: border-box;
}
.book-audio[hidden] {
  display: none;
}
.book-curl-face {
  background: #f1e8d2;
  box-shadow: none;
}
.book-curl-face.curl-back {
  background: #eee5cf;
}
.book-turn-sheet {
  filter: none;
}

/* The turning leaf uses the same paper surface as the WebGL faces. */
.book-curl-face,
.book-curl-face.curl-back {
  background: var(--book-paper-color);
  box-shadow: none;
}
.book-turn-print {
  background-color: var(--book-paper-color);
  background-image: var(--book-paper);
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.book-turn-sheet {
  filter: none;
}

/* Apply the same analogue overlay to both static and turning paper. */
body.book-held #memory-grain {
  z-index: 4;
}
#panel.book-mode .book-corner {
  width: 48px;
  height: 28px;
  text-align: center;
}
.book-corner:focus-visible {
  outline: 1px solid #897d66;
  outline-offset: -3px;
}
body.book-held > header,
body.book-held > nav,
body.book-held > footer,
body.book-held > #shelf-pages,
body.book-held > #tooltip {
  z-index: 5;
}

#panel.book-mode .book-spread {
  position: relative;
  z-index: 6;
}
#panel.book-mode .book-turn-ink {
  z-index: 7;
  pointer-events: none;
}

#panel.book-mode .book-title-page .book-copy {
  flex: 0 1 auto;
}
#panel.book-mode .book-title-page .book-page-number {
  margin-top: auto;
}
#panel.book-mode .book-title-page .book-audio {
  margin-top: 8px;
}
#panel.book-mode .book-audio .audio-note {
  display: none;
}

/* Shade leaf faces without flattening the folding 3D strips. */
.book-curl-shade {
  position: absolute;
  inset: 0;
  background: #473416;
  opacity: 0;
  pointer-events: none;
}
#panel.book-mode:has(.book-turn-sheet) {
  overflow: visible;
}
