:root {
  --bg40-gold: #c89a3c;
  --bg40-gold-2: #e0b760;
  --bg40-ink: #0a0a0a;
  --bg40-panel: #111111;
  --bg40-panel-2: #171717;
  --bg40-line: rgba(224, 183, 96, .34);
  --bg40-text: #f5f0e6;
  --bg40-muted: #bdb5a7;
  --bg40-soft: #f6f1e8;
}

#bg40-root,
#bg40-root * {
  box-sizing: border-box;
}

#bg40-root {
  position: relative;
  z-index: 2147483000;
  font-family: Arial, Helvetica, sans-serif;
}

.bg40-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(0, 0, 0, .78);
  backdrop-filter: blur(4px);
}

.bg40-overlay[data-open="true"] {
  display: flex;
}

.bg40-shell {
  width: min(1180px, 94vw);
  max-height: 90vh;
  overflow: hidden;
  border: 1px solid var(--bg40-line);
  border-radius: 18px;
  background:
    radial-gradient(circle at 88% 8%, rgba(200,154,60,.08), transparent 28%),
    linear-gradient(155deg, #151515 0%, #0b0b0b 72%);
  color: var(--bg40-text);
  box-shadow: 0 35px 110px rgba(0,0,0,.66);
}

.bg40-catalog-shell {
  overflow: auto;
  padding: 30px;
}

.bg40-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.bg40-eyebrow {
  margin: 0 0 8px;
  color: var(--bg40-gold-2);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.bg40-head h2,
.bg40-info h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  line-height: 1.04;
}

.bg40-head h2 {
  font-size: clamp(30px, 3vw, 44px);
}

.bg40-count {
  margin: 8px 0 0;
  color: var(--bg40-muted);
  font-size: 14px;
}

.bg40-close {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 50%;
  color: #fff;
  background: rgba(255,255,255,.04);
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
}

.bg40-close:hover,
.bg40-close:focus-visible {
  border-color: var(--bg40-gold);
  outline: none;
}

.bg40-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 320px));
  gap: 22px;
  padding-top: 24px;
}

.bg40-card {
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 16px;
  background: #121212;
  box-shadow: 0 16px 40px rgba(0,0,0,.25);
}

.bg40-card-media {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  padding: 18px;
  background: #f7f4ee;
}

.bg40-card-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.bg40-card-body {
  padding: 18px;
}

.bg40-card-title {
  margin: 0 0 10px;
  color: #fff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  line-height: 1.15;
}

.bg40-card-copy {
  min-height: 58px;
  margin: 0 0 14px;
  color: var(--bg40-muted);
  font-size: 14px;
  line-height: 1.5;
}

.bg40-card-meta {
  margin: 0 0 16px;
  color: #d6c9b4;
  font-size: 12px;
}

.bg40-card-button,
.bg40-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border: 1px solid #d6aa4e;
  border-radius: 10px;
  font-weight: 800;
  letter-spacing: .02em;
  text-decoration: none;
  cursor: pointer;
}

.bg40-card-button {
  width: 100%;
  color: #14100a;
  background: linear-gradient(180deg, #e2bc67, #c39131);
}

.bg40-detail-shell {
  display: grid;
  grid-template-columns: minmax(0, 56%) minmax(0, 44%);
  min-height: 680px;
}

.bg40-gallery {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  padding: 24px;
  background: #f3efe7;
}

.bg40-main-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  border-radius: 14px;
  background: #fff;
}

.bg40-main {
  width: 100%;
  height: 100%;
  min-height: 460px;
  max-height: 570px;
  object-fit: contain;
  user-select: none;
}

.bg40-arrow {
  position: absolute;
  top: 50%;
  z-index: 2;
  width: 46px;
  height: 46px;
  transform: translateY(-50%);
  border: 1px solid rgba(0,0,0,.18);
  border-radius: 50%;
  color: #111;
  background: rgba(255,255,255,.90);
  box-shadow: 0 8px 26px rgba(0,0,0,.12);
  cursor: pointer;
  font-size: 28px;
}

.bg40-arrow-prev { left: 14px; }
.bg40-arrow-next { right: 14px; }

.bg40-counter {
  position: absolute;
  right: 14px;
  bottom: 14px;
  padding: 7px 10px;
  border-radius: 999px;
  color: #fff;
  background: rgba(0,0,0,.72);
  font-size: 12px;
  font-weight: 700;
}

.bg40-thumbs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-top: 14px;
  scrollbar-width: thin;
}

.bg40-thumb {
  flex: 0 0 78px;
  width: 78px;
  height: 78px;
  padding: 4px;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 11px;
  background: #fff;
  cursor: pointer;
}

.bg40-thumb[aria-current="true"] {
  border-color: #b98526;
  box-shadow: 0 0 0 2px rgba(185,133,38,.18);
}

.bg40-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 7px;
}

.bg40-info {
  position: relative;
  overflow-y: auto;
  padding: 34px 34px 112px;
}

.bg40-info .bg40-close {
  position: absolute;
  top: 20px;
  right: 20px;
}

.bg40-info h2 {
  padding-right: 52px;
  color: #fff;
  font-size: clamp(31px, 3.2vw, 45px);
}

.bg40-description {
  margin: 18px 0 22px;
  color: #d6d0c6;
  font-size: 16px;
  line-height: 1.68;
}

.bg40-section-title {
  margin: 24px 0 12px;
  color: #f2d28a;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.bg40-benefits {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.bg40-chip {
  min-height: 62px;
  padding: 13px 14px;
  border: 1px solid rgba(224,183,96,.22);
  border-radius: 12px;
  color: #f4eee3;
  background: rgba(255,255,255,.035);
  font-size: 13px;
  line-height: 1.4;
}

.bg40-usage {
  margin: 0;
  padding: 15px 16px;
  border-left: 3px solid var(--bg40-gold);
  border-radius: 0 10px 10px 0;
  color: #d8d0c3;
  background: rgba(200,154,60,.07);
  font-size: 14px;
  line-height: 1.55;
}

.bg40-merchant {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 14px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid rgba(255,255,255,.08);
  color: #d6d0c6;
  font-size: 13px;
}

.bg40-merchant strong {
  color: #fff;
}

.bg40-price {
  margin: 20px 0 0;
  color: #fff;
  font-size: 27px;
  font-weight: 800;
}

.bg40-price[hidden] {
  display: none;
}

.bg40-action-area {
  position: sticky;
  bottom: -112px;
  margin: 24px -34px -112px;
  padding: 18px 34px 24px;
  background:
    linear-gradient(180deg, rgba(11,11,11,0), #0b0b0b 20%, #0b0b0b 100%);
}

.bg40-cta {
  width: 100%;
  min-height: 56px;
  color: #151008;
  background: linear-gradient(180deg, #e2bc67 0%, #c68f2d 100%);
  box-shadow: 0 10px 28px rgba(200,154,60,.16);
}

.bg40-disclaimer {
  margin: 10px 0 0;
  color: #91897d;
  font-size: 11px;
  line-height: 1.45;
  text-align: center;
}

.bg40-empty {
  padding: 32px 0 6px;
  color: var(--bg40-muted);
}

body.bg40-locked {
  overflow: hidden !important;
}

@media (max-width: 900px) {
  .bg40-overlay {
    align-items: stretch;
    padding: 0;
    background: #0a0a0a;
  }

  .bg40-shell {
    width: 100%;
    max-width: none;
    max-height: none;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .bg40-catalog-shell {
    padding: 22px 18px 40px;
  }

  .bg40-grid {
    grid-template-columns: 1fr;
  }

  .bg40-card {
    display: grid;
    grid-template-columns: 132px minmax(0, 1fr);
  }

  .bg40-card-media {
    aspect-ratio: auto;
    min-height: 178px;
    padding: 10px;
  }

  .bg40-card-body {
    padding: 15px;
  }

  .bg40-card-copy {
    min-height: 0;
  }

  .bg40-detail-shell {
    display: block;
    min-height: 100dvh;
    overflow-y: auto;
  }

  .bg40-gallery {
    display: block;
    padding: 0 0 12px;
  }

  .bg40-main-wrap {
    border-radius: 0;
    aspect-ratio: 1 / 1;
  }

  .bg40-main {
    min-height: 0;
    max-height: none;
    aspect-ratio: 1 / 1;
  }

  .bg40-arrow {
    width: 42px;
    height: 42px;
  }

  .bg40-thumbs {
    padding: 10px 14px 0;
  }

  .bg40-thumb {
    flex-basis: 66px;
    width: 66px;
    height: 66px;
  }

  .bg40-info {
    overflow: visible;
    padding: 24px 18px 132px;
  }

  .bg40-info .bg40-close {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 5;
    background: rgba(0,0,0,.80);
  }

  .bg40-info h2 {
    padding-right: 0;
    font-size: 34px;
  }

  .bg40-benefits {
    grid-template-columns: 1fr 1fr;
  }

  .bg40-action-area {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 4;
    margin: 0;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(224,183,96,.20);
    background: rgba(10,10,10,.96);
    backdrop-filter: blur(10px);
  }

  .bg40-disclaimer {
    display: none;
  }
}

@media (max-width: 520px) {
  .bg40-card {
    grid-template-columns: 112px minmax(0, 1fr);
  }

  .bg40-card-media {
    min-height: 160px;
  }

  .bg40-card-title {
    font-size: 19px;
  }

  .bg40-benefits {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================
   STAGE 40 V3 - VIEWPORT FIT + INTERNAL SCROLL
   Candidate-only override. Approved home source is untouched.
   ========================================================== */

@media (min-width: 901px) {
  .bg40-overlay {
    padding: clamp(8px, 1.6vh, 18px);
  }

  .bg40-shell {
    max-height: calc(100dvh - 16px);
  }

  .bg40-detail-shell {
    height: min(820px, calc(100dvh - 16px));
    min-height: 0;
    max-height: calc(100dvh - 16px);
    overflow: hidden;
  }

  .bg40-gallery {
    min-height: 0;
    overflow: hidden;
    padding: clamp(12px, 1.8vh, 20px);
  }

  .bg40-main-wrap {
    min-height: 0;
  }

  .bg40-main {
    min-height: 0;
    max-height: none;
    height: 100%;
    object-fit: contain;
  }

  .bg40-thumbs {
    flex: 0 0 auto;
    padding-top: 10px;
  }

  .bg40-thumb {
    flex-basis: 68px;
    width: 68px;
    height: 68px;
  }

  .bg40-info {
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: #b98526 #171717;
    padding: clamp(22px, 2.8vh, 30px) 30px 0;
  }

  .bg40-info::-webkit-scrollbar {
    width: 10px;
  }

  .bg40-info::-webkit-scrollbar-track {
    background: #171717;
  }

  .bg40-info::-webkit-scrollbar-thumb {
    border: 2px solid #171717;
    border-radius: 999px;
    background: #b98526;
  }

  .bg40-info .bg40-close {
    position: sticky;
    top: 10px;
    z-index: 10;
    float: right;
    margin-top: -10px;
    margin-right: -8px;
    background: rgba(12, 12, 12, .94);
    backdrop-filter: blur(8px);
  }

  .bg40-info h2 {
    font-size: clamp(29px, 2.65vw, 42px);
  }

  .bg40-description {
    margin: 14px 0 18px;
    font-size: 15px;
    line-height: 1.56;
  }

  .bg40-section-title {
    margin: 18px 0 10px;
  }

  .bg40-chip {
    min-height: 52px;
    padding: 11px 12px;
  }

  .bg40-usage {
    padding: 13px 14px;
  }

  .bg40-merchant {
    margin-top: 16px;
    padding-top: 14px;
  }

  .bg40-action-area {
    position: sticky;
    bottom: 0;
    z-index: 8;
    margin: 20px -30px 0;
    padding: 28px 30px 18px;
    background:
      linear-gradient(
        180deg,
        rgba(11, 11, 11, 0) 0%,
        rgba(11, 11, 11, .96) 22%,
        #0b0b0b 42%,
        #0b0b0b 100%
      );
  }
}

@media (min-width: 901px) and (max-height: 780px) {
  .bg40-overlay {
    padding: 6px;
  }

  .bg40-detail-shell {
    height: calc(100dvh - 12px);
    max-height: calc(100dvh - 12px);
  }

  .bg40-gallery {
    padding: 10px 12px;
  }

  .bg40-thumbs {
    gap: 8px;
    padding-top: 8px;
  }

  .bg40-thumb {
    flex-basis: 56px;
    width: 56px;
    height: 56px;
  }

  .bg40-info {
    padding: 16px 24px 0;
  }

  .bg40-info .bg40-close {
    top: 8px;
    margin-top: -6px;
    margin-right: -4px;
  }

  .bg40-info h2 {
    font-size: 32px;
  }

  .bg40-description {
    margin: 10px 0 13px;
    font-size: 13px;
    line-height: 1.45;
  }

  .bg40-section-title {
    margin: 12px 0 7px;
  }

  .bg40-benefits {
    gap: 7px;
  }

  .bg40-chip {
    min-height: 44px;
    padding: 8px 10px;
    font-size: 12px;
  }

  .bg40-usage {
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.45;
  }

  .bg40-merchant {
    gap: 5px 12px;
    margin-top: 12px;
    padding-top: 11px;
    font-size: 12px;
  }

  .bg40-action-area {
    margin: 12px -24px 0;
    padding: 22px 24px 12px;
  }

  .bg40-cta {
    min-height: 48px;
  }

  .bg40-disclaimer {
    margin-top: 7px;
    font-size: 10px;
  }
}
