@font-face {
  font-family: 'Manrope';
  src: url('fonts/Manrope-VariableFont_wght.ttf') format('truetype');
  font-weight: 200 800;
  font-display: swap;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--navy-deep);
}

body {
  font-family: var(--font);
  color: var(--white);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  background:
    radial-gradient(ellipse 70% 60% at 50% 46%, rgba(var(--navy-light-rgb), 0.55) 0%, rgba(var(--navy-light-rgb), 0) 70%),
    var(--gradient-brand);
  overflow: hidden;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px 6px;
  padding-top: max(14px, env(safe-area-inset-top));
  min-height: 56px;
}
.logo { height: 30px; width: auto; display: block; flex: none; }
.title {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--grey-blue);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { flex: none; display: flex; justify-content: flex-end; min-width: 117px; }
.topbar-actions { gap: 6px; }
.back-btn { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px 0 10px; border-radius: 999px; border: 1px solid rgba(255,255,255,.18); color: #fff; font-size: 13px; text-decoration: none; white-space: nowrap; transition: background-color 150ms, border-color 150ms; }
.back-btn:hover { background: rgba(255,255,255,.08); border-color: var(--gold-light, #E7A368); }
.back-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.back-btn[hidden], .icon-btn[hidden] { display: none; }
@media (max-width: 640px) { .back-btn span { display: none; } .back-btn { padding: 0 9px; } .back-btn + .logo { display: none; } }

/* Buttons */
.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--white);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  opacity: 0.86;
  transition: background-color 0.15s, opacity 0.15s, color 0.15s;
}
.icon-btn svg, .side-btn svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn:hover { background: rgba(var(--white-rgb), 0.08); opacity: 1; }
.icon-btn:active { background: rgba(var(--white-rgb), 0.14); }
.icon-btn:disabled { opacity: 0.3; cursor: default; background: transparent; }
.icon-btn[aria-expanded="true"], .icon-btn[aria-pressed="true"] { color: var(--gold); opacity: 1; }
.icon-btn:focus-visible, .side-btn:focus-visible, .page-input:focus-visible, .thumb:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
#btn-fullscreen .i-exit { display: none; }
.is-fullscreen #btn-fullscreen .i-enter { display: none; }
.is-fullscreen #btn-fullscreen .i-exit { display: block; }

/* Stage and book */
.stage {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 72px;
  align-items: center;
}
.book-area {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  height: 100%;
  min-width: 0;
  padding: 18px 0;
}
.book-shift {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.7s cubic-bezier(0.3, 0.1, 0.25, 1), opacity 0.16s ease;
}
.book-shift.no-anim { transition: opacity 0.16s ease; }
.book-shift.fading { opacity: 0; }

.book {
  position: relative;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Page-flip library layout (its own CSS is not shipped in the browser build) */
.stf__parent { position: relative; display: block; transform: translateZ(0); }
.stf__wrapper { position: absolute; inset: 0; }
.stf__block { position: absolute; inset: 0; perspective: 2000px; }
.stf__item { display: none; position: absolute; transform-style: preserve-3d; }
.stf__outerShadow, .stf__innerShadow, .stf__hardShadow, .stf__hardInnerShadow {
  position: absolute; left: 0; top: 0;
}

.page {
  background: var(--white);
  overflow: hidden;
}
.page img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.page img.loaded { opacity: 1; }
.page::before {
  /* shown until the image arrives */
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(var(--grey-blue-rgb), 0.16);
}

/* Printed-in spine shading on each page of a spread */
.gutter {
  position: absolute;
  top: 0; bottom: 0;
  width: 12%;
  pointer-events: none;
  display: none;
}
.landscape .gutter { display: block; }
.page.is-left .gutter {
  right: 0;
  background: linear-gradient(to left,
    rgba(0, 0, 0, 0.34) 0%, rgba(0, 0, 0, 0.16) 8%, rgba(0, 0, 0, 0.06) 30%, rgba(0, 0, 0, 0.015) 65%, rgba(0, 0, 0, 0) 100%);
}
.page.is-right .gutter {
  left: 0;
  background: linear-gradient(to right,
    rgba(0, 0, 0, 0.30) 0%, rgba(0, 0, 0, 0.13) 7%, rgba(255, 255, 255, 0.06) 22%, rgba(255, 255, 255, 0.02) 45%, rgba(0, 0, 0, 0) 100%);
}
/* Covers only show a faint hinge */
.page.is-cover .gutter { width: 4%; opacity: 0.45; }

/* Soft drop shadow under the visible page(s) */
.plate {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  border-radius: 2px;
  box-shadow:
    0 2px 4px rgba(0, 10, 20, 0.25),
    0 14px 28px rgba(0, 10, 20, 0.30),
    0 34px 70px rgba(0, 10, 20, 0.38);
  transition: left 0.5s ease, width 0.5s ease, top 0.2s, height 0.2s;
}
.plate::before, .plate::after {
  /* page-block edges */
  content: '';
  position: absolute;
  top: 1px; bottom: 1px;
  width: var(--edge-r, 0px);
  right: calc(-1 * var(--edge-r, 0px));
  background: repeating-linear-gradient(to right, rgba(235, 239, 241, 0.92) 0 1px, rgba(150, 163, 172, 0.92) 1px 2px);
  border-radius: 0 2px 2px 0;
}
.plate::after {
  right: auto;
  width: var(--edge-l, 0px);
  left: calc(-1 * var(--edge-l, 0px));
  border-radius: 2px 0 0 2px;
}

/* Side arrows */
.side-btn {
  appearance: none;
  grid-row: 1;
  justify-self: center;
  width: 48px; height: 48px;
  border-radius: 999px;
  border: 1px solid rgba(var(--white-rgb), 0.14);
  background: rgba(var(--navy-rgb), 0.35);
  color: var(--white);
  display: grid; place-items: center;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.15s, background-color 0.15s, border-color 0.15s;
  z-index: 2;
}
.side-prev { grid-column: 1; }
.side-next { grid-column: 3; }
.side-btn:hover { opacity: 1; background: rgba(var(--navy-light-rgb), 0.7); border-color: rgba(var(--gold-rgb), 0.5); }
.side-btn:disabled { opacity: 0; pointer-events: none; }

/* Toolbar */
.toolbar {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 16px 16px;
  margin-bottom: max(16px, env(safe-area-inset-bottom));
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(var(--navy-deep-rgb), 0.55);
  border: 1px solid rgba(var(--white-rgb), 0.09);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: relative;
  z-index: 5;
}
.group { display: flex; align-items: center; gap: 2px; }
.divider { width: 1px; height: 20px; background: rgba(var(--white-rgb), 0.14); margin: 0 4px; }
.pager { display: flex; align-items: center; gap: 4px; margin: 0 6px; font-size: 13px; color: var(--grey-blue); }
.page-input {
  width: 64px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(var(--white-rgb), 0.12);
  background: rgba(var(--white-rgb), 0.05);
  color: var(--white);
  font: 500 13px/1 var(--font);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.page-input:focus { border-color: rgba(var(--gold-rgb), 0.7); outline: none; background: rgba(var(--white-rgb), 0.08); }
.page-total { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Thumbnails */
.thumbs {
  position: absolute;
  left: 0; right: 0;
  bottom: 76px;
  z-index: 4;
  padding: 0 16px;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.thumbs[hidden] { display: none; }
.thumbs-track {
  pointer-events: auto;
  max-width: min(1200px, 100%);
  display: flex;
  gap: 14px;
  overflow-x: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding: 14px 16px 10px;
  border-radius: 14px;
  background: rgba(var(--navy-deep-rgb), 0.86);
  border: 1px solid rgba(var(--white-rgb), 0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--white-rgb), 0.2) transparent;
  animation: rise 0.22s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.thumb {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  color: var(--grey-blue);
  font: 500 12px/1 var(--font);
  cursor: pointer;
  flex: none;
  display: grid;
  justify-items: center;
  gap: 7px;
  border-radius: 4px;
}
.thumb-pages {
  display: flex;
  outline: 1px solid rgba(var(--white-rgb), 0.08);
  border-radius: 2px;
  overflow: hidden;
  transition: outline-color 0.15s, transform 0.15s;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.thumb img { display: block; height: 68px; width: auto; aspect-ratio: var(--ratio); background: rgba(var(--grey-blue-rgb), 0.16); }
.thumb:hover .thumb-pages { outline-color: rgba(var(--white-rgb), 0.4); transform: translateY(-2px); }
.thumb[aria-current="true"] { color: var(--white); }
.thumb[aria-current="true"] .thumb-pages { outline: 2px solid var(--gold); }

/* Zoom */
.zoom {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.zoom[hidden] { display: none; }
.zoom.dragging { cursor: grabbing; }
.zoom-content {
  position: absolute;
  transform-origin: 0 0;
  display: flex;
  box-shadow: 0 30px 70px rgba(0, 10, 20, 0.45);
}
.zoom-content.animate { transition: transform 0.28s cubic-bezier(0.3, 0.1, 0.25, 1); }
.zoom-page { position: relative; height: 100%; background: var(--white); overflow: hidden; }
.zoom-page img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; -webkit-user-drag: none; user-select: none; }
.zoom-close {
  position: absolute;
  top: 12px; right: 12px;
  background: rgba(var(--navy-deep-rgb), 0.7);
  border: 1px solid rgba(var(--white-rgb), 0.12);
}
.zooming .book-shift { visibility: hidden; }
.zooming .side-btn { opacity: 0; pointer-events: none; }

/* Smaller screens */
@media (max-width: 760px) {
  .stage { grid-template-columns: 0 minmax(0, 1fr) 0; }
  .side-btn { display: none; }
  .book-area { padding: 10px 12px; }
  .topbar { padding-left: 16px; padding-right: 12px; gap: 10px; }
  .topbar-actions { min-width: 40px; }
  .logo { height: 22px; }
  .title { font-size: 13px; text-align: right; }
  .thumbs { bottom: 70px; padding: 0 10px; }
}
@media (max-width: 480px) {
  .hide-sm { display: none; }
  .title { font-size: 11.5px; white-space: normal; line-height: 1.3; }
  .toolbar { margin: 4px 10px 12px; gap: 2px; padding: 4px; }
  .pager { margin: 0 2px; }
  .page-input { width: 58px; }
  .divider { margin: 0 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .plate, .zoom-content.animate, .thumbs-track, .thumb-pages { transition: none !important; animation: none !important; }
  .book-shift { transition: opacity 0.16s ease !important; }
}

/* Book list side bar */
.books-btn { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px 0 10px; border-radius: 999px; border: 1px solid rgba(255,255,255,.18); background: transparent; color: #fff; font: inherit; font-size: 13px; cursor: pointer; transition: background-color 150ms, border-color 150ms; }
.books-btn:hover, .books-btn[aria-expanded="true"] { background: rgba(255,255,255,.08); border-color: var(--gold-light); }
.books-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.library { position: absolute; z-index: 30; top: 64px; left: 12px; bottom: 12px; width: min(300px, calc(100vw - 24px)); display: flex; flex-direction: column; border-radius: 14px; background: rgba(var(--navy-deep-rgb), .96); border: 1px solid rgba(255,255,255,.1); box-shadow: 0 18px 48px rgba(0,0,0,.45); backdrop-filter: blur(10px); animation: library-in 180ms ease-out; }
.library[hidden] { display: none; }
@keyframes library-in { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
.library-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 8px 16px; font-size: 13px; color: var(--grey-blue); }
.library-list { list-style: none; margin: 0; padding: 4px 8px 12px; overflow-y: auto; }
.library-item { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 10px; color: #fff; text-decoration: none; }
.library-item:hover { background: rgba(255,255,255,.06); }
.library-item.is-current { background: rgba(var(--gold-light-rgb), .14); }
.library-item img { width: 48px; height: 64px; object-fit: cover; border-radius: 3px; flex: none; box-shadow: 0 2px 6px rgba(0,0,0,.35); background: rgba(255,255,255,.06); }
.library-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.library-title { font-size: 14px; line-height: 1.25; }
.library-item.is-current .library-title { color: var(--gold-light); }
.library-meta { font-size: 12px; color: var(--grey-blue); }
@media (max-width: 640px) { .books-btn span { display: none; } .books-btn { padding: 0 9px; } }
@media (prefers-reduced-motion: reduce) { .library { animation: none; } }

/* Product code search */
.code-search { position: relative; flex: 0 1 300px; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.04); }
.code-search[hidden] { display: none; }
.code-search:focus-within { border-color: var(--gold-light); }
.code-search > svg { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--grey-blue); stroke-width: 2; stroke-linecap: round; }
.code-search input { flex: 1; min-width: 0; border: 0; background: transparent; color: #fff; font: inherit; font-size: 13px; outline: none; }
.code-search input::placeholder { color: rgba(var(--grey-blue-rgb), .8); }
.code-results { position: absolute; z-index: 40; top: 44px; right: 0; width: min(360px, calc(100vw - 24px)); margin: 0; padding: 6px; list-style: none; border-radius: 12px; background: rgba(var(--navy-deep-rgb), .98); border: 1px solid rgba(255,255,255,.1); box-shadow: 0 18px 48px rgba(0,0,0,.45); }
.code-results[hidden] { display: none; }
.code-none { padding: 10px; font-size: 13px; color: var(--grey-blue); }
.title { flex: 1 1 auto; }

/* Rows shared by search results and the favourites list */
.fav-row { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; }
.fav-row:hover { background: rgba(255,255,255,.05); }
.fav-row img { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; flex: none; background: rgba(255,255,255,.06); }
.fav-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.fav-text b { font-size: 13px; font-weight: 600; color: #fff; }
.fav-text span { font-size: 12px; color: var(--grey-blue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fav-heart { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 999px; background: transparent; color: var(--grey-blue); cursor: pointer; }
.fav-heart:hover { background: rgba(255,255,255,.08); color: #fff; }
.fav-heart.on { color: var(--gold-light); }
.fav-heart svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }

/* Side bar tabs + favourites */
.library-tabs { display: flex; align-items: center; gap: 4px; padding: 10px 8px 6px 10px; }
.library-tabs [role="tab"] { border: 0; background: transparent; color: var(--grey-blue); font: inherit; font-size: 13px; padding: 7px 12px; border-radius: 999px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.library-tabs [role="tab"][aria-selected="true"] { background: rgba(255,255,255,.08); color: #fff; }
.library-tabs [role="tab"][hidden] { display: none; }
.library-tabs #library-close { margin-left: auto; }
.fav-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--gold-light); color: var(--navy-deep); font-size: 11px; font-weight: 600; display: inline-grid; place-items: center; }
.fav-count[hidden] { display: none; }
.library-list[hidden], .fav-panel[hidden] { display: none; }
.fav-panel { display: flex; flex-direction: column; min-height: 0; flex: 1; padding: 4px 8px 12px; }
.fav-empty { margin: 8px; font-size: 13px; line-height: 1.5; color: var(--grey-blue); }
.fav-empty[hidden] { display: none; }
.fav-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.fav-send { margin: 10px 4px 0; display: flex; justify-content: center; align-items: center; height: 40px; border-radius: 999px; background: var(--gold-light); color: var(--navy-deep); font-size: 13px; font-weight: 600; text-decoration: none; }
.fav-send:hover { filter: brightness(1.06); }
.fav-send[hidden] { display: none; }
@media (max-width: 900px) { .title { display: none; } }
@media (max-width: 640px) { .code-search { flex: 1 1 auto; } .logo { display: none; } }
