.gallery-grid {
  list-style: none;
  margin: 0.8rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.2rem, 1fr));
  gap: 0.55rem;
}
.gallery-grid li { margin: 0; }
.gallery-grid button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #102028;
  min-height: 0;
}
.gallery-grid img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #102028;
}
.gallery, .viewer {
  position: fixed;
  inset: 0;
  z-index: 36;
  background: #07141c;
  color: #fff;
}
.gallery {
  overflow: auto;
  padding: calc(0.8rem + env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom));
}
.gallery-bar, .viewer-actions, .viewer-confirm {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}
.gallery-bar h2, .viewer h2 { margin: 0; font-size: 1.35rem; font-weight: 500; }
.gallery-bar button, .viewer-actions button, .viewer-confirm button, .crop-rot button {
  min-height: 44px;
  padding: 0 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  font: 600 16px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.viewer {
  z-index: 37;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(15rem, 18rem);
  gap: 1rem;
  align-items: center;
  padding: calc(0.8rem + env(safe-area-inset-top)) 1rem calc(0.8rem + env(safe-area-inset-bottom));
}
.viewer-frame {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
}
.viewer-frame img {
  width: 100%;
  max-height: calc(100vh - 2.4rem);
  object-fit: contain;
  background: #000;
  border-radius: 16px;
}
.viewer-side { display: grid; gap: 0.7rem; align-content: center; }
.viewer-actions, .viewer-confirm { display: grid; }
.viewer-actions .viewer-delete,
.viewer-confirm #viewer-yes {
  background: #c43838;
  border-color: #e07070;
  color: #fff;
}
.viewer-status { min-height: 1.2em; margin: 0; font-size: 16px; color: rgba(255, 255, 255, 0.8); }
.crop-rot {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  width: min(100%, 28rem);
}
.share-modal {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.55);
}
.share-card {
  width: min(28rem, 100%);
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 1rem 1rem 1.1rem;
  border-radius: 18px;
  background: #10151b;
  color: #fff;
  text-align: center;
}
.share-card h2 { margin: 0 0 0.7rem; font-size: 1.4rem; font-weight: 500; }
#share-qr { display: block; margin: 0 auto; background: #fff; border-radius: 12px; }
.share-url { margin: 0.7rem 0 0.4rem; font-size: 16px; line-height: 1.35; word-break: break-all; }
.share-note { margin: 0 0 0.8rem; font-size: 16px; line-height: 1.35; color: rgba(255, 255, 255, 0.78); }
.share-actions { display: flex; gap: 0.45rem; justify-content: center; }
.share-actions button, #share-form .pick {
  min-height: 44px;
  padding: 0 0.9rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: 600 16px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.share-status { min-height: 1.2em; margin: 0.6rem 0 0; font-size: 16px; }
#share-form .field { display: grid; gap: 0.3rem; margin: 0 0 0.8rem; font-size: 16px; text-align: left; }
#share-name {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.28);
  color: inherit;
  font: inherit;
  padding: 0 0.7rem;
}
.viewer-credit { margin: 0; font-size: 16px; color: rgba(255, 255, 255, 0.8); }
#library [data-share] {
  min-height: 44px;
  margin-top: 0.4rem;
  padding: 0 0.9rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: 600 16px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
@media (max-width: 800px) {
  .viewer { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; align-items: stretch; }
  .viewer-frame img { max-height: 52vh; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(8.2rem, 1fr)); }
}
