/* ==========================================================================
   Layout — the flipbook shell
   A horizontally paged track (native CSS scroll-snap) with fixed chrome
   above and below. Works via swipe/trackpad/scrollbar with zero JS;
   flipbook.js layers keyboard nav, buttons, hash routing and focus mgmt.
   ========================================================================== */

html {
  background: var(--color-paper);
}

body {
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  overflow: hidden; /* the .book element owns scrolling */
}

.book {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: row;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.book::-webkit-scrollbar { display: none; }

.book.is-jumping {
  scroll-behavior: auto;
}

.page {
  flex: 0 0 100%;
  width: 100%;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--color-paper);
  -webkit-overflow-scrolling: touch;
}

.page__inner {
  position: relative;
  z-index: 1;
  max-width: var(--content-max);
  margin-inline: auto;
  min-height: 100%;
  width: 100%;
  padding: calc(var(--chrome-height) + var(--space-7)) var(--space-5) calc(var(--pager-height) + var(--space-7));
  display: flex;
  flex-direction: column;
}

/* Phone landscape: the default padding (chrome/pager height + a full
   space-7) is tuned for tall portrait viewports and eats too much of a
   short one. Applies globally — any page not already covered by the
   tighter .page--product/.page--tight tiers still needs this. */
@media (max-height: 500px) and (min-width: 560px) {
  .page__inner {
    padding-top: calc(var(--chrome-height) + var(--space-2));
    padding-bottom: calc(var(--pager-height) + var(--space-2));
  }
}

@media (min-width: 640px) {
  .page__inner { padding-inline: var(--space-7); }
}
@media (min-width: 1024px) {
  .page__inner { padding-inline: var(--space-9); }
}

/* ---- Full-bleed photographic pages (cover / dividers / back cover) ---- */
.page--bleed .page__media {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.page--bleed .page__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.page--bleed .page__media::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--page-scrim, linear-gradient(180deg, rgba(20,14,8,.15) 0%, rgba(20,14,8,.1) 40%, rgba(20,14,8,.72) 100%));
}
.page--bleed .page__inner {
  justify-content: flex-end;
  color: var(--color-paper);
  min-height: 100%;
}
.page--center .page__inner {
  justify-content: center;
  align-items: center;
  text-align: center;
}

/* ---- Product pages: blurred category-photo backdrop behind a glass panel.
   Padding is deliberately tighter than the default page so a full product
   (photo + name + description + facts + allergens) fits one mobile
   viewport with no scrolling. ---- */
.page--product .page__inner,
.page--tight .page__inner {
  padding-top: calc(var(--chrome-height) + var(--space-2));
  padding-bottom: calc(var(--pager-height) + var(--space-2));
}
.page--product .page__inner {
  justify-content: center;
  gap: var(--space-3);
}
@media (min-width: 800px) and (min-height: 501px) {
  .page--product .page__inner,
  .page--tight .page__inner {
    padding-top: calc(var(--chrome-height) + var(--space-6));
    padding-bottom: calc(var(--pager-height) + var(--space-6));
  }
}

.page--product .page__media {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}
.page--product .page__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(11px) saturate(1.15) brightness(1.02);
  transform: scale(1.08);
}
.page--product .page__media::after {
  content: "";
  position: absolute;
  inset: 0;
  /* A calm, near-solid band across the top — where the chrome bar and
     eyebrow live — so that text sits on settled ground rather than
     fighting the photo underneath it letter by letter. Clears by ~30%
     so the product photography stays the richest part of the page. */
  background: linear-gradient(
    180deg,
    rgba(247, 241, 230, 0.94) 0%,
    rgba(247, 241, 230, 0.9) 14%,
    rgba(247, 241, 230, 0.5) 24%,
    rgba(247, 241, 230, 0.34) 32%,
    rgba(247, 241, 230, 0.38) 100%
  );
}

/* ---- Fixed chrome ---- */
.chrome {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  height: var(--chrome-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-inline: var(--space-4);
  background: rgba(247, 241, 230, 0.6);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border-bottom: 1px solid rgba(139, 115, 85, 0.14);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .chrome, .pager { background: var(--color-paper); }
}
@media (min-width: 640px) {
  .chrome { padding-inline: var(--space-6); }
}

.chrome__home {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1);
  border-radius: var(--radius-pill);
}
.chrome__home img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}
.chrome__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-small);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-ink-soft);
  display: none;
}
@media (min-width: 560px) {
  .chrome__title { display: block; }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: var(--color-ink);
  background: rgba(255,255,255,0.4);
  transition: background var(--dur-fast) var(--ease-standard), transform var(--dur-fast) var(--ease-standard);
}
.icon-btn:hover { background: rgba(255,255,255,0.75); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---- Fixed pager (bottom) ----
   Grid with fixed-width outer columns so the prev/next buttons stay put
   regardless of how wide the current page's label text is. */
.pager {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 100;
  height: var(--pager-height);
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: var(--space-3);
  padding-inline: var(--space-4);
  background: rgba(247, 241, 230, 0.6);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border-top: 1px solid rgba(139, 115, 85, 0.14);
}
@media (min-width: 640px) {
  .pager { padding-inline: var(--space-6); }
}

.pager__progress {
  position: absolute;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--color-gold-deep);
  width: 0%;
  transition: width var(--dur-fast) var(--ease-standard);
}

.pager__status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  text-align: center;
}
.pager__label {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-small);
  color: var(--color-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
}
.pager__count {
  font-size: var(--fs-micro);
  letter-spacing: var(--tracking-wide);
  color: var(--color-ink-soft);
}

/* ---- Table of contents overlay ---- */
.toc-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--color-paper);
  overflow-y: auto;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-standard), transform var(--dur-fast) var(--ease-standard);
}
.toc-overlay.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.toc-overlay__inner {
  max-width: 880px;
  margin-inline: auto;
  padding: calc(var(--chrome-height) + var(--space-6)) var(--space-5) var(--space-8);
}

@media (prefers-reduced-motion: reduce) {
  .book { scroll-behavior: auto; }
}
