*{box-sizing:border-box}body{margin:0;background:white;color:#111;font-family:Arial,sans-serif}button{font:inherit}button:focus-visible{outline:2px solid #007d91;outline-offset:2px}.reader{margin:auto;width:100%}[hidden]{display:none!important}
.reader { max-width: 1500px; text-align: center; }
.reader h1 { font-size: clamp(24px, 4vw, 38px); }
.stage { overflow: auto; padding: clamp(24px, 3vw, 58px) clamp(18px, 4.5vw, 86px); min-height: 220px; touch-action: pan-y; }
.stage.zoomed { width: 100%; min-width: 0; height: 68vh; height: 68dvh; min-height: 0; overflow: auto; overscroll-behavior: contain; cursor: grab; touch-action: none; user-select: none; }
.zoomed .book { margin-inline: 0; flex-wrap: nowrap; }
.zoomed .sheet { flex-shrink: 0; }
.stage.dragging { cursor: grabbing; }
.book { position: relative; display: flex; justify-content: center; margin-inline: auto; perspective: 1600px; transform-style: preserve-3d; }
.sheet { position: relative; width: 50%; min-width: 0; box-shadow: 0 3px 12px #0003; }
.sheet canvas { display: block; width: 100%; height: auto; }
.sheet:first-child { transform-origin: right center; }
.sheet:last-child { transform-origin: left center; }
.sheet:only-child { transform-origin: center; }
.turn { position: absolute; top: 0; height: 100%; width: 50%; z-index: 2; transform-style: preserve-3d; pointer-events: none; }
.turn.forward { left: 50%; }
.turn.backward { right: 50%; }
.turn-strip { position: absolute; top: 0; height: 100%; transform-style: preserve-3d; }
.turn-strip canvas { position: absolute; inset: 0; width: 100%; height: 100%; backface-visibility: hidden; filter: brightness(var(--paper-light, 1)); }
.turn-strip canvas + canvas { transform: rotateY(180deg); }
.reader-frame { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; }
.side-arrow { border: 0; border-radius: 50%; background: #eee; color: #333; min-height: 44px; font: 38px/1 Arial, sans-serif; cursor: pointer; }
.side-arrow:disabled { opacity: .35; cursor: default; }
.page-corner { position: absolute; bottom: 0; z-index: 1; width: 48px; height: 48px; border: 0; padding: 0; background: transparent; cursor: grab; touch-action: none; }
.page-corner.next { right: 0; }
.page-corner.prev { left: 0; }
.page-corner::after { content: ""; position: absolute; bottom: 0; right: 0; width: 100%; height: 100%; transform-origin: bottom right; transform: scale(var(--fold, .5)); clip-path: polygon(100% 0, 100% 100%, 0 100%); background: linear-gradient(135deg, #292929 48%, #fff 54%, #b7b7b7); transition: transform 160ms ease-out; }
.page-corner.prev::after { transform-origin: bottom left; transform: scale(var(--fold, .5)); left: 0; right: auto; clip-path: polygon(0 0, 100% 100%, 0 100%); background: linear-gradient(225deg, #292929 48%, #fff 54%, #b7b7b7); }
.page-corner:hover, .page-corner:focus-visible { --fold: .9; }
.page-corner.dragging::after { transition: none; }
.zoomed .page-corner { display: none; }
@media (max-width: 460px) { .reader-frame { grid-template-columns: 36px minmax(0, 1fr) 36px; } }
.toolbar { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 8px; margin: 12px auto; }
.toolbar button { min-height: 44px; padding: 8px 14px; border: 1px solid #ccc; border-radius: 5px; background: white; cursor: pointer; }
.toolbar button:disabled { opacity: .45; cursor: default; }
.reader:fullscreen { background: white; overflow: auto; }
@media (max-width: 760px) { .stage { padding: 12px 0; } }

html, body { width: 100%; height: 100%; overflow: hidden; }
.reader, .reader:fullscreen {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.reader #status { flex: none; margin: 0; }
.reader #status:not(:empty) { padding: 12px; }
.reader-frame { flex: 1; min-height: 0; width: 100%; }
.stage, .stage.zoomed {
    height: 100%;
    min-height: 0;
    max-height: none;
    min-width: 0;
    padding: 16px 24px;
}
.stage { overflow: hidden; }
.stage.zoomed { overflow: auto; }
.book { margin: auto; }
.sheet { flex-shrink: 0; }
.toolbar { flex: none; margin: 0; padding: 8px; gap: 6px; }
.toolbar button { min-height: 44px; }
@media (max-width: 600px) {
    .stage, .stage.zoomed { padding: 10px 4px; }
    .toolbar button { padding: 6px 10px; }
}

/* Panning remains available without displaying an inner scrollbar. */
.stage, .stage.zoomed { scrollbar-width: none; -ms-overflow-style: none; }
.stage::-webkit-scrollbar { display: none; width: 0; height: 0; }
.reader { position: relative; }
.reader-frame { display: block; position: relative; }
.stage, .stage.zoomed { width: 100%; padding: 20px 60px; }
.reader-frame > .side-arrow { position: absolute; top: 50%; transform: translateY(-50%); z-index: 4; width: 44px; background: #ffffffb3; }
#side-prev { left: 4px; }
#side-next { right: 4px; }
.toolbar { position: relative; z-index: 5; background: #fffffff0; box-shadow: 0 1px 9px #0002; border-radius: 5px; align-self: center; margin: 4px 8px 8px; }
.reader:fullscreen { background: #282a2c; }
@media (max-width: 600px) {
    .stage, .stage.zoomed { padding: 12px 34px; }
    .reader-frame > .side-arrow { width: 30px; min-width: 30px; }
}

.stage { touch-action: none; }
@media (max-width: 600px) {
    .toolbar { flex-wrap: nowrap; gap: 3px; padding: 6px 4px; max-width: calc(100% - 8px); }
    .toolbar button { padding: 6px 8px; flex: none; font-size: 14px; }
    #counter { white-space: nowrap; font-size: 13px; }
    #full { font-size: 0; }
    #full::after { content: "⛶"; font-size: 24px; }
    .stage, .stage.zoomed { padding: 12px 22px; }
}

/* Center the page and keep reading controls above the zoomed content. */
.reader { position: relative; }
.reader-frame { flex: none; width: 100%; height: 100%; }
.stage, .stage.zoomed { padding-bottom: 78px; }
.toolbar {
    position: absolute;
    top: var(--toolbar-top, auto);
    bottom: auto;
    left: 50%;
    transform: translateX(-50%);
    align-self: auto;
    margin: 0;
    z-index: 20;
    white-space: nowrap;
}
.reader:fullscreen .toolbar {
    top: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
}
.reader:fullscreen .stage,
.reader:fullscreen .stage.zoomed { padding-bottom: 80px; }
@media (max-width: 600px) {
    .stage, .stage.zoomed { padding-bottom: 72px; }
    .toolbar { width: max-content; max-width: calc(100% - 12px); }
}

.toolbar #full { font-size: 24px; line-height: 1; min-width: 44px; }
.toolbar #full::after { content: none; }
