/* ============ BingLingo shared reader styles ============ */
:root{
  --sky:#4FB8F5; --royal:#2563D6; --deep:#1E4FA8;
  --sunny:#FFC93C; --coral:#EF6A52; --lav:#C9BCF5;
  --ink:#20304F; --ink-soft:#51627F; --cream:#F6FAFF;
  --card:#FFFFFF; --line:#E3EEF9;
  --radius:22px; --radius-sm:14px;
  --shadow:0 14px 40px rgba(37,99,214,.16);
  --font-display:"Baloo 2",system-ui,"Segoe UI",sans-serif;
  --font-body:"Nunito",system-ui,"Segoe UI",sans-serif;
}
*{box-sizing:border-box;margin:0;padding:0}
[hidden]{display:none!important}
html,body{height:100%}
body{
  font-family:var(--font-body);color:var(--ink);
  background:linear-gradient(180deg,#EAF4FF 0%,#F6FAFF 42%);
  line-height:1.6;-webkit-font-smoothing:antialiased;min-height:100vh;
}
img{max-width:100%;display:block}
a{color:inherit;text-decoration:none}
.reader .wrap{max-width:1080px;margin:0 auto;padding:0 22px}

/* ---------- Reader head ---------- */
.reader{padding:30px 0 46px}
.reader-head{display:flex;align-items:flex-end;justify-content:space-between;gap:16px;margin-bottom:22px;flex-wrap:wrap}
.reader-head h1{font-family:var(--font-display);font-size:clamp(23px,3.2vw,30px);color:var(--deep)}
.reader-head .sub{color:var(--ink-soft);font-size:14px;margin-top:3px}
.chip-row{display:flex;gap:8px;align-items;margin-top:10px;flex-wrap:wrap}
.chip{display:inline-block;background:#EAF3FF;color:var(--royal);font-weight:800;font-size:12px;padding:4px 12px;border-radius:999px}
.chip-free{background:#FFF3D6;color:#B7791F}
.chip-spec{background:#F0ECFF;color:#6B57C9}
.chip-age{background:#EAF7EF;color:#2E8B57}
#filterChips a.chip{text-decoration:none;transition:background .15s ease,color .15s ease}
#filterChips a.chip:hover{background:#D6E8FF}
.lang-row{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:12px}
.lang-row__label{font-size:12px;font-weight:800;color:var(--ink-soft);letter-spacing:.02em}
.lang-row__list{display:flex;gap:8px;flex-wrap:wrap}
.lang-chip{display:inline-flex;align-items:center;font-size:12.5px;font-weight:700;line-height:1;padding:7px 13px;border-radius:999px;border:1px solid var(--line);background:#fff;color:var(--royal);text-decoration:none;transition:background .15s ease,border-color .15s ease,color .15s ease}
.lang-chip:hover{border-color:var(--royal);background:#EAF3FF}
.lang-chip.is-current{background:var(--royal);border-color:var(--royal);color:#fff;cursor:default}
.page-count{font-weight:800;color:var(--ink-soft);font-size:14px;min-width:72px;text-align:center}

/* ---------- Stage ---------- */
.book-stage{position:relative;z-index:1;display:flex;flex-direction:column;align-items:center;justify-content:center}

/* Cover shelf: standing 3D hardcover picture book */
.cover-shelf{display:flex;flex-direction:column;align-items:center;gap:30px;padding:10px 0 4px}
.book-3d{position:relative;width:min(300px,78vw);aspect-ratio:3/4;cursor:pointer;
  border-radius:10px 14px 14px 10px;
  transform:perspective(1300px) rotateY(-16deg);
  transition:transform .4s cubic-bezier(.3,.7,.3,1), box-shadow .4s ease;
  box-shadow:26px 34px 38px rgba(30,48,79,.28)}
/* ground shadow */
.book-3d::after{content:"";position:absolute;left:4%;right:14%;bottom:-26px;height:26px;z-index:-1;
  background:radial-gradient(ellipse at center, rgba(30,48,79,.32) 0%, rgba(30,48,79,0) 68%)}
.book-3d:hover{transform:perspective(1300px) rotateY(-4deg) translateY(-8px);box-shadow:30px 44px 50px rgba(30,48,79,.34)}

/* front cover board */
.book-3d-cover{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;border-radius:10px 14px 14px 10px;z-index:1}

/* spine: left bound edge, curved shading + hinge groove */
.book-3d-spine{position:absolute;left:0;top:2px;bottom:2px;width:24px;z-index:2;border-radius:10px 0 0 10px;
  background:linear-gradient(90deg,#0B2557 0%,#163E86 42%,#2E66C4 100%);
  box-shadow:inset -2px 0 3px rgba(0,0,0,.35), inset 2px 0 2px rgba(255,255,255,.12)}
.book-3d-spine::after{content:"";position:absolute;right:0;top:0;bottom:0;width:3px;
  background:linear-gradient(90deg,rgba(0,0,0,.42),rgba(0,0,0,0))}

/* page fore-edge: stacked sheet lines on the right */
.book-3d-edge{position:absolute;right:0;top:10px;bottom:10px;width:15px;z-index:0;border-radius:0 10px 10px 0;
  background:repeating-linear-gradient(180deg,#F4F8FC 0 2px,#DCE9F4 2px 3px,#F4F8FC 3px 4px);
  box-shadow:inset -2px 0 2px #C7DBEE, inset 2px 0 2px rgba(255,255,255,.7)}

/* page bottom edge: stacked sheets under the cover */
.book-3d::before{content:"";position:absolute;left:24px;right:3px;bottom:0;height:12px;z-index:0;border-radius:0 0 10px 10px;
  background:repeating-linear-gradient(180deg,#EDF3FA 0 1px,#D8E6F2 1px 2px,#EDF3FA 2px 3px);
  box-shadow:inset 0 -2px 2px rgba(120,150,180,.4)}

.book-3d-brand{position:absolute;left:32px;bottom:16px;z-index:3;font-family:var(--font-display);font-weight:800;color:#fff;font-size:15px;text-shadow:0 1px 6px rgba(0,0,0,.45)}

/* Cover opening transition: keep the closed 3D pose, lift and fade out.
   No axis flip — a single-layer cover swinging past 90° reads as two sheets
   splitting apart and closing back, which looked janky. */
@keyframes coverOpen {
  0%   { transform:perspective(1300px) rotateY(-16deg) translateY(0) scale(1); opacity:1; }
  100% { transform:perspective(1300px) rotateY(-16deg) translateY(-20px) scale(.95); opacity:0; }
}
.cover-actions{display:flex;flex-direction:column;align-items:center;gap:12px}
#downloadBtn{color:var(--royal);background:#fff;border:1.5px solid var(--line);font-weight:700}
#downloadBtn:hover{border-color:var(--royal)}
#downloadBtn .dl-icon{width:16px;height:16px;flex:0 0 auto}
#downloadBtn .dl-lang{color:var(--ink-soft);font-weight:600}
#downloadBtn .dl-price{color:var(--royal);font-weight:700}

.cover-shelf.opening .book-3d{animation:coverOpen .55s cubic-bezier(.4,.1,.3,1) forwards}
.cover-shelf.opening .cover-actions{opacity:0;pointer-events:none;transition:opacity .25s ease}
.cover-shelf.opening{pointer-events:none}

/* Open-book: landscape two-page spread (St.PageFlip curved turn) */
#book{position:relative;width:100%;max-width:840px !important;opacity:0;transition:opacity .45s ease}
/* While the reader mounts behind the opening cover, take it out of flow so
   the transparent shell never sits side-by-side with the cover and shoves it
   off-center. It is centered over the stage, then returns to normal flow. */
#book.is-staging{position:absolute;left:50%;top:0;transform:translateX(-50%);width:100%;max-width:840px}
#book.is-ready{opacity:1}
.pf-page{background:#fff;overflow:hidden}
#book.reader-fallback{display:grid;gap:22px}
#book.reader-fallback .pf-page{display:none;overflow:hidden;border-radius:var(--radius-sm);box-shadow:var(--shadow)}
#book.reader-fallback .pf-page.is-active{display:block}
/* Static stack: the wide 840px board would stretch the 4:3 art frame past the
   page height and push the caption off-screen, so cap the art height and give
   the text panel a reserved band. */
#book.reader-fallback .spread{height:auto}
#book.reader-fallback .spread-img{max-height:420px}
#book.reader-fallback .spread-text{min-height:84px;padding:18px 22px}

/* spread-in entrance after the cover opens (inner layer only; the library page
   element keeps its own transform, so we never animate .pf-page itself).
   The open spread fades in once via the #book host opacity transition; the
   inner panels do NOT run their own fade, otherwise the two opacity layers
   desync and the first spread appears to flash twice. */
@keyframes spreadIn{from{opacity:0}to{opacity:1}}
.back-page-inner{animation:spreadIn .5s ease both}

.spread{width:100%;height:100%;display:flex;flex-direction:column;background:#fff}
/* Fixed 4:3 art frame: every inner page gets the same illustration area
   regardless of how many lines its caption wraps to. */
.spread-img{flex:0 0 auto;width:100%;aspect-ratio:4/3;overflow:hidden;background:#F2F8FF}
.spread-img img{width:100%;height:100%;object-fit:cover}
.spread-text{flex:1 1 auto;min-height:0;display:flex;align-items:center;justify-content:center;padding:14px 22px;text-align:center;overflow-y:auto;overflow-x:hidden}
.spread-text p{font-family:var(--font-display);font-weight:600;font-size:clamp(14px,1.7vw,17px);color:var(--ink);line-height:1.45;max-width:100%}

/* Title page: opening page prepended for an even inner-page count. */
.title-page{background:linear-gradient(160deg,#F6FAFF,#EAF3FF)}
.title-page-inner{width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;text-align:center;padding:24px}
.title-page-inner img{width:84px;height:84px;border-radius:50%;object-fit:cover}
.title-page-inner h2{font-family:var(--font-display);font-size:clamp(20px,2.4vw,26px);color:var(--deep);line-height:1.3}
.title-page-inner p{font-size:15px;color:var(--ink-soft)}

/* Closing back cover: a real flip page on the last spread's right board. */
.back-page{background:linear-gradient(160deg,#EAF3FF,#FFF6E0)}
.back-page-inner{width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;text-align:center;padding:24px}
.back-page-inner img{width:72px;height:72px;border-radius:50%;object-fit:cover}
.back-page-inner h3{font-family:var(--font-display);font-size:22px;color:var(--deep)}
.back-page-inner p{font-size:15px;color:var(--ink-soft);max-width:240px}

/* ---------- Controls ---------- */
.reader-controls{position:relative;z-index:30;display:flex;align-items:center;justify-content:center;gap:12px;margin-top:30px;flex-wrap:wrap}
/* Reserved-but-hidden during prep: keeps the bar's layout height so the
   page does not jump when the controls appear with the first spread. */
.reader-controls.controls-hidden{visibility:hidden}
.reader-controls button{font-family:var(--font-display);font-weight:800;font-size:16px;border:1.5px solid transparent;border-radius:18px;min-height:48px;padding:0 26px;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:8px;box-shadow:var(--shadow);transition:transform .18s ease,box-shadow .18s ease,border-color .18s ease,background .18s ease,color .18s ease}
.reader-controls button:disabled{opacity:.35;cursor:default;box-shadow:none}

/* Page turn: primary blue actions */
.reader-controls .page-nav{background:#fff;color:var(--royal);border-color:var(--line)}
.reader-controls .page-nav:hover:not(:disabled){border-color:var(--royal);background:#F2F8FF;transform:translateY(-2px)}
.reader-controls .page-nav.primary{background:linear-gradient(135deg,var(--royal),var(--deep));color:#fff;border-color:transparent;box-shadow:0 12px 26px rgba(37,99,214,.28)}
.reader-controls .page-nav.primary:hover:not(:disabled){background:var(--deep);transform:translateY(-2px)}

/* Sibling book navigation: muted neutral, visually separated from page turn */
.reader-controls .book-nav{background:#fff;color:var(--ink-soft);border-color:#D9E2EE}
.reader-controls .book-nav:hover:not(:disabled){color:var(--ink);border-color:#B9C8DC;transform:translateY(-2px)}

/* Page-turn group carries its own side dividers, shown only next to a
   visible sibling-book button, so a hidden sibling never leaves an
   orphan divider behind. */
.page-group{display:inline-flex;align-items:center;gap:12px;padding:0 14px;position:relative}
.page-group::before,.page-group::after{content:"";display:none;position:absolute;top:50%;transform:translateY(-50%);width:1px;height:22px;background:#D9E2EE}
.page-group::before{left:0}
.page-group::after{right:0}
.page-group.has-prev::before{display:block}
.page-group.has-next::after{display:block}
@media(max-width:600px){
  .page-group{padding:0;gap:10px}
  .page-group::before,.page-group::after{display:none}
}
.note{margin-top:22px;text-align:center;font-size:13px;color:var(--ink-soft);max-width:620px;margin-left:auto;margin-right:auto}

/* ---------- Responsive ---------- */
@media(max-width:600px){
  .reader{padding:22px 0 36px}
  .reader-head{flex-direction:column;align-items:flex-start}
  .spread-text{padding:14px 18px}
}
