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

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface-hover: #24243a;
  --border: #2a2a3e;
  --text: #e0e0e8;
  --text-dim: #8888a0;
  --accent: #6c63ff;
  --accent-hover: #7f78ff;
  --danger: #e84057;
  --success: #2ecc71;
  --warning: #f1c40f;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  text-align: center;
  padding: 1rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

main {
  display: flex;
  gap: 1px;
  background: var(--border);
  height: calc(100vh - 110px);
  min-height: 400px;
  overflow: hidden;
}

.panel {
  background: var(--bg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
}

.panel h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.left-panel {
  width: 360px;
  min-width: 300px;
  flex-shrink: 0;
}

.right-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
}

/* Upload area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: 12px;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
  overflow: hidden;
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--accent);
  background: rgba(108, 99, 255, 0.05);
}

.upload-placeholder {
  text-align: center;
  padding: 1.5rem;
}

.upload-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.5rem;
}

.upload-placeholder p {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.upload-hint {
  font-size: 0.75rem !important;
  margin-top: 0.25rem;
}

.preview-image {
  max-width: 100%;
  max-height: 300px;
  object-fit: contain;
  display: none;
  border-radius: 8px;
}

.preview-image.visible {
  display: block;
}

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

.btn-danger:hover:not(:disabled) {
  background: rgba(232, 64, 87, 0.1);
  border-color: var(--danger);
}

/* Status */
.status {
  font-size: 0.85rem;
  min-height: 1.2em;
  color: var(--text-dim);
}

.status.error {
  color: var(--danger);
}

.status.success {
  color: var(--success);
}

.status.loading {
  color: var(--warning);
}

.status.loading::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%  { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* 3D Viewer */
.viewer {
  flex: 1;
  min-height: 300px;
  max-height: 100%;
  background: #0a0a0f;
  border-radius: 12px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

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

.viewer-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
  pointer-events: none;
}

.viewer-hint.hidden {
  display: none;
}

/* Parts palette */
footer {
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem;
}

footer h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

.parts-palette {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.part-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: fit-content;
}

.part-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
}

.part-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.part-name {
  font-size: 0.8rem;
  font-weight: 600;
}

.part-dims {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* Responsive */
@media (max-width: 768px) {
  main {
    flex-direction: column;
  }

  .left-panel {
    width: 100%;
    min-width: 0;
  }

  .viewer {
    min-height: 300px;
  }

  .parts-palette {
    flex-wrap: nowrap;
  }

  .controls {
    flex-wrap: wrap;
  }

  .btn {
    flex: 0 0 auto;
  }
}
