/* Reading surfaces only. The live court has its own pointer controls. */
.courtBook { touch-action: pan-y pinch-zoom; }
.folioLine, .guideFolio, .storyFoot { display: flex; align-items: center; gap: 12px; }
.folioLine { margin-bottom: 12px; }
.folioLine .chapter, .guideFolio .book-guideNumber { margin: 0; }
.storyFoot { justify-content: space-between; }
.storyFoot button { padding-inline: 5px; }
.swipeCue { display: none; }
.courtBook .bookLeft { transform-origin: right center; }
.courtBook .bookRight { transform-origin: left center; }

/* Linen cover, gilt edges, and a lit gutter between two independent leaves. */
@media (min-width: 700px) {
  main:has(.courtBook:not([hidden])) { width: min(100%, 1100px); }
  .book-story, .book-chapterGuide {
    --gilt: #a58a51;
    --page: #f9f2df;
    display: grid;
    position: relative;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    isolation: isolate;
    margin: clamp(24px, 6vh, 72px) auto 24px;
    max-width: 995px;
    padding: 7px;
    border: 1px solid #132f27;
    border-radius: 8px 12px 12px 8px;
    background: #274538;
    box-shadow: inset 0 0 0 2px #45604d, inset 0 0 0 3px #ac975e,
      0 3px 0 -1px #e7d8b5, 0 5px 0 -1px #9d8b66, 0 7px 0 -1px #e3d2ac,
      0 9px 0 -1px #365040, 0 16px 24px -13px #47362380, 0 36px 60px -43px #41321a;
  }
  .book-story { min-height: clamp(395px, 54vh, 560px); }
  .bookLeft { min-width: 0; border-radius: 2px 5px 4px 2px; }
  .courtBook .bookRight {
    min-width: 0;
    background: linear-gradient(90deg, #a58f667a, #e5d7b84a 3.5%, transparent 10%),
      radial-gradient(ellipse at 72% 29%, #fffaf0, var(--page) 67%, #eee2c9);
    border-radius: 5px 4px 4px 2px;
  }
  .book-story .plate {
    position: relative;
    min-height: 0;
    overflow: hidden;
    background: #203c32;
    box-shadow: inset 0 0 0 1px #ae9866;
  }
  .book-story .plate img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
  .book-story .plate::after, .guideLeaf::after {
    position: absolute; inset: 0; content: ""; pointer-events: none;
    background: linear-gradient(90deg, transparent 88%, #3329184d 98%, #1f211bcc);
    border: 1px solid #ad956533;
    outline: 1px solid #e5d3a77a;
    outline-offset: -12px;
    border-radius: inherit;
  }
  .book-story .storyCopy {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: clamp(25px, 4.4vw, 62px);
    color: #243e33;
    position: relative;
  }
  .book-story .folioLine { color: #866637; margin-bottom: 20px; }
  .book-story .folioLine::before { content: ""; width: 29px; height: 1px; background: var(--gilt); }
  .book-story .chapter { color: #846337; font-size: 11px; letter-spacing: .14em; }
  .book-story .storyCopy h1 { font-size: clamp(32px, 3.7vw, 52px); text-wrap: balance; }
  .book-story .storyCopy p { max-width: 32ch; margin: 17px 0 24px; }
  .book-story .storyFoot {
    position: absolute;
    inset: auto clamp(25px, 4.4vw, 62px) 12px;
    border-top: 1px solid #cbb9908c;
    color: #566459;
  }
  .storyActions { gap: 9px; }
  .storyActions .primary { border-radius: 5px; box-shadow: inset 0 0 0 2px #ffffff0f; }
  .book-chapterGuide .guideLeaf {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "cover" "demo";
    overflow: hidden;
    background: radial-gradient(ellipse at 46% 62%, #fdf7e9, #e9ddbf);
  }
  .guideLeaf::after { outline-color: #af986740; }
  .book-chapterGuide .guideCover { grid-area: cover; min-height: 148px; height: clamp(148px, 20vh, 210px); }
  .book-chapterGuide .guideFigure { align-self: stretch; justify-content: center; padding: 14px; }
  .book-chapterGuide .guideInside { display: flex; flex-direction: column; gap: 6px; padding: clamp(17px, 2.6vw, 35px); align-items: stretch; }
  .book-chapterGuide .guidePitch { align-self: stretch; margin: 0 0 8px; }
  .book-chapterGuide .book-guideLevels button { min-height: 46px; padding-block: 6px; }
  .book-chapterGuide .book-guideBoard { width: min(80%, clamp(148px, 26vh, 255px)); }
}

/* Page snapshots are separate from the interactive DOM and the game canvas. */
:root[data-book-turn] { view-transition-name: none; }
:root[data-book-turn] .courtBook:not([hidden]) > .bookLeft { view-transition-name: court-left; }
:root[data-book-turn] .courtBook:not([hidden]) > .bookRight { view-transition-name: court-right; }
:root[data-book-turn]::view-transition { pointer-events: none; }
::view-transition-group(court-left), ::view-transition-group(court-right) {
  animation-duration: .56s;
}
::view-transition-image-pair(court-left), ::view-transition-image-pair(court-right) { overflow: visible; transform-style: preserve-3d; }
::view-transition-old(court-left), ::view-transition-new(court-left),
::view-transition-old(court-right), ::view-transition-new(court-right) {
  animation: none;
  mix-blend-mode: normal;
  backface-visibility: hidden;
}
::view-transition-old(court-left), ::view-transition-new(court-left) { transform-origin: right center; }
::view-transition-old(court-right), ::view-transition-new(court-right) { transform-origin: left center; }
:root[data-book-turn="forward"]::view-transition-old(court-right),
:root[data-book-turn="back"]::view-transition-old(court-left) { z-index: 1; animation: fold-away .56s ease-in-out both; }
:root[data-book-turn="forward"]::view-transition-new(court-left),
:root[data-book-turn="back"]::view-transition-new(court-right) { z-index: 1; animation: unfold .56s ease-in-out both; }
:root[data-book-turn="forward"] { --away: -180deg; --from: 180deg; }
:root[data-book-turn="back"] { --away: 180deg; --from: -180deg; }
@keyframes fold-away {
  from { transform: perspective(1350px) rotateY(0); }
  48% { box-shadow: 7px 6px 16px #42342445; }
  to { transform: perspective(1350px) rotateY(var(--away)); filter: brightness(.73); }
}
@keyframes unfold {
  from { transform: perspective(1350px) rotateY(var(--from)); filter: brightness(.73); }
  56% { box-shadow: -7px 6px 16px #42342445; }
  to { transform: perspective(1350px) rotateY(0); }
}

@media (max-width: 699px),
  (pointer: coarse) and (orientation: portrait) and (max-width: 1024px),
  (pointer: coarse) and (max-height: 540px) {
  main:has(.courtBook:not([hidden])) { width: 100%; overflow: clip; }
  .book-story, .book-chapterGuide {
    margin: 0; padding: 0; min-height: 0; max-width: none;
    border: 0; border-radius: 0; box-shadow: none;
    grid-template-columns: minmax(0, 1fr);
  }
  .book-story { background: #152b23; }
  .book-story .plate { position: absolute; inset: 0; border-radius: 0; }
  .book-story .plate::after, .guideLeaf::after, .book-story .folioLine::before { display: none; }
  .book-story .storyCopy {
    display: block; align-self: end; color: #fff2d7;
    max-height: calc(100% - var(--safe-t) - 54px); overflow-y: auto;
    background: none; padding: 14px max(20px, var(--safe-r)) calc(6px + var(--safe-b)) max(20px, var(--safe-l));
  }
  .book-story .folioLine { margin-bottom: 8px; }
  .book-story .chapter { color: #f1cf92; }
  .book-story .storyCopy h1 { font-size: clamp(28px, 8vw, 46px); }
  .book-story .storyCopy p { margin: 9px 0 14px; max-width: 43ch; }
  .swipeCue { display: inline-flex; align-items: center; gap: 6px; color: #f5dfaf; font-size: 12px; font-weight: 500; white-space: nowrap; letter-spacing: .025em; }
  .swipeCue svg { width: 25px; height: 15px; }
  .folioLine { justify-content: space-between; }
  .book-story .storyFoot { position: static; color: #efe4ca; margin-top: 8px; border-top: 1px solid #d5be8a55; }
  .storyFoot .textButton { color: inherit; }
  .book-chapterGuide {
    background: radial-gradient(ellipse at 55% 48%, #fffaf0, #eee3ca);
    display: grid;
    grid-template-areas: "cover" "pitch" "demo" "route";
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 5px;
    padding-bottom: calc(var(--safe-b) + 8px);
  }
  .book-chapterGuide .guideLeaf, .book-chapterGuide .guideInside { display: contents; }
  .book-chapterGuide .guideCover { grid-area: cover; height: clamp(106px, 22dvh, 210px); min-height: calc(var(--safe-t) + 105px); }
  .book-chapterGuide :is(.guideFigure,.guideRoute,.guidePitch) { margin-inline: calc(var(--safe-l) + 12px) calc(var(--safe-r) + 12px); }
  .book-chapterGuide .guidePitch { margin-block: 1px 0; }
  .book-chapterGuide .guideFigure { padding: 0; }
  .book-chapterGuide .book-guideBoard { width: 100%; }
  .book-chapterGuide .book-guideLevels button { min-height: 45px; padding: 3px 2px; }
  .guideActions {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.65fr);
    gap: 8px; margin-block: 3px;
  }
  .guideActions .book-enterStage, .guideActions .book-guideReplay {
    position: static; width: 100%; min-height: 54px; margin: 0;
    padding: 7px 10px; border-radius: 11px;
  }
  .guideActions .book-enterStage { font-size: 16px; }
  .guideActions .book-guideReplay { font-size: 13px; }
  .book-chapterGuide .guideRoute { gap: 6px; }
  .guideFolio { gap: 9px; flex-wrap: wrap; }
  .guideFolio .swipeCue { font-size: 10px; gap: 4px; }
  .guideFolio .swipeCue svg { width: 17px; height: 12px; }
}
@media (orientation: landscape) and (max-height: 540px) and (pointer: coarse),
  (orientation: landscape) and (max-height: 540px) and (max-width: 699px) {
  .book-chapterGuide { grid-template-columns: 1fr 1.15fr; grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "cover cover" "demo pitch" "demo route"; }
  .book-chapterGuide .guideCover { height: calc(var(--safe-t) + 92px); min-height: 0; }
  .book-chapterGuide .guideHeading { align-self: center; margin-left: calc(var(--safe-l) + 98px); max-width: calc(100% - 250px); }
  .book-chapterGuide .book-guideLevels button { min-height: 35px; }
  .book-story .storyFoot { margin-top: 0; }
}

.bookViewport {
  position: absolute; inset: 0; z-index: 2; overflow: hidden; contain: strict;
  isolation: isolate; pointer-events: none; user-select: none;
}
.bookTrack { display: flex; width: 200%; height: 100%; will-change: transform; }
.bookTrack > .courtBook {
  position: relative; inset: auto; flex: 0 0 50%; width: 50%; height: 100%; min-width: 0;
}
.storyCopy { touch-action: pan-y pinch-zoom; }
