.line {
  overflow: hidden;
}

.char {
  transform: translate3d(0, 100%, 0);
}

/* View toggle pill - 完全匹配 home/lookbook 按鈕樣式 */
.view-toggle-pill {
  position: fixed;
  top: 1rem;
  left: 1rem;
  display: flex;
  background: #d1d5db;
  border: 2px solid #000;
  border-radius: 50px;
  padding: 4px;
  cursor: pointer;
  z-index: 10002;
  transition: all 0.3s ease;
  transform: scaleY(0.85);
  width: 100px;
  height: 31px; /* 匹配 home/lookbook 按鈕高度 */
  box-sizing: border-box;
}

.view-toggle-pill:hover {
  filter: brightness(0.95);
}

.view-toggle-pill:active {
  transform: scaleY(0.85) scale(0.95);
}

.toggle-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  width: 50%;
  color: #666;
  transition: all 0.3s ease;
  z-index: 2;
  cursor: pointer;
  user-select: none;
}

.toggle-option svg {
  width: 16px;
  height: 16px;
  transition: all 0.3s ease;
}

.toggle-option:hover svg {
  transform: scale(1.05);
}

.view-toggle-pill:not(.grid-mode) .toggle-option[data-view="draggable"] {
  color: #fff;
}

.view-toggle-pill.grid-mode .toggle-option[data-view="grid"] {
  color: #fff;
}

.toggle-slider {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  background: #000;
  border-radius: 50px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

.view-toggle-pill.grid-mode .toggle-slider {
  transform: translateX(100%);
}

.container {
  position: fixed;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
  background-color: #ffffff;
  overflow: hidden;

  transform-origin: center center;
  will-change: transform;
}

.container::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(255, 255, 255, 0.1);
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease-in-out, visibility 0.4s, backdrop-filter 0.4s;
}

.grid {
  position: absolute;
  width: max-content;
  height: max-content;
  display: flex;
  gap: 3rem;
  will-change: transform;
  transform: translate3d(0, 0, 0);
}

.--is-loaded {
  overflow: hidden;

  .grid {
    transition: transform 0.45s cubic-bezier(0.33, 1, 0.68, 1);
    cursor: grab;
  }
}

/* Grid view mode */
html.--grid-view,
body.--grid-view {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  height: 100% !important;
  position: relative !important;
}

html.--grid-view {
  overflow-y: scroll !important;
}

body.--grid-view main {
  height: auto !important;
  min-height: 100vh !important;
}

body.--grid-view .container {
  position: relative !important;
  width: 100% !important;
  height: auto !important;
  min-height: 100vh !important;
  overflow: visible !important;
  transform: none !important;
}

body.--grid-view .grid {
  position: relative !important;
  width: 100% !important;
  height: auto !important;
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)) !important;
  gap: 2rem !important;
  padding: 4rem 2rem !important;
  transform: none !important;
  cursor: default !important;
}

body.--grid-view .column {
  display: contents !important;
  margin-top: 0 !important;
}

body.--grid-view .product {
  width: 100% !important;
  margin: 0 !important;
}

body.--grid-view .product div {
  width: 100% !important;
}

@media (max-width: 1024px) {
  body.--grid-view .grid {
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)) !important;
    gap: 1.5rem !important;
    padding: 3rem 1.5rem !important;
  }
}

@media (max-width: 768px) {
  body.--grid-view .grid {
    grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)) !important;
    gap: 1rem !important;
    padding: 2rem 1rem !important;
  }
}

@media (max-width: 480px) {
  body.--grid-view .grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem !important;
    padding: 1.5rem 0.75rem !important;
  }

  body.--grid-view .product {
    width: 100% !important;
  }

  body.--grid-view .product div {
    width: 100% !important;
  }
}

.column {
  display: flex;
  flex-direction: column;
  gap: 3rem;
}

.column:nth-child(even) {
  margin-top: 6rem;
}

.product {
  position: relative;
  width: 16rem;
  aspect-ratio: 1 / 1;
  contain: layout style paint; /* 隔離布局計算 */

  div {
    width: 16rem;
    aspect-ratio: 1 / 1;
    will-change: transform, opacity;
    transform: translate3d(0, 0, 0);
  }

  img {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: contain;
    will-change: transform;
    transition: transform 300ms ease-in-out;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
    pointer-events: auto;
    background: linear-gradient(90deg, #f0f0f0 25%, #f8f8f8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
  }

  @keyframes shimmer {
    0% {
      background-position: 200% 0;
    }
    100% {
      background-position: -200% 0;
    }
  }

  /* Lazy loading 圖片 */
  img.lazy-image {
    opacity: 0;
    transform: translateZ(0) scale(0.95);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
  }

  img.loaded {
    opacity: 1;
    transform: translateZ(0) scale(1);
    background: transparent;
  }

  /* 預載圖片淡入動畫 */
  img.preloaded-image {
    background: transparent;
    animation: fadeInImage 0.6s ease-out forwards;
  }

  @keyframes fadeInImage {
    from {
      opacity: 0;
      transform: translateZ(0) scale(0.95);
    }
    to {
      opacity: 1;
      transform: translateZ(0) scale(1);
    }
  }

  /* Grid View 模式確保所有圖片可見 */
  body.--grid-view .product img {
    opacity: 1 !important;
    transform: translateZ(0) scale(1) !important;
    animation: none !important;
  }

  :hover {
    transform: scale(1.05);
  }
}

.product-detail-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.product-detail-content {
  text-align: center;
  max-height: 100%;
  overflow-y: auto;
  width: 100%;
}

.product-detail-content .close-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: #000;
  color: #fff;
  border: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

.product-detail-content .close-btn:hover {
  transform: scale(1.1);
}

.product-detail-content h2 {
  font-size: 1.2rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
  color: #000;
}

.product-detail-content .price {
  font-size: 1.5rem;
  font-weight: bold;
  color: #000;
  margin-bottom: 1rem;
}

.product-detail-content .description {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 1rem;
  line-height: 1.4;
  max-height: 6rem;
  overflow-y: auto;
}

.product-detail-content .add-to-cart {
  background: #000;
  color: #fff;
  border: none;
  padding: 0.75rem 2rem;
  border-radius: 4px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.2s;
}

.product-detail-content .add-to-cart:hover {
  transform: scale(1.05);
}

.product.--loading::after {
  content: 'Loading...';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  color: #666;
  z-index: 5;
}

.product.--expanded {
  z-index: 100;
}

.details {
  position: fixed;
  top: 0;
  right: 0;
  width: 50vw;
  height: 100vh;
  padding: 3vw 4vw;
  background-color: #ffffff;

  transform: translate3d(50vw, 0, 0);
  will-change: transform;
  z-index: 10000;
  pointer-events: none;

  &.--is-showing {
    pointer-events: auto;
  }

  @media (max-width: 600px) {
    width: 90%;
    height: 100vh;
    padding: 8vw 7vw;

    transform: translate3d(90%, 0, 0);
  }
}

.details__title {
  margin-bottom: 1.5vw;
  margin-left: -4vw;
  margin-right: -4vw;
  padding-left: 4vw;
  padding-right: calc(4vw + 3vw + 1vw);
  padding-top: 0.5vw;
  padding-bottom: 0.5vw;
  position: relative;
  display: grid;
  align-items: center;
  min-height: 3vw;

  @media (max-width: 600px) {
    margin-bottom: 3vw;
  }

  p {
    grid-area: 1 / -1;
    overflow: visible;
    font-size: 1.5vw;
    white-space: nowrap;
    line-height: 1.2;

    @media (max-width: 600px) {
      font-size: 1rem;
    }
  }
}

.details__body {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 2vw;
  height: calc(100vh - 1.5vw - 10vw);
}

.details__texts {
  position: relative;
  flex: 2;
  line-height: 1.5;
  overflow-y: auto;
  height: 100%;
  padding-right: 0.5rem;
}

.product-description {
  overflow: visible;
  pointer-events: auto;
  z-index: 1;
  width: 100%;
}

.desc-plain-content {
  font-size: 0.85rem;
  line-height: 1.6;
}

.desc-plain-content p {
  margin: 0.5rem 0;
}

.desc-section {
  margin-bottom: 0.25rem;
  border-bottom: 1px solid #e0e0e0;
  padding-bottom: 0.25rem;
}

.desc-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.desc-section-plain {
  margin-top: 1rem;
  padding-top: 0.5rem;
}

.desc-section-plain p {
  font-size: 0.85rem;
  line-height: 1.6;
  margin: 0;
}

.desc-section-plain strong {
  font-weight: 600;
  color: #333;
}

.desc-title {
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  user-select: none;
  transition: color 0.2s ease;
  position: relative;
  z-index: 10;
  pointer-events: auto;
  background: transparent;
}

.desc-title:hover {
  color: #666;
}

.desc-title:active {
  color: #333;
}

.toggle-icon {
  font-size: 1.2rem;
  font-weight: normal;
  transition: transform 0.2s ease;
  min-width: 20px;
  text-align: center;
  pointer-events: none;
}

.toggle-icon::before {
  content: '+';
}

.desc-section.expanded .toggle-icon::before {
  content: '−';
}

.desc-content {
  padding-left: 0;
  font-size: 0.85rem;
  line-height: 1.6;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
}

.desc-content p {
  margin: 0.5rem 0;
  font-weight: normal;
}

.size-chart-section {
  margin-bottom: 0.25rem;
  border-bottom: none;
}

.size-chart-content {
  padding-top: 0.5rem;
}

.size-chart-box {
  padding: 0.5rem;
  margin: 0.25rem 0;
  background-color: rgba(245, 245, 245, 0.5);
  border-radius: 4px;
}

.size-chart-box p {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.5;
}

.desc-content {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
}

.desc-content p {
  margin: 0.5rem 0;
  font-size: 0.85rem;
  line-height: 1.6;
}

.size-chart-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.7rem;
  table-layout: auto;
}

.size-chart-table th,
.size-chart-table td {
  border: 1px solid #333;
  padding: 0.4rem 0.25rem;
  text-align: center;
  word-break: break-word;
}

.size-chart-table th {
  font-weight: 600;
  color: #333;
  font-size: 0.7rem;
  text-transform: capitalize;
}

.size-chart-table td {
  color: #555;
}

.size-chart-table .size-col {
  font-weight: bold;
  color: #333;
  min-width: 40px;
}


.details__thumb {
  position: relative;
  flex: 3;
  aspect-ratio: 1 / 1;
  z-index: 3;
  will-change: transform;
  flex-shrink: 0;

  @media (max-width: 600px) {
    width: 100%;
  }

  div:not(.gallery-dots):not(.gallery-dot),
  img:not(.gallery-image) {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
}

.image-gallery-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
}

.gallery-image {
  position: absolute !important;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
  background-color: #ffffff;
  opacity: 0;
  transform: scale(1.02);
  transition: opacity 0.4s ease-out, transform 0.4s ease-out;
  pointer-events: none;
}

.gallery-image.active {
  opacity: 1;
  transform: scale(1);
  z-index: 1;
  pointer-events: auto;
}

.gallery-dots {
  position: absolute !important;
  bottom: -1.2rem !important;
  left: 0 !important;
  right: 0 !important;
  transform: none !important;
  display: flex !important;
  gap: 0.4rem !important;
  z-index: 1000 !important;
  pointer-events: auto !important;
  width: 100% !important;
  height: auto !important;
}

.gallery-dot {
  flex: 1 !important;
  height: 0.5rem !important;
  border-radius: 0;
  background-color: #d1d5db;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 0 !important;
}

.gallery-dot:hover {
  background-color: #9ca3af;
}

.gallery-dot.active {
  background-color: #000000;
}

p {
  font-size: 0.85rem;
  margin-bottom: 1vw;
}

.cross {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 2rem;
  height: 2rem;
  transform: scale(0);
  z-index: 10001;
  pointer-events: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: transform;

  &.--is-visible {
    pointer-events: auto;
  }

  svg {
    width: 2rem;
    height: 2rem;
    pointer-events: none;
  }
}

.blocking-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: transparent;
  z-index: 9998;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.4s ease-in-out, visibility 0.4s;
}

.blocking-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto !important;
}

.container.--is-details-showing {
  pointer-events: none !important;
  overflow: hidden !important;
}

.container.--is-details-showing::before {
  opacity: 1 !important;
  visibility: visible !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  pointer-events: auto !important;
  z-index: 9999 !important;
  transition: opacity 0.4s ease-in-out, visibility 0.4s, backdrop-filter 0.4s;
}

.container.--is-details-showing .grid,
.container.--is-details-showing .column,
.container.--is-details-showing .product,
.container.--is-details-showing .product *,
.container.--is-details-showing img {
  pointer-events: none !important;
  cursor: default !important;
}

.--is-details-showing {
  .grid {
    pointer-events: none !important;
  }

  .cross {
    pointer-events: auto !important;
    cursor: pointer !important;
  }
}

.details.--is-showing {
  pointer-events: auto !important;
}

.cross.--is-visible {
  pointer-events: auto !important;
}

.--is-showing {
  opacity: 1;
}

/* ===== Responsive Styles for Mobile ===== */
@media (max-width: 640px) {
  .grid {
    gap: 1.5rem;
  }

  .column {
    gap: 1.5rem;
  }

  .column:nth-child(even) {
    margin-top: 3rem;
  }

  .product {
    width: 12rem;
  }

  .product div {
    width: 12rem;
  }

  .details {
    width: 100vw;
    padding: 2rem 0.75rem;
    transform: translate3d(100vw, 0, 0);
  }

  .details__title {
    margin-left: -0.75rem;
    margin-right: -0.75rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    margin-bottom: 1rem;
  }

  .details__title p {
    font-size: 1.25rem;
  }

  .details__body {
    flex-direction: column;
    height: auto;
    gap: 1.5rem;
  }

  .details__thumb {
    width: 100%;
    max-height: 40vh;
  }

  .details__image {
    max-height: 35vh;
    margin-bottom: 1.5rem;
  }

  .details__texts {
    max-height: 40vh;
    font-size: 0.9rem;
    padding-right: 0;
    width: 100%;
  }

  .details__texts .price {
    font-size: 1.25rem;
  }

  .product-description,
  .desc-section,
  .desc-section-plain {
    width: 100%;
  }

  .desc-title {
    width: 100%;
    padding-right: 0;
  }

  .cross {
    top: 1rem;
    right: 1rem;
    width: 2rem;
    height: 2rem;
  }

  .desc-plain-content {
    font-size: 0.8rem;
  }
}

/* ===== Tablet Styles ===== */
@media (min-width: 641px) and (max-width: 1024px) {
  .grid {
    gap: 2rem;
  }

  .column {
    gap: 2rem;
  }

  .column:nth-child(even) {
    margin-top: 4rem;
  }

  .product {
    width: 14rem;
  }

  .product div {
    width: 14rem;
  }

  .details {
    width: 60vw;
    padding: 2.5vw 3.5vw;
    transform: translate3d(60vw, 0, 0);
  }

  .details__texts {
    max-height: 55vh;
  }
}

/* ===== Loading Indicator ===== */
.product.--is-loading {
  position: relative;
}

.product.--is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2rem;
  height: 2rem;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 100;
}

.product.--is-loading::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  z-index: 99;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

