/* Biki and Hupu read-along: the reader. Loaded after site.css. One text-page colour
   for every page (the browser edition's fix), Biki's yellow for the word being read. */
:root {
  --bar: calc(76px + var(--sab));
  --fs: clamp(17px, min(3.3vw, 3.4vh), 34px);
  --text-h: calc(var(--fs) * 1.45 * 4 + 6vh + 24px);
}
html, body.reader { height: 100%; overflow: hidden; overscroll-behavior: none; }
body.reader { background: var(--paper); font-size: 16px; line-height: 1.4; min-height: 0; }

/* The book: one page shown at a time, softly fading in. */
.book {
  position: fixed; inset: 0 0 var(--bar) 0; overflow: hidden;
  touch-action: pan-y pinch-zoom; user-select: none; -webkit-user-select: none;
}
body.on-cover .book { bottom: 0; }
.page {
  position: absolute; inset: 0; opacity: 0; visibility: hidden;
  transition: opacity .5s ease, visibility 0s linear .5s;
}
.page.on { opacity: 1; visibility: visible; transition: opacity .5s ease; }

/* Cover */
.cover {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(14px, 2.6vh, 28px); padding: 20px 16px calc(20px + var(--sab));
  background: linear-gradient(var(--sky), var(--paper) 70%);
  text-align: center;
}
.cover-pic img {
  display: block; width: min(88vw, 50dvh); height: auto; aspect-ratio: 921 / 939;
  border-radius: 16px; box-shadow: 0 10px 30px rgba(29, 53, 87, .25);
}
.cover-text { display: flex; flex-direction: column; align-items: center; gap: clamp(6px, 1.2vh, 12px); max-width: 30em; }
.kicker { font-size: clamp(14px, 2vh, 18px); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.cover h1 { font-weight: 700; font-size: clamp(26px, min(7vw, 5vh), 48px); line-height: 1.1; }
.by { font-size: clamp(15px, 2.2vh, 20px); color: var(--ink-soft); }
.choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: clamp(4px, 1.4vh, 14px); }

@media (min-aspect-ratio: 5/4) {
  .cover { flex-direction: row; gap: clamp(24px, 5vw, 72px); }
  .cover-pic img { width: min(46vw, 78dvh); }
  .cover-text { align-items: flex-start; text-align: left; }
  .choices { justify-content: flex-start; }
}

.to-shelf {
  position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; z-index: 2;
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: .3em 1em .3em .7em;
  border-radius: 999px; background: rgba(255, 255, 255, .85); text-decoration: none; font-size: 15px;
}
.to-shelf svg { width: 18px; height: 18px; }
.end .actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* Story pages: the moving picture above, the words below. */
.story {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: clamp(10px, 2.4vh, 28px) 16px 0;
}
.frame {
  width: min(100%, 1400px, calc((100dvh - var(--bar) - var(--text-h)) * 16 / 9));
  aspect-ratio: 16 / 9; flex: 0 0 auto;
  border-radius: 18px; overflow: hidden; background: var(--sky);
  box-shadow: 0 8px 26px rgba(29, 53, 87, .22);
}
.frame video, .frame img { display: block; width: 100%; height: 100%; object-fit: cover; }
.text {
  flex: 0 0 auto; max-width: 36em; padding: clamp(10px, 3vh, 30px) 8px clamp(8px, 2vh, 20px);
  text-align: center; font-size: var(--fs); line-height: 1.45;
}
.line { margin: .08em 0; }
.w {
  border-radius: .28em; padding: 0 .04em; cursor: pointer;
  transition: background-color .12s, box-shadow .12s;
}
.w.now { background: var(--yellow); box-shadow: 0 0 0 .1em var(--yellow); }

@media (orientation: landscape) and (max-height: 520px) {
  :root { --bar: calc(62px + var(--sab)); }
  .story { flex-direction: row; gap: 20px; padding: 12px 20px 0; }
  .frame { width: min(54vw, calc((100dvh - var(--bar) - 24px) * 16 / 9)); }
  .text { flex: 1 1 0; min-width: 0; max-width: 30em; text-align: left; padding: 0; }
  .panel { padding: 14px 24px; }
  .end .panel { gap: 8px; }
  .end h2 { font-size: calc(var(--fs) * 1.4); }
  .end .btn { min-height: 44px; font-size: 16px; }
  .grown-ups { font-size: 13px; }
  .press img { width: 40px; }
}

/* Closing pages: his words on a white panel over a softened picture from the story. */
.close, .end { display: flex; align-items: center; justify-content: center; padding: 16px; }
.backdrop {
  position: absolute; inset: -30px; width: calc(100% + 60px); height: calc(100% + 60px);
  object-fit: cover; filter: blur(12px) saturate(.9);
}
.close::before, .end::before { content: ""; position: absolute; inset: 0; background: rgba(251, 245, 230, .45); }
.panel {
  position: relative; max-width: 34em; padding: clamp(20px, 4vh, 44px) clamp(20px, 4vw, 48px);
  border-radius: 28px; background: rgba(255, 255, 255, .92); text-align: center;
  font-size: var(--fs); line-height: 1.45; box-shadow: 0 10px 34px rgba(29, 53, 87, .2);
}
.panel .line + .line { margin-top: .7em; }
.panel .ask { font-weight: 700; }
.end .panel { display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 2vh, 20px); }
.end h2 { font-weight: 700; font-size: calc(var(--fs) * 1.7); line-height: 1.1; }
.end .draw { max-width: 24em; }
.grown-ups { font-size: 15px; color: var(--ink-soft); line-height: 1.6; }
.grown-ups a { color: var(--navy); }

/* Controls */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--bar);
  padding: 0 max(12px, env(safe-area-inset-right)) var(--sab) max(12px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: rgba(251, 245, 230, .96); border-top: 1px solid rgba(29, 53, 87, .12);
}
body.on-cover .bar { display: none; }
.progress { position: absolute; top: -1px; left: 0; right: 0; height: 4px; background: rgba(29, 53, 87, .08); }
.fill { height: 100%; width: 0; background: var(--yellow); transition: width .4s ease; }
.middle { display: flex; align-items: center; gap: 10px; }
.round {
  display: grid; place-items: center; width: 52px; height: 52px; padding: 0;
  border: 3px solid var(--navy); border-radius: 50%; background: var(--white); color: var(--navy);
  box-shadow: 0 3px 0 var(--navy); transition: transform .08s, box-shadow .08s, opacity .2s;
}
.round:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--navy); }
.round.big { width: 62px; height: 62px; background: var(--yellow); }
.round svg { width: 24px; height: 24px; }
.round.big svg { width: 28px; height: 28px; }
.round:disabled { opacity: .3; cursor: default; }
.switch {
  display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 4px 6px;
  border: 0; background: none; font-weight: 700; font-size: 15px;
}
.switch-icon svg { width: 22px; height: 22px; display: block; }
.track {
  position: relative; width: 44px; height: 26px; border-radius: 13px;
  background: rgba(29, 53, 87, .25); transition: background-color .2s;
}
.knob {
  position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--white); transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.switch[aria-pressed="true"] .track { background: var(--navy); }
.switch[aria-pressed="true"] .knob { transform: translateX(18px); background: var(--yellow); }
@media (max-width: 480px) {
  .switch-label { display: none; }
  .round { width: 46px; height: 46px; }
  .round.big { width: 56px; height: 56px; }
  .middle { gap: 8px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .round { width: 44px; height: 44px; }
  .round.big { width: 52px; height: 52px; }
}

.oops { padding: 40px 20px; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .page, .page.on, .fill, .w { transition: none; }
}
