/* rSplat — Gaussian Splat Viewer */

:root {
  --splat-bg: var(--rs-bg-page, #0f172a);
  --splat-surface: var(--rs-bg-surface, #1e293b);
  --splat-border: var(--rs-border-strong, #334155);
  --splat-text: var(--rs-text-primary, #e2e8f0);
  --splat-text-muted: var(--rs-text-muted, #94a3b8);
  --splat-accent: #818cf8;
  --splat-accent-hover: #6366f1;
  --splat-card-bg: var(--rs-bg-surface, rgba(30, 41, 59, 0.8));
}

/* ── Gallery ── */

.splat-gallery {
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  color: var(--splat-text);
  min-height: 100%;
  background: var(--splat-bg);
}

.splat-gallery h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.splat-gallery__subtitle {
  color: var(--splat-text-muted);
  font-size: 0.875rem;
  margin: 0 0 2rem;
}

.splat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

/* ── Card ── */

.splat-card {
  background: var(--splat-card-bg);
  border: 1px solid var(--splat-border);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.splat-card:hover {
  transform: translateY(-2px);
  border-color: var(--splat-accent);
  box-shadow: 0 8px 24px rgba(129, 140, 248, 0.15);
}

.splat-card__preview {
  height: 160px;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e293b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  position: relative;
  overflow: hidden;
}

.splat-card__model-viewer {
  width: 100%;
  height: 100%;
  --poster-color: transparent;
}

.splat-card__thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.splat-card__body {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.splat-card__title {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.3;
}

.splat-card__meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--splat-text-muted);
}

.splat-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.splat-badge--ply { background: #4338ca; color: #e0e7ff; }
.splat-badge--splat { background: #7c3aed; color: #ede9fe; }
.splat-badge--spz { background: #2563eb; color: #dbeafe; }

/* ── Processing status badges ── */

.splat-badge--pending { background: #92400e; color: #fef3c7; }
.splat-badge--processing { background: #1e40af; color: #dbeafe; }
.splat-badge--failed { background: #991b1b; color: #fecaca; }

/* ── Processing card variants ── */

.splat-card--pending,
.splat-card--processing,
.splat-card--failed {
  cursor: default;
}

.splat-card--pending:hover,
.splat-card--processing:hover,
.splat-card--failed:hover {
  transform: none;
  border-color: var(--splat-border);
  box-shadow: none;
}

.splat-card--pending .splat-card__preview {
  background: linear-gradient(135deg, #451a03 0%, #78350f 50%, #1e293b 100%);
}

.splat-card--processing .splat-card__preview {
  background: linear-gradient(135deg, #1e1b4b 0%, #1e3a5f 50%, #1e293b 100%);
}

.splat-card--failed .splat-card__preview {
  background: linear-gradient(135deg, #450a0a 0%, #7f1d1d 50%, #1e293b 100%);
}

/* ── Processing overlay ── */

.splat-card__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  gap: 0.5rem;
  z-index: 2;
}

.splat-card__spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(147, 197, 253, 0.3);
  border-top-color: #93c5fd;
  border-radius: 50%;
  animation: splat-spin 0.8s linear infinite;
}

/* ── Upload ── */

.splat-upload {
  margin-top: 2rem;
  border: 2px dashed var(--splat-border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.splat-upload:hover,
.splat-upload--dragover {
  border-color: var(--splat-accent);
  background: rgba(129, 140, 248, 0.05);
}

.splat-upload__icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.splat-upload__text {
  color: var(--splat-text-muted);
  font-size: 0.875rem;
  margin: 0 0 1rem;
}

.splat-upload__text strong {
  color: var(--splat-accent);
  cursor: pointer;
}

/* ── Upload mode toggle ── */

.splat-upload__toggle {
  display: inline-flex;
  border-radius: 9999px;
  overflow: hidden;
  border: 1px solid var(--splat-border);
  margin-bottom: 1.5rem;
}

.splat-upload__toggle-btn {
  padding: 0.5rem 1.25rem;
  border: none;
  background: transparent;
  color: var(--splat-text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.splat-upload__toggle-btn:hover {
  color: var(--splat-text);
}

.splat-upload__toggle-btn.active {
  background: var(--splat-accent);
  color: white;
}

/* ── Upload modes ── */

.splat-upload__mode {
  /* shown/hidden via JS display toggle */
  cursor: pointer;
}

.splat-upload__form {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 400px;
  margin: 1rem auto 0;
}

.splat-upload__form.active {
  display: flex;
}

.splat-upload__form input,
.splat-upload__form textarea {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--splat-border);
  background: var(--splat-surface);
  color: var(--splat-text);
  font-size: 0.875rem;
}

.splat-upload__form textarea {
  resize: vertical;
  min-height: 60px;
}

.splat-upload__btn {
  padding: 0.625rem 1.25rem;
  border-radius: 8px;
  border: none;
  background: var(--splat-accent);
  color: white;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.2s;
}

.splat-upload__btn:hover {
  background: var(--splat-accent-hover);
}

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

.splat-upload__status {
  font-size: 0.8rem;
  color: var(--splat-text-muted);
}

.splat-upload__login {
  color: var(--splat-text-muted);
  font-size: 0.875rem;
}

.splat-upload__login a {
  color: var(--splat-accent);
}

/* ── Media file count ── */

.splat-upload__selected {
  min-height: 0;
}

.splat-upload__file-count {
  display: inline-block;
  padding: 0.375rem 0.75rem;
  border-radius: 6px;
  background: rgba(129, 140, 248, 0.15);
  color: var(--splat-accent);
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

/* ── Generate mode ── */

.splat-generate__preview {
  display: none;
  margin: 1rem auto;
  max-width: 240px;
}

.splat-generate__preview img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--splat-border);
}

.splat-generate__actions {
  display: flex;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.splat-generate__progress {
  max-width: 300px;
  margin: 1rem auto;
  text-align: center;
}

.splat-generate__progress-bar {
  --splat-progress: 0%;
  height: 6px;
  border-radius: 3px;
  background: var(--splat-border);
  overflow: hidden;
  position: relative;
}

.splat-generate__progress-bar::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--splat-progress);
  background: linear-gradient(90deg, var(--splat-accent), #a78bfa);
  border-radius: 3px;
  transition: width 0.5s ease-out;
}

.splat-generate__progress-text {
  margin-top: 0.75rem;
  color: var(--splat-text-muted);
  font-size: 0.8rem;
}

/* ── Demo card ── */

.splat-card--demo {
  cursor: pointer;
}

/* ── Back + Save buttons (inline viewer) ── */

button.splat-viewer__back,
button.splat-viewer__save {
  cursor: pointer;
  font-family: inherit;
}

.splat-viewer__save {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: var(--splat-accent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: white;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--splat-accent);
  transition: background 0.2s, opacity 0.2s;
}

.splat-viewer__save:hover {
  background: var(--splat-accent-hover);
}

.splat-viewer__save:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── Viewer ── */

.splat-viewer {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--splat-bg);
  overflow: hidden;
}

.splat-viewer__canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.splat-viewer__controls {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 100;
  display: flex;
  gap: 0.5rem;
  pointer-events: auto;
}

.splat-viewer__back {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: var(--rs-glass-bg, rgba(30, 41, 59, 0.85));
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--splat-text);
  text-decoration: none;
  font-size: 0.8rem;
  border: 1px solid var(--splat-border);
  transition: background 0.2s;
}

.splat-viewer__back:hover {
  background: var(--rs-bg-surface, rgba(51, 65, 85, 0.9));
}

.splat-viewer__info {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  z-index: 100;
  pointer-events: auto;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--rs-glass-bg, rgba(30, 41, 59, 0.85));
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--splat-border);
  color: var(--splat-text);
  font-size: 0.8rem;
  max-width: 320px;
}

.splat-viewer__title {
  font-weight: 600;
  margin: 0 0 0.25rem;
}

.splat-viewer__desc {
  color: var(--splat-text-muted);
  margin: 0;
}

/* ── Loading ── */

.splat-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--splat-bg);
  z-index: 20;
  transition: opacity 0.4s;
}

.splat-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.splat-loading__spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--splat-border);
  border-top-color: var(--splat-accent);
  border-radius: 50%;
  animation: splat-spin 0.8s linear infinite;
}

.splat-loading__text {
  margin-top: 1rem;
  color: var(--splat-text-muted);
  font-size: 0.875rem;
}

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

/* ── Empty state ── */

.splat-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--splat-text-muted);
}

.splat-empty__icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.splat-empty h3 {
  font-size: 1.125rem;
  color: var(--splat-text);
  margin: 0 0 0.5rem;
}

.splat-empty p {
  font-size: 0.875rem;
  margin: 0;
}

/* ── Light theme overrides ── */

[data-theme="light"] .splat-card__preview {
  background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 50%, #f1f5f9 100%);
}

[data-theme="light"] .splat-card--pending .splat-card__preview {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 50%, #f1f5f9 100%);
}

[data-theme="light"] .splat-card--processing .splat-card__preview {
  background: linear-gradient(135deg, #e0e7ff 0%, #bfdbfe 50%, #f1f5f9 100%);
}

[data-theme="light"] .splat-card--failed .splat-card__preview {
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 50%, #f1f5f9 100%);
}

[data-theme="light"] .splat-card:hover {
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.12);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .splat-card__preview {
    background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 50%, #f1f5f9 100%);
  }
  :root:not([data-theme]) .splat-card--pending .splat-card__preview {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 50%, #f1f5f9 100%);
  }
  :root:not([data-theme]) .splat-card--processing .splat-card__preview {
    background: linear-gradient(135deg, #e0e7ff 0%, #bfdbfe 50%, #f1f5f9 100%);
  }
  :root:not([data-theme]) .splat-card--failed .splat-card__preview {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 50%, #f1f5f9 100%);
  }
  :root:not([data-theme]) .splat-card:hover {
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.12);
  }
}

/* ── Download button ── */

.splat-viewer__download {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: var(--rs-glass-bg, rgba(30, 41, 59, 0.85));
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--splat-text);
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--splat-border);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}

.splat-viewer__download:hover {
  background: var(--rs-bg-surface, rgba(51, 65, 85, 0.9));
}

.splat-viewer__download:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── Format info ── */

.splat-viewer__format-info {
  color: var(--splat-text-muted);
  font-size: 0.7rem;
  margin: 0.25rem 0 0;
  opacity: 0.8;
}

/* ── My Models section ── */

.splat-my-models {
  margin-bottom: 2rem;
}

.splat-my-models__title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--splat-text);
  margin: 0 0 1rem;
}

.splat-section-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--splat-text);
  margin: 0 0 1rem;
}

/* ── Responsive ── */

@media (max-width: 640px) {
  .splat-gallery {
    padding: 1rem;
  }

  .splat-grid {
    grid-template-columns: 1fr;
  }

  .splat-viewer__info {
    left: 0.5rem;
    right: 0.5rem;
    max-width: none;
  }

  .splat-upload__toggle-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
  }
}
