@mixin aspect-ratio($width, $height) {
  position: relative;
    
  &:before {
    display: block;
    content: "";
    width: 100%;
    padding-top: ($height / $width) * 100%;
  }
    
  > img {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
  }
}

// Styling

section {
    background: #F4F4F4;
    padding: 50px 0;
}

.container {
    max-width: 1044px;
    margin: 0 auto;
    padding: 0 20px;
}

.carousel {
    display: block;
    text-align: left;
    position: relative;
    margin-bottom: 22px;
    
    > input {
        clip: rect(1px, 1px, 1px, 1px);
        clip-path: inset(50%);
        height: 1px;
        width: 1px;
        margin: -1px;
        overflow: hidden;
        padding: 0;
        position: absolute;
        
        &:nth-of-type(6):checked ~ .carousel__slides .carousel__slide:first-of-type { margin-left: -500%; }
        &:nth-of-type(5):checked ~ .carousel__slides .carousel__slide:first-of-type { margin-left: -400%; }
        &:nth-of-type(4):checked ~ .carousel__slides .carousel__slide:first-of-type { margin-left: -300%; }
        &:nth-of-type(3):checked ~ .carousel__slides .carousel__slide:first-of-type { margin-left: -200%; }
        &:nth-of-type(2):checked ~ .carousel__slides .carousel__slide:first-of-type { margin-left: -100%; }
        &:nth-of-type(1):checked ~ .carousel__slides .carousel__slide:first-of-type { margin-left: 0%; }
        
        &:nth-of-type(1):checked ~ .carousel__thumbnails li:nth-of-type(1) { box-shadow: 0px 0px 0px 5px rgba(0,0,255,0.5); }
        &:nth-of-type(2):checked ~ .carousel__thumbnails li:nth-of-type(2) { box-shadow: 0px 0px 0px 5px rgba(0,0,255,0.5); }
        &:nth-of-type(3):checked ~ .carousel__thumbnails li:nth-of-type(3) { box-shadow: 0px 0px 0px 5px rgba(0,0,255,0.5); }
        &:nth-of-type(4):checked ~ .carousel__thumbnails li:nth-of-type(4) { box-shadow: 0px 0px 0px 5px rgba(0,0,255,0.5); }
        &:nth-of-type(5):checked ~ .carousel__thumbnails li:nth-of-type(5) { box-shadow: 0px 0px 0px 5px rgba(0,0,255,0.5); }
        &:nth-of-type(6):checked ~ .carousel__thumbnails li:nth-of-type(6) { box-shadow: 0px 0px 0px 5px rgba(0,0,255,0.5); }
    }
}

.carousel__slides {
    position: relative;
    z-index: 1;
    padding: 0;
    margin: 0;
    overflow: hidden;
    white-space: nowrap;
    box-sizing: border-box;
    display: flex;
}

.carousel__slide {
    position: relative;
    display: block;
    flex: 1 0 100%;
    width: 100%;
    height: 100%;
    overflow: hidden;
    transition: all 300ms ease-out;
    vertical-align: top;
    box-sizing: border-box;
    white-space: normal;
    
    figure {
        display: flex;
        margin: 0;
    }
    
    div {
        @include aspect-ratio(3, 2);
        width: 100%;
    }
    
    img {
        display: block;
        flex: 1 1 auto;
        object-fit: cover;
    }
    
    figcaption {
        align-self: flex-end;
        padding: 20px 20px 0 20px;
        flex: 0 0 auto;
        width: 25%;
        min-width: 150px;
    }
    
    .credit {
        margin-top: 1rem;
        color: rgba(0, 0, 0, 0.5);
        display: block;        
    }
    
    &.scrollable {
        overflow-y: scroll;
    }
}

.carousel__thumbnails {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    
    margin: 0 -10px;
    
    .carousel__slides + & {
        margin-top: 20px;
    }
    
    li {        
        flex: 1 1 auto;
        max-width: calc((100% / 6) - 20px);  
        margin: 0 10px;
        transition: all 300ms ease-in-out;
    }
    
    label {
        display: block;
        @include aspect-ratio(1,1);
        
                  
        &:hover,
        &:focus {
            cursor: pointer;
            
            img {
                box-shadow: 0px 0px 0px 1px rgba(0,0,0,0.25);
                transition: all 300ms ease-in-out;
            }
        }
    }
    
    img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
}

@media (max-width: 575.98px) {
  .carousel__slide h1, 
  .carousel__slide h2 {
    font-size: 1.2rem; /* ปรับขนาดหัวข้อให้พอดีกับจอ */
    line-height: 1.3;
    word-break: break-word;
  }

  .carousel__slide p,
  .carousel__slide li {
    font-size: 0.95rem; /* ลดขนาดเนื้อหาเล็กน้อย */
    line-height: 1.4;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  .carousel__slide .text-start {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
}
.carousel__slide .text-start {
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: break-word;
}
    .carousel__slide .text-start {
      max-width: 100%;
      overflow-wrap: break-word;
      word-break: break-word;
      padding-left: 0.5rem;
      padding-right: 0.5rem;
    }

    .carousel__slide ul {
      word-break: break-word;
      padding-left: 1.2rem;
    }

    @media (max-width: 768px) {
      h1, h2 {
        font-size: 1.3rem;
      }
      .carousel__slide p {
        font-size: 0.95rem;
      }
    }
/* ปรับให้ข้อความสามารถตัดบรรทัดได้ในทุกจุด */
.carousel__slide p,
.carousel__slide ul,
.carousel__slide li,
.carousel__slide h1,
.carousel__slide h2,
.carousel__slide strong {
  white-space: normal !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
}

/* ปรับขนาดหัวข้อและระยะห่างในมือถือ */
@media (max-width: 767.98px) {
  .carousel__slide h1,
  .carousel__slide h2 {
    font-size: 1.1rem;
    line-height: 1.4;
  }

  .carousel__slide p,
  .carousel__slide li {
    font-size: 0.95rem;
    line-height: 1.5;
  }

  .carousel__slide .text-start {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .carousel__slide ul {
    padding-left: 1rem;
  }
}

@media (max-width: 768px) {
  .carousel__slide .text-center {
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .carousel__slide img.certificate-img {
    margin-left: auto;
    margin-right: auto;
    display: block;
    max-width: 100%;
    height: auto;
  }
}
@media (max-width: 768px) {
  .carousel__slide .col-md-5.text-center {
    display: flex;
    justify-content: center;
  }

  .carousel__slide .certificate-img {
    display: block;
    margin-left: auto;
    margin-right: auto;
    max-width: 100%;
    height: auto;
  }
}
@media (max-width: 768px) {
  .carousel__slide .row > div.col-md-5 {
    display: flex !important;
    justify-content: center;
  }

  .carousel__slide .certificate-img {
    display: block;
    margin: 0 auto;
    max-width: 90%;
    height: auto !important;
    object-fit: contain;
  }

  /* ปิดการจัดแนวแบบ d-flex ที่ใช้กับข้อความในมือถือ */
  .carousel__slide .col-md-6.d-flex {
    display: block !important;
  }
}
@media (max-width: 768px) {
  .carousel__slide .certificate-img {
    width: 100%;
    max-width: 100%;
    height: auto;
    padding-left: 0;
    padding-right: 0;
    margin-left: auto;
    margin-right: auto;
    display: block;
  }

  .carousel__slide .text-center {
    padding-left: 0;
    padding-right: 0;
  }

  .carousel__slide .col-md-5 {
    padding-left: 0;
    padding-right: 0;
  }
}
@media (max-width: 768px) {
  .certificate-img {
    display: block;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    max-width: 320px;
    height: auto;
  }
}
/* สำหรับมือถือ (ภาพชิดซ้าย-ขวา) */
@media (max-width: 768px) {
  .cert-full {
    width: 90%;
    height: auto;
    display: block;
    margin: 0 auto;
  }

  .carousel__slide .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* สำหรับ desktop (ภาพอยู่ใน column ปกติ) */
@media (min-width: 769px) {
  .cert-full {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
  }
}
.carousel__slide .text-start {
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: break-word;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.carousel__slide ul {
  word-break: break-word;
  padding-left: 1.2rem;
}

@media (max-width: 768px) {
  h1, h2 {
    font-size: 1.3rem;
  }

  .carousel__slide p {
    font-size: 0.95rem;
  }

  .certificate-img {
    width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
  }
}

@media (min-width: 769px) {
  .certificate-img {
    width: auto;
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
  }
}
@media (max-width: 576px) {
  .carousel__slide h1 {
    margin-top: 1rem;
  }
}
@media (max-width: 767.98px) {
  .carousel__thumbnails {
    justify-content: center !important;
    text-align: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }

  .carousel__thumbnails li {
    flex: 0 0 auto;
  }
}
.carousel__thumbnails {
  justify-content: center !important;
  display: flex !important;
}
