/* ==========================================================================
   סיפורים לילדים — Full-Bleed Landscape RTL Hebrew Children's Storybook UI
   ========================================================================== */

:root {
  --bg-deep: #140f21;
  --bg-mid: #211735;
  --bg-glow: #362454;

  --cover-leather: #5b2538;
  --cover-leather-dark: #3a1522;
  --paper-cream: #fcf7eb;
  --paper-warm: #f6eed9;

  --ink-primary: #251b16;
  --ink-secondary: #58453a;
  --ink-muted: #846f5f;
  --accent-gold: #f5b942;
  --highlight-word: #ffe082;

  --font-story: 'Frank Ruhl Libre', Georgia, serif;
  --font-ui: 'Heebo', system-ui, -apple-system, sans-serif;
  --font-display: 'Fredoka', 'Heebo', sans-serif;

  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 25%, var(--bg-glow) 0%, var(--bg-mid) 55%, var(--bg-deep) 100%);
  color: #fff9ee;
  font-family: var(--font-ui);
  direction: rtl;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ==========================================================================
   Ambient Fireflies Background
   ========================================================================== */
.ambient-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.firefly {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffe89e 0%, rgba(255, 210, 90, 0) 75%);
  box-shadow: 0 0 14px 3px rgba(255, 214, 102, 0.55);
  opacity: 0.55;
  animation: floatFirefly 12s infinite ease-in-out alternate;
}

.firefly.f1 { top: 14%; right: 12%; animation-duration: 9s; }
.firefly.f2 { top: 28%; left: 18%; animation-duration: 13s; animation-delay: -3s; }
.firefly.f3 { bottom: 18%; right: 24%; animation-duration: 11s; animation-delay: -5s; }
.firefly.f4 { top: 65%; left: 10%; animation-duration: 15s; animation-delay: -2s; }
.firefly.f5 { top: 18%; left: 48%; animation-duration: 10s; animation-delay: -7s; }

@keyframes floatFirefly {
  0% { transform: translate(0, 0) scale(0.8); opacity: 0.25; }
  50% { transform: translate(-16px, -12px) scale(1.2); opacity: 0.75; }
  100% { transform: translate(12px, -22px) scale(0.9); opacity: 0.35; }
}

/* ==========================================================================
   Portrait Mode Gentle Banner (Shown only inside Reader View when held vertically)
   ========================================================================== */
.portrait-banner {
  display: none;
  position: fixed;
  bottom: calc(var(--safe-bottom) + 10px);
  left: 12px;
  right: 12px;
  z-index: 90;
  background: rgba(30, 19, 50, 0.94);
  border: 1px solid rgba(245, 185, 66, 0.45);
  backdrop-filter: blur(12px);
  border-radius: 14px;
  padding: 8px 14px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  font-size: 0.82rem;
}

.portrait-banner[hidden] {
  display: none !important;
}

@media (orientation: portrait) {
  .portrait-banner:not(.dismissed):not([hidden]) {
    display: flex;
  }
}

.portrait-banner-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #ffe9b5;
  font-weight: 500;
}

.rotate-phone-icon {
  color: var(--accent-gold);
  display: flex;
  animation: tiltPhone 2.4s infinite ease-in-out;
}

@keyframes tiltPhone {
  0%, 20%, 100% { transform: rotate(0deg); }
  50%, 70% { transform: rotate(-90deg); }
}

.portrait-dismiss-btn {
  background: rgba(255, 255, 255, 0.14);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  color: #fff;
  white-space: nowrap;
}

/* ==========================================================================
   App Shell
   ========================================================================== */
.app-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.view {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.view[hidden] {
  display: none !important;
}

/* ==========================================================================
   VIEW 1: LIBRARY SHELF (Works beautifully in BOTH Portrait and Landscape!)
   ========================================================================== */
.library-view {
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 14px) calc(var(--safe-bottom) + 8px) calc(var(--safe-left) + 14px);
  overflow-y: auto;
  overflow-x: hidden;
}

.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(255, 217, 102, 0.2), rgba(244, 162, 54, 0.08));
  border: 1px solid rgba(255, 217, 102, 0.35);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-titles {
  min-width: 0;
}

.app-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 2.5vw, 1.55rem);
  font-weight: 700;
  background: linear-gradient(90deg, #fffdf7, #ffd97d);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

.app-subtitle {
  margin: 1px 0 0;
  font-size: clamp(0.72rem, 1.2vw, 0.82rem);
  color: rgba(255, 244, 224, 0.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.age-tabs {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(17, 11, 29, 0.6);
  padding: 4px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: none;
}

.age-tabs::-webkit-scrollbar {
  display: none;
}

.age-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: clamp(0.76rem, 1.3vw, 0.86rem);
  font-weight: 600;
  color: rgba(255, 245, 225, 0.82);
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.age-tab.active {
  background: linear-gradient(135deg, #f6be4f 0%, #e58c24 100%);
  color: #231409;
  box-shadow: 0 3px 10px rgba(245, 185, 66, 0.4);
}

.ai-magic-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.42), rgba(236, 72, 153, 0.42));
  border: 1px solid rgba(233, 168, 255, 0.55);
  color: #fce7ff;
  font-size: clamp(0.76rem, 1.3vw, 0.86rem);
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(147, 51, 234, 0.3);
}

.library-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.bookshelf-grid {
  display: flex;
  align-items: stretch;
  gap: clamp(12px, 1.8vw, 20px);
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 4px 12px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  height: 100%;
  max-height: 390px;
}

.bookshelf-grid::-webkit-scrollbar {
  display: none;
}

.book-card {
  position: relative;
  scroll-snap-align: start;
  border-radius: 16px;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  display: flex;
  cursor: pointer;
}

.book-card.featured-book {
  flex: 0 0 clamp(370px, 54vw, 590px);
  background: linear-gradient(135deg, #fffdf8 0%, #f5ebd6 100%);
  color: var(--ink-primary);
  border: 3px solid #e6c687;
  box-shadow:
    0 14px 32px rgba(0, 0, 0, 0.48),
    -6px 0 0 #6e3044,
    -9px 0 0 #d8ccb4;
  overflow: hidden;
  padding: clamp(10px, 1.6vw, 16px);
  gap: clamp(12px, 1.8vw, 18px);
  align-items: center;
}

.featured-cover-wrap {
  position: relative;
  height: 100%;
  aspect-ratio: 1 / 1;
  max-height: 260px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(45, 25, 10, 0.25);
}

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

.featured-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  text-align: right;
}

.book-badges-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.badge-age {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: #f5dec0;
  color: #6b3b10;
  white-space: nowrap;
}

.badge-ai {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, #69369c, #9b4dca);
  color: #fff;
  white-space: nowrap;
}

.featured-title {
  margin: 4px 0;
  font-family: var(--font-story);
  font-size: clamp(1.18rem, 2.2vw, 1.7rem);
  font-weight: 900;
  color: #2b1810;
  line-height: 1.15;
}

.featured-synopsis {
  margin: 0;
  font-size: clamp(0.78rem, 1.3vw, 0.92rem);
  line-height: 1.42;
  color: var(--ink-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.featured-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.74rem;
  color: var(--ink-muted);
  font-weight: 600;
  margin-top: 4px;
}

.open-story-cta {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 12px;
  background: linear-gradient(135deg, #d96b27 0%, #b83749 100%);
  color: #fff;
  font-weight: 700;
  font-size: clamp(0.84rem, 1.35vw, 0.94rem);
  box-shadow: 0 5px 14px rgba(184, 55, 73, 0.35);
  align-self: flex-start;
  white-space: nowrap;
}

/* ==========================================================================
   PORTRAIT PHONE LAYOUT FOR MAIN LIBRARY MENU
   So holding the phone vertically in the menu looks sleek & native!
   ========================================================================== */
@media (orientation: portrait), (max-width: 720px) {
  .library-header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px 8px;
    padding-bottom: 12px;
  }

  .brand-cluster {
    grid-column: 1 / 2;
    grid-row: 1;
    justify-content: flex-start;
  }

  .app-subtitle {
    display: none;
  }

  .header-actions {
    grid-column: 2 / 3;
    grid-row: 1;
    position: static;
  }

  .age-tabs {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    justify-content: space-between;
  }

  .age-tab {
    flex: 1;
    justify-content: center;
    padding: 7px 8px;
    font-size: 0.78rem;
  }

  .library-stage {
    justify-content: flex-start;
  }

  .bookshelf-grid {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: visible;
    max-height: none;
    height: auto;
    gap: 14px;
    padding-bottom: 20px;
  }

  /* Featured Story Card becomes a sleek vertical card in portrait */
  .book-card.featured-book {
    flex: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    padding: 14px;
    gap: 12px;
  }

  .featured-cover-wrap {
    width: 100%;
    height: 210px;
    max-height: 210px;
    aspect-ratio: auto;
  }

  .featured-info {
    gap: 8px;
  }

  .featured-title {
    font-size: 1.45rem;
    margin: 6px 0 4px;
  }

  .featured-synopsis {
    font-size: 0.9rem;
    -webkit-line-clamp: 3;
  }

  .open-story-cta {
    width: 100%;
    padding: 11px 16px;
    font-size: 0.95rem;
  }

  /* Secondary books arrange in a neat horizontal row or 2-column grid below */
  .book-card.shelf-book {
    flex: none;
    width: 100%;
    height: 110px;
    flex-direction: row;
    align-items: center;
  }

  .shelf-book-cover {
    width: 110px;
    height: 100%;
    flex: none;
  }

  .shelf-book-footer {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 12px 16px;
  }

  .shelf-book-title {
    font-size: 1.1rem;
    white-space: normal;
  }

  .wooden-shelf-ledge {
    display: none;
  }
}

.book-card.shelf-book {
  flex: 0 0 clamp(140px, 18vw, 190px);
  flex-direction: column;
  background: #2c2042;
  border-radius: 14px 18px 18px 14px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  box-shadow:
    0 12px 24px rgba(0, 0, 0, 0.45),
    -4px 0 0 #dfd2b5;
  overflow: hidden;
}

.shelf-book-cover {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

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

.coming-soon-ribbon {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(21, 16, 34, 0.82);
  border: 1px solid rgba(255, 217, 102, 0.4);
  color: #ffe299;
  font-size: 0.66rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.shelf-book-footer {
  padding: 7px 10px;
  background: rgba(22, 15, 36, 0.98);
}

.shelf-book-age {
  font-size: 0.65rem;
  color: #f5b942;
  font-weight: 700;
  display: block;
}

.shelf-book-title {
  margin: 2px 0 0;
  font-family: var(--font-story);
  font-size: clamp(0.82rem, 1.25vw, 0.96rem);
  color: #fff8eb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wooden-shelf-ledge {
  width: 100%;
  height: 14px;
  margin-top: -5px;
  flex-shrink: 0;
}

.shelf-top-bevel {
  height: 5px;
  background: linear-gradient(90deg, #5d3623, #8c5438 30%, #a46546 50%, #8c5438 70%, #5d3623);
  border-radius: 5px 5px 0 0;
}

.shelf-front-face {
  height: 9px;
  background: linear-gradient(180deg, #4b2a1a 0%, #2e180e 100%);
  border-radius: 0 0 7px 7px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   VIEW 2: FULL-BLEED OPEN HARDCOVER BOOK READER
   Takes 100% of the screen width & height so the book feels large and real
   ========================================================================== */
.reader-view {
  padding: calc(var(--safe-top) + 4px) calc(var(--safe-right) + 6px) calc(var(--safe-bottom) + 4px) calc(var(--safe-left) + 6px);
}

.book-stage-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* Open Book fills the entire landscape screen */
.open-book {
  width: 100%;
  height: 100%;
  max-width: 1280px;
  max-height: 760px;
  display: flex;
  outline: none;
}

.hardcover-board {
  position: relative;
  width: 100%;
  height: 100%;
  background: linear-gradient(145deg, var(--cover-leather) 0%, var(--cover-leather-dark) 100%);
  border-radius: 16px;
  padding: clamp(5px, 1vh, 10px) clamp(9px, 1.3vw, 15px) clamp(6px, 1.2vh, 12px);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.65),
    inset 0 1px 1px rgba(255, 225, 175, 0.28),
    inset 0 0 0 1.5px rgba(243, 193, 90, 0.25);
  display: flex;
}

/* Stacked Paper Thickness Edges */
.paper-stack-right,
.paper-stack-left {
  position: absolute;
  top: clamp(6px, 1.1vh, 12px);
  bottom: clamp(7px, 1.3vh, 14px);
  width: 8px;
  z-index: 1;
  pointer-events: none;
}

.paper-stack-right {
  right: 3px;
  background: repeating-linear-gradient(to left, #fdf9ef 0px, #fdf9ef 1.5px, #d8cab0 1.5px, #d8cab0 3px);
  border-radius: 0 5px 5px 0;
}

.paper-stack-left {
  left: 3px;
  background: repeating-linear-gradient(to right, #fdf9ef 0px, #fdf9ef 1.5px, #d8cab0 1.5px, #d8cab0 3px);
  border-radius: 5px 0 0 5px;
}

/* Two-Page Spread Container */
.book-spread {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 18px 1fr;
  border-radius: 11px;
  overflow: hidden;
  background: var(--paper-cream);
  box-shadow: inset 0 -2px 0 #ded0b4;
  perspective: 1800px;
}

.book-page {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page-right {
  background: linear-gradient(to left, #fbf6e9 0%, #fdfaf0 82%, #ede2c9 100%);
}

.page-left {
  background: linear-gradient(to right, #fbf6e9 0%, #fdfaf0 82%, #ede2c9 100%);
}

.page-paper-texture {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.3;
  background-image: radial-gradient(rgba(165, 130, 85, 0.12) 1px, transparent 0);
  background-size: 16px 16px;
  z-index: 1;
}

.page-inner {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Center Spine Gutter & Ribbon Bookmark */
.book-spine-gutter {
  position: relative;
  width: 18px;
  height: 100%;
  background: linear-gradient(90deg, #dfd3b8 0%, #b8a586 35%, #7f6b50 50%, #b8a586 65%, #dfd3b8 100%);
  box-shadow: inset 0 0 7px rgba(45, 28, 10, 0.35);
  z-index: 6;
  display: flex;
  justify-content: center;
}

.spine-stitch {
  width: 1.5px;
  height: 100%;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 250, 235, 0.65) 0px,
    rgba(255, 250, 235, 0.65) 9px,
    transparent 9px,
    transparent 16px
  );
}

.ribbon-bookmark {
  position: absolute;
  top: 0;
  width: 9px;
  height: 36px;
  background: linear-gradient(180deg, #991b36 0%, #c82d4d 100%);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%);
}

/* ==========================================================================
   RIGHT PAGE: Clean, Unclipped Hebrew Story Text + Embedded Header/Footer
   ========================================================================== */
.right-page-inner {
  padding: clamp(8px, 2.2vh, 22px) clamp(14px, 2.8vw, 34px) clamp(8px, 2vh, 18px);
  justify-content: space-between;
  color: var(--ink-primary);
  gap: clamp(4px, 1vh, 10px);
}

/* Single-line non-wrapping page header with back button */
.story-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgba(138, 117, 101, 0.2);
  padding-bottom: 4px;
  flex-shrink: 0;
  white-space: nowrap;
}

.embedded-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 999px;
  background: #8b2f47;
  color: #fff8eb;
  font-size: clamp(0.74rem, 1.25vw, 0.86rem);
  font-weight: 700;
  box-shadow: 0 3px 8px rgba(139, 47, 71, 0.3);
  transition: transform 0.18s ease, background 0.18s ease;
}

.embedded-back-btn:hover {
  background: #722237;
  transform: scale(1.03);
}

.story-chapter-tag {
  font-size: clamp(0.68rem, 1.15vw, 0.8rem);
  font-weight: 700;
  color: #9e5816;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-spread-counter {
  font-family: var(--font-story);
  font-size: clamp(0.7rem, 1.15vw, 0.82rem);
  color: var(--ink-muted);
  font-weight: 700;
}

/* Main Story Text Body — Scales cleanly to fit without any scrollbar */
.story-text-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(5px, 1.4vh, 14px);
  overflow: hidden;
}

.story-paragraph {
  margin: 0;
  font-family: var(--font-story);
  /* Responsive clamp using BOTH vh and vw so even with Chrome's URL bar open it never overflows! */
  font-size: clamp(0.88rem, min(4.2vh, 2.05vw), 1.38rem);
  line-height: 1.46;
  color: var(--ink-primary);
  font-weight: 500;
}

.story-paragraph:first-child .story-word:first-child {
  font-size: 1.18em;
  font-weight: 900;
  color: #8b2f47;
}

.story-word {
  display: inline;
  padding: 0 2px;
  border-radius: 5px;
  transition: background-color 0.15s ease, color 0.15s ease;
  cursor: pointer;
}

.story-word.active-word {
  background-color: var(--highlight-word);
  color: #1a0f07;
  font-weight: 700;
}

/* Compact Single-Row Interactive Child Prompt */
.story-activity-box {
  background: linear-gradient(135deg, rgba(245, 185, 66, 0.16), rgba(230, 138, 30, 0.08));
  border: 1px dashed rgba(196, 125, 38, 0.5);
  border-radius: 10px;
  padding: clamp(4px, 1vh, 9px) clamp(8px, 1.3vw, 12px);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.activity-icon {
  font-size: clamp(0.9rem, 3.2vh, 1.15rem);
  flex-shrink: 0;
}

.activity-text {
  margin: 0;
  font-size: clamp(0.68rem, min(2.8vh, 1.2vw), 0.85rem);
  color: #5c3a16;
  font-weight: 600;
  line-height: 1.28;
}

/* Page Footer with Embedded Page Dots & Flip CTA */
.story-page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 2px;
  font-size: 0.72rem;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.inline-spread-dots {
  display: flex;
  align-items: center;
  gap: 5px;
}

.spread-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(124, 101, 82, 0.28);
  transition: all 0.2s ease;
  padding: 0;
}

.spread-dot.active {
  width: 18px;
  background: #c86428;
}

.flip-next-inline-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: clamp(0.72rem, 2.7vh, 0.82rem);
  color: #9e4720;
  padding: 3px 9px;
  border-radius: 8px;
  background: rgba(217, 107, 39, 0.12);
}

/* ==========================================================================
   LEFT PAGE: Edge-to-Edge Framed Illustration + Clean Caption Strip
   ========================================================================== */
.left-page-inner {
  padding: clamp(6px, 1.6vh, 16px) clamp(8px, 1.6vw, 18px);
  justify-content: center;
  align-items: center;
}

.illustration-frame {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 11px;
  overflow: hidden;
  box-shadow:
    0 6px 18px rgba(45, 28, 12, 0.18),
    inset 0 0 0 2px rgba(255, 250, 238, 0.85);
  background: #231934;
  cursor: pointer;
}

.illustration-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  animation: subtleKenBurns 14s ease-in-out infinite alternate;
}

@keyframes subtleKenBurns {
  0% { transform: scale(1); }
  100% { transform: scale(1.04); }
}

/* Sleek single-line bottom caption gradient — NEVER blocks the illustration! */
.illustration-caption-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 12px 6px;
  background: linear-gradient(to top, rgba(16, 10, 26, 0.82) 0%, rgba(16, 10, 26, 0.38) 60%, transparent 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #fff8eb;
  font-size: clamp(0.66rem, min(2.6vh, 1.1vw), 0.78rem);
  pointer-events: none;
}

.caption-text-line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.tap-magic-hint {
  color: #ffd966;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Floating Glass Controls inside Top-Left of Left Page */
.book-floating-controls {
  position: absolute;
  top: clamp(10px, 2.2vh, 20px);
  left: clamp(12px, 2vw, 24px);
  z-index: 14;
  display: flex;
  align-items: center;
  gap: 6px;
}

.book-exit-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(184, 55, 73, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 220, 225, 0.45);
  color: #fff;
  font-size: clamp(0.7rem, 2.5vh, 0.8rem);
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.book-glass-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(20, 14, 34, 0.68);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff8eb;
  font-size: clamp(0.68rem, 2.5vh, 0.78rem);
  font-weight: 600;
}

.book-glass-pill.playing {
  background: linear-gradient(135deg, #f5b942, #e68a1e);
  color: #241406;
  border-color: #ffe082;
}

.book-glass-icon {
  width: clamp(26px, 6vh, 32px);
  height: clamp(26px, 6vh, 32px);
  border-radius: 50%;
  background: rgba(20, 14, 34, 0.68);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff8eb;
  display: inline-grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.78rem;
}

.book-glass-icon.active {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

/* Subtle Translucent Edge Chevrons directly on book outer edges */
.book-edge-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 52px;
  border-radius: 10px;
  background: rgba(25, 16, 40, 0.38);
  backdrop-filter: blur(4px);
  color: #fff5dc;
  display: grid;
  place-items: center;
  z-index: 14;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.book-edge-nav:hover:not(:disabled) {
  background: rgba(25, 16, 40, 0.7);
}

.book-edge-nav:disabled {
  opacity: 0;
  pointer-events: none;
}

.edge-prev {
  right: 4px;
}

.edge-next {
  left: 4px;
}

/* Interactive Sparkle Burst */
.magic-sparkle-burst {
  position: absolute;
  width: 26px;
  height: 26px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: burstPop 0.75s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  z-index: 10;
  font-size: 1.3rem;
  display: grid;
  place-items: center;
}

@keyframes burstPop {
  0% { transform: translate(-50%, -50%) scale(0.3) rotate(-15deg); opacity: 1; }
  60% { transform: translate(-50%, -75%) scale(1.35) rotate(12deg); opacity: 1; }
  100% { transform: translate(-50%, -95%) scale(0.8) rotate(25deg); opacity: 0; }
}

/* Page Corner Curls */
.page-corner-curl {
  position: absolute;
  bottom: 0;
  width: 28px;
  height: 28px;
  z-index: 8;
  cursor: pointer;
  transition: width 0.2s ease, height 0.2s ease;
}

.corner-left {
  left: 0;
  background: linear-gradient(45deg, #d7c7a9 0%, #f4ead5 48%, rgba(244, 234, 213, 0) 52%);
  border-top-right-radius: 7px;
}

.corner-right {
  right: 0;
  background: linear-gradient(315deg, #d7c7a9 0%, #f4ead5 48%, rgba(244, 234, 213, 0) 52%);
  border-top-left-radius: 7px;
}

/* ==========================================================================
   3D PAGE FLIP ANIMATION OVERLAY
   ========================================================================== */
.turning-leaf {
  position: absolute;
  top: 0;
  bottom: 0;
  width: calc(50% - 9px);
  z-index: 12;
  pointer-events: none;
  transform-style: preserve-3d;
  opacity: 0;
}

.leaf-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 8px;
}

.leaf-front {
  background: linear-gradient(90deg, #e9dcc2 0%, #fcf7eb 100%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.leaf-back {
  background: linear-gradient(-90deg, #e9dcc2 0%, #fcf7eb 100%);
  transform: rotateY(180deg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.turning-leaf.flip-next {
  left: 0;
  transform-origin: right center;
  opacity: 1;
  animation: flipLeftToRight 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes flipLeftToRight {
  0% { transform: rotateY(0deg); opacity: 1; }
  85% { transform: rotateY(175deg); opacity: 1; }
  100% { transform: rotateY(180deg); opacity: 0; }
}

.turning-leaf.flip-prev {
  right: 0;
  transform-origin: left center;
  opacity: 1;
  animation: flipRightToLeft 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes flipRightToLeft {
  0% { transform: rotateY(0deg); opacity: 1; }
  85% { transform: rotateY(-175deg); opacity: 1; }
  100% { transform: rotateY(-180deg); opacity: 0; }
}

/* End-of-Book Celebration Badge */
.story-end-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(43, 138, 126, 0.14), rgba(245, 185, 66, 0.18));
  border: 1px solid rgba(43, 138, 126, 0.35);
}

.replay-story-btn {
  padding: 4px 10px;
  border-radius: 999px;
  background: #8b2f47;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ==========================================================================
   MODAL: Generate Your Own Story
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(12, 8, 22, 0.78);
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  padding: 10px;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  position: relative;
  width: min(640px, 94vw);
  max-height: 94dvh;
  overflow-y: auto;
  background: linear-gradient(160deg, #2b1d44 0%, #191129 100%);
  border: 1px solid rgba(245, 185, 66, 0.45);
  border-radius: 18px;
  padding: clamp(12px, 2.2vh, 20px) clamp(14px, 2.5vw, 24px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
  color: #fff8eb;
}

.modal-close-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  display: grid;
  place-items: center;
}

.modal-badges-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: #ffd966;
  background: rgba(255, 217, 102, 0.16);
  padding: 2px 9px;
  border-radius: 999px;
}

.api-status-pill {
  font-size: 0.68rem;
  color: #d8b4fe;
  background: rgba(168, 85, 247, 0.18);
  border: 1px solid rgba(192, 132, 252, 0.35);
  padding: 2px 8px;
  border-radius: 999px;
}

.modal-header h3 {
  margin: 4px 0 2px;
  font-family: var(--font-display);
  font-size: clamp(1rem, 2vw, 1.25rem);
}

.modal-header p {
  margin: 0;
  font-size: 0.78rem;
  color: rgba(255, 245, 225, 0.76);
}

.modal-form-grid {
  margin: 8px 0;
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 8px 12px;
}

.form-row.full-width {
  grid-column: 1 / -1;
}

.form-row label {
  display: block;
  font-size: 0.72rem;
  color: #ffd97d;
  font-weight: 600;
  margin-bottom: 3px;
}

.form-row input,
.form-row textarea {
  width: 100%;
  padding: 7px 10px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(10, 6, 20, 0.45);
  color: #fff;
  font-family: inherit;
  font-size: 0.84rem;
  resize: none;
  outline: none;
}

.pill-selector-group {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.pill-option {
  font-size: 0.72rem;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #fff5e0;
}

.pill-option.selected {
  background: rgba(245, 185, 66, 0.26);
  border-color: var(--accent-gold);
  color: #ffe394;
  font-weight: 700;
}

.prompt-chips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 5px;
}

.prompt-chip {
  font-size: 0.7rem;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px dashed rgba(255, 217, 102, 0.35);
  color: #ffe8b3;
}

.ai-safety-error {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 13px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: rgba(220, 38, 38, 0.22);
  border: 1px solid rgba(252, 165, 165, 0.55);
  color: #ffe4e6;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
}

.ai-safety-error[hidden] {
  display: none !important;
}

.ai-safety-error p {
  margin: 0;
}

.safety-error-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.ai-generation-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: rgba(168, 85, 247, 0.2);
  border: 1px solid rgba(216, 180, 254, 0.45);
}

.ai-generation-status[hidden] {
  display: none !important;
}

.magic-spinner {
  font-size: 1.3rem;
  animation: spinPulse 1.1s infinite ease-in-out alternate;
}

@keyframes spinPulse {
  0% { transform: scale(0.9) rotate(-12deg); }
  100% { transform: scale(1.25) rotate(18deg); }
}

.generation-steps-text {
  display: flex;
  flex-direction: column;
  font-size: 0.78rem;
}

.generation-steps-text span {
  color: rgba(255, 240, 215, 0.78);
  font-size: 0.72rem;
}

.primary-cta-btn {
  width: 100%;
  padding: 9px 14px;
  border-radius: 11px;
  background: linear-gradient(135deg, #f5b942 0%, #e07b1b 100%);
  color: #231204;
  font-weight: 700;
  font-size: 0.88rem;
  box-shadow: 0 5px 15px rgba(245, 185, 66, 0.35);
}

@media (max-height: 450px) {
  .app-subtitle {
    display: none;
  }
}
