/* The Explore theater: full-screen scenes built from each book panel. */
html.theater-open { overflow: hidden; }
.theater { position: fixed; inset: 0; z-index: 70; background: #121838; overflow: hidden; color: var(--ink); }
.theater-scenes { position: absolute; inset: 0; }

/* ---------- scene transitions ---------- */
.scene { position: absolute; inset: 0; opacity: 0; transition: opacity 0.6s ease, transform 0.65s cubic-bezier(0.22, 0.9, 0.3, 1); }
.scene.from-right { transform: translateX(5%); }
.scene.from-left { transform: translateX(-5%); }
.scene.in { opacity: 1; transform: none; }
.scene.out-left { opacity: 0; transform: translateX(-5%) scale(0.98); }
.scene.out-right { opacity: 0; transform: translateX(5%) scale(0.98); }

/* ---------- stage ---------- */
.scene-stage { position: absolute; inset: 0; overflow: hidden; }
.scene-art {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; user-select: none;
  animation: scene-drift 26s ease-in-out infinite alternate;
}
/* the end scale must overflow each edge by more than the (scaled) translate, or a dark strip shows at the left edge */
@keyframes scene-drift { from { transform: scale(1.08) translate(-1%, 0.5%); } to { transform: scale(1.03) translate(1%, -0.5%); } }
.scene[data-theme='night'] .scene-art, .scene[data-theme='dawn'] .scene-art { filter: saturate(1.05); }
.scene-ambient { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.scene-cast { position: absolute; inset: 0; pointer-events: none; }
.scene-layer { position: absolute; inset: 0; pointer-events: none; }
.scene-layer > * { pointer-events: auto; }

/* ---------- cast ---------- */
.cast { position: absolute; translate: -50% 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; width: max-content; }
.cast-body { height: 100%; }
.cast-img { height: 100%; width: auto; max-width: none; display: block; user-select: none; filter: drop-shadow(0 14px 12px rgba(0, 0, 0, 0.28)); transition: opacity 0.16s; transform-origin: 50% 100%; }
.cast-img.flip { scale: -1 1; }
.cast-img.swap { opacity: 0; }
.idle-bob { animation: cast-bob 3.8s ease-in-out infinite; }
.idle-sway { animation: cast-sway 5s ease-in-out infinite; }
.idle-breathe { animation: cast-breathe 4.2s ease-in-out infinite; }
/* idles stay gentle: characters breathe in the scene, big motion is saved for moves and demos */
@keyframes cast-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes cast-sway { 0%, 100% { transform: rotate(-0.8deg); } 50% { transform: rotate(0.8deg); } }
@keyframes cast-breathe { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(1.012); } }
.enter-pop { animation: cast-pop 0.7s var(--ease-pop) both; }
.enter-slide-left { animation: cast-slide-l 0.9s cubic-bezier(0.22, 0.9, 0.3, 1) both; }
.enter-slide-right { animation: cast-slide-r 0.9s cubic-bezier(0.22, 0.9, 0.3, 1) both; }
.enter-rise { animation: cast-rise 0.9s var(--ease-pop) both; }
.enter-fade { animation: cast-fade 0.9s ease both; }
.enter-hop { animation: cast-hop 0.9s var(--ease-pop) both; }
@keyframes cast-pop { from { opacity: 0; transform: scale(0.4); } to { opacity: 1; transform: none; } }
@keyframes cast-slide-l { from { opacity: 0; transform: translateX(-140px); } to { opacity: 1; transform: none; } }
@keyframes cast-slide-r { from { opacity: 0; transform: translateX(140px); } to { opacity: 1; transform: none; } }
@keyframes cast-rise { from { opacity: 0; transform: translateY(80px); } to { opacity: 1; transform: none; } }
@keyframes cast-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes cast-hop { 0% { opacity: 0; transform: translateY(-90px); } 60% { opacity: 1; transform: translateY(10px); } 100% { transform: none; } }
.cast-bubble {
  position: absolute; bottom: 92%; left: 50%; translate: -20% 0; width: max-content; max-width: min(260px, 60vw); z-index: 2;
  background: var(--paper); color: var(--ink); border-radius: 18px; padding: 8px 14px; font-family: var(--font-hand); font-size: 1.2rem; line-height: 1.25;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}
.cast.bubble-left .cast-bubble { translate: -80% 0; }
.cast-bubble.show { animation: pop-in 0.35s var(--ease-pop); }
/* bubbles stay click-through (scene controls under them keep working); only the small
   🔊 button on a bubble's corner (or beside a cast-less quote) takes a tap */
.bubble-hear {
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; flex: 0 0 auto;
  display: inline-grid; place-items: center; font-size: 15px; line-height: 1; cursor: pointer;
  background: var(--gold-hi, #ffd76a); color: var(--navy); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
  pointer-events: auto; -webkit-tap-highlight-color: transparent;
}
.cast-bubble .bubble-hear { position: absolute; top: -18px; right: -22px; }
.bubble-hear:active { scale: 0.92; }
.bubble-hear:focus-visible { outline: 3px solid var(--navy, #1d2556); outline-offset: 2px; }
.scene-quote { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------- narration card ---------- */
.scene-card {
  position: absolute; z-index: 5; bottom: 24px; width: min(440px, 36vw); max-height: calc(100% - 110px); overflow-y: auto;
  background: rgba(255, 250, 242, 0.95); backdrop-filter: blur(8px); border-radius: 26px; padding: 20px 22px;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.3); animation: rise-in 0.7s 0.15s var(--ease-pop) both;
}
.scene[data-card='right'] .scene-card { right: 24px; }
.scene[data-card='left'] .scene-card { left: 24px; }
.scene-step { font-family: var(--font-title); font-weight: 600; font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold); }
.scene-title { font-size: clamp(1.35rem, 2.3vw, 1.9rem); margin: 2px 0 6px; outline: none; }
.scene-text { font-size: clamp(1.08rem, 1.45vw, 1.28rem); line-height: 1.5; margin-bottom: 6px; }
.scene-quote { font-family: var(--font-hand); font-size: 1.2rem; background: #eef0ff; border-radius: 14px; padding: 6px 12px; margin: 6px 0; }
.scene-hint { font-family: var(--font-hand); font-size: 1.25rem; color: #3f6b2a; margin: 6px 0 0; animation: rise-in 0.4s var(--ease-pop); }
.scene-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; }
.scene-next.ready { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2), 0 0 0 5px rgba(244, 198, 82, 0.85); }
.scene-next.cheer { animation: next-wiggle 0.9s ease-in-out 1, next-glow 1.6s ease-in-out 2; }
@keyframes next-wiggle { 0%, 100% { rotate: 0deg; scale: 1; } 20% { rotate: -6deg; scale: 1.12; } 40% { rotate: 5deg; scale: 1.12; } 60% { rotate: -3deg; scale: 1.06; } 80% { rotate: 2deg; } }
@keyframes next-glow { 0%, 100% { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2), 0 0 0 0 rgba(244, 198, 82, 0.75); } 50% { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2), 0 0 0 12px rgba(244, 198, 82, 0); } }

/* ---------- top bar ---------- */
.theater-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: linear-gradient(rgba(10, 14, 36, 0.55), rgba(10, 14, 36, 0));
}
.tbtn {
  border: 0; border-radius: 999px; background: rgba(255, 250, 242, 0.92); color: var(--navy); height: 40px; min-width: 40px; padding: 0 12px;
  font-family: var(--font-title); font-weight: 600; font-size: 1rem; cursor: pointer; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
  display: inline-flex; align-items: center; justify-content: center;
}
.tbtn[aria-pressed='true'] { background: var(--gold-hi); }
.theater-title { display: flex; flex-direction: column; color: #fff; font-family: var(--font-title); font-weight: 600; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); line-height: 1.15; min-width: 0; }
.theater-title small { font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.85; }
.theater-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32vw; }
.theater-dots { display: flex; gap: 11px; margin: 0 auto; }
.tdot { position: relative; width: 13px; height: 13px; padding: 0; border-radius: 50%; border: 2px solid #fff; background: rgba(255, 255, 255, 0.15); cursor: pointer; transition: transform 0.25s var(--ease-pop), background 0.25s; }
/* a 25px tap target around each 13px dot (fingers on phones) */
.tdot::after { content: ''; position: absolute; inset: -8px; border-radius: 50%; }
.tdot[aria-current='step'] { background: #fff; transform: scale(1.3); }
/* visited but not finished: a gold ring; finished: filled gold */
.tdot.seen { border-color: var(--gold-hi); }
.tdot.done { background: var(--gold-hi); border-color: var(--gold-hi); }
.theater-tools { display: flex; gap: 8px; }
.tspark { position: fixed; z-index: 90; color: var(--gold-hi); font-size: 18px; pointer-events: none; animation: tspark 0.9s ease-out forwards; }
@keyframes tspark { to { transform: translate(var(--dx), var(--dy)) scale(0.4); opacity: 0; } }

/* ---------- book map overlay ---------- */
.bookmap { position: fixed; inset: 0; z-index: 95; background: rgba(18, 24, 56, 0.62); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 16px; animation: cast-fade 0.25s ease; }
.bookmap-card { position: relative; width: min(760px, 100%); max-height: calc(100vh - 32px); background: var(--paper); border-radius: 26px; padding: 16px; display: grid; gap: 10px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45); animation: dialog-in 0.35s var(--ease-pop); }
.bookmap-head { display: flex; align-items: center; justify-content: space-between; padding-right: 34px; font-family: var(--font-title); color: var(--navy); }
.bookmap-head span { font-family: var(--font-hand); font-size: 1.15rem; color: var(--ink-soft); }
.bookmap-viewer { height: min(62vh, 620px); }
.bookmap-label { margin: 0; text-align: center; font-family: var(--font-hand); font-size: 1.2rem; }
.bookmap-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- explore launch card (lesson page) ---------- */
.explore-launch { position: relative; border-radius: 30px; overflow: hidden; min-height: min(70vh, 620px); display: grid; align-items: end; box-shadow: var(--shadow); background: #2b2f6b; }
.explore-launch > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; animation: scene-drift 26s ease-in-out infinite alternate; }
.explore-launch-card { position: relative; margin: 22px; max-width: 520px; background: rgba(255, 250, 242, 0.95); border-radius: 24px; padding: 22px; box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3); }
.explore-launch-card h2 { margin-bottom: 4px; }
.explore-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 16px; }
.explore-chips span { font-family: var(--font-hand); font-size: 1.05rem; background: #efe5d2; border-radius: 999px; padding: 3px 10px; }
.explore-chips span.done { background: var(--sticky); }

/* ---------- phones: art on top, card as a bottom sheet ---------- */
@media (max-width: 760px) {
  .scene { display: flex; flex-direction: column; }
  .scene-stage { position: relative; inset: auto; flex: 1 1 auto; }
  .scene-card, .scene[data-card='right'] .scene-card, .scene[data-card='left'] .scene-card {
    position: relative; inset: auto; width: auto; max-height: 46%; flex: 0 0 auto; border-radius: 22px 22px 0 0; padding: 14px 16px 16px;
  }
  .scene-text { font-size: 1.05rem; }
  .theater-title { display: none; }
  .tbtn-label { display: none; }
  .cast-bubble { font-size: 1.05rem; max-width: 52vw; }
  /* the hint keeps its line in the bottom sheet so the stage never resizes (and jumps) when it comes and goes */
  .scene-card .scene-hint, .scene-card .scene-hint[hidden] { display: block !important; min-height: 1.6em; }
  .scene-card .scene-hint[hidden] { visibility: hidden; animation: none; }
}

@media (prefers-reduced-motion: reduce) {
  .scene-art, .explore-launch > img { animation: none; }
}

/* narration animates on, word by word, as the scene arrives */
.scene-text .w { display: inline-block; opacity: 0; transform: translateY(6px); }
.scene.in .scene-text .w { animation: word-on 0.5s ease-out forwards; animation-delay: calc(0.55s + var(--i) * 32ms); }
@keyframes word-on { to { opacity: 1; transform: none; } }
/* keyboard focus: the site's gold ring alone is faint on the cream card and on bright art,
   so theater/book-map controls get a navy ring with a gold halo (visible on light and dark) */
.theater :focus-visible:not(.scene-title), .bookmap :focus-visible {
  outline: 3px solid var(--navy, #1d2556); outline-offset: 2px; box-shadow: 0 0 0 6px var(--gold-hi, #ffd76a);
}
.tbtn.tmap { opacity: 0.75; }
.tbtn.tmap:hover, .tbtn.tmap:focus-visible { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .scene-text .w { opacity: 1; transform: none; animation: none !important; } }
/* .calm is set by the engine from the same reducedMotion() check its JS uses, so the CSS
   motion (drift, idles, entrances, word reveal, glow) and the JS motion always agree */
.theater.calm .scene-art, .theater.calm .cast, .theater.calm .cast-img, .theater.calm .cast-bubble,
.theater.calm .scene-card, .theater.calm .scene-hint, .theater.calm .scene-next.ready { animation: none !important; }
.theater.calm .scene, .theater.calm .tdot, .theater.calm .cast-img { transition: none !important; }
.theater.calm .scene-text .w { opacity: 1; transform: none; animation: none !important; }

/* bigger Next, so the way forward is obvious */
.scene-next { min-height: 52px; padding-inline: 26px; font-size: 1.15rem; }
.scene-nav { position: relative; }
.scene-nice { position: absolute; right: 8px; bottom: calc(100% + 4px); font-family: var(--font-hand); font-size: 1.2rem; color: #3f6b2a; animation: rise-in 0.4s var(--ease-pop); pointer-events: none; }

/* speech bubbles live in their own layer above the scene, pinned to the speaker by the engine */
.scene-bubbles { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.scene-bubbles .cast-bubble { bottom: auto; translate: -20% -100%; }
.scene-bubbles .cast-bubble.left { translate: -80% -100%; }

/* narration reveals quickly (well inside the time it takes to say it), never lagging the voice */
.scene.in .scene-text .w { animation-duration: 0.35s; animation-delay: calc(0.3s + min(var(--i) * 18ms, 0.9s)); }

/* phones: characters never shrink below a readable size */
@media (max-width: 760px) {
  .cast[data-who='kid'] { min-height: 34%; }
  .cast[data-who='robot'] { min-height: 22%; }
  .cast[data-who='grownup'], .cast[data-who='friend'] { min-height: 32%; }
  .cast[data-sprite='kid-laptop'], .cast[data-sprite='kid-read'], .cast[data-sprite='friend-build'], .cast[data-sprite='grownup-point'] { min-height: 24%; }
}

/* the "your turn" line reads as an instruction, not a caption */
.scene-hint:not(:empty)::before { content: '👉 '; }
.scene-hint { font-size: 1.3rem; color: #2f5a1e; background: #eef6df; border-radius: 12px; padding: 4px 10px; display: inline-block; }
.scene-hint:empty { display: none; }

/* book page loading */
.bookmap .page.loading img { filter: blur(2px); }
.bookmap .page .page-spinner { display: none; }
.bookmap .page.loading .page-spinner { display: block; position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border: 5px solid rgba(29, 37, 86, 0.2); border-top-color: var(--gold, #d39a1e); border-radius: 50%; animation: ug-spin 0.9s linear infinite; }
@keyframes ug-spin { to { rotate: 360deg; } }

/* Next is always tappable, but it only turns gold and glowing once the scene is done (api.done),
   so "finished" looks clearly different from "not yet" */
.scene-next:not(.ready) { background: #fffaf0; color: var(--navy, #1d2556); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12); outline: 2px solid #e8c56a; outline-offset: -2px; }
.scene-next:not(.ready):hover { background: #fff3cf; }
/* the finish cue sits in the nav row beside the button it names, never over the hint or the narration */
.scene-nav .scene-nice { position: static; margin-left: auto; align-self: center; white-space: nowrap; line-height: 1.1; }
/* a cleared hint keeps its space (see api.hint), so nothing jumps */
.scene-hint.parked { visibility: hidden; animation: none; }
@media (max-width: 760px) {
  .scene-card .scene-hint, .scene-card .scene-hint[hidden] { min-height: 2.15em; box-sizing: border-box; }
  .scene-nav .scene-nice { font-size: 1.05rem; }
}
/* bubbles sit above the cast and the scene's own props (lesson kits lift speakers to z 4; the
   later layer wins the tie), and point at their speaker */
.scene-bubbles { z-index: 4; }
.scene-bubbles .cast-bubble:not([data-mtail]):not([data-wl-tail])::after {
  content: ''; position: absolute; top: calc(100% - 1px); left: 20%; translate: -50% 0; pointer-events: none;
  border: 9px solid transparent; border-top: 11px solid var(--paper); border-bottom: 0;
}
.scene-bubbles .cast-bubble.left:not([data-mtail]):not([data-wl-tail])::after { left: 80%; }
/* phones: the finish wiggle grows from the button's right edge inward, so it never touches the screen edge */
@media (max-width: 760px) {
  .scene-next { transform-origin: 85% 50%; }
  .scene-nav { padding-right: 4px; }
}
