:root {
  --bg-primary: #0a0a0c;
  --panel-bg: rgba(18, 18, 22, 0.75);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-main: #f4f4f5;
  --text-muted: #9ca3af;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

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

body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-primary);
  font-family: var(--font-sans);
  color: var(--text-main);
  user-select: none;
}

#viewport-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Header Bar */
header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: linear-gradient(180deg, rgba(228, 226, 220, 0.85) 0%, rgba(228, 226, 220, 0) 100%);
  z-index: 10;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}

.logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #18181b;
}

.brand-divider {
  width: 1px;
  height: 18px;
  background: rgba(24, 24, 27, 0.18);
}

.model-identity {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.model-name {
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #3f3f46;
}

.badge {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  background: rgba(217, 119, 6, 0.15);
  color: #b45309;
  border: 1px solid rgba(217, 119, 6, 0.35);
  padding: 2px 8px;
  border-radius: 9999px;
  font-weight: 600;
}

.badge-btn {
  cursor: pointer;
  transition: all 0.2s ease;
}

.badge-btn:hover {
  background: rgba(217, 119, 6, 0.25);
  border-color: rgba(217, 119, 6, 0.6);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.btn-header {
  height: 34px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: #18181b;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-header:hover {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.2);
}

.model-select {
  width: 168px;
  height: 34px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: #18181b;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: all 0.2s ease;
  outline: none;
}

.model-select:hover,
.model-select:focus {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.25);
}

.model-select option:disabled {
  color: #6b7280;
}

/* Floating Sidebar Controls */
#configurator-panel {
  position: absolute;
  top: 72px;
  right: 24px;
  width: 320px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 20px;
  z-index: 10;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
}

#configurator-panel::-webkit-scrollbar {
  width: 4px;
}
#configurator-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.panel-section {
  margin-bottom: 20px;
}
.panel-section:last-child {
  margin-bottom: 0;
}

.section-title {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Preset Themes Grid */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.btn-preset {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-preset:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-preset.active {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.5);
  color: #fff;
}

.preset-swatches {
  display: flex;
  gap: 3px;
}

.swatch-pip {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

/* Variant Toggle */
.segmented-control {
  display: flex;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  padding: 3px;
  border: 1px solid var(--panel-border);
}

.segmented-option {
  flex: 1;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 6px 0;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.segmented-option.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Chassis Palette (Tabs + Swatch Grid + Secondary Custom Picker) */
.part-selector-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  padding: 3px;
  border: 1px solid var(--panel-border);
  gap: 2px;
  margin-bottom: 8px;
}

.part-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.71rem;
  font-weight: 500;
  padding: 6px 2px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.part-tab:hover {
  color: var(--text-main);
}

.part-tab.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.tab-pip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

.part-suboptions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 2px 2px 4px;
}

.part-suboptions[hidden],
.subpart-toggle[hidden] {
  display: none;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  color: var(--text-muted);
  cursor: pointer;
}

.toggle-label input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.subpart-toggle {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}

.subpart-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.subpart-btn.active {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

/* Primary Swatch Grid */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  padding: 6px 2px;
}

.swatch-chip {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  position: relative;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  padding: 0;
}

.swatch-chip:hover {
  transform: scale(1.14);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
  border-color: rgba(255, 255, 255, 0.65);
  z-index: 2;
}

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

.swatch-chip.active {
  outline: 2px solid #fff;
  outline-offset: 2px;
  transform: scale(1.06);
  z-index: 1;
}

/* Secondary Custom Hex Input */
.custom-color-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.custom-label {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.hex-input {
  width: 84px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 4px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.hex-input:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.1);
}

/* Bottom Controls */
.view-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.btn-ctrl {
  flex: 1 1 calc(50% - 4px);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 6px 0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-ctrl-full {
  flex: 1 1 100%;
}

.btn-ctrl:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.btn-ctrl.active {
  background: rgba(245, 158, 11, 0.2);
  color: var(--accent);
  border-color: rgba(245, 158, 11, 0.4);
}

/* Loading Overlay */
#loader-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #0a0a0c;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.4s ease, visibility 0.4s;
}

#loader-overlay.hidden {
  opacity: 0;
  visibility: hidden;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(245, 158, 11, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

.loading-text {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.progress-bar-container {
  width: 200px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  margin-top: 12px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* About Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  width: 440px;
  background: #141418;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #fff;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
}

.modal-close:hover {
  color: #fff;
}

.modal-body {
  font-size: 0.88rem;
  color: #d1d5db;
  line-height: 1.55;
  user-select: text;
  -webkit-user-select: text;
}

.spec-table {
  width: 100%;
  margin: 16px 0;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.spec-table td {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.spec-table td:first-child {
  color: var(--text-muted);
}

.spec-table td:last-child {
  text-align: right;
  font-family: var(--font-mono);
  color: #fff;
}

.community-links {
  position: absolute;
  bottom: 24px;
  left: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 10;
}

.community-links .modal-btn {
  flex: none;
  padding: 9px 16px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.modal-links {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-youtube {
  background: #dc2626;
  color: #fff;
}
.btn-youtube:hover {
  background: #b91c1c;
}

.btn-makerworld {
  background: #00ae42;
  color: #fff;
}
.btn-makerworld:hover {
  background: #009438;
}

.about-lead {
  color: #f4f4f5;
  font-weight: 500;
  margin-bottom: 10px;
}

.about-sub {
  color: var(--text-muted);
}

/* Changelog Modal */
.modal-card-wide {
  width: 480px;
  max-width: calc(100vw - 32px);
}

.changelog-list {
  max-height: 62vh;
  overflow-y: auto;
  padding-right: 6px;
}

.changelog-list::-webkit-scrollbar {
  width: 4px;
}

.changelog-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.changelog-entry {
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.changelog-entry:first-child {
  padding-top: 2px;
}

.changelog-entry:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.changelog-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.changelog-version {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.32);
  padding: 2px 8px;
  border-radius: 9999px;
}

.changelog-date {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.changelog-items {
  list-style: disc;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #e5e7eb;
  font-size: 0.84rem;
  line-height: 1.45;
}

/* 3D Projected Dimension Callout Labels */
#dimension-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}

#dimension-labels.hidden {
  display: none;
}

.dim-label {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(20, 20, 24, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: #f4f4f5;
  white-space: nowrap;
  will-change: transform;
}

.dim-label.hidden {
  display: none;
}

.dim-axis {
  font-weight: 700;
  font-size: 0.68rem;
  padding: 1px 4px;
  border-radius: 3px;
  line-height: 1.1;
}

.dim-axis-x {
  background: rgba(220, 38, 38, 0.25);
  color: #fca5a5;
}

.dim-axis-y {
  background: rgba(5, 150, 105, 0.25);
  color: #6ee7b7;
}

.dim-axis-z {
  background: rgba(37, 99, 235, 0.28);
  color: #93c5fd;
}

.dim-value {
  letter-spacing: 0.01em;
}
