:root {
  font-family: Arial, Helvetica, sans-serif;
  color: #292525;
  background: #fff9f6;
}
* { box-sizing: border-box; }
body { margin: 0; }
.wrap { max-width: 1480px; margin: auto; padding: 20px 24px 40px; }
header, .actions, .controls, .zoom-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem;
}
header { justify-content: space-between; gap: 1rem; margin-bottom: 22px; }
h1 { font-size: clamp(1.5rem, 3vw, 2.125rem); margin: 0 0 5px; }
header p, .hint { color: #594641; }
header p { margin: 0; line-height: 1.45; }
.btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  border: 1px solid #a2756d;
  border-radius: 9px;
  padding: .5rem .85rem;
  background: white;
  color: #342c29;
  font: 700 .875rem/1.3 Arial, Helvetica, sans-serif;
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: #ad392b; color: white; border-color: #ad392b; }
.btn[aria-disabled="true"] { background: #f5ebe7; color: #665650; border-color: #b89b91; cursor: default; }
:focus-visible { outline: 3px solid #174b65; outline-offset: 3px; }
.stage {
  background: #f4e2dc;
  border-radius: 18px;
  padding: 24px;
  display: grid;
  justify-items: center;
}
.book {
  --page-width: clamp(220px, calc((100dvh - 240px) * .707), 575px);
  width: min(100%, var(--page-width));
  position: relative;
  perspective: 1800px;
}
.book.pair { width: min(100%, calc(2 * var(--page-width))); }
.spread { display: flex; box-shadow: 0 10px 12px #6e3e3524; }
.page {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  padding: 0;
  background: #f5e1da;
  cursor: zoom-in;
}
.page:focus-visible { position: relative; z-index: 2; }
.page img { display: block; width: 100%; height: auto; }
.controls { justify-content: center; margin: 16px 0 8px; }
#count { font-weight: 700; font-size: .875rem; text-align: center; }
.hint { margin: 0; text-align: center; font-size: .875rem; line-height: 1.5; }
.leaf {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  transform-origin: left center;
  animation: turn-forward .55s ease-in-out both;
}
.leaf.right { left: 50%; }
.leaf.left { right: 50%; }
.leaf.backward { transform-origin: right center; animation-name: turn-backward; }
.leaf img { display: block; width: 100%; height: 100%; object-fit: contain; }
.leaf.full-turn {
  transform-style: preserve-3d;
  animation-name: full-forward;
}
.leaf.full-turn.backward { animation-name: full-backward; }
.leaf.full-turn img { position: absolute; inset: 0; backface-visibility: hidden; }
.leaf.full-turn img + img { transform: rotateY(180deg); }
@keyframes full-forward { from { transform: rotateY(0); } to { transform: rotateY(-180deg); } }
@keyframes full-backward { from { transform: rotateY(0); } to { transform: rotateY(180deg); } }
@keyframes turn-forward { 0% { transform: rotateY(0); } 100% { transform: rotateY(-90deg); } }
@keyframes turn-backward { 0% { transform: rotateY(0); } 100% { transform: rotateY(90deg); } }
dialog {
  width: min(960px, calc(100% - 16px));
  max-width: none;
  max-height: calc(100dvh - 16px);
  padding: 0;
  border: 1px solid #a2756d;
  border-radius: 12px;
  color: inherit;
  background: #fff9f6;
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: #1c1615e8; }
.zoom-bar { padding: 12px; justify-content: space-between; }
.zoom-bar h2 { font-size: 1rem; margin: 0; }
.zoom-view { overflow: auto; min-height: 0; background: #f4e2dc; }
.zoom-view:focus-visible { outline-offset: -3px; }
.zoom-view img { display: block; height: auto; margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.text-content { max-width: 42rem; margin: auto; line-height: 1.6; overflow-wrap: anywhere; }
.text-content section { border-top: 1px solid #a2756d; padding-block: 1rem; }
.text-content h2 { margin: 0; font-size: 1.25rem; }
.text-content .byline { margin-top: .25rem; }
.text-content a { color: #174b65; }
@media (max-width: 720px) {
  .wrap { padding: 14px 12px 24px; }
  .stage { padding: 12px; }
  .book { width: min(100%, 450px); }
}
@media (prefers-reduced-motion: reduce) { .leaf { display: none; } }
