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

:root {
  --panel-width: 340px;
  --bg-primary: #1a1a1a;
  --bg-panel: #242424;
  --bg-card: #2e2e2e;
  --bg-card-hover: #383838;
  --text-primary: #f0f0f0;
  --text-secondary: #a0a0a0;
  --accent: #ffffff;
  --accent-hover: #dabb8f;
  --border: #3a3a3a;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

#app {
  display: flex;
  width: 100%;
  height: 100%;
}

/* Canvas */
#canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

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

/* UI Panel */
#ui-panel {
  width: var(--panel-width);
  height: 100%;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
}

#ui-panel::-webkit-scrollbar {
  width: 6px;
}

#ui-panel::-webkit-scrollbar-track {
  background: transparent;
}

#ui-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Category panels */
.category {
  margin: 18px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-panel);
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  cursor: pointer;
  background: var(--bg-primary);
  user-select: none;
  position: sticky;
  top: 0;
  z-index: 1;
  border-radius: 12px 12px 0 0;
}

.category.collapsed .category-header {
  border-radius: 12px;
}

.category-header:hover {
  background: #202020;
}

.category-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-primary);
}

.category-chevron {
  font-size: 14px;
  color: var(--text-secondary);
  transition: transform 0.2s;
}

.category.collapsed .category-chevron {
  transform: rotate(-90deg);
}

.category.collapsed .category-content {
  display: none;
}

/* Panel sections */
.panel-section {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
  border-bottom: none;
}

.panel-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* Swatch grid */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.swatch {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  position: relative;
  overflow: hidden;
}

.swatch:hover {
  transform: scale(1.08);
}

.swatch.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 100px rgba(0, 0, 0, 0.15);
}

.swatch-edge-accent {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  height: 4px;
}

.swatch-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 9px;
  text-align: center;
  padding: 2px;
  background: rgba(0,0,0,0.6);
  color: #fff;
}

.tabletop-grid {
  grid-template-columns: repeat(4, 1fr);
}

/* Option buttons */
.option-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.option-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-primary);
  font-size: 12px;
  text-align: center;
  min-height: 56px;
}

.option-btn:hover {
  background: var(--bg-card-hover);
}

.option-btn.active {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.option-btn .label {
  font-weight: 500;
}

.option-btn .sublabel {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.option-btn.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* Leg color swatches */
.leg-color-row {
  display: flex;
  gap: 8px;
}

.leg-color-swatch {
  flex: 1;
  height: 40px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.leg-color-swatch:hover {
  transform: scale(1.05);
}

.leg-color-swatch.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 100px rgba(0, 0, 0, 0.15);
}

.leg-color-label {
  font-size: 11px;
  font-weight: 500;
  color: #333;
}

.leg-color-swatch.dark-bg .leg-color-label {
  color: #ccc;
}

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

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-card);
  border-radius: 12px;
  transition: 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-secondary);
  border-radius: 50%;
  transition: 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background-color: white;
}

/* Module slots */
.module-slots {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.module-slot {
  flex: 1;
  aspect-ratio: 1;
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  min-width: 0;
}

.module-slot:hover {
  border-color: var(--accent);
}

.module-slot.active {
  border-style: solid;
  border-color: var(--accent);
}

.module-slot.occupied {
  border-style: solid;
  border-color: var(--text-secondary);
  background: var(--bg-card-hover);
}

.module-slot .slot-label {
  font-size: 9px;
  text-align: center;
  word-break: break-all;
  padding: 2px;
}

.module-slot .remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: #e74c3c;
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  display: none;
}

.module-slot.occupied:hover .remove-btn {
  display: block;
}

/* Module palette */
.module-palette {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.module-palette-item {
  padding: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  text-align: center;
  transition: all 0.15s;
  color: var(--text-primary);
}

.module-palette-item:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.module-palette-item.selected {
  border-color: var(--accent);
  background: rgba(200, 169, 126, 0.15);
}

/* Price display */
.price-display {
  padding: 16px;
  text-align: center;
  background: var(--bg-card);
  margin: 16px 20px;
  border-radius: 8px;
}

.price-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.price-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 4px;
}

/* Scene logo */
.scene-logo {
  position: absolute;
  bottom: 16px;
  left: 20px;
  z-index: 10;
  opacity: 1;
  user-select: none;
  text-decoration: none;
}

.terms-link {
  display: inline-block;
  margin: 50px 20px 20px;
  float: right;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
}
.terms-link:hover {
  color: var(--text-primary);
}

/* Lighting toggle */
.lighting-toggle {
  position: absolute;
  bottom: 26px;
  right: 32px;
  z-index: 10;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.2s;
}

.lighting-toggle:hover {
  background: rgba(0, 0, 0, 0.7);
}

.lighting-toggle.night-active {
  box-shadow: 0 0 12px 4px rgba(255, 220, 150, 0.5), 0 0 24px 8px rgba(255, 200, 100, 0.2);
}

.lighting-toggle svg {
  pointer-events: none;
}

/* Party toggle */
.party-toggle {
  position: absolute;
  bottom: 26px;
  right: 32px;
  z-index: 9;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transform: scale(0.4);
  pointer-events: none;
  transition: right 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.25s ease,
              transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
              background 0.2s,
              box-shadow 0.2s;
}

.party-toggle.visible {
  right: 82px;
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.party-toggle:hover {
  background: rgba(0, 0, 0, 0.7);
}

.party-toggle svg {
  pointer-events: none;
}

.party-toggle.party-active {
  animation: rainbow-glow 2s linear infinite;
}

@keyframes rainbow-glow {
  0%   { box-shadow: 0 0 12px 4px rgba(255, 0, 0, 0.6), 0 0 24px 8px rgba(255, 0, 0, 0.2); }
  16%  { box-shadow: 0 0 12px 4px rgba(255, 136, 0, 0.6), 0 0 24px 8px rgba(255, 136, 0, 0.2); }
  33%  { box-shadow: 0 0 12px 4px rgba(255, 255, 0, 0.6), 0 0 24px 8px rgba(255, 255, 0, 0.2); }
  50%  { box-shadow: 0 0 12px 4px rgba(0, 255, 0, 0.6), 0 0 24px 8px rgba(0, 255, 0, 0.2); }
  66%  { box-shadow: 0 0 12px 4px rgba(0, 128, 255, 0.6), 0 0 24px 8px rgba(0, 128, 255, 0.2); }
  83%  { box-shadow: 0 0 12px 4px rgba(136, 0, 255, 0.6), 0 0 24px 8px rgba(136, 0, 255, 0.2); }
  100% { box-shadow: 0 0 12px 4px rgba(255, 0, 0, 0.6), 0 0 24px 8px rgba(255, 0, 0, 0.2); }
}

/* Mobile layout */
@media (max-width: 768px) {
  #app {
    flex-direction: column;
  }

  #canvas-container {
    flex: none;
    height: 55vh;
  }

  #ui-panel {
    width: 100%;
    height: 45vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
