/* =============================================================
   Identity Forge — Cosplay Gallery Styles
   Dark theme optimized for browsing ~1600+ character samples.
   ============================================================= */

/* --- CSS Variables --- */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1e2a3a;
  --bg-card-hover: #253545;
  --bg-input: #0f1824;
  --text-primary: #e8e8f0;
  --text-secondary: #9098a8;
  --text-muted: #606878;
  --accent: #5b8def;
  --accent-hover: #7aa5ff;
  --accent-glow: rgba(91, 141, 239, 0.15);
  --border: #2a3a50;
  --border-hover: #4a6a90;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --transition: 0.2s ease;
  --max-width: 1400px;
  --card-min-width: 200px;
  --card-max-width: 280px;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* --- Header --- */
.gallery-header {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
  max-width: var(--max-width);
  margin: 0 auto;
}

.gallery-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.header-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 700px;
  margin: 0 auto 1rem;
  line-height: 1.6;
}

.header-subtitle strong {
  color: var(--accent);
}

.header-links {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.header-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
}

.header-link:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* --- Controls --- */
.gallery-controls {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.search-bar {
  max-width: 600px;
  margin: 0 auto 0.5rem;
  position: relative;
}

.search-bar input {
  width: 100%;
  padding: 0.6rem 1rem;
  padding-right: 2.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.search-clear {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
  transition: color var(--transition);
}

.search-clear:hover { color: var(--text-primary); }
.search-clear.hidden { display: none; }

.stats-bar {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stats-missing {
  color: #c9a44b;
  cursor: pointer;
}

.stats-missing:hover {
  text-decoration: underline;
}

/* --- Grid --- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min-width), 1fr));
  gap: 0.75rem;
  padding: 1rem;
  max-width: var(--max-width);
  margin: 0 auto;
}

/* --- Card --- */
.gallery-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.gallery-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.gallery-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-image-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--bg-input);
  overflow: hidden;
}

.card-image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 0;
}

.card-image-wrapper img.loaded {
  opacity: 1;
}

.card-image-wrapper img:hover {
  transform: scale(1.05);
}

/* Placeholder for missing images */
.card-image-wrapper.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
}

.placeholder-icon {
  font-size: 2rem;
  color: var(--text-muted);
  opacity: 0.5;
}

.card-name {
  padding: 0.5rem 0.6rem;
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  color: var(--text-primary);
}

/* Missing image card styling */
.gallery-card.missing {
  opacity: 0.6;
  cursor: default;
}

.gallery-card.missing:hover {
  opacity: 0.75;
  transform: none;
  border-color: var(--border);
  box-shadow: none;
}

.missing-badge {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  background: rgba(0, 0, 0, 0.7);
  color: #c9a44b;
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  pointer-events: none;
}

/* --- Loading --- */
.loading-indicator {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.loading-indicator.hidden { display: none; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 0.75rem;
}

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

/* --- No Results --- */
.no-results {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.no-results.hidden { display: none; }

.btn-secondary {
  margin-top: 0.75rem;
  padding: 0.5rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all var(--transition);
}

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

/* --- Lightbox --- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.lightbox.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lightbox-content img {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.lightbox-name {
  margin-top: 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
}

.lightbox-close {
  position: fixed;
  top: 1rem;
  right: 1.5rem;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--text-primary);
  font-size: 2rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

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

.lightbox-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--text-primary);
  font-size: 2.5rem;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), opacity var(--transition);
}

.lightbox-nav:hover { background: rgba(255, 255, 255, 0.2); }
.lightbox-nav:disabled { opacity: 0.3; cursor: default; }

.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }

/* --- Footer --- */
.gallery-footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

/* --- Keyboard shortcut hint --- */
.keyboard-hint {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 999;
}

.keyboard-hint.visible { opacity: 1; }

/* --- Responsive --- */
@media (max-width: 600px) {
  .gallery-header h1 { font-size: 1.35rem; }
  .header-subtitle { font-size: 0.85rem; }
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem;
    padding: 0.5rem;
  }
  .card-name { font-size: 0.72rem; padding: 0.35rem 0.4rem; }
  .lightbox-prev { left: 0.25rem; }
  .lightbox-next { right: 0.25rem; }
  .lightbox-nav { font-size: 2rem; width: 40px; height: 40px; }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}
