*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0f;
  --surface: #141419;
  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.15);
  --text: #f0f0f5;
  --text-muted: #6b7280;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --radius: 0;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

/* Header Top Row */
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
}

.back-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  transition: all 0.2s;
}

.back-link:hover {
  color: var(--text);
  background: var(--surface);
}

.back-link svg {
  flex-shrink: 0;
}

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

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
  color: white;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  background: linear-gradient(135deg, #fff 0%, rgba(255,255,255,0.7) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* Navigation Links */
.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.2s;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface);
}

.nav-link.highlight {
  color: #a78bfa;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.2);
  animation: subtleGlow 3s ease-in-out infinite;
}

.nav-link.highlight:hover {
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.15);
  border-color: rgba(139, 92, 246, 0.4);
  animation: none;
}

@keyframes subtleGlow {
  0%, 100% {
    border-color: rgba(139, 92, 246, 0.2);
    box-shadow: 0 0 0 rgba(139, 92, 246, 0);
  }
  50% {
    border-color: rgba(139, 92, 246, 0.4);
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.15);
  }
}

.nav-link.x-link {
  padding: 6px 8px;
}

/* Download Button */
.download-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  border-radius: 8px;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.download-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.download-btn svg {
  flex-shrink: 0;
}

/* Header Bottom Row - Search */
.header-bottom {
  display: flex;
  justify-content: center;
  padding: 12px 20px;
}

.search-container {
  position: relative;
  width: 100%;
  max-width: 500px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 2;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-count {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-muted);
  z-index: 2;
}

/* Laser Swipe Animation */
.search-laser {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 10px;
  pointer-events: none;
  overflow: hidden;
}

.search-laser::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(99, 102, 241, 0.3),
    rgba(168, 85, 247, 0.5),
    rgba(99, 102, 241, 0.3),
    transparent
  );
  animation: laserSwipe 2s ease-in-out 0.5s;
}

@keyframes laserSwipe {
  0% {
    left: -50%;
  }
  100% {
    left: 150%;
  }
}

/* Gallery Grid - Uniform 5 columns */
.gallery {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-rows: 200px;
  gap: 1px;
  background: var(--border);
  padding-top: 1px;
  margin-top: 20px;
}

/* Element Card - No gaps, seamless tiles */
.card {
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  position: relative;
}

/* Size variations disabled - uniform grid */
.card.wide,
.card.tall,
.card.large {
  /* All cards same size */
}

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

.card-preview {
  width: 200%;
  height: 200%;
  border: none;
  pointer-events: none;
  display: block;
  overflow: hidden;
  transform: scale(0.5);
  transform-origin: top left;
}

/* Hide scrollbars in iframes */
.card-preview::-webkit-scrollbar {
  display: none;
}

/* Hover overlay with info */
.card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.4) 50%, rgba(0,0,0,0) 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px;
  opacity: 0;
  transition: opacity 0.2s;
}

.card-title {
  font-size: 11px;
  font-weight: 600;
  margin: 0 0 6px 0;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tag {
  font-size: 9px;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
  color: rgba(255, 255, 255, 0.8);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Remove card-info since we show on hover */
.card-info {
  display: none;
}

.card-overlay-text {
  display: none;
}

/* Loading */
.loading {
  display: flex;
  justify-content: center;
  padding: 40px;
  background: var(--bg);
}

.loading .spinner {
  opacity: 0;
  transition: opacity 0.2s;
}

.loading.visible .spinner {
  opacity: 1;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
  overflow-y: auto;
}

.modal-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  transform: scale(0.95);
  transition: transform 0.25s;
}

.modal-overlay.visible .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}

.modal-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.modal-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.modal-btn:hover {
  background: var(--surface);
  border-color: var(--border-hover);
}

.modal-btn svg {
  width: 13px;
  height: 13px;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

.modal-close svg {
  width: 16px;
  height: 16px;
}

.modal-tags {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.modal-tags .tag {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.modal-body {
  flex: 1;
  min-height: 0;
  padding: 0;
  background: var(--bg);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Subtle scrollbar styling */
.modal-body::-webkit-scrollbar {
  width: 6px;
}

.modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Firefox scrollbar */
.modal-body {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.modal-iframe {
  width: 100%;
  height: calc(90vh - 140px);
  min-height: 400px;
  max-height: 800px;
  border: none;
  display: block;
  overflow: hidden;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s ease;
  z-index: 1100;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media (max-width: 1200px) {
  .gallery {
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 180px;
  }
}

@media (max-width: 900px) {
  .gallery {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 160px;
  }

  .card.wide,
  .card.large {
    grid-column: span 2;
  }

  .card.large {
    grid-row: span 2;
  }

  .nav-link span {
    display: none;
  }

  .nav-link.highlight span {
    display: inline;
  }
}

@media (max-width: 768px) {
  .header-top {
    padding: 8px 12px;
    gap: 8px;
  }

  .back-link span {
    display: none;
  }

  .back-link {
    padding: 8px;
  }

  .brand-text {
    display: none;
  }

  .download-btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  .download-btn span {
    display: none;
  }

  .download-btn::after {
    content: 'Download';
    font-size: 11px;
  }

  .nav-links {
    gap: 4px;
  }

  .nav-link {
    padding: 6px 8px;
    font-size: 11px;
  }

  .nav-link.highlight {
    font-size: 0;
  }

  .nav-link.highlight::after {
    content: attr(data-short);
    font-size: 11px;
  }

  .header-bottom {
    padding: 10px 12px;
  }

  .search-container {
    max-width: 100%;
  }

  .search-input {
    padding: 10px 14px 10px 40px;
    font-size: 13px;
  }

  .gallery {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 150px;
    margin-top: 12px;
  }

  .modal-overlay {
    padding: 12px;
    align-items: flex-start;
    padding-top: 20px;
    padding-bottom: 20px;
  }

  .modal {
    max-height: calc(100vh - 40px);
    margin: 0;
    width: 100%;
  }

  .modal-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    flex-shrink: 0;
  }

  .modal-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .modal-tags {
    flex-shrink: 0;
  }

  .modal-iframe {
    height: calc(100vh - 200px);
    min-height: 300px;
  }
}

@media (max-width: 480px) {
  .header-top {
    padding: 6px 10px;
  }

  .brand-icon {
    width: 32px;
    height: 32px;
  }

  .brand-icon svg {
    width: 18px;
    height: 18px;
  }

  .download-btn {
    padding: 6px 8px;
  }

  .download-btn::after {
    display: none;
  }

  .nav-link.highlight {
    padding: 6px;
    font-size: 0;
  }

  .nav-link.highlight::after {
    font-size: 10px;
  }

  .gallery {
    grid-template-columns: 1fr;
    grid-auto-rows: 180px;
  }

  .modal-overlay {
    padding: 8px;
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .modal {
    max-height: calc(100vh - 32px);
  }

  .modal-iframe {
    height: calc(100vh - 180px);
    min-height: 250px;
  }
}

/* Empty state */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
  background: var(--bg);
}

.empty-state h3 {
  font-size: 16px;
  margin: 0 0 8px 0;
  color: var(--text);
}

.empty-state p {
  margin: 0;
  font-size: 13px;
}
