* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #111;
  color: #eee;
  min-height: 100vh;
}

.hidden { display: none !important; }

.centered {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#pinForm {
  background: #1a1a1a;
  padding: 32px;
  border-radius: 12px;
  min-width: 280px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

#pinForm h1 {
  margin: 0 0 20px;
  text-align: center;
  font-size: 22px;
  font-weight: 500;
}

#pinForm input {
  width: 100%;
  padding: 14px;
  font-size: 24px;
  text-align: center;
  letter-spacing: 8px;
  background: #222;
  color: #eee;
  border: 1px solid #333;
  border-radius: 8px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.15s;
}

#pinForm input:focus { border-color: #4a90e2; }

#pinForm button {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  background: #4a90e2;
  color: white;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

#pinForm button:hover { background: #3a7bc8; }
#pinForm button:active { background: #2a6cb8; }

.error {
  color: #e74c3c;
  min-height: 20px;
  text-align: center;
  margin: 8px 0 0;
  font-size: 14px;
}

header {
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #222;
  background: #181818;
  position: sticky;
  top: 0;
  z-index: 5;
}

header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#count { color: #999; font-size: 14px; }

header button {
  background: transparent;
  color: #aaa;
  border: 1px solid #444;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: color 0.15s, border-color 0.15s;
}

header button:hover { color: #eee; border-color: #666; }

#grid {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}

#grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.15s;
  background: #222;
  display: block;
}

#grid img:hover { transform: scale(1.03); }

.empty {
  text-align: center;
  color: #777;
  padding: 60px 20px;
}

.empty code {
  background: #222;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  touch-action: pan-y;
}

#lightbox img {
  max-width: 95vw;
  max-height: 82vh;
  object-fit: contain;
  user-select: none;
}

#lightbox button {
  position: absolute;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#lightbox button:hover { background: rgba(255, 255, 255, 0.2); }

#lbClose { top: 16px; right: 16px; }
#lbPrev  { left: 16px; top: 50%; transform: translateY(-50%); }
#lbNext  { right: 16px; top: 50%; transform: translateY(-50%); }

.lb-actions {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.5);
  padding: 8px 16px;
  border-radius: 24px;
}

#lbName {
  color: #ccc;
  font-size: 13px;
  max-width: 50vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-actions a {
  padding: 8px 16px;
  background: #4a90e2;
  color: white;
  text-decoration: none;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s;
}

.lb-actions a:hover { background: #3a7bc8; }

@media (max-width: 600px) {
  #grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  #lightbox button { width: 40px; height: 40px; }
  #lbPrev, #lbNext { display: none; }
}
