:root {
  /* Premium Design System - HSL Colors */
  /* Primary Brand: Deep Blue/Indigo */
  --h-primary: 220;
  --s-primary: 90%;
  --l-primary: 56%;
  --color-primary: hsl(var(--h-primary), var(--s-primary), var(--l-primary));
  --color-primary-hover: hsl(var(--h-primary), var(--s-primary), 48%);

  /* Backgrounds */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fc;
  /* Slightly cool gray */
  --bg-tertiary: #f1f3f9;

  /* Text */
  --text-primary: #111827;
  /* Near black */
  --text-secondary: #4b5563;
  /* Cool gray */
  --text-placeholder: #9ca3af;

  /* Accents & Status */
  --color-success: #10b981;
  --color-danger: #ef4444;
  --color-warning: #f59e0b;

  /* Borders */
  --border-color: #e5e7eb;
  --border-focus: var(--color-primary);

  /* Shadows (Multi-layered for depth) */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Layout */
  --container-max-width: 1200px;
  --header-height: 64px;
  --border-radius-sm: 6px;
  --border-radius-md: 12px;
  --border-radius-lg: 20px;
  --border-radius-xl: 28px;
}

/* Dark Theme */
/* Dark Theme - System Preference (unless overridden) or Manual Override */


* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--bg-secondary);
  /* Use secondary background for page bg */
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.025em;
  /* Tighter headings for modern look */
  color: var(--text-primary);
}

a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

a:hover {
  color: var(--color-primary-hover);
}

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 999;
  background-color: rgba(255, 255, 255, 0.9);
  /* Slightly more opaque */
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  height: var(--header-height);
  display: flex;
  align-items: center;
  transition: background-color 0.3s ease;
}



.header-container {
  width: 100%;
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  letter-spacing: -0.05em;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.user-profile {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

.logout-btn {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  text-decoration: none;
  white-space: nowrap;
}

.theme-toggle-wrapper {
  display: flex;
  background: var(--bg-tertiary);
  padding: 2px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.theme-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 16px;
  font-size: 14px;
  opacity: 0.5;
  transition: all 0.2s;
  /* grayscale filter for inactive? */
  filter: grayscale(100%);
  flex-shrink: 0;
}

.theme-btn:hover {
  opacity: 0.8;
  background-color: rgba(128, 128, 128, 0.1);
}

.theme-btn.active {
  opacity: 1;
  background-color: var(--bg-primary);
  box-shadow: var(--shadow-sm);
  filter: none;
  transform: scale(1.05);
}

/* Layout Container */
.container {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: 20px 24px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 24px;
  border-radius: var(--border-radius-lg);
  /** Pill shape often looks premium */
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background-color: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background-color: var(--color-primary-hover);
  color: white;
  /* Force white text on hover to override a:hover */
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-tertiary);
  border-color: var(--text-secondary);
}

/* Forms */
input[type="text"],
input[type="email"],
input[type="password"],
textarea {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--border-radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  font-family: inherit;
  font-size: 15px;
  transition: all 0.2s ease;
}

textarea {
  resize: none;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(var(--h-primary), var(--s-primary), var(--l-primary), 0.15);
}

/* Upload Card (Glassmorphismish) */
.upload-card {
  background: var(--bg-primary);
  border-radius: var(--border-radius-xl);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 40px;
  border: 1px solid var(--border-color);
  text-align: center;
}

.upload-title h3 {
  font-size: 20px;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.upload-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
}

.file-input-wrapper {
  position: relative;
  overflow: hidden;
  display: flex;
  width: 100%;
  max-width: 400px;
  height: 120px;
  border: 2px dashed var(--border-color);
  border-radius: var(--border-radius-md);
  align-items: center;
  justify-content: center;
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  transition: all 0.2s;
  margin: 0;
  /* Margin handled by parent gap */
}

.file-input-wrapper:hover {
  border-color: var(--color-primary);
  background-color: rgba(var(--h-primary), var(--s-primary), var(--l-primary), 0.02);
  color: var(--color-primary);
}

/* Grid Layout */
.masonry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 24px;
  align-items: start;
}

.grid-item {
  background-color: var(--bg-primary);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  position: relative;
  border: 1px solid var(--border-color);
  /* Ensure images don't overflow */
  display: flex;
  flex-direction: column;
}

.grid-item:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-xl);
}

.media-wrapper {
  position: relative;
  cursor: pointer;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 1 / 1;
  background-color: var(--bg-tertiary);
}

.grid-media {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.media-wrapper:hover .grid-media {
  transform: scale(1.08);
}

/* Badges & Icons */
.favorite-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.3);
  color: white;
  /* Outline color */
  border: none;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  backdrop-filter: blur(4px);
  z-index: 20;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.favorite-btn:hover {
  transform: scale(1.2);
  background: rgba(0, 0, 0, 0.5);
}

.favorite-btn.active {
  color: #ef4444;
  /* Red heart */
  background: rgba(255, 255, 255, 0.9);
}

.video-badge {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 10px;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 700;
  backdrop-filter: blur(4px);
}

.memory-date-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  gap: 4px;
}

.play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 56px;
  height: 56px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  backdrop-filter: blur(8px);
  transition: all 0.3s ease;
  font-size: 20px;
}

/* Processing Overlay */
.processing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  z-index: 5;
  font-size: 14px;
  font-weight: 600;
  gap: 8px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
}

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

/* Delete Button Loading State */
.btn.loading {
  opacity: 0.7;
  pointer-events: none;
  cursor: wait;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn.loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: currentColor;
  animation: spin 1s linear infinite;
}


/* Item Info */
.item-info {
  padding: 12px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  position: relative;
}


.item-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.uploader-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.uploader-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  overflow: hidden;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.uploader-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.meta-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.uploader-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.date-text {
  font-size: 10px;
  color: var(--text-placeholder);
}

.edit-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: background 0.2s;
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-btn:hover {
  background: var(--bg-tertiary);
  color: var(--color-primary);
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.lightbox.active {
  opacity: 1;
  visibility: visible;
}

.lightbox-content {
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-2xl);
  transform: scale(0.95);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.lightbox.active .lightbox-content {
  transform: scale(1);
}

.lightbox-media {
  max-width: 90vw;
  max-height: 85vh;
  display: block;
}

.lightbox-close,
.lightbox-nav {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1010;
  /* Ensure on top of content */
}

.lightbox-close {
  position: absolute;
  top: 24px;
  right: 10px !important;
  /* Offset to avoid volume icon */
  left: auto;
  width: 48px;
  height: 48px;
  font-size: 28px;
}

.lightbox-nav {
  width: 56px;
  height: 56px;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 24px;
}

.lightbox-prev {
  left: 32px;
}

.lightbox-next {
  right: 32px;
}

.lightbox-close:hover,
.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(-50%) scale(1.1);
  /* Nav override */
}

.lightbox-close:hover {
  transform: scale(1.1);
  /* Close override */
}

/* Alerts */
.flashes {
  margin-bottom: 24px;
}

.alert {
  padding: 16px;
  border-radius: var(--border-radius-md);
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 500;
}

.alert-success {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--color-success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.alert-error,
.alert-danger {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--color-danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Infinite Scroll Sentinel */
#scroll-sentinel {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* File Preview */
.file-preview-container {
  display: none;
  margin-top: 10px;
  text-align: center;
  background-color: var(--bg-tertiary);
  padding: 10px;
  border-radius: var(--border-radius-md);
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

/* Animation Utilities */
.fade-in {
  opacity: 0;
  animation: fadeIn 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes fadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }

  from {
    opacity: 0;
    transform: translateY(20px);
  }
}

/* Navigation Bar */
.main-nav {
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  padding: 0;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: var(--header-height);
  z-index: 998;
  transition: all 0.3s ease;
}

.nav-container {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 50px;
}

.nav-list {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 32px;
}

.nav-link {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  position: relative;
  padding: 14px 0;
  display: block;
}

.nav-link:hover {
  color: var(--color-primary);
}

.nav-link.active {
  color: var(--color-primary);
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: var(--color-primary);
  border-radius: 2px;
}

/* Edit Modal Styles */
.edit-modal-content {
  background: var(--bg-primary);
  /* Fallback or variable */
  padding: 24px;
  position: relative;
  max-width: 500px;
  width: 90%;
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}



.edit-preview-img {
  position: absolute;
  top: 24px;
  right: 60px;
  /* Left of close button */
  width: 150px;
  height: 150px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.nav-link:hover {
  color: var(--color-primary);

}

.nav-search .search-input {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  font-size: 13px;
  width: 200px;
  background-color: var(--bg-tertiary);
}

.nav-search .search-input:focus {
  background-color: var(--bg-primary);
  border-color: var(--color-primary);
}

.nav-select {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  font-size: 13px;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
}

.nav-select:focus {
  background-color: var(--bg-primary);
  border-color: var(--color-primary);
}

/* Floating Action Button */
.fab-btn {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background-color: hsla(var(--h-primary), var(--s-primary), var(--l-primary), 0.6);
  backdrop-filter: blur(4px);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  /* Fix vertical alignment */
  padding-bottom: 2px;
  /* Slight visual adjustment for text + */
  font-size: 32px;
  box-shadow: var(--shadow-xl);
  z-index: 100;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  text-decoration: none;
}

.fab-btn:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 20px 25px -5px rgba(var(--h-primary), var(--s-primary), var(--l-primary), 0.4);
  color: white;
  background-color: hsla(var(--h-primary), var(--s-primary), var(--l-primary), 1);
  /* Opaque on hover */
}

.fab-btn:active {
  background-color: hsla(var(--h-primary), var(--s-primary), var(--l-primary), 1);
}

/* Utility: Hide on mobile */
@media (max-width: 768px) {
  .mobile-hidden {
    display: none !important;
  }

  .masonry-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .lightbox-media {
    max-height: 65vh !important;
    max-width: 90vw !important;
  }

  .item-info {
    padding: 6px 8px !important;
  }

  .container {
    padding: 16px 12px;
  }
}

@media (max-width: 600px) {
  .header-container {
    padding: 0 16px;
  }

  .logo {
    font-size: 18px;
  }

  .user-name {
    display: none;
    /* Hide name on mobile to save space */
  }

  .logout-btn {
    padding: 4px 10px;
    font-size: 11px;
  }

  .user-avatar {
    width: 28px;
    height: 28px;
  }
}