/* ============================================================
   THE READER — animated read-aloud storybook
   Drops into bb2g-savetheworld / bb2g-takecare / talk-about-it.
   Scoped under .rdr so it can't collide with a host page.
   ============================================================ */

.rdr {
  --rdr-hue: #F2A93B;
  --rdr-deep: #8A5410;
  --rdr-page: #FFF6E7;
  --rdr-page-2: #F7E7CB;
  --rdr-ink: #2A1B09;
  --rdr-ink-2: #6A5027;
  --rdr-lit: #FFE0A3;
  --rdr-rule: #E3CDA4;

  position: relative;
  isolation: isolate;
  color: var(--rdr-ink);
  background: var(--rdr-page);
  font-family: "Fraunces", "Iowan Old Style", Georgia, serif;
  border: 1px solid var(--rdr-rule);
  overflow: hidden;
  display: grid;
  /* Only the first two tracks are fixed: chrome, then the page. The note and
     the bar take auto rows after them. */
  grid-template-rows: auto minmax(0, 1fr);
  grid-auto-rows: auto;
  height: min(84vh, 44rem);
}

/* The book stays a lit room whatever the host theme is doing. A story does
   not change colour because the site around it did. */

/* ---------------------------------------------------------- moving ground */

.rdr__stage { position: absolute; inset: 0; z-index: 0; overflow: hidden; }

.rdr__loop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* The loops are live footage; the page has to stay readable over them. */
  filter: saturate(0.72) brightness(1.06);
  opacity: 0.34;
  transition: opacity 1.1s ease;
}

.rdr__loop[data-idle="true"] { opacity: 0.18; }

.rdr__wash {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 80% at 50% 0%, color-mix(in oklab, var(--rdr-page) 55%, transparent), transparent 70%),
    linear-gradient(to bottom, color-mix(in oklab, var(--rdr-page) 88%, transparent) 0%,
                                color-mix(in oklab, var(--rdr-page) 70%, transparent) 42%,
                                color-mix(in oklab, var(--rdr-page) 92%, transparent) 100%);
}

/* ---------------------------------------------------------- chrome */

.rdr__top,
.rdr__bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem clamp(0.9rem, 2.5vw, 1.6rem);
  background: color-mix(in oklab, var(--rdr-page) 86%, transparent);
  backdrop-filter: blur(6px);
  flex-wrap: wrap;
}

.rdr__top { border-bottom: 1px solid var(--rdr-rule); }
.rdr__bar { border-top: 1px solid var(--rdr-rule); }

.rdr__title {
  font-size: 1.05rem;
  font-weight: 600;
  font-variation-settings: "SOFT" 40, "WONK" 1, "opsz" 30;
  margin: 0;
}

.rdr__chapter {
  font-family: "DM Mono", ui-monospace, Menlo, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--rdr-ink-2);
}

.rdr__spacer { margin-left: auto; }

/* Controls are sized for a child's hand and a parent's thumb: nothing
   interactive is under 48px in either direction. */
.rdr__btn {
  min-height: 48px;
  min-width: 48px;
  padding: 0 1.05rem;
  border-radius: 999px;
  border: 1px solid var(--rdr-deep);
  background: transparent;
  color: var(--rdr-deep);
  font: inherit;
  font-family: "Public Sans", system-ui, sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.18s, color 0.18s, transform 0.12s;
}

.rdr__btn:hover { background: color-mix(in oklab, var(--rdr-hue) 26%, transparent); }
.rdr__btn:active { transform: scale(0.96); }
.rdr__btn:disabled { opacity: 0.38; cursor: default; }

.rdr__btn--go {
  background: var(--rdr-deep);
  color: var(--rdr-page);
  padding-inline: 1.4rem;
}
.rdr__btn--go:hover { background: color-mix(in oklab, var(--rdr-deep) 84%, #000); }

.rdr__btn:focus-visible,
.rdr__w:focus-visible {
  outline: 3px solid var(--rdr-deep);
  outline-offset: 2px;
}

/* ---------------------------------------------------------- the page */

.rdr__page {
  position: relative;
  z-index: 1;
  overflow-y: auto;
  /* A grid item's min-height is auto, so an overflow:auto child still grows to
     its content and the whole reader stretches to the length of the chapter.
     This is what makes it scroll inside the book instead. */
  min-height: 0;
  padding: clamp(1.4rem, 4vw, 3rem) clamp(1rem, 4vw, 2rem) clamp(2rem, 5vw, 3rem);
  scroll-behavior: smooth;
}

.rdr__sheet { max-width: 34rem; margin-inline: auto; }

.rdr__h {
  font-size: clamp(1.7rem, 5vw, 2.6rem);
  font-variation-settings: "SOFT" 30, "WONK" 1, "opsz" 90;
  font-weight: 500;
  line-height: 1.08;
  text-wrap: balance;
  margin: 0 0 1.4rem;
}

.rdr__p {
  font-size: clamp(1.12rem, 2.6vw, 1.35rem);
  line-height: 1.72;
  margin: 0 0 1.2rem;
  /* generous measure for new readers — short lines, big type */
  max-width: 32ch;
}

/* A margin voice is a different person talking. It should look like one. */
.rdr__p[data-voice="margin"] {
  font-family: "Public Sans", system-ui, sans-serif;
  font-size: clamp(0.98rem, 2.2vw, 1.1rem);
  line-height: 1.62;
  color: var(--rdr-ink-2);
  border-left: 3px solid color-mix(in oklab, var(--rdr-hue) 70%, var(--rdr-rule));
  padding: 0.15rem 0 0.15rem 1rem;
  max-width: 36ch;
}

.rdr__p em, .rdr__p i { font-style: italic; }

/* every word is its own target — tap one to hear from there */
.rdr__w {
  display: inline;
  border-radius: 4px;
  padding: 0.06em 0.04em;
  margin: 0 -0.02em;
  cursor: pointer;
  background: transparent;
  border: 0;
  font: inherit;
  color: inherit;
  transition: background 0.14s ease, color 0.14s ease;
}

.rdr__w:hover { background: color-mix(in oklab, var(--rdr-hue) 24%, transparent); }

.rdr__w[data-lit="now"] {
  background: var(--rdr-lit);
  box-shadow: 0 0 0 0.12em var(--rdr-lit);
}

.rdr__w[data-lit="done"] { color: var(--rdr-ink-2); }

.rdr__p[data-active="true"] { }

/* ---------------------------------------------------------- progress */

.rdr__track {
  position: relative;
  z-index: 2;
  height: 4px;
  background: var(--rdr-rule);
  flex: 1 1 8rem;
  border-radius: 999px;
  overflow: hidden;
  min-width: 6rem;
}

.rdr__fill {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--rdr-deep);
  transition: width 0.2s linear;
}

.rdr__voices {
  font-family: "DM Mono", ui-monospace, Menlo, monospace;
  font-size: 0.72rem;
  color: var(--rdr-ink-2);
  letter-spacing: 0.06em;
}

.rdr__note {
  position: relative;
  z-index: 2;
  margin: 0 clamp(0.9rem, 2.5vw, 1.6rem) 0.9rem;
  padding: 0.7rem 0.9rem;
  border-left: 3px solid var(--rdr-deep);
  background: color-mix(in oklab, var(--rdr-hue) 16%, transparent);
  font-family: "Public Sans", system-ui, sans-serif;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--rdr-ink-2);
}

.rdr__note b { color: var(--rdr-ink); }

/* ---------------------------------------------------------- motion */

@media (prefers-reduced-motion: reduce) {
  .rdr__loop { display: none; }
  .rdr__page { scroll-behavior: auto; }
  .rdr__w { transition: none; }
}

@media (max-width: 34rem) {
  .rdr__top, .rdr__bar { gap: 0.5rem; padding-inline: 0.9rem; }
  .rdr__btn { padding-inline: 0.8rem; font-size: 0.86rem; }
  .rdr__spacer { margin-left: 0; width: 100%; height: 0; }
}
