.media-gallery { min-width: 0; }
.polishing .media-gallery { margin-top: 64px; }
.media-gallery__head { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.media-gallery__head h2 { max-width: 760px; }
.media-gallery__head h3 { margin: 0; }
.media-gallery__controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.media-gallery__controls[hidden], .gallery-button[hidden] { display: none; }
.media-gallery__count { min-width: 56px; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.gallery-button { display: inline-grid; place-items: center; flex-shrink: 0; width: 46px; height: 46px; padding: 0; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: transparent; font: inherit; font-size: 24px; line-height: 1; text-decoration: none; cursor: pointer; transition: color 160ms, border-color 160ms, background 160ms; }
.gallery-button:hover { color: var(--red); border-color: var(--red); background: rgba(222,74,83,.05); }
.gallery-button:disabled { opacity: .3; cursor: default; color: inherit; border-color: var(--line); background: transparent; }
.gallery-button:focus-visible, .media-gallery__open:focus-visible, .media-gallery__track:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }
.media-gallery__track { display: flex; gap: 24px; overflow-x: auto; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; padding: 4px 0 18px; }
.media-gallery__item { flex: 0 0 43%; min-width: 0; margin: 0; scroll-snap-align: start; }
.polishing .media-gallery__item { flex-basis: 30.1%; }
.projects .media-gallery__item { flex-basis: 29%; }
.media-gallery__open { position: relative; display: block; width: 100%; padding: 0; overflow: hidden; border: 0; border-radius: var(--radius); background: var(--paper-2); cursor: zoom-in; color: var(--ink); }
.media-gallery__open img { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; transition: transform 250ms ease; }
.polishing .media-gallery__open img { aspect-ratio: 1; }
.media-gallery__open:hover img { transform: scale(1.025); }
.media-gallery figcaption { padding: 18px 0 0; }
.media-gallery .media-gallery__category { display: block; margin: 0 0 8px; font-size: 13px; line-height: 1.4; font-weight: 400; color: var(--muted); }
.media-gallery figcaption h3 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; margin: 0; font-size: 19px; line-height: 1.35; font-weight: 600; }
.media-gallery figcaption p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; margin: 7px 0 0; min-height: 2.9em; font-size: 15px; line-height: 1.45; color: var(--muted); font-weight: 400; }
.is-gallery-open { overflow: hidden; }
.gallery-viewer { position: fixed; inset: 0; width: 100%; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 22px 32px; border: 0; color: var(--ink); background: #f3f4f1; }
.gallery-viewer[open] { display: grid; grid-template-rows: auto minmax(0,1fr) auto; gap: 20px; }
.gallery-viewer::backdrop { background: rgba(8,23,29,.9); }
.gallery-viewer__bar { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.gallery-viewer__bar > span { font-size: 15px; font-variant-numeric: tabular-nums; }
.gallery-viewer__tools { display: flex; gap: 8px; }
.gallery-viewer__stage { display: grid; grid-template-columns: 46px minmax(0,1fr) 46px; align-items: center; gap: 24px; min-height: 0; }
.gallery-viewer__image-area { height: 100%; min-height: 0; overflow: auto; display: grid; place-items: center; border-radius: 12px; }
.gallery-viewer__image-area img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.gallery-viewer__caption { text-align: center; }
.gallery-viewer__caption > span { color: var(--muted); font-size: 13px; }
.gallery-viewer__caption h2 { margin: 6px 0; font-size: 24px; line-height: 1.3; }
.gallery-viewer__caption p { margin: 0 auto; max-width: 760px; color: var(--muted); font-size: 15px; line-height: 1.45; }
.gallery-viewer__caption .gallery-viewer__error { color: var(--red-dark); }
@media (max-width: 760px) {
  .media-gallery__head { align-items: start; flex-wrap: wrap; gap: 16px; }
  .media-gallery__item, .projects .media-gallery__item { flex-basis: 82%; }
  .polishing .media-gallery__item { flex-basis: 57.4%; }
  .media-gallery__track { gap: 16px; }
  .gallery-viewer { padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom)); }
  .gallery-viewer[open] { gap: 12px; }
  .gallery-viewer__stage { grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; grid-template-rows: minmax(0,1fr) 46px; }
  .gallery-viewer__image-area { grid-column: 1 / -1; grid-row: 1; }
  .gallery-viewer__stage > button { grid-row: 2; }
  .gallery-viewer__stage > button:last-child { justify-self: end; }
  .gallery-viewer__caption h2 { font-size: 20px; }
  .gallery-viewer__tools { gap: 4px; }
  .gallery-viewer__tools .gallery-button { width: 42px; height: 42px; }
}
@media (prefers-reduced-motion: reduce) { .media-gallery__open img { transition: none; } }
