:root {
  color-scheme: light;
  --paper: #f6f3ed;
  --ink: #24211e;
  --muted: #6d635a;
  --rule: #d8d0c4;
  --accent: #ad3526;
  font-family: system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body { margin: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; font: inherit; cursor: pointer; }
a { color: inherit; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.masthead {
  min-height: 76px;
  padding: 12px clamp(16px, 4vw, 64px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--rule);
}
.wordmark {
  justify-self: start;
  font: 500 clamp(22px, 3vw, 34px)/1.05 Georgia, serif;
  letter-spacing: -.055em;
  text-decoration: none;
  white-space: nowrap;
}
.wordmark i { color: var(--accent); font-size: .78em; margin-inline: .08em; }
.edition, .index-button, figcaption, .counter {
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 650;
}
.edition { color: var(--muted); }
.edition b { margin-inline: .5em; color: var(--accent); }
.index-button {
  justify-self: end;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 4px;
}
.index-button:hover, .close:hover { background: #eae3d7; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.index-button svg { width: 17px; height: 17px; }
.reader {
  padding: clamp(18px, 3vh, 34px) clamp(12px, 4vw, 64px) 14px;
  display: grid;
  justify-items: center;
}
.stage {
  width: 100%;
  min-height: max(145px, min(68svh, calc(100svh - 210px)));
  display: grid;
  place-items: center;
  touch-action: pan-y pinch-zoom;
}
.book {
  --leaf-width: min(68vw, 820px, calc(max(100px, 100svh - 250px) * 4 / 3));
  position: relative;
  display: flex;
  isolation: isolate;
  perspective: 1900px;
}
.book:is(.spread, .wide) { --leaf-width: min(46vw, 730px, calc(max(100px, 100svh - 250px) * 4 / 3)); }
.leaf { flex: none; width: var(--leaf-width); margin: 0; }
.wide .leaf { width: calc(2 * var(--leaf-width)); }
.leaf a, .turning {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #e6dfd3;
  box-shadow: 0 7px 22px #392c2521, 0 1px 3px #392c2533;
}
.leaf a { cursor: zoom-in; }
.wide .leaf a { aspect-ratio: 8 / 3; }
.leaf img, .turning img { width: 100%; height: 100%; object-fit: contain; display: block; }
.spread .leaf:first-child a { box-shadow: -4px 7px 18px #392c2524; }
.spread .leaf:last-of-type a { box-shadow: 4px 7px 18px #392c2524; }
.spread::after {
  content: "";
  position: absolute;
  left: calc(50% - 9px);
  top: 0;
  bottom: 29px;
  width: 18px;
  background: linear-gradient(90deg, transparent, #30282026 49%, #30282040 50%, #fff2 56%, transparent);
  pointer-events: none;
}
figcaption { display: grid; place-items: end center; height: 29px; color: var(--muted); }
.controls { display: grid; grid-template-columns: 48px minmax(116px, auto) 48px; align-items: center; margin-top: 10px; }
.turn, .close {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 50%;
}
.turn:not(:disabled):hover { color: white; background: var(--accent); border-color: var(--accent); }
.turn:disabled { opacity: .42; }
.counter { text-align: center; font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; text-align: center; }
.turning {
  position: absolute;
  z-index: 2;
  top: 0;
  width: var(--leaf-width);
  pointer-events: none;
  backface-visibility: hidden;
}
.turning.forward { right: 0; transform-origin: left center; animation: turn-forward .44s ease-in forwards; }
.turning.backward { left: 0; transform-origin: right center; animation: turn-backward .44s ease-in forwards; }
.book.arriving { animation: arrive .28s ease-out; }
@keyframes turn-forward { to { transform: rotateY(-100deg); opacity: 0; } }
@keyframes turn-backward { to { transform: rotateY(100deg); opacity: 0; } }
@keyframes arrive { from { opacity: .52; } }
dialog {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 8px;
  max-height: 90svh;
  padding: 0;
  box-shadow: 0 14px 60px #1c15174a;
}
dialog::backdrop { background: #241e1acf; }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule);
}
.dialog-head h1, .dialog-head h2 { margin: 0; font: 500 24px/1.2 Georgia, serif; }
.close { width: 44px; height: 44px; font-size: 24px; }
#page-index { width: min(760px, 92vw); }
#page-index[open] { display: flex; flex-direction: column; }
.index-grid { overflow: auto; padding: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(97px, 1fr)); gap: 8px; }
.index-grid button { min-height: 44px; border: 1px solid var(--rule); background: transparent; border-radius: 4px; }
.index-grid button:hover, .index-grid button[aria-current] { background: #ede2d6; border-color: var(--accent); }
#zoom { max-width: 94vw; }
#zoom-image { display: block; max-width: 100%; max-height: calc(90svh - 71px); margin: auto; object-fit: contain; }
@media (max-width: 630px) {
  .masthead { grid-template-columns: 1fr auto; min-height: 64px; gap: 8px; }
  .edition { display: none; }
  .book { --leaf-width: min(88vw, calc(max(100px, 100svh - 210px) * 4 / 3)); }
  .book:is(.spread, .wide) { --leaf-width: min(46vw, calc(max(100px, 100svh - 210px) * 4 / 3)); }
  .stage { min-height: max(155px, min(59svh, calc(100svh - 170px))); }
}
@media (max-height: 480px) and (orientation: landscape) {
  .masthead { min-height: 56px; padding-block: 4px; }
  .reader { padding-top: 8px; }
  .book, .book:is(.spread, .wide) { --leaf-width: min(46vw, calc(max(100px, 100svh - 177px) * 4 / 3)); }
  .stage { min-height: 0; }
  .hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}
