/* Scenery is local to the Bazar page. The catalog remains plugin-owned. */
/* Image overrides replace only background-image. Keep sizing, position and
   repeat rules outside the variable so uploaded artwork behaves like defaults. */
.lbm-bazar-scene {
  --lbm-bazar-accent: #4fa4ff;
  position: relative;
  width: min(100%, var(--lbm-bazar-max, 1040px));
  margin: clamp(20px, 3cqw, 44px) auto 0;
  isolation: isolate;
  color: #f7f9ff;
  font-family: var(--lbm-bazar-font, Georgia, serif);
}
.lbm-bazar-scene::before {
  content: '';
  position: absolute;
  inset: 10% 1% 7%;
  z-index: -1;
  background: var(--lbm-bazar-bg, radial-gradient(ellipse at center, #253a89, #03091f 76%));
  background-size: cover;
  box-shadow: 0 0 28px #132d7970;
}
.lbm-bazar-crown {
  position: relative;
  z-index: 4;
  width: 100%;
  aspect-ratio: 3;
  margin-bottom: -7%;
  background-image: var(--lbm-bazar-crown, url('../images/bazar/crown.webp'));
  background-position: center bottom;
  background-size: 100% auto;
  background-repeat: no-repeat;
  pointer-events: none;
  transform: translateY(var(--lbm-bazar-crown-y, 0px));
}
.lbm-bazar-frame { position: relative; padding: 0; }
.lbm-bazar-cabinet {
  position: relative;
  /* Let per-shelf overlays rise above the separate crown artwork. */
  border-left: clamp(2px, .5cqw, 6px) ridge #bfd5f9;
  border-right: clamp(2px, .5cqw, 6px) ridge #bfd5f9;
  background: linear-gradient(90deg, #020818, #081334 8%, #09184a 50%, #081334 92%, #020818);
  box-shadow: inset 8px 0 18px #000b, inset -8px 0 18px #000b, 0 0 16px #75a4ff90;
}
/* Each shelf has a continuous upright. Optional per-shelf art sits in one bounded module. */
.lbm-bazar-shelf {
  --lbm-bazar-book-height: clamp(296px, calc(var(--lbm-bazar-shelf-h, 430px) * .57), 370px);
  --lbm-bazar-plaque-shift: calc(var(--lbm-bazar-shelf-h, 430px) * .85 - var(--lbm-bazar-book-height) - 57px);
  position: relative;
  display: grid;
  grid-template-rows: minmax(65px, auto) minmax(335px, 1fr);
  min-height: var(--lbm-bazar-shelf-h, 430px);
  padding: 3px 9% 19px;
  background-image: var(--lbm-bazar-shelf, url('../images/bazar/shelf-bay-clean.webp'));
  background-position: center;
  background-size: 135% 100%;
  background-repeat: no-repeat;
  /* Shelves share one stack so a vine can cover the preceding silver ledge. */
}
.lbm-bazar-shelf-backdrop {
  position: absolute;
  z-index: 0;
  inset: 0 var(--lbm-bazar-side-width, 8%);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  pointer-events: none;
}
/* The garland bridges the upper ledge and this bay's plaque. Its transparent
   artwork overlays their edges without taking up layout space. */
.lbm-bazar-shelf-vine {
  position: absolute;
  z-index: 6;
  top: calc(-52px + var(--lbm-bazar-plaque-shift));
  left: calc(var(--lbm-bazar-side-width, 8%) + 2%);
  right: calc(var(--lbm-bazar-side-width, 8%) + 2%);
  height: clamp(90px, calc(var(--lbm-bazar-shelf-h, 430px) * .27), 150px);
  pointer-events: none;
  background: url('../images/bazar/ivy-plaque-garland-v1.png') center top / contain no-repeat;
}
.lbm-bazar-shelf-vine--positioned {
  z-index: 6;
  top: calc(-52px + var(--lbm-bazar-plaque-shift));
  left: 50%;
  right: auto;
  width: var(--lbm-bazar-vine-width, 55%);
  height: auto;
  transform: translate(calc(-50% + var(--lbm-bazar-vine-x, 0px)), var(--lbm-bazar-vine-y, 0px));
  background: none;
}
.lbm-bazar-shelf-vine--positioned img {
  display: block;
  width: 100%;
  height: auto;
  max-width: none;
}
/* The silver ledge is its own layer. A per-shelf backdrop can cover the sky
   without covering the ledge on which the books rest. */
.lbm-bazar-shelf-rail {
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  background: url('../images/bazar/shelf-bay-clean.webp') center / 135% 100% no-repeat;
  clip-path: inset(80% 0 1%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 80%, #000 84%, #000 95%, transparent 99%);
  mask-image: linear-gradient(to bottom, transparent 80%, #000 84%, #000 95%, transparent 99%);
}
/* The final illustrated ledge sits just above the drawer fronts. Stretch this
   one bay down slightly, keeping its books on the same uninterrupted ledge. */
.lbm-bazar-shelf:has(+ .lbm-bazar-drawers) {
  --lbm-bazar-bottom-rail-drop: clamp(10px, calc(var(--lbm-bazar-shelf-h, 430px) * .028), 18px);
  background-size: 135% calc(100% + var(--lbm-bazar-bottom-rail-drop));
  background-position: center top;
}
.lbm-bazar-shelf:has(+ .lbm-bazar-drawers) .lbm-bazar-shelf-rail {
  bottom: calc(-1 * var(--lbm-bazar-bottom-rail-drop));
  background-position: center top;
  clip-path: inset(80% 0 0);
  -webkit-mask-image: linear-gradient(to bottom, transparent 80%, #000 84%, #000 100%);
  mask-image: linear-gradient(to bottom, transparent 80%, #000 84%, #000 100%);
}
.lbm-bazar-shelf:has(+ .lbm-bazar-drawers) .lbm-bazar-spines {
  transform: translateY(calc(var(--lbm-bazar-bottom-rail-drop) * .83));
}
.lbm-bazar-shelf + .lbm-bazar-shelf { margin-top: -1px; }
.lbm-bazar-shelf::before,
.lbm-bazar-shelf::after {
  content: '';
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  width: var(--lbm-bazar-side-width, 8%);
  pointer-events: none;
  background: linear-gradient(90deg, #03091f, #264984 12%, #d9e8ff 32%, #566fa9 53%, #eff7ff 70%, #152856 91%, #02091d);
  box-shadow: inset 1px 0 #e9f7ffb0, inset -2px 0 #15245d, 0 0 6px #4f85eb;
}
.lbm-bazar-shelf::before { left: 0; }
.lbm-bazar-shelf::after { right: 0; transform: scaleX(-1); }
.lbm-bazar-shelf-side {
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: 0;
  width: var(--lbm-bazar-side-width, 8%);
  overflow: hidden;
  pointer-events: none;
}
.lbm-bazar-shelf-side--left { left: 0; }
.lbm-bazar-shelf-side--right { right: 0; }
.lbm-bazar-shelf-side img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
}
.lbm-bazar-plaque {
  position: relative;
  z-index: 4;
  grid-row: 1;
  justify-self: center;
  align-self: start;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: min(88%, 550px);
  min-height: 85px;
  /* The plaque graphic has transparent padding. Align its visible lower edge
     just above the books, leaving the height of the spine itself unchanged. */
  margin: -24px 0 0;
  transform: translateY(var(--lbm-bazar-plaque-shift));
  padding: 7px 9%;
  border: 0;
  background-image: var(--lbm-bazar-plaque, url('../images/bazar/plaque.webp'));
  background-position: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  color: #0c1a53;
  text-align: center;
  text-shadow: 0 1px 0 #fff;
  line-height: 1.05;
}
.lbm-bazar-plaque small,
.lbm-bazar-plaque strong { display: block; max-width: 100%; overflow-wrap: normal; word-break: normal; hyphens: none; }
.lbm-bazar-plaque small { font-size: clamp(11px, 1.3cqw, 16px); font-weight: 700; text-transform: uppercase; }
.lbm-bazar-plaque strong { font-size: clamp(16px, var(--lbm-bazar-plaque-size, 20px), 30px); font-weight: 700; line-height: 1.03; }
.lbm-bazar-spines {
  position: relative;
  z-index: 1;
  grid-row: 2;
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  align-content: flex-end;
  gap: 7px;
  min-width: 0;
  min-height: 340px;
  /* Place book bottoms just inside the illustrated ledge (about 84% of the bay).
     Subtract the shelf's own bottom padding so this remains aligned as height changes. */
  padding: 0 0 clamp(40px, calc(var(--lbm-bazar-shelf-h, 430px) * .15 - 19px), 90px);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: #a5c9ff #071538;
}
.lbm-bazar-book {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: var(--lbm-bazar-spine-width, 68px);
  height: var(--lbm-bazar-book-height);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: url('../images/bazar/spines-atlas.png') 8% center / 580% 100% no-repeat;
  filter: drop-shadow(3px 4px 4px #000a);
  color: #fff;
  font-size: clamp(11px, calc(var(--lbm-bazar-spine-size, 15px) * var(--lbm-bazar-spine-fit, 1)), 24px);
  line-height: 1.12;
  text-align: center;
  text-decoration: none;
  text-shadow: 0 1px 3px #00123d;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
  transition: transform .2s ease, filter .2s ease;
}
.lbm-bazar-book span {
  position: absolute;
  top: 24%;
  left: 50%;
  transform: translateX(-50%);
  display: block;
  max-height: 52%;
  max-width: 66%;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}
.lbm-bazar-book[data-spine-style='flame'] { background-position: 36% center; }
.lbm-bazar-book[data-spine-style='chef'] { background-position: 64% center; }
.lbm-bazar-book[data-spine-style='fork'] { background-position: 92% center; }
.lbm-bazar-book[data-spine-style='heart'] {
  background-image: url('../images/bazar/spine-heart.png');
  background-size: 350% 100%;
  background-position: 50% center;
}
.lbm-bazar-book:hover,
.lbm-bazar-book:focus-visible { transform: translateY(-5px); filter: brightness(1.2) drop-shadow(3px 4px 4px #000a); outline: 2px solid #effcff; outline-offset: 2px; }
.lbm-bazar-empty { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
/* The drawers overlap the bay only to pull their fronts up to the ledge.
   Their replaceable backdrop starts below the complete silver rail. */
.lbm-bazar-drawers {
  --lbm-bazar-drawer-overlap: calc(var(--lbm-bazar-shelf-h, 430px) * .115);
  --lbm-bazar-bottom-rail-drop: clamp(10px, calc(var(--lbm-bazar-shelf-h, 430px) * .028), 18px);
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(5px, 1cqw, 12px);
  margin-top: calc(-1 * var(--lbm-bazar-drawer-overlap));
  padding: clamp(19px, 2.5cqw, 28px) 10% clamp(7px, 1cqw, 12px);
}
.lbm-bazar-drawers::before {
  content: '';
  position: absolute;
  z-index: 0;
  inset: var(--lbm-bazar-drawer-overlap) 0 0;
  background: var(--lbm-bazar-drawer-backdrop, radial-gradient(ellipse at 50% 20%, #224b8b, #0b204e 58%, #050d25 100%)) center / cover no-repeat;
  /* Only the center crystal crosses into the drawer backing. */
  clip-path: polygon(0 0, 43% 0, 47% calc(var(--lbm-bazar-bottom-rail-drop) + 5px),
    53% calc(var(--lbm-bazar-bottom-rail-drop) + 5px), 57% 0, 100% 0, 100% 100%, 0 100%);
  pointer-events: none;
}
/* Continue the two external uprights down to the feet, without drawing a
   vertical line between the actual drawer fronts. */
.lbm-bazar-drawers::after {
  content: '';
  position: absolute;
  z-index: 1;
  inset: var(--lbm-bazar-drawer-overlap) 0 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, #03091f, #264984 12%, #d9e8ff 32%, #566fa9 53%, #eff7ff 70%, #152856 91%, #02091d) left / var(--lbm-bazar-side-width, 8%) 100% no-repeat,
    linear-gradient(270deg, #03091f, #264984 12%, #d9e8ff 32%, #566fa9 53%, #eff7ff 70%, #152856 91%, #02091d) right / var(--lbm-bazar-side-width, 8%) 100% no-repeat;
}
.lbm-bazar-drawer {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  aspect-ratio: 3.25;
  border: 0;
  background-image: var(--lbm-bazar-drawer, url('../images/bazar/drawer.webp'));
  background-position: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  filter: drop-shadow(0 3px 4px #0009);
  color: #10245a;
  text-decoration: none;
  text-shadow: 0 1px 0 #fff;
}
.lbm-bazar-drawer span {
  position: absolute;
  top: 38%; left: 18%; width: 64%;
  transform: translateY(-50%);
  font-family: var(--lbm-bazar-drawer-font, inherit);
  font-size: clamp(11px, calc(clamp(13px, 2cqw, 27px) * var(--lbm-bazar-drawer-font-scale, 1)), 38px);
  font-weight: 700;
  text-align: center;
  line-height: 1;
}
.lbm-bazar-drawer:hover,
.lbm-bazar-drawer:focus-visible { filter: brightness(1.15); outline: 2px solid #e9fbff; outline-offset: 2px; }
.lbm-bazar-pedestal {
  position: relative;
  z-index: 3;
  width: 104%;
  aspect-ratio: 3.8;
  margin: -1% 0 0 -2%;
  background-image: var(--lbm-bazar-pedestal, url('../images/bazar/pedestal.webp'));
  background-position: center bottom;
  background-size: 100% auto;
  background-repeat: no-repeat;
  pointer-events: none;
  transform: translateY(var(--lbm-bazar-pedestal-y, 0px));
}
.lbm-bazar-tabula-dock {
  position: absolute;
  z-index: 7;
  right: -2%;
  bottom: var(--lbm-bazar-tabula-bottom, 8px);
  width: min(var(--lbm-bazar-tabula-width, 230px), 36%);
  pointer-events: none;
}
.lbm-bazar-shelf > .lbm-bazar-tabula-dock {
  transform: translateX(var(--lbm-bazar-tabula-x, 0px));
}
.lbm-bazar-tabula-dock--left { left: -2%; right: auto; }
.lbm-bazar-shelf:has(.lbm-bazar-tabula-dock) .lbm-bazar-spines { width: 66%; }
.lbm-bazar-shelf:has(.lbm-bazar-tabula-dock--left) .lbm-bazar-spines { justify-self: end; }
.lbm-bazar-cabinet > .lbm-bazar-tabula-dock {
  position: relative;
  right: auto;
  bottom: auto;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  width: 100%;
  min-height: 155px;
  padding: 4px 10%;
  background: url('../images/bazar/shelf-bay-clean.webp') center / 135% 100% no-repeat;
  border-bottom: 4px ridge #d6ebff;
}
.lbm-bazar-cabinet > .lbm-bazar-tabula-dock--left { justify-content: flex-start; }
.lbm-bazar-tabula {
  position: relative;
  flex: none;
  width: 100%;
  container-type: inline-size;
  aspect-ratio: var(--lbm-bazar-tabula-ratio, 1983 / 793);
  background-image: var(--lbm-bazar-tabula, url('../images/bazar/tabula.webp'));
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  color: #10225f;
  text-align: center;
  text-shadow: 0 1px 0 #fff;
  filter: drop-shadow(0 4px 8px #020820);
}
.lbm-bazar-tabula--approved {
  aspect-ratio: 1448 / 1086;
  background-image: url('../images/bazar/tabula-editable.webp');
}
.lbm-bazar-cabinet > .lbm-bazar-tabula-dock .lbm-bazar-tabula { width: min(100%, var(--lbm-bazar-tabula-width, 230px)); }
.lbm-bazar-tabula__cap,
.lbm-bazar-tabula__text { position: absolute; display: flex; align-items: center; justify-content: center; }
.lbm-bazar-tabula__cap { top: 27%; left: 39%; width: 22%; height: 11%; font-size: clamp(10px, 1cqw, 14px); font-weight: bold; letter-spacing: .09em; }
.lbm-bazar-tabula__text { top: 40%; left: 18%; width: 64%; height: 30%; font-size: clamp(12px, 1.2cqw, 16px); font-weight: bold; line-height: 1.04; }
.lbm-bazar-tabula--approved .lbm-bazar-tabula__text,
.lbm-bazar-tabula--portrait .lbm-bazar-tabula__text {
  top: 38%; left: 22%; width: 56%; height: 25%;
  color: #071e64; font-size: clamp(10px, 5.2cqw, 15px);
  line-height: 1.1; text-wrap: balance;
}
/* Keep the desktop composition at one scale on narrow screens. The factor
   uses the configured desktop parchment/scene widths, rather than independent
   minimum heights for shelves and books. */
@media (max-width: 760px) {
  .lbm-bazar-scene { --lbm-bazar-mobile-scale: .45; margin-top: 12px; }
  .lbm-bazar-crown { transform: translateY(calc(var(--lbm-bazar-crown-y, 0px) * var(--lbm-bazar-mobile-scale))); }
  .lbm-bazar-pedestal { transform: translateY(calc(var(--lbm-bazar-pedestal-y, 0px) * var(--lbm-bazar-mobile-scale))); }
  .lbm-bazar-shelf {
    --lbm-bazar-book-base-height: clamp(296px, calc(var(--lbm-bazar-shelf-h, 430px) * .57), 370px);
    --lbm-bazar-book-height: calc(var(--lbm-bazar-book-base-height) * var(--lbm-bazar-mobile-scale));
    --lbm-bazar-plaque-shift: calc((var(--lbm-bazar-shelf-h, 430px) * .85 - var(--lbm-bazar-book-base-height) - 57px) * var(--lbm-bazar-mobile-scale));
    grid-template-rows: minmax(calc(65px * var(--lbm-bazar-mobile-scale)), auto) minmax(calc(335px * var(--lbm-bazar-mobile-scale)), 1fr);
    min-height: calc(var(--lbm-bazar-shelf-h, 430px) * var(--lbm-bazar-mobile-scale));
    padding: calc(3px * var(--lbm-bazar-mobile-scale)) 9% calc(19px * var(--lbm-bazar-mobile-scale));
  }
  .lbm-bazar-spines {
    min-height: calc(340px * var(--lbm-bazar-mobile-scale));
    gap: calc(7px * var(--lbm-bazar-mobile-scale));
    padding-bottom: calc(clamp(40px, calc(var(--lbm-bazar-shelf-h, 430px) * .15 - 19px), 90px) * var(--lbm-bazar-mobile-scale));
  }
  .lbm-bazar-plaque {
    min-height: calc(85px * var(--lbm-bazar-mobile-scale));
    margin-top: calc(-24px * var(--lbm-bazar-mobile-scale));
    padding: calc(7px * var(--lbm-bazar-mobile-scale)) 9%;
  }
  .lbm-bazar-plaque small { font-size: clamp(5px, calc(16px * var(--lbm-bazar-mobile-scale)), 12px); }
  .lbm-bazar-plaque strong { font-size: clamp(6px, calc(var(--lbm-bazar-plaque-size, 20px) * var(--lbm-bazar-mobile-scale)), 21px); text-wrap: balance; }
  .lbm-bazar-book {
    width: calc(var(--lbm-bazar-spine-width, 68px) * var(--lbm-bazar-mobile-scale));
    height: var(--lbm-bazar-book-height);
    font-size: calc(clamp(11px, calc(var(--lbm-bazar-spine-size, 15px) * var(--lbm-bazar-spine-fit, 1)), 24px) * var(--lbm-bazar-mobile-scale));
  }
  .lbm-bazar-shelf-vine {
    top: calc(-52px * var(--lbm-bazar-mobile-scale) + var(--lbm-bazar-plaque-shift));
    height: calc(clamp(90px, calc(var(--lbm-bazar-shelf-h, 430px) * .27), 150px) * var(--lbm-bazar-mobile-scale));
  }
  .lbm-bazar-shelf-vine--positioned {
    height: auto;
    transform: translate(calc(-50% + var(--lbm-bazar-vine-x, 0px) * var(--lbm-bazar-mobile-scale)), calc(var(--lbm-bazar-vine-y, 0px) * var(--lbm-bazar-mobile-scale)));
  }
  .lbm-bazar-shelf:has(+ .lbm-bazar-drawers) {
    --lbm-bazar-bottom-rail-drop: calc(clamp(10px, calc(var(--lbm-bazar-shelf-h, 430px) * .028), 18px) * var(--lbm-bazar-mobile-scale));
  }
  .lbm-bazar-drawers {
    --lbm-bazar-drawer-overlap: calc(var(--lbm-bazar-shelf-h, 430px) * .115 * var(--lbm-bazar-mobile-scale));
    --lbm-bazar-bottom-rail-drop: calc(clamp(10px, calc(var(--lbm-bazar-shelf-h, 430px) * .028), 18px) * var(--lbm-bazar-mobile-scale));
    gap: calc(8px * var(--lbm-bazar-mobile-scale));
    padding: calc(24px * var(--lbm-bazar-mobile-scale)) 10% calc(10px * var(--lbm-bazar-mobile-scale));
  }
  .lbm-bazar-drawer span { font-size: clamp(7px, calc(24px * var(--lbm-bazar-mobile-scale) * var(--lbm-bazar-drawer-font-scale, 1)), 25px); }
  .lbm-bazar-tabula-dock { bottom: calc(var(--lbm-bazar-tabula-bottom, 8px) * var(--lbm-bazar-mobile-scale)); width: min(calc(var(--lbm-bazar-tabula-width, 230px) * var(--lbm-bazar-mobile-scale)), 36%); }
  .lbm-bazar-shelf > .lbm-bazar-tabula-dock { transform: translateX(calc(var(--lbm-bazar-tabula-x, 0px) * var(--lbm-bazar-mobile-scale))); }
  .lbm-bazar-cabinet > .lbm-bazar-tabula-dock { min-height: calc(155px * var(--lbm-bazar-mobile-scale)); padding: calc(4px * var(--lbm-bazar-mobile-scale)) 10%; }
  .lbm-bazar-cabinet > .lbm-bazar-tabula-dock .lbm-bazar-tabula { width: min(100%, calc(var(--lbm-bazar-tabula-width, 230px) * var(--lbm-bazar-mobile-scale))); }
  .lbm-bazar-tabula__cap { font-size: min(14px, 4.3cqw); }
  .lbm-bazar-tabula__text { font-size: min(16px, 5.2cqw); }
  .lbm-bazar-tabula--approved .lbm-bazar-tabula__text,
  .lbm-bazar-tabula--portrait .lbm-bazar-tabula__text { font-size: min(15px, 5.2cqw); }
}
