/*
  Bumblequill reader: shared layout for every interactive book.

  This file controls HOW the reader works and is laid out.
  Each book's own theme.css controls how that book LOOKS, by setting
  the --bk-* variables below (and adding any extra decoration).
*/

/* ---------- Default book theme (each book overrides these) ---------- */
:root {
  --bk-backdrop: radial-gradient(ellipse at 50% 40%, #2a2620, #111113 70%);
  --bk-chrome-ink: #FFF5DB;
  --bk-chrome-muted: rgba(255, 245, 219, 0.62);
  --bk-chrome-line: rgba(246, 223, 145, 0.18);
  --bk-accent: #F6DF91;

  --bk-paper: #fbf6ea;
  --bk-ink: #2b2620;
  --bk-ink-soft: rgba(43, 38, 32, 0.72);
  --bk-font-body: "Fraunces", Georgia, serif;
  --bk-font-title: "Fraunces", Georgia, serif;
  --bk-text-size: 4.2cqw;   /* page text size: 1cqw = 1% of the page's width */

  --bk-cover: #3b3127;
  --bk-cover-ink: #fbf1d6;

  /* Text panel laid over full-bleed artwork */
  --bk-panel: rgba(251, 246, 234, 0.9);
  --bk-panel-ink: var(--bk-ink);

  /* Reader chrome sizes */
  --r-top: 64px;
  --r-bottom: 84px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body.reader {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: var(--r-top) 1fr var(--r-bottom);
  background: #111113;
  background: var(--bk-backdrop);
  color: var(--bk-chrome-ink);
  font-family: "Manrope", system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar ---------- */
.r-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 max(16px, env(safe-area-inset-left));
}
.r-title {
  margin: 0;
  font: 500 18px/1.2 var(--bk-font-title);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50vw;
}
.r-tools { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Buttons ---------- */
.r-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  border: 1px solid var(--bk-chrome-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--bk-chrome-ink);
  font: 600 14px/1 "Manrope", system-ui, sans-serif;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, opacity 0.2s;
}
.r-btn:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--bk-accent); }
.r-btn:focus-visible { outline: 2px solid var(--bk-accent); outline-offset: 3px; }
.r-btn:disabled { opacity: 0.3; cursor: default; }
.r-btn:disabled:hover { background: rgba(255, 255, 255, 0.04); border-color: var(--bk-chrome-line); }
.r-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.r-btn--text { justify-self: start; padding: 0 14px 0 10px; }
.r-btn--round { width: 52px; height: 52px; }
.r-btn--round svg { width: 24px; height: 24px; }

/* ---------- Stage (where the book sits) ---------- */
.r-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 8px 16px;
}

/*
  The box around the book. StPageFlip fills this box's width, so we size
  the box so the whole book always fits on screen.
  --r-ratio is one page's width ÷ height (set by reader.js from book.json).
  Wide screens show two pages side by side (ratio × 2);
  narrow screens show one page.
*/
.r-wrap {
  /* the extra 14px / 20px leave room for the paper stack, boards and shadow */
  --r-avail-h: calc(100vh - var(--r-top) - var(--r-bottom) - 30px);
  width: min(100% - 20px, calc(var(--r-avail-h) * var(--r-ratio, 0.75) * 2));
  margin: 0 auto;
}
@supports (height: 100dvh) {
  .r-wrap { --r-avail-h: calc(100dvh - var(--r-top) - var(--r-bottom) - 30px); }
}
@media (max-width: 719px) {
  .r-wrap { width: min(100%, calc(var(--r-avail-h) * var(--r-ratio, 0.75))); }
}

/* Fade the book in once it's ready, so it never jumps around while loading. */
.r-book { opacity: 0; transition: opacity 0.4s ease; }
.is-ready .r-book { opacity: 1; }

/* Closed book in the middle: in two-page view the front cover sits on the
   right half and the back cover on the left half, so slide it to the centre. */
.is-ready .r-book { transition: opacity 0.4s ease, transform 0.7s ease; }
.r-wrap.closed-front .r-book { transform: translateX(-25%); }
.r-wrap.closed-back .r-book { transform: translateX(25%); }

.r-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  color: var(--bk-chrome-muted);
}
.r-message h2 { margin: 0; font: 500 26px/1.2 "Fraunces", Georgia, serif; color: var(--bk-chrome-ink); }
.r-message p { margin: 0; }
.r-message a { justify-self: center; }

/* ---------- Bottom bar ---------- */
.r-bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 0 16px max(14px, env(safe-area-inset-bottom));
}
.r-progress { display: grid; gap: 8px; width: min(320px, 50vw); text-align: center; }
.r-progress__bar { height: 4px; border-radius: 4px; background: var(--bk-chrome-line); overflow: hidden; }
.r-progress__bar span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--bk-accent); transition: width 0.4s ease; }
.r-progress__label { font-size: 13px; font-weight: 600; letter-spacing: 0.02em; color: var(--bk-chrome-muted); }

/* ---------- Narration bar ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.r-btn--narrate.is-active { background: var(--bk-accent); border-color: var(--bk-accent); color: #16151a; }

/* While narration is on, the bottom area grows to make room for the bar
   (the book shrinks a little to keep fitting on screen). */
body.reader.is-narrating { --r-bottom: 152px; }
.r-bottom { align-items: flex-end; padding-bottom: max(16px, env(safe-area-inset-bottom)); }

body.reader { position: relative; }
.r-narration {
  position: absolute;   /* measured from the bottom of the reader layout, just above the arrows */
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 8px 10px 8px 8px;
  border: 1px solid var(--bk-chrome-line);
  border-radius: 999px;
  background: rgba(17, 17, 19, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 5;
}
.r-narration .r-btn { height: 40px; min-width: 40px; padding: 0; }
.r-btn--accent { background: var(--bk-accent); border-color: var(--bk-accent); color: #16151a; }
.r-btn--accent:hover { background: var(--bk-accent); filter: brightness(1.08); }
.r-narration .r-btn--round { width: 44px; height: 44px; }
.r-btn--accent svg { fill: currentColor; stroke-width: 2.4; }
.r-btn--accent .i-pause { fill: none; stroke-width: 2.6; }
.r-btn--accent .i-pause, .r-narration.is-playing .i-play { display: none; }
.r-narration.is-playing .i-pause { display: block; }
.r-btn--close { border-color: transparent; background: transparent; }

.r-narration__status {
  min-width: 150px;
  font-size: 13px;
  font-weight: 600;
  color: var(--bk-chrome-muted);
  white-space: nowrap;
}

.r-volume { display: inline-flex; align-items: center; gap: 6px; color: var(--bk-chrome-muted); }
.r-volume svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.r-volume input { width: 96px; accent-color: var(--bk-accent); cursor: pointer; }

.r-switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--bk-chrome-muted); }
.r-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.r-switch__track { position: relative; width: 34px; height: 20px; border-radius: 999px; background: var(--bk-chrome-line); transition: background 0.2s; }
.r-switch__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--bk-chrome-ink); transition: transform 0.2s; }
.r-switch input:checked + .r-switch__track { background: var(--bk-accent); }
.r-switch input:checked + .r-switch__track::after { transform: translateX(14px); background: #16151a; }
.r-switch input:focus-visible + .r-switch__track { outline: 2px solid var(--bk-accent); outline-offset: 3px; }

/* ---------- Toast ---------- */
.r-toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--r-bottom) + 8px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 18px;
  border: 1px solid var(--bk-chrome-line);
  border-radius: 999px;
  background: rgba(17, 17, 19, 0.92);
  color: var(--bk-chrome-ink);
  font-size: 14px;
  white-space: nowrap;
  z-index: 10;
}
.r-toast .r-btn { height: 34px; min-width: 0; font-size: 13px; }

/* =========================================================
   Pages
   ========================================================= */
.bk-page {
  position: relative;
  overflow: hidden;
  background: var(--bk-paper);
  color: var(--bk-ink);
  font-family: var(--bk-font-body);
  container-type: inline-size;   /* lets text sizes use cqw (page width) */
}
.bk-page__inner { position: absolute; inset: 0; display: flex; flex-direction: column; }

.bk-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.06);
  opacity: 0;
  transition: opacity 0.35s ease;
}
.bk-art.is-loaded { opacity: 1; }

.bk-text { font-size: var(--bk-text-size); line-height: 1.5; }
.bk-text p { margin: 0 0 0.6em; }
.bk-text p:last-child { margin-bottom: 0; }
.bk-text h2 { margin: 0 0 0.4em; font: 500 1.5em/1.15 var(--bk-font-title); }

.bk-num {
  position: absolute;
  bottom: 3.2cqw;
  left: 0;
  right: 0;
  text-align: center;
  font: 600 2.8cqw/1 "Manrope", system-ui, sans-serif;
  color: var(--bk-ink-soft);
  pointer-events: none;
}

/* Layout: full picture, text on a panel at the bottom */
.bk-layout-text-bottom .bk-art,
.bk-layout-text-top .bk-art,
.bk-layout-full .bk-art { position: absolute; inset: 0; }
.bk-layout-text-bottom .bk-text,
.bk-layout-text-top .bk-text {
  position: absolute;
  left: 6cqw;
  right: 6cqw;
  padding: 5cqw 6cqw;
  border-radius: 3cqw;
  background: var(--bk-panel);
  color: var(--bk-panel-ink);
}
.bk-layout-text-bottom .bk-text { bottom: 9cqw; }
.bk-layout-text-top .bk-text { top: 7cqw; }
.bk-layout-full .bk-num,
.bk-layout-text-bottom .bk-num,
.bk-layout-text-top .bk-num { color: rgba(255, 255, 255, 0.85); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }

/* Layout: picture on top, text below */
.bk-layout-image-top .bk-art { height: 52%; flex: none; }
.bk-layout-image-top .bk-text { padding: 6cqw 9cqw 12cqw; }

/* Layout: text only */
.bk-layout-text .bk-text {
  margin: auto 0;
  padding: 12cqw 11cqw;
  font-size: calc(var(--bk-text-size) * 1.08);
}

/* Layout: spread (one wide picture across two facing pages).
   Each half shows its side of a picture twice the page's width. */
.bk-layout-spread .bk-art--spread { position: absolute; top: 0; width: 200%; max-width: none; height: 100%; }
.bk-spread--left .bk-art--spread { left: 0; }
.bk-spread--right .bk-art--spread { left: -100%; }
.bk-layout-spread .bk-text {
  position: absolute;
  top: 7cqw;
  left: 6cqw;
  right: 6cqw;
  padding: 5cqw 6cqw;
  border-radius: 3cqw;
  background: var(--bk-panel);
  color: var(--bk-panel-ink);
}
.bk-layout-spread .bk-text--bottom { top: auto; bottom: 9cqw; }
.bk-layout-spread .bk-num { color: rgba(255, 255, 255, 0.85); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }

/* Layout: comic panels */
.bk-layout-panels { background: var(--bk-gutter, var(--bk-paper)); }
.bk-layout-panels .bk-page__inner { padding: 4cqw 4cqw 9cqw; }
.bk-panels { flex: 1; min-height: 0; display: grid; gap: 2.4cqw; grid-template-columns: 1fr 1fr; }
.bk-panels--t2 { grid-template-rows: 1.53fr 1fr; }
.bk-panels--t2 > :first-child { grid-column: 1 / -1; }
.bk-panels--2x2 { grid-template-rows: 1fr 1fr; }
.bk-panels--stack { grid-template-columns: 1fr; grid-auto-rows: 1fr; }
.bk-panel {
  position: relative;
  margin: 0;
  overflow: hidden;
  min-height: 0;
  border: var(--bk-panel-line, 0.5cqw solid #141414);
  border-radius: var(--bk-panel-radius, 0.6cqw);
  background: #1b1b1b;
}
.bk-panel .bk-art { position: absolute; inset: 0; }
.bk-caption {
  position: absolute;
  top: 2cqw;
  left: 2cqw;
  max-width: 82%;
  padding: 1.6cqw 2.4cqw;
  background: var(--bk-caption-bg, var(--bk-paper));
  color: var(--bk-caption-ink, var(--bk-ink));
  border: var(--bk-caption-line, 0.3cqw solid #141414);
  font: var(--bk-caption-weight, 600) max(12.5px, calc(var(--bk-text-size) * 0.74)) / 1.35 var(--bk-font-body);
}
.bk-caption--bottom { top: auto; bottom: 2cqw; }
.bk-bubble {
  position: absolute;
  max-width: 58%;
  padding: 1.5cqw 2.6cqw;
  background: #fff;
  color: #111;
  border: 0.4cqw solid #111;
  border-radius: 4cqw;
  font: 700 max(12.5px, calc(var(--bk-text-size) * 0.76)) / 1.25 var(--bk-font-bubble, var(--bk-font-body));
  text-align: center;
}
.bk-bubble::after {
  content: "";
  position: absolute;
  width: 2.2cqw;
  height: 2.2cqw;
  background: #fff;
  border: 0 solid #111;
  transform: rotate(45deg);
}
.bk-bubble--bl::after, .bk-bubble--br::after { bottom: -1.5cqw; border-right-width: 0.4cqw; border-bottom-width: 0.4cqw; }
.bk-bubble--tl::after, .bk-bubble--tr::after { top: -1.5cqw; border-left-width: 0.4cqw; border-top-width: 0.4cqw; }
.bk-bubble--bl::after, .bk-bubble--tl::after { left: 3.5cqw; }
.bk-bubble--br::after, .bk-bubble--tr::after { right: 3.5cqw; }

/* Layout: labelled diagram (picture with pointer lines, words below) */
.bk-diagram { position: relative; flex: none; width: 100%; aspect-ratio: var(--bk-diagram-ratio, 3 / 2); }
.bk-diagram .bk-art { position: absolute; inset: 0; }
.bk-diagram__lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.bk-diagram__lines line { stroke: var(--bk-label-line, rgba(60, 55, 48, 0.75)); vector-effect: non-scaling-stroke; stroke-width: 1.4px; }
.bk-dot {
  position: absolute;
  width: 1.6cqw;
  height: 1.6cqw;
  margin: -0.8cqw 0 0 -0.8cqw;
  border-radius: 50%;
  background: var(--bk-label-line, rgba(60, 55, 48, 0.85));
}
.bk-label {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 0.6cqw 1.6cqw;
  border-radius: 1.5cqw;
  white-space: nowrap;
  background: var(--bk-label-bg, rgba(255, 252, 243, 0.82));
  color: var(--bk-label-ink, var(--bk-ink));
  font: var(--bk-label-weight, 600) max(13px, calc(var(--bk-text-size) * 0.82)) / 1.2 var(--bk-font-label, var(--bk-font-body));
}
.bk-layout-diagram .bk-text { padding: 4.5cqw 8cqw 10cqw; }

/* End of a free preview (public preview copies only, made by build-site.py) */
.bk-preview-end .bk-text { text-align: center; }
.bk-preview-end h2 { margin: 0 0 4cqw; font: 600 7cqw/1.15 var(--bk-font-title); }
.bk-preview-end__btn {
  display: inline-block;
  margin-top: 6cqw;
  padding: 3cqw 7cqw;
  border-radius: 99px;
  background: var(--bk-accent, #E2A93B);
  color: #1a1408;
  font: 700 max(14px, calc(var(--bk-text-size) * 0.95)) / 1.2 var(--bk-font-body);
  text-decoration: none;
}
.bk-preview-end__btn:focus-visible { outline: 0.6cqw solid var(--bk-ink); outline-offset: 0.6cqw; }
.bk-preview-end__soon { margin-top: 6cqw; font-style: italic; opacity: 0.8; }

/* Layout: hotspots (a full picture with stars to tap; added 2026-11-21) */
.bk-sky { position: absolute; inset: 0; }
.bk-sky .bk-art { position: absolute; inset: 0; }
.bk-sky__lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.bk-sky__lines line {
  stroke: var(--bk-star-line, rgba(255, 244, 194, 0.75));
  stroke-width: 1.6px;
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
  opacity: 0;
  transition: opacity 0.6s ease;
}
.bk-sky__lines line.is-on { opacity: 1; }
.bk-star {
  --star: var(--bk-star, #FFF4C2);
  position: absolute;
  width: 10cqw;
  height: 10cqw;
  min-width: 34px;
  min-height: 34px;
  margin: 0;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bk-star > span { pointer-events: none; }
.bk-star__glow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1.6cqw;
  height: 1.6cqw;
  transform: translate(-50%, -50%) rotate(45deg);
  background: var(--star);
  opacity: 0.45;
  box-shadow: 0 0 1.4cqw 0.4cqw rgba(255, 244, 194, 0.25);
  animation: bk-star-hint 2.4s ease-in-out infinite;
  transition: width 0.35s ease, height 0.35s ease, opacity 0.35s ease, box-shadow 0.35s ease;
}
.bk-star--big .bk-star__glow { width: 2cqw; height: 2cqw; }
.bk-star.is-lit { cursor: default; }
.bk-star.is-lit .bk-star__glow {
  width: 2.8cqw;
  height: 2.8cqw;
  opacity: 1;
  animation: none;
  box-shadow: 0 0 2.4cqw 1cqw color-mix(in srgb, var(--star) 55%, transparent);
}
.bk-star--big.is-lit .bk-star__glow { width: 3.4cqw; height: 3.4cqw; }
.bk-star:focus-visible { outline: 0.5cqw solid var(--star); outline-offset: -1cqw; }
.bk-star__name, .bk-sky__done {
  position: absolute;
  white-space: nowrap;
  color: var(--bk-star-ink, #FFF4C2);
  font: 700 max(12px, calc(var(--bk-text-size) * 0.78)) / 1.1 var(--bk-font-label, var(--bk-font-body));
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transition: opacity 0.5s ease;
}
.bk-star__name { left: 50%; top: 78%; transform: translateX(-50%); }
.bk-star.is-lit .bk-star__name { opacity: 1; }
.bk-sky__done { transform: translate(-50%, -50%); font-size: max(14px, calc(var(--bk-text-size) * 1.05)); pointer-events: none; }
.bk-sky.is-complete .bk-sky__done { opacity: 1; }
@keyframes bk-star-hint { 50% { opacity: 0.9; } }
.bk-layout-hotspots .bk-text {
  position: absolute;
  top: 7cqw;
  left: 6cqw;
  right: 6cqw;
  padding: 5cqw 6cqw;
  border-radius: 3cqw;
  background: var(--bk-panel);
  color: var(--bk-panel-ink);
}
.bk-layout-hotspots .bk-text--bottom { top: auto; bottom: 9cqw; }
.bk-layout-hotspots .bk-num { color: rgba(255, 255, 255, 0.85); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
@media (prefers-reduced-motion: reduce) { .bk-star__glow { animation: none; } }

/* Layout: find (tap the hidden shapes; added 2026-11-21). Also used on spreads that carry "spots". */
.bk-findpic { position: absolute; inset: 0; }
.bk-findpic .bk-art { position: absolute; inset: 0; }
.bk-find { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.bk-spot {
  --spot: var(--bk-find, #FFD23F);
  position: absolute;
  min-width: 34px;
  min-height: 34px;
  margin: 0;
  padding: 0;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  border: 0;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}
.bk-spot svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.bk-spot svg > * {
  fill: color-mix(in srgb, var(--spot) 18%, transparent);
  stroke: var(--spot);
  stroke-width: 4px;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 0.8cqw var(--spot)) drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5));
  opacity: 0;
  transform: scale(0.6);
  transform-origin: 50% 50%;
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.bk-spot.is-found { cursor: default; }
.bk-spot.is-found svg > * { opacity: 1; transform: scale(1); }
.bk-spot:focus-visible { outline: 0.5cqw dashed var(--spot); outline-offset: 0.5cqw; }
.bk-find__count {
  position: absolute;
  right: 3cqw;
  top: 3cqw;
  padding: 1.2cqw 2.6cqw;
  border-radius: 99px;
  background: var(--bk-panel, rgba(255, 252, 243, 0.92));
  color: var(--bk-panel-ink, var(--bk-ink));
  font: 700 max(12px, calc(var(--bk-text-size) * 0.8)) / 1.1 var(--bk-font-label, var(--bk-font-body));
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
.bk-spread--left .bk-find__count { display: none; }        /* one counter per spread, on the right half */
.bk-find.is-complete .bk-find__count { background: var(--bk-find, #FFD23F); color: #2a1d00; animation: bk-find-pop 0.6s ease; }
.bk-find.is-complete .bk-find__count::before { content: "\2605  "; }
.bk-find__done {
  position: absolute;
  transform: translate(-50%, -50%) scale(0.6);
  padding: 1.6cqw 3.6cqw;
  border-radius: 3cqw;
  background: var(--bk-find, #FFD23F);
  color: #2a1d00;
  white-space: nowrap;
  font: 800 max(14px, calc(var(--bk-text-size) * 1.05)) / 1.1 var(--bk-font-label, var(--bk-font-body));
  box-shadow: 0 0 3cqw color-mix(in srgb, var(--bk-find, #FFD23F) 70%, transparent);
  opacity: 0;
  transition: opacity 0.4s ease 0.3s, transform 0.5s cubic-bezier(0.3, 1.6, 0.5, 1) 0.3s;
}
.bk-find.is-complete .bk-find__done { opacity: 1; transform: translate(-50%, -50%) scale(1); }
@keyframes bk-find-pop { 40% { transform: scale(1.25); } }
.bk-layout-find .bk-text {
  position: absolute;
  top: 7cqw;
  left: 6cqw;
  right: 6cqw;
  padding: 5cqw 6cqw;
  border-radius: 3cqw;
  background: var(--bk-panel);
  color: var(--bk-panel-ink);
  z-index: 1;
}
.bk-layout-find .bk-text--bottom { top: auto; bottom: 9cqw; }
.bk-layout-find .bk-find__count { top: auto; bottom: 3cqw; }
@media (prefers-reduced-motion: reduce) {
  .bk-spot svg > *, .bk-find__done { transition: opacity 0.2s ease; }
  .bk-find.is-complete .bk-find__count { animation: none; }
}

/* Depth gauge (book.gauge + page.depth; added 2026-11-21 for Ocean Deep) */
.bk-gauge { position: absolute; top: 8cqw; bottom: 10cqw; right: 2.4cqw; width: 2.4cqw; z-index: 3; pointer-events: none; }
.bk-gauge--left { right: auto; left: 2.4cqw; }
.bk-gauge__bar {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  border-radius: 99px;
  overflow: hidden;
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.75), 0 1px 4px rgba(0, 0, 0, 0.5);
}
.bk-gauge__band { flex: 1; }
.bk-gauge__band + .bk-gauge__band { border-top: 1px solid rgba(255, 255, 255, 0.35); }
.bk-gauge__mark { position: absolute; left: 50%; width: 4cqw; height: 4cqw; transform: translate(-50%, -50%); }
.bk-gauge__mark::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: #FFD23F;
  box-shadow: 0 0 0 2px #fff, 0 0 2cqw #FFD23F;
}
.bk-gauge__label {
  position: absolute;
  right: 5.2cqw;
  top: 50%;
  transform: translateY(-50%);
  padding: 1cqw 2cqw;
  border-radius: 1.6cqw;
  background: rgba(8, 20, 38, 0.82);
  color: #fff;
  white-space: nowrap;
  text-align: right;
  font: 700 max(11px, calc(var(--bk-text-size) * 0.72)) / 1.15 var(--bk-font-label, var(--bk-font-body));
}
.bk-gauge__label small { display: block; font-weight: 600; opacity: 0.8; font-size: 0.85em; }
.bk-gauge--left .bk-gauge__label { right: auto; left: 5.2cqw; text-align: left; }

/* ---------- Covers ---------- */
.bk-cover { background: var(--bk-cover); color: var(--bk-cover-ink); }
.bk-cover .bk-art { position: absolute; inset: 0; }
.bk-cover__title {
  position: absolute;
  left: 8cqw;
  right: 8cqw;
  bottom: 12cqw;
  text-align: center;
}
.bk-cover__title h2 { margin: 0; font: 500 11cqw/1.05 var(--bk-font-title); }
.bk-cover__title p { margin: 3cqw 0 0; font-size: 4.2cqw; opacity: 0.85; }
.bk-cover--back .bk-cover__title { top: 50%; bottom: auto; transform: translateY(-50%); }
.bk-cover--back .bk-cover__title p { font-size: 4.6cqw; line-height: 1.5; }

/* Blank page added automatically so the back cover lands on its own */
.bk-blank { background: var(--bk-paper); }

/* Soft shading near the spine, so two pages look bound together */
.stf__item.--left:not(.bk-cover)::after,
.stf__item.--right:not(.bk-cover)::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.stf__item.--left:not(.bk-cover)::after { background: linear-gradient(to left, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.05) 5%, transparent 14%); }
.stf__item.--right:not(.bk-cover)::after { background: linear-gradient(to right, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.05) 5%, transparent 14%); }

/* =========================================================
   Hardcover look: paper stack, cover boards, spine, shadow.
   Everything here sits BEHIND the pages (z-index -1) and ignores the
   mouse, so StPageFlip's flipping, clicks and swipes are unchanged.
   ========================================================= */
.r-book {
  isolation: isolate;   /* keeps the layers below inside the book */
  --stack-min: 2px;     /* thinnest paper stack */
  --stack-range: 5px;   /* extra thickness for a full stack */
}

/* One layer under each half of the spread. Its box-shadows draw the
   page edges (right/bottom), a hint of paper along the top, the
   hardcover board peeking out, and the soft shadow on the backdrop. */
.r-book::before,
.r-book::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: -1;
  border-radius: 2px;
  background: var(--bk-paper);
  pointer-events: none;
  transition: opacity 0.35s ease;
  --l1: var(--bk-edge-line);
  --l2: var(--bk-edge);
  box-shadow:
    calc(var(--sx) * var(--t) * 0.15) calc(var(--t) * 0.12) 0 var(--l1),
    calc(var(--sx) * var(--t) * 0.3)  calc(var(--t) * 0.24) 0 var(--l2),
    calc(var(--sx) * var(--t) * 0.45) calc(var(--t) * 0.36) 0 var(--bk-edge-line),
    calc(var(--sx) * var(--t) * 0.6)  calc(var(--t) * 0.48) 0 var(--bk-edge),
    calc(var(--sx) * var(--t) * 0.75) calc(var(--t) * 0.6)  0 var(--bk-edge-line),
    calc(var(--sx) * var(--t) * 0.9)  calc(var(--t) * 0.72) 0 var(--bk-edge),
    calc(var(--sx) * var(--t))        calc(var(--t) * 0.8)  0 var(--bk-edge-line),
    /* top edge: two thin sheets just showing above the page */
    calc(var(--sx) * var(--t) * 0.3) -0.75px 0 var(--bk-edge),
    calc(var(--sx) * var(--t) * 0.6) -1.5px 0 var(--bk-edge-line),
    /* back board (hardcover) around the paper */
    calc(var(--sx) * (var(--t) + 3px)) calc(var(--t) * 0.8 + 3.5px) 0 var(--bk-board),
    /* lifted off the backdrop */
    calc(var(--sx) * 4px) 22px 34px -8px rgba(0, 0, 0, 0.55),
    0 6px 12px rgba(0, 0, 0, 0.28);
}
.r-book::before { left: 0;   --sx: -1; --t: calc(var(--stack-min) + var(--r-read, 0) * var(--stack-range)); }
.r-book::after  { left: 50%; --sx: 1;  --t: calc(var(--stack-min) + (1 - var(--r-read, 0)) * var(--stack-range)); }

/* Closed book: only one half exists, and the front (or back) cover board
   sits on top of the stack, so the first sheets are cover-coloured. */
.r-wrap.closed-front .r-book::before,
.r-wrap.closed-back .r-book::after { opacity: 0; }
.r-wrap.closed-front .r-book::after,
.r-wrap.closed-back .r-book::before { --l1: var(--bk-board-edge); --l2: var(--bk-board); }

/* Phones (one page at a time): a single stack under the whole page. */
.r-book:has(.--portrait)::before { display: none; }
.r-book:has(.--portrait)::after { left: 0; width: 100%; }

/* Spine. Open book: the bound spine shows between the two stacks.
   Closed book or phone view: the rounded spine edge beside the cover. */
.r-book .stf__wrapper::before {
  content: "";
  position: absolute;
  z-index: -2;
  top: -1px;
  bottom: calc(var(--stack-min) * -0.8 - var(--stack-range) * 0.8 - 3.5px);
  left: 50%;
  width: 16px;
  transform: translateX(-50%);
  border-radius: 0 0 6px 6px;
  background: linear-gradient(to right, var(--bk-board), var(--bk-board-edge) 50%, var(--bk-board));
  pointer-events: none;
}
.r-wrap.closed-front .stf__wrapper::before,
.r-book .stf__wrapper.--portrait::before {
  top: 0;
  bottom: -3.5px;
  width: 6px;
  transform: translateX(-100%);
  border-radius: 5px 0 0 5px;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.45), transparent 70%), var(--bk-board);
}
.r-book .stf__wrapper.--portrait::before { left: 0; }
.r-wrap.closed-back .stf__wrapper::before {
  top: 0;
  bottom: -3.5px;
  width: 6px;
  transform: none;
  border-radius: 0 5px 5px 0;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.45), transparent 70%), var(--bk-board);
}

/* Covers: thicker board with a bevelled edge and the hinge groove
   near the spine, like a real hardcover. */
.bk-cover {
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    inset 0 0 0 2px rgba(0, 0, 0, 0.25),
    inset 0 0 2.5cqw rgba(0, 0, 0, 0.3);
}
.bk-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to right,
    rgba(0, 0, 0, 0.4) 0,
    rgba(255, 255, 255, 0.1) 1.4%,
    rgba(0, 0, 0, 0.12) 3%,
    rgba(0, 0, 0, 0.28) 4.6%,
    rgba(255, 255, 255, 0.12) 5.6%,
    transparent 8.5%);
}
.bk-cover--back::after { transform: scaleX(-1); }   /* spine is on the right when you see the back */

/* Page tokens for the look above (books can override in theme.css) */
:root {
  --bk-edge: #ece3cc;        /* page edges: paper */
  --bk-edge-line: #d3c6a6;   /* page edges: the fine lines between sheets */
  --bk-board: #2e261e;       /* hardcover board edge seen around the paper */
  --bk-board-edge: #4a3e31;  /* lighter rim of the board */
}

/* ---------- Small screens ---------- */
@media (max-width: 719px) {
  :root { --r-top: 56px; --r-bottom: 76px; }
  .r-stage { padding-inline: 7px 11px; }   /* room for the spine (left) and paper stack (right) */
  .r-btn--text span, .r-btn--narrate span { display: none; }
  .r-title { font-size: 16px; }
  .r-bottom { gap: 12px; }
  body.reader.is-narrating { --r-bottom: 140px; }
  .r-narration { bottom: calc(76px + env(safe-area-inset-bottom)); gap: 6px; padding-block: 6px; }
  .r-narration__status { display: none; }
  .r-volume input { width: 64px; }
  .r-switch__label { font-size: 12px; }
}

/* ---------- Fullscreen: give the book more room ---------- */
:fullscreen body.reader, body.reader:fullscreen { --r-top: 56px; }

@media (prefers-reduced-motion: reduce) {
  .r-book, .is-ready .r-book, .bk-art, .r-progress__bar span { transition: none; }
}

/* Bonus games page (book.bonus, added 2026-11-26): the page after the story with a button per game.
   The games themselves open above the book (assets/reader/games/bq-games.css). */
.bk-layout-bonus .bk-page__inner { justify-content: flex-end; }
.bk-layout-bonus .bk-bonus__art { position: absolute; inset: 0; }
.bk-bonus {
  position: relative;
  margin: 0 6cqw 8cqw;
  padding: 5cqw 6cqw 6cqw;
  border-radius: 5cqw;
  background: var(--bk-panel, rgba(255, 248, 236, 0.94));
  color: var(--bk-panel-ink, var(--bk-ink));
  text-align: center;
  box-shadow: 0 1cqw 4cqw rgba(0, 0, 0, 0.3);
}
.bk-bonus h2 { margin: 0 0 1.5cqw; font: 700 8cqw/1.1 var(--bk-font-title); }
.bk-bonus p { margin: 0 0 4cqw; font: 700 4.2cqw/1.35 var(--bk-font-body); }
.bk-bonus__list { display: grid; gap: 2.6cqw; }
.bk-bonus__btn {
  min-height: 44px;
  padding: 2.6cqw 4cqw;
  border: 0;
  border-radius: 99px;
  background: var(--bk-accent, #FFC857);
  color: var(--bk-panel-ink, var(--bk-ink));
  font: 800 4.6cqw/1.15 var(--bk-font-body);
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 0.8cqw 0 rgba(0, 0, 0, 0.22);
}
.bk-bonus__btn::before { content: "\25B6\FE0E  "; font-size: 0.8em; }
.bk-bonus__btn:hover { filter: brightness(1.06); }
.bk-bonus__btn[aria-busy="true"] { opacity: 0.6; cursor: progress; }
.bk-bonus__btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 6px var(--bk-ink); }
.bk-bonus__btn { display: flex; align-items: center; justify-content: center; gap: 3cqw; }
.bk-bonus__btn * { pointer-events: none; }   /* the button itself must be the tap target, or the page turns */
.bk-bonus__thumb { flex: none; width: 11cqw; height: 11cqw; min-width: 36px; min-height: 36px; border-radius: 50%; border: 0.6cqw solid #fff; background-repeat: no-repeat; }
.bk-bonus__btn:has(.bk-bonus__thumb) { justify-content: flex-start; text-align: left; padding: 2cqw 5cqw 2cqw 2.4cqw; }
.bk-bonus__btn:has(.bk-bonus__thumb)::before { content: none; }
.bk-bonus--cover .bk-bonus h2 { font-size: 10cqw; }
.bk-bonus--menu .bk-page__inner { justify-content: center; }
.bk-bonus--menu .bk-bonus { background: transparent; box-shadow: none; }
.bk-bonus--menu .bk-bonus__list { gap: 4cqw; }
.bk-bonus--menu .bk-bonus__btn { font-size: 5.2cqw; min-height: 17cqw; }
.bk-bonus--menu .bk-bonus__thumb { width: 14cqw; height: 14cqw; }
