/**
 * Works Gallery Slider - Styles
 * 施工事例ギャラリースライダーのスタイル (Auto-play slider with modal)
 */

.works-gallery-slider {
  position: relative;
  width: 100%;
  overflow: visible;
}

/* ===== Slider Container ===== */
.works-gallery-slides {
  display: flex;
  gap: 7px;
  margin-bottom: 30px;
  transition: transform 0.6s ease-in-out;
  touch-action: none; /* Fully prevent browser gesture handling on slider */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none; /* Prevent Safari long-press menu */
  overscroll-behavior: none; /* Prevent Safari elastic scroll interference */
}

/* Desktop: Multiple images side by side */
@media (min-width: 769px) {
  .works-gallery-slide {
    flex-shrink: 0;
    width: 548px;
  }
}

/* Mobile: One image at a time */
@media (max-width: 768px) {
  .works-gallery-slides {
    gap: 7px;
  }

  .works-gallery-slide {
    flex-shrink: 0;
    width: 332px;
  }
}

/* Image - 548:465 aspect ratio */
.works-gallery-image {
  width: 100%;
  height: 100%;
  aspect-ratio: 548 / 465;
  overflow: hidden;
  cursor: pointer;
  transition: opacity 0.3s ease;
}

.works-gallery-image:hover {
  opacity: 0.9;
}

.works-gallery-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Caption */
.works-gallery-caption {
  margin: 16px 0 0 0;
  padding: 0;
  font-size: 14px;
  line-height: 1.8;
  color: #333;
  text-align: left;
  font-family: var(--wp--preset--font-family--ja-serif);
  cursor: pointer;
  transition: opacity 0.3s ease;
}

.works-gallery-caption:hover {
  opacity: 0.7;
}

/* ===== Line Indicators ===== */
.works-gallery-indicators {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

@media (max-width: 768px) {
  .works-gallery-indicators {
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 18px;
  }
}

/* ===== Nav container (indicators + arrows) ===== */
/* ===== Side Arrow Navigation (Desktop only) ===== */
.works-gallery-arrows-sides {
  display: none;
}

@media (min-width: 769px) {
  .works-gallery-arrows-sides {
    display: flex;
    justify-content: space-between;
    position: absolute;
    top: 40%;
    left: 0;
    right: 0;
    z-index: 10;
    pointer-events: none;
  }

  .works-gallery-arrow-side {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    overflow: hidden;
  }

  .works-gallery-arrow-side .c-arrow__arrow path {
    transform: translateX(-1px);
  }

  .works-gallery-arrow-side .c-arrow__arrow {
    opacity: 1;
    transform: translate(0, 0);
    transition: transform 0.4s cubic-bezier(0.76, 0, 0.24, 1), opacity 0.4s cubic-bezier(0.76, 0, 0.24, 1);
  }

  .works-gallery-arrow-side .c-arrow__arrow--hover {
    opacity: 0;
    transform: translate(100%, 0);
  }

  .works-gallery-arrow-side--prev:hover .c-arrow__arrow:not(.c-arrow__arrow--hover) {
    opacity: 0;
    transform: translate(-100%, 0);
  }

  .works-gallery-arrow-side--prev:hover .c-arrow__arrow--hover {
    opacity: 1;
    transform: translate(0, 0);
  }

  .works-gallery-arrow-side--next:hover .c-arrow__arrow:not(.c-arrow__arrow--hover) {
    opacity: 0;
    transform: translate(-100%, 0);
  }

  .works-gallery-arrow-side--next:hover .c-arrow__arrow--hover {
    opacity: 1;
    transform: translate(0, 0);
  }
}

.works-gallery-nav {
  position: relative;
  margin-top: 64px;
}

@media (max-width: 768px) {
  .works-gallery-nav {
    margin-top: 65px;
  }
}

/* ===== Arrow Navigation (Desktop only) ===== */
.works-gallery-arrows {
  display: none;
}

@media (min-width: 769px) {
  .works-gallery-arrows {
    display: flex;
    align-items: center;
    gap: 8px;
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    display: none;
  }

  .works-gallery-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    overflow: hidden;
  }

  .works-gallery-arrow svg {
    width: 32px;
    height: 32px;
    overflow: hidden;
  }

  .works-gallery-arrow .c-arrow__arrow path {
    transform: translateX(-1px);
  }

  /* Arrow animation: first arrow visible, second hidden */
  .works-gallery-arrow .c-arrow__arrow {
    opacity: 1;
    transform: translate(0, 0);
    transition: transform 0.4s cubic-bezier(0.76, 0, 0.24, 1), opacity 0.4s cubic-bezier(0.76, 0, 0.24, 1);
  }

  .works-gallery-arrow .c-arrow__arrow--hover {
    opacity: 0;
    transform: translate(100%, 0);
  }

  /* Prev button: arrows slide right on hover */
  .works-gallery-arrow--prev:hover .c-arrow__arrow:not(.c-arrow__arrow--hover) {
    opacity: 0;
    transform: translate(-100%, 0);
  }

  .works-gallery-arrow--prev:hover .c-arrow__arrow--hover {
    opacity: 1;
    transform: translate(0, 0);
  }

  /* Next button: arrows slide left on hover (mirrored) */
  .works-gallery-arrow--next:hover .c-arrow__arrow:not(.c-arrow__arrow--hover) {
    opacity: 0;
    transform: translate(-100%, 0);
  }

  .works-gallery-arrow--next:hover .c-arrow__arrow--hover {
    opacity: 1;
    transform: translate(0, 0);
  }
}

.works-gallery-line {
  width: 40px;
  height: 5px;
  padding: 0;
  border: none;
  background: #ccc;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.works-gallery-line::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: #333;
  opacity: 0;
  transition: opacity 0.3s ease;
}

@keyframes worksGalleryLineFill {
  from { width: 0; }
  to { width: 100%; }
}

.works-gallery-line:hover {
  background: #999;
}

.works-gallery-line.is-active::before {
  opacity: 1;
  animation: worksGalleryLineFill 3s linear forwards;
}

/* ===== Modal ===== */
.works-gallery-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.works-gallery-modal:not([hidden]) {
  opacity: 1;
  visibility: visible;
  box-sizing: border-box;
}

.works-gallery-modal[hidden] {
  display: none;
}

.works-gallery-modal-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.works-gallery-modal-image {
  max-width: 100%;
  max-height: 90vh;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* Modal Close Button */
.works-gallery-close {
  position: absolute;
  top: 30px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.3s ease;
}

.works-gallery-close:hover {
  background-color: rgba(0, 0, 0, 0.8);
}

/* Modal Navigation Buttons - Desktop */
.works-gallery-prev,
.works-gallery-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.3s ease;
}

.works-gallery-prev:hover,
.works-gallery-next:hover {
  background-color: rgba(0, 0, 0, 0.8);
}

/* Desktop: Botones posicionados absolute cerca de la imagen */
@media (min-width: 769px) {
  .works-gallery-modal-content {
    padding: 0 80px;
  }

  .works-gallery-prev-desktop {
    left: 30px;
  }

  .works-gallery-next-desktop {
    right: 30px;
  }

  /* Ocultar botones mobile en desktop */
  .works-gallery-modal-nav {
    display: none;
  }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  /* Ocultar botones desktop en mobile */
  .works-gallery-prev-desktop,
  .works-gallery-next-desktop {
    display: none;
  }
  .works-gallery-caption {
    font-size: 13px;
  }

  .works-gallery-line {
    min-width: 30px;
    width: 30px;
    height: 2px;
    flex-shrink: 0;
  }

  .works-gallery-close {
    width: 35px;
    height: 35px;
    font-size: 24px;
    top: 10px;
    right: 10px;
  }

  /* Mobile: Modal centrado con box-sizing */
  .works-gallery-modal {
    box-sizing: border-box;
    padding: 20px;
  }

  .works-gallery-modal-content {
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    padding: 0;
  }

  .works-gallery-modal-image {
    max-width: 100%;
    max-height: 70vh;
  }

  /* Mobile: Botones abajo con space-around */
  .works-gallery-modal-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    margin-top: 20px;
  }

  .works-gallery-prev,
  .works-gallery-next {
    position: static;
    transform: none;
    width: 40px;
    height: 40px;
    font-size: 20px;
    margin: 0;
  }
}

/* ===== Editor Placeholder ===== */
.works-gallery-slider-placeholder {
  padding: 40px 20px;
  border: 2px dashed #ccc;
  background: #f9f9f9;
  text-align: center;
  border-radius: 4px;
}
