/* Die-cut gallery — Google-like minimal, image-first */

.gallery-page,
.gallery-page body {
  background: #fff;
}

.gallery-main {
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 16px 64px;
}

@media (min-width: 720px) {
  .gallery-main {
    padding: 0 28px 80px;
  }
}

.gallery-hero {
  padding: 28px 0 8px;
}

.gallery-title {
  margin: 0 0 8px;
  font-family: var(--font-brand);
  font-size: clamp(22px, 3vw, 28px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--ink);
}

.gallery-lead {
  margin: 0;
  max-width: 40em;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

.gallery-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 0 10px;
  margin: 0 -4px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
}

.gallery-toolbar.is-stuck {
  border-bottom-color: var(--line);
}

.gallery-search {
  flex: 1 1 220px;
  min-width: 0;
  max-width: 420px;
}

.gallery-search input {
  width: 100%;
  height: 40px;
  padding: 0 14px 0 40px;
  border: none;
  border-radius: 24px;
  background: #f1f3f4 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='%235f6368'%3E%3Cpath d='M15.5 14h-.79l-.28-.27A6.47 6.47 0 0016 9.5 6.5 6.5 0 109.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E")
    14px 50% no-repeat;
  color: var(--ink);
  font: inherit;
  outline: none;
}

.gallery-search input:focus {
  background-color: #e8eaed;
  box-shadow: inset 0 0 0 1px #dadce0;
}

.gallery-count {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.gallery-page-size select {
  height: 36px;
  padding: 0 28px 0 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.gallery-stage {
  position: relative;
  min-height: 200px;
}

.gallery-loading {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

.gallery-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #dadce0;
  border-top-color: #1a73e8;
  border-radius: 50%;
  animation: gallery-spin 0.7s linear infinite;
}

@keyframes gallery-spin {
  to {
    transform: rotate(360deg);
  }
}

.gallery-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 10px;
  padding: 28px 0 8px;
}

.gallery-pager-btn,
.gallery-pager-num {
  min-width: 36px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.gallery-pager-btn:hover:not(:disabled),
.gallery-pager-num:hover:not(:disabled) {
  background: var(--hover);
}

.gallery-pager-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.gallery-pager-num.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  cursor: default;
}

.gallery-pager-pages {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.gallery-pager-ell {
  color: var(--muted);
  padding: 0 2px;
  font-size: 13px;
}

.gallery-pager-meta {
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

@media (min-width: 720px) {
  .gallery-pager-meta {
    width: auto;
    margin-left: 8px;
  }
}

.gallery-density {
  display: inline-flex;
  margin-left: auto;
  padding: 2px;
  border-radius: 20px;
  background: #f1f3f4;
}

.gallery-density-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 18px;
  cursor: pointer;
}

.gallery-density-btn.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(60, 64, 67, 0.15);
}

.gallery-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 12px 0 16px;
  overflow-x: auto;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.gallery-chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.gallery-chip:hover {
  background: var(--hover);
}

.gallery-chip.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* Image-first grid */
.gallery-grid {
  display: grid;
  gap: 20px 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.gallery-grid[data-density="comfortable"] {
  gap: 28px 16px;
}

@media (min-width: 600px) {
  .gallery-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .gallery-grid[data-density="comfortable"] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .gallery-grid[data-density="compact"] {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 16px 10px;
  }
}

@media (min-width: 1200px) {
  .gallery-grid[data-density="comfortable"] {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .gallery-grid[data-density="compact"] {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (min-width: 1500px) {
  .gallery-grid[data-density="compact"] {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
}

.gallery-item {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: none;
  background: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.gallery-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: #f8f9fa;
}

.gallery-thumb:not(.gallery-thumb--flip) img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #f8f9fa;
  transition: transform 0.25s ease;
}

.gallery-item:not(.has-3d):hover .gallery-thumb img,
.gallery-item:not(.has-3d):focus-visible .gallery-thumb img {
  transform: scale(1.03);
}

.gallery-item:focus-visible {
  outline: none;
}

.gallery-item:focus-visible .gallery-thumb {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink);
}

/* Flip card — 2D front / 3D back */
.gallery-thumb--flip {
  perspective: 900px;
  overflow: visible;
  background: transparent;
}

.gallery-flip {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (hover: hover) and (pointer: fine) {
  .gallery-item.has-3d:hover .gallery-flip,
  .gallery-item.has-3d:focus-within .gallery-flip {
    transform: rotateY(180deg);
  }
}

.gallery-item.has-3d.is-flipped .gallery-flip {
  transform: rotateY(180deg);
}

.gallery-face {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #f8f9fa;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.gallery-face img,
.gallery-face .gallery-thumb-ph {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #f8f9fa;
}

.gallery-face .gallery-thumb-ph {
  position: absolute;
  inset: 0;
}

.gallery-face--back {
  transform: rotateY(180deg);
}

.gallery-badge-3d,
.gallery-badge-des {
  position: absolute;
  top: 8px;
  z-index: 2;
  min-width: 28px;
  padding: 3px 7px;
  border-radius: 4px;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.2;
  user-select: none;
}

.gallery-badge-3d {
  right: 8px;
  background: rgba(32, 33, 36, 0.82);
  pointer-events: auto;
  cursor: pointer;
}

.gallery-badge-des {
  left: 8px;
  background: rgba(60, 64, 67, 0.78);
  pointer-events: none;
}

.gallery-item.has-3d:hover .gallery-badge-3d,
.gallery-item.has-3d.is-flipped .gallery-badge-3d {
  opacity: 0.35;
}

.gallery-thumb-ph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: #9aa0a6;
  background: linear-gradient(160deg, #f8f9fa, #e8eaed);
}

.gallery-thumb-ph-3d {
  background: linear-gradient(160deg, #e8eaed, #dadce0);
}

.gallery-lb-face-toggle {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 8px;
}

.gallery-lb-face-toggle:hover {
  background: var(--hover);
}

.gallery-meta {
  padding: 10px 2px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

.gallery-name {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-desc {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.gallery-grid[data-density="compact"] .gallery-desc {
  display: none;
}

.gallery-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

.gallery-tag {
  font-size: 11px;
  color: #80868b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-edit {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 500;
  color: #1a73e8;
  text-decoration: none;
  padding: 4px 0;
}

.gallery-edit:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.gallery-empty {
  margin: 48px 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Lightbox */
.gallery-lightbox {
  position: relative;
  width: min(960px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100vh - 24px);
  margin: auto;
  padding: 0;
  border: none;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  overflow: hidden;
  box-shadow: 0 8px 28px rgba(60, 64, 67, 0.28);
}

.gallery-lightbox::backdrop {
  background: rgba(32, 33, 36, 0.55);
}

.gallery-lb-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.gallery-lb-close,
.gallery-lb-nav {
  border: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.gallery-lb-close {
  font-size: 13px;
  font-weight: 500;
  padding: 6px 8px;
  border-radius: 4px;
}

.gallery-lb-close:hover {
  background: var(--hover);
}

.gallery-lb-edit {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 14px;
  border-radius: 4px;
  background: #1a73e8;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}

.gallery-lb-edit:hover {
  background: #1765cc;
  text-decoration: none;
}

.gallery-lb-figure {
  margin: 0;
  padding: 16px 16px 20px;
  display: grid;
  gap: 14px;
}

.gallery-lb-figure img {
  width: 100%;
  max-height: min(58vh, 560px);
  object-fit: contain;
  background: #f8f9fa;
  border-radius: 8px;
}

.gallery-lb-figure figcaption h3 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.gallery-lb-figure figcaption p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.gallery-lb-tags {
  margin-top: 8px !important;
  font-size: 12px !important;
  color: #80868b !important;
}

.gallery-lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
  font-size: 28px;
  line-height: 1;
  color: var(--ink);
}

.gallery-lb-nav.prev {
  left: 10px;
}

.gallery-lb-nav.next {
  right: 10px;
}

.gallery-lb-nav:hover {
  background: #f8f9fa;
}

@media (max-width: 640px) {
  .gallery-lb-nav {
    display: none;
  }
}

@media (max-width: 720px) {
  .gallery-main {
    padding: 0 max(12px, env(safe-area-inset-right)) max(48px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .gallery-hero {
    padding: 20px 0 4px;
  }

  .gallery-toolbar {
    top: 0;
    gap: 8px 10px;
    padding: 10px 0 8px;
  }

  .gallery-search {
    flex: 1 1 100%;
    max-width: none;
  }

  .gallery-search input {
    font-size: 16px;
    height: 44px;
  }

  .gallery-count {
    font-size: 12px;
  }

  .gallery-page-size select {
    height: 40px;
  }

  .gallery-lb-figure figcaption {
    padding: 12px 14px max(16px, env(safe-area-inset-bottom));
  }
}
