*,
*::before,
*::after {
  box-sizing: border-box;
}

.page-storybook {
  margin: 0;
  min-height: 100dvh;
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  color: #831843;
  /* Purple story-world wash — aligns with portal “Sofia’s Stories” tile */
  background: linear-gradient(165deg, #f5efff 0%, #fde7f3 42%, #ddd6fe 92%);
  -webkit-font-smoothing: antialiased;
  /* Book binding + accents (pink/magenta, same family as portal --theme-storybook) */
  --sb-flip-red: #db2777;
  --sb-flip-light: #fce7f3;
  --sb-flip-mid: #be185d;
  --sb-flip-dark: #9d174d;
  --sb-flip-darker: #831843;
  --sb-flip-paper: #ffffff;
  --sb-flip-desk: #cbc0e6;
  /* Facing text page: cream paper + soft white “paint” corners (CSS only — not sampled from art) */
  --sb-facing-cream: #faf6ec;
  --sb-facing-blob-layer-opacity: 0.94;
  /* Slight tonal steps so blobs read as separate white washes on cream */
  --sb-facing-corner-strong: color-mix(in srgb, #ffffff 96%, var(--sb-facing-cream) 4%);
  --sb-facing-corner-mid: color-mix(in srgb, #ffffff 90%, var(--sb-facing-cream) 10%);
  --sb-facing-corner-soft: color-mix(in srgb, #ffffff 84%, var(--sb-facing-cream) 16%);
  --sb-facing-corner-accent: color-mix(in srgb, #ffffff 78%, var(--sb-facing-cream) 22%);
  /* Open spread height; width follows aspect-ratio on .sb-flip-spread__inner (portrait book, crease centered) */
  --sb-book-inner-h: clamp(288px, min(70dvh, 82vh), 640px);
  /* width ≈ height × this (7/10 → taller than wide); kept for cover / reader width calcs */
  --sb-book-spread-w-factor: 0.7;
}

/* Landing: magical room art edge-to-edge; hidden during immersive reader */
body.page-storybook.sb-route-story {
  background: #f4e8ef;
}

body.page-storybook.sb-route-story::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(
      180deg,
      rgba(255, 253, 251, 0.42) 0%,
      rgba(255, 250, 252, 0.18) 45%,
      rgba(237, 231, 255, 0.28) 100%
    ),
    url("images/storybook-landing-room-bg.jpg") center / cover no-repeat;
  pointer-events: none;
}

body.page-storybook.sb-reader-immersive::before {
  opacity: 0;
  transition: opacity 0.35s ease;
}

body.page-storybook.sb-route-story .sb-landing__left {
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

@media (min-width: 640px) {
  .page-storybook {
    --sb-book-inner-h: clamp(300px, min(72dvh, 84vh), 660px);
  }
}

@media (min-width: 640px) and (orientation: portrait) {
  .page-storybook {
    --sb-book-inner-h: clamp(300px, min(68dvh, 78vh), 640px);
  }

  .sb-reader-stack {
    min-height: clamp(320px, min(72dvh, 80vh), 680px);
  }
}

@media (max-width: 1200px) {
  .page-storybook {
    --sb-book-inner-h: clamp(280px, min(66dvh, 80vh), 620px);
  }

  .sb-reader-stack {
    min-height: clamp(300px, min(70dvh, 82vh), 640px);
  }
}

@media (max-width: 1200px) and (orientation: landscape) and (max-height: 900px) {
  .page-storybook {
    --sb-book-inner-h: clamp(292px, min(72dvh, 74vh), 580px);
  }

  .sb-reader-stack {
    min-height: clamp(308px, min(74dvh, 76vh), 600px);
  }
}

@media (max-width: 1200px) and (orientation: portrait) {
  .page-storybook {
    --sb-book-inner-h: clamp(292px, min(64dvh, 76vh), 620px);
  }

  .sb-reader-stack {
    min-height: clamp(308px, min(68dvh, 78vh), 640px);
  }
}

@media (max-width: 1200px) and (max-height: 900px) {
  .sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-flip-text__highlight {
    font-size: clamp(1rem, min(3.6vw, 3.4dvh), 1.52rem);
    line-height: 1.48;
  }

  .sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-big-word {
    font-size: 1.48em;
  }
}

body.page-storybook.sb-modal-open {
  overflow: hidden;
}

.sb-app {
  max-width: 28rem;
  margin: 0 auto;
  padding: max(0.5rem, env(safe-area-inset-top, 0px)) 1rem
    max(1.25rem, env(safe-area-inset-bottom, 0px));
}

/* Storybook reader: wider stage so the two-page spread can breathe */
.page-storybook .sb-app {
  max-width: min(80rem, 100%);
}

.sb-nav {
  margin-bottom: 0.75rem;
}

.sb-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: #db2777;
  font-weight: 800;
  text-decoration: none;
  font-size: 0.95rem;
}

/* Full-screen welcome when opening storybook from main portal (?from=portal) */
body.sb-portal-welcome-open {
  overflow: hidden;
}

.sb-portal-welcome {
  position: fixed;
  inset: 0;
  z-index: 8500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top)) 1.25rem max(1rem, env(safe-area-inset-bottom));
  box-sizing: border-box;
}

.sb-portal-welcome[hidden] {
  display: none !important;
}

.sb-portal-welcome__veil {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 85% 70% at 50% 45%, rgba(255, 253, 251, 0.55) 0%, transparent 55%),
    linear-gradient(165deg, rgba(245, 230, 255, 0.42) 0%, rgba(253, 232, 242, 0.5) 50%, rgba(220, 210, 245, 0.45) 100%);
  opacity: 0;
  transition: opacity 0.55s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.sb-portal-welcome.is-active .sb-portal-welcome__veil {
  opacity: 1;
}

.sb-portal-welcome__inner {
  position: relative;
  width: min(24rem, 100%);
  padding: 1.65rem 1.35rem 1.5rem;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94) 0%, rgba(252, 247, 255, 0.92) 100%);
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow:
    0 4px 0 rgba(180, 140, 200, 0.12),
    0 28px 56px rgba(75, 40, 90, 0.18),
    inset 0 1px 0 #fff;
  text-align: center;
  transform: scale(0.88) translateY(12px);
  opacity: 0;
  transition:
    transform 0.55s cubic-bezier(0.34, 1.35, 0.64, 1),
    opacity 0.45s ease;
}

.sb-portal-welcome.is-active .sb-portal-welcome__inner {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.sb-portal-welcome.is-leaving {
  pointer-events: none;
}

.sb-portal-welcome.is-leaving .sb-portal-welcome__veil {
  opacity: 0;
  transition-duration: 0.28s;
}

.sb-portal-welcome.is-leaving .sb-portal-welcome__inner {
  transform: scale(0.96) translateY(-8px);
  opacity: 0;
  transition:
    transform 0.32s ease,
    opacity 0.28s ease;
}

.sb-portal-welcome__sparkles {
  position: absolute;
  inset: -6px;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
  opacity: 0.85;
}

.sb-portal-welcome__sparkles::before,
.sb-portal-welcome__sparkles::after {
  content: "";
  position: absolute;
  width: 120%;
  height: 120%;
  left: -10%;
  top: -10%;
  background-image:
    radial-gradient(circle at 15% 22%, rgba(255, 220, 120, 0.55) 0%, transparent 9px),
    radial-gradient(circle at 78% 18%, rgba(255, 182, 220, 0.5) 0%, transparent 8px),
    radial-gradient(circle at 42% 78%, rgba(186, 230, 253, 0.5) 0%, transparent 7px),
    radial-gradient(circle at 88% 72%, rgba(196, 181, 253, 0.45) 0%, transparent 8px),
    radial-gradient(circle at 8% 65%, rgba(253, 224, 171, 0.5) 0%, transparent 6px);
  background-size: 100% 100%;
  animation: sb-portal-sparkle-drift 4.5s ease-in-out infinite;
}

.sb-portal-welcome__sparkles::after {
  animation-delay: -2.2s;
  opacity: 0.7;
}

.sb-portal-welcome__mascot {
  position: relative;
  z-index: 1;
  margin: 0 auto 0.25rem;
  max-width: 7.5rem;
}

.sb-portal-welcome__char {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 10px 22px rgba(107, 47, 82, 0.2));
  transform: scale(0.82) translateY(14px);
  opacity: 0;
  transition:
    transform 0.5s cubic-bezier(0.34, 1.35, 0.64, 1),
    opacity 0.4s ease;
  transition-delay: 0.06s;
}

.sb-portal-welcome.is-active .sb-portal-welcome__char {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.sb-portal-welcome.is-leaving .sb-portal-welcome__char {
  transform: scale(0.9) translateY(-6px);
  opacity: 0;
  transition:
    transform 0.28s ease,
    opacity 0.24s ease;
  transition-delay: 0s;
}

@keyframes sb-portal-sparkle-drift {
  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }
  50% {
    transform: translate(3%, -2%) rotate(4deg);
  }
}

.sb-portal-welcome__kicker {
  position: relative;
  margin: 0 0 0.35rem;
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
  color: #7c3a6a;
  letter-spacing: 0.02em;
}

.sb-portal-welcome__title {
  position: relative;
  margin: 0 0 0.65rem;
  font-family: "Fredoka", "Sniglet", "Nunito", sans-serif;
  font-size: clamp(1.6rem, 5vw, 1.9rem);
  font-weight: 800;
  color: #6b2f52;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.sb-portal-welcome__lead {
  position: relative;
  margin: 0 0 1.25rem;
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 0.98rem;
  font-weight: 600;
  color: rgba(80, 45, 70, 0.88);
  line-height: 1.55;
}

.sb-portal-welcome__dismiss {
  position: relative;
  width: 100%;
  max-width: 16rem;
  margin: 0 auto;
  border-radius: 14px;
}

@media (prefers-reduced-motion: reduce) {
  .sb-portal-welcome__veil,
  .sb-portal-welcome__inner {
    transition: opacity 0.2s ease;
  }

  .sb-portal-welcome__char {
    transition: opacity 0.2s ease;
  }

  .sb-portal-welcome.is-active .sb-portal-welcome__inner {
    transform: none;
  }

  .sb-portal-welcome.is-active .sb-portal-welcome__char {
    transform: none;
  }

  .sb-portal-welcome__sparkles::before,
  .sb-portal-welcome__sparkles::after {
    animation: none;
  }

  .sb-portal-welcome.is-leaving .sb-portal-welcome__inner {
    transform: none;
  }

  .sb-portal-welcome.is-leaving .sb-portal-welcome__char {
    transform: none;
  }
}

.sb-landing {
  text-align: center;
  padding: 0.5rem 0 1.5rem;
}

.sb-landing__head {
  margin: 0 0 1.25rem;
}

.sb-landing__emoji {
  margin: 0 0 0.4rem;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0.06em;
}

.sb-landing__title {
  font-family: "Fredoka", "Sniglet", "Nunito", sans-serif;
  font-size: clamp(1.75rem, 5.2vw, 2.125rem);
  font-weight: 800;
  margin: 0;
  color: #831843;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.sb-landing__copy {
  margin: 0 0 1.5rem;
}

.sb-landing__tagline {
  margin: 0 auto 0.85rem;
  max-width: 26rem;
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  font-size: 1.0625rem;
  font-weight: 700;
  color: #6b1d3d;
  line-height: 1.5;
  text-align: center;
}

.sb-landing__lead {
  margin: 0 auto;
  max-width: 28rem;
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  font-size: 0.9375rem;
  font-weight: 600;
  color: rgba(55, 22, 40, 0.96);
  line-height: 1.65;
  text-align: center;
}

.sb-landing__actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.95rem;
  margin-top: 0.25rem;
}

.sb-landing__secondary {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.55rem;
}

.sb-landing__demo-hint {
  margin: 0;
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  font-size: 0.8125rem;
  font-weight: 600;
  color: rgba(91, 39, 68, 0.78);
  line-height: 1.5;
  text-align: center;
}

.sb-landing__split {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  text-align: center;
}

/* Build your book column — frosted card over full-bleed room */
.sb-landing__left {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  padding: clamp(1.35rem, 4.2vw, 1.85rem) clamp(1.2rem, 3.8vw, 1.85rem);
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.92);
  box-shadow:
    0 8px 32px rgba(55, 25, 50, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.98);
}

.sb-landing__left > * {
  position: relative;
  z-index: 1;
}

.sb-landing__left .sb-landing__title {
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.95);
}

.sb-landing__left .sb-landing__tagline,
.sb-landing__left .sb-landing__lead {
  text-shadow: none;
}

.sb-landing__left .sb-landing__tagline {
  color: #6b1d3d;
}

.sb-landing__left .sb-btn.sb-btn--primary.sb-btn--landing-primary {
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  font-size: 1.0625rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  padding: 1rem 1.15rem;
  border-radius: 14px;
  color: #52374d;
  background: linear-gradient(180deg, #f2eaf9 0%, #e7dbf3 40%, #dcc9ea 100%);
  border: 2px solid rgba(125, 95, 150, 0.38);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.72),
    0 2px 0 rgba(140, 110, 165, 0.2),
    0 10px 26px rgba(95, 65, 115, 0.12);
}

.sb-landing__left .sb-btn.sb-btn--primary.sb-btn--landing-primary:active {
  transform: translateY(3px);
  color: #452f40;
  background: linear-gradient(180deg, #eae2f4 0%, #dfd1eb 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 0 0 rgba(140, 110, 165, 0.12);
}

.sb-landing__left .sb-btn--ghost.sb-btn--landing-secondary {
  width: 100%;
  max-width: none;
  flex: none;
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  font-size: 0.9375rem;
  font-weight: 700;
  padding: 0.82rem 1rem;
  border-radius: 14px;
  border: 2px solid rgba(157, 23, 77, 0.35);
  background: rgba(255, 255, 255, 0.78);
  color: #9d174d;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
}

.sb-landing__left .sb-btn--ghost.sb-btn--landing-secondary:active {
  transform: translateY(2px);
}

/* Stacked layout: keep the frosted “Build your book” card compact (~40% viewport height). */
@media (max-width: 899px) {
  body.page-storybook.sb-route-story .sb-landing__left {
    max-height: 40dvh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
}

@media (min-width: 900px) {
  .sb-landing__split {
    flex-direction: row;
    /* Stretch row height so .sb-landing__right gets a definite height for the library flex chain */
    align-items: stretch;
    gap: clamp(1.5rem, 3vw, 2.25rem);
    text-align: left;
  }

  /* Left card stays content-height — does not grow with the library column */
  .sb-landing__left {
    align-self: flex-start;
    flex: 0 1 min(320px, 36%);
    min-width: min(240px, 100%);
    max-width: 38%;
    padding: clamp(1rem, 2.4vw, 1.55rem) clamp(1rem, 2.2vw, 1.35rem);
  }

  .sb-landing__left .sb-landing__emoji {
    font-size: 1.65rem;
    margin-bottom: 0.35rem;
  }

  .sb-landing__left .sb-landing__title {
    font-size: clamp(1.4rem, 2.5vw, 1.75rem);
  }

  .sb-landing__left .sb-landing__copy {
    margin-bottom: 1.15rem;
  }

  .sb-landing__left .sb-landing__tagline {
    font-size: 0.98rem;
    margin-bottom: 0.65rem;
  }

  .sb-landing__left .sb-landing__lead {
    font-size: 0.875rem;
  }

  .sb-landing__left .sb-landing__demo-hint {
    font-size: 0.78rem;
  }

  .sb-landing__left .sb-btn.sb-btn--primary.sb-btn--landing-primary {
    font-size: 0.98rem;
    padding: 0.88rem 1rem;
  }

  .sb-landing__left .sb-btn--ghost.sb-btn--landing-secondary {
    font-size: 0.88rem;
    padding: 0.72rem 0.9rem;
  }

  .sb-landing__left .sb-landing__tagline,
  .sb-landing__left .sb-landing__lead,
  .sb-landing__left .sb-landing__demo-hint,
  .sb-landing__left .sb-landing__emoji {
    text-align: left;
    margin-left: 0;
    margin-right: 0;
  }

  .sb-landing__left .sb-landing__tagline,
  .sb-landing__left .sb-landing__lead {
    max-width: none;
  }

  .sb-landing__left .sb-landing__head {
    text-align: left;
    margin-bottom: 1rem;
  }

  .sb-landing__left .sb-landing__title,
  .sb-landing__left .sb-landing__emoji {
    text-align: left;
  }

  .sb-landing__right {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
  }

  .sb-landing__right .sb-library {
    margin-bottom: 0;
    flex: 1 1 auto;
    min-height: 0;
  }

  /* Landing visible: hub fits viewport; ~80% for nav+story block, ~10% breathing room top/bottom. */
  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden)) {
    box-sizing: border-box;
    min-height: 100dvh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-top: max(0.4rem, env(safe-area-inset-top, 0px), 10dvh);
    padding-bottom: max(0.4rem, env(safe-area-inset-bottom, 0px), 10dvh);
    padding-left: max(0.65rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.65rem, env(safe-area-inset-right, 0px));
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-nav {
    flex: 0 0 auto;
    margin-bottom: 0.4rem;
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-landing {
    flex: 1 1 0;
    min-height: 0;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-landing__split {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-landing__left {
    align-self: flex-start;
    max-height: 100%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-landing__right {
    min-height: 0;
    overflow: hidden;
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-landing__right
    .sb-library {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0.65rem 0.75rem 0.75rem;
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-library__h {
    margin-bottom: 0.25rem;
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-library__hint {
    margin-bottom: 0.45rem;
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-carousel {
    flex: 1 1 0;
    min-height: 0;
    margin-top: 0.4rem;
    align-items: stretch;
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-carousel__track {
    flex: 1 1 0;
    min-height: 0;
    padding: 0.35rem 0.35rem;
    align-items: center;
  }

  /* Let the shelf fill the carousel slab; caps like 62vh are shorter than the flex slot → looks like books are missing. */
  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-landing__right
    #sbShelf.sb-shelf-has-books {
    max-height: none;
    min-height: 0;
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-landing__right
    #sbShelf
    > .sb-cover-card-wrap
    .sb-cover-card {
    --sb-book-thickness: clamp(5px, 0.38rem, 9px);
  }

  body.page-storybook.sb-route-story:not(.sb-modal-open)
    .sb-app:has(#sbLanding:not(.is-hidden))
    .sb-landing__right
    #sbShelf
    > .sb-cover-card-wrap {
    padding-bottom: 0.2rem;
  }
}

.sb-note--landing {
  text-align: left;
  margin-bottom: 1rem;
}

/* My library — frosted panel so covers pop over full-bleed room */
.sb-library {
  text-align: left;
  margin-bottom: 1.35rem;
}

.sb-landing__right .sb-library {
  position: relative;
  margin-bottom: 0;
  padding: 1.2rem 1rem 1.45rem;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    0 6px 28px rgba(80, 20, 55, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.92);
  background: transparent;
  overflow: visible;
}

/* Frosted glass on a ::before layer. Omit isolation: isolate so shelf 3D (preserve-3d) is not flattened in WebKit. */
.sb-landing__right .sb-library::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  z-index: 0;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.4);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.sb-landing__right .sb-library > * {
  position: relative;
  z-index: 1;
}

.sb-landing__right .sb-library__h {
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.95), 0 2px 8px rgba(255, 250, 252, 0.85);
}

.sb-landing__right .sb-library__hint {
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.85);
}

.sb-library__h {
  font-family: "Fredoka", "Sniglet", "Nunito", sans-serif;
  font-size: clamp(1.45rem, 4.5vw, 1.7rem);
  font-weight: 800;
  margin: 0 0 0.5rem;
  color: #9d174d;
  text-align: center;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 0 rgba(251, 207, 232, 0.8);
}

.sb-library__hint {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: #831843;
  line-height: 1.45;
  text-align: center;
}

/* Fixed bottom-left — visually aligned with kids-fbar (mute/settings) on the right */
.sb-cloud-pull-fab {
  position: fixed;
  z-index: 9000;
  left: max(0.5rem, env(safe-area-inset-left));
  bottom: max(0.5rem, env(safe-area-inset-bottom));
  width: 3rem;
  height: 3rem;
  min-width: 48px;
  min-height: 48px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 3px solid #fff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  background: linear-gradient(180deg, #fff, #f3e8ff);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.sb-cloud-pull-fab:active {
  transform: scale(0.96);
}

.sb-cloud-pull-fab__ic {
  display: block;
  line-height: 1;
}

.sb-carousel {
  margin-top: 1.5rem;
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sb-carousel__btn {
  flex: 0 0 2rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: none;
  background: var(--sb-flip-red);
  color: white;
  font-size: 1.5rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(157, 23, 77, 0.25);
  transition: transform 0.15s ease, opacity 0.2s ease, background 0.15s;
  padding-bottom: 2px;
}

.sb-carousel__btn:hover:not(:disabled) {
  background: #be185d;
  transform: scale(1.1);
}

.sb-carousel__btn:active:not(:disabled) {
  transform: scale(0.95);
}

.sb-carousel__btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.sb-carousel__track {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  padding: 1rem 0.5rem;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
}

.sb-carousel__track::-webkit-scrollbar {
  display: none;
}

.sb-carousel__track {
  -ms-overflow-style: none; /* IE and Edge */
  scrollbar-width: none; /* Firefox */
}

.sb-carousel__track > * {
  scroll-snap-align: center;
}

/* My library: all covers visible in one vertical-scroll grid (#sbShelf is the carousel track). */
/* Class from JS (.sb-shelf-has-books): avoid relying only on :has() for shelf grid/scrolling. */
#sbShelf.sb-shelf-has-books {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  justify-items: center;
  align-items: end;
  grid-auto-rows: max-content;
  gap: 0.9rem 0.65rem;
  /* .sb-carousel uses align-items: center — shelf would keep intrinsic grid height,
     overflow .sb-library (overflow:hidden) and hide books below ~ one viewport (~14 in 2 cols). */
  align-self: stretch;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scroll-behavior: auto;
  scroll-snap-type: none;
  /* Loose layouts only — landing hub overrides with max-height:none so the flex chain sets the scroll area */
  max-height: min(62vh, 620px);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(157, 23, 77, 0.45) rgba(255, 255, 255, 0.2);
}

#sbShelf.sb-shelf-has-books::-webkit-scrollbar {
  width: 8px;
  display: block;
}

#sbShelf.sb-shelf-has-books::-webkit-scrollbar-thumb {
  background: rgba(157, 23, 77, 0.4);
  border-radius: 999px;
}

@media (min-width: 520px) {
  #sbShelf.sb-shelf-has-books {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem 0.75rem;
  }
}

@media (min-width: 900px) {
  #sbShelf.sb-shelf-has-books {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.85rem 0.6rem;
  }
}

#sbShelf.sb-shelf-has-books > .sb-cover-card-wrap {
  scroll-snap-align: none;
}

/* Covers fill grid cells (drop the 10.5rem cap inside the shelf grid). */
#sbShelf > .sb-cover-card-wrap .sb-cover-card {
  max-width: 100%;
}

/* My library: flat portrait “app cover” tiles (see .sb-cover-card--library-preview). */
#sbShelf > .sb-cover-card-wrap {
  perspective: none;
  align-items: center;
  padding-bottom: 0.35rem;
}

#sbShelf > .sb-cover-card-wrap:hover,
#sbShelf > .sb-cover-card-wrap:focus-within {
  transform: translateY(-4px) scale(1.03);
}

.sb-cover-card--library-preview {
  container-type: inline-size;
  container-name: sb-lib-cover;
  overflow: hidden;
  border-radius: 5px 13px 15px 6px;
  box-shadow:
    0 2px 8px rgba(25, 45, 80, 0.18),
    0 6px 20px rgba(20, 35, 70, 0.12);
}

.sb-cover-card--library-preview:active {
  transform: scale(0.98);
}

.sb-cover-card__scene--library-flat {
  position: absolute;
  inset: 0;
}

.sb-library-cover {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  border-radius: inherit;
}

.sb-library-cover__spine {
  flex: 0 0 9%;
  min-width: 5px;
  max-width: 14px;
  align-self: stretch;
  border-radius: 4px 0 0 4px;
  box-shadow: inset -3px 0 8px rgba(0, 0, 0, 0.18);
  background: linear-gradient(
    90deg,
    hsl(var(--sb-h, 210), 58%, 34%) 0%,
    hsl(var(--sb-h, 210), 64%, 46%) 100%
  );
}

.sb-library-cover__panel {
  position: relative;
  flex: 1;
  min-width: 0;
  border-radius: 0 10px 12px 0;
  overflow: hidden;
}

.sb-library-cover__panel .sb-cover-card__thumb-bg,
.sb-library-cover__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  z-index: 0;
  pointer-events: none;
  border-radius: 0;
  opacity: var(--sb-cover-photo-opacity, 1);
}

.sb-library-cover__placeholder-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(
    165deg,
    hsl(var(--sb-h, 210), 46%, 44%) 0%,
    hsl(calc(var(--sb-h, 210) + 10), 50%, 32%) 50%,
    hsl(var(--sb-h, 210), 38%, 22%) 100%
  );
}

.sb-library-cover__tint {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    hsla(var(--sb-h, 210), 55%, 26%, 0.42) 0%,
    hsla(var(--sb-h, 210), 48%, 52%, 0.2) 100%
  );
}

.sb-library-cover__frame {
  position: absolute;
  inset: 5.5%;
  z-index: 2;
  pointer-events: none;
  border-radius: 2px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.96),
    inset 0 0 0 3px rgba(15, 40, 80, 0.12),
    inset 0 0 0 4px rgba(255, 255, 255, 0.82);
}

.sb-library-cover__titles {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16% 9% 14%;
  text-align: center;
  pointer-events: none;
}

.sb-library-cover__sparkle-icon {
  display: block;
  margin-bottom: 0.28rem;
  font-size: clamp(0.52rem, 4.4cqw, 0.76rem);
  color: #ffe14a;
  text-shadow:
    0 0 10px rgba(255, 225, 80, 0.95),
    0 0 2px rgba(140, 90, 0, 0.45);
  line-height: 1;
  transform: rotate(-10deg);
}

.sb-library-cover__title {
  font-family: "Fredoka", "Sniglet", "Nunito", sans-serif;
  font-size: clamp(0.52rem, 5.6cqw, 0.92rem);
  font-weight: 700;
  line-height: 1.14;
  color: #fffefd;
  text-shadow:
    0 1px 4px rgba(0, 0, 0, 0.45),
    0 2px 14px rgba(20, 35, 80, 0.35);
  max-width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sb-library-cover__tap {
  margin-top: 0.32rem;
  font-family: "Nunito", "Fredoka", sans-serif;
  font-size: clamp(0.4rem, 3.55cqw, 0.58rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.93);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

#sbShelf > .sb-cover-card-wrap .sb-cover-card--library-preview.sb-cover-card--has-art:hover .sb-cover-card__thumb-bg,
#sbShelf
  > .sb-cover-card-wrap:focus-within
  .sb-cover-card--library-preview.sb-cover-card--has-art
  .sb-cover-card__thumb-bg {
  filter: saturate(1.07) brightness(1.02);
}

.sb-library__empty {
  margin: 0;
  padding: 1.25rem 0.65rem;
  text-align: center;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 0.86rem;
  font-weight: 600;
  color: rgba(80, 55, 68, 0.72);
  text-shadow: none;
  line-height: 1.45;
  min-height: 6.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Fore-edge visible at rest (CSS-book style); hover swings deeper. Idle == keyframe 0%/100%. */
@keyframes sb-shelf-book-sway {
  0%,
  100% {
    transform: translate3d(0, 0, 0) rotateX(2deg) rotateY(-34deg);
  }
  50% {
    transform: translate3d(0, 0, 0) rotateX(5.5deg) rotateY(-48deg);
  }
}

#sbShelf > .sb-cover-card-wrap:nth-child(1) {
  --sb-shelf-stagger: 0s;
}
#sbShelf > .sb-cover-card-wrap:nth-child(2) {
  --sb-shelf-stagger: 0.83s;
}
#sbShelf > .sb-cover-card-wrap:nth-child(3) {
  --sb-shelf-stagger: 1.67s;
}
#sbShelf > .sb-cover-card-wrap:nth-child(4) {
  --sb-shelf-stagger: 2.5s;
}
#sbShelf > .sb-cover-card-wrap:nth-child(5) {
  --sb-shelf-stagger: 3.33s;
}
#sbShelf > .sb-cover-card-wrap:nth-child(6) {
  --sb-shelf-stagger: 4.17s;
}
#sbShelf > .sb-cover-card-wrap:nth-child(7) {
  --sb-shelf-stagger: 5s;
}
#sbShelf > .sb-cover-card-wrap:nth-child(8) {
  --sb-shelf-stagger: 5.83s;
}
#sbShelf > .sb-cover-card-wrap:nth-child(9) {
  --sb-shelf-stagger: 6.67s;
}

#sbShelf > .sb-cover-card-wrap:nth-child(10) {
  --sb-shelf-stagger: 0.35s;
}
#sbShelf > .sb-cover-card-wrap:nth-child(11) {
  --sb-shelf-stagger: 2.1s;
}
#sbShelf > .sb-cover-card-wrap:nth-child(12) {
  --sb-shelf-stagger: 4.85s;
}

/* Front-facing shelf book: real cover art + soft spine; placeholder keeps cloth fallback */
.sb-cover-card-wrap {
  --sb-shelf-stagger: 0s;
  --sb-shelf-anim-dur: 7.5s;
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 2;
  transition:
    transform 0.62s cubic-bezier(0.33, 1, 0.48, 1),
    z-index 0s linear;
  width: 100%;
  perspective: min(880px, 138vw);
  perspective-origin: 40% 40%;
  padding-bottom: 0.45rem;
  box-sizing: border-box;
}

.sb-cover-card-wrap:hover,
.sb-cover-card-wrap:focus-within {
  z-index: 8;
  transform: translateY(-8px) scale(1.05);
}

.sb-cover-card-wrap:hover .sb-cover-card__book,
.sb-cover-card-wrap:focus-within .sb-cover-card__book {
  animation: sb-shelf-book-sway var(--sb-shelf-anim-dur, 7.5s) cubic-bezier(0.42, 0, 0.58, 1) infinite;
  animation-delay: var(--sb-shelf-stagger, 0s);
}

.sb-cover-card {
  position: relative;
  display: block;
  width: 100%;
  max-width: 10.5rem;
  aspect-ratio: 3 / 4;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 3px 12px 14px 5px;
  cursor: pointer;
  touch-action: manipulation;
  overflow: visible;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  --sb-book-thickness: clamp(9px, 0.56rem, 14px);
}

.sb-cover-card__scene {
  position: absolute;
  inset: 0;
}

.sb-cover-card__book {
  position: absolute;
  inset: 0;
  z-index: 1;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transform: translate3d(0, 0, 0) rotateX(2deg) rotateY(-34deg);
  -webkit-transform: translate3d(0, 0, 0) rotateX(2deg) rotateY(-34deg);
  transform-origin: 52% 90%;
  animation: none;
  transition: transform 0.4s cubic-bezier(0.42, 0, 0.58, 1);
}

.sb-cover-card__book-front {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  transform: translateZ(calc(var(--sb-book-thickness) + 0.75px));
  -webkit-transform: translateZ(calc(var(--sb-book-thickness) + 0.75px));
  transform-style: flat;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.sb-cover-card__book-back {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  transform: translateZ(calc(-1 * var(--sb-book-thickness)));
  -webkit-transform: translateZ(calc(-1 * var(--sb-book-thickness)));
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.sb-cover-card--has-art .sb-cover-card__book-back {
  background: linear-gradient(
    135deg,
    hsl(var(--sb-h), 44%, 26%) 0%,
    hsl(var(--sb-h), 38%, 18%) 55%,
    hsl(var(--sb-h), 42%, 14%) 100%
  );
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.sb-cover-card--placeholder .sb-cover-card__book-back {
  background: linear-gradient(145deg, #353234 0%, #2a2829 50%, #1f1d1e 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.sb-cover-card--has-art .sb-cover-card__book-paper {
  background:
    linear-gradient(
      90deg,
      hsla(var(--sb-h), 42%, 22%, 0.88) 0%,
      hsla(var(--sb-h), 38%, 18%, 0.35) 18%,
      transparent 34%
    ),
    linear-gradient(90deg, rgba(0, 0, 0, 0.22), rgba(255, 255, 255, 0)),
    repeating-linear-gradient(
      90deg,
      #faf7f0 0,
      #faf7f0 2px,
      rgba(48, 42, 38, 0.14) 2px,
      rgba(48, 42, 38, 0.14) 2.5px,
      #f4f0e8 2.5px,
      #f4f0e8 5px
    );
}

.sb-cover-card__book-paper {
  height: 98%;
  width: calc(var(--sb-book-thickness) * 2);
  position: absolute;
  top: 1%;
  right: 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.24), rgba(255, 255, 255, 0)),
    repeating-linear-gradient(
      90deg,
      #faf7f0 0,
      #faf7f0 2px,
      rgba(48, 42, 38, 0.14) 2px,
      rgba(48, 42, 38, 0.14) 2.5px,
      #f4f0e8 2.5px,
      #f4f0e8 5px
    );
  border-radius: 0 2px 2px 0;
  transform: rotateY(90deg) translateX(calc(var(--sb-book-thickness) / 10))
    translateZ(calc(var(--sb-book-thickness) * 0.32));
  -webkit-transform: rotateY(90deg) translateX(calc(var(--sb-book-thickness) / 10))
    translateZ(calc(var(--sb-book-thickness) * 0.32));
  transform-origin: right center;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  box-shadow: inset -2px 0 5px rgba(0, 0, 0, 0.12);
}

/* 3D "floor" ellipse removed — looked like a flat plate behind the book; use light tile shadow only */
.sb-cover-card__book-shadow {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .sb-cover-card-wrap {
    transition: transform 0.2s ease, z-index 0s linear;
  }

  .sb-cover-card__book {
    transform: translate3d(0, 0, 0) rotateX(2deg) rotateY(-34deg);
    -webkit-transform: translate3d(0, 0, 0) rotateX(2deg) rotateY(-34deg);
    animation: none !important;
    transition: none;
  }

  .sb-cover-card-wrap:hover .sb-cover-card__book,
  .sb-cover-card-wrap:focus-within .sb-cover-card__book {
    animation: none !important;
  }
}

/* Shelf books with artwork: show cover photo — soft paper edge + coloured spine (no black frame) */
.sb-cover-card--has-art {
  --sb-cover-photo-opacity: 1;
  background: transparent;
  box-shadow: 0 4px 12px rgba(45, 32, 42, 0.12);
}

.sb-cover-card--placeholder {
  background: transparent;
  box-shadow: 0 4px 12px rgba(25, 15, 32, 0.12);
}

.sb-cover-card--library-preview.sb-cover-card--has-art {
  box-shadow:
    0 2px 8px rgba(25, 45, 80, 0.18),
    0 6px 20px rgba(20, 35, 70, 0.12);
}

.sb-cover-card--library-preview.sb-cover-card--placeholder {
  box-shadow: 0 4px 14px rgba(25, 15, 32, 0.14);
}

.sb-cover-card--hardback:active {
  transform: scale(0.98);
}

.sb-cover-card:focus-visible {
  outline: 3px solid #f9a8d4;
  outline-offset: 3px;
}

.sb-cover-card__face {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: inherit;
}

.sb-cover-card__hardback {
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.sb-cover-card__cloth {
  position: absolute;
  inset: 4px;
  border-radius: 2px 10px 10px 2px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 9% 0.32rem 0.45rem;
  border-left: 4px solid rgba(15, 10, 12, 0.55);
  box-shadow:
    inset 3px 0 12px rgba(255, 255, 245, 0.1),
    inset 0 -2px 6px rgba(0, 0, 0, 0.12);
}

.sb-cover-card--has-art .sb-cover-card__cloth {
  inset: 0;
  padding: 0;
  border-left: none;
  border-radius: inherit;
  background: transparent;
  box-shadow: none;
}

.sb-cover-card__cloth--pat0 {
  background: linear-gradient(
    145deg,
    hsl(var(--sb-h, 320), 58%, 44%) 0%,
    hsl(var(--sb-h, 320), 50%, 30%) 100%
  );
}

.sb-cover-card__cloth--pat1 {
  background: linear-gradient(
    145deg,
    hsl(calc(var(--sb-h, 280) + 18), 55%, 48%) 0%,
    hsl(var(--sb-h, 280), 48%, 30%) 100%
  );
}

.sb-cover-card__cloth--pat2 {
  background: linear-gradient(
    145deg,
    hsl(var(--sb-h, 200), 52%, 42%) 0%,
    hsl(calc(var(--sb-h, 200) - 16), 45%, 28%) 100%
  );
}

.sb-cover-card__cloth--pat3 {
  background: linear-gradient(
    145deg,
    hsl(calc(var(--sb-h, 340) + 8), 53%, 46%) 0%,
    hsl(var(--sb-h, 340), 46%, 29%) 100%
  );
}

.sb-cover-card--has-art .sb-cover-card__cloth--pat0,
.sb-cover-card--has-art .sb-cover-card__cloth--pat1,
.sb-cover-card--has-art .sb-cover-card__cloth--pat2,
.sb-cover-card--has-art .sb-cover-card__cloth--pat3 {
  background: transparent;
}

.sb-cover-card__thumb-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: var(--sb-cover-photo-opacity, 1);
  filter: none;
  z-index: 5;
  pointer-events: none;
  border-radius: inherit;
}

.sb-cover-card--has-art:hover .sb-cover-card__thumb-bg,
.sb-cover-card-wrap:focus-within .sb-cover-card--has-art .sb-cover-card__thumb-bg {
  filter: saturate(1.05);
}

.sb-cover-card__gilt {
  flex-shrink: 0;
  height: 2px;
  margin: 0 7%;
  border-radius: 2px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 242, 200, 0.45) 15%,
    #e8c56a 50%,
    rgba(255, 242, 200, 0.45) 85%,
    transparent 100%
  );
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  z-index: 10;
}

.sb-cover-card--has-art .sb-cover-card__gilt {
  display: none;
}

.sb-cover-card__gilt--top {
  margin-bottom: 0.4rem;
}

.sb-cover-card__gilt--bot {
  margin-top: auto;
  margin-bottom: 0.28rem;
}

.sb-cover-card__cover-title-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0.5rem 0.4rem;
  z-index: 10;
  position: relative;
  background: rgba(0, 0, 0, 0.45);
  margin: 0 4%;
  border-radius: 6px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.sb-cover-card--has-art .sb-cover-card__cover-title-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  flex: unset;
  min-height: unset;
  margin: 0;
  padding: 0.55rem 0.35rem 0.45rem;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(0, 0, 0, 0.05) 28%,
    rgba(0, 0, 0, 0.75) 100%
  );
  border-radius: 0;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
}

.sb-cover-card__cover-title {
  font-family: "Fredoka", "Sniglet", "Nunito", serif;
  font-size: clamp(0.7rem, 3.5vw, 1.1rem);
  font-weight: 700;
  line-height: 1.22;
  text-align: center;
  letter-spacing: 0.01em;
  color: #fffdf7;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.8),
    0 0 10px rgba(0, 0, 0, 0.6);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.sb-cover-card--has-art .sb-cover-card__cover-title {
  -webkit-line-clamp: 2;
  line-clamp: 2;
  font-size: clamp(0.62rem, 2.6vw, 0.88rem);
}

.sb-cover-card--placeholder .sb-cover-card__thumb-bg {
  display: none;
}

.sb-shelf-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  font-size: 0.72rem;
  line-height: 1;
  font-weight: 800;
  color: #fff;
  background: rgba(55, 45, 55, 0.38);
  cursor: pointer;
  z-index: 12;
  opacity: 0.65;
  transition: opacity 0.15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.sb-cover-card-wrap:focus-within .sb-shelf-remove,
.sb-cover-card-wrap:hover .sb-shelf-remove {
  opacity: 1;
}

.sb-shelf-remove:active {
  background: rgba(185, 28, 28, 0.9);
}

.sb-note--modal {
  text-align: center;
  margin: 0 0 0.65rem;
}

/* Journey modal */
.sb-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-height: 520px) {
  .sb-modal {
    align-items: center;
  }
}

.sb-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(131, 24, 67, 0.45);
  backdrop-filter: blur(4px);
}

.sb-modal__sheet {
  position: relative;
  width: 100%;
  max-width: min(40rem, calc(100vw - 1.25rem));
  max-height: min(92dvh, 36rem);
  overflow-y: auto;
  margin: 0 auto;
  padding: 3.1rem 3.15rem 1.65rem 1.25rem;
  /* Softer dots + cleaner base so body text isn’t fighting pink-on-pink */
  background-color: #fffdfbff;
  background-image: radial-gradient(rgba(219, 39, 119, 0.11) 17%, transparent 18%);
  background-size: 18px 18px;
  background-position: 0 0;
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -12px 48px rgba(131, 24, 67, 0.18), 0 0 0 1px rgba(244, 114, 182, 0.2);
  border: 4px solid #fbcfe8;
  border-bottom: none;
}

@media (min-height: 520px) {
  .sb-modal__sheet {
    border-radius: 28px;
    border: 4px solid #fbcfe8;
    margin: 1rem;
  }
}

.sb-modal__close {
  position: absolute;
  top: max(0.5rem, env(safe-area-inset-top, 0px));
  right: max(0.5rem, env(safe-area-inset-right, 0px));
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  margin: 0;
  border: 2px solid rgba(219, 39, 119, 0.28);
  border-radius: 50%;
  background: rgba(255, 253, 251, 0.95);
  box-shadow: 0 1px 4px rgba(131, 24, 67, 0.1);
  font: inherit;
  line-height: 1;
  color: #86143f;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, transform 0.12s ease, border-color 0.15s ease;
}

.sb-modal__close:hover {
  background: #fff;
  border-color: rgba(219, 39, 119, 0.45);
}

.sb-modal__close:active {
  transform: scale(0.96);
}

.sb-modal__close-x {
  font-size: 1.15rem;
  font-weight: 800;
  opacity: 0.88;
}

.sb-modal__progress {
  display: flex;
  justify-content: center;
  gap: 0.2rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.sb-progress-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.22rem;
  min-width: 2.85rem;
}

.sb-progress-step__label {
  font-size: 0.6rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #be185d;
  opacity: 0.72;
  line-height: 1.1;
  text-align: center;
  max-width: 4.2rem;
}

.sb-progress-step.is-current .sb-progress-step__label {
  opacity: 1;
  color: #9d174d;
}

.sb-progress-step.is-done .sb-progress-step__label {
  opacity: 0.85;
}

.sb-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fbcfe8;
  transition: transform 0.15s, background 0.15s;
}

.sb-progress-step.is-done .sb-dot {
  background: #f472b6;
}

.sb-progress-step.is-current .sb-dot {
  background: #db2777;
  transform: scale(1.2);
}

.sb-modal__kicker {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #be185d;
  text-align: center;
}

.sb-modal__heading {
  font-family: "Sniglet", "Nunito", sans-serif;
  font-size: clamp(1.45rem, 4.5vw, 1.7rem);
  font-weight: 800;
  margin: 0 0 0.35rem;
  color: #9d174d;
  text-align: center;
  text-shadow: 0 2px 0 rgba(251, 207, 232, 0.8);
}

.sb-modal__read-step-wrap {
  text-align: center;
  margin: 0 0 0.75rem;
}

.sb-read-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 2px solid rgba(219, 39, 119, 0.35);
  background: rgba(252, 231, 243, 0.95);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  color: #9d174d;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 2px 0 rgba(219, 39, 119, 0.12);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.sb-read-step:active {
  transform: translateY(1px);
}

.sb-panel__why {
  margin: 0 0 0.75rem;
  font-size: 0.84rem;
  font-weight: 700;
  font-style: italic;
  color: #86143f;
  line-height: 1.45;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.85);
  opacity: 0.95;
}

.sb-panel__text {
  margin: 0 0 1.1rem;
  font-size: 0.94rem;
  font-weight: 700;
  color: #5c1835;
  line-height: 1.55;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.85);
}

.sb-panel__hint {
  margin: 0 0 0.65rem;
  font-size: 0.92rem;
  font-weight: 800;
  color: #701a36;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
}

.sb-panel__hint--tight {
  margin-bottom: 0.4rem;
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.4;
  color: #5c1835;
}

.sb-panel__micro {
  margin: 0.45rem 0 0.85rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: #631f3b;
}

.sb-picture-quality {
  border: none;
  margin: 0.35rem 0 0.25rem;
  padding: 0;
}

.sb-picture-quality .sb-label--secondary {
  margin-bottom: 0.25rem;
}

.sb-picture-quality__hint {
  margin-top: 0.2rem;
  margin-bottom: 0.55rem;
}

.sb-book-spread-layout {
  border: none;
  margin: 1.1rem 0 0.25rem;
  padding: 0;
}

.sb-book-spread-layout .sb-label--secondary {
  margin-bottom: 0.25rem;
}

.sb-book-spread-layout__hint {
  margin-top: 0.2rem;
  margin-bottom: 0.55rem;
}

.sb-story-text-mode {
  border: none;
  margin: 1.1rem 0 0.25rem;
  padding: 0;
}

.sb-story-text-mode .sb-label--secondary {
  margin-bottom: 0.25rem;
}

.sb-story-text-mode__hint {
  margin-top: 0.2rem;
  margin-bottom: 0.55rem;
}

.sb-story-length {
  border: none;
  margin: 1.1rem 0 0.25rem;
  padding: 0;
}

.sb-story-length .sb-label--secondary {
  margin-bottom: 0.25rem;
}

.sb-story-length__hint {
  margin-top: 0.2rem;
  margin-bottom: 0.55rem;
}

.sb-illustration-styles {
  border: none;
  margin: 1rem 0 0.35rem;
  padding: 0;
}

.sb-illustration-styles .sb-label--secondary {
  margin-bottom: 0.25rem;
}

.sb-illustration-styles__hint {
  margin-top: 0.2rem;
  margin-bottom: 0.65rem;
}

.sb-style-picks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.25rem, 1fr));
  gap: 0.5rem;
}

.sb-style-pick {
  display: block;
  margin: 0;
  cursor: pointer;
}

.sb-style-pick input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.sb-style-pick__card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  padding: 0.45rem 0.5rem 0.55rem;
  border-radius: 12px;
  border: 2px solid rgba(157, 23, 77, 0.18);
  background: rgba(255, 255, 255, 0.72);
  box-sizing: border-box;
  min-height: 100%;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease;
}

.sb-style-pick:has(input:focus-visible) .sb-style-pick__card {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
}

.sb-style-pick:has(input:checked) .sb-style-pick__card {
  border-color: rgba(124, 58, 237, 0.75);
  background: rgba(237, 233, 254, 0.95);
  box-shadow: 0 2px 10px rgba(88, 28, 135, 0.12);
}

.sb-style-pick__thumb {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
  background: rgba(247, 244, 235, 0.9);
}

.sb-style-pick__thumb-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}

.sb-style-pick__text {
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  text-align: center;
}

.sb-style-pick__title {
  font-size: 0.78rem;
  font-weight: 800;
  color: rgba(42, 10, 31, 0.92);
  line-height: 1.25;
}

.sb-style-pick__sub {
  font-size: 0.66rem;
  font-weight: 600;
  color: rgba(55, 35, 60, 0.62);
  line-height: 1.3;
}

.sb-quality-row {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

@media (min-width: 420px) {
  .sb-quality-row {
    flex-direction: row;
    gap: 0.5rem;
  }
}

/* Three picture-tier options: allow wrap so labels stay readable on tablets */
.sb-picture-quality .sb-quality-row {
  flex-wrap: wrap;
}
@media (min-width: 420px) {
  .sb-picture-quality .sb-quality-opt {
    flex: 1 1 min(100%, 200px);
  }
}

.sb-quality-opt {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  cursor: pointer;
  padding: 0.55rem 0.6rem;
  border-radius: 12px;
  border: 2px solid rgba(157, 23, 77, 0.22);
  background: rgba(255, 255, 255, 0.65);
  box-sizing: border-box;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}

.sb-quality-opt:has(input:focus-visible) {
  outline: 3px solid #f9a8d4;
  outline-offset: 2px;
}

.sb-quality-opt:has(input:checked) {
  border-color: rgba(157, 23, 77, 0.55);
  background: rgba(252, 231, 243, 0.85);
}

.sb-quality-opt input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.sb-quality-opt__body {
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  min-width: 0;
}

.sb-quality-opt__title {
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  font-size: 0.92rem;
  font-weight: 800;
  color: #831843;
}

.sb-quality-opt__sub {
  font-size: 0.76rem;
  font-weight: 600;
  color: rgba(91, 39, 68, 0.78);
  line-height: 1.25;
}

.sb-modal__actions {
  margin-top: 1.1rem;
}

.sb-modal__actions--split {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.sb-modal__actions--split .sb-btn--ghost {
  flex: 0 1 auto;
  min-width: 5rem;
}

.sb-modal__actions--split .sb-btn--primary {
  flex: 1 1 auto;
}

.sb-modal__actions--full {
  margin-top: 0.4rem;
}

.sb-modal__actions--full .sb-btn {
  width: 100%;
}

.sb-panel__micro--skip-hint {
  margin-top: 0.35rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.75rem;
  color: #522030;
  opacity: 1;
}

.sb-btn--modal {
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
}

.sb-textarea {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border-radius: 16px;
  border: 3px solid rgba(219, 39, 119, 0.25);
  font: inherit;
  font-weight: 700;
  color: #3d0a22;
  background: #fff;
  resize: vertical;
  min-height: 6.5rem;
  line-height: 1.45;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.sb-textarea:focus {
  outline: none;
  border-color: #f472b6;
  box-shadow: 0 0 0 4px rgba(244, 114, 182, 0.25), inset 0 2px 4px rgba(0,0,0,0.02);
}

.sb-textarea.sb-textarea--compact {
  min-height: 4.75rem;
  font-weight: 650;
}

.sb-custom-choice-wrap .sb-label--secondary {
  margin-top: 0;
}

.sb-custom-choice-wrap {
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px dashed rgba(219, 39, 119, 0.22);
}

.sb-label.sb-label--secondary {
  font-size: 0.72rem;
  margin-bottom: 0.35rem;
  color: #9d174d;
}

.sb-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #be185d;
  margin-bottom: 0.35rem;
}

.sb-label--secondary {
  margin-top: 1rem;
}

/* Scene chips + plot idea share the last wizard step */
.sb-panel__scene-heading {
  margin-top: 0;
}

.sb-panel__story-idea-wrap {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed rgba(219, 39, 119, 0.2);
}

.sb-input {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border-radius: 16px;
  border: 3px solid rgba(219, 39, 119, 0.25);
  font: inherit;
  font-weight: 700;
  background: #fff;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.sb-input:focus {
  outline: none;
  border-color: #f472b6;
  box-shadow: 0 0 0 4px rgba(244, 114, 182, 0.25), inset 0 2px 4px rgba(0,0,0,0.02);
}

.sb-voice-row {
  display: flex;
  align-items: stretch;
  gap: 0.45rem;
}

.sb-input--flex {
  flex: 1;
  min-width: 0;
  width: auto;
}

.sb-voice-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-width: 3.25rem;
  padding: 0.5rem 0.65rem;
  border-radius: 14px;
  border: 2px solid rgba(219, 39, 119, 0.45);
  background: #fdf2f8;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  color: #9d174d;
  cursor: pointer;
  touch-action: manipulation;
  line-height: 1.1;
}

.sb-voice-btn__ic {
  font-size: 1.05rem;
  line-height: 1;
}

.sb-voice-btn__txt {
  max-width: 4.2rem;
  text-align: center;
}

@media (min-width: 360px) {
  .sb-voice-btn__txt {
    max-width: none;
  }
}

.sb-voice-btn.is-listening {
  background: linear-gradient(180deg, #f472b6 0%, #db2777 100%);
  border-color: #9d174d;
  color: #fff;
  animation: sb-voice-pulse 1.1s ease-in-out infinite;
}

@keyframes sb-voice-pulse {
  50% {
    filter: brightness(1.08);
  }
}

.sb-voice-btn:focus-visible {
  outline: 3px solid rgba(219, 39, 119, 0.55);
  outline-offset: 2px;
}

.sb-voice-btn[disabled],
.sb-voice-btn.is-unavailable {
  opacity: 0.45;
  cursor: not-allowed;
  animation: none;
}

.sb-voice-plot-actions {
  margin-top: 0.45rem;
}

.sb-voice-btn--block {
  width: 100%;
  min-height: 2.65rem;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
}

.sb-voice-btn--block .sb-voice-btn__txt {
  max-width: none;
}

.sb-voice-hint {
  min-height: 1.15rem;
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: #be185d;
  line-height: 1.35;
}

.sb-hero-ref {
  margin: 1rem 0 0;
}

.sb-filepick {
  margin: 0.45rem 0 0;
}

.sb-filepick__btn {
  width: 100%;
  max-width: 100%;
  border-radius: 16px;
  border-width: 3px;
  font-weight: 800;
  font-size: 0.95rem;
  justify-content: center;
}

.sb-book-colors {
  margin: 0.35rem 0 0;
}

.sb-book-colors__toggle {
  margin-top: 0.5rem;
  width: 100%;
  justify-content: center;
  border-radius: 14px;
}

.sb-book-colors__extra {
  margin-top: 0.55rem;
  padding: 0.65rem 0.45rem 0.5rem;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 16px;
  border: 2px solid rgba(219, 39, 119, 0.18);
}

.sb-color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5.6rem, 1fr));
  gap: 0.45rem;
  justify-items: stretch;
}

.sb-color-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.28rem;
  padding: 0.4rem 0.35rem 0.45rem;
  margin: 0;
  border-radius: 14px;
  border: 2px solid rgba(219, 39, 119, 0.22);
  background: #fff;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.sb-color-swatch:active {
  transform: scale(0.97);
}

.sb-color-swatch.is-selected {
  border-color: #db2777;
  border-width: 3px;
  box-shadow: 0 2px 0 rgba(157, 23, 77, 0.12);
}

.sb-color-swatch__dot {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.06),
    0 2px 6px rgba(60, 30, 50, 0.14);
}

.sb-color-swatch__dot--auto {
  background: conic-gradient(
    from 0deg,
    #fbcfe8,
    #c4b5fd,
    #93c5fd,
    #86efac,
    #fde047,
    #fdba74,
    #fb7185,
    #fbcfe8
  );
}

.sb-color-swatch__label {
  font-size: 0.68rem;
  font-weight: 800;
  color: #631f3b;
  line-height: 1.15;
  text-align: center;
}

.sb-filepick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sb-filepick .sb-filepick__btn {
  flex: 1 1 13rem;
  width: auto;
  max-width: none;
  white-space: nowrap;
}

.sb-savedchar__open[hidden] {
  display: none;
}

.sb-savedchar {
  margin: 0.55rem 0 0;
  padding: 0.7rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.75);
  border: 2px dashed rgba(219, 39, 119, 0.3);
}

.sb-savedchar__status {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: #6b1d4a;
}

.sb-savedchar__grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
  gap: 0.55rem;
}

.sb-savedchar__item {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.35rem 0.45rem;
  border: 3px solid transparent;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(131, 24, 67, 0.12);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.sb-savedchar__item:hover {
  transform: translateY(-2px);
}

.sb-savedchar__item.is-added {
  border-color: #db2777;
}

.sb-savedchar__item.is-busy {
  opacity: 0.6;
  cursor: progress;
}

.sb-savedchar__pic {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: #fdf2f8;
  font-size: 1.4rem;
}

.sb-savedchar__pic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sb-savedchar__name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  font-weight: 800;
  color: #6b1d4a;
}

.sb-savedchar__tick {
  position: absolute;
  top: -0.45rem;
  right: -0.45rem;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  display: none;
  place-items: center;
  background: #db2777;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 800;
}

.sb-savedchar__item.is-added .sb-savedchar__tick {
  display: grid;
}

.sb-savedchar__make {
  display: inline-block;
  margin-top: 0.6rem;
  font-size: 0.85rem;
  font-weight: 800;
  color: #db2777;
}

/* File field is .visually-hidden — picker is .sb-filepick__btn */
.sb-hero-ref__input {
  margin: 0;
}

.sb-hero-ref__preview {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.65rem 0 0;
  flex-wrap: nowrap;
}

.sb-hero-ref__thumb {
  width: 4.5rem;
  height: 4.5rem;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid rgba(219, 39, 119, 0.28);
  box-shadow: 0 2px 8px rgba(131, 24, 67, 0.12);
  flex-shrink: 0;
}

.sb-hero-ref__thumbs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.65rem;
  align-items: flex-start;
}

.sb-hero-ref__thumb-wrap {
  position: relative;
  display: block;
  align-self: flex-start;
  border-radius: 12px;
  line-height: 0;
}

.sb-hero-ref__thumb-item {
  position: relative;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  width: fit-content;
  max-width: 100%;
}

.sb-hero-ref__who-input {
  display: block;
  width: 100%;
  min-width: 9rem;
  max-width: 12rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: inherit;
  color: #6b1d4a;
  background: #fff;
  border: 2px solid rgba(219, 39, 119, 0.35);
  border-radius: 10px;
  box-sizing: border-box;
}

.sb-hero-ref__thumb-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 1.375rem;
  height: 1.375rem;
  min-width: 1.375rem;
  min-height: 1.375rem;
  border-radius: 50%;
  border: none;
  background: rgba(30, 20, 30, 0.55);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
}

.sb-hero-ref__thumb-remove:focus-visible {
  outline: 2px solid #db2777;
  outline-offset: 2px;
}

.sb-hero-ref__remove-all {
  margin: 0;
  padding: 0.15rem 0;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  color: rgba(107, 29, 74, 0.72);
  text-decoration: underline;
  letter-spacing: 0.02em;
  align-self: flex-start;
  -webkit-tap-highlight-color: transparent;
}

.sb-hero-ref__remove-all:active {
  color: #9d174d;
}

/* Pop-up after adding a reference photo — big type for kids */
.sb-hero-name-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.85rem;
  box-sizing: border-box;
  background: rgba(75, 20, 50, 0.28);
  backdrop-filter: blur(3px);
}

.sb-hero-name-overlay__card {
  width: min(21rem, 100%);
  padding: 1.15rem 1.05rem 1.2rem;
  border-radius: 22px;
  background: linear-gradient(160deg, #fffefb 0%, #fff6fb 48%, #fdf2ff 100%);
  border: 3px solid #fbcfe8;
  box-shadow:
    0 12px 36px rgba(107, 25, 70, 0.22),
    0 0 0 1px rgba(255, 255, 255, 0.95) inset;
  text-align: center;
}

.sb-hero-name-overlay__title {
  margin: 0 0 0.35rem;
  font-size: clamp(1.35rem, 4.8vw, 1.72rem);
  font-weight: 900;
  line-height: 1.18;
  color: #831843;
  letter-spacing: -0.01em;
}

.sb-hero-name-overlay__lead {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.38;
  color: #73123d;
}

.sb-hero-name-overlay__thumb-wrap {
  display: flex;
  justify-content: center;
  margin: 0 0 0.95rem;
}

.sb-hero-name-overlay__thumb {
  width: 6rem;
  height: 6rem;
  border-radius: 16px;
  object-fit: cover;
  border: 3px solid rgba(251, 113, 133, 0.45);
  box-shadow: 0 6px 20px rgba(131, 24, 67, 0.15);
}

.sb-hero-name-overlay__voice-row {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  margin: 0 0 0.45rem;
}

.sb-hero-name-overlay__input {
  flex: 1;
  min-height: 2.85rem;
  font-size: 1.06rem !important;
  font-weight: 700;
  border-radius: 14px !important;
  padding: 0.45rem 0.65rem !important;
}

.sb-voice-btn--hero-photo {
  flex-shrink: 0;
  align-self: stretch;
  min-height: 2.85rem;
  padding-inline: 0.6rem !important;
}

.sb-voice-btn--hero-photo .sb-voice-btn__txt {
  font-size: 0.8rem !important;
}

.sb-hero-name-overlay__voice-hint {
  margin: 0 0 0.35rem;
  min-height: 1rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: #db2777;
  line-height: 1.3;
}

.sb-hero-name-overlay__err {
  margin: 0 0 0.65rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: #be123c;
  line-height: 1.35;
}

.sb-hero-name-overlay__quick {
  margin: 0 0 0.55rem;
  min-height: 2rem;
}

.sb-hero-name-overlay__quick-btn.sb-btn {
  padding: 0.4rem 0.95rem !important;
  border-radius: 999px !important;
  font-size: 0.92rem !important;
}

.sb-hero-name-overlay__actions {
  margin: 0.15rem 0 0;
}

.sb-hero-name-overlay__done.sb-btn {
  width: 100%;
  min-height: 2.85rem;
  font-size: 1.1rem !important;
  border-radius: 16px !important;
  font-weight: 900 !important;
}

.sb-note--inline {
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
}

.sb-btn--small {
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
}

.sb-fieldset {
  border: none;
  margin: 0 0 1rem;
  padding: 0;
}

.sb-legend {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #be185d;
  margin-bottom: 0.45rem;
  padding: 0;
}

.sb-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.sb-chip-row--family {
  margin-bottom: 0.35rem;
}

.sb-chip {
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 3px solid rgba(219, 39, 119, 0.28);
  background: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  color: #831843;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s ease;
  box-shadow: 0 2px 0 rgba(219, 39, 119, 0.1);
}

.sb-chip:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 rgba(219, 39, 119, 0.1);
}

.sb-chip.is-selected {
  border-color: #db2777;
  background: #fce7f3;
  color: #831843;
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(219, 39, 119, 0.15);
}

.sb-chip--with-icon {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
}

.sb-chip__ic {
  font-size: 1.05rem;
  line-height: 1;
}

.sb-chip__lbl {
  line-height: 1.2;
}

.sb-plot-starters-label {
  margin: 0.55rem 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #be185d;
}

.sb-plot-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 0.65rem;
}

.sb-plot-starter {
  padding: 0.38rem 0.72rem;
  border-radius: 999px;
  border: 2px dashed rgba(219, 39, 119, 0.4);
  background: rgba(255, 255, 255, 0.92);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: #701a36;
  cursor: pointer;
  touch-action: manipulation;
  text-align: left;
  line-height: 1.3;
  transition: background 0.12s ease, border-color 0.12s ease;
  max-width: 100%;
}

.sb-plot-starter:active {
  background: #fce7f3;
  border-style: solid;
}

.sb-note {
  color: #b91c1c;
  font-weight: 700;
  font-size: 0.9rem;
  margin: 0 0 0.75rem;
}

.sb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 20px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  border: none;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s ease;
}

.sb-btn--primary {
  font-family: "Sniglet", "Nunito", sans-serif;
  font-size: 1.15rem;
  color: #fff;
  background: linear-gradient(180deg, #f472b6 0%, #db2777 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25), 0 4px 0 #9d174d, 0 8px 24px rgba(219, 39, 119, 0.25);
  border: 2px solid #be185d;
}

.sb-btn--primary:active {
  transform: translateY(4px);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25), 0 0 0 #9d174d;
}

.sb-btn--secondary {
  margin-top: 0.75rem;
  background: #fdf2f8;
  color: #9d174d;
  border: 3px solid rgba(219, 39, 119, 0.35);
  box-shadow: 0 4px 0 rgba(219, 39, 119, 0.2);
}

.sb-btn--secondary:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 rgba(219, 39, 119, 0.2);
}

.sb-btn--ghost {
  width: auto;
  flex: 1;
  max-width: 9rem;
  background: #fff;
  color: #db2777;
  border: 3px solid rgba(219, 39, 119, 0.3);
  box-shadow: 0 4px 0 rgba(219, 39, 119, 0.15);
}

.sb-btn--ghost:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 rgba(219, 39, 119, 0.15);
}

.sb-book {
  position: relative;
  border-radius: 22px;
  padding: 0.35rem 0.15rem 0.15rem;
  /* Per-book overrides set inline from `story.readerFont` (clever-service picks at creation). */
  --sb-reader-font-body: "Fredoka", "Sniglet", "Nunito", sans-serif;
  --sb-reader-font-over-art: "Schoolbell", "Nunito", sans-serif;
  --sb-reader-font-emphasis: "Kalam", "Sniglet", "Fredoka", cursive, sans-serif;
}

.sb-book--themed {
  background-color: #fce7f3;
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    0 4px 24px rgba(131, 24, 67, 0.12),
    inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.sb-book--themed::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: linear-gradient(
    180deg,
    rgba(253, 242, 248, 0.55) 0%,
    rgba(253, 242, 248, 0.08) 40%,
    rgba(252, 231, 243, 0.5) 100%
  );
  pointer-events: none;
  z-index: 0;
}

.sb-book--themed .sb-book-title,
.sb-book--themed .sb-book-close-tool,
.sb-book--themed .sb-book-spread,
.sb-book--themed .sb-book__actions {
  position: relative;
  z-index: 1;
}

.sb-book--themed .sb-book-title {
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.95),
    0 0 14px rgba(253, 242, 248, 1);
}

body.page-storybook .sb-book:not(.sb-reader--sample) .sb-book-title {
  color: #fffaf3;
  text-shadow:
    0 2px 14px rgba(0, 0, 0, 0.55),
    0 1px 4px rgba(0, 0, 0, 0.65);
}

.sb-book-title {
  font-family: var(--sb-reader-font-body);
  text-align: center;
  font-size: clamp(1.35rem, 4vw, 1.7rem);
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: #831843;
  text-shadow: 0 2px 0 rgba(251, 207, 232, 0.5);
}

.sb-book-close-tool {
  margin: 0 0 0.65rem;
  text-align: center;
}

.sb-close-book {
  font-size: 0.88rem;
  font-weight: 800;
}

.sb-book-spread {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 1rem;
  min-height: 0;
}

.sb-read-stage {
  position: relative;
  flex: 1;
  min-width: 0;
}

/* Bottom-right on the spread (over right-hand art) — keeps speaker + hint off verse text */
.sb-book-side-actions {
  position: absolute;
  right: max(0.35rem, env(safe-area-inset-right, 0px));
  bottom: max(0.55rem, env(safe-area-inset-bottom, 0px));
  z-index: 25;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 0.45rem;
  pointer-events: none;
}

/* Immersive reader: fixed 📚 FAB + kids bar sit on the screen — lift controls so they aren’t covered */
body.page-storybook.sb-reader-immersive .sb-book .sb-book-side-actions {
  bottom: calc(max(0.55rem, env(safe-area-inset-bottom, 0px)) + 4.75rem);
  z-index: 56;
}

/* Touch devices: extra clearance above global bottom chrome */
@media (hover: none) and (pointer: coarse) {
  .sb-book-side-actions {
    bottom: calc(max(0.55rem, env(safe-area-inset-bottom, 0px)) + 3.25rem);
    z-index: 56;
  }

  body.page-storybook.sb-reader-immersive .sb-book .sb-book-side-actions {
    bottom: calc(max(0.55rem, env(safe-area-inset-bottom, 0px)) + 5rem);
  }
}

.sb-book-side-actions > * {
  pointer-events: auto;
}

.sb-book-side-actions .sb-read-to-me {
  font-size: 1.1rem;
  padding: 0.75rem;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
}

.sb-book-side-actions .sb-tap-hint {
  background: rgba(255, 255, 255, 0.94);
  padding: 0.45rem 0.65rem;
  border-radius: 1rem;
  font-size: clamp(0.72rem, 2.4vw, 0.85rem);
  color: var(--sb-flip-dark);
  font-weight: 700;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  text-align: right;
  max-width: min(9.5rem, 38vw);
  line-height: 1.35;
}

.sb-book-side-actions .sb-tap-hint__ic {
  display: block;
  margin-bottom: 0.2rem;
  text-align: right;
}

.sb-reader-stack {
  position: relative;
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: clamp(300px, min(72dvh, 84vh), 680px);
  container-type: inline-size;
  container-name: sb-reader;
}

/* Book plate: perspective + preserve-3d so cover hinge reads as real rotation, not a flat fade. */
.sb-reader-book {
  position: relative;
  width: 100%;
  max-width: min(
    calc(100% - 1rem),
    calc(var(--sb-book-inner-h) * var(--sb-book-spread-w-factor) + 3.75rem)
  );
  margin-left: auto;
  margin-right: auto;
  border-radius: 14px;
  box-shadow: 0 18px 42px rgba(25, 25, 25, 0.18);
  perspective: min(1400px, 160vw);
  perspective-origin: center center;
  transform-style: preserve-3d;
  transform: translate3d(0, 0, 0);
  /* Match simple book-open demo: plate widens in step with the cover hinge */
  transition: max-width 0.8s ease;
}

/* Open: plate width matches two-page .sb-flip-spread__inner; bias perspective toward hinge (left). */
.sb-reader-stack--open .sb-reader-book {
  perspective-origin: 18% 50%;
  max-width: min(
    calc(100% - 1rem),
    calc(var(--sb-book-inner-h) * var(--sb-book-spread-w-factor) * 2),
    calc(100vw - 2rem)
  );
}

/* Cover hinge is transform-origin left on .sb-cover__pivot; anchor the element to the left edge of the plate. */
.sb-cover {
  position: absolute;
  z-index: 3;
  top: 0.45rem;
  left: 0;
  width: min(
    calc(var(--sb-book-inner-h) * var(--sb-book-spread-w-factor)),
    calc(100% - 1.25rem)
  );
  height: var(--sb-book-inner-h);
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transform: translate3d(0, 0, 0);
  transform-style: preserve-3d;
  /* Hinge at plate left (spine); closed-book spine centration is .sb-reader-book translateX, not this layer. */
}

.sb-cover__pivot {
  display: block;
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform 0.8s ease;
  will-change: transform;
}

.sb-cover__outside,
.sb-cover__inside {
  position: absolute;
  inset: 0;
  border-radius: 4px 14px 14px 4px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
}

.sb-cover__outside {
  transform: rotateY(0deg);
  box-shadow: 2px 2px 12px rgba(0, 0, 0, 0.12);
}

.sb-cover__inside {
  display: block;
  position: relative;
  background: linear-gradient(
    155deg,
    #fffdf8 0%,
    #f5f0e8 48%,
    #ebe4d8 100%
  );
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.06),
    -2px 2px 10px rgba(0, 0, 0, 0.06);
  transform: rotateY(180deg);
}

.sb-cover__inside::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background-image: var(--sb-cover-inside-art, none);
  background-size: cover;
  background-position: center center;
  opacity: 0.42;
  pointer-events: none;
  z-index: 0;
}

.sb-cover__face {
  display: flex;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  overflow: hidden;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.04);
}

.sb-cover__spine {
  width: 14px;
  flex-shrink: 0;
  background: linear-gradient(
    90deg,
    var(--sb-flip-darker) 0%,
    var(--sb-flip-mid) 45%,
    var(--sb-flip-red) 100%
  );
  box-shadow: inset -3px 0 8px rgba(0, 0, 0, 0.2);
}

.sb-cover__panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 1rem 0.85rem 1.15rem;
  background: linear-gradient(145deg, var(--sb-flip-light) 0%, var(--sb-flip-red) 45%, var(--sb-flip-dark) 100%);
  transition: filter 0.2s ease;
  position: relative;
  background-size: cover;
  background-position: center;
}

.sb-cover__panel--themed {
  /* Cover art is painted in ::after at --sb-cover-photo-opacity so book colour shows through */
  --sb-cover-photo-opacity: 0.33;
}

.sb-cover__panel--themed::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 0 10px 10px 0;
  background-image: var(--sb-cover-photo, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: var(--sb-cover-photo-opacity, 0.33);
  pointer-events: none;
  z-index: 0;
}

.sb-cover__panel--themed .sb-cover__title,
.sb-cover__panel--themed .sb-cover__hint,
.sb-cover__panel--themed .sb-cover__deco {
  position: relative;
  z-index: 2;
}

.sb-cover__panel::before {
  content: "";
  position: absolute;
  inset: 10px 12px 12px 12px;
  border-radius: 8px;
  border: 2px solid rgba(255, 230, 190, 0.45);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.12),
    0 0 0 1px rgba(0, 0, 0, 0.06);
  pointer-events: none;
  z-index: 1;
}

.sb-cover__deco {
  font-size: 1.75rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  position: relative;
  z-index: 1;
}

.sb-cover__title {
  font-family: var(--sb-reader-font-body);
  font-size: clamp(1rem, 4.2vw, 1.35rem);
  font-weight: 600;
  color: #fff8fa;
  text-align: center;
  line-height: 1.25;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
  max-width: 100%;
  overflow-wrap: anywhere;
  position: relative;
  z-index: 1;
  padding: 0 0.25rem;
}

.sb-cover__hint {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.88);
  position: relative;
  z-index: 1;
}

.sb-cover:hover .sb-cover__panel,
.sb-cover:focus-visible .sb-cover__panel {
  filter: brightness(1.05);
}

.sb-cover:focus-visible {
  outline: 3px solid #fbcfe8;
  outline-offset: 4px;
}

.sb-reader-pages {
  width: 100%;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition:
    opacity 0.8s ease,
    transform 0.8s ease;
}

/* Open book: plate fits two-page spread */
.sb-reader-stack--open .sb-reader-pages {
  position: relative;
  z-index: 4;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  margin-left: 0;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
}

/* Open: hinge cover aside (same idea as a simple CSS book: translate plate + rotateY on transform-origin left). */
.sb-reader-stack--open .sb-cover {
  z-index: 2;
  pointer-events: none;
  cursor: default;
}

.sb-reader-stack--open .sb-cover__pivot {
  transform: rotateY(-165deg);
  box-shadow: 2px 2px 14px rgba(0, 0, 0, 0.12);
}

@media (prefers-reduced-motion: reduce) {
  .sb-cover__pivot {
    transition: none;
  }

  .sb-reader-pages {
    transition: none;
  }

  .sb-reader-book,
  .sb-book.sb-book--immersive .sb-reader-book {
    transition: none;
  }

  .sb-flip-spread__inner {
    transition: none;
  }

  .sb-turn-leaf {
    transition-duration: 0.01ms;
  }

  .sb-flip-spread__art-peel.sb-story-pageflip {
    transition-duration: 0.01ms !important;
    -webkit-transition-duration: 0.01ms !important;
    transform: none !important;
    -webkit-transform: none !important;
  }

  .sb-flip-text__clip.sb-flip-text__clip--reveal-turn,
  .sb-flip-spread__art-base.sb-flip-spread__art-base--reveal-turn {
    animation: none !important;
    clip-path: none !important;
    -webkit-clip-path: none !important;
  }

  .sb-flip-spread__inner--peel-turning .sb-flip-left-shell .sb-flip-page--text .sb-flip-page__sheet > *,
  .sb-flip-spread__inner--peel-turning .sb-flip-right-shell .sb-flip-page--text .sb-flip-page__sheet > * {
    animation: none !important;
    opacity: 1 !important;
  }

  .sb-flip-spread {
    transform: none;
    box-shadow: 0 12px 28px rgba(20, 12, 28, 0.16);
  }
}

.sb-book--cover-visible .sb-read-arrow {
  visibility: hidden;
  pointer-events: none;
}

.sb-read-arrow {
  flex: 0 0 auto;
  align-self: center;
  width: 2.85rem !important;
  height: 2.85rem !important;
  min-width: 2.85rem !important;
  max-width: none !important;
  padding: 0 !important;
  border-radius: 50% !important;
  font-size: 1rem !important;
  line-height: 1 !important;
  box-shadow:
    0 2px 0 rgba(219, 39, 119, 0.12),
    0 8px 20px rgba(80, 20, 55, 0.12);
  background: #fff !important;
}

.sb-read-arrow:disabled {
  opacity: 0.35;
}

/* Open-book spread: shelf-like depth (subtle tilt) + red frame + gutter */
.sb-flip-spread {
  width: fit-content;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding: 0;
  background: var(--sb-flip-desk);
  border-radius: 6px;
  box-sizing: border-box;
  overflow: visible;
  transform: perspective(3200px) rotateX(3.25deg);
  transform-origin: center bottom;
  box-shadow:
    0 4px 0 rgba(255, 255, 255, 0.35),
    0 28px 56px rgba(25, 18, 32, 0.2),
    0 12px 24px rgba(25, 18, 32, 0.1);
}

/* Outer shelf tilt + inner peel both use 3D; combined they cause gutter seams, wrong half-bleed, and text “ghosting” on some GPUs. */
.sb-flip-spread.sb-flip-spread--peel-active {
  transform: none;
  box-shadow:
    0 4px 0 rgba(255, 255, 255, 0.35),
    0 18px 40px rgba(25, 18, 32, 0.18),
    0 8px 20px rgba(25, 18, 32, 0.1);
}

/* Touch / tablet: parent rotateX + inner 3D peel misaligns the gutter and art on WebKit (hairline seam, shifted duplex). */
@media (hover: none) and (pointer: coarse) {
  .sb-flip-spread {
    transform: none;
    box-shadow:
      0 4px 0 rgba(255, 255, 255, 0.35),
      0 18px 40px rgba(25, 18, 32, 0.18),
      0 8px 20px rgba(25, 18, 32, 0.1);
  }
}

.sb-flip-spread__inner {
  position: relative;
  display: flex;
  align-items: stretch;
  width: min(
    calc(var(--sb-book-inner-h) * var(--sb-book-spread-w-factor)),
    calc(100vw - 2rem)
  );
  max-width: min(100%, calc(100vw - 2rem));
  height: var(--sb-book-inner-h);
  margin: 0 auto;
  border: 0;
  border-radius: 6px;
  background: var(--sb-flip-paper);
  box-sizing: border-box;
  box-shadow: none;
  overflow: hidden;
  transition: width 0.8s ease;
  /* Required for gutter 3D page turns; `flat` flattens descendants and breaks rotateY peels on Safari/WebKit */
  transform-style: preserve-3d;
  perspective: min(720px, max(52vw, 380px));
  -webkit-perspective: min(720px, max(52vw, 380px));
  perspective-origin: center center;
  -webkit-perspective-origin: center center;
}

/* Mid-turn hinge rotation extends past spread bounds — parent overflow clipped the leaf halfway */
.sb-flip-spread__inner.sb-flip-spread__inner--peel-turning {
  overflow: visible;
}

/* Flex / reader plate can clip 3D leaf past the nominal spread bounds */
.sb-read-stage:has(.sb-flip-spread__inner--peel-turning),
.sb-book-spread:has(.sb-flip-spread__inner--peel-turning),
.sb-reader-pages:has(.sb-flip-spread__inner--peel-turning),
.sb-reader-book:has(.sb-flip-spread__inner--peel-turning),
.sb-reader-stack:has(.sb-flip-spread__inner--peel-turning) {
  overflow: visible;
}

/*
 * Fallback when :has() is missing or flaky: navigateSpread adds .sb-book-spread--peel-overflow on #sbBookSpread
 * during the hinge so rotated geometry is not clipped by flex ancestors (Safari/WebKit peel “vanished” mid-turn).
 */
.sb-book-spread.sb-book-spread--peel-overflow,
.sb-book-spread.sb-book-spread--peel-overflow .sb-read-stage,
.sb-book-spread.sb-book-spread--peel-overflow .sb-reader-stack,
.sb-book-spread.sb-book-spread--peel-overflow .sb-reader-book,
.sb-book-spread.sb-book-spread--peel-overflow .sb-reader-pages {
  overflow: visible !important;
}

/* Two-page spread: 2× the closed cover width, same height */
.sb-reader-stack--open .sb-flip-spread__inner {
  width: min(
    calc(var(--sb-book-inner-h) * var(--sb-book-spread-w-factor) * 2),
    calc(100vw - 2rem)
  );
  perspective: min(1200px, max(72vw, 420px));
  -webkit-perspective: min(1200px, max(72vw, 420px));
}

.sb-flip-spread__inner.sb-flip-spread__inner--fade-out {
  opacity: 0;
  transition: opacity 0.17s ease;
}

.sb-flip-spread__inner.sb-flip-spread__inner--fade-in {
  animation: sb-spread-fade-in 0.26s ease forwards;
}

@keyframes sb-spread-fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Binding edge: thin “spine” strip like a closed book block (inside the red frame) */
.sb-flip-spread__inner::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  z-index: 1;
  border-radius: 4px 0 0 4px;
  background: linear-gradient(
    90deg,
    rgba(88, 20, 60, 0.9) 0%,
    rgba(190, 24, 93, 0.5) 55%,
    transparent 100%
  );
  pointer-events: none;
}

.sb-flip-spread__inner--has-art {
  max-width: min(100%, calc(100vw - 2rem));
  /* Keep 1: opening from a narrow plate to a double spread no longer jumps perceived “zoom”; slight crop tradeoff vs matting. */
  --sb-spread-art-scale: 1;
  /* Soft paper tint so transparency never reveals two-tone “desk” bands under the shells */
  background: radial-gradient(
    ellipse 130% 88% at 50% 42%,
    rgba(255, 251, 245, 0.98) 0%,
    rgba(237, 230, 255, 0.97) 100%
  );
}

.sb-flip-spread__inner--has-art .sb-flip-right-shell.sb-flip-right-shell--flip {
  background: transparent;
}

/** Duplex stack: `#sbSpreadArtCover` shows the current spread; `#sbSpreadArtPeel` is only the outgoing sheet during animation. */
.sb-flip-spread__art-bg {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 6px;
  pointer-events: none;
  /* No background-image in normal use (see JS); no transform here — preserves 3D peel + avoids double scale with child imgs. */
}

.sb-flip-spread__art-base {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 6px;
  overflow: hidden;
  /* Isolate duplex paints during 3D peels — reduces one-frame flashes on WebKit tablets (iPad Safari). */
  isolation: isolate;
}

/* Readable soft serif used for dedication + facing prose (loaded in storybook.html). */
:root {
  --sb-story-soft-serif: "Lora", Georgia, "Times New Roman", serif;
}

/* Dedication / author credit: right-hand half-page — calm cream, no pastel splodges or per-line tape. */
.sb-flip-spread__art-flyleaf {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% + 3.5px);
  width: calc(50% - 3.5px);
  right: auto;
  z-index: 3;
  box-sizing: border-box;
  padding: clamp(1rem, 4vw, 2.25rem);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background-color: var(--sb-facing-cream, #faf6ec);
  background-image: none;
  pointer-events: auto;
  border-radius: 0 6px 6px 0;
  overflow: hidden;
  isolation: isolate;
}

/* Was an extra pastel/sparkle layer over the SVG corners — removed for plainer credits. */
.sb-flip-spread__art-flyleaf::before {
  content: none;
  display: none;
}

/* Author `display:flex` above beats the default `[hidden]{display:none}` — without this, the flyleaf
   stays an invisible white slab over the right half of #sbSpreadArtCover until the peel stacks above it. */
.sb-flip-spread__art-flyleaf[hidden] {
  display: none !important;
}

.sb-flip-spread__art-flyleaf .sb-flip-text {
  position: relative;
  z-index: 1;
}

.sb-flip-spread__art-flyleaf .sb-flip-flyleaf-paragraph {
  margin: 0;
  font-family: var(--sb-story-soft-serif);
  font-size: clamp(1.02rem, 2.85vw, 1.36rem);
  font-weight: 400;
  font-style: italic;
  line-height: 1.7;
  letter-spacing: 0.02em;
  color: rgba(42, 28, 35, 0.92);
  max-width: 30ch;
  text-shadow: none;
}

.sb-flip-spread__art-flyleaf .sb-flip-text__highlight {
  font-family: inherit;
  font-style: italic;
  font-weight: inherit;
  display: block;
  padding: 0;
  margin: 0 auto;
  width: 100%;
  max-width: 100%;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  box-decoration-break: initial;
  -webkit-box-decoration-break: initial;
  color: inherit;
}

.sb-flip-spread__art-flyleaf .sb-readable-word:hover {
  background: color-mix(in srgb, var(--sb-flip-light) 42%, rgba(91, 33, 182, 0.1));
  border-radius: 0.22em;
}

.sb-flip-spread__inner--flyleaf-pane .sb-flip-spread__art-cover {
  opacity: 0;
  visibility: hidden;
}

/* Definite paint when a duplex image is active (overrides flyleaf-pane if a class race happens). */
.sb-flip-spread__inner--has-art .sb-flip-spread__art-cover {
  opacity: 1;
  visibility: visible;
}

/* Base duplex: cover keeps the spread fully painted; center crop balances top/bottom so horns and heads are less often clipped */
.sb-flip-spread__art-cover {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  pointer-events: none;
  z-index: 1;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform: translateZ(0) scale(var(--sb-spread-art-scale, 1));
  transform-origin: center center;
}

/* --- One-page pictures: art fills the whole picture page (cover) --- */
.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-spread__art-base {
  left: calc(50% + 1.75px);
  right: 0;
  width: auto;
  background: #ede8df;
}

/* Facing uses one illustration per spread (not a panoramic duplex strip). Do not expand art under the text column during a peel. */

/* New facing-page art is prompted centred; crop with horizontal centre so the cast stays in frame. */
.sb-flip-spread__inner--art-facing .sb-flip-spread__art-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: center 45%;
}

.sb-page-num:empty {
  display: none;
}

.sb-page-num {
  position: absolute;
  bottom: 0.65rem;
  font-family: var(--sb-reader-font-body, "Fredoka", "Nunito", sans-serif);
  font-size: 0.88rem;
  font-weight: 700;
  color: rgba(42, 10, 31, 0.52);
  line-height: 1;
  z-index: 2;
  pointer-events: none;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-page-num {
  left: auto;
  right: max(0.65rem, env(safe-area-inset-right, 0px));
  bottom: max(0.55rem, env(safe-area-inset-bottom, 0px));
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--sb-flip-light) 82%, rgba(255, 255, 255, 0.95));
  border: 1px solid color-mix(in srgb, var(--sb-flip-red) 22%, transparent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    0 1px 4px rgba(45, 20, 35, 0.08);
  font-size: 0.8rem;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--sb-flip-darker, #2a1810) 52%, #1a1a1a);
  z-index: 3;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art
  .sb-flip-left-shell
  .sb-flip-page--text
  .sb-flip-page__sheet {
  background: var(--sb-facing-cream, #faf6ec);
  box-shadow: none;
  margin: 0;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  min-height: 0;
}

.sb-flip-facing-blobs {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: var(--sb-facing-blob-layer-opacity, 0.94);
  transform: scale(1.08);
  transform-origin: center center;
  -webkit-transform: scale(1.08);
  -webkit-transform-origin: center center;
  /* Strong at top and bottom edges, softer mid-page so cream shows between white washes */
  -webkit-mask-image: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 1) 0%,
    rgba(255, 255, 255, 0.92) 12%,
    rgba(255, 255, 255, 0.38) 50%,
    rgba(255, 255, 255, 0.92) 88%,
    rgba(255, 255, 255, 1) 100%
  );
  mask-image: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 1) 0%,
    rgba(255, 255, 255, 0.92) 12%,
    rgba(255, 255, 255, 0.38) 50%,
    rgba(255, 255, 255, 0.92) 88%,
    rgba(255, 255, 255, 1) 100%
  );
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-facing-blobs {
  display: block;
}

/* Paper tooth + gentle tint on top of cream (no full-bleed colour wash). */
.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art
  .sb-flip-left-shell
  .sb-flip-page--text
  .sb-flip-page__sheet::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      -13deg,
      transparent 0,
      transparent 15px,
      rgba(255, 255, 255, 0.08) 15px,
      rgba(255, 255, 255, 0.08) 16px
    ),
    linear-gradient(
      168deg,
      transparent 0%,
      rgba(255, 255, 255, 0.14) 52%,
      rgba(255, 255, 255, 0.22) 100%
    );
}

/* Small star + squiggle (muted blue-grey like sample books). */
.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art
  .sb-flip-left-shell
  .sb-flip-page--text
  .sb-flip-page__sheet::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='3' fill='%2399b4c9' opacity='0.8'/%3E%3Cpath stroke='%2399b4c9' stroke-width='1.8' stroke-linecap='round' opacity='0.65' d='M12 6v12M6 12h12'/%3E%3C/svg%3E")
      no-repeat 90% 4.5% / 19px 19px,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 52 38' fill='none'%3E%3Cpath stroke='%2399b4c9' stroke-width='2.2' stroke-linecap='round' opacity='0.78' d='M6 28c10-28 38 4 40-22'/%3E%3C/svg%3E")
      no-repeat calc(100% - 8px) 30% / 30px 20px,
    radial-gradient(circle at 22% 70%, rgba(255, 255, 255, 0.4) 0%, transparent 5%),
    radial-gradient(circle at 35% 18%, rgba(255, 255, 255, 0.35) 0%, transparent 4%);
  opacity: 0.92;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art
  .sb-flip-left-shell
  .sb-flip-page--text
  .sb-flip-text {
  position: relative;
  z-index: 3;
  box-sizing: border-box;
  width: 66%;
  max-width: 66%;
  margin: 0 auto;
  padding: clamp(1.8%, 1dvh, 4.5%) 0 clamp(2%, 1.1dvh, 6%);
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art
  .sb-flip-left-shell
  .sb-flip-text__highlight {
  display: block;
  font-family: var(--sb-story-soft-serif), "Lora", Georgia, serif !important;
  font-size: clamp(0.66rem, 1.58vw, 0.8rem);
  font-weight: 400;
  font-style: normal;
  letter-spacing: 0.015em;
  line-height: 1.5;
  color: rgba(42, 28, 35, 0.94);
  text-align: center;
  white-space: pre-line;
  padding: 0;
  margin: 0 auto;
  width: 100%;
  max-width: 100%;
  background: transparent;
  border-radius: 0;
  box-decoration-break: initial;
  -webkit-box-decoration-break: initial;
  box-shadow: none;
  text-shadow: none;
  -webkit-text-stroke: 0;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-left-shell .sb-flip-text__highlight::first-line {
  font-weight: 500;
  font-style: italic;
  font-size: 1.03em;
  letter-spacing: 0.025em;
  color: color-mix(in srgb, var(--sb-flip-dark, #9d174d) 28%, rgba(42, 28, 35, 0.92));
  text-shadow: none;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-left-shell .sb-big-word {
  font-family: var(--sb-story-soft-serif), "Lora", Georgia, serif;
  color: color-mix(in srgb, var(--sb-flip-mid, #9333ea) 72%, #5b21b6);
  font-weight: 600;
  font-style: italic;
  text-shadow: none;
}

/* Proper-name / keyword emphasis (paired with JS .sb-key-word) */
.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-left-shell .sb-key-word {
  font-family: "Patrick Hand", "Comic Neue", "Kalam", cursive !important;
  font-size: 1.08em;
  font-weight: 700 !important;
  font-style: normal !important;
  letter-spacing: 0.06em;
  color: color-mix(in srgb, var(--sb-flip-dark, #86143f) 55%, #4c0519);
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-left-shell .sb-flip-text::before {
  content: "✦";
  display: block;
  text-align: center;
  font-size: 0.52rem;
  letter-spacing: 0.42em;
  margin: 0 0 0.3rem;
  padding-right: 0.48em;
  color: color-mix(in srgb, var(--sb-flip-red, #db2777) 38%, #8b7369);
  opacity: 0.75;
  font-family: var(--sb-story-soft-serif);
  font-style: italic;
  font-weight: 400;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-left-shell .sb-readable-word:hover {
  background: color-mix(in srgb, var(--sb-flip-light) 42%, rgba(91, 33, 182, 0.12));
  border-radius: 0.22em;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-left-shell .sb-flip-text:has(.sb-the-end-wrap)::before {
  display: none;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-left-shell .sb-the-end-title {
  font-family: var(--sb-story-soft-serif), "Lora", Georgia, serif;
  font-weight: 600;
  font-style: italic;
  color: var(--sb-flip-mid, #be185d);
  text-shadow: none;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-left-shell .sb-the-end-lead {
  font-family: var(--sb-story-soft-serif), "Lora", Georgia, serif;
  font-weight: 400;
  font-style: italic;
  color: color-mix(in srgb, var(--sb-flip-dark, #9d174d) 45%, #2a0a1f);
  text-shadow: none;
}

/* Drop outgoing left-column copy early so it does not overlap incoming verso type mid-turn */
@keyframes sb-peel-fade-outgoing-text {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

/* Duplex only: fade outgoing type so it does not clash with verso copy. Facing prose page must not blink out mid-turn */
.sb-flip-spread__inner--peel-turning:not(.sb-flip-spread__inner--art-facing)
  .sb-flip-left-shell
  .sb-flip-page--text
  .sb-flip-page__sheet
  > *,
.sb-flip-spread__inner--peel-turning:not(.sb-flip-spread__inner--art-facing)
  .sb-flip-right-shell
  .sb-flip-page--text
  .sb-flip-page__sheet
  > * {
  animation: sb-peel-fade-outgoing-text 0.18s cubic-bezier(0.45, 0, 0.75, 1) forwards;
  pointer-events: none;
}

/* Reset peel text fade: forwards fill can stick across WebKit until animation is cleared. */
.sb-flip-spread__inner:not(.sb-flip-spread__inner--peel-turning)
  .sb-flip-left-shell
  .sb-flip-page--text
  .sb-flip-page__sheet
  > *,
.sb-flip-spread__inner:not(.sb-flip-spread__inner--peel-turning)
  .sb-flip-right-shell
  .sb-flip-page--text
  .sb-flip-page__sheet
  > * {
  opacity: 1;
  animation: none;
}

/* One leaf turns: right-hand page only, hinged at the gutter (normative book forward turn) */
.sb-flip-spread__art-peel {
  position: absolute;
  top: 0;
  bottom: 0;
  /* Slight overlap at the hinge hides subpixel gaps between turning leaf and base (Safari / tablet). */
  left: calc(50% - 0.5px);
  width: calc(50% + 0.5px);
  right: auto;
  z-index: 3;
  border-radius: 0 6px 6px 0;
  /* No overflow:hidden — it clips the 3D fold over the gutter. Clip the recto to the verso column instead: */
  overflow: visible;
  pointer-events: none;
  background-color: transparent;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transform-origin: left center;
  -webkit-transform-origin: left center;
  transform: rotateY(0deg);
  transition: transform 0.36s cubic-bezier(0.42, 0, 0.58, 1);
  -webkit-transition: -webkit-transform 0.36s cubic-bezier(0.42, 0, 0.58, 1);
}

/*
 * Peel stacks above gutters/shells while turning (`z-index: 22`; default peel is lower).
 * Rotation is already a full ±180deg (`sb-story-pageflip--turn-next-1` / `turn-prev-1`): near 90deg
 * both textured faces sit edge-on with `backface-visibility:hidden`, so this paints a paper-ish matte,
 * plus `will-change` for compositing. JS pins duplex `#sbSpreadArtCover` on the outgoing frame until idle.
 */
.sb-flip-spread__inner.sb-flip-spread__inner--peel-turning .sb-flip-spread__art-peel {
  z-index: 22;
  will-change: transform;
  /* Page edge / matte when the folded leaf has near-zero projected width mid-way */
  background: linear-gradient(
    92deg,
    rgba(237, 232, 223, 0.98) 0%,
    rgba(255, 252, 248, 1) 50%,
    rgba(237, 232, 223, 0.96) 100%
  );
  background-color: #ede8df;
}

/* Keep overflow visible — clipping here hid the turning leaf halfway through hinge rotation */
.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--peel-turning .sb-flip-spread__art-peel {
  overflow: visible;
}

.sb-flip-spread__peel-front,
.sb-flip-spread__peel-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  border-radius: 0 6px 6px 0;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

.sb-flip-spread__peel-front {
  transform: rotateY(0deg) translateZ(2px);
  -webkit-transform: rotateY(0deg) translateZ(2px);
}

.sb-flip-spread__peel-front-text {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: max(0.45rem, env(safe-area-inset-top, 0px))
    max(0.65rem, env(safe-area-inset-right, 0px)) max(0.45rem, env(safe-area-inset-bottom, 0px))
    max(0.65rem, env(safe-area-inset-left, 0px));
  pointer-events: none;
  overflow: hidden;
}

.sb-flip-spread__peel-front-text .sb-flip-text {
  margin: 0;
  width: 100%;
  max-width: min(32rem, 92%);
  text-align: center;
}

.sb-flip-spread__peel-front.sb-flip-spread__peel-front--recto-prose {
  background: #f7f4eb;
}

.sb-flip-spread__peel-front.sb-flip-spread__peel-front--recto-prose .sb-flip-spread__peel-front-text .sb-flip-text__highlight {
  display: inline;
  font-family: var(--sb-reader-font-body);
  font-size: clamp(0.9rem, 2.65vw, 1.1rem);
  font-weight: 550;
  line-height: 1.72;
  color: #25141c;
  text-align: center;
  white-space: pre-line;
  padding: 0;
  margin: 0;
  background: transparent;
  box-shadow: none;
  text-shadow: none;
}

.sb-flip-spread__peel-front.sb-flip-spread__peel-front--recto-prose .sb-big-word {
  color: #5b21b6;
}

.sb-flip-spread__peel-back {
  transform: rotateY(180deg) translateZ(2px);
  -webkit-transform: rotateY(180deg) translateZ(2px);
}

/* Recto (front of leaf): right half of OUTGOING duplex. Verso (back): left half of INCOMING duplex — not the same crop. */
.sb-flip-spread__peel-front .sb-flip-spread__art-cover {
  width: 200%;
  height: 100%;
  max-width: none;
  left: -100%;
  top: 0;
  position: absolute;
}

.sb-flip-spread__peel-back .sb-flip-spread__art-cover {
  width: 200%;
  height: 100%;
  max-width: none;
  left: 0;
  top: 0;
  position: absolute;
  z-index: 0;
}

/* Facing: single-page art fills the leaf (not panoramic half of one wide texture). */
.sb-flip-spread__inner--art-facing .sb-flip-spread__peel-front .sb-flip-spread__art-cover {
  width: 100%;
  max-width: none;
  left: 0;
  object-fit: cover;
  object-position: center 45%;
  transform: translateZ(0) scale(var(--sb-spread-art-scale, 1));
  -webkit-transform: translateZ(0) scale(var(--sb-spread-art-scale, 1));
  transform-origin: center center;
}

.sb-flip-spread__inner--art-facing .sb-flip-spread__peel-back .sb-flip-spread__art-cover {
  width: 100%;
  max-width: none;
  left: 0;
  object-fit: cover;
  object-position: center 45%;
  transform: rotateY(180deg) translateZ(0) scale(var(--sb-spread-art-scale, 1));
  -webkit-transform: rotateY(180deg) translateZ(0) scale(var(--sb-spread-art-scale, 1));
  transform-origin: center center;
}

/* Facing: back face mirrors glyphs in X; flip horizontally so verso reads normally. */
.sb-flip-spread__peel-back-text {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: max(0.45rem, env(safe-area-inset-top, 0px))
    max(0.65rem, env(safe-area-inset-right, 0px)) max(0.45rem, env(safe-area-inset-bottom, 0px))
    max(0.65rem, env(safe-area-inset-left, 0px));
  pointer-events: none;
  overflow: hidden;
}

.sb-flip-spread__inner--art-facing .sb-flip-spread__peel-back-text {
  transform: scaleX(-1) translateZ(3px);
  -webkit-transform: scaleX(-1) translateZ(3px);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}

.sb-flip-spread__peel-back-text .sb-flip-text {
  margin: 0;
  width: 100%;
  max-width: min(32rem, 92%);
  text-align: center;
}

.sb-flip-spread__inner--has-art .sb-flip-spread__peel-back-text .sb-flip-text {
  max-width: min(32rem, 92%);
}

/* Facing uses cream-page type on the sheet; during duplex-style peel, verso matches over-art duplex type */
.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--peel-turning .sb-flip-spread__peel-back-text .sb-flip-text__highlight {
  display: inline;
  font-family: var(--sb-reader-font-over-art);
  font-size: clamp(1.35rem, 4.2vw, 1.75rem);
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.55;
  color: #fff;
  text-align: center;
  padding: 0;
  background: none;
  border-radius: 0;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  box-shadow: none;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.92),
    0 2px 10px rgba(0, 0, 0, 0.65),
    0 0 2px rgba(0, 0, 0, 0.9);
  -webkit-text-stroke: 0;
  -webkit-font-smoothing: antialiased;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--peel-turning .sb-flip-spread__peel-back-text .sb-big-word {
  color: #fff;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.92),
    0 2px 10px rgba(0, 0, 0, 0.65),
    0 0 2px rgba(0, 0, 0, 0.9);
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--peel-turning .sb-flip-spread__peel-back-text .sb-the-end-title,
.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--peel-turning .sb-flip-spread__peel-back-text .sb-the-end-lead {
  color: #fff;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.92),
    0 2px 10px rgba(0, 0, 0, 0.65),
    0 0 2px rgba(0, 0, 0, 0.9);
}

/* Facing verso is prose on cream paper (incoming text column), not art + white type. */
.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--peel-turning
  .sb-flip-spread__peel-back.sb-flip-spread__peel-back--verso-text {
  background-color: var(--sb-facing-cream, #faf6ec);
  background-image:
    radial-gradient(
      ellipse 118% 118% at -12% -8%,
      color-mix(in srgb, var(--sb-facing-corner-strong) 72%, transparent) 0%,
      transparent 58%
    ),
    radial-gradient(
      ellipse 120% 120% at 110% -4%,
      color-mix(in srgb, var(--sb-facing-corner-strong) 70%, transparent) 0%,
      transparent 58%
    ),
    radial-gradient(
      ellipse 110% 110% at -6% 108%,
      color-mix(in srgb, var(--sb-facing-corner-mid) 68%, transparent) 0%,
      transparent 58%
    ),
    radial-gradient(
      ellipse 110% 110% at 106% 108%,
      color-mix(in srgb, var(--sb-facing-corner-mid) 66%, transparent) 0%,
      transparent 58%
    ),
    linear-gradient(
      168deg,
      transparent 0%,
      rgba(255, 255, 255, 0.18) 55%,
      rgba(255, 255, 255, 0.26) 100%
    );
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--peel-turning
  .sb-flip-spread__peel-back.sb-flip-spread__peel-back--verso-text
  .sb-flip-spread__peel-back-text
  .sb-flip-text__highlight {
  display: block;
  font-family: var(--sb-story-soft-serif);
  font-size: clamp(0.78rem, 1.95vw, 0.92rem);
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1.74;
  font-style: normal;
  color: rgba(42, 28, 35, 0.9);
  text-shadow: none;
  -webkit-font-smoothing: antialiased;
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--peel-turning
  .sb-flip-spread__peel-back.sb-flip-spread__peel-back--verso-text
  .sb-flip-spread__peel-back-text
  .sb-big-word {
  font-family: var(--sb-story-soft-serif);
  font-style: italic;
  font-weight: 600;
  color: color-mix(in srgb, var(--sb-flip-mid, #9333ea) 75%, #5b21b6);
  text-shadow: none;
}

.sb-flip-spread__art-outgoing-left {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: auto;
  width: calc(50% + 0.5px);
  z-index: 2;
  overflow: hidden;
  border-radius: 6px 0 0 6px;
}

.sb-flip-spread__art-outgoing-left .sb-flip-spread__art-cover {
  width: 200%;
  height: 100%;
  max-width: none;
  left: 0;
  top: 0;
  position: absolute;
}

/* Facing: duplex left-half crop is empty/wrong — paint full illustration in-strip so the leaf crosses the gutter solidly */
.sb-flip-spread__inner--art-facing .sb-flip-spread__art-outgoing-left .sb-flip-spread__art-cover {
  width: 100%;
  height: 100%;
  max-width: none;
  left: 0;
  top: 0;
  position: absolute;
  object-fit: cover;
  object-position: center 45%;
}

.sb-flip-spread__art-peel.sb-story-pageflip--turn-next-1 .sb-flip-spread__art-peel__img,
.sb-flip-spread__art-peel.sb-story-pageflip--turn-next-1 .sb-flip-spread__art-cover {
  box-shadow:
    inset 0 0 0 1px rgba(157, 23, 77, 0.06),
    4px 0 28px rgba(45, 20, 40, 0.12);
}

.sb-flip-spread__art-peel.sb-story-pageflip--turn-prev-1 .sb-flip-spread__art-peel__img,
.sb-flip-spread__art-peel.sb-story-pageflip--turn-prev-1 .sb-flip-spread__art-cover {
  box-shadow:
    inset 0 0 0 1px rgba(157, 23, 77, 0.06),
    -4px 0 28px rgba(45, 20, 40, 0.12);
}

/* Left page copy: story text uncovers gutter → spine together with duplex art underneath */
@keyframes sb-turn-reveal-leftcol {
  from {
    clip-path: inset(0 0 0 50%);
    -webkit-clip-path: inset(0 0 0 50%);
  }

  to {
    clip-path: inset(0 0 0 0);
    -webkit-clip-path: inset(0 0 0 0);
  }
}

.sb-flip-text__clip {
  display: block;
  width: 100%;
  clip-path: none;
  -webkit-clip-path: none;
}

.sb-flip-text__clip.sb-flip-text__clip--reveal-turn {
  animation: sb-turn-reveal-leftcol 0.36s cubic-bezier(0.42, 0, 0.58, 1) both;
}

.sb-flip-spread__art-peel.sb-story-pageflip--turn-next-1 {
  transform: rotateY(-180deg);
  -webkit-transform: rotateY(-180deg);
}

.sb-flip-spread__art-peel.sb-story-pageflip--turn-prev-1 {
  transform: rotateY(180deg);
  -webkit-transform: rotateY(180deg);
}

/* Text over full-bleed art: plain type + soft shadow for legibility (no per-line tape) */
.sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-flip-page--text .sb-flip-page__sheet {
  background: transparent;
  box-shadow: none;
  margin: 0;
  padding: max(0.45rem, env(safe-area-inset-top, 0px))
    max(0.65rem, env(safe-area-inset-right, 0px)) max(0.45rem, env(safe-area-inset-bottom, 0px))
    max(0.65rem, env(safe-area-inset-left, 0px));
  align-self: stretch;
  width: 100%;
  max-width: none;
  justify-content: center;
  align-items: center;
  min-height: 0;
  /* Avoid pairing clip-path reveal with overflow:auto — WebKit clips the left edge of lines mid-turn. */
  overflow: visible;
}

.sb-flip-spread__inner--has-art .sb-flip-page--art .sb-flip-art {
  background: transparent;
  box-shadow: none;
}

.sb-flip-spread__inner--has-art .sb-flip-page--art .sb-flip-art::before {
  display: none;
}

.sb-flip-spread__inner--has-art .sb-flip-page--art .sb-flip-art__num {
  display: none;
}

.sb-flip-book-legacy-art {
  display: none !important;
}

/* Keep <img> for page-turn animation & preload; not shown when full-bleed background is active */
.sb-flip-spread__inner--has-art .sb-flip-page--art .sb-flip-art img {
  opacity: 0;
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 4px;
  max-width: 4px;
  max-height: 4px;
  margin: 0;
  pointer-events: none;
}

/* One half of the spread: static page + optional turn overlay stacked above */
.sb-flip-left-shell,
.sb-flip-right-shell {
  position: relative;
  z-index: 4;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-self: stretch;
  transform-style: preserve-3d;
}

/* Empty right column must not paint paper over the full-bleed duplex (#sbSpreadArtCover). */
.sb-flip-right-shell.sb-flip-right-shell--flip {
  background: transparent;
}

.sb-flip-left-shell > .sb-flip-page,
.sb-flip-right-shell > .sb-flip-page {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

/* Page-turn: single “leaf” hinged at the gutter (not the whole spread) */
.sb-page-turn-overlay {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
}

.sb-page-turn-overlay.is-visible {
  z-index: 20;
  visibility: visible;
  opacity: 1;
}

/* Match classic “CSS 3D book” feel (e.g. subhamgiri16/3D-Flipbook): huge perspective + left-hinge -180deg */
.sb-page-turn-overlay--right {
  -webkit-perspective: min(250rem, 4200px);
  perspective: min(250rem, 4200px);
  -webkit-perspective-origin: left center;
  perspective-origin: left center;
}

.sb-page-turn-overlay--left {
  -webkit-perspective: min(250rem, 4200px);
  perspective: min(250rem, 4200px);
  -webkit-perspective-origin: right center;
  perspective-origin: right center;
}

.sb-turn-leaf {
  width: 100%;
  height: 100%;
  position: relative;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transform-origin: left;
  -webkit-transform: rotateY(0deg);
  transform: rotateY(0deg);
  -webkit-transition: -webkit-transform 1.12s cubic-bezier(0.25, 0.82, 0.32, 1);
  transition: transform 1.12s cubic-bezier(0.25, 0.82, 0.32, 1);
  box-shadow:
    inset 0 0 0 1px rgba(157, 23, 77, 0.08),
    3px 0 18px rgba(65, 20, 50, 0.12),
    1px 0 6px rgba(0, 0, 0, 0.06);
  border-radius: 0 3px 3px 0;
}

.sb-page-turn-overlay--left .sb-turn-leaf {
  border-radius: 3px 0 0 3px;
  box-shadow:
    inset 0 0 0 1px rgba(157, 23, 77, 0.08),
    -3px 0 18px rgba(65, 20, 50, 0.12),
    -1px 0 6px rgba(0, 0, 0, 0.06);
}

.sb-turn-leaf--next {
  -webkit-transform: rotateY(-180deg);
  transform: rotateY(-180deg);
}

.sb-turn-leaf--prev {
  transform-origin: right;
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
}

.sb-turn-leaf__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--sb-flip-paper);
  overflow: hidden;
  -webkit-transform: rotateY(0deg) translateZ(1px);
  transform: rotateY(0deg) translateZ(1px);
}

.sb-turn-leaf__face--back {
  -webkit-transform: rotateY(180deg) translateZ(1px);
  transform: rotateY(180deg) translateZ(1px);
  background: linear-gradient(105deg, #ebe6df 0%, #faf8f4 45%, #f3eee8 100%);
  box-shadow: inset 4px 0 14px rgba(0, 0, 0, 0.07);
}

.sb-turn-leaf__face--text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: clamp(10px, 2.5vw, 20px);
  box-sizing: border-box;
  writing-mode: horizontal-tb;
  direction: ltr;
  -webkit-transform: rotateY(0deg) translateZ(2px);
  transform: rotateY(0deg) translateZ(2px);
}

.sb-turn-leaf__face--front > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}

/* Turning leaf when the previous spread had no illustration URL (still get a convincing page turn). */
.sb-turn-leaf__face--placeholder {
  background: linear-gradient(
    133deg,
    #faf6f1 0%,
    #f0eae2 42%,
    #e8e2da 72%,
    #ddd7cf 100%
  );
}

.sb-page-turn-overlay--left .sb-turn-leaf__face--placeholder.sb-turn-leaf__face--text {
  justify-content: center;
}

.sb-flip-page {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: stretch;
}

.sb-flip-page__sheet {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: clamp(10px, 2.5vw, 22px) clamp(14px, 4vw, 28px);
  box-sizing: border-box;
  overflow: auto;
}

.sb-flip-text {
  margin: 0;
  width: 100%;
  max-width: 26rem;
  text-align: center;
  line-height: 1.65;
}

/* Child-friendly type + per-line white “tape” so story reads over busy art */
.sb-flip-text__highlight {
  display: inline;
  font-family: var(--sb-reader-font-body);
  font-size: clamp(0.92rem, 2.6vw, 1.12rem);
  font-weight: 500;
  line-height: 1.65;
  color: #2a0a1f;
  text-align: center;
  padding: 0.12em 0.42em;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 0.38em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  box-shadow: 0 1px 3px rgba(42, 10, 31, 0.08);
}

/* Picture-book text over art: duplex / full-bleed only — excluded when using facing “paper page” prose */
.sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-flip-text__highlight {
  display: inline;
  font-family: var(--sb-reader-font-over-art);
  font-size: clamp(1.35rem, 4.2vw, 1.75rem);
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.55;
  color: #fff;
  text-align: center;
  padding: 0;
  background: none;
  border-radius: 0;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  box-shadow: none;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.92),
    0 2px 10px rgba(0, 0, 0, 0.65),
    0 0 2px rgba(0, 0, 0, 0.9);
  -webkit-text-stroke: 0;
  -webkit-font-smoothing: antialiased;
}

.sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-flip-text {
  position: relative;
  z-index: 0;
  max-width: min(32rem, 92%);
  text-align: center;
  padding: clamp(0.35rem, 1.5vw, 0.65rem) clamp(0.5rem, 3vw, 1.25rem);
  border-radius: 0;
}

.sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-readable-word {
  cursor: pointer;
  border-radius: 0.18em;
  transition: background 0.15s ease;
}

.sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-readable-word:hover {
  background: rgba(0, 0, 0, 0.22);
}

.sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-left-shell .sb-readable-word {
  cursor: pointer;
}

.sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-big-word {
  font-family: var(--sb-reader-font-emphasis);
  font-size: 1.65em;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.15;
  color: #fff;
  transform: rotate(-3deg) skewX(-4deg);
  display: inline-block;
  margin: 0.1em 0.05em 0 0.02em;
  -webkit-text-stroke: 0;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.92),
    0 2px 10px rgba(0, 0, 0, 0.65),
    0 0 2px rgba(0, 0, 0, 0.9);
}

.sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-word-reading {
  outline: 2px solid rgba(255, 255, 255, 0.95);
  outline-offset: 2px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 0.24em;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5),
    0 1px 4px rgba(0, 0, 0, 0.45);
}

.sb-the-end-wrap {
  text-align: center;
  margin-top: 1.25rem;
  padding: 0.35rem 0.75rem;
}

.sb-the-end-title {
  font-family: var(--sb-reader-font-emphasis);
  font-size: clamp(1.75rem, 5.5vw, 2.35rem);
  font-weight: 800;
  margin: 0 0 0.35rem;
  color: #9d174d;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.sb-the-end-lead {
  font-family: var(--sb-reader-font-emphasis);
  font-size: clamp(0.98rem, 3vw, 1.15rem);
  font-weight: 700;
  margin: 0;
  color: #500724;
}

.sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-the-end-title {
  color: #fff;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.92),
    0 2px 10px rgba(0, 0, 0, 0.65),
    0 0 2px rgba(0, 0, 0, 0.9);
}

.sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-the-end-lead {
  color: #fff;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.92),
    0 2px 10px rgba(0, 0, 0, 0.65),
    0 0 2px rgba(0, 0, 0, 0.9);
}

.sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-the-end-wrap {
  padding: 0.5rem 0.75rem;
  border-radius: 0;
  background: none;
  box-shadow: none;
}

/* Tablet band: duplex over-art type shrinks; facing text page stays readable (no sticker boxes). */
@media (min-width: 600px) and (max-width: 1200px) {
  .sb-flip-spread__inner--art-facing.sb-flip-spread__inner--has-art .sb-flip-left-shell .sb-flip-text__highlight {
    font-size: clamp(0.6rem, 1.42vw, 0.73rem);
    line-height: 1.48;
  }

  .sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-flip-text__highlight {
    font-size: clamp(1.05rem, 3.35vw, 1.48rem);
    line-height: 1.5;
  }

  .sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-big-word {
    font-size: 1.48em;
  }

  .sb-flip-text__highlight {
    font-size: clamp(0.82rem, 2.35vw, 1.02rem);
  }

  .sb-flip-spread__art-flyleaf .sb-flip-flyleaf-paragraph {
    font-size: clamp(0.9rem, 2.35vw, 1.15rem);
  }

  .sb-book-title {
    font-size: clamp(1.12rem, 3.25vw, 1.48rem);
  }

  .sb-the-end-title {
    font-size: clamp(1.45rem, 4.5vw, 2rem);
  }

  .sb-the-end-lead {
    font-size: clamp(0.88rem, 2.65vw, 1.05rem);
  }

  .sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-the-end-title {
    font-size: clamp(1.45rem, 4.5vw, 2rem);
  }

  .sb-flip-spread__inner--has-art:not(.sb-flip-spread__inner--art-facing) .sb-the-end-lead {
    font-size: clamp(0.88rem, 2.65vw, 1.05rem);
  }

  .sb-book.sb-book--immersive .sb-book-title {
    font-size: clamp(0.92rem, 2.5vw, 1.28rem);
  }
}

.sb-flip-page--art .sb-flip-page__sheet {
  padding: 0;
  justify-content: stretch;
  align-items: stretch;
  overflow: hidden;
  min-height: 0;
}

.sb-flip-page--art .sb-flip-art {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  height: 100%;
  max-width: none;
  max-height: none;
  aspect-ratio: auto;
  margin: 0;
  align-self: stretch;
  border-radius: 0;
  box-shadow: none;
}

.sb-flip-page--art .sb-flip-art:not(.is-empty)::before {
  display: none;
}

.sb-flip-page--art .sb-flip-art.is-empty {
  margin: clamp(8px, 2vw, 14px);
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px rgba(230, 27, 65, 0.22);
  flex: 1 1 auto;
  min-height: 8rem;
}

.sb-flip-page--art .sb-flip-art.is-empty::before {
  display: block;
}

.sb-flip-page--art .sb-flip-art:not(.is-empty) .sb-flip-art__num {
  left: auto;
  top: auto;
  right: 0.5rem;
  bottom: 0.45rem;
  transform: none;
  margin: 0;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 999px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.sb-flip-page--art .sb-flip-art img {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  border-radius: 0;
}

.sb-flip-gutter {
  position: relative;
  z-index: 5;
  width: 7px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #7a7a7a 0%, #dadada 38%, #f2f2f2 50%, #c8c8c8 100%);
  box-shadow:
    inset 3px 0 10px rgba(0, 0, 0, 0.14),
    inset -3px 0 10px rgba(0, 0, 0, 0.1),
    0 0 14px rgba(0, 0, 0, 0.08);
  align-self: stretch;
}

.sb-flip-art {
  position: relative;
  width: 100%;
  max-width: min(100%, 400px);
  aspect-ratio: 3 / 4;
  max-height: min(100%, 440px);
  margin: 0 auto;
  border-radius: 6px;
  overflow: hidden;
  background: linear-gradient(165deg, #faf7f2 0%, #fff 50%, #fef9f5 100%);
}

.sb-flip-art::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  border-radius: inherit;
  background: url("../images/flip-book/page-front-edge.png") center / 100% 100% no-repeat;
  opacity: 0.72;
}

.sb-flip-art.is-empty {
  background: linear-gradient(145deg, #fff5f7, #fff);
}

.sb-flip-art.is-empty::before {
  opacity: 0.4;
}

.sb-flip-art.is-empty .sb-flip-art__num {
  opacity: 0.5;
}

.sb-flip-art__num {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  margin: 0;
  padding: 0.15rem 0.55rem;
  font-size: 0.74rem;
  font-weight: 800;
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--sb-flip-red);
  text-shadow:
    0 0 10px #fff,
    0 0 8px #fff,
    0 1px 2px rgba(255, 255, 255, 0.85);
  pointer-events: none;
}

.sb-flip-art img {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  z-index: 1;
  border-radius: 4px;
}

.sb-book__actions {
  position: relative;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.85rem;
}

.sb-book__actions-dock {
  display: contents;
}

.sb-book__actions-fab {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sb-book__actions .sb-btn--primary {
  font-size: 1rem;
}

.sb-busy {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(131, 24, 67, 0.35);
  backdrop-filter: blur(3px);
}

.sb-busy__card {
  max-width: 24rem;
  padding: 2.25rem 1.65rem;
  background: radial-gradient(ellipse at center top, #ffffff 0%, #fffdf8 100%);
  border-radius: 32px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(131, 24, 67, 0.25), inset 0 0 0 4px #fbcfe8;
  position: relative;
}

.sb-busy__card::before {
  content: "📖";
  display: block;
  font-size: 3.25rem;
  margin-bottom: 0.85rem;
  animation: sb-float 2.5s ease-in-out infinite;
}

@keyframes sb-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.sb-busy__title {
  margin: 0 0 0.5rem;
  font-family: "Sniglet", "Nunito", sans-serif;
  font-size: 1.55rem;
  color: #9d174d;
}

.sb-busy__msg {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: #9f1239;
  line-height: 1.45;
}

.sb-busy__progress-track {
  margin-top: 1.15rem;
  height: 12px;
  border-radius: 999px;
  background: rgba(253, 186, 216, 0.72);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(157, 23, 77, 0.14);
}

.sb-busy__progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f9a8d4, #f472b6 42%, #db2777);
  transition: width 0.5s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .sb-busy__progress-fill {
    transition: none;
  }
}

.sb-busy__step {
  margin: 0.65rem 0 0;
  font-size: 0.88rem;
  font-weight: 800;
  color: #be185d;
  min-height: 1.3em;
}

.sb-busy__dots {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 1rem;
}

.sb-busy__dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f472b6;
  animation: sb-dot 0.9s ease-in-out infinite alternate;
}

.sb-busy__dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.sb-busy__dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes sb-dot {
  from {
    opacity: 0.35;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.is-hidden {
  display: none !important;
}

@media (min-width: 600px) {
  .sb-app {
    max-width: 32rem;
  }
}

/* ——— Tablet / wide: immersive reader (edge-to-edge + floating controls) ——— */
@media (min-width: 768px) {
  body.page-storybook.sb-reader-immersive {
    overflow: hidden;
    height: 100%;
    min-height: 100dvh;
  }

  body.page-storybook.sb-reader-immersive .sb-app {
    max-width: none;
    margin: 0;
    padding: 0;
    min-height: 100dvh;
    min-height: 100vh;
  }

  body.page-storybook.sb-reader-immersive .sb-nav {
    position: fixed;
    top: max(0.5rem, env(safe-area-inset-top, 8px));
    left: max(0.65rem, env(safe-area-inset-left, 12px));
    z-index: 60;
    margin: 0;
  }

  body.page-storybook.sb-reader-immersive .sb-nav .sb-back {
    background: rgba(255, 255, 255, 0.94);
    border-radius: 999px;
    padding: 0.45rem 0.85rem;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(219, 39, 119, 0.28);
  }

  .sb-book.sb-book--immersive {
    /* Bias height (dvh) for a portrait spread; width comes from aspect-ratio on the spread */
    --sb-book-inner-h: clamp(300px, min(78dvh, 86vh), 660px);
    position: fixed;
    inset: 0;
    z-index: 40;
    margin: 0;
    border-radius: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    min-height: 100vh;
    background: linear-gradient(
      165deg,
      #2a1420 0%,
      #3d1f2d 42%,
      #1a1016 100%
    );
  }

  .sb-book.sb-book--immersive.sb-book--themed {
    border: none;
    box-shadow: none;
  }

  .sb-book.sb-book--immersive.sb-book--themed::before {
    border-radius: 0;
    background: linear-gradient(
      180deg,
      rgba(25, 12, 20, 0.5) 0%,
      rgba(25, 12, 20, 0.18) 45%,
      rgba(12, 6, 10, 0.55) 100%
    );
  }

  .sb-book.sb-book--immersive .sb-book-title {
    position: fixed;
    top: max(0.65rem, env(safe-area-inset-top, 10px));
    left: 50%;
    transform: translateX(-50%);
    width: min(92vw, 30rem);
    margin: 0;
    padding: 0 5.5rem;
    z-index: 52;
    font-size: clamp(1rem, 2.8vw, 1.45rem);
    color: #fff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
    pointer-events: none;
    line-height: 1.2;
    box-sizing: border-box;
  }

  .sb-book.sb-book--immersive.sb-book--themed .sb-book-title {
    color: #fff;
    text-shadow:
      0 1px 3px rgba(0, 0, 0, 0.5),
      0 0 20px rgba(0, 0, 0, 0.25);
  }

  .sb-book.sb-book--immersive .sb-book-close-tool {
    position: fixed;
    top: max(0.5rem, env(safe-area-inset-top, 8px));
    right: max(0.65rem, env(safe-area-inset-right, 12px));
    left: auto;
    margin: 0;
    z-index: 55;
    text-align: right;
  }

  .sb-book.sb-book--immersive .sb-book-close-tool .sb-close-book {
    background: rgba(255, 255, 255, 0.94);
    border-radius: 999px;
    padding: 0.5rem 1.1rem;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.2);
    font-weight: 800;
    width: auto;
    max-width: none;
  }

  .sb-book.sb-book--immersive .sb-book-spread {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    align-items: stretch;
    padding-top: clamp(2.25rem, 5.5dvh, 3.25rem);
    padding-bottom: 6.5rem;
    gap: 0;
    position: relative;
    z-index: 1;
  }

  .sb-book.sb-book--immersive .sb-read-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-left: max(1.25rem, env(safe-area-inset-left, 12px));
    padding-right: max(1.25rem, env(safe-area-inset-right, 12px));
  }

  .sb-book.sb-book--immersive .sb-read-arrow {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 50;
    margin: 0;
    width: 3.35rem !important;
    height: 3.35rem !important;
    min-width: 3.35rem !important;
    max-width: none !important;
    background: rgba(255, 255, 255, 0.95) !important;
    box-shadow: 0 4px 22px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(219, 39, 119, 0.2);
  }

  .sb-book.sb-book--immersive #sbPrev {
    left: max(0.45rem, env(safe-area-inset-left, 8px));
  }

  .sb-book.sb-book--immersive #sbNext {
    right: max(0.45rem, env(safe-area-inset-right, 8px));
  }

  .sb-book.sb-book--immersive.sb-book--cover-visible .sb-read-arrow {
    visibility: hidden;
    pointer-events: none;
  }

  .sb-book.sb-book--immersive .sb-reader-stack {
    min-height: min(80dvh, 780px);
    width: 100%;
  }

  .sb-book.sb-book--immersive .sb-reader-book {
    max-width: min(
      calc(100% - 1rem),
      calc(var(--sb-book-inner-h) * var(--sb-book-spread-w-factor) + 3.75rem),
      720px
    );
    transition: max-width 0.8s ease;
  }

  .sb-book.sb-book--immersive .sb-reader-stack--open .sb-reader-book {
    max-width: min(
      calc(100% - 1rem),
      calc(var(--sb-book-inner-h) * var(--sb-book-spread-w-factor) * 2),
      calc(100vw - 2rem),
      min(960px, 98vw)
    );
  }

  .sb-book.sb-book--immersive .sb-book__actions-dock {
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 0.45rem;
    position: fixed;
    bottom: max(0.65rem, env(safe-area-inset-bottom, 12px));
    right: max(0.65rem, env(safe-area-inset-right, 10px));
    left: max(0.65rem, env(safe-area-inset-left, 10px));
    z-index: 54;
    pointer-events: none;
    /* Leave room for global .kids-fbar (2× 3rem + gap) so 📚 isn’t under ⚙️ */
    padding-right: calc(3rem + 0.35rem + 3rem + 0.75rem);
    box-sizing: border-box;
  }

  .sb-book.sb-book--immersive .sb-book__actions-dock > * {
    pointer-events: auto;
  }

  .sb-book.sb-book--immersive .sb-book__actions-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3.35rem;
    height: 3.35rem;
    padding: 0;
    margin: 0;
    border: 2px solid rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    background: linear-gradient(165deg, #f472b6 0%, #db2777 55%, #9d174d 100%);
    box-shadow: 0 6px 22px rgba(157, 23, 77, 0.45), 0 2px 0 rgba(0, 0, 0, 0.12);
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
  }

  .sb-book.sb-book--immersive .sb-book__actions-fab:active {
    transform: scale(0.94);
  }

  .sb-book.sb-book--immersive .sb-book__actions-fab-icon {
    font-size: 1.35rem;
    line-height: 1;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
  }

  .sb-book.sb-book--immersive.sb-book--actions-open .sb-book__actions-fab {
    box-shadow: 0 4px 18px rgba(157, 23, 77, 0.55);
  }

  .sb-book.sb-book--immersive .sb-book__actions {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    margin: 0;
    width: 100%;
    max-width: min(520px, 100%);
    align-self: center;
    flex-direction: column;
    gap: 0.55rem;
    justify-content: stretch;
    padding: 0;
    margin-top: 0;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 18px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.65);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    border-width: 0;
    transform: translateY(10px);
    transition:
      max-height 0.3s ease,
      opacity 0.22s ease,
      visibility 0.22s ease,
      transform 0.22s ease,
      padding 0.22s ease,
      border-width 0.15s ease;
  }

  .sb-book.sb-book--immersive.sb-book--actions-open .sb-book__actions {
    max-height: 300px;
    opacity: 1;
    visibility: visible;
    padding: 0.6rem 0.7rem;
    border-width: 1px;
    transform: translateY(0);
  }

  .sb-book.sb-book--immersive .sb-book__actions .sb-btn {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    width: 100%;
    font-size: 0.9rem;
    padding: 0.62rem 0.75rem;
  }

  .sb-book.sb-book--immersive .sb-book__actions .sb-btn--secondary {
    margin-top: 0;
  }

  .sb-book.sb-book--immersive:not(.sb-book--actions-open) .sb-book-spread {
    padding-bottom: 2.85rem;
  }

  .sb-book.sb-book--immersive.sb-book--actions-open .sb-book-spread {
    padding-bottom: 6.75rem;
  }
}

@media (min-width: 768px) and (prefers-reduced-motion: reduce) {
  .sb-book.sb-book--immersive .sb-book__actions {
    transition: none;
  }

  .sb-book.sb-book--immersive .sb-book__actions-fab {
    transition: none;
  }
}

@media (min-width: 768px) and (orientation: portrait) {
  .sb-book.sb-book--immersive {
    --sb-book-inner-h: clamp(320px, min(84dvh, 90vh), 700px);
  }

  .sb-book.sb-book--immersive .sb-reader-stack {
    min-height: min(84dvh, 800px);
  }
}

/* Landscape tablets: height is scarce — weight dvh over vw so the spread grows taller and fills the screen. */
@media (min-width: 768px) and (orientation: landscape) and (max-height: 900px) {
  .sb-book.sb-book--immersive {
    /* dvh-first — do not cap with vw here or landscape tablets end up shorter than the base rule */
    --sb-book-inner-h: clamp(300px, min(80dvh, 78vh), 640px);
  }

  .sb-book.sb-book--immersive .sb-reader-stack {
    min-height: min(84dvh, 780px);
  }

  .sb-book.sb-book--immersive .sb-book-spread {
    padding-top: clamp(1.85rem, 4.5dvh, 2.75rem);
  }
}

/* Between phone and laptop: a bit more horizontal room for the spread (arrows are fixed overlays). */
@media (min-width: 768px) and (max-width: 1100px) {
  .sb-book.sb-book--immersive .sb-read-stage {
    padding-left: max(0.85rem, env(safe-area-inset-left, 8px));
    padding-right: max(0.85rem, env(safe-area-inset-right, 8px));
  }
}

/* Touch tablets / phones: slightly less art zoom — still full-bleed cover, less aggressive crop on short viewports. */
@media (max-width: 1100px) and (hover: none) and (pointer: coarse) {
  .sb-flip-spread__inner--has-art {
    --sb-spread-art-scale: 1;
  }
}

/* Wooden table — full reader session (cover + open spreads); last in file wins over immersive purple / themed overlays. */
body.page-storybook .sb-book:not(.sb-reader--sample) {
  background-color: #4a3426;
  background-image: url("images/storybook-cover-table-wood.png");
  background-size: cover;
  background-position: 50% 38%;
  background-repeat: no-repeat;
  border-color: rgba(45, 32, 22, 0.55);
  box-shadow:
    0 4px 28px rgba(18, 10, 6, 0.4),
    inset 0 0 0 1px rgba(255, 255, 255, 0.09);
}

body.page-storybook .sb-book:not(.sb-reader--sample)::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(
      ellipse 92% 78% at 72% 26%,
      rgba(255, 235, 210, 0.28) 0%,
      rgba(255, 220, 190, 0.09) 40%,
      transparent 58%
    ),
    radial-gradient(
      ellipse 145% 125% at 50% 50%,
      transparent 22%,
      rgba(18, 10, 6, 0.52) 100%
    );
}

/* Let wood show in the margins around the spread (replacing lavender desk). */
body.page-storybook .sb-book:not(.sb-reader--sample) .sb-flip-spread {
  background: transparent;
}
