/* ===========================================
   AI With Dance Music - Styles
   Modern, classy, mobile-first design
   =========================================== */

/* CSS Variables for theming */
:root {
  /* Colors */
  --bg-primary: #0a0a0a;
  --bg-secondary: #121212;
  --bg-tertiary: #1a1a1a;
  --bg-elevated: #222;
  --bg-hover: #2a2a2a;
  
  --border-subtle: #1f1f1f;
  --border-default: #2a2a2a;
  --border-strong: #3a3a3a;
  
  --text-primary: #fff;
  --text-secondary: #b0b0b0;
  --text-muted: #707070;
  
  --accent-primary: #6366f1;
  --accent-hover: #818cf8;
  --accent-muted: rgba(99, 102, 241, 0.15);
  
  --danger: #ef4444;
  --danger-hover: #f87171;
  --danger-bg: rgba(239, 68, 68, 0.15);
  
  --success: #10b981;
  --success-hover: #34d399;
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 0.75rem;
  --space-lg: 1rem;
  --space-xl: 1.5rem;
  --space-2xl: 2rem;
  
  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
  --transition-slow: 300ms ease;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);
  
  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  
  /* Grid */
  --grid-gap: 4px;
  --thumb-min-size: 140px;
}

/* Base reset */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===========================================
   Header
   =========================================== */
header {
  display: flex;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  gap: var(--space-md);
  background: linear-gradient(to bottom, var(--bg-secondary), var(--bg-primary));
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  white-space: nowrap;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

header a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

header a:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

/* Controls wrapper */
.controls {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  flex: 1;
  min-width: 0;
}

/* Search input */
.controls input[type="text"] {
  flex: 1;
  min-width: 80px;
  max-width: 280px;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: all var(--transition-fast);
}

.controls input[type="text"]:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.controls .item-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.controls input[type="text"]::placeholder {
  color: var(--text-muted);
}

/* Header shortcut to /generate.html — mobile only (desktop has the nav link).
   Shares .upload-btn's look; shown by the 600px media query below. */
.generate-link {
  display: none;
  text-decoration: none;
  line-height: 1;
}

/* Burger menu */
.burger {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: var(--space-sm);
  line-height: 1;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.burger:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

/* Menu items */
.menu-items {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.menu-items select {
  padding: var(--space-sm) var(--space-md);
  padding-right: var(--space-xl);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23707070' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.menu-items select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

/* Tag filter indicator — one chip per active tag, joined by "+" (AND) */
.tag-filter-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-wrap: wrap;
  font-size: 0.75rem;
  font-weight: 500;
  margin-left: var(--space-sm);
  animation: fadeIn var(--transition-normal);
}

.tag-filter-chip {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  background: var(--accent-primary);
  padding: var(--space-xs) var(--space-sm) var(--space-xs) var(--space-md);
  border-radius: var(--radius-full);
}

.tag-filter-and {
  opacity: 0.6;
}

.tag-filter-chip button {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1rem;
  cursor: pointer;
  padding: 0 var(--space-xs);
  line-height: 1;
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}

.tag-filter-chip button:hover {
  opacity: 1;
}

/* Mobile menu */
@media (max-width: 600px) {
  header {
    padding: var(--space-sm) var(--space-md);
  }

  /* On phones the count is noise and Generate is buried in the burger menu —
     swap one for the other. */
  .controls .item-count {
    display: none;
  }

  .generate-link {
    display: inline-block;
  }

  .burger {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .menu-items {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    padding: var(--space-md);
    flex-direction: column;
    gap: var(--space-sm);
    z-index: 101;
    animation: slideDown var(--transition-normal);
  }
  
  .menu-items.open {
    display: flex;
  }
  
  .menu-items select {
    width: 100%;
    padding: var(--space-md);
    font-size: 0.9rem;
  }
  
  .menu-items a {
    width: 100%;
    text-align: center;
    padding: var(--space-md);
  }
}

/* ===========================================
   Grid
   =========================================== */
#loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
  font-size: 0.9rem;
}

#grid {
  position: relative;
  min-height: 100vh;
  padding: var(--grid-gap);
}

/* Scroll sentinel for infinite scroll */
#scroll-sentinel {
  height: 1px;
  width: 100%;
}

@media (min-width: 480px) {
  :root { --thumb-min-size: 160px; }
}

@media (min-width: 768px) {
  :root { --thumb-min-size: 180px; }
  #grid { gap: 6px; padding: 6px; }
}

@media (min-width: 1200px) {
  :root { --thumb-min-size: 220px; }
  #grid { gap: 8px; padding: 8px; }
}

/* Thumbnail cards — real <button>s for keyboard access */
.thumb {
  overflow: hidden;
  cursor: pointer;
  position: absolute;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  transition: transform var(--transition-fast);
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.thumb:focus-visible {
  outline: 3px solid var(--accent-hover);
  outline-offset: -3px;
  z-index: 1;
}

.thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.4) 0%, transparent 50%);
  opacity: 0;
  transition: opacity var(--transition-normal);
  pointer-events: none;
}

.thumb:hover::after {
  opacity: 1;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--transition-slow);
}

.thumb:hover img {
  transform: scale(1.05);
}

@media (hover: none) {
  .thumb:hover img {
    transform: none;
  }
  .thumb:hover::after {
    opacity: 0;
  }
}

/* Badges */
.thumb .badge {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  color: var(--text-secondary);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.thumb .variant-count {
  position: absolute;
  bottom: var(--space-sm);
  right: var(--space-sm);
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  color: var(--text-primary);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

/* Play indicator for videos */
.thumb .play-indicator {
  position: absolute;
  bottom: var(--space-sm);
  left: var(--space-sm);
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  color: var(--text-primary);
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Selection mode */
.thumb .check {
  position: absolute;
  top: var(--space-sm);
  left: var(--space-sm);
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  border: 2px solid var(--text-primary);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--text-primary);
  z-index: 2;
  pointer-events: none;
  transition: all var(--transition-fast);
}

.thumb.selected {
  outline: 3px solid var(--accent-primary);
  outline-offset: -3px;
}

.thumb.selected .check {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.thumb.selected img {
  opacity: 0.8;
}

/* ===========================================
   Lightbox - TikTok Style Fullscreen
   =========================================== */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 1000;
  animation: fadeIn var(--transition-normal);
}

#lightbox.open {
  display: block;
}

/* Media container - fullscreen */
#lightbox .media-container {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Our own pointer handlers own every gesture here (swipe L/R/up). Without
     this, the browser's native pan/scroll can win the gesture and drag the
     grid page underneath instead of the lightbox reacting to the swipe. */
  touch-action: none;
}

#lightbox img,
#lightbox video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#lightbox video.loading {
  filter: blur(4px);
}

/* Close button - top left */
#lightbox .close-btn {
  position: absolute;
  top: var(--space-lg);
  left: var(--space-lg);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  z-index: 10;
}

#lightbox .close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Help button - top right, mirror of close button */
#lightbox .help-btn {
  position: absolute;
  top: var(--space-lg);
  right: var(--space-lg);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 700;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  z-index: 10;
}

#lightbox .help-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Prev / next lightbox navigation */
#lightbox .nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  color: var(--text-primary);
  width: 44px;
  height: 64px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Dimmed but always discoverable; full opacity on hover/focus. */
  opacity: 0.35;
  transition: opacity var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
  z-index: 10;
}

#lightbox .nav-btn svg {
  width: 22px;
  height: 22px;
}

#lightbox .nav-prev {
  left: var(--space-lg);
}

#lightbox .nav-next {
  right: calc(var(--space-lg) + 80px);
}

#lightbox:hover .nav-btn:not([disabled]),
#lightbox .nav-btn:focus-visible:not([disabled]) {
  opacity: 1;
}

#lightbox .nav-btn:hover:not([disabled]) {
  background: rgba(255, 255, 255, 0.2);
}

#lightbox .nav-btn:active:not([disabled]) {
  transform: translateY(-50%) scale(0.94);
}

#lightbox .nav-btn[disabled] {
  opacity: 0;
  pointer-events: none;
  cursor: default;
}

/* On touch devices swipe is primary — hide the buttons entirely. */
@media (hover: none) {
  #lightbox .nav-btn {
    display: none;
  }
}

/* Click-to-play overlay: videos download nothing until this is pressed. */
.play-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 76px;
  height: 76px;
  border-radius: var(--radius-full);
  border: none;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.play-overlay:hover {
  background: rgba(99, 102, 241, 0.7);
  transform: translate(-50%, -50%) scale(1.06);
}

.play-overlay:focus-visible {
  outline: 3px solid var(--accent-hover);
  outline-offset: 2px;
}

.play-overlay svg {
  width: 36px;
  height: 36px;
  margin-left: 4px;
}

/* Right side floating actions - TikTok style */
#lightbox .actions-sidebar {
  position: absolute;
  right: var(--space-lg);
  bottom: 50%;
  transform: translateY(50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  z-index: 10;
}

#lightbox .action-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  padding: 0;
}

#lightbox .action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

#lightbox .action-btn.active {
  background: var(--accent-primary);
}

#lightbox .action-btn.active:hover {
  background: var(--accent-hover);
}

#lightbox .action-btn.danger {
  color: var(--danger);
}

#lightbox .action-btn.danger:hover {
  background: var(--danger);
  color: var(--text-primary);
}

#lightbox .action-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* Score display between upvote/downvote */
#lightbox .score-display {
  width: 48px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

/* Rating dropdown - compact */
#lightbox .rating-select {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  color: var(--text-primary);
  font-size: 0.8rem;
  line-height: normal;
  font-weight: 700;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding: 0;
  margin: 0;
  text-align: center;
  text-align-last: center;
  text-indent: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

/* Safari ignores flex alignment inside a closed <select>'s display box, so
   fall back to centering the whole box's text run via text-indent trickery
   is unreliable across engines — text-align-last above covers Firefox/Chrome,
   flex covers Chrome/newer Safari. Keep the option list itself left-aligned
   and normal-sized so the open dropdown stays readable. */
#lightbox .rating-select option {
  text-align: left;
  font-size: 1rem;
  font-weight: 400;
}

#lightbox .rating-select:hover {
  background: rgba(255, 255, 255, 0.2);
}

#lightbox .rating-select:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-primary);
}

/* Bottom info overlay — no background of its own; description/tags carry
   their own translucent panels, and both are hidden most of the time
   anyway, so there's no need for a permanent dark bar behind them. */
#lightbox .info-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 80px;
  padding: var(--space-xl) var(--space-lg);
  pointer-events: none;
}

#lightbox .info-overlay > * {
  pointer-events: auto;
}

#lightbox .video-counter {
  display: inline-block;
  font-size: 0.8rem;
  color: var(--text-primary);
  font-weight: 500;
  margin-bottom: var(--space-xs);
  padding: 2px 10px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: var(--radius-full);
}

#lightbox .title {
  display: inline-block;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: var(--space-xs);
  padding: 2px 10px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: var(--radius-md);
}

/* Description / tags toggle buttons live in the actions sidebar now
   (.action-btn), just with a small dot marking unseen content behind a
   collapsed one, and an accent highlight while expanded. */
.info-toggle {
  position: relative;
}

.info-toggle[aria-expanded="true"] {
  background: var(--accent-primary);
}

.info-toggle.has-content::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 1.5px solid rgba(0, 0, 0, 0.6);
}

.info-toggle[aria-expanded="true"].has-content::after {
  display: none;
}

/* Editable description / prompt in the overlay — hidden until toggled on. */
.description-input {
  display: none;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(4px);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  line-height: 1.35;
  resize: vertical;
  min-height: 2.4rem;
  max-height: 40vh;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  /* Unfocused, long-press copies the text (lightbox.js) — keep the native
     long-press selection/callout from grabbing the gesture first. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.description-input::placeholder {
  color: var(--text-secondary);
}

.description-input:hover {
  background: rgba(255, 255, 255, 0.12);
}

.description-input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
  -webkit-user-select: text;
  user-select: text;
}

.description-input.saving {
  opacity: 0.6;
}

.description-input.dirty {
  border-color: var(--accent-primary, #6366f1);
}

.description-input.expanded {
  display: block;
}

/* Tags content — hidden until toggled on, same as the description. */
.tags-content {
  display: none;
}

.tags-content.expanded {
  display: block;
}

/* Tags in lightbox */
.tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: var(--space-sm);
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(4px);
  border: none;
  border-radius: var(--radius-full);
  font-size: 0.65rem;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.tag-chip.clickable {
  cursor: pointer;
}

.tag-chip.clickable:hover {
  background: rgba(255, 255, 255, 0.25);
}

.tag-chip .remove {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1;
  margin-left: var(--space-xs);
  transition: color var(--transition-fast);
}

.tag-chip .remove:hover {
  color: var(--danger);
}

/* Tag input */
.tag-input-wrapper {
  position: relative;
  display: inline-block;
}

.tag-input {
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(4px);
  color: var(--text-primary);
  font-size: 0.8rem;
  width: 140px;
  transition: all var(--transition-fast);
}

.tag-input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.25);
  width: 180px;
}

.tag-input::placeholder {
  color: var(--text-secondary);
}

/* Autocomplete dropdown */
.autocomplete-list {
  position: absolute;
  bottom: 100%;
  left: 0;
  min-width: 180px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  max-height: 180px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: var(--shadow-lg);
  margin-bottom: var(--space-sm);
}

.autocomplete-item {
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.autocomplete-item .count {
  color: var(--text-muted);
  font-size: 0.7rem;
}

/* Mobile adjustments */
@media (max-width: 600px) {
  /* Photos go edge-to-edge like a story card; cropping is preferred over
     letterboxing here. Video keeps object-fit: contain (native controls,
     nothing should be cropped out of view). */
  #lightbox img {
    object-fit: cover;
  }

  #lightbox .close-btn {
    top: var(--space-md);
    left: var(--space-md);
  }
  
  #lightbox .actions-sidebar {
    right: var(--space-md);
    gap: var(--space-sm);
  }
  
  #lightbox .action-btn,
  #lightbox .rating-select {
    width: 44px;
    height: 44px;
  }
  
  #lightbox .action-btn svg {
    width: 20px;
    height: 20px;
  }
  
  #lightbox .info-overlay {
    right: 60px;
    padding: var(--space-lg) var(--space-md);
  }
}

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  #lightbox .info-overlay {
    padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom));
  }
  
  #lightbox .actions-sidebar {
    bottom: calc(50% + env(safe-area-inset-bottom) / 2);
  }
}

/* ===========================================
   Selection Bar
   =========================================== */
.selection-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: center;
  z-index: 500;
  animation: slideUp var(--transition-normal);
  box-shadow: var(--shadow-lg);
}

.selection-bar button,
.selection-bar select {
  padding: var(--space-sm) var(--space-lg);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.selection-bar button:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.selection-bar select {
  padding-right: var(--space-xl);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23707070' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.selection-bar select:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.selection-bar button.danger {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.selection-bar button.danger:hover {
  background: var(--danger);
  color: var(--text-primary);
}

/* Bulk tag input */
.bulk-tag-wrapper {
  position: relative;
}

.bulk-tag-input {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.85rem;
  width: 160px;
  transition: all var(--transition-fast);
}

.bulk-tag-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.bulk-autocomplete-list {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  max-height: 200px;
  overflow-y: auto;
  z-index: 510;
  box-shadow: var(--shadow-md);
}

.bulk-autocomplete-list .autocomplete-item {
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.bulk-autocomplete-list .autocomplete-item:hover,
.bulk-autocomplete-list .autocomplete-item.selected {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* ===========================================
   Toast notifications
   =========================================== */
.toast {
  position: fixed;
  bottom: var(--space-2xl);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: var(--space-md) var(--space-xl);
  padding-left: calc(var(--space-xl) + 4px);
  border-radius: var(--radius-lg);
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 2000;
  opacity: 0;
  transition: opacity var(--transition-normal), transform var(--transition-normal),
              background-color var(--transition-normal), border-color var(--transition-normal);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-default);
  border-left-width: 4px;
  max-width: min(90vw, 440px);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast.toast-success {
  border-left-color: var(--success);
}

.toast.toast-error {
  border-left-color: var(--danger);
  background: linear-gradient(to right, var(--danger-bg) 0, var(--bg-elevated) 40%);
}

.toast.toast-info {
  border-left-color: var(--accent-primary);
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: opacity var(--transition-fast);
    transform: translateX(-50%);
  }
  .toast.show { transform: translateX(-50%); }
}

/* ===========================================
   Animations
   =========================================== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===========================================
   Scrollbar styling
   =========================================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) var(--bg-primary);
}

/* ===========================================
   Mobile touch improvements
   =========================================== */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .menu-items select,
  .selection-bar button,
  .selection-bar select,
  #lightbox .actions button,
  #lightbox .actions select {
    min-height: 44px;
    padding: var(--space-md) var(--space-lg);
  }
  
  #lightbox .close-btn {
    width: 48px;
    height: 48px;
    top: var(--space-md);
    right: var(--space-md);
  }
  
  .tag-chip {
    padding: 3px 10px;
    font-size: 0.7rem;
  }
}

/* Safe areas for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  .selection-bar {
    padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
  }

  #lightbox {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ===========================================
   Modals
   =========================================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: var(--space-lg);
}

.modal.open {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-default);
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: var(--space-sm);
  line-height: 1;
  transition: color var(--transition-fast);
}

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

/* ===== Keyboard shortcuts help ===== */

.shortcuts-content {
  max-width: 540px;
  width: 92vw;
}

.shortcuts-body {
  padding: var(--space-lg);
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg) var(--space-xl, 2rem);
}

.shortcuts-body section h3 {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
}

.shortcuts-body dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-xs) var(--space-md);
  align-items: center;
}

.shortcuts-body dt {
  text-align: right;
  white-space: nowrap;
}

.shortcuts-body dd {
  color: var(--text-secondary);
  font-size: 0.88rem;
}

.shortcuts-body kbd {
  display: inline-block;
  min-width: 28px;
  padding: 2px 7px;
  margin: 0 1px;
  text-align: center;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  line-height: 1.2;
}

@media (max-width: 520px) {
  .shortcuts-body {
    grid-template-columns: 1fr;
    gap: var(--space-lg);
  }
}

/* ===== Upload ===== */

.upload-btn {
  background: none;
  border: none;
  color: var(--text-primary, #fff);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}
.upload-btn:hover { background: rgba(255, 255, 255, 0.08); }
.upload-btn:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 3px var(--accent-muted);
}
.upload-btn:active { transform: scale(0.94); }

.upload-modal-content { max-width: 560px; width: 92vw; }

.upload-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.25rem 0;
}

.upload-dropzone {
  border: 2px dashed var(--border-strong, #3a3a3a);
  border-radius: 10px;
  padding: 1.25rem;
  text-align: center;
  color: var(--text-secondary, #b0b0b0);
  transition: background-color 150ms ease, border-color 150ms ease;
}
.upload-dropzone.is-drag {
  background: rgba(99, 102, 241, 0.08);
  border-color: var(--accent-primary, #6366f1);
}
.upload-dropzone .upload-hint {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted, #707070);
}
.upload-browse {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.45rem 0.9rem;
  background: var(--accent-primary, #6366f1);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: background-color var(--transition-fast), transform var(--transition-fast),
              box-shadow var(--transition-fast);
}
.upload-browse:hover {
  background: var(--accent-hover, #818cf8);
}
.upload-browse:focus-within {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-muted);
}
.upload-browse:active { transform: scale(0.97); }

.upload-controls {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 0.75rem;
  align-items: center;
}
.upload-controls select, .upload-controls input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  background: var(--bg-primary, #0a0a0a);
  border: 1px solid var(--border-default, #2a2a2a);
  border-radius: 6px;
  color: var(--text-primary, #fff);
  font-size: 0.95rem;
}

.upload-queue {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 220px;
  overflow-y: auto;
  border-top: 1px solid var(--border-default, #2a2a2a);
  border-bottom: 1px solid var(--border-default, #2a2a2a);
}
.upload-queue:empty { display: none; }
.upload-queue li {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 0.6rem;
  row-gap: 0.25rem;
  padding: 0.5rem 0.2rem;
  border-bottom: 1px solid var(--border-default, #2a2a2a);
  font-size: 0.9rem;
  transition: background-color var(--transition-normal);
  animation: uploadRowIn var(--transition-normal);
}
.upload-queue li:last-child { border-bottom: none; }
.upload-queue .file-name {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upload-queue .file-state {
  font-size: 0.78rem;
  color: var(--text-muted, #707070);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: color var(--transition-normal);
}
.upload-queue .file-progress {
  grid-column: 1 / -1;
  height: 3px;
  background: var(--bg-elevated, #222);
  border-radius: var(--radius-full);
  overflow: hidden;
  display: none;
}
.upload-queue .file-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-primary, #6366f1);
  border-radius: var(--radius-full);
  transition: width 120ms ease-out, background-color var(--transition-normal);
}
.upload-queue li.state-active {
  background: rgba(99, 102, 241, 0.06);
}
.upload-queue li.state-active .file-name {
  color: var(--text-primary, #fff);
}
.upload-queue li.state-done   .file-state { color: var(--success, #10b981); }
.upload-queue li.state-done   .file-progress-fill { background: var(--success, #10b981); }
.upload-queue li.state-skipped .file-state { color: #facc15; }
.upload-queue li.state-failed  .file-state { color: var(--danger, #ef4444); }

@keyframes uploadRowIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .upload-queue li { animation: none; }
  .upload-queue .file-progress-fill { transition: none; }
}

.upload-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.upload-start {
  padding: 0.6rem 1rem;
  background: var(--accent-primary, #6366f1);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast),
              box-shadow var(--transition-fast), opacity var(--transition-fast);
}
.upload-start:hover:not(:disabled) {
  background: var(--accent-hover, #818cf8);
  box-shadow: var(--shadow-glow);
}
/* Sleeper target: same button, teal accent to signal the different store. */
.upload-start-sleeper { background: #0d9488; }
.upload-start-sleeper:hover:not(:disabled) { background: #14b8a6; }
.upload-start:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-muted);
}
.upload-start:active:not(:disabled) { transform: scale(0.97); }
.upload-start:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.upload-summary {
  font-size: 0.85rem;
  color: var(--text-secondary, #b0b0b0);
}

/* ===========================================
   Login page (served unauthenticated)
   =========================================== */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1rem;
}

.login-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  padding: 2rem;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin: 0 0 0.5rem;
  text-align: center;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-box label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.login-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  transition: all var(--transition-fast);
}

.login-box input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

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

.login-submit {
  width: 100%;
  padding: 0.85rem;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent-primary);
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-top: 0.5rem;
}

.login-submit:hover { background: var(--accent-hover); }
.login-submit:active { transform: scale(0.98); }

.login-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 0.85rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  display: none;
}

@media (max-width: 400px) {
  .login-box { padding: 1.5rem; }
}

