* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--qa-color-bg);
}

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--qa-color-bg);
  color: var(--qa-color-text-main);
  font-family: var(--qa-font-cn);
  -webkit-font-smoothing: antialiased;
}

button,
kbd {
  font: inherit;
}

button {
  color: inherit;
}

.gallery-shell {
  width: min(100%, 1180px);
  height: 100dvh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--qa-space-24);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--qa-space-24);
}

.gallery-workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: clamp(200px, 20vw, 220px) minmax(0, 1fr);
  grid-template-areas: "rail viewer";
  gap: var(--qa-space-24);
}

.gallery-header {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--qa-space-24);
}

.gallery-brand {
  display: flex;
  align-items: center;
}

.gallery-brand__copy {
  display: grid;
  gap: var(--qa-space-4);
}

.gallery-brand__copy h1 {
  margin: 0;
  font-size: var(--qa-font-heading-1);
  line-height: var(--qa-line-heading-1);
  font-weight: var(--qa-weight-semibold);
}

.gallery-brand__copy small,
.viewer-caption__eyebrow {
  color: var(--qa-color-text-main);
  font-size: var(--qa-font-mini);
  line-height: var(--qa-line-mini);
  font-weight: var(--qa-weight-medium);
}

.gallery-header__hint {
  margin: 0;
  color: var(--qa-color-text-main);
  font-size: var(--qa-font-body-small);
  line-height: var(--qa-line-body-small);
}

.gallery-header__hint kbd {
  min-width: 24px;
  height: 24px;
  margin-left: var(--qa-space-4);
  border: 1px solid var(--qa-color-line);
  border-radius: var(--qa-radius-xs);
  display: inline-grid;
  place-items: center;
  background: var(--qa-color-white);
  color: var(--qa-color-text-main);
  font-family: var(--qa-font-num);
  font-size: var(--qa-font-body-small);
  line-height: var(--qa-line-body-small);
  box-shadow: var(--qa-shadow-card);
}

.gallery-rail {
  grid-area: rail;
  min-height: 0;
  padding: var(--qa-space-18) var(--qa-space-14) var(--qa-space-14);
  border-radius: var(--qa-radius-card);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--qa-space-14);
  overflow: hidden;
  background: var(--qa-color-white);
  box-shadow: var(--qa-shadow-card);
}

.gallery-rail__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--qa-space-12);
}

.gallery-rail__eyebrow {
  display: block;
  margin-bottom: var(--qa-space-4);
  color: var(--qa-color-text-main);
  font-size: var(--qa-font-mini);
  line-height: var(--qa-line-mini);
  font-weight: var(--qa-weight-medium);
}

.gallery-rail__heading h2 {
  margin: 0;
  font-size: var(--qa-font-body-large);
  line-height: var(--qa-line-body-large);
  font-weight: var(--qa-weight-semibold);
}

.gallery-rail__count {
  flex: 0 0 auto;
  padding: var(--qa-space-6) var(--qa-space-10);
  border-radius: var(--qa-radius-pill);
  background: var(--qa-color-bg);
  color: var(--qa-color-text-main);
  font-family: var(--qa-font-num);
  font-size: var(--qa-font-mini);
  line-height: var(--qa-line-mini);
  font-weight: var(--qa-weight-medium);
}

.gallery-rail__hint {
  margin: 0;
  color: var(--qa-color-text-main);
  font-size: var(--qa-font-body-small);
  line-height: var(--qa-line-body-small);
}

.viewer-card {
  grid-area: viewer;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--qa-radius-card);
  background: var(--qa-color-white);
  box-shadow: var(--qa-shadow-float);
}

.viewer-stage {
  height: 100%;
  min-height: 0;
  margin: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.viewer-stage__canvas {
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--qa-color-bg);
  touch-action: pan-y;
  user-select: none;
}

.viewer-stage__canvas::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--qa-color-line);
  pointer-events: none;
}

.viewer-stage__canvas.has-load-error::before {
  content: "图片加载失败，请切换其他图片";
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  color: var(--qa-color-text-sub);
  font-size: var(--qa-font-body-small);
  line-height: var(--qa-line-body-small);
}

.viewer-stage__canvas img {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  object-fit: contain;
  transform: scale(1);
  opacity: 1;
  transition:
    opacity var(--qa-motion-fast) var(--qa-ease-standard),
    transform var(--qa-motion-base) var(--qa-ease-standard);
  -webkit-user-drag: none;
}

.viewer-stage__canvas img.is-switching {
  opacity: 0.2;
  transform: scale(0.99);
}

.viewer-stage__canvas.has-load-error img {
  opacity: 0;
}

.viewer-stage__counter {
  position: absolute;
  top: var(--qa-space-18);
  right: var(--qa-space-18);
  min-width: 70px;
  height: 36px;
  padding: 0 var(--qa-space-14);
  border-radius: var(--qa-radius-pill);
  display: inline-grid;
  place-items: center;
  background: var(--qa-overlay);
  color: var(--qa-color-white);
  font-family: var(--qa-font-num);
  font-size: var(--qa-font-body-small);
  line-height: var(--qa-line-body-small);
  font-weight: var(--qa-weight-medium);
  backdrop-filter: blur(10px);
}

.viewer-caption {
  min-height: 104px;
  padding: var(--qa-space-18) var(--qa-space-20);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--qa-space-24);
  background: var(--qa-color-white);
}

.viewer-caption__copy {
  min-width: 0;
}

.viewer-caption__eyebrow {
  display: block;
  margin-bottom: var(--qa-space-6);
}

.viewer-caption h2 {
  margin: 0;
  font-size: var(--qa-font-heading-2);
  line-height: var(--qa-line-heading-2);
  font-weight: var(--qa-weight-semibold);
}

.viewer-caption p {
  margin: var(--qa-space-6) 0 0;
  color: var(--qa-color-text-main);
  font-size: var(--qa-font-body-small);
  line-height: var(--qa-line-body-small);
}

.viewer-controls {
  display: flex;
  gap: var(--qa-space-10);
}

.icon-button {
  width: 52px;
  height: 52px;
  padding: 0;
  border: 1px solid var(--qa-color-line);
  border-radius: var(--qa-radius-pill);
  display: grid;
  place-items: center;
  background: var(--qa-color-white);
  cursor: pointer;
  transition:
    border-color var(--qa-motion-fast) var(--qa-ease-standard),
    background-color var(--qa-motion-fast) var(--qa-ease-standard),
    transform var(--qa-motion-fast) var(--qa-ease-standard);
}

.icon-button svg {
  width: var(--qa-nav-icon-size);
  height: var(--qa-nav-icon-size);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:hover {
  border-color: var(--qa-color-primary);
  background: var(--qa-color-bg);
}

.icon-button:active {
  transform: scale(0.96);
}

.thumbnail-strip {
  min-height: 0;
  padding: var(--qa-space-2);
  display: flex;
  flex-direction: column;
  gap: var(--qa-space-10);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.thumbnail-strip::-webkit-scrollbar {
  display: none;
}

.thumbnail-button {
  width: 100%;
  min-height: 116px;
  min-width: 0;
  padding: var(--qa-space-6);
  border: 1px solid var(--qa-color-line);
  border-radius: var(--qa-radius-md);
  position: relative;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: var(--qa-space-10);
  background: var(--qa-color-white);
  cursor: pointer;
  box-shadow: var(--qa-shadow-card);
  transition:
    border-color var(--qa-motion-fast) var(--qa-ease-standard),
    transform var(--qa-motion-fast) var(--qa-ease-standard),
    opacity var(--qa-motion-fast) var(--qa-ease-standard);
}

.thumbnail-button:hover {
  transform: translateX(2px);
}

.thumbnail-button[aria-current="true"] {
  border-color: var(--qa-color-primary);
  background: var(--qa-color-bg);
  opacity: 1;
}

.thumbnail-button[aria-current="true"]::after {
  content: "";
  width: var(--qa-space-6);
  height: var(--qa-space-6);
  position: absolute;
  top: var(--qa-space-10);
  right: var(--qa-space-10);
  border-radius: var(--qa-radius-pill);
  background: var(--qa-color-primary);
}

.thumbnail-button img {
  width: 48px;
  height: 104px;
  border-radius: var(--qa-radius-sm);
  display: block;
  object-fit: cover;
  background: var(--qa-color-bg);
  transition: opacity var(--qa-motion-fast) var(--qa-ease-standard);
}

.thumbnail-button:not([aria-current="true"]) img {
  opacity: 0.72;
}

.thumbnail-button:hover img {
  opacity: 1;
}

.thumbnail-button__copy {
  min-width: 0;
  padding: 0 var(--qa-space-4);
  display: grid;
  gap: var(--qa-space-4);
  text-align: left;
}

.thumbnail-button__copy small,
.thumbnail-button__copy strong {
  overflow: hidden;
  color: var(--qa-color-text-main);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumbnail-button__copy small {
  overflow: hidden;
  color: var(--qa-color-text-main);
  font-family: var(--qa-font-num);
  font-size: var(--qa-font-mini);
  line-height: var(--qa-line-mini);
  font-weight: var(--qa-weight-regular);
}

.thumbnail-button__copy strong {
  font-size: var(--qa-font-body-small);
  line-height: var(--qa-line-body-small);
  font-weight: var(--qa-weight-medium);
}

.thumbnail-button[aria-current="true"] .thumbnail-button__copy strong {
  font-weight: var(--qa-weight-semibold);
}

button:focus-visible {
  outline: 2px solid var(--qa-color-text-main);
  outline-offset: var(--qa-space-2);
}

.sr-only {
  width: 1px;
  height: 1px;
  padding: 0;
  position: absolute;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

noscript {
  position: fixed;
  inset: auto var(--qa-space-18) var(--qa-space-18);
  padding: var(--qa-space-12) var(--qa-space-14);
  border-radius: var(--qa-radius-md);
  background: var(--qa-toast-bg);
  color: var(--qa-color-white);
  font-size: var(--qa-font-body-small);
  line-height: var(--qa-line-body-small);
  text-align: center;
}

@media (max-width: 719px) {
  .gallery-shell {
    height: auto;
    padding: var(--qa-space-18);
    gap: var(--qa-space-18);
  }

  .gallery-workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "rail"
      "viewer";
    gap: var(--qa-space-18);
  }

  .gallery-rail {
    padding: 0;
    grid-template-rows: auto auto;
    gap: var(--qa-space-10);
    overflow: visible;
    background: transparent;
    box-shadow: none;
  }

  .gallery-rail__hint {
    display: none;
  }

  .gallery-header__hint {
    display: none;
  }

  .gallery-brand__copy h1 {
    font-size: var(--qa-font-body-large);
    line-height: var(--qa-line-body-large);
  }

  .viewer-stage {
    height: auto;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .viewer-card {
    height: auto;
  }

  .viewer-stage__canvas {
    height: min(53dvh, 520px);
    min-height: 0;
  }

  .viewer-stage__counter {
    top: var(--qa-space-14);
    right: var(--qa-space-14);
  }

  .viewer-caption {
    min-height: 116px;
    padding: var(--qa-space-16);
    gap: var(--qa-space-12);
  }

  .viewer-caption p {
    max-width: 210px;
  }

  .viewer-controls {
    gap: var(--qa-space-8);
  }

  .icon-button svg {
    width: 20px;
    height: 20px;
  }

  .thumbnail-strip {
    margin: 0 calc(var(--qa-space-18) * -1);
    padding: 0 var(--qa-space-18) var(--qa-space-4);
    display: flex;
    flex-direction: row;
    gap: var(--qa-space-10);
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }

  .thumbnail-strip::-webkit-scrollbar {
    display: none;
  }

  .thumbnail-button {
    width: 116px;
    min-height: 0;
    flex: 0 0 116px;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--qa-space-6);
    scroll-snap-align: start;
  }

  .thumbnail-button:hover {
    transform: translateY(-2px);
  }

  .thumbnail-button img {
    width: 100%;
    height: 132px;
    object-position: top;
  }

  .thumbnail-button__copy {
    padding: 0 var(--qa-space-4) var(--qa-space-2);
    gap: var(--qa-space-2);
  }
}

@media (max-width: 399px) {
  .gallery-shell {
    padding-right: var(--qa-space-18);
    padding-left: var(--qa-space-18);
  }

  .viewer-caption {
    align-items: flex-end;
  }

  .viewer-caption p {
    display: none;
  }

  .thumbnail-strip {
    margin-right: calc(var(--qa-space-18) * -1);
    margin-left: calc(var(--qa-space-18) * -1);
    padding-right: var(--qa-space-18);
    padding-left: var(--qa-space-18);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
