:root {
  --bg-color: #1a1a1a;
  --text-color: #ffffff;
  --nav-opacity: 0.85;
  --nav-hover-opacity: 1;
  --transition-speed: 500ms;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Syne', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  overflow: hidden;
  height: 100vh;
  /* Fallback: iOS Safari 16.4+ supports dvh (dynamic viewport height) */
  height: 100dvh;
  width: 100vw;
}

/* Carousel Container */
.carousel {
  position: relative;
  width: 100%;
  height: 100vh;
  /* Fallback: iOS Safari 16.4+ supports dvh (dynamic viewport height) */
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Prevent bounce effects and overscroll */
  overscroll-behavior: none;
}

/* Image Container */
.image-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Prevent pull-to-refresh and other browser gestures */
  overscroll-behavior: none;
  touch-action: pan-x pan-y pinch-zoom;
}

#currentImage {
  max-width: 100%;
  max-height: 100vh;
  /* Fallback: iOS Safari 16.4+ supports dvh (dynamic viewport height) */
  max-height: 100dvh;
  width: auto;
  height: auto;
  object-fit: contain;
  opacity: 0;
  transition: opacity var(--transition-speed) ease;
  /* Enable pinch-to-zoom on iOS */
  touch-action: pan-x pan-y pinch-zoom;
}

#currentImage.loaded {
  opacity: 1;
}

/* Navigation Buttons */
.nav-btn {
  position: absolute;
  bottom: 25%;
  transform: translateY(50%);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: var(--nav-opacity);
  transition: all 0.3s ease;
  z-index: 10;
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.nav-btn:hover {
  opacity: var(--nav-hover-opacity);
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow:
    0 6px 24px rgba(0, 0, 0, 0.5),
    0 0 20px rgba(255, 255, 255, 0.15),
    0 0 0 1px rgba(255, 255, 255, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transform: translateY(50%) scale(1.05);
}

.nav-btn:active {
  transform: translateY(50%) scale(0.98);
  background: rgba(255, 255, 255, 0.25);
}

.nav-btn svg {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.prev-btn {
  left: 20px;
}

.next-btn {
  right: 20px;
}

/* Counter */
.counter {
  position: absolute;
  bottom: 30px;
  right: 30px;
  font-size: 14px;
  letter-spacing: 2px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  opacity: 0.7;
  pointer-events: none;
}

/* Fade controls after inactivity */
.carousel.idle .nav-btn,
.carousel.idle .counter {
  opacity: 0;
}

/* Loading State */
.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Landscape orientation on mobile devices */
@media (max-width: 1024px) and (orientation: landscape) {
  /* Hide all UI elements in landscape for immersive viewing */
  .carousel.idle .nav-btn,
  .carousel.idle .counter {
    opacity: 0;
  }

  /* Make controls more subtle in landscape */
  .nav-btn {
    opacity: 0.5;
    background: rgba(255, 255, 255, 0.08);
  }

  .counter {
    opacity: 0.5;
  }

  /* Increase touch target size in landscape */
  .nav-btn {
    width: 56px;
    height: 56px;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .nav-btn {
    width: 52px;
    height: 52px;
  }

  .nav-btn svg {
    width: 28px;
    height: 28px;
  }

  .prev-btn {
    left: 10px;
  }

  .next-btn {
    right: 10px;
  }

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

/* ============================
   Admin Styles
   ============================ */

.admin-body {
  overflow-y: auto;
  height: auto;
  min-height: 100vh;
}

/* Login Screen */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
}

.login-screen.hidden {
  display: none;
}

.login-modal {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  padding: 40px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.login-modal h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 30px;
  text-align: center;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 14px;
  margin-bottom: 8px;
  opacity: 0.7;
  letter-spacing: 1px;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: white;
  font-family: inherit;
  font-size: 16px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.form-group input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05);
}

.btn-primary {
  width: 100%;
  padding: 14px 24px;
  background: white;
  color: var(--bg-color);
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.error-message {
  margin-top: 16px;
  text-align: center;
  color: #ff6b6b;
  font-size: 14px;
  min-height: 20px;
}

.login-modal.shake {
  animation: shake 0.5s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

/* Admin Dashboard */
.admin-dashboard {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.admin-dashboard.hidden {
  display: none;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30px 40px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-header h1 {
  font-size: 32px;
  font-weight: 700;
}

.btn-secondary {
  padding: 10px 20px;
  background: transparent;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.3);
}

.admin-content {
  flex: 1;
  padding: 40px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Upload Section */
.upload-section {
  margin-bottom: 40px;
}

.upload-btn {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 28px;
}

.upload-btn svg {
  width: 20px;
  height: 20px;
}

.progress-bar {
  margin-top: 20px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar.hidden {
  display: none;
}

.progress-fill {
  height: 100%;
  background: white;
  width: 0%;
  transition: width 0.3s ease;
}

/* Image Grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.image-card {
  position: relative;
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  overflow: hidden;
  cursor: grab;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.image-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.image-card.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.image-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.3s ease;
  display: flex;
  align-items: flex-end;
  padding: 16px;
}

.image-card:hover .image-card-overlay {
  opacity: 1;
}

.delete-btn {
  background: rgba(255, 82, 82, 0.9);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
  margin-left: auto;
}

.delete-btn:hover {
  transform: scale(1.1);
  background: rgb(255, 82, 82);
}

.delete-btn svg {
  width: 18px;
  height: 18px;
}

.drag-handle {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--bg-color);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-card:hover .drag-handle {
  opacity: 1;
}

.drag-handle svg {
  width: 16px;
  height: 16px;
}

/* Empty State */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 24px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 16px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  color: var(--bg-color);
  padding: 14px 24px;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(20px);
  animation: toast-in 0.3s ease forwards;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.toast-out {
  animation: toast-out 0.3s ease forwards;
}

.toast.success {
  border-left: 3px solid #4ade80;
}

.toast.error {
  border-left: 3px solid #ff6b6b;
}

.toast.info {
  border-left: 3px solid #60a5fa;
}

@keyframes toast-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* Drag and Drop Visual Feedback */
.image-card.drag-over {
  border-color: #60a5fa;
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.3);
}

.image-card.drag-over::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(96, 165, 250, 0.1);
  pointer-events: none;
}

/* Responsive */
@media (max-width: 768px) {
  .admin-header {
    padding: 20px;
  }

  .admin-header h1 {
    font-size: 24px;
  }

  .admin-content {
    padding: 20px;
  }

  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
  }

  .login-modal {
    margin: 20px;
    padding: 30px;
  }
}
