/* =========================================================
   3D Design Studio — global styles
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg: #fafafa;
  --bg-card: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #6b6b6b;
  --text-muted: #a0a0a0;
  --border: #e8e8e8;
  --border-hover: #d0d0d0;
  --accent: #2a2a2a;
  --accent-light: #f0f0f0;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --radius-lg: 16px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ===== NAVIGATION ===== */
nav {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  background: rgba(250, 250, 250, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}
.nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 40px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; color: var(--text-primary); }
.logo span { font-weight: 300; color: var(--text-secondary); }
.nav-links { display: flex; gap: 32px; list-style: none; }
.nav-links a {
  text-decoration: none; color: var(--text-secondary);
  font-size: 14px; font-weight: 500; transition: var(--transition);
  position: relative;
}
.nav-links a:hover, .nav-links a.active { color: var(--text-primary); }
.nav-links a.active::after {
  content: ''; position: absolute; inset: auto 0 -4px 0;
  height: 1.5px; background: var(--text-primary); border-radius: 1px;
}
.nav-actions { display: flex; align-items: center; gap: 12px; }

.btn-vr, .btn-upload {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: var(--transition); font-family: var(--font);
}
.btn-vr { background: var(--accent); color: white; border: none; }
.btn-vr:hover { opacity: 0.85; transform: translateY(-1px); }
.btn-vr svg { width: 16px; height: 16px; }
.btn-upload { background: transparent; color: var(--text-primary); border: 1px solid var(--border); }
.btn-upload:hover { border-color: var(--border-hover); background: var(--accent-light); }

.mobile-menu-btn {
  display: none; background: none; border: none; cursor: pointer;
  padding: 8px; color: var(--text-primary);
}
.mobile-menu-btn svg { width: 24px; height: 24px; }

.model-desc { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }

/* ===== HERO ===== */
.hero { padding: 140px 40px 60px; text-align: center; max-width: 800px; margin: 0 auto; }
.hero h1 {
  font-size: clamp(36px, 5vw, 56px);
  font-weight: 700; letter-spacing: -0.03em; line-height: 1.1;
  margin-bottom: 16px;
}
.hero p {
  font-size: 18px; color: var(--text-secondary);
  font-weight: 400; max-width: 500px; margin: 0 auto;
}

/* ===== VIEWER ===== */
.viewer-section { max-width: 1400px; margin: 0 auto; padding: 20px 40px 60px; }
.viewer-container {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  max-height: 600px;
}
#viewerStage { position: absolute; inset: 0; cursor: grab; }
#viewerStage:active { cursor: grabbing; }

.viewer-controls {
  position: absolute; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 8px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.ctrl-btn {
  width: 36px; height: 36px;
  border: none; background: transparent;
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  color: var(--text-secondary);
}
.ctrl-btn:hover { background: var(--accent-light); color: var(--text-primary); }
.ctrl-btn.active { background: var(--accent); color: white; }
.ctrl-btn svg { width: 18px; height: 18px; }

.viewer-info {
  position: absolute; top: 20px; left: 20px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  padding: 12px 16px; border-radius: 10px;
  border: 1px solid var(--border);
}
.viewer-info h3 { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.viewer-info p { font-size: 12px; color: var(--text-muted); }

/* ===== MODEL DETAILS ===== */
.model-details {
  max-width: 1400px; margin: 0 auto;
  padding: 0 40px 40px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px;
}
.detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.detail-card h4 {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin-bottom: 8px;
}
.detail-card .value { font-size: 20px; font-weight: 600; }
.detail-card .sub { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* ===== GALLERY ===== */
.gallery-section { max-width: 1400px; margin: 0 auto; padding: 60px 40px; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 32px;
}
.section-header h2 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.filter-bar { display: flex; gap: 8px; }
.filter-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 20px;
  font-size: 13px; font-weight: 500;
  cursor: pointer; transition: var(--transition);
  font-family: var(--font); color: var(--text-secondary);
}
.filter-btn:hover { border-color: var(--border-hover); }
.filter-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.model-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
  display: flex; flex-direction: column;
}
.model-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: var(--border-hover);
}
.model-card .thumbnail {
  position: relative;
  aspect-ratio: 4 / 3;
  background: linear-gradient(135deg, #f5f5f5 0%, #eaeaea 100%);
  overflow: hidden;
}
.model-card .thumbnail canvas {
  width: 100% !important; height: 100% !important; display: block;
  /* Block pointer events on thumbnail canvases so clicks bubble to the
     card (for selection). Auto-rotate still works because OrbitControls
     drives it from the render loop, not pointer input. */
  pointer-events: none;
}
.model-card .thumb-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.model-card .thumb-placeholder svg { width: 48px; height: 48px; opacity: 0.4; }

.model-card .card-body { padding: 16px; flex: 1; }
.model-card .card-body h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.model-card .card-body p { font-size: 13px; color: var(--text-secondary); }

.model-card .card-meta {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.model-card .tag {
  font-size: 11px; font-weight: 500;
  padding: 3px 8px; background: var(--accent-light);
  border-radius: 4px; color: var(--text-secondary);
}
.card-actions { display: flex; gap: 8px; }
.card-action-btn {
  width: 28px; height: 28px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  color: var(--text-muted);
}
.card-action-btn:hover { border-color: var(--border-hover); color: var(--text-primary); }

/* ===== EMPTY / LOADING ===== */
.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-muted);
  pointer-events: none;
}
.empty-state svg { width: 64px; height: 64px; opacity: 0.3; margin-bottom: 16px; }
.empty-state p { font-size: 15px; }
.empty-state .hint { font-size: 13px; margin-top: 4px; }

.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(250, 250, 250, 0.9);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 10;
  opacity: 0; pointer-events: none;
  transition: var(--transition);
}
.loading-overlay.visible { opacity: 1; pointer-events: all; }
.spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay p { margin-top: 12px; font-size: 13px; color: var(--text-secondary); }

/* ===== DROP ZONE ===== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 60px 40px;
  text-align: center;
  transition: var(--transition);
  cursor: pointer;
  margin-top: 20px;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}
.drop-zone svg { width: 40px; height: 40px; color: var(--text-muted); margin-bottom: 12px; }
.drop-zone h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.drop-zone p { font-size: 13px; color: var(--text-secondary); }

/* ===== FOOTER ===== */
footer {
  text-align: center;
  padding: 40px;
  border-top: 1px solid var(--border);
  margin-top: 60px;
}
footer p { font-size: 13px; color: var(--text-muted); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .nav-inner { padding: 0 20px; }
  .nav-links { display: none; }
  .nav-links.mobile-open {
    display: flex; flex-direction: column; gap: 0;
    position: absolute; top: 64px; left: 0; right: 0;
    background: rgba(250, 250, 250, 0.97);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px 20px;
  }
  .nav-links.mobile-open li { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .nav-links.mobile-open li:last-child { border-bottom: none; }
  .mobile-menu-btn { display: block; }

  .hero { padding: 120px 20px 40px; }
  .hero h1 { font-size: 32px; }
  .hero p { font-size: 16px; }

  .viewer-section { padding: 20px 20px 40px; }
  .viewer-container { aspect-ratio: 4 / 3; }

  .model-details { padding: 0 20px 20px; grid-template-columns: 1fr; }

  .gallery-section { padding: 40px 20px; }
  .section-header { flex-direction: column; align-items: flex-start; gap: 16px; }
  .gallery-grid { grid-template-columns: 1fr; }

  .btn-vr span { display: none; }
  .nav-actions .btn-upload { display: none; }
}

@media (max-width: 480px) {
  .viewer-controls { gap: 4px; padding: 6px; }
  .ctrl-btn { width: 32px; height: 32px; }
}

/* ===== MOBILE FULLSCREEN VIEWER ===== */
.mobile-fs {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #111;
  display: none;
  flex-direction: column;
}
.mobile-fs.active { display: flex; }

.mobile-fs model-viewer {
  flex: 1;
  width: 100%;
}

.mobile-fs-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 24px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
}

.mobile-fs-title {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.mobile-fs-close {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.3);
  background: rgba(0,0,0,0.5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.mobile-fs-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.mobile-fs-loading.hidden { display: none; }
