:where(.product-detail) {
  --shop-pd-gap: 24px;
  --shop-pd-thumb-gap: 6px;
}

/* Layout: split on desktop, stack on small screens */
:where(.product-detail .pd-wrap--with-gallery) {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--shop-pd-gap);
}

@media (min-width: 900px) {
  :where(.product-detail .pd-wrap--with-gallery) {
    align-items: start;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  }

  /* allow columns to shrink instead of overflowing the grid */
  :where(.product-detail .pd-wrap--with-gallery .pd-gallery),
  :where(.product-detail .pd-wrap--with-gallery .product-meta) {
    min-width: 0;
  }
}

/* ---- GALLERY ---- */
:where(.product-detail .pd-gallery) {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

:where(.product-detail .pd-mainblock) {
  display: flex;
  flex-direction: column;
}

/* Main stage */
:where(.product-detail .pd-stage),
:where(.product-detail .pd-single-stage) {
  position: relative;
  overflow: hidden;
  display: grid;
  aspect-ratio: 4 / 3;
}

:where(.product-detail .pd-stage figure) {
  margin: 0;
  padding: 0;
  display: none;
  width: 100%;
  height: 100%;
}

:where(.product-detail .pd-stage figure.active) {
  display: block;
  border: 1px solid;
}

:where(.product-detail .pd-stage img),
:where(.product-detail .pd-single-stage img) {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  object-fit: cover;
  object-position: center;
}

/* Caption: present + visually connected directly under image */
:where(.product-detail .pd-caption) {
  margin: 0;
  border-width: 0 1px 1px;
  border-style: solid;
  border-color: currentColor;
  padding: 4px 8px;
  font-size: 0.9rem;
  font-style: italic;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Thumbs row: [ prev ] [thumb grid fills 1fr] [ next ] */
:where(.product-detail .pd-thumbsrow) {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  column-gap: var(--shop-pd-thumb-gap);
}

/* Thumbnails grid: 4 per row */
:where(.product-detail .pd-thumbs) {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--shop-pd-thumb-gap);
}

/* Thumb buttons: square */
.product-detail .pd-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  display: block;
  overflow: hidden;
  border: 0;
  background: transparent;
}

.product-detail .pd-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0.9;
}

.product-detail .pd-thumb[aria-current="true"] {
  box-shadow: 0 0 0 1px currentColor;
}

.product-detail .pd-thumb[aria-current="true"] img {
  opacity: 1;
}

/* Arrow buttons: compact, grid-centered glyphs */
.product-detail .pd-nav {
  appearance: none;
  background: none;
  color: inherit;
  display: grid;
  place-items: center;
  margin: 0;
  width: 40px;
  height: 100%;
  padding: 0;
  line-height: 1;
  border: 1px solid;
  touch-action: manipulation;
}

.product-detail .pd-nav-icon {
  display: block;
  width: 24px;
  height: 24px;
  opacity: 0.8;
  pointer-events: none; /* keep click on button */
}

/* ---- RIGHT ---- */
:where(.product-detail .product-content) {
  margin-top: 16px;
}

:where(.product-detail .product-review-summary) {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.25rem 0;
}

:where(.product-detail .product-review-count) {
  font-size: 1em;
}
/* ---- TABS ---- */
:where(.product-tabs){
  width: 100%;
  display: inline-block;
  text-align: center;
  border-bottom: 1px solid;
  margin-block: 1.2rem;
  padding: 0.5rem;
}
:where(.product-tabs span){
  font-size: 1.3rem;
  font-weight: 500;
  padding: 0 1rem; 
}
:where(.product-tabs span a) {
  text-decoration: none;
}
/* ---- ATTRIBUTES TABLE ---- */
:where(.product-attr-wrap) {
  overflow-x: auto;
}
:where(table.attributes) {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  margin: 0;
}
:where(table.attributes tr:nth-child(even)) {
  background-color: rgba(0, 0, 0, 0.025);
}
:where(table.attributes th),
:where(table.attributes td) {
  padding: 0.75rem;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  vertical-align: top;
}
:where(table.attributes tr:last-child th),
:where*table.attributes tr:last-child td) {
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}


/* Native radios keep keyboard navigation while labels provide tag targets. */
:where(.product-detail .shop-options) {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
:where(.shop-options legend) {
  margin-bottom: 0.5rem;
  padding: 0;
  font-weight: 600;
}
:where(.shop-option-tags) {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
:where(.shop-option-tag) {
  position: relative;
  min-width: 0;
  max-width: 100%;
  cursor: pointer;
}
/* Keep the native control focusable without letting theme input styles leak in. */
.product-detail .shop-option-tag input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
:where(.shop-option-tag span) {
  display: block;
  padding: 0.55rem 0.85rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  overflow-wrap: anywhere;
}
:where(.shop-option-tag input:checked + span) {
  background: var(--shop-option-selected-bg, #222);
  color: var(--shop-option-selected-color, #fff);
  border-color: var(--shop-option-selected-bg, #222);
  font-weight: 600;
}
:where(.shop-option-tag input:focus-visible + span) {
  outline: 2px solid var(--shop-option-focus-color, #222);
  outline-offset: 3px;
}
:where(.shop-option-tag:hover span) {
  box-shadow: inset 0 0 0 1px currentColor;
}

:where(.shop-option-tag small) {
  display: block;
  font-size: 0.8em;
  font-weight: normal;
}

:where(.shop-product-details) { margin-block: 1rem 0; }
:where(.shop-product-details > div:not([hidden])) { display: flex; flex-wrap: wrap; gap: 0.35rem; }
:where(.shop-product-details dt) { font-weight: 600; }
:where(.shop-product-details dd) { margin: 0; }

@media (min-width: 900px) {
  .product-detail--sticky-desktop .pd-wrap--with-gallery .product-meta {
    position: sticky;
    top: var(--shop-purchase-sticky-top, 1rem);
    align-self: start;
    max-height: calc(100dvh - var(--shop-purchase-sticky-top, 1rem) - 1rem);
    overflow-y: auto;
  }
}
.shop-sticky-purchase[hidden] { display: none; }
.shop-sticky-purchase {
  position: fixed;
  inset: auto 0 0;
  z-index: 40;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.65rem max(0.75rem, env(safe-area-inset-right)) calc(0.65rem + env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
  background: var(--shop-purchase-bg, #fff);
  color: var(--shop-purchase-color, #222);
  border-top: 1px solid;
  box-shadow: 0 -4px 20px #0002;
}
.shop-sticky-purchase input { width: 3.5rem; min-width: 0; padding: 0.5rem; }
.shop-sticky-purchase .button { margin: 0; }
.shop-sticky-price { font-weight: 700; }
.shop-sticky-option { max-width: 9rem; overflow-wrap: anywhere; }
.shop-sticky-actions { display: flex; align-items: center; flex: 1 1 14rem; gap: 0.5rem; min-width: min-content; }
.shop-sticky-wishlist { display: inline-flex; align-items: center; flex: 0 0 auto; }
.shop-sticky-notice { flex-basis: 100%; margin: 0; }
body.shop-sticky-purchase-visible { padding-bottom: var(--shop-sticky-bar-height, 6rem); }
.shop-option-sheet {
  inset: auto 0 0;
  width: 100%;
  max-width: 100%;
  max-height: 75dvh;
  margin: 0;
  padding: 1.5rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 1rem 1rem 0 0;
  background: var(--shop-purchase-bg, #fff);
  color: var(--shop-purchase-color, #222);
  overflow-y: auto;
}
.shop-option-sheet::backdrop { background: #0006; }
.shop-option-sheet h2 { margin: 0 2rem 1rem 0; font-size: 1.2rem; }
.shop-option-sheet-close {
  position: absolute;
  top: 0.5rem;
  right: 1rem;
  display: grid;
  place-items: center;
  min-width: 48px;
  min-height: 48px;
  padding: 0.5rem;
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.shop-option-sheet h2 { margin-right: 4rem; min-height: 2rem; }
@media (prefers-reduced-motion: no-preference) {
  .shop-option-sheet[open] { animation: shop-sheet-rise 160ms ease-out; }
  @keyframes shop-sheet-rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
}

/* Let the desktop purchase panel remain alongside the full product details. */
@media (min-width: 900px) {
  .product-detail--sticky-desktop:has(.pd-wrap--with-gallery) {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    column-gap: var(--shop-pd-gap);
    align-items: start;
  }
  .product-detail--sticky-desktop .pd-wrap--with-gallery { display: contents; }
  .product-detail--sticky-desktop .pd-wrap--with-gallery .pd-gallery { grid-column: 1; grid-row: 1; min-width: 0; }
  .product-detail--sticky-desktop .pd-wrap--with-gallery .product-meta { grid-column: 2; grid-row: 1 / span 4; }
  .product-detail--sticky-desktop:has(.pd-wrap--with-gallery) > .product-tabs,
  .product-detail--sticky-desktop:has(.pd-wrap--with-gallery) > .product-content,
  .product-detail--sticky-desktop:has(.pd-wrap--with-gallery) > #tab-attributes { grid-column: 1; min-width: 0; }
}

.shop-option-sheet .shop-options legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.shop-sticky-actions > .shop-sticky-add {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  white-space: nowrap;
}
