/* BookSpreadLayout — cover on its own row, then two-page spreads.
   See /book-spread-layout.js. Flat, storybook-like: no curl, no 3D, no gloss.
   Two-up vs one-up is decided by the CONTAINER width (not the viewport):
   a page must be at least 280px wide, so two pages need >= 560px. */
.bsl {
  --bsl-min-page: 280px;
  --bsl-spine: var(--jade, #2b6049);
  --bsl-paper: var(--parchment, #f5e9d1);
  --bsl-line: var(--line, #e6d5b5);
  --bsl-caption: var(--muted, #7a6b56);
  container-type: inline-size;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}
.bsl-pages {
  list-style: none; margin: 0; padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  row-gap: 24px;
}
.bsl-item { min-width: 0; margin: 0; padding: 0; }
.bsl-blank { display: none; }            /* filler is dropped in one-up mode */

/* ---- one page's paper ---- */
.bsl-sheet {
  position: relative;
  aspect-ratio: 1 / 1;                   /* reserved box: no layout shift */
  background: var(--bsl-paper);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow-md, 0 10px 30px -8px rgba(43,33,24,.14));
}
.bsl-sheet img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;                   /* whole image, never cropped */
  display: block;
}
.bsl-sheet.is-loading img { opacity: 0; }
.bsl-sheet.is-empty img { display: none; }

/* skeleton shown inside the box until the image loads */
.bsl-skel {
  position: absolute; inset: 0; display: none;
  background: linear-gradient(90deg, var(--line-soft, #efe2c6) 0%, var(--bsl-paper) 50%, var(--line-soft, #efe2c6) 100%);
  background-size: 200% 100%;
  animation: bsl-shimmer 1.4s ease-in-out infinite;
}
.bsl-sheet.is-loading .bsl-skel, .bsl-sheet.is-empty .bsl-skel { display: block; }
@keyframes bsl-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* per-page error with retry */
.bsl-error {
  position: absolute; inset: 0; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 16px; text-align: center; font-size: 14px; color: var(--ink-soft, #4a3f32);
  background: var(--bsl-paper);
}
.bsl-sheet.is-error .bsl-error { display: flex; }
.bsl-sheet.is-error img, .bsl-sheet.is-error .bsl-skel { display: none; }
.bsl-retry {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 6px 14px; border-radius: 8px;
  border: 1.5px solid var(--bsl-line); background: var(--card, #fff); color: var(--ink, #1f1912);
}

/* blank filler and dedication share the paper look */
.bsl-blank .bsl-sheet { box-shadow: var(--shadow-md, 0 10px 30px -8px rgba(43,33,24,.14)); }
.bsl-dedication .bsl-sheet {
  display: flex; align-items: center; justify-content: center; padding: 12%;
}
.bsl-dedication-text {
  font-family: var(--font-display, Georgia, serif);
  font-style: italic; font-size: clamp(18px, 6cqw, 30px); line-height: 1.3;
  text-align: center; color: var(--ink-soft, #4a3f32); text-wrap: balance;
}

/* captions under each page */
.bsl-meta { padding: 8px 4px 0; }
.bsl-text {
  margin: 0 0 6px; font-size: 14px; line-height: 1.6; color: var(--ink-soft, #4a3f32);
  white-space: pre-line;
}
.bsl-num { font-size: 12px; text-align: center; color: var(--bsl-caption); }
.bsl-actions { margin-top: 8px; }

/* cover: one page wide, spine on the left like the Library book object */
.bsl-cover { max-width: 480px; margin: 0 auto; width: 100%; }
.bsl-cover .bsl-sheet {
  border-radius: 0 6px 6px 0;
  box-shadow: 4px 4px 14px -2px rgba(31,25,18,.18), 1px 1px 3px rgba(31,25,18,.08);
}
.bsl-cover .bsl-sheet::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; z-index: 2;
  background: var(--bsl-spine); border-radius: 3px 0 0 3px;
  box-shadow: inset -2px 0 4px rgba(0,0,0,.15);
}
/* optional title overlay on the cover (Create v2) */
.bsl-cover-overlay {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  padding: 8%; pointer-events: none;
  background: linear-gradient(to top, rgba(43,33,24,.78), rgba(43,33,24,0) 55%);
}
.bsl-cover-title {
  font-family: var(--font-display, Georgia, serif); font-weight: 700; line-height: 1.1;
  font-size: clamp(20px, 7cqw, 36px); color: #fdf6ec; text-align: center; margin: 0 0 4px;
  text-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.bsl-cover-subtitle { font-size: clamp(12px, 3cqw, 16px); color: #fbe9d3; text-align: center; font-style: italic; margin: 0; }

/* ---- two-up: page width >= 280px ---- */
@container (min-width: 560px) {
  .bsl-pages:not(.bsl-book) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 0;                       /* pages touch at the gutter */
    row-gap: 28px;
  }
  .bsl-pages:not(.bsl-book) .bsl-blank { display: block; }
  .bsl-pages:not(.bsl-book) .bsl-cover { grid-column: 1 / -1; width: 50%; }

  /* Cover is child 1, so left pages are the even children, right pages the odd. */
  .bsl-pages:not(.bsl-book) .bsl-item:not(.bsl-cover):nth-child(even) .bsl-sheet {
    border-radius: 6px 0 0 6px;
  }
  .bsl-pages:not(.bsl-book) .bsl-item:not(.bsl-cover):nth-child(odd) .bsl-sheet {
    border-radius: 0 6px 6px 0;
  }
}
/* inner-edge shadow sits above the art */
.bsl-sheet::after {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
}
@container (min-width: 560px) {
  .bsl-pages:not(.bsl-book) .bsl-item:not(.bsl-cover):nth-child(even) .bsl-sheet::after { box-shadow: inset -14px 0 14px -12px rgba(31,25,18,.28); }
  .bsl-pages:not(.bsl-book) .bsl-item:not(.bsl-cover):nth-child(odd) .bsl-sheet::after  { box-shadow: inset 14px 0 14px -12px rgba(31,25,18,.28); }
}
@media (prefers-reduced-motion: reduce) { .bsl-skel { animation: none; } }

.bsl-badge {
  position: absolute; top: 5%; left: 5%; z-index: 2;
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: #fdf6ec; background: #2b6049; padding: 4px 10px; border-radius: 999px; font-weight: 600;
}


/* ===== Picture-book format: one item per row (see book-spread-layout.js) ===== */
.bsl-spread { width: 100%; }
.bsl-spread .bsl-sheet { aspect-ratio: 3 / 2; border-radius: 6px; cursor: zoom-in; }   /* two facing pages, one image */
/* faint centre fold laid over the art: a shadow, not a gap */
.bsl-spread .bsl-sheet::after {
  background: linear-gradient(90deg, rgba(31,25,18,0) 44%, rgba(31,25,18,.08) 50%, rgba(31,25,18,0) 56%);
}
/* covers: one page = half a spread, so they read as the two sides of a closed book */
/* both covers are the same box: exactly one page of a spread (half its width, its full height = 3:4).
   Story spreads stay whole (contain). The covers are generated 2:3, so they fill the 3:4 box and lose a thin strip
   at the top and bottom, exactly like the PDF; the text safe area (page_format.safe_area) allows for it. */
.bsl-cover, .bsl-back-cover { grid-column: auto; max-width: none; margin: 0 auto; width: max(50%, min(100%, 220px)); }
.bsl-cover .bsl-sheet, .bsl-back-cover .bsl-sheet { aspect-ratio: 3 / 4; cursor: zoom-in; }
.bsl-back-cover .bsl-sheet { border-radius: 6px 0 0 6px; box-shadow: -4px 4px 14px -2px rgba(31,25,18,.18), -1px 1px 3px rgba(31,25,18,.08); }
.bsl-back-cover .bsl-sheet::before {                          /* spine edge on the right */
  content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 6px; z-index: 2;
  background: var(--bsl-spine); border-radius: 0 3px 3px 0; box-shadow: inset 2px 0 4px rgba(0,0,0,.15);
}
.bsl-book .bsl-cover .bsl-sheet img, .bsl-book .bsl-back-cover .bsl-sheet img { object-fit: cover; }
.bsl-sheet:focus-visible { outline: 3px solid var(--bsl-spine); outline-offset: 3px; }
.bsl-spread .bsl-num, .bsl-back-cover .bsl-num { text-align: center; }
.bsl-notice {
  margin-top: 6px; font-size: 13px; color: var(--bsl-caption); text-align: center;
  display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap;
}
.bsl-regen {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 3px 10px; border-radius: 8px;
  border: 1.5px solid var(--bsl-line); background: var(--card, #fff); color: var(--ink, #1f1912);
}
/* fullscreen: whole image, native pinch-zoom; uses the full screen in landscape */
.bsl-viewer {
  position: fixed; inset: 0; z-index: 1000; background: rgba(15,12,9,.94);
  display: flex; align-items: center; justify-content: center; overflow: auto; touch-action: pinch-zoom pan-x pan-y;
}
.bsl-viewer img { max-width: 100vw; max-height: 100vh; width: auto; height: auto; object-fit: contain; display: block; }
.bsl-viewer-close {
  position: fixed; top: 10px; right: 10px; width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  font-size: 28px; line-height: 1; background: rgba(255,255,255,.9); color: #1f1912;
}
body.bsl-noscroll { overflow: hidden; }

/* Dedication: plain paper spread, one centred line, no art */
/* The line sits on the RIGHT-hand page (upper part, centred in that page's margins) so the fold never touches it. */
.bsl-sheet.bsl-plain { display: flex; align-items: flex-start; justify-content: flex-end; padding: 8% 0 0; cursor: default; }
.bsl-ded-text {
  font-family: var(--font-display, Georgia, serif); font-style: italic; text-align: right; white-space: pre-line;
  font-size: clamp(16px, 3cqw, 30px); line-height: 1.35; color: var(--ink-soft, #4a3f32);
  width: 50%; box-sizing: border-box; padding: 0 8%;          /* the right half, inside its margins */
}

.bsl-banner {
  margin: 0 0 16px; padding: 10px 14px; border-radius: 8px; font-size: 14px; text-align: center;
  background: #fdf0e6; border: 1px solid var(--bsl-line); color: var(--ink-soft, #4a3f32);
}
