/* ───────── Читалка-книга: страницы одного размера, перелистывание ───────── */
@property --shade { syntax: '<number>'; inherits: true; initial-value: 0; }

.reader.book { width: 100%; max-width: 860px; gap: 12px; padding-top: 10px; scroll-margin-top: calc(var(--bar-h) + 52px); }
@media (max-width: 899px) { .reader.book { scroll-margin-top: calc(var(--bar-h) + 4px); padding-top: 8px; gap: 10px; } }
.book .reader-top { min-height: 38px; }
.book .reader-t { transition: opacity .25s; }
.book.is-first .reader-t { opacity: 0; visibility: hidden; }

/* сцена: стопки страниц по краям рисует JS через box-shadow */
.book-stage { position: relative; width: var(--stage-w, var(--pg-w, 100%)); height: var(--pg-h, 70vh); max-width: 100%; margin: 0; perspective: 3600px; perspective-origin: 20% 50%; border-radius: 2px 4px 4px 2px; background: var(--paper-2); touch-action: pan-y; transition: box-shadow .35s; }
.book-stage > .pg { position: absolute; inset: 0; }
.book-stage > .pg:not(.is-cur) { pointer-events: none; }
.book-stage > .pg.is-cur { z-index: 2; }
.book-stage > .pg.is-under { z-index: 1; }
.book-stage > .pg.is-over, .book-stage > .pg.turn-out, .book-stage > .pg.is-drag { z-index: 3; }

/* страница */
.leaf.pg { width: var(--pg-w); max-width: 100%; height: var(--pg-h); display: flex; flex-direction: column; overflow: hidden auto; overscroll-behavior: contain; touch-action: pan-y; scrollbar-width: thin; padding: 36px clamp(22px, 4.6vw, 50px) 40px; border-radius: 2px 4px 4px 2px; box-shadow: none; transform-origin: left center; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.leaf.pg > * { flex: none; }
.leaf.pg.is-measure { position: static; height: auto; overflow: visible; }
.book-measure { position: fixed; left: -12000px; top: 0; width: var(--pg-w); visibility: hidden; pointer-events: none; contain: layout style; }
.leaf.pg::before { content: ''; position: absolute; inset: 0; z-index: 6; pointer-events: none; background: linear-gradient(90deg, rgba(20,14,6,.05), rgba(20,14,6,.42)); opacity: var(--shade); }
.pg-spine { position: absolute; left: 0; top: 0; bottom: 0; width: 26px; pointer-events: none; background: linear-gradient(90deg, rgba(70,45,15,.2), rgba(70,45,15,.06) 40%, transparent); }

/* шапка первой страницы главы */
.pg .leaf-head { margin-bottom: 18px; gap: 4px; }
.pg .leaf-ch { letter-spacing: .24em; }

/* арт листовки: растёт первым и забирает пустоту до своего предела */
.leaf.pg > .leaf-art, .leaf.pg > .pg-art { flex: 1000 1 var(--art-min); min-height: var(--art-min); max-height: var(--art-max); aspect-ratio: auto; margin: 0 0 20px; }
.pg-art.is-ph { height: var(--art-min); }

/* текст: книжный набор, разрез между страницами без «буквицы» на продолжении */
.pg .b-text { hyphens: auto; -webkit-hyphens: auto; }
.pg .leaf-body > .b-text.is-cont:first-child::first-letter { float: none; font: inherit; color: inherit; padding: 0; }
.pg .b-say.is-cont { grid-template-columns: 1fr; padding-left: 70px; }
.pg .b-say.is-cont .b-say-ava { display: none; }
.pg .b-say.is-cont .b-say-who::after { content: ' · продолжает'; font-weight: 500; color: var(--ink-3); letter-spacing: .08em; }
.pg .b-say.is-cont p::before { content: none; }

/* заполнитель пустоты */
.leaf.pg > .pg-fill { flex: 1 1 0; min-height: 0; container-type: size; display: grid; }
.pg-fill:empty { container-type: normal; }
.fill { width: 100%; height: 100%; min-height: 0; display: grid; place-items: center; padding-top: 16px; }
.fill--pic { grid-template-rows: minmax(0, 1fr) auto; gap: 8px; align-content: stretch; }
.fill-pic { width: min(100%, 150cqh); height: 100%; min-height: 0; border: 3px solid var(--ink); box-shadow: 6px 6px 0 rgba(29,25,20,.18); rotate: var(--tilt, 0deg); justify-self: center; }
.fill-pic img { filter: contrast(1.03) saturate(.92) sepia(.08); }
.fill-cap { font: 600 12px var(--f-label); letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); padding: 3px 10px; background: rgba(236,222,180,.7); box-shadow: 0 1px 2px rgba(0,0,0,.15); rotate: -1deg; }
.fill--sticker { padding: 0; grid-template: minmax(0, 1fr) / minmax(0, 1fr); }
.fill--sticker img {
  display: block; width: min(78%, 248px); height: min(86cqh, 184px);
  object-fit: contain; filter: drop-shadow(0 2px 1px rgba(55, 35, 20, .22));
}
.fill--sticker.is-small img { height: min(86cqh, 48px); }

/* уголок «перевернуть» */
.pg-corner { position: absolute; right: 0; bottom: 0; z-index: 5; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 0; cursor: pointer; background: linear-gradient(315deg, var(--night) 0 49%, #b9a479 50%, #e9dbb9 58%, #f3e7cd 70%); box-shadow: -2px -2px 5px rgba(29,25,20,.18); clip-path: polygon(100% 0, 100% 100%, 0 100%); transition: width .2s, height .2s; }
.pg-corner::after { content: ''; position: absolute; right: 7px; bottom: 7px; width: 9px; height: 9px; border-right: 2px solid var(--cream-on-night); border-bottom: 2px solid var(--cream-on-night); rotate: -45deg; opacity: .8; }
.pg-corner:hover { width: 58px; height: 58px; }
.pg.is-tall .pg-corner, .pg--end .pg-corner { display: none; }

/* последняя страница выпуска */
.leaf.pg.pg--end { display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 14px; text-align: center; }
.pg-end-art { flex: 1 1 0; min-height: 0; max-height: 44%; width: 100%; border: 3px solid var(--ink); box-shadow: 6px 6px 0 rgba(29,25,20,.18); rotate: -.4deg; }
.pg--end > .stamp { margin-top: 6px; }

/* перелистывание */
.pg.turn-out { animation: pg-out .76s cubic-bezier(.45,.05,.3,1) forwards; }
.pg.turn-in { animation: pg-in .76s cubic-bezier(.45,.05,.3,1) both; }
.pg.is-drag { transition: none !important; }
.pg.is-fade { animation: pg-fade .25s ease both; }
@keyframes pg-out { to { transform: rotateY(-118deg); --shade: 1; } }
@keyframes pg-in { from { transform: rotateY(-118deg); --shade: 1; } to { transform: none; --shade: 0; } }
@keyframes pg-fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pg.turn-out, .pg.turn-in { animation: none; } }

@media (max-width: 640px) {
  .leaf.pg { padding: 26px 18px 30px; font-size: 17px; line-height: 1.6; }
  .leaf.pg::after { inset: 9px; }
  .pg .b-say.is-cont { padding-left: 54px; }
  .pg-spine { width: 14px; }
  .book .reader-top { gap: 8px; }
  .book .reader-back span { display: none; }
  .book .reader-t b { font-size: 18px; }
  .book .reader-clock { display: none; }
}

/* длинная страница (анкета, большая загадка на телефоне) листается внутри */
.leaf.pg > .pg-more { position: sticky; bottom: -1px; z-index: 4; align-self: stretch; margin: -14px -4px 0; padding: 16px 4px 0; line-height: 14px; text-align: right; font: 600 11px var(--f-label); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); background: linear-gradient(rgba(243,231,205,0), var(--paper) 60%); pointer-events: none; }

/* книга + закладки листания по бокам */
.book-row { display: grid; grid-template-columns: 72px var(--stage-w, var(--pg-w, 100%)) 72px; grid-template-areas: "prev stage next" ". foot ."; justify-content: center; align-items: center; column-gap: 12px; row-gap: 12px; }
.book-row > .book-stage { grid-area: stage; }
.book-row > .rd-prev { grid-area: prev; justify-self: end; }
.book-row > .rd-next { grid-area: next; justify-self: start; }
.book-foot { grid-area: foot; min-height: 22px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 14px; min-width: 0; }
.book-foot .reader-dots.is-bar { display: block; }
.book-foot .rbar { display: block; height: 4px; background: rgba(241,230,207,.14); }
.book-foot .rtick { width: 9px; height: 9px; border-width: 1.5px; }
.book-foot .rd-count { font: 600 14px var(--f-label); letter-spacing: .06em; text-transform: none; color: var(--muted-on-night); font-variant-numeric: tabular-nums; white-space: nowrap; }

.pgbtn { position: relative; display: grid; justify-items: center; align-content: center; gap: 12px; width: 64px; height: clamp(150px, calc(var(--pg-h, 600px) * .42), 300px); padding: 14px 0; border: 2px solid var(--ink); border-radius: 4px; cursor: pointer;
  color: var(--ink); background: var(--paper) var(--noise); box-shadow: 4px 4px 0 rgba(0,0,0,.35); transition: transform .18s, background-color .18s, opacity .2s; }
.pgbtn-l { writing-mode: vertical-rl; font: 600 13px/1 var(--f-label); letter-spacing: .22em; text-transform: uppercase; }
.rd-prev .pgbtn-l { transform: rotate(180deg); }
.pgbtn.rd-next { color: #fff6e6; background-color: #b53a16; border-color: #6e2108; }
.pgbtn.rd-next.is-skip { color: var(--ink); background-color: var(--paper-2); border-color: var(--ink); }
.pgbtn.rd-next.is-last { background-color: var(--gold); border-color: #5a400c; }
.pgbtn.rd-next.is-must { color: var(--paper); background: var(--night-3); border: 2px dashed var(--ember); cursor: not-allowed; }
.pgbtn.rd-next.is-must .pgbtn-l { color: var(--ember); }
.pgbtn:not(:disabled):hover { transform: translateX(3px); }
.pgbtn.rd-prev:not(:disabled):hover { transform: translateX(-3px); }
.pgbtn:disabled:not(.is-must) { opacity: .28; cursor: default; box-shadow: none; }
.pgbtn:focus-visible { outline: 3px solid var(--frost); outline-offset: 3px; }
.book-row .rd-next[hidden] { display: grid; visibility: hidden; }

.book.is-narrow .book-row { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "stage stage stage" "prev foot next"; column-gap: 10px; row-gap: 10px; }
.book.is-narrow .book-stage { justify-self: center; }
.book.is-narrow .pgbtn { grid-auto-flow: column; width: auto; min-width: 52px; height: 48px; padding: 0 14px; gap: 8px; box-shadow: 3px 3px 0 rgba(0,0,0,.35); }
.book.is-narrow .pgbtn-l { writing-mode: horizontal-tb; transform: none; letter-spacing: .1em; }
.book.is-narrow .rd-prev .pgbtn-l { display: none; }
.book.is-narrow .rd-next .ic { order: 2; }
.book.is-narrow .book-foot { grid-template-columns: 1fr; gap: 6px; justify-items: stretch; text-align: center; min-height: 40px; }
.book.is-narrow .book-foot .reader-dots.is-bar { width: 100%; }

.pg .leaf-body > .b-text.no-cap:first-child::first-letter { float: none; font: inherit; color: inherit; padding: 0; }
.pg .leaf-body > .is-pstart { margin-top: 26px; }
/* узкая страница: пометки рассказчика не в колонку, а между абзацами */
.is-compact .pg .b-narr, .book-measure.is-compact .b-narr { float: none; width: auto; margin: 12px 0 12px 10px; rotate: -1deg; }
.pg .leaf-art.is-portrait img { object-position: 50% 16%; }

.turn-shade { position: absolute; inset: 0; z-index: 2; pointer-events: none; background: linear-gradient(90deg, rgba(10,6,2,.28), rgba(10,6,2,.08) 45%, transparent 75%); }
.turn-shade.is-out { animation: shade-out .76s cubic-bezier(.45,.05,.3,1) forwards; }
.turn-shade.is-in { animation: shade-out .76s cubic-bezier(.45,.05,.3,1) reverse forwards; }
@keyframes shade-out { from { opacity: 1; clip-path: inset(0 0 0 0); } to { opacity: 0; clip-path: inset(0 0 0 0); } }
.pg.turn-out, .pg.turn-in, .pg.is-drag { box-shadow: 8px 0 24px rgba(0,0,0,.35); background-image: linear-gradient(90deg, transparent 55%, rgba(255,250,235,.35) 80%, rgba(60,40,15,.18)), var(--fibers), var(--noise); }
.leaf.pg:not(.is-tall) > .pg-more, .leaf.pg.is-scrolled-end > .pg-more { display: none; }
/* телефон боком: читалке нужен весь экран — нижние табы прячем на время чтения */
@media (max-height: 520px) and (max-width: 1099px) {
  body.is-reading .tabs { display: none; }
  body.is-reading .topline { position: relative; }
  body.is-reading { padding-bottom: 0; }
  .book .reader-top { min-height: 0; }
  .book .reader-top { display: none; }
}
.is-wide .pg .leaf-body, .book-measure.is-wide .leaf-body { column-count: 2; column-gap: 34px; }
.is-wide .pg .b-narr, .book-measure.is-wide .b-narr { float: none; width: auto; margin: 8px 0 8px 10px; }
.is-wide .leaf.pg { padding-top: 22px; padding-bottom: 22px; font-size: 16px; }
.book-measure.is-wide .leaf.pg { padding-top: 22px; padding-bottom: 22px; font-size: 16px; }
.leaf.pg.pg--end { gap: 10px; }
.pg--end h2 { font-size: clamp(22px, 3.4vw, 34px); }

/* буквица — только в начале сцены (страница с артом или титул главы) */
.pg:not(.has-art):not(.has-head) .leaf-body > .b-text:first-child::first-letter { float: none; font: inherit; color: inherit; padding: 0; }
/* ремарка рассказчика обтекается текстом, только если рядом есть текст; одинокая — на всю ширину */
.pg .b-narr.is-solo { float: none; width: auto; max-width: 560px; margin: 14px auto 14px 6%; }
.pg .b-narr { break-inside: avoid; }
.pg .b-narr.is-long .hand { font-size: 20px; line-height: 1.22; }
.book-foot .rd-count { color: var(--cream-on-night); font-size: 15px; }
.is-large .leaf.pg, .book-measure.is-large .leaf.pg { font-size: 19px; }

/* в читалке подвал сайта не нужен: экран — это книга */
body.is-reading .foot { display: none; }
body.is-reading .shell { padding-bottom: 8px; }
/* анкета внутри страницы — плотнее, чтобы помещалась без прокрутки */
.pg .questionnaire.is-inline { gap: 10px; padding-top: 12px; margin-top: 12px; }
.pg .questionnaire.is-inline .q-h { font-size: 21px; }
.pg .questionnaire.is-inline .q-stamp, .pg .questionnaire.is-inline .q-sign { display: none; }
.pg .questionnaire.is-inline .q-seg { grid-template-columns: 1fr 1fr; gap: 8px; }
.pg .questionnaire.is-inline .q-opt span { padding: 8px 10px; }
.pg .questionnaire.is-inline .q-opt small { font-size: 12px; }
.pg .questionnaire.is-inline .q-animals { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.pg .questionnaire.is-inline .q-an span { padding: 6px 8px; font-size: 14px; }
.pg .questionnaire.is-inline input[type="text"], .pg .questionnaire.is-inline .q-num { height: 40px; }
.pg .questionnaire.is-inline .btn--lg { font-size: 16px; padding: .6em 1.1em; }
.is-wide .pg .leaf-body > .b-text:first-child::first-letter { float: none; font: inherit; color: inherit; padding: 0; }
@container main (min-width: 1180px) { .reader-layout { grid-template-columns: minmax(0, 1fr); } .reader.book { margin: 0 auto; } }

/* ── разворот на широком экране ── */
.reader.book.is-spread { max-width: none; }
.book-stage > .spread { position: absolute; inset: 0; z-index: 2; perspective: 3400px; }
.book-stage > .spread:not(.is-cur) { z-index: 3; pointer-events: none; }
.book-stage > .spread.is-under { z-index: 1; }
.spread > .pg { position: absolute; top: 0; width: var(--pg-w); height: var(--pg-h); }
.spread > .pg.is-left { left: 0; border-radius: 4px 0 0 4px; }
.spread > .pg.is-right { left: var(--pg-w); border-radius: 0 4px 4px 0; }
.spread > .pg.is-left .pg-spine, .flipper > .pg.is-left .pg-spine { left: auto; right: 0; background: linear-gradient(270deg, rgba(70,45,15,.24), rgba(70,45,15,.07) 40%, transparent); }
.spread::after { content: ''; position: absolute; z-index: 4; top: 0; bottom: 0; left: calc(var(--pg-w) - 1px); width: 2px; background: rgba(60,40,15,.25); pointer-events: none; }
.flipper { position: absolute; top: 0; z-index: 5; width: var(--pg-w); height: 100%; transform-style: preserve-3d; }
.flipper.to-left { left: var(--pg-w); transform-origin: left center; animation: flip-l .9s cubic-bezier(.45,.05,.3,1) forwards; }
.flipper.to-right { left: 0; transform-origin: right center; animation: flip-r .9s cubic-bezier(.45,.05,.3,1) forwards; }
.flipper > .pg { position: absolute; inset: 0; width: 100%; height: 100%; left: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; visibility: visible !important; box-shadow: 0 0 30px rgba(0,0,0,.25); }
.flipper > .pg { transform-origin: 50% 50%; }
.flipper > .face--back { transform: rotateY(180deg); }
@keyframes flip-l { to { transform: rotateY(-180deg); } }
@keyframes flip-r { to { transform: rotateY(180deg); } }
.pg--blank { display: flex; flex-direction: column; justify-content: center; align-items: center; }
.pg--blank > .pg-fill { flex: 0 0 46%; width: 70%; }
.pg-blank-note { font: 600 12px var(--f-label); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); }
.is-spread.is-compact .leaf.pg { font-size: 17px; line-height: 1.6; }
.is-wide .pg .leaf-body > *, .book-measure.is-wide .leaf-body > * { break-inside: avoid; }
.is-wide .pg .leaf-body > .b-text { break-inside: auto; }
.pg .riddle-form .q-err { margin: 0; font-size: 14px; }
.pg .leaf-clock { display: inline-block; font-size: 13px; margin-top: 8px; rotate: -2deg; }
.pg .leaf-clock b { font-variant-numeric: tabular-nums; }
.pg .pg-gorn { margin: 0 0 -6px; text-align: right; }
.pg .pg-gorn .leaf-clock { font-size: 12px; margin: 0; }

/* арт посреди страницы (листовка продолжила текст предыдущей) */
.pg .leaf-body > .leaf-art.is-inline { display: block; flex: none; min-height: 0; max-height: none; margin: 20px 0 18px; }
.pg .leaf-body > .leaf-art.is-inline + * { margin-top: 0; }
.flipper .art img { opacity: 1; transition: none; }

/* загадка и выбор внутри страницы — компактнее, чтобы помещались целиком */
.pg .riddle, .pg .choice { padding: 14px 14px 14px; }
.pg .riddle-q, .pg .choice-q { font-size: 17px; margin-bottom: 8px; }
.pg .copt { padding: 9px 12px; font-size: 15.5px; }
.pg .choice-opts { gap: 6px; margin-bottom: 8px; }
.pg .choice-def { font-size: 19px; }
.leaf-endstamp { white-space: nowrap; font-size: clamp(12px, 2vw, 17px) !important; }

/* в читалке тосты — сверху, чтобы не закрывать поля и кнопки на странице */
@media (max-width: 899px), (max-height: 520px) { body.is-reading .toasts { top: calc(var(--bar-h) + 48px); bottom: auto; }   /* под строкой с отсчётом до НГ */ }

/* на первой странице «назад» не нужна — место остаётся, плашки нет */
.book-row .pgbtn.rd-prev:disabled { visibility: hidden; }
