* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f2f2f2;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  justify-content: center;
  height: 100vh;
  overflow: hidden;
  /* iOS safe area support */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.reader {
  max-width: 1200px;
  width: 100%;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

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

.main img {
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: auto;
  touch-action: pan-y;
  transition: opacity 0.2s ease;
}

.page-indicator {
  position: absolute;
  top: max(20px, env(safe-area-inset-top) + 10px);
  right: max(20px, env(safe-area-inset-right) + 20px);
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: white;
  padding: 8px 12px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 10;
}

.thumbnails {
  height: 100px;
  padding: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  flex-shrink: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.thumbnails::-webkit-scrollbar {
  display: none;
}

.thumbnails img {
  height: 76px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.6;
  transition: all 0.2s ease;
  flex-shrink: 0;
  object-fit: cover;
}

.thumbnails img.active {
  opacity: 1;
  outline: 2px solid #000;
  transform: scale(1.05);
}

.thumbnails img:hover {
  opacity: 0.8;
}

.thumbnails img.active:hover {
  opacity: 1;
}

/* Mobile optimizations */
@media (max-width: 768px) {
  .reader {
    height: 100vh;
    height: 100dvh;
    /* Account for safe areas on mobile */
    min-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  
  .main {
    flex: 1;
    min-height: calc(100vh - 100px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    min-height: calc(100dvh - 100px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  
  .main img {
    cursor: default;
  }
  
  .page-indicator {
    top: max(10px, env(safe-area-inset-top) + 5px);
    right: max(10px, env(safe-area-inset-right) + 10px);
    padding: 6px 10px;
    font-size: 12px;
  }
  
  .thumbnails {
    height: 90px;
    padding: 8px;
    /* Add padding for safe areas */
    padding-bottom: max(8px, env(safe-area-inset-bottom) + 8px);
  }
  
  .thumbnails img {
    height: 70px;
  }
}

/* Loading state */
.main img[src=""] {
  opacity: 0;
}

/* Smooth transitions */
.main.loading img {
  opacity: 0.7;
}