/* Story Adventures — Sesame-like chunky preschool UI */

.sa-root {
  --ink: #263238;
  --white: #ffffff;
  --yellow: #ffd54f;
  --red: #e53935;
  --blue: #1e88e5;
  --green: #43a047;
  --pink: #f48fb1;
  --orange: #ff9800;
  --sky: #81d4fa;
  --purple: #7e57c2;
  --outline: 5px;
  --ease-pop: cubic-bezier(0.34, 1.4, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #5c9ef0;
  overflow: hidden;
  font-family: "Fredoka", "Nunito", system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.sa-chrome {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.55rem;
  padding: max(0.85rem, env(safe-area-inset-top)) 0.9rem 0.5rem;
  flex-shrink: 0;
}

.sa-exit,
.sa-back {
  display: grid;
  place-items: center;
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 999px;
  background: var(--orange);
  border: var(--outline) solid var(--white);
  color: var(--white);
  font-size: 1.55rem;
  font-weight: 700;
  text-decoration: none;
  line-height: 1;
  box-shadow: 0 6px 0 rgba(38, 50, 56, 0.18);
  cursor: pointer;
  font-family: inherit;
  padding: 0;
}

.sa-back {
  background: var(--blue);
}

.sa-exit:active,
.sa-back:active {
  transform: translateY(3px) scale(0.92);
  box-shadow: 0 2px 0 rgba(38, 50, 56, 0.18);
}

.sa-title-pill {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.85rem;
  padding: 0.35rem 1.1rem;
  border-radius: 999px;
  background: var(--blue);
  border: var(--outline) solid var(--white);
  color: var(--white);
  font-weight: 700;
  font-size: clamp(1rem, 3.5vw, 1.25rem);
  box-shadow: 0 6px 0 rgba(38, 50, 56, 0.16);
  text-align: center;
  max-width: 100%;
}

.sa-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0.4rem 0.9rem max(1rem, env(safe-area-inset-bottom));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sa-screen[hidden] {
  display: none;
}

/* —— Picker —— */

.sa-picker {
  overflow: hidden;
}

.sa-picker__lead {
  margin: 0.35rem 0 0.85rem;
  text-align: center;
  color: var(--white);
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  font-weight: 700;
  text-shadow: 0 3px 0 rgba(38, 50, 56, 0.18);
  flex-shrink: 0;
}

.sa-story-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 0.75rem;
  align-content: start;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.15rem 0.15rem 0.85rem;
}

.sa-story-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0;
  border-radius: 1.1rem;
  background: #fff8e7;
  border: var(--outline) solid var(--white);
  box-shadow:
    0 8px 0 rgba(38, 50, 56, 0.16),
    4px 0 0 rgba(38, 50, 56, 0.08);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  overflow: hidden;
  min-width: 0;
}

.sa-story-card:active {
  transform: translateY(4px);
  box-shadow:
    0 4px 0 rgba(38, 50, 56, 0.16),
    3px 0 0 rgba(38, 50, 56, 0.08);
}

.sa-story-card__cover {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: linear-gradient(165deg, #81d4fa 0%, #b8e6c8 100%);
  overflow: hidden;
}

.sa-story-card__cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.sa-story-card__cover-img[hidden],
.sa-story-card__cover-fallback[hidden] {
  display: none;
}

.sa-story-card__cover-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(2.4rem, 12vw, 3.4rem);
  line-height: 1;
}

.sa-story-card__body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.65rem 0.7rem 0.75rem;
  background: #fff8e7;
  border-top: 3px solid rgba(38, 50, 56, 0.12);
}

.sa-story-card__title {
  display: block;
  font-size: clamp(0.95rem, 3.4vw, 1.15rem);
  font-weight: 800;
  line-height: 1.2;
}

.sa-story-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}

.sa-age-tag {
  display: inline-flex;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #e3f2fd;
  border: 2.5px solid var(--ink);
  font-size: 0.68rem;
  font-weight: 800;
}

.sa-endings-tag {
  font-size: 0.72rem;
  font-weight: 800;
  color: rgba(38, 50, 56, 0.72);
}

@media (min-width: 720px) {
  .sa-story-list {
    max-width: 36rem;
    margin: 0 auto;
    width: 100%;
    gap: 1.1rem 1rem;
  }

  .sa-story-card__title {
    font-size: 1.2rem;
  }

  .sa-age-tag {
    font-size: 0.75rem;
  }

  .sa-endings-tag {
    font-size: 0.8rem;
  }
}

/* —— Play: an open book (JG-046) ——
   Phone: the scene on top, the words underneath (they scroll; the buttons stay put).
   Desktop: two pages side by side — words on the left page, the scene on the right. */

.sa-book {
  gap: 0.65rem;
  overflow: hidden;
}

.sa-book__page--scene {
  flex: 0 0 auto;
}

.sa-book__page--text {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sa-book__scroll {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sa-book__story {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.sa-book__story[hidden],
.sa-ending__card[hidden] {
  display: none;
}

.sa-book__scroll.is-turn {
  animation: sa-turn 0.45s var(--ease-out) both;
}

@keyframes sa-turn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.sa-scene {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  height: min(42vh, 22rem);
  min-height: 10rem;
  border-radius: 1.4rem;
  overflow: hidden;
  background: linear-gradient(165deg, #81d4fa 0%, #b8e6c8 100%);
  border: var(--outline) solid var(--white);
  box-shadow: 0 8px 0 rgba(38, 50, 56, 0.16);
}

.sa-scene3d {
  position: absolute;
  inset: 0;
  transition: opacity 0.2s;
}

.sa-scene3d[hidden] {
  display: none;
}

.sa-scene3d__canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.sa-scene__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sa-scene__fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(4rem, 18vw, 7rem);
}

.sa-scene__fallback[hidden],
.sa-scene__img[hidden] {
  display: none;
}

/* the words scroll if they're long; the choices underneath stay in view */
.sa-copy {
  flex: 0 1 auto;
  min-height: 3.5rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.85rem 1rem;
  border-radius: 1.25rem;
  background: var(--white);
  border: var(--outline) solid var(--white);
  box-shadow: 0 6px 0 rgba(38, 50, 56, 0.14);
}

.sa-story-text {
  margin: 0;
  font-size: clamp(1.15rem, 4.2vw, 1.4rem);
  font-weight: 700;
  line-height: 1.35;
}

.sa-question {
  margin: 0.65rem 0 0;
  font-size: clamp(1.2rem, 4.5vw, 1.5rem);
  font-weight: 800;
  color: var(--blue);
  line-height: 1.25;
}

.sa-question[hidden] {
  display: none;
}

.sa-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.15rem;
  padding-bottom: 0.35rem;
}

.sa-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  min-height: 3.5rem;
  padding: 0.75rem 1.1rem;
  border-radius: 1.15rem;
  border: var(--outline) solid var(--white);
  font-family: inherit;
  font-size: clamp(1.2rem, 4.5vw, 1.45rem);
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 7px 0 rgba(38, 50, 56, 0.18);
  color: var(--white);
}

.sa-btn:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 rgba(38, 50, 56, 0.18);
}

.sa-btn--primary {
  background: var(--green);
}

/* JG-046: while the scene acts out the choice, the picked button stays lit and the rest step back */
.sa-actions.is-acting .sa-btn {
  opacity: 0.45;
  cursor: default;
}
.sa-actions.is-acting .sa-btn.is-picked,
.sa-actions.is-acting .sa-btn--primary {
  opacity: 1;
  transform: scale(1.02);
  box-shadow:
    0 7px 0 rgba(38, 50, 56, 0.18),
    0 0 0 5px rgba(255, 213, 79, 0.75);
}

.sa-btn--choice {
  background: var(--yellow);
  color: var(--ink);
  justify-content: flex-start;
  text-align: left;
}

.sa-btn--choice:nth-child(2) {
  background: #80deea;
}

.sa-btn--choice:nth-child(3) {
  background: var(--pink);
}

.sa-btn--secondary {
  background: var(--blue);
}

.sa-btn__emoji {
  font-size: 1.45em;
  line-height: 1;
  flex-shrink: 0;
}

.sa-btn__label {
  flex: 1;
}

/* —— Ending —— */

.sa-ending__card {
  width: min(100%, 26rem);
  margin: auto;
  box-sizing: border-box;
  padding: 1.4rem 1.2rem 1.25rem;
  border-radius: 1.5rem;
  background: var(--blue);
  border: var(--outline) solid var(--white);
  box-shadow: 0 10px 0 rgba(38, 50, 56, 0.18);
  text-align: center;
  color: var(--white);
}

.sa-ending__card[data-ending-kind="silly"] {
  background: #fb8c00;
}

.sa-ending__card[data-ending-kind="surprise"] {
  background: var(--purple);
}

.sa-ending__card[data-ending-kind="happy"] {
  background: var(--green);
}

.sa-ending__emoji {
  margin: 0;
  font-size: 4rem;
  line-height: 1;
}

.sa-ending__title {
  margin: 0.55rem 0 0.35rem;
  font-size: clamp(1.6rem, 6vw, 2rem);
  font-weight: 800;
}

.sa-ending__text {
  margin: 0;
  font-size: clamp(1.1rem, 4vw, 1.3rem);
  font-weight: 700;
  line-height: 1.35;
}

.sa-ending__progress {
  margin: 0.85rem 0 0;
  font-size: 1rem;
  font-weight: 700;
  opacity: 0.92;
}

.sa-ending__actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 1.1rem;
}

@media (max-height: 700px) {
  .sa-scene {
    height: min(34vh, 13rem);
    min-height: 8rem;
  }

  .sa-copy {
    padding: 0.7rem 0.85rem;
  }

  .sa-story-text {
    font-size: clamp(1.05rem, 3.8vw, 1.25rem);
  }

  .sa-question {
    margin-top: 0.5rem;
    font-size: clamp(1.1rem, 4vw, 1.35rem);
  }

  .sa-btn {
    min-height: 3.15rem;
    padding: 0.65rem 1rem;
  }
}

@media (min-width: 720px) {
  .sa-book {
    max-width: 40rem;
    margin: 0 auto;
    width: 100%;
  }
}

/* Desktop / tablet landscape: an open book — words on the left page, the scene on the right */
@media (min-width: 900px) and (min-height: 520px) and (min-aspect-ratio: 5/4) {
  .sa-book {
    flex-direction: row;
    gap: 0;
    max-width: min(76rem, 100%);
    width: 100%;
    margin: 0 auto 0.4rem;
    padding: 0.9rem;
    box-sizing: border-box;
    border-radius: 1.6rem;
    background: #8d4f2a; /* the book's cover peeking out round the pages */
    border: var(--outline) solid var(--white);
    box-shadow: 0 12px 0 rgba(38, 50, 56, 0.22);
  }

  .sa-book__page {
    flex: 1 1 50%;
    min-width: 0;
    min-height: 0;
    background: #fffaf0;
    box-sizing: border-box;
  }

  .sa-book__page--text {
    order: 1;
    padding: 2rem 2.2rem 1.6rem;
    border-radius: 1rem 0 0 1rem;
    /* the fold: shading in toward the spine */
    background: linear-gradient(90deg, #fffaf0 0%, #fffaf0 86%, #efe3cc 100%);
  }

  .sa-book__page--scene {
    order: 2;
    display: flex;
    padding: 1.4rem 1.4rem 1.4rem 1.6rem;
    border-radius: 0 1rem 1rem 0;
    background: linear-gradient(90deg, #efe3cc 0%, #fffaf0 12%, #fffaf0 100%);
  }

  .sa-scene {
    height: auto;
    flex: 1;
    min-height: 0;
    border-radius: 0.9rem;
    border-width: 4px;
    box-shadow: 0 4px 0 rgba(38, 50, 56, 0.12);
  }

  /* the words read like a page: no white box, bigger type */
  .sa-copy {
    padding: 0.2rem 0.2rem 0.8rem;
    background: none;
    border: 0;
    box-shadow: none;
  }

  .sa-story-text {
    font-size: clamp(1.5rem, 2.2vw, 2rem);
    line-height: 1.45;
  }

  .sa-question {
    font-size: clamp(1.45rem, 2vw, 1.8rem);
    margin-top: 1.1rem;
  }

  .sa-actions {
    margin-top: auto;
  }

  .sa-btn {
    font-size: clamp(1.2rem, 1.7vw, 1.45rem);
  }

  .sa-book__scroll.is-turn {
    animation-name: sa-turn-side;
  }

  @keyframes sa-turn-side {
    from {
      opacity: 0;
      transform: translateX(-14px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .sa-exit:active,
  .sa-back:active,
  .sa-story-card:active,
  .sa-btn:active {
    transform: none;
  }
  .sa-book__scroll.is-turn {
    animation: none;
  }
}

/* ── JG-048 v3: interactive pages — tap things in the picture (no Continue button) ── */
.sa-cues {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.sa-cue {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.35s;
}
.sa-cue.is-on {
  opacity: 1;
}
/* A soft white ring on the thing to tap, a gentle ripple going out from it, and (for GO)
   a small pointing hand that taps. Choices get a little picture badge; fun taps just twinkle. */
.sa-cue.is-out {
  visibility: hidden;
}
.sa-cue__ring,
.sa-cue__ripple {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}
.sa-cue__ring {
  border: 3px solid rgba(255, 255, 255, 0.95);
  box-shadow:
    0 0 0 1.5px rgba(38, 50, 56, 0.22),
    0 0 14px 2px rgba(255, 255, 255, 0.55),
    inset 0 0 10px rgba(255, 255, 255, 0.35);
}
.sa-cue__ripple {
  border: 2.5px solid rgba(255, 255, 255, 0.9);
  animation: sa-cue-ripple 2s ease-out infinite;
}
.sa-cue__hand {
  position: absolute;
  right: -14px;
  bottom: -16px;
  width: 30px;
  height: 30px;
  filter: drop-shadow(0 2px 2px rgba(38, 50, 56, 0.3));
  animation: sa-cue-press 2s ease-in-out infinite;
}
/* nobody's tapped for a while: the ripple quickens and the hand taps a little more */
.sa-cue--go.is-nudge .sa-cue__ripple {
  animation-duration: 1.1s;
}
.sa-cue--go.is-nudge .sa-cue__hand {
  animation-duration: 1.1s;
}
/* fun taps: no ring — just a small twinkle now and then */
.sa-cue--fun .sa-cue__ring,
.sa-cue--fun .sa-cue__ripple {
  display: none;
}
.sa-cue--fun::after {
  content: "";
  position: absolute;
  right: 12%;
  top: 8%;
  width: 14px;
  height: 14px;
  background: #fff;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  filter: drop-shadow(0 0 3px rgba(255, 241, 118, 0.9));
  animation: sa-cue-wink 3.2s ease-in-out infinite;
}
.sa-cue--fun:nth-child(2n)::after {
  animation-delay: 1.4s;
}
.sa-cue--fun:nth-child(3n)::after {
  animation-delay: 2.3s;
}
/* choices: the ring plus a small badge with the choice's picture */
.sa-cue--pick .sa-cue__ripple {
  animation-duration: 2.4s;
}
.sa-cue__label {
  position: absolute;
  left: 50%;
  top: -0.85rem;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 0 2px rgba(38, 50, 56, 0.2);
  font-size: 1.05rem;
}
.sa-cue.is-pressed .sa-cue__ring {
  background: rgba(255, 255, 255, 0.25);
}
@keyframes sa-cue-ripple {
  0% {
    transform: scale(0.95);
    opacity: 0.85;
  }
  70%,
  100% {
    transform: scale(1.45);
    opacity: 0;
  }
}
@keyframes sa-cue-press {
  0%,
  60%,
  100% {
    transform: translate(0, 0) scale(1);
  }
  75% {
    transform: translate(-4px, -5px) scale(0.9);
  }
}
@keyframes sa-cue-wink {
  0%,
  72%,
  100% {
    opacity: 0;
    transform: scale(0.3) rotate(0deg);
  }
  84% {
    opacity: 1;
    transform: scale(1) rotate(45deg);
  }
}

/* the climb meter across the top of the picture */
.sa-meter {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  pointer-events: none;
}
.sa-meter[hidden] {
  display: none;
}
.sa-meter__bar {
  flex: 1;
  height: 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  border: 3px solid var(--ink);
  overflow: hidden;
}
.sa-meter__fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #66bb6a, #ffd54f);
  transition: width 0.5s ease-out;
}
.sa-meter__flag {
  font-size: 1.5rem;
}

/* the GO helper under the words: names the thing to tap (shows if the reader needs a hint) */
.sa-btn--go {
  background: var(--white);
  color: var(--ink);
  border-color: var(--green);
  border-style: dashed;
  justify-content: flex-start;
  animation: sa-go-pop 0.35s ease-out;
}
.sa-btn--go[hidden] {
  display: none;
}
.sa-btn--choice.is-done {
  opacity: 0.55;
}
.sa-btn--choice .sa-btn__done {
  font-size: 1.3em;
}
@keyframes sa-go-pop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
}

/* the moral and the Helper Star on the last page */
.sa-ending__moral {
  margin: 0.4rem 0 0;
  padding: 0.6rem 0.9rem;
  border-radius: 1rem;
  background: #fff8d6;
  color: var(--ink);
  font-weight: 800;
  font-size: clamp(1.1rem, 3.8vw, 1.3rem);
  line-height: 1.3;
}
.sa-ending__moral[hidden],
.sa-ending__star[hidden] {
  display: none;
}
.sa-ending__star {
  margin: 0.5rem 0 0;
  font-weight: 800;
  color: #8d6e00;
}

@media (prefers-reduced-motion: reduce) {
  .sa-cue__ripple,
  .sa-cue__hand,
  .sa-cue--fun::after {
    animation: none !important;
  }
  .sa-cue__ripple {
    display: none;
  }
}
