.wcpg-wrapper {
  display: grid;
  gap: 12px;
  --thumb-size: 64px;
  --gap: 8px;
  /* Aspect ratio for main media */
  --ratio-w: calc(1 * (var(--wcpg-aspect-ratio, 1/1)));
}

/* Layout variants */
.wcpg--thumbs-bottom {
  grid-template-areas:
    "main"
    "thumbs";
}

.wcpg--thumbs-left {
  grid-template-columns: minmax(56px, 120px) 1fr;
  grid-template-areas: "thumbs main";
  align-items: start;
}

.wcpg--thumbs-right {
  grid-template-columns: 1fr minmax(56px, 120px);
  grid-template-areas: "main thumbs";
  align-items: start;
}

.wcpg-main {
  grid-area: main;
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0;
  aspect-ratio: var(--wcpg-aspect-ratio, 1 / 1);
  background: #f6f7f8;
  border-radius: 8px;
  overflow: hidden;
}

.wcpg-main .wcpg-main-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Thumbnails */
.wcpg-thumbs-container {
  grid-area: thumbs;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}

.wcpg-thumbs {
  display: grid;
  gap: var(--gap);
  flex: 1;
}

.wcpg-scroll-arrow {
  width: 100%;
  height: 32px;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.wcpg-scroll-arrow:hover {
  background: rgba(0, 0, 0, 0.1);
  border-color: rgba(0, 0, 0, 0.2);
}

.wcpg-scroll-arrow:active {
  background: rgba(0, 0, 0, 0.15);
}

.wcpg-scroll-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.wcpg-scroll-arrow svg {
  width: 20px;
  height: 20px;
}

/* Hide horizontal arrows on desktop (only show on mobile) */
.wcpg-scroll-left,
.wcpg-scroll-right {
  display: none;
}

/* Bottom layout: horizontal scroll, shows 5 at a time */
.wcpg--thumbs-bottom .wcpg-thumbs {
  grid-auto-flow: column;
  grid-auto-columns: calc((100% - (var(--gap) * 4)) / 5);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  padding-bottom: 4px;
  /* Hide scrollbar */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.wcpg--thumbs-bottom .wcpg-thumbs::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Edge */
}

/* Left/Right layouts: vertical, shows 5 at a time with scroll */
.wcpg--thumbs-left .wcpg-thumbs,
.wcpg--thumbs-right .wcpg-thumbs {
  grid-auto-flow: row;
  grid-auto-rows: var(--thumb-size);
  grid-template-columns: 1fr;
  overflow-y: auto;
  max-height: calc(var(--thumb-size) * 5 + (var(--gap) * 4));
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  /* Hide scrollbar */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.wcpg--thumbs-left .wcpg-thumbs::-webkit-scrollbar,
.wcpg--thumbs-right .wcpg-thumbs::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Edge */
}

.wcpg-thumb {
  background: transparent;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  line-height: 0;
  scroll-snap-align: start;
  flex-shrink: 0;
}

.wcpg-thumb img {
  width: 100%;
  height: var(--thumb-size);
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.wcpg-thumb.is-active {
  border-color: #1e88e5;
  outline: none;
}

.wcpg-thumb:focus-visible {
  box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.35);
  outline: none;
}

/* Mobile tweaks */
@media (max-width: 768px) {
  .wcpg--thumbs-left,
  .wcpg--thumbs-right {
    grid-template-columns: 1fr;
    grid-template-areas:
      "main"
      "thumbs";
  }

  /* Hide desktop vertical arrows on mobile */
  .wcpg-scroll-up,
  .wcpg-scroll-down {
    display: none !important;
  }

  /* Show mobile horizontal arrows */
  .wcpg-scroll-left,
  .wcpg-scroll-right {
    display: flex !important;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 32px !important;
    height: 48px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.15);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .wcpg-scroll-left {
    left: -4px;
  }

  .wcpg-scroll-right {
    right: -4px;
  }

  .wcpg-thumbs-container {
    position: relative;
    flex-direction: row !important;
  }

  /* Force horizontal layout for ALL thumbnail positions on mobile */
  .wcpg-thumbs,
  .wcpg--thumbs-left .wcpg-thumbs,
  .wcpg--thumbs-right .wcpg-thumbs,
  .wcpg--thumbs-bottom .wcpg-thumbs {
    display: grid !important;
    grid-auto-flow: column !important;
    grid-auto-columns: calc((100% - (var(--gap) * 2)) / 3) !important;
    grid-template-columns: none !important;
    grid-auto-rows: auto !important;
    max-height: none !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding-bottom: 4px;
    scroll-snap-type: x mandatory !important;
    scroll-behavior: smooth;
    /* Hide scrollbar on mobile */
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .wcpg-thumbs::-webkit-scrollbar,
  .wcpg--thumbs-left .wcpg-thumbs::-webkit-scrollbar,
  .wcpg--thumbs-right .wcpg-thumbs::-webkit-scrollbar,
  .wcpg--thumbs-bottom .wcpg-thumbs::-webkit-scrollbar {
    display: none;
  }

  .wcpg-thumb {
    scroll-snap-align: start;
  }
}
