/* ============================================
   GLOBAL STYLES & RESETS
   ============================================ */
* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  padding: 0;
  background: #0a0a0a;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

/* ============================================
   HEADER
   ============================================ */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(to bottom, rgba(10, 10, 10, 0.95), rgba(10, 10, 10, 0.85));
  backdrop-filter: blur(10px);
  padding: max(16px, env(safe-area-inset-top)) 16px 12px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.album-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.album-subtitle {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.6);
  font-weight: 400;
}

/* ============================================
   GALLERY GRID
   ============================================ */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 3px;
  overflow-y: auto;
  overflow-x: hidden;
  height: calc(100vh - 130px);
  padding-bottom: env(safe-area-inset-bottom);
}

@media (min-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1024px) {
  .gallery-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ============================================
   GALLERY ITEMS (THUMBNAILS)
   ============================================ */
.gallery-item {
  position: relative;
  aspect-ratio: 1;
  background: #1a1a1a;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.gallery-item:active {
  transform: scale(0.98);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.gallery-item.loading-thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0) 100%);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.video-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 600;
}

/* ============================================
   LOADING STATE
   ============================================ */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: #0a0a0a;
  color: rgba(255, 255, 255, 0.7);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

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

/* ============================================
   ERROR STATE
   ============================================ */
.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: #0a0a0a;
  padding: 24px;
  text-align: center;
  color: #ff6b6b;
}

.error p {
  margin-bottom: 20px;
  font-size: 1rem;
}

.retry-btn {
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.retry-btn:active {
  background: rgba(255, 255, 255, 0.25);
}

/* ============================================
   FULLSCREEN VIEWER MODAL
   ============================================ */
.viewer {
  position: fixed;
  inset: 0;
  background: #0a0a0a;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(10, 10, 10, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.photo-counter {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 500;
}

.close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.close-btn:active {
  color: rgba(255, 255, 255, 0.6);
}

.viewer-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0a0a0a;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ============================================
   IMAGE VIEWER
   ============================================ */
.image-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  touch-action: none;
}

.viewer-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  transition: transform 0.1s ease-out;
}

.zoom-controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  backdrop-filter: blur(10px);
}

.zoom-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.zoom-btn:active {
  color: rgba(255, 255, 255, 0.6);
}

.zoom-level {
  color: white;
  font-size: 0.8rem;
  min-width: 45px;
  text-align: center;
}

/* ============================================
   VIDEO VIEWER
   ============================================ */
.video-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.viewer-video {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: auto;
}

/* ============================================
   VIEWER FOOTER (NAVIGATION)
   ============================================ */
.viewer-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  background: rgba(10, 10, 10, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 2rem;
  width: 48px;
  height: 48px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
}

.nav-btn:active {
  background: rgba(255, 255, 255, 0.2);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ============================================
   MOBILE OPTIMIZATIONS
   ============================================ */
@media (max-height: 600px) and (orientation: landscape) {
  .header {
    padding: max(8px, env(safe-area-inset-top)) 16px 4px;
  }

  .album-title {
    font-size: 1.1rem;
  }

  .album-subtitle {
    font-size: 0.8rem;
  }

  .gallery-grid {
    height: calc(100vh - 90px);
  }

  .viewer-header {
    padding: max(8px, env(safe-area-inset-top)) 16px 4px;
  }

  .viewer-footer {
    padding: 4px 16px max(8px, env(safe-area-inset-bottom));
  }
}

/* ============================================
   SCROLLBAR STYLING (DESKTOP)
   ============================================ */
.gallery-grid::-webkit-scrollbar {
  width: 6px;
}

.gallery-grid::-webkit-scrollbar-track {
  background: transparent;
}

.gallery-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.gallery-grid::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}
