body[data-view="reader"] {
  background: #e5ddd0;
}

:root[data-theme="light"] body[data-view="reader"] { background: #e9e8e5; }
:root[data-theme="dark"] body[data-view="reader"] { background: #201e24; }

body[data-view="reader"] .app-frame {
  width: 100%;
  border-radius: 0;
  background: transparent;
}

.reader-view {
  --reader-paper: #f6eddd;
  --reader-paper-end: #fffaf0;
  --reader-desk: #e7ddce;
  --reader-desk-edge: #c6b9a7;
  --reader-board: #352922;
  --reader-gold: #745436;
  --reader-gutter: rgb(72 45 28 / .23);
  --reader-edge: #d6c3a7;
  --reader-text-color: #33271f;
  background: radial-gradient(ellipse at 47% 22%, var(--reader-paper-end), var(--reader-desk) 66%, var(--reader-desk-edge) 112%);
  color: var(--reader-text-color);
}

.reader-view[data-reader-theme="light"] {
  --reader-paper: #fbfaf7;
  --reader-paper-end: #fff;
  --reader-desk: #e9e8e5;
  --reader-desk-edge: #c8c6c2;
  --reader-edge: #d9d8d2;
  --reader-gutter: rgb(44 41 37 / .19);
  --reader-text-color: #292524;
}

.reader-view[data-reader-theme="dark"] {
  --reader-paper: #29282d;
  --reader-paper-end: #333137;
  --reader-desk: #201e24;
  --reader-desk-edge: #151416;
  --reader-board: #141217;
  --reader-gold: #d0ac78;
  --reader-gutter: rgb(8 6 7 / .55);
  --reader-edge: #403c43;
  --reader-text-color: #f3e7d4;
}

.reader-top {
  justify-content: space-between;
  width: min(100%, 1220px);
  align-self: center;
  padding-block: 20px;
}

.reader-back { font-size: 14px; }
.reader-top-actions { display: flex; align-items: center; gap: clamp(9px, 2.2vw, 24px); }
.reader-preview-label { opacity: 1; color: var(--reader-gold); }
.reader-cover-link {
  border: 1px solid currentColor;
  border-radius: 999px;
  background: transparent;
  padding: 6px 12px;
  font-size: 12px;
  white-space: nowrap;
}
.reader-cover-link:hover { background: rgb(125 106 80 / .12); }

.reader-desk {
  width: min(100%, 1160px);
  margin-inline: auto;
  padding: clamp(23px, 4.1vh, 47px) clamp(22px, 5.6vw, 84px) 18px;
}

.book-stage {
  --board-height: clamp(410px, calc(100svh - 190px), 570px);
  --cover-width: calc(var(--board-height) * 2 / 3);
  --turn-shadow: 0;
  position: relative;
  width: min(100%, 975px);
  margin-inline: auto;
  min-height: var(--turn-height, 0px);
  perspective: 1250px;
  perspective-origin: 50% 46%;
  touch-action: pan-y;
}

.book-stage::before {
  position: absolute;
  content: '';
  inset: 4px -8px -14px;
  border: 1px solid rgb(0 0 0 / .37);
  border-radius: 9px 9px 12px 12px;
  background: linear-gradient(90deg, #1d1816, var(--reader-board) 46%, #151112 50%, var(--reader-board) 54%, #1d1816);
  box-shadow: 0 9px 10px rgb(38 25 18 / .2), 0 27px 47px -11px rgb(38 25 18 / .46), 0 3px 0 #1c1716;
}

.book-stage.is-closed::before { left: calc(50% - 2px); right: max(-8px, calc(50% - var(--cover-width) - 8px)); }
.book-stage.is-turning::before { left: -8px; right: -8px; }

.book-stage::after {
  position: absolute;
  content: '';
  z-index: 3;
  inset: 3px 0 0;
  background: radial-gradient(ellipse at var(--turn-shadow-x, 50%) 61%, rgb(42 28 18 / var(--turn-shadow)), transparent 67%);
  pointer-events: none;
}

.book-spread, .book-spread-next {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: var(--board-height);
  isolation: isolate;
}
.book-spread-next { z-index: 2; position: absolute; inset: 0; pointer-events: none; }
.book-spread-next .book-leaf { min-height: 100%; }
.book-stage.is-turning .book-spread .book-leaf:not(.is-lifted) { z-index: 3; }
.book-stage.is-turning .book-spread .is-lifted { opacity: 0; }
.book-stage.is-turning .book-spread { z-index: 3; }
.book-stage.is-turning.is-closed .book-cover-intro { visibility: hidden; }
.book-spread-next .book-cover-intro { visibility: hidden; }

.book-leaf {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: var(--board-height);
  padding: clamp(27px, 4vh, 54px) clamp(21px, 3.6vw, 50px) 49px;
  border-radius: 3px 4px 4px 3px;
  background-color: var(--reader-paper);
  box-shadow: inset 0 1px 0 rgb(255 248 230 / .28), 0 1px 0 rgb(48 35 28 / .26), 0 2px 0 var(--reader-edge), 0 3px 0 rgb(48 35 28 / .29), 0 4px 0 var(--reader-edge), 0 5px 0 rgb(48 35 28 / .29), 0 6px 0 var(--reader-edge), 0 7px 0 rgb(48 35 28 / .29), 0 8px 0 var(--reader-edge);
}
.book-leaf--left {
  border-radius: 6px 2px 3px 7px / 6px 6px 14px 6px;
  background-image: linear-gradient(90deg, var(--reader-paper) 1%, var(--reader-paper-end) 8%, var(--reader-paper) 89%, var(--reader-gutter));
}
.book-leaf--right {
  border-radius: 2px 6px 7px 3px / 6px 6px 6px 14px;
  background-image: linear-gradient(90deg, var(--reader-gutter), var(--reader-paper) 11%, var(--reader-paper-end) 93%, var(--reader-paper));
}

.book-leaf .chapter { max-width: 38ch; line-height: 1.48; }
.book-leaf .chapter h2 { font-family: var(--book-font); font-size: 1.65em; line-height: 1.12; margin-block: 8px 20px; overflow-wrap: anywhere; }
.leaf-kicker {
  font-family: var(--body-font);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--reader-gold);
}
.leaf-illustration {
  margin-block-start: 18px;
  width: 100%;
  max-height: 145px;
  aspect-ratio: 16 / 7;
  object-fit: cover;
  object-position: center 40%;
  border-radius: 2px;
  user-select: none;
}
.leaf-illustration { display: none; }

.book-endpaper.has-plate { padding: clamp(18px, 3.6vw, 42px); }
.endpaper-plate { min-height: 0; flex: 1; position: relative; overflow: hidden; border-radius: 2px; }
.endpaper-plate img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 48% center; }
.endpaper-plate::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 22px rgb(26 20 17 / .42); }

.book-leaf .folio { font-size: 13px; left: 50%; bottom: 20px; transform: translateX(-50%); color: var(--reader-gold); }

.book-endpaper { padding: 21px; }
.endpaper-inset {
  flex: 1;
  min-height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--reader-gold);
  border: 1px solid rgb(142 113 78 / .32);
  outline: 1px solid rgb(142 113 78 / .23);
  outline-offset: -6px;
  background: repeating-linear-gradient(135deg, rgb(141 112 78 / .05) 0 1px, transparent 1px 13px);
}
.endpaper-inset > div { background: var(--reader-paper); border: 1px solid rgb(142 113 78 / .32); margin: 20px; padding: clamp(12px, 2.6vw, 36px); }
.endpaper-inset .icon { margin-inline: auto; margin-block-end: 10px; }
.endpaper-inset p { font-family: var(--book-font); font-size: clamp(20px, 2.4vw, 34px); line-height: 1.15; }
.endpaper-inset span { display: block; font-size: 11px; margin-block-start: 12px; }

.book-cover-intro {
  align-self: center;
  margin-inline: clamp(8px, 6vw, 92px) clamp(21px, 3vw, 51px);
}
.book-cover-intro h1 { font-family: var(--book-font); font-size: clamp(36px, 5.2vw, 76px); line-height: 1.03; margin: 12px 0 16px; }
.book-cover-intro > p:not(.leaf-kicker) { font-size: 15px; }
.book-board {
  padding: 0;
  background: var(--reader-board);
  justify-self: start;
  width: min(100%, var(--cover-width));
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 5px 7px 7px 4px;
}
.book-board .cover-face { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: inherit; }
.reader-open {
  margin-block-start: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 9px 17px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: #342b26;
  color: #fff8e9;
  font-weight: 650;
  font-size: 13px;
}
.reader-open:hover { background: #544239; }
.reader-view[data-reader-theme="dark"] .reader-open { background: #e7c891; color: #2d241d; }
.reader-open .icon { width: 17px; height: 17px; }
.reader-open--mobile, .reader-mobile-heading { display: none; }

.book-corner {
  position: absolute;
  z-index: 8;
  bottom: 3px;
  display: grid;
  place-items: end center;
  width: 52px;
  height: 62px;
  padding-block-end: 8px;
  border: 0;
  color: var(--reader-gold);
  background: transparent;
  touch-action: none;
  cursor: grab;
}
.book-corner:active { cursor: grabbing; }
.book-corner .icon { width: 18px; height: 18px; }
.book-corner--next { right: 0; border-radius: 0 0 5px 0; }
.book-corner--previous { left: 0; border-radius: 0 0 0 5px; }
.book-corner::before {
  content: '';
  position: absolute;
  inset: auto 0 0 auto;
  width: 23px;
  height: 21px;
  border-radius: 2px;
  background: linear-gradient(135deg, transparent 47%, rgb(126 89 47 / .22) 49%, rgb(181 158 127 / .34) 65%, transparent 90%);
  transition: width 160ms ease, height 160ms ease;
}
.book-corner--previous::before { left: 0; right: auto; transform: scaleX(-1); }
.book-corner:hover::before, .book-corner:focus-visible::before { width: 34px; height: 32px; }
.is-closed .book-corner { color: #fff7e5; }

.turning-sheet {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  transform-style: preserve-3d;
}
.paper-strip {
  position: absolute;
  height: 100%;
  transform-origin: 0 50%;
  transform-style: preserve-3d;
}
.turn-surface {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.turn-surface--back { transform: rotateY(180deg); }
.turn-surface::after { content: ''; position: absolute; inset: 0; background: rgb(30 18 10 / var(--paper-shade, 0)); }
.turn-surface .book-leaf {
  position: absolute;
  top: 0;
  left: calc(-1 * var(--turn-print-offset));
  width: var(--turn-print-width);
  min-height: 100%;
  height: 100%;
  box-shadow: none;
}

.reader-page-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 23px;
  width: min(100%, 975px);
  margin-inline: auto;
  margin-block-start: 25px;
  color: var(--reader-gold);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.reader-mobile-counter, .reader-swipe-hint { display: none; }
.reader-tools {
  margin: auto auto max(16px, env(safe-area-inset-bottom));
  width: min(calc(100% - 24px), 650px);
}
.reader-page-button:disabled { visibility: visible; opacity: .4; cursor: default; }
.reader-page-button:disabled:hover { background: var(--dark-button); }
.reader-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 760px) {
  .reader-top { min-height: 50px; padding-block: 10px; }
  .reader-desk { max-width: 500px; padding: 21px 17px 15px; }
  .book-stage { --board-height: 465px; width: 100%; perspective: 950px; }
  .book-stage::before, .book-stage.is-closed::before, .book-stage.is-turning::before { left: -5px; right: -5px; bottom: -11px; }
  .book-spread, .book-spread-next { grid-template-columns: minmax(0, 1fr); }
  .book-stage.is-closed { --board-height: 0px; }
  .book-spread > .book-leaf:not(.is-current), .book-spread-next > .book-leaf:not(.is-current), .book-cover-intro { display: none; }
  .book-leaf { padding: 29px clamp(21px, 6.3vw, 42px) 52px; }
  .book-board { width: 100%; padding: 0; }
  .reader-mobile-heading { display: block; }
  .reader-open--mobile { display: flex; margin: 26px auto 0; }
  .reader-mobile-counter, .reader-swipe-hint { display: inline; }
  .reader-spread-counter, .reader-turn-hint { display: none; }
  .reader-page-caption { margin-block-start: 20px; }
  .book-leaf .leaf-illustration { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  .book-corner::before { transition: none; }
}
