/* ==========================================================================
   ALONE3D / CLICKER STUDIO - 3D PARAMETRIC GENERATOR
   Inspired by Create.Blitch (100% In-Browser 3D CAD & Multi-color 3MF)
   ========================================================================== */

:root {
  --bg-main: #0a0e17;
  --bg-surface: #111827;
  --bg-card: #182234;
  --bg-card-hover: #1f2d44;
  --bg-input: #0e1524;
  --border-subtle: #243248;
  --border-focus: #3b82f6;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-purple: #8b5cf6;
  --shadow-glow: 0 0 25px rgba(59, 130, 246, 0.15);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ==========================================================================
   HEADER & NAVBAR
   ========================================================================== */
.gen-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(10, 14, 23, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.gen-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

.gen-brand-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.3);
}

.gen-brand-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.gen-badge-beta {
  font-size: 0.65rem;
  padding: 0.15rem 0.45rem;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #34d399;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
}

.gen-brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.gen-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-nav-outline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-nav-outline:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--border-focus);
}

/* ==========================================================================
   VIEW MODES: CATALOG VIEW VS STUDIO VIEW
   ========================================================================== */
#view-catalog, #view-studio {
  display: none;
  width: 100%;
}

#view-catalog.active, #view-studio.active {
  display: block;
}

/* ==========================================================================
   CATALOG VIEW (GALLERY OF GENERATORS)
   ========================================================================== */
.catalog-container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.catalog-hero {
  text-align: center;
  margin-bottom: 2.5rem;
}

.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.9rem;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  color: #60a5fa;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.catalog-hero h2 {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, #ffffff 40%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.catalog-hero p {
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 680px;
  margin: 0 auto 1.5rem;
  line-height: 1.6;
}

.catalog-filters {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.filter-chip {
  padding: 0.5rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-chip:hover, .filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.3);
}

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

.gen-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  cursor: pointer;
  position: relative;
}

.gen-card:hover {
  transform: translateY(-4px);
  border-color: rgba(59, 130, 246, 0.5);
  box-shadow: var(--shadow-glow);
}

.gen-card-banner {
  height: 160px;
  background: linear-gradient(135deg, #131d2e, #1e2c42);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--border-subtle);
}

.gen-card-banner svg {
  transition: transform 0.4s ease;
}

.gen-card:hover .gen-card-banner svg {
  transform: scale(1.08) rotate(3deg);
}

.gen-card-badge {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border-subtle);
  color: var(--accent-cyan);
}

.gen-card-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.gen-card-body h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  color: var(--text-main);
}

.gen-card-body p {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
  flex: 1;
}

.gen-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 0.85rem;
}

.gen-tags {
  display: flex;
  gap: 0.35rem;
}

.tag-pill {
  font-size: 0.7rem;
  padding: 0.2rem 0.45rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
  font-weight: 600;
}

.tag-pill.tag-3mf {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.btn-open-gen {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.2s;
}

.gen-card:hover .btn-open-gen {
  color: var(--accent-cyan);
}

/* ==========================================================================
   STUDIO VIEW (3D WORKSPACE)
   ========================================================================== */
#view-studio.active {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 61px);
  overflow: hidden;
}

.studio-subbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.6rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.studio-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.studio-breadcrumb button {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
}

.studio-title {
  color: var(--text-main);
  font-weight: 700;
}

.studio-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.btn-export-stl {
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid var(--border-subtle);
}

.btn-export-stl:hover {
  background: #334155;
  border-color: #475569;
}

.btn-export-3mf {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.35);
}

.btn-export-3mf:hover {
  background: linear-gradient(135deg, #059669, #047857);
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.5);
}

.studio-workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* SIDEBAR CONTROLS */
.studio-controls {
  width: 380px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.control-group {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.control-group-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 0.5rem;
}

.form-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-item label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
}

.form-item label span.val-badge {
  color: var(--primary);
  font-family: monospace;
  font-size: 0.8rem;
}

.input-text, .select-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 600;
  outline: none;
  transition: border-color 0.2s;
}

.input-text:focus, .select-input:focus {
  border-color: var(--border-focus);
}

.slider-input {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

/* PALETTE COLOR SWATCHES */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.4rem;
}

.swatch-btn {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  position: relative;
}

.swatch-btn:hover {
  transform: scale(1.1);
}

.swatch-btn.active {
  border-color: #ffffff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
}

/* TOGGLE SWITCH */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-round {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  transition: .3s;
  border-radius: 24px;
}

.slider-round:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider-round {
  background-color: var(--accent-emerald);
  border-color: var(--accent-emerald);
}

input:checked + .slider-round:before {
  transform: translateX(18px);
}

/* 3D VIEWPORT */
.studio-viewport {
  flex: 1;
  position: relative;
  background: radial-gradient(circle at center, #172033 0%, #0a0e17 100%);
  overflow: hidden;
}

#threejs-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* FLOATING VIEWPORT TOOLS */
.viewport-floating-tools {
  position: absolute;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  gap: 0.4rem;
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(8px);
  padding: 0.35rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.btn-tool {
  padding: 0.45rem 0.65rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s;
}

.btn-tool:hover, .btn-tool.active {
  background: var(--bg-card);
  color: var(--text-main);
}

/* REAL-TIME SPECS CARD (FLOATING TOP-RIGHT) */
.specs-overlay {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 180px;
}

.spec-line {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
}

.spec-line strong {
  color: var(--text-main);
  font-family: monospace;
}

/* DROPZONE FOR SVG */
.dropzone-box {
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.5rem 1rem;
  text-align: center;
  background: var(--bg-input);
  cursor: pointer;
  transition: all 0.2s;
}

.dropzone-box:hover {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.05);
}

/* RESPONSIVE */
@media (max-width: 900px) {
  #view-studio.active {
    height: auto;
    overflow: auto;
  }
  .studio-workspace {
    flex-direction: column-reverse;
  }
  .studio-controls {
    width: 100%;
    max-height: none;
  }
  .studio-viewport {
    height: 380px;
    min-height: 380px;
  }
}
