* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  background: #111;
  color: #eee;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
}

.gallery {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  min-height: 0;
  padding: 8px;
  touch-action: pan-y;
}

.stage {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

#mainImage {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  border-radius: 8px;
}

#mainImage.loaded { opacity: 1; }

.counter {
  position: absolute;
  bottom: 12px;
  right: 16px;
  background: rgba(0,0,0,0.55);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  pointer-events: none;
}

.nav {
  background: rgba(255,255,255,0.08);
  border: none;
  color: #fff;
  font-size: 40px;
  line-height: 1;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
  z-index: 2;
}

.nav:hover { background: rgba(255,255,255,0.2); }
.nav:active { background: rgba(255,255,255,0.35); }

.spinner {
  position: absolute;
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: none;
}
.spinner.active { display: block; }

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

.thumbs {
  height: 90px;
  display: flex;
  gap: 6px;
  padding: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  background: #0a0a0a;
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
}

.thumbs::-webkit-scrollbar { height: 6px; }
.thumbs::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }

.thumb {
  flex: 0 0 auto;
  height: 100%;
  width: 100px;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s, transform 0.2s;
  border: 2px solid transparent;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.thumb.active {
  opacity: 1;
  border-color: #4ea1ff;
  transform: scale(1.05);
}

/* Мобильная адаптация */
@media (max-width: 640px) {
  .nav {
    position: absolute;
    width: 44px;
    height: 44px;
    font-size: 32px;
    background: rgba(0,0,0,0.5);
  }
  .nav.prev { left: 8px; }
  .nav.next { right: 8px; }

  .thumbs { height: 70px; }
  .thumb  { width: 80px; }

  .counter { bottom: 8px; right: 8px; font-size: 12px; }
}