1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/NativeFullscreenWeb-DELoe6kh.js","assets/index-Bhvx0-ct.js","assets/vendor-data-BwcWGEsa.js","assets/rolldown-runtime-M0oDzQ_3.js","assets/defineProperty-CkKLuKw5.js","assets/vendor-react-BK73EwAN.js","assets/createLucideIcon-BBBB7OBy.js","assets/arrow-left-B_Ixnu3o.js","assets/bell-C8bIKvRf.js","assets/book-open-PWQIawMS.js","assets/clock-DTQt8uc9.js","assets/refresh-cw-dz9G8Tu5.js","assets/settings-oQoyF2GI.js","assets/sparkles-B_ubz5O3.js","assets/triangle-alert-n-SskdNm.js","assets/trophy-Bwd7Gm_w.js","assets/supabase-C5lAo7mf.js","assets/Popover-BQ-5hxwj.js","assets/utils-Dxo0lxcD.js","assets/bundle-mjs-DRfmn-Pm.js","assets/AuthContext-DecS5GCe.js","assets/adminMode-CWVc3RLz.js","assets/isPaidStatus-YyvLKkHl.js","assets/AnalyticsService-CIS6thDy.js","assets/platform-D00atzh8.js","assets/useNotifications-60UOvS2I.js","assets/ProviderAvailabilityService-DfGx2tY0.js","assets/SecureContentService-NR9DsHsx.js","assets/contentUrls-DB4ooyH1.js","assets/legalHold-C_9EGpge.js","assets/routes-oA-ZsG_Z.js","assets/scrollIdeaSelection-DA_PJ2O5.js","assets/index-BKtUt3kZ.css","assets/DynamicIslandWeb-kFvSrxCT.js","assets/GlobalSearchModal-sImSI1nB.js","assets/file-text-CwSYTkZv.js","assets/route-Bo3Ce4DW.js","assets/ui-DMgQNDEI.js","assets/EmptyState-BDmnM8Uq.js","assets/proxy-B16EueI6.js","assets/use-reduced-motion-DTS5NUB0.js","assets/loader-circle-CdxwvVl2.js","assets/Card-j2WymbDT.js","assets/Chip-M54y8j2g.js","assets/Dialog-D30fkc27.js","assets/x-cBmH4UyD.js","assets/Skeleton-CdI1Cp3H.js","assets/SearchService-CkAd75rL.js","assets/ideaContext-C78ky_Dl.js","assets/ConceptService-DZf0FlMp.js","assets/BookChatPanel-CzyypN4s.js","assets/ChatUpgradeCard-gKE-_Cyr.js","assets/lib-DBGBammb.js","assets/lib-DHdYLOhi.js","assets/AnimatePresence-D119C_uX.js","assets/arrow-right-cqcrLAgG.js","assets/check-BO0RcrH5.js","assets/circle-check-big-uf5VIAIA.js","assets/circle-DI6nfsq4.js","assets/external-link-CJfwKTEY.js","assets/lock-B4mfAUEC.js","assets/quote-DRqlUYC5.js","assets/skip-forward-Bv9JAPLj.js","assets/tag-BVobHy7f.js","assets/bookBuddyContext-QBioSl4d.js","assets/useChatMemories-BDR-Nd9W.js","assets/brain-Dhuvxm-r.js","assets/chevron-down-Bi5BlOmC.js","assets/chevron-right-CejzDIR0.js","assets/clipboard-list-BJs6ERe0.js","assets/trash-2-B5cSdbqi.js","assets/ActionItemsPanel-C4s62Mps.js","assets/circle-check-DpATGgU0.js","assets/ChapterQuizModal-sqvcLFlN.js","assets/circle-x-BWv_pDsq.js","assets/star-DNxba_je.js","assets/ChapterRecallBeat-B4HBpMwU.js","assets/eye-p4K02Njq.js","assets/rotate-ccw-DuSNkFOM.js","assets/ActorFlashcardModal-BkjLMoX-.js","assets/circle-alert-CBdHC6QX.js","assets/layers-Crk8r4zl.js","assets/useFlashcardSwipe-CNKSAUdC.js","assets/use-gesture-react.esm-Bj7A8nza.js","assets/ChapterCompleteSheet-BJP8oeu4.js","assets/bookmark-nDmOc7qL.js","assets/SaveIdeasSheet-DuBQUZ6o.js","assets/useHighlights-DFf01aj5.js","assets/HighlightsService-DkwHxxoq.js","assets/IdeaPlayground-DbMueYhU.js","assets/target-BvJKye09.js","assets/RelatedBooks-BngA6NXy.js","assets/link-2-zgy-kZIQ.js","assets/CompactBookCard-YhGEzXZq.js","assets/AddToCollectionButton-lto0Vy8P.js","assets/folder-BD2qdBUR.js","assets/heart-BNwO2fIy.js","assets/plus-DkAbSNHZ.js","assets/useCollections-B8kMa6su.js","assets/CollectionService-D2qugMHz.js","assets/useFavorites-C7B2hVOR.js","assets/InAppReviewService-DapwnoBN.js","assets/FreeBadge-DugLOzjd.js","assets/ConceptStateService-NuyDAEFd.js","assets/ActorHome-Jn0ID93D.js","assets/eye-off-BYXnwIhL.js","assets/pencil-Ckv7Qm9j.js","assets/pin-BrLPLup8.js","assets/StoryBeatsRenderer-CDzIMu-G.js","assets/vendor-gsap-CzPqb2ME.js","assets/AnimatedGradientText-adhhrYHQ.js","assets/useSecureContent-Cbl2YDZw.js","assets/gsap-Bnbg_Pj9.js","assets/ImmersiveAudioBar-B71jIa0J.js","assets/chevron-left-D_4mGLus.js","assets/list-D2Zgr-Hf.js","assets/minimize-2-BVshIq6N.js","assets/pause-C8aATl06.js","assets/play-C1rzHH5w.js","assets/repeat-Y2lfIIos.js","assets/rotate-cw-BBOYzo9U.js","assets/ChapterNavButton-DjBUOPOQ.js","assets/skip-back-JOiltEXG.js","assets/ReadingTranscript-DU4vECGY.js","assets/message-circle-Dm-wCD4h.js","assets/KaraokeTranscript-BhXiJODB.js","assets/useBookSequenceNavigation-BBTmSoSL.js","assets/ideaFabricCapability-B4wXgagy.js","assets/ScrollFlashcardService-DlhqJQpN.js","assets/narrativeSequence-CjsVtaFo.js","assets/UserProgressService-0GiYQbB3.js","assets/pressedPrint-x1XGuNl0.css","assets/storyBeatsSummary-3XM5kbp-.js","assets/zLayers-EPz7nUD0.js","assets/CapacitorService-C0-1L8yK.js","assets/esm-Ba72VcyY.js","assets/esm-COsXcn5P.js"])))=>i.map(i=>d[i]); 2import{a as gi}from"./rolldown-runtime-M0oDzQ_3.js";import{_ as uc,c as Ze,h as vi,m as hc,v as mc,x as fc,y as fe}from"./vendor-react-BK73EwAN.js";import{O as pc,i as xc,k as bc}from"./vendor-data-BwcWGEsa.js";import{t as S}from"./proxy-B16EueI6.js";import{t as J}from"./AnimatePresence-D119C_uX.js";import{t as yi}from"./use-reduced-motion-DTS5NUB0.js";import{t as cs}from"./supabase-C5lAo7mf.js";import{c as Ds,s as $,t as I}from"./AnalyticsService-CIS6thDy.js";import{n as ki}from"./AuthContext-DecS5GCe.js";import{i as gc,l as q,n as wi,o as rt,t as vc}from"./platform-D00atzh8.js";import{p as fn}from"./useNotifications-60UOvS2I.js";import{r as yc}from"./SecureContentService-NR9DsHsx.js";import{t as W}from"./utils-Dxo0lxcD.js";import{t as ji}from"./createLucideIcon-BBBB7OBy.js";import{t as qo}from"./arrow-left-B_Ixnu3o.js";import{t as Ur}from"./book-open-PWQIawMS.js";import{t as Ni}from"./bookmark-nDmOc7qL.js";import{t as kc}from"./brain-Dhuvxm-r.js";import{t as pn}from"./check-BO0RcrH5.js";import{t as Vo}from"./chevron-down-Bi5BlOmC.js";import{t as an}from"./chevron-left-D_4mGLus.js";import{t as ft}from"./chevron-right-CejzDIR0.js";import{t as wc}from"./clock-DTQt8uc9.js";import{t as jc}from"./crown-DtnpovBO.js";import{a as Nc,c as Sc,d as Cc,f as Tc,i as _c,l as Ec,o as Rc,p as Yo,s as Ic,t as Ac,u as Pc}from"./useBookSequenceNavigation-BBTmSoSL.js";import{t as Lc}from"./eye-off-BYXnwIhL.js";import{t as Fc}from"./eye-p4K02Njq.js";import{t as $c}from"./file-text-CwSYTkZv.js";import{t as Mc}from"./flame-BvIua86V.js";import"./AddToCollectionButton-lto0Vy8P.js";import{t as Oc}from"./grid-3x3-CcCaQgVf.js";import{t as Bc}from"./heart-BNwO2fIy.js";import{t as Dc}from"./lock-B4mfAUEC.js";import{n as zr,t as Si}from"./minimize-2-BVshIq6N.js";import{t as nn}from"./message-circle-Dm-wCD4h.js";import{t as on}from"./pause-C8aATl06.js";import{t as Vs}from"./play-C1rzHH5w.js";import{t as Ko}from"./refresh-cw-dz9G8Tu5.js";import{t as Ci}from"./repeat-Y2lfIIos.js";import{t as Ti}from"./rotate-ccw-DuSNkFOM.js";import{t as ln}from"./rotate-cw-BBOYzo9U.js";import{t as Uc}from"./share-2-BZ2bb9ih.js";import{t as _i}from"./skip-back-JOiltEXG.js";import{t as Ei}from"./skip-forward-Bv9JAPLj.js";import{t as zc}from"./smartphone-JQUi7LsG.js";import{t as Wr}from"./sparkles-B_ubz5O3.js";import{t as Ri}from"./star-DNxba_je.js";import{t as ns}from"./triangle-alert-n-SskdNm.js";import{t as Hr}from"./x-cBmH4UyD.js";import{a as os}from"./routes-oA-ZsG_Z.js";import{$t as Go,At as Hc,D as Lr,E as Ja,Et as Wc,Kt as qc,O as xn,Ot as Vc,P as Ii,Q as Yc,Qt as Kc,Vt as Gc,W as Ai,X as Dr,Xt as Xc,Yt as Qc,Zt as Us,b as Xo,h as Jc,i as Fr,j as Zc,o as ed,qt as td,rt as St,s as sd,sn as rd,tn as Pi,v as Za}from"./index-Bhvx0-ct.js";import{n as ad,t as qr}from"./Dialog-D30fkc27.js";import{n as Ct,t as nd}from"./zLayers-EPz7nUD0.js";import{t as Qo}from"./ConceptService-DZf0FlMp.js";import{t as $r}from"./Skeleton-CdI1Cp3H.js";import"./ui-DMgQNDEI.js";import{t as Jo}from"./ChapterNavButton-DjBUOPOQ.js";import{a as od,n as id,r as ld,t as cd}from"./storyBeatsSummary-3XM5kbp-.js";import{r as Zo,t as dd}from"./useSecureContent-Cbl2YDZw.js";import{t as ud}from"./KeyboardShortcutsModal-BvhXhjAm.js";import{t as ei}from"./SleepTimer-Cct9rvHH.js";import{i as hd}from"./shareContent-Csb_p5ga.js";import{ShareBottomSheet as md}from"./ShareBottomSheet-BPJIQPT-.js";import{n as fd,t as Li}from"./use-gesture-react.esm-Bj7A8nza.js";import{n as pd,t as xd}from"./useRecordIdeaReview-CaFF7s7v.js";import{t as ti}from"./betaEvents-ChqBgO9a.js";import{t as cn}from"./BetaFeedbackService-YrQNRtDF.js";import{t as si}from"./CollectionService-D2qugMHz.js";import{n as bd}from"./useRecommendations-25kjuWOg.js";import"./useCollections-B8kMa6su.js";import{t as gd}from"./InAppReviewService-DapwnoBN.js";import{t as vd}from"./ConceptStateService-NuyDAEFd.js";import{s as yd}from"./useGamification-CartC8PM.js";import{t as kd}from"./ChapterList-Di9LjXEn.js";import{t as zs}from"./UserProgressService-0GiYQbB3.js";import{r as wd}from"./authReturnTo-Ba78PTWI.js";import{a as jd}from"./useDashboard-BMIDyx2T.js";import{l as Nd}from"./useJourneys-c_RH0DM6.js";import{t as Sd}from"./usePageMeta-tgH-_p5u.js";import{n as Cd,t as Td}from"./productFacts-BUUBgHG8.js";import{n as Hs,r as _d,t as Mr}from"./paywallGate-CRnhraAx.js";import{a as Ed,c as ri,d as mt,f as Rd,m as Id,s as Ad,t as Pd,u as ai}from"./useEntitlements-Bp9ns7Mc.js";import{n as Ld,t as Fd}from"./useGlobalAudioEnded-Ca38Za4p.js";import{t as Or}from"./ideaFabricCapability-B4wXgagy.js";import{r as Ut}from"./LoopsService-CH-FT-po.js";import{t as $d}from"./useReadingSessionSave-E3ZwWtfv.js";import{i as Fi,n as $i,r as Mi,t as ni}from"./FeedbackButton-DP2EqION.js";import"./ShareButton-DcMigTMv.js";import{t as is}from"./useMediaQuery-BWQf3C4r.js";import{t as Md}
2from"./useUnifiedScrollReaderEnabled-Bv7YL1TX.js";import{n as Od}from"./WidgetDataService-Bcm43IPj.js";import"./BookmarkButton-XJYYBmIh.js";import{a as Bd,i as Dd,n as Ud,r as zd,t as Hd}from"./paywallModel-Cedx6Uym.js";var Wd=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]],dn=ji("layout-grid",Wd),qd=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M7 11h10",key:"1twpyw"}],["path",{d:"M7 15h6",key:"d9of3u"}],["path",{d:"M7 7h8",key:"af5zfr"}]],Vd=ji("message-square-text",qd),s=gi(bc(),1);function Yd(){const a=(0,s.useRef)(0),r=(0,s.useCallback)(o=>{const h=Date.now();h-a.current<2e3||(a.current=h,fe(async()=>{const{default:l}=await import("./confetti.module-Dg2uj2df.js");return{default:l}},[]).then(({default:l})=>{switch(o.type){case"chapter_complete":l({particleCount:50,spread:60,origin:{y:.9},colors:["#8B5CF6","#A78BFA","#C4B5FD"],disableForReducedMotion:!0});break;case"book_complete":{const m=Date.now()+2e3,f=()=>{l({particleCount:3,angle:60,spread:55,origin:{x:0},colors:["#8B5CF6","#F59E0B","#10B981"],disableForReducedMotion:!0}),l({particleCount:3,angle:120,spread:55,origin:{x:1},colors:["#8B5CF6","#F59E0B","#10B981"],disableForReducedMotion:!0}),Date.now()<m&&requestAnimationFrame(f)};f();break}case"milestone":l({particleCount:100,spread:70,origin:{y:.6},shapes:["star"],colors:["#FFD700","#FFA500","#FF6347"],disableForReducedMotion:!0});break}}))},[]);return{celebrate:r,celebrateChapterComplete:(0,s.useCallback)(()=>{r({type:"chapter_complete"})},[r]),celebrateBookComplete:(0,s.useCallback)(()=>{r({type:"book_complete"})},[r]),celebrateMilestone:(0,s.useCallback)(()=>{r({type:"milestone"})},[r])}}function Kd(a,r={}){const{threshold:o=50,maxVerticalMovement:h=100}=r,l=Li(({movement:[m,f],direction:[c],velocity:[b],last:p})=>{if(!p)return;const C=Math.abs(m),v=Math.abs(f);C<o&&b<.3||v>h||(c<0?a.onSwipeLeft?.():c>0&&a.onSwipeRight?.())},{axis:"lock",filterTaps:!0,threshold:10})();return{onTouchStart:(0,s.useCallback)(m=>{l.onPointerDown?.(m.nativeEvent)},[l]),onTouchMove:(0,s.useCallback)(m=>{},[]),onTouchEnd:(0,s.useCallback)(m=>{},[])}}function Gd({onDoubleTapLeft:a,onDoubleTapRight:r,onDoubleTapCenter:o,timeout:h=300}){const l=(0,s.useRef)({lastTap:0,lastPosition:null}),m=(0,s.useCallback)((f,c)=>{const b=c/3;return f<b?"left":f>b*2?"right":"center"},[]);return{onTouchEnd:(0,s.useCallback)(f=>{const c=Date.now(),b=f.changedTouches[0],p=f.currentTarget.getBoundingClientRect(),C=m(b.clientX-p.left,p.width),v=c-l.current.lastTap,k=l.current.lastPosition===C;if(v<h&&k){switch(q("medium"),C){case"left":a?.();break;case"right":r?.();break;case"center":o?.();break}l.current={lastTap:0,lastPosition:null}}else l.current={lastTap:c,lastPosition:C}},[h,m,a,r,o])}}var Xd=[/atomic-habits\/infographics\/01-the-surprising-power-of-atomic-habits-infographic\.png/i];function en(a){if(!a)return!1;const r=a.split("?")[0]??a;return Xd.some(o=>o.test(r))}function Qd(a,r){const o=a?.infographicPath;return o&&!o.startsWith("http")?o:null}function Jd(a,r){return r??a?.infographicUrl??null}function Zd(a,r,o){return o?en(r)||en(a?.infographicUrl)||en(a?.infographicPath):!1}function eu(a,r,o){return a&&r&&o===a?r:a??null}function tu(a,r,o){const h=a??null;return{imageLoaded:!!h&&r===h,imageError:!!h&&o===h}}function su(a,r,o,h){return(0,s.useMemo)(()=>{if(!a?.storyBeats)return{data:null,hasStoryBeats:!1};const l=id(a.storyBeats,{domainColor:r?.color,domain:r?.name,author:h,title:a.title,chapterNumber:a.orderIndex});return!l.data||!l.hasRenderableSections?{data:null,hasStoryBeats:!1}:{data:l.data,hasStoryBeats:!0}},[a?.storyBeats,r?.color,r?.name,o,h,a?.title,a?.orderIndex])}var oi=1200,ru=1.5;function au({sections:a,audioDuration:r,audioProgress:o,isPlaying:h,enabled:l=!0,scrollContainer:m}){const f=(0,s.useRef)(new Map),c=(0,s.useRef)(-1),[b,p]=(0,s.use
2State)(!1),C=(0,s.useRef)(null),v=(0,s.useRef)(!1),k=(0,s.useMemo)(()=>{if(a.length===0||r<=0)return[];const _=a.map(A=>A.startTime);if(_.every((A,K)=>Number.isFinite(A)&&(A??0)>=0&&(K===0||(A??0)>=(_[K-1]??0)))){const A=a.map((K,Ee)=>{const be=Math.min(r,Math.max(0,K.startTime??0)),R=a[Ee+1]?.startTime;return{start:be,end:Number.isFinite(R)?Math.min(r,Math.max(be,R??r)):r}});return A.length>0&&(A[0].start=0,A[A.length-1].end=r),A}const V=a.reduce((A,K)=>A+(K.duration??0),0),E=[];let te=0;if(V>0){const A=r/V;for(const K of a){const Ee=(K.duration??0)*A;E.push({start:te,end:te+Ee}),te+=Ee}}else{const A=r/a.length;for(let K=0;K<a.length;K++)E.push({start:K*A,end:(K+1)*A})}return E.length>0&&(E[E.length-1].end=r),E},[a,r]),L=(0,s.useMemo)(()=>{if(!l||k.length===0)return 0;for(let _=k.length-1;_>=0;_--)if(o>=(_===0?0:Math.max(0,k[_].start-ru)))return _;return 0},[l,k,o]),D=a[L]?.id||"",re=(0,s.useMemo)(()=>{if(!l||k.length===0)return 0;const _=k[L];if(!_)return 0;const V=_.end-_.start;return V<=0?0:Math.min(1,Math.max(0,(o-_.start)/V))},[l,k,o,L]);return(0,s.useEffect)(()=>{const _=m,V=_||window,E=()=>{v.current||(C.current&&clearTimeout(C.current),p(!0))},te=()=>{C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{p(!1)},oi)},A=()=>{v.current||(p(!0),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{p(!1)},oi))};return V.addEventListener("pointerdown",E,{passive:!0}),V.addEventListener("pointerup",te,{passive:!0}),V.addEventListener("pointercancel",te,{passive:!0}),V.addEventListener("wheel",A,{passive:!0}),_||(V.addEventListener("touchstart",E,{passive:!0}),V.addEventListener("touchend",te,{passive:!0})),()=>{V.removeEventListener("pointerdown",E),V.removeEventListener("pointerup",te),V.removeEventListener("pointercancel",te),V.removeEventListener("wheel",A),_||(V.removeEventListener("touchstart",E),V.removeEventListener("touchend",te)),C.current&&clearTimeout(C.current)}},[m]),(0,s.useEffect)(()=>{if(!l||!h||b)return;const _=f.current.get(D);_&&L!==c.current&&(c.current=L,v.current=!0,_.scrollIntoView({behavior:"smooth",block:"start"}),setTimeout(()=>{v.current=!1},600))},[l,h,b,D,L]),(0,s.useEffect)(()=>{!b&&h&&l&&(c.current=-1)},[b,h,l]),{activeSectionIndex:L,activeSectionId:D,sectionRefs:f,isUserScrolling:b,sectionProgress:re}}function bn(a){return typeof a!="string"?"":a.replace(/\s+/g," ").trim()}function ls(a,r=220){const o=bn(a);if(o.length<=r)return o;const h=o.split(/(?<=[.!?])\s+/).find(l=>l.length>=24&&l.length<=r);return h||`${o.slice(0,r-1).trim()}...`}function nu(a,r){const o=ls(a,64);return!o||["section","summary","core idea","takeaway"].includes(o.toLowerCase())?r:o}function tn(a){const r=new Set,o=[];for(const h of a){const l=bn(h.answer??h.text).toLowerCase();!l||r.has(l)||(r.add(l),o.push(h))}return o}function ou(a,r){const o=ls(a.text,240);if(!o)return null;const h=nu(a.label,`Idea ${r+1}`);return{id:a.sectionId||`story-beat-${r}`,label:h,prompt:`Explain ${h} from memory.`,answer:o,audioSectionIndex:a.audioSectionIndex}}function iu(a,r={}){const o=bn(r.chapterTitle??a?.title)||"Current chapter",h=typeof r.chapterNumber=="number"?r.chapterNumber:typeof a?.chapterNumber=="number"?a.chapterNumber:void 0;if(a?.sections?.length){const m=cd(a),f=ls(m.thesis?.text,260),c=ls(m.keyInsight?.text,240),b=tn(m.sectionTakeaways.filter(C=>C.text!==m.thesis?.text).map(ou).filter(C=>C!=null)).slice(0,4),p=tn(m.actions.map(C=>({text:ls(C.text,180)}))).map(C=>C.text).filter(Boolean).slice(0,3);if(f||c||b.length>0||p.length>0)return{chapterTitle:o,chapterNumber:h,thesis:f||void 0,keyInsight:c&&c!==f?c:void 0,prompts:b,actions:p}}const l=tn((r.fallbackTakeaways??[]).map((m,f)=>{const c=ls(m,220);return c?{id:`takeaway-${f}`,label:`Idea ${f+1}`,prompt:"Recall the key idea, then compare it with the chapter note.",answer:c}:null}).filter(m=>m!=null)).slice(0,4);return l.length===0?null:{chapterTitle:o,chapterNumber:h,prompts:l,actions:[]}}
2function lu(a){const[r,o]=(0,s.useState)(!1),[h,l]=(0,s.useState)(!1);(0,s.useEffect)(()=>{if(typeof document>"u")return;const c=document.documentElement;l(!!(c.requestFullscreen||c.webkitRequestFullscreen||c.mozRequestFullScreen||c.msRequestFullscreen))},[]),(0,s.useEffect)(()=>{if(typeof document>"u")return;const c=()=>{const b=document;o(!!(b.fullscreenElement||b.webkitFullscreenElement||b.mozFullScreenElement||b.msFullscreenElement))};return document.addEventListener("fullscreenchange",c),document.addEventListener("webkitfullscreenchange",c),document.addEventListener("mozfullscreenchange",c),document.addEventListener("MSFullscreenChange",c),()=>{document.removeEventListener("fullscreenchange",c),document.removeEventListener("webkitfullscreenchange",c),document.removeEventListener("mozfullscreenchange",c),document.removeEventListener("MSFullscreenChange",c)}},[]);const m=(0,s.useCallback)(async()=>{if(typeof document>"u")return;const c=a?.targetElement?.current||document.documentElement;try{c.requestFullscreen?await c.requestFullscreen():c.webkitRequestFullscreen?await c.webkitRequestFullscreen():c.mozRequestFullScreen?await c.mozRequestFullScreen():c.msRequestFullscreen&&await c.msRequestFullscreen()}catch(b){console.error("Failed to enter fullscreen:",b)}},[a?.targetElement]),f=(0,s.useCallback)(async()=>{if(typeof document>"u")return;const c=document;try{c.exitFullscreen?await c.exitFullscreen():c.webkitExitFullscreen?await c.webkitExitFullscreen():c.mozCancelFullScreen?await c.mozCancelFullScreen():c.msExitFullscreen&&await c.msExitFullscreen()}catch(b){console.error("Failed to exit fullscreen:",b)}},[]);return{isFullscreen:r,isSupported:h,enterFullscreen:m,exitFullscreen:f,toggleFullscreen:(0,s.useCallback)(async()=>{r?await f():await m()},[r,m,f])}}var We=Ii("NativeFullscreen",{web:()=>fe(()=>import("./NativeFullscreenWeb-DELoe6kh.js").then(a=>new a.NativeFullscreenWeb),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]))}),ii="scrollbook_fullscreen_preference",li=4e3;function cu(a){const{isFullscreen:r,enterFullscreen:o,exitFullscreen:h}=lu({targetElement:a?.targetElement}),{isLandscape:l}=xn(),m=Zc.isNativePlatform(),[f,c]=(0,s.useState)(!1),[b,p]=(0,s.useState)(!1),[C,v]=(0,s.useState)(!1),[k,L]=(0,s.useState)(!1),[D,re]=(0,s.useState)(!1),[_,V]=(0,s.useState)(()=>{const O=localStorage.getItem(ii);if(O)try{return JSON.parse(O)}catch{}return{asked:!1,preference:"ask",lastUpdated:Date.now()}}),E=m?f:r,te=(0,s.useMemo)(()=>!m&&/iPad|iPhone|iPod/.test(navigator.userAgent)?l:!0,[m,l]),A=(0,s.useCallback)(async()=>{if(m)try{await We.lockOrientation({orientation:"landscape"}),await We.enterFullscreen(),c(!0)}catch(O){console.error("Failed to enter native fullscreen:",O)}else{await o();try{"orientation"in screen&&"lock"in screen.orientation&&await screen.orientation.lock("landscape-primary")}catch(O){console.debug("Screen orientation lock not supported:",O)}}},[m,o]),K=(0,s.useCallback)(async()=>{if(m)try{await We.exitFullscreen(),await We.unlockOrientation(),c(!1)}catch(O){console.error("Failed to exit native fullscreen:",O)}else{await h();try{"orientation"in screen&&"unlock"in screen.orientation&&screen.orientation.unlock()}catch(O){console.debug("Screen orientation unlock not supported:",O)}}},[m,h]);(0,s.useEffect)(()=>{if(m&&_.preference==="always"){We.enableAutoFullscreen({enabled:!0});const O=We.addListener("fullscreenChange",ne=>{c(ne.fullscreen)});return()=>{We.enableAutoFullscreen({enabled:!1}),O.then(()=>We.removeAllListeners())}}},[m,_.preference]);const Ee=(0,s.useCallback)(O=>{const ne={asked:!0,preference:O,lastUpdated:Date.now()};V(ne),localStorage.setItem(ii,JSON.stringify(ne)),L(!1)},[]),be=(0,s.useCallback)(()=>{re(!0),p(!1),v(!1)},[]),R=(0,s.useCallback)(async()=>{!E&&l&&(await A(),be())},[E,l,A,be]);return(0,s.useEffect)(()=>{if(!m){p(!1),v(!1),L(!1);return}if(!l){re(!1),p(!1),v(!1);return}if(E){p(!1),v(!1);return}if(!D){if(!_.asked){L(!0);return}if(_.preference!=="never"&&l&&!E){p(!0),v(!0);const O=setTimeout(()=>{p(!1)},li),ne=setTimeout(()=>{v(!1)},li*2);return()=>{clearTimeout(O),clearTimeout(ne)}}}},[m,l,E,_,D]),(0,s.useEffect)(()=>{!l&&E&&K()},[l,E,K]),{showHint:b,shouldPulseButton:C,showPermissionPrompt:k,isFullscreen:E,isLandscape:l,canEnterFullscreen:te,preference:_,enterFullscreen:A,exitFullscreen:K,dismissHint:be,savePreference:Ee,handleTapForFullscreen:R}}function du(a={}){const{minScale:r=1,maxScale:o=5,doubleTapZoom:h=!0,doubleTapScale:l=2.5}
2=a,[m,f]=(0,s.useState)({scale:1,x:0,y:0}),c=(0,s.useRef)(0),b=vc(),p=(0,s.useCallback)(L=>Math.min(Math.max(L,r),o),[r,o]),C=(0,s.useCallback)(()=>{f({scale:1,x:0,y:0})},[]),v=fd(({offset:[L],memo:D})=>(b.reduced||f(re=>({...re,scale:p(L)})),D),{scaleBounds:{min:r,max:o},rubberband:!0}),k=Li(({offset:[L,D],tap:re})=>{if(!b.reduced){if(re&&h){const _=Date.now();if(_-c.current<300){m.scale>1.1?C():f({scale:l,x:0,y:0}),c.current=0;return}c.current=_;return}m.scale>1.05&&f(_=>({..._,x:L,y:D}))}},{filterTaps:!0,bounds:()=>{const L=(m.scale-1)*150;return{left:-L,right:L,top:-L,bottom:L}},rubberband:!0});return{bind:(0,s.useCallback)(()=>({...v(),...k()}),[v,k]),style:{transform:`translate3d(${m.x}px, ${m.y}px, 0) scale(${m.scale})`,touchAction:m.scale>1?"none":"pinch-zoom",transition:"transform 0.1s ease-out"},scale:m.scale,isZoomed:m.scale>1.05,reset:C}}var sn=Ii("DynamicIsland",{web:()=>fe(()=>import("./DynamicIslandWeb-kFvSrxCT.js").then(a=>new a.DynamicIslandWeb),__vite__mapDeps([33,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]))}),uu=5e3;function hu({bookTitle:a,chapterTitle:r,chapterNumber:o,totalChapters:h,progress:l,isPlaying:m,domainColor:f,coverUrl:c,statusString:b,enabled:p}){const C=(0,s.useRef)(0),v=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(!p)return;const k={bookTitle:a,chapterTitle:r,chapterNumber:o,totalChapters:h,progress:l,isPlaying:m,domainColor:f,coverUrl:c,statusString:b},L=Date.now(),D=L-C.current<uu;v.current?(!D||!m)&&(sn.update(k).catch(()=>{}),C.current=L):(sn.start(k).catch(()=>{}),v.current=!0,C.current=L)},[p,a,r,o,h,l,m,f,c]),(0,s.useEffect)(()=>()=>{v.current&&(sn.end().catch(()=>{}),v.current=!1)},[])}function mu(a,r,o){return`${a}:ch${r}:h${o}`}function fu(a,r){return`${a}:ch${r}:takeaway`}function pu(){return{promote:(0,s.useCallback)(async a=>{const{bookId:r,chapterNumber:o,highlightId:h,ideaText:l}=a;if(!r)return!1;const m=h?mu(r,o,h):fu(r,o),f=l.slice(0,280);try{const{error:c}=await cs.rpc("enqueue_idea_for_study",{p_book_id:r,p_chapter_number:o,p_idea_key:m,p_idea_text:f});if(c)return console.warn("[useStudyThis] enqueue_idea_for_study RPC error:",c.message),!1;if(h){const{error:b}=await cs.from("user_highlights").update({is_quiz_seed:!0,idea_key:m}).eq("id",h);b&&console.warn("[useStudyThis] highlight update error:",b.message),I.track($.STUDY_PROMOTED,{book_id:r,chapter_number:o,highlight_id:h})}else I.track($.IDEA_SAVED,{book_id:r,chapter_number:o,source:"chapter_takeaway"});return!0}catch(c){return console.warn("[useStudyThis] unexpected error (swallowed):",c),!1}},[])}}function xu(a,r){const o=r.get("resumeTime");if(!o)return null;const h=Number.parseFloat(o);if(!Number.isFinite(h)||h<=0)return null;a.currentTime=h;const l=new URLSearchParams(r);return l.delete("resumeTime"),l}var bu=3e3;function Oi(a={}){const{delay:r=bu,enabled:o=!0}=a,[h,l]=(0,s.useState)(!1),m=(0,s.useRef)(null),f=(0,s.useCallback)(()=>{l(!1),m.current&&clearTimeout(m.current)},[]),c=(0,s.useCallback)(()=>{o&&(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{l(!1)},r))},[r,o]),b=(0,s.useCallback)(()=>{l(!0),c()},[c]),p=(0,s.useCallback)(()=>{h?f():b()},[h,b,f]);return(0,s.useEffect)(()=>()=>{m.current&&clearTimeout(m.current)},[]),{isVisible:h,showControls:b,hideControls:f,resetTimer:c,toggleControls:p}}var e=pc();function z(a,r){return`rgba(${parseInt(a.slice(1,3),16)},${parseInt(a.slice(3,5),16)},${parseInt(a.slice(5,7),16)},${r})`}function Ws(a){return`${Math.floor(a/60)}:${String(Math.floor(a%60)).padStart(2,"0")}`}var gu=(0,s.memo)(function({isVisible:r,isPlaying:o,currentTime:h,duration:l,playbackRate:m=1,autoplayEnabled:f,chapterNumber:c,totalChapters:b,domainColor:p="#F59E0B",bookTitle:C,chapterTitle:v,onPlay:k,onPause:L,onSkipBack:D,onSkipForward:re,onSeek:_,onPrevChapter:V,onNextChapter:E,onChangeSpeed:te,onCycleFontSize:A,onToggleAutoplay:K,onToggleChapterDrawer:Ee,isChapterDrawerOpen:be,onToggleFullscreen:R,onOpenChat:O,isChatOpen:ne=!1,onExpand:F,bottomOffset:ie}){const ge=yi(),pt=(0,s.useRef)(null),[ke,us]=(0,s.useState)(!1),at=rt()&&wi(),[$e,Ys]=(0,s.use
2State)(0);(0,s.useLayoutEffect)(()=>{const M=pt.current;if(!M)return;Ys(M.offsetWidth);const ae=new ResizeObserver(([Ye])=>{Ys(Ye?.contentRect.width??0)});return ae.observe(M),()=>ae.disconnect()},[]);const{isLandscape:we}=xn(),he=is("(min-width: 1401px)"),{resolvedTheme:Ks}=fn(),qe=Ks==="dark",Ve=!he&&we,{isVisible:hs,showControls:xt}=Oi({enabled:Ve,delay:2500});(0,s.useEffect)(()=>{r&&xt()},[Ve,r,xt]);const ms=(0,s.useCallback)(()=>{Ve&&xt()},[Ve,xt]),zt=qe?"rgba(255,255,255,0.82)":"rgba(0,0,0,0.80)",Re=qe?"rgba(255,255,255,0.50)":"rgba(0,0,0,0.45)",le=qe?"rgba(255,255,255,0.36)":"rgba(0,0,0,0.32)",bt=qe?"rgba(255,255,255,0.72)":"rgba(0,0,0,0.68)",i=qe?`linear-gradient(180deg, ${z(p,.1)} 0%, ${z(p,.04)} 100%), rgb(8,8,10)`:`linear-gradient(180deg, ${z(p,.06)} 0%, ${z(p,.02)} 100%), #FFFFFF`,Ht=qe?`1px solid ${z(p,.22)}`:`1px solid ${z(p,.28)}`;(0,s.useEffect)(()=>{if(r)if(we)if(rt())We.lockOrientation({orientation:"landscape"}).then(()=>We.enterFullscreen()).catch(M=>console.debug("Native landscape fullscreen failed:",M));else{const M=document.documentElement,ae=M.requestFullscreen??M.webkitRequestFullscreen;ae&&ae.call(M).catch(Ye=>console.debug("Web landscape fullscreen failed:",Ye))}else if(rt())We.exitFullscreen().then(()=>We.unlockOrientation()).catch(M=>console.debug("Native portrait restore failed:",M));else{const M=document,ae=M.exitFullscreen??M.webkitExitFullscreen;ae&&(M.fullscreenElement||M.webkitFullscreenElement)&&ae.call(M).catch(Ye=>console.debug("Web portrait restore failed:",Ye))}},[we,r]);const g=l>0?h/l*100:0,Wt=Math.max(0,l-h),Tt=(0,s.useCallback)(M=>{if(!pt.current||l<=0)return;const ae=pt.current.getBoundingClientRect(),Ye="touches"in M?M.touches[0]?.clientX??M.changedTouches[0]?.clientX:M.clientX;_(Math.max(0,Math.min(1,(Ye-ae.left)/ae.width))*l)},[l,_]),Ce=(0,s.useCallback)(M=>{us(!0),Tt(M)},[Tt]),Ie=(0,s.useCallback)(M=>{ke&&Tt(M)},[ke,Tt]),Me=(0,s.useCallback)(()=>{us(!1)},[]),Gs=(0,s.useCallback)(M=>{if(l<=0)return;const ae=M.shiftKey?30:10;switch(M.key){case"ArrowLeft":M.preventDefault(),_(Math.max(0,h-ae));break;case"ArrowRight":M.preventDefault(),_(Math.min(l,h+ae));break;case"Home":M.preventDefault(),_(0);break;case"End":M.preventDefault(),_(l);break}},[h,l,_]),et=(0,s.useCallback)(()=>{if(q("light"),o){L();return}k()},[o,k,L]),_t=(0,s.useCallback)(()=>{O&&(q("light"),O())},[O]),fs=(0,s.useCallback)((M,ae)=>{ae.offset.y<-40||ae.velocity.y<-300?F?.():(ae.offset.y>60||ae.velocity.y>400)&&be&&(q("light"),Ee?.())},[F,be,Ee]),Vr=c<=0,qt=c>=b-1,ps=ke?14:10,Et=we?{paddingLeft:"max(16px, env(safe-area-inset-left, 16px))",paddingRight:"max(16px, env(safe-area-inset-right, 16px))"}:{paddingLeft:"16px",paddingRight:"16px"},Xs=we?"4px":ie?"8px":"max(env(safe-area-inset-bottom, 8px), 8px)";return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(J,{children:r&&(0,e.jsx)(S.div,{initial:he?{x:320,opacity:0}:{y:72,opacity:0,z:0},animate:he?{x:0,opacity:1}:Ve&&!hs?{y:96,opacity:0,z:0}:{y:0,opacity:1,z:0},exit:he?{x:320,opacity:0}:{y:72,opacity:0,z:0},transition:{type:"spring",damping:32,stiffness:420},className:he?`fixed right-0 top-0 h-full ${Ct("mobileFloatingPlayer")} w-80 flex flex-col overflow-hidden`:`fixed left-0 right-0 ${Ct("mobileFloatingPlayer")}${at?" player-gpu-layer":""}`,style:he?{borderLeft:`1px solid ${z(p,.18)}`,boxShadow:`-4px 0 32px ${z(p,.08)}, -1px 0 0 rgba(0,0,0,0.3)`}:{bottom:ie??0,transition:at?void 0:"bottom 0.3s ease-out",transform:"translateZ(0)",willChange:"transform"},...!he&&{drag:"y",dragConstraints:{top:0,bottom:0},dragElastic:{top:.25,bottom:.25},onDragEnd:fs},"data-testid":"mobile-player",children:(0,e.jsxs)("div",{onPointerDown:ms,style:{background:i,boxShadow:qe?"none":"0 -1px 0 rgba(0,0,0,0.06), 0 -4px 16px rgba(0,0,0,0.06)",...he?{height:"100%",display:"flex",flexDirection:"column",overflowY:"auto"}:{borderTop:Ht}},children:[he?(0,e.jsxs)("div",{className:"flex flex-col px-5 pt-5 pb-3 flex-shrink-0",style:{borderBottom:`1px solid ${z(p,.12)}`},children:[(0,e.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-widest mb-2",style:{color:z(p,.65)},children:"Now Playing"}),v&&(0,e.jsx)("p",{className:"text-sm font-semibold leading-snug mb-1",style:{color:zt},children:v}),C&&(0,e.jsxs)("p",{className:"text-xs truncate",style:{color:Re},children:[C,b>1&&(0,e.jsxs)(e.Fragment,{children:[" · ",(0,e.jsxs)("span",{style:{color:z(p,.65)},children:["Ch ",c,"/",b]})]})]})]}):(0,e.jsxs)("button",{onClick:()=>{q("light"),Ee?.()},className:"flex flex-col items-center w-full pt-1.5 pb-0 touch-manipulation active:opacity-60 transition-opacity",style:{background:"transparent",border:"none"},"aria-label":be?"Close chapter list":"Open chapter list",children:[(0,e.jsx)("div",{style:{width:32,height:3,borderRadius:2,background:be?z(p,.7):qe?"rgba(255,255,255,0.35)":"rgba(0,0,0,0.25)"}}),!we&&v&&(0,e.jsx)("p",{className:"text-xs font-semibold truncate w-full text-center",style:{color:zt,lineHeight:1,maxWidth:"88%",paddingTop:4,paddingBottom:0},children:v}),!we&&C&&(0,e.jsxs)("p",{className:"text-xs truncate w-full text-center",style:{color:Re,lineHeight:1,maxWidth:"80%",paddingTop:2,paddingBottom:0},children:[C,b>1&&(0,e.jsxs)(e.Fragment,{children:[" · ",(0,e.jsxs)("span",{style:{color:z(p,.65)},children:[c,"/",b]})]})]})]}),(0,e.jsxs)("div",{style:{...Et,paddingTop:he?20:4,paddingBottom:0,...he&&{flexShrink:0}},children:[(0,e.jsx)("div",{ref:pt,role:"slider","aria-label":"Audio progress","aria-valuemin":0,"aria-valuemax":Math.round(l),"aria-valuenow":Math.round(h),"aria-valuetext":`${Ws(h)} of ${Ws(l)}`,tabIndex:0,className:"h-5 flex items-center cursor-pointer touch-manipulation focus:outline-none select-none",onClick:Tt,onMouseDown:Ce,onTouchStart:Ce,onTouchMove:Ie,onTouchEnd:Me,onMouseUp:Me,onKeyDown:Gs,children:(0,e.jsxs)("div",{className:"relative w-full",style:{height:2},children:[(0,e.jsx)("div",{className:"absolute inset-0 rounded-full",style:{background:z(p,.18),transform:ke?"scaleY(2)":"none",transition:"transform 150ms cubic-bezier(0.23, 1, 0.32, 1)"},children:(0,e.jsx)("div",{className:"h-full rounded-full",style:{width:"100%",background:p,boxSh
2adow:`0 0 6px ${z(p,.6)}, 0 0 2px ${p}`,transformOrigin:"left center",transform:`scaleX(${g/100})`}})}),(0,e.jsx)("div",{className:"absolute top-1/2 rounded-full",style:{width:ps,height:ps,left:0,opacity:$e===0?0:1,transform:`translateX(${$e*g/100-ps/2}px) translateY(-50%)`,background:"#fff",boxShadow:`0 0 0 2px ${z(p,.35)}, 0 1px 4px rgba(0,0,0,0.5), 0 0 10px ${z(p,.5)}`,transition:ke?"none":"width 0.15s, height 0.15s"}})]})}),(0,e.jsxs)("div",{className:"flex justify-between",style:{marginTop:-1},children:[(0,e.jsx)("span",{className:"text-xs font-medium tabular-nums",style:{color:z(p,.85)},children:Ws(h)}),(0,e.jsxs)("span",{className:"text-xs tabular-nums",style:{color:Re},children:["-",Ws(Wt)]})]})]}),(0,e.jsxs)("div",{className:"flex items-center justify-evenly",style:{...Et,paddingTop:he?16:we?2:4,paddingBottom:he?8:we?0:2,...he&&{flexShrink:0}},children:[(0,e.jsx)("button",{onClick:()=>{q("medium"),V?.()},disabled:Vr||!V,className:"w-10 h-10 flex items-center justify-center active:scale-90 transition-transform disabled:opacity-15 disabled:pointer-events-none touch-manipulation","aria-label":"Previous chapter",children:(0,e.jsx)(_i,{className:"w-[15px] h-[15px]",style:{color:le}})}),(0,e.jsxs)("button",{onClick:()=>{q("light"),D()},className:"w-10 h-10 relative flex items-center justify-center active:scale-90 transition-transform touch-manipulation","aria-label":"Rewind 10 seconds",children:[(0,e.jsx)(Ti,{className:"w-[22px] h-[22px]",style:{color:bt}}),(0,e.jsx)("span",{className:"absolute text-[10px] font-bold tabular-nums",style:{color:bt,marginTop:2},children:"10"})]}),(0,e.jsx)(S.button,{onClick:et,className:`${we?"w-[40px] h-[40px]":"w-[52px] h-[52px]"} rounded-full flex items-center justify-center text-white touch-manipulation flex-shrink-0`,style:{background:p,boxShadow:`0 0 0 6px ${z(p,.14)}, 0 4px 18px ${z(p,.55)}, 0 0 36px ${z(p,.16)}`},animate:o&&!ge&&!at?{scale:[1,1.04,1]}:{scale:1},transition:o&&!ge&&!at?{repeat:1/0,duration:2.6,ease:"easeInOut"}:{duration:.15},whileTap:{scale:.86},"aria-label":o?"Pause":"Play",children:o?(0,e.jsx)(on,{className:"w-[22px] h-[22px]"}):(0,e.jsx)(Vs,{className:"w-[22px] h-[22px] translate-x-[2px]"})}),(0,e.jsxs)("button",{onClick:()=>{q("light"),re()},className:"w-10 h-10 relative flex items-center justify-center active:scale-90 transition-transform touch-manipulation","aria-label":"Forward 10 seconds",children:[(0,e.jsx)(ln,{className:"w-[22px] h-[22px]",style:{color:bt}}),(0,e.jsx)("span",{className:"absolute text-[10px] font-bold tabular-nums",style:{color:bt,marginTop:2},children:"10"})]}),(0,e.jsx)("button",{onClick:()=>{q("medium"),E?.()},disabled:qt||!E,className:"w-10 h-10 flex items-center justify-center active:scale-90 transition-transform disabled:opacity-15 disabled:pointer-events-none touch-manipulation","aria-label":"Next chapter",children:(0,e.jsx)(Ei,{className:"w-[15px] h-[15px]",style:{color:le}})})]}),!we&&(0,e.jsxs)("div",{className:"flex items-center justify-evenly",style:{...Et,paddingTop:he?12:4,paddingBottom:6,...he&&{flexShrink:0}},children:[(0,e.jsxs)("button",{onClick:Ee,className:"flex min-h-11 w-12 flex-col items-center justify-center gap-[2px] active:scale-90 transition-transform touch-manipulation","aria-label":be?"Close chapters":"Open chapters",children:[(0,e.jsx)(dn,{className:"w-[14px] h-[14px]",style:{color:be?p:le}}),(0,e.jsx)("span",{className:"text-[10px] font-medium leading-none",style:{color:be?z(p,.9):Re},children:"Chapters"})]}),te?(0,e.jsxs)("button",{onClick:te,className:"flex min-h-11 w-12 flex-col items-center justify-center gap-[2px] active:scale-90 transition-transform touch-manipulation","aria-label":`Speed ${m}x`,children:[(0,e.jsxs)("span",{className:"font-bold tabular-nums",style:{fontSize:12,lineHeight:1,color:m!==1?p:Re},children:[m,"Ã"]}),(0,e.jsx)("span",{className:"text-[10px] font-medium leading-none",style:{color:m!==1?z(p,.9):Re},children:"Speed"})]}):(0,e.jsx)("div",{className:"w-12"}),A&&(0,e.jsxs)("button",{onClick:()=>{q("light"),A()},className:"flex min-h-11 w-12 flex-col items-center justify-center gap-[2px] active:scale-90 transition-transform touch-manipulation","aria-label":"Cycle font size",children:[(0,e.jsxs)("span",{style:{color:le,fontSize:14,fontWeight:700,lineHeight:1},children:["A",(0,e.jsx)("span",{style:{fontSize:10},children:"A"})]}),(0,e.jsx)("span",{className:"text-[10px] font-medium leading-none",style:{color:Re},children:"Text"})]}),(0,e.jsxs)("button",{onClick:K,className:"flex min-h-11 w-12 flex-col items-center justify-center gap-[2px] active:scale-90 transition-transform touch-manipulation","aria-label":f?"Autoplay on":"Autoplay off",children:[(0,e.jsx)(Ci,{className:"w-[14px] h-[14px]",style:{color:f?p:le}}),(0,e.jsx)("span",{className:"text-[10px] font-medium leading-none",style:{color:f?z(p,.9):Re},children:"Auto"})]}),R&&(0,e.jsxs)("button",{type:"button",onClick:M=>{q("light"),R(M)},className:"flex min-h-11 w-12 flex-col items-center justify-center gap-[2px] active:scale-90 transition-transform touch-manipulation","aria-label":"Enter fullscreen",children:[(0,e.jsx)(zr,{className:"h-[14px] w-[14px]",style:{color:le}}),(0,e.jsx)("span",{className:"text-[10px] font-medium leading-none",style:{color:Re},children:"Full"})]})]}),!we&&(0,e.jsx)("div",{className:"flex",style:{...Et,paddingTop:2,paddingBottom:Xs,...he&&{flexShrink:0}},children:(0,e.jsx)("button",{onClick:_t,disabled:!O,className:"flex-1 min-h-[46px] rounded-2xl border transition-all active:scale-[0.98] touch-manipulation disabled:opacity-40 disabled:pointer-events-none",style:{borderColor:ne?z(p,.45):z(p,.18),background:ne?`linear-gradient(180deg, ${z(p,.18)} 0%, ${z(p,.1)} 100%)`:qe?"rgba(255,255,255,0.04)":"rgba(255,255,255,0.78)",boxShadow:ne?`0 8px 24px ${z(p,.14)}`:"none"},"aria-label":"Ask BookBuddy about this chapter",children:(0,e.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,e.jsx)(Wr,{className:"w-4 h-4",style:{color:ne?p:bt}}),(0,e.jsxs)("div",{className:"flex flex-col items-start",children:[(0,e.jsx)("span",{className:"text-[12px] font-semibold leading-none",style:{color:zt},children:"Ask BookBuddy"}),(0,e.jsx)("span",{className:"text-[10px] leading-none mt-1",style:{color:ne?z(p,.95):Re},children:"Chapter questions and deep dives"})]})]})})})]})},"mobile-player")}),(0,e.jsx)(J,{children:r&&Ve&&!hs&&(0,e.jsxs)(S.div,{initial:{y:44},animate:{y:0},exit:{y:44},transition:{type:"spring",damping:30,stiffness:400},className:`fixed left-0 right-0 ${Ct("mobileFloatingPlayer")} flex items-center gap-3`,style:{bottom:0,height:44,paddingLeft:"max(14px, env(safe-area-inset-left, 14px))",paddingRight:"max(14px, env(safe-area-inset-right, 14px))",background:i,borderTop:Ht},onPointerDown:()=>xt(),children:[(0,e.jsx)("button",{onClick:et,className:"w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 touch-manipulation",style:{background:p,boxSh
2adow:`0 0 0 3px ${z(p,.18)}`},"aria-label":o?"Pause":"Play",children:o?(0,e.jsx)(on,{className:"w-3 h-3 text-white"}):(0,e.jsx)(Vs,{className:"w-3 h-3 text-white translate-x-[0.5px]"})}),(0,e.jsx)("div",{className:"flex-1 h-[2px] rounded-full",style:{background:z(p,.18)},children:(0,e.jsx)("div",{className:"h-full rounded-full",style:{width:`${g}%`,background:p}})}),(0,e.jsxs)("span",{className:"text-[10px] tabular-nums flex-shrink-0",style:{color:Re},children:["-",Ws(Wt)]})]},"player-peek")})]})}),ci=[{key:"summary",label:"Summary",Icon:Ur},{key:"chat",label:"Chat",Icon:nn}],vu={key:"playground",label:"Practice",Icon:Wr};function yu({active:a,ffActor:r,onChange:o,domainColor:h,className:l}){const m=r?[...ci,vu]:ci;return(0,e.jsx)("div",{role:"tablist",className:W("inline-flex items-center gap-1 rounded-full bg-stone-100 p-1 dark:bg-white/5",l),children:m.map(({key:f,label:c,Icon:b})=>{const p=a===f;return(0,e.jsxs)("button",{role:"tab",type:"button","aria-selected":p,"aria-label":c,onClick:()=>o(f),className:W("flex min-h-[36px] items-center justify-center gap-1.5 rounded-full px-3 text-xs font-semibold transition-colors",p?"text-white":"text-stone-500 hover:text-stone-800 dark:text-white/50 dark:hover:text-white"),style:p?{backgroundColor:h}:void 0,children:[(0,e.jsx)(b,{className:"h-3.5 w-3.5"}),(0,e.jsx)("span",{children:c})]},f)})})}var Bi={concepts:[{conceptNodeId:"c-amyg",label:"Amygdala",slug:"amygdala",teachChapterId:"ch1",teachChapterNo:1,centrality:9,prereqRank:0,bookCount:3,band:"known",dot:"owned",strength:.86},{conceptNodeId:"c-neo",label:"Neocortex",slug:"neocortex",teachChapterId:"ch1",teachChapterNo:1,centrality:7,prereqRank:0,bookCount:2,band:"learning",dot:"partial",strength:.42},{conceptNodeId:"c-dual",label:"Dual-Mind Theory",slug:"dual-mind",teachChapterId:"ch1",teachChapterNo:1,centrality:8,prereqRank:1,bookCount:4,band:"learning",dot:"partial",strength:.55},{conceptNodeId:"c-hijack",label:"Amygdala Hijack",slug:"amygdala-hijack",teachChapterId:"ch2",teachChapterNo:2,centrality:6,prereqRank:1,bookCount:2,band:"new",dot:"not_yet",strength:.12},{conceptNodeId:"c-selfaware",label:"Self-Awareness",slug:"self-awareness",teachChapterId:"ch2",teachChapterNo:2,centrality:8,prereqRank:2,bookCount:5,band:"new",dot:"not_yet",strength:.05},{conceptNodeId:"c-selfreg",label:"Self-Regulation",slug:"self-regulation",teachChapterId:"ch3",teachChapterNo:3,centrality:7,prereqRank:2,bookCount:3,band:"new",dot:"not_yet",strength:0},{conceptNodeId:"c-empathy",label:"Empathy",slug:"empathy",teachChapterId:"ch4",teachChapterNo:4,centrality:6,prereqRank:3,bookCount:4,band:"new",dot:"not_yet",strength:0},{conceptNodeId:"c-social",label:"Social Skill",slug:"social-skill",teachChapterId:"ch5",teachChapterNo:5,centrality:5,prereqRank:3,bookCount:2,band:"new",dot:"not_yet",strength:0},{conceptNodeId:"c-eq",label:"Emotional Intelligence",slug:"emotional-intelligence",teachChapterId:"ch5",teachChapterNo:5,centrality:10,prereqRank:4,bookCount:6,band:"new",dot:"not_yet",strength:0}],edges:[{from:"c-amyg",to:"c-dual",type:"prerequisite"},{from:"c-neo",to:"c-dual",type:"prerequisite"},{from:"c-amyg",to:"c-hijack",type:"prerequisite"},{from:"c-dual",to:"c-selfaware",type:"prerequisite"},{from:"c-hijack",to:"c-selfreg",type:"prerequisite"},{from:"c-selfaware",to:"c-selfreg",type:"prerequisite"},{from:"c-selfaware",to:"c-empathy",type:"prerequisite"},{from:"c-selfreg",to:"c-social",type:"prerequisite"},{from:"c-empathy",to:"c-eq",type:"prerequisite"},{from:"c-social",to:"c-eq",type:"prerequisite"},{from:"c-selfreg",to:"c-hijack",type:"contrasts"},{from:"c-empathy",to:"c-social",type:"contrasts"}]};async function ku(a){const r=cs,{data:o,error:h}=await r.rpc("graph_book_journey",{p_book_id:a,p_max_concepts:12});if(h||!Array.isArray(o)||o.length===0)return Bi;const l=o.map(c=>({conceptNodeId:c.concept_node_id,label:c.concept_label,slug:c.concept_slug,teachChapterId:c.teach_chapter_id,teachChapterNo:c.teach_chapter_no,centrality:c.centrality??0,prereqRank:c.prereq_rank??0,bookCount:c.book_count??1,band:"new",dot:"not_yet",strength:0})),m=l.map(c=>c.conceptNodeId),{data:f}=await r.rpc("graph_book_journey_edges",{p_book_id:a,p_concept_ids:m});return{concepts:l,edges:Array.isArray(f)?f.filter(c=>c.edge_type==="prerequisite"||c.edge_type==="contrasts").map(c=>({from:c.from_node,to:c.to_node,type:c.edge_type})):[]}}
2function wu(a,r=!0){return xc({queryKey:["actor-book-journey",a],queryFn:()=>ku(a),enabled:Ai&&r&&!!a,staleTime:300*1e3,gcTime:600*1e3,retry:!1})}function ju({isOpen:a,onClose:r,topic:o,lessons:h,currentIndex:l,completedChapters:m,onChapterClick:f,estimatedTime:c,domainColor:b="#F59E0B",isMobile:p=!1,domainSlug:C,topicSlug:v,freeChapterLimit:k,isSeries:L=!1,currentIdeas:D=[],onIdeaClick:re}){const _=h.filter(A=>A.orderIndex!==0&&!A.title.toLowerCase().includes("series overview")),V=o.coverUrl||_[0]?.infographicUrl||h[0]?.infographicUrl,E=m.filter(A=>{const K=h[A];return K&&K.orderIndex!==0&&!K.title.toLowerCase().includes("series overview")}).length,te=_.length>0?Math.round(E/_.length*100):0;return(0,e.jsx)(ad,{open:a,onOpenChange:A=>{A||r()},side:"bottom",swipeToDismiss:!0,title:o.title,ariaLabel:`Book context for ${o.title}`,initialFocus:"panel",closeLabel:"Close book context",className:"max-h-[88dvh]",style:{outline:"none"},contentClassName:"flex flex-col overflow-hidden p-0",headerClassName:"px-4 py-2",backdropClassName:"bg-black/40 backdrop-blur-[1px]",children:(0,e.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col",style:{"--book-hub-accent":b},children:[(0,e.jsx)(Ec,{title:o.title,author:o.author,coverUrl:V,subtitle:o.subtitle||o.synopsis||o.description,chapterCount:_.length,totalMinutes:c,showTitle:!1,testId:"chapter-drawer-book-summary"}),(0,e.jsxs)("section",{className:"flex min-h-0 flex-1 flex-col","aria-label":"Chapters",children:[(0,e.jsxs)("header",{className:"flex shrink-0 items-center justify-between border-b border-[var(--sb-border)] px-4 py-3",children:[(0,e.jsx)("h2",{className:"m-0 text-sm font-bold text-[var(--sb-ink)]",children:"Chapters"}),(0,e.jsx)("span",{className:"text-xs font-semibold text-[var(--sb-ink-faint)]",children:_.length})]}),(0,e.jsxs)("div",{className:"shrink-0 border-b border-[var(--sb-border)] bg-[var(--sb-surface-subtle)] px-4 py-2",children:[(0,e.jsxs)("div",{className:"mb-1 flex items-center justify-between text-xs font-medium",children:[(0,e.jsx)("span",{className:"text-[var(--sb-ink-muted)]",children:"Progress"}),(0,e.jsxs)("span",{className:"font-semibold",style:{color:b},children:[E,"/",_.length]})]}),(0,e.jsx)("div",{className:"h-1 overflow-hidden rounded-full bg-[var(--sb-border)]",role:"progressbar","aria-label":"Book progress","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":te,children:(0,e.jsx)("div",{className:"h-full rounded-full transition-[width] duration-300 motion-reduce:transition-none",style:{backgroundColor:b,width:`${te}%`}})})]}),D.length>0&&re&&(0,e.jsxs)("section",{className:"shrink-0 border-b border-[var(--sb-border)] px-4 py-2.5","aria-labelledby":"chapter-drawer-ideas-heading",children:[(0,e.jsx)("h3",{id:"chapter-drawer-ideas-heading",className:"mb-1.5 text-[11px] font-semibold uppercase text-[var(--sb-ink-faint)]",children:"Ideas in this chapter"}),(0,e.jsx)("div",{className:"flex gap-1.5 overflow-x-auto pb-0.5 scrollbar-hide",children:D.slice(0,3).map(A=>(0,e.jsx)("button",{type:"button",onClick:()=>{re(A),r()},className:"min-h-11 shrink-0 rounded-[var(--sb-radius-control)] border border-[var(--sb-border)] bg-[var(--sb-surface)] px-3 text-xs font-semibold text-[var(--sb-ink-muted)] transition-colors hover:border-[var(--book-hub-accent,var(--sb-accent))] hover:text-[var(--book-hub-accent,var(--sb-accent))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)]",children:A.label},A.slug))})]}),(0,e.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:(0,e.jsx)(kd,{lessons:h,currentIndex:l,completedChapters:m,onChapterClick:A=>{f(A),r()},primaryColor:b,variant:"compact",showCurrentLabel:!1,bookSlug:v,domainSlug:C,freeChapterLimit:k,isSeries:L,showMediaActions:!1,showLockedStatus:!1})})]})]})})}function Nu({open:a,onOpenChange:r,bookTitle:o,coverUrl:h,domainColor:l,publishedBookCount:m,returnTo:f}){const c=(0,s.useRef)(null),b=m&&m>0?`${m}+ published Scrollbooks`:"all published Scrollbooks";return(0,e.jsx)(qr,{open:a,onOpenChange:r,title:"Sign in to listen",description:"Create a free account to start this chapter and keep your progress.",placement:"adaptive",initialFocusRef:c,swipeToDismiss:!0,closeLabel:"Close sign-in prompt",testId:"topic-login-gate",className:"sm:max-w-md",contentClassName:"p-0",children:(0,e.jsxs)("div",{className:"p-5",children:[(0,e.jsxs)("div",{className:"flex items-start gap-4",children:[h?(0,e.jsx)("img",{src:h,alt:`${o} cover`,className:"h-[7.5rem] w-[5.25rem] shrink-0 rounded-[6px] bg-[var(--sb-surface-subtle)] object-cover shadow-sm",loading:"lazy"}):(0,e.jsx)("div",{"aria-hidden":"true",className:"flex h-[7.5rem] w-[5.25rem] shrink-0 items-center justify-center rounded-[6px] border border-[var(--sb-border)] bg-[var(--sb-surface-subtle)]",children:(0,e.jsx)(Vs,{className:"h-6 w-6",style:{color:l}})}),(0,e.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,e.jsx)("p",{className:"line-clamp-3 text-sm font-semibold leading-5 text-[var(--sb-ink)]",children:o}),(0,e.jsx)("ul",{className:"mt-3 grid gap-2",children:[`Access ${b}`,"Audio and visual chapter cards","Progress saved across devices"].map(p=>(0,e.jsxs)("li",{className:"flex items-start gap-2 text-sm leading-5 text-[var(--sb-ink-muted)]",children:[(0,e.jsx)(pn,{className:"mt-0.5 h-4 w-4 shrink-0",style:{color:l},"aria-hidden":"true"}),(0,e.jsx)("span",{children:p})]},p))})]})]}),(0,e.jsxs)("div",{className:"mt-5 grid gap-2",children:[(0,e.jsx)(Ze,{ref:c,to:"/signup",state:{from:f},onClick:()=>r(!1),className:"inline-flex min-h-11 w-full items-center justify-center rounded-[var(--sb-radius-control)] px-4 text-sm font-semibold text-stone-950 transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)] focus-visible:ring-offset-2",style:{backgroundColor:l},children:"Create free account"}),(0,e.jsx)(Ze,{to:"/login",state:{from:f},onClick:()=>r(!1),className:"inline-flex min-h-11 w-full items-center justify-center rounded-[var(--sb-radius-control)] px-4 text-sm font-medium text-[var(--sb-ink-muted)] hover:bg-[var(--sb-surface-subtle)] focu
2s-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)]",children:"Already have an account? Log in"})]})]})})}function Su(a,r){const{isAuthenticated:o,profile:h}=ki(),{data:l,isLoading:m}=bd(o?h?.id:void 0,{enabled:Dr});return{next:(0,s.useMemo)(()=>{if(!Dr||!l)return null;const f=l.becauseYouRead.flatMap(k=>k.recommendations),c=[...l.forYou,...f,...l.trending],b=new Set,p=[];for(const k of c)k.slug!==a&&(b.has(k.slug)||(b.add(k.slug),p.push({slug:k.slug,title:k.title,domainSlug:k.domainSlug,coverUrl:k.coverUrl??k.thumbnailUrl,reason:k.reason})));if(p.length===0)return null;const C=r?p.filter(k=>k.domainSlug===r):[],v=r?p.filter(k=>k.domainSlug!==r):p;return C[0]??v[0]??null},[l,a,r]),isLoading:Dr&&m}}function Cu({isOpen:a,onClose:r,book:o,chaptersRead:h,timeSpentMinutes:l,gamStats:m,domainSlug:f}){(0,s.useEffect)(()=>{if(!a)return;(async()=>{try{const{data:L}=await cs.auth.getUser(),D=L?.user?.id;if(!D)return;const{justCompleted:re}=await Mi.incrementMission(D,"complete_book");re&&$i({missionKey:"complete_book",xpAwarded:Fi.complete_book})}catch(L){console.warn("[BookCompletionModal] mission tracking unavailable:",L)}})()},[a]);const{next:c}=Su(o.slug,f),b=Dr&&!!c,p=m?.todayChapters||0,C=(m?.totalBooks||0)+1,v=(0,s.useRef)(null);return(0,e.jsx)(qr,{open:a,onOpenChange:k=>{k||r()},title:"Book Complete!",description:`You finished ${o.title}`,closeLabel:"Close completion summary",placement:"adaptive",swipeToDismiss:!0,contentClassName:"p-0",initialFocusRef:v,children:(0,e.jsxs)("div",{className:"px-5 pb-5 pt-4 sm:px-6",children:[(0,e.jsxs)("div",{"aria-label":"Completion summary",className:"mb-4 grid grid-cols-3 divide-x divide-[var(--sb-border)] rounded-[var(--sb-radius-control)] border border-[var(--sb-border)] bg-[var(--sb-surface-subtle)] px-2 py-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-center gap-1.5 px-1 text-center",children:[(0,e.jsx)(Ur,{className:"h-4 w-4 shrink-0 text-gold-500","aria-hidden":"true"}),(0,e.jsxs)("p",{className:"text-sm font-bold text-[var(--sb-ink)]",children:[h," ",(0,e.jsx)("span",{className:"font-medium text-[var(--sb-ink-muted)]",children:"chapters"})]})]}),(0,e.jsxs)("div",{className:"flex items-center justify-center gap-1.5 px-1 text-center",children:[(0,e.jsx)(wc,{className:"h-4 w-4 shrink-0 text-blue-500","aria-hidden":"true"}),(0,e.jsxs)("p",{className:"text-sm font-bold text-[var(--sb-ink)]",children:[l," ",(0,e.jsx)("span",{className:"font-medium text-[var(--sb-ink-muted)]",children:"min"})]})]}),(0,e.jsxs)("div",{className:"flex items-center justify-center gap-1.5 px-1 text-center",children:[(0,e.jsx)(Mc,{className:"h-4 w-4 shrink-0 text-orange-500","aria-hidden":"true"}),(0,e.jsxs)("p",{className:"text-sm font-bold text-[var(--sb-ink)]",children:[p," ",(0,e.jsx)("span",{className:"font-medium text-[var(--sb-ink-muted)]",children:"today"})]})]})]}),(0,e.jsxs)("div",{className:"mb-4 flex items-center gap-2.5 rounded-[var(--sb-radius-control)] border border-gold-500/25 bg-gold-500/5 px-3 py-2.5",children:[(0,e.jsx)(Ri,{className:"h-4 w-4 flex-shrink-0 text-gold-500","aria-hidden":"true"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-sm font-bold text-[var(--sb-ink)]",children:C===1?"First book finished!":`${C} books completed!`}),(0,e.jsx)("p",{className:"text-xs text-[var(--sb-ink-muted)]",children:"Keep the momentum going"})]})]}),(0,e.jsxs)("div",{className:"space-y-1",children:[b&&c?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(Ze,{ref:k=>{v.current=k},to:`/domain/${c.domainSlug}/topic/${c.slug}`,onClick:()=>{I.track($.NEXT_BOOK_CLICKED,{from:o.slug,to:c.slug}),r()},className:"flex min-h-11 w-full items-center justify-between rounded-[var(--sb-radius-control)] bg-gold-500 px-4 py-3 text-sm font-bold text-stone-950 transition-colors hover:bg-gold-400 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)]",children:[(0,e.jsxs)("span",{className:"truncate",children:["Read next: ",c.title]}),(0,e.jsx)(ft,{className:"w-4 h-4 flex-shrink-0 ml-2"})]}),f&&(0,e.jsx)(Ze,{to:`/domain/${f}`,onClick:r,className:"flex min-h-11 w-full items-center justify-center px-4 py-2.5 text-sm font-medium text-[var(--sb-ink-muted)] transition-colors hover:text-[var(--sb-ink)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)]",children:"Browse more books"})]}):f&&(0,e.jsxs)(Ze,{ref:k=>{v.current=k},to:`/domain/${f}`,onClick:r,className:"flex min-h-11 w-full items-center justify-between rounded-[var(--sb-radius-control)] bg-[var(--sb-ink)] px-4 py-3 text-sm font-bold text-[var(--sb-surface)] transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)]",children:[(0,e.jsx)("span",{children:"Explore More Books"}),(0,e.jsx)(ft,{className:"w-4 h-4"})]}),(0,e.jsx)("button",{ref:k=>{!b&&!f&&(v.current=k)},onClick:r,className:"min-h-11 w-full px-4 py-3 text-sm font-medium text-[var(--sb-ink-muted)] transition-colors hover:text-[var(--sb-ink)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)]",children:"Continue Exploring"})]})]})})}var Tu=[{id:"content",label:"Content"},{id:"audio",label:"Audio"},{id:"design",label:"Design"}];function _u({bookSlug:a,chapterNumber:r,onDismiss:o}
2){const[h,l]=(0,s.useState)(0),[m,f]=(0,s.useState)(0),[c,b]=(0,s.useState)(),[p,C]=(0,s.useState)(""),[v,k]=(0,s.useState)(!1),[L,D]=(0,s.useState)(!1),re=(0,s.useCallback)(async()=>{try{const{data:{user:E}}=await cs.auth.getUser();if(!E)return;const{justCompleted:te}=await Mi.incrementMission(E.id,"rate_chapters");te&&$i({missionKey:"rate_chapters",xpAwarded:Fi.rate_chapters})}catch(E){console.warn("[ChapterRating] mission tracking unavailable:",E)}},[]),_=(0,s.useCallback)(async E=>{f(E),E>=4&&(D(!0),await cn.submitChapterRating(a,r,E),I.track(ti.CHAPTER_RATED,{book_slug:a,chapter_number:r,rating:E,category:null,had_comment:!1}),k(!0),re(),setTimeout(o,1500))},[a,r,o,re]),V=(0,s.useCallback)(async()=>{m&&(D(!0),await cn.submitChapterRating(a,r,m,c,p||void 0),I.track(ti.CHAPTER_RATED,{book_slug:a,chapter_number:r,rating:m,category:c??null,had_comment:!!p}),k(!0),re(),setTimeout(o,1500))},[a,r,m,c,p,o,re]);return(0,e.jsx)(J,{children:(0,e.jsx)(S.div,{initial:{opacity:0,y:24},animate:{opacity:1,y:0},exit:{opacity:0,y:24},className:"fixed left-1/2 -translate-x-1/2 z-50 w-[calc(100vw-32px)] max-w-sm",style:{bottom:"calc(var(--tab-bar-height, 56px) + env(safe-area-inset-bottom, 0px) + 8px)"},children:(0,e.jsx)("div",{className:"bg-white dark:bg-stone-900 rounded-2xl shadow-2xl border border-stone-200 dark:border-stone-700 p-4",children:v?(0,e.jsx)("div",{className:"text-center py-2",children:(0,e.jsx)("p",{className:"text-sm font-semibold text-stone-900 dark:text-white",children:"Thanks for the feedback! â"})}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,e.jsx)("p",{className:"text-sm font-semibold text-stone-900 dark:text-white",children:"How was this chapter?"}),(0,e.jsx)("button",{onClick:o,className:"p-2 rounded-full hover:bg-stone-100 dark:hover:bg-stone-800 touch-manipulation",children:(0,e.jsx)(Hr,{className:"w-3.5 h-3.5 text-stone-400"})})]}),(0,e.jsx)("div",{className:"flex items-center justify-center gap-2 mb-3",children:[1,2,3,4,5].map(E=>(0,e.jsx)("button",{onClick:()=>_(E),onMouseEnter:()=>l(E),onMouseLeave:()=>l(0),className:"transition-transform active:scale-90",children:(0,e.jsx)(Ri,{className:W("w-8 h-8 transition-colors",(h||m)>=E?"fill-gold-400 text-gold-400":"text-stone-300 dark:text-stone-600")})},E))}),m>0&&m<=3&&(0,e.jsxs)(S.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},children:[(0,e.jsx)("p",{className:"text-xs text-stone-500 mb-2",children:"What was the issue?"}),(0,e.jsx)("div",{className:"flex gap-2 mb-2",children:Tu.map(E=>(0,e.jsx)("button",{onClick:()=>b(E.id),className:W("text-xs px-3 py-1.5 rounded-full border transition-colors",c===E.id?"bg-gold-500 text-white border-gold-500":"border-stone-200 dark:border-stone-700 text-stone-600 dar
2k:text-stone-300"),children:E.label},E.id))}),(0,e.jsx)("textarea",{value:p,onChange:E=>C(E.target.value),placeholder:"Any details? (optional)",rows:2,className:"w-full text-xs p-2 rounded-lg border border-stone-200 dark:border-stone-700 bg-stone-50 dark:bg-stone-800 text-stone-800 dark:text-stone-200 resize-none focus:outline-none focus:ring-1 focus:ring-gold-400 mb-2",maxLength:300}),(0,e.jsx)("button",{onClick:V,disabled:L,className:"w-full py-2 rounded-xl bg-gold-500 text-white text-xs font-bold hover:bg-gold-600 transition-colors disabled:opacity-50",children:L?"Sendingâ¦":"Send Feedback"})]})]})})})})}function Eu({show:a,onChoice:r}){const o=(0,s.useRef)(null);return(0,e.jsx)(qr,{open:a,onOpenChange:(0,s.useCallback)(h=>{h||r("ask")},[r]),placement:"adaptive",swipeToDismiss:!0,initialFocusRef:o,ariaLabel:"Fullscreen reminders",title:(0,e.jsxs)("span",{className:"flex items-center gap-2",children:[(0,e.jsx)("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-[var(--sb-radius-control)] bg-[color-mix(in_srgb,var(--sb-accent)_14%,transparent)] text-[var(--sb-accent)]",children:(0,e.jsx)(zr,{className:"h-4 w-4"})}),"Fullscreen reminders"]}),description:"Show fullscreen reminders in landscape?",className:"sm:max-w-sm",headerClassName:"gap-2 px-4 py-2.5",contentClassName:"flex-[0_1_auto] p-3",children:(0,e.jsxs)("div",{className:"grid gap-2 sm:grid-cols-2",children:[(0,e.jsx)("button",{ref:o,type:"button",onClick:()=>r("always"),className:"inline-flex min-h-11 w-full items-center justify-center rounded-[var(--sb-radius-control)] bg-[var(--sb-accent)] px-4 text-sm font-semibold text-[var(--sb-accent-foreground)] transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)]",children:"Yes, show hints"}),(0,e.jsx)("button",{type:"button",onClick:()=>r("ask"),className:"inline-flex min-h-11 w-full items-center justify-center rounded-[var(--sb-radius-control)] border border-[var(--sb-border)] bg-[var(--sb-surface-subtle)] px-4 text-sm font-semibold text-[var(--sb-ink)] transition-colors hover:border-[var(--sb-border-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)]",children:"Ask me later"}),(0,e.jsx)("button",{type:"button",onClick:()=>r("never"),className:"inline-flex min-h-11 w-full items-center justify-center rounded-[var(--sb-radius-control)] px-4 text-sm font-medium text-[var(--sb-ink-muted)] transition-colors hover:bg-[var(--sb-surface-subtle)] hover:text-[var(--sb-ink)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)] sm:col-span-2",children:"No thanks"})]})})}function Ru(a){const r=`/domain/${a.domainSlug}/topic/${a.bookSlug}`;return`${a.routeChapterSlug?`${r}/${a.routeChapterSlug}`:r}${a.search??""}`}function Iu(a){const r=a.sourceAttribution??null;return Rc(a,"page",{completeness:r?"full":a.sourceType?"partial":"none",sourceType:a.sourceType,sourceAttribution:r},[])}function Au({bookSlug:a,domainColor:r,nextChapter:o,onNavigate:h,onOpenQuiz:l,currentChapterTitle:m="This Chapter",keepIdea:f}){const[c,b]=(0,s.useState)("idle");(0,s.useEffect)(()=>{b("idle")},[f?.text]);const p=(0,s.useCallback)(async()=>{f&&(c!=="idle"&&c!=="error"||(b("pending"),b(await f.onKeep()?"saved":"error")))},[f,c]);return!o&&!l&&!f?null:(0,e.jsxs)(S.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.35,ease:"easeOut"},className:"flex-shrink-0 border-t border-stone-200 dark:border-white/[0.06] px-3 py-3 space-y-2",children:[o&&(0,e.jsxs)(S.button,{type:"button",onClick:()=>h(a,o.domainSlug,o.slug),className:"w-full flex items-center gap-3 p-3 rounded-xl border text-left cursor-pointer transition-all active:scale-[0.98]",style:{backgroundColor:`${r}18`,borderColor:`${r}50`},whileHover:{scale:1.01,backgroundColor:`${r}25`},whileTap:{scale:.98},children:[(0,e.jsx)("div",{className:"w-9 h-9 flex-shrink-0 rounded-lg flex items-center justify-center",style:{backgroundColor:`${r}30`},children:(0,e.jsx)(ft,{className:"w-4 h-4",style:{color:r}})}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsxs)("p",{className:"text-[10px] font-semibold tracking-widest uppercase mb-0.5",style:{color:`${r}CC`},children:["Up Next · Ch. ",o.chapterNumber]}),(0,e.jsx)("p",{className:"text-[13px] font-semibold text-stone-900 dark:text-white leading-snug line-clamp-2",title:o.title,children:o.title})]}),(0,e.jsx)(ft,{className:"w-4 h-4 flex-shrink-0 text-stone-400 dark:text-white/30"})]}),f?(0,e.jsxs)(S.div,{className:"w-full flex items-start gap-3 p-2 rounded-xl bg-stone-100 dar
2k:bg-white/5 border border-stone-200 dark:border-white/10",children:[(0,e.jsx)("div",{className:"w-10 h-10 flex-shrink-0 rounded-lg flex items-center justify-center",style:{backgroundColor:"#10B98120",border:"1px solid #10B98130"},children:(0,e.jsx)(Ni,{className:"w-4 h-4",style:{color:"#10B981"}})}),(0,e.jsx)("div",{className:"flex-1 min-w-0",children:c==="saved"?(0,e.jsx)("p",{className:"text-[12px] font-medium text-emerald-600 dark:text-emerald-400 leading-snug pt-1",children:"Saved â we'll bring it back."}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:"text-[11px] font-semibold tracking-wider uppercase mb-1 text-stone-500 dark:text-white/40",children:"Worth remembering"}),(0,e.jsx)("p",{className:"text-[12px] text-stone-700 dark:text-white/75 leading-snug line-clamp-2",children:f.text}),(0,e.jsx)("button",{type:"button",onClick:p,disabled:c==="pending",className:"mt-2 px-3 py-1 text-[11px] font-semibold rounded-full bg-emerald-500 text-white hover:bg-emerald-600 active:scale-95 transition-all disabled:opacity-60 disabled:cursor-not-allowed",children:c==="pending"?"Savingâ¦":c==="error"?"Couldn't save â try again.":"Keep it"})]})})]}):l&&(0,e.jsxs)(S.button,{type:"button",onClick:l,className:"w-full flex items-start gap-3 p-2 rounded-xl bg-stone-100 dark:bg-white/5 border border-stone-200 dark:border-white/10 hover:bg-stone-200 dark:hover:bg-white/[0.08] hover:border-stone-300 dark:hover:border-white/20 transition-all text-left cursor-pointer",whileHover:{scale:1.01},whileTap:{scale:.99},children:[(0,e.jsx)("div",{className:"w-10 h-10 flex-shrink-0 rounded-lg flex items-center justify-center",style:{backgroundColor:"#D4AF3720",border:"1px solid #D4AF3730"},children:(0,e.jsx)(kc,{className:"w-4 h-4",style:{color:"#D4AF37"}})}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsx)("p",{className:"text-[12px] font-semibold text-stone-800 dark:text-white/85 leading-tight truncate",children:"Test Your Knowledge"}),(0,e.jsxs)("p",{className:"text-[10px] text-stone-400 dark:text-white/30 mt-1 line-clamp-1 leading-snug",children:[m," · 3 questions"]})]})]})]})}var Pu="#EF4444";function Lu({isVisible:a,bookTitle:r,isFullscreen:o,isZenMode:h=!1,onExitFullscreen:l,onBookmark:m,onShare:f,onToggleZen:c,isBookmarked:b=!1,className:p}){const C=vi(),{resolvedTheme:v}=fn(),k=v==="dark",L=()=>{C(-1)},D=[];return m&&D.push({key:"save",icon:Bc,ariaLabel:"Save",onClick:()=>{q("medium"),m()},active:b,activeColor:Pu}),f&&D.push({key:"share",icon:Uc,ariaLabel:"Share",onClick:()=>{q("light"),f()}}),(0,e.jsx)(J,{children:a&&(0,e.jsx)(e.Fragment,{children:(0,e.jsx)(S.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.3,ease:"easeOut"},className:W("fixed top-0 left-0 right-0 z-50","pt-safe px-2",p),style:{background:k?"linear-gradient(to bottom, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.22) 60%, transparent 100%)":"linear-gradient(to bottom, rgba(255,255,255,0.88) 0%, rgba(255,255,255,0.45) 60%, transparent 100%)",backdropFilter:"blur(24px)",WebkitBackdropFilter:"blur(24px)"},children:(0,e.jsxs)("div",{className:"h-16 px-2 flex items-center justify-between",children:[!h&&(0,e.jsx)("button",{onClick:()=>{q("light"),L()},className:W("w-10 h-10 flex items-center justify-center rounded-full active:scale-90 transition-all touch-manipulation",k?"text-white/90 hover:text-white hover:bg-white/10":"text-stone-700 hover:text-stone-900 hover:bg-black/8"),"aria-label":"Go back",children:(0,e.jsx)(an,{className:"w-6 h-6"})}),(0,e.jsx)("h1",{className:W("flex-1 px-4 font-bold text-sm sm:text-base truncate text-center drop-shadow-sm transition-opacity duration-500",k?"text-white":"text-stone-900",h?"opacity-0":"opacity-100"),style:{fontFamily:"var(--premium-display)"},children:r}),(0,e.jsxs)("div",{className:"flex items-center gap-1",children:[c&&(0,e.jsx)("button",{onClick:()=>{q("medium"),c()},className:W("w-10 h-10 flex items-center justify-center rounded-full active:scale-90 transition-all touch-manipulation focus-visible:outline-none focus-visible:ring-2",k?"text-white/90 hover:text-white hover:bg-white/10 focus-visible:ring-white/50":"text-stone-700 hover:text-stone-900 hover:bg-black/8 focus-visible:ring-stone-400/50"),"aria-label":h?"Exit Zen Mode":"Enter Zen Mode",children:h?(0,e.jsx)(Lc,{className:"w-5 h-5"}):(0,e.jsx)(Fc,{className:"w-5 h-5"})}),o&&l&&(0,e.jsx)("button",{onClick:()=>{q("light"),l()},className:W("w-10 h-10 flex items-center justify-center rounded-full active:scale-90 transition-all touch-manipulation focus-visible:outline-none focus-visible:ring-2",k?"text-white/90 hover:text-white hover:bg-white/10 focus-visible:ring-white/50":"text-stone-700 hover:text-stone-900 hover:bg-black/8 focus-visible:ring-stone-400/50"),"aria-label":"Exit fullscreen",children:(0,e.jsx)(Si,{className:"w-5 h-5"})}),!h&&(m||f)&&(0,e.jsx)(Sc,{orientation:"horizontal",theme:k?"dark":"adaptive",actions:D})]})]})})})})}var Fu=[{title:"Playback",shortcuts:[{key:"Space",description:"Play / Pause"},{key:"J",description:"Rewind 10 seconds"},{key:"L",description:"Forward 10 seconds"},{key:"Shift + â",description:"Rewind 10 seconds"},{key:"Shift + â",description:"Forward 10 seconds"},{key:"S",description:"Change playback speed"},{key:"A",description:"Toggle autoplay"}]},{title:"Navigation and view",shortcuts:[{key:"â",description:"Previous chapter"}
2,{key:"â",description:"Next chapter"},{key:"F",description:"Toggle fullscreen"},{key:"?",description:"Show or close shortcuts"},{key:"Esc",description:"Close or exit fullscreen"}]}];function $u({isOpen:a,onClose:r}){return(0,e.jsx)(ud,{isOpen:a,onClose:r,title:"Reader shortcuts",ariaLabel:"Reader keyboard shortcuts",groups:Fu})}function Mu(a){const{bookId:r,chapterId:o}=a,{isBookFree:h,isChapterUnlocked:l,getPromoForBook:m,recordUnlock:f}=Pi(),c=r??"",b=o??"",p=c?h(c):!1,C=c?m(c):null;return(0,s.useEffect)(()=>{!c||!b||h(c)&&(l(b)||f(b,m(c)?.id??null))},[c,b]),{isFreePromo:p,promo:C}}var Ou=gi(fc(),1),Di="seen_promo_toast_",Bu=6e3,Ui=60*1e3,un=60*Ui,di=24*un;function Du(a){if(!a)return"";const r=new Date(a).getTime();if(Number.isNaN(r))return"";const o=r-Date.now();if(o<=0)return"";if(o>=di){const l=Math.round(o/di);return l===1?"1 day":`${l} days`}if(o>=un){const l=Math.round(o/un);return l===1?"1 hour":`${l} hours`}const h=Math.max(1,Math.round(o/Ui));return h===1?"1 minute":`${h} minutes`}function Uu(a){try{return typeof window<"u"&&window.localStorage?.getItem(Di+a)==="1"}catch{return!1}}function zu(a){try{window.localStorage?.setItem(Di+a,"1")}catch{}}function Hu({isFreePromo:a,promo:r,bookId:o}){const[h,l]=(0,s.useState)(!1);if((0,s.useEffect)(()=>{if(!a||!o||!r||Uu(o))return;l(!0),zu(o);const c=window.setTimeout(()=>l(!1),Bu);return()=>window.clearTimeout(c)},[o,a]),typeof document>"u"||!a||!r||!o)return null;const m=Du(r.endsAt),f=m?`ð This book is free for ${m} â your progress is saved forever.`:"ð This book is free â read at your own pace.";return(0,Ou.createPortal)((0,e.jsx)(J,{children:h&&(0,e.jsxs)(S.div,{initial:{y:24,opacity:0,scale:.95},animate:{y:0,opacity:1,scale:1},exit:{y:16,opacity:0,scale:.96},transition:{type:"spring",stiffness:320,damping:28},role:"status","aria-live":"polite","data-testid":"free-promo-toast",className:"fixed bottom-[calc(var(--tab-bar-height,0px)+var(--player-bar-height,0px)+env(safe-area-inset-bottom,0px)+0.75rem)] left-1/2 -translate-x-1/2 z-[120] w-[calc(100vw-2rem)] max-w-md px-3 py-2.5 md:bottom-4 md:w-auto md:min-w-80 rounded-[var(--sb-radius-surface)] shadow-2xl flex items-center gap-3 bg-emerald-600/95 text-white backdrop-blur-md ring-1 ring-emerald-300/40",children:[(0,e.jsx)(Wr,{className:"w-5 h-5 mt-0.5 flex-shrink-0 text-white"}),(0,e.jsx)("p",{className:"flex-1 text-sm font-semibold leading-snug",children:f}),(0,e.jsx)("button",{type:"button",onClick:()=>l(!1),"aria-label":"Dismiss free book notice",className:"flex min-h-11 min-w-11 flex-shrink-0 items-center justify-center rounded-full text-white/80 hover:text-white hover:bg-white/10 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white",children:(0,e.jsx)(Hr,{className:"w-4 h-4"})})]},"free-promo-toast")}),document.body)}var _e=8,qs=100/_e,hn=_e*_e;function zi(a){const r=Math.floor(a/_e);return{x:a%_e*qs,y:r*qs,width:qs,height:qs}}function Wu(a){const r=[];for(let o=0;o<hn;o++){const h=zi(o),l=h.x+h.width,m=h.y+h.height,f=a.x+a.width,c=a.y+a.height,b=a.x<l&&f>h.x,p=a.y<m&&c>h.y;b&&p&&r.push(o)}return r.length>0?r:[27,28,35,36]}function ui({activeRegions:a,focusRegion:r,intensity:o=.35,edgeSoftness:h=6,isActive:l=!0}){const m=(0,s.useMemo)(()=>a&&a.length>0?a:r?Wu(r):[27,28,35,36],[a,r]),f=(0,s.useMemo)(()=>`grid-spotlight-mask-${Math.random().toString(36).substr(2,9)}`,[]),c=(0,s.useMemo)(()=>`grid-blur-${Math.random().toString(36).substr(2,9)}`,[]);return l?(0,e.jsxs)(S.svg,{className:"absolute inset-0 w-full h-full pointer-events-none z-10",initial:{opacity:0}
2,animate:{opacity:1},exit:{opacity:0},transition:{duration:.4},preserveAspectRatio:"none",children:[(0,e.jsxs)("defs",{children:[(0,e.jsx)("filter",{id:c,x:"-10%",y:"-10%",width:"120%",height:"120%",children:(0,e.jsx)("feGaussianBlur",{in:"SourceGraphic",stdDeviation:h})}),(0,e.jsxs)("mask",{id:f,children:[(0,e.jsx)("rect",{width:"100%",height:"100%",fill:"white"}),m.map(b=>{const p=zi(b);return(0,e.jsx)(S.rect,{x:`${p.x}%`,y:`${p.y}%`,width:`${p.width}%`,height:`${p.height}%`,fill:"black",filter:`url(#${c})`,initial:{opacity:0},animate:{opacity:1},transition:{duration:.25,delay:Math.min(b*.01,.3)}},b)})]})]}),(0,e.jsx)(S.rect,{width:"100%",height:"100%",fill:`rgba(0,0,0,${o})`,mask:`url(#${f})`,initial:{opacity:0},animate:{opacity:1},transition:{duration:.5}})]}):null}var Qe=a=>Array.from({length:_e},(r,o)=>a*_e+o),Je=a=>Array.from({length:_e},(r,o)=>o*_e+a),Y=(a,r,o,h)=>{const l=[];for(let m=a;m<a+o&&m<_e;m++)for(let f=r;f<r+h&&f<_e;f++)l.push(m*_e+f);return l},Qh={GRID_SIZE:_e,CELL_PERCENT:qs,TOTAL_CELLS:hn,row:Qe,col:Je,rect:Y,ROW_0:Qe(0),ROW_1:Qe(1),ROW_2:Qe(2),ROW_3:Qe(3),ROW_4:Qe(4),ROW_5:Qe(5),ROW_6:Qe(6),ROW_7:Qe(7),COL_0:Je(0),COL_1:Je(1),COL_2:Je(2),COL_3:Je(3),COL_4:Je(4),COL_5:Je(5),COL_6:Je(6),COL_7:Je(7),QUADRANT_TOP_LEFT:Y(0,0,4,4),QUADRANT_TOP_RIGHT:Y(0,4,4,4),QUADRANT_BOTTOM_LEFT:Y(4,0,4,4),QUADRANT_BOTTOM_RIGHT:Y(4,4,4,4),TOP_HALF:Y(0,0,4,8),BOTTOM_HALF:Y(4,0,4,8),LEFT_HALF:Y(0,0,8,4),RIGHT_HALF:Y(0,4,8,4),CENTER_SMALL:Y(3,3,2,2),CENTER_MEDIUM:Y(2,2,4,4),CENTER_LARGE:Y(1,1,6,6),TITLE_AREA:Y(0,0,2,8),MAIN_CHART:Y(2,0,4,6),SIDEBAR:Y(0,6,8,2),FOOTER_AREA:Y(6,0,2,8),KEY_TAKEAWAYS:Y(1,5,3,3),DIAGONAL_MAIN:[0,9,18,27,36,45,54,63],DIAGONAL_ANTI:[7,14,21,28,35,42,49,56],BORDER:[...Qe(0),...Qe(7),...Je(0).slice(1,7),...Je(7).slice(1,7)],ALL:Array.from({length:hn}
2,(a,r)=>r),HEADER_TITLE:Y(0,0,1,5),HEADER_STAT:Y(0,5,1,3),CHART_FULL:Y(1,0,5,5),CHART_TOP:Y(1,0,2,5),CHART_MIDDLE:Y(2,0,2,5),CHART_BOTTOM:Y(4,0,2,5),RIGHT_TOP:Y(1,5,2,3),RIGHT_MIDDLE:Y(3,5,2,3),RIGHT_BOTTOM:Y(5,5,2,3),BOTTOM_FULL:Y(6,0,2,8),BOTTOM_LEFT:Y(6,0,2,4),BOTTOM_RIGHT:Y(6,4,2,4),getCell:(a,r)=>[a*_e+r],getCells:(...a)=>a.map(([r,o])=>r*_e+o)};function qu({section:a,position:r="right",showKeyPoints:o=!0}){if(!a||!o||a.keyPoints.length===0)return null;const h={left:"left-8",right:"right-8",auto:a.annotationPosition==="left"?"left-8":"right-8"};return(0,e.jsx)(J,{mode:"wait",children:(0,e.jsxs)(S.div,{className:`absolute top-1/2 -translate-y-1/2 ${h[r]} max-w-sm z-20`,initial:{opacity:0,x:r==="left"?-30:30,scale:.95},animate:{opacity:1,x:0,scale:1},exit:{opacity:0,x:r==="left"?-20:20,scale:.95},transition:{type:"spring",stiffness:300,damping:25,mass:.8},children:[(0,e.jsxs)("div",{className:"relative overflow-hidden rounded-2xl",children:[(0,e.jsx)("div",{className:"absolute inset-0 bg-white/95 dark:bg-stone-900/95 backdrop-blur-xl",style:{backdropFilter:"blur(20px) saturate(180%)",WebkitBackdropFilter:"blur(20px) saturate(180%)"}}),(0,e.jsx)("div",{className:"absolute inset-0 opacity-30",style:{background:"linear-gradient(135deg, rgba(212, 175, 55, 0.1) 0%, transparent 50%)"}}),(0,e.jsx)("div",{className:"absolute inset-0 rounded-2xl",style:{boxShadow:"inset 0 0 0 1px rgba(255, 255, 255, 0.2), inset 0 1px 0 0 rgba(255, 255, 255, 0.3)"}}),(0,e.jsxs)("div",{className:"relative p-5",children:[(0,e.jsxs)(S.div,{className:"flex items-center gap-2 mb-4",initial:{opacity:0,y:-10},animate:{opacity:1,y:0},transition:{delay:.1},children:[(0,e.jsx)("div",{className:"w-1 h-4 rounded-full bg-gradient-to-b from-gold-400 to-gold-600"}),(0,e.jsx)("span",{className:"text-xs font-semibold uppercase tracking-[0.15em] text-gold-700 dark:text-gold-400",children:a.title})]}),(0,e.jsx)("ul",{className:"space-y-3",children:a.keyPoints.slice(0,4).map((l,m)=>(0,e.jsxs)(S.li,{className:"flex items-start gap-3",initial:{opacity:0,x:-15},animate:{opacity:1,x:0},transition:{delay:.15+m*.08,type:"spring",stiffness:200,damping:20},children:[(0,e.jsx)(S.span,{className:"w-2 h-2 rounded-full bg-gradient-to-br from-gold-400 to-gold-600 mt-1.5 flex-shrink-0",initial:{scale:0},animate:{scale:1},transition:{delay:.2+m*.08,type:"spring",stiffness:400}}),(0,e.jsx)("span",{className:"text-sm text-stone-700 dark:text-stone-300 leading-relaxed font-medium",children:l})]},m))}),a.keyPoints.length>4&&(0,e.jsx)(S.div,{className:"mt-3 pt-3 border-t border-stone-200/50 dark:border-stone-700/50",initial:{opacity:0}
2,animate:{opacity:1},transition:{delay:.5},children:(0,e.jsxs)("span",{className:"text-xs text-stone-400",children:["+",a.keyPoints.length-4," more points"]})})]}),(0,e.jsx)("div",{className:"absolute inset-0 -z-10 rounded-2xl",style:{boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.15), 0 12px 24px -8px rgba(0, 0, 0, 0.1)"}})]}),(0,e.jsx)(S.div,{className:`absolute top-1/2 ${r==="left"?"right-0 translate-x-full":"left-0 -translate-x-full"} w-8 h-px`,initial:{scaleX:0,opacity:0},animate:{scaleX:1,opacity:.3},transition:{delay:.3,duration:.3},style:{background:r==="left"?"linear-gradient(to right, rgba(212, 175, 55, 0.5), transparent)":"linear-gradient(to left, rgba(212, 175, 55, 0.5), transparent)",transformOrigin:r==="left"?"left":"right"}})]},a.id)})}function Vu({sections:a,currentIndex:r,onSectionClick:o,orientation:h="vertical"}){if(a.length===0)return null;const l=h==="vertical";return(0,e.jsx)("div",{className:`flex ${l?"flex-col":"flex-row"} gap-0 items-center`,role:"navigation","aria-label":"Lesson sections",children:a.map((m,f)=>{const c=f<r,b=f===r;return(0,e.jsxs)("div",{className:`flex ${l?"flex-col":"flex-row"} items-center`,children:[(0,e.jsxs)(S.button,{onClick:()=>o(f),className:"relative group ",whileHover:{scale:1.2},whileTap:{scale:.9},title:m.title,"aria-label":`Go to ${m.title}`,"aria-current":b?"step":void 0,children:[(0,e.jsx)(S.div,{className:`w-4 h-4 rounded-full border-2 flex items-center justify-center transition-all duration-300 3 ${c?"bg-emerald-500 border-emerald-500":b?"bg-gold-500 border-gold-500":"bg-transparent border-stone-500 hover:border-stone-400"}`,initial:{scale:0},animate:{scale:1},transition:{delay:f*.05,type:"spring",stiffness:300},children:c&&(0,e.jsx)(pn,{className:"w-2.5 h-2.5 text-white",strokeWidth:3})}),b&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(S.div,{className:"absolute inset-0 rounded-full border-2 border-gold-400",animate:{scale:[1,1.6,1.6],opacity:[.6,0,0]},transition:{duration:2,repeat:1/0,ease:"easeOut"}}),(0,e.jsx)(S.div,{className:"absolute inset-0 rounded-full border-2 border-gold-400",animate:{scale:[1,1.4,1.4],opacity:[.8,0,0]},transition:{duration:2,repeat:1/0,ease:"easeOut",delay:.5}})]}),(0,e.jsx)("div",{className:`absolute ${l?"left-8":"bottom-8 left-1/2 -translate-x-1/2"} 4 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-30`,children:(0,e.jsxs)("div",{className:"bg-stone-900 text-white text-xs px-3 py-1.5 rounded-lg whitespace-nowrap shadow-lg",children:[m.title,(0,e.jsx)("div",{className:`absolute ${l?"right-full top-1/2 -translate-y-1/2":"top-full left-1/2 -translate-x-1/2"} 5 w-0 h-0 border-4 ${l?"border-r-stone-900 border-l-transparent border-y-transparent":"border-t-stone-900 border-b-transparent border-x-transparent"}`})]})})]}),f<a.length-1&&(0,e.jsx)(S.div,{className:`${l?"w-0.5 h-6":"w-6 h-0.5"} mx-1 my-1`,initial:{opacity:0}
5,animate:{opacity:1},transition:{delay:f*.05+.1},children:(0,e.jsx)("div",{className:`w-full h-full rounded-full transition-colors duration-300 ${f<r?"bg-emerald-500":"bg-stone-600"}`})})]},m.id)})})}function hi({focusRegion:a,isActive:r=!0,color:o="gold",intensity:h="medium"}){if(!r)return null;const l={gold:{border:"border-gold-400",glow:"rgba(212, 175, 55, 0.4)",ring:"rgba(212, 175, 55, 0.6)"},emerald:{border:"border-emerald-400",glow:"rgba(16, 185, 129, 0.4)",ring:"rgba(16, 185, 129, 0.6)"},blue:{border:"border-blue-400",glow:"rgba(59, 130, 246, 0.4)",ring:"rgba(59, 130, 246, 0.6)"}},m={subtle:{opacity:.3,blur:"4px",scale:1.03},medium:{opacity:.5,blur:"8px",scale:1.05},strong:{opacity:.7,blur:"12px",scale:1.08}},f=l[o],c=m[h];return(0,e.jsx)(J,{children:(0,e.jsxs)("div",{className:"absolute pointer-events-none z-10",style:{left:`${a.x}%`,top:`${a.y}%`,width:`${a.width}%`,height:`${a.height}%`},children:[(0,e.jsx)(S.div,{className:`absolute inset-0 rounded-xl ${f.border} border-2`,initial:{opacity:0},animate:{opacity:c.opacity},style:{boxShadow:`0 0 ${c.blur} ${f.glow}, inset 0 0 ${c.blur} ${f.glow}`}}),(0,e.jsx)(S.div,{className:`absolute inset-0 rounded-xl border-2 ${f.border}`,animate:{scale:[1,c.scale,c.scale],opacity:[c.opacity,0,0]},transition:{duration:2.5,repeat:1/0,ease:"easeOut"}}),(0,e.jsx)(S.div,{className:`absolute inset-0 rounded-xl border ${f.border}`,animate:{scale:[1,c.scale*1.02,c.scale*1.02],opacity:[c.opacity*.7,0,0]},transition:{duration:2.5,repeat:1/0,ease:"easeOut",delay:.8}}
5),["top-0 left-0","top-0 right-0","bottom-0 left-0","bottom-0 right-0"].map((b,p)=>(0,e.jsx)(S.div,{className:`absolute ${b} w-4 h-4`,initial:{opacity:0},animate:{opacity:.8},transition:{delay:.3+p*.1},children:(0,e.jsx)("div",{className:`absolute ${b.includes("left")?"left-0":"right-0"} 6 ${b.includes("top")?"top-0":"bottom-0"} 7 w-3 h-3`,style:{borderWidth:"2px 0 0 2px",borderColor:f.ring,borderTopLeftRadius:"4px",transform:`rotate(${p*90}deg)`,transformOrigin:b.includes("left")?b.includes("top")?"0 0":"0 100%":b.includes("top")?"100% 0":"100% 100%"}})},p)),(0,e.jsx)(S.div,{className:"absolute inset-0 rounded-xl",animate:{boxShadow:[`0 0 20px ${f.glow}`,`0 0 40px ${f.glow}`,`0 0 20px ${f.glow}`]},transition:{duration:3,repeat:1/0,ease:"easeInOut"}})]})})}var ds=(a,r)=>(0,s.lazy)(()=>a().then(o=>{const h=(r?o[r]:null)||o.default;if(!h)throw new Error(`Component not found in module: ${r||"default"}`);return{default:h}}).catch(o=>{throw console.error(`Failed to load lazy component ${r||""}`,o),o})),Yu=ds(()=>fe(()=>import("./GlobalSearchModal-sImSI1nB.js"),__vite__mapDeps([34,2,3,1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49])),"GlobalSearchModal"),Ku=ds(()=>fe(()=>import("./BookChatPanel-CzyypN4s.js"),__vite__mapDeps([50,2,3,51,4,1,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,52,53,39,54,55,56,57,58,59,60,61,62,63,42,43,64,48,65,66,67,68,69,70,45,37,38,40,41,44,46])),"BookChatPanel"),Gu=ds(()=>fe(()=>import("./BookChatPanel-CzyypN4s.js"),__vite__mapDeps([50,2,3,51,4,1,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,52,53,39,54,55,56,57,58,59,60,61,62,63,42,43,64,48,65,66,67,68,69,70,45,37,38,40,41,44,46])),"BookChatPanelBody"),Xu=ds(()=>fe(()=>import("./ActionItemsPanel-C4s62Mps.js"),__vite__mapDeps([71,2,3,1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,72,58,38,39,40,37,41,42,43,44,45,46,65])),"ActionItemsPanel"),Qu=(0,s.lazy)(()=>fe(()=>import("./ChapterQuizModal-sqvcLFlN.js").then(a=>({default:a.ChapterQuizModal})),__vite__mapDeps([73,2,3,1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,39,57,74,41,75,44,45])).catch(a=>{throw console.error("Failed to load ChapterQuizModal",a),a})),Ju=(0,s.lazy)(()=>fe(()=>import("./ChapterRecallBeat-B4HBpMwU.js").then(a=>({default:a.ChapterRecallBeat})),__vite__mapDeps([76,2,3,55,6,56,77,78,44,5,45,18,19])).catch(a=>{throw console.error("Failed to load ChapterRecallBeat",a),a})),Zu=(0,s.lazy)(()=>fe(()=>import("./ActorFlashcardModal-BkjLMoX-.js").then(a=>({default:a.ActorFlashcardModal})),__vite__mapDeps([79,2,3,6,56,80,81,16,44,5,45,18,19,82,83,24,29])).catch(a=>{throw console.error("Failed to load ActorFlashcardModal",a),a})),e0=(0,s.lazy)(()=>fe(()=>import("./ChapterCompleteSheet-BJP8oeu4.js").then(a=>({default:a.ChapterCompleteSheet})),__vite__mapDeps([84,2,3,1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,39,55,85,66,56,75,44,45])).catch(a=>{throw console.error("Failed to load ChapterCompleteSheet",a),a})),t0=(0,s.lazy)(()=>fe(()=>import("./SaveIdeasSheet-DuBQUZ6o.js").then(a=>({default:a.SaveIdeasSheet})),__vite__mapDeps([86,2,3,1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,39,54,85,56,44,45,87,88])).catch(a=>{throw console.error("Failed to load SaveIdeasSheet",a),a})),s0=(0,s.lazy)(()=>fe(()=>import("./IdeaPlayground-DbMueYhU.js").then(a=>({default:a.IdeaPlayground})),__vite__mapDeps([89,2,3,1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,39,54,55,66,68,90,91,92,93,94,85,56,67,57,95,96,97,98,99,100,101,102,43,103,49,48])).catch(a=>{throw console.error("Failed to load IdeaPlayground",a),a})),r0=(0,s.lazy)(()=>fe(()=>import("./ActorHome-Jn0ID93D.js").then(a=>({default:a.ActorHome})),__vite__mapDeps([104,2,3,1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,55,66,56,105,77,35,81,106,107,97,78,90,45])).catch(a=>{throw console.error("Failed to load ActorHome",a),a})),mi="__scrollbookImmersiveFullscreen",Br=(0,s.lazy)(()=>fe(()=>import("./StoryBeatsRenderer-CDzIMu-G.js").then(a=>a.t).then(a=>({default:a.StoryBeatsRenderer})),__vite__mapDeps([108,2,3,1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,39,109,110,111,112])).catch(a=>(console.error("Failed to load StoryBeatsRenderer",a),{default:()=>(0,e.jsx)(e.Fragment,{})})));ds(()=>fe(()=>import("./ImmersiveAudioBar-B71jIa0J.js"),__vite__mapDeps([113,2,3,114,6,68,115,116,117,118,119,78,120,121,122,62,18,19])),"ImmersiveAudioBar");var fi=ds(()=>fe(()=>import("./ReadingTranscript-DU4vECGY.js"),__vite__mapDeps([123,2,3,1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,124,70,45,125,108,39,109,110,111,112,126,55,56,
7115,117,118,78,120,122,62,48,127,128,129,130,131,132,87,88,133])),"ReadingTranscript"),a0={initial:{opacity:0,y:20},animate:{opacity:1,y:0,transition:{duration:.4,ease:"easeOut"}},exit:{opacity:0,y:-20,transition:{duration:.3}}},rn="9 / 16";function He(a,r){return r<=0?0:a===2?-r:a===1?-Math.round(r*.42):0}function pi(a,r){return a?a.replace(/^\d+-/,"").split("-").filter(Boolean).map(o=>{const h=o.toLowerCase();return["ai","llm","roi","ml"].includes(h)?h.toUpperCase():o.charAt(0).toUpperCase()+o.slice(1)}).join(" "):r}function xi(a,r,o){const h=a,l=h?.prefetchedTopic,m=h?.prefetchedDomain,f=!!l&&l.slug===o&&l.domainSlug===r,c=!!m&&m.slug===r;return{topic:f?l:null,domain:f&&c?m:null}}function n0({bookLabel:a,chapterLabel:r}){return(0,e.jsxs)("div",{"data-testid":"reader-loading-skeleton",role:"status","aria-live":"polite","aria-label":`Loading ${r}`,className:"min-h-screen bg-stone-50 dark:bg-stone-950",children:[(0,e.jsxs)("div",{className:"hidden lg:flex h-screen flex-col bg-[#0a0a0a]",children:[(0,e.jsx)("div",{className:"bg-black/80 border-b border-white/5 flex-shrink-0",children:(0,e.jsxs)("div",{className:"flex items-center h-10 px-3 gap-3",children:[(0,e.jsx)("div",{className:"w-4 h-4 rounded bg-white/10 animate-pulse"}),(0,e.jsx)("div",{className:"w-px h-4 bg-white/10"}),(0,e.jsx)("div",{className:"w-6 h-5 rounded bg-white/10 animate-pulse"}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsx)("p",{className:"truncate text-sm font-semibold text-white/90",children:r}),(0,e.jsx)("p",{className:"truncate text-xs text-white/50",children:a})]}),(0,e.jsxs)("div",{className:"flex gap-1",children:[(0,e.jsx)("div",{className:"w-7 h-7 rounded-md bg-white/5 animate-pulse"}),(0,e.jsx)("div",{className:"w-7 h-7 rounded-md bg-white/5 animate-pulse"})]})]})}),(0,e.jsxs)("div",{className:"flex flex-1 overflow-hidden",children:[(0,e.jsx)("div",{className:"flex-1 bg-[#FAF9F6] dark:bg-stone-950 flex items-center justify-center p-4",children:(0,e.jsx)($r,{className:"w-full max-w-sm aspect-[3/4] rounded-2xl shadow-xl"})}),(0,e.jsx)("div",{className:"w-[340px] flex-shrink-0 border-l border-white/5 p-4 space-y-4",children:[1,2,3,4].map(o=>(0,e.jsxs)("div",{className:"rounded-xl bg-white/5 p-4 space-y-3",children:[(0,e.jsx)($r,{className:"h-3 w-20"}),(0,e.jsx)($r,{className:"h-4 w-full"}),(0,e.jsx)($r,{className:"h-3 w-3/4"})]},o))})]}),(0,e.jsxs)("div",{className:"h-14 bg-black/80 border-t border-white/5 flex items-center px-4 gap-4 flex-shrink-0",children:[(0,e.jsx)("div",{className:"w-8 h-8 rounded-full bg-white/10 animate-pulse"}),(0,e.jsx)("div",{className:"flex-1 h-1 rounded-full bg-white/10 animate-pulse"}),(0,e.jsx)("div",{className:"w-16 h-3 rounded bg-white/10 animate-pulse"})]})]}),(0,e.jsxs)("div",{className:"lg:hidden min-h-screen bg-stone-50 dark:bg-stone-950",children:[(0,e.jsx)("div",{className:"flex min-h-14 items-center border-b border-stone-200 bg-white px-4 dark:border-stone-800 dark:bg-stone-900",children:(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("p",{className:"truncate text-sm font-semibold text-stone-900 dark:text-white",children:r}),(0,e.jsx)("p",{className:"truncate text-xs text-stone-500 dark:text-stone-400",children:a})]})}),(0,e.jsx)("div",{className:"max-w-7xl mx-auto sm:px-3 sm:pt-3",children:(0,e.jsxs)("div",{className:"bg-white dark:bg-stone-900 sm:rounded-xl overflow-hidden border-x-0 sm:border border-stone-200 dark:border-stone-800 shadow-sm",children:[(0,e.jsxs)("div",{className:"hidden sm:flex bg-stone-100 dark:bg-stone-900 px-3 py-2 items-center gap-2",children:[(0,e.jsx)("div",{className:"w-7 h-7 rounded-lg bg-stone-200 dark:bg-stone-800 animate-pulse"}),(0,e.jsx)("div",{className:"flex-1 flex justify-center",children:(0,e.jsx)("div",{className:"h-4 w-48 rounded bg-stone-200 dark:bg-stone-800 animate-pulse"})}),(0,e.jsx)("div",{className:"w-7 h-7 rounded-lg bg-stone-200 dark:bg-stone-800 animate-pulse"})]}),(0,e.jsx)("div",{className:"bg-white dark:bg-stone-900 flex items-center justify-center min-h-[60vh] sm:min-h-[70vh]",children:(0,e.jsx)("div",{className:"w-[85%] aspect-[3/4] max-h-[75vh] rounded bg-stone-100 dar
7k:bg-stone-800 animate-pulse"})}),(0,e.jsxs)("div",{className:"hidden sm:flex bg-stone-100 dark:bg-stone-900 px-3 py-2 items-center gap-3",children:[(0,e.jsx)("div",{className:"w-8 h-8 rounded-full bg-stone-200 dark:bg-stone-800 animate-pulse"}),(0,e.jsx)("div",{className:"flex-1 h-1.5 rounded-full bg-stone-200 dark:bg-stone-800 animate-pulse"}),(0,e.jsx)("div",{className:"w-12 h-3 rounded bg-stone-200 dark:bg-stone-800 animate-pulse"}),(0,e.jsx)("div",{className:"w-6 h-6 rounded bg-stone-200 dark:bg-stone-800 animate-pulse"})]})]})})]})]})}var mn="scrollbook_progress";function o0(a){try{const r=localStorage.getItem(mn);if(r)return JSON.parse(r)[a]||[]}catch{}return[]}function i0(a,r){try{const o=localStorage.getItem(mn),h=o?JSON.parse(o):{};h[a]=r,localStorage.setItem(mn,JSON.stringify(h))}catch{}}function bi({color:a,prefersReducedMotion:r}){return r?(0,e.jsxs)("div",{className:"absolute inset-0 pointer-events-none overflow-hidden z-0","aria-hidden":"true",children:[(0,e.jsx)("div",{className:"absolute -top-[10%] -right-[10%] w-[80%] h-[80%] rounded-full blur-[130px] opacity-[0.07]",style:{background:`radial-gradient(circle, ${a} 0%, transparent 70%)`}}),(0,e.jsx)("div",{className:"absolute -bottom-[10%] -left-[10%] w-[70%] h-[70%] rounded-full blur-[110px] opacity-[0.05]",style:{background:`radial-gradient(circle, ${a} 0%, transparent 70%)`}})]}):(0,e.jsxs)("div",{className:"absolute inset-0 pointer-events-none overflow-hidden z-0","aria-hidden":"true",children:[(0,e.jsx)(S.div,{animate:{scale:[1,1.15,1],opacity:[.07,.12,.07],x:[0,40,0],y:[0,-30,0]},transition:{duration:18,repeat:1/0,ease:"linear"},className:"absolute -top-[10%] -right-[10%] w-[80%] h-[80%] rounded-full blur-[130px]",style:{background:`radial-gradient(circle, ${a} 0%, transparent 70%)`}}),(0,e.jsx)(S.div,{animate:{scale:[1,1.1,1],opacity:[.05,.09,.05],x:[0,-30,0],y:[0,40,0]},transition:{duration:25,repeat:1/0,ease:"linear"},className:"absolute -bottom-[10%] -left-[10%] w-[70%] h-[70%] rounded-full blur-[110px]",style:{background:`radial-gradient(circle, ${a} 0%, transparent 70%)`}})]})}function Jh(){const{domainSlug:a,topicSlug:r,chapterSlug:o}=uc();(0,s.useEffect)(()=>{window.scrollTo(0,0)},[r]);const h=vi(),l=hc(),m=l.state?.scrollReturnTo||new URLSearchParams(l.search).get("returnTo"),f=o&&a&&r?Ed({state:l.state,queryReturnTo:new URLSearchParams(l.search).get("returnTo"),fallbackParentPath:os.book(a,r)}):null,c=f?.parentPath??m,b=wd(c)?c:null,p=f?.originPath??(f?null:b),C=a&&r?`${os.book(a,r)}${p?`?returnTo=${encodeURIComponent(p)}`:""}`:b,v=(0,s.useCallback)(((t,n)=>{if(typeof t=="number")return h(t);if(typeof t=="string"&&t.includes("/topic/")){const[d,y=""]=t.split("?"),j=new URLSearchParams(y);p&&j.set("returnTo",p);const N=new URLSearchParams(l.search).get("view");N&&!j.has("view")&&!j.has("surface")&&j.set("view",N);const B=typeof n?.state=="object"&&n.state!==null?n.state:{},X=!!(b&&d===b.split(/[?#]/,1)[0]);return h(`${d}?${j}`,{...n,state:{...f??{},...B,scrollReturnTo:f?.parentPath??b,...X?{sectionTransition:"back"}:{}}})}return h(t,n)}),[f,h,b,p,l.search]),k=xi(l.state,a,r),L=(0,s.useRef)(l.state?.fromScrollOrientation===!0).current,D=(0,s.useRef)(l.state?.continuePlaying===!0),{setChapterInfo:re,setPlaylist:_,setPlaylistAutoAdvanceEnabled:V,setPersistenceHandlers:E,setCurrentAudioPath:te}=Gc(),[A,K]=mc(),{celebrateChapterComplete:Ee,celebrateBookComplete:be}=Yd(),{isAuthenticated:R,isPremium:O,isLoading:ne,user:F,profile:ie}=ki(),ge=Ai&&ie?.isAdmin===!0,{isBookFree:pt,isChapterUnlocked:ke,isLoading:us}=Pi(),{theme:at,resolvedTheme:$e,toggleTheme:Ys}=fn(),[we,he]=(0,s.useState)(()=>{try{return localStorage.getItem("scrollbook-font-size")||"md"}catch{return"md"}}),Ks=()=>{he(t=>{const n=["sm","md","lg"],d=n[(n.indexOf(t)+1)%n.length];try{localStorage.setItem("scrollbook-font-size",d)}catch{}return d})},qe=$e==="dark"?"bg-black/40 backdrop-blur-sm border border-white/20 text-white/80 active:text-white active:bg-black/60":"bg-white/80 backdrop-blur-sm border border-black/10 text-gray-700 shadow-sm active:text-gray-900 active:bg-white/95",{mutate:Ve}=jd(),{mutate:hs}=Nd(),{data:xt}=yd(),{data:ms}=Jc(),{hasDomain:zt}
7=Pd(),Re=!0,[le,bt]=(0,s.useState)(()=>k.domain),[i,Ht]=(0,s.useState)(()=>k.topic),[g,Wt]=(0,s.useState)([]),Tt=wu(i?.id,ge),Ce=i?.id?pt(i.id):!1,Ie=Yc&&i?.domainSlug?zt(i.domainSlug):!1,Me=!!i&&(i.visibility==="unlisted"||i.visibility==="public")&&!!i.ownerUserId&&i.ownerUserId!==(F?.id??null),Gs=_d({isAuthenticated:R,isPremium:O,isAdmin:ie?.isAdmin??!1,isBookCurrentlyFree:Ce,hasDomainEntitlement:Ie,isCreatorShared:Me}),et=(0,s.useCallback)(t=>{const n=t?.sourceAttribution;return!n||!n.sourceBookId?{isPaidSourceReference:!1,sourceChapterIndex:void 0}:{isPaidSourceReference:!pt(n.sourceBookId),sourceChapterIndex:typeof n.sourceChapterNumber=="number"?n.sourceChapterNumber:void 0}},[pt]),[_t,fs]=(0,s.useState)(()=>!!o||!k.topic),[Vr,qt]=(0,s.useState)(!1),ps=ed(_t),[Et,Xs]=(0,s.useState)(null),[M,ae]=(0,s.useState)(0),Ye=(0,s.useRef)(0),[tt,Qs]=(0,s.useState)(0),xs=(0,s.useRef)(0),[gn,Yr]=(0,s.useState)(1),Kr=(0,s.useRef)(0);(0,s.useEffect)(()=>{tt>Kr.current?Yr(1):tt<Kr.current&&Yr(-1),Kr.current=tt},[tt]);const[Hi,vn]=(0,s.useState)(!1),[ce,Te]=(0,s.useState)(!1),[se,gt]=(0,s.useState)(0),[G,Gr]=(0,s.useState)(0),[je,Wi]=(0,s.useState)(1),[Xr,Js]=(0,s.useState)(!1),[yn,Qr]=(0,s.useState)(!1),[Jr,Zr]=(0,s.useState)(!1),nt=(0,s.useRef)(null),[qi,ea]=(0,s.useState)(!1),Vt=is("(max-width: 768px)"),bs=is("(min-width: 768px) and (max-width: 1080px)"),Vi=is("(min-width: 1200px) and (max-width: 1400px)"),gs=is("(min-width: 1081px) and (max-width: 1200px)"),ot=yi(),{isLandscape:Yi}=xn(),U=Yi,Zs=gc(),Ki=Md(),ta=rt()&&!Zs,Gi=Zs&&!U,Xi=!rt()&&!Zs&&Vt,de=ta?!U:Gi||Xi&&!U,Oe=is("(max-height: 550px)")&&!Zs&&(ta||!rt())&&U,Ne=ta&&U&&!Ki,Qi=!de&&!Ne,er=rt()&&wi(),kn=rd(),{bind:Ji,style:Zi,isZoomed:tr,reset:sr}=du({minScale:1,maxScale:4}),[H,wn]=(0,s.useState)(!1),jn=(0,s.useRef)(null),Nn=(0,s.useRef)(null),[Yt,el]=(0,s.useState)(!1);(0,s.useEffect)(()=>()=>{nt.current&&clearTimeout(nt.current)},[]);const[tl,Sn]=(0,s.useState)(!1),it=(0,s.useRef)(null),rr=(0,s.useRef)(null),Kt=(0,s.useRef)(null),ar=(0,s.useRef)(null),vs=(0,s.useRef)(!1),nr=(0,s.useRef)(!1);(0,s.useEffect)(()=>()=>{it.current&&clearTimeout(it.current)},[]);const[Be,vt]=(0,s.useState)(1),[ys,Le]=(0,s.useState)(0),[sa,ra]=(0,s.use
7State)(!1),[lt,sl]=(0,s.useState)(0),Cn=(0,s.useRef)(0),Tn=(0,s.useRef)(0);(0,s.useLayoutEffect)(()=>{if(!de||!ks.current)return;const t=()=>{ks.current&&sl(ks.current.offsetHeight)},n=new ResizeObserver(t);return n.observe(ks.current),()=>n.disconnect()},[o,U,de,g.length,H]),(0,s.useEffect)(()=>{ra(!1),it.current&&(clearTimeout(it.current),it.current=null)},[tt]),(0,s.useEffect)(()=>{U||H||sa||Le(He(Be,lt))},[Be,lt,U,H,sa]);const rl=(0,s.useCallback)(t=>{Cn.current=t.touches[0].clientY,Tn.current=ys,ra(!0)},[ys]),al=(0,s.useCallback)(t=>{const n=t.touches[0].clientY-Cn.current,d=-lt;Le(Math.min(0,Math.max(d,Tn.current+n)))},[lt]),_n=(0,s.useRef)(0),En=(0,s.useRef)(0),nl=(0,s.useCallback)(t=>{_n.current=t.touches[0].clientY,En.current=t.currentTarget.scrollTop},[]),ol=(0,s.useCallback)(t=>{if(Be===0)return;const n=t.changedTouches[0].clientY-_n.current;En.current<=2&&n>60&&(Be===2?(vt(1),Le(He(1,lt))):(vt(0),Le(He(0,lt))))},[Be,lt]),il=(0,s.useCallback)(()=>{ra(!1);const t=lt;if(t<=0)return;const n=Math.abs(ys)/t;Be===0?n>.65?(vt(2),Le(He(2,t))):n>.18?(vt(1),Le(He(1,t))):Le(He(0,t)):Be===1?n>.65?(vt(2),Le(He(2,t))):n<.15?(vt(0),Le(He(0,t))):Le(He(1,t)):n<.15?(vt(0),Le(He(0,t))):n<.65?(vt(1),Le(He(1,t))):Le(He(2,t))},[Be,ys,lt]),[Rt,aa]=(0,s.useState)(!1),[Rn,na]=(0,s.useState)(!0),ks=(0,s.useRef)(null),In=(0,s.useRef)(null),{shouldPulseButton:An,showPermissionPrompt:ll,dismissHint:l0,savePreference:cl}=cu({targetElement:de?void 0:In}),pe=de?H:Rt,or=pe||Ne,Pn=(0,s.useCallback)(()=>{try{"orientation"in screen&&"unlock"in screen.orientation&&screen.orientation.unlock()}catch{}},[]),Se=(0,s.useCallback)(()=>{H&&(wn(!1),Pn()),Rt&&aa(!1)},[Rt,H,Pn]),Ln=(0,s.useCallback)(async()=>{if(H){Se();return}wn(!0);try{"orientation"in screen&&"lock"in screen.orientation?(await screen.orientation.lock("landscape-primary"),na(!0)):na(!1)}catch{na(!1)}try{await q("medium")}catch{}},[Se,H]),It=(0,s.useCallback)(t=>{if(vs.current){vs.current=!1;return}if(pe){Se();return}const n=t?.currentTarget??(document.activeElement instanceof HTMLElement?document.activeElement:null);n&&n!==document.body&&(Nn.current=n),de?Ln():aa(!0)},[Se,pe,de,Ln]);(0,s.useEffect)(()=>{Ne&&Rt&&aa(!1)},[Ne,Rt]),(0,s.useEffect)(()=>{if(H&&!U&&Rn===!1){const t=setTimeout(()=>{U||Se()},2e3);return()=>clearTimeout(t)}},[H,U,Se,Rn]);const{showControls:oa,isVisible:Gt,toggleControls:c0,resetTimer:Fn}=Oi({enabled:!yn}),{isSaved:ia,isSaving:$n,toggleSaved:Mn}=$d(i?.id||""),dl=(0,s.useCallback)(async()=>{if(i?.id)try{await Mn(),q("medium")}catch(t){console.error("Failed to toggle bookmark:",t)}},[i?.id,Mn]),ul=(0,s.useCallback)(()=>{if(!i||!o||!a||!r)return;const t=g.find(y=>y.slug===o),n=new URL(os.book(a,r,o),window.location.origin),d=new URLSearchParams(l.search).get("view")??new URLSearchParams(l.search).get("surface");d&&(n.searchParams.set("view",d),n.searchParams.set("surface",d==="visual"?"visual":"text")),hd({title:`${t?.title??o} â ${i.title}`,text:`Read ${t?.title??"this chapter"} from "${i.title}" on Scrollbook`,url:n.href,source:"topicpage_topbar"})},[i,g,o,a,r,l.search]),[la,ca]=(0,s.useState)(!1),[hl,da]=(0,s.useState)(!1),[On,ir]=(0,s.useState)(!1),[ua,yt]=(0,s.useState)(!1),[ha,lr]=(0,s.useState)(Mr),[ma,ws]=(0,s.useState)(!1),[Bn,Dn]=(0,s.use
7State)(!1),fa=(0,s.useRef)(!1),[ml,Un]=(0,s.useState)(!1),zn=t=>{const n=new URLSearchParams(t),d=n.get("view")??n.get("surface");return d==="visual"||d==="transcript"||d==="chat"||d==="ideas"?d:"reading"},[w,Hn]=(0,s.useState)(()=>zn(l.search)),ve=(0,s.useCallback)(t=>{const n=typeof t=="function"?t(w):t;Hn(n);const d=new URLSearchParams(l.search);d.set("view",n==="reading"?"text":n),d.set("surface",n==="visual"?"visual":"text"),K(d,{replace:!0,state:l.state})},[w,l.search,l.state,K]);(0,s.useEffect)(()=>{Hn(zn(l.search))},[l.search]);const[Wn,pa]=(0,s.useState)(void 0),[fl,qn]=(0,s.useState)(!1),[pl,Vn]=(0,s.useState)(!1),[xl,bl]=(0,s.useState)(0),[gl,Yn]=(0,s.useState)(!1),Kn=(0,s.useRef)(typeof window<"u"&&localStorage.getItem("player_swipe_hint")==="1"),[js,Ns]=(0,s.useState)(null),[Fe,xa]=(0,s.useState)(null),vl=pd(),yl=xd(),{promote:kl}=pu(),[ba,Gn]=(0,s.useState)(null),[cr,At]=(0,s.useState)(!1),[Xn,ga]=(0,s.useState)(!1),[wl,va]=(0,s.useState)([]),[Ss,ya]=(0,s.useState)([]),[jl,dr]=(0,s.useState)(!1),[,ka]=(0,s.useState)(new Map),[kt,Nl]=(0,s.useState)(()=>{try{const t=localStorage.getItem("scrollbook-sidebar-width"),n=t?parseInt(t,10):NaN;return isNaN(n)?360:Math.min(560,Math.max(280,n))}catch{return 360}}),wa=(0,s.useRef)(!1),Qn=(0,s.useRef)(0),Jn=(0,s.useRef)(0),Zn=(0,s.useRef)(kt),eo=(0,s.useRef)(kt),ur=(0,s.useRef)(null),hr=(0,s.useRef)(null);(0,s.useEffect)(()=>{Zn.current=kt},[kt]),(0,s.useEffect)(()=>()=>{ur.current&&window.removeEventListener("mousemove",ur.current),hr.current&&window.removeEventListener("mouseup",hr.current),document.body.style.cursor="",document.body.style.userSelect=""},[]);const Sl=(0,s.useCallback)(t=>{t.preventDefault(),wa.current=!0,Qn.current=t.clientX,Jn.current=Zn.current,document.body.style.cursor="col-resize",document.body.style.userSelect="none";const n=y=>{if(!wa.current)return;const j=Qn.current-y.clientX,N=Math.min(560,Math.max(280,Jn.current+j));eo.current=N,Nl(N)},d=()=>{wa.current=!1,document.body.style.cursor="",document.body.style.userSelect="";try{localStorage.setItem("scrollbook-sidebar-width",String(eo.current))}catch{}window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",d),ur.current=null,hr.current=null};ur.current=n,hr.current=d,window.addEventListener("mousemove",n),window.addEventListener("mouseup",d)},[]);(0,s.useEffect)(()=>{},[Re,w]);const[Cl,Tl]=(0,s.useState)(!1),[mr,_l]=(0,s.useState)(null),[ja,El]=(0,s.useState)(null),to=g[tt]?.title,Rl=g[0]?.infographicUrl;Sd({title:i?to?`${to} | ${i.title} â Scrollbook`:`${i.title} Summary â Visual Chapters + Audio`:void 0,description:i?i.synopsis?`Visual infographic summary of ${i.title}${i.author?` by ${i.author}`:""}. See it. Hear it. Retain it. ${i.synopsis.slice(0,100).trimEnd()}â¦`:`Visual book summary of ${i.title}${i.author?` by ${i.author}`:""} â key takeaways across ${i.lessonCount} chapters with audio narration and infographics.`:void 0,image:Rl||i?.coverUrl||void 0,url:a&&r?`/domain/${a}/topic/${r}`:void 0,type:"book",schema:i&&a&&r?{"@context":"https://schema.org","@graph":[{"@type":"Book",name:i.title,author:i.author?{"@type":"Person",name:i.author}:void 0,image:i.coverUrl||void 0,description:`Key ideas from ${i.title}${i.author?` by ${i.author}`:""}`,url:`https://scrollbook.io/domain/${a}/topic/${r}`,genre:a,numberOfPages:i.lessonCount,inLanguage:"en",publisher:{"@type":"Organization",name:"Scrollbook",url:"https://scrollbook.io"}},{"@type":"BreadcrumbList",itemListElement:[{"@type":"ListItem",position:1,name:"Home",item:"https://scrollbook.io"},{"@type":"ListItem",position:2,name:a,item:`https://scrollbook.io/domain/${a}`},{"@type":"ListItem",position:3,name:i.title,item:`https://scrollbook.io/domain/${a}/topic/${r}`}]},{"@type":"FAQPage",mainEntity:[{"@type":"Question",name:`What is "${i.title}" about?`,acceptedAnswer:{"@type":"Answer",text:i.description||`"${i.title}" by ${i.author} is a ${i.lessonCount}-chapter summary covering key ideas in ${a}. Available with audio narration and visual infographics on Scrollbook.`}},{"@type":"Question",name:`Who wrote "${i.title}
7"?`,acceptedAnswer:{"@type":"Answer",text:i.author?`"${i.title}" was written by ${i.author}.`:`"${i.title}" is available as a full summary on Scrollbook.`}},{"@type":"Question",name:`How long is the "${i.title}" summary?`,acceptedAnswer:{"@type":"Answer",text:`The Scrollbook summary of "${i.title}" has ${i.lessonCount} chapters, each with audio narration and a visual infographic. Total listening time is approximately ${i.lessonCount*3}â${i.lessonCount*4} minutes.`}},{"@type":"Question",name:`Is "${i.title}" available as an audio summary?`,acceptedAnswer:{"@type":"Answer",text:`Yes â every chapter of "${i.title}" on Scrollbook includes a professionally narrated audio summary alongside a full visual infographic. The first 3 chapters are free.`}}]}]}:void 0});const[so,Na]=(0,s.useState)(null),[ro,fr]=(0,s.useState)(null),ao="scrollbook_rotate_fullscreen_hint_shown",[Il,no]=(0,s.useState)(!1),x=(0,s.useMemo)(()=>{if(o&&g.length>0){const t=g.findIndex(n=>n.slug===o);if(t>=0)return t}return tt},[o,g,tt]);xs.current=x;const u=g[x],Ae=A.get("book_queue")==="both",Q=Ac({enabled:Ae&&!!u,accessKey:[F?.id??"anonymous",O?"premium":"standard",ie?.isAdmin?"admin":"reader",Ce?"promo":"standard",Ie?"domain":"no-domain",Me?"shared":"catalog"].join(":"),bookSlug:r??"",domainSlug:a??"",current:{kind:"summary",chapterId:u?.id??"",chapterSlug:u?.slug??o??""},surface:w==="visual"?"visual":"text",returnTo:b}),wt=Ae?Q.isExact&&!Q.isPending&&!!Q.nextPath:x<g.length-1,Cs=Ae?Q.isExact&&!Q.isPending&&!!Q.previousPath:x>0,Sa=(0,s.useMemo)(()=>u?Hs({chapterIndex:x,isAuthenticated:R,isPremium:O,isAdmin:ie?.isAdmin??!1,isBookCurrentlyFree:Ce,isChapterPreviouslyUnlocked:u.id?ke(u.id):!1,hasDomainEntitlement:Ie,isCreatorShared:Me,...et(u)}).action!=="allow":!1,[u,x,R,O,ie?.isAdmin,Ce,ke,Ie,Me,et]);(0,s.useEffect)(()=>{if(!(St&&Or.canonicalDiscovery)||!cr||!u?.id){va([]);return}let t=!1;return Qo.getChapterConcepts(u.id,3).then(n=>{t||va(n)}).catch(()=>{t||va([])}),()=>{t=!0}},[cr,u?.id]),(0,s.useEffect)(()=>{if(!Or.canonicalDiscovery||!u?.id){ya([]),dr(!1);return}let t=!1;return dr(!0),Qo.getChapterConcepts(u.id,3).then(n=>{t||(ya(n),dr(!1))}).catch(()=>{t||(ya([]),dr(!1))}),()=>{t=!0}},[u?.id]),(0,s.useEffect)(()=>{if(!ge)return;const t=Ss.map(d=>d.nodeId).filter(d=>!!d);if(t.length===0){ka(new Map);return}let n=!1;return vd(t).then(d=>{n||ka(d)}).catch(()=>{n||ka(new Map)}),()=>{n=!0}},[ge,Ss]);const[Ca,Ta]=(0,s.useState)(!1),[d0,oo]=(0,s.useState)(!1),[Ke,pr]=(0,s.useState)(!!o),[io,Pt]=(0,s.useState)(!1),[u0,lo]=(0,s.useState)([]),[xr,Ts]=(0,s.useState)(()=>new Set),Xt=(0,s.useRef)(Date.now()),_s=(0,s.useRef)(!1),Es=(0,s.useRef)([]),De=(0,s.useRef)(new Set),Lt=(0,s.useRef)(!1),Qt=(0,s.useRef)(null),_a=(0,s.useRef)(null),Ea=(0,s.useRef)(null),Al=(0,s.useCallback)((t,n,d)=>{if(_s.current){Ve({lessonId:n,bookId:_a.current??void 0,progress:d});return}return zs.saveChapterProgressWithRewards(t,n,d)},[Ve]),{persistPosition:co,resetPosition:br}=Tc({enabled:R,userId:F?.id,persist:Al}),P=(0,s.useRef)(Us),Ra=(0,s.useRef)(1),Ge=(0,s.useRef)(!1),uo=(0,s.useRef)(0),ho=(0,s.useRef)(null),mo=(0,s.useRef)(null),Ia=(0,s.useRef)(!1),gr=[.75,1,1.25,1.5,2],fo=Cc(se,3e3),st=(0,s.useRef)(0);(0,s.useRef)(0);const po=(0,s.useRef)(()=>{}),Ft=(0,s.useRef)(null),Aa=(0,s.useRef)(0),[Jt,xo]=(0,s.useState)(0),[bo,Pa]=(0,s.use
7State)(!0),$t=(0,s.useRef)(null);(0,s.useEffect)(()=>(_s.current=!0,()=>{_s.current=!1}),[]),(0,s.useEffect)(()=>{Es.current=g},[g]),(0,s.useEffect)(()=>{De.current=xr},[xr]),(0,s.useEffect)(()=>{_a.current=i?.id??null},[i?.id]),(0,s.useEffect)(()=>{Ea.current=F?.id??null},[F?.id]),(0,s.useEffect)(()=>{if(!Gt)return;const t=()=>{Fn()},n=["touchstart","mousemove","keydown"];return n.forEach(d=>document.addEventListener(d,t,{passive:!0})),()=>{n.forEach(d=>document.removeEventListener(d,t))}},[Gt,Fn]);const Zt=(0,s.useRef)(!1),go=(0,s.useRef)(!1);(0,s.useEffect)(()=>{const t=()=>{pe&&Zt.current&&(Zt.current=!1,Se())};if(pe&&!Zt.current){Zt.current=!0;const n=window.history.state&&typeof window.history.state=="object"?window.history.state:{};window.history.pushState({...n,[mi]:!0},"",window.location.href)}else!pe&&Zt.current&&window.history.state?.[mi]&&(Zt.current=!1,window.history.back());return window.addEventListener("popstate",t),()=>{window.removeEventListener("popstate",t)}},[pe,Se]),(0,s.useEffect)(()=>{const t=()=>{document.hidden&&pe&&Se()};return document.addEventListener("visibilitychange",t),()=>{document.removeEventListener("visibilitychange",t)}},[pe,Se]),(0,s.useEffect)(()=>{if(Kn.current||!de||U)return;Kn.current=!0,localStorage.setItem("player_swipe_hint","1");let t;const n=setTimeout(()=>{Yn(!0),t=setTimeout(()=>Yn(!1),3200)},1400);return()=>{clearTimeout(n),clearTimeout(t)}},[de,U]);const{isFreePromo:Pl,promo:Ll}=Mu({bookId:i?.id,chapterId:u?.id}),vr=(g||[]).filter(mt).length,Fl=Math.max(0,(g||[]).length-vr),La=Math.max(1,Fl),vo=(0,s.useMemo)(()=>g.reduce((t,n,d)=>(n.id&&xr.has(n.id)&&t.push(d),t),[]),[xr,g]),$l=vo.filter(t=>{const n=g[t];return n&&!mt(n)}).length,Rs=!u||mt(u)?"OV":a==="fiction"?`Book ${x-vr+1}`:`Ch ${u.orderIndex??x}`;g.length>0&&Math.round($l/La*100);const{data:oe,hasStoryBeats:Mt}=su(u,le,i?.title,i?.author),Ml=(0,s.useMemo)(()=>iu(oe,{chapterTitle:u?.title,chapterNumber:u?.orderIndex??x,fallbackTakeaways:u?.keyTakeaways}),[x,u?.keyTakeaways,u?.orderIndex,u?.title,oe]);hu({bookTitle:i?.title??"",chapterTitle:u?.title??"",chapterNumber:u?.orderIndex??0,totalChapters:g.length,progress:G>0?Math.round(se/G*100):0,isPlaying:ce,domainColor:le?.color||"#F59E0B",coverUrl:i?.coverUrl||void 0,statusString:`${Rs} of ${La}`,enabled:!!(i&&u)});const Z=u?.slug??o,ue=u?.orderIndex??x,{markText:yo,markAudio:ko,markInfographic:wo}=Pc(Z,{bookSlug:r,domainSlug:a,chapterNumber:ue,userId:F?.id??null}),yr=(0,s.useMemo)(()=>{const t=oe?.sections||[];if(t.length===0)return[];const n=u?.audioScript;if(!n)return t;const d=(N,B)=>N.id==="hook"?-1:N.id==="conclusion"?n.sections?.length??0:t.slice(0,B).filter(X=>X.id!=="hook"&&X.id!=="conclusion").length,y=ld({transcript:u?.audioTranscript??null,audioScript:n});if(y){const N=od(y);return t.map((B,X)=>{const Xe=d(B,X),Bs=N.get(Xe);return{...B,audioSectionIndex:Xe,startTime:Bs?.startTime??B.startTime??0,duration:Bs?.duration??B.duration??0}})}const j=N=>{let B=0;return t.map((X,Xe)=>{const Bs=d(X,Xe),Wo=N(X,Xe,Bs),dc={...X,duration:Wo,startTime:B,audioSectionIndex:Bs};return B+=Wo,dc})};return t[0]?.duration!==void 0?j(N=>N.duration??0):j((N,B,X)=>N.id==="hook"?Math.ceil((n.hook?.split(" ").length||0)/2.5):N.id==="conclusion"?Math.ceil((n.conclusion?.split(" ").length||0)/2.5):n.sections?.[X]?.duration||Math.ceil((N.narrative?.split(" ").length||0)/2.5))},[oe?.sections,u?.audioScript,u?.audioTranscript]),ct=au({sections:yr,audioDuration:G,audioProgress:se,isPlaying:ce,enabled:Mt&&Re,scrollC
7ontainer:mr}),es=Rd({narrativeSectionIndex:Jt,storyBeatSectionIndex:ct.activeSectionIndex,hasStoryBeatSections:yr.length>0}),{url:Ol,loading:Bl}=Zo((0,s.useMemo)(()=>Qd(u),[u])),{url:Dl,loading:Ul,error:zl,refresh:jo}=Zo(u?.audioPath),Is=Ol,me=Dl,Fa=!!(u?.audioPath&&!me&&!Ul&&zl),$a=Xr||Fa,No=(0,s.useCallback)(()=>{if(Js(!1),Fa){jo();return}P.current?.load()},[Fa,jo]),[Hl,So]=(0,s.useState)(null),[Wl,Co]=(0,s.useState)(null),[ql,To]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!me){So(n=>(n&&URL.revokeObjectURL(n),null));return}let t=!1;return Fr.getCachedUrl(me).then(n=>{if(t){n&&URL.revokeObjectURL(n);return}So(d=>(d&&URL.revokeObjectURL(d),n))}),()=>{t=!0}},[me]),(0,s.useEffect)(()=>{if(!Is){To(null),Co(n=>(n&&URL.revokeObjectURL(n),null));return}let t=!1;return Fr.getCachedUrl(Is).then(n=>{if(t){n&&URL.revokeObjectURL(n);return}To(n?Is:null),Co(d=>(d&&URL.revokeObjectURL(d),n))}),()=>{t=!0}},[Is]),(0,s.useEffect)(()=>{if(!r||!i||!u)return;const t=G>0?Math.round(se/G*100):0,n=le?.color||"#F59E0B";Od({bookSlug:r,bookTitle:i.title,chapterSlug:u.slug,chapterTitle:u.title,chapterNumber:u.orderIndex??0,totalChapters:g.length,progress:t,domainColor:n,domainSlug:a??"",updatedAt:new Date().toISOString()})},[r,i,u,se,G,g.length,le?.color,a]);const dt=Hl??me,_o=eu(Is,Wl,ql),ee=(0,s.useMemo)(()=>Jd(u,_o),[u,_o]),Ue=(0,s.useMemo)(()=>{if(!u||!i||!a||!r)return null;const t=x>0?g[x-1]:null,n=x<g.length-1?g[x+1]:null,d=y=>`/domain/${a}/topic/${r}/${y}`;return Iu({preferredPlayer:L?"scroll":"page",bookId:i.id,bookSlug:r,bookTitle:i.title,bookAuthor:i.author??null,domainSlug:a,chapterId:u.id,chapterSlug:u.slug,chapterTitle:u.title,chapterNumber:u.orderIndex,chapterIndex:x,chapterCount:g.length,isOverview:mt(u),audioUrl:dt??null,infographicUrl:ee??null,audioDurationSeconds:G>0?G:u.audioDuration??null,positionSeconds:se,isPlaying:ce,isSaved:ia,isSaving:$n,entitlementAction:Sa?R?"paywall":"login":"allow",currentPath:Ru({domainSlug:a,bookSlug:r,routeChapterSlug:o,search:l.search}),previousPath:Ae?Q.isExact?Q.previousPath:null:t?mt(t)?os.book(a,r):d(t.slug):null,nextPath:Ae?Q.isExact?Q.nextPath:null:n?d(n.slug):null,sourceType:u.sourceType??null,sourceAttribution:u.sourceAttribution??null})},[Ae,Q.isExact,Q.previousPath,Q.nextPath,x,G,se,o,Sa,u,a,L,R,ia,$n,ce,g,l.search,ee,dt,i,r]),ut=(0,s.useMemo)(()=>Zd(u,ee,!!oe?.sections?.length),[u,ee,oe?.sections?.length]),{imageLoaded:ye,imageError:kr}=(0,s.useMemo)(()=>tu(ee,so,ro),[ee,so,ro]),wr=(0,s.useRef)(null);wr.current=ut?null:ee??null;const jr=(0,s.useCallback)(t=>{const n=wr.current;return n?!t||t===n:!1},[]),ts=(0,s.useCallback)(t=>{if(!jr(t))return;const n=wr.current;fr(null),Na(n??t??null)},[jr]),Eo=(0,s.useCallback)(t=>{if(!jr(t))return;const n=wr.current;Na(null),fr(n??t??null)},[jr]),Ro=(0,s.useCallback)(t=>{t?.complete&&t.naturalWidth>0&&ts(t.currentSrc||t.src),El(n=>n===t?n:t)},[ts]);(0,s.useEffect)(()=>{if(!ye||H||U||!de||localStorage.getItem(ao))return;no(!0),localStorage.setItem(ao,"1");const t=setTimeout(()=>no(!1),2200);return()=>clearTimeout(t)},[ye,H,U,de]);const Vl=!!(u?.audioPath||u?.audioUrl||me||dt||yn||ce||G>0),Yl=!!(ee&&ye&&!kn),Kl=!!(i?.coverUrl&&!kn),Gl=Vl&&!Yt?"calc(256px + env(safe-area-inset-bottom, 0px))":"env(safe-area-inset-bottom, 0px)",Ma=(0,s.useMemo)(()=>!g.length||!i?[]:g.map((t,n)=>{const d=Hs({chapterIndex:n,isAuthenticated:R,isPremium:O,isAdmin:ie?.isAdmin??!1,isBookCurrentlyFree:Ce,isChapterPreviouslyUnlocked:t.id?ke(t.id):!1,hasDomainEntitlement:Ie,isCreatorShared:Me,...et(t)});return{chapterTitle:t.title,chapterPath:`/domain/${a}/topic/${r}/${t.slug}`,audioPath:d.action==="allow"?t.audioPath??t.audioUrl??"":"",lessonId:t.id,bookId:i.id,infographicUrl:d.action==="allow"?t.infographicUrl??void 0:void 0,bookTitle:i.title,domainColor:le?.color||"#F59E0B"}}),[g,i,a,r,le?.color,R,O,ie?.isAdmin,Ce,ke,Ie,Me,et]),Oa=(0,s.useMemo)(()=>qc(Ue,le?.color||"#F59E0B"),[le?.color,Ue?.sessionKey,Ue?.entitlement.canReadContent,Ue?.identity.bookTitle,Ue?.identity.chapterTitle,Ue?.media.infographicUrl,Ue?.navigation.currentPath,Ue?.navigation.nextPath,Ue?.navigation.previousPath]);Ld({publicationKey:(0,s.useMemo)(()=>td(Ue?.sessionKey,Oa,Ma,x),[x,Oa,Ma,Ue?.sessionKey]),chapterInfo:Oa,playlist:Ma,playlistIndex:x,publishPlaylistWithoutChapterInfo:!0,setChapterInfo:re,setPlaylist:_,autoAdvanceEnabled:!1,restoreAutoAdvanceEnabled:!0,setAutoAdvanceEnabled:V}),(0,s.useEffect)(()=>{te(u?.audioPath??null)},[u?.audioPath,te]),dd(r,(0,s.useMemo)(()=>{const t=[];return x<g.length-1&&g[x+1]?.infographicPath&&t.push(g[x+1].infographicPath),t},[x,g]).map(t=>t.split("/").pop()?.replace(".png","")||""));const Xl=le?.name||null,Ql=(0,s.useMemo)(()=>{const t=g.reduce((n,d)=>n+(d.audioDuration||120),0);return Math.ceil(t/60)},[g]);(0,s.useMemo)(()=>{let t=0,n=0,d=0;return g.forEach(y=>{if(y.keyTakeaways&&Array.isArray(y.keyTakeaways)&&(t+=y.keyTakeaways.length),y.audioScript){const j=JSON.stringify(y.audioScript),N=j.match(/framework|model|system|method|strategy|principle/gi);N&&(n+=Math.min(N.length,3));const B=j.match(/case study|example|story of|real-world|company like/gi);B&&(d+=Math.min(B.length,2))}}),{keyInsights:t,frameworks:Math.min(n,g.length*2),caseStudies:Math.min(d,g.length)}},[g]),(0,s.useEffect)(()=>
7{if(!a||!r)return;let t=!1;const n=Ye.current+1;Ye.current=n;const d=()=>!t&&Ye.current===n,y=xi(l.state,a,r);return fs(!0),qt(!0),Xs(null),bt(y.domain),Ht(y.topic),Wt([]),(async()=>{try{if(await cs.auth.getSession(),t)return;const[j,N]=await Promise.all([Za.getDomainBySlug(a),Za.getTopicBySlug(a,r)]);if(t)return;if(j&&bt(j),!N){Ht(null),Wt([]),d()&&qt(!1),fs(!1);return}Ht(N);const B=await Za.getLessonsByTopic(N.id,{includeTranscripts:!0});if(!d())return;if(Wt(B),qt(!1),N){if(o&&B.length>0){const X=B.findIndex(Xe=>Xe.slug===o);X>=0&&Qs(X)}lo(o0(N.id))}}catch(j){if(t)return;(j instanceof Error?j.message:"").includes("abort")||(console.error("[TopicPage] Failed to load data:",j),Xs("We hit a temporary issue loading this chapter. Please try again."))}finally{t||(d()&&qt(!1),fs(!1))}})(),()=>{t=!0}},[a,r,M]);const Ba=(0,s.useRef)(0),Ot=(0,s.useRef)({p50:!1,p75:!1,p95:!1}),As=(0,s.useRef)(!1);(0,s.useEffect)(()=>{Ba.current=0,Ot.current={p50:!1,p75:!1,p95:!1},As.current=!1},[Z]),(0,s.useEffect)(()=>{if(!mr||!Z||!r)return;const t=mr,n={book_slug:r,chapter_slug:Z,chapter_number:ue},d=()=>{const y=t.scrollHeight-t.clientHeight;if(y<=0)return;const j=Math.min(100,Math.max(0,t.scrollTop/y*100));j<=Ba.current||(Ba.current=j,j>=50&&!Ot.current.p50&&(Ot.current.p50=!0,I.track($.CHAPTER_SCROLL_50,{...n,scroll_pct:Math.round(j)})),j>=75&&!Ot.current.p75&&(Ot.current.p75=!0,I.track($.CHAPTER_SCROLL_75,{...n,scroll_pct:Math.round(j)})),j>=95&&!Ot.current.p95&&(Ot.current.p95=!0,yo(),!R&&(ue===0||ue===1)&&I.track($.ANON_FREE_CHAPTER_READ,{book_slug:r,chapter_slug:Z,chapter_number:ue}),St&&!As.current&&xs.current<g.length-1&&(As.current=!0,At(!0),I.track($.CHAPTER_COMPLETE_SHEET_VIEW,{book_slug:r,chapter_number:ue,trigger:"scroll"}))))};return t.addEventListener("scroll",d,{passive:!0}),d(),()=>{t.removeEventListener("scroll",d)}},[mr,Z,r,ue,yo,R,g.length]);const Da=(0,s.useRef)(Date.now()),Ua=(0,s.useRef)(0);(0,s.useEffect)(()=>{Ua.current=0,Da.current=Date.now()},[Z]),(0,s.useEffect)(()=>{if(!Z||!r)return;const t=()=>{Da.current=Date.now()},n=["click","keydown","scroll","pointerdown","touchstart"];n.forEach(j=>{document.addEventListener(j,t,{passive:!0})});const d=3e4,y=window.setInterval(()=>{document.visibilityState==="visible"&&(Date.now()-Da.current>d||(Ua.current+=30,I.track($.CHAPTER_TIME_HEARTBEAT,{book_slug:r,chapter_slug:Z,chapter_number:ue,seconds_active:30,total_seconds_session:Ua.current})))},d);return()=>{window.clearInterval(y),n.forEach(j=>{document.removeEventListener(j,t)})}},[Z,r,ue]);const Nr=(0,s.useRef)(!1);(0,s.useEffect)(()=>{Nr.current=!1},[Z]),(0,s.useEffect)(()=>{if(!ja||!Z||Nr.current||typeof IntersectionObserver>"u")return;let t=null,n=null;const d=()=>{Nr.current||(Nr.current=!0,wo())},y=new IntersectionObserver(j=>{const N=j[0];N&&(N.intersectionRatio>=.5?t==null&&(t=Date.now(),n!=null&&window.clearTimeout(n),n=window.setTimeout(d,2e3)):(t=null,n!=null&&(window.clearTimeout(n),n=null)))},{threshold:[0,.25,.5,.75,1]});return y.observe(ja),()=>{y.disconnect(),n!=null&&window.clearTimeout(n)}},[ja,Z,wo]),(0,s.useLayoutEffect)(()=>{if(!o||g.length===0)return;const t=g.findIndex(n=>n.slug===o);if(t<0){v(`/domain/${a}/topic/${r}`,{replace:!0});return}t!==tt&&(Qs(t),pr(!0))},[o,g,a,r]),(0,s.useEffect)(()=>{if(ne||us||!o||g.length===0)return;const t=g.findIndex(y=>y.slug===o);if(t<0)return;const n=g[t],d=Hs({chapterIndex:t,isAuthenticated:R,isPremium:O,isAdmin:ie?.isAdmin??!1,isBookCurrentlyFree:Ce,isChapterPreviouslyUnlocked:n?.id?ke(n.id):!1,hasDomainEntitlement:Ie,isCreatorShared:Me,...et(n)});if(d.action==="login"){sessionStorage.setItem("returnTo",window.location.pathname),v("/login");return}d.action==="paywall"&&(lr(t),yt(!0),I.track(R?$.PAYWALL_HIT:$.ANON_PAYWALL_HIT,{book_slug:r,domain_slug:a,chapter_index:t,chapter_slug:o}),F?.email&&i?.title&&r&&Ut.onPaywallHit(F.email,i.title,r,a))},[o,g,R,O,ne,us,ie?.isAdmin,Ce,Ie,ke]),(0,s.useEffect)(()=>{if(!R||!F?.id||g.length===0){Lt.current=!0,Qt.current=null,De.current=new Set,Ts(new Set);return}let t=!1;const n=g.map(d=>d.id).filter(d=>!!d);return Lt.current=!1,Qt.current=zs.getChaptersProgressBatch(F.id,n).then(d=>{const y=new Set;return d.forEach((j,N)=>{j.completed&&y.add(N)}),t||(De.current=y,Lt.current=!0,Qt.current=null,Ts(y)),y}).catch(()=>
7{if(t)return new Set;const d=new Set;return De.current=d,Lt.current=!0,Qt.current=null,Ts(d),d}),()=>{t=!0}},[R,g,F?.id]);const Sr=(0,s.useCallback)(async()=>{if(Lt.current)return new Set(De.current);const t=Qt.current;if(t)try{return new Set(await t)}catch{return new Set(De.current)}const n=Ea.current,d=Es.current.map(y=>y.id).filter(y=>!!y);if(!n||d.length===0)return new Set(De.current);try{const y=await zs.getChaptersProgressBatch(n,d),j=new Set;return y.forEach((N,B)=>{N.completed&&j.add(B)}),De.current=j,Lt.current=!0,Qt.current=null,_s.current&&Ts(j),j}catch{return new Set(De.current)}},[]);(0,s.useEffect)(()=>{if(i&&x>=0){if(r&&I.chapterStarted(r,x),r&&R&&F?.id){const t=`sb_first_chapter_viewed_${F.id}`;try{localStorage.getItem(t)||(localStorage.setItem(t,new Date().toISOString()),I.track($.FIRST_CHAPTER_VIEWED,{book_slug:r,domain_slug:a,chapter_number:x}))}catch{}}lo(t=>{if(!t.includes(x)){const n=[...t,x];return i0(i.id,n),n}return t})}},[i,x,R,F?.id]),(0,s.useEffect)(()=>{i?.slug&&a&&I.bookViewed(i.slug,a),!go.current&&F?.email&&i?.title&&i?.slug&&(go.current=!0,Ut.onBookViewed(F.email,i.title,i.slug))},[i?.id,R]);const Bt=(0,s.useCallback)((t,n,d)=>{if(!t)return;const y=Date.now();co({lessonId:t,positionSeconds:n,lastSectionIndex:d,additionalTimeSpent:Math.floor((y-Xt.current)/1e3)})&&(Xt.current=y)},[co]),Cr=(0,s.useCallback)(t=>{Ft.current&&Ft.current!==u?.id||Bt(u?.id,t,es)},[u?.id,es,Bt]),ze=(0,s.useCallback)(()=>{const t=P.current?.currentTime??0,n=Math.max(t,st.current,0);po.current(n)},[]),Jl=(0,s.useCallback)(t=>{if(!t.lessonId)return;const n=P.current?.currentTime??0,d=Math.max(n,st.current,0);Bt(t.lessonId,d,Aa.current)},[Bt]);Nc(Ue,F?.id,{flushPosition:Jl});const Io=(0,s.useCallback)((t,n)=>{if(t&&t===u?.id)return es;const d=Es.current.find(j=>j.id===t);if(!d)return 0;const y=d.storyBeats?.sections;return Id(d.sections?.length?d.sections:Array.isArray(y)?y:[],n)},[u?.id,es]),Ao=(0,s.useCallback)(t=>{const n=t.entry?.lessonId??(_s.current?u?.id:null),d=Io(n,t.currentTime);Bt(n,t.currentTime,d)},[u?.id,Bt,Io]),Po=(0,s.useCallback)(t=>{if(!R)return;const n=Ea.current,d=t.entry?.lessonId;if(!n||!d||mt(Es.current.find(N=>N.id===d)))return;const y=Date.now(),j=Math.floor((y-Xt.current)/1e3);Xt.current=y,br(d),zs.saveChapterProgressWithRewards(n,d,{completed:!0,audioPosition:0,additionalTimeSpent:j}).then(async({completionApplied:N})=>{const B=ri(await Sr(),d);De.current=B;const X=t.entry?.bookId??_a.current,Xe=ai(Es.current,B);X&&Xe&&si.markBookFinished(n,X).catch(()=>{}),r&&(I.audioCompleted(r,t.playlistIndex,Math.floor(t.duration||t.currentTime||0)),N&&(I.chapterCompleted(r,t.playlistIndex,j),Xe&&I.bookCompleted(r))),N&&F?.email&&i?.title&&(Ut.onChapterCompleted(
7F.email,i.title,t.playlistIndex+1),Xe&&Ut.onBookFinished(F.email,i.title)),N&&gd.onChapterCompleted()}).catch(()=>{})},[R,Sr,br,i?.title,r,F?.email]);(0,s.useEffect)(()=>{E({onProgress:Ao,onEnded:Po})},[Ao,Po,E]),(0,s.useEffect)(()=>{st.current=se},[se]),(0,s.useEffect)(()=>{po.current=Cr},[Cr]),(0,s.useEffect)(()=>{Cr(fo)},[Cr,fo]),(0,s.useEffect)(()=>{Pt(!1),sr()},[x,sr]),(0,s.useEffect)(()=>{sr();const t=document.querySelector('meta[name="viewport"]');if(t){const n=t.content;t.content=n+", maximum-scale=1.0",requestAnimationFrame(()=>requestAnimationFrame(()=>{t.content=n}))}if(tr){Un(!0);const n=setTimeout(()=>Un(!1),1500);return()=>clearTimeout(n)}},[U,sr,tr]),(0,s.useEffect)(()=>{ua?fa.current=!0:fa.current=!1},[ua]),(0,s.useEffect)(()=>{if(O){if(fa.current){Dn(!0),I.track($.PAYWALL_SAFARI_RETURN_DISMISSED,{book_slug:r}),I.track($.PAYWALL_CHECKOUT_RETURN,{source:"topic",book_slug:r,status:"success",program_version:Ds});const t=setTimeout(()=>{Dn(!1),yt(!1),ws(!1)},1500);return()=>clearTimeout(t)}yt(!1),ws(!1)}},[O]),(0,s.useEffect)(()=>{if(Vt)return;const t="scrollbook_seen_shortcut_hint";if(!localStorage.getItem(t)){const n=setTimeout(()=>{oo(!0),localStorage.setItem(t,"1"),setTimeout(()=>oo(!1),5e3)},2e3);return()=>clearTimeout(n)}},[Vt]),(0,s.useEffect)(()=>{if(ut||!ee)return;const t=new Image;return t.onload=()=>{ts(ee)},t.onerror=()=>{},t.src=ee,()=>{t.onload=null,t.onerror=null}},[u?.infographicPath,ts,ut,ee]),(0,s.useEffect)(()=>{if(!G||G-se>30)return;const t=g[x+1];if(!t?.audioPath)return;let n=!1,d=null;return yc.getSignedUrl(t.audioPath).then(({url:y})=>{!y||n||(d=new Audio,d.preload="auto",d.src=y)}),()=>{n=!0,d?.pause(),d&&(d.src="",d.load())}},[G>0&&G-se<=30,x,g]),(0,s.useEffect)(()=>{if(nt.current&&(clearTimeout(nt.current),nt.current=null),Zr(!1),P.current){const t=P.current,n=Ft.current;if(n&&n!==u?.id&&t.currentTime>0&&Bt(n,t.currentTime,Aa.current),D.current&&!t.paused&&t.currentTime>0){Te(!0),Ge.current=!1,Ft.current=u?.id??Ft.current,me&&(D.current=!1);return}D.current=!1,t.pause(),t.currentTime=0,gt(0),Gr(0),Js(!1),xo(0),Ke&&me?Ge.current=!0:(Ge.current=!1,Te(!1))}Ft.current=u?.id??null},[x,Ke,me,u?.audioPath,u?.id]),(0,s.useEffect)(()=>{Aa.current=es},[es]);const Tr=(0,s.useCallback)(t=>{const n=xu(t,A);n&&K(n,{replace:!0})},[A,K]),za=(0,s.useCallback)(()=>{if(!ne){if(!R){Ge.current=!1;return}if(P.current&&Ra.current!==1&&(P.current.playbackRate=Ra.current),P.current&&Tr(P.current),Ge.current&&P.current){Ge.current=!1;const t=P.current.currentTime||0;P.current.play().then(()=>{Pt(!1),Te(!0),r&&x>
7=0&&I.audioPlayed(r,x),I.track($.AUDIO_PLAY,{book_slug:r,chapter_slug:Z,chapter_number:ue,resumed:t>1})}).catch(n=>{console.warn("[AutoPlay] canplaythrough play() rejected:",n?.name??n),n?.name==="NotAllowedError"&&Pt(!0),Te(!1)})}}},[ne,R,r,x,Tr,Z,ue]);(0,s.useEffect)(()=>{if(!u?.sections?.length)return;const t=u.sections.find((n,d)=>se>=n.startTime&&(d===u.sections.length-1||se<u.sections[d+1].startTime));if(t){const n=u.sections.findIndex(d=>d.id===t.id);n!==Jt&&xo(n)}},[se,u?.sections,Jt]);const Ha=(0,s.useCallback)(()=>{if(!P.current)return;st.current=P.current.currentTime;const t=Date.now();t-uo.current<250||(uo.current=t,gt(P.current.currentTime))},[]),Wa=(0,s.useCallback)(()=>{P.current&&Gr(P.current.duration)},[]),qa=(0,s.useCallback)(()=>{Te(!1),Js(!0),Ge.current=!1},[]),Va=(0,s.useCallback)(()=>{Qr(!0)},[]),Ya=(0,s.useCallback)(()=>{Qr(!1)},[]),Zl=(0,s.useCallback)(async()=>{Te(!1),gt(0),P.current&&(P.current.currentTime=0),st.current=0,u?.id&&br(u.id);const t=ri(Lt.current?new Set(De.current):await Sr(),u?.id),n=Date.now(),d=Math.floor((n-Xt.current)/1e3),y=x===g.length-1,j=!!(R&&u?.id&&!mt(u)&&ai(g,t));if(R&&u?.id&&(Ts(t),De.current=t,Ve({lessonId:u.id,bookId:i?.id,progress:{completed:!0,audioPosition:0,additionalTimeSpent:d}}),Xt.current=n,ie?.isBetaUser&&r)){const N=u?.orderIndex??x;cn.hasRatedChapter(r,N).then(B=>{B||setTimeout(()=>{bl(N),Vn(!0)},2e3)})}if(j&&i?.id&&F?.id&&si.markBookFinished(F.id,i.id).catch(()=>{}),r&&(I.chapterCompleted(r,x,d),I.audioCompleted(r,x,Math.floor(G))),ko(),r&&R&&F?.id){const N=`sb_first_chapter_finished_${F.id}`;try{localStorage.getItem(N)||(localStorage.setItem(N,new Date().toISOString()),I.track($.FIRST_CHAPTER_FINISHED,{book_slug:r,chapter_number:x,time_spent_seconds:d}))}catch{}}Vt&&q("medium"),j?(hs(),be(),r&&I.bookCompleted(r),setTimeout(()=>qn(!0),1500),F?.email&&i?.title&&Ut.onBookFinished(F.email,i.title)):(Ee(),St&&!As.current&&!(Ke&&(Ae?wt:!y))&&(As.current=!0,At(!0),r&&I.track($.CHAPTER_COMPLETE_SHEET_VIEW,{book_slug:r,chapter_number:x,trigger:"audio"}
7))),F?.email&&i?.title&&Ut.onChapterCompleted(F.email,i.title,x+1),fe(async()=>{const{nativeNotificationHaptic:N}=await import("./CapacitorService-C0-1L8yK.js").then(B=>B.t);return{nativeNotificationHaptic:N}},__vite__mapDeps([134,3,1,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,135])).then(({nativeNotificationHaptic:N})=>{N("success")}),Zr(!0),nt.current&&(clearTimeout(nt.current),nt.current=null),nt.current=setTimeout(()=>{if(Zr(!1),Ae){Ke&&wt&&Q.nextPath&&xs.current===x&&v(Q.nextPath,{state:l.state});return}if(Ke&&!y){const B=xs.current+1,X=g[B];X&&(Hs({chapterIndex:B,isAuthenticated:R,isPremium:O,isAdmin:ie?.isAdmin??!1,isBookCurrentlyFree:Ce,isChapterPreviouslyUnlocked:X.id?ke(X.id):!1,hasDomainEntitlement:Ie,isCreatorShared:Me,...et(X)}).action==="paywall"?(yt(!0),lr(B)):(v(`/domain/${a}/topic/${r}/${X.slug}`,{replace:!0}),Qs(B)))}const N=g[x+2];if(N&&r&&!Fr.isDownloaded(N.slug)){const B=N.audioUrl,X=N.infographicUrl;B&&X&&Fr.downloadChapter(N.slug,r,B,X,void 0,a,{bookTitle:i?.title,bookAuthor:i?.author,bookCoverUrl:i?.coverUrl,chapterTitle:N.title}).catch(()=>{})}},Vt?1500:700)},[Ae,wt,Q.nextPath,l.state,Ke,G,x,g,Ee,be,R,O,ie?.isAdmin,ie?.isBetaUser,u,Sr,br,Ve,hs,v,a,r,i?.id,i?.title,i?.author,i?.coverUrl,F?.id,F?.email,Vt,Ce,Ie,ke,yt,ko]),Ps=(0,s.useCallback)(()=>{if(!R){vn(!0);return}if(P.current){if(ce){const t=Math.floor(P.current.currentTime||0);ze(),P.current.pause(),Te(!1),I.track($.AUDIO_PAUSE,{book_slug:r,chapter_slug:Z,chapter_number:ue,seconds_listened:t})}else{const t=(P.current.currentTime||0)>1;Pt(!1),P.current.play().then(()=>{Te(!0),i?.id&&F?.id&&zs.recordBookView(F.id,i.id)}).catch(n=>{n?.name==="NotAllowedError"&&Pt(!0),Te(!1)}
7),r&&I.audioPlayed(r,x),I.track($.AUDIO_PLAY,{book_slug:r,chapter_slug:Z,chapter_number:ue,resumed:t})}q("medium")}},[ze,R,ce,r,x,Z,ue,i?.id,F?.id]),ec=(0,s.useCallback)(()=>{pr(t=>!t)},[]),Ls=(0,s.useCallback)(()=>{const t=gr[(gr.indexOf(je)+1)%gr.length];Wi(t),P.current&&(P.current.playbackRate=t),I.track($.AUDIO_SPEED_CHANGED,{book_slug:r,chapter_slug:Z,chapter_number:ue,speed:t})},[je,gr,r,Z,ue]),jt=(0,s.useCallback)(()=>{if(P.current){const t=Math.max(P.current.currentTime||0,st.current),n=Math.max(0,t-10);P.current.currentTime=n,st.current=n,gt(n),q("light")}},[]),Nt=(0,s.useCallback)(()=>{const t=P.current;if(!t)return;const n=t.duration,d=Number.isFinite(n)&&n>0?n:1/0,y=Math.max(t.currentTime||0,st.current),j=Math.min(d,y+10);t.currentTime=j,st.current=j,gt(j),q("light")},[]),Lo=Kd({onSwipeLeft:Nt,onSwipeRight:jt},{threshold:60,maxVerticalMovement:80}),_r=Gd({onDoubleTapLeft:jt,onDoubleTapRight:Nt,onDoubleTapCenter:Ps}),Ka=(0,s.useCallback)(()=>{P.current&&(ze(),P.current.pause(),Te(!1))},[ze]);(0,s.useEffect)(()=>{Ra.current=je},[je]),(0,s.useEffect)(()=>{P.current&&(P.current.playbackRate=je)},[je,tt]);const Er=(0,s.useCallback)(()=>{Pa(!0),$t.current&&clearTimeout($t.current),ce&&or&&($t.current=setTimeout(()=>{Pa(!1)},3e3))},[ce,or]);(0,s.useEffect)(()=>{ce?Er():(Pa(!0),$t.current&&clearTimeout($t.current))},[ce,Er]),(0,s.useEffect)(()=>()=>{$t.current&&clearTimeout($t.current)},[]);const Fo=(0,s.useCallback)(t=>{const n=parseFloat(t.target.value);if(P.current){const d=Math.floor(P.current.currentTime||0);P.current.currentTime=n,gt(n),I.track($.AUDIO_SEEK,{book_slug:r,chapter_slug:Z,chapter_number:ue,from_seconds:d,to_seconds:Math.floor(n)})}},[r,Z,ue]),Fs=(0,s.useCallback)(t=>{if(P.current){const n=Math.floor(P.current.currentTime||0);P.current.currentTime=t,st.current=t,gt(t),I.track($.AUDIO_SEEK,{book_slug:r,chapter_slug:Z,chapter_number:ue,from_seconds:n,to_seconds:Math.floor(t)})}},[r,Z,ue]);_c({enabled:R&&!D.current,userId:F?.id,lessonId:u?.id,activeMediaLessonId:Ft.current,durationSeconds:G,currentPositionSeconds:P.current?.currentTime??se,seekTo:Fs}),(0,s.useEffect)(()=>{},[ze,Fs]);const ht=(0,s.useCallback)(t=>{if(t<0||t>=g.length||!a||!r)return;ze();const n=g[t],d=Hs({chapterIndex:t,isAuthenticated:R,isPremium:O,isAdmin:ie?.isAdmin??!1,isBookCurrentlyFree:Ce,isChapterPreviouslyUnlocked:n?.id?ke(n.id):!1,hasDomainEntitlement:Ie,isCreatorShared:Me,...et(n)});if(d.action==="login"){sessionStorage.setItem("returnTo",window.location.pathname),v("/login");return}if(d.action==="paywall"){lr(t),yt(!0),q("light"),I.track(R?$.PAYWALL_HIT:$.ANON_PAYWALL_HIT,{book_slug:r,domain_slug:a,chapter_index:t,chapter_slug:n?.slug}),F?.email&&i?.title&&r&&Ut.onPaywallHit(F.email,i.title,r,a);return}const y=g[t];if(mt(y)){v(os.book(a,r),{replace:!0});return}Yr(t>xs.current?1:-1),v(`/domain/${a}/topic/${r}/${y.slug}`,{replace:!0}),Qs(t)},[g,ze,a,r,v,R,O,ie?.isAdmin,Ce,Ie,ke,F?.email,i?.title]),xe=(0,s.useCallback)(()=>{if(Ae){wt&&Q.nextPath&&(ze(),v(Q.nextPath,{state:l.state}));return}x<g.length-1&&(ht(x+1),q("medium"))},[Ae,wt,Q.nextPath,ze,v,l.state,x,g.length,ht]),Pe=(0,s.useCallback)(()=>{if(Ae){Cs&&Q.previousPath&&(ze(),v(Q.previousPath,{state:l.state}));return}x>0&&(ht(x-1),q("medium"))},[Ae,Cs,Q.previousPath,ze,v,l.state,x,ht]),$o=(0,s.useRef)(xe),Mo=(0,s.useRef)(Pe);(0,s.useEffect)(()=>{$o.current=xe,Mo.current=Pe},[xe,Pe]),(0,s.useEffect)(()=>{const t={next:()=>$o.current(),previous:()=>Mo.current()};return Go(t),()=>{Xc()===t&&Go(null)}},[]),(0,s.useEffect)(()=>{const t=()=>{pe&&!Gt&&oa()};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t)}},[Gt,pe,oa]),(0,s.useEffect)(()=>{const t=n=>{n.target instanceof HTMLInputElement||n.target instanceof HTMLTextAreaElement||(n.key==="ArrowLeft"?n.shiftKey&&me?jt():Pe():n.key==="ArrowRight"?n.shiftKey&&me?Nt():xe():n.key==="j"||n.key==="J"?me&&jt():n.key==="l"||n.key==="L"?me&&Nt():n.key==="a"||n.key==="A"?pr(d=>!d):n.key==="Escape"?Ca&&(n.preventDefault(),Ta(!1)):n.key==="f"||n.key==="F"?pe?Se():It():n.key==="?"?Ta(d=>!d):n.key===" "&&me?(n.preventDefault(),Ps()):(n.key==="s"||n.key==="S")&&Ls())};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[me,Ls,Se,pe,xe,Pe,It,Ca,jt,Nt,Ps]);const tc=(0,s.useCallback)(t=>{if(!Ne||t.touches.length!==1){ar.current=null;return}nr.current=!1,ar.current={x:t.touches[0].clientX,y:t.touches[0].clientY}},[Ne]),sc=(0,s.useCallback)(t=>{const n=ar.current;if(ar.current=null,!Ne||!n||t.changedTouches.length!==1){_r.onTouchEnd?.(t);return}const d=t.changedTouches[0].clientX-n.x,y=t.changedTouches[0].clientY-n.y;
7if(Math.abs(d)>Math.abs(y)&&Math.abs(d)>70){nr.current=!0,t.preventDefault(),d<0?xe():Pe();return}_r.onTouchEnd?.(t)},[_r,xe,Pe,Ne]),rc=(0,s.useCallback)(t=>{if(!de)return;const n=t.touches[0];rr.current={x:n.clientX,y:n.clientY},Kt.current={x:n.clientX,y:n.clientY},vs.current=!1,it.current=setTimeout(()=>{q("medium"),Sn(!0)},600)},[de]),Oo=(0,s.useCallback)(()=>{it.current&&(clearTimeout(it.current),it.current=null)},[]),ac=(0,s.useCallback)(t=>{ht(t),q("light")},[ht]),nc=(0,s.useCallback)(t=>{if(!u?.sections||t<0||t>=u.sections.length)return;const n=u.sections[t];Fs(n.startTime)},[u?.sections,Fs]);(0,s.useEffect)(()=>{if(!ho.current||!i?.slug)return;const t=new IntersectionObserver(n=>{n[0].isIntersecting&&(I.feedbackWidgetViewed(i.slug,x),t.disconnect())},{threshold:.5});return t.observe(ho.current),()=>t.disconnect()},[i?.slug,x]),(0,s.useEffect)(()=>{ea(!1),Ia.current=!1},[x]),(0,s.useEffect)(()=>{const t=mo.current;if(!t||typeof IntersectionObserver>"u")return;const n=new IntersectionObserver(d=>{d[0].isIntersecting&&!Ia.current&&ea(!0)},{threshold:.1});return n.observe(t),()=>n.disconnect()},[x,w!=="chat"&&w!=="ideas",_t]),(0,s.useEffect)(()=>{const t=Us;if(!t||!dt)return;const n=u?.audioPath||u?.audioUrl||dt,d=Qc(),y=n&&t.src&&d===n?!0:!!t.src&&(t.src.endsWith(dt)||t.src===dt);y||(Kc(n||null),t.src=dt,gt(0),Gr(0),Js(!1),Qr(!0)),Ge.current&&!ne&&R?(Tr(t),Ge.current=!1,t.play().then(()=>{Pt(!1),Te(!0)}).catch(j=>{console.debug("[AutoPlay] Wire-src play() deferred to canplaythrough:",j?.name??j),j?.name==="NotAllowedError"&&Pt(!0),Ge.current=!0,t.load()})):(!ne&&!R&&(Ge.current=!1),y||t.load())},[dt,u?.audioPath,u?.audioUrl,ne,R,Tr]);const Ga=(0,s.useCallback)(()=>Te(!0),[]),Xa=(0,s.useCallback)(()=>Te(!1),[]);Fd(!0,Zl),(0,s.useEffect)(()=>{const t=Us;if(t)return t.addEventListener("timeupdate",Ha),t.addEventListener("loadedmetadata",Wa),t.addEventListener("canplaythrough",za),t.addEventListener("error",qa),t.addEventListener("waiting",Va),t.addEventListener("canplay",Ya),t.addEventListener("play",Ga),t.addEventListener("pause",Xa),()=>{t.removeEventListener("timeupdate",Ha),t.removeEventListener("loadedmetadata",Wa),t.removeEventListener("canplaythrough",za),t.removeEventListener("error",qa),t.removeEventListener("waiting",Va),t.removeEventListener("canplay",Ya),t.removeEventListener("play",Ga),t.removeEventListener("pause",Xa)}},[Ha,Wa,za,qa,Va,Ya,Ga,Xa]),(0,s.useEffect)(()=>{Us&&(Us.playbackRate=je)},[je]);const ss=u?.sections?.[Jt]||null,Rr=ss?.focusRegion||{x:0,y:0,width:100,height:100},Bo=ss?.activeRegions;if(_t)return ps?(0,e.jsx)("div",{className:"flex min-h-screen items-center justify-center bg-stone-50 p-4 dark:bg-stone-950",children:(0,e.jsx)(sd,{title:"Still loading this chapter",description:"Retry to reconnect without losing your reading place.",onRetry:()=>ae(t=>t+1)})}):(0,e.jsx)(n0,{bookLabel:pi(r,"Book"),chapterLabel:pi(o,"Chapter")});if(Et)return(0,e.jsx)("div",{className:"min-h-screen bg-stone-50 dark:bg-stone-950 flex items-center justify-center p-4","data-testid":"reader-load-error",children:(0,e.jsx)(S.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},transition:{duration:.3},className:"max-w-md w-full",children:(0,e.jsxs)("div",{className:"bg-white dark:bg-stone-900 rounded-2xl shadow-xl p-8 text-center border border-stone-100 dark:border-stone-800",children:[(0,e.jsx)(Ja,{icon:ns,size:"xl",variant:"warning",className:"mx-auto mb-6 text-amber-500 dark:text-amber-500"}),(0,e.jsx)(Lr,{variant:"h2",className:"font-bold mb-2",children:"Reader temporarily unavailable"}),(0,e.jsx)("p",{className:"text-stone-500 dark:text-stone-400 mb-8 leading-relaxed",children:Et}),(0,e.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,e.jsxs)("button",{onClick:()=>ae(t=>t+1),className:"flex-1 inline-flex items-center justify-center gap-2 py-3 px-6 bg-stone-900 hover:bg-stone-800 dark:bg-white dark:hover:bg-stone-200 text-white dark:text-stone-900 font-bold rounded-xl transition-all duration-200 shadow-lg hover:shadow-xl active:scale-95",children:[(0,e.jsx)(Ko,{className:"w-4 h-4"}),"Try Again"]}),(0,e.jsxs)("button",{onClick:()=>v("/explore"),className:"flex-1 inline-flex items-center justify-center gap-2 py-3 px-6 bg-stone-100 hover:bg-stone-200 dark:bg-stone-800 dark:hover:bg-stone-700 text-stone-700 dark:text-stone-200 font-semibold rounded-xl transition-all duration-200",children:[(0,e.jsx)(qo,{className:"w-4 h-4"}),"Back to Explore"]})]})]})})});if(i&&i.visibility==="private"&&i.ownerUserId&&i.ownerUserId!==(F?.id??null))return(0,e.jsx)("div",{className:"min-h-screen bg-stone-50 dark:bg-stone-950 flex items-center justify-center p-4",children:(0,e.jsxs)("div",{className:"max-w-md w-full bg-white dark:bg-stone-900 rounded-2xl shadow-xl p-8 text-center border border-stone-100 dar
7k:border-stone-800",children:[(0,e.jsx)(Ja,{icon:ns,size:"xl",variant:"neutral",className:"mx-auto mb-6"}),(0,e.jsx)(Lr,{variant:"h2",className:"font-bold mb-2",children:"This book is private"}),(0,e.jsx)("p",{className:"text-stone-500 dark:text-stone-400 mb-8 leading-relaxed",children:"The creator hasn't shared this book publicly yet. If you think this is a mistake, ask them for an updated link."}),(0,e.jsx)("button",{onClick:()=>v("/explore"),className:"w-full py-3 px-6 bg-stone-900 hover:bg-stone-800 dark:bg-white dark:hover:bg-stone-200 text-white dark:text-stone-900 font-bold rounded-xl transition-all duration-200 shadow-lg hover:shadow-xl active:scale-95",children:"Back to Explore"})]})});if(!le||!i)return(0,e.jsx)("div",{className:"min-h-screen bg-stone-50 dark:bg-stone-950 flex items-center justify-center p-4",children:(0,e.jsx)(S.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},transition:{duration:.4},className:"max-w-md w-full",children:(0,e.jsxs)("div",{className:"bg-white dark:bg-stone-900 rounded-2xl shadow-xl p-8 text-center border border-stone-100 dark:border-stone-800",children:[(0,e.jsx)(Ja,{icon:ns,size:"xl",variant:"neutral",className:"mx-auto mb-6 text-gold-500 dark:text-gold-500"}),(0,e.jsx)(Lr,{variant:"h2",className:"font-bold mb-2",children:"Content Not Found"}),(0,e.jsx)("p",{className:"text-stone-500 dark:text-stone-400 mb-8 leading-relaxed",children:"We couldn't find the topic or domain you requested. It may have been moved or doesn't exist."}),(0,e.jsx)("button",{onClick:()=>v("/explore"),className:"w-full py-3 px-6 bg-stone-900 hover:bg-stone-800 dark:bg-white dark:hover:bg-stone-200 text-white dark:text-stone-900 font-bold rounded-xl transition-all duration-200 shadow-lg hover:shadow-xl active:scale-95",children:"Return to Explore"})]})})});if(o&&!Vr&&g.length===0)return(0,e.jsx)("div",{className:"min-h-screen bg-stone-50 dark:bg-stone-950 flex items-center justify-center",children:(0,e.jsx)(S.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},transition:{duration:.4},children:(0,e.jsxs)("div",{className:"p-8 text-center max-w-md bg-white/70 backdrop-blur-xl border border-stone-200/50 shadow-xl rounded-2xl",children:[(0,e.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-red-100 to-red-200 flex items-center justify-center mx-auto mb-4",children:(0,e.jsx)(Wr,{className:"w-8 h-8 text-red-600"})}),(0,e.jsx)(Lr,{variant:"h2",className:"mb-2",children:"Chapters unavailable"}),(0,e.jsxs)("p",{className:"text-stone-500 mb-6",children:["â",i.title,"â is still being prepared."]}),(0,e.jsxs)("button",{onClick:()=>v(`/domain/${a}`),className:"inline-flex items-center gap-2 px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg shadow-lg",children:[(0,e.jsx)(qo,{className:"w-4 h-4"}),"Back to Domain"]})]})})});const T=le?.color||"#F59E0B",oc=a==="fiction",rs=Math.max(1,x-vr+1),$s=La,Qa=Ne&&Oe,Ms=!Qa,as=!Ne,ic=!Ne,Ir=g[ha]??null,Dt=Math.max(1,Ir?.orderIndex??ha-vr+1),Do=g.filter((t,n)=>n>=ha&&!mt(t)).length,Uo=ms?`${ms}+ published books`:"all published books",Ar=[{id:"chapter",label:"Locked chapter",value:`Chapter ${Dt}: ${Ir?.title??"Locked chapter"}`},{id:"remaining",label:"Remaining value",value:`${Do} learning chapter${Do===1?"":"s"} from here`},{id:"catalog",label:"Premium library",value:Uo},{id:"billing",label:"Annual billing",value:`$${Td.toFixed(2)}/month equivalent · $${Cd.annual.toFixed(2)}/year after the 30-day trial`}],Pr={imageUrl:Ir?.infographicUrl??null,title:`Chapter ${Dt} is locked`,subtitle:Ir?.title},zo=Bn?Dd({title:"Premium is active",body:`Chapter ${Dt} and every published learning chapter are now unlocked.`,facts:Ar,preview:Pr}):R?rt()&&ma?zd({facts:Ar,preview:Pr}):Ud({title:`Unlock chapter ${Dt} and every chapter`,body:`Start a free trial to continue this book and open ${Uo}.`,primaryActionLabel:rt()?"Subscribe at scrollbook.io":"View Premium plans",facts:Ar,preview:Pr}):Hd({title:`Sign in to continue with chapter ${Dt}`,body:"Create a free account to save your place and keep your free preview synced across devices.",primaryActionLabel:"Sign in",facts:Ar.slice(0,2),preview:Pr}),Os=()=>{yt(!1),ws(!1)},Ho=()=>{I.track($.PAYWALL_DISMISSED,{source:"topic",book_slug:r,chapter_number:Dt,program_version:Ds}),Os()},lc=()=>
7{if(I.track($.PAYWALL_PRIMARY_CTA,{source:"topic",variant:zo.kind,book_slug:r,chapter_number:Dt,program_version:Ds}),Bn){Os();return}if(!R){I.track($.PAYWALL_SIGN_IN,{source:"topic",book_slug:r,program_version:Ds}),Os(),v(`/login?redirect=${encodeURIComponent(l.pathname+l.search)}`);return}if(!rt()){Os(),v("/pricing");return}if(!ma){I.track($.PAYWALL_BILLING_DISCLOSURE_VIEWED,{source:"topic",book_slug:r,program_version:Ds}),ws(!0);return}fe(async()=>{const{Browser:t}=await import("./esm-COsXcn5P.js");return{Browser:t}},__vite__mapDeps([136,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32])).then(({Browser:t})=>t.open({url:"https://scrollbook.io/pricing?source=ios_app&utm_medium=native_paywall"})).finally(Os)},cc=or&&u&&(0,e.jsx)(qr,{open:!0,onOpenChange:t=>{!t&&pe&&Se()},title:`${i?.title??"Book"} immersive reader`,ariaLabel:`${i?.title??"Book"} immersive reader`,placement:"fullscreen",dismissible:pe,initialFocus:pe?"first":"panel",initialFocusRef:pe?jn:void 0,returnFocusRef:pe?Nn:void 0,headerHidden:!0,className:"border-0 bg-black text-white",backdropClassName:"bg-black backdrop-blur-none",contentClassName:"overflow-hidden p-0",testId:"topic-immersive-reader",children:(0,e.jsx)(J,{children:(0,e.jsxs)(S.div,{initial:as?{opacity:0}:!1,animate:{opacity:1},exit:as?{opacity:0}:{opacity:1},transition:as?{duration:.18,ease:"easeOut"}:{duration:0},className:"relative h-full w-full overflow-hidden bg-black",onMouseMove:Er,children:[ic&&(0,e.jsx)(bi,{color:T,prefersReducedMotion:ot??void 0}),(0,e.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center px-0 pb-[calc(env(safe-area-inset-bottom,0px)+5.5rem)] pt-[calc(env(safe-area-inset-top,0px)+3.5rem)] sm:px-4 sm:pb-24 sm:pt-16",onClick:()=>{if(Ne){if(nr.current){nr.current=!1;return}Gt||oa(),Er();return}Se()},onTouchStart:tc,onTouchEnd:sc,children:(0,e.jsxs)(S.div,{initial:as?{scale:.95,opacity:0}:!1,animate:{scale:1,opacity:1},exit:as?{scale:.95,opacity:0}:{scale:1,opacity:1},transition:as?{duration:.32,ease:"easeOut"}:{duration:0},className:"relative max-h-[calc(100dvh-9rem)] max-w-full sm:max-h-[calc(100dvh-10rem)]",children:[(0,e.jsx)("img",{src:ee||void 0,alt:u.title,className:"max-h-[calc(100dvh-9rem)] max-w-[100vw] object-contain sm:max-h-[calc(100dvh-10rem)] sm:max-w-[calc(100vw-2rem)]"},u.slug),ss&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(ui,{activeRegions:Bo,focusRegion:Rr,isActive:!0}),(0,e.jsx)(hi,{focusRegion:Rr,color:"gold",intensity:"subtle",isActive:!0})]})]})}),!Ne&&(0,e.jsx)("div",{className:"absolute z-40",style:{top:"max(8px, env(safe-area-inset-top, 0px))",right:"max(8px, env(safe-area-inset-right, 0px))"},children:(0,e.jsx)("button",{ref:jn,type:"button",onClick:t=>{t.stopPropagation(),Se()},className:"flex h-11 w-11 items-center justify-center rounded-lg border border-white/10 bg-black/35 backdrop-blur-md transition-colors hover:bg-black/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70","aria-label":"Exit fullscreen",children:(0,e.jsx)(Hr,{className:"w-4 h-4 text-white"})})}),(0,e.jsx)("div",{className:"absolute z-20 max-w-[calc(100%_-_4rem)] sm:max-w-[60%]",style:{top:"max(8px, env(safe-area-inset-top, 0px))",left:"max(8px, env(safe-area-inset-left, 0px))"},children:(0,e.jsxs)("span",{className:"inline-flex items-center truncate rounded-full border border-white/10 bg-black/30 px-3 py-1.5 text-xs font-medium text-white/85 backdrop-blur-md",children:[(0,e.jsxs)("span",{className:"hidden sm:inline",children:[rs,"/",$s," · "]}),(0,e.jsxs)("span",{className:"sm:hidden",children:[rs,". "]}),(0,e.jsx)("span",{className:"truncate",children:u.title})]})}),(0,e.jsx)(J,{children:x>0&&(0,e.jsx)(S.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:"absolute left-2 sm:left-4 top-1/2 -translate-y-1/2 z-20",children:(0,e.jsx)(Jo,{direction:"prev",onClick:t=>
7{t?.stopPropagation(),Pe()},variant:"fullscreen",showLabel:!0})})}),(0,e.jsx)(J,{children:x<g.length-1&&(0,e.jsx)(S.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},className:"absolute right-2 sm:right-4 top-1/2 -translate-y-1/2 z-20",children:(0,e.jsx)(Jo,{direction:"next",onClick:t=>{t?.stopPropagation(),xe()},variant:"fullscreen",showLabel:!0})})}),(0,e.jsx)(J,{children:me&&bo&&(0,e.jsx)(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:20},transition:{type:"spring",stiffness:300,damping:30},className:W("absolute left-1/2 z-30 -translate-x-1/2",Ne?"w-[94vw] max-w-[860px]":"w-[95%] sm:w-auto max-w-lg"),style:{bottom:"max(16px, env(safe-area-inset-bottom, 0px))"},onClick:t=>t.stopPropagation(),children:(0,e.jsxs)("div",{className:W("flex items-center backdrop-blur-2xl shadow-2xl shadow-black/50 border bg-stone-950/80 border-white/10 ring-1 ring-white/5",Qa?"gap-3 px-4 py-2.5 rounded-[28px]":"gap-1 px-2 py-0.5 sm:gap-3 sm:px-4 sm:py-2.5 rounded-full"),...Lo,children:[(0,e.jsxs)("button",{onClick:jt,"aria-label":"Rewind 10 seconds",className:"relative flex h-11 w-11 flex-shrink-0 touch-manipulation items-center justify-center rounded text-white/60 transition-colors hover:text-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-white/50",children:[(0,e.jsx)(Ti,{className:"w-5 h-5"}),(0,e.jsx)("span",{className:"absolute inset-0 flex items-center justify-center text-xs font-bold translate-y-[2px]",children:"10"})]}),(0,e.jsx)("button",{onClick:Ps,"aria-label":ce?"Pause":"Play",className:"flex h-11 w-11 flex-shrink-0 touch-manipulation items-center justify-center rounded-full text-white transition-opacity hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/50",style:{backgroundColor:T},children:ce?(0,e.jsx)(on,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"}):(0,e.jsx)(Vs,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4 ml-0.5"})}),(0,e.jsxs)("button",{onClick:Nt,"aria-label":"Forward 10 seconds",className:"relative flex h-11 w-11 flex-shrink-0 touch-manipulation items-center justify-center rounded text-white/60 transition-colors hover:text-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-white/50",children:[(0,e.jsx)(ln,{className:"w-5 h-5"}),(0,e.jsx)("span",{className:"absolute inset-0 flex items-center justify-center text-xs font-bold translate-y-[2px]",children:"10"})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5 sm:gap-2 flex-1 min-w-0",children:[(0,e.jsx)("span",{className:"text-xs text-white/60 font-mono w-8 sm:w-10 flex-shrink-0",children:Yo(se)}),(0,e.jsxs)("div",{className:W("relative flex h-11 flex-1 items-center",Qa?"min-w-[140px]":"min-w-[60px]"),children:[(0,e.jsx)("div",{className:"absolute inset-x-0 h-1 overflow-hidden rounded-full bg-white/20",children:(0,e.jsx)(S.div,{className:"h-full rounded-full",style:{width:`${G?se/G*100:0}%`,backgroundColor:T}})}),(0,e.jsx)("input",{type:"range","aria-label":"Seek audio",min:"0",max:G||100,value:se,onChange:Fo,className:"absolute inset-0 h-full w-full cursor-pointer opacity-0"})]}),Ms&&(0,e.jsxs)("span",{className:"text-xs text-white/60 font-mono w-8 sm:w-10 flex-shrink-0 hidden sm:block",children:["-",Yo(Math.max(0,G-se))]})]}),Ms&&(0,e.jsxs)("button",{onClick:Ls,"aria-label":`Playback speed ${je}x`,className:"hidden h-11 min-w-11 flex-shrink-0 items-center justify-center rounded px-1 text-xs font-mono transition-colors sm:flex",style:je!==1?{color:T,backgroundColor:`${T}25`}:{color:"rgba(255,255,255,0.5)"},children:[je,"x"]}),Ms&&(0,e.jsx)(ei,{onTimerEnd:Ka,isPlaying:ce,className:"hidden sm:block [&_button]:min-w-11",iconOnly:!0}),Ms&&(0,e.jsx)("div",{className:"w-px h-5 bg-white/20 hidden sm:block"}),(0,e.jsxs)("div",{className:"flex items-center gap-0.5 sm:gap-1",children:[(0,e.jsx)("button",{onClick:Pe,disabled:!Cs,"aria-label":"Previous chapter",className:"flex h-11 w-11 touch-manipulation items-center justify-center rounded text-white/60 transition-colors hover:text-white disabled:cursor-not-allowed disabled:opacity-30 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-white/50",children:(0,e.jsx)(_i,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"})}),Ms&&(0,e.jsxs)("span",{className:"text-xs font-medium px-0.5 sm:px-1 text-white/50",children:[rs,"/",$s]}),(0,e.jsx)("button",{onClick:xe,disabled:!wt,"aria-label":"Next chapter",className:"flex h-11 w-11 touch-manipulation items-center justify-center rounded text-white/60 transition-colors hover:text-white disabled:cursor-not-allowed disabled:opacity-30 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-white/50",children:(0,e.jsx)(Ei,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"})})]})]})})}),(0,e.jsx)(J,{children:me&&!bo&&ce&&(0,e.jsx)(S.div,{initial:{opacity:0}
7,animate:{opacity:1},exit:{opacity:0},className:"absolute bottom-4 left-1/2 -translate-x-1/2 z-30",children:(0,e.jsx)("div",{className:"text-xs text-white/60 bg-black/60 px-3 py-1.5 rounded-full backdrop-blur-sm border border-white/10",children:Ne?(0,e.jsx)("span",{children:"Tap to show controls"}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"sm:hidden",children:"Tap to show controls · â top-right to exit"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"Move mouse to show controls · â top-right to exit"})]})})})})]},"fullscreen-overlay")})});return(0,e.jsxs)(e.Fragment,{children:[Ae&&(Q.isPending||!Q.isExact)&&(0,e.jsxs)("div",{role:"status",className:"fixed top-2 left-1/2 z-50 -translate-x-1/2 rounded-lg bg-stone-900 px-3 py-2 text-sm text-white shadow",children:[Q.isPending?"Loading your book sequenceâ¦":"This chapter is unavailable in the combined sequence.",!Q.isPending&&(0,e.jsx)(Ze,{className:"ml-2 underline",to:C||os.book(a,r),state:l.state,children:"Back to book"})]}),cc,!Oe&&(0,e.jsx)(Hu,{isFreePromo:Pl,promo:Ll,bookId:i?.id}),i&&(0,e.jsx)(Lu,{isVisible:Gt,bookTitle:i.title,domainSlug:a||"",topicSlug:r||"",isFullscreen:or,isZenMode:Yt,onExitFullscreen:Ne?void 0:Se,onBookmark:dl,onShare:ul,onToggleZen:()=>{el(t=>!t),q("medium")},isBookmarked:ia}),(0,e.jsx)(Eu,{show:ll,onChoice:cl}),An&&(0,e.jsx)("style",{children:` 8 @keyframes fullscreen-pulse { 9 0%, 100% { 10 opacity: 1; 11 transform: scale(1); 12 } 13 50% { 14 opacity: 0.7; 15 transform: scale(1.15); 16 } 17 } 18 .fullscreen-button-pulse { 19 animation: fullscreen-pulse 2s ease-in-out infinite; 20 } 21 `}),(0,e.jsx)("style",{children:` 22 @media (max-width: 1023px) { 23 header, 24 [data-mobile-header], 25 nav[role="banner"] { 26 display: none !important; 27 } 28 } 29 `}),(0,e.jsx)($u,{isOpen:Ca,onClose:()=>Ta(!1)}),(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(S.div,{variants:a0,initial:"initial",animate:"animate",exit:"exit",className:W("min-h-screen overflow-x-hidden relative transition-colors duration-700",Yt?"bg-black":"bg-stone-50 dark:bg-stone-950"),children:[(0,e.jsx)(bi,{color:T,prefersReducedMotion:ot??void 0}),(0,e.jsx)("div",{className:"hidden bg-white/95 dark:bg-stone-900/95 backdrop-blur-sm border-b border-stone-200/80 dark:border-stone-800 sticky top-0 z-30",children:(0,e.jsx)("div",{className:"mx-auto px-4 md:px-6 py-2 md:py-3",children:(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,e.jsx)("button",{onClick:Pe,disabled:!Cs,className:"p-2.5 rounded-lg hover:bg-stone-100 dark:hover:bg-stone-800 text-stone-400 hover:text-stone-700 dark:hover:text-white disabled:opacity-25 disabled:cursor-not-allowed transition-colors touch-manipulation",children:(0,e.jsx)(an,{className:"w-4 h-4"})}),(0,e.jsx)("button",{onClick:xe,disabled:!wt,className:"p-2.5 rounded-lg hover:bg-stone-100 dark:hover:bg-stone-800 text-stone-400 hover:text-stone-700 dark:hover:text-white disabled:opacity-25 disabled:cursor-not-allowed transition-colors touch-manipulation",children:(0,e.jsx)(ft,{className:"w-4 h-4"})})]}),(0,e.jsxs)("div",{className:"flex-1 min-w-0 sm:hidden","data-testid":"active-chapter-slug","data-active-chapter-slug":u?.slug??"",children:[(0,e.jsxs)("p",{className:"text-sm font-semibold text-stone-800 dark:text-stone-200 truncate",children:[Rs,": ",u?.title||"Loading..."]}),(0,e.jsxs)("p",{className:"text-xs text-stone-400",children:[rs," of ",$s," chapters"]})]}),(0,e.jsxs)("nav",{className:"hidden sm:flex flex-1 min-w-0 items-center gap-1 text-[13px]",children:[(0,e.jsxs)(Ze,{to:"/",className:"text-stone-400 dark:text-stone-500 hover:text-stone-700 dark:hover:text-stone-300 transition-colors hidden md:flex items-center gap-1.5 flex-shrink-0",children:[(0,e.jsx)(Ur,{className:"w-4 h-4"}),(0,e.jsx)("span",{className:"hidden lg:inline font-semibold",children:"Scrollbook"})]}),(0,e.jsx)(ft,{className:"w-3 h-3 text-stone-300 dark:text-stone-600 hidden md:block flex-shrink-0"}),(0,e.jsx)(Ze,{to:`/domain/${a}`,className:"text-stone-500 dark:text-stone-400 hover:text-stone-700 dark:hover:text-stone-200 transition-colors flex-shrink-0",children:Xl||a}),(0,e.jsx)(ft,{className:"w-3 h-3 text-stone-300 dark:text-stone-600 flex-shrink-0"}),(0,e.jsx)(Ze,{to:C||`/domain/${a}/topic/${r}
29`,className:"font-medium text-stone-600 dark:text-stone-300 hover:text-stone-900 dark:hover:text-white truncate max-w-[160px] lg:max-w-[220px] transition-colors",title:i.title,children:i.title}),(0,e.jsx)(ft,{className:"w-3 h-3 text-stone-300 dark:text-stone-600 flex-shrink-0"}),(0,e.jsxs)("span",{className:"font-bold text-stone-800 dark:text-stone-100 truncate","data-testid":"active-chapter-slug","data-active-chapter-slug":u?.slug??"",children:[(0,e.jsxs)("span",{className:"font-semibold",style:{color:T},children:[Rs,":"]})," ",u?.title||"Loading..."]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsxs)("div",{className:"hidden lg:flex items-center gap-1 p-1 bg-stone-100 dark:bg-stone-800/60 rounded-lg border border-stone-200 dark:border-stone-700/50",children:[(0,e.jsxs)("button",{onClick:()=>ve("reading"),className:W("relative flex items-center gap-1.5 px-3 py-1.5 rounded-md transition-all duration-200 text-sm font-semibold",w==="reading"?"text-white shadow-md":"text-stone-600 dark:text-stone-400 hover:text-stone-900 dark:hover:text-white hover:bg-stone-200 dark:hover:bg-stone-700/50"),style:w==="reading"?{backgroundColor:T}:{},children:[(0,e.jsx)($c,{className:"w-4 h-4"}),(0,e.jsx)("span",{children:"Chapter Summary"})]}),(0,e.jsxs)("button",{onClick:()=>ve("visual"),className:W("relative flex items-center gap-1.5 px-3 py-1.5 rounded-md transition-all duration-200 text-sm font-semibold",w==="visual"?"text-white shadow-md":"text-stone-600 dar
29k:text-stone-400 hover:text-stone-900 dark:hover:text-white hover:bg-stone-200 dark:hover:bg-stone-700/50"),style:w==="visual"?{backgroundColor:T}:{},children:[(0,e.jsx)(dn,{className:"w-4 h-4"}),(0,e.jsx)("span",{children:"Highlight Cards"})]})]}),(0,e.jsx)(ni,{variant:"icon",bookSlug:i?.slug,chapterNumber:x,pageContext:"chapter_reader_desktop"}),(0,e.jsx)("button",{type:"button",onClick:()=>ir(!0),className:"inline-flex h-11 w-11 items-center justify-center rounded-[var(--sb-radius-control)] text-stone-500 transition-colors hover:bg-stone-100 active:bg-stone-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)] dark:hover:bg-stone-800 lg:hidden","aria-label":"Open chapter list",children:(0,e.jsx)(Oc,{className:"h-5 w-5 sm:h-4 sm:w-4"})})]})]})})}),(0,e.jsxs)("div",{className:"mx-auto px-0 pt-12 sm:pt-0 pb-16 md:pb-0 md:pt-0",children:[de&&(0,e.jsxs)("div",{className:"fixed top-0 left-0 right-0 flex flex-col z-50",style:{bottom:0,background:$e==="dark"?"#000":"#FFFFFF",paddingTop:"env(safe-area-inset-top, 0px)",paddingBottom:Gl},children:[(0,e.jsxs)("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",style:{zIndex:0},children:[(0,e.jsx)(J,{mode:"sync",children:Yl?(0,e.jsx)(S.img,{src:ee??void 0,alt:"","aria-hidden":"true",className:"absolute inset-0 w-full h-full object-cover",style:{transform:"scale(1.7)",transformOrigin:"50% 28%",filter:"blur(72px) saturate(1.9) brightness(0.9)"},initial:{opacity:0}
29,animate:er?{opacity:$e==="dark"?.36:.09}:ye&&ce&&!ot?{opacity:$e==="dark"?[.42,.58,.42]:[.11,.18,.11]}:{opacity:$e==="dark"?.36:.09},exit:{opacity:0},transition:er?{duration:0}:ye&&ce&&!ot?{duration:4.2,ease:"easeInOut",repeat:1/0,repeatType:"loop"}:{duration:1.4,ease:"easeInOut"}},ee):(0,e.jsx)(S.div,{className:"absolute inset-0",style:{background:`radial-gradient(ellipse at 50% 30%, ${T}55 0%, transparent 65%)`},initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:er?0:.8}},`color-fallback-${u?.slug??x}`)}),(0,e.jsx)("div",{className:"absolute inset-0",style:{background:$e==="dark"?"radial-gradient(ellipse 160% 90% at 50% 62%, transparent 28%, rgba(0,0,0,0.70) 85%)":"radial-gradient(ellipse 160% 90% at 50% 62%, transparent 38%, rgba(0,0,0,0.05) 85%)"}})]}),(0,e.jsx)(J,{children:Jr&&(0,e.jsxs)(S.div,{className:`absolute inset-0 pointer-events-none ${Ct("playerOverlay")} flex items-center justify-center`,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.28},children:[(0,e.jsx)("div",{className:"absolute inset-0",style:{background:`radial-gradient(ellipse at 50% 52%, ${T}2a 0%, transparent 68%)`}}),!ot&&(0,e.jsxs)(S.div,{initial:{scale:.82,opacity:0,y:14},animate:{scale:1,opacity:1,y:0},exit:{scale:.9,opacity:0,y:-8},transition:{type:"spring",damping:22,stiffness:300,delay:.07},className:"relative flex items-center gap-2 px-5 py-2.5 rounded-full",style:{background:"rgba(0,0,0,0.58)",backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",border:`1px solid ${T}50`,boxShadow:`0 0 0 4px ${T}12, 0 4px 28px ${T}30`},children:[(0,e.jsx)(pn,{className:"w-[15px] h-[15px] flex-shrink-0",style:{color:T}}),(0,e.jsx)("span",{className:"text-[13px] font-semibold tracking-tight",style:{color:"rgba(255,255,255,0.92)"},children:"Chapter Complete"})]})]},"chapter-complete-overlay")}),(0,e.jsx)("button",{className:`absolute ${Ct("playerOverlayControl")} flex items-center justify-center w-10 h-10 rounded-full transition-all touch-manipulation ${qe}`,style:{top:"calc(env(safe-area-inset-top, 0px) + 8px)",right:"max(16px, env(safe-area-inset-right, 16px))"},"aria-label":"Minimize to mini player",onClick:()=>{q("light"),v(b||-1)},children:(0,e.jsx)(Vo,{className:"w-5 h-5"})}),(0,e.jsx)(J,{children:gl&&(0,e.jsxs)(S.div,{initial:{opacity:0,x:10},animate:{opacity:1,x:0},exit:{opacity:0,x:10},transition:{duration:.3},className:`absolute ${Ct("playerOverlayBadge")} flex items-center gap-1 pointer-events-none`,style:{top:"calc(env(safe-area-inset-top, 0px) + 18px)",right:"max(56px, calc(env(safe-area-inset-right, 0px) + 56px))"},children:[(0,e.jsx)(Vo,{className:"w-3 h-3 text-white/40"}),(0,e.jsx)("span",{className:"text-[11px] font-medium text-white/40",children:"Swipe down to exit"})]})}),(0,e.jsxs)("div",{className:`flex flex-1 min-h-0 overflow-hidden ${U?"flex-row":"flex-col"}`,style:U?void 0:{paddingTop:12},children:[(0,e.jsxs)("div",{ref:ks,className:"relative flex-shrink-0",style:{flex:U?"0 0 65%":H?"1":"0 0 auto",width:U?"65%":"100%",height:U||H?"100%":void 0,maxHeight:!H&&!U&&Mt&&oe?"60dvh":void 0,overflow:"hidden"},onClick:It,onTouchStart:rc,onTouchEnd:t=>{if(Oo(),t.changedTouches.length!==1||tr||!Kt.current)return;const n=t.changedTouches[0].clientX-Kt.current.x,d=t.changedTouches[0].clientY-Kt.current.y;Math.abs(n)>Math.abs(d)&&Math.abs(n)>50&&(vs.current=!0,n<0?xe():Pe()),Kt.current=null},onTouchMove:t=>{if(rr.current){const n=Math.abs(t.touches[0].clientX-rr.current.x),d=Math.abs(t.touches[0].clientY-rr.current.y);(n>10||d>10)&&(Oo(),vs.current=!0)}t.touches.length>1&&(Kt.current=null)},children:[u?(0,e.jsx)(J,{mode:"wait",custom:gn,initial:!1,children:(0,e.jsxs)(S.div,{custom:gn,className:H?"absolute inset-0 overflow-hidden":"relative w-full overflow-hidden",initial:(t=>({opacity:0,x:t>0?60:-60})),animate:{opacity:1,x:0},exit:(t=>({opacity:0,x:t<0?60:-60})),transition:er?{duration:0}:{duration:.3,ease:[.23,1,.32,1]},children:[ut&&oe?(0,e.jsx)("div",{"data-lenis-prevent":!0,className:"relative w-full overflow-y-auto rounded-xl bg-[#0A0A0A] px-2 py-2",style:{aspectRatio:H?void 0:rn,height:H?"100%":void 0,maxHeight:H?void 0:"60dvh",scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch"},children:(0,e.jsx)(s.Suspense,{fallback:(0,e.jsx)("div",{className:"flex h-full items-center justify-center",children:(0,e.jsx)("div",{className:"w-6 h-6 rounded-full border-2 border-stone-700 border-t-gold-500 animate-spin"})}),children:(0,e.jsx)(Br,{data:oe,compact:!0,onNextChapter:xe})})}):kr?(0,e.jsxs)("div",{className:"flex flex-col items-center justify-center w-full min-h-[300px] bg-stone-900 rounded-xl border border-stone-700",children:[(0,e.jsx)("p",{className:"text-stone-400 text-sm mb-2",children:"Failed to load infographic"}),(0,e.jsx)("button",{onClick:()=>fr(null),className:"text-xs text-amber-400 hover:text-amber-300",children:"Retry"})]}):ee||Bl?(0,e.jsxs)("div",{className:"relative w-full",children:[(0,e.jsx)("div",{className:W("absolute inset-0 z-0 animate-pulse rounded-xl transition-opacity duration-1000",ye?"opacity-0":"opacity-100"),style:{backgroundColor:`${T}
2915`,aspectRatio:H?void 0:rn,height:H?"100%":void 0}}),ee?(0,e.jsx)("div",{className:W("relative w-full overflow-hidden",H?"h-full":""),style:{aspectRatio:H?void 0:rn,maxHeight:H?void 0:"60dvh"},children:(0,e.jsx)("img",{...de&&!H?Ji():{},ref:Ro,src:ee??void 0,alt:u?.title||"",className:W("relative z-10 w-full",H?"h-full object-contain":"absolute inset-0 h-full object-contain",ye?"opacity-100":"opacity-0"),style:{transform:ye?"scale(1)":"scale(0.98)",filter:ye?"blur(0px)":"blur(8px)",transition:"opacity 260ms cubic-bezier(0.23, 1, 0.32, 1), transform 260ms cubic-bezier(0.23, 1, 0.32, 1), filter 260ms cubic-bezier(0.23, 1, 0.32, 1)",objectPosition:H?"center center":"top center",...de&&!H&&ye?Zi:{},touchAction:tr?"none":"pan-y"},onLoad:t=>ts(t.currentTarget.currentSrc||t.currentTarget.src),onError:t=>Eo(t.currentTarget.currentSrc||t.currentTarget.src),draggable:!1,fetchPriority:"high",loading:"eager"},u?.slug)}):(0,e.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,e.jsx)("div",{className:"w-8 h-8 rounded-full border-2 border-stone-700 border-t-white animate-spin"})})]}):(0,e.jsxs)("div",{className:"flex flex-col items-center justify-center w-full min-h-[300px] bg-stone-900 rounded-xl border border-stone-700 p-6 text-center",children:[(0,e.jsx)("div",{className:"w-12 h-12 rounded-xl bg-stone-800 flex items-center justify-center mb-3 mx-auto",children:(0,e.jsxs)("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"#D4AF37",strokeWidth:"1.5",children:[(0,e.jsx)("path",{d:"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}),(0,e.jsx)("polyline",{points:"9 22 9 12 15 12 15 22"})]})}),(0,e.jsx)("p",{className:"text-stone-400 text-sm",children:"Infographic unavailable for this chapter â continue listening with audio."})]}),!H&&!U&&(0,e.jsx)("div",{className:"absolute bottom-0 left-0 right-0 pointer-events-none",style:{height:80,background:`linear-gradient(to bottom, transparent, ${$e==="dark"?"rgba(6,6,6,0.97)":"rgba(255,255,255,0.97)"})`}})]},u?.slug??x)}):(0,e.jsx)("div",{className:"w-full flex items-center justify-center",style:{minHeight:"44dvh"},children:(0,e.jsx)("div",{className:"w-10 h-10 rounded-full border-2 border-stone-700 border-t-white animate-spin"})}),(0,e.jsx)(J,{children:Il&&!H&&!U&&(0,e.jsx)(S.div,{initial:{opacity:0,y:8,scale:.96},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:6,scale:.96},transition:{duration:.2,ease:"easeOut"},className:"absolute bottom-5 right-5 z-30 pointer-events-none",children:(0,e.jsxs)("div",{className:"relative flex items-center justify-center w-11 h-11 rounded-full",style:{background:"rgba(0,0,0,0.22)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",border:"1px solid rgba(255,255,255,0.14)",boxShadow:"0 8px 20px rgba(0,0,0,0.10)"},children:[(0,e.jsx)(zc,{className:"w-4 h-4 text-white/70 rotate-90",strokeWidth:1.9}),(0,e.jsx)(ln,{className:"absolute -top-0.5 -right-0.5 w-3 h-3 text-white/75",strokeWidth:2.1})]})})})]}),!Yt&&(!H||U)&&Mt&&oe&&(0,e.jsxs)("div",{className:"flex flex-col overflow-hidden flex-1 min-h-0",style:{marginTop:U?0:ys,transition:U||sa||!ye?"none":"margin-top 0.35s cubic-bezier(0.77, 0, 0.175, 1)",background:U?"transparent":$e==="dark"?"rgb(6,6,6)":"#FFFFFF",zIndex:nd.mobileSummaryPanel,borderLeft:U?"1px solid rgba(255,255,255,0.06)":void 0},children:[!U&&(0,e.jsx)("div",{className:"flex-shrink-0 w-full pointer-events-none",style:{height:1.5,background:`linear-gradient(to right, transparent, ${T}80 25%, ${T} 50%, ${T}80 75%, transparent)`,boxShadow:`0 0 8px ${T}45`,opacity:Be>0?1:.55,transition:"opacity 0.3s ease"}}),(0,e.jsx)("div",{className:`flex-shrink-0 flex flex-col items-center pt-2.5 pb-1 touch-manipulation cursor-grab active:cursor-grabbing${U?" hidden":""}`,onTouchStart:rl,onTouchMove:al,onTouchEnd:il,children:Be>0&&oe?.sections?.[ct.activeSectionIndex]?.label&&(0,e.jsx)("p",{className:"text-[10px] font-medium truncate max-w-[180px]",style:{color:`${T}B0`},children:oe.sections[ct.activeSectionIndex].label})}),!U&&w!=="chat"&&w!=="ideas"&&(0,e.jsx)("div",{className:"flex-shrink-0 flex items-center justify-center pb-2.5 -mt-0.5",children:(0,e.jsxs)("div",{role:"group","aria-label":"View",className:"inline-flex items-center gap-0.5 rounded-full bg-stone-100 dar
29k:bg-white/5 p-0.5",children:[(0,e.jsx)("button",{type:"button",onClick:()=>ve("visual"),"aria-pressed":w==="visual",className:W("flex min-h-[30px] items-center rounded-full px-2.5 text-xs font-semibold transition-colors touch-manipulation",w==="visual"?"text-white":"text-stone-500 hover:text-stone-800 dark:text-white/50 dark:hover:text-white"),style:w==="visual"?{backgroundColor:T}:void 0,children:"Story Cards"}),(0,e.jsx)("button",{type:"button",onClick:()=>ve("transcript"),"aria-pressed":w==="transcript","aria-label":"Read full text",className:W("flex min-h-[30px] items-center rounded-full px-2.5 text-xs font-semibold transition-colors touch-manipulation",w==="transcript"?"text-white":"text-stone-500 hover:text-stone-800 dark:text-white/50 dark:hover:text-white"),style:w==="transcript"?{backgroundColor:T}:void 0,children:"Read"})]})}),(0,e.jsx)("div",{className:"absolute bottom-0 left-0 right-0 pointer-events-none z-20",style:{height:80,background:`linear-gradient(to bottom, transparent, ${$e==="dark"?"rgba(6,6,6,0.97)":"rgba(255,255,255,0.97)"})`}}),(0,e.jsx)("div",{className:"flex-1 min-h-0 relative",children:w==="visual"?(0,e.jsx)("div",{ref:de?_l:void 0,"data-lenis-prevent":!0,className:"absolute inset-0 overflow-y-auto overscroll-contain",onTouchStart:nl,onTouchEnd:ol,style:{scrollbarWidth:"none",WebkitOverflowScrolling:"touch",paddingBottom:"12px",paddingTop:Be===2?"calc(env(safe-area-inset-top, 0px) + 56px)":Be===1?"max(8px, env(safe-area-inset-top, 0px))":0,transition:"padding-top 0.35s cubic-bezier(0.77, 0, 0.175, 1)"},children:(0,e.jsx)(s.Suspense,{fallback:(0,e.jsx)("div",{className:"flex items-center justify-center h-16",children:(0,e.jsx)("div",{className:"w-5 h-5 rounded-full border-2 border-stone-600 border-t-white animate-spin"})}),children:(0,e.jsx)(Br,{data:oe,compact:!0,onNextChapter:xe})})}):(0,e.jsx)(s.Suspense,{fallback:null,children:(0,e.jsx)(fi,{fontSize:we,chapterTitle:u?.title,audioScript:u?.audioScript||{hook:"",sections:[],conclusion:""},audioTranscript:w==="transcript"?null:u?.audioTranscript||null,storyBeats:oe||void 0,currentTime:se,duration:G,domainColor:T,className:"absolute inset-0",bookId:i?.id,bookSlug:r||"",chapterNumber:x,onAskSelection:St?t=>{pa(t),ve("chat")}:void 0})})})]})]}),!Yt&&!Mt&&u?.audioScript&&i&&ie?.isAdmin&&(0,e.jsxs)("div",{className:"flex-shrink-0 px-5 pt-4 pb-3",children:[" ",(0,e.jsx)("p",{className:"text-xs font-semibold text-white/25 tracking-widest uppercase mb-3 text-center",children:"Explore this chapter"}),(0,e.jsx)("div",{className:"flex gap-2.5",children:(0,e.jsxs)(Ze,{to:`/ai-studio?book=${encodeURIComponent(i.title)}`,className:"flex-1 flex flex-col items-center gap-1.5 py-3 rounded-xl bg-white/[0.05] border border-white/10 transition-all active:scale-95",children:[(0,e.jsx)(Wc,{className:"w-4 h-4 text-white/50"}),(0,e.jsx)("span",{className:"text-xs font-semibold text-white/50 leading-none",children:"Art"})]})})]}),(0,e.jsx)(md,{isOpen:tl,onClose:()=>Sn(!1),infographicUrl:ee||"",chapterTitle:u?u.orderIndex===0?"Introduction":`${Rs}: ${u.title}`:"",bookTitle:i?.title||"",chapterUrl:new URL(Ad(`${l.pathname}${l.search}${l.hash}`)??l.pathname,window.location.origin).href,domainColor:T||"#F59E0B"})]}),Qi&&(0,e.jsx)("div",{className:"overflow-hidden",children:(0,e.jsxs)("div",{id:"desktop-player-section","data-route-focus":!0,tabIndex:-1,className:"flex flex-row-reverse overflow-hidden",style:{height:Oe?"100dvh":"100vh"},children:[(0,e.jsxs)("div",{className:"flex-shrink-0 flex flex-col bg-white dark:bg-[#0d0d0d] border-l border-stone-200 dark:border-white/[0.06] relative z-20",style:{width:Oe?"clamp(240px, 30vw, 264px)":bs?Math.min(kt,280):gs?Math.min(kt,320):Vi?Math.min(kt,360):kt},children:[(0,e.jsx)("div",{onMouseDown:Oe||bs||gs?void 0:Sl,className:W("absolute left-0 top-0 bottom-0 w-1 z-30 transition-colors group",Oe||bs||gs?"hidden":"cursor-col-resize hover:bg-stone-100 dark:hover:bg-white/10"),title:"Drag to resize","aria-label":"Resize sidebar",children:(0,e.jsx)("div",{className:"absolute inset-y-0 left-0 w-px bg-gold-400/0 group-hover:bg-gold-400/40 transition-colors"})}),(0,e.jsxs)("div",{className:"flex-shrink-0 flex flex-col border-b border-stone-200 dark:border-white/[0.06]",children:[(0,e.jsxs)("div",{className:W("flex items-center justify-between",Oe?"px-3 py-2":`px-4 ${bs||gs?"py-2":"py-3"}`),children:[ge&&i&&g.length>0?(0,e.jsx)(yu,{active:w==="chat"?"chat":w==="ideas"?"playground":"summary",ffActor:!0,domainColor:T,onChange:t=>{t==="chat"?ve("chat"):t==="playground"?(ve("ideas"),I.track($.GRAPH_PLAYGROUND_OPENED,{surface:"reader_tabs",book_slug:r,chapter_number:x+1})):ve(n=>n==="chat"||n==="ideas"?"reading":n)}}):w==="chat"||w==="ideas"?(0,e.jsx)("span",{className:"text-xs font-semibold text-stone-400 dark:text-white/30 tracking-widest uppercase",children:w==="ideas"?"Idea Playground":"Ask BookBuddy"}):(0,e.jsxs)("div",{role:"group","aria-label":"View",className:"inline-flex items-center gap-0.5 rounded-full bg-stone-100 dar
29k:bg-white/5 p-0.5",children:[Mt&&oe&&(0,e.jsx)("button",{type:"button",onClick:()=>ve("visual"),"aria-pressed":w==="visual",className:W("flex min-h-[30px] items-center rounded-full px-2.5 text-xs font-semibold transition-colors touch-manipulation",w==="visual"?"text-white":"text-stone-500 hover:text-stone-800 dark:text-white/50 dark:hover:text-white"),style:w==="visual"?{backgroundColor:T}:void 0,children:"Story Cards"}),(0,e.jsx)("button",{type:"button",onClick:()=>ve("transcript"),"aria-pressed":w==="transcript","aria-label":"Read full text",className:W("flex min-h-[30px] items-center rounded-full px-2.5 text-xs font-semibold transition-colors touch-manipulation",w==="transcript"?"text-white":"text-stone-500 hover:text-stone-800 dark:text-white/50 dark:hover:text-white"),style:w==="transcript"?{backgroundColor:T}:void 0,children:"Read"})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1",children:[St&&w!=="chat"&&w!=="ideas"&&R&&(u?.keyTakeaways?.length??0)>0&&(0,e.jsx)("button",{onClick:()=>{ga(!0),r&&I.track($.SAVE_IDEAS_OPENED,{book_slug:r,chapter_number:x,from:"reader_toolbar"})},className:"w-8 h-8 flex items-center justify-center rounded text-stone-400 dark:text-white/30 hover:text-amber-500 hover:bg-amber-50 dark:hover:bg-amber-900/20 transition-all touch-manipulation",title:"Save key ideas","aria-label":"Save key ideas",children:(0,e.jsx)(Ni,{className:"w-3.5 h-3.5"})}),Or.canonicalDiscovery&&!ge&&i&&g.length>0&&(0,e.jsx)("button",{onClick:()=>{const t=w==="ideas"?"reading":"ideas";ve(t),t==="ideas"&&I.track($.GRAPH_PLAYGROUND_OPENED,{surface:"reader_sidebar",book_slug:r,chapter_number:x+1})},className:W("w-8 h-8 flex items-center justify-center rounded transition-all touch-manipulation",w==="ideas"?"":"text-stone-400 dark:text-white/30 hover:text-stone-700 dark:hover:text-white hover:bg-stone-100 dark:hover:bg-white/[0.08]"),style:w==="ideas"?{color:T,backgroundColor:`${T}1A`}:void 0,title:w==="ideas"?"Back to summary":ge?"Practice":"Idea Playground","aria-label":"Toggle Idea Playground","aria-pressed":w==="ideas",children:(0,e.jsx)("span",{"aria-hidden":"true",style:{fontSize:"15px",lineHeight:1},children:"â¦"})}),!ge&&i&&g.length>0&&(0,e.jsx)("button",{onClick:()=>ve(w==="chat"?"reading":"chat"),className:W("w-8 h-8 flex items-center justify-center rounded transition-all touch-manipulation",w==="chat"?"text-amber-500 bg-amber-50 dark:bg-amber-900/20":"text-stone-400 dark:text-white/30 hover:text-stone-700 dark:hover:text-white hover:bg-stone-100 dark:hover:bg-white/[0.08]"),title:w==="chat"?"Back to summary":"Ask BookBuddy","aria-label":"Toggle Ask BookBuddy",children:(0,e.jsx)(nn,{className:"w-3.5 h-3.5"})}),w!=="chat"&&w!=="ideas"&&(0,e.jsxs)("button",{onClick:()=>Ks(),className:"w-8 h-8 flex items-center justify-center rounded text-stone-400 dark:text-white/30 hover:text-stone-700 dark:hover:text-white hover:bg-stone-100 dark:hover:bg-white/[0.08] transition-all touch-manipulation",title:`Font size: ${we}`,"aria-label":"Cycle font size",children:[(0,e.jsx)("span",{className:"text-xs font-bold leading-none",children:"A"}),(0,e.jsx)("span",{className:"text-[14px] font-bold leading-none ml-[1px]",children:"A"})]})]})]}),ge&&i&&g.length>0&&w!=="chat"&&w!=="ideas"&&(0,e.jsx)("div",{className:"px-4 pb-2 flex",children:(0,e.jsxs)("div",{role:"group","aria-label":"View",className:"inline-flex items-center gap-0.5 rounded-full bg-stone-100 dark:bg-white/5 p-0.5",children:[Mt&&oe&&(0,e.jsx)("button",{type:"button",onClick:()=>ve("visual"),"aria-pressed":w==="visual",className:W("flex min-h-[30px] items-center rounded-full px-2.5 text-xs font-semibold transition-colors touch-manipulation",w==="visual"?"text-white":"text-stone-500 hover:text-stone-800 dark:text-white/50 dark:hover:text-white"),style:w==="visual"?{backgroundColor:T}:void 0,children:"Story Cards"}),(0,e.jsx)("button",{type:"button",onClick:()=>ve("transcript"),"aria-pressed":w==="transcript","aria-label":"Read full text",className:W("flex min-h-[30px] items-center rounded-full px-2.5 text-xs font-semibold transition-colors touch-manipulation",w==="transcript"?"text-white":"text-stone-500 hover:text-stone-800 dark:text-white/50 dark:hover:text-white"),style:w==="transcript"?{backgroundColor:T}:void 0,children:"Read"})]})})]}),(0,e.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col",children:[(0,e.jsx)("div",{className:"flex-1 min-h-0 relative",children:w==="chat"?i&&(0,e.jsx)("div",{className:"absolute inset-0 bg-white dark:bg-[#0d0d0d]",children:(0,e.jsx)(Xo,{fallback:(0,e.jsx)("div",{className:"flex flex-col items-center justify-center h-full gap-3 p-6 text-center",children:(0,e.jsx)("p",{className:"text-sm text-stone-500 dark:text-stone-400",children:"Chat unavailable. Please refresh."})}),children:(0,e.jsx)(s.Suspense,{fallback:(0,e.jsx)("div",{className:"flex justify-center p-8",children:(0,e.jsx)("div",{className:"w-6 h-6 rounded-full border-2 border-stone-300 border-t-amber-500 animate-spin"})}),children:(0,e.jsx)(Gu,{book:i,lessons:g,currentChapterNum:x+1,onChapterClick:t=>ht(t-1),onBookClick:t=>v(`/book/${t}`),onOpenActionItems:()=>da(!0),initialSelectedText:Wn,onSeedConsumed:()=>pa(void 0)})})})}):Or.canonicalDiscovery&&w==="ideas"?(0,e.jsx)(Xo,{fallback:(0,e.jsx)("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 p-6 text-center",children:(0,e.jsx)("p",{className:"text-sm text-stone-500 dark:text-stone-400",children:"Idea Playground unavailable. Please refresh."})}),children:(0,e.jsx)(s.Suspense,{fallback:(0,e.jsx)("div",{className:"absolute inset-0 flex justify-center pt-12",children:(0,e.jsx)("div",{className:"w-6 h-6 rounded-full border-2 border-stone-300 border-t-gold-500 animate-spin"})}),children:ge?(0,e.jsx)(r0,{aimText:i?.title?`Actually learn ${i.title}`:null,journey:Tt.data??Bi,domainColor:T||"#F59E0B",bookId:i?.id,practicePlan:Ml,onStartReading:()=>ve("reading"),onOpenChapter:()=>ve("reading"),onStartFlashcards:()=>Gn({}),onQuizChapter:t=>i&&Ns({bookId:i.id,chapterNumber:t,chapterTitle:`Chapter ${t}`})}):(0,e.jsx)(s0,{bookId:i?.id||"",bookSlug:r||"",domainSlug:a||"",domainColor:T||"#F59E0B",chapterNumber:x+1,concepts:Ss,conceptsLoading:jl})})}):w==="visual"?Mt&&oe?(0,e.jsx)("div",{"data-lenis-prevent":!0,className:`absolute inset-0 overflow-y-auto px-2 ${bs||gs?"py-1":"py-2"}`,style:{scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch"},children:(0,e.jsx)(s.Suspense,{fallback:(0,e.jsx)("div",{className:"flex justify-center p-8",children:(0,e.jsx)("div",{className:"w-6 h-6 rounded-full border-2 border-stone-300 border-t-gold-500 animate-spin"})}),children:(0,e.jsx)(Br,{data:oe,activeSectionIndex:ct.activeSectionIndex,sectionRefs:ct.sectionRefs,sectionProgress:ct.sectionProgress,compact:!0,onNextChapter:xe})})}):(0,e.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-center p-6 text-stone-400 dark:text-white/20",children:[(0,e.jsx)(Vd,{className:"w-10 h-10 mb-3 opacity-40"}),(0,e.jsx)("p",{className:"text-sm",children:"No highlights available for this chapter."})]}):(0,e.jsx)(s.Suspense,{fallback:null,children:(0,e.jsx)(fi,{chapterTitle:u?.title,audioScript:u?.audioScript||{hook:"",sections:[],conclusion:""},audioTranscript:w==="transcript"?null:u?.audioTranscript||null,storyBeats:oe||void 0,currentTime:se,duration:G,fontSize:we,domainColor:T,className:"absolute inset-0",bookId:i?.id,bookSlug:r||"",chapterNumber:x})})}),!_t&&u&&i&&w!=="chat"&&w!=="ideas"&&(0,e.jsx)("div",{ref:mo,"aria-hidden":"true",className:"h-px flex-shrink-0"})]})]}),(0,e.jsxs)("div",{className:W("flex-1 flex flex-col relative bg-stone-100 dar
29k:bg-[#0a0a0a] z-10",Oe?"min-h-0":"min-h-[400px] lg:min-h-0"),children:[!Oe&&(0,e.jsx)("div",{"data-testid":"title-bar",className:"flex-shrink-0 bg-stone-50 dark:bg-[#111111] border-b border-stone-200 dark:border-white/[0.06] px-4 py-2.5",children:(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[(0,e.jsx)("button",{onClick:Pe,disabled:!Cs,className:"w-7 h-7 flex items-center justify-center rounded-md text-stone-400 dark:text-white/35 hover:text-stone-900 dark:hover:text-white hover:bg-stone-100 dark:hover:bg-white/[0.08] disabled:opacity-20 disabled:cursor-not-allowed transition-all",title:"Previous chapter (â)",children:(0,e.jsx)(an,{className:"w-4 h-4"})}),(0,e.jsxs)("span",{className:"text-xs font-medium text-stone-400 dark:text-white/30 tabular-nums px-1",children:[rs,(0,e.jsxs)("span",{className:"text-stone-300 dark:text-white/15",children:["/",$s]})]}),(0,e.jsx)("button",{onClick:xe,disabled:!wt,className:"w-7 h-7 flex items-center justify-center rounded-md text-stone-400 dark:text-white/35 hover:text-stone-900 dark:hover:text-white hover:bg-stone-100 dark:hover:bg-white/[0.08] disabled:opacity-20 disabled:cursor-not-allowed transition-all",title:"Next chapter (â)",children:(0,e.jsx)(ft,{className:"w-4 h-4"})})]}),(0,e.jsx)("div",{className:"w-px h-4 bg-stone-200 dark:bg-white/[0.08] flex-shrink-0"}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsx)(Ze,{to:C||`/domain/${a}/topic/${r}`,className:"block text-sm font-semibold text-stone-800 dark:text-white/90 hover:text-stone-950 dark:hover:text-white transition-colors truncate leading-tight",title:i.title,children:i.title}),(0,e.jsxs)("p",{className:"text-xs truncate mt-0.5 leading-tight",children:[(0,e.jsx)("span",{className:"font-semibold",style:{color:T},children:Rs}),(0,e.jsxs)("span",{className:"text-stone-400 dark:text-white/30",children:[" · ",u?.title||"Loading..."]})]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[!ge&&(0,e.jsxs)("button",{onClick:()=>ve(t=>t==="chat"?"reading":"chat"),className:W("inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs font-semibold transition-all",w==="chat"?"text-amber-600 dark:text-amber-300 bg-amber-50 dark:bg-amber-900/20":"text-stone-600 dar
29k:text-white/70 hover:text-stone-900 dark:hover:text-white hover:bg-stone-100 dark:hover:bg-white/[0.08]"),title:w==="chat"?"Back to summary":"Ask BookBuddy","aria-label":"Toggle Ask BookBuddy",children:[(0,e.jsx)(nn,{className:"w-3.5 h-3.5"}),(0,e.jsx)("span",{children:"Ask BookBuddy"})]}),(0,e.jsx)("button",{type:"button",onClick:()=>ir(!0),className:"inline-flex h-11 w-11 items-center justify-center rounded-[var(--sb-radius-control)] text-stone-500 transition-colors hover:bg-stone-100 hover:text-stone-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)] dark:text-white/55 dark:hover:bg-white/[0.08] dark:hover:text-white","aria-label":"Open chapter list",children:(0,e.jsx)(dn,{className:"h-4 w-4"})}),(0,e.jsx)(ni,{variant:"icon",bookSlug:i?.slug,chapterNumber:x,pageContext:"chapter_reader_desktop_title"})]})]})}),(0,e.jsxs)("div",{className:"flex-1 relative flex items-center justify-center overflow-hidden",style:Oe?{paddingTop:"max(env(safe-area-inset-top), 4px)"}:void 0,..._r,children:[Kl&&(0,e.jsx)(J,{mode:"sync",children:(0,e.jsx)(S.img,{src:i?.coverUrl,initial:{opacity:0,scale:1.1},animate:{opacity:.07,scale:1.1},exit:{opacity:0,scale:1.1},transition:{duration:.8},className:"absolute inset-0 w-full h-full object-cover pointer-events-none select-none z-0",style:{filter:"blur(80px) saturate(1.3)",willChange:"transform, opacity"},"aria-hidden":"true",alt:""},i?.coverUrl)}),u&&ut&&oe&&(0,e.jsx)("div",{"data-lenis-prevent":!0,className:"absolute inset-0 z-10 overflow-y-auto bg-[#0A0A0A] px-3 py-3",style:{scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch"},children:(0,e.jsx)(s.Suspense,{fallback:(0,e.jsx)("div",{className:"flex h-full items-center justify-center",children:(0,e.jsx)("div",{className:"w-6 h-6 rounded-full border-2 border-stone-700 border-t-gold-500 animate-spin"})}),children:(0,e.jsx)(Br,{data:oe,activeSectionIndex:ct.activeSectionIndex,sectionRefs:ct.sectionRefs,sectionProgress:ct.sectionProgress,compact:!0,onNextChapter:xe})})}),(0,e.jsx)(J,{mode:"wait",children:!ut&&!ye&&ee&&!kr&&(0,e.jsxs)(S.div,{initial:{opacity:0}
29,animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 flex flex-col items-center justify-center",children:[(0,e.jsx)("div",{className:"relative w-3/4 max-w-md aspect-[3/4] rounded-xl overflow-hidden bg-stone-200/60 dark:bg-white/[0.04]",children:(0,e.jsx)("div",{className:"absolute inset-0 bg-gradient-to-r from-transparent via-stone-100/80 dark:via-white/[0.06] to-transparent animate-[shimmer_1.5s_infinite]"})}),(0,e.jsx)("p",{className:"mt-3 text-xs text-stone-400 dark:text-white/25",children:"Loading infographic..."})]})}),!ut&&u&&kr&&ee&&(0,e.jsxs)("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[(0,e.jsx)(ns,{className:"w-8 h-8 text-red-400/70 mb-3"}),(0,e.jsx)("h3",{className:"text-base font-semibold text-stone-500 dark:text-white/50",children:"Failed to load"}),(0,e.jsxs)("button",{onClick:()=>{Na(null),fr(null)},className:"mt-4 flex items-center gap-2 px-4 py-2 rounded-lg bg-stone-200 dark:bg-white/[0.08] hover:bg-stone-300 dark:hover:bg-white/[0.12] text-stone-600 dar
29k:text-white/60 hover:text-stone-900 dark:hover:text-white text-sm font-medium transition-all",children:[(0,e.jsx)(Ko,{className:"w-4 h-4"})," Retry"]})]}),!ut&&u&&!ee&&(()=>{const t=Sa||x>=Mr&&!Gs,n=t&&!R,d=t&&R;return n?(0,e.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-[400px] p-8 text-center",children:[(0,e.jsx)("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center mb-4",style:{background:`${T}20`},children:(0,e.jsx)(Dc,{className:"w-7 h-7",style:{color:T}})}),(0,e.jsx)("h3",{className:"text-base font-semibold text-stone-700 dark:text-stone-200 mb-1",children:"Sign in to continue reading"}),(0,e.jsxs)("p",{className:"text-sm text-stone-500 dark:text-stone-400 mb-5 max-w-xs",children:["Create a free account to access this chapter and unlock your first ",Mr," chapters on every book."]}),(0,e.jsx)("button",{onClick:()=>{sessionStorage.setItem("returnTo",window.location.pathname),v("/login")},className:"px-5 py-2.5 rounded-xl text-sm font-semibold text-white shadow-lg",style:{background:T},children:"Sign in free"})]}):d?(0,e.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-[400px] p-8 text-center",children:[(0,e.jsx)("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center mb-4",style:{background:`${T}20`},children:(0,e.jsx)(jc,{className:"w-7 h-7",style:{color:T}})}),(0,e.jsx)("h3",{className:"text-base font-semibold text-stone-700 dark:text-stone-200 mb-1",children:"Premium chapter"}),(0,e.jsx)("p",{className:"text-sm text-stone-500 dark:text-stone-400 mb-5 max-w-xs",children:"Upgrade to unlock this chapter and every book in the library."}),(0,e.jsx)("button",{onClick:()=>{lr(x),yt(!0)},className:"px-5 py-2.5 rounded-xl text-sm font-semibold text-white shadow-lg",style:{background:T},children:"Upgrade to Premium"})]}):(0,e.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-[400px] p-8 text-center",children:[(0,e.jsx)("div",{className:"w-14 h-14 rounded-2xl bg-stone-200 dark:bg-white/[0.05] flex items-center justify-center mb-3",children:(0,e.jsx)(Ur,{className:"w-7 h-7 text-stone-400 dark:text-white/20"})}),(0,e.jsx)("h3",{className:"text-base font-semibold text-stone-500 dark:text-white/40 mb-1",children:"Visual unavailable"}),(0,e.jsx)("p",{className:"text-sm text-stone-400 dark:text-white/20",children:$a?"Text is ready while media reconnects.":"Audio and text are ready."})]})})(),!ut&&u&&ee&&!kr&&(0,e.jsxs)("div",{ref:In,className:"absolute inset-0 flex items-center justify-center bg-transparent z-10",onClick:It,children:[(0,e.jsxs)(S.div,{className:"relative w-full h-full flex items-center justify-center",initial:{opacity:0}
29,animate:{opacity:1},transition:{duration:.2,ease:"easeOut"},children:[(0,e.jsx)("div",{className:W("absolute inset-0 z-0 animate-pulse rounded-2xl transition-opacity duration-1000",ye?"opacity-0":"opacity-100"),style:{backgroundColor:`${T}15`}}),(0,e.jsx)("img",{ref:Ro,src:ee??void 0,alt:u.title,className:"relative z-10 h-full w-auto max-w-full object-contain",style:{display:"block",margin:"auto",opacity:ye?1:0,transition:"opacity 260ms cubic-bezier(0.23, 1, 0.32, 1), transform 260ms cubic-bezier(0.23, 1, 0.32, 1), filter 260ms cubic-bezier(0.23, 1, 0.32, 1)",transform:ye?"scale(1)":"scale(0.98)",filter:ye?"blur(0px)":"blur(8px)"},onLoad:t=>ts(t.currentTarget.currentSrc||t.currentTarget.src),onError:t=>Eo(t.currentTarget.currentSrc||t.currentTarget.src),fetchPriority:"high",loading:"eager"},u.slug)]},u.slug),ye&&ss&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(ui,{activeRegions:Bo,focusRegion:Rr,isActive:!0}),(0,e.jsx)(hi,{focusRegion:Rr,color:"gold",intensity:"subtle",isActive:!0})]})]}),(0,e.jsx)("div",{className:"absolute bottom-4 right-4 z-30 flex items-center gap-2",children:(0,e.jsx)("button",{onClick:It,className:`flex h-11 w-11 items-center justify-center rounded-lg bg-black/50 text-white/50 backdrop-blur-sm transition-all hover:bg-black/70 hover:text-white ${An?"fullscreen-button-pulse":""}`,title:"Fullscreen","aria-label":"Expand to fullscreen",children:(0,e.jsx)(zr,{className:"w-3.5 h-3.5"})})}),u?.sections?.length>0&&(0,e.jsx)("div",{className:"absolute left-4 top-1/2 -translate-y-1/2 z-10 hidden xl:block",children:(0,e.jsx)(Vu,{sections:u.sections,currentIndex:Jt,onSectionClick:nc,orientation:"vertical"})}),ss&&(0,e.jsx)("div",{className:"absolute right-4 top-1/2 -translate-y-1/2 z-10 max-w-xs hidden xl:block",children:(0,e.jsx)(qu,{section:ss,position:"right",showKeyPoints:!0})})]}),$a&&u?.audioPath&&(0,e.jsxs)("div",{"data-testid":"topic-audio-unavailable",role:"status",className:"flex-shrink-0 px-4 py-3 bg-stone-50 dark:bg-black/90 border-t border-stone-200 dark:border-white/[0.06] flex items-center gap-3 text-red-500 dark:text-red-400",children:[(0,e.jsx)(ns,{className:"w-4 h-4 flex-shrink-0"}),(0,e.jsx)("span",{className:"text-xs",children:"Audio unavailable"}),(0,e.jsx)("button",{"aria-label":"Retry audio",onClick:No,className:"text-xs underline hover:text-red-600 dark:hover:text-red-300",children:"Retry"})]}),me&&!Xr&&(0,e.jsxs)("div",{className:"flex-shrink-0 bg-white/95 dark:bg-black/90 backdrop-blur-xl border-t border-stone-200 dark:border-white/[0.06]",...Lo,children:[io&&(0,e.jsx)("div",{className:"px-4 pt-2 text-center",children:(0,e.jsxs)("span",{className:"inline-flex items-center gap-2 rounded-full border border-amber-300/60 bg-amber-50 px-3 py-1 text-[11px] font-medium text-amber-700 dark:border-amber-700/40 dark:bg-amber-900/20 dark:text-amber-300",children:[(0,e.jsx)(Vs,{className:"w-3 h-3"}),"Tap play to start audio on this device"]})}),(0,e.jsx)(Ic,{variant:"bar",isPlaying:ce,currentTimeSec:se,durationSec:G,onPlayPause:Ps,onSeek:Fo,onSkipBack:jt,onSkipForward:Nt,onPrev:Pe,onNext:xe,prevDisabled:x<=0,nextDisabled:x>=g.length-1,isComplete:Jr,completeRing:(0,e.jsx)(J,{children:Jr&&(0,e.jsx)(S.div,{initial:{scale:1,opacity:.8},animate:{scale:2.4,opacity:0},transition:{duration:.65,ease:"easeOut"},className:"absolute inset-0 rounded-full pointer-events-none",style:{backgroundColor:T}},"completion-ring")}),domainColor:T,compact:Oe,seekRowClassName:io?"pt-2 pb-1.5":"pt-3 pb-1.5",seekOverlay:G>0&&yr.length>0&&yr.map((t,n)=>{const d=(t.startTime??0)/G*100,y=n===Jt;return(0,e.jsxs)("div",{className:"absolute top-1/2 group/dot pointer-events-auto z-10",style:{left:`${d}%`},children:[(0,e.jsx)("div",{className:"w-1.5 h-1.5 rounded-full transition-all duration-200",style:{backgroundColor:y?T:at==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",boxShadow:y?`0 0 6px ${T}80`:"none",transform:"translateX(-50%) translateY(-50%)"}}),(0,e.jsx)("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 opacity-0 group-hover/dot:opacity-100 transition-opacity duration-150 pointer-events-none whitespace-nowrap z-50",children:(0,e.jsx)("div",{className:"px-2 py-1 rounded text-xs font-medium text-white bg-stone-900/90 backdrop-blur-sm border border-white/10 shadow-lg",children:t.label})})]},t.id||n)}),trailingContent:(0,e.jsxs)("div",{className:`flex ${Oe?"items-center gap-1 [&_span]:hidden":"items-end gap-3"}`,children:[(0,e.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,e.jsxs)("button",{onClick:Ls,className:`h-9 min-w-[36px] px-2 rounded-xl text-[12px] font-bold tabular-nums transition-all ${je!==1?"text-white":"text-stone-500 dark:text-white/50 hover:text-stone-900 dark:hover:text-white hover:bg-stone-100 dar
29k:hover:bg-white/[0.08]"}`,style:je!==1?{backgroundColor:T,boxShadow:`0 2px 10px ${T}55`}:{},title:"Playback speed (S)","aria-label":`Speed ${je}x`,children:[je,"Ã"]}),(0,e.jsx)("span",{className:"text-xs font-medium text-stone-400 dark:text-white/25 leading-none",children:"Speed"})]}),(0,e.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,e.jsx)("button",{onClick:()=>pr(!Ke),className:`w-9 h-9 flex items-center justify-center rounded-xl transition-all ${Ke?"text-white":"text-stone-500 dark:text-white/50 hover:text-stone-900 dark:hover:text-white hover:bg-stone-100 dark:hover:bg-white/[0.08]"}`,style:Ke?{backgroundColor:T,boxShadow:`0 2px 10px ${T}55`}:{},title:Ke?"Autoplay ON (A)":"Autoplay OFF (A)","aria-label":"Toggle autoplay",children:(0,e.jsx)(Ci,{className:"w-4 h-4"})}),(0,e.jsx)("span",{className:"text-xs font-medium text-stone-400 dark:text-white/25 leading-none",children:"Autoplay"})]}),(0,e.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,e.jsx)("div",{className:"w-9 h-9 flex items-center justify-center rounded-xl text-stone-500 dark:text-white/50 hover:text-stone-900 dark:hover:text-white hover:bg-stone-100 dark:hover:bg-white/[0.08] transition-all",children:(0,e.jsx)(ei,{onTimerEnd:Ka,isPlaying:ce,direction:"up",iconOnly:!0})}),(0,e.jsx)("span",{className:"text-xs font-medium text-stone-400 dark:text-white/25 leading-none",children:"Sleep"})]}),(0,e.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,e.jsx)("button",{onClick:Ys,className:"w-9 h-9 flex items-center justify-center rounded-xl text-stone-500 dark:text-white/50 hover:text-stone-900 dark:hover:text-white hover:bg-stone-100 dark:hover:bg-white/[0.08] transition-all",title:at==="dark"?"Light mode":"Dark mode","aria-label":"Toggle theme",children:at==="dark"?(0,e.jsx)(Vc,{className:"w-4 h-4"}):(0,e.jsx)(Hc,{className:"w-4 h-4"})}),(0,e.jsx)("span",{className:"text-xs font-medium text-stone-400 dark:text-white/25 leading-none",children:at==="dark"?"Light":"Dark"})]}),(0,e.jsx)("div",{className:"w-px h-9 bg-stone-200 dark:bg-white/10 self-start"}),(0,e.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,e.jsx)("button",{onClick:It,className:"flex h-11 w-11 items-center justify-center rounded-xl text-stone-500 transition-all hover:bg-stone-100 hover:text-stone-900 dark:text-white/50 dark:hover:bg-white/[0.08] dark:hover:text-white",title:"Fullscreen (F)","aria-label":"Toggle fullscreen",children:Rt?(0,e.jsx)(Si,{className:"w-4 h-4"}):(0,e.jsx)(zr,{className:"w-4 h-4"})}),(0,e.jsx)("span",{className:"text-xs font-medium text-stone-400 dark:text-white/25 leading-none",children:Rt?"Exit":"Full"})]})]})})]})]})]})})," "]})]}),de&&$a&&u?.audioPath&&(0,e.jsxs)("div",{"data-testid":"topic-audio-unavailable",role:"status",className:"fixed inset-x-0 z-40 px-4 py-2 bg-red-50 dark:bg-red-950/50 border-t border-red-200 dark:border-red-800 flex items-center gap-3 [bottom:calc(var(--tab-bar-height,56px)+env(safe-area-inset-bottom,0px))] md:bottom-14",children:[(0,e.jsx)(ns,{className:"w-4 h-4 text-red-500 flex-shrink-0"}),(0,e.jsx)("span",{className:"text-xs text-red-600 dark:text-red-400",children:"Audio unavailable"}),(0,e.jsx)("button",{"aria-label":"Retry audio",onClick:No,className:"text-xs underline text-red-600 dark:text-red-400",children:"Retry"})]}),de&&me&&!Xr&&!Yt&&(0,e.jsx)(gu,{isVisible:!0,isPlaying:ce,currentTime:se,duration:G,playbackRate:je,autoplayEnabled:Ke,chapterNumber:rs,totalChapters:$s,domainColor:le?.color||"#F59E0B",bookTitle:i?.title??void 0,chapterTitle:u?.title??void 0,onPlay:()=>{P.current&&(P.current.play(),Te(!0))},onPause:()=>{P.current&&(ze(),P.current.pause(),Te(!1))},onSkipBack:jt,onSkipForward:Nt,onSeek:Fs,onPrevChapter:Pe,onNextChapter:xe,onChangeSpeed:Ls,onCycleFontSize:()=>{Ks(),q("light")},onToggleAutoplay:ec,onToggleChapterDrawer:()=>ir(t=>!t),isChapterDrawerOpen:On,onSleepTimerEnd:Ka,onToggleFullscreen:It,onOpenChat:()=>ca(!0),isChatOpen:la,bookSlug:r,bottomOffset:void 0}),la&&i&&(0,e.jsx)(s.Suspense,{fallback:null,children:(0,e.jsx)(Ku,{isOpen:la,onClose:()=>ca(!1),book:i,lessons:g,currentChapterNum:x+1,onChapterClick:t=>ht(t-1),onBookClick:t=>{ca(!1),window.location.href=`/book/${t}`},onOpenActionItems:()=>da(!0),initialSelectedText:Wn,onSeedConsumed:()=>pa(void 0)})}),hl&&i&&(0,e.jsx)(s.Suspense,{fallback:null,children:(0,e.jsx)(Xu,{bookSlug:i.slug??i.id,onClose:()=>da(!1)})}),i&&(0,e.jsx)("div",{children:(0,e.jsx)(ju,{isOpen:On,onClose:()=>ir(!1),topic:i,lessons:g,currentIndex:x,completedChapters:vo,onChapterClick:ac,estimatedTime:Ql,domainColor:le?.color,isMobile:de,domainSlug:a,topicSlug:r,playerBottomOffset:"env(safe-area-inset-bottom, 0px)",freeChapter
29Limit:Gs?void 0:Mr,isSeries:oc,currentIdeas:Ss,onIdeaClick:t=>{I.track($.CONCEPT_CHIP_CLICKED,{book_slug:r,chapter_number:x,concept_slug:t.slug,from:"chapter_drawer"}),v(`/concept/${t.slug}`)}})}),(0,e.jsx)(J,{children:ml&&(0,e.jsx)(S.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},exit:{opacity:0,y:16},transition:{type:"spring",damping:28,stiffness:380},className:`fixed bottom-[calc(env(safe-area-inset-bottom,0px)+132px)] inset-x-0 ${Ct("zoomResetToast")} flex justify-center pointer-events-none`,children:(0,e.jsx)("div",{className:"bg-stone-800/90 dark:bg-stone-900/90 text-white text-xs font-medium px-4 py-2 rounded-full shadow-lg backdrop-blur-sm",children:"Zoom reset"})},"zoom-reset-toast")}),(0,e.jsx)(Bd,{open:ua,model:zo,onClose:Ho,onPrimaryAction:lc,onSecondaryAction:ma?()=>ws(!1):Ho,testId:"topic-paywall-dialog"})]}),i&&(0,e.jsx)(Cu,{isOpen:fl,onClose:()=>qn(!1),book:i,chaptersRead:g.length,timeSpentMinutes:Math.round(xt?.todayMinutes||0),gamStats:xt,domainSlug:a}),js&&i&&(0,e.jsx)(s.Suspense,{fallback:null,children:(0,e.jsx)(Qu,{isOpen:!!js,bookId:js.bookId,bookSlug:i.slug,chapterNumber:js.chapterNumber,chapterTitle:js.chapterTitle,onClose:()=>Ns(null),conceptNodeIds:ge?Ss.map(t=>t.nodeId).filter(t=>!!t):void 0})}),(0,e.jsx)(J,{children:ge&&Fe&&i&&(0,e.jsx)(s.Suspense,{fallback:null,children:(0,e.jsx)(Ju,{chapterTitle:Fe.chapterTitle,takeaways:Fe.takeaways,domainColor:T||"#F59E0B",onOwned:()=>{r&&I.track($.ACTOR_CONCEPT_OWNED,{book_slug:r,chapter_number:Fe.chapterNumber})},onScored:t=>{r&&I.track($.ACTOR_RECALL_SCORED,{book_slug:r,chapter_number:Fe.chapterNumber,verdict:t,idea_count:Fe.takeaways.length}),Fe.takeaways.forEach((n,d)=>{vl({bookId:Fe.bookId,chapterNumber:Fe.chapterNumber,ideaIndex:d,ideaText:n,verdict:t,bookSlug:r})})},onContinueToQuiz:()=>{const t={bookId:Fe.bookId,chapterNumber:Fe.chapterNumber,chapterTitle:Fe.chapterTitle};xa(null),r&&I.track($.RECALL_QUIZ_STARTED,{book_slug:r,chapter_number:Fe.chapterNumber,from:"actor_recall"}),Ns(t)},onClose:()=>xa(null)})},"actor-recall-beat")}),(0,e.jsx)(J,{children:ge&&ba&&i&&(0,e.jsx)(s.Suspense,{fallback:null,children:(0,e.jsx)(Zu,{bookId:i.id,domainColor:T||"#F59E0B",chapterNumber:ba.chapterNumber,onOwned:t=>{r&&I.track($.ACTOR_CONCEPT_OWNED,{book_slug:r,source:"flashcards"});const n=ba?.chapterNumber??0;yl({bookId:i.id,chapterNumber:n,ideaKey:`${i.id}:ch${n}:card:${t}`,ideaText:t.slice(0,280),verdict:"got_it",bookSlug:r})},onClose:()=>Gn(null)})},"actor-flashcards")}),(0,e.jsx)(J,{children:St&&cr&&i&&u&&(0,e.jsx)(s.Suspense,{fallback:null,children:(0,e.jsx)(e0,{open:cr,chapterTitle:u.title||`Chapter ${x+1}`,bookTitle:i.title,chaptersDone:x+1,chaptersTotal:g.length,quizQuestionCount:3,saveableIdeaCount:R?u.keyTakeaways?.length??0:0,nextChapterTitle:g[x+1]?.title??null,isSignedIn:R,onTestYourself:()=>{At(!1);const t={bookId:i.id,chapterNumber:u.orderIndex??x,chapterTitle:u.title||`Chapter ${x+1}`},n=u.keyTakeaways??[];ge&&n.length>0?xa({...t,takeaways:n}):(r&&I.track($.RECALL_QUIZ_STARTED,{book_slug:r,chapter_number:x,from:"completion"}),Ns(t))},concepts:wl,onSaveIdeas:()=>{At(!1),ga(!0),r&&I.track($.SAVE_IDEAS_OPENED,{book_slug:r,chapter_number:x})},onConceptClick:t=>{r&&I.track($.CONCEPT_CHIP_CLICKED,{book_slug:r,chapter_number:x,concept_slug:t}),At(!1),v(`/concept/${t}`)},onContinue:()=>{At(!1),r&&I.track($.UP_NEXT_CLICKED,{book_slug:r,chapter_number:x,is_last_chapter:!g[x+1]}),g[x+1]?ht(x+1):v(`/domain/${a}`)},onSignIn:()=>v("/login"),onDismiss:()=>At(!1)})},"chapter-complete-sheet")}),(0,e.jsx)(J,{children:St&&Xn&&i&&r&&u&&(0,e.jsx)(s.Suspense,{fallback:null,children:(0,e.jsx)(t0,{open:Xn,takeaways:u.keyTakeaways??[],bookSlug:r,bookTitle:i.title,chapterNumber:u.orderIndex??x,chapterTitle:u.title||`Chapter ${x+1}`,onClose:()=>ga(!1),onIdeaSaved:()=>{r&&I.track($.IDEA_SAVED,{book_slug:r,chapter_number:x})}})},"save-ideas-sheet")}),pl&&ie?.isBetaUser&&r&&(0,e.jsx)(_u,{bookSlug:r,chapterNumber:xl,onDismiss:()=>Vn(!1)}),(0,e.jsx)(s.Suspense,{fallback:null,children:(0,e.jsx)(Yu,{isOpen:Cl,onClose:()=>Tl(!1)})}),(0,e.jsx)(Nu,{open:Hi,onOpenChange:vn,bookTitle:i?.title??"This Scrollbook",coverUrl:i?.coverUrl,domainColor:T,publishedBookCount:ms,returnTo:l.pathname+l.search}),(0,e.jsx)(J,{children:qi&&!_t&&u&&i&&w!=="chat"&&w!=="ideas"&&(0,e.jsx)(S.div,{role:"complementary","aria-label":"End of chapter options",initial:ot?{opacity:0}
29:{opacity:0,y:60},animate:ot?{opacity:1}:{opacity:1,y:0},exit:ot?{opacity:0}:{opacity:0,y:60},transition:ot?{duration:.15}:{type:"spring",damping:28,stiffness:320},className:`fixed inset-x-0 ${Ct("chatPanel")} pointer-events-auto [bottom:calc(var(--tab-bar-height,56px)+env(safe-area-inset-bottom,0px)+8px)] md:bottom-4`,children:(0,e.jsxs)("div",{className:"mx-auto max-w-sm px-3 relative",children:[(0,e.jsx)("button",{type:"button","aria-label":"Dismiss end of chapter options",onClick:()=>{Ia.current=!0,ea(!1)},className:"absolute -top-2 right-3 w-6 h-6 flex items-center justify-center rounded-full bg-stone-200/80 dark:bg-white/10 backdrop-blur-sm text-stone-500 dark:text-white/50 hover:bg-stone-300 dark:hover:bg-white/20 transition-colors",children:(0,e.jsx)(Hr,{className:"w-3.5 h-3.5"})}),(0,e.jsx)("div",{className:"bg-white/95 dark:bg-stone-900/95 backdrop-blur-md rounded-2xl shadow-xl border border-stone-200/60 dark:border-white/[0.08] overflow-hidden",children:(0,e.jsx)(Au,{bookSlug:r||"",domainColor:T||"#F59E0B",nextChapter:g[x+1]?{slug:g[x+1].slug,title:g[x+1].title,chapterNumber:g[x+1].orderIndex,domainSlug:a||""}:void 0,onNavigate:(t,n,d)=>{v(`/domain/${n}/topic/${t}/${d}`)},onOpenQuiz:()=>{const t=g[x];i&&t&&Ns({bookId:i.id,chapterNumber:t.orderIndex??x,chapterTitle:t.title||`Chapter ${x+1}`})},currentChapterTitle:g[x]?.title||"This Chapter",keepIdea:(()=>{if(!St)return;const t=u?.keyTakeaways?.[0];if(t)return{text:t,onKeep:async()=>i?kl({bookId:i.id,chapterNumber:u.orderIndex??x,ideaText:t}):!1}})()})})]})},"end-of-chapter-popup")})]})}export{Jh as TopicPage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.