/* Modern CSS Reset and Variables */
:root {
  --primary-color: #2563eb;
  --secondary-color: #1e40af;
  --background-start: #0f172a;
  --background-end: #1e293b;
  --text-color: #f8fafc;
  --card-bg: rgba(255, 255, 255, 0.05);
  --card-border: rgba(255, 255, 255, 0.1);
  --transition-speed: 0.2s;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: linear-gradient(135deg, var(--background-start), var(--background-end));
  color: var(--text-color);
  min-height: 100vh;
  line-height: 1.6;
  user-select: none;
  /* Prevent text selection during drag */
}

/* Header Styles */
header {
  padding: 2rem;
  text-align: center;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--card-border);
}

h1 {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(to right, #60a5fa, #a855f7);
  -webkit-background-clip: text;
  color: transparent;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: #94a3b8;
  font-size: 1.1rem;
}

/* Main Container */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
  position: relative;
  /* For drag selection context */
}

/* Car Section */
.car-section {
  margin-bottom: 4rem;
  animation: fadeIn 0.6s ease-out;
}

.car-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--card-border);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 1rem;
}

.car-title {
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
}

.car-specs {
  display: flex;
  gap: 1.5rem;
  color: #cbd5e1;
  font-size: 0.95rem;
}

.spec-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card-bg);
  padding: 0.5rem 1rem;
  border-radius: 2rem;
  border: 1px solid var(--card-border);
}

/* Controls */
.controls-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--card-bg);
  border-radius: 0.5rem;
  border: 1px solid var(--card-border);
  align-items: center;
}

.btn {
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

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

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

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}

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

.format-select {
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  background: var(--card-bg);
  color: var(--text-color);
  border: 1px solid var(--card-border);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
}

.format-select:hover {
  border-color: rgba(255, 255, 255, 0.3);
}

.format-select option {
  background: var(--background-end);
}

/* Gallery Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.gallery-item {
  position: relative;
  background: var(--card-bg);
  border-radius: 1rem;
  overflow: hidden;
  border: 1px solid var(--card-border);
  transition: transform var(--transition-speed), box-shadow var(--transition-speed), border-color var(--transition-speed);
  cursor: pointer;
  aspect-ratio: 4/3;
}

.gallery-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
  border-color: var(--primary-color);
}

.gallery-item.selected {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.3);
  transform: translateY(-2px);
}

.gallery-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
  pointer-events: none;
  /* Crucial for drag selection */
}

.gallery-item:hover .gallery-image {
  transform: scale(1.05);
}

.gallery-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent);
  color: white;
  transform: translateY(100%);
  transition: transform var(--transition-speed);
  pointer-events: none;
}

.gallery-item:hover .gallery-caption {
  transform: translateY(0);
}

/* Custom Checkbox Styling */
.selection-overlay {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  width: 24px;
  height: 24px;
  background: rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  opacity: 0;
  /* Hidden by default */
}

.gallery-item:hover .selection-overlay,
.gallery-item.selected .selection-overlay {
  opacity: 1;
}

.gallery-item.selected .selection-overlay {
  background: var(--primary-color);
  border-color: var(--primary-color);
}

.selection-overlay::after {
  content: '✓';
  color: white;
  font-size: 16px;
  font-weight: bold;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.2s ease;
}

.gallery-item.selected .selection-overlay::after {
  opacity: 1;
  transform: scale(1);
}

/* Hidden native checkbox */
.image-checkbox {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Drag Selection Box */
.selection-box {
  position: fixed;
  background: rgba(37, 99, 235, 0.2);
  border: 1px solid var(--primary-color);
  pointer-events: none;
  z-index: 1000;
  display: none;
}

/* Lightbox */
.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.lightbox.active {
  display: flex;
  opacity: 1;
}

.lightbox-content {
  max-width: 90%;
  max-height: 90vh;
  position: relative;
}

.lightbox-image {
  max-width: 100%;
  max-height: 85vh;
  border-radius: 0.5rem;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

.lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  color: white;
  font-size: 2rem;
  cursor: pointer;
  transition: color 0.2s;
}

.lightbox-close:hover {
  color: var(--primary-color);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.1);
  color: white;
  padding: 1rem;
  cursor: pointer;
  border-radius: 50%;
  border: none;
  font-size: 1.5rem;
  transition: background 0.2s;
}

.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.3);
}

.prev {
  left: -60px;
}

.next {
  right: -60px;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

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

/* Responsive Design */
@media (max-width: 768px) {
  .car-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .car-specs {
    flex-wrap: wrap;
  }

  h1 {
    font-size: 2rem;
  }

  .lightbox-content {
    width: 100%;
  }

  .prev {
    left: 10px;
  }

  .next {
    right: 10px;
  }

  .controls-bar {
    flex-direction: column;
    align-items: stretch;
  }
}