* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: #f5f5f5; color: #111; font-family: Arial, Helvetica, sans-serif; }
body { min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 18px 24px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid #ddd;
  backdrop-filter: blur(10px);
}
h1 { margin: 0 0 4px; font-size: 24px; }
#count { margin: 0; color: #666; font-size: 14px; }

#search {
  width: min(360px, 45vw); padding: 12px 14px;
  border: 1px solid #ccc; border-radius: 10px;
  font-size: 15px; outline: none; background: white;
}
#search:focus { border-color: #111; }

main { max-width: 1600px; margin: 0 auto; padding: 22px; }
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}
.card {
  overflow: hidden; background: white; border: 1px solid #e2e2e2;
  border-radius: 14px; box-shadow: 0 2px 10px rgba(0,0,0,.05);
}
.card img {
  display: block; width: 100%; aspect-ratio: 1 / 1;
  object-fit: cover; background: #eee; cursor: zoom-in;
}
.info { padding: 11px; }
.filename {
  display: block; width: 100%; margin-bottom: 9px;
  padding: 8px 9px; border-radius: 8px;
  background: #f3f3f3; font: 13px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer;
}
.copy {
  width: 100%; padding: 9px; border: 0; border-radius: 8px;
  background: #111; color: white; font-weight: 600; cursor: pointer;
}
.copy:hover { opacity: .85; }
.empty { text-align: center; color: #777; padding: 60px 0; }

.viewer {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 70px 70px 110px;
  background: rgba(0,0,0,.92);
}
.viewer[hidden] { display: none; }
#viewerImage { max-width: 100%; max-height: 100%; object-fit: contain; }
.close, .prev, .next {
  position: fixed; border: 0; color: white; background: rgba(255,255,255,.12);
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer; font-size: 26px;
}
.close { top: 18px; right: 20px; }
.prev { left: 18px; top: 50%; }
.next { right: 18px; top: 50%; }
.viewerName {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; max-width: calc(100% - 30px);
  padding: 9px 10px 9px 14px; border-radius: 10px;
  background: rgba(20,20,20,.9); color: white;
}
#viewerFilename {
  max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}
#viewerCopy {
  border: 0; border-radius: 7px; padding: 8px 11px;
  cursor: pointer; font-weight: 600;
}

@media (max-width: 600px) {
  .topbar { align-items: stretch; flex-direction: column; }
  #search { width: 100%; }
  main { padding: 12px; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .info { padding: 8px; }
  .filename { font-size: 11px; }
  .copy { font-size: 12px; }
  .viewer { padding: 60px 35px 100px; }
}
